| 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 "OK"'; |
| 17 | console.log(`Prompt: "${prompt}"`); |
| 18 | |
| 19 | const stream = await session.stream(prompt); |
| 20 | |
| 21 | const textDeltas: string[] = []; |
| 22 | const seen = new Set<string>(); |
| 23 | let eventCount = 0; |
| 24 | |
| 25 | while (true) { |
| 26 | const result = await stream.next(); |
| 27 | if (!result.value || result.done) break; |
| 28 | |
| 29 | const event = result.value; |
| 30 | eventCount++; |
| 31 | |
| 32 | if (event.type === 'text_delta' && event.text) { |
| 33 | textDeltas.push(event.text); |
| 34 | if (seen.has(event.text)) { |
| 35 | console.log(`❌ DUPLICATE: "${event.text}"`); |
| 36 | console.log('\n--- Summary ---'); |
| 37 | console.log(`Total text_delta events: ${textDeltas.length}`); |
| 38 | console.log(`Unique text_delta events: ${seen.size}`); |
| 39 | console.log('\n❌ DUPLICATES DETECTED'); |
| 40 | return; |
| 41 | } |
| 42 | seen.add(event.text); |
| 43 | console.log(`[${eventCount}] text: "${event.text.slice(0, 30)}..."`); |
| 44 | } |
| 45 | |
| 46 | if (eventCount > 100) { |
| 47 | console.log('\n... (stopping after 100 events)'); |
| 48 | break; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | console.log('\n--- Summary ---'); |
| 53 | console.log(`Total text_delta events: ${textDeltas.length}`); |
| 54 | console.log(`Unique text_delta events: ${seen.size}`); |
| 55 | |
| 56 | if (textDeltas.length === seen.size) { |
| 57 | console.log('\n✅ No duplicates!'); |
| 58 | } else { |
| 59 | console.log('\n❌ DUPLICATES DETECTED'); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | main().catch(err => { |
| 64 | console.error('Error:', err); |