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

Function main

sdk/node/examples/streaming/test_minimax_stream.ts:30–92  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28}
29
30async function main(): Promise<void> {
31 const configPath = resolveConfigPath();
32 console.log(`Using config: ${configPath}\n`);
33
34 const agent = await Agent.create(configPath);
35 const session = agent.session('.', {
36 permissionPolicy: { defaultDecision: 'allow' },
37 maxToolRounds: 0,
38 });
39
40 console.log('Streaming with prompt: "Say hello in 5 words"\n');
41
42 const stream = await session.stream('Say hello in 5 words');
43
44 let eventCount = 0;
45 const eventTypes = new Map<string, number>();
46 const textDeltas: string[] = [];
47 const reasoningDeltas: string[] = [];
48
49 while (true) {
50 const result = await stream.next();
51 if (!result.value || result.done) break;
52
53 const event = result.value;
54 eventCount++;
55 const type = event.type || 'unknown';
56 const count = eventTypes.get(type) ?? 0;
57 eventTypes.set(type, count + 1);
58
59 if (type === 'text_delta' && event.text) {
60 textDeltas.push(event.text);
61 } else if (type === 'reasoning_delta' && event.text) {
62 reasoningDeltas.push(event.text);
63 }
64
65 // Log first 10 events
66 if (eventCount <= 10) {
67 console.log(
68 `[${eventCount}] type="${type}"` +
69 (event.text ? ` text="${event.text.slice(0, 40)}"` : '') +
70 (event.data ? ` data="${event.data?.slice(0, 60)}"` : ''),
71 );
72 }
73 }
74
75 console.log('\n' + '='.repeat(80));
76 console.log('Summary:');
77 console.log(`Total events: ${eventCount}`);
78 console.log('Event types received:');
79 for (const [type, count] of eventTypes) {
80 console.log(` ${type}: ${count}`);
81 }
82 console.log(`\nTextDelta count: ${textDeltas.length}`);
83 console.log(`Text content: "${textDeltas.join('')}"`);
84 console.log(`\nReasoningDelta count: ${reasoningDeltas.length}`);
85 console.log(`Reasoning content preview: "${reasoningDeltas.slice(0, 3).join('').slice(0, 100)}..."`);
86
87 if (reasoningDeltas.length > 0 && textDeltas.join('').length === 0) {

Callers 1

Calls 8

resolveConfigPathFunction · 0.85
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