@openclaw/codex 2026.6.5 → 2026.6.6-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{client-kMCtlApt.js → client-DovmVtbr.js} +3 -10
- package/dist/{client-factory-Bt49r45B.js → client-factory-XajDuvQ1.js} +1 -1
- package/dist/{command-handlers-DMn2M7W7.js → command-handlers-DIUFKqaF.js} +11 -9
- package/dist/{compact-CwnPeYnM.js → compact-BWiNkDSs.js} +96 -9
- package/dist/{computer-use-ClweWaMz.js → computer-use-D3pi5csE.js} +3 -2
- package/dist/{config-BT6SLiE6.js → config-DJXpBkGf.js} +214 -13
- package/dist/{conversation-binding-CzpvaBs1.js → conversation-binding-CMwrZrt7.js} +190 -65
- package/dist/harness.js +12 -5
- package/dist/index.js +11 -10
- package/dist/media-understanding-provider.js +6 -6
- package/dist/{models-DXorTaja.js → models-CQGfP7nG.js} +2 -2
- package/dist/{native-hook-relay-DHwz_ICg.js → native-hook-relay-CmUUO3Eu.js} +160 -4
- package/dist/notification-correlation-D-MYfJwV.js +382 -0
- package/dist/{request-D64BfplD.js → plugin-app-cache-key-NpzxEcSR.js} +4 -36
- package/dist/protocol-oeJQu4rs.js +9 -0
- package/dist/{protocol-validators-CIpP8IJ2.js → protocol-validators-B48C6S9O.js} +2296 -2273
- package/dist/provider-Cs6kWhDQ.js +584 -0
- package/dist/provider.js +1 -164
- package/dist/request-Dq0LUOqZ.js +36 -0
- package/dist/{run-attempt-BWdNnok4.js → run-attempt-DG9p9ReO.js} +374 -65
- package/dist/{session-binding-BgTv_YGm.js → session-binding-ElbcSq2o.js} +107 -44
- package/dist/{shared-client-xytpSKD0.js → shared-client-CflavQ_i.js} +3 -3
- package/dist/{side-question-BnvBQPqW.js → side-question-Ctu2VXAG.js} +82 -26
- package/dist/{thread-lifecycle-BJsazZ8j.js → thread-lifecycle-Cq1-IfZB.js} +115 -34
- package/npm-shrinkwrap.json +30 -30
- package/package.json +5 -5
- package/dist/notification-correlation-o8quHmTK.js +0 -656
|
@@ -1,656 +0,0 @@
|
|
|
1
|
-
import { l as isJsonObject } from "./client-kMCtlApt.js";
|
|
2
|
-
import { MAX_DATE_TIMESTAMP_MS, resolveExpiresAtMsFromEpochSeconds } from "openclaw/plugin-sdk/number-runtime";
|
|
3
|
-
import { asFiniteNumber } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
4
|
-
//#region extensions/codex/src/app-server/rate-limits.ts
|
|
5
|
-
/**
|
|
6
|
-
* Parses Codex account rate-limit payloads into user-facing usage summaries,
|
|
7
|
-
* reset hints, and enriched usage-limit error messages.
|
|
8
|
-
*/
|
|
9
|
-
const CODEX_LIMIT_ID = "codex";
|
|
10
|
-
const LIMIT_WINDOW_KEYS = ["primary", "secondary"];
|
|
11
|
-
const ONE_SECOND_MS = 1e3;
|
|
12
|
-
const ONE_MINUTE_MS = 6e4;
|
|
13
|
-
const ONE_HOUR_MS = 60 * ONE_MINUTE_MS;
|
|
14
|
-
const ONE_DAY_MS = 24 * ONE_HOUR_MS;
|
|
15
|
-
/** Enriches Codex usage-limit failures with reset timing and recovery guidance. */
|
|
16
|
-
function formatCodexUsageLimitErrorMessage(params) {
|
|
17
|
-
const message = normalizeText(params.message);
|
|
18
|
-
if (!isCodexUsageLimitError(params.codexErrorInfo, message)) return;
|
|
19
|
-
const nowMs = params.nowMs ?? Date.now();
|
|
20
|
-
const usageSummary = summarizeCodexAccountUsage(params.rateLimits, nowMs);
|
|
21
|
-
const nextReset = selectBlockingRateLimitReset(params.rateLimits, nowMs) ?? (usageSummary?.blocked ? void 0 : selectNextRateLimitReset(params.rateLimits, nowMs));
|
|
22
|
-
const parts = ["You've reached your Codex subscription usage limit."];
|
|
23
|
-
let recoveryAction = "Wait until Codex becomes available";
|
|
24
|
-
if (nextReset) {
|
|
25
|
-
parts.push(`Next reset ${formatResetTime(nextReset.resetsAtMs, nowMs)}.`);
|
|
26
|
-
recoveryAction = "Wait until the reset time";
|
|
27
|
-
} else {
|
|
28
|
-
const codexRetryHint = extractCodexRetryHint(message);
|
|
29
|
-
if (codexRetryHint) {
|
|
30
|
-
parts.push(`Codex says to try again ${codexRetryHint}.`);
|
|
31
|
-
recoveryAction = "Wait until the retry time";
|
|
32
|
-
} else {
|
|
33
|
-
if (usageSummary?.blockingPeriod && usageSummary.blockingReason) parts.push(`Your ${usageSummary.blockingReason}.`);
|
|
34
|
-
parts.push("OpenClaw could not determine a reset time from Codex.");
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
parts.push(`${recoveryAction}, use another Codex account if available, or switch to another configured model/provider.`);
|
|
38
|
-
return parts.join(" ");
|
|
39
|
-
}
|
|
40
|
-
/** Detects usage-limit messages that need a fresh rate-limit query before display. */
|
|
41
|
-
function shouldRefreshCodexRateLimitsForUsageLimitMessage(message) {
|
|
42
|
-
const text = normalizeText(message);
|
|
43
|
-
return Boolean(text?.includes("You've reached your Codex subscription usage limit.") && !text.includes("Next reset "));
|
|
44
|
-
}
|
|
45
|
-
/** Formats compact summaries for raw Codex rate-limit snapshot payloads. */
|
|
46
|
-
function summarizeCodexRateLimits(value, nowMs = Date.now()) {
|
|
47
|
-
const snapshots = collectCodexRateLimitSnapshots(value).filter(snapshotHasDisplayableData);
|
|
48
|
-
if (snapshots.length === 0) return;
|
|
49
|
-
const summaries = snapshots.slice(0, 4).map((snapshot) => summarizeRateLimitSnapshot(snapshot, nowMs)).filter((summary) => summary !== void 0);
|
|
50
|
-
return summaries.length > 0 ? summaries.join("; ") : void 0;
|
|
51
|
-
}
|
|
52
|
-
/** Returns true when a value contains any recognizable Codex rate-limit snapshots. */
|
|
53
|
-
function hasCodexRateLimitSnapshots(value) {
|
|
54
|
-
return collectCodexRateLimitSnapshots(value).length > 0;
|
|
55
|
-
}
|
|
56
|
-
/** Builds short account availability lines suitable for status surfaces. */
|
|
57
|
-
function summarizeCodexAccountRateLimits(value, nowMs = Date.now()) {
|
|
58
|
-
const summary = summarizeCodexAccountUsage(value, nowMs);
|
|
59
|
-
if (!summary) return;
|
|
60
|
-
if (!summary.blocked) return ["Codex is available."];
|
|
61
|
-
return [summary.blockedUntilText ? `Codex is paused until ${summary.blockedUntilText}.` : "Codex is paused by a usage limit.", summary.blockingReason ? `Your ${summary.blockingReason}.` : "Your Codex usage limit is reached."];
|
|
62
|
-
}
|
|
63
|
-
/** Returns the reset timestamp for the currently blocking Codex usage limit. */
|
|
64
|
-
function resolveCodexUsageLimitResetAtMs(value, nowMs = Date.now()) {
|
|
65
|
-
return selectBlockingRateLimitReset(value, nowMs)?.resetsAtMs;
|
|
66
|
-
}
|
|
67
|
-
/** Summarizes account availability, blocking reason, and reset time from rate-limit data. */
|
|
68
|
-
function summarizeCodexAccountUsage(value, nowMs = Date.now()) {
|
|
69
|
-
const snapshots = collectCodexRateLimitSnapshots(value).filter(snapshotHasDisplayableData);
|
|
70
|
-
if (snapshots.length === 0) return;
|
|
71
|
-
const usageSnapshot = snapshots.find(isCodexLimitSnapshot) ?? snapshots[0];
|
|
72
|
-
const blockedSnapshots = snapshots.filter(snapshotHasLimitBlock);
|
|
73
|
-
const blockingSnapshot = blockedSnapshots.find(isCodexLimitSnapshot) ?? blockedSnapshots[0] ?? void 0;
|
|
74
|
-
const blockingWindow = blockingSnapshot ? selectSnapshotBlockingWindow(blockingSnapshot, nowMs) : void 0;
|
|
75
|
-
const blockingReset = blockingWindow && blockingWindow.resetsAtMs > nowMs ? blockingWindow : void 0;
|
|
76
|
-
const blockingPeriod = formatBlockingLimitPeriod(blockingWindow?.windowDurationMins);
|
|
77
|
-
const blockedUntilText = blockingReset ? formatAccountResetTime(blockingReset.resetsAtMs, nowMs) : void 0;
|
|
78
|
-
const blockedResetRelative = blockingReset ? `in ${formatRelativeDuration(blockingReset.resetsAtMs - nowMs)}` : void 0;
|
|
79
|
-
const blockingReason = blockingPeriod ? `${blockingPeriod} Codex usage limit is reached` : blockingSnapshot ? "Codex usage limit is reached" : void 0;
|
|
80
|
-
return {
|
|
81
|
-
usageLine: formatUsageLine(usageSnapshot),
|
|
82
|
-
blocked: Boolean(blockingSnapshot),
|
|
83
|
-
...blockingReset ? { blockedUntilMs: blockingReset.resetsAtMs } : {},
|
|
84
|
-
...blockedUntilText ? { blockedUntilText } : {},
|
|
85
|
-
...blockedResetRelative ? { blockedResetRelative } : {},
|
|
86
|
-
...blockingPeriod ? { blockingPeriod } : {},
|
|
87
|
-
...blockingReason ? { blockingReason } : {}
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
function isCodexUsageLimitError(codexErrorInfo, message) {
|
|
91
|
-
if (codexErrorInfo === "usageLimitExceeded") return true;
|
|
92
|
-
if (typeof codexErrorInfo === "string") {
|
|
93
|
-
if (codexErrorInfo.replace(/[_\s-]/gu, "").toLowerCase() === "usagelimitexceeded") return true;
|
|
94
|
-
}
|
|
95
|
-
return Boolean(message?.toLowerCase().includes("usage limit"));
|
|
96
|
-
}
|
|
97
|
-
function selectNextRateLimitReset(value, nowMs) {
|
|
98
|
-
const futureWindows = collectCodexRateLimitSnapshots(value).flatMap((snapshot) => LIMIT_WINDOW_KEYS.flatMap((key) => readRateLimitWindow(snapshot, key) ?? [])).filter((window) => window.resetsAtMs > nowMs);
|
|
99
|
-
if (futureWindows.length === 0) return;
|
|
100
|
-
const exhaustedWindows = futureWindows.filter((window) => window.usedPercent !== void 0 && window.usedPercent >= 100);
|
|
101
|
-
return (exhaustedWindows.length > 0 ? exhaustedWindows : futureWindows).toSorted((left, right) => left.resetsAtMs - right.resetsAtMs)[0];
|
|
102
|
-
}
|
|
103
|
-
function selectBlockingRateLimitReset(value, nowMs) {
|
|
104
|
-
const blockedSnapshots = collectCodexRateLimitSnapshots(value).filter(snapshotHasLimitBlock);
|
|
105
|
-
const blockingSnapshot = blockedSnapshots.find(isCodexLimitSnapshot) ?? blockedSnapshots[0] ?? void 0;
|
|
106
|
-
return blockingSnapshot ? selectSnapshotBlockingReset(blockingSnapshot, nowMs) : void 0;
|
|
107
|
-
}
|
|
108
|
-
function summarizeRateLimitSnapshot(snapshot, nowMs) {
|
|
109
|
-
const label = formatLimitLabel(snapshot);
|
|
110
|
-
const windows = LIMIT_WINDOW_KEYS.flatMap((key) => {
|
|
111
|
-
const window = readRateLimitWindow(snapshot, key);
|
|
112
|
-
return window ? [formatRateLimitWindow(key, window, nowMs)] : [];
|
|
113
|
-
});
|
|
114
|
-
const reachedType = readString$2(snapshot, "rateLimitReachedType") ?? readString$2(snapshot, "rate_limit_reached_type");
|
|
115
|
-
const suffix = reachedType ? ` (${formatReachedType(reachedType)})` : "";
|
|
116
|
-
if (windows.length > 0) return `${label}: ${windows.join(" · ")}${suffix}`;
|
|
117
|
-
if (reachedType) return `${label}: ${formatReachedType(reachedType)}`;
|
|
118
|
-
}
|
|
119
|
-
function collectCodexRateLimitSnapshots(value) {
|
|
120
|
-
const snapshots = [];
|
|
121
|
-
collectRateLimitSnapshots(value, snapshots, /* @__PURE__ */ new Set());
|
|
122
|
-
return snapshots;
|
|
123
|
-
}
|
|
124
|
-
function collectRateLimitSnapshots(value, snapshots, seen) {
|
|
125
|
-
if (Array.isArray(value)) {
|
|
126
|
-
for (const entry of value) collectRateLimitSnapshots(entry, snapshots, seen);
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
if (!isJsonObject(value)) return;
|
|
130
|
-
if (isRateLimitSnapshot(value)) {
|
|
131
|
-
addRateLimitSnapshot(value, snapshots, seen);
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
const byLimitId = value.rateLimitsByLimitId;
|
|
135
|
-
if (isJsonObject(byLimitId)) for (const key of sortedRateLimitKeys(Object.keys(byLimitId))) collectRateLimitSnapshots(byLimitId[key], snapshots, seen);
|
|
136
|
-
const snakeByLimitId = value.rate_limits_by_limit_id;
|
|
137
|
-
if (isJsonObject(snakeByLimitId)) for (const key of sortedRateLimitKeys(Object.keys(snakeByLimitId))) collectRateLimitSnapshots(snakeByLimitId[key], snapshots, seen);
|
|
138
|
-
collectRateLimitSnapshots(value.rateLimits, snapshots, seen);
|
|
139
|
-
collectRateLimitSnapshots(value.rate_limits, snapshots, seen);
|
|
140
|
-
collectRateLimitSnapshots(value.data, snapshots, seen);
|
|
141
|
-
collectRateLimitSnapshots(value.items, snapshots, seen);
|
|
142
|
-
}
|
|
143
|
-
function sortedRateLimitKeys(keys) {
|
|
144
|
-
return keys.toSorted((left, right) => {
|
|
145
|
-
if (left === CODEX_LIMIT_ID) return -1;
|
|
146
|
-
if (right === CODEX_LIMIT_ID) return 1;
|
|
147
|
-
return left.localeCompare(right);
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
function addRateLimitSnapshot(snapshot, snapshots, seen) {
|
|
151
|
-
const signature = [
|
|
152
|
-
readNullableString(snapshot, "limitId") ?? readNullableString(snapshot, "limit_id") ?? "",
|
|
153
|
-
readNullableString(snapshot, "limitName") ?? readNullableString(snapshot, "limit_name") ?? "",
|
|
154
|
-
formatWindowSignature(snapshot.primary),
|
|
155
|
-
formatWindowSignature(snapshot.secondary)
|
|
156
|
-
].join("|");
|
|
157
|
-
if (seen.has(signature)) return;
|
|
158
|
-
seen.add(signature);
|
|
159
|
-
snapshots.push(snapshot);
|
|
160
|
-
}
|
|
161
|
-
function isRateLimitSnapshot(value) {
|
|
162
|
-
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;
|
|
163
|
-
}
|
|
164
|
-
function readRateLimitWindow(snapshot, key) {
|
|
165
|
-
const window = snapshot[key];
|
|
166
|
-
if (!isJsonObject(window)) return;
|
|
167
|
-
return {
|
|
168
|
-
resetsAtMs: resolveExpiresAtMsFromEpochSeconds(readNumber(window, "resetsAt") ?? readNumber(window, "resets_at"), { maxMs: MAX_DATE_TIMESTAMP_MS }) ?? 0,
|
|
169
|
-
...readOptionalNumberField(window, "usedPercent", "used_percent"),
|
|
170
|
-
...readOptionalNumberField(window, "windowDurationMins", "window_duration_mins", "windowMinutes", "window_minutes")
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
function snapshotHasDisplayableData(snapshot) {
|
|
174
|
-
if (readString$2(snapshot, "rateLimitReachedType") ?? readString$2(snapshot, "rate_limit_reached_type")) return true;
|
|
175
|
-
return readWindowEntries(snapshot).some((entry) => entry.window.usedPercent !== void 0 || entry.window.resetsAtMs > 0);
|
|
176
|
-
}
|
|
177
|
-
function readOptionalNumberField(record, ...keys) {
|
|
178
|
-
const value = keys.map((key) => readNumber(record, key)).find((entry) => entry !== void 0);
|
|
179
|
-
if (value === void 0) return {};
|
|
180
|
-
return keys.some((key) => key.toLowerCase().includes("window")) ? { windowDurationMins: value } : { usedPercent: value };
|
|
181
|
-
}
|
|
182
|
-
function formatRateLimitWindow(key, window, nowMs) {
|
|
183
|
-
return `${key} ${formatRateLimitWindowDetails(window, nowMs)}`;
|
|
184
|
-
}
|
|
185
|
-
function formatRateLimitWindowDetails(window, nowMs) {
|
|
186
|
-
return `${window.usedPercent === void 0 ? "usage unknown" : `${Math.max(0, 100 - Math.round(window.usedPercent))}% left`}${window.resetsAtMs > nowMs ? ` ⏱${formatResetDuration(window.resetsAtMs, nowMs)}` : ""}`;
|
|
187
|
-
}
|
|
188
|
-
function formatLimitLabel(snapshot) {
|
|
189
|
-
const label = readNullableString(snapshot, "limitName") ?? readNullableString(snapshot, "limit_name") ?? readNullableString(snapshot, "limitId") ?? readNullableString(snapshot, "limit_id");
|
|
190
|
-
if (!label || label === CODEX_LIMIT_ID) return "Codex";
|
|
191
|
-
return label.replace(/[_-]+/gu, " ").replace(/\s+/gu, " ").trim();
|
|
192
|
-
}
|
|
193
|
-
function formatReachedType(value) {
|
|
194
|
-
return value.replace(/[_-]+/gu, " ").replace(/\s+/gu, " ").trim();
|
|
195
|
-
}
|
|
196
|
-
function formatResetTime(resetsAtMs, nowMs) {
|
|
197
|
-
return `in ${formatRelativeDuration(resetsAtMs - nowMs)}, ${formatCalendarResetTime(resetsAtMs, nowMs)}`;
|
|
198
|
-
}
|
|
199
|
-
function formatAccountResetTime(resetsAtMs, nowMs) {
|
|
200
|
-
return `${formatCalendarResetTime(resetsAtMs, nowMs)} (in ${formatRelativeDuration(resetsAtMs - nowMs)})`;
|
|
201
|
-
}
|
|
202
|
-
function snapshotHasLimitBlock(snapshot) {
|
|
203
|
-
return Boolean(readString$2(snapshot, "rateLimitReachedType") ?? readString$2(snapshot, "rate_limit_reached_type") ?? readWindowEntries(snapshot).some((entry) => entry.window.usedPercent !== void 0 && entry.window.usedPercent >= 100));
|
|
204
|
-
}
|
|
205
|
-
function isCodexLimitSnapshot(snapshot) {
|
|
206
|
-
const id = readNullableString(snapshot, "limitId") ?? readNullableString(snapshot, "limit_id");
|
|
207
|
-
return !id || id === CODEX_LIMIT_ID;
|
|
208
|
-
}
|
|
209
|
-
function selectSnapshotBlockingReset(snapshot, nowMs) {
|
|
210
|
-
const futureWindows = readWindowEntries(snapshot).map((entry) => entry.window).filter((window) => window.resetsAtMs > nowMs);
|
|
211
|
-
const exhaustedWindows = futureWindows.filter((window) => window.usedPercent !== void 0 && window.usedPercent >= 100);
|
|
212
|
-
const candidates = exhaustedWindows.length > 0 ? exhaustedWindows : futureWindows;
|
|
213
|
-
const resetSort = exhaustedWindows.length > 0 ? (left, right) => right.resetsAtMs - left.resetsAtMs : (left, right) => left.resetsAtMs - right.resetsAtMs;
|
|
214
|
-
return candidates.toSorted(resetSort)[0];
|
|
215
|
-
}
|
|
216
|
-
function selectSnapshotBlockingWindow(snapshot, nowMs) {
|
|
217
|
-
const resetWindow = selectSnapshotBlockingReset(snapshot, nowMs);
|
|
218
|
-
if (resetWindow) return resetWindow;
|
|
219
|
-
return readWindowEntries(snapshot).map((entry) => entry.window).filter((window) => window.usedPercent !== void 0 && window.usedPercent >= 100).toSorted((left, right) => (right.windowDurationMins ?? 0) - (left.windowDurationMins ?? 0))[0];
|
|
220
|
-
}
|
|
221
|
-
function readWindowEntries(snapshot) {
|
|
222
|
-
return LIMIT_WINDOW_KEYS.flatMap((key) => {
|
|
223
|
-
const window = readRateLimitWindow(snapshot, key);
|
|
224
|
-
return window ? [{
|
|
225
|
-
key,
|
|
226
|
-
window
|
|
227
|
-
}] : [];
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
function formatBlockingLimitPeriod(minutes) {
|
|
231
|
-
if (minutes === 10080) return "weekly";
|
|
232
|
-
if (minutes === 1440) return "daily";
|
|
233
|
-
if (minutes !== void 0 && minutes > 0 && minutes < 1440) return "short-term";
|
|
234
|
-
}
|
|
235
|
-
function formatUsageLine(snapshot) {
|
|
236
|
-
const windows = readWindowEntries(snapshot).filter((entry) => entry.window.usedPercent !== void 0).toSorted((left, right) => (right.window.windowDurationMins ?? 0) - (left.window.windowDurationMins ?? 0)).map((entry) => {
|
|
237
|
-
return `${formatUsageWindowLabel(entry.window.windowDurationMins)} ${Math.round(entry.window.usedPercent ?? 0)}%`;
|
|
238
|
-
});
|
|
239
|
-
return windows.length > 0 ? windows.join(" · ") : void 0;
|
|
240
|
-
}
|
|
241
|
-
function formatUsageWindowLabel(minutes) {
|
|
242
|
-
if (minutes === 10080) return "weekly";
|
|
243
|
-
if (minutes === 1440) return "daily";
|
|
244
|
-
if (minutes !== void 0 && minutes > 0 && minutes < 1440) return "short-term";
|
|
245
|
-
if (minutes !== void 0 && minutes > 0 && minutes % 1440 === 0) return `${minutes / 1440}-day`;
|
|
246
|
-
if (minutes !== void 0 && minutes > 0 && minutes % 60 === 0) return `${minutes / 60}-hour`;
|
|
247
|
-
return "usage";
|
|
248
|
-
}
|
|
249
|
-
function formatCalendarResetTime(resetsAtMs, nowMs) {
|
|
250
|
-
const resetDate = new Date(resetsAtMs);
|
|
251
|
-
const resetParts = new Intl.DateTimeFormat("en-US", {
|
|
252
|
-
month: "short",
|
|
253
|
-
day: "numeric",
|
|
254
|
-
...resetDate.getFullYear() === new Date(nowMs).getFullYear() ? {} : { year: "numeric" },
|
|
255
|
-
hour: "numeric",
|
|
256
|
-
minute: "2-digit",
|
|
257
|
-
timeZoneName: "short"
|
|
258
|
-
}).formatToParts(resetDate);
|
|
259
|
-
const part = (type) => resetParts.find((entry) => entry.type === type)?.value;
|
|
260
|
-
const dateParts = [
|
|
261
|
-
part("month"),
|
|
262
|
-
part("day"),
|
|
263
|
-
part("year")
|
|
264
|
-
].filter(Boolean);
|
|
265
|
-
return [
|
|
266
|
-
dateParts.length > 1 ? `${dateParts[0]} ${dateParts.slice(1).join(", ")}` : dateParts[0],
|
|
267
|
-
"at",
|
|
268
|
-
[
|
|
269
|
-
[part("hour"), part("minute")].filter(Boolean).join(":"),
|
|
270
|
-
part("dayPeriod"),
|
|
271
|
-
part("timeZoneName")
|
|
272
|
-
].filter(Boolean).join(" ")
|
|
273
|
-
].filter(Boolean).join(" ");
|
|
274
|
-
}
|
|
275
|
-
function formatRelativeDuration(durationMs) {
|
|
276
|
-
const safeMs = Math.max(1e3, durationMs);
|
|
277
|
-
if (safeMs < ONE_MINUTE_MS) return `${Math.ceil(safeMs / 1e3)} seconds`;
|
|
278
|
-
if (safeMs < ONE_HOUR_MS) {
|
|
279
|
-
const minutes = Math.ceil(safeMs / ONE_MINUTE_MS);
|
|
280
|
-
return `${minutes} ${minutes === 1 ? "minute" : "minutes"}`;
|
|
281
|
-
}
|
|
282
|
-
if (safeMs < ONE_DAY_MS) {
|
|
283
|
-
const hours = Math.ceil(safeMs / ONE_HOUR_MS);
|
|
284
|
-
return `${hours} ${hours === 1 ? "hour" : "hours"}`;
|
|
285
|
-
}
|
|
286
|
-
const days = Math.ceil(safeMs / ONE_DAY_MS);
|
|
287
|
-
return `${days} ${days === 1 ? "day" : "days"}`;
|
|
288
|
-
}
|
|
289
|
-
function formatResetDuration(resetsAtMs, nowMs) {
|
|
290
|
-
const durationMs = Math.round(Math.max(ONE_SECOND_MS, resetsAtMs - nowMs) / ONE_SECOND_MS) * ONE_SECOND_MS;
|
|
291
|
-
const days = Math.floor(durationMs / ONE_DAY_MS);
|
|
292
|
-
const hours = Math.floor(durationMs % ONE_DAY_MS / ONE_HOUR_MS);
|
|
293
|
-
const minutes = Math.floor(durationMs % ONE_HOUR_MS / ONE_MINUTE_MS);
|
|
294
|
-
const seconds = Math.floor(durationMs % ONE_MINUTE_MS / ONE_SECOND_MS);
|
|
295
|
-
if (days > 0) return hours > 0 ? `${days}d ${hours}h` : `${days}d`;
|
|
296
|
-
if (hours > 0) return minutes > 0 ? `${hours}h ${minutes}m` : `${hours}h`;
|
|
297
|
-
if (minutes > 0) return seconds > 0 ? `${minutes}m ${seconds}s` : `${minutes}m`;
|
|
298
|
-
return `${seconds}s`;
|
|
299
|
-
}
|
|
300
|
-
function formatWindowSignature(value) {
|
|
301
|
-
if (!isJsonObject(value)) return "";
|
|
302
|
-
return `${readNumber(value, "usedPercent") ?? readNumber(value, "used_percent") ?? ""}:${readNumber(value, "resetsAt") ?? readNumber(value, "resets_at") ?? ""}`;
|
|
303
|
-
}
|
|
304
|
-
function extractCodexRetryHint(message) {
|
|
305
|
-
if (!message) return;
|
|
306
|
-
const tryAgainAt = /\btry again\s+(at\s+[^.!?\n]+)(?:[.!?]|$)/iu.exec(message);
|
|
307
|
-
if (tryAgainAt?.[1]) return tryAgainAt[1].trim();
|
|
308
|
-
return /\btry again\s+((?:tomorrow|in\s+[^.!?\n]+)[^.!?\n]*)(?:[.!?]|$)/iu.exec(message)?.[1]?.trim();
|
|
309
|
-
}
|
|
310
|
-
function readString$2(record, key) {
|
|
311
|
-
const value = record[key];
|
|
312
|
-
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
313
|
-
}
|
|
314
|
-
function readNullableString(record, key) {
|
|
315
|
-
return readString$2(record, key) ?? void 0;
|
|
316
|
-
}
|
|
317
|
-
function readNumber(record, key) {
|
|
318
|
-
return asFiniteNumber(record[key]);
|
|
319
|
-
}
|
|
320
|
-
function normalizeText(value) {
|
|
321
|
-
const text = value?.trim();
|
|
322
|
-
return text ? text : void 0;
|
|
323
|
-
}
|
|
324
|
-
//#endregion
|
|
325
|
-
//#region extensions/codex/src/command-formatters.ts
|
|
326
|
-
/** Formats the combined `/codex status` probe result. */
|
|
327
|
-
function formatCodexStatus(probes) {
|
|
328
|
-
const lines = [`Codex app-server: ${probes.models.ok || probes.account.ok || probes.limits.ok || probes.mcps.ok || probes.skills.ok ? "connected" : "unavailable"}`];
|
|
329
|
-
if (probes.models.ok) lines.push(`Models: ${probes.models.value.models.map((model) => formatCodexDisplayText(model.id)).slice(0, 8).join(", ") || "none"}`);
|
|
330
|
-
else lines.push(`Models: ${formatCodexDisplayText(probes.models.error)}`);
|
|
331
|
-
lines.push(`Account: ${probes.account.ok ? formatCodexAccountSummary(probes.account.value) : formatCodexDisplayText(probes.account.error)}`);
|
|
332
|
-
lines.push(`Rate limits: ${probes.limits.ok ? formatCodexRateLimitSummary(probes.limits.value) : formatCodexDisplayText(probes.limits.error)}`);
|
|
333
|
-
lines.push(`MCP servers: ${probes.mcps.ok ? summarizeArrayLike(probes.mcps.value) : formatCodexDisplayText(probes.mcps.error)}`);
|
|
334
|
-
lines.push(`Skills: ${probes.skills.ok ? summarizeCodexSkills(probes.skills.value) : formatCodexDisplayText(probes.skills.error)}`);
|
|
335
|
-
return lines.join("\n");
|
|
336
|
-
}
|
|
337
|
-
/** Formats Codex model-list results for `/codex models`. */
|
|
338
|
-
function formatModels(result) {
|
|
339
|
-
if (result.models.length === 0) return "No Codex app-server models returned.";
|
|
340
|
-
const lines = ["Codex models:", ...result.models.map((model) => `- ${formatCodexDisplayText(model.id)}${model.isDefault ? " (default)" : ""}`)];
|
|
341
|
-
if (result.truncated) lines.push("- More models available; output truncated.");
|
|
342
|
-
return lines.join("\n");
|
|
343
|
-
}
|
|
344
|
-
/** Formats Codex thread-list responses with safe resume hints. */
|
|
345
|
-
function formatThreads(response) {
|
|
346
|
-
const threads = extractArray(response);
|
|
347
|
-
if (threads.length === 0) return "No Codex threads returned.";
|
|
348
|
-
return ["Codex threads:", ...threads.slice(0, 10).map((thread) => {
|
|
349
|
-
const record = isJsonObject(thread) ? thread : {};
|
|
350
|
-
const id = readString$1(record, "threadId") ?? readString$1(record, "id") ?? "<unknown>";
|
|
351
|
-
const title = readString$1(record, "title") ?? readString$1(record, "name") ?? readString$1(record, "summary");
|
|
352
|
-
const details = [
|
|
353
|
-
readString$1(record, "model"),
|
|
354
|
-
readString$1(record, "cwd"),
|
|
355
|
-
readString$1(record, "updatedAt") ?? readString$1(record, "lastUpdatedAt")
|
|
356
|
-
].filter((value) => Boolean(value));
|
|
357
|
-
return `- ${formatCodexDisplayText(id)}${title ? ` - ${formatCodexDisplayText(title)}` : ""}${details.length > 0 ? ` (${details.map(formatCodexDisplayText).join(", ")})` : ""}\n Resume: ${formatCodexResumeHint(id)}`;
|
|
358
|
-
})].join("\n");
|
|
359
|
-
}
|
|
360
|
-
/** Formats account and rate-limit output for `/codex account`. */
|
|
361
|
-
function formatAccount(account, limits, authOverview) {
|
|
362
|
-
if (authOverview) return formatAccountAuthOverview(authOverview);
|
|
363
|
-
const formattedLimits = limits.ok ? formatCodexRateLimitDetails(limits.value) : formatCodexDisplayText(limits.error);
|
|
364
|
-
const rateLimitBlock = formattedLimits.startsWith("Codex is ") ? formattedLimits : formattedLimits.includes("\n") ? `Rate limits:\n${formattedLimits}` : `Rate limits: ${formattedLimits}`;
|
|
365
|
-
return [`Account: ${account.ok ? formatCodexAccountSummary(account.value) : formatCodexDisplayText(account.error)}`, rateLimitBlock].join("\n\n");
|
|
366
|
-
}
|
|
367
|
-
function formatAccountAuthOverview(overview) {
|
|
368
|
-
const lines = [];
|
|
369
|
-
if (overview.currentLine) lines.push(overview.currentLine, "");
|
|
370
|
-
if (overview.subscriptionLabel) {
|
|
371
|
-
lines.push(`Subscription ${overview.subscriptionLabel}`);
|
|
372
|
-
if (overview.subscriptionUsage) lines.push(` ${overview.subscriptionUsage}`);
|
|
373
|
-
lines.push("");
|
|
374
|
-
}
|
|
375
|
-
if (overview.rows.length > 0) {
|
|
376
|
-
lines.push(overview.orderTitle);
|
|
377
|
-
for (const [index, row] of overview.rows.entries()) lines.push(` ${index + 1}. ${row.label} ${row.kind} — ${formatAuthRowStatus(row)}`);
|
|
378
|
-
}
|
|
379
|
-
while (lines.at(-1) === "") lines.pop();
|
|
380
|
-
return lines.map(formatCodexAccountLine).join("\n");
|
|
381
|
-
}
|
|
382
|
-
function formatAuthRowStatus(row) {
|
|
383
|
-
return row.billingNote ? `${row.status} · ${row.billingNote}` : row.status;
|
|
384
|
-
}
|
|
385
|
-
/** Formats Codex Computer Use readiness and plugin/MCP availability. */
|
|
386
|
-
function formatComputerUseStatus(status) {
|
|
387
|
-
const lines = [`Computer Use: ${status.ready ? "ready" : status.enabled ? "not ready" : "disabled"}`];
|
|
388
|
-
lines.push(`Plugin: ${formatCodexDisplayText(status.pluginName)} (${computerUsePluginState(status)})`);
|
|
389
|
-
lines.push(`MCP server: ${formatCodexDisplayText(status.mcpServerName)}${status.mcpServerAvailable ? ` (${status.tools.length} tools)` : " (unavailable)"}`);
|
|
390
|
-
if (status.marketplaceName) lines.push(`Marketplace: ${formatCodexDisplayText(status.marketplaceName)}`);
|
|
391
|
-
if (status.tools.length > 0) lines.push(`Tools: ${status.tools.slice(0, 8).map(formatCodexDisplayText).join(", ")}`);
|
|
392
|
-
lines.push(formatCodexDisplayText(status.message));
|
|
393
|
-
return lines.join("\n");
|
|
394
|
-
}
|
|
395
|
-
function computerUsePluginState(status) {
|
|
396
|
-
if (!status.installed) return "not installed";
|
|
397
|
-
return status.pluginEnabled ? "installed" : "installed, disabled";
|
|
398
|
-
}
|
|
399
|
-
/** Formats generic array-like Codex app-server responses. */
|
|
400
|
-
function formatList(response, label) {
|
|
401
|
-
const entries = extractArray(response);
|
|
402
|
-
if (entries.length === 0) return `${label}: none returned.`;
|
|
403
|
-
return [`${label}:`, ...entries.slice(0, 25).map((entry) => {
|
|
404
|
-
const record = isJsonObject(entry) ? entry : {};
|
|
405
|
-
return `- ${formatCodexDisplayText(readString$1(record, "name") ?? readString$1(record, "id") ?? JSON.stringify(entry))}`;
|
|
406
|
-
})].join("\n");
|
|
407
|
-
}
|
|
408
|
-
/** Formats Codex skills grouped by scope, omitting disabled entries. */
|
|
409
|
-
function formatSkills(response) {
|
|
410
|
-
const groups = isJsonObject(response) && Array.isArray(response.data) ? response.data : [];
|
|
411
|
-
if (groups.length === 0) return "Codex skills: none returned.";
|
|
412
|
-
const lines = ["Codex skills:"];
|
|
413
|
-
let renderedSkills = 0;
|
|
414
|
-
let loadErrors = 0;
|
|
415
|
-
for (const group of groups) {
|
|
416
|
-
const record = isJsonObject(group) ? group : {};
|
|
417
|
-
if (Array.isArray(record.errors)) loadErrors += record.errors.length;
|
|
418
|
-
const skills = Array.isArray(record.skills) ? record.skills : [];
|
|
419
|
-
if (skills.length === 0) continue;
|
|
420
|
-
for (const skill of skills) {
|
|
421
|
-
if (isJsonObject(skill) && skill.enabled === false) continue;
|
|
422
|
-
lines.push(`- ${formatCodexSkillEntry(skill)}`);
|
|
423
|
-
renderedSkills += 1;
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
if (renderedSkills === 0) {
|
|
427
|
-
if (loadErrors > 0) return `Codex skills: none returned (${loadErrors} load ${loadErrors === 1 ? "error" : "errors"}).`;
|
|
428
|
-
return "Codex skills: none returned.";
|
|
429
|
-
}
|
|
430
|
-
return lines.join("\n");
|
|
431
|
-
}
|
|
432
|
-
function formatCodexSkillEntry(entry) {
|
|
433
|
-
return `\`${formatCodexDisplayText(readString$1(isJsonObject(entry) ? entry : {}, "name") ?? "<unknown>")}\``;
|
|
434
|
-
}
|
|
435
|
-
const CODEX_RESUME_SAFE_THREAD_ID_PATTERN = /^[A-Za-z0-9._:-]+$/;
|
|
436
|
-
function formatCodexResumeHint(threadId) {
|
|
437
|
-
const safe = formatCodexTextForDisplay(threadId);
|
|
438
|
-
if (!CODEX_RESUME_SAFE_THREAD_ID_PATTERN.test(safe)) return "copy the thread id above and run /codex resume <thread-id>";
|
|
439
|
-
return `/codex resume ${safe}`;
|
|
440
|
-
}
|
|
441
|
-
/** Escapes Codex-originated text so it is safe to render in chat command output. */
|
|
442
|
-
function formatCodexDisplayText(value) {
|
|
443
|
-
return escapeCodexChatText(formatCodexTextForDisplay(value));
|
|
444
|
-
}
|
|
445
|
-
function formatCodexAccountSummary(value) {
|
|
446
|
-
const safe = formatCodexTextForDisplay(summarizeAccount(value));
|
|
447
|
-
return isLikelyEmailAddress(safe) ? escapeCodexChatTextPreservingAt(safe) : escapeCodexChatText(safe);
|
|
448
|
-
}
|
|
449
|
-
function formatCodexTextForDisplay(value) {
|
|
450
|
-
return sanitizeCodexTextForDisplay(value).trim() || "<unknown>";
|
|
451
|
-
}
|
|
452
|
-
function sanitizeCodexTextForDisplay(value) {
|
|
453
|
-
let safe = "";
|
|
454
|
-
for (const character of value) {
|
|
455
|
-
const codePoint = character.codePointAt(0);
|
|
456
|
-
safe += codePoint != null && isUnsafeDisplayCodePoint(codePoint) ? "?" : character;
|
|
457
|
-
}
|
|
458
|
-
return safe;
|
|
459
|
-
}
|
|
460
|
-
function escapeCodexChatText(value) {
|
|
461
|
-
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("@", "@").replaceAll("`", "`").replaceAll("[", "[").replaceAll("]", "]").replaceAll("(", "(").replaceAll(")", ")").replaceAll("*", "∗").replaceAll("_", "_").replaceAll("~", "~").replaceAll("|", "|");
|
|
462
|
-
}
|
|
463
|
-
function escapeCodexChatTextPreservingAt(value) {
|
|
464
|
-
return escapeCodexChatText(value).replaceAll("@", "@");
|
|
465
|
-
}
|
|
466
|
-
function formatCodexAccountLine(value) {
|
|
467
|
-
if (value === "") return "";
|
|
468
|
-
const safe = sanitizeCodexTextForDisplay(value).trimEnd();
|
|
469
|
-
if (!safe.trim()) return "";
|
|
470
|
-
const emailPattern = /[^\s@<>()[\]`]+@[^\s@<>()[\]`]+\.[^\s@<>()[\]`]+/gu;
|
|
471
|
-
let formatted = "";
|
|
472
|
-
let lastIndex = 0;
|
|
473
|
-
for (const match of safe.matchAll(emailPattern)) {
|
|
474
|
-
const index = match.index ?? 0;
|
|
475
|
-
formatted += escapeCodexChatText(safe.slice(lastIndex, index));
|
|
476
|
-
formatted += escapeCodexChatTextPreservingAt(match[0]);
|
|
477
|
-
lastIndex = index + match[0].length;
|
|
478
|
-
}
|
|
479
|
-
formatted += escapeCodexChatText(safe.slice(lastIndex));
|
|
480
|
-
return formatted;
|
|
481
|
-
}
|
|
482
|
-
function isLikelyEmailAddress(value) {
|
|
483
|
-
return /^[^\s@<>()[\]`]+@[^\s@<>()[\]`]+\.[^\s@<>()[\]`]+$/.test(value);
|
|
484
|
-
}
|
|
485
|
-
function isUnsafeDisplayCodePoint(codePoint) {
|
|
486
|
-
return codePoint <= 31 || codePoint >= 127 && codePoint <= 159 || codePoint === 173 || codePoint === 1564 || codePoint === 6158 || codePoint >= 8203 && codePoint <= 8207 || codePoint >= 8234 && codePoint <= 8238 || codePoint >= 8288 && codePoint <= 8303 || codePoint === 65279 || codePoint >= 65529 && codePoint <= 65531 || codePoint >= 917504 && codePoint <= 917631;
|
|
487
|
-
}
|
|
488
|
-
/** Builds the portable `/codex` command help text. */
|
|
489
|
-
function buildHelp() {
|
|
490
|
-
return [
|
|
491
|
-
"Codex commands:",
|
|
492
|
-
"- /codex status",
|
|
493
|
-
"- /codex models",
|
|
494
|
-
"- /codex threads [filter]",
|
|
495
|
-
"- /codex sessions --host <node> [filter]",
|
|
496
|
-
"- /codex resume <thread-id>",
|
|
497
|
-
"- /codex resume <session-id> --host <node> --bind here",
|
|
498
|
-
"- /codex bind [thread-id] [--cwd <path>] [--model <model>] [--provider <provider>]",
|
|
499
|
-
"- /codex binding",
|
|
500
|
-
"- /codex stop",
|
|
501
|
-
"- /codex steer <message>",
|
|
502
|
-
"- /codex model [model]",
|
|
503
|
-
"- /codex fast [on|off|status]",
|
|
504
|
-
"- /codex permissions [default|yolo|status]",
|
|
505
|
-
"- /codex detach",
|
|
506
|
-
"- /codex compact",
|
|
507
|
-
"- /codex review",
|
|
508
|
-
"- /codex diagnostics [note]",
|
|
509
|
-
"- /codex computer-use [status|install]",
|
|
510
|
-
"- /codex account",
|
|
511
|
-
"- /codex mcp",
|
|
512
|
-
"- /codex skills",
|
|
513
|
-
"- /codex plugins [list|enable|disable]"
|
|
514
|
-
].join("\n");
|
|
515
|
-
}
|
|
516
|
-
function summarizeAccount(value) {
|
|
517
|
-
if (!isJsonObject(value)) return "unavailable";
|
|
518
|
-
const account = isJsonObject(value.account) ? value.account : value;
|
|
519
|
-
if (readString$1(account, "type") === "amazonBedrock") return "Amazon Bedrock";
|
|
520
|
-
return readString$1(account, "email") ?? readString$1(account, "accountEmail") ?? readString$1(account, "planType") ?? readString$1(account, "id") ?? "available";
|
|
521
|
-
}
|
|
522
|
-
function summarizeArrayLike(value) {
|
|
523
|
-
const entries = extractArray(value);
|
|
524
|
-
if (entries.length === 0) return "none returned";
|
|
525
|
-
return `${entries.length}`;
|
|
526
|
-
}
|
|
527
|
-
function summarizeCodexSkills(value) {
|
|
528
|
-
const groups = isJsonObject(value) && Array.isArray(value.data) ? value.data : [];
|
|
529
|
-
if (groups.length === 0) return "none returned";
|
|
530
|
-
let enabledSkills = 0;
|
|
531
|
-
let loadErrors = 0;
|
|
532
|
-
for (const group of groups) {
|
|
533
|
-
if (!isJsonObject(group)) continue;
|
|
534
|
-
if (Array.isArray(group.errors)) loadErrors += group.errors.length;
|
|
535
|
-
if (!Array.isArray(group.skills)) continue;
|
|
536
|
-
enabledSkills += group.skills.filter((skill) => !isJsonObject(skill) || skill.enabled !== false).length;
|
|
537
|
-
}
|
|
538
|
-
if (enabledSkills > 0) return `${enabledSkills}`;
|
|
539
|
-
if (loadErrors > 0) return `none returned (${loadErrors} load ${loadErrors === 1 ? "error" : "errors"})`;
|
|
540
|
-
return "none returned";
|
|
541
|
-
}
|
|
542
|
-
function formatCodexRateLimitSummary(value) {
|
|
543
|
-
const summary = summarizeCodexRateLimits(value);
|
|
544
|
-
if (summary) return formatCodexDisplayText(summary);
|
|
545
|
-
return formatCodexDisplayText(hasCodexRateLimitSnapshots(value) ? "none returned" : summarizeRateLimits(value));
|
|
546
|
-
}
|
|
547
|
-
function formatCodexRateLimitDetails(value) {
|
|
548
|
-
const lines = summarizeCodexAccountRateLimits(value);
|
|
549
|
-
if (!lines) return formatCodexDisplayText(hasCodexRateLimitSnapshots(value) ? "none returned" : summarizeRateLimits(value));
|
|
550
|
-
return lines.map(formatCodexDisplayText).join("\n");
|
|
551
|
-
}
|
|
552
|
-
function summarizeRateLimits(value) {
|
|
553
|
-
const entries = extractArray(value);
|
|
554
|
-
if (entries.length > 0) {
|
|
555
|
-
const count = entries.filter(isMeaningfulRateLimitSnapshot).length;
|
|
556
|
-
return count > 0 ? `${count}` : "none returned";
|
|
557
|
-
}
|
|
558
|
-
if (!isJsonObject(value)) return "none returned";
|
|
559
|
-
const keyed = value.rateLimitsByLimitId;
|
|
560
|
-
if (isJsonObject(keyed)) {
|
|
561
|
-
const count = Object.values(keyed).filter(isMeaningfulRateLimitSnapshot).length;
|
|
562
|
-
if (count > 0) return `${count}`;
|
|
563
|
-
}
|
|
564
|
-
return isMeaningfulRateLimitSnapshot(value.rateLimits) ? "1" : "none returned";
|
|
565
|
-
}
|
|
566
|
-
function isMeaningfulRateLimitSnapshot(value) {
|
|
567
|
-
if (!isJsonObject(value)) return false;
|
|
568
|
-
if (readString$1(value, "rateLimitReachedType") ?? readString$1(value, "rate_limit_reached_type")) return true;
|
|
569
|
-
return ["primary", "secondary"].some((key) => {
|
|
570
|
-
const window = value[key];
|
|
571
|
-
return isJsonObject(window) && Object.values(window).some((entry) => entry != null);
|
|
572
|
-
});
|
|
573
|
-
}
|
|
574
|
-
function extractArray(value) {
|
|
575
|
-
if (Array.isArray(value)) return value;
|
|
576
|
-
if (!isJsonObject(value)) return [];
|
|
577
|
-
for (const key of [
|
|
578
|
-
"data",
|
|
579
|
-
"items",
|
|
580
|
-
"threads",
|
|
581
|
-
"models",
|
|
582
|
-
"skills",
|
|
583
|
-
"servers",
|
|
584
|
-
"rateLimits"
|
|
585
|
-
]) {
|
|
586
|
-
const child = value[key];
|
|
587
|
-
if (Array.isArray(child)) return child;
|
|
588
|
-
}
|
|
589
|
-
return [];
|
|
590
|
-
}
|
|
591
|
-
/** Reads and trims a non-empty string field from a JSON object. */
|
|
592
|
-
function readString$1(record, key) {
|
|
593
|
-
const value = record[key];
|
|
594
|
-
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
595
|
-
}
|
|
596
|
-
//#endregion
|
|
597
|
-
//#region extensions/codex/src/app-server/notification-correlation.ts
|
|
598
|
-
/**
|
|
599
|
-
* Correlates Codex app-server notifications with the active thread/turn so
|
|
600
|
-
* projectors can ignore global or stale events without losing diagnostics.
|
|
601
|
-
*/
|
|
602
|
-
/** Returns true when a notification payload belongs to the exact active thread and turn. */
|
|
603
|
-
function isCodexNotificationForTurn(value, threadId, turnId) {
|
|
604
|
-
if (!isJsonObject(value)) return false;
|
|
605
|
-
return readCodexNotificationThreadId(value) === threadId && readCodexNotificationTurnId(value) === turnId;
|
|
606
|
-
}
|
|
607
|
-
/** Reads a thread id from either top-level notification params or nested turn payloads. */
|
|
608
|
-
function readCodexNotificationThreadId(record) {
|
|
609
|
-
return readNestedTurnThreadId(record) ?? readString(record, "threadId");
|
|
610
|
-
}
|
|
611
|
-
/** Reads a turn id from either top-level notification params or nested turn payloads. */
|
|
612
|
-
function readCodexNotificationTurnId(record) {
|
|
613
|
-
return readNestedTurnId(record) ?? readString(record, "turnId");
|
|
614
|
-
}
|
|
615
|
-
/** Builds structured correlation details for logs when notification routing is ambiguous. */
|
|
616
|
-
function describeCodexNotificationCorrelation(notification, active) {
|
|
617
|
-
const params = isJsonObject(notification.params) ? notification.params : void 0;
|
|
618
|
-
const turn = params && isJsonObject(params.turn) ? params.turn : void 0;
|
|
619
|
-
const threadId = params ? readString(params, "threadId") : void 0;
|
|
620
|
-
const turnId = params ? readString(params, "turnId") : void 0;
|
|
621
|
-
const nestedTurnThreadId = turn ? readString(turn, "threadId") : void 0;
|
|
622
|
-
const nestedTurnId = turn ? readString(turn, "id") : void 0;
|
|
623
|
-
const resolvedThreadId = params ? readCodexNotificationThreadId(params) : void 0;
|
|
624
|
-
const resolvedTurnId = params ? readCodexNotificationTurnId(params) : void 0;
|
|
625
|
-
const matchesActiveThread = resolvedThreadId === active.threadId;
|
|
626
|
-
const matchesActiveTurn = active.turnId ? matchesActiveThread && resolvedTurnId === active.turnId : void 0;
|
|
627
|
-
const items = turn?.items;
|
|
628
|
-
return {
|
|
629
|
-
method: notification.method,
|
|
630
|
-
...params ? { paramsKeys: Object.keys(params).toSorted() } : {},
|
|
631
|
-
activeThreadId: active.threadId,
|
|
632
|
-
...active.turnId ? { activeTurnId: active.turnId } : {},
|
|
633
|
-
...threadId ? { threadId } : {},
|
|
634
|
-
...turnId ? { turnId } : {},
|
|
635
|
-
...nestedTurnThreadId ? { nestedTurnThreadId } : {},
|
|
636
|
-
...nestedTurnId ? { nestedTurnId } : {},
|
|
637
|
-
...turn ? { turnStatus: readString(turn, "status") } : {},
|
|
638
|
-
...Array.isArray(items) ? { turnItemCount: items.length } : {},
|
|
639
|
-
matchesActiveThread,
|
|
640
|
-
...matchesActiveTurn === void 0 ? {} : { matchesActiveTurn }
|
|
641
|
-
};
|
|
642
|
-
}
|
|
643
|
-
function readNestedTurnId(record) {
|
|
644
|
-
const turn = record.turn;
|
|
645
|
-
return isJsonObject(turn) ? readString(turn, "id") : void 0;
|
|
646
|
-
}
|
|
647
|
-
function readNestedTurnThreadId(record) {
|
|
648
|
-
const turn = record.turn;
|
|
649
|
-
return isJsonObject(turn) ? readString(turn, "threadId") : void 0;
|
|
650
|
-
}
|
|
651
|
-
function readString(record, key) {
|
|
652
|
-
const value = record[key];
|
|
653
|
-
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
654
|
-
}
|
|
655
|
-
//#endregion
|
|
656
|
-
export { shouldRefreshCodexRateLimitsForUsageLimitMessage as _, buildHelp as a, formatCodexStatus as c, formatModels as d, formatSkills as f, resolveCodexUsageLimitResetAtMs as g, formatCodexUsageLimitErrorMessage as h, readCodexNotificationTurnId as i, formatComputerUseStatus as l, readString$1 as m, isCodexNotificationForTurn as n, formatAccount as o, formatThreads as p, readCodexNotificationThreadId as r, formatCodexDisplayText as s, describeCodexNotificationCorrelation as t, formatList as u, summarizeCodexAccountUsage as v };
|