@ai-sdk/harness-claude-code 1.0.181 → 1.0.183
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 +21 -0
- package/dist/bridge/index.mjs +72 -9
- package/dist/bridge/index.mjs.map +1 -1
- package/dist/bridge/package.json +3 -3
- package/dist/bridge/pnpm-lockfile.yaml +146 -141
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -17
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/bridge/index.ts +1 -1
- package/src/bridge/package.json +3 -3
- package/src/claude-code-harness.ts +23 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @ai-sdk/harness-claude-code
|
|
2
2
|
|
|
3
|
+
## 1.0.183
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0fc1f13: chore(harness): update harness adapter underlying SDKs to their latest releases
|
|
8
|
+
- c849d37: feat(harness): use public-key cryptography instead of token for sandbox bridge communication
|
|
9
|
+
- fcd763a: fix(harness-claude-code): fix incorrect low-level property being passed to Claude Agent SDK
|
|
10
|
+
- Updated dependencies [c849d37]
|
|
11
|
+
- Updated dependencies [7f1c01e]
|
|
12
|
+
- Updated dependencies [88b9575]
|
|
13
|
+
- @ai-sdk/harness@1.0.179
|
|
14
|
+
- @ai-sdk/provider-utils@5.0.78
|
|
15
|
+
|
|
16
|
+
## 1.0.182
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Updated dependencies [9f37b45]
|
|
21
|
+
- @ai-sdk/provider-utils@5.0.77
|
|
22
|
+
- @ai-sdk/harness@1.0.178
|
|
23
|
+
|
|
3
24
|
## 1.0.181
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
package/dist/bridge/index.mjs
CHANGED
|
@@ -1,14 +1,76 @@
|
|
|
1
1
|
import { appendFile, lstat, mkdir, realpath, writeFile } from "node:fs/promises";
|
|
2
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
-
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { createPublicKey, randomBytes, randomUUID, verify } from "node:crypto";
|
|
4
4
|
import { argv, env, pid, stdout } from "node:process";
|
|
5
5
|
import { WebSocketServer } from "ws";
|
|
6
|
+
import { Buffer as Buffer$1 } from "node:buffer";
|
|
6
7
|
import * as claudeAgentSdk from "@anthropic-ai/claude-agent-sdk";
|
|
7
8
|
import * as mcpServerModule from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
8
9
|
import { isDeepStrictEqual } from "node:util";
|
|
9
10
|
import { z } from "zod/v4";
|
|
10
11
|
import path from "node:path";
|
|
11
12
|
//#region ../harness/dist/bridge/index.js
|
|
13
|
+
const BRIDGE_AUTH_TIMEOUT_MS = 1e4;
|
|
14
|
+
const BRIDGE_AUTH_MESSAGE_PREFIX = "ai-sdk-harness-bridge-auth-v1\0";
|
|
15
|
+
const PROOF_FRAME_REGEXP = /^\{"type":"bridge-auth-proof","signature":"([A-Za-z0-9_-]{86})"\}$/;
|
|
16
|
+
function createBridgeAuthMessage({ challenge }) {
|
|
17
|
+
return Buffer$1.from(`${BRIDGE_AUTH_MESSAGE_PREFIX}${challenge}`, "utf8");
|
|
18
|
+
}
|
|
19
|
+
function serializeBridgeAuthChallengeFrame({ challenge }) {
|
|
20
|
+
return JSON.stringify({
|
|
21
|
+
type: "bridge-auth-challenge",
|
|
22
|
+
challenge
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function parseBridgeAuthProofFrame({ text }) {
|
|
26
|
+
return PROOF_FRAME_REGEXP.exec(text)?.[1];
|
|
27
|
+
}
|
|
28
|
+
const PUBLIC_KEY_REGEXP = /^[A-Za-z0-9_-]{43}$/;
|
|
29
|
+
const UNAUTHORIZED_CLOSE_CODE = 1008;
|
|
30
|
+
const INVALID_PUBLIC_KEY_MESSAGE = "The bridge requires a valid Ed25519 public key for authentication.";
|
|
31
|
+
function parseBridgeAuthPublicKey({ publicKey }) {
|
|
32
|
+
if (publicKey == null || !PUBLIC_KEY_REGEXP.test(publicKey)) throw new Error(INVALID_PUBLIC_KEY_MESSAGE);
|
|
33
|
+
let key;
|
|
34
|
+
try {
|
|
35
|
+
key = createPublicKey({
|
|
36
|
+
key: {
|
|
37
|
+
kty: "OKP",
|
|
38
|
+
crv: "Ed25519",
|
|
39
|
+
x: publicKey
|
|
40
|
+
},
|
|
41
|
+
format: "jwk"
|
|
42
|
+
});
|
|
43
|
+
} catch {
|
|
44
|
+
throw new Error(INVALID_PUBLIC_KEY_MESSAGE);
|
|
45
|
+
}
|
|
46
|
+
if (key.asymmetricKeyType !== "ed25519") throw new Error(INVALID_PUBLIC_KEY_MESSAGE);
|
|
47
|
+
return key;
|
|
48
|
+
}
|
|
49
|
+
function authenticateBridgeConnection({ ws, publicKey, timeoutMs = BRIDGE_AUTH_TIMEOUT_MS, onAuthenticated }) {
|
|
50
|
+
const challenge = randomBytes(32).toString("hex");
|
|
51
|
+
const timeout = setTimeout(() => ws.terminate(), timeoutMs);
|
|
52
|
+
timeout.unref?.();
|
|
53
|
+
const onError = () => {};
|
|
54
|
+
ws.on("error", onError);
|
|
55
|
+
ws.once("close", () => clearTimeout(timeout));
|
|
56
|
+
ws.once("message", (raw, isBinary) => {
|
|
57
|
+
clearTimeout(timeout);
|
|
58
|
+
const text = isBinary ? void 0 : rawDataToString(raw);
|
|
59
|
+
const signature = text == null ? void 0 : parseBridgeAuthProofFrame({ text });
|
|
60
|
+
if (signature == null || !verify(null, createBridgeAuthMessage({ challenge }), publicKey, Buffer$1.from(signature, "base64url"))) {
|
|
61
|
+
ws.close(UNAUTHORIZED_CLOSE_CODE, "unauthorized");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
ws.off("error", onError);
|
|
65
|
+
onAuthenticated();
|
|
66
|
+
});
|
|
67
|
+
ws.send(serializeBridgeAuthChallengeFrame({ challenge }));
|
|
68
|
+
}
|
|
69
|
+
function rawDataToString(raw) {
|
|
70
|
+
const buffer = Array.isArray(raw) ? Buffer$1.concat(raw) : Buffer$1.isBuffer(raw) ? raw : Buffer$1.from(raw);
|
|
71
|
+
if (buffer.byteLength > 1024) return void 0;
|
|
72
|
+
return buffer.toString("utf8");
|
|
73
|
+
}
|
|
12
74
|
const name = "AI_HarnessBridgeCapabilityUnsupportedError";
|
|
13
75
|
/**
|
|
14
76
|
* Signals an unsupported capability discovered inside a sandbox bridge.
|
|
@@ -207,7 +269,7 @@ async function runBridge(options) {
|
|
|
207
269
|
clearTimeout(hostDisconnectTimer);
|
|
208
270
|
hostDisconnectTimer = void 0;
|
|
209
271
|
};
|
|
210
|
-
const
|
|
272
|
+
const authPublicKey = parseBridgeAuthPublicKey({ publicKey: options.publicKey ?? env["BRIDGE_AUTH_PUBLIC_KEY"] });
|
|
211
273
|
const bridgeWsPort = options.port ?? parseInt(env.BRIDGE_WS_PORT ?? "0", 10);
|
|
212
274
|
const bridgeMetaPath = `${bridgeStateDir}/bridge-meta.json`;
|
|
213
275
|
const startConfigPath = `${bridgeStateDir}/start-config.json`;
|
|
@@ -588,11 +650,12 @@ async function runBridge(options) {
|
|
|
588
650
|
}) + "\n");
|
|
589
651
|
options.onListening?.(currentBoundPort);
|
|
590
652
|
});
|
|
591
|
-
wss.on("connection", (ws
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
653
|
+
wss.on("connection", (ws) => authenticateBridgeConnection({
|
|
654
|
+
ws,
|
|
655
|
+
publicKey: authPublicKey,
|
|
656
|
+
onAuthenticated: () => acceptConnection(ws)
|
|
657
|
+
}));
|
|
658
|
+
const acceptConnection = (ws) => {
|
|
596
659
|
sendControl(ws, {
|
|
597
660
|
type: "bridge-hello",
|
|
598
661
|
state: currentTurnState,
|
|
@@ -630,7 +693,7 @@ async function runBridge(options) {
|
|
|
630
693
|
}
|
|
631
694
|
});
|
|
632
695
|
ws.on("error", () => {});
|
|
633
|
-
}
|
|
696
|
+
};
|
|
634
697
|
process.on("uncaughtException", (err) => {
|
|
635
698
|
emitError({
|
|
636
699
|
error: err,
|
|
@@ -2042,7 +2105,7 @@ async function runTurn(start, turn) {
|
|
|
2042
2105
|
mcpServers,
|
|
2043
2106
|
settingSources: ["user"],
|
|
2044
2107
|
cwd: workdir,
|
|
2045
|
-
|
|
2108
|
+
abortController: abortCtl
|
|
2046
2109
|
}
|
|
2047
2110
|
};
|
|
2048
2111
|
let deferredToolUseId = start.deferredToolUseId;
|