@ai-sdk/harness-codex 1.0.165 → 1.0.167
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 +22 -0
- package/README.md +4 -43
- package/dist/bridge/index.mjs +16 -1
- package/dist/bridge/index.mjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -100
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/bridge/codex-app-server-driver.ts +30 -1
- package/src/codex-harness.ts +25 -147
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["SandboxSession"],"sources":["../src/codex-auth.ts","../src/codex-harness.ts","../src/version.ts","../src/index.ts"],"mappings":";;;;;KA8CY,0BAA0B;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["SandboxSession"],"sources":["../src/codex-auth.ts","../src/codex-harness.ts","../src/version.ts","../src/index.ts"],"mappings":";;;;;KA8CY,0BAA0B;;;KCkD1B;WACD,OAAO;;;;;;WAMP,uBAAuB;;;;;;WAMvB,cAAc;;;;;WAKd,aAAa;;;;;WAKb;;;;WAIA;;;;;;;WAOA;;;;;WAKA,eAAe;;WAEf;;;;;;;WAOA,YAAY;;;;;WAKZ,kBAAkB;;cAYvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA8DU,YACd,WAAU,uBACT,iBAAiB;;;qBC/NP;;;;;;;;qBCKA,iCAAK"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import path, { dirname, join, resolve } from "node:path";
|
|
3
3
|
import { HarnessCapabilityUnsupportedError, commonTool, harnessSessionDataDirectoryPath, harnessStateDirectoryPath, harnessV1BridgeInboundCommandSchemas, harnessV1BridgeOutboundMessageSchema, harnessV1BridgeStartBaseSchema, harnessV1DiagnosticFromBridgeFrame } from "@ai-sdk/harness";
|
|
4
|
-
import { SandboxChannel, applyCredentialForwarding, classifyDiskLog, createBridgeErrorHandler, createBridgeStartupError, createBridgeToken, createCredentialRequestTransformation, createReadBridgeAsset, drainBridgeProcessStream, experimental_createBridgeUserMessageSubmitter, extractHarnessPromptContent, forwardBridgeProcessStream, getAiGatewayAuthFromEnv, getJwtExpiresAt, getRestrictedSandboxSession, harnessPromptContentSchema, isAccessTokenExpiringSoon, isHarnessAuthenticationEnvironment, isLinux, isMacOS, isWindows, markBridgeStarting, readLinuxSecretServicePassword, readMacOSKeychainPassword, readWindowsCredentialManagerPassword, refreshOAuthAccessToken, resolveSandboxCredentialEnvironment, resolveSandboxHomeDir, shellQuote, shouldResolveNativeSubscription, waitForBridgeReady, warnCredentialBrokeringUnavailable,
|
|
4
|
+
import { SandboxChannel, applyCredentialForwarding, classifyDiskLog, createBridgeErrorHandler, createBridgeStartupError, createBridgeToken, createBridgeWebSocketConnect, createCredentialRequestTransformation, createReadBridgeAsset, drainBridgeProcessStream, experimental_createBridgeUserMessageSubmitter, extractHarnessPromptContent, forwardBridgeProcessStream, getAiGatewayAuthFromEnv, getJwtExpiresAt, getRestrictedSandboxSession, harnessPromptContentSchema, isAccessTokenExpiringSoon, isHarnessAuthenticationEnvironment, isLinux, isMacOS, isWindows, markBridgeStarting, readLinuxSecretServicePassword, readMacOSKeychainPassword, readWindowsCredentialManagerPassword, refreshOAuthAccessToken, resolveBridgeEndpoint, resolveBridgePort, resolveSandboxCredentialEnvironment, resolveSandboxHomeDir, shellQuote, shouldResolveNativeSubscription, validateBridgeSandboxSettings, waitForBridgeReady, warnCredentialBrokeringUnavailable, writeSkills } from "@ai-sdk/harness/utils";
|
|
5
5
|
import { isRecord, safeParseJSON, tool } from "@ai-sdk/provider-utils";
|
|
6
6
|
import { WebSocket } from "ws";
|
|
7
7
|
import { z } from "zod/v4";
|
|
@@ -399,7 +399,7 @@ const startMessageSchema = harnessV1BridgeStartBaseSchema.extend({
|
|
|
399
399
|
z.discriminatedUnion("type", [startMessageSchema, ...harnessV1BridgeInboundCommandSchemas]);
|
|
400
400
|
//#endregion
|
|
401
401
|
//#region src/version.ts
|
|
402
|
-
const VERSION = "1.0.
|
|
402
|
+
const VERSION = "1.0.167";
|
|
403
403
|
//#endregion
|
|
404
404
|
//#region src/codex-harness.ts
|
|
405
405
|
const DEFAULT_CODEX_MODEL = "gpt-5.5";
|
|
@@ -482,14 +482,12 @@ function createCodex(settings = {}) {
|
|
|
482
482
|
const sandboxSession = startOpts.sandboxSession;
|
|
483
483
|
const toolSafeSandboxSession = getRestrictedSandboxSession(sandboxSession);
|
|
484
484
|
const sandboxId = "id" in sandboxSession ? sandboxSession.id : void 0;
|
|
485
|
-
|
|
485
|
+
validateBridgeSandboxSettings({
|
|
486
486
|
sandboxSession,
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
harnessId: "codex",
|
|
492
|
-
message: "The codex harness cannot use `mintBridgeToken` with a sandbox session that does not expose an id."
|
|
487
|
+
sandboxId,
|
|
488
|
+
portOverride: settings.port,
|
|
489
|
+
portEndpointOverride: settings.portEndpoint,
|
|
490
|
+
mintBridgeToken: settings.mintBridgeToken
|
|
493
491
|
});
|
|
494
492
|
const lifecycleState = startOpts.continueFrom ?? startOpts.resumeFrom;
|
|
495
493
|
const isResume = lifecycleState != null;
|
|
@@ -551,19 +549,16 @@ function createCodex(settings = {}) {
|
|
|
551
549
|
sessionId: startOpts.sessionId
|
|
552
550
|
});
|
|
553
551
|
if (coords) try {
|
|
554
|
-
const
|
|
552
|
+
const attachEndpoint = await resolveBridgeEndpoint({
|
|
555
553
|
sandboxSession,
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
});
|
|
559
|
-
const attachEndpoint = withBridgeToken({
|
|
560
|
-
endpoint,
|
|
554
|
+
port: coords.port,
|
|
555
|
+
portEndpointOverride: settings.portEndpoint,
|
|
561
556
|
token: coords.token
|
|
562
557
|
});
|
|
563
558
|
const attachChannel = new SandboxChannel({
|
|
564
|
-
connect: ({
|
|
565
|
-
|
|
566
|
-
|
|
559
|
+
connect: createBridgeWebSocketConnect({
|
|
560
|
+
endpoint: attachEndpoint,
|
|
561
|
+
webSocketConstructor: WebSocket
|
|
567
562
|
}),
|
|
568
563
|
outboundSchema: outboundMessageSchema,
|
|
569
564
|
initialLastSeenEventId: coords.lastSeenEventId,
|
|
@@ -608,7 +603,7 @@ function createCodex(settings = {}) {
|
|
|
608
603
|
}
|
|
609
604
|
const port = resolveBridgePort({
|
|
610
605
|
sandboxSession,
|
|
611
|
-
|
|
606
|
+
portOverride: settings.port
|
|
612
607
|
});
|
|
613
608
|
const token = settings.mintBridgeToken == null ? createBridgeToken() : settings.mintBridgeToken(sandboxId);
|
|
614
609
|
const forwardedAuthEnvironment = credentialsBrokered ? sandboxAuthEnvironment : await applyCredentialForwarding({
|
|
@@ -673,19 +668,18 @@ function createCodex(settings = {}) {
|
|
|
673
668
|
})
|
|
674
669
|
});
|
|
675
670
|
drainBridgeProcessStream(proc.stdout);
|
|
676
|
-
const
|
|
671
|
+
const bridgeEndpoint = await resolveBridgeEndpoint({
|
|
677
672
|
sandboxSession,
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
});
|
|
681
|
-
const bridgeEndpoint = withBridgeToken({
|
|
682
|
-
endpoint,
|
|
673
|
+
port: boundPort,
|
|
674
|
+
portEndpointOverride: settings.portEndpoint,
|
|
683
675
|
token
|
|
684
676
|
});
|
|
685
677
|
const channel = new SandboxChannel({
|
|
686
|
-
connect: ({
|
|
687
|
-
|
|
688
|
-
|
|
678
|
+
connect: createBridgeWebSocketConnect({
|
|
679
|
+
endpoint: bridgeEndpoint,
|
|
680
|
+
webSocketConstructor: WebSocket,
|
|
681
|
+
openRetryTimeoutMs: timeoutMs,
|
|
682
|
+
startAbortSignal: startOpts.abortSignal
|
|
689
683
|
}),
|
|
690
684
|
outboundSchema: outboundMessageSchema,
|
|
691
685
|
onDiagnostic,
|
|
@@ -722,78 +716,6 @@ function createCodex(settings = {}) {
|
|
|
722
716
|
}
|
|
723
717
|
};
|
|
724
718
|
}
|
|
725
|
-
function resolveBridgePort({ sandboxSession, override }) {
|
|
726
|
-
if (override !== void 0) return override;
|
|
727
|
-
if ("ports" in sandboxSession && sandboxSession.ports.length > 0) return sandboxSession.ports[0];
|
|
728
|
-
throw new HarnessCapabilityUnsupportedError({
|
|
729
|
-
harnessId: "codex",
|
|
730
|
-
message: "The codex harness needs a TCP port exposed by the sandbox. Create the sandbox with `ports: [<port>]` or pass `createCodex({ port })`."
|
|
731
|
-
});
|
|
732
|
-
}
|
|
733
|
-
function validateBasicSandboxSettings({ sandboxSession, port, portEndpoint }) {
|
|
734
|
-
if ("getPortEndpoint" in sandboxSession) return;
|
|
735
|
-
if (port == null) throw new HarnessCapabilityUnsupportedError({
|
|
736
|
-
harnessId: "codex",
|
|
737
|
-
message: "The codex harness requires an explicit `port` when using a basic sandbox session."
|
|
738
|
-
});
|
|
739
|
-
if (portEndpoint == null) throw new HarnessCapabilityUnsupportedError({
|
|
740
|
-
harnessId: "codex",
|
|
741
|
-
message: "The codex harness requires an explicit `portEndpoint` when using a basic sandbox session."
|
|
742
|
-
});
|
|
743
|
-
}
|
|
744
|
-
async function resolveBridgeEndpoint({ sandboxSession, override, port }) {
|
|
745
|
-
if (override != null) return override;
|
|
746
|
-
if ("getPortEndpoint" in sandboxSession) return sandboxSession.getPortEndpoint({
|
|
747
|
-
port,
|
|
748
|
-
protocol: "ws"
|
|
749
|
-
});
|
|
750
|
-
throw new HarnessCapabilityUnsupportedError({
|
|
751
|
-
harnessId: "codex",
|
|
752
|
-
message: "The codex harness requires an explicit `portEndpoint` when using a basic sandbox session."
|
|
753
|
-
});
|
|
754
|
-
}
|
|
755
|
-
function openWebSocket({ url, headers, abortSignal }) {
|
|
756
|
-
return new Promise((resolve, reject) => {
|
|
757
|
-
if (abortSignal.aborted) {
|
|
758
|
-
reject(abortSignal.reason ?? /* @__PURE__ */ new Error("WebSocket connection aborted"));
|
|
759
|
-
return;
|
|
760
|
-
}
|
|
761
|
-
const ws = new WebSocket(url, { headers: headers == null ? void 0 : { ...headers } });
|
|
762
|
-
let settled = false;
|
|
763
|
-
const cleanup = () => {
|
|
764
|
-
abortSignal.removeEventListener("abort", onAbort);
|
|
765
|
-
ws.off("open", onOpen);
|
|
766
|
-
ws.off("error", onError);
|
|
767
|
-
};
|
|
768
|
-
const rejectWithCleanup = (error) => {
|
|
769
|
-
if (settled) return;
|
|
770
|
-
settled = true;
|
|
771
|
-
cleanup();
|
|
772
|
-
ws.once("error", () => {});
|
|
773
|
-
try {
|
|
774
|
-
ws.terminate();
|
|
775
|
-
} catch {
|
|
776
|
-
try {
|
|
777
|
-
ws.close();
|
|
778
|
-
} catch {}
|
|
779
|
-
}
|
|
780
|
-
reject(error);
|
|
781
|
-
};
|
|
782
|
-
const onOpen = () => {
|
|
783
|
-
if (settled) return;
|
|
784
|
-
settled = true;
|
|
785
|
-
cleanup();
|
|
786
|
-
resolve(ws);
|
|
787
|
-
};
|
|
788
|
-
const onError = (err) => {
|
|
789
|
-
rejectWithCleanup(err);
|
|
790
|
-
};
|
|
791
|
-
const onAbort = () => rejectWithCleanup(abortSignal.reason ?? /* @__PURE__ */ new Error("WebSocket connection aborted"));
|
|
792
|
-
ws.once("open", onOpen);
|
|
793
|
-
ws.once("error", onError);
|
|
794
|
-
abortSignal.addEventListener("abort", onAbort, { once: true });
|
|
795
|
-
});
|
|
796
|
-
}
|
|
797
719
|
function createSession({ sessionId, channel, proc, model, reasoningEffort, webSearch, builtinToolFiltering, codexConfig, mcpServers, headers, resumeThreadId, isResume, seedResumeThreadOnFirstPrompt, rerunContinue, bridgePort, bridgeToken, sandboxId, sandboxCredentialEnvironment, debug, permissionMode, sandbox, sandboxHomeDir, turnConfigurationFingerprint }) {
|
|
798
720
|
let stopped = false;
|
|
799
721
|
let stopPromise;
|