Skip to content

Commit 3873870

Browse files
committed
fix(sdk): handle all AgentEvent variants in stream output
Previously, many Rust AgentEvent variants (like ToolInputDelta, AgentModeChanged, ConfirmationRequired, etc.) were not handled in the From<RustAgentEvent> implementations for Node.js and Python SDKs, causing them to fall through to a catch-all that returned type "unknown". Now all event variants are explicitly handled and mapped to the appropriate event type. A new "data" field (JSON-encoded) is used to carry extra event data that doesn't fit the standard fields. Also bumps version to 1.9.1 for both Node.js and Python SDKs.
1 parent b46c93d commit 3873870

9 files changed

Lines changed: 781 additions & 110 deletions

File tree

core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "a3s-code-core"
3-
version = "1.9.0"
3+
version = "1.9.1"
44
edition = "2021"
55
authors = ["A3S Lab Team"]
66
license = "MIT"
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env npx tsx
2+
/**
3+
* Stream fix verification test.
4+
* Uses kimi model from config and logs ALL event types to verify no "unknown" appears.
5+
*/
6+
7+
import { Agent, Session } from '../../index.js';
8+
import * as path from 'path';
9+
import * as os from 'os';
10+
11+
async function main(): Promise<void> {
12+
const configPath = process.env.A3S_CONFIG || path.join(os.homedir(), '.a3s', 'config.hcl');
13+
console.log(`Using config: ${configPath}\n`);
14+
console.log('='.repeat(80));
15+
console.log('Stream Fix Verification Test');
16+
console.log('='.repeat(80));
17+
console.log();
18+
19+
const agent = await Agent.create(configPath);
20+
const session = agent.session('.');
21+
22+
console.log('Streaming with prompt: "Say hello in 5 words"\n');
23+
24+
const stream = await session.stream('Say hello in 5 words');
25+
26+
const eventTypes = new Map<string, number>();
27+
let totalEvents = 0;
28+
29+
while (true) {
30+
const result = await stream.next();
31+
if (!result.value || result.done) break;
32+
33+
const event = result.value;
34+
totalEvents++;
35+
const count = eventTypes.get(event.type) ?? 0;
36+
eventTypes.set(event.type, count + 1);
37+
38+
// Log all events
39+
console.log(`[${totalEvents}] type="${event.type}"` +
40+
(event.text ? ` text="${event.text.slice(0, 50)}"` : '') +
41+
(event.toolName ? ` toolName="${event.toolName}"` : '') +
42+
(event.data ? ` data="${event.data.slice(0, 80)}"` : '') +
43+
(event.error ? ` error="${event.error}"` : '') +
44+
'');
45+
}
46+
47+
console.log('\n' + '='.repeat(80));
48+
console.log('Summary:');
49+
console.log(`Total events: ${totalEvents}`);
50+
console.log('Event types received:');
51+
for (const [type, count] of eventTypes) {
52+
console.log(` ${type}: ${count}`);
53+
}
54+
55+
if (eventTypes.has('unknown')) {
56+
console.log('\n❌ FAILED: Still receiving "unknown" event types!');
57+
process.exit(1);
58+
} else {
59+
console.log('\n✅ PASSED: No "unknown" event types detected.');
60+
}
61+
}
62+
63+
main().catch((err: unknown) => {
64+
console.error('Test failed:', err);
65+
process.exit(1);
66+
});

sdk/node/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ export interface AgentEvent {
179179
question?: string
180180
/** For btw_answer event: the LLM's answer */
181181
answer?: string
182+
/** Extra data for events that don't map to standard fields (JSON-encoded) */
183+
data?: string
182184
}
183185
export interface ToolResult {
184186
name: string

sdk/node/package-lock.json

Lines changed: 14 additions & 74 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/node/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@a3s-lab/code",
3-
"version": "1.9.0",
3+
"version": "1.9.1",
44
"description": "A3S Code - Native AI coding agent library for Node.js",
55
"main": "index.js",
66
"types": "index.d.ts",
@@ -44,11 +44,11 @@
4444
"test:loop": "tsx --tsconfig examples/tsconfig.json examples/test_loop_commands.ts"
4545
},
4646
"optionalDependencies": {
47-
"@a3s-lab/code-darwin-arm64": "1.9.0",
48-
"@a3s-lab/code-linux-x64-gnu": "1.9.0",
49-
"@a3s-lab/code-linux-x64-musl": "1.9.0",
50-
"@a3s-lab/code-linux-arm64-gnu": "1.9.0",
51-
"@a3s-lab/code-linux-arm64-musl": "1.9.0",
52-
"@a3s-lab/code-win32-x64-msvc": "1.9.0"
47+
"@a3s-lab/code-darwin-arm64": "1.9.1",
48+
"@a3s-lab/code-linux-x64-gnu": "1.9.1",
49+
"@a3s-lab/code-linux-x64-musl": "1.9.1",
50+
"@a3s-lab/code-linux-arm64-gnu": "1.9.1",
51+
"@a3s-lab/code-linux-arm64-musl": "1.9.1",
52+
"@a3s-lab/code-win32-x64-msvc": "1.9.1"
5353
}
5454
}

0 commit comments

Comments
 (0)