@openclaw/codex 2026.7.1 → 2026.7.2-beta.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/README.md +27 -3
- package/dist/app-server-policy-Scc-Wevo.js +49 -0
- package/dist/{attempt-notifications-BGsEIIDI.js → attempt-notifications-BFmNhqFl.js} +3 -6
- package/dist/auth-binding-C1czuHPA.js +62 -0
- package/dist/cli-metadata.js +20 -0
- package/dist/{app-server-policy-C968Kgin.js → command-formatters-Dq9InZUK.js} +39 -51
- package/dist/{command-handlers-Dv-pzAmg.js → command-handlers-IgqmL_kv.js} +161 -61
- package/dist/{compact-4mVBriKT.js → compact-DCTmg3id.js} +39 -10
- package/dist/computer-use-CPcU8TjG.js +685 -0
- package/dist/conversation-control-CGkBlfc5.js +286 -0
- package/dist/doctor-contract-api.js +120 -81
- package/dist/{provider-capabilities-CDnHbmUZ.js → dynamic-tools-C_1tEs34.js} +6109 -5725
- package/dist/harness.js +59 -15
- package/dist/index.js +1460 -269
- package/dist/{media-understanding-provider-BHOu9-Gg.js → media-understanding-provider-D31dOJwb.js} +32 -15
- package/dist/media-understanding-provider.js +1 -1
- package/dist/{models-DDmO1zwd.js → models-uh26C8QU.js} +5 -9
- package/dist/notification-correlation-KmfV4EkP.js +67 -0
- package/dist/plugin-app-cache-key-Ceb-lm2c.js +315 -0
- package/dist/{provider-zjPfx5Fs.js → rate-limits-DyXaYAxU.js} +10 -266
- package/dist/request-B_oQsCXy.js +157 -0
- package/dist/{run-attempt-FUyOjGCV.js → run-attempt-MLzoMe_m.js} +7395 -6430
- package/dist/runtime-artifact-C2ITXdhM.js +488 -0
- package/dist/{sandbox-guard-DA2TQfZW.js → sandbox-guard-D1Wky__S.js} +10 -1
- package/dist/{config-CYEDnLJ2.js → session-binding-h1mmCGnl.js} +985 -31
- package/dist/session-catalog-CEvoXWHA.js +2412 -0
- package/dist/session-cli-XsEuWb_C.js +175 -0
- package/dist/{shared-client-4ICy3U6d.js → shared-client-JiAnW6pc.js} +2193 -1319
- package/dist/{side-question-N4OaDer2.js → side-question-DqDvIwSU.js} +140 -70
- package/dist/{thread-lifecycle-qWE88Dn2.js → thread-lifecycle-CN_pPtPh.js} +1826 -1188
- package/dist/{protocol-validators-dZQ-UTOa.js → transcript-mirror-D9rTxx2P.js} +485 -2
- package/dist/transport-stdio-DXgGZ7Ib.js +88 -0
- package/dist/usage-D5Rohxoc.js +25 -0
- package/dist/{web-search-provider.runtime-BSlriav6.js → web-search-provider.runtime-CKVBn3fP.js} +3 -3
- package/npm-shrinkwrap.json +56 -30
- package/openclaw.plugin.json +177 -14
- package/package.json +8 -6
- package/dist/command-rpc-eLM_mtC7.js +0 -784
- package/dist/computer-use-Bmaz333N.js +0 -377
- package/dist/notification-correlation-Bo7KB3ks.js +0 -35
- package/dist/plugin-app-cache-key-BrhVdeEf.js +0 -98
- package/dist/prompt-overlay.js +0 -15
- package/dist/protocol-2POPqAY4.js +0 -13
- package/dist/provider-catalog.js +0 -79
- package/dist/provider-discovery.js +0 -34
- package/dist/provider.js +0 -2
- package/dist/request-BcJyl8KL.js +0 -36
- package/dist/session-binding-C1ZXdP-x.js +0 -627
package/dist/{media-understanding-provider-BHOu9-Gg.js → media-understanding-provider-D31dOJwb.js}
RENAMED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { d as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { H as mergeCodexThreadConfigs, r as buildCodexRuntimeThreadConfig } from "./thread-lifecycle-qWE88Dn2.js";
|
|
1
|
+
import { Z as isJsonObject, o as isCodexAppServerStartSelectionChangedError } from "./shared-client-JiAnW6pc.js";
|
|
2
|
+
import { _ as readCodexNotificationItem } from "./attempt-notifications-BFmNhqFl.js";
|
|
3
|
+
import { b as resolveCodexAppServerRuntimeOptions } from "./session-binding-h1mmCGnl.js";
|
|
4
|
+
import { _ as readCodexTurnCompletedNotification, d as assertCodexThreadStartResponse, f as assertCodexTurnStartResponse, m as readCodexErrorNotification } from "./transcript-mirror-D9rTxx2P.js";
|
|
5
|
+
import { r as readModelListResult } from "./models-uh26C8QU.js";
|
|
6
|
+
import { J as mergeCodexThreadConfigs, l as buildCodexRuntimeThreadConfig } from "./thread-lifecycle-CN_pPtPh.js";
|
|
8
7
|
import { validateJsonSchemaValue } from "openclaw/plugin-sdk/json-schema-runtime";
|
|
9
8
|
import fs from "node:fs/promises";
|
|
10
9
|
import path from "node:path";
|
|
@@ -30,7 +29,10 @@ const CODEX_PRIVATE_BOUNDED_THREAD_CONFIG = {
|
|
|
30
29
|
notify: []
|
|
31
30
|
};
|
|
32
31
|
async function runBoundedCodexAppServerTurn(params) {
|
|
33
|
-
const appServer = resolveCodexAppServerRuntimeOptions({
|
|
32
|
+
const appServer = resolveCodexAppServerRuntimeOptions({
|
|
33
|
+
pluginConfig: params.options.pluginConfig,
|
|
34
|
+
managedCommandOrder: params.isolation === "private-stdio" ? "package-first" : void 0
|
|
35
|
+
});
|
|
34
36
|
if (params.isolation === "configured-transport") return await runBoundedCodexAppServerTurnInWorkspace(params, appServer, { cwd: params.agentDir?.trim() || process.cwd() });
|
|
35
37
|
if (appServer.start.transport !== "stdio") throw new Error("Bounded Codex turns require stdio transport so native tools can be isolated.");
|
|
36
38
|
return await withTempWorkspace({
|
|
@@ -46,8 +48,11 @@ async function runBoundedCodexAppServerTurn(params) {
|
|
|
46
48
|
});
|
|
47
49
|
});
|
|
48
50
|
}
|
|
49
|
-
async function runBoundedCodexAppServerTurnInWorkspace(params, appServer, workspace) {
|
|
50
|
-
const
|
|
51
|
+
async function runBoundedCodexAppServerTurnInWorkspace(params, appServer, workspace, selectionAttempt = 0, timing) {
|
|
52
|
+
const totalTimeoutMs = timing?.timeoutMs ?? resolveTimerTimeoutMs(params.timeoutMs, 100, 100);
|
|
53
|
+
const deadline = timing?.deadline ?? Date.now() + totalTimeoutMs;
|
|
54
|
+
const timeoutMs = deadline - Date.now();
|
|
55
|
+
if (timeoutMs <= 0) throw new Error(`${params.taskLabel} timed out`);
|
|
51
56
|
const agentDir = params.agentDir?.trim() || void 0;
|
|
52
57
|
const startOptions = workspace.codexHome ? buildPrivateCodexAppServerStartOptions(appServer.start, workspace.codexHome) : appServer.start;
|
|
53
58
|
const ownsClient = !params.options.clientFactory;
|
|
@@ -57,7 +62,7 @@ async function runBoundedCodexAppServerTurnInWorkspace(params, appServer, worksp
|
|
|
57
62
|
agentDir,
|
|
58
63
|
config: params.config,
|
|
59
64
|
timeoutMs
|
|
60
|
-
}) : await import("./shared-client-
|
|
65
|
+
}) : await import("./shared-client-JiAnW6pc.js").then((n) => n.f).then(({ createIsolatedCodexAppServerClient }) => createIsolatedCodexAppServerClient({
|
|
61
66
|
startOptions,
|
|
62
67
|
timeoutMs,
|
|
63
68
|
authProfileId: params.profile,
|
|
@@ -69,8 +74,11 @@ async function runBoundedCodexAppServerTurnInWorkspace(params, appServer, worksp
|
|
|
69
74
|
const abortFromCaller = () => abortController.abort(params.signal?.reason ?? "aborted");
|
|
70
75
|
if (params.signal?.aborted) abortFromCaller();
|
|
71
76
|
else params.signal?.addEventListener("abort", abortFromCaller, { once: true });
|
|
72
|
-
const
|
|
77
|
+
const remainingRunMs = deadline - Date.now();
|
|
78
|
+
if (remainingRunMs <= 0) abortController.abort("timeout");
|
|
79
|
+
const timeout = setTimeout(() => abortController.abort("timeout"), Math.max(1, remainingRunMs));
|
|
73
80
|
timeout.unref?.();
|
|
81
|
+
let retrySelection = false;
|
|
74
82
|
try {
|
|
75
83
|
const model = await resolveCodexBoundedTurnModel({
|
|
76
84
|
client,
|
|
@@ -122,11 +130,19 @@ async function runBoundedCodexAppServerTurnInWorkspace(params, appServer, worksp
|
|
|
122
130
|
requestCleanup();
|
|
123
131
|
cleanup();
|
|
124
132
|
}
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (ownsClient && isCodexAppServerStartSelectionChangedError(error) && selectionAttempt === 0) retrySelection = true;
|
|
135
|
+
else throw error;
|
|
125
136
|
} finally {
|
|
126
137
|
clearTimeout(timeout);
|
|
127
138
|
params.signal?.removeEventListener("abort", abortFromCaller);
|
|
128
139
|
if (ownsClient) client.close();
|
|
129
140
|
}
|
|
141
|
+
if (retrySelection) return await runBoundedCodexAppServerTurnInWorkspace(params, appServer, workspace, selectionAttempt + 1, {
|
|
142
|
+
deadline,
|
|
143
|
+
timeoutMs: totalTimeoutMs
|
|
144
|
+
});
|
|
145
|
+
throw new Error("Codex bounded turn selection retry exited unexpectedly");
|
|
130
146
|
}
|
|
131
147
|
function resolveBoundedThreadConfig(params, workspace) {
|
|
132
148
|
const boundedConfig = mergeCodexThreadConfigs(CODEX_BOUNDED_THREAD_CONFIG, params.threadConfig) ?? CODEX_BOUNDED_THREAD_CONFIG;
|
|
@@ -305,7 +321,8 @@ function isTerminalTurn(turn) {
|
|
|
305
321
|
* Codex-backed media understanding provider for bounded image description and
|
|
306
322
|
* structured extraction turns.
|
|
307
323
|
*/
|
|
308
|
-
const
|
|
324
|
+
const CODEX_MEDIA_PROVIDER_ID = "codex";
|
|
325
|
+
const DEFAULT_CODEX_IMAGE_MODEL = "gpt-5.6-sol";
|
|
309
326
|
const DEFAULT_CODEX_IMAGE_PROMPT = "Describe the image.";
|
|
310
327
|
/**
|
|
311
328
|
* Builds the media-understanding provider that delegates image tasks to an
|
|
@@ -313,9 +330,9 @@ const DEFAULT_CODEX_IMAGE_PROMPT = "Describe the image.";
|
|
|
313
330
|
*/
|
|
314
331
|
function buildCodexMediaUnderstandingProvider(options = {}) {
|
|
315
332
|
return {
|
|
316
|
-
id:
|
|
333
|
+
id: CODEX_MEDIA_PROVIDER_ID,
|
|
317
334
|
capabilities: ["image"],
|
|
318
|
-
|
|
335
|
+
defaultModels: { image: DEFAULT_CODEX_IMAGE_MODEL },
|
|
319
336
|
describeImage: async (req) => describeCodexImages({
|
|
320
337
|
images: [{
|
|
321
338
|
buffer: req.buffer,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as buildCodexMediaUnderstandingProvider } from "./media-understanding-provider-
|
|
1
|
+
import { t as buildCodexMediaUnderstandingProvider } from "./media-understanding-provider-D31dOJwb.js";
|
|
2
2
|
export { buildCodexMediaUnderstandingProvider };
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { s as readCodexModelListResponse } from "./protocol-validators-dZQ-UTOa.js";
|
|
1
|
+
import { h as readCodexModelListResponse } from "./transcript-mirror-D9rTxx2P.js";
|
|
3
2
|
import { uniqueStrings } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
4
3
|
//#region extensions/codex/src/app-server/models.ts
|
|
5
4
|
/**
|
|
6
5
|
* Lists and normalizes models exposed by the Codex app-server `model/list`
|
|
7
6
|
* endpoint, including pagination and shared-client lease handling.
|
|
8
7
|
*/
|
|
9
|
-
var models_exports = /* @__PURE__ */ __exportAll({
|
|
10
|
-
listAllCodexAppServerModels: () => listAllCodexAppServerModels,
|
|
11
|
-
listCodexAppServerModels: () => listCodexAppServerModels,
|
|
12
|
-
readModelListResult: () => readModelListResult
|
|
13
|
-
});
|
|
14
8
|
/** Lists one Codex app-server model page using the configured auth/client options. */
|
|
15
9
|
async function listCodexAppServerModels(options = {}) {
|
|
16
10
|
return await withCodexAppServerModelClient(options, async ({ client, timeoutMs }) => requestModelListPage(client, {
|
|
@@ -46,17 +40,19 @@ async function listAllCodexAppServerModels(options = {}) {
|
|
|
46
40
|
async function withCodexAppServerModelClient(options, run) {
|
|
47
41
|
const timeoutMs = options.timeoutMs ?? 2500;
|
|
48
42
|
const useSharedClient = options.sharedClient !== false;
|
|
49
|
-
const { createIsolatedCodexAppServerClient, getLeasedSharedCodexAppServerClient, releaseLeasedSharedCodexAppServerClient } = await import("./shared-client-
|
|
43
|
+
const { createIsolatedCodexAppServerClient, getLeasedSharedCodexAppServerClient, releaseLeasedSharedCodexAppServerClient } = await import("./shared-client-JiAnW6pc.js").then((n) => n.f);
|
|
50
44
|
const client = useSharedClient ? await getLeasedSharedCodexAppServerClient({
|
|
51
45
|
startOptions: options.startOptions,
|
|
52
46
|
timeoutMs,
|
|
53
47
|
authProfileId: options.authProfileId,
|
|
48
|
+
authRequirement: options.authRequirement,
|
|
54
49
|
agentDir: options.agentDir,
|
|
55
50
|
config: options.config
|
|
56
51
|
}) : await createIsolatedCodexAppServerClient({
|
|
57
52
|
startOptions: options.startOptions,
|
|
58
53
|
timeoutMs,
|
|
59
54
|
authProfileId: options.authProfileId,
|
|
55
|
+
authRequirement: options.authRequirement,
|
|
60
56
|
agentDir: options.agentDir,
|
|
61
57
|
config: options.config
|
|
62
58
|
});
|
|
@@ -115,4 +111,4 @@ function normalizeMaxPages(value) {
|
|
|
115
111
|
return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.floor(value) : 20;
|
|
116
112
|
}
|
|
117
113
|
//#endregion
|
|
118
|
-
export {
|
|
114
|
+
export { listCodexAppServerModels as n, readModelListResult as r, listAllCodexAppServerModels as t };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Z as isJsonObject } from "./shared-client-JiAnW6pc.js";
|
|
2
|
+
import { E as resolveCodexSupervisionAppServerRuntimeOptions, b as resolveCodexAppServerRuntimeOptions, y as readCodexPluginConfig } from "./session-binding-h1mmCGnl.js";
|
|
3
|
+
import { t as buildCodexAppServerConnectionFingerprint } from "./plugin-app-cache-key-Ceb-lm2c.js";
|
|
4
|
+
//#region extensions/codex/src/app-server/binding-connection.ts
|
|
5
|
+
/** Requires the native model pair after a supervised pending branch has materialized. */
|
|
6
|
+
function requireCodexSupervisionModelSelection(binding) {
|
|
7
|
+
const model = binding.model?.trim();
|
|
8
|
+
const modelProvider = binding.modelProvider?.trim();
|
|
9
|
+
if (binding.connectionScope !== "supervision" || !model || !modelProvider) throw new Error("Codex supervised binding is missing its native model and provider; refusing request selection");
|
|
10
|
+
return {
|
|
11
|
+
model,
|
|
12
|
+
modelProvider
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/** Resolves connection and auth ownership exclusively from the private thread binding. */
|
|
16
|
+
function resolveCodexBindingAppServerConnection(params) {
|
|
17
|
+
const { binding, authProfileId, ...runtimeParams } = params;
|
|
18
|
+
const usesSupervisionConnection = binding?.connectionScope === "supervision";
|
|
19
|
+
if (usesSupervisionConnection && readCodexPluginConfig(runtimeParams.pluginConfig).supervision?.enabled !== true) throw new Error("Codex supervision is disabled; refusing to open a native user-home supervised session");
|
|
20
|
+
const appServer = (usesSupervisionConnection ? resolveCodexSupervisionAppServerRuntimeOptions : resolveCodexAppServerRuntimeOptions)(runtimeParams);
|
|
21
|
+
if (usesSupervisionConnection) {
|
|
22
|
+
const persistedFingerprint = binding.pendingSupervisionBranch?.connectionFingerprint ?? binding.appServerRuntimeFingerprint;
|
|
23
|
+
const currentFingerprint = buildCodexAppServerConnectionFingerprint(appServer, runtimeParams.agentDir);
|
|
24
|
+
if (!persistedFingerprint || persistedFingerprint !== currentFingerprint) throw new Error("Codex supervision connection changed; refusing to operate on its bound native thread");
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
appServer,
|
|
28
|
+
usesSupervisionConnection,
|
|
29
|
+
requestAuthProfileId: usesSupervisionConnection ? void 0 : authProfileId,
|
|
30
|
+
clientAuthProfileId: usesSupervisionConnection ? null : authProfileId
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region extensions/codex/src/app-server/notification-correlation.ts
|
|
35
|
+
/**
|
|
36
|
+
* Correlates Codex app-server notifications with the active thread/turn so
|
|
37
|
+
* projectors can ignore global or stale events without losing diagnostics.
|
|
38
|
+
*/
|
|
39
|
+
/** Returns true when a notification payload belongs to the exact active thread and turn. */
|
|
40
|
+
function isCodexNotificationForTurn(value, threadId, turnId) {
|
|
41
|
+
if (!isJsonObject(value)) return false;
|
|
42
|
+
return readCodexNotificationThreadId(value) === threadId && readCodexNotificationTurnId(value) === turnId;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Reads a thread id from canonical top-level or nested thread payloads.
|
|
46
|
+
* The generated v2 schemas require top-level `threadId` on turn/item-scoped
|
|
47
|
+
* notifications and define `Turn` without one, so `turn.threadId` is not a
|
|
48
|
+
* wire shape and is deliberately not read here.
|
|
49
|
+
*/
|
|
50
|
+
function readCodexNotificationThreadId(record) {
|
|
51
|
+
const thread = isJsonObject(record.thread) ? record.thread : void 0;
|
|
52
|
+
return readString(record, "threadId") ?? (thread ? readString(thread, "id") : void 0);
|
|
53
|
+
}
|
|
54
|
+
/** Reads a turn id from either top-level notification params or nested turn payloads. */
|
|
55
|
+
function readCodexNotificationTurnId(record) {
|
|
56
|
+
return readNestedTurnId(record) ?? readString(record, "turnId");
|
|
57
|
+
}
|
|
58
|
+
function readNestedTurnId(record) {
|
|
59
|
+
const turn = record.turn;
|
|
60
|
+
return isJsonObject(turn) ? readString(turn, "id") : void 0;
|
|
61
|
+
}
|
|
62
|
+
function readString(record, key) {
|
|
63
|
+
const value = record[key];
|
|
64
|
+
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { resolveCodexBindingAppServerConnection as a, requireCodexSupervisionModelSelection as i, readCodexNotificationThreadId as n, readCodexNotificationTurnId as r, isCodexNotificationForTurn as t };
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { D as resolveCodexAppServerHomeDir } from "./shared-client-JiAnW6pc.js";
|
|
2
|
+
import { S as resolveCodexAppServerUserHomeDir } from "./session-binding-h1mmCGnl.js";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { isFutureDateTimestampMs, resolveDateTimestampMs, resolveExpiresAtMsFromDurationMs } from "openclaw/plugin-sdk/number-runtime";
|
|
5
|
+
import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
8
|
+
import { OPENCLAW_VERSION, embeddedAgentLog } from "openclaw/plugin-sdk/agent-harness-runtime";
|
|
9
|
+
import { readPluginPackageVersion } from "openclaw/plugin-sdk/extension-shared";
|
|
10
|
+
//#region extensions/codex/src/app-server/app-inventory-cache.ts
|
|
11
|
+
/**
|
|
12
|
+
* Process-local cache for Codex app-server app inventories, keyed by runtime
|
|
13
|
+
* identity and safe to refresh in the background.
|
|
14
|
+
*/
|
|
15
|
+
/** Default app inventory cache freshness window. */
|
|
16
|
+
const CODEX_APP_INVENTORY_CACHE_TTL_MS = 3600 * 1e3;
|
|
17
|
+
const CODEX_TARGETED_APP_INVENTORY_LIMIT = 1e3;
|
|
18
|
+
const MAX_SERIALIZED_ERROR_MESSAGE_LENGTH = 500;
|
|
19
|
+
/** In-memory app inventory cache with coalesced refreshes per key. */
|
|
20
|
+
var CodexAppInventoryCache = class {
|
|
21
|
+
constructor(options = {}) {
|
|
22
|
+
this.entries = /* @__PURE__ */ new Map();
|
|
23
|
+
this.inFlight = /* @__PURE__ */ new Map();
|
|
24
|
+
this.refreshTokens = /* @__PURE__ */ new Map();
|
|
25
|
+
this.diagnostics = /* @__PURE__ */ new Map();
|
|
26
|
+
this.revision = 0;
|
|
27
|
+
this.ttlMs = options.ttlMs ?? CODEX_APP_INVENTORY_CACHE_TTL_MS;
|
|
28
|
+
}
|
|
29
|
+
/** Reads a snapshot and schedules refresh when missing, stale, or forced. */
|
|
30
|
+
read(params) {
|
|
31
|
+
const nowMs = resolveDateTimestampMs(params.nowMs);
|
|
32
|
+
const entry = this.entries.get(params.key);
|
|
33
|
+
if (!entry) {
|
|
34
|
+
const refreshScheduled = params.suppressRefresh ? false : this.scheduleRefresh(params);
|
|
35
|
+
return {
|
|
36
|
+
state: "missing",
|
|
37
|
+
key: params.key,
|
|
38
|
+
revision: this.revision,
|
|
39
|
+
refreshScheduled,
|
|
40
|
+
...this.diagnostics.get(params.key) ? { diagnostic: this.diagnostics.get(params.key) } : {}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const state = entry.invalidated || !isFutureDateTimestampMs(entry.expiresAtMs, { nowMs }) ? "stale" : "fresh";
|
|
44
|
+
const refreshScheduled = state === "fresh" && !params.forceRefetch ? false : this.scheduleRefresh(params);
|
|
45
|
+
return {
|
|
46
|
+
state,
|
|
47
|
+
key: params.key,
|
|
48
|
+
revision: entry.revision,
|
|
49
|
+
snapshot: stripEntryState(entry),
|
|
50
|
+
refreshScheduled,
|
|
51
|
+
...entry.lastError ? { diagnostic: entry.lastError } : {}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** Forces or joins an immediate refresh for a cache key. */
|
|
55
|
+
refreshNow(params) {
|
|
56
|
+
return this.refresh(params);
|
|
57
|
+
}
|
|
58
|
+
/** Marks a key stale and records the reason as a diagnostic. */
|
|
59
|
+
invalidate(key, reason, nowMs = Date.now()) {
|
|
60
|
+
this.revision += 1;
|
|
61
|
+
const diagnostic = {
|
|
62
|
+
message: reason,
|
|
63
|
+
atMs: nowMs
|
|
64
|
+
};
|
|
65
|
+
const entry = this.entries.get(key);
|
|
66
|
+
if (entry) {
|
|
67
|
+
entry.invalidated = true;
|
|
68
|
+
entry.lastError = diagnostic;
|
|
69
|
+
entry.revision = this.revision;
|
|
70
|
+
} else this.diagnostics.set(key, diagnostic);
|
|
71
|
+
return this.revision;
|
|
72
|
+
}
|
|
73
|
+
/** Clears all cached snapshots, diagnostics, in-flight requests, and revision state. */
|
|
74
|
+
clear() {
|
|
75
|
+
this.entries.clear();
|
|
76
|
+
this.inFlight.clear();
|
|
77
|
+
this.refreshTokens.clear();
|
|
78
|
+
this.diagnostics.clear();
|
|
79
|
+
this.revision = 0;
|
|
80
|
+
}
|
|
81
|
+
/** Returns the monotonically increasing cache revision. */
|
|
82
|
+
getRevision() {
|
|
83
|
+
return this.revision;
|
|
84
|
+
}
|
|
85
|
+
scheduleRefresh(params) {
|
|
86
|
+
if (this.inFlight.has(params.key) && !params.forceRefetch) return true;
|
|
87
|
+
const promise = this.refresh(params);
|
|
88
|
+
this.inFlight.set(params.key, promise);
|
|
89
|
+
promise.catch(() => void 0);
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
async refresh(params) {
|
|
93
|
+
const existing = this.inFlight.get(params.key);
|
|
94
|
+
if (existing && !params.forceRefetch) return existing;
|
|
95
|
+
const refreshToken = (this.refreshTokens.get(params.key) ?? 0) + 1;
|
|
96
|
+
this.refreshTokens.set(params.key, refreshToken);
|
|
97
|
+
const promise = this.refreshUncoalesced(params, refreshToken);
|
|
98
|
+
this.inFlight.set(params.key, promise);
|
|
99
|
+
try {
|
|
100
|
+
return await promise;
|
|
101
|
+
} finally {
|
|
102
|
+
if (this.inFlight.get(params.key) === promise) this.inFlight.delete(params.key);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async refreshUncoalesced(params, refreshToken) {
|
|
106
|
+
const nowMs = resolveDateTimestampMs(params.nowMs);
|
|
107
|
+
try {
|
|
108
|
+
const apps = await listAllApps(params.request, params.forceRefetch ?? false, params.targetAppIds);
|
|
109
|
+
this.revision += 1;
|
|
110
|
+
const expiresAtMs = resolveExpiresAtMsFromDurationMs(this.ttlMs, { nowMs }) ?? 0;
|
|
111
|
+
const snapshot = {
|
|
112
|
+
key: params.key,
|
|
113
|
+
apps,
|
|
114
|
+
fetchedAtMs: nowMs,
|
|
115
|
+
expiresAtMs,
|
|
116
|
+
revision: this.revision
|
|
117
|
+
};
|
|
118
|
+
if (this.refreshTokens.get(params.key) === refreshToken) {
|
|
119
|
+
this.entries.set(params.key, {
|
|
120
|
+
...snapshot,
|
|
121
|
+
invalidated: false
|
|
122
|
+
});
|
|
123
|
+
this.diagnostics.delete(params.key);
|
|
124
|
+
}
|
|
125
|
+
return snapshot;
|
|
126
|
+
} catch (error) {
|
|
127
|
+
const diagnostic = {
|
|
128
|
+
message: sanitizeErrorMessage(error instanceof Error ? error.message : String(error)),
|
|
129
|
+
atMs: nowMs
|
|
130
|
+
};
|
|
131
|
+
this.diagnostics.set(params.key, diagnostic);
|
|
132
|
+
const entry = this.entries.get(params.key);
|
|
133
|
+
if (entry) entry.lastError = diagnostic;
|
|
134
|
+
embeddedAgentLog.warn("codex app inventory refresh failed", {
|
|
135
|
+
forceRefetch: params.forceRefetch === true,
|
|
136
|
+
keyFingerprint: fingerprintInventoryCacheKey(params.key),
|
|
137
|
+
error: serializeCodexAppInventoryError(error)
|
|
138
|
+
});
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
/** Serializes a refresh failure without leaking large or sensitive error data. */
|
|
144
|
+
function serializeCodexAppInventoryError(error) {
|
|
145
|
+
const record = isRecord(error) ? error : void 0;
|
|
146
|
+
const data = record && "data" in record ? redactErrorData(record.data) : void 0;
|
|
147
|
+
return {
|
|
148
|
+
name: error instanceof Error ? error.name : typeof record?.name === "string" ? record.name : void 0,
|
|
149
|
+
message: sanitizeErrorMessage(error instanceof Error ? error.message : String(error)),
|
|
150
|
+
...typeof record?.code === "number" ? { code: record.code } : {},
|
|
151
|
+
...data !== void 0 ? { data } : {}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/** Shared app inventory cache used by Codex app-server runtime paths. */
|
|
155
|
+
const defaultCodexAppInventoryCache = new CodexAppInventoryCache();
|
|
156
|
+
/** Builds a stable cache key from build versions and runtime identity fields. */
|
|
157
|
+
function buildCodexAppInventoryCacheKey(input, openClawVersion, codexPluginVersion) {
|
|
158
|
+
return JSON.stringify({
|
|
159
|
+
openClawVersion,
|
|
160
|
+
codexPluginVersion,
|
|
161
|
+
codexHome: input.codexHome ?? null,
|
|
162
|
+
endpoint: input.endpoint ?? null,
|
|
163
|
+
runtimeIdentity: normalizeRuntimeIdentityForCacheKey(input.runtimeIdentity),
|
|
164
|
+
authProfileId: input.authProfileId ?? null,
|
|
165
|
+
accountId: input.accountId ?? null,
|
|
166
|
+
envApiKeyFingerprint: input.envApiKeyFingerprint ?? null,
|
|
167
|
+
appServerVersion: input.appServerVersion ?? null
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function normalizeRuntimeIdentityForCacheKey(value) {
|
|
171
|
+
if (!value) return null;
|
|
172
|
+
const entries = Object.entries(value).flatMap(([key, rawValue]) => {
|
|
173
|
+
const normalized = rawValue?.trim();
|
|
174
|
+
return normalized ? [[key, normalized]] : [];
|
|
175
|
+
}).toSorted(([left], [right]) => left.localeCompare(right));
|
|
176
|
+
return entries.length > 0 ? Object.fromEntries(entries) : null;
|
|
177
|
+
}
|
|
178
|
+
async function listAllApps(request, forceRefetch, targetAppIds = []) {
|
|
179
|
+
const apps = [];
|
|
180
|
+
const targetIds = new Set(targetAppIds.filter(Boolean));
|
|
181
|
+
const remainingTargetIds = new Set(targetIds);
|
|
182
|
+
const seenCursors = /* @__PURE__ */ new Set();
|
|
183
|
+
let cursor;
|
|
184
|
+
do {
|
|
185
|
+
const response = await request("app/list", {
|
|
186
|
+
cursor,
|
|
187
|
+
limit: targetIds.size > 0 ? CODEX_TARGETED_APP_INVENTORY_LIMIT : 100,
|
|
188
|
+
forceRefetch
|
|
189
|
+
});
|
|
190
|
+
apps.push(...response.data);
|
|
191
|
+
for (const app of response.data) remainingTargetIds.delete(app.id);
|
|
192
|
+
if (targetIds.size > 0 && remainingTargetIds.size === 0) break;
|
|
193
|
+
cursor = response.nextCursor;
|
|
194
|
+
if (cursor && seenCursors.has(cursor)) throw new Error(`app/list returned repeated cursor ${cursor}`);
|
|
195
|
+
if (cursor) seenCursors.add(cursor);
|
|
196
|
+
} while (cursor);
|
|
197
|
+
return apps;
|
|
198
|
+
}
|
|
199
|
+
function stripEntryState(entry) {
|
|
200
|
+
const { invalidated: _invalidated, ...snapshot } = entry;
|
|
201
|
+
return snapshot;
|
|
202
|
+
}
|
|
203
|
+
function fingerprintInventoryCacheKey(key) {
|
|
204
|
+
let hash = 0;
|
|
205
|
+
for (let index = 0; index < key.length; index += 1) hash = hash * 31 + key.charCodeAt(index) >>> 0;
|
|
206
|
+
return hash.toString(16).padStart(8, "0");
|
|
207
|
+
}
|
|
208
|
+
function truncateSerializedErrorText(value) {
|
|
209
|
+
return value.length > MAX_SERIALIZED_ERROR_MESSAGE_LENGTH ? `${truncateUtf16Safe(value, MAX_SERIALIZED_ERROR_MESSAGE_LENGTH)}...` : value;
|
|
210
|
+
}
|
|
211
|
+
function redactErrorData(value, depth = 0) {
|
|
212
|
+
if (value === void 0) return;
|
|
213
|
+
if (value === null || typeof value === "boolean" || typeof value === "number") return value;
|
|
214
|
+
if (depth > 6) return "[truncated]";
|
|
215
|
+
if (Array.isArray(value)) return value.map((entry) => redactErrorData(entry, depth + 1) ?? null);
|
|
216
|
+
if (isRecord(value)) {
|
|
217
|
+
const redacted = {};
|
|
218
|
+
for (const [key, entry] of Object.entries(value)) redacted[key] = isSensitiveErrorDataKey(key) ? "<redacted>" : redactErrorData(entry, depth + 1) ?? null;
|
|
219
|
+
return redacted;
|
|
220
|
+
}
|
|
221
|
+
if (typeof value === "string") return truncateSerializedErrorText(value);
|
|
222
|
+
if (typeof value === "bigint") return value.toString();
|
|
223
|
+
if (typeof value === "symbol") return value.description ? `Symbol(${value.description})` : "Symbol()";
|
|
224
|
+
if (typeof value === "function") return value.name ? `[function ${value.name}]` : "[function]";
|
|
225
|
+
return "[unserializable]";
|
|
226
|
+
}
|
|
227
|
+
function sanitizeErrorMessage(message) {
|
|
228
|
+
const htmlStart = message.search(/<html[\s>]/i);
|
|
229
|
+
return truncateSerializedErrorText((htmlStart >= 0 ? `${message.slice(0, htmlStart).trimEnd()} [HTML response body omitted]` : message).replace(/([?&][^=\s"'<>]*(?:api[_-]?key|authorization|cookie|credential|password|secret|token|tk)[^=\s"'<>]*=)[^&\s"'<>]+/gi, "$1<redacted>"));
|
|
230
|
+
}
|
|
231
|
+
function isSensitiveErrorDataKey(key) {
|
|
232
|
+
return /api[_-]?key|authorization|cookie|credential|password|secret|token/i.test(key);
|
|
233
|
+
}
|
|
234
|
+
//#endregion
|
|
235
|
+
//#region extensions/codex/src/app-server/plugin-app-cache-key.ts
|
|
236
|
+
/**
|
|
237
|
+
* Builds stable Codex plugin/app inventory cache keys from app-server startup,
|
|
238
|
+
* auth, account, and version inputs without storing secret material.
|
|
239
|
+
*/
|
|
240
|
+
const CODEX_PLUGIN_VERSION = readPluginPackageVersion({ require: createRequire(import.meta.url) });
|
|
241
|
+
/** Builds the full app inventory cache key for Codex plugin/app discovery. */
|
|
242
|
+
function buildCodexPluginAppCacheKey(params) {
|
|
243
|
+
return buildCodexAppInventoryCacheKey({
|
|
244
|
+
codexHome: params.runtimeIdentity?.codexHome ?? resolveCodexPluginAppCacheCodexHome(params.appServer, params.agentDir),
|
|
245
|
+
endpoint: resolveCodexPluginAppCacheEndpoint(params.appServer),
|
|
246
|
+
authProfileId: params.authProfileId,
|
|
247
|
+
accountId: params.accountId,
|
|
248
|
+
envApiKeyFingerprint: params.envApiKeyFingerprint,
|
|
249
|
+
appServerVersion: params.appServerVersion ?? params.runtimeIdentity?.serverVersion,
|
|
250
|
+
runtimeIdentity: params.runtimeIdentity
|
|
251
|
+
}, OPENCLAW_VERSION, CODEX_PLUGIN_VERSION);
|
|
252
|
+
}
|
|
253
|
+
/** Builds a durable thread-binding fingerprint for one initialized app-server runtime. */
|
|
254
|
+
function buildCodexAppServerRuntimeFingerprint(params) {
|
|
255
|
+
return JSON.stringify({
|
|
256
|
+
endpoint: resolveCodexPluginAppCacheEndpoint(params.appServer),
|
|
257
|
+
connectionClass: params.appServer.connectionClass,
|
|
258
|
+
remoteWorkspaceRoot: params.appServer.remoteWorkspaceRoot ?? null,
|
|
259
|
+
appServerVersion: params.appServerVersion ?? params.runtimeIdentity?.serverVersion ?? null,
|
|
260
|
+
runtimeIdentity: params.runtimeIdentity ?? null
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
/** Fingerprints the configured connection that owns a supervised source thread. */
|
|
264
|
+
function buildCodexAppServerConnectionFingerprint(appServer, agentDir) {
|
|
265
|
+
return JSON.stringify({
|
|
266
|
+
endpoint: resolveCodexPluginAppCacheEndpoint(appServer),
|
|
267
|
+
connectionClass: appServer.connectionClass,
|
|
268
|
+
remoteWorkspaceRoot: appServer.remoteWorkspaceRoot ?? null,
|
|
269
|
+
homeScope: appServer.start.homeScope ?? null,
|
|
270
|
+
codexHome: resolveCodexAppServerConnectionHome(appServer.start, agentDir),
|
|
271
|
+
cwd: appServer.start.cwd ?? null
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
function resolveCodexAppServerConnectionHome(start, agentDir) {
|
|
275
|
+
const configured = start.env?.CODEX_HOME?.trim();
|
|
276
|
+
if (configured) return configured;
|
|
277
|
+
if (start.transport === "unix" && (!start.url || start.url === "unix://")) return resolveCodexAppServerUserHomeDir(start.env ?? process.env);
|
|
278
|
+
if (start.transport !== "stdio") return null;
|
|
279
|
+
if (start.homeScope === "user") return resolveCodexAppServerUserHomeDir(process.env);
|
|
280
|
+
return agentDir ? resolveCodexAppServerHomeDir(agentDir) : null;
|
|
281
|
+
}
|
|
282
|
+
/** Serializes app-server endpoint identity, including credential fingerprints. */
|
|
283
|
+
function resolveCodexPluginAppCacheEndpoint(appServer) {
|
|
284
|
+
return JSON.stringify({
|
|
285
|
+
transport: appServer.start.transport,
|
|
286
|
+
command: appServer.start.command,
|
|
287
|
+
args: appServer.start.args,
|
|
288
|
+
url: appServer.start.url ?? null,
|
|
289
|
+
credentialFingerprint: fingerprintCodexPluginAppCacheCredentials(appServer.start)
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
/** Resolves the CODEX_HOME value that scopes local app-server inventory. */
|
|
293
|
+
function resolveCodexPluginAppCacheCodexHome(appServer, agentDir) {
|
|
294
|
+
const configuredCodexHome = appServer.start.env?.CODEX_HOME?.trim();
|
|
295
|
+
if (configuredCodexHome) return configuredCodexHome;
|
|
296
|
+
return appServer.start.transport === "stdio" && agentDir ? resolveCodexAppServerHomeDir(agentDir) : void 0;
|
|
297
|
+
}
|
|
298
|
+
function fingerprintCodexPluginAppCacheCredentials(startOptions) {
|
|
299
|
+
const authToken = startOptions.authToken ?? "";
|
|
300
|
+
const headers = Object.entries(startOptions.headers).map(([key, value]) => [key.toLowerCase(), value]).toSorted(([left], [right]) => left.localeCompare(right));
|
|
301
|
+
if (!authToken && headers.length === 0) return null;
|
|
302
|
+
const hash = createHash("sha256");
|
|
303
|
+
hash.update("openclaw:codex:plugin-app-cache-credentials:v1");
|
|
304
|
+
hash.update("\0");
|
|
305
|
+
hash.update(authToken);
|
|
306
|
+
for (const [key, value] of headers) {
|
|
307
|
+
hash.update("\0");
|
|
308
|
+
hash.update(key);
|
|
309
|
+
hash.update("\0");
|
|
310
|
+
hash.update(value);
|
|
311
|
+
}
|
|
312
|
+
return `sha256:${hash.digest("hex")}`;
|
|
313
|
+
}
|
|
314
|
+
//#endregion
|
|
315
|
+
export { serializeCodexAppInventoryError as a, defaultCodexAppInventoryCache as i, buildCodexAppServerRuntimeFingerprint as n, buildCodexPluginAppCacheKey as r, buildCodexAppServerConnectionFingerprint as t };
|