The most common use case is having a conversation with Nira:
// Create a new conversationconst conversation = await nb.nira.conversations.create('My First Chat');console.log(`Created conversation: ${conversation.id}`);// Send a message and stream the responseconsole.log('\nNira response:');for await (const event of nb.nira.messages.stream(conversation.id, 'Hello! What can you help me with?')) { if (event.type === 'content') { process.stdout.write(event.data.text as string); }}console.log('\n');
Here’s a complete example that ties everything together:
import { NimbleBrain } from '@nimblebrain/sdk';async function main() { // Initialize const nb = new NimbleBrain({ apiKey: process.env.NIMBLEBRAIN_API_KEY!, }); try { // List available playbooks const playbooks = await nb.playbooks.list(); console.log(`Found ${playbooks.length} playbooks`); // Chat with Nira console.log('\nStarting conversation with Nira...'); const conversation = await nb.nira.conversations.create('SDK Demo'); // Stream the response process.stdout.write('\nNira: '); for await (const event of nb.nira.messages.stream( conversation.id, 'Hello! Give me a brief introduction of what you can help me with.' )) { if (event.type === 'content') { process.stdout.write(event.data.text as string); } } console.log('\n'); } catch (error) { console.error('Error:', error); }}main();