import { ChuckyClient, tool, getAssistantText } from '@chucky.cloud/sdk';
// Define a tool
const weatherTool = tool(
'get_weather',
'Get current weather for a city',
{
type: 'object',
properties: {
city: { type: 'string', description: 'City name' },
},
required: ['city'],
},
async ({ city }) => {
// Your implementation
const weather = await fetchWeather(city);
return { content: [{ type: 'text', text: `${city}: ${weather}` }] };
}
);
// Use tools in a session
const client = new ChuckyClient({ token });
const session = client.createSession({
tools: [weatherTool],
});
await session.send('What is the weather in Tokyo?');
for await (const msg of session.stream()) {
if (msg.type === 'assistant') {
console.log(getAssistantText(msg));
}
}
// Claude will call get_weather, then respond with the result
session.close();