MCPcopy Index your code
hub / github.com/AI45Lab/Code / main

Function main

sdk/node/examples/streaming/stream_fix_test.ts:11–64  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9import * as os from 'os';
10
11async function main(): Promise<void> {
12 const configPath = process.env.A3S_CONFIG || path.join(os.homedir(), '.a3s', 'config.acl');
13 console.log(`Using config: ${configPath}\n`);
14 console.log('='.repeat(80));
15 console.log('Stream Fix Verification Test (maxToolRounds: 0, no tools)');
16 console.log('='.repeat(80));
17 console.log();
18
19 const agent = await Agent.create(configPath);
20 // User's exact code: maxToolRounds: 0 to disable tool calls
21 const session = agent.session('.', {
22 permissionPolicy: { defaultDecision: 'allow' }, maxToolRounds: 0,
23 });
24
25 console.log('Streaming with prompt: "Say hello in 5 words"\n');
26
27 const stream = await session.stream('Say hello in 5 words');
28
29 const eventTypes = new Map<string, number>();
30 let totalEvents = 0;
31
32 while (true) {
33 const result = await stream.next();
34 if (!result.value || result.done) break;
35
36 const event = result.value;
37 totalEvents++;
38 const count = eventTypes.get(event.type) ?? 0;
39 eventTypes.set(event.type, count + 1);
40
41 // Log all events
42 console.log(`[${totalEvents}] type="${event.type}"` +
43 (event.text ? ` text="${event.text.slice(0, 50)}"` : '') +
44 (event.toolName ? ` toolName="${event.toolName}"` : '') +
45 (event.data ? ` data="${event.data.slice(0, 80)}"` : '') +
46 (event.error ? ` error="${event.error}"` : '') +
47 '');
48 }
49
50 console.log('\n' + '='.repeat(80));
51 console.log('Summary:');
52 console.log(`Total events: ${totalEvents}`);
53 console.log('Event types received:');
54 for (const [type, count] of eventTypes) {
55 console.log(` ${type}: ${count}`);
56 }
57
58 if (eventTypes.has('unknown')) {
59 console.log('\n❌ FAILED: Still receiving "unknown" event types!');
60 process.exit(1);
61 } else {
62 console.log('\n✅ PASSED: No "unknown" event types detected.');
63 }
64}
65
66main().catch((err: unknown) => {
67 console.error('Test failed:', err);

Callers 1

stream_fix_test.tsFile · 0.70

Calls 7

logMethod · 0.45
createMethod · 0.45
sessionMethod · 0.45
streamMethod · 0.45
nextMethod · 0.45
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected