@openclaw/codex 2026.7.2-beta.1 → 2026.7.2-beta.3
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/README.md +1 -1
- package/dist/{app-server-policy-DVcxdse_.js → app-server-policy-DUMF2Xyr.js} +1 -1
- package/dist/{attempt-notifications-DEv9h7iC.js → attempt-notifications-Ecjyzufe.js} +3 -6
- package/dist/cli-metadata.js +1 -1
- package/dist/{command-formatters-D6ZlGNmb.js → command-formatters-NCTL7A2q.js} +38 -3
- package/dist/{command-handlers-Cpl9fUWv.js → command-handlers-DtFbZiba.js} +70 -15
- package/dist/{compact-FnJmiPNA.js → compact-Kgy26gIM.js} +4 -5
- package/dist/{computer-use-DVzr8OP1.js → computer-use-C7x4ZaqR.js} +4 -4
- package/dist/{conversation-control-DtQ-E7mr.js → conversation-control-B0s3aIjT.js} +5 -7
- package/dist/doctor-contract-api.js +1 -1
- package/dist/{dynamic-tools-BMLoaTeG.js → dynamic-tools-D_vSVmv9.js} +851 -434
- package/dist/harness.js +11 -6
- package/dist/index.js +52 -31
- package/dist/{media-understanding-provider-D580L0P8.js → media-understanding-provider-IPNNQre6.js} +11 -12
- package/dist/media-understanding-provider.js +1 -1
- package/dist/{models-DuKzZA6G.js → models-DD5zBdX5.js} +5 -9
- package/dist/{notification-correlation-DfaCm0mx.js → notification-correlation-C8DVQ_Bq.js} +3 -3
- package/dist/{plugin-app-cache-key-BKNjHMEs.js → plugin-app-cache-key-DJbhLYSK.js} +2 -2
- package/dist/{rate-limits-Dhp04Rqo.js → rate-limits-CqhWQ2R9.js} +9 -6
- package/dist/{request-DborTWgw.js → request-9yf9pZjf.js} +54 -8
- package/dist/{run-attempt-VPVJoYDP.js → run-attempt-BIoO8ISr.js} +637 -351
- package/dist/{config-c48K5HP9.js → session-binding-Bmt20HfB.js} +788 -3
- package/dist/{session-catalog-7H112Tr_.js → session-catalog-CA7R-hX2.js} +82 -45
- package/dist/{session-cli-B28RhCyp.js → session-cli-Bxk3-Wqz.js} +2 -2
- package/dist/{shared-client-D4mFI9al.js → shared-client-CSXLtCLE.js} +304 -81
- package/dist/{side-question-CgJBz52s.js → side-question-DtzquMOb.js} +15 -13
- package/dist/{thread-lifecycle-BgLXzjvV.js → thread-lifecycle-CQ_9mAa1.js} +1821 -1582
- package/dist/{protocol-validators-dZQ-UTOa.js → transcript-mirror-D9rTxx2P.js} +485 -2
- package/dist/usage-CuPpFgTc.js +25 -0
- package/dist/{web-search-provider.runtime-Bs-eTn5U.js → web-search-provider.runtime-_x5XTeqh.js} +3 -3
- package/npm-shrinkwrap.json +30 -30
- package/openclaw.plugin.json +21 -6
- package/package.json +6 -6
- package/dist/capabilities-42Dfn2TV.js +0 -33
- package/dist/prompt-overlay.js +0 -15
- package/dist/protocol-BMifTfdW.js +0 -15
- package/dist/provider-catalog.js +0 -118
- package/dist/provider-discovery.js +0 -34
- package/dist/provider.js +0 -307
- package/dist/session-binding-BMfX1OX-.js +0 -786
- package/dist/transcript-mirror-DhLwFIL4.js +0 -485
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
|
|
2
|
-
import { a as
|
|
3
|
-
import { a as codexAppServerStartOptionsKey, f as resolveCodexAppServerRuntimeOptions, h as resolveCodexComputerUseConfig, m as resolveCodexAppServerUserHomeDir, p as resolveCodexAppServerStartOptionsForAgent } from "./config-c48K5HP9.js";
|
|
2
|
+
import { C as resolveCodexComputerUseConfig, S as resolveCodexAppServerUserHomeDir, a as isCodexAppServerNativeAuthProfile, b as resolveCodexAppServerRuntimeOptions, m as codexAppServerStartOptionsKey, x as resolveCodexAppServerStartOptionsForAgent } from "./session-binding-Bmt20HfB.js";
|
|
4
3
|
import { n as resolveCodexAppServerSpawnEnv, t as createStdioTransport } from "./transport-stdio-DXgGZ7Ib.js";
|
|
5
|
-
import { a as isCodexAppServerNativeAuthProfile } from "./session-binding-BMfX1OX-.js";
|
|
6
4
|
import { createRequire } from "node:module";
|
|
7
5
|
import fs, { access } from "node:fs/promises";
|
|
8
6
|
import path from "node:path";
|
|
9
|
-
import {
|
|
7
|
+
import { addTimerTimeoutGraceMs, resolveTimerTimeoutMs } from "openclaw/plugin-sdk/number-runtime";
|
|
8
|
+
import { sliceUtf16Safe, truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
|
|
10
9
|
import { createHash, randomUUID } from "node:crypto";
|
|
11
10
|
import fsSync, { constants, existsSync, readFileSync, realpathSync } from "node:fs";
|
|
12
11
|
import os from "node:os";
|
|
@@ -24,6 +23,21 @@ import { hasUsableOAuthCredential } from "openclaw/plugin-sdk/provider-auth";
|
|
|
24
23
|
import { fileURLToPath } from "node:url";
|
|
25
24
|
import { expectDefined } from "openclaw/plugin-sdk/expect-runtime";
|
|
26
25
|
import { withTimeout } from "openclaw/plugin-sdk/security-runtime";
|
|
26
|
+
//#region extensions/codex/src/app-server/protocol.ts
|
|
27
|
+
/** Namespace Codex keeps directly model-visible without exposing it to Code Mode guests. */
|
|
28
|
+
const CODEX_OPENCLAW_DIRECT_DYNAMIC_TOOL_NAMESPACE = "openclaw_direct";
|
|
29
|
+
function flattenCodexDynamicToolFunctions(tools) {
|
|
30
|
+
return (tools ?? []).flatMap((tool) => tool.type === "namespace" ? tool.tools : [tool]);
|
|
31
|
+
}
|
|
32
|
+
const CODEX_INTERACTIVE_THREAD_SOURCE_KINDS = ["cli", "vscode"];
|
|
33
|
+
const CODEX_INTERACTIVE_CUSTOM_THREAD_SOURCES = ["atlas", "chatgpt"];
|
|
34
|
+
function isJsonObject$1(value) {
|
|
35
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
36
|
+
}
|
|
37
|
+
function isRpcResponse(message) {
|
|
38
|
+
return "id" in message && !("method" in message);
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
27
41
|
//#region extensions/codex/src/app-server/transport-websocket.ts
|
|
28
42
|
/**
|
|
29
43
|
* Adapts a remote Codex app-server WebSocket endpoint to the shared stdio-like
|
|
@@ -177,6 +191,8 @@ function signalCodexAppServerTransport(child, signal) {
|
|
|
177
191
|
*/
|
|
178
192
|
/** Minimum Codex app-server version supported by the OpenClaw Codex bridge. */
|
|
179
193
|
const MIN_CODEX_APP_SERVER_VERSION = "0.143.0";
|
|
194
|
+
/** Newest Codex app-server version validated by the OpenClaw Codex bridge. */
|
|
195
|
+
const MAX_CODEX_APP_SERVER_VERSION = "0.144.6";
|
|
180
196
|
/** npm package name for the managed Codex app-server binary. */
|
|
181
197
|
const MANAGED_CODEX_APP_SERVER_PACKAGE = "@openai/codex";
|
|
182
198
|
//#endregion
|
|
@@ -191,6 +207,9 @@ const CODEX_APP_SERVER_PARSE_BUFFER_MAX = 8 * 1024 * 1024;
|
|
|
191
207
|
const CODEX_APP_SERVER_PARSE_BUFFER_MAX_LINES = 1e3;
|
|
192
208
|
const CODEX_DYNAMIC_TOOL_SERVER_REQUEST_TIMEOUT_MS = 6e5;
|
|
193
209
|
const CODEX_APP_SERVER_STDERR_TAIL_MAX = 2e3;
|
|
210
|
+
const CODEX_APP_SERVER_OVERLOADED_ERROR_CODE = -32001;
|
|
211
|
+
const CODEX_APP_SERVER_OVERLOAD_MAX_RETRIES = 3;
|
|
212
|
+
const CODEX_APP_SERVER_OVERLOAD_RETRY_BASE_MS = 50;
|
|
194
213
|
const CODEX_APP_SERVER_CLIENT_INSTANCE_IDS = /* @__PURE__ */ new WeakMap();
|
|
195
214
|
const UNPAIRED_SURROGATE_RE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;
|
|
196
215
|
/** Process-local generation fence for bindings tied to one app-server client instance. */
|
|
@@ -208,16 +227,31 @@ var CodexAppServerRpcError = class extends Error {
|
|
|
208
227
|
this.name = "CodexAppServerRpcError";
|
|
209
228
|
this.code = error.code;
|
|
210
229
|
this.data = error.data;
|
|
230
|
+
this.method = method;
|
|
211
231
|
}
|
|
212
232
|
};
|
|
213
233
|
var CodexAppServerLocalRequestCancellationError = class extends Error {
|
|
214
234
|
constructor(method, reason, mayHaveWritten) {
|
|
215
235
|
super(`${method} ${reason}`);
|
|
236
|
+
this.reason = reason;
|
|
216
237
|
this.mayHaveWritten = mayHaveWritten;
|
|
217
238
|
this.code = "CODEX_APP_SERVER_LOCAL_REQUEST_CANCELLED";
|
|
218
239
|
this.name = "CodexAppServerLocalRequestCancellationError";
|
|
219
240
|
}
|
|
220
241
|
};
|
|
242
|
+
function isCodexAppServerRequestTimeoutError(error) {
|
|
243
|
+
return error instanceof Error && "code" in error && error.code === "CODEX_APP_SERVER_LOCAL_REQUEST_CANCELLED" && "reason" in error && error.reason === "timed out";
|
|
244
|
+
}
|
|
245
|
+
function isCodexAppServerBrokenPipeError(error) {
|
|
246
|
+
const seen = /* @__PURE__ */ new Set();
|
|
247
|
+
let current = error;
|
|
248
|
+
while (current && typeof current === "object" && !seen.has(current)) {
|
|
249
|
+
seen.add(current);
|
|
250
|
+
if ("code" in current && current.code === "EPIPE") return true;
|
|
251
|
+
current = "cause" in current ? current.cause : void 0;
|
|
252
|
+
}
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
221
255
|
var CodexAppServerIndeterminateTransportError = class extends Error {
|
|
222
256
|
constructor(method, cause) {
|
|
223
257
|
super(`${method} transport failed after request write: ${cause.message}`, { cause });
|
|
@@ -278,8 +312,8 @@ var CodexAppServerClient = class CodexAppServerClient {
|
|
|
278
312
|
this.lines.on("line", (line) => this.handleLine(line));
|
|
279
313
|
this.lines.on("error", (error) => this.closeWithError(error instanceof Error ? error : new Error(String(error))));
|
|
280
314
|
child.stdout.on("error", (error) => this.closeWithError(error instanceof Error ? error : new Error(String(error))));
|
|
281
|
-
child.stderr.
|
|
282
|
-
|
|
315
|
+
child.stderr.setEncoding("utf8");
|
|
316
|
+
child.stderr.on("data", (text) => {
|
|
283
317
|
this.stderrTail = appendBoundedTail(this.stderrTail, text, CODEX_APP_SERVER_STDERR_TAIL_MAX);
|
|
284
318
|
const trimmed = text.trim();
|
|
285
319
|
if (trimmed) embeddedAgentLog.debug(`codex app-server stderr: ${trimmed}`);
|
|
@@ -352,54 +386,101 @@ var CodexAppServerClient = class CodexAppServerClient {
|
|
|
352
386
|
if (this.closed) return Promise.reject(this.closeError ?? /* @__PURE__ */ new Error("codex app-server client is closed"));
|
|
353
387
|
if (options.signal?.aborted) return Promise.reject(new CodexAppServerLocalRequestCancellationError(method, "aborted", false));
|
|
354
388
|
const guard = method === "thread/start" || method === "thread/resume" || method === "thread/fork" ? this.threadSessionRequestGuard : void 0;
|
|
355
|
-
if (guard)
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
releaseGuard
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
389
|
+
if (guard) {
|
|
390
|
+
if (!options.signal && !(options.timeoutMs !== void 0 && Number.isFinite(options.timeoutMs) && options.timeoutMs > 0)) return Promise.reject(/* @__PURE__ */ new TypeError(`${method} requires a positive finite timeout or abort signal`));
|
|
391
|
+
return (async () => {
|
|
392
|
+
const guardStartedAt = Date.now();
|
|
393
|
+
const timeoutMessage = `${method} timed out`;
|
|
394
|
+
const abortMessage = `${method} aborted`;
|
|
395
|
+
let releaseGuard;
|
|
396
|
+
try {
|
|
397
|
+
releaseGuard = await guard({
|
|
398
|
+
signal: options.signal,
|
|
399
|
+
timeoutMs: options.timeoutMs,
|
|
400
|
+
timeoutMessage,
|
|
401
|
+
abortMessage
|
|
402
|
+
});
|
|
403
|
+
} catch (error) {
|
|
404
|
+
if (error instanceof Error && error.message === timeoutMessage) throw new CodexAppServerLocalRequestCancellationError(method, "timed out", false);
|
|
405
|
+
if (error instanceof Error && error.message === abortMessage) throw new CodexAppServerLocalRequestCancellationError(method, "aborted", false);
|
|
406
|
+
throw error;
|
|
407
|
+
}
|
|
408
|
+
let released = false;
|
|
409
|
+
const release = () => {
|
|
410
|
+
if (released) return;
|
|
411
|
+
released = true;
|
|
412
|
+
releaseGuard();
|
|
413
|
+
};
|
|
414
|
+
let releaseWhenRequestSettles = true;
|
|
415
|
+
let requestMayHaveWritten = false;
|
|
416
|
+
try {
|
|
417
|
+
const elapsedMs = Date.now() - guardStartedAt;
|
|
418
|
+
const remainingTimeoutMs = options.timeoutMs === void 0 ? void 0 : options.timeoutMs - elapsedMs;
|
|
419
|
+
if (remainingTimeoutMs !== void 0 && remainingTimeoutMs <= 0) throw new CodexAppServerLocalRequestCancellationError(method, "timed out", false);
|
|
420
|
+
return await this.requestWithoutThreadSessionGuard(method, params, {
|
|
421
|
+
...options,
|
|
422
|
+
...remainingTimeoutMs !== void 0 ? { timeoutMs: remainingTimeoutMs } : {}
|
|
423
|
+
}, () => {
|
|
424
|
+
requestMayHaveWritten = true;
|
|
425
|
+
});
|
|
426
|
+
} catch (error) {
|
|
427
|
+
if (requestMayHaveWritten && !(error instanceof CodexAppServerRpcError)) {
|
|
428
|
+
releaseWhenRequestSettles = false;
|
|
429
|
+
await this.closeAndRunAfterExit(release, method);
|
|
430
|
+
}
|
|
431
|
+
throw error;
|
|
432
|
+
} finally {
|
|
433
|
+
if (releaseWhenRequestSettles) release();
|
|
434
|
+
}
|
|
435
|
+
})();
|
|
436
|
+
}
|
|
437
|
+
return this.requestWithoutThreadSessionGuard(method, params, options);
|
|
438
|
+
}
|
|
439
|
+
requestWithoutThreadSessionGuard(method, params, options, onWriteAttempt) {
|
|
440
|
+
return this.requestWithOverloadRetry(method, params, options, onWriteAttempt);
|
|
441
|
+
}
|
|
442
|
+
async requestWithOverloadRetry(method, params, options, onWriteAttempt) {
|
|
443
|
+
const deadline = options.timeoutMs !== void 0 && Number.isFinite(options.timeoutMs) ? Date.now() + options.timeoutMs : void 0;
|
|
444
|
+
for (let retry = 0;; retry += 1) {
|
|
445
|
+
if (options.signal?.aborted) throw new CodexAppServerLocalRequestCancellationError(method, "aborted", false);
|
|
446
|
+
const remainingTimeoutMs = deadline === void 0 ? void 0 : deadline - Date.now();
|
|
447
|
+
if (remainingTimeoutMs !== void 0 && remainingTimeoutMs <= 0) throw new CodexAppServerLocalRequestCancellationError(method, "timed out", false);
|
|
380
448
|
try {
|
|
381
|
-
|
|
382
|
-
const remainingTimeoutMs = options.timeoutMs === void 0 ? void 0 : options.timeoutMs - elapsedMs;
|
|
383
|
-
if (remainingTimeoutMs !== void 0 && remainingTimeoutMs <= 0) throw new CodexAppServerLocalRequestCancellationError(method, "timed out", false);
|
|
384
|
-
return await this.requestWithoutThreadSessionGuard(method, params, {
|
|
449
|
+
return await this.requestOnce(method, params, {
|
|
385
450
|
...options,
|
|
386
451
|
...remainingTimeoutMs !== void 0 ? { timeoutMs: remainingTimeoutMs } : {}
|
|
387
|
-
},
|
|
388
|
-
requestMayHaveWritten = true;
|
|
389
|
-
});
|
|
452
|
+
}, onWriteAttempt);
|
|
390
453
|
} catch (error) {
|
|
391
|
-
if (
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
}
|
|
395
|
-
throw error;
|
|
396
|
-
} finally {
|
|
397
|
-
if (releaseWhenRequestSettles) release();
|
|
454
|
+
if (!(error instanceof CodexAppServerRpcError) || error.code !== CODEX_APP_SERVER_OVERLOADED_ERROR_CODE || retry >= CODEX_APP_SERVER_OVERLOAD_MAX_RETRIES) throw error;
|
|
455
|
+
const backoffMs = Math.round(CODEX_APP_SERVER_OVERLOAD_RETRY_BASE_MS * 2 ** retry * (.75 + Math.random() * .5));
|
|
456
|
+
await this.waitForOverloadRetry(method, backoffMs, deadline, options.signal);
|
|
398
457
|
}
|
|
399
|
-
}
|
|
400
|
-
return this.requestWithoutThreadSessionGuard(method, params, options);
|
|
458
|
+
}
|
|
401
459
|
}
|
|
402
|
-
|
|
460
|
+
async waitForOverloadRetry(method, backoffMs, deadline, signal) {
|
|
461
|
+
if (signal?.aborted) throw new CodexAppServerLocalRequestCancellationError(method, "aborted", false);
|
|
462
|
+
const remainingMs = deadline === void 0 ? void 0 : deadline - Date.now();
|
|
463
|
+
if (remainingMs !== void 0 && remainingMs <= 0) throw new CodexAppServerLocalRequestCancellationError(method, "timed out", false);
|
|
464
|
+
const delayMs = remainingMs === void 0 ? backoffMs : Math.min(backoffMs, remainingMs);
|
|
465
|
+
await new Promise((resolve, reject) => {
|
|
466
|
+
const timer = setTimeout(() => {
|
|
467
|
+
cleanup();
|
|
468
|
+
resolve();
|
|
469
|
+
}, delayMs);
|
|
470
|
+
timer.unref?.();
|
|
471
|
+
const abortListener = () => {
|
|
472
|
+
cleanup();
|
|
473
|
+
reject(new CodexAppServerLocalRequestCancellationError(method, "aborted", false));
|
|
474
|
+
};
|
|
475
|
+
const cleanup = () => {
|
|
476
|
+
clearTimeout(timer);
|
|
477
|
+
signal?.removeEventListener("abort", abortListener);
|
|
478
|
+
};
|
|
479
|
+
signal?.addEventListener("abort", abortListener, { once: true });
|
|
480
|
+
if (signal?.aborted) abortListener();
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
requestOnce(method, params, options, onWriteAttempt) {
|
|
403
484
|
if (this.closed) return Promise.reject(this.closeError ?? /* @__PURE__ */ new Error("codex app-server client is closed"));
|
|
404
485
|
if (options.signal?.aborted) return Promise.reject(new CodexAppServerLocalRequestCancellationError(method, "aborted", false));
|
|
405
486
|
const id = this.nextId++;
|
|
@@ -727,7 +808,7 @@ function timeoutServerRequestResponse(request) {
|
|
|
727
808
|
var CodexAppServerVersionError = class extends Error {
|
|
728
809
|
constructor(detectedVersion) {
|
|
729
810
|
const detected = detectedVersion ? `detected ${detectedVersion}` : "OpenClaw could not determine the running Codex version";
|
|
730
|
-
super(`Codex app-server ${MIN_CODEX_APP_SERVER_VERSION}
|
|
811
|
+
super(`A stable Codex app-server from ${MIN_CODEX_APP_SERVER_VERSION} through ${MAX_CODEX_APP_SERVER_VERSION} is required, but ${detected}. Update the configured Codex app-server binary, or remove custom command overrides to use the managed binary.`);
|
|
731
812
|
this.name = "CodexAppServerVersionError";
|
|
732
813
|
this.detectedVersion = detectedVersion;
|
|
733
814
|
}
|
|
@@ -735,7 +816,7 @@ var CodexAppServerVersionError = class extends Error {
|
|
|
735
816
|
function assertSupportedCodexAppServerVersion(response) {
|
|
736
817
|
const detectedVersion = readCodexVersionFromUserAgent(response.userAgent);
|
|
737
818
|
const parsedVersion = parse(detectedVersion ?? "");
|
|
738
|
-
if (!detectedVersion || !parsedVersion || parsedVersion.compare("0.143.0") < 0 || parsedVersion.
|
|
819
|
+
if (!detectedVersion || !parsedVersion || parsedVersion.compare("0.143.0") < 0 || parsedVersion.compare("0.144.6") > 0 || parsedVersion.prerelease.length > 0 || parsedVersion.build.length > 0) throw new CodexAppServerVersionError(detectedVersion);
|
|
739
820
|
return detectedVersion;
|
|
740
821
|
}
|
|
741
822
|
function isUnsupportedCodexAppServerVersionError(error) {
|
|
@@ -768,7 +849,7 @@ function redactCodexAppServerLinePreview(value) {
|
|
|
768
849
|
}
|
|
769
850
|
function appendBoundedTail(current, next, maxLength) {
|
|
770
851
|
const combined = `${current}${next}`;
|
|
771
|
-
return combined.length > maxLength ?
|
|
852
|
+
return combined.length > maxLength ? sliceUtf16Safe(combined, -maxLength) : combined;
|
|
772
853
|
}
|
|
773
854
|
function buildCodexAppServerExitError(code, signal, stderrTail) {
|
|
774
855
|
const stderrPreview = redactCodexAppServerLinePreview(stderrTail);
|
|
@@ -806,6 +887,103 @@ function formatExitValue(value) {
|
|
|
806
887
|
return "unknown";
|
|
807
888
|
}
|
|
808
889
|
//#endregion
|
|
890
|
+
//#region extensions/codex/src/app-server/attempt-timeouts.ts
|
|
891
|
+
/**
|
|
892
|
+
* Timeout defaults and normalizers for Codex app-server startup and turn
|
|
893
|
+
* liveness watches.
|
|
894
|
+
*/
|
|
895
|
+
/** Minimum startup timeout accepted by the Codex app-server harness. */
|
|
896
|
+
const CODEX_APP_SERVER_STARTUP_TIMEOUT_FLOOR_MS = 100;
|
|
897
|
+
/** Default idle timeout while waiting for app-server turn completion. */
|
|
898
|
+
const CODEX_TURN_COMPLETION_IDLE_TIMEOUT_MS = 6e4;
|
|
899
|
+
/** Short guard after apparent assistant completion. */
|
|
900
|
+
const CODEX_TURN_ASSISTANT_COMPLETION_IDLE_TIMEOUT_MS = 1e4;
|
|
901
|
+
const CODEX_POST_TOOL_RAW_ASSISTANT_COMPLETION_IDLE_TIMEOUT_MS = 5 * 6e4;
|
|
902
|
+
/** Guard after reasoning/commentary progress when no tool handoff occurred. */
|
|
903
|
+
const CODEX_POST_REASONING_REPLY_IDLE_TIMEOUT_MS = 5 * 6e4;
|
|
904
|
+
/** Long terminal idle watch for app-server turns that never send completion. */
|
|
905
|
+
const CODEX_TURN_TERMINAL_IDLE_TIMEOUT_MS = 30 * 6e4;
|
|
906
|
+
var CodexAppServerStartupError = class extends Error {
|
|
907
|
+
constructor(reason, message = reason === "timed_out" ? "codex app-server startup timed out" : "codex app-server startup aborted") {
|
|
908
|
+
super(message);
|
|
909
|
+
this.reason = reason;
|
|
910
|
+
this.code = "CODEX_APP_SERVER_STARTUP_CANCELLED";
|
|
911
|
+
this.name = "CodexAppServerStartupError";
|
|
912
|
+
}
|
|
913
|
+
};
|
|
914
|
+
function isCodexAppServerStartupError(error, reason) {
|
|
915
|
+
return error instanceof Error && "code" in error && error.code === "CODEX_APP_SERVER_STARTUP_CANCELLED" && "reason" in error && (error.reason === "aborted" || error.reason === "timed_out") && (reason === void 0 || error.reason === reason);
|
|
916
|
+
}
|
|
917
|
+
function resolvePositiveIntegerTimeoutMs(value, fallbackMs) {
|
|
918
|
+
return resolveTimerTimeoutMs(value, resolveTimerTimeoutMs(fallbackMs, 1));
|
|
919
|
+
}
|
|
920
|
+
/** Runs startup work with abort and timeout handling plus optional cleanup. */
|
|
921
|
+
async function withCodexStartupTimeout(params) {
|
|
922
|
+
if (params.signal.aborted) throw new CodexAppServerStartupError("aborted");
|
|
923
|
+
let timeout;
|
|
924
|
+
let abortCleanup;
|
|
925
|
+
let timeoutError;
|
|
926
|
+
let timeoutCleanup;
|
|
927
|
+
try {
|
|
928
|
+
return await Promise.race([params.operation(), new Promise((_, reject) => {
|
|
929
|
+
const rejectOnce = (error) => {
|
|
930
|
+
if (timeout) {
|
|
931
|
+
clearTimeout(timeout);
|
|
932
|
+
timeout = void 0;
|
|
933
|
+
}
|
|
934
|
+
reject(error);
|
|
935
|
+
};
|
|
936
|
+
timeout = setTimeout(() => {
|
|
937
|
+
timeoutError = new CodexAppServerStartupError("timed_out");
|
|
938
|
+
timeoutCleanup = Promise.resolve(params.onTimeout?.()).then(() => void 0, () => void 0);
|
|
939
|
+
timeoutCleanup.finally(() => {
|
|
940
|
+
rejectOnce(timeoutError);
|
|
941
|
+
});
|
|
942
|
+
}, params.timeoutMs);
|
|
943
|
+
const abortListener = () => rejectOnce(new CodexAppServerStartupError("aborted"));
|
|
944
|
+
params.signal.addEventListener("abort", abortListener, { once: true });
|
|
945
|
+
abortCleanup = () => params.signal.removeEventListener("abort", abortListener);
|
|
946
|
+
})]);
|
|
947
|
+
} catch (error) {
|
|
948
|
+
if (timeoutError) {
|
|
949
|
+
await timeoutCleanup;
|
|
950
|
+
throw timeoutError;
|
|
951
|
+
}
|
|
952
|
+
throw error;
|
|
953
|
+
} finally {
|
|
954
|
+
if (timeout) clearTimeout(timeout);
|
|
955
|
+
abortCleanup?.();
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
/** Resolves startup timeout while honoring the configured floor. */
|
|
959
|
+
function resolveCodexStartupTimeoutMs(params) {
|
|
960
|
+
const timeoutFloorMs = resolvePositiveIntegerTimeoutMs(params.timeoutFloorMs, CODEX_APP_SERVER_STARTUP_TIMEOUT_FLOOR_MS);
|
|
961
|
+
const timeoutMs = resolvePositiveIntegerTimeoutMs(params.timeoutMs, timeoutFloorMs);
|
|
962
|
+
return Math.max(timeoutFloorMs, timeoutMs);
|
|
963
|
+
}
|
|
964
|
+
/** Resolves the completion-idle timeout for an active turn. */
|
|
965
|
+
function resolveCodexTurnCompletionIdleTimeoutMs(value) {
|
|
966
|
+
return resolvePositiveIntegerTimeoutMs(value, CODEX_TURN_COMPLETION_IDLE_TIMEOUT_MS);
|
|
967
|
+
}
|
|
968
|
+
/** Resolves the short assistant-completion release timeout. */
|
|
969
|
+
function resolveCodexTurnAssistantCompletionIdleTimeoutMs(value) {
|
|
970
|
+
return resolvePositiveIntegerTimeoutMs(value, CODEX_TURN_ASSISTANT_COMPLETION_IDLE_TIMEOUT_MS);
|
|
971
|
+
}
|
|
972
|
+
/** Resolves the conservative post-tool raw assistant guard timeout. */
|
|
973
|
+
function resolveCodexPostToolRawAssistantCompletionIdleTimeoutMs(value, fallbackMs) {
|
|
974
|
+
return resolvePositiveIntegerTimeoutMs(value, Math.max(resolvePositiveIntegerTimeoutMs(void 0, fallbackMs), CODEX_POST_TOOL_RAW_ASSISTANT_COMPLETION_IDLE_TIMEOUT_MS));
|
|
975
|
+
}
|
|
976
|
+
/** Resolves the long terminal turn idle timeout. */
|
|
977
|
+
function resolveCodexTurnTerminalIdleTimeoutMs(value, runTimeoutOverrideMs) {
|
|
978
|
+
const explicitRunBudgetMs = resolvePositiveIntegerTimeoutMs(runTimeoutOverrideMs, CODEX_TURN_TERMINAL_IDLE_TIMEOUT_MS);
|
|
979
|
+
return resolvePositiveIntegerTimeoutMs(value, Math.max(CODEX_TURN_TERMINAL_IDLE_TIMEOUT_MS, explicitRunBudgetMs));
|
|
980
|
+
}
|
|
981
|
+
/** Adds gateway grace time to a caller timeout without overflowing invalid values. */
|
|
982
|
+
function resolveCodexGatewayTimeoutWithGraceMs(timeoutMs, graceMs = 1e4) {
|
|
983
|
+
const timeout = resolvePositiveIntegerTimeoutMs(timeoutMs, 1);
|
|
984
|
+
return addTimerTimeoutGraceMs(timeout, resolveTimerTimeoutMs(graceMs, 0, 0)) ?? timeout;
|
|
985
|
+
}
|
|
986
|
+
//#endregion
|
|
809
987
|
//#region extensions/codex/src/app-server/auth-start-options.ts
|
|
810
988
|
const CODEX_APP_SERVER_HOME_DIRNAME = "codex-home";
|
|
811
989
|
const CODEX_EPHEMERAL_AUTH_STORE_OVERRIDE = "cli_auth_credentials_store=\"ephemeral\"";
|
|
@@ -1080,14 +1258,14 @@ async function resolveCodexAppServerPreparedAuthHandoff(params) {
|
|
|
1080
1258
|
authProfileId,
|
|
1081
1259
|
nativeAuthProfile
|
|
1082
1260
|
};
|
|
1083
|
-
if (!authProfileId || !nativeAuthProfile) throw
|
|
1261
|
+
if (!authProfileId || !nativeAuthProfile) throw createCodexAppServerAuthError(params.subscriptionProfileRequiredError);
|
|
1084
1262
|
const snapshot = await resolveCodexAppServerPreparedAuthProfileSnapshot({
|
|
1085
1263
|
authProfileId,
|
|
1086
1264
|
authProfileStore: params.authProfileStore,
|
|
1087
1265
|
agentDir: params.agentDir,
|
|
1088
1266
|
config: params.config
|
|
1089
1267
|
});
|
|
1090
|
-
if (!snapshot) throw
|
|
1268
|
+
if (!snapshot) throw createCodexAppServerAuthError(params.subscriptionProfileUnusableError);
|
|
1091
1269
|
return {
|
|
1092
1270
|
authProfileId,
|
|
1093
1271
|
nativeAuthProfile,
|
|
@@ -1215,15 +1393,29 @@ async function applyCodexAppServerAuthProfile(params) {
|
|
|
1215
1393
|
});
|
|
1216
1394
|
return;
|
|
1217
1395
|
}
|
|
1218
|
-
if (params.authProfileId === null)
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
}
|
|
1396
|
+
if (params.authProfileId === null) {
|
|
1397
|
+
if (params.authRequirement === "subscription") {
|
|
1398
|
+
const response = await params.client.request("account/read", { refreshToken: false });
|
|
1399
|
+
if (!isJsonObject$1(response.account) || response.account.type !== "chatgpt") throw createCodexAppServerAuthError("Codex subscription auth profile could not produce login credentials.");
|
|
1400
|
+
}
|
|
1401
|
+
return;
|
|
1402
|
+
}
|
|
1403
|
+
let loginParams;
|
|
1404
|
+
try {
|
|
1405
|
+
loginParams = await resolveCodexAppServerAuthProfileLoginParams({
|
|
1406
|
+
agentDir: params.agentDir,
|
|
1407
|
+
authProfileId: params.authProfileId,
|
|
1408
|
+
authProfileStore: params.authProfileStore,
|
|
1409
|
+
config: params.config
|
|
1410
|
+
});
|
|
1411
|
+
} catch (error) {
|
|
1412
|
+
if (params.authRequirement === "subscription" && error instanceof CodexAppServerAuthProfileUnavailableError) throw createCodexAppServerAuthError("Codex subscription auth profile could not produce login credentials.", error);
|
|
1413
|
+
throw error;
|
|
1414
|
+
}
|
|
1415
|
+
if (params.authRequirement === "subscription" && loginParams?.type !== "chatgptAuthTokens") throw createCodexAppServerAuthError("Codex subscription auth profile could not produce login credentials.");
|
|
1225
1416
|
if (!loginParams) {
|
|
1226
|
-
if (params.
|
|
1417
|
+
if (params.authRequirement === "subscription") throw createCodexAppServerAuthError("Codex subscription auth profile could not produce login credentials.");
|
|
1418
|
+
if (params.authRequirement !== "api-key" || params.startOptions?.transport !== "stdio") return;
|
|
1227
1419
|
const env = resolveCodexAppServerSpawnEnv(params.startOptions, process.env);
|
|
1228
1420
|
const fallbackLoginParams = await resolveCodexAppServerFallbackApiKeyLoginParams({
|
|
1229
1421
|
client: params.client,
|
|
@@ -1235,8 +1427,25 @@ async function applyCodexAppServerAuthProfile(params) {
|
|
|
1235
1427
|
}
|
|
1236
1428
|
await params.client.request("account/login/start", loginParams);
|
|
1237
1429
|
}
|
|
1238
|
-
function
|
|
1239
|
-
|
|
1430
|
+
function createCodexAppServerAuthError(message, cause) {
|
|
1431
|
+
const error = cause === void 0 ? new Error(message) : new Error(message, { cause });
|
|
1432
|
+
return Object.assign(error, { status: 401 });
|
|
1433
|
+
}
|
|
1434
|
+
var CodexAppServerAuthProfileUnavailableError = class extends Error {};
|
|
1435
|
+
async function resolveCodexAppServerAuthProfileLoginParams(params) {
|
|
1436
|
+
const store = resolveCodexAppServerAuthProfileStore(params);
|
|
1437
|
+
const profileId = resolveCodexAppServerAuthProfileId({
|
|
1438
|
+
authProfileId: params.authProfileId,
|
|
1439
|
+
store,
|
|
1440
|
+
config: params.config
|
|
1441
|
+
});
|
|
1442
|
+
const profile = profileId ? store.profiles[profileId] : void 0;
|
|
1443
|
+
if (profileId && !profile) throw new CodexAppServerAuthProfileUnavailableError(`Codex app-server auth profile "${profileId}" was not found.`);
|
|
1444
|
+
if (profileId && profile && !isCodexAppServerAuthProfileCredential(profile, params.config)) throw new CodexAppServerAuthProfileUnavailableError(`Codex app-server auth profile "${profileId}" must be OpenAI Codex auth or an OpenAI API-key backup.`);
|
|
1445
|
+
return await resolveCodexAppServerAuthProfileLoginParamsInternal({
|
|
1446
|
+
...params,
|
|
1447
|
+
authProfileStore: store
|
|
1448
|
+
});
|
|
1240
1449
|
}
|
|
1241
1450
|
async function refreshCodexAppServerAuthTokens(params) {
|
|
1242
1451
|
const loginParams = await resolveCodexAppServerAuthProfileLoginParamsInternal({
|
|
@@ -1273,7 +1482,7 @@ async function resolveCodexAppServerAuthProfileLoginParamsInternal(params) {
|
|
|
1273
1482
|
forceOAuthRefresh: params.forceOAuthRefresh === true,
|
|
1274
1483
|
config: params.config
|
|
1275
1484
|
});
|
|
1276
|
-
if (!loginParams) throw new
|
|
1485
|
+
if (!loginParams) throw new CodexAppServerAuthProfileUnavailableError(`Codex app-server auth profile "${profileId}" does not contain usable credentials.`);
|
|
1277
1486
|
return loginParams;
|
|
1278
1487
|
}
|
|
1279
1488
|
async function resolveCodexAppServerFallbackApiKeyLoginParams(params) {
|
|
@@ -1903,8 +2112,11 @@ async function waitForPreviousFence(previous, options) {
|
|
|
1903
2112
|
* runtime timeout helper.
|
|
1904
2113
|
*/
|
|
1905
2114
|
/** Awaits a promise with a Codex-specific timeout error message. */
|
|
1906
|
-
async function withTimeout$1(promise, timeoutMs, timeoutMessage) {
|
|
1907
|
-
return await withTimeout(promise, timeoutMs, {
|
|
2115
|
+
async function withTimeout$1(promise, timeoutMs, timeoutMessage, createError) {
|
|
2116
|
+
return await withTimeout(promise, timeoutMs, {
|
|
2117
|
+
message: timeoutMessage,
|
|
2118
|
+
...createError ? { createError } : {}
|
|
2119
|
+
});
|
|
1908
2120
|
}
|
|
1909
2121
|
//#endregion
|
|
1910
2122
|
//#region extensions/codex/src/app-server/shared-client.ts
|
|
@@ -1913,7 +2125,6 @@ async function withTimeout$1(promise, timeoutMs, timeoutMessage) {
|
|
|
1913
2125
|
* lease tracking, and teardown.
|
|
1914
2126
|
*/
|
|
1915
2127
|
var shared_client_exports = /* @__PURE__ */ __exportAll({
|
|
1916
|
-
CodexAppServerStartSelectionChangedError: () => CodexAppServerStartSelectionChangedError,
|
|
1917
2128
|
assertCodexAppServerClientStartSelectionCurrent: () => assertCodexAppServerClientStartSelectionCurrent,
|
|
1918
2129
|
clearSharedCodexAppServerClientAndWait: () => clearSharedCodexAppServerClientAndWait,
|
|
1919
2130
|
clearSharedCodexAppServerClientIfCurrent: () => clearSharedCodexAppServerClientIfCurrent,
|
|
@@ -1995,6 +2206,10 @@ function resolveCodexNativeConfigFenceKey(params) {
|
|
|
1995
2206
|
const codexHome = configuredHome ? configuredHome : startOptions.homeScope === "user" ? resolveCodexAppServerUserHomeDir() : agentDir ? resolveCodexAppServerHomeDir(agentDir) : void 0;
|
|
1996
2207
|
return codexHome ? `codex-home:${path.resolve(codexHome)}` : void 0;
|
|
1997
2208
|
}
|
|
2209
|
+
function inferAuthRequirement(preparedAuth) {
|
|
2210
|
+
if (preparedAuth?.kind === "api-key") return "api-key";
|
|
2211
|
+
return preparedAuth?.kind === "profile" ? "subscription" : void 0;
|
|
2212
|
+
}
|
|
1998
2213
|
async function resolveCodexAppServerClientStartContext(options) {
|
|
1999
2214
|
const agentDir = options?.agentDir ?? resolveDefaultAgentDir(options?.config ?? {});
|
|
2000
2215
|
const requestedStartOptions = options?.startOptions ?? resolveCodexAppServerRuntimeOptions().start;
|
|
@@ -2004,6 +2219,9 @@ async function resolveCodexAppServerClientStartContext(options) {
|
|
|
2004
2219
|
if (preparedAuth?.kind === "profile" && !preparedAuth.store.profiles[preparedAuth.profileId]) throw new Error(`Prepared Codex auth profile "${preparedAuth.profileId}" was not found.`);
|
|
2005
2220
|
if (preparedAuth?.kind === "api-key" && !preparedApiKey) throw new Error("Prepared Codex API-key auth is missing its resolved key.");
|
|
2006
2221
|
if (preparedAuth && requestedStartOptions.homeScope === "user") throw new Error("Prepared Codex auth requires an isolated app-server home.");
|
|
2222
|
+
const preparedAuthRequirement = inferAuthRequirement(preparedAuth);
|
|
2223
|
+
if (options?.authRequirement && preparedAuthRequirement && options.authRequirement !== preparedAuthRequirement) throw new Error("Prepared Codex auth does not satisfy the requested auth requirement.");
|
|
2224
|
+
const authRequirement = options?.authRequirement ?? preparedAuthRequirement;
|
|
2007
2225
|
const usesNativeAuth = !preparedAuth && (options?.authProfileId === null || requestedStartOptions.homeScope === "user");
|
|
2008
2226
|
const requestedAuthProfileId = preparedAuth?.kind === "profile" ? preparedAuth.profileId : options?.authProfileId ?? void 0;
|
|
2009
2227
|
const authProfileStore = preparedAuth?.kind === "profile" ? preparedAuth.store : !usesNativeAuth && options?.authProfileStore ? resolveCodexAppServerAuthProfileStore({
|
|
@@ -2039,6 +2257,7 @@ async function resolveCodexAppServerClientStartContext(options) {
|
|
|
2039
2257
|
authProfileStore,
|
|
2040
2258
|
requestedStartOptions,
|
|
2041
2259
|
preparedAuth: resolvedPreparedAuth,
|
|
2260
|
+
authRequirement,
|
|
2042
2261
|
startOptions: await bridgeCodexAppServerStartOptions({
|
|
2043
2262
|
startOptions: await resolveManagedCodexAppServerStartOptions(resolveCodexAppServerStartOptionsForAgent({
|
|
2044
2263
|
startOptions: requestedStartOptions,
|
|
@@ -2087,9 +2306,9 @@ async function withLeasedCodexAppServerClientStartSelectionRetry(params) {
|
|
|
2087
2306
|
const deadline = Date.now() + timeoutMs;
|
|
2088
2307
|
const signal = params.signal ?? params.options?.abandonSignal;
|
|
2089
2308
|
const requestOptions = () => {
|
|
2090
|
-
if (signal?.aborted) throw new
|
|
2309
|
+
if (signal?.aborted) throw new CodexAppServerStartupError("aborted", "Codex app-server selection retry aborted");
|
|
2091
2310
|
const remainingTimeoutMs = deadline - Date.now();
|
|
2092
|
-
if (remainingTimeoutMs <= 0) throw new
|
|
2311
|
+
if (remainingTimeoutMs <= 0) throw new CodexAppServerStartupError("timed_out", "Codex app-server selection retry timed out");
|
|
2093
2312
|
return {
|
|
2094
2313
|
timeoutMs: remainingTimeoutMs,
|
|
2095
2314
|
...signal ? { signal } : {}
|
|
@@ -2117,18 +2336,18 @@ async function withLeasedCodexAppServerClientStartSelectionRetry(params) {
|
|
|
2117
2336
|
throw new Error("Codex app-server selection retry loop exited unexpectedly");
|
|
2118
2337
|
}
|
|
2119
2338
|
async function acquireSharedCodexAppServerClient(options, leaseOptions) {
|
|
2120
|
-
if (options?.abandonSignal?.aborted) throw new
|
|
2339
|
+
if (options?.abandonSignal?.aborted) throw new CodexAppServerStartupError("aborted", "codex app-server initialize aborted");
|
|
2121
2340
|
const acquireStartedAt = Date.now();
|
|
2122
2341
|
const timeoutMs = options?.timeoutMs ?? 0;
|
|
2123
|
-
const { agentDir, usesNativeAuth, authProfileId, authProfileStore, preparedAuth, requestedStartOptions, startOptions } = await withCodexAppServerAcquireDeadline(timeoutMs, resolveCodexAppServerClientStartContext(options), options?.abandonSignal);
|
|
2342
|
+
const { agentDir, usesNativeAuth, authProfileId, authProfileStore, preparedAuth, authRequirement, requestedStartOptions, startOptions } = await withCodexAppServerAcquireDeadline(timeoutMs, resolveCodexAppServerClientStartContext(options), options?.abandonSignal);
|
|
2124
2343
|
const remainingTimeoutMs = resolveRemainingAcquireTimeout(timeoutMs, acquireStartedAt);
|
|
2125
|
-
const authIdentityCacheKey = preparedAuth?.kind === "api-key" ? resolveCodexAppServerPreparedApiKeyCacheKey(preparedAuth.apiKey) : preparedAuth?.snapshot.secretFreeCacheKey ?? (
|
|
2126
|
-
const baseKey = codexAppServerStartOptionsKey(startOptions, {
|
|
2344
|
+
const authIdentityCacheKey = preparedAuth?.kind === "api-key" ? resolveCodexAppServerPreparedApiKeyCacheKey(preparedAuth.apiKey) : preparedAuth?.snapshot.secretFreeCacheKey ?? (authRequirement === "api-key" && !authProfileId ? resolveCodexAppServerFallbackApiKeyCacheKey({ startOptions }) : void 0);
|
|
2345
|
+
const baseKey = `${codexAppServerStartOptionsKey(startOptions, {
|
|
2127
2346
|
authProfileId,
|
|
2128
2347
|
authBindingFingerprint: options?.authBindingFingerprint,
|
|
2129
2348
|
agentDir: usesNativeAuth ? void 0 : agentDir,
|
|
2130
2349
|
fallbackApiKeyCacheKey: authIdentityCacheKey
|
|
2131
|
-
})
|
|
2350
|
+
})}\0auth-requirement:${authRequirement ?? "native"}`;
|
|
2132
2351
|
const runtimeArtifactMode = options?.runtimeArtifactMode ?? (options?.expectedRuntimeArtifact ? "capture" : void 0);
|
|
2133
2352
|
const expectedRuntimeArtifactKey = options?.expectedRuntimeArtifact ? createHash("sha256").update(options.expectedRuntimeArtifact.id).update("\0").update(options.expectedRuntimeArtifact.fingerprint).digest("hex") : "mint";
|
|
2134
2353
|
const key = runtimeArtifactMode ? `${baseKey}\0runtime-artifact:capture-v1:${expectedRuntimeArtifactKey}` : baseKey;
|
|
@@ -2164,6 +2383,7 @@ async function acquireSharedCodexAppServerClient(options, leaseOptions) {
|
|
|
2164
2383
|
authProfileId: usesNativeAuth || preparedAuth?.kind === "api-key" ? null : authProfileId,
|
|
2165
2384
|
authProfileStore,
|
|
2166
2385
|
preparedAuth,
|
|
2386
|
+
authRequirement,
|
|
2167
2387
|
runtimeArtifactMode,
|
|
2168
2388
|
...options?.expectedRuntimeArtifact ? { expectedRuntimeArtifact: options.expectedRuntimeArtifact } : {},
|
|
2169
2389
|
runtimeArtifactSignal: entry.runtimeArtifactStartupAbort?.signal,
|
|
@@ -2196,11 +2416,11 @@ async function acquireSharedCodexAppServerClient(options, leaseOptions) {
|
|
|
2196
2416
|
}
|
|
2197
2417
|
}
|
|
2198
2418
|
async function withCodexAppServerAcquireDeadline(timeoutMs, promise, signal, timeoutMessage = "codex app-server initialize timed out") {
|
|
2199
|
-
if (signal?.aborted) throw new
|
|
2200
|
-
const timed = withTimeout$1(promise, timeoutMs, timeoutMessage);
|
|
2419
|
+
if (signal?.aborted) throw new CodexAppServerStartupError("aborted", "codex app-server initialize aborted");
|
|
2420
|
+
const timed = withTimeout$1(promise, timeoutMs, timeoutMessage, () => new CodexAppServerStartupError("timed_out", timeoutMessage));
|
|
2201
2421
|
if (!signal) return await timed;
|
|
2202
2422
|
return await new Promise((resolve, reject) => {
|
|
2203
|
-
const onAbort = () => reject(
|
|
2423
|
+
const onAbort = () => reject(new CodexAppServerStartupError("aborted", "codex app-server initialize aborted"));
|
|
2204
2424
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
2205
2425
|
timed.then(resolve, reject).finally(() => signal.removeEventListener("abort", onAbort));
|
|
2206
2426
|
});
|
|
@@ -2208,7 +2428,7 @@ async function withCodexAppServerAcquireDeadline(timeoutMs, promise, signal, tim
|
|
|
2208
2428
|
function resolveRemainingAcquireTimeout(timeoutMs, startedAt) {
|
|
2209
2429
|
if (!(timeoutMs > 0)) return timeoutMs;
|
|
2210
2430
|
const remaining = timeoutMs - (Date.now() - startedAt);
|
|
2211
|
-
if (remaining <= 0) throw new
|
|
2431
|
+
if (remaining <= 0) throw new CodexAppServerStartupError("timed_out", "codex app-server initialize timed out");
|
|
2212
2432
|
return remaining;
|
|
2213
2433
|
}
|
|
2214
2434
|
function createSharedCodexAppServerClientStartup(params) {
|
|
@@ -2220,6 +2440,7 @@ function createSharedCodexAppServerClientStartup(params) {
|
|
|
2220
2440
|
authProfileId: params.authProfileId,
|
|
2221
2441
|
authProfileStore: params.authProfileStore,
|
|
2222
2442
|
preparedAuth: params.preparedAuth,
|
|
2443
|
+
authRequirement: params.authRequirement,
|
|
2223
2444
|
runtimeArtifactMode: params.runtimeArtifactMode,
|
|
2224
2445
|
...params.expectedRuntimeArtifact ? { expectedRuntimeArtifact: params.expectedRuntimeArtifact } : {},
|
|
2225
2446
|
runtimeArtifactSignal: params.runtimeArtifactSignal,
|
|
@@ -2246,10 +2467,10 @@ function createSharedCodexAppServerClientStartup(params) {
|
|
|
2246
2467
|
}
|
|
2247
2468
|
/** Starts a non-shared Codex app-server client owned entirely by the caller. */
|
|
2248
2469
|
async function createIsolatedCodexAppServerClient(options) {
|
|
2249
|
-
if (options?.abandonSignal?.aborted) throw new
|
|
2470
|
+
if (options?.abandonSignal?.aborted) throw new CodexAppServerStartupError("aborted", "codex app-server initialize aborted");
|
|
2250
2471
|
const acquireStartedAt = Date.now();
|
|
2251
2472
|
const timeoutMs = options?.timeoutMs ?? 0;
|
|
2252
|
-
const { agentDir, usesNativeAuth, authProfileId, authProfileStore, preparedAuth, requestedStartOptions, startOptions } = await withCodexAppServerAcquireDeadline(timeoutMs, resolveCodexAppServerClientStartContext(options), options?.abandonSignal);
|
|
2473
|
+
const { agentDir, usesNativeAuth, authProfileId, authProfileStore, preparedAuth, authRequirement, requestedStartOptions, startOptions } = await withCodexAppServerAcquireDeadline(timeoutMs, resolveCodexAppServerClientStartContext(options), options?.abandonSignal);
|
|
2253
2474
|
return await startInitializedCodexAppServerClient({
|
|
2254
2475
|
requestedStartOptions,
|
|
2255
2476
|
startOptions,
|
|
@@ -2257,6 +2478,7 @@ async function createIsolatedCodexAppServerClient(options) {
|
|
|
2257
2478
|
authProfileId: usesNativeAuth || preparedAuth?.kind === "api-key" ? null : authProfileId,
|
|
2258
2479
|
authProfileStore,
|
|
2259
2480
|
preparedAuth,
|
|
2481
|
+
authRequirement,
|
|
2260
2482
|
runtimeArtifactMode: options?.runtimeArtifactMode ?? (options?.expectedRuntimeArtifact ? "capture" : void 0),
|
|
2261
2483
|
...options?.expectedRuntimeArtifact ? { expectedRuntimeArtifact: options.expectedRuntimeArtifact } : {},
|
|
2262
2484
|
runtimeArtifactSignal: options?.abandonSignal,
|
|
@@ -2324,6 +2546,7 @@ async function startInitializedCodexAppServerClient(params) {
|
|
|
2324
2546
|
agentDir: params.agentDir,
|
|
2325
2547
|
authProfileId: params.authProfileId,
|
|
2326
2548
|
preparedAuth: params.preparedAuth,
|
|
2549
|
+
authRequirement: params.authRequirement,
|
|
2327
2550
|
startOptions,
|
|
2328
2551
|
config: params.config,
|
|
2329
2552
|
...params.authProfileStore ? { authProfileStore: params.authProfileStore } : {}
|
|
@@ -2550,4 +2773,4 @@ function collectSharedClients(state) {
|
|
|
2550
2773
|
return [...new Set([...state.clients.values()].map((entry) => entry.client).filter((client) => Boolean(client)))];
|
|
2551
2774
|
}
|
|
2552
2775
|
//#endregion
|
|
2553
|
-
export {
|
|
2776
|
+
export { isCodexAppServerStartupError as A, isCodexAppServerApprovalRequest as B, resolveCodexAppServerFallbackApiKeyCacheKey as C, resolveCodexAppServerHomeDir as D, resolveFirstExistingMacOSDesktopCodexBundledMarketplacePath as E, resolveCodexTurnCompletionIdleTimeoutMs as F, isCodexAppServerPrewriteRequestCancellationError as G, isCodexAppServerConnectionClosedError as H, resolveCodexTurnTerminalIdleTimeoutMs as I, CODEX_INTERACTIVE_THREAD_SOURCE_KINDS as J, isCodexAppServerRequestTimeoutError as K, withCodexStartupTimeout as L, resolveCodexPostToolRawAssistantCompletionIdleTimeoutMs as M, resolveCodexStartupTimeoutMs as N, CODEX_POST_REASONING_REPLY_IDLE_TIMEOUT_MS as O, resolveCodexTurnAssistantCompletionIdleTimeoutMs as P, CodexAppServerRpcError as R, resolveCodexAppServerAuthProfileIdForAgent as S, resolveCodexAppServerPreparedAuthHandoff as T, isCodexAppServerIndeterminateRequestCancellationError as U, isCodexAppServerBrokenPipeError as V, isCodexAppServerIndeterminateTransportError as W, flattenCodexDynamicToolFunctions as X, CODEX_OPENCLAW_DIRECT_DYNAMIC_TOOL_NAMESPACE as Y, isJsonObject$1 as Z, readCodexRateLimitsRevision as _, getLeasedSharedCodexAppServerClient as a, resolveCodexAppServerAuthAccountCacheKey as b, releaseLeasedSharedCodexAppServerClient as c, retireSharedCodexAppServerClientIfCurrent as d, shared_client_exports as f, ensureCodexAppServerClientRuntime as g, acquireCodexNativeConfigFence as h, createIsolatedCodexAppServerClient as i, resolveCodexGatewayTimeoutWithGraceMs as j, CodexAppServerStartupError as k, resolveCodexNativeConfigFenceKey as l, withTimeout$1 as m, clearSharedCodexAppServerClientIfCurrentAndUnclaimed as n, isCodexAppServerStartSelectionChangedError as o, withLeasedCodexAppServerClientStartSelectionRetry as p, CODEX_INTERACTIVE_CUSTOM_THREAD_SOURCES as q, clearSharedCodexAppServerClientIfCurrentAndWait as r, releaseCodexAppServerClientLease as s, clearSharedCodexAppServerClientIfCurrent as t, retainSharedCodexAppServerClientIfCurrent as u, readRecentCodexRateLimits as v, resolveCodexAppServerPreparedApiKeyCacheKey as w, resolveCodexAppServerAuthProfileId as x, rememberCodexRateLimitsRead as y, getCodexAppServerClientInstanceId as z };
|