@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
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as isJsonObject } from "./protocol-2POPqAY4.js";
|
|
3
|
-
import { d as resolveCodexAppServerRuntimeOptions, u as readCodexPluginConfig } from "./config-CYEDnLJ2.js";
|
|
4
|
-
import { resolveCodexSystemPromptContribution } from "./prompt-overlay.js";
|
|
5
|
-
import { resolvePluginConfigObject } from "openclaw/plugin-sdk/plugin-config-runtime";
|
|
1
|
+
import { Z as isJsonObject } from "./shared-client-JiAnW6pc.js";
|
|
6
2
|
import { MAX_DATE_TIMESTAMP_MS, resolveExpiresAtMsFromEpochSeconds } from "openclaw/plugin-sdk/number-runtime";
|
|
7
3
|
import { asFiniteNumber, parseStrictFiniteNumber } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
8
|
-
import {
|
|
9
|
-
import { createSubsystemLogger } from "openclaw/plugin-sdk/core";
|
|
4
|
+
import { expectDefined } from "openclaw/plugin-sdk/expect-runtime";
|
|
10
5
|
import { PROVIDER_LABELS, clampPercent } from "openclaw/plugin-sdk/provider-usage";
|
|
11
6
|
//#region extensions/codex/src/app-server/rate-limits.ts
|
|
12
7
|
/**
|
|
@@ -22,14 +17,15 @@ const ONE_DAY_MS = 24 * ONE_HOUR_MS;
|
|
|
22
17
|
const DAY_WINDOW_MINUTES = 1440;
|
|
23
18
|
const WEEKLY_WINDOW_MINUTES = 7 * DAY_WINDOW_MINUTES;
|
|
24
19
|
const WEEKLY_RESET_GAP_MS = 3 * ONE_DAY_MS;
|
|
20
|
+
const CODEX_USAGE_LIMIT_MESSAGE_PREFIX = "You've reached your Codex subscription usage limit.";
|
|
25
21
|
/** Enriches Codex usage-limit failures with reset timing and recovery guidance. */
|
|
26
22
|
function formatCodexUsageLimitErrorMessage(params) {
|
|
27
23
|
const message = normalizeText(params.message);
|
|
28
|
-
if (!isCodexUsageLimitError(params.codexErrorInfo
|
|
24
|
+
if (!isCodexUsageLimitError(params.codexErrorInfo)) return;
|
|
29
25
|
const nowMs = params.nowMs ?? Date.now();
|
|
30
26
|
const usageSummary = summarizeCodexAccountUsage(params.rateLimits, nowMs);
|
|
31
27
|
const nextReset = selectBlockingRateLimitReset(params.rateLimits, nowMs) ?? (usageSummary?.blocked ? void 0 : selectNextRateLimitReset(params.rateLimits, nowMs));
|
|
32
|
-
const parts = [
|
|
28
|
+
const parts = [CODEX_USAGE_LIMIT_MESSAGE_PREFIX];
|
|
33
29
|
let recoveryAction = "Wait until Codex becomes available";
|
|
34
30
|
if (nextReset) {
|
|
35
31
|
parts.push(`Next reset ${formatResetTime(nextReset.resetsAtMs, nowMs)}.`);
|
|
@@ -50,7 +46,7 @@ function formatCodexUsageLimitErrorMessage(params) {
|
|
|
50
46
|
/** Detects usage-limit messages that need a fresh rate-limit query before display. */
|
|
51
47
|
function shouldRefreshCodexRateLimitsForUsageLimitMessage(message) {
|
|
52
48
|
const text = normalizeText(message);
|
|
53
|
-
return Boolean(text?.
|
|
49
|
+
return Boolean(text?.startsWith(CODEX_USAGE_LIMIT_MESSAGE_PREFIX) && !text.includes("Next reset "));
|
|
54
50
|
}
|
|
55
51
|
/** Formats compact summaries for raw Codex rate-limit snapshot payloads. */
|
|
56
52
|
function summarizeCodexRateLimits(value, nowMs = Date.now()) {
|
|
@@ -78,7 +74,7 @@ function resolveCodexUsageLimitResetAtMs(value, nowMs = Date.now()) {
|
|
|
78
74
|
function summarizeCodexAccountUsage(value, nowMs = Date.now()) {
|
|
79
75
|
const snapshots = collectCodexRateLimitSnapshots(value).filter(snapshotHasDisplayableData);
|
|
80
76
|
if (snapshots.length === 0) return;
|
|
81
|
-
const usageSnapshot = snapshots.find(isCodexLimitSnapshot) ?? snapshots[0];
|
|
77
|
+
const usageSnapshot = snapshots.find(isCodexLimitSnapshot) ?? expectDefined(snapshots[0], "displayable Codex rate-limit snapshot");
|
|
82
78
|
const blockedSnapshots = snapshots.filter(snapshotHasLimitBlock);
|
|
83
79
|
const blockingSnapshot = blockedSnapshots.find(isCodexLimitSnapshot) ?? blockedSnapshots[0] ?? void 0;
|
|
84
80
|
const blockingEntries = blockingSnapshot ? readWindowEntries(blockingSnapshot) : [];
|
|
@@ -111,12 +107,12 @@ function buildCodexAppServerUsageSnapshot(value) {
|
|
|
111
107
|
...snapshot ? { plan: resolveCodexProviderUsagePlan(snapshot) } : {}
|
|
112
108
|
};
|
|
113
109
|
}
|
|
114
|
-
function isCodexUsageLimitError(codexErrorInfo
|
|
110
|
+
function isCodexUsageLimitError(codexErrorInfo) {
|
|
115
111
|
if (codexErrorInfo === "usageLimitExceeded") return true;
|
|
116
112
|
if (typeof codexErrorInfo === "string") {
|
|
117
113
|
if (codexErrorInfo.replace(/[_\s-]/gu, "").toLowerCase() === "usagelimitexceeded") return true;
|
|
118
114
|
}
|
|
119
|
-
return
|
|
115
|
+
return false;
|
|
120
116
|
}
|
|
121
117
|
function selectNextRateLimitReset(value, nowMs) {
|
|
122
118
|
const futureWindows = collectCodexRateLimitSnapshots(value).flatMap((snapshot) => LIMIT_WINDOW_KEYS.flatMap((key) => readRateLimitWindow(snapshot, key) ?? [])).filter((window) => window.resetsAtMs > nowMs);
|
|
@@ -400,256 +396,4 @@ function normalizeText(value) {
|
|
|
400
396
|
return text ? text : void 0;
|
|
401
397
|
}
|
|
402
398
|
//#endregion
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* Codex provider plugin and live app-server model catalog discovery.
|
|
406
|
-
*/
|
|
407
|
-
const DEFAULT_DISCOVERY_TIMEOUT_MS = 2500;
|
|
408
|
-
const LIVE_DISCOVERY_ENV = "OPENCLAW_CODEX_DISCOVERY_LIVE";
|
|
409
|
-
const MODEL_DISCOVERY_PAGE_LIMIT = 100;
|
|
410
|
-
const CODEX_APP_SERVER_SETUP_METHOD_ID = "app-server";
|
|
411
|
-
const CODEX_DEFAULT_MODEL_REF = `${CODEX_PROVIDER_ID}/${FALLBACK_CODEX_MODELS[0].id}`;
|
|
412
|
-
const codexCatalogLog = createSubsystemLogger("codex/catalog");
|
|
413
|
-
const CODEX_REASONING_EFFORTS = [
|
|
414
|
-
"minimal",
|
|
415
|
-
"low",
|
|
416
|
-
"medium",
|
|
417
|
-
"high",
|
|
418
|
-
"xhigh",
|
|
419
|
-
"max",
|
|
420
|
-
"ultra"
|
|
421
|
-
];
|
|
422
|
-
const GPT_56_MAX_REASONING_EFFORTS = [
|
|
423
|
-
"low",
|
|
424
|
-
"medium",
|
|
425
|
-
"high",
|
|
426
|
-
"xhigh",
|
|
427
|
-
"max"
|
|
428
|
-
];
|
|
429
|
-
const GPT_56_ULTRA_REASONING_EFFORTS = [...GPT_56_MAX_REASONING_EFFORTS, "ultra"];
|
|
430
|
-
const GPT_56_ULTRA_MODEL_IDS = /* @__PURE__ */ new Set(["gpt-5.6-sol", "gpt-5.6-terra"]);
|
|
431
|
-
const GPT_56_MAX_MODEL_IDS = /* @__PURE__ */ new Set([...GPT_56_ULTRA_MODEL_IDS, "gpt-5.6-luna"]);
|
|
432
|
-
const GPT_56_DEFAULT_REASONING_EFFORTS = /* @__PURE__ */ new Map([
|
|
433
|
-
["gpt-5.6-sol", "low"],
|
|
434
|
-
["gpt-5.6-terra", "medium"],
|
|
435
|
-
["gpt-5.6-luna", "medium"]
|
|
436
|
-
]);
|
|
437
|
-
const GPT_5_PRO_REASONING_EFFORTS = [
|
|
438
|
-
"medium",
|
|
439
|
-
"high",
|
|
440
|
-
"xhigh"
|
|
441
|
-
];
|
|
442
|
-
/**
|
|
443
|
-
* Builds the Codex provider plugin, including setup metadata, catalog discovery,
|
|
444
|
-
* dynamic model resolution, and prompt/thinking hooks.
|
|
445
|
-
*/
|
|
446
|
-
function buildCodexProvider(options = {}) {
|
|
447
|
-
return {
|
|
448
|
-
id: CODEX_PROVIDER_ID,
|
|
449
|
-
label: "Codex",
|
|
450
|
-
docsPath: "/providers/models",
|
|
451
|
-
auth: [{
|
|
452
|
-
id: CODEX_APP_SERVER_SETUP_METHOD_ID,
|
|
453
|
-
label: "Codex app-server",
|
|
454
|
-
hint: "Use the Codex app-server runtime and managed model catalog.",
|
|
455
|
-
kind: "custom",
|
|
456
|
-
wizard: {
|
|
457
|
-
choiceId: CODEX_PROVIDER_ID,
|
|
458
|
-
choiceLabel: "Codex app-server",
|
|
459
|
-
choiceHint: "Use the Codex app-server runtime and managed model catalog.",
|
|
460
|
-
assistantPriority: -40,
|
|
461
|
-
groupId: CODEX_PROVIDER_ID,
|
|
462
|
-
groupLabel: "Codex",
|
|
463
|
-
groupHint: "Codex app-server model provider",
|
|
464
|
-
onboardingScopes: ["text-inference"]
|
|
465
|
-
},
|
|
466
|
-
run: async () => ({
|
|
467
|
-
profiles: [],
|
|
468
|
-
defaultModel: CODEX_DEFAULT_MODEL_REF
|
|
469
|
-
})
|
|
470
|
-
}],
|
|
471
|
-
catalog: {
|
|
472
|
-
order: "late",
|
|
473
|
-
run: async (ctx) => {
|
|
474
|
-
const pluginConfig = resolvePluginConfigObject(ctx.config, "codex") ?? (ctx.config ? void 0 : options.pluginConfig);
|
|
475
|
-
return await buildCodexProviderCatalog({
|
|
476
|
-
env: ctx.env,
|
|
477
|
-
pluginConfig,
|
|
478
|
-
listModels: options.listModels
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
},
|
|
482
|
-
staticCatalog: {
|
|
483
|
-
order: "late",
|
|
484
|
-
run: async () => ({ provider: buildCodexProviderConfig(FALLBACK_CODEX_MODELS) })
|
|
485
|
-
},
|
|
486
|
-
resolveDynamicModel: (ctx) => resolveCodexDynamicModel(ctx.modelId),
|
|
487
|
-
resolveSyntheticAuth: () => ({
|
|
488
|
-
apiKey: CODEX_APP_SERVER_AUTH_MARKER,
|
|
489
|
-
source: "codex-app-server",
|
|
490
|
-
mode: "token"
|
|
491
|
-
}),
|
|
492
|
-
fetchUsageSnapshot: async (ctx) => {
|
|
493
|
-
if (ctx.token !== "codex-app-server") return null;
|
|
494
|
-
const appServer = resolveCodexAppServerRuntimeOptions({ pluginConfig: resolvePluginConfigObject(ctx.config, "codex") ?? (ctx.config ? void 0 : options.pluginConfig) });
|
|
495
|
-
return buildCodexAppServerUsageSnapshot(await (options.readRateLimits ?? requestCodexAppServerRateLimitsLazy)({
|
|
496
|
-
timeoutMs: ctx.timeoutMs,
|
|
497
|
-
agentDir: ctx.agentDir,
|
|
498
|
-
...ctx.authProfileId ? { authProfileId: ctx.authProfileId } : {},
|
|
499
|
-
config: ctx.config,
|
|
500
|
-
startOptions: appServer.start
|
|
501
|
-
}));
|
|
502
|
-
},
|
|
503
|
-
resolveThinkingProfile: ({ modelId, compat }) => {
|
|
504
|
-
const efforts = resolveCodexThinkingEfforts({
|
|
505
|
-
modelId,
|
|
506
|
-
supportedReasoningEfforts: readCodexSupportedReasoningEfforts(compat)
|
|
507
|
-
});
|
|
508
|
-
const defaultLevel = GPT_56_DEFAULT_REASONING_EFFORTS.get(modelId.trim().toLowerCase());
|
|
509
|
-
return {
|
|
510
|
-
levels: [{ id: "off" }, ...efforts.map((id) => ({ id }))],
|
|
511
|
-
...defaultLevel && efforts.includes(defaultLevel) ? { defaultLevel } : {}
|
|
512
|
-
};
|
|
513
|
-
},
|
|
514
|
-
resolveSystemPromptContribution: ({ config, modelId }) => resolveCodexSystemPromptContribution({
|
|
515
|
-
config,
|
|
516
|
-
modelId
|
|
517
|
-
}),
|
|
518
|
-
isModernModelRef: ({ modelId }) => isModernCodexModel(modelId)
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
/**
|
|
522
|
-
* Builds the Codex model catalog from live app-server discovery, falling back
|
|
523
|
-
* to built-in model records when discovery is disabled or unavailable.
|
|
524
|
-
*/
|
|
525
|
-
async function buildCodexProviderCatalog(options = {}) {
|
|
526
|
-
const config = readCodexPluginConfig(options.pluginConfig);
|
|
527
|
-
const appServer = resolveCodexAppServerRuntimeOptions({ pluginConfig: options.pluginConfig });
|
|
528
|
-
const timeoutMs = normalizeTimeoutMs(config.discovery?.timeoutMs);
|
|
529
|
-
let discovered = [];
|
|
530
|
-
if (config.discovery?.enabled !== false && !shouldSkipLiveDiscovery(options.env)) discovered = await listModelsBestEffort({
|
|
531
|
-
listModels: options.listModels ?? listCodexAppServerModelsLazy,
|
|
532
|
-
timeoutMs,
|
|
533
|
-
startOptions: appServer.start,
|
|
534
|
-
onDiscoveryFailure: options.onDiscoveryFailure
|
|
535
|
-
});
|
|
536
|
-
return { provider: buildCodexProviderConfig(discovered.length > 0 ? discovered : FALLBACK_CODEX_MODELS) };
|
|
537
|
-
}
|
|
538
|
-
function resolveCodexDynamicModel(modelId) {
|
|
539
|
-
const id = modelId.trim();
|
|
540
|
-
if (!id) return;
|
|
541
|
-
const fallbackModel = FALLBACK_CODEX_MODELS.find((model) => model.id === id);
|
|
542
|
-
return normalizeModelCompat({
|
|
543
|
-
...buildCodexModelDefinition({
|
|
544
|
-
id,
|
|
545
|
-
model: id,
|
|
546
|
-
inputModalities: fallbackModel?.inputModalities ?? ["text"],
|
|
547
|
-
supportedReasoningEfforts: fallbackModel?.supportedReasoningEfforts
|
|
548
|
-
}),
|
|
549
|
-
provider: CODEX_PROVIDER_ID,
|
|
550
|
-
baseUrl: CODEX_BASE_URL
|
|
551
|
-
});
|
|
552
|
-
}
|
|
553
|
-
async function listModelsBestEffort(params) {
|
|
554
|
-
try {
|
|
555
|
-
const models = [];
|
|
556
|
-
let cursor;
|
|
557
|
-
do {
|
|
558
|
-
const result = await params.listModels({
|
|
559
|
-
timeoutMs: params.timeoutMs,
|
|
560
|
-
limit: MODEL_DISCOVERY_PAGE_LIMIT,
|
|
561
|
-
cursor,
|
|
562
|
-
startOptions: params.startOptions,
|
|
563
|
-
sharedClient: false
|
|
564
|
-
});
|
|
565
|
-
models.push(...result.models.filter((model) => !model.hidden));
|
|
566
|
-
cursor = result.nextCursor;
|
|
567
|
-
} while (cursor);
|
|
568
|
-
return models;
|
|
569
|
-
} catch (error) {
|
|
570
|
-
params.onDiscoveryFailure?.(error);
|
|
571
|
-
codexCatalogLog.debug("codex model discovery failed; using fallback catalog", { error: error instanceof Error ? error.message : String(error) });
|
|
572
|
-
return [];
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
async function listCodexAppServerModelsLazy(options) {
|
|
576
|
-
const { listCodexAppServerModels } = await import("./models-DDmO1zwd.js").then((n) => n.r);
|
|
577
|
-
return listCodexAppServerModels(options);
|
|
578
|
-
}
|
|
579
|
-
async function requestCodexAppServerRateLimitsLazy(options) {
|
|
580
|
-
const { requestCodexAppServerJson } = await import("./request-BcJyl8KL.js").then((n) => n.n);
|
|
581
|
-
return await requestCodexAppServerJson({
|
|
582
|
-
method: "account/rateLimits/read",
|
|
583
|
-
timeoutMs: options.timeoutMs,
|
|
584
|
-
agentDir: options.agentDir,
|
|
585
|
-
...options.authProfileId ? { authProfileId: options.authProfileId } : {},
|
|
586
|
-
config: options.config,
|
|
587
|
-
startOptions: options.startOptions,
|
|
588
|
-
isolated: true
|
|
589
|
-
});
|
|
590
|
-
}
|
|
591
|
-
function normalizeTimeoutMs(value) {
|
|
592
|
-
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : DEFAULT_DISCOVERY_TIMEOUT_MS;
|
|
593
|
-
}
|
|
594
|
-
function shouldSkipLiveDiscovery(env = process.env) {
|
|
595
|
-
const override = env[LIVE_DISCOVERY_ENV]?.trim().toLowerCase();
|
|
596
|
-
if (override === "0" || override === "false") return true;
|
|
597
|
-
return Boolean(env.VITEST) && override !== "1";
|
|
598
|
-
}
|
|
599
|
-
function isKnownXHighCodexModel(modelId) {
|
|
600
|
-
const lower = modelId.trim().toLowerCase();
|
|
601
|
-
return lower.startsWith("gpt-5") || lower.startsWith("o3") || lower.startsWith("o4") || lower.includes("codex");
|
|
602
|
-
}
|
|
603
|
-
function normalizeCodexReasoningEfforts(efforts) {
|
|
604
|
-
if (!efforts) return [];
|
|
605
|
-
const supported = new Set(efforts.map((effort) => effort.trim().toLowerCase()));
|
|
606
|
-
return CODEX_REASONING_EFFORTS.filter((effort) => supported.has(effort));
|
|
607
|
-
}
|
|
608
|
-
/** Read app-server reasoning metadata from a runtime model compat union. */
|
|
609
|
-
function readCodexSupportedReasoningEfforts(compat) {
|
|
610
|
-
if (!compat || typeof compat !== "object" || Array.isArray(compat)) return;
|
|
611
|
-
const efforts = compat.supportedReasoningEfforts;
|
|
612
|
-
if (!Array.isArray(efforts)) return;
|
|
613
|
-
const strings = efforts.filter((effort) => typeof effort === "string");
|
|
614
|
-
return strings.some((effort) => effort.trim().toLowerCase() === "none") ? void 0 : strings;
|
|
615
|
-
}
|
|
616
|
-
function resolveCodexThinkingEfforts(params) {
|
|
617
|
-
if (params.supportedReasoningEfforts) return normalizeCodexReasoningEfforts(params.supportedReasoningEfforts);
|
|
618
|
-
const fallbackEfforts = resolveCodexFallbackReasoningEfforts(params.modelId);
|
|
619
|
-
if (fallbackEfforts) return [...fallbackEfforts];
|
|
620
|
-
return [
|
|
621
|
-
"minimal",
|
|
622
|
-
"low",
|
|
623
|
-
"medium",
|
|
624
|
-
"high",
|
|
625
|
-
...isKnownXHighCodexModel(params.modelId) ? ["xhigh"] : [],
|
|
626
|
-
...isMaxReasoningCodexModel(params.modelId) ? ["max"] : []
|
|
627
|
-
];
|
|
628
|
-
}
|
|
629
|
-
/** Map a requested effort onto the authoritative app-server model contract. */
|
|
630
|
-
function resolveCodexSupportedReasoningEffort(params) {
|
|
631
|
-
const supported = normalizeCodexReasoningEfforts(params.supportedReasoningEfforts);
|
|
632
|
-
if (supported.includes(params.requested)) return params.requested;
|
|
633
|
-
const fallbackEfforts = params.requested === "ultra" ? supported : supported.filter((effort) => effort !== "ultra");
|
|
634
|
-
const requestedRank = CODEX_REASONING_EFFORTS.indexOf(params.requested);
|
|
635
|
-
return fallbackEfforts.find((effort) => CODEX_REASONING_EFFORTS.indexOf(effort) >= requestedRank) ?? fallbackEfforts.at(-1);
|
|
636
|
-
}
|
|
637
|
-
/** Return the known effort contract when app-server model metadata is unavailable. */
|
|
638
|
-
function resolveCodexFallbackReasoningEfforts(modelId) {
|
|
639
|
-
const normalized = modelId.trim().toLowerCase();
|
|
640
|
-
if (GPT_56_ULTRA_MODEL_IDS.has(normalized)) return GPT_56_ULTRA_REASONING_EFFORTS;
|
|
641
|
-
if (normalized === "gpt-5.6-luna") return GPT_56_MAX_REASONING_EFFORTS;
|
|
642
|
-
if (normalized === "gpt-5.5-pro" || normalized === "gpt-5.4-pro") return GPT_5_PRO_REASONING_EFFORTS;
|
|
643
|
-
}
|
|
644
|
-
/** Return whether the model uses the modern Codex reasoning profile. */
|
|
645
|
-
function isModernCodexModel(modelId) {
|
|
646
|
-
const lower = modelId.trim().toLowerCase();
|
|
647
|
-
return GPT_56_MAX_MODEL_IDS.has(lower) || lower === "gpt-5.5" || lower === "gpt-5.5-pro" || lower === "gpt-5.4" || lower === "gpt-5.4-pro" || lower === "gpt-5.4-mini" || lower === "gpt-5.3-codex-spark";
|
|
648
|
-
}
|
|
649
|
-
/** Return whether Codex accepts the preview GPT-5.6 `max` reasoning effort. */
|
|
650
|
-
function isMaxReasoningCodexModel(modelId) {
|
|
651
|
-
const lower = modelId.trim().toLowerCase();
|
|
652
|
-
return GPT_56_MAX_MODEL_IDS.has(lower);
|
|
653
|
-
}
|
|
654
|
-
//#endregion
|
|
655
|
-
export { readCodexSupportedReasoningEfforts as a, formatCodexUsageLimitErrorMessage as c, shouldRefreshCodexRateLimitsForUsageLimitMessage as d, summarizeCodexAccountRateLimits as f, isModernCodexModel as i, hasCodexRateLimitSnapshots as l, summarizeCodexRateLimits as m, buildCodexProviderCatalog as n, resolveCodexFallbackReasoningEfforts as o, summarizeCodexAccountUsage as p, isMaxReasoningCodexModel as r, resolveCodexSupportedReasoningEffort as s, buildCodexProvider as t, resolveCodexUsageLimitResetAtMs as u };
|
|
399
|
+
export { shouldRefreshCodexRateLimitsForUsageLimitMessage as a, summarizeCodexRateLimits as c, resolveCodexUsageLimitResetAtMs as i, formatCodexUsageLimitErrorMessage as n, summarizeCodexAccountRateLimits as o, hasCodexRateLimitSnapshots as r, summarizeCodexAccountUsage as s, buildCodexAppServerUsageSnapshot as t };
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { a as getLeasedSharedCodexAppServerClient, c as releaseLeasedSharedCodexAppServerClient, d as retireSharedCodexAppServerClientIfCurrent, i as createIsolatedCodexAppServerClient, m as withTimeout, o as isCodexAppServerStartSelectionChangedError } from "./shared-client-JiAnW6pc.js";
|
|
2
|
+
import { t as resolveCodexAppServerDirectSandboxBypassBlock } from "./sandbox-guard-D1Wky__S.js";
|
|
3
|
+
//#region extensions/codex/src/app-server/request.ts
|
|
4
|
+
/** Sends one guarded request over a client lease owned by the caller. */
|
|
5
|
+
async function requestCodexAppServerClientJson(params) {
|
|
6
|
+
const sandboxBlock = resolveCodexAppServerDirectSandboxBypassBlock({
|
|
7
|
+
method: params.method,
|
|
8
|
+
requestParams: params.requestParams,
|
|
9
|
+
config: params.config,
|
|
10
|
+
sessionKey: params.sessionKey,
|
|
11
|
+
sessionId: params.sessionId
|
|
12
|
+
});
|
|
13
|
+
if (sandboxBlock) throw new Error(sandboxBlock);
|
|
14
|
+
const timeoutMs = params.timeoutMs ?? 6e4;
|
|
15
|
+
return await withTimeout(params.client.request(params.method, params.requestParams, { timeoutMs }), timeoutMs, `codex app-server ${params.method} timed out`);
|
|
16
|
+
}
|
|
17
|
+
async function requestCodexAppServerJson(params) {
|
|
18
|
+
const sandboxBlock = resolveCodexAppServerDirectSandboxBypassBlock({
|
|
19
|
+
method: params.method,
|
|
20
|
+
requestParams: params.requestParams,
|
|
21
|
+
config: params.config,
|
|
22
|
+
sessionKey: params.sessionKey,
|
|
23
|
+
sessionId: params.sessionId
|
|
24
|
+
});
|
|
25
|
+
if (sandboxBlock) throw new Error(sandboxBlock);
|
|
26
|
+
return await withCodexAppServerJsonClient({
|
|
27
|
+
...params,
|
|
28
|
+
timeoutMessage: `codex app-server ${params.method} timed out`
|
|
29
|
+
}, async (request) => await request({
|
|
30
|
+
method: params.method,
|
|
31
|
+
requestParams: params.requestParams
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
const CODEX_USAGE_ISOLATED_SHUTDOWN = {
|
|
35
|
+
forceKillDelayMs: 200,
|
|
36
|
+
exitTimeoutMs: 300
|
|
37
|
+
};
|
|
38
|
+
const CODEX_ACCOUNT_READ_MAX_TIMEOUT_MS = 4e3;
|
|
39
|
+
const CODEX_USAGE_DEADLINE_RESERVE_MS = CODEX_USAGE_ISOLATED_SHUTDOWN.forceKillDelayMs + CODEX_USAGE_ISOLATED_SHUTDOWN.exitTimeoutMs + 250;
|
|
40
|
+
/** Reads rate limits and best-effort account identity from one isolated app-server session. */
|
|
41
|
+
async function readCodexAppServerUsage(options) {
|
|
42
|
+
const deadline = Date.now() + options.timeoutMs;
|
|
43
|
+
return await withCodexAppServerJsonClient({
|
|
44
|
+
timeoutMs: options.timeoutMs,
|
|
45
|
+
timeoutMessage: "codex app-server usage read timed out",
|
|
46
|
+
agentDir: options.agentDir,
|
|
47
|
+
...options.authProfileId ? { authProfileId: options.authProfileId } : {},
|
|
48
|
+
config: options.config,
|
|
49
|
+
startOptions: options.startOptions,
|
|
50
|
+
isolated: true,
|
|
51
|
+
isolatedShutdown: CODEX_USAGE_ISOLATED_SHUTDOWN
|
|
52
|
+
}, async (request) => {
|
|
53
|
+
const rateLimits = await request({ method: "account/rateLimits/read" });
|
|
54
|
+
const accountEmail = await readCodexAccountEmailBestEffort(request, deadline);
|
|
55
|
+
return {
|
|
56
|
+
rateLimits,
|
|
57
|
+
...accountEmail ? { accountEmail } : {}
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function extractCodexAccountEmail(value) {
|
|
62
|
+
if (!value || typeof value !== "object") return;
|
|
63
|
+
const record = value;
|
|
64
|
+
const account = record.account && typeof record.account === "object" ? record.account : record;
|
|
65
|
+
const email = account.email ?? account.accountEmail;
|
|
66
|
+
return typeof email === "string" && email.trim() ? email.trim() : void 0;
|
|
67
|
+
}
|
|
68
|
+
async function readCodexAccountEmailBestEffort(request, deadline) {
|
|
69
|
+
const boundMs = Math.min(CODEX_ACCOUNT_READ_MAX_TIMEOUT_MS, deadline - Date.now() - CODEX_USAGE_DEADLINE_RESERVE_MS);
|
|
70
|
+
if (boundMs <= 0) return;
|
|
71
|
+
const read = request({
|
|
72
|
+
method: "account/read",
|
|
73
|
+
requestParams: {}
|
|
74
|
+
}).then((account) => extractCodexAccountEmail(account), () => void 0);
|
|
75
|
+
let timer;
|
|
76
|
+
const timeout = new Promise((resolve) => {
|
|
77
|
+
timer = setTimeout(() => resolve(void 0), boundMs);
|
|
78
|
+
timer.unref?.();
|
|
79
|
+
});
|
|
80
|
+
try {
|
|
81
|
+
return await Promise.race([read, timeout]);
|
|
82
|
+
} finally {
|
|
83
|
+
if (timer) clearTimeout(timer);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Runs several guarded requests over one acquired client (shared lease or
|
|
88
|
+
* isolated child) so related reads see the same app-server session. The whole
|
|
89
|
+
* callback re-runs once when the client's start selection changed underneath it.
|
|
90
|
+
*/
|
|
91
|
+
async function withCodexAppServerJsonClient(params, run) {
|
|
92
|
+
const timeoutMs = params.timeoutMs ?? 6e4;
|
|
93
|
+
const timeoutMessage = params.timeoutMessage ?? "codex app-server request timed out";
|
|
94
|
+
const timeoutController = new AbortController();
|
|
95
|
+
const deadline = Number.isFinite(timeoutMs) && timeoutMs > 0 ? Date.now() + timeoutMs : void 0;
|
|
96
|
+
const isPastDeadline = () => deadline !== void 0 && Date.now() >= deadline;
|
|
97
|
+
const throwIfAbandoned = () => {
|
|
98
|
+
if (timeoutController.signal.aborted || isPastDeadline()) throw new Error(timeoutMessage);
|
|
99
|
+
};
|
|
100
|
+
const remainingTimeoutMs = () => {
|
|
101
|
+
throwIfAbandoned();
|
|
102
|
+
return deadline === void 0 ? timeoutMs : Math.max(1, deadline - Date.now());
|
|
103
|
+
};
|
|
104
|
+
try {
|
|
105
|
+
return await withTimeout((async () => {
|
|
106
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
107
|
+
throwIfAbandoned();
|
|
108
|
+
const client = await (params.isolated ? createIsolatedCodexAppServerClient : getLeasedSharedCodexAppServerClient)({
|
|
109
|
+
startOptions: params.startOptions,
|
|
110
|
+
pluginConfig: params.pluginConfig,
|
|
111
|
+
timeoutMs: remainingTimeoutMs(),
|
|
112
|
+
authProfileId: params.authProfileId,
|
|
113
|
+
agentDir: params.agentDir,
|
|
114
|
+
config: params.config,
|
|
115
|
+
abandonSignal: timeoutController.signal
|
|
116
|
+
});
|
|
117
|
+
try {
|
|
118
|
+
throwIfAbandoned();
|
|
119
|
+
const scopedRequest = async (request) => {
|
|
120
|
+
const sandboxBlock = resolveCodexAppServerDirectSandboxBypassBlock({
|
|
121
|
+
method: request.method,
|
|
122
|
+
requestParams: request.requestParams,
|
|
123
|
+
config: params.config,
|
|
124
|
+
sessionKey: params.sessionKey,
|
|
125
|
+
sessionId: params.sessionId
|
|
126
|
+
});
|
|
127
|
+
if (sandboxBlock) throw new Error(sandboxBlock);
|
|
128
|
+
throwIfAbandoned();
|
|
129
|
+
return await client.request(request.method, request.requestParams, {
|
|
130
|
+
timeoutMs: remainingTimeoutMs(),
|
|
131
|
+
signal: timeoutController.signal
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
return await run(scopedRequest);
|
|
135
|
+
} catch (error) {
|
|
136
|
+
if (!isCodexAppServerStartSelectionChangedError(error) || attempt > 0) throw error;
|
|
137
|
+
if (!params.isolated) retireSharedCodexAppServerClientIfCurrent(client);
|
|
138
|
+
throwIfAbandoned();
|
|
139
|
+
} finally {
|
|
140
|
+
if (params.isolated) await client.closeAndWait({
|
|
141
|
+
exitTimeoutMs: params.isolatedShutdown?.exitTimeoutMs ?? 2e3,
|
|
142
|
+
forceKillDelayMs: params.isolatedShutdown?.forceKillDelayMs ?? 250
|
|
143
|
+
});
|
|
144
|
+
else releaseLeasedSharedCodexAppServerClient(client);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
throw new Error("Codex app-server selection retry loop exited unexpectedly");
|
|
148
|
+
})(), timeoutMs, timeoutMessage);
|
|
149
|
+
} catch (error) {
|
|
150
|
+
if (isPastDeadline()) throw new Error(timeoutMessage, { cause: error });
|
|
151
|
+
throw error;
|
|
152
|
+
} finally {
|
|
153
|
+
timeoutController.abort();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
//#endregion
|
|
157
|
+
export { requestCodexAppServerClientJson as n, requestCodexAppServerJson as r, readCodexAppServerUsage as t };
|