@ai-sdk/harness-codex 1.0.178 → 1.0.181
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 +26 -0
- package/dist/bridge/index.mjs +84 -13
- package/dist/bridge/index.mjs.map +1 -1
- package/dist/bridge/package.json +1 -1
- package/dist/bridge/pnpm-lockfile.yaml +30 -30
- 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 +4 -4
- package/src/bridge/codex-app-server-driver.ts +41 -6
- package/src/bridge/codex-tool-filtering-hook.ts +2 -2
- package/src/bridge/index.ts +0 -1
- package/src/bridge/package.json +1 -1
- package/src/codex-harness.ts +22 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @ai-sdk/harness-codex
|
|
2
2
|
|
|
3
|
+
## 1.0.181
|
|
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
|
+
- Updated dependencies [c849d37]
|
|
10
|
+
- Updated dependencies [7f1c01e]
|
|
11
|
+
- Updated dependencies [88b9575]
|
|
12
|
+
- @ai-sdk/harness@1.0.179
|
|
13
|
+
- @ai-sdk/provider-utils@5.0.78
|
|
14
|
+
|
|
15
|
+
## 1.0.180
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [9f37b45]
|
|
20
|
+
- @ai-sdk/provider-utils@5.0.77
|
|
21
|
+
- @ai-sdk/harness@1.0.178
|
|
22
|
+
|
|
23
|
+
## 1.0.179
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- @ai-sdk/harness@1.0.177
|
|
28
|
+
|
|
3
29
|
## 1.0.178
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
package/dist/bridge/index.mjs
CHANGED
|
@@ -1,13 +1,75 @@
|
|
|
1
1
|
import { appendFile, mkdir, writeFile } from "node:fs/promises";
|
|
2
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
3
|
+
import { createHash, 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 { fileURLToPath } from "node:url";
|
|
7
8
|
import { spawn } from "node:child_process";
|
|
8
9
|
import { isDeepStrictEqual } from "node:util";
|
|
9
10
|
import path from "node:path";
|
|
10
11
|
//#region ../harness/dist/bridge/index.js
|
|
12
|
+
const BRIDGE_AUTH_TIMEOUT_MS = 1e4;
|
|
13
|
+
const BRIDGE_AUTH_MESSAGE_PREFIX = "ai-sdk-harness-bridge-auth-v1\0";
|
|
14
|
+
const PROOF_FRAME_REGEXP = /^\{"type":"bridge-auth-proof","signature":"([A-Za-z0-9_-]{86})"\}$/;
|
|
15
|
+
function createBridgeAuthMessage({ challenge }) {
|
|
16
|
+
return Buffer$1.from(`${BRIDGE_AUTH_MESSAGE_PREFIX}${challenge}`, "utf8");
|
|
17
|
+
}
|
|
18
|
+
function serializeBridgeAuthChallengeFrame({ challenge }) {
|
|
19
|
+
return JSON.stringify({
|
|
20
|
+
type: "bridge-auth-challenge",
|
|
21
|
+
challenge
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function parseBridgeAuthProofFrame({ text }) {
|
|
25
|
+
return PROOF_FRAME_REGEXP.exec(text)?.[1];
|
|
26
|
+
}
|
|
27
|
+
const PUBLIC_KEY_REGEXP = /^[A-Za-z0-9_-]{43}$/;
|
|
28
|
+
const UNAUTHORIZED_CLOSE_CODE = 1008;
|
|
29
|
+
const INVALID_PUBLIC_KEY_MESSAGE = "The bridge requires a valid Ed25519 public key for authentication.";
|
|
30
|
+
function parseBridgeAuthPublicKey({ publicKey }) {
|
|
31
|
+
if (publicKey == null || !PUBLIC_KEY_REGEXP.test(publicKey)) throw new Error(INVALID_PUBLIC_KEY_MESSAGE);
|
|
32
|
+
let key;
|
|
33
|
+
try {
|
|
34
|
+
key = createPublicKey({
|
|
35
|
+
key: {
|
|
36
|
+
kty: "OKP",
|
|
37
|
+
crv: "Ed25519",
|
|
38
|
+
x: publicKey
|
|
39
|
+
},
|
|
40
|
+
format: "jwk"
|
|
41
|
+
});
|
|
42
|
+
} catch {
|
|
43
|
+
throw new Error(INVALID_PUBLIC_KEY_MESSAGE);
|
|
44
|
+
}
|
|
45
|
+
if (key.asymmetricKeyType !== "ed25519") throw new Error(INVALID_PUBLIC_KEY_MESSAGE);
|
|
46
|
+
return key;
|
|
47
|
+
}
|
|
48
|
+
function authenticateBridgeConnection({ ws, publicKey, timeoutMs = BRIDGE_AUTH_TIMEOUT_MS, onAuthenticated }) {
|
|
49
|
+
const challenge = randomBytes(32).toString("hex");
|
|
50
|
+
const timeout = setTimeout(() => ws.terminate(), timeoutMs);
|
|
51
|
+
timeout.unref?.();
|
|
52
|
+
const onError = () => {};
|
|
53
|
+
ws.on("error", onError);
|
|
54
|
+
ws.once("close", () => clearTimeout(timeout));
|
|
55
|
+
ws.once("message", (raw, isBinary) => {
|
|
56
|
+
clearTimeout(timeout);
|
|
57
|
+
const text = isBinary ? void 0 : rawDataToString(raw);
|
|
58
|
+
const signature = text == null ? void 0 : parseBridgeAuthProofFrame({ text });
|
|
59
|
+
if (signature == null || !verify(null, createBridgeAuthMessage({ challenge }), publicKey, Buffer$1.from(signature, "base64url"))) {
|
|
60
|
+
ws.close(UNAUTHORIZED_CLOSE_CODE, "unauthorized");
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
ws.off("error", onError);
|
|
64
|
+
onAuthenticated();
|
|
65
|
+
});
|
|
66
|
+
ws.send(serializeBridgeAuthChallengeFrame({ challenge }));
|
|
67
|
+
}
|
|
68
|
+
function rawDataToString(raw) {
|
|
69
|
+
const buffer = Array.isArray(raw) ? Buffer$1.concat(raw) : Buffer$1.isBuffer(raw) ? raw : Buffer$1.from(raw);
|
|
70
|
+
if (buffer.byteLength > 1024) return void 0;
|
|
71
|
+
return buffer.toString("utf8");
|
|
72
|
+
}
|
|
11
73
|
const name = "AI_HarnessBridgeCapabilityUnsupportedError";
|
|
12
74
|
/**
|
|
13
75
|
* Signals an unsupported capability discovered inside a sandbox bridge.
|
|
@@ -206,7 +268,7 @@ async function runBridge(options) {
|
|
|
206
268
|
clearTimeout(hostDisconnectTimer);
|
|
207
269
|
hostDisconnectTimer = void 0;
|
|
208
270
|
};
|
|
209
|
-
const
|
|
271
|
+
const authPublicKey = parseBridgeAuthPublicKey({ publicKey: options.publicKey ?? env["BRIDGE_AUTH_PUBLIC_KEY"] });
|
|
210
272
|
const bridgeWsPort = options.port ?? parseInt(env.BRIDGE_WS_PORT ?? "0", 10);
|
|
211
273
|
const bridgeMetaPath = `${bridgeStateDir}/bridge-meta.json`;
|
|
212
274
|
const startConfigPath = `${bridgeStateDir}/start-config.json`;
|
|
@@ -587,11 +649,12 @@ async function runBridge(options) {
|
|
|
587
649
|
}) + "\n");
|
|
588
650
|
options.onListening?.(currentBoundPort);
|
|
589
651
|
});
|
|
590
|
-
wss.on("connection", (ws
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
652
|
+
wss.on("connection", (ws) => authenticateBridgeConnection({
|
|
653
|
+
ws,
|
|
654
|
+
publicKey: authPublicKey,
|
|
655
|
+
onAuthenticated: () => acceptConnection(ws)
|
|
656
|
+
}));
|
|
657
|
+
const acceptConnection = (ws) => {
|
|
595
658
|
sendControl(ws, {
|
|
596
659
|
type: "bridge-hello",
|
|
597
660
|
state: currentTurnState,
|
|
@@ -629,7 +692,7 @@ async function runBridge(options) {
|
|
|
629
692
|
}
|
|
630
693
|
});
|
|
631
694
|
ws.on("error", () => {});
|
|
632
|
-
}
|
|
695
|
+
};
|
|
633
696
|
process.on("uncaughtException", (err) => {
|
|
634
697
|
emitError({
|
|
635
698
|
error: err,
|
|
@@ -1359,7 +1422,7 @@ function toTomlInline(value) {
|
|
|
1359
1422
|
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
|
1360
1423
|
if (Array.isArray(value)) return `[${value.map(toTomlInline).join(",")}]`;
|
|
1361
1424
|
if (value != null && typeof value === "object") return `{${Object.entries(value).filter(([, item]) => item !== void 0).map(([key, item]) => `${JSON.stringify(key)}=${toTomlInline(item)}`).join(",")}}`;
|
|
1362
|
-
throw new Error("Codex
|
|
1425
|
+
throw new Error("Codex configuration contains an unsupported value.");
|
|
1363
1426
|
}
|
|
1364
1427
|
function asRecord$1(value) {
|
|
1365
1428
|
return value != null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
@@ -1382,7 +1445,8 @@ function createCodexAppServerRuntime() {
|
|
|
1382
1445
|
await previous?.close();
|
|
1383
1446
|
};
|
|
1384
1447
|
const runTurn = async (options) => {
|
|
1385
|
-
const { start, turn, emit, workdir, threadId, codexModel
|
|
1448
|
+
const { start, turn, emit, workdir, threadId, codexModel } = options;
|
|
1449
|
+
const { codexConfig, providerCliOverrides } = splitModelProviderConfig(options.codexConfig);
|
|
1386
1450
|
if (activeTurn != null) throw new Error("A Codex turn is already active.");
|
|
1387
1451
|
const toolPolicy = resolveCodexBuiltinToolPolicy({
|
|
1388
1452
|
builtinToolFiltering: start.builtinToolFiltering,
|
|
@@ -1398,9 +1462,10 @@ function createCodexAppServerRuntime() {
|
|
|
1398
1462
|
...toolPolicy.disabled.view_image ? { view_image: false } : {}
|
|
1399
1463
|
} } : {}
|
|
1400
1464
|
};
|
|
1465
|
+
const cliOverrides = [...providerCliOverrides, ...trustedHook?.cliOverrides ?? []];
|
|
1401
1466
|
const processConfig = {
|
|
1402
1467
|
thread: nextConfig,
|
|
1403
|
-
cliOverrides
|
|
1468
|
+
cliOverrides
|
|
1404
1469
|
};
|
|
1405
1470
|
if (client != null && !isDeepStrictEqual(loadedConfig, processConfig)) await close();
|
|
1406
1471
|
const handler = createAppServerEventHandler({
|
|
@@ -1427,7 +1492,7 @@ function createCodexAppServerRuntime() {
|
|
|
1427
1492
|
if (client == null) {
|
|
1428
1493
|
const created = new CodexAppServerClient({
|
|
1429
1494
|
executable: process.execPath,
|
|
1430
|
-
args: createCodexAppServerArgs({ cliOverrides
|
|
1495
|
+
args: createCodexAppServerArgs({ cliOverrides }),
|
|
1431
1496
|
cwd: workdir,
|
|
1432
1497
|
env: process.env,
|
|
1433
1498
|
onNotification: (notification) => {
|
|
@@ -1649,6 +1714,13 @@ function createCodexAppServerArgs({ cliOverrides = [] } = {}) {
|
|
|
1649
1714
|
"--stdio"
|
|
1650
1715
|
];
|
|
1651
1716
|
}
|
|
1717
|
+
function splitModelProviderConfig(codexConfig) {
|
|
1718
|
+
const { model_provider: modelProvider, model_providers: modelProviders, ...threadConfig } = codexConfig;
|
|
1719
|
+
return {
|
|
1720
|
+
codexConfig: threadConfig,
|
|
1721
|
+
providerCliOverrides: [...modelProvider === void 0 ? [] : [`model_provider=${toTomlInline(modelProvider)}`], ...modelProviders === void 0 ? [] : [`model_providers=${toTomlInline(modelProviders)}`]]
|
|
1722
|
+
};
|
|
1723
|
+
}
|
|
1652
1724
|
function createThreadParams({ start, workdir, codexModel, codexConfig }) {
|
|
1653
1725
|
return {
|
|
1654
1726
|
...codexModel == null ? {} : { model: codexModel },
|
|
@@ -2212,7 +2284,6 @@ function resolveCodexRuntime({ start }) {
|
|
|
2212
2284
|
developer_instructions: [start.instructions, "Only respond with your `final` message once you have fully addressed the user request."].filter((instruction) => Boolean(instruction)).join("\n\n")
|
|
2213
2285
|
};
|
|
2214
2286
|
if (apiBaseUrl) {
|
|
2215
|
-
codexConfig.preferred_auth_method = "apikey";
|
|
2216
2287
|
codexConfig.model_provider = "agent_bridge_openai";
|
|
2217
2288
|
codexConfig.model_providers = { agent_bridge_openai: {
|
|
2218
2289
|
name: env.CODEX_MODEL_PROVIDER_NAME || "Agent Bridge OpenAI",
|