@openclaw/codex 2026.9.1-beta.1 → 2026.9.2
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/dist/api.js +8 -9
- package/dist/{attempt-client-cleanup-bfsmcQ6m.js → attempt-client-cleanup-Bp1ZOnk2.js} +105 -75
- package/dist/attempt-context-CSazkWns.js +634 -0
- package/dist/{auth-binding-B4FfbcCg.js → auth-binding-Ds_QVm-X.js} +18 -3
- package/dist/{bounded-turn-B7iBUcuP.js → bounded-turn-DxGJRYbY.js} +53 -57
- package/dist/{capabilities-BRMh0aIq.js → capabilities-B1mgvpP8.js} +2 -1
- package/dist/cli-metadata.js +1 -1
- package/dist/{command-formatters-DEsIufkt.js → command-formatters-DSbGMXA0.js} +5 -4
- package/dist/{command-handlers-D_-1_qRp.js → command-handlers-DOJvGv6-.js} +243 -148
- package/dist/{compact-BglNFZrQ.js → compact-Y_xBqrHN.js} +109 -65
- package/dist/{config-giW8X0QA.js → config-CyapYSji.js} +328 -374
- package/dist/config-utils-C57JiJrU.js +69 -0
- package/dist/{context-compaction-activity-BOeJf7yo.js → context-compaction-activity-CMla5FPJ.js} +4 -1
- package/dist/{conversation-binding-data-CW2GuupV.js → conversation-binding-data-BiodpIzq.js} +2 -1
- package/dist/doctor-contract-api.js +144 -14
- package/dist/{dynamic-tools-Dnlfa--w.js → dynamic-tools-BwpvTxaX.js} +1119 -1135
- package/dist/{effective-mcp-catalog-CTeGrnfO.js → effective-mcp-catalog-CY9Jn4bA.js} +4 -3
- package/dist/{event-projector-assistant-message-C5-Ds8mA.js → event-projector-assistant-message-B9kp6iGC.js} +15 -6
- package/dist/event-projector-usage-ZqEVbAEY.js +212 -0
- package/dist/{harness-Csz0F-DK.js → harness-Czh2Sdoc.js} +65 -52
- package/dist/harness.js +1 -1
- package/dist/{image-payload-sanitizer-CnfoUPCE.js → image-payload-sanitizer-tupAr-2o.js} +29 -15
- package/dist/index.js +495 -457
- package/dist/{isolated-completion-Cv6FqygM.js → isolated-completion-CRh-51AK.js} +9 -21
- package/dist/{managed-binary-DFYK4DWq.js → managed-binary-DcpnJF9x.js} +117 -80
- package/dist/media-understanding-provider.js +1 -1
- package/dist/model-catalog-DT5vo6qo.js +101 -0
- package/dist/{models-TS3HBU-q.js → models-CcrgSMQR.js} +26 -29
- package/dist/{native-subagent-monitor-4Mfq2HDs.js → native-subagent-monitor-B3bvQGcg.js} +63 -122
- package/dist/{node-exec-server.runtime-BpWqJO1V.js → node-exec-server.runtime-nfbUOtUB.js} +10 -7
- package/dist/{plugin-approval-roundtrip-bUm777tR.js → plugin-approval-roundtrip-aQVdyL5g.js} +30 -3
- package/dist/{plugin-marketplace-discovery-B9DvaAG-.js → plugin-marketplace-discovery-B7gHXJ3d.js} +44 -30
- package/dist/{plugin-metadata-cache-CTCT3w5L.js → plugin-metadata-cache-BwCLTY_U.js} +6 -6
- package/dist/provider-capabilities-BpG9Ltc5.js +101 -0
- package/dist/{rate-limits-C5_D8Gmb.js → rate-limits-Fx_l4eNa.js} +3 -2
- package/dist/{sandbox-guard-kuWTn9C5.js → request-C8H22rPi.js} +195 -2
- package/dist/{run-attempt-DYc0QCBF.js → run-attempt-BzthFQSM.js} +1616 -2634
- package/dist/{runtime-artifact-BvyT1uyd.js → runtime-artifact-Bh_gf6-t.js} +22 -15
- package/dist/{session-binding-Bcynfd-_.js → session-binding-4Ki04sW-.js} +282 -399
- package/dist/session-binding-record-CyaXZvTe.js +270 -0
- package/dist/{session-catalog-DaLKVtpH.js → session-catalog-B47uwekb.js} +812 -504
- package/dist/{session-cli-DMc4oS2w.js → session-cli-BjLhpmS1.js} +1 -1
- package/dist/session-history-DWmMqiqW.js +93 -0
- package/dist/session-history-read-LHldwvyh.js +36 -0
- package/dist/session-history-worker-runtime.js +48 -0
- package/dist/session-history.worker-zZVcx0ME.js +267 -0
- package/dist/session-history.worker.js +2 -0
- package/dist/session-initialization-BCFVnLL4.js +75 -0
- package/dist/{session-permission-policy-BrNH1bjy.js → session-permission-policy-BaueHmSj.js} +2 -2
- package/dist/session-retirement-DNdmYdFc.js +97 -0
- package/dist/{session-upstream-marker-BIkusb95.js → session-upstream-marker-DReTpGz6.js} +20 -4
- package/dist/settled-turn-context-BOM3Y1pl.js +45 -0
- package/dist/settled-turn-finalizer-BI-b1sry.js +115 -0
- package/dist/{shared-client-DKz23hHY.js → shared-client-CKhX2kFt.js} +3659 -847
- package/dist/{side-question-DjA_jsNe.js → side-question-B6DWAw1A.js} +168 -81
- package/dist/{thread-lifecycle-L7oEkTlq.js → thread-lifecycle-DPK30jad.js} +2412 -2145
- package/dist/{thread-ownership-DZeuKH1j.js → thread-ownership-CbucAmmp.js} +27 -16
- package/dist/thread-policy-CTalhWFy.js +105 -0
- package/dist/{plugin-app-cache-key-C1CAdfcP.js → thread-resume-BLgqkUc1.js} +61 -9
- package/dist/{transcript-mirror-DsCMWBca.js → transcript-mirror-_njEB84z.js} +114 -110
- package/dist/transcript-mirror-attestation-Byl34PC-.js +76 -0
- package/dist/transport-stdio-CzTngV0j.js +728 -0
- package/dist/{upstream-prompt-provenance-CFmsKwr9.js → upstream-prompt-provenance-LphB8slG.js} +8 -4
- package/dist/upstream-session-fork-1fwbNKzQ.js +886 -0
- package/dist/{usage-ROIaW3wo.js → usage-i9fv5-4m.js} +3 -3
- package/dist/{web-search-provider.runtime-ClaNPV7N.js → web-search-provider.runtime-DKQn67A7.js} +3 -3
- package/openclaw.plugin.json +1 -30
- package/package.json +6 -6
- package/dist/binding-connection-BMvPX73o.js +0 -45
- package/dist/command-rpc-CCeCkf_v.js +0 -90
- package/dist/event-projector-usage-Bk1I90Bg.js +0 -328
- package/dist/incognito-session-ET_ufDH-.js +0 -2
- package/dist/model-catalog-i9rNBthX.js +0 -48
- package/dist/protocol-validators-VeJxxJ0U.js +0 -2421
- package/dist/request-DXXGHko0.js +0 -157
- package/dist/session-catalog-home-id-BNwAJ9D7.js +0 -18
- package/dist/session-retirement-CcNC3YSY.js +0 -36
- package/dist/settled-turn-finalizer-Dc3ApjU4.js +0 -328
- package/dist/thread-resume-BE9qNEW0.js +0 -30
- package/dist/transport-stdio-DhoGy33Z.js +0 -99
- package/dist/upstream-session-fork-DlaHxSLC.js +0 -326
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { h as releaseLeasedSharedCodexAppServerClient } from "./shared-client-CKhX2kFt.js";
|
|
2
|
+
import { ut as normalizeCodexDynamicToolName } from "./thread-lifecycle-DPK30jad.js";
|
|
3
|
+
import { pinExecToolTarget } from "openclaw/plugin-sdk/codex-mcp-projection";
|
|
4
|
+
import { loadNodeExecAvailability } from "openclaw/plugin-sdk/node-selection-runtime";
|
|
5
|
+
//#region extensions/codex/src/app-server/shell-dynamic-tools.ts
|
|
6
|
+
const CODEX_NODE_EXEC_DYNAMIC_TOOL_NAME = "node_exec";
|
|
7
|
+
const CODEX_GATEWAY_EXEC_DYNAMIC_TOOL_NAME = "gateway_exec";
|
|
8
|
+
const CODEX_GATEWAY_PROCESS_DYNAMIC_TOOL_NAME = "gateway_process";
|
|
9
|
+
const PROCESS_FOLLOWUP_TEXT = "Use process (list/poll/log/write/send-keys/submit/paste/kill/clear/remove) for follow-up.";
|
|
10
|
+
/** Returns true when plugin config explicitly removes any named dynamic tool. */
|
|
11
|
+
function isCodexDynamicToolExcluded(config, names) {
|
|
12
|
+
const normalizedNames = new Set(names.map((name) => normalizeCodexDynamicToolName(name)));
|
|
13
|
+
return (config.codexDynamicToolsExclude ?? []).some((name) => normalizedNames.has(normalizeCodexDynamicToolName(name)));
|
|
14
|
+
}
|
|
15
|
+
async function createNodeExecAliasDynamicTool(execTool, node, discoverySignal, availabilityRef) {
|
|
16
|
+
const pinnedNode = node?.trim();
|
|
17
|
+
const availability = await (availabilityRef ? availabilityRef.current ??= loadNodeExecAvailability(discoverySignal) : loadNodeExecAvailability(discoverySignal));
|
|
18
|
+
discoverySignal?.throwIfAborted();
|
|
19
|
+
if (!availability.isAvailable(pinnedNode)) return;
|
|
20
|
+
const pinnedTool = pinExecToolTarget(execTool, {
|
|
21
|
+
host: "node",
|
|
22
|
+
...pinnedNode ? { node: pinnedNode } : {}
|
|
23
|
+
});
|
|
24
|
+
const execute = async (toolCallId, args, signal, onUpdate) => {
|
|
25
|
+
const result = await pinnedTool.execute(toolCallId, args, signal, onUpdate);
|
|
26
|
+
return {
|
|
27
|
+
...result,
|
|
28
|
+
content: result.content.map((item) => item.type === "text" ? Object.assign({}, item, { text: item.text.replace(PROCESS_FOLLOWUP_TEXT, "Remote-node background follow-up is unavailable. Wait for the command to complete.") }) : item)
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
...pinnedTool,
|
|
33
|
+
name: CODEX_NODE_EXEC_DYNAMIC_TOOL_NAME,
|
|
34
|
+
description: pinnedNode ? "Run a shell command to completion on the OpenClaw configured remote node for this session. This tool always uses OpenClaw host=node internally and follows the existing node exec approval and allowlist policy. Remote-node background follow-up is unavailable. Use Codex's native shell for local app-server work when it is available." : "Run a shell command to completion on an OpenClaw remote node. The sole connected node that can execute commands is selected automatically; select by name or id when several can. This tool always uses OpenClaw host=node internally and follows the existing node exec approval and allowlist policy. Remote-node background follow-up is unavailable. Use Codex's native shell for local app-server work when it is available.",
|
|
35
|
+
execute
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function createGatewayExecProjection(createProjection, execTool, params) {
|
|
39
|
+
return createProjection(execTool, {
|
|
40
|
+
kind: "exec",
|
|
41
|
+
name: CODEX_GATEWAY_EXEC_DYNAMIC_TOOL_NAME,
|
|
42
|
+
description: "Run a shell command through OpenClaw on the Gateway host for OpenClaw-managed Gateway environment access, including Secret Store agent-readable environment values and protected egress sentinels. Native Codex shell remains preferred for ordinary local work. This tool always uses OpenClaw host=gateway internally and follows Gateway exec approval and allowlist policy.",
|
|
43
|
+
followupText: params.processAliasAvailable ? "Use gateway_process (list/poll/log/write/send-keys/submit/paste/kill/clear/remove) for follow-up." : "Background session follow-up is unavailable because gateway_process is not exposed. Rerun without background=true and set yieldMs high enough to wait for completion.",
|
|
44
|
+
...params.ask ? { ask: params.ask } : {}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function createGatewayProcessProjection(createProjection, processTool) {
|
|
48
|
+
return createProjection(processTool, {
|
|
49
|
+
kind: "process",
|
|
50
|
+
name: CODEX_GATEWAY_PROCESS_DYNAMIC_TOOL_NAME,
|
|
51
|
+
description: "Manage background shell sessions in the existing per-session OpenClaw process scope: list, poll, log, write, send-keys, submit, paste, kill, clear, or remove. Use for gateway_exec follow-up; use native Codex shell session handling for ordinary local work."
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region extensions/codex/src/app-server/provider-capabilities.ts
|
|
56
|
+
function resolveOverriddenProviderWebSearchSupport(modelProviderOverride) {
|
|
57
|
+
const provider = modelProviderOverride?.trim().toLowerCase();
|
|
58
|
+
if (!provider) return;
|
|
59
|
+
return provider === "openai" ? "supported" : "unsupported";
|
|
60
|
+
}
|
|
61
|
+
async function readConfiguredProviderWebSearchSupport(params) {
|
|
62
|
+
return (await params.client.request("modelProvider/capabilities/read", {}, {
|
|
63
|
+
timeoutMs: params.timeoutMs,
|
|
64
|
+
signal: params.signal
|
|
65
|
+
})).webSearch ? "supported" : "unsupported";
|
|
66
|
+
}
|
|
67
|
+
async function resolveCodexProviderWebSearchSupportForClient(params) {
|
|
68
|
+
const overrideSupport = resolveOverriddenProviderWebSearchSupport(params.modelProviderOverride);
|
|
69
|
+
if (overrideSupport) return overrideSupport;
|
|
70
|
+
try {
|
|
71
|
+
return await readConfiguredProviderWebSearchSupport(params);
|
|
72
|
+
} catch {
|
|
73
|
+
return "unknown";
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async function resolveCodexProviderWebSearchSupport(params) {
|
|
77
|
+
const overrideSupport = resolveOverriddenProviderWebSearchSupport(params.modelProviderOverride);
|
|
78
|
+
if (overrideSupport) return overrideSupport;
|
|
79
|
+
let client;
|
|
80
|
+
try {
|
|
81
|
+
client = await params.clientFactory({
|
|
82
|
+
startOptions: params.appServer.start,
|
|
83
|
+
...params.preparedAuth ? { preparedAuth: params.preparedAuth } : { authProfileId: params.authProfileId },
|
|
84
|
+
agentDir: params.agentDir,
|
|
85
|
+
config: params.config,
|
|
86
|
+
timeoutMs: params.appServer.requestTimeoutMs
|
|
87
|
+
});
|
|
88
|
+
return await resolveCodexProviderWebSearchSupportForClient({
|
|
89
|
+
client,
|
|
90
|
+
timeoutMs: params.appServer.requestTimeoutMs,
|
|
91
|
+
modelProviderOverride: params.modelProviderOverride,
|
|
92
|
+
signal: params.signal
|
|
93
|
+
});
|
|
94
|
+
} catch {
|
|
95
|
+
return "unknown";
|
|
96
|
+
} finally {
|
|
97
|
+
if (client) releaseLeasedSharedCodexAppServerClient(client);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
export { CODEX_NODE_EXEC_DYNAMIC_TOOL_NAME as a, createNodeExecAliasDynamicTool as c, CODEX_GATEWAY_PROCESS_DYNAMIC_TOOL_NAME as i, isCodexDynamicToolExcluded as l, resolveCodexProviderWebSearchSupportForClient as n, createGatewayExecProjection as o, CODEX_GATEWAY_EXEC_DYNAMIC_TOOL_NAME as r, createGatewayProcessProjection as s, resolveCodexProviderWebSearchSupport as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as isJsonObject } from "./config-CyapYSji.js";
|
|
2
2
|
import { asBoolean, asFiniteNumber, normalizeOptionalString, parseStrictFiniteNumber } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
3
3
|
import { MAX_DATE_TIMESTAMP_MS, resolveExpiresAtMsFromEpochSeconds } from "openclaw/plugin-sdk/number-runtime";
|
|
4
4
|
import { expectDefined } from "openclaw/plugin-sdk/expect-runtime";
|
|
@@ -186,8 +186,9 @@ function isRateLimitSnapshot(value) {
|
|
|
186
186
|
function readRateLimitWindow(snapshot, key) {
|
|
187
187
|
const window = snapshot[key];
|
|
188
188
|
if (!isJsonObject(window)) return;
|
|
189
|
+
const resetsAt = asFiniteNumber(window.resetsAt) ?? asFiniteNumber(window.resets_at);
|
|
189
190
|
return {
|
|
190
|
-
resetsAtMs: resolveExpiresAtMsFromEpochSeconds(
|
|
191
|
+
resetsAtMs: resolveExpiresAtMsFromEpochSeconds(resetsAt, { maxMs: MAX_DATE_TIMESTAMP_MS }) ?? 0,
|
|
191
192
|
...readOptionalNumberField(window, "usedPercent", "used_percent"),
|
|
192
193
|
...readOptionalNumberField(window, "windowDurationMins", "window_duration_mins", "windowMinutes", "window_minutes")
|
|
193
194
|
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
|
|
2
|
+
import { E as isCodexRemoteExecPlacementSandbox } from "./config-CyapYSji.js";
|
|
3
|
+
import { Ft as withTimeout, c as getLeasedSharedCodexAppServerClient, h as releaseLeasedSharedCodexAppServerClient, s as createIsolatedCodexAppServerClient, u as isCodexAppServerStartSelectionChangedError, y as retireSharedCodexAppServerClientIfCurrent } from "./shared-client-CKhX2kFt.js";
|
|
2
4
|
import { resolveAgentConfig, tryResolveDefaultAgentId } from "openclaw/plugin-sdk/agent-scope-runtime";
|
|
3
5
|
import { getSessionEntry } from "openclaw/plugin-sdk/session-store-runtime";
|
|
4
6
|
import { normalizeAgentId, parseAgentSessionKey } from "openclaw/plugin-sdk/routing";
|
|
@@ -279,4 +281,195 @@ function resolveCodexNativeNodeExecBlock(params) {
|
|
|
279
281
|
});
|
|
280
282
|
}
|
|
281
283
|
//#endregion
|
|
282
|
-
|
|
284
|
+
//#region extensions/codex/src/app-server/request.ts
|
|
285
|
+
var request_exports = /* @__PURE__ */ __exportAll({
|
|
286
|
+
CodexAppServerScopedRequestRejectedError: () => CodexAppServerScopedRequestRejectedError,
|
|
287
|
+
readCodexAppServerUsage: () => readCodexAppServerUsage,
|
|
288
|
+
requestCodexAppServerClientJson: () => requestCodexAppServerClientJson,
|
|
289
|
+
requestCodexAppServerJson: () => requestCodexAppServerJson,
|
|
290
|
+
withCodexAppServerJsonClient: () => withCodexAppServerJsonClient
|
|
291
|
+
});
|
|
292
|
+
/** Sends one guarded request over a client lease owned by the caller. */
|
|
293
|
+
async function requestCodexAppServerClientJson(params) {
|
|
294
|
+
const sandboxBlock = resolveCodexAppServerDirectSandboxBypassBlock({
|
|
295
|
+
method: params.method,
|
|
296
|
+
requestParams: params.requestParams,
|
|
297
|
+
config: params.config,
|
|
298
|
+
sessionKey: params.sessionKey,
|
|
299
|
+
sessionId: params.sessionId
|
|
300
|
+
});
|
|
301
|
+
if (sandboxBlock) throw new Error(sandboxBlock);
|
|
302
|
+
const timeoutMs = params.timeoutMs ?? 6e4;
|
|
303
|
+
return await withTimeout(params.client.request(params.method, params.requestParams, {
|
|
304
|
+
timeoutMs,
|
|
305
|
+
signal: params.signal,
|
|
306
|
+
...params.assertCurrent ? { assertCurrent: () => assertRequestOwnerCurrent(params.assertCurrent) } : {}
|
|
307
|
+
}), timeoutMs, `codex app-server ${params.method} timed out`);
|
|
308
|
+
}
|
|
309
|
+
async function requestCodexAppServerJson(params) {
|
|
310
|
+
const sandboxBlock = resolveCodexAppServerDirectSandboxBypassBlock({
|
|
311
|
+
method: params.method,
|
|
312
|
+
requestParams: params.requestParams,
|
|
313
|
+
config: params.config,
|
|
314
|
+
sessionKey: params.sessionKey,
|
|
315
|
+
sessionId: params.sessionId
|
|
316
|
+
});
|
|
317
|
+
if (sandboxBlock) throw new Error(sandboxBlock);
|
|
318
|
+
return await withCodexAppServerJsonClient({
|
|
319
|
+
...params,
|
|
320
|
+
timeoutMessage: `codex app-server ${params.method} timed out`
|
|
321
|
+
}, async (request) => await request({
|
|
322
|
+
method: params.method,
|
|
323
|
+
requestParams: params.requestParams
|
|
324
|
+
}));
|
|
325
|
+
}
|
|
326
|
+
/** A scoped guard rejected the request before a physical write. */
|
|
327
|
+
var CodexAppServerScopedRequestRejectedError = class extends Error {
|
|
328
|
+
constructor(message, options) {
|
|
329
|
+
super(message, options);
|
|
330
|
+
this.name = "CodexAppServerScopedRequestRejectedError";
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
function assertRequestOwnerCurrent(assertCurrent) {
|
|
334
|
+
try {
|
|
335
|
+
assertCurrent?.();
|
|
336
|
+
} catch (cause) {
|
|
337
|
+
throw new CodexAppServerScopedRequestRejectedError(cause instanceof Error ? cause.message : String(cause), { cause });
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
const CODEX_USAGE_ISOLATED_SHUTDOWN = {
|
|
341
|
+
forceKillDelayMs: 200,
|
|
342
|
+
exitTimeoutMs: 300
|
|
343
|
+
};
|
|
344
|
+
const CODEX_ACCOUNT_READ_MAX_TIMEOUT_MS = 4e3;
|
|
345
|
+
const CODEX_USAGE_DEADLINE_RESERVE_MS = CODEX_USAGE_ISOLATED_SHUTDOWN.forceKillDelayMs + CODEX_USAGE_ISOLATED_SHUTDOWN.exitTimeoutMs + 250;
|
|
346
|
+
/** Reads rate limits and best-effort account identity from one isolated app-server session. */
|
|
347
|
+
async function readCodexAppServerUsage(options) {
|
|
348
|
+
const deadline = Date.now() + options.timeoutMs;
|
|
349
|
+
return await withCodexAppServerJsonClient({
|
|
350
|
+
timeoutMs: options.timeoutMs,
|
|
351
|
+
timeoutMessage: "codex app-server usage read timed out",
|
|
352
|
+
agentDir: options.agentDir,
|
|
353
|
+
...options.authProfileId ? { authProfileId: options.authProfileId } : {},
|
|
354
|
+
config: options.config,
|
|
355
|
+
startOptions: options.startOptions,
|
|
356
|
+
isolated: true,
|
|
357
|
+
isolatedShutdown: CODEX_USAGE_ISOLATED_SHUTDOWN
|
|
358
|
+
}, async (request) => {
|
|
359
|
+
const rateLimits = await request({ method: "account/rateLimits/read" });
|
|
360
|
+
const accountEmail = await readCodexAccountEmailBestEffort(request, deadline);
|
|
361
|
+
return {
|
|
362
|
+
rateLimits,
|
|
363
|
+
...accountEmail ? { accountEmail } : {}
|
|
364
|
+
};
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
function extractCodexAccountEmail(value) {
|
|
368
|
+
if (!value || typeof value !== "object") return;
|
|
369
|
+
const record = value;
|
|
370
|
+
const account = record.account && typeof record.account === "object" ? record.account : record;
|
|
371
|
+
const email = account.email ?? account.accountEmail;
|
|
372
|
+
return typeof email === "string" && email.trim() ? email.trim() : void 0;
|
|
373
|
+
}
|
|
374
|
+
async function readCodexAccountEmailBestEffort(request, deadline) {
|
|
375
|
+
const boundMs = Math.min(CODEX_ACCOUNT_READ_MAX_TIMEOUT_MS, deadline - Date.now() - CODEX_USAGE_DEADLINE_RESERVE_MS);
|
|
376
|
+
if (boundMs <= 0) return;
|
|
377
|
+
const read = request({
|
|
378
|
+
method: "account/read",
|
|
379
|
+
requestParams: {}
|
|
380
|
+
}).then((account) => extractCodexAccountEmail(account), () => void 0);
|
|
381
|
+
let timer;
|
|
382
|
+
const timeout = new Promise((resolve) => {
|
|
383
|
+
timer = setTimeout(() => resolve(void 0), boundMs);
|
|
384
|
+
timer.unref?.();
|
|
385
|
+
});
|
|
386
|
+
try {
|
|
387
|
+
return await Promise.race([read, timeout]);
|
|
388
|
+
} finally {
|
|
389
|
+
if (timer) clearTimeout(timer);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Runs several guarded requests over one acquired client (shared lease or
|
|
394
|
+
* isolated child) so related reads see the same app-server session. The whole
|
|
395
|
+
* callback re-runs once when the client's start selection changed underneath it.
|
|
396
|
+
*/
|
|
397
|
+
async function withCodexAppServerJsonClient(params, run) {
|
|
398
|
+
const timeoutMs = params.timeoutMs ?? 6e4;
|
|
399
|
+
const timeoutMessage = params.timeoutMessage ?? "codex app-server request timed out";
|
|
400
|
+
const timeoutController = new AbortController();
|
|
401
|
+
const deadline = Number.isFinite(timeoutMs) && timeoutMs > 0 ? Date.now() + timeoutMs : void 0;
|
|
402
|
+
const isPastDeadline = () => deadline !== void 0 && Date.now() >= deadline;
|
|
403
|
+
const throwIfAbandoned = () => {
|
|
404
|
+
if (timeoutController.signal.aborted || isPastDeadline()) throw new CodexAppServerScopedRequestRejectedError(timeoutMessage);
|
|
405
|
+
};
|
|
406
|
+
const remainingTimeoutMs = () => {
|
|
407
|
+
throwIfAbandoned();
|
|
408
|
+
return deadline === void 0 ? timeoutMs : Math.max(1, deadline - Date.now());
|
|
409
|
+
};
|
|
410
|
+
try {
|
|
411
|
+
return await withTimeout((async () => {
|
|
412
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
413
|
+
throwIfAbandoned();
|
|
414
|
+
const client = await (params.isolated ? createIsolatedCodexAppServerClient : getLeasedSharedCodexAppServerClient)({
|
|
415
|
+
startOptions: params.startOptions,
|
|
416
|
+
pluginConfig: params.pluginConfig,
|
|
417
|
+
timeoutMs: remainingTimeoutMs(),
|
|
418
|
+
authProfileId: params.authProfileId,
|
|
419
|
+
authProfileStore: params.authProfileStore,
|
|
420
|
+
authBindingFingerprint: params.authBindingFingerprint,
|
|
421
|
+
preparedAuth: params.preparedAuth,
|
|
422
|
+
authRequirement: params.authRequirement,
|
|
423
|
+
agentDir: params.agentDir,
|
|
424
|
+
config: params.config,
|
|
425
|
+
abandonSignal: timeoutController.signal
|
|
426
|
+
});
|
|
427
|
+
let scopeActive = true;
|
|
428
|
+
const assertCurrent = () => {
|
|
429
|
+
throwIfAbandoned();
|
|
430
|
+
if (!scopeActive) throw new CodexAppServerScopedRequestRejectedError("Codex app-server request scope is closed");
|
|
431
|
+
assertRequestOwnerCurrent(params.assertCurrent);
|
|
432
|
+
};
|
|
433
|
+
try {
|
|
434
|
+
assertCurrent();
|
|
435
|
+
const scopedRequest = async (request) => {
|
|
436
|
+
const sandboxBlock = resolveCodexAppServerDirectSandboxBypassBlock({
|
|
437
|
+
method: request.method,
|
|
438
|
+
requestParams: request.requestParams,
|
|
439
|
+
config: params.config,
|
|
440
|
+
sessionKey: params.sessionKey,
|
|
441
|
+
sessionId: params.sessionId
|
|
442
|
+
});
|
|
443
|
+
if (sandboxBlock) throw new CodexAppServerScopedRequestRejectedError(sandboxBlock);
|
|
444
|
+
assertCurrent();
|
|
445
|
+
return await client.request(request.method, request.requestParams, {
|
|
446
|
+
timeoutMs: remainingTimeoutMs(),
|
|
447
|
+
signal: timeoutController.signal,
|
|
448
|
+
assertCurrent
|
|
449
|
+
});
|
|
450
|
+
};
|
|
451
|
+
return await run(scopedRequest, client, { assertCurrent });
|
|
452
|
+
} catch (error) {
|
|
453
|
+
if (!isCodexAppServerStartSelectionChangedError(error) || attempt > 0) throw error;
|
|
454
|
+
if (!params.isolated) retireSharedCodexAppServerClientIfCurrent(client);
|
|
455
|
+
throwIfAbandoned();
|
|
456
|
+
} finally {
|
|
457
|
+
scopeActive = false;
|
|
458
|
+
if (params.isolated) await client.closeAndWait({
|
|
459
|
+
exitTimeoutMs: params.isolatedShutdown?.exitTimeoutMs ?? 2e3,
|
|
460
|
+
forceKillDelayMs: params.isolatedShutdown?.forceKillDelayMs ?? 250
|
|
461
|
+
});
|
|
462
|
+
else releaseLeasedSharedCodexAppServerClient(client);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
throw new Error("Codex app-server selection retry loop exited unexpectedly");
|
|
466
|
+
})(), timeoutMs, timeoutMessage);
|
|
467
|
+
} catch (error) {
|
|
468
|
+
if (isPastDeadline()) throw new Error(timeoutMessage, { cause: error });
|
|
469
|
+
throw error;
|
|
470
|
+
} finally {
|
|
471
|
+
timeoutController.abort();
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
//#endregion
|
|
475
|
+
export { request_exports as a, resolveCodexNativeSandboxBlock as c, requestCodexAppServerJson as i, resolveCodexNativeExecutionPolicy as l, readCodexAppServerUsage as n, withCodexAppServerJsonClient as o, requestCodexAppServerClientJson as r, resolveCodexNativeExecutionBlock as s, CodexAppServerScopedRequestRejectedError as t, resolveCodexNodeExecToolOverrides as u };
|