MCPcopy Create free account
hub / github.com/AI45Lab/Code / main

Function main

sdk/node/examples/streaming/test_fix_minimax.ts:12–88  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10import { Agent } from '../../index.js';
11
12async function main(): Promise<void> {
13 const configPath = '/Users/roylin/Desktop/code/a3s/crates/code/sdk/node/examples/streaming/test_minimax.acl';
14 console.log(`Using config: ${configPath}\n`);
15
16 const agent = await Agent.create(configPath);
17 const session = agent.session('.', {
18 permissionPolicy: { defaultDecision: 'allow' }, maxToolRounds: 0,
19 });
20
21 const prompt = 'Say hello in 3 Chinese characters.';
22 console.log(`Streaming with prompt: "${prompt}"\n`);
23
24 const stream = await session.stream(prompt);
25
26 const textDeltas: string[] = [];
27 const reasoningDeltas: string[] = [];
28 let eventCount = 0;
29
30 while (true) {
31 const result = await stream.next();
32 if (!result.value || result.done) break;
33
34 const event = result.value;
35 eventCount++;
36 const type = event.type || 'unknown';
37
38 if (type === 'text_delta' && event.text) {
39 textDeltas.push(event.text);
40 console.log(`[${eventCount}] text_delta: "${event.text}"`);
41 } else if (type === 'reasoning_delta' && event.text) {
42 reasoningDeltas.push(event.text);
43 if (eventCount <= 3) {
44 console.log(`[${eventCount}] reasoning_delta: "${event.text.slice(0, 40)}..."`);
45 }
46 }
47 }
48
49 console.log('\n' + '='.repeat(80));
50 console.log('Summary:');
51 console.log(`Total events: ${eventCount}`);
52 console.log(`TextDelta count: ${textDeltas.length}`);
53 console.log(`ReasoningDelta count: ${reasoningDeltas.length}`);
54
55 const combinedText = textDeltas.join('');
56 console.log(`\nFinal text: "${combinedText}"`);
57
58 // Check for duplicates
59 const uniqueChunks = new Set(textDeltas);
60 console.log(`Unique chunks: ${uniqueChunks.size} / ${textDeltas.length}`);
61
62 if (textDeltas.length >= 2) {
63 const halfLen = Math.floor(combinedText.length / 2);
64 const firstHalf = combinedText.slice(0, halfLen);
65 const secondHalf = combinedText.slice(halfLen);
66
67 if (firstHalf === secondHalf && combinedText.length > 4) {
68 console.log('\n❌ DUPLICATE DETECTED: Full text appears twice!');
69 process.exit(1);

Callers 1

Calls 7

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

Tested by

no test coverage detected