@coda-console/codex 1.12.0 → 1.13.0
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/agent/errors.mjs +27 -3
- package/package.json +1 -1
package/agent/errors.mjs
CHANGED
|
@@ -4,12 +4,31 @@ export function explainCodexError(message) {
|
|
|
4
4
|
if (!message || typeof message !== 'object' || !('id' in message) || 'method' in message) return message;
|
|
5
5
|
const error = message.error;
|
|
6
6
|
if (!error || typeof error.message !== 'string') return message;
|
|
7
|
-
const
|
|
7
|
+
const resetAt = error.data?._meta?.coda?.failure?.resetAt;
|
|
8
|
+
const readable = text => resetAt ? text.replace(resetText, (_, prefix, time) => `${prefix}<t:${time}>`) : text;
|
|
9
|
+
const parts = [readable(error.message)];
|
|
8
10
|
for (const value of [error.data?.message, error.data?.details, error.data]) {
|
|
9
|
-
const detail = typeof value === 'string' ? value.trim() : '';
|
|
11
|
+
const detail = typeof value === 'string' ? readable(value.trim()) : '';
|
|
10
12
|
if (detail && !parts.some(part => part.includes(detail))) parts.push(detail);
|
|
11
13
|
}
|
|
12
|
-
|
|
14
|
+
const explained = parts.join('\n\n');
|
|
15
|
+
return explained === error.message ? message : { ...message, error: { ...error, message: explained } };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Only absolute reset times from the failed request are evidence. The account-wide rateLimits/read can contain several
|
|
19
|
+
// model pools, without identifying which one blocked this turn; do not schedule a retry from an unrelated window.
|
|
20
|
+
const resetText = /\b(try again at |resets (?:at )?)(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?Z)\b/gi;
|
|
21
|
+
function quotaReset(error, data) {
|
|
22
|
+
for (const text of [data.additionalDetails, data.message, error.message]) {
|
|
23
|
+
if (typeof text !== 'string') continue;
|
|
24
|
+
let body; try { body = JSON.parse(text); } catch {}
|
|
25
|
+
const seconds = body?.error?.resets_at;
|
|
26
|
+
if (Number.isSafeInteger(seconds) && seconds > 0 && seconds <= 253402300799)
|
|
27
|
+
return new Date(seconds * 1000).toISOString();
|
|
28
|
+
const time = [...text.matchAll(resetText)][0]?.[2];
|
|
29
|
+
if (time && Number.isFinite(Date.parse(time)) && new Date(time).toISOString().slice(0, 19) === time.slice(0, 19))
|
|
30
|
+
return new Date(time).toISOString();
|
|
31
|
+
}
|
|
13
32
|
}
|
|
14
33
|
|
|
15
34
|
// Native service facts, not a retry policy: Coda decides when/how often to try again. Explicit permanent kinds win over
|
|
@@ -17,6 +36,11 @@ export function explainCodexError(message) {
|
|
|
17
36
|
export function codexFailureData(error, input) {
|
|
18
37
|
const data = error.data && typeof error.data === 'object' && !Array.isArray(error.data) ? error.data : {};
|
|
19
38
|
const info = data.codexErrorInfo;
|
|
39
|
+
if (info === 'usageLimitExceeded') {
|
|
40
|
+
const resetAt = quotaReset(error, data);
|
|
41
|
+
return { ...data, _meta: { ...data._meta, coda: { ...data._meta?.coda,
|
|
42
|
+
failure: { kind: 'quota_exhausted', ...(resetAt ? { resetAt } : {}) } } } };
|
|
43
|
+
}
|
|
20
44
|
const message = typeof data.message === 'string' ? data.message : typeof data.details === 'string' ? data.details : typeof error.data === 'string' ? error.data : error.message;
|
|
21
45
|
let provider; try { provider = JSON.parse(message); } catch {}
|
|
22
46
|
const status = provider?.status ?? (info && typeof info === 'object' ? Object.values(info)[0]?.httpStatusCode : null);
|