@openclaw/codex 2026.9.3 → 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-B6el6hdO.js → .setup/apply-CJ0ZfmBG.mjs} +12 -13
- package/dist/.setup/async-questions-DdhOCwGi.mjs +27 -0
- package/dist/{attempt-client-cleanup-D6cR54TV.js → .setup/attempt-client-cleanup-BpYKdTA0.mjs} +30 -211
- package/dist/{attempt-context-AO4DSjE0.js → .setup/attempt-context-VXVwTCfS.mjs} +6 -6
- package/dist/.setup/attempt-terminal-gZrxQ35N.mjs +5 -0
- package/dist/{auth-binding-Co2Vfcf_.js → .setup/auth-binding-DhLWa_7K.mjs} +2 -2
- package/dist/{auth-cache-key-Kq6oerr6.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-lRpmZHFv.js → .setup/bounded-turn-BtlZcivC.mjs} +19 -14
- package/dist/{build-state-6RL6qohz.js → .setup/build-state-Xx9ybZqa.mjs} +1 -1
- package/dist/{capabilities-BeqLPbtM.js → .setup/capabilities-_vXcZGSx.mjs} +1 -1
- package/dist/{client-BEKu4yDx.js → .setup/client-vXs2929Q.mjs} +355 -164
- package/dist/{command-dispatch-CisT9Jqq.js → .setup/command-dispatch-naHIZwwF.mjs} +3 -3
- package/dist/{command-formatters-DeTfrapr.js → .setup/command-formatters-CGEkdawF.mjs} +4 -3
- package/dist/{command-handlers-BfIsJEuA.js → .setup/command-handlers-BtAJEW1X.mjs} +812 -152
- package/dist/{command-rpc-BMqRQOFX.js → .setup/command-rpc-DHFpn4le.mjs} +37 -21
- package/dist/{compact-CGJZ2rlb.js → .setup/compact-C3i3qlzj.mjs} +28 -43
- package/dist/{config-JDfTI4VI.js → .setup/config-CedDWjM-.mjs} +5 -4
- package/dist/{config-options-jnIFvwxD.js → .setup/config-options-BsanJ8QG.mjs} +9 -421
- package/dist/{protocol-CAAcVIKF.js → .setup/config-parsing-CcB9iPoq.mjs} +9 -51
- package/dist/{config-runtime-BWf6JLWG.js → .setup/config-runtime-CeAhl_h4.mjs} +2 -2
- package/dist/.setup/config-security-BRQ2mgW9.mjs +465 -0
- package/dist/{config-utils-C57JiJrU.js → .setup/config-utils-DujwEnhg.mjs} +2 -4
- package/dist/{conversation-binding-CxOlHiix.js → .setup/conversation-binding-DhzrpTM6.mjs} +60 -47
- package/dist/{conversation-binding-data-BiodpIzq.js → .setup/conversation-binding-data-CrcyZk6O.mjs} +1 -1
- package/dist/{conversation-control-CUCrSIQI.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-D-JBoaLt.js → .setup/dynamic-tools-D16lOp67.mjs} +168 -61
- package/dist/{effective-mcp-catalog-J_5Ep5Um.js → .setup/effective-mcp-catalog-K6kLCN8X.mjs} +3 -3
- package/dist/{ephemeral-turn-DSwzP8YY.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/.setup/event-projector-items-DyTQ_XqL.mjs +200 -0
- package/dist/{attempt-notifications--H8zXR5-.js → .setup/event-projector-usage-C7Ntzs-f.mjs} +102 -9
- package/dist/{harness-FR6eQgyO.js → .setup/harness-rxaaoN-o.mjs} +90 -19
- package/dist/.setup/inference-context-fulhZuz8.mjs +94 -0
- package/dist/.setup/inference-proxy-CC15HuSi.mjs +311 -0
- package/dist/{isolated-completion-DHBefrzg.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-DrjjRRUD.js → .setup/managed-binary-DP6Rib3P.mjs} +11 -2
- package/dist/{managed-thread-store-D1t5jh3G.js → .setup/managed-thread-store-BMqgThVL.mjs} +48 -14
- package/dist/{model-catalog-B_6M04Wo.js → .setup/model-catalog-DkvUuBey.mjs} +35 -10
- package/dist/{models-P9k2qAof.js → .setup/models-BDFgm_G-.mjs} +3 -3
- package/dist/.setup/native-auth-BLZGqFjw.mjs +57 -0
- package/dist/.setup/native-subagent-history-YXaL6dMd.mjs +135 -0
- package/dist/.setup/native-subagent-monitor-B1hxzIOy.mjs +5031 -0
- package/dist/.setup/native-subagent-task-ids-DsuOonKv.mjs +411 -0
- package/dist/{node-cli-sessions-rj0ysJwM.js → .setup/node-cli-sessions-Cl8b2ZF3.mjs} +1 -1
- package/dist/{node-exec-server.runtime-BY_ctYnT.js → .setup/node-exec-server.runtime-BaViBKNz.mjs} +5 -5
- package/dist/{plan-BMJdMOEF.js → .setup/plan-xD7WKYTM.mjs} +331 -79
- package/dist/{plugin-activation-BQK-f5sV.js → .setup/plugin-activation-r8nq5Jzp.mjs} +24 -19
- package/dist/{plugin-app-cache-key-CdSQzWyX.js → .setup/plugin-app-cache-key-BOxKP7db.mjs} +29 -25
- package/dist/{plugin-approval-roundtrip-DeW95wB5.js → .setup/plugin-approval-roundtrip-CjfzafAZ.mjs} +1 -1
- package/dist/{plugin-inventory-CoRCzWW4.js → .setup/plugin-inventory-DUle8DLz.mjs} +12 -8
- package/dist/{plugin-marketplace-discovery-3akBizzF.js → .setup/plugin-marketplace-discovery-P-Vndfqq.mjs} +18 -15
- package/dist/{plugin-metadata-cache-DgNfRAGA.js → .setup/plugin-metadata-cache-DsS5buNa.mjs} +33 -14
- package/dist/{provider-capabilities-W4tfK5Y5.js → .setup/provider-capabilities-B8J4Dy-O.mjs} +2 -2
- package/dist/.setup/provider-fFh_-VR3.mjs +50 -0
- package/dist/{rate-limits-Bqnx1N4z.js → .setup/rate-limits-DOEGYRNs.mjs} +90 -46
- package/dist/.setup/request-BioXJLYa.mjs +292 -0
- package/dist/.setup/run-attempt-lifecycle-B7JbY4-F.mjs +71 -0
- package/dist/{run-attempt-DwKds3DN.js → .setup/run-attempt-rlA07pUv.mjs} +644 -491
- package/dist/{runtime-artifact-T-NwqeSH.js → .setup/runtime-artifact-Dy38Z5iU.mjs} +2 -2
- package/dist/{sandbox-guard-BcT66fWy.js → .setup/sandbox-guard-BBP-RbTf.mjs} +4 -3
- package/dist/{session-binding-CKSepwIC.js → .setup/session-binding-_0W_fHRr.mjs} +45 -63
- package/dist/{session-binding-record-CaZjYwNS.js → .setup/session-binding-record-TH3xA0zj.mjs} +181 -3
- package/dist/.setup/session-binding-sidecars-CKYEcfNn.mjs +543 -0
- package/dist/{session-catalog-adoption-BKLtSrwi.js → .setup/session-catalog-adoption-CR_whkEW.mjs} +6 -6
- package/dist/{session-catalog-archive-D0i2pGj2.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/{session-catalog-parsing-CdD3JhdM.js → .setup/session-catalog-native-projection-ChV3cCtm.mjs} +213 -21
- package/dist/{session-catalog-node-adoption-BUuDYY8R.js → .setup/session-catalog-node-adoption-BVRsYOSh.mjs} +3 -3
- package/dist/{session-catalog-node-continue-CBtc4wkI.js → .setup/session-catalog-node-continue-Dowv8osw.mjs} +7 -7
- package/dist/.setup/session-catalog-projection-C1Bj9Jl-.mjs +414 -0
- package/dist/{session-cli-CbgaHh0f.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-DFN7sWRU.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-CNEvGaU5.js → .setup/session-history.worker-CpNj7H_P.mjs} +192 -89
- package/dist/{session-initialization-Jo86C60I.js → .setup/session-initialization-DH1z6fXn.mjs} +2 -2
- package/dist/{session-permission-policy-B22InTp_.js → .setup/session-permission-policy-DhurXY0l.mjs} +2 -2
- package/dist/{session-retirement-BSNG_mhf.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-BuLUrZl2.js → .setup/settled-turn-finalizer-CiY2bLFK.mjs} +10 -10
- package/dist/{shared-client-CVhez2Uo.js → .setup/shared-client-BpTtuLQ5.mjs} +495 -156
- package/dist/{side-question-DLbr2vUU.js → .setup/side-question-DSCZyoBD.mjs} +64 -47
- package/dist/{source-Da-h6f7e.js → .setup/source-Bjp4UQij.mjs} +15 -14
- package/dist/{thread-archive-guard-D1bP04Tf.js → .setup/thread-archive-guard-jmecf6OJ.mjs} +1 -1
- package/dist/.setup/thread-history-page-BTx-4xsg.mjs +83 -0
- package/dist/{thread-lifecycle-D1pzRwHB.js → .setup/thread-lifecycle-Cik28qWn.mjs} +330 -150
- package/dist/{thread-ownership-D6oASVRu.js → .setup/thread-ownership-skomxnIt.mjs} +4 -4
- package/dist/{thread-policy-D8kI7yAO.js → .setup/thread-policy-Cjs4B8xf.mjs} +3 -3
- package/dist/{thread-resume-T5cveyxA.js → .setup/thread-resume-BkNpj9Pz.mjs} +8 -5
- package/dist/.setup/timeout-DZF05XrR.mjs +63 -0
- package/dist/{session-catalog-home-id-D7-aLiNt.js → .setup/transcript-history-projection-DHNBDhCU.mjs} +73 -20
- package/dist/{transcript-mirror-t5TOccct.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-De-sLJ2r.js → .setup/upstream-session-fork-D3UKxgVD.mjs} +27 -26
- package/dist/{usage-CPPTmBvZ.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-CSVgQL0w.js → .setup/web-search-provider.runtime-CTGuJt6i.mjs} +3 -3
- package/dist/api.js +28 -20
- 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 +130 -135
- package/dist/media-understanding-provider.js +3 -3
- package/dist/migration-provider-api.js +2 -0
- 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 -68
- package/package.json +11 -8
- package/dist/binding-connection-QqgcPCgk.js +0 -60
- package/dist/event-projector-usage-CIyrYYid.js +0 -102
- package/dist/native-subagent-monitor-BbCUKRwC.js +0 -3350
- package/dist/request-CGvGOpeR.js +0 -198
- package/dist/session-catalog-HaDcp7Sv.js +0 -1533
- package/dist/session-catalog-provenance-DkJHo735.js +0 -124
- package/dist/timeout-BVw8aaM1.js +0 -33
- package/dist/{auth-profile-selection-DFu9e167.js → .setup/auth-profile-selection-DFu9e167.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/{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;
|
|
@@ -0,0 +1,292 @@
|
|
|
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
|
+
//#region extensions/codex/src/app-server/request.ts
|
|
4
|
+
var request_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
+
CodexAppServerScopedRequestRejectedError: () => CodexAppServerScopedRequestRejectedError,
|
|
6
|
+
readCodexAppServerUsage: () => readCodexAppServerUsage,
|
|
7
|
+
requestCodexAppServerClientJson: () => requestCodexAppServerClientJson,
|
|
8
|
+
requestCodexAppServerJson: () => requestCodexAppServerJson,
|
|
9
|
+
withCodexAppServerJsonClient: () => withCodexAppServerJsonClient
|
|
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
|
+
}
|
|
26
|
+
/** Sends one guarded request over a client lease owned by the caller. */
|
|
27
|
+
async function requestCodexAppServerClientJson(params) {
|
|
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
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function requestCodexAppServerJson(params) {
|
|
59
|
+
observeControlPhase(params.controlObservation, "prepare");
|
|
60
|
+
const { resolveCodexAppServerDirectSandboxBypassBlock } = await import("./sandbox-guard-BBP-RbTf.mjs").then((n) => n.r);
|
|
61
|
+
const sandboxBlock = resolveCodexAppServerDirectSandboxBypassBlock({
|
|
62
|
+
method: params.method,
|
|
63
|
+
requestParams: params.requestParams,
|
|
64
|
+
config: params.config,
|
|
65
|
+
sessionKey: params.sessionKey,
|
|
66
|
+
sessionId: params.sessionId
|
|
67
|
+
});
|
|
68
|
+
if (sandboxBlock) throw new Error(sandboxBlock);
|
|
69
|
+
return await withCodexAppServerJsonClient({
|
|
70
|
+
...params,
|
|
71
|
+
timeoutMessage: `codex app-server ${params.method} timed out`
|
|
72
|
+
}, async (request) => await request({
|
|
73
|
+
method: params.method,
|
|
74
|
+
requestParams: params.requestParams
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
/** A scoped guard rejected the request before a physical write. */
|
|
78
|
+
var CodexAppServerScopedRequestRejectedError = class extends Error {
|
|
79
|
+
constructor(message, options) {
|
|
80
|
+
super(message, options);
|
|
81
|
+
this.name = "CodexAppServerScopedRequestRejectedError";
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
function assertRequestOwnerCurrent(assertCurrent) {
|
|
85
|
+
try {
|
|
86
|
+
assertCurrent?.();
|
|
87
|
+
} catch (cause) {
|
|
88
|
+
throw new CodexAppServerScopedRequestRejectedError(cause instanceof Error ? cause.message : String(cause), { cause });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const CODEX_USAGE_ISOLATED_SHUTDOWN = {
|
|
92
|
+
forceKillDelayMs: 200,
|
|
93
|
+
exitTimeoutMs: 300
|
|
94
|
+
};
|
|
95
|
+
const CODEX_ACCOUNT_READ_MAX_TIMEOUT_MS = 4e3;
|
|
96
|
+
const CODEX_USAGE_DEADLINE_RESERVE_MS = CODEX_USAGE_ISOLATED_SHUTDOWN.forceKillDelayMs + CODEX_USAGE_ISOLATED_SHUTDOWN.exitTimeoutMs + 250;
|
|
97
|
+
/** Reads rate limits and best-effort account identity from one isolated app-server session. */
|
|
98
|
+
async function readCodexAppServerUsage(options) {
|
|
99
|
+
const deadline = performance.now() + options.timeoutMs;
|
|
100
|
+
return await withCodexAppServerJsonClient({
|
|
101
|
+
timeoutMs: options.timeoutMs,
|
|
102
|
+
timeoutMessage: "codex app-server usage read timed out",
|
|
103
|
+
agentDir: options.agentDir,
|
|
104
|
+
...options.authProfileId ? { authProfileId: options.authProfileId } : {},
|
|
105
|
+
config: options.config,
|
|
106
|
+
startOptions: options.startOptions,
|
|
107
|
+
preparedAuth: options.preparedAuth,
|
|
108
|
+
authRequirement: options.authRequirement,
|
|
109
|
+
assertCurrent: options.assertCurrent,
|
|
110
|
+
isolated: true,
|
|
111
|
+
isolatedShutdown: CODEX_USAGE_ISOLATED_SHUTDOWN
|
|
112
|
+
}, async (request) => {
|
|
113
|
+
const rateLimits = await request({ method: "account/rateLimits/read" });
|
|
114
|
+
const accountEmail = await readCodexAccountEmailBestEffort(request, deadline);
|
|
115
|
+
return {
|
|
116
|
+
rateLimits,
|
|
117
|
+
...accountEmail ? { accountEmail } : {}
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function extractCodexAccountEmail(value) {
|
|
122
|
+
if (!value || typeof value !== "object") return;
|
|
123
|
+
const record = value;
|
|
124
|
+
const account = record.account && typeof record.account === "object" ? record.account : record;
|
|
125
|
+
const email = account.email ?? account.accountEmail;
|
|
126
|
+
return typeof email === "string" && email.trim() ? email.trim() : void 0;
|
|
127
|
+
}
|
|
128
|
+
async function readCodexAccountEmailBestEffort(request, deadline) {
|
|
129
|
+
const boundMs = Math.min(CODEX_ACCOUNT_READ_MAX_TIMEOUT_MS, deadline - performance.now() - CODEX_USAGE_DEADLINE_RESERVE_MS);
|
|
130
|
+
if (boundMs <= 0) return;
|
|
131
|
+
const read = request({
|
|
132
|
+
method: "account/read",
|
|
133
|
+
requestParams: {}
|
|
134
|
+
}).then((account) => extractCodexAccountEmail(account), () => void 0);
|
|
135
|
+
let timer;
|
|
136
|
+
const timeout = new Promise((resolve) => {
|
|
137
|
+
timer = setTimeout(() => resolve(void 0), boundMs);
|
|
138
|
+
timer.unref?.();
|
|
139
|
+
});
|
|
140
|
+
try {
|
|
141
|
+
return await Promise.race([read, timeout]);
|
|
142
|
+
} finally {
|
|
143
|
+
if (timer) clearTimeout(timer);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Runs several guarded requests over one acquired client (shared lease or
|
|
148
|
+
* isolated child) so related reads see the same app-server session. The whole
|
|
149
|
+
* callback re-runs once when the client's start selection changed underneath it.
|
|
150
|
+
*/
|
|
151
|
+
async function withCodexAppServerJsonClient(params, run) {
|
|
152
|
+
const timeoutMs = params.timeoutMs ?? 6e4;
|
|
153
|
+
const timeoutMessage = params.timeoutMessage ?? "codex app-server request timed out";
|
|
154
|
+
let activePhase = "prepare";
|
|
155
|
+
let errorPhase;
|
|
156
|
+
observeControlPhase(params.controlObservation, activePhase);
|
|
157
|
+
const timeoutController = new AbortController();
|
|
158
|
+
const deadline = Number.isFinite(timeoutMs) && timeoutMs > 0 ? performance.now() + timeoutMs : void 0;
|
|
159
|
+
const isPastDeadline = () => deadline !== void 0 && performance.now() >= deadline;
|
|
160
|
+
const throwIfAbandoned = () => {
|
|
161
|
+
if (timeoutController.signal.aborted && timeoutController.signal.reason instanceof Error) throw timeoutController.signal.reason;
|
|
162
|
+
if (timeoutController.signal.aborted || isPastDeadline()) throw new CodexAppServerScopedRequestRejectedError(timeoutMessage);
|
|
163
|
+
};
|
|
164
|
+
const remainingTimeoutMs = () => {
|
|
165
|
+
throwIfAbandoned();
|
|
166
|
+
return deadline === void 0 ? timeoutMs : Math.max(1, deadline - performance.now());
|
|
167
|
+
};
|
|
168
|
+
try {
|
|
169
|
+
return await withAbortableTimeout({
|
|
170
|
+
signal: timeoutController.signal,
|
|
171
|
+
timeoutMs,
|
|
172
|
+
timeoutMessage,
|
|
173
|
+
promise: (async () => {
|
|
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);
|
|
176
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
177
|
+
errorPhase = void 0;
|
|
178
|
+
activePhase = "prepare";
|
|
179
|
+
observeControlPhase(params.controlObservation, activePhase);
|
|
180
|
+
throwIfAbandoned();
|
|
181
|
+
const acquireClient = params.isolated ? createIsolatedCodexAppServerClient : getLeasedSharedCodexAppServerClient;
|
|
182
|
+
const acquireOptions = {
|
|
183
|
+
startOptions: params.startOptions,
|
|
184
|
+
pluginConfig: params.pluginConfig,
|
|
185
|
+
timeoutMs: remainingTimeoutMs(),
|
|
186
|
+
authProfileId: params.authProfileId,
|
|
187
|
+
authProfileStore: params.authProfileStore,
|
|
188
|
+
authBindingFingerprint: params.authBindingFingerprint,
|
|
189
|
+
preparedAuth: params.preparedAuth,
|
|
190
|
+
authRequirement: params.authRequirement,
|
|
191
|
+
agentDir: params.agentDir,
|
|
192
|
+
config: params.config,
|
|
193
|
+
abandonSignal: timeoutController.signal,
|
|
194
|
+
assertCurrent: params.assertCurrent
|
|
195
|
+
};
|
|
196
|
+
activePhase = "acquire-client";
|
|
197
|
+
observeControlPhase(params.controlObservation, activePhase);
|
|
198
|
+
const client = await acquireClient(acquireOptions);
|
|
199
|
+
let scopeActive = true;
|
|
200
|
+
const assertCurrent = () => {
|
|
201
|
+
throwIfAbandoned();
|
|
202
|
+
if (!scopeActive) throw new CodexAppServerScopedRequestRejectedError("Codex app-server request scope is closed");
|
|
203
|
+
assertRequestOwnerCurrent(params.assertCurrent);
|
|
204
|
+
};
|
|
205
|
+
try {
|
|
206
|
+
activePhase = "prepare";
|
|
207
|
+
observeControlPhase(params.controlObservation, activePhase);
|
|
208
|
+
assertCurrent();
|
|
209
|
+
const scopedRequest = async (request) => {
|
|
210
|
+
activePhase = "prepare";
|
|
211
|
+
observeControlPhase(params.controlObservation, activePhase);
|
|
212
|
+
const sandboxBlock = resolveCodexAppServerDirectSandboxBypassBlock({
|
|
213
|
+
method: request.method,
|
|
214
|
+
requestParams: request.requestParams,
|
|
215
|
+
config: params.config,
|
|
216
|
+
sessionKey: params.sessionKey,
|
|
217
|
+
sessionId: params.sessionId
|
|
218
|
+
});
|
|
219
|
+
if (sandboxBlock) throw new CodexAppServerScopedRequestRejectedError(sandboxBlock);
|
|
220
|
+
assertCurrent();
|
|
221
|
+
const method = request.method;
|
|
222
|
+
const requestParams = request.requestParams;
|
|
223
|
+
const attemptWaiterFinished = method === "thread/list" ? params.controlObservation?.attemptWaiterFinished : void 0;
|
|
224
|
+
const requestOptions = {
|
|
225
|
+
timeoutMs: remainingTimeoutMs(),
|
|
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
|
+
} : {},
|
|
233
|
+
assertCurrent: () => {
|
|
234
|
+
assertCurrent();
|
|
235
|
+
request.assertCurrent?.();
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
activePhase = "client-request";
|
|
239
|
+
observeControlPhase(params.controlObservation, activePhase);
|
|
240
|
+
return await client.request(method, requestParams, requestOptions);
|
|
241
|
+
};
|
|
242
|
+
return await run(scopedRequest, client, {
|
|
243
|
+
assertCurrent,
|
|
244
|
+
abort: (reason) => {
|
|
245
|
+
if (scopeActive) timeoutController.abort(reason);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
} catch (error) {
|
|
249
|
+
errorPhase = activePhase;
|
|
250
|
+
if (!isCodexAppServerStartSelectionChangedError(error) || attempt > 0) throw error;
|
|
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
|
+
}
|
|
265
|
+
} finally {
|
|
266
|
+
scopeActive = false;
|
|
267
|
+
activePhase = "release-client";
|
|
268
|
+
observeControlPhase(params.controlObservation, activePhase);
|
|
269
|
+
const requestErrorPhase = errorPhase;
|
|
270
|
+
errorPhase = activePhase;
|
|
271
|
+
if (params.isolated) await client.closeAndWait({
|
|
272
|
+
exitTimeoutMs: params.isolatedShutdown?.exitTimeoutMs ?? 2e3,
|
|
273
|
+
forceKillDelayMs: params.isolatedShutdown?.forceKillDelayMs ?? 250
|
|
274
|
+
});
|
|
275
|
+
else releaseLeasedSharedCodexAppServerClient(client);
|
|
276
|
+
errorPhase = requestErrorPhase;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
throw new Error("Codex app-server selection retry loop exited unexpectedly");
|
|
280
|
+
})()
|
|
281
|
+
});
|
|
282
|
+
} catch (error) {
|
|
283
|
+
const deadlineObserved = isPastDeadline();
|
|
284
|
+
observeControlFailure(params.controlObservation, deadlineObserved ? activePhase : errorPhase ?? activePhase, error, deadlineObserved);
|
|
285
|
+
if (deadlineObserved) throw new Error(timeoutMessage, { cause: error });
|
|
286
|
+
throw error;
|
|
287
|
+
} finally {
|
|
288
|
+
timeoutController.abort(new CodexAppServerScopedRequestRejectedError(timeoutMessage));
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
//#endregion
|
|
292
|
+
export { request_exports as a, requestCodexAppServerJson as i, readCodexAppServerUsage as n, withCodexAppServerJsonClient as o, requestCodexAppServerClientJson as r, CodexAppServerScopedRequestRejectedError as t };
|
|
@@ -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 };
|