()
| 14 | import { Agent } from '../../index.js'; |
| 15 | |
| 16 | async function main(): Promise<void> { |
| 17 | const configPath = process.env.A3S_CONFIG_PATH |
| 18 | || '/Users/roylin/Desktop/code/a3s/crates/code/sdk/node/examples/streaming/test_minimax.acl'; |
| 19 | |
| 20 | console.log(`Using config: ${configPath}\n`); |
| 21 | |
| 22 | const agent = await Agent.create(configPath); |
| 23 | const session = agent.session('.', { |
| 24 | permissionPolicy: { defaultDecision: 'allow' }, maxToolRounds: 0, |
| 25 | }); |
| 26 | |
| 27 | const prompt = 'Say hello in exactly 5 Chinese characters.'; |
| 28 | console.log(`Streaming with prompt: "${prompt}"\n`); |
| 29 | |
| 30 | const stream = await session.stream(prompt); |
| 31 | |
| 32 | const textDeltas: string[] = []; |
| 33 | const reasoningDeltas: string[] = []; |
| 34 | const allEvents: Array<{ type: string; text?: string }> = []; |
| 35 | let eventCount = 0; |
| 36 | |
| 37 | while (true) { |
| 38 | const result = await stream.next(); |
| 39 | if (!result.value || result.done) break; |
| 40 | |
| 41 | const event = result.value; |
| 42 | eventCount++; |
| 43 | const type = event.type || 'unknown'; |
| 44 | |
| 45 | if (type === 'text_delta' && event.text) { |
| 46 | textDeltas.push(event.text); |
| 47 | allEvents.push({ type, text: event.text }); |
| 48 | } else if (type === 'reasoning_delta' && event.text) { |
| 49 | reasoningDeltas.push(event.text); |
| 50 | allEvents.push({ type, text: event.text }); |
| 51 | } |
| 52 | |
| 53 | // Log first 15 events for debugging |
| 54 | if (eventCount <= 15) { |
| 55 | console.log(`[${eventCount}] type="${type}"` + |
| 56 | (event.text ? ` text="${event.text.slice(0, 50)}"` : '') + |
| 57 | (event.data ? ` data="${event.data?.slice(0, 60)}"` : '') |
| 58 | ); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | console.log('\n' + '='.repeat(80)); |
| 63 | console.log('Summary:'); |
| 64 | console.log(`Total events: ${eventCount}`); |
| 65 | console.log(`TextDelta events: ${textDeltas.length}`); |
| 66 | console.log(`ReasoningDelta events: ${reasoningDeltas.length}`); |
| 67 | |
| 68 | const combinedText = textDeltas.join(''); |
| 69 | console.log(`\nCombined text: "${combinedText}"`); |
| 70 | console.log(`Text length: ${combinedText.length}`); |
| 71 | |
| 72 | // Verify no duplicates |
| 73 | let hasDuplicate = false; |
no test coverage detected