@adecore/agents 0.45.0 → 0.45.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.
@@ -764,7 +764,7 @@ export class ClaudeProtocol {
764
764
  const errors = Array.isArray(frame.errors) ? frame.errors.filter((error) => typeof error === 'string') : [];
765
765
  const lastUuid = this.lastUuid;
766
766
  this.lastUuid = null;
767
- const limit = failed ? this.limit() : null;
767
+ const limit = failed ? this.limit([str(frame.result), ...errors].join('\n')) : null;
768
768
  const replaceProcess = failed && this.apiError === 'authentication_failed';
769
769
  if (limit?.kind !== 'usage') {
770
770
  this.refusedResets.clear();
@@ -819,10 +819,10 @@ export class ClaudeProtocol {
819
819
  }
820
820
  /*
821
821
  * What stopped a failed turn, in the words of Claude Code 2.1.281: a window of the plan that refused
822
- * the request is a usage limit, and an API error of `rate_limit` without one (a 429 the plan did
823
- * not explain) or of `overloaded` is a model too busy to answer.
822
+ * the request or an explicit spent-plan message is a usage limit. A bare `rate_limit` (a 429
823
+ * the plan did not explain) or `overloaded` is a model too busy to answer.
824
824
  */
825
- limit() {
825
+ limit(message) {
826
826
  if (this.refusedWindows.size > 0) {
827
827
  let resetsAt = 0;
828
828
  for (const reset of this.refusedWindows.values()) {
@@ -833,6 +833,10 @@ export class ClaudeProtocol {
833
833
  }
834
834
  return { kind: 'usage', resetsAt };
835
835
  }
836
+ // The first refusal can name the spent plan before a rate_limit_event supplies its window.
837
+ if (this.apiError === 'rate_limit' && /you(?:'|’)ve hit your (?:5[- ]hour|weekly|session|usage) limit\b/i.test(message)) {
838
+ return { kind: 'usage' };
839
+ }
836
840
  if (this.apiError === 'rate_limit' || this.apiError === 'overloaded') {
837
841
  return { kind: 'overload' };
838
842
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adecore/agents",
3
- "version": "0.45.0",
3
+ "version": "0.45.1",
4
4
  "description": "Node-compatible agent chat hosts, providers, accounts, usage and durable task coordination.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -93,8 +93,8 @@
93
93
  "test": "bun --conditions=source test"
94
94
  },
95
95
  "dependencies": {
96
- "@adecore/agent-contracts": "0.45.0",
97
- "@adecore/intelligent-ui": "0.45.0",
96
+ "@adecore/agent-contracts": "0.45.1",
97
+ "@adecore/intelligent-ui": "0.45.1",
98
98
  "zod": "^4.6.7"
99
99
  },
100
100
  "devDependencies": {
@@ -949,7 +949,7 @@ export class ClaudeProtocol {
949
949
  const errors = Array.isArray(frame.errors) ? frame.errors.filter((error): error is string => typeof error === 'string') : [];
950
950
  const lastUuid = this.lastUuid;
951
951
  this.lastUuid = null;
952
- const limit = failed ? this.limit() : null;
952
+ const limit = failed ? this.limit([str(frame.result), ...errors].join('\n')) : null;
953
953
  const replaceProcess = failed && this.apiError === 'authentication_failed';
954
954
 
955
955
  if (limit?.kind !== 'usage') {
@@ -1014,10 +1014,10 @@ export class ClaudeProtocol {
1014
1014
 
1015
1015
  /*
1016
1016
  * What stopped a failed turn, in the words of Claude Code 2.1.281: a window of the plan that refused
1017
- * the request is a usage limit, and an API error of `rate_limit` without one (a 429 the plan did
1018
- * not explain) or of `overloaded` is a model too busy to answer.
1017
+ * the request or an explicit spent-plan message is a usage limit. A bare `rate_limit` (a 429
1018
+ * the plan did not explain) or `overloaded` is a model too busy to answer.
1019
1019
  */
1020
- private limit(): ChatTurnLimit | null {
1020
+ private limit(message: string): ChatTurnLimit | null {
1021
1021
  if (this.refusedWindows.size > 0) {
1022
1022
  let resetsAt = 0;
1023
1023
 
@@ -1032,6 +1032,11 @@ export class ClaudeProtocol {
1032
1032
  return { kind: 'usage', resetsAt };
1033
1033
  }
1034
1034
 
1035
+ // The first refusal can name the spent plan before a rate_limit_event supplies its window.
1036
+ if (this.apiError === 'rate_limit' && /you(?:'|’)ve hit your (?:5[- ]hour|weekly|session|usage) limit\b/i.test(message)) {
1037
+ return { kind: 'usage' };
1038
+ }
1039
+
1035
1040
  if (this.apiError === 'rate_limit' || this.apiError === 'overloaded') {
1036
1041
  return { kind: 'overload' };
1037
1042
  }