| 6 | import { Agent } from '../../index.js'; |
| 7 | |
| 8 | async function main(): Promise<void> { |
| 9 | const configPath = '/Users/roylin/Desktop/code/a3s/crates/code/sdk/node/examples/streaming/test_minimax.acl'; |
| 10 | |
| 11 | const agent = await Agent.create(configPath); |
| 12 | const session = agent.session('.', { |
| 13 | permissionPolicy: { defaultDecision: 'allow' }, maxToolRounds: 0, |
| 14 | }); |
| 15 | |
| 16 | const prompt = 'Say hello in 3 words.'; |
| 17 | console.log(`Prompt: "${prompt}"`); |
| 18 | |
| 19 | const stream = await session.stream(prompt); |
| 20 | |
| 21 | let eventCount = 0; |
| 22 | |
| 23 | while (true) { |
| 24 | const result = await stream.next(); |
| 25 | if (!result.value || result.done) break; |
| 26 | |
| 27 | const event = result.value; |
| 28 | eventCount++; |
| 29 | |
| 30 | // Log all events |
| 31 | console.log(`[${eventCount}] type="${event.type}"` + |
| 32 | (event.text ? ` text="${event.text.slice(0, 30)}..."` : '') + |
| 33 | (event.data ? ` data="${JSON.stringify(event.data)?.slice(0, 60)}..."` : '') |
| 34 | ); |
| 35 | |
| 36 | // Stop after 30 events to avoid flooding |
| 37 | if (eventCount >= 30) { |
| 38 | console.log('\n... (stopping after 30 events)'); |
| 39 | break; |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | main().catch(err => { |
| 45 | console.error('Error:', err); |