/** * Multi-turn session example. * * Usage: * npx tsx examples/multi-turn-session.ts */ import { DroidMessageType, createSession } from '@factory/droid-sdk'; async function streamText( session: Awaited>, prompt: string ): Promise { let text = ''; for await (const msg of session.stream(prompt, { includePartialMessages: true, })) { if (msg.type === DroidMessageType.AssistantTextDelta) { text += msg.text; } } return text; } const session = await createSession({ apiKey: process.env.FACTORY_API_KEY!, cwd: process.cwd(), }); try { console.log(`Session: ${session.sessionId}\n`); const first = await streamText(session, 'What is this project?'); console.log(first); const second = await streamText(session, 'What should I test first?'); console.log('\n', second); } finally { await session.close(); }