| 7 | import * as path from 'path'; |
| 8 | |
| 9 | async function main(): Promise<void> { |
| 10 | const configPath = '/Users/roylin/Desktop/code/a3s/crates/code/sdk/node/examples/streaming/test_config3.acl'; |
| 11 | console.log(`Using config: ${configPath}\n`); |
| 12 | |
| 13 | const agent = await Agent.create(configPath); |
| 14 | const session = agent.session('.', { |
| 15 | permissionPolicy: { defaultDecision: 'allow' }, maxToolRounds: 0, |
| 16 | }); |
| 17 | |
| 18 | console.log('Streaming with prompt: "Say hello in 5 words"\n'); |
| 19 | |
| 20 | const stream = await session.stream('Say hello in 5 words'); |
| 21 | |
| 22 | let eventCount = 0; |
| 23 | let textDeltaCount = 0; |
| 24 | let totalText = ''; |
| 25 | |
| 26 | while (true) { |
| 27 | const result = await stream.next(); |
| 28 | if (!result.value || result.done) break; |
| 29 | |
| 30 | const event = result.value; |
| 31 | eventCount++; |
| 32 | console.log(`[${eventCount}] type="${event.type}"` + |
| 33 | (event.text ? ` text="${event.text.slice(0, 50)}"` : '') + |
| 34 | (event.data ? ` data="${event.data?.slice(0, 80)}"` : '') |
| 35 | ); |
| 36 | |
| 37 | if (event.type === 'text_delta' && event.text) { |
| 38 | textDeltaCount++; |
| 39 | totalText += event.text; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | console.log('\n' + '='.repeat(80)); |
| 44 | console.log('Summary:'); |
| 45 | console.log(`Total events: ${eventCount}`); |
| 46 | console.log(`TextDelta events: ${textDeltaCount}`); |
| 47 | console.log(`Total text length: ${totalText.length}`); |
| 48 | console.log(`Total text preview: "${totalText.slice(0, 100)}..."`); |
| 49 | } |
| 50 | |
| 51 | main().catch((err: unknown) => { |
| 52 | console.error('Test failed:', err); |