@ai-sdk/harness-claude-code 1.0.192 → 1.0.194
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/bridge/index.mjs +1 -0
- package/dist/bridge/index.mjs.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/package.json +6 -7
- package/src/bridge/create-emit-stream-event.ts +7 -1
- package/src/claude-code-harness.ts +32 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/harness-claude-code",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.194",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@ai-sdk/harness": "1.0.
|
|
29
|
+
"@ai-sdk/harness": "1.0.190",
|
|
30
30
|
"@ai-sdk/provider": "4.0.39",
|
|
31
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
31
|
+
"@ai-sdk/provider-utils": "5.0.83",
|
|
32
32
|
"ws": "^8.21.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
@@ -67,11 +67,10 @@
|
|
|
67
67
|
"claude-code"
|
|
68
68
|
],
|
|
69
69
|
"scripts": {
|
|
70
|
-
"build": "
|
|
71
|
-
"build:watch": "
|
|
72
|
-
"clean": "del-cli *.tsbuildinfo",
|
|
70
|
+
"build": "tsdown && pnpm copy-bridge-assets",
|
|
71
|
+
"build:watch": "tsdown --watch",
|
|
73
72
|
"copy-bridge-assets": "node -e \"import('node:fs/promises').then(async fs => { await fs.copyFile('src/bridge/package.json', 'dist/bridge/package.json'); await fs.copyFile('src/bridge/pnpm-lock.yaml', 'dist/bridge/pnpm-lockfile.yaml'); await fs.copyFile('src/bridge/pnpm-workspace.yaml', 'dist/bridge/pnpm-workspace.yaml'); })\"",
|
|
74
|
-
"type-check": "tsc --
|
|
73
|
+
"type-check": "tsc --noEmit",
|
|
75
74
|
"test": "pnpm test:node",
|
|
76
75
|
"test:watch": "vitest --config vitest.node.config.js",
|
|
77
76
|
"test:node": "vitest --config vitest.node.config.js --run"
|
|
@@ -6,6 +6,7 @@ type Emit = (message: Record<string, unknown>) => void;
|
|
|
6
6
|
export type ClaudeMessage = {
|
|
7
7
|
type?: string;
|
|
8
8
|
subtype?: string;
|
|
9
|
+
session_id?: string;
|
|
9
10
|
permissionMode?: string;
|
|
10
11
|
parent_tool_use_id?: string | null;
|
|
11
12
|
model?: string;
|
|
@@ -226,13 +227,18 @@ export function createEmitStreamEvent({
|
|
|
226
227
|
type === 'system' &&
|
|
227
228
|
(msg.subtype === 'init' || msg.subtype === 'status')
|
|
228
229
|
) {
|
|
229
|
-
// Expose
|
|
230
|
+
// Expose resume metadata without forwarding the large init payload
|
|
230
231
|
// (tools, MCP servers, skills, plugins, and other session metadata).
|
|
231
232
|
emit({
|
|
232
233
|
type: 'raw',
|
|
233
234
|
rawValue: {
|
|
234
235
|
type,
|
|
235
236
|
subtype: msg.subtype,
|
|
237
|
+
...(msg.subtype === 'init' &&
|
|
238
|
+
typeof msg.session_id === 'string' &&
|
|
239
|
+
msg.session_id.length > 0
|
|
240
|
+
? { sessionId: msg.session_id }
|
|
241
|
+
: {}),
|
|
236
242
|
...(msg.permissionMode != null
|
|
237
243
|
? { permissionMode: msg.permissionMode }
|
|
238
244
|
: {}),
|
|
@@ -218,6 +218,11 @@ export type ClaudeCodeHarnessSettings = {
|
|
|
218
218
|
* milliseconds up to 2 seconds.
|
|
219
219
|
*/
|
|
220
220
|
readonly reconnect?: SandboxChannelReconnectOptions;
|
|
221
|
+
/**
|
|
222
|
+
* WebSocket ping interval in milliseconds. Defaults to 20_000. Set to 0 to
|
|
223
|
+
* disable. Two unanswered pings terminate the socket and trigger reconnect.
|
|
224
|
+
*/
|
|
225
|
+
readonly keepAliveMs?: number;
|
|
221
226
|
/**
|
|
222
227
|
* Called with bridge connection lifecycle events: reconnect attempts,
|
|
223
228
|
* successful reconnects, and `reconnect-failed` once the connection is
|
|
@@ -1111,6 +1116,7 @@ export function createClaudeCode(
|
|
|
1111
1116
|
onDiagnostic,
|
|
1112
1117
|
onBridgeError,
|
|
1113
1118
|
reconnect: settings.reconnect,
|
|
1119
|
+
keepAliveMs: settings.keepAliveMs,
|
|
1114
1120
|
onDebug: settings.onDebug,
|
|
1115
1121
|
});
|
|
1116
1122
|
const finishListenerAttachment = isContinue
|
|
@@ -1283,6 +1289,7 @@ export function createClaudeCode(
|
|
|
1283
1289
|
onDiagnostic,
|
|
1284
1290
|
onBridgeError,
|
|
1285
1291
|
reconnect: settings.reconnect,
|
|
1292
|
+
keepAliveMs: settings.keepAliveMs,
|
|
1286
1293
|
onDebug: settings.onDebug,
|
|
1287
1294
|
// In replay mode the respawned bridge reloaded the finished turn from
|
|
1288
1295
|
// disk; seed the cursor and resume so it streams the tail (incl.
|
|
@@ -1463,8 +1470,8 @@ function createSession({
|
|
|
1463
1470
|
|
|
1464
1471
|
/*
|
|
1465
1472
|
* The Claude conversation this session currently embodies. Seeded from the
|
|
1466
|
-
* resume state and updated from
|
|
1467
|
-
* may fork a new id, so the latest observation is the one a later
|
|
1473
|
+
* resume state and updated from init raw events and `finish` metadata. Each
|
|
1474
|
+
* turn may fork a new id, so the latest observation is the one a later
|
|
1468
1475
|
* stop/detach must record for exact resume.
|
|
1469
1476
|
*/
|
|
1470
1477
|
let lastClaudeSessionId = resumeSessionId;
|
|
@@ -1614,7 +1621,6 @@ function createSession({
|
|
|
1614
1621
|
'tool-result',
|
|
1615
1622
|
'finish-step',
|
|
1616
1623
|
'compaction',
|
|
1617
|
-
'raw',
|
|
1618
1624
|
] as const;
|
|
1619
1625
|
for (const type of eventTypes) {
|
|
1620
1626
|
unsubs.push(
|
|
@@ -1624,6 +1630,29 @@ function createSession({
|
|
|
1624
1630
|
}),
|
|
1625
1631
|
);
|
|
1626
1632
|
}
|
|
1633
|
+
unsubs.push(
|
|
1634
|
+
channel.on('raw', msg => {
|
|
1635
|
+
if (!belongsToTurn(msg)) return;
|
|
1636
|
+
const rawValue = (msg as { rawValue?: unknown }).rawValue;
|
|
1637
|
+
if (
|
|
1638
|
+
rawValue != null &&
|
|
1639
|
+
typeof rawValue === 'object' &&
|
|
1640
|
+
!Array.isArray(rawValue)
|
|
1641
|
+
) {
|
|
1642
|
+
const raw = rawValue as Record<string, unknown>;
|
|
1643
|
+
const sessionId = raw.sessionId;
|
|
1644
|
+
if (
|
|
1645
|
+
raw.type === 'system' &&
|
|
1646
|
+
raw.subtype === 'init' &&
|
|
1647
|
+
typeof sessionId === 'string' &&
|
|
1648
|
+
sessionId.length > 0
|
|
1649
|
+
) {
|
|
1650
|
+
lastClaudeSessionId = sessionId;
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
forward(msg);
|
|
1654
|
+
}),
|
|
1655
|
+
);
|
|
1627
1656
|
unsubs.push(
|
|
1628
1657
|
channel.on('finish', msg => {
|
|
1629
1658
|
if (!belongsToTurn(msg)) return;
|