replicas-engine 0.1.1248 → 0.1.1249

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.
@@ -8,9 +8,9 @@ import {
8
8
  listRunningCodexModels,
9
9
  restartCodexAspHost,
10
10
  restartCodexAspHostIfRunning
11
- } from "./chunk-3V6VDRU5.js";
11
+ } from "./chunk-GH5EEUT2.js";
12
12
  import "./chunk-6PVW5AKP.js";
13
- import "./chunk-P3G4OERE.js";
13
+ import "./chunk-5GHRPLRX.js";
14
14
  import "./chunk-3C2WTKME.js";
15
15
  import "./chunk-UZSNFLDQ.js";
16
16
  import "./chunk-7QJWP5ZL.js";
@@ -3,7 +3,7 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  AspClient
6
- } from "./chunk-P3G4OERE.js";
6
+ } from "./chunk-5GHRPLRX.js";
7
7
  import {
8
8
  ASTER_BASE_URL,
9
9
  ASTER_PROVIDER,
@@ -240,7 +240,7 @@ function getCodexModelProvider(method) {
240
240
  if (method === "foundry") return "azure";
241
241
  return method === "ollama" || method === "openai-compatible" ? "replicas_openai_compatible" : "openai";
242
242
  }
243
- var ENGINE_PACKAGE_VERSION = "0.1.1248";
243
+ var ENGINE_PACKAGE_VERSION = "0.1.1249";
244
244
  var INITIALIZE_METHOD = "initialize";
245
245
  var INITIALIZED_NOTIFICATION = "initialized";
246
246
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -14,7 +14,7 @@ import {
14
14
  import {
15
15
  AppServerProcess,
16
16
  buildCodexAgentEnv
17
- } from "./chunk-P3G4OERE.js";
17
+ } from "./chunk-5GHRPLRX.js";
18
18
  import {
19
19
  SUBPROCESS_MAX_BUFFER,
20
20
  execFileAsync
@@ -291,7 +291,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
291
291
  await this.applyCredentialUpdate(++this.credentialGeneration, async () => {
292
292
  await this.applyCredentialsResponse(data);
293
293
  setAgentCredentialSnapshot("codex", data);
294
- const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-DFIT2PB7.js");
294
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-UBXPKAXA.js");
295
295
  await restartCodexAspHostIfRunning2();
296
296
  });
297
297
  await this.start(true);
@@ -313,7 +313,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
313
313
  const accountChanged = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.codex?.credentialId !== data.credentialId;
314
314
  await this.applyCredentialsResponse(data);
315
315
  if (restartOnChange && (accountChanged || CODEX_AUTH_ENV_KEYS.some((key, index) => process.env[key] !== previousEnv[index]))) {
316
- const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-DFIT2PB7.js");
316
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-UBXPKAXA.js");
317
317
  await restartCodexAspHostIfRunning2();
318
318
  }
319
319
  setAgentCredentialSnapshot("codex", data);
@@ -13,11 +13,11 @@ import {
13
13
  recoverCompletedTurn,
14
14
  spawnMuseMsp,
15
15
  startMuseSession
16
- } from "./chunk-EVNSRGKX.js";
16
+ } from "./chunk-5ANTWWVQ.js";
17
17
  import {
18
18
  AppServerProcess,
19
19
  buildCodexAgentEnv
20
- } from "./chunk-P3G4OERE.js";
20
+ } from "./chunk-5GHRPLRX.js";
21
21
  import "./chunk-3C2WTKME.js";
22
22
  import {
23
23
  AGENT,
package/dist/src/index.js CHANGED
@@ -64,7 +64,7 @@ import {
64
64
  spawnMuseMsp,
65
65
  startMuseSession,
66
66
  uuidV7
67
- } from "./chunk-EVNSRGKX.js";
67
+ } from "./chunk-5ANTWWVQ.js";
68
68
  import {
69
69
  publishedPullRequestUrls
70
70
  } from "./chunk-FQZ6YTN2.js";
@@ -140,7 +140,7 @@ import {
140
140
  timestampFromSeconds,
141
141
  upsertCredentialFileLines,
142
142
  writeSecureCredentialFile
143
- } from "./chunk-3V6VDRU5.js";
143
+ } from "./chunk-GH5EEUT2.js";
144
144
  import {
145
145
  ENGINE_ENV,
146
146
  monolithRequest,
@@ -152,7 +152,7 @@ import {
152
152
  } from "./chunk-6PVW5AKP.js";
153
153
  import {
154
154
  getCodexModelProvider
155
- } from "./chunk-P3G4OERE.js";
155
+ } from "./chunk-5GHRPLRX.js";
156
156
  import {
157
157
  SUBPROCESS_MAX_BUFFER,
158
158
  execAsync,
@@ -8844,7 +8844,7 @@ var ClaudeTokenManager = class extends BaseRefreshManager {
8844
8844
  await this.applyCredentialUpdate(generation, () => this.applyCredentialsResponse(data));
8845
8845
  console.log(`[ClaudeTokenManager] Credentials refreshed (method=${data.type})`);
8846
8846
  }
8847
- async fetchFreshCredentials(failureReason, failureKind = "rejected", failedCredential = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.claude, allowedMethods) {
8847
+ async fetchFreshCredentials(failureReason, failureKind = "rejected", failedCredential = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.claude, allowedMethods, resetsAt) {
8848
8848
  const configuredMethod = ENGINE_ENV.REPLICAS_CLAUDE_AUTH_METHOD;
8849
8849
  const failedMethod = failedCredential?.method === "ollama" || failedCredential?.method === "oauth" || failedCredential?.method === "api_key" || failedCredential?.method === "bedrock" || failedCredential?.method === "foundry" ? failedCredential.method : configuredMethod === "ollama" || configuredMethod === "oauth" || configuredMethod === "api_key" || configuredMethod === "bedrock" || configuredMethod === "foundry" ? configuredMethod : void 0;
8850
8850
  return this.swapCredentials({
@@ -8856,6 +8856,7 @@ var ClaudeTokenManager = class extends BaseRefreshManager {
8856
8856
  ...failedCredential?.method === failedMethod ? { failedCredential } : {},
8857
8857
  failureReason,
8858
8858
  failureKind,
8859
+ ...resetsAt ? { resetsAt } : {},
8859
8860
  ...exclusions
8860
8861
  } : exclusions),
8861
8862
  isOauthNow: () => ENGINE_ENV.REPLICAS_CLAUDE_AUTH_METHOD === "oauth"
@@ -11177,12 +11178,12 @@ var AuthFallbackCoordinator = class {
11177
11178
  record;
11178
11179
  context;
11179
11180
  /** `attempted` is the credential the failed turn ran on, which another chat may already have replaced. */
11180
- fallBack(reason, detail, attempted) {
11181
+ fallBack(reason, detail, attempted, resetsAt) {
11181
11182
  let lock = fallbackLocks.get(this.provider);
11182
11183
  if (!lock) fallbackLocks.set(this.provider, lock = new AsyncLock());
11183
- return lock.run(() => this.fallBackNow(reason, detail, attempted));
11184
+ return lock.run(() => this.fallBackNow(reason, detail, attempted, resetsAt));
11184
11185
  }
11185
- async fallBackNow(reason, detail, attempted) {
11186
+ async fallBackNow(reason, detail, attempted, resetsAt) {
11186
11187
  const tokenManager = SWAPPABLE_AGENTS[this.provider];
11187
11188
  const live = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS[this.provider];
11188
11189
  const exhausted = attempted ?? live;
@@ -11219,7 +11220,8 @@ var AuthFallbackCoordinator = class {
11219
11220
  // Skipped via the exclusion above, not rested, so Settings doesn't show a usage limit.
11220
11221
  reason === "auth_failed" || reason === "credits_required" ? "rejected" : "exhausted",
11221
11222
  exhausted,
11222
- step.methods.length > 0 ? step.methods : void 0
11223
+ step.methods.length > 0 ? step.methods : void 0,
11224
+ resetsAt
11223
11225
  );
11224
11226
  if (!swap.ok) {
11225
11227
  failed ||= swap.error.code !== "no_credentials";
@@ -11574,9 +11576,9 @@ var CodingAgentManager = class {
11574
11576
  this.getHistorySink()?.append(event);
11575
11577
  }, options.fallbackContext ?? (() => ({ excludeProviders: [], forkable: false }))) : null;
11576
11578
  }
11577
- async fallBackCredential(reason, detail, attempted) {
11579
+ async fallBackCredential(reason, detail, attempted, resetsAt) {
11578
11580
  if (!this.authFallback) return { outcome: "unavailable" };
11579
- const result = await this.authFallback.fallBack(reason, detail, attempted);
11581
+ const result = await this.authFallback.fallBack(reason, detail, attempted, resetsAt);
11580
11582
  if (result.outcome === "switched" && result.model) await this.onModelSwitched(result.model);
11581
11583
  return result;
11582
11584
  }
@@ -12806,12 +12808,14 @@ var ClaudeMissingSessionError = class extends Error {
12806
12808
  }
12807
12809
  };
12808
12810
  var ClaudeQuotaError = class extends Error {
12809
- constructor(message, kind) {
12811
+ constructor(message, kind, resetsAt) {
12810
12812
  super(message);
12811
12813
  this.kind = kind;
12814
+ this.resetsAt = resetsAt;
12812
12815
  this.name = "ClaudeQuotaError";
12813
12816
  }
12814
12817
  kind;
12818
+ resetsAt;
12815
12819
  };
12816
12820
  var MAX_AUTH_RETRIES = 2;
12817
12821
  var MAX_TRANSIENT_RETRIES = 2;
@@ -13260,7 +13264,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13260
13264
  const detail = error instanceof ClaudeQuotaError ? error.message : extractErrorText(error);
13261
13265
  const repeated = !!attemptedCredential && failedCredentials.some((failed) => isSameCredential(failed, attemptedCredential));
13262
13266
  if (attemptedCredential) failedCredentials.push(attemptedCredential);
13263
- const fallback = repeated ? { outcome: "unavailable" } : await this.fallBackCredential(reason, detail, attemptedCredential);
13267
+ const fallback = repeated ? { outcome: "unavailable" } : await this.fallBackCredential(reason, detail, attemptedCredential, error instanceof ClaudeQuotaError ? error.resetsAt : void 0);
13264
13268
  if (fallback.outcome === "switched") {
13265
13269
  if (fallback.model) currentRequest = { ...currentRequest, model: fallback.model };
13266
13270
  authRetries = 0;
@@ -13673,6 +13677,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13673
13677
  let loopError = null;
13674
13678
  let suppressLinearResponseFlush = false;
13675
13679
  let creditsRequired = false;
13680
+ let resetsAt;
13676
13681
  let turnFailed = false;
13677
13682
  try {
13678
13683
  while (true) {
@@ -13680,10 +13685,15 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13680
13685
  if (next.done || this.activeQuery !== response) break;
13681
13686
  const msg = next.value;
13682
13687
  if (!msg) break;
13683
- if (msg.type === "rate_limit_event") creditsRequired = msg.rate_limit_info.errorCode === "credits_required";
13688
+ if (msg.type === "rate_limit_event") {
13689
+ creditsRequired = msg.rate_limit_info.errorCode === "credits_required";
13690
+ if (msg.rate_limit_info.status === "rejected" && msg.rate_limit_info.resetsAt) {
13691
+ resetsAt = new Date(msg.rate_limit_info.resetsAt * 1e3).toISOString();
13692
+ }
13693
+ }
13684
13694
  const authErrorMessage = _ClaudeManager.detectAuthErrorInMessage(msg);
13685
13695
  const transientErrorMessage = _ClaudeManager.detectTransientTurnErrorInMessage(msg);
13686
- const turnError = authErrorMessage ? new ClaudeAuthError(authErrorMessage) : msg.type === "result" && msg.subtype !== "success" && msg.num_turns === 0 && msg.errors.some((err) => err.startsWith("No conversation found with session ID")) ? new ClaudeMissingSessionError(msg.errors.join("\n")) : _ClaudeManager.detectQuotaErrorInMessage(msg, creditsRequired) ?? (transientErrorMessage ? new ClaudeTransientTurnError(transientErrorMessage, this.pendingTurn?.sawActivity ?? false) : null);
13696
+ const turnError = authErrorMessage ? new ClaudeAuthError(authErrorMessage) : msg.type === "result" && msg.subtype !== "success" && msg.num_turns === 0 && msg.errors.some((err) => err.startsWith("No conversation found with session ID")) ? new ClaudeMissingSessionError(msg.errors.join("\n")) : _ClaudeManager.detectQuotaErrorInMessage(msg, creditsRequired, resetsAt) ?? (transientErrorMessage ? new ClaudeTransientTurnError(transientErrorMessage, this.pendingTurn?.sawActivity ?? false) : null);
13687
13697
  if (turnError) {
13688
13698
  suppressLinearResponseFlush = true;
13689
13699
  turnFailed = true;
@@ -13977,17 +13987,18 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13977
13987
  if (error instanceof ClaudeQuotaError) return error.kind;
13978
13988
  return detectAgentQuotaLimit(extractErrorText(error));
13979
13989
  }
13980
- static detectQuotaErrorInMessage(message, creditsRequired) {
13990
+ static detectQuotaErrorInMessage(message, creditsRequired, resetsAt) {
13991
+ const quotaError = (text2, kind2) => new ClaudeQuotaError(text2, creditsRequired ? "credits_required" : kind2, resetsAt);
13981
13992
  if (message.type === "assistant" && "error" in message) {
13982
13993
  const content = Array.isArray(message.message?.content) ? message.message.content.map((block) => "text" in block ? block.text : "").join("\n") : "";
13983
13994
  const text2 = [typeof message.error === "string" ? message.error : "", content].filter(Boolean).join("\n");
13984
13995
  const kind2 = detectAgentQuotaLimit(text2);
13985
- if (kind2) return new ClaudeQuotaError(text2, creditsRequired ? "credits_required" : kind2);
13996
+ if (kind2) return quotaError(text2, kind2);
13986
13997
  }
13987
13998
  if (message.type !== "result" || !message.is_error) return null;
13988
13999
  const text = message.subtype === "success" ? message.result : message.errors.join("\n");
13989
14000
  const kind = detectAgentQuotaLimit(text);
13990
- return kind ? new ClaudeQuotaError(text, creditsRequired ? "credits_required" : kind) : null;
14001
+ return kind ? quotaError(text, kind) : null;
13991
14002
  }
13992
14003
  static isTransientTurnError(error) {
13993
14004
  if (error instanceof ClaudeTransientTurnError) return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.1248",
3
+ "version": "0.1.1249",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",