@coda-console/claude 1.6.3 → 1.6.4

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 CHANGED
@@ -1,11 +1,21 @@
1
1
  import { RequestError } from '@agentclientprotocol/sdk';
2
2
 
3
3
  // Only failed turns come here. Claude Code's synthetic assistant error and the subscription's rejected window are
4
- // evidence, ordinary assistant text and a bare HTTP 429 are not. Keep the provider's reset time/recovery advice intact.
4
+ // evidence, ordinary assistant text and a bare HTTP 429 are not. Keep the provider's recovery advice intact (its reset time
5
+ // said as a time mark: `marked`).
5
6
  const exhausted = message => /^(?:You've (?:hit|reached) your (?:session|weekly|5-hour|7-day|usage) limit\b|(?:Your )?[Cc]redit balance is too low\b|You're out of (?:usage credits|extra usage)\b|Your org is out of usage\b)/.test(message);
6
7
 
7
- export function claudeFailure(message, { error, limits } = {}) {
8
+ // Claude Code says when the window that limits now resets in the time zone of the machine it runs on ("resets 5:10am
9
+ // (Australia/Sydney)"), not of whoever reads it. With that window's reset known (`window`: the latest rate_limit_info,
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
+ // its own time zone (Coda's docs/agent-protocol.md「文字里的时刻」).
12
+ const windowReset = /^(You've (?:hit|reached) your [^·]+ · resets )[^·()]+ \([^()]+\)/;
13
+ const marked = (message, window) => window?.status === 'rejected' && Number.isSafeInteger(window.resetsAt) && window.resetsAt > 0
14
+ ? message.replace(windowReset, (_, said) => `${said}<t:${new Date(window.resetsAt * 1000).toISOString()}>`) : message;
15
+
16
+ export function claudeFailure(message, { error, limits, window } = {}) {
8
17
  const quota = (!error || ['rate_limit', 'billing_error'].includes(error)) &&
9
18
  (exhausted(message) || (error === 'rate_limit' && limits?.status === 'rejected'));
10
- return new RequestError(-32603, message, quota ? { _meta: { coda: { failure: { kind: 'quota_exhausted' } } } } : undefined);
19
+ const data = quota ? { _meta: { coda: { failure: { kind: 'quota_exhausted' } } } } : undefined;
20
+ return new RequestError(-32603, quota ? marked(message, window) : message, data);
11
21
  }
package/agent/session.mjs CHANGED
@@ -365,7 +365,7 @@ export class ClaudeSession {
365
365
  case 'user': return this.toolResults(m, parent);
366
366
  case 'result': return this.result(m);
367
367
  case 'rate_limit_event':
368
- this.turnLimits = m.rate_limit_info;
368
+ this.turnLimits = this.window = m.rate_limit_info;
369
369
  if (this.env.CODA_PLUGIN_STATE) new ClaudeSessionLimits({ path: join(this.env.CODA_PLUGIN_STATE, 'limits.json') }).observe(m.rate_limit_info, this.account ?? null);
370
370
  }
371
371
  }
@@ -516,7 +516,7 @@ export class ClaudeSession {
516
516
  const id = ids.find(id => this.prompts.has(id)) ?? (steered ? this.held : undefined);
517
517
  const cancelled = interrupted(m), failed = !cancelled && (m.is_error || m.subtype !== 'success');
518
518
  const error = failed ? claudeFailure(m.errors?.length || m.result ? errorText(m) : this.turnError?.message || errorText(m),
519
- { error: this.turnError?.error, limits: this.turnLimits }) : null;
519
+ { error: this.turnError?.error, limits: this.turnLimits, window: this.window }) : null;
520
520
  this.turnError = null; this.turnLimits = null;
521
521
  if (id) {
522
522
  const outcome = this.ending ?? (failed ? { failure: error } : { stopReason: cancelled ? 'cancelled' : 'end_turn' });
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "id": "claude",
4
4
  "displayName": "Claude",
5
5
  "description": "Claude SDK Agent:Coda 基于 Claude Agent SDK 写的 ACP 入口,一个进程一个 SDK 会话;资源页的「Claude」面板显示会话报告的额度,可从 Coda 登录。",
6
- "version": "1.6.3",
6
+ "version": "1.6.4",
7
7
  "categories": ["Agent"],
8
8
  "dependencies": {
9
9
  "@agentclientprotocol/sdk": "1.4.0",