@openclaw/codex 2026.9.4 → 2026.9.5
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/assets/activity.svg +30 -0
- package/assets/icon.png +0 -0
- package/dist/.setup/account-usage-runtime-C2MOIvfq.mjs +75 -0
- package/dist/{apply-CvT8tW5i.js → .setup/apply-CJ0ZfmBG.mjs} +11 -11
- package/dist/.setup/async-questions-DdhOCwGi.mjs +27 -0
- package/dist/{attempt-client-cleanup-DKHzbwt5.js → .setup/attempt-client-cleanup-BpYKdTA0.mjs} +29 -14
- package/dist/{attempt-context-D44yeDII.js → .setup/attempt-context-VXVwTCfS.mjs} +5 -5
- package/dist/.setup/attempt-terminal-gZrxQ35N.mjs +5 -0
- package/dist/{auth-binding-CWlKVccJ.js → .setup/auth-binding-DhLWa_7K.mjs} +1 -1
- package/dist/{auth-cache-key-7orQae_j.js → .setup/auth-cache-key-QirmgiCo.mjs} +3 -3
- package/dist/{auth-profile-CwzO4_RG.js → .setup/auth-profile-WqZtZfXN.mjs} +1 -1
- package/dist/.setup/binding-connection-Bm38niE8.mjs +50 -0
- package/dist/.setup/binding-connection.runtime-CnRMC0ta.mjs +48 -0
- package/dist/{bounded-turn-C_Hneydj.js → .setup/bounded-turn-BtlZcivC.mjs} +16 -11
- package/dist/{build-state-BCmg9-5p.js → .setup/build-state-Xx9ybZqa.mjs} +1 -1
- package/dist/{capabilities-8vx68WLH.js → .setup/capabilities-_vXcZGSx.mjs} +1 -1
- package/dist/{client-B57KWPQx.js → .setup/client-vXs2929Q.mjs} +332 -163
- package/dist/{command-dispatch-BpduNGVf.js → .setup/command-dispatch-naHIZwwF.mjs} +3 -3
- package/dist/{command-formatters-lxlkNZgU.js → .setup/command-formatters-CGEkdawF.mjs} +2 -2
- package/dist/{command-handlers-tiL9iWj7.js → .setup/command-handlers-BtAJEW1X.mjs} +59 -42
- package/dist/{command-rpc-CR5EOEZX.js → .setup/command-rpc-DHFpn4le.mjs} +22 -13
- package/dist/{compact-B_H3AOd7.js → .setup/compact-C3i3qlzj.mjs} +28 -43
- package/dist/{config-oIORaQ5T.js → .setup/config-CedDWjM-.mjs} +5 -4
- package/dist/{config-options-CXMq1T-C.js → .setup/config-options-BsanJ8QG.mjs} +6 -418
- package/dist/{protocol-5bh1G-H7.js → .setup/config-parsing-CcB9iPoq.mjs} +9 -51
- package/dist/{config-runtime-D0zGNIHu.js → .setup/config-runtime-CeAhl_h4.mjs} +2 -2
- package/dist/.setup/config-security-BRQ2mgW9.mjs +465 -0
- package/dist/{conversation-binding-DsB4-O7U.js → .setup/conversation-binding-DhzrpTM6.mjs} +23 -21
- package/dist/{conversation-binding-data-BiodpIzq.js → .setup/conversation-binding-data-CrcyZk6O.mjs} +1 -1
- package/dist/{conversation-control-CtUu1b3m.js → .setup/conversation-control-DN53ns41.mjs} +17 -13
- package/dist/.setup/cyber-failover-DYwbmf1o.mjs +123 -0
- package/dist/.setup/cyber-failover-notice-e9G3J9-e.mjs +17 -0
- package/dist/{dynamic-tools-CmN5RAip.js → .setup/dynamic-tools-D16lOp67.mjs} +101 -55
- package/dist/{effective-mcp-catalog-Bd73bqA8.js → .setup/effective-mcp-catalog-K6kLCN8X.mjs} +3 -3
- package/dist/{ephemeral-turn-D78_VmzO.js → .setup/ephemeral-turn-R1gA8Sn6.mjs} +4 -5
- package/dist/{event-projector-assistant-message-BmBM4qBV.js → .setup/event-projector-assistant-message-DNUR1s0A.mjs} +6 -3
- package/dist/{event-projector-items-5VhsECCO.js → .setup/event-projector-items-DyTQ_XqL.mjs} +1 -1
- package/dist/{attempt-notifications-C9XufG6l.js → .setup/event-projector-usage-C7Ntzs-f.mjs} +102 -9
- package/dist/{harness-C7rRa7bm.js → .setup/harness-rxaaoN-o.mjs} +74 -20
- package/dist/{inference-context-Dr_mzvk4.js → .setup/inference-context-fulhZuz8.mjs} +1 -1
- package/dist/{inference-proxy-HGXKUIre.js → .setup/inference-proxy-CC15HuSi.mjs} +4 -4
- package/dist/{isolated-completion-DWVb5U2J.js → .setup/isolated-completion-B6srt48J.mjs} +7 -7
- package/dist/{launch-args-RXQwn8zV.js → .setup/launch-args-DnMak49W.mjs} +22 -1
- package/dist/{managed-binary-D22rNEcR.js → .setup/managed-binary-DP6Rib3P.mjs} +2 -2
- package/dist/{managed-thread-store-D1t5jh3G.js → .setup/managed-thread-store-BMqgThVL.mjs} +48 -14
- package/dist/{model-catalog-Dq2n8f_p.js → .setup/model-catalog-DkvUuBey.mjs} +35 -10
- package/dist/{models-PCKOim-h.js → .setup/models-BDFgm_G-.mjs} +3 -3
- package/dist/.setup/native-auth-BLZGqFjw.mjs +57 -0
- package/dist/{native-subagent-history-DjtPloaU.js → .setup/native-subagent-history-YXaL6dMd.mjs} +24 -29
- package/dist/.setup/native-subagent-monitor-B1hxzIOy.mjs +5031 -0
- package/dist/{native-subagent-task-ids-BzTdT0Uw.js → .setup/native-subagent-task-ids-DsuOonKv.mjs} +32 -8
- package/dist/{node-cli-sessions-DKaOmVUh.js → .setup/node-cli-sessions-Cl8b2ZF3.mjs} +1 -1
- package/dist/{node-exec-server.runtime-Cl2vapEi.js → .setup/node-exec-server.runtime-BaViBKNz.mjs} +3 -3
- package/dist/{plan-7uG-Fp36.js → .setup/plan-xD7WKYTM.mjs} +64 -48
- package/dist/{plugin-activation-BYQculil.js → .setup/plugin-activation-r8nq5Jzp.mjs} +3 -3
- package/dist/{plugin-app-cache-key-d0eKxy7b.js → .setup/plugin-app-cache-key-BOxKP7db.mjs} +29 -25
- package/dist/{plugin-approval-roundtrip-Bz3FT8W5.js → .setup/plugin-approval-roundtrip-CjfzafAZ.mjs} +1 -1
- package/dist/{plugin-inventory-oL4Na1ZG.js → .setup/plugin-inventory-DUle8DLz.mjs} +7 -6
- package/dist/{plugin-metadata-cache-ClPJpRio.js → .setup/plugin-metadata-cache-DsS5buNa.mjs} +29 -14
- package/dist/{provider-capabilities-BvCUL69A.js → .setup/provider-capabilities-B8J4Dy-O.mjs} +2 -2
- package/dist/{provider-MQ8PVkuE.js → .setup/provider-fFh_-VR3.mjs} +4 -4
- package/dist/{rate-limits-CBMmWBr9.js → .setup/rate-limits-DOEGYRNs.mjs} +90 -46
- package/dist/{request-B7hEkBGq.js → .setup/request-BioXJLYa.mjs} +113 -33
- package/dist/.setup/run-attempt-lifecycle-B7JbY4-F.mjs +71 -0
- package/dist/{run-attempt-CvsAAGa0.js → .setup/run-attempt-rlA07pUv.mjs} +580 -498
- package/dist/{runtime-artifact-BJ0rXBZ_.js → .setup/runtime-artifact-Dy38Z5iU.mjs} +2 -2
- package/dist/{sandbox-guard-BxgyoM8M.js → .setup/sandbox-guard-BBP-RbTf.mjs} +3 -3
- package/dist/{session-binding-CI8UuilT.js → .setup/session-binding-_0W_fHRr.mjs} +46 -64
- package/dist/{session-binding-record-Bcvslnhf.js → .setup/session-binding-record-TH3xA0zj.mjs} +181 -3
- package/dist/.setup/session-binding-sidecars-CKYEcfNn.mjs +543 -0
- package/dist/{session-catalog-adoption-tcZi1IfX.js → .setup/session-catalog-adoption-CR_whkEW.mjs} +6 -6
- package/dist/{session-catalog-archive-CwKg8Xz2.js → .setup/session-catalog-archive-CwZaPacf.mjs} +6 -6
- package/dist/.setup/session-catalog-events-jMcYfQyd.mjs +250 -0
- package/dist/.setup/session-catalog-fUdWDx-U.mjs +2464 -0
- package/dist/.setup/session-catalog-index-B141u15s.mjs +1070 -0
- package/dist/.setup/session-catalog-index-order-Cc5BzlQr.mjs +48 -0
- package/dist/.setup/session-catalog-index-state-BAuDztHN.mjs +180 -0
- package/dist/{thread-history-page-D0JIp48V.js → .setup/session-catalog-native-projection-ChV3cCtm.mjs} +206 -95
- package/dist/{session-catalog-node-adoption-B1tgDW-m.js → .setup/session-catalog-node-adoption-BVRsYOSh.mjs} +3 -3
- package/dist/{session-catalog-node-continue-Ci-DXyJP.js → .setup/session-catalog-node-continue-Dowv8osw.mjs} +7 -7
- package/dist/.setup/session-catalog-projection-C1Bj9Jl-.mjs +414 -0
- package/dist/{session-cli-DNN_jhGc.js → .setup/session-cli-DIj-IE-E.mjs} +4 -4
- package/dist/{session-history-Cz-tOOYj.js → .setup/session-history-C--SrLI8.mjs} +10 -5
- package/dist/{session-history-import-DwyijFI6.js → .setup/session-history-import-JHXT5Xfi.mjs} +4 -4
- package/dist/{session-history-read-cxPUxyVV.js → .setup/session-history-read-B3ZfSUbF.mjs} +2 -2
- package/dist/{session-history.worker-BeK1YOyT.js → .setup/session-history.worker-CpNj7H_P.mjs} +5 -6
- package/dist/{session-initialization-Ct0_Hzmg.js → .setup/session-initialization-DH1z6fXn.mjs} +2 -2
- package/dist/{session-permission-policy-BBmXA8Eg.js → .setup/session-permission-policy-DhurXY0l.mjs} +2 -2
- package/dist/{session-retirement-B2YfbAAT.js → .setup/session-retirement-CU87AOg9.mjs} +6 -6
- package/dist/{settled-turn-context-Du6gdUDd.js → .setup/settled-turn-context-fmwouT5I.mjs} +2 -2
- package/dist/{settled-turn-finalizer-Dn91stmc.js → .setup/settled-turn-finalizer-CiY2bLFK.mjs} +9 -9
- package/dist/{shared-client-CscigXXL.js → .setup/shared-client-BpTtuLQ5.mjs} +286 -145
- package/dist/{side-question-BGMJQf4U.js → .setup/side-question-DSCZyoBD.mjs} +64 -47
- package/dist/{source-CElXU0Oy.js → .setup/source-Bjp4UQij.mjs} +7 -6
- package/dist/{thread-archive-guard-DfpBr-Sz.js → .setup/thread-archive-guard-jmecf6OJ.mjs} +1 -1
- package/dist/.setup/thread-history-page-BTx-4xsg.mjs +83 -0
- package/dist/{thread-lifecycle-DXl1-I6b.js → .setup/thread-lifecycle-Cik28qWn.mjs} +256 -128
- package/dist/{thread-ownership-BsDRTsyp.js → .setup/thread-ownership-skomxnIt.mjs} +4 -4
- package/dist/{thread-policy-BuEQfE0g.js → .setup/thread-policy-Cjs4B8xf.mjs} +2 -2
- package/dist/{thread-resume-DsDOZpFg.js → .setup/thread-resume-BkNpj9Pz.mjs} +8 -5
- package/dist/.setup/timeout-DZF05XrR.mjs +63 -0
- package/dist/{transcript-history-projection-v17wXgdK.js → .setup/transcript-history-projection-DHNBDhCU.mjs} +8 -3
- package/dist/{transcript-mirror-C5CKgNy6.js → .setup/transcript-mirror-D4qp_leP.mjs} +15 -6
- package/dist/{transcript-mirror-attestation-DibE0krH.js → .setup/transcript-mirror-attestation-CzM-94NC.mjs} +4 -1
- package/dist/{transport-stdio-BGjHoYLr.js → .setup/transport-stdio-Cmx94Oiy.mjs} +149 -44
- package/dist/{upstream-session-fork-BZerMte_.js → .setup/upstream-session-fork-D3UKxgVD.mjs} +27 -26
- package/dist/{usage-tCk-mg_x.js → .setup/usage-BOgBEKso.mjs} +4 -4
- package/dist/.setup/usage-limit-error-C0ow7DOc.mjs +166 -0
- package/dist/{version-omm6IPI3.js → .setup/version-CoqzXPgK.mjs} +1 -1
- package/dist/{web-search-provider.runtime-B7bGbGWq.js → .setup/web-search-provider.runtime-CTGuJt6i.mjs} +3 -3
- package/dist/api.js +6 -6
- package/dist/cli-metadata.js +1 -1
- package/dist/doctor-contract-api.js +8 -528
- package/dist/harness.js +1 -1
- package/dist/index.js +123 -83
- package/dist/media-understanding-provider.js +3 -3
- package/dist/migration-provider-api.js +1 -1
- package/dist/native-tool-policy.js +12 -0
- package/dist/provider-discovery.js +18 -0
- package/dist/session-history-worker-runtime.js +23 -5
- package/dist/session-history.worker.js +2 -2
- package/dist/web-search-contract-api.js +1 -1
- package/openclaw.plugin.json +354 -69
- package/package.json +11 -8
- package/dist/binding-connection-D3udKbIE.js +0 -60
- package/dist/event-projector-usage-BfXmpOec.js +0 -102
- package/dist/native-subagent-history-owner-Pcp7JuVF.js +0 -34
- package/dist/native-subagent-monitor-fQ7eIXEf.js +0 -2978
- package/dist/rpc-error-ttN_QjEm.js +0 -30
- package/dist/session-catalog-ct-AH01I.js +0 -1477
- package/dist/session-catalog-home-id-CwhLdC03.js +0 -18
- package/dist/session-catalog-provenance-D-dIfRAH.js +0 -96
- package/dist/timeout-BVw8aaM1.js +0 -33
- package/dist/{auth-profile-selection-DFu9e167.js → .setup/auth-profile-selection-DFu9e167.mjs} +0 -0
- package/dist/{config-utils-DujwEnhg.js → .setup/config-utils-DujwEnhg.mjs} +0 -0
- package/dist/{context-compaction-activity-CMla5FPJ.js → .setup/context-compaction-activity-CMla5FPJ.mjs} +0 -0
- package/dist/{elicitation-input-DPoK8F7w.js → .setup/elicitation-input-DPoK8F7w.mjs} +0 -0
- package/dist/{history-rejection-B4nOXNXF.js → .setup/history-rejection-B4nOXNXF.mjs} +0 -0
- package/dist/{image-payload-sanitizer-tupAr-2o.js → .setup/image-payload-sanitizer-tupAr-2o.mjs} +0 -0
- package/dist/{incognito-session-uhrBF6wJ.js → .setup/incognito-session-uhrBF6wJ.mjs} +0 -0
- package/dist/{local-runtime-attribution-B_2mnqhb.js → .setup/local-runtime-attribution-B_2mnqhb.mjs} +0 -0
- package/dist/{native-execution-policy-umd0tgh4.js → .setup/native-execution-policy-YBMHSzC4.mjs} +1 -1
- /package/dist/{plugin-marketplace-discovery-P-Vndfqq.js → .setup/plugin-marketplace-discovery-P-Vndfqq.mjs} +0 -0
- /package/dist/{rolldown-runtime-8H4AJuhK.js → .setup/rolldown-runtime-8H4AJuhK.mjs} +0 -0
- /package/dist/{session-binding-meta-B7aEMU7g.js → .setup/session-binding-meta-B7aEMU7g.mjs} +0 -0
- /package/dist/{session-upstream-marker-D15C9NHp.js → .setup/session-upstream-marker-D15C9NHp.mjs} +0 -0
- /package/dist/{upstream-prompt-provenance-LphB8slG.js → .setup/upstream-prompt-provenance-LphB8slG.mjs} +0 -0
- /package/dist/{web-search-provider.shared-BrZmlqyR.js → .setup/web-search-provider.shared-BrZmlqyR.mjs} +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { m as isJsonObject } from "./config-security-BRQ2mgW9.mjs";
|
|
2
|
+
import { normalizeOptionalString, parseStrictFiniteNumber } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
3
|
+
import { z } from "zod";
|
|
3
4
|
import { MAX_DATE_TIMESTAMP_MS, resolveExpiresAtMsFromEpochSeconds } from "openclaw/plugin-sdk/number-runtime";
|
|
4
5
|
import { expectDefined } from "openclaw/plugin-sdk/expect-runtime";
|
|
5
6
|
import { PROVIDER_LABELS, clampPercent } from "openclaw/plugin-sdk/provider-usage";
|
|
@@ -19,6 +20,49 @@ const WEEKLY_WINDOW_MINUTES = 7 * DAY_WINDOW_MINUTES;
|
|
|
19
20
|
const WEEKLY_RESET_GAP_MS = 3 * ONE_DAY_MS;
|
|
20
21
|
const CODEX_USAGE_LIMIT_MESSAGE_PREFIX = "You've reached your Codex subscription usage limit.";
|
|
21
22
|
const CODEX_USAGE_LIMIT_STATE_MISMATCH_MESSAGE = "Codex rejected the request with a usage-limit error, but its current account usage does not report an exhausted limit.";
|
|
23
|
+
const optionalNumber = z.number().optional().catch(void 0);
|
|
24
|
+
const optionalBoolean = z.boolean().optional().catch(void 0);
|
|
25
|
+
const rateLimitWindowSchema = z.object({
|
|
26
|
+
usedPercent: optionalNumber,
|
|
27
|
+
used_percent: optionalNumber,
|
|
28
|
+
resetsAt: optionalNumber,
|
|
29
|
+
resets_at: optionalNumber,
|
|
30
|
+
windowDurationMins: optionalNumber,
|
|
31
|
+
window_duration_mins: optionalNumber,
|
|
32
|
+
windowMinutes: optionalNumber,
|
|
33
|
+
window_minutes: optionalNumber
|
|
34
|
+
}).transform((window) => {
|
|
35
|
+
const resetsAt = window.resetsAt ?? window.resets_at;
|
|
36
|
+
return {
|
|
37
|
+
usedPercent: window.usedPercent ?? window.used_percent,
|
|
38
|
+
resetsAt,
|
|
39
|
+
resetsAtMs: resolveExpiresAtMsFromEpochSeconds(resetsAt, { maxMs: MAX_DATE_TIMESTAMP_MS }) ?? 0,
|
|
40
|
+
windowDurationMins: window.windowDurationMins ?? window.window_duration_mins ?? window.windowMinutes ?? window.window_minutes
|
|
41
|
+
};
|
|
42
|
+
}).optional().catch(void 0);
|
|
43
|
+
const creditsSchema = z.object({
|
|
44
|
+
hasCredits: optionalBoolean,
|
|
45
|
+
has_credits: optionalBoolean,
|
|
46
|
+
unlimited: optionalBoolean,
|
|
47
|
+
balance: z.preprocess(parseStrictFiniteNumber, optionalNumber)
|
|
48
|
+
}).transform((credits) => ({
|
|
49
|
+
hasCredits: credits.hasCredits ?? credits.has_credits,
|
|
50
|
+
unlimited: credits.unlimited,
|
|
51
|
+
balance: credits.balance
|
|
52
|
+
})).optional().catch(void 0);
|
|
53
|
+
const rateLimitSnapshotSchema = z.looseObject({
|
|
54
|
+
primary: rateLimitWindowSchema,
|
|
55
|
+
secondary: rateLimitWindowSchema,
|
|
56
|
+
credits: creditsSchema
|
|
57
|
+
}).transform((snapshot) => ({
|
|
58
|
+
primary: snapshot.primary,
|
|
59
|
+
secondary: snapshot.secondary,
|
|
60
|
+
credits: snapshot.credits,
|
|
61
|
+
limitId: normalizeOptionalString(snapshot.limitId) ?? normalizeOptionalString(snapshot.limit_id),
|
|
62
|
+
limitName: normalizeOptionalString(snapshot.limitName) ?? normalizeOptionalString(snapshot.limit_name),
|
|
63
|
+
planType: normalizeOptionalString(snapshot.planType) ?? normalizeOptionalString(snapshot.plan_type),
|
|
64
|
+
rateLimitReachedType: normalizeOptionalString(snapshot.rateLimitReachedType) ?? normalizeOptionalString(snapshot.rate_limit_reached_type)
|
|
65
|
+
}));
|
|
22
66
|
/** Enriches Codex usage-limit failures with reset timing and recovery guidance. */
|
|
23
67
|
function formatCodexUsageLimitErrorMessage(params) {
|
|
24
68
|
const message = normalizeOptionalString(params.message);
|
|
@@ -98,16 +142,39 @@ function summarizeCodexAccountUsage(value, nowMs = Date.now()) {
|
|
|
98
142
|
};
|
|
99
143
|
}
|
|
100
144
|
/** Converts Codex app-server rate-limit payloads into OpenAI/Codex usage windows. */
|
|
101
|
-
function buildCodexAppServerUsageSnapshot(value) {
|
|
102
|
-
const
|
|
145
|
+
function buildCodexAppServerUsageSnapshot(value, options = {}) {
|
|
146
|
+
const snapshots = collectCodexRateLimitSnapshots(value);
|
|
147
|
+
const snapshot = snapshots.find(isCodexLimitSnapshot) ?? snapshots[0];
|
|
103
148
|
const entries = snapshot ? readWindowEntries(snapshot) : [];
|
|
104
149
|
const windows = entries.map((entry) => readProviderUsageWindow(entry, entries)).filter((window) => Boolean(window));
|
|
105
|
-
|
|
150
|
+
const result = {
|
|
106
151
|
provider: "openai",
|
|
107
152
|
displayName: PROVIDER_LABELS.openai,
|
|
108
153
|
windows,
|
|
109
154
|
...snapshot ? { plan: resolveCodexProviderUsagePlan(snapshot) } : {}
|
|
110
155
|
};
|
|
156
|
+
if (options.accountDetails && snapshot) {
|
|
157
|
+
result.plan = snapshot.planType;
|
|
158
|
+
for (const extra of snapshots) {
|
|
159
|
+
if (extra === snapshot) continue;
|
|
160
|
+
const extraEntries = readWindowEntries(extra);
|
|
161
|
+
for (const entry of extraEntries) {
|
|
162
|
+
const window = readProviderUsageWindow(entry, extraEntries);
|
|
163
|
+
if (window) windows.push({
|
|
164
|
+
...window,
|
|
165
|
+
groupLabel: formatLimitLabel(extra)
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const credits = snapshot.credits;
|
|
170
|
+
const balance = credits?.balance;
|
|
171
|
+
if (balance !== void 0 && balance >= 0 && credits?.unlimited !== true) result.billing = [{
|
|
172
|
+
type: "balance",
|
|
173
|
+
amount: balance,
|
|
174
|
+
unit: "credits"
|
|
175
|
+
}];
|
|
176
|
+
}
|
|
177
|
+
return result;
|
|
111
178
|
}
|
|
112
179
|
function isCodexUsageLimitError(codexErrorInfo) {
|
|
113
180
|
if (codexErrorInfo === "usageLimitExceeded") return true;
|
|
@@ -117,7 +184,7 @@ function isCodexUsageLimitError(codexErrorInfo) {
|
|
|
117
184
|
return false;
|
|
118
185
|
}
|
|
119
186
|
function selectNextRateLimitReset(value, nowMs) {
|
|
120
|
-
const futureWindows = collectCodexRateLimitSnapshots(value).flatMap((snapshot) => LIMIT_WINDOW_KEYS.flatMap((key) =>
|
|
187
|
+
const futureWindows = collectCodexRateLimitSnapshots(value).flatMap((snapshot) => LIMIT_WINDOW_KEYS.flatMap((key) => snapshot[key] ?? [])).filter((window) => window.resetsAtMs > nowMs);
|
|
121
188
|
if (futureWindows.length === 0) return;
|
|
122
189
|
const exhaustedWindows = futureWindows.filter((window) => window.usedPercent !== void 0 && window.usedPercent >= 100);
|
|
123
190
|
return (exhaustedWindows.length > 0 ? exhaustedWindows : futureWindows).toSorted((left, right) => left.resetsAtMs - right.resetsAtMs)[0];
|
|
@@ -130,10 +197,10 @@ function selectBlockingRateLimitReset(value, nowMs) {
|
|
|
130
197
|
function summarizeRateLimitSnapshot(snapshot, nowMs) {
|
|
131
198
|
const label = formatLimitLabel(snapshot);
|
|
132
199
|
const windows = LIMIT_WINDOW_KEYS.flatMap((key) => {
|
|
133
|
-
const window =
|
|
200
|
+
const window = snapshot[key];
|
|
134
201
|
return window ? [formatRateLimitWindow(key, window, nowMs)] : [];
|
|
135
202
|
});
|
|
136
|
-
const reachedType =
|
|
203
|
+
const reachedType = snapshot.rateLimitReachedType;
|
|
137
204
|
const suffix = reachedType ? ` (${formatReachedType(reachedType)})` : "";
|
|
138
205
|
if (windows.length > 0) return `${label}: ${windows.join(" · ")}${suffix}`;
|
|
139
206
|
if (reachedType) return `${label}: ${formatReachedType(reachedType)}`;
|
|
@@ -150,7 +217,7 @@ function collectRateLimitSnapshots(value, snapshots, seen) {
|
|
|
150
217
|
}
|
|
151
218
|
if (!isJsonObject(value)) return;
|
|
152
219
|
if (isRateLimitSnapshot(value)) {
|
|
153
|
-
addRateLimitSnapshot(value, snapshots, seen);
|
|
220
|
+
addRateLimitSnapshot(rateLimitSnapshotSchema.parse(value), snapshots, seen);
|
|
154
221
|
return;
|
|
155
222
|
}
|
|
156
223
|
const byLimitId = value.rateLimitsByLimitId;
|
|
@@ -171,8 +238,8 @@ function sortedRateLimitKeys(keys) {
|
|
|
171
238
|
}
|
|
172
239
|
function addRateLimitSnapshot(snapshot, snapshots, seen) {
|
|
173
240
|
const signature = [
|
|
174
|
-
|
|
175
|
-
|
|
241
|
+
snapshot.limitId ?? "",
|
|
242
|
+
snapshot.limitName ?? "",
|
|
176
243
|
formatWindowSignature(snapshot.primary),
|
|
177
244
|
formatWindowSignature(snapshot.secondary)
|
|
178
245
|
].join("|");
|
|
@@ -183,24 +250,8 @@ function addRateLimitSnapshot(snapshot, snapshots, seen) {
|
|
|
183
250
|
function isRateLimitSnapshot(value) {
|
|
184
251
|
return isJsonObject(value.primary) || isJsonObject(value.secondary) || value.rateLimitReachedType !== void 0 || value.rate_limit_reached_type !== void 0 || value.limitId !== void 0 || value.limit_id !== void 0 || value.limitName !== void 0 || value.limit_name !== void 0;
|
|
185
252
|
}
|
|
186
|
-
function readRateLimitWindow(snapshot, key) {
|
|
187
|
-
const window = snapshot[key];
|
|
188
|
-
if (!isJsonObject(window)) return;
|
|
189
|
-
const resetsAt = asFiniteNumber(window.resetsAt) ?? asFiniteNumber(window.resets_at);
|
|
190
|
-
return {
|
|
191
|
-
resetsAtMs: resolveExpiresAtMsFromEpochSeconds(resetsAt, { maxMs: MAX_DATE_TIMESTAMP_MS }) ?? 0,
|
|
192
|
-
...readOptionalNumberField(window, "usedPercent", "used_percent"),
|
|
193
|
-
...readOptionalNumberField(window, "windowDurationMins", "window_duration_mins", "windowMinutes", "window_minutes")
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
253
|
function snapshotHasDisplayableData(snapshot) {
|
|
197
|
-
|
|
198
|
-
return readWindowEntries(snapshot).some((entry) => entry.window.usedPercent !== void 0 || entry.window.resetsAtMs > 0);
|
|
199
|
-
}
|
|
200
|
-
function readOptionalNumberField(record, ...keys) {
|
|
201
|
-
const value = keys.map((key) => asFiniteNumber(record[key])).find((entry) => entry !== void 0);
|
|
202
|
-
if (value === void 0) return {};
|
|
203
|
-
return keys.some((key) => key.toLowerCase().includes("window")) ? { windowDurationMins: value } : { usedPercent: value };
|
|
254
|
+
return Boolean(snapshot.rateLimitReachedType) || readWindowEntries(snapshot).some((entry) => entry.window.usedPercent !== void 0 || entry.window.resetsAtMs > 0);
|
|
204
255
|
}
|
|
205
256
|
function formatRateLimitWindow(key, window, nowMs) {
|
|
206
257
|
return `${key} ${formatRateLimitWindowDetails(window, nowMs)}`;
|
|
@@ -209,7 +260,7 @@ function formatRateLimitWindowDetails(window, nowMs) {
|
|
|
209
260
|
return `${window.usedPercent === void 0 ? "usage unknown" : `${Math.max(0, 100 - Math.round(window.usedPercent))}% left`}${window.resetsAtMs > nowMs ? ` ⏱${formatResetDuration(window.resetsAtMs, nowMs)}` : ""}`;
|
|
210
261
|
}
|
|
211
262
|
function formatLimitLabel(snapshot) {
|
|
212
|
-
const label =
|
|
263
|
+
const label = snapshot.limitName ?? snapshot.limitId;
|
|
213
264
|
if (!label || label === CODEX_LIMIT_ID) return "Codex";
|
|
214
265
|
return label.replace(/[_-]+/gu, " ").replace(/\s+/gu, " ").trim();
|
|
215
266
|
}
|
|
@@ -223,15 +274,10 @@ function formatAccountResetTime(resetsAtMs, nowMs) {
|
|
|
223
274
|
return `${formatCalendarResetTime(resetsAtMs, nowMs)} (in ${formatRelativeDuration(resetsAtMs - nowMs)})`;
|
|
224
275
|
}
|
|
225
276
|
function snapshotHasLimitBlock(snapshot) {
|
|
226
|
-
return Boolean(
|
|
277
|
+
return Boolean(snapshot.rateLimitReachedType ?? readWindowEntries(snapshot).some((entry) => entry.window.usedPercent !== void 0 && entry.window.usedPercent >= 100));
|
|
227
278
|
}
|
|
228
279
|
function isCodexLimitSnapshot(snapshot) {
|
|
229
|
-
|
|
230
|
-
return !id || id === CODEX_LIMIT_ID;
|
|
231
|
-
}
|
|
232
|
-
function selectCodexProviderUsageSnapshot(value) {
|
|
233
|
-
const snapshots = collectCodexRateLimitSnapshots(value);
|
|
234
|
-
return snapshots.find(isCodexLimitSnapshot) ?? snapshots[0];
|
|
280
|
+
return !snapshot.limitId || snapshot.limitId === CODEX_LIMIT_ID;
|
|
235
281
|
}
|
|
236
282
|
function readProviderUsageWindow(entry, entries) {
|
|
237
283
|
const { window } = entry;
|
|
@@ -252,16 +298,15 @@ function formatProviderUsageWindowLabel(entry, entries) {
|
|
|
252
298
|
return entry.key === "primary" ? "Short" : "Long";
|
|
253
299
|
}
|
|
254
300
|
function resolveCodexProviderUsagePlan(snapshot) {
|
|
255
|
-
const plan =
|
|
256
|
-
const creditSummary = formatCodexCreditSummary(
|
|
301
|
+
const plan = snapshot.planType;
|
|
302
|
+
const creditSummary = formatCodexCreditSummary(snapshot.credits);
|
|
257
303
|
if (!creditSummary) return plan;
|
|
258
304
|
return plan ? `${plan} (${creditSummary})` : creditSummary;
|
|
259
305
|
}
|
|
260
306
|
function formatCodexCreditSummary(credits) {
|
|
261
|
-
if (!credits) return;
|
|
262
|
-
if (
|
|
263
|
-
|
|
264
|
-
const balance = typeof credits.balance === "string" ? parseStrictFiniteNumber(credits.balance) : asFiniteNumber(credits.balance);
|
|
307
|
+
if (!credits || credits.hasCredits === false) return;
|
|
308
|
+
if (credits.unlimited) return "Unlimited credits";
|
|
309
|
+
const balance = credits.balance;
|
|
265
310
|
if (balance === void 0 || balance <= 0) return;
|
|
266
311
|
const roundedBalance = Math.round(balance);
|
|
267
312
|
return roundedBalance > 0 ? `${roundedBalance} credits` : void 0;
|
|
@@ -285,7 +330,7 @@ function selectBlockingWindowEntry(entries, nowMs) {
|
|
|
285
330
|
}
|
|
286
331
|
function readWindowEntries(snapshot) {
|
|
287
332
|
return LIMIT_WINDOW_KEYS.flatMap((key) => {
|
|
288
|
-
const window =
|
|
333
|
+
const window = snapshot[key];
|
|
289
334
|
return window ? [{
|
|
290
335
|
key,
|
|
291
336
|
window
|
|
@@ -370,9 +415,8 @@ function formatResetDuration(resetsAtMs, nowMs) {
|
|
|
370
415
|
if (minutes > 0) return seconds > 0 ? `${minutes}m ${seconds}s` : `${minutes}m`;
|
|
371
416
|
return `${seconds}s`;
|
|
372
417
|
}
|
|
373
|
-
function formatWindowSignature(
|
|
374
|
-
|
|
375
|
-
return `${asFiniteNumber(value.usedPercent) ?? asFiniteNumber(value.used_percent) ?? ""}:${asFiniteNumber(value.resetsAt) ?? asFiniteNumber(value.resets_at) ?? ""}`;
|
|
418
|
+
function formatWindowSignature(window) {
|
|
419
|
+
return window ? `${window.usedPercent ?? ""}:${window.resetsAt ?? ""}` : "";
|
|
376
420
|
}
|
|
377
421
|
function extractCodexRetryHint(message) {
|
|
378
422
|
if (!message) return;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.
|
|
2
|
-
import { n as withTimeout, t as withAbortableTimeout } from "./timeout-
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
|
|
2
|
+
import { i as CodexAppServerRpcError, n as withTimeout, t as withAbortableTimeout } from "./timeout-DZF05XrR.mjs";
|
|
3
3
|
//#region extensions/codex/src/app-server/request.ts
|
|
4
4
|
var request_exports = /* @__PURE__ */ __exportAll({
|
|
5
5
|
CodexAppServerScopedRequestRejectedError: () => CodexAppServerScopedRequestRejectedError,
|
|
@@ -8,26 +8,56 @@ var request_exports = /* @__PURE__ */ __exportAll({
|
|
|
8
8
|
requestCodexAppServerJson: () => requestCodexAppServerJson,
|
|
9
9
|
withCodexAppServerJsonClient: () => withCodexAppServerJsonClient
|
|
10
10
|
});
|
|
11
|
+
function observeControlPhase(observation, phase) {
|
|
12
|
+
try {
|
|
13
|
+
observation?.phase(phase);
|
|
14
|
+
} catch {}
|
|
15
|
+
}
|
|
16
|
+
function observeControlFailure(observation, phase, error, deadlineObserved = false) {
|
|
17
|
+
if (!observation) return;
|
|
18
|
+
try {
|
|
19
|
+
const category = deadlineObserved ? "deadline-observed" : error instanceof CodexAppServerScopedRequestRejectedError ? "scoped-rejection" : error instanceof CodexAppServerRpcError ? error.code === -32601 ? "rpc-method-unavailable" : "rpc-error" : "other";
|
|
20
|
+
observation.failed({
|
|
21
|
+
phase,
|
|
22
|
+
category
|
|
23
|
+
});
|
|
24
|
+
} catch {}
|
|
25
|
+
}
|
|
11
26
|
/** Sends one guarded request over a client lease owned by the caller. */
|
|
12
27
|
async function requestCodexAppServerClientJson(params) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
let phase = "prepare";
|
|
29
|
+
observeControlPhase(params.controlObservation, phase);
|
|
30
|
+
try {
|
|
31
|
+
const { resolveCodexAppServerDirectSandboxBypassBlock } = await import("./sandbox-guard-BBP-RbTf.mjs").then((n) => n.r);
|
|
32
|
+
const sandboxBlock = resolveCodexAppServerDirectSandboxBypassBlock({
|
|
33
|
+
method: params.method,
|
|
34
|
+
requestParams: params.requestParams,
|
|
35
|
+
config: params.config,
|
|
36
|
+
sessionKey: params.sessionKey,
|
|
37
|
+
sessionId: params.sessionId
|
|
38
|
+
});
|
|
39
|
+
if (sandboxBlock) throw new Error(sandboxBlock);
|
|
40
|
+
const timeoutMs = params.timeoutMs ?? 6e4;
|
|
41
|
+
const method = params.method;
|
|
42
|
+
const requestParams = params.requestParams;
|
|
43
|
+
const attemptWaiterFinished = method === "thread/list" ? params.controlObservation?.attemptWaiterFinished : void 0;
|
|
44
|
+
const options = {
|
|
45
|
+
timeoutMs,
|
|
46
|
+
signal: params.signal,
|
|
47
|
+
...attemptWaiterFinished ? { attemptWaiterFinished } : {},
|
|
48
|
+
...params.assertCurrent ? { assertCurrent: () => assertRequestOwnerCurrent(params.assertCurrent) } : {}
|
|
49
|
+
};
|
|
50
|
+
phase = "client-request";
|
|
51
|
+
observeControlPhase(params.controlObservation, phase);
|
|
52
|
+
return await withTimeout(params.client.request(method, requestParams, options), timeoutMs, `codex app-server ${params.method} timed out`);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
observeControlFailure(params.controlObservation, phase, error);
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
28
57
|
}
|
|
29
58
|
async function requestCodexAppServerJson(params) {
|
|
30
|
-
|
|
59
|
+
observeControlPhase(params.controlObservation, "prepare");
|
|
60
|
+
const { resolveCodexAppServerDirectSandboxBypassBlock } = await import("./sandbox-guard-BBP-RbTf.mjs").then((n) => n.r);
|
|
31
61
|
const sandboxBlock = resolveCodexAppServerDirectSandboxBypassBlock({
|
|
32
62
|
method: params.method,
|
|
33
63
|
requestParams: params.requestParams,
|
|
@@ -66,7 +96,7 @@ const CODEX_ACCOUNT_READ_MAX_TIMEOUT_MS = 4e3;
|
|
|
66
96
|
const CODEX_USAGE_DEADLINE_RESERVE_MS = CODEX_USAGE_ISOLATED_SHUTDOWN.forceKillDelayMs + CODEX_USAGE_ISOLATED_SHUTDOWN.exitTimeoutMs + 250;
|
|
67
97
|
/** Reads rate limits and best-effort account identity from one isolated app-server session. */
|
|
68
98
|
async function readCodexAppServerUsage(options) {
|
|
69
|
-
const deadline =
|
|
99
|
+
const deadline = performance.now() + options.timeoutMs;
|
|
70
100
|
return await withCodexAppServerJsonClient({
|
|
71
101
|
timeoutMs: options.timeoutMs,
|
|
72
102
|
timeoutMessage: "codex app-server usage read timed out",
|
|
@@ -74,6 +104,9 @@ async function readCodexAppServerUsage(options) {
|
|
|
74
104
|
...options.authProfileId ? { authProfileId: options.authProfileId } : {},
|
|
75
105
|
config: options.config,
|
|
76
106
|
startOptions: options.startOptions,
|
|
107
|
+
preparedAuth: options.preparedAuth,
|
|
108
|
+
authRequirement: options.authRequirement,
|
|
109
|
+
assertCurrent: options.assertCurrent,
|
|
77
110
|
isolated: true,
|
|
78
111
|
isolatedShutdown: CODEX_USAGE_ISOLATED_SHUTDOWN
|
|
79
112
|
}, async (request) => {
|
|
@@ -93,7 +126,7 @@ function extractCodexAccountEmail(value) {
|
|
|
93
126
|
return typeof email === "string" && email.trim() ? email.trim() : void 0;
|
|
94
127
|
}
|
|
95
128
|
async function readCodexAccountEmailBestEffort(request, deadline) {
|
|
96
|
-
const boundMs = Math.min(CODEX_ACCOUNT_READ_MAX_TIMEOUT_MS, deadline -
|
|
129
|
+
const boundMs = Math.min(CODEX_ACCOUNT_READ_MAX_TIMEOUT_MS, deadline - performance.now() - CODEX_USAGE_DEADLINE_RESERVE_MS);
|
|
97
130
|
if (boundMs <= 0) return;
|
|
98
131
|
const read = request({
|
|
99
132
|
method: "account/read",
|
|
@@ -118,16 +151,19 @@ async function readCodexAccountEmailBestEffort(request, deadline) {
|
|
|
118
151
|
async function withCodexAppServerJsonClient(params, run) {
|
|
119
152
|
const timeoutMs = params.timeoutMs ?? 6e4;
|
|
120
153
|
const timeoutMessage = params.timeoutMessage ?? "codex app-server request timed out";
|
|
154
|
+
let activePhase = "prepare";
|
|
155
|
+
let errorPhase;
|
|
156
|
+
observeControlPhase(params.controlObservation, activePhase);
|
|
121
157
|
const timeoutController = new AbortController();
|
|
122
|
-
const deadline = Number.isFinite(timeoutMs) && timeoutMs > 0 ?
|
|
123
|
-
const isPastDeadline = () => deadline !== void 0 &&
|
|
158
|
+
const deadline = Number.isFinite(timeoutMs) && timeoutMs > 0 ? performance.now() + timeoutMs : void 0;
|
|
159
|
+
const isPastDeadline = () => deadline !== void 0 && performance.now() >= deadline;
|
|
124
160
|
const throwIfAbandoned = () => {
|
|
125
161
|
if (timeoutController.signal.aborted && timeoutController.signal.reason instanceof Error) throw timeoutController.signal.reason;
|
|
126
162
|
if (timeoutController.signal.aborted || isPastDeadline()) throw new CodexAppServerScopedRequestRejectedError(timeoutMessage);
|
|
127
163
|
};
|
|
128
164
|
const remainingTimeoutMs = () => {
|
|
129
165
|
throwIfAbandoned();
|
|
130
|
-
return deadline === void 0 ? timeoutMs : Math.max(1, deadline -
|
|
166
|
+
return deadline === void 0 ? timeoutMs : Math.max(1, deadline - performance.now());
|
|
131
167
|
};
|
|
132
168
|
try {
|
|
133
169
|
return await withAbortableTimeout({
|
|
@@ -135,11 +171,15 @@ async function withCodexAppServerJsonClient(params, run) {
|
|
|
135
171
|
timeoutMs,
|
|
136
172
|
timeoutMessage,
|
|
137
173
|
promise: (async () => {
|
|
138
|
-
const { resolveCodexAppServerDirectSandboxBypassBlock } = await import("./sandbox-guard-
|
|
139
|
-
const { createIsolatedCodexAppServerClient, getLeasedSharedCodexAppServerClient, isCodexAppServerStartSelectionChangedError, releaseLeasedSharedCodexAppServerClient, retireSharedCodexAppServerClientIfCurrent } = await import("./shared-client-
|
|
174
|
+
const { resolveCodexAppServerDirectSandboxBypassBlock } = await import("./sandbox-guard-BBP-RbTf.mjs").then((n) => n.r);
|
|
175
|
+
const { createIsolatedCodexAppServerClient, getLeasedSharedCodexAppServerClient, isCodexAppServerStartSelectionChangedError, releaseLeasedSharedCodexAppServerClient, retireSharedCodexAppServerClientIfCurrent } = await import("./shared-client-BpTtuLQ5.mjs").then((n) => n.y);
|
|
140
176
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
177
|
+
errorPhase = void 0;
|
|
178
|
+
activePhase = "prepare";
|
|
179
|
+
observeControlPhase(params.controlObservation, activePhase);
|
|
141
180
|
throwIfAbandoned();
|
|
142
|
-
const
|
|
181
|
+
const acquireClient = params.isolated ? createIsolatedCodexAppServerClient : getLeasedSharedCodexAppServerClient;
|
|
182
|
+
const acquireOptions = {
|
|
143
183
|
startOptions: params.startOptions,
|
|
144
184
|
pluginConfig: params.pluginConfig,
|
|
145
185
|
timeoutMs: remainingTimeoutMs(),
|
|
@@ -150,8 +190,12 @@ async function withCodexAppServerJsonClient(params, run) {
|
|
|
150
190
|
authRequirement: params.authRequirement,
|
|
151
191
|
agentDir: params.agentDir,
|
|
152
192
|
config: params.config,
|
|
153
|
-
abandonSignal: timeoutController.signal
|
|
154
|
-
|
|
193
|
+
abandonSignal: timeoutController.signal,
|
|
194
|
+
assertCurrent: params.assertCurrent
|
|
195
|
+
};
|
|
196
|
+
activePhase = "acquire-client";
|
|
197
|
+
observeControlPhase(params.controlObservation, activePhase);
|
|
198
|
+
const client = await acquireClient(acquireOptions);
|
|
155
199
|
let scopeActive = true;
|
|
156
200
|
const assertCurrent = () => {
|
|
157
201
|
throwIfAbandoned();
|
|
@@ -159,8 +203,12 @@ async function withCodexAppServerJsonClient(params, run) {
|
|
|
159
203
|
assertRequestOwnerCurrent(params.assertCurrent);
|
|
160
204
|
};
|
|
161
205
|
try {
|
|
206
|
+
activePhase = "prepare";
|
|
207
|
+
observeControlPhase(params.controlObservation, activePhase);
|
|
162
208
|
assertCurrent();
|
|
163
209
|
const scopedRequest = async (request) => {
|
|
210
|
+
activePhase = "prepare";
|
|
211
|
+
observeControlPhase(params.controlObservation, activePhase);
|
|
164
212
|
const sandboxBlock = resolveCodexAppServerDirectSandboxBypassBlock({
|
|
165
213
|
method: request.method,
|
|
166
214
|
requestParams: request.requestParams,
|
|
@@ -170,14 +218,26 @@ async function withCodexAppServerJsonClient(params, run) {
|
|
|
170
218
|
});
|
|
171
219
|
if (sandboxBlock) throw new CodexAppServerScopedRequestRejectedError(sandboxBlock);
|
|
172
220
|
assertCurrent();
|
|
173
|
-
|
|
221
|
+
const method = request.method;
|
|
222
|
+
const requestParams = request.requestParams;
|
|
223
|
+
const attemptWaiterFinished = method === "thread/list" ? params.controlObservation?.attemptWaiterFinished : void 0;
|
|
224
|
+
const requestOptions = {
|
|
174
225
|
timeoutMs: remainingTimeoutMs(),
|
|
175
226
|
signal: timeoutController.signal,
|
|
227
|
+
...attemptWaiterFinished ? { attemptWaiterFinished } : {},
|
|
228
|
+
...params.catalogPreview && method === "thread/list" ? {
|
|
229
|
+
catalogPreview: true,
|
|
230
|
+
catalogPreviewCache: params.catalogPreviewCache,
|
|
231
|
+
catalogRows: params.catalogRows
|
|
232
|
+
} : {},
|
|
176
233
|
assertCurrent: () => {
|
|
177
234
|
assertCurrent();
|
|
178
235
|
request.assertCurrent?.();
|
|
179
236
|
}
|
|
180
|
-
}
|
|
237
|
+
};
|
|
238
|
+
activePhase = "client-request";
|
|
239
|
+
observeControlPhase(params.controlObservation, activePhase);
|
|
240
|
+
return await client.request(method, requestParams, requestOptions);
|
|
181
241
|
};
|
|
182
242
|
return await run(scopedRequest, client, {
|
|
183
243
|
assertCurrent,
|
|
@@ -186,23 +246,43 @@ async function withCodexAppServerJsonClient(params, run) {
|
|
|
186
246
|
}
|
|
187
247
|
});
|
|
188
248
|
} catch (error) {
|
|
249
|
+
errorPhase = activePhase;
|
|
189
250
|
if (!isCodexAppServerStartSelectionChangedError(error) || attempt > 0) throw error;
|
|
190
|
-
|
|
191
|
-
|
|
251
|
+
errorPhase = void 0;
|
|
252
|
+
try {
|
|
253
|
+
if (!params.isolated) {
|
|
254
|
+
activePhase = "release-client";
|
|
255
|
+
observeControlPhase(params.controlObservation, activePhase);
|
|
256
|
+
retireSharedCodexAppServerClientIfCurrent(client);
|
|
257
|
+
}
|
|
258
|
+
activePhase = "prepare";
|
|
259
|
+
observeControlPhase(params.controlObservation, activePhase);
|
|
260
|
+
throwIfAbandoned();
|
|
261
|
+
} catch (retryError) {
|
|
262
|
+
errorPhase = activePhase;
|
|
263
|
+
throw retryError;
|
|
264
|
+
}
|
|
192
265
|
} finally {
|
|
193
266
|
scopeActive = false;
|
|
267
|
+
activePhase = "release-client";
|
|
268
|
+
observeControlPhase(params.controlObservation, activePhase);
|
|
269
|
+
const requestErrorPhase = errorPhase;
|
|
270
|
+
errorPhase = activePhase;
|
|
194
271
|
if (params.isolated) await client.closeAndWait({
|
|
195
272
|
exitTimeoutMs: params.isolatedShutdown?.exitTimeoutMs ?? 2e3,
|
|
196
273
|
forceKillDelayMs: params.isolatedShutdown?.forceKillDelayMs ?? 250
|
|
197
274
|
});
|
|
198
275
|
else releaseLeasedSharedCodexAppServerClient(client);
|
|
276
|
+
errorPhase = requestErrorPhase;
|
|
199
277
|
}
|
|
200
278
|
}
|
|
201
279
|
throw new Error("Codex app-server selection retry loop exited unexpectedly");
|
|
202
280
|
})()
|
|
203
281
|
});
|
|
204
282
|
} catch (error) {
|
|
205
|
-
|
|
283
|
+
const deadlineObserved = isPastDeadline();
|
|
284
|
+
observeControlFailure(params.controlObservation, deadlineObserved ? activePhase : errorPhase ?? activePhase, error, deadlineObserved);
|
|
285
|
+
if (deadlineObserved) throw new Error(timeoutMessage, { cause: error });
|
|
206
286
|
throw error;
|
|
207
287
|
} finally {
|
|
208
288
|
timeoutController.abort(new CodexAppServerScopedRequestRejectedError(timeoutMessage));
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { t as attemptTerminal } from "./attempt-terminal-gZrxQ35N.mjs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
import { awaitAgentEndSideEffects, embeddedAgentLog, emitAgentEvent, runAgentEndSideEffects } from "openclaw/plugin-sdk/agent-harness-runtime";
|
|
5
|
+
//#region extensions/codex/src/app-server/workspace-dir-cache.ts
|
|
6
|
+
/** Process-local cache of Codex workspaces already created by the run loop. */
|
|
7
|
+
const codexWorkspaceDirCache = /* @__PURE__ */ new Set();
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region extensions/codex/src/app-server/run-attempt-lifecycle.ts
|
|
10
|
+
const CODEX_APP_SERVER_PROJECTED_CHARS_PER_TOKEN = 4;
|
|
11
|
+
function shouldKeepCodexSharedAbortOpen(params) {
|
|
12
|
+
const terminal = attemptTerminal.project(params.result.terminal);
|
|
13
|
+
if (params.explicitCancellationObserved || terminal.aborted || terminal.externalAbort) return false;
|
|
14
|
+
return params.trigger === "memory" || !params.attemptSucceeded;
|
|
15
|
+
}
|
|
16
|
+
function withCodexAppServerFastModeServiceTier(appServer, params) {
|
|
17
|
+
const fastMode = typeof params.fastMode === "function" ? params.fastMode() : params.fastMode;
|
|
18
|
+
const serviceTier = fastMode === void 0 ? appServer.serviceTier : fastMode ? "priority" : void 0;
|
|
19
|
+
if (serviceTier === appServer.serviceTier) return appServer;
|
|
20
|
+
if (serviceTier) return {
|
|
21
|
+
...appServer,
|
|
22
|
+
serviceTier
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
...appServer,
|
|
26
|
+
serviceTier: null
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function estimateCodexAppServerProjectedTurnTokens(params) {
|
|
30
|
+
const inputChars = params.prompt.length + (params.developerInstructions?.length ?? 0);
|
|
31
|
+
return Math.max(1, Math.ceil(inputChars / CODEX_APP_SERVER_PROJECTED_CHARS_PER_TOKEN));
|
|
32
|
+
}
|
|
33
|
+
async function ensureCodexWorkspaceDirOnce(workspaceDir) {
|
|
34
|
+
const normalized = path.resolve(workspaceDir);
|
|
35
|
+
if (codexWorkspaceDirCache.has(normalized)) return;
|
|
36
|
+
await fs.mkdir(normalized, { recursive: true });
|
|
37
|
+
codexWorkspaceDirCache.add(normalized);
|
|
38
|
+
}
|
|
39
|
+
async function emitCodexAppServerEvent(params, event) {
|
|
40
|
+
try {
|
|
41
|
+
emitAgentEvent({
|
|
42
|
+
runId: params.runId,
|
|
43
|
+
stream: event.stream,
|
|
44
|
+
data: event.data,
|
|
45
|
+
...params.sessionKey ? { sessionKey: params.sessionKey } : {}
|
|
46
|
+
});
|
|
47
|
+
} catch (error) {
|
|
48
|
+
embeddedAgentLog.debug("codex app-server global agent event emit failed", { error });
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
await params.onAgentEvent?.(event);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
embeddedAgentLog.debug("codex app-server agent event handler threw", { error });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async function runCodexAgentEndHook(params, hookParams) {
|
|
57
|
+
const sideEffectParams = {
|
|
58
|
+
...hookParams,
|
|
59
|
+
ctx: {
|
|
60
|
+
...hookParams.ctx,
|
|
61
|
+
config: params.config
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
if (!params.messageChannel && !params.messageProvider) {
|
|
65
|
+
await awaitAgentEndSideEffects(sideEffectParams);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
runAgentEndSideEffects(sideEffectParams);
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { shouldKeepCodexSharedAbortOpen as a, runCodexAgentEndHook as i, ensureCodexWorkspaceDirOnce as n, withCodexAppServerFastModeServiceTier as o, estimateCodexAppServerProjectedTurnTokens as r, emitCodexAppServerEvent as t };
|