| 11 | import { Agent } from '../../index.js'; |
| 12 | |
| 13 | async function main(): Promise<void> { |
| 14 | const apiKey = process.env.A3S_API_KEY; |
| 15 | const baseUrl = process.env.A3S_BASE_URL || 'https://api.moonshot.cn/v1'; |
| 16 | |
| 17 | if (!apiKey) { |
| 18 | console.error('❌ Missing A3S_API_KEY environment variable'); |
| 19 | console.log('\nUsage:'); |
| 20 | console.log(' A3S_API_KEY=your_key A3S_BASE_URL=https://api.moonshot.cn/v1 \\'); |
| 21 | console.log(' npx tsx sdk/node/examples/streaming/test_fix_verification_kimi.ts'); |
| 22 | process.exit(1); |
| 23 | } |
| 24 | |
| 25 | console.log(`Using API: ${baseUrl}\n`); |
| 26 | |
| 27 | // Create config inline with env vars. |
| 28 | const agent = await Agent.create(` |
| 29 | default_model = "openai/kimi-k2.5" |
| 30 | |
| 31 | providers "openai" { |
| 32 | apiKey = "${apiKey}" |
| 33 | baseUrl = "${baseUrl}" |
| 34 | |
| 35 | models "kimi-k2.5" { |
| 36 | name = "kimi" |
| 37 | reasoning = true |
| 38 | } |
| 39 | } |
| 40 | `); |
| 41 | |
| 42 | const session = agent.session('.', { |
| 43 | permissionPolicy: { defaultDecision: 'allow' }, maxToolRounds: 0, |
| 44 | }); |
| 45 | |
| 46 | const prompt = 'Say hello in exactly 3 words in Chinese.'; |
| 47 | console.log(`Streaming with prompt: "${prompt}"\n`); |
| 48 | |
| 49 | const stream = await session.stream(prompt); |
| 50 | |
| 51 | const textDeltas: string[] = []; |
| 52 | const reasoningDeltas: string[] = []; |
| 53 | let eventCount = 0; |
| 54 | |
| 55 | while (true) { |
| 56 | const result = await stream.next(); |
| 57 | if (!result.value || result.done) break; |
| 58 | |
| 59 | const event = result.value; |
| 60 | eventCount++; |
| 61 | const type = event.type || 'unknown'; |
| 62 | |
| 63 | if (type === 'text_delta' && event.text) { |
| 64 | textDeltas.push(event.text); |
| 65 | console.log(`[${eventCount}] text_delta: "${event.text}"`); |
| 66 | } else if (type === 'reasoning_delta' && event.text) { |
| 67 | reasoningDeltas.push(event.text); |
| 68 | if (eventCount <= 5) { |
| 69 | console.log(`[${eventCount}] reasoning_delta: "${event.text.slice(0, 40)}..."`); |
| 70 | } |