replicas-engine 0.1.1181 → 0.1.1183

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-GJ42APJ6.js";
12
- import "./chunk-7AXWBC3X.js";
13
- import "./chunk-YB2HONQF.js";
11
+ } from "./chunk-6TR2W5B3.js";
12
+ import "./chunk-OKE4RCRY.js";
13
+ import "./chunk-RB33U66A.js";
14
14
  import "./chunk-2AG3DWDX.js";
15
15
  import "./chunk-UZSNFLDQ.js";
16
16
  import "./chunk-AGNQDFJU.js";
@@ -10,11 +10,11 @@ import {
10
10
  resolveDiffBase,
11
11
  runGitCommand,
12
12
  setAgentCredentialSnapshot
13
- } from "./chunk-7AXWBC3X.js";
13
+ } from "./chunk-OKE4RCRY.js";
14
14
  import {
15
15
  AppServerProcess,
16
16
  buildCodexAgentEnv
17
- } from "./chunk-YB2HONQF.js";
17
+ } from "./chunk-RB33U66A.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-6TFTFKWQ.js");
294
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-Y5PB7ROJ.js");
295
295
  await restartCodexAspHostIfRunning2();
296
296
  });
297
297
  await this.start(true);
@@ -301,7 +301,8 @@ var CodexTokenManager = class extends BaseRefreshManager {
301
301
  const previousEnv = CODEX_AUTH_ENV_KEYS.map((key) => process.env[key]);
302
302
  console.log("[CodexTokenManager] Refreshing Codex credentials...");
303
303
  const response = await monolithRequest("/v1/engine/codex/refresh-credentials", {
304
- body: { supportsOpenAICompatibleAuth: true, ...request }
304
+ body: { supportsOpenAICompatibleAuth: true, ...request },
305
+ signal: AbortSignal.timeout(12e4)
305
306
  });
306
307
  if (!response.ok) {
307
308
  const errorText = await response.text();
@@ -312,7 +313,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
312
313
  const accountChanged = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.codex?.credentialId !== data.credentialId;
313
314
  await this.applyCredentialsResponse(data);
314
315
  if (restartOnChange && (accountChanged || CODEX_AUTH_ENV_KEYS.some((key, index) => process.env[key] !== previousEnv[index]))) {
315
- const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-6TFTFKWQ.js");
316
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-Y5PB7ROJ.js");
316
317
  await restartCodexAspHostIfRunning2();
317
318
  }
318
319
  setAgentCredentialSnapshot("codex", data);
@@ -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-YB2HONQF.js";
6
+ } from "./chunk-RB33U66A.js";
7
7
  import {
8
8
  ASTER_BASE_URL,
9
9
  ASTER_PROVIDER,
@@ -304,7 +304,7 @@ var MonolithService = class {
304
304
  if (params.exhaustedMethod) query.set("exhaustedMethod", params.exhaustedMethod);
305
305
  if (params.userId) query.set("userId", params.userId);
306
306
  try {
307
- const response = await monolithRequest(`/v1/engine/fallback-plan?${query}`, { method: "GET" });
307
+ const response = await monolithRequest(`/v1/engine/fallback-plan?${query}`, { method: "GET", signal: AbortSignal.timeout(3e4) });
308
308
  if (response.status === 404) return createErrorResult({ message: "Monolith has no fallback-plan route", code: "unsupported" });
309
309
  if (!response.ok) return createErrorResult({ message: `Fallback plan request failed: ${response.status}`, code: "unavailable" });
310
310
  const parsed = fallbackPlanResponseSchema.safeParse(await response.json());
@@ -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.1181";
243
+ var ENGINE_PACKAGE_VERSION = "0.1.1183";
244
244
  var INITIALIZE_METHOD = "initialize";
245
245
  var INITIALIZED_NOTIFICATION = "initialized";
246
246
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -5,7 +5,7 @@ import {
5
5
  getOriginDefaultBranch,
6
6
  monolithRequest,
7
7
  runGitCommand
8
- } from "./chunk-7AXWBC3X.js";
8
+ } from "./chunk-OKE4RCRY.js";
9
9
  import {
10
10
  extractCommandProtectionCommandText,
11
11
  findCommandProtectionGitLookups,
@@ -3,8 +3,8 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  evaluateCommandProtection
6
- } from "./chunk-ADMXJN77.js";
7
- import "./chunk-7AXWBC3X.js";
6
+ } from "./chunk-XG6BQ3DQ.js";
7
+ import "./chunk-OKE4RCRY.js";
8
8
  import "./chunk-2AG3DWDX.js";
9
9
  import {
10
10
  isRecord
@@ -13,11 +13,11 @@ import {
13
13
  recoverCompletedTurn,
14
14
  spawnMuseMsp,
15
15
  startMuseSession
16
- } from "./chunk-IHQCAVNI.js";
16
+ } from "./chunk-E6ZC5R42.js";
17
17
  import {
18
18
  AppServerProcess,
19
19
  buildCodexAgentEnv
20
- } from "./chunk-YB2HONQF.js";
20
+ } from "./chunk-RB33U66A.js";
21
21
  import "./chunk-2AG3DWDX.js";
22
22
  import {
23
23
  AGENT,
package/dist/src/index.js CHANGED
@@ -27,7 +27,7 @@ import {
27
27
  evaluateCommandProtection,
28
28
  extractToolCommand,
29
29
  reportCommandProtectionBlock
30
- } from "./chunk-ADMXJN77.js";
30
+ } from "./chunk-XG6BQ3DQ.js";
31
31
  import {
32
32
  ACCOUNT_RATE_LIMITS_UPDATED_METHOD,
33
33
  AGENT_MESSAGE_DELTA_METHOD,
@@ -64,7 +64,7 @@ import {
64
64
  spawnMuseMsp,
65
65
  startMuseSession,
66
66
  uuidV7
67
- } from "./chunk-IHQCAVNI.js";
67
+ } from "./chunk-E6ZC5R42.js";
68
68
  import {
69
69
  publishedPullRequestUrls
70
70
  } from "./chunk-E5HOEAHV.js";
@@ -130,7 +130,7 @@ import {
130
130
  timestampFromSeconds,
131
131
  upsertCredentialFileLines,
132
132
  writeSecureCredentialFile
133
- } from "./chunk-GJ42APJ6.js";
133
+ } from "./chunk-6TR2W5B3.js";
134
134
  import {
135
135
  ENGINE_ENV,
136
136
  monolithRequest,
@@ -139,10 +139,10 @@ import {
139
139
  reloadEngineEnv,
140
140
  resolveDiffBase,
141
141
  setAgentCredentialSnapshot
142
- } from "./chunk-7AXWBC3X.js";
142
+ } from "./chunk-OKE4RCRY.js";
143
143
  import {
144
144
  getCodexModelProvider
145
- } from "./chunk-YB2HONQF.js";
145
+ } from "./chunk-RB33U66A.js";
146
146
  import {
147
147
  SUBPROCESS_MAX_BUFFER,
148
148
  execAsync,
@@ -11019,7 +11019,7 @@ var MuseTokenManager = class extends BaseRefreshManager {
11019
11019
  failureKind,
11020
11020
  ...exclusions
11021
11021
  };
11022
- const response = await monolithRequest("/v1/engine/muse/refresh-credentials", { body: request });
11022
+ const response = await monolithRequest("/v1/engine/muse/refresh-credentials", { body: request, signal: AbortSignal.timeout(12e4) });
11023
11023
  if (!response.ok) {
11024
11024
  throw new Error(`Credentials refresh failed: ${response.status} ${await response.text()}`);
11025
11025
  }
@@ -11051,6 +11051,7 @@ function describeQuotaExhaustion(provider, reason, credential, fallback) {
11051
11051
  const next = fallback.outcome === "fork" ? `Forking this chat to ${getProviderDisplayName(fallback.target.provider, "long")}.` : QUOTA_STOP_NEXT_STEP[fallback.outcome];
11052
11052
  return `${limit} ${next}`;
11053
11053
  }
11054
+ var fallbackLocks = /* @__PURE__ */ new Map();
11054
11055
  var AuthFallbackCoordinator = class {
11055
11056
  constructor(provider, record3, context) {
11056
11057
  this.provider = provider;
@@ -11060,9 +11061,17 @@ var AuthFallbackCoordinator = class {
11060
11061
  provider;
11061
11062
  record;
11062
11063
  context;
11063
- async fallBack(reason, detail) {
11064
+ /** `attempted` is the credential the failed turn ran on, which another chat may already have replaced. */
11065
+ fallBack(reason, detail, attempted) {
11066
+ let lock = fallbackLocks.get(this.provider);
11067
+ if (!lock) fallbackLocks.set(this.provider, lock = new AsyncLock());
11068
+ return lock.run(() => this.fallBackNow(reason, detail, attempted));
11069
+ }
11070
+ async fallBackNow(reason, detail, attempted) {
11064
11071
  const tokenManager = SWAPPABLE_AGENTS[this.provider];
11065
- const exhausted = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS[this.provider];
11072
+ const live = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS[this.provider];
11073
+ const exhausted = attempted ?? live;
11074
+ const alreadyReplaced = !!exhausted && !!live && !isSameCredential(live, exhausted);
11066
11075
  if (exhausted) recordExhaustedCredential(this.provider, exhausted);
11067
11076
  const { userId, excludeProviders, forkable } = this.context();
11068
11077
  const plan = await monolithService.getFallbackPlan({
@@ -11082,13 +11091,19 @@ var AuthFallbackCoordinator = class {
11082
11091
  if (forkable && isAgentAvailable(step.provider)) return { outcome: "fork", target: step };
11083
11092
  continue;
11084
11093
  }
11094
+ if (alreadyReplaced && live) {
11095
+ if (step.methods.length > 0 && !step.methods.includes(live.method)) continue;
11096
+ this.recordNotice(reason, exhausted, live, "switched", detail);
11097
+ const model2 = step.models?.[live.method];
11098
+ return { outcome: "switched", ...model2 ? { model: model2 } : {} };
11099
+ }
11085
11100
  if (!tokenManager || !exhausted) continue;
11086
11101
  const swap = await tokenManager.fetchFreshCredentials(
11087
11102
  `${this.provider} ${describeQuotaLimit(reason)}: ${detail}`,
11088
11103
  // A rejected login is skipped through the exclusion above rather than rested
11089
11104
  // like a spent quota, which Settings would show as a usage limit.
11090
11105
  reason === "auth_failed" ? "rejected" : "exhausted",
11091
- void 0,
11106
+ exhausted,
11092
11107
  step.methods.length > 0 ? step.methods : void 0
11093
11108
  );
11094
11109
  if (!swap.ok) {
@@ -11405,9 +11420,9 @@ var CodingAgentManager = class {
11405
11420
  this.getHistorySink()?.append(event);
11406
11421
  }, options.fallbackContext ?? (() => ({ excludeProviders: [], forkable: false }))) : null;
11407
11422
  }
11408
- async fallBackCredential(reason, detail) {
11423
+ async fallBackCredential(reason, detail, attempted) {
11409
11424
  if (!this.authFallback) return { outcome: "unavailable" };
11410
- const result = await this.authFallback.fallBack(reason, detail);
11425
+ const result = await this.authFallback.fallBack(reason, detail, attempted);
11411
11426
  if (result.outcome === "switched" && result.model) await this.onModelSwitched(result.model);
11412
11427
  return result;
11413
11428
  }
@@ -12999,7 +13014,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
12999
13014
  if (quotaKind || isAuthError) {
13000
13015
  const reason = quotaKind ?? "auth_failed";
13001
13016
  const detail = error instanceof ClaudeQuotaError ? error.message : extractErrorText(error);
13002
- const fallback = fallbacks < MAX_FALLBACKS ? await this.fallBackCredential(reason, detail) : { outcome: "unavailable" };
13017
+ const fallback = fallbacks < MAX_FALLBACKS ? await this.fallBackCredential(reason, detail, attemptedCredential) : { outcome: "unavailable" };
13003
13018
  if (fallback.outcome === "switched") {
13004
13019
  if (fallback.model) currentRequest = { ...currentRequest, model: fallback.model };
13005
13020
  fallbacks++;
@@ -14337,7 +14352,8 @@ var CodexAspManager = class extends CodingAgentManager {
14337
14352
  quotaFallbackAttempted = true;
14338
14353
  const fallback = await this.fallBackCredential(
14339
14354
  detectAgentQuotaLimit(terminalError.message) ?? "rate_limit",
14340
- terminalError.message
14355
+ terminalError.message,
14356
+ attemptedCredential
14341
14357
  );
14342
14358
  if (fallback.outcome === "switched") {
14343
14359
  if (fallback.model) request = { ...request, model: fallback.model };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.1181",
3
+ "version": "0.1.1183",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",