@coda-console/claude 1.11.0 → 1.12.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 +5 -4
- package/package.json +1 -1
package/agent/errors.mjs
CHANGED
|
@@ -10,12 +10,13 @@ const exhausted = message => /^(?:You've (?:hit|reached) your (?:session|weekly|
|
|
|
10
10
|
// which the CLI sends only as a window moves), the reason says it as a time mark instead, which each client writes in
|
|
11
11
|
// its own time zone (Coda's docs/agent-protocol.md「文字里的时刻」).
|
|
12
12
|
const windowReset = /^(You've (?:hit|reached) your [^·]+ · resets )[^·()]+ \([^()]+\)/;
|
|
13
|
-
const
|
|
14
|
-
|
|
13
|
+
const resetTime = window => window?.status === 'rejected' && Number.isSafeInteger(window.resetsAt) && window.resetsAt > 0 &&
|
|
14
|
+
window.resetsAt <= 253402300799 ? new Date(window.resetsAt * 1000).toISOString() : undefined;
|
|
15
15
|
|
|
16
16
|
export function claudeFailure(message, { error, limits, window } = {}) {
|
|
17
17
|
const quota = (!error || ['rate_limit', 'billing_error'].includes(error)) &&
|
|
18
18
|
(exhausted(message) || (error === 'rate_limit' && limits?.status === 'rejected'));
|
|
19
|
-
const
|
|
20
|
-
|
|
19
|
+
const resetAt = quota ? resetTime(window) : undefined;
|
|
20
|
+
const data = quota ? { _meta: { coda: { failure: { kind: 'quota_exhausted', ...(resetAt ? { resetAt } : {}) } } } } : undefined;
|
|
21
|
+
return new RequestError(-32603, resetAt ? message.replace(windowReset, (_, said) => `${said}<t:${resetAt}>`) : message, data);
|
|
21
22
|
}
|