import { defineSkill } from '@cognest/sdk'
export default defineSkill({
// Required: Identity
name: 'order-lookup',
description: 'Look up order status by order ID or customer email',
// Optional: Version and metadata
version: '1.0.0',
author: 'your-team',
tags: ['ecommerce', 'customer-support'],
// Optional: Required integrations
integrations: [],
permissions: [],
// Required: Input schema for the Think Engine
input: {
order_id: {
type: 'string',
description: 'The order ID to look up',
required: false,
},
email: {
type: 'string',
description: 'Customer email to find orders for',
required: false,
},
},
// Required: Execution logic
async execute(context, input) {
if (!input.order_id && !input.email) {
return { text: 'Please provide an order ID or email address.' }
}
// Your business logic here
const order = await lookupOrder(input.order_id ?? input.email)
if (!order) {
return { text: 'Order not found. Please check the ID and try again.' }
}
return {
text: `Order #${order.id}: ${order.status}. Shipped ${order.shipped_at}. Tracking: ${order.tracking_number}`,
data: order,
}
},
})
async function lookupOrder(identifier: string) {
const res = await fetch(`https://api.mystore.com/orders/search?q=${identifier}`)
return res.json()
}
async execute(context, input) {
// State is scoped per user per integration
const history = await context.state.get('lookup-history') ?? []
history.push({
query: input.order_id,
timestamp: new Date().toISOString(),
})
await context.state.set('lookup-history', history)
// Access state from the triggering event
const userId = context.event.from
context.log.info(`User ${userId} has made ${history.length} lookups`)
return { text: `Lookup recorded. Total lookups: ${history.length}` }
}