replicas-engine 0.1.923 → 0.1.925

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.
@@ -5,11 +5,11 @@ import {
5
5
  getCodexAspHost,
6
6
  restartCodexAspHost,
7
7
  restartCodexAspHostIfRunning
8
- } from "./chunk-MNNFNXNL.js";
9
- import "./chunk-LYX74DW2.js";
10
- import "./chunk-IRVUCLOA.js";
8
+ } from "./chunk-ARAD76EY.js";
9
+ import "./chunk-Y3ZAG37O.js";
10
+ import "./chunk-JLRNRGG3.js";
11
11
  import "./chunk-UZSNFLDQ.js";
12
- import "./chunk-VT557AFP.js";
12
+ import "./chunk-RLBC7EZ4.js";
13
13
  import "./chunk-VEQXQN22.js";
14
14
  export {
15
15
  getCodexAspHost,
@@ -5,7 +5,7 @@ import {
5
5
  extractCommandProtectionCommandText,
6
6
  isRecord,
7
7
  parseCodeHostPrUrl
8
- } from "./chunk-VT557AFP.js";
8
+ } from "./chunk-RLBC7EZ4.js";
9
9
 
10
10
  // src/services/published-pull-request-urls.ts
11
11
  function publishedPullRequestUrls(result) {
@@ -5,13 +5,13 @@ import {
5
5
  ENGINE_ENV,
6
6
  monolithRequest,
7
7
  setAgentCredentialSnapshot
8
- } from "./chunk-LYX74DW2.js";
8
+ } from "./chunk-Y3ZAG37O.js";
9
9
  import {
10
10
  AppServerProcess,
11
11
  SUBPROCESS_MAX_BUFFER,
12
12
  buildCodexAgentEnv,
13
13
  execFileAsync
14
- } from "./chunk-IRVUCLOA.js";
14
+ } from "./chunk-JLRNRGG3.js";
15
15
  import {
16
16
  isRecord
17
17
  } from "./chunk-UZSNFLDQ.js";
@@ -25,7 +25,7 @@ import {
25
25
  listOpenAICompatibleModels,
26
26
  readOllamaAuthEnv,
27
27
  resolveOpenAICompatibleModelsUrl
28
- } from "./chunk-VT557AFP.js";
28
+ } from "./chunk-RLBC7EZ4.js";
29
29
 
30
30
  // src/managers/codex-token-manager.ts
31
31
  import { promises as fs } from "fs";
@@ -80,6 +80,13 @@ function recordExhaustedCredential(provider, credential) {
80
80
  }
81
81
 
82
82
  // src/managers/base-refresh-manager.ts
83
+ function credentialSwapError(error) {
84
+ const message = error instanceof Error ? error.message : String(error);
85
+ return createErrorResult({
86
+ message,
87
+ code: message.includes('"code":"no_credentials"') ? "no_credentials" : "refresh_failed"
88
+ });
89
+ }
83
90
  function refreshDelayMs(expiresAtMs, maxMs = 5 * 60 * 1e3) {
84
91
  const ttlMs = expiresAtMs - Date.now();
85
92
  return Number.isFinite(ttlMs) ? Math.max(1e3, Math.min(maxMs, Math.floor(ttlMs * 0.8))) : maxMs;
@@ -158,12 +165,8 @@ var BaseRefreshManager = class {
158
165
  }
159
166
  return createSuccessResult();
160
167
  } catch (error) {
161
- const message = error instanceof Error ? error.message : String(error);
162
168
  console.error(`[${this.managerName}] Failed to fetch fresh credentials:`, error);
163
- return createErrorResult({
164
- message,
165
- code: message.includes('"code":"no_credentials"') ? "no_credentials" : "refresh_failed"
166
- });
169
+ return credentialSwapError(error);
167
170
  }
168
171
  }
169
172
  async stop() {
@@ -255,7 +258,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
255
258
  await this.applyCredentialUpdate(++this.credentialGeneration, async () => {
256
259
  await this.applyCredentialsResponse(data);
257
260
  setAgentCredentialSnapshot("codex", data);
258
- const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-24DVCCC3.js");
261
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-7Q4EG2HV.js");
259
262
  await restartCodexAspHostIfRunning2();
260
263
  });
261
264
  await this.start(true);
@@ -275,7 +278,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
275
278
  await this.applyCredentialUpdate(generation, async () => {
276
279
  await this.applyCredentialsResponse(data);
277
280
  if (restartOnChange && CODEX_AUTH_ENV_KEYS.some((key, index) => process.env[key] !== previousEnv[index])) {
278
- const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-24DVCCC3.js");
281
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-7Q4EG2HV.js");
279
282
  await restartCodexAspHostIfRunning2();
280
283
  }
281
284
  setAgentCredentialSnapshot("codex", data);
@@ -323,11 +326,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
323
326
  }
324
327
  return createSuccessResult(this.buildAspOauthLogin(response));
325
328
  } catch (error) {
326
- const message = error instanceof Error ? error.message : String(error);
327
- return createErrorResult({
328
- message,
329
- code: message.includes('"code":"no_credentials"') ? "no_credentials" : "refresh_failed"
330
- });
329
+ return credentialSwapError(error);
331
330
  }
332
331
  }
333
332
  async fetchFreshCredentials(failureReason, failureKind = "rejected", failedCredential = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.codex, allowedMethods) {
@@ -510,6 +509,7 @@ export {
510
509
  listCredentialFallbacks,
511
510
  routineRefreshExclusions,
512
511
  recordExhaustedCredential,
512
+ credentialSwapError,
513
513
  refreshDelayMs,
514
514
  BaseRefreshManager,
515
515
  applyAuthEnvTransition,
@@ -4,7 +4,7 @@ const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  HOOK_EXEC_MAX_BUFFER_BYTES,
6
6
  isVersionBelow
7
- } from "./chunk-VT557AFP.js";
7
+ } from "./chunk-RLBC7EZ4.js";
8
8
 
9
9
  // src/utils/codex-agent-env.ts
10
10
  function buildCodexAgentEnv(source = process.env) {
@@ -245,7 +245,7 @@ function getCodexModelProvider(method) {
245
245
  if (method === "foundry") return "azure";
246
246
  return method === "ollama" || method === "openai-compatible" ? "replicas_openai_compatible" : "openai";
247
247
  }
248
- var ENGINE_PACKAGE_VERSION = "0.1.923";
248
+ var ENGINE_PACKAGE_VERSION = "0.1.925";
249
249
  var INITIALIZE_METHOD = "initialize";
250
250
  var INITIALIZED_NOTIFICATION = "initialized";
251
251
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -3,12 +3,12 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  monolithRequest
6
- } from "./chunk-LYX74DW2.js";
6
+ } from "./chunk-Y3ZAG37O.js";
7
7
  import {
8
8
  extractCommandProtectionCommandText,
9
9
  findGitCommitSignals,
10
10
  findPrMergeSignals
11
- } from "./chunk-VT557AFP.js";
11
+ } from "./chunk-RLBC7EZ4.js";
12
12
 
13
13
  // src/services/command-protection-service.ts
14
14
  var DEFAULT_COMMAND_PROTECTION_BLOCK_MESSAGE = "Blocked by Replicas command protection.";
@@ -208,6 +208,7 @@ var CLAUDE_FABLE_5_MODEL = "claude-fable-5";
208
208
  var CLAUDE_OPUS_5_5_MODEL = "claude-opus-5-5";
209
209
  var CLAUDE_OPUS_5_MODEL = "claude-opus-5";
210
210
  var CLAUDE_OPUS_4_8_MODEL = "claude-opus-4-8";
211
+ var CLAUDE_SONNET_5_5_MODEL = "claude-sonnet-5-5";
211
212
  var CLAUDE_SONNET_5_MODEL = "claude-sonnet-5";
212
213
  var CLAUDE_HAIKU_4_5_MODEL = "claude-haiku-4-5";
213
214
  var CLAUDE_FABLE_5_1_BEDROCK_MODEL = "anthropic.claude-fable-5-1";
@@ -215,6 +216,7 @@ var CLAUDE_FABLE_5_BEDROCK_MODEL = "anthropic.claude-fable-5";
215
216
  var CLAUDE_OPUS_5_5_BEDROCK_MODEL = "anthropic.claude-opus-5-5";
216
217
  var CLAUDE_OPUS_5_BEDROCK_MODEL = "anthropic.claude-opus-5";
217
218
  var CLAUDE_OPUS_4_8_BEDROCK_MODEL = "us.anthropic.claude-opus-4-8";
219
+ var CLAUDE_SONNET_5_5_BEDROCK_MODEL = "anthropic.claude-sonnet-5-5";
218
220
  var CLAUDE_SONNET_5_BEDROCK_MODEL = "anthropic.claude-sonnet-5";
219
221
  var CLAUDE_HAIKU_4_5_BEDROCK_MODEL = "us.anthropic.claude-haiku-4-5-20251001-v1:0";
220
222
  var DEFAULT_CLAUDE_MODEL = CLAUDE_OPUS_5_5_MODEL;
@@ -262,9 +264,10 @@ var FALLBACK_AGENT_MODEL = {
262
264
  };
263
265
  function getDefaultAgentModel(provider, overrides) {
264
266
  const catalogDefault = overrides?.defaultModels?.[provider];
265
- if (catalogDefault !== void 0) return catalogDefault ?? "";
266
- const fallback = FALLBACK_AGENT_MODEL[provider];
267
+ if (catalogDefault === null) return "";
267
268
  const options = getAgentModelOptions(provider, overrides);
269
+ if (catalogDefault && options.includes(catalogDefault)) return catalogDefault;
270
+ const fallback = FALLBACK_AGENT_MODEL[provider];
268
271
  return options.includes(fallback) ? fallback : options[0];
269
272
  }
270
273
  function normalizeClaudeModel(model) {
@@ -288,6 +291,7 @@ var CLAUDE_MODEL_CONTEXT_WINDOWS = {
288
291
  [CLAUDE_OPUS_5_5_MODEL]: 1e6,
289
292
  [CLAUDE_OPUS_5_MODEL]: 1e6,
290
293
  [CLAUDE_OPUS_4_8_MODEL]: 1e6,
294
+ [CLAUDE_SONNET_5_5_MODEL]: 1e6,
291
295
  [CLAUDE_SONNET_5_MODEL]: 1e6,
292
296
  [CLAUDE_HAIKU_4_5_MODEL]: 2e5,
293
297
  [CLAUDE_FABLE_5_1_BEDROCK_MODEL]: 1e6,
@@ -295,6 +299,7 @@ var CLAUDE_MODEL_CONTEXT_WINDOWS = {
295
299
  [CLAUDE_OPUS_5_5_BEDROCK_MODEL]: 1e6,
296
300
  [CLAUDE_OPUS_5_BEDROCK_MODEL]: 1e6,
297
301
  [CLAUDE_OPUS_4_8_BEDROCK_MODEL]: 1e6,
302
+ [CLAUDE_SONNET_5_5_BEDROCK_MODEL]: 1e6,
298
303
  [CLAUDE_SONNET_5_BEDROCK_MODEL]: 1e6,
299
304
  [CLAUDE_HAIKU_4_5_BEDROCK_MODEL]: 2e5,
300
305
  "anthropic.claude-opus-4-8": 1e6,
@@ -319,6 +324,7 @@ var AGENT_MODELS = {
319
324
  CLAUDE_OPUS_5_5_MODEL,
320
325
  CLAUDE_OPUS_5_MODEL,
321
326
  CLAUDE_OPUS_4_8_MODEL,
327
+ CLAUDE_SONNET_5_5_MODEL,
322
328
  CLAUDE_SONNET_5_MODEL,
323
329
  CLAUDE_HAIKU_4_5_MODEL
324
330
  ],
@@ -358,7 +364,7 @@ var AGENT_MODELS = {
358
364
  muse: [MUSE_SPARK_1_3_MODEL, DEFAULT_MUSE_MODEL],
359
365
  opencode: [...DEFAULT_OPENROUTER_MODELS, ...ASTER_MODELS],
360
366
  pi: [...DEFAULT_OPENROUTER_MODELS, ...ASTER_MODELS],
361
- relay: [CLAUDE_FABLE_5_1_MODEL, CLAUDE_FABLE_5_MODEL, CLAUDE_OPUS_5_5_MODEL, CLAUDE_OPUS_5_MODEL, CLAUDE_OPUS_4_8_MODEL, CLAUDE_SONNET_5_MODEL]
367
+ relay: [CLAUDE_FABLE_5_1_MODEL, CLAUDE_FABLE_5_MODEL, CLAUDE_OPUS_5_5_MODEL, CLAUDE_OPUS_5_MODEL, CLAUDE_OPUS_4_8_MODEL, CLAUDE_SONNET_5_5_MODEL, CLAUDE_SONNET_5_MODEL]
362
368
  };
363
369
  var DEFAULT_STATIC_AGENT_MODELS = {
364
370
  claude: AGENT_MODELS.claude.filter((model) => model !== CLAUDE_FABLE_5_MODEL && model !== CLAUDE_OPUS_4_8_MODEL),
@@ -372,7 +378,8 @@ function getAgentModelOptions(provider, overrides) {
372
378
  }
373
379
  var CLAUDE_MODEL_MIN_SANDBOX_IMAGE = {
374
380
  [CLAUDE_FABLE_5_1_MODEL]: "replicas-sandbox-2026-09-01-v6",
375
- [CLAUDE_OPUS_5_5_MODEL]: "replicas-sandbox-2026-09-22-v4"
381
+ [CLAUDE_OPUS_5_5_MODEL]: "replicas-sandbox-2026-09-22-v4",
382
+ [CLAUDE_SONNET_5_5_MODEL]: "replicas-sandbox-2026-09-28-v7"
376
383
  };
377
384
  var CODEX_MODEL_MIN_SANDBOX_IMAGE = {
378
385
  [GPT_6_ASTRA_MODEL]: "replicas-sandbox-2026-09-04-v7",
@@ -385,6 +392,7 @@ var MODEL_LABELS = {
385
392
  [CLAUDE_FABLE_5_MODEL]: "Fable 5",
386
393
  sonnet: "Sonnet 5",
387
394
  "claude-sonnet-5": "Sonnet 5",
395
+ [CLAUDE_SONNET_5_5_MODEL]: "Sonnet 5.5",
388
396
  opus: "Opus 5",
389
397
  [CLAUDE_OPUS_5_5_MODEL]: "Opus 5.5",
390
398
  [CLAUDE_OPUS_5_MODEL]: "Opus 5",
@@ -1173,6 +1181,7 @@ var sendChatMessageRequestSchema = z3.object({
1173
1181
  idempotencyKey: z3.string().min(1).max(128).optional(),
1174
1182
  automationId: z3.string().optional(),
1175
1183
  environmentId: z3.string().min(1).optional(),
1184
+ chatCredentials: z3.boolean().optional(),
1176
1185
  senderUserId: z3.string().optional(),
1177
1186
  senderEmail: z3.string().optional(),
1178
1187
  senderDisplayName: z3.string().optional(),
@@ -7912,6 +7921,7 @@ export {
7912
7921
  CLAUDE_OPUS_5_5_MODEL,
7913
7922
  CLAUDE_OPUS_5_MODEL,
7914
7923
  CLAUDE_OPUS_4_8_MODEL,
7924
+ CLAUDE_SONNET_5_5_MODEL,
7915
7925
  CLAUDE_SONNET_5_MODEL,
7916
7926
  CLAUDE_HAIKU_4_5_MODEL,
7917
7927
  CLAUDE_FABLE_5_1_BEDROCK_MODEL,
@@ -7919,6 +7929,7 @@ export {
7919
7929
  CLAUDE_OPUS_5_5_BEDROCK_MODEL,
7920
7930
  CLAUDE_OPUS_5_BEDROCK_MODEL,
7921
7931
  CLAUDE_OPUS_4_8_BEDROCK_MODEL,
7932
+ CLAUDE_SONNET_5_5_BEDROCK_MODEL,
7922
7933
  CLAUDE_SONNET_5_BEDROCK_MODEL,
7923
7934
  CLAUDE_HAIKU_4_5_BEDROCK_MODEL,
7924
7935
  DEFAULT_CLAUDE_MODEL,
@@ -15,7 +15,7 @@ import {
15
15
  isValidRelayBaseProvider,
16
16
  parsePosixEnvFile,
17
17
  readReplicasRuntimeEnv
18
- } from "./chunk-VT557AFP.js";
18
+ } from "./chunk-RLBC7EZ4.js";
19
19
 
20
20
  // src/runtime-env-loader.ts
21
21
  import { readFileSync } from "fs";
@@ -220,6 +220,7 @@ var MonolithService = class {
220
220
  const query = new URLSearchParams({ provider: params.provider, exclude: params.exclude.join(",") });
221
221
  if (params.exhaustedMethod) query.set("exhaustedMethod", params.exhaustedMethod);
222
222
  if (params.userId) query.set("userId", params.userId);
223
+ if (params.chatId) query.set("chatId", params.chatId);
223
224
  try {
224
225
  const response = await monolithRequest(`/v1/engine/fallback-plan?${query}`, { method: "GET" });
225
226
  if (response.status === 404) return createErrorResult({ message: "Monolith has no fallback-plan route", code: "unsupported" });
@@ -3,12 +3,12 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  evaluateCommandProtection
6
- } from "./chunk-HEYQCKMN.js";
7
- import "./chunk-LYX74DW2.js";
6
+ } from "./chunk-P56H3PGY.js";
7
+ import "./chunk-Y3ZAG37O.js";
8
8
  import {
9
9
  isRecord
10
10
  } from "./chunk-UZSNFLDQ.js";
11
- import "./chunk-VT557AFP.js";
11
+ import "./chunk-RLBC7EZ4.js";
12
12
  import "./chunk-VEQXQN22.js";
13
13
 
14
14
  // src/command-protection-hook.ts
@@ -8,12 +8,12 @@ import {
8
8
  import {
9
9
  AppServerProcess,
10
10
  buildCodexAgentEnv
11
- } from "./chunk-IRVUCLOA.js";
11
+ } from "./chunk-JLRNRGG3.js";
12
12
  import {
13
13
  AGENT,
14
14
  getMemoryOutputSafetyViolation,
15
15
  headlessAgentRequestSchema
16
- } from "./chunk-VT557AFP.js";
16
+ } from "./chunk-RLBC7EZ4.js";
17
17
  import "./chunk-VEQXQN22.js";
18
18
 
19
19
  // src/headless-agent.ts
package/dist/src/index.js CHANGED
@@ -27,7 +27,7 @@ import {
27
27
  evaluateCommandProtection,
28
28
  extractToolCommand,
29
29
  reportCommandProtectionBlock
30
- } from "./chunk-HEYQCKMN.js";
30
+ } from "./chunk-P56H3PGY.js";
31
31
  import {
32
32
  ACCOUNT_RATE_LIMITS_UPDATED_METHOD,
33
33
  AGENT_MESSAGE_DELTA_METHOD,
@@ -52,7 +52,7 @@ import {
52
52
  } from "./chunk-FLDA7BX3.js";
53
53
  import {
54
54
  publishedPullRequestUrls
55
- } from "./chunk-2J5TLHIA.js";
55
+ } from "./chunk-4Q7E2QOZ.js";
56
56
  import {
57
57
  RELAY_MCP_TOOLS,
58
58
  RELAY_MCP_TOOL_NAMES,
@@ -66,6 +66,7 @@ import {
66
66
  applyAuthEnvTransition,
67
67
  clearCredentialFallbacks,
68
68
  codexTokenManager,
69
+ credentialSwapError,
69
70
  getCodexAspHost,
70
71
  listCredentialFallbacks,
71
72
  recordCredentialFallback,
@@ -73,7 +74,7 @@ import {
73
74
  refreshDelayMs,
74
75
  restartCodexAspHost,
75
76
  routineRefreshExclusions
76
- } from "./chunk-MNNFNXNL.js";
77
+ } from "./chunk-ARAD76EY.js";
77
78
  import {
78
79
  ENGINE_ENV,
79
80
  monolithRequest,
@@ -81,14 +82,14 @@ import {
81
82
  readRuntimeEnvFile,
82
83
  reloadEngineEnv,
83
84
  setAgentCredentialSnapshot
84
- } from "./chunk-LYX74DW2.js";
85
+ } from "./chunk-Y3ZAG37O.js";
85
86
  import {
86
87
  AspClient,
87
88
  SUBPROCESS_MAX_BUFFER,
88
89
  execAsync,
89
90
  execFileAsync,
90
91
  getCodexModelProvider
91
- } from "./chunk-IRVUCLOA.js";
92
+ } from "./chunk-JLRNRGG3.js";
92
93
  import {
93
94
  isRecord as isRecord2
94
95
  } from "./chunk-UZSNFLDQ.js";
@@ -121,6 +122,8 @@ import {
121
122
  CLAUDE_OPUS_5_BEDROCK_MODEL,
122
123
  CLAUDE_OPUS_5_MODEL,
123
124
  CLAUDE_PARTIAL_MESSAGE_EVENT_TYPE,
125
+ CLAUDE_SONNET_5_5_BEDROCK_MODEL,
126
+ CLAUDE_SONNET_5_5_MODEL,
124
127
  CLAUDE_SONNET_5_BEDROCK_MODEL,
125
128
  CLAUDE_SONNET_5_MODEL,
126
129
  CODEX_ASP_ITEM_ID_PAYLOAD_KEY,
@@ -313,7 +316,7 @@ import {
313
316
  workspaceCredentialProviderSchema,
314
317
  workspaceTokenRequestSchema,
315
318
  workspaceTokenResponseSchema
316
- } from "./chunk-VT557AFP.js";
319
+ } from "./chunk-RLBC7EZ4.js";
317
320
  import {
318
321
  cloneMcpConfig,
319
322
  ensureCompatibilityImports,
@@ -9492,6 +9495,13 @@ var gitlabTokenManager = new GitLabTokenManager();
9492
9495
  // src/managers/claude-token-manager.ts
9493
9496
  import { promises as fs } from "fs";
9494
9497
  import path3 from "path";
9498
+ async function requestClaudeCredentials(request) {
9499
+ const response = await monolithRequest("/v1/engine/claude/refresh-credentials", { body: request });
9500
+ if (!response.ok) {
9501
+ throw new Error(`Credentials refresh failed: ${response.status} ${await response.text()}`);
9502
+ }
9503
+ return response.json();
9504
+ }
9495
9505
  var ClaudeTokenManager = class extends BaseRefreshManager {
9496
9506
  constructor() {
9497
9507
  super("ClaudeTokenManager");
@@ -9513,14 +9523,7 @@ var ClaudeTokenManager = class extends BaseRefreshManager {
9513
9523
  async refreshWithRequest(request) {
9514
9524
  const generation = this.credentialGeneration;
9515
9525
  console.log("[ClaudeTokenManager] Refreshing Claude credentials...");
9516
- const response = await monolithRequest("/v1/engine/claude/refresh-credentials", {
9517
- body: request
9518
- });
9519
- if (!response.ok) {
9520
- const errorText = await response.text();
9521
- throw new Error(`Credentials refresh failed: ${response.status} ${errorText}`);
9522
- }
9523
- const data = await response.json();
9526
+ const data = await requestClaudeCredentials(request);
9524
9527
  await this.applyCredentialUpdate(generation, () => this.applyCredentialsResponse(data));
9525
9528
  console.log(`[ClaudeTokenManager] Credentials refreshed (method=${data.type})`);
9526
9529
  }
@@ -11698,16 +11701,21 @@ var AuthFallbackCoordinator = class {
11698
11701
  provider;
11699
11702
  record;
11700
11703
  context;
11701
- async fallBack(reason, detail) {
11702
- const tokenManager = SWAPPABLE_AGENTS[this.provider];
11703
- const exhausted = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS[this.provider];
11704
- if (exhausted) recordExhaustedCredential(this.provider, exhausted);
11704
+ async fallBack(reason, detail, chatCredentials) {
11705
+ const tokenManager = chatCredentials ?? SWAPPABLE_AGENTS[this.provider];
11706
+ const current = () => chatCredentials ? chatCredentials.snapshot() : ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS[this.provider];
11707
+ const exhausted = current();
11708
+ if (exhausted) {
11709
+ if (chatCredentials) chatCredentials.markExhausted(exhausted);
11710
+ else recordExhaustedCredential(this.provider, exhausted);
11711
+ }
11705
11712
  const { userId, excludeProviders, forkable } = this.context();
11706
11713
  const plan = await monolithService.getFallbackPlan({
11707
11714
  provider: this.provider,
11708
11715
  exhaustedMethod: exhausted?.method,
11709
11716
  exclude: excludeProviders,
11710
- userId
11717
+ userId,
11718
+ chatId: chatCredentials?.chatId
11711
11719
  });
11712
11720
  if (!plan.ok && plan.error.code === "unavailable") {
11713
11721
  console.error(`[AuthFallback] ${this.provider} fallback stopped; plan unavailable:`, plan.error.message);
@@ -11731,20 +11739,20 @@ var AuthFallbackCoordinator = class {
11731
11739
  failed ||= swap.error.code !== "no_credentials";
11732
11740
  continue;
11733
11741
  }
11734
- const applied = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS[this.provider] ?? exhausted;
11742
+ const applied = current() ?? exhausted;
11735
11743
  if (applied.method === exhausted.method && applied.scope === exhausted.scope) {
11736
11744
  failed = true;
11737
11745
  continue;
11738
11746
  }
11739
- this.recordNotice(reason, exhausted, applied, "switched", detail);
11747
+ this.recordNotice(reason, exhausted, applied, "switched", detail, !chatCredentials);
11740
11748
  return { outcome: "switched" };
11741
11749
  }
11742
11750
  if (!tokenManager || !exhausted) return { outcome: "unavailable" };
11743
11751
  if (!failed) return { outcome: "not_configured" };
11744
- this.recordNotice(reason, exhausted, exhausted, "failed", "Replicas could not load an alternate credential.");
11752
+ this.recordNotice(reason, exhausted, exhausted, "failed", "Replicas could not load an alternate credential.", !chatCredentials);
11745
11753
  return { outcome: "failed" };
11746
11754
  }
11747
- recordNotice(reason, exhausted, applied, status, detail) {
11755
+ recordNotice(reason, exhausted, applied, status, detail, workspaceWide) {
11748
11756
  const payload = {
11749
11757
  provider: this.provider,
11750
11758
  reason,
@@ -11759,7 +11767,7 @@ var AuthFallbackCoordinator = class {
11759
11767
  };
11760
11768
  const at = (/* @__PURE__ */ new Date()).toISOString();
11761
11769
  this.record({ timestamp: at, type: AUTH_FALLBACK_EVENT_TYPE, payload: { ...payload } });
11762
- recordCredentialFallback({ ...payload, at });
11770
+ if (workspaceWide) recordCredentialFallback({ ...payload, at });
11763
11771
  }
11764
11772
  };
11765
11773
 
@@ -12015,9 +12023,9 @@ var CodingAgentManager = class {
12015
12023
  this.getHistorySink()?.append(event);
12016
12024
  }, options.fallbackContext ?? (() => ({ excludeProviders: [], forkable: false }))) : null;
12017
12025
  }
12018
- async fallBackCredential(reason, detail) {
12026
+ async fallBackCredential(reason, detail, chatCredentials) {
12019
12027
  if (!this.authFallback) return { outcome: "unavailable" };
12020
- return this.authFallback.fallBack(reason, detail);
12028
+ return this.authFallback.fallBack(reason, detail, chatCredentials);
12021
12029
  }
12022
12030
  onTurnComplete = async () => {
12023
12031
  if (this.compacting) {
@@ -12306,16 +12314,17 @@ function resolveClaudeAuthMethodForMessage(env = ENGINE_ENV) {
12306
12314
  if (env.ANTHROPIC_API_KEY) return "api_key";
12307
12315
  return "unknown";
12308
12316
  }
12309
- function buildClaudeAgentEnv(overrides) {
12310
- const env = { ...process.env };
12317
+ function buildClaudeAgentEnv(overrides, chatEnv) {
12318
+ const env = { ...chatEnv ?? process.env };
12311
12319
  if (overrides) {
12312
12320
  Object.assign(env, overrides);
12313
12321
  }
12314
- const isBedrock = isClaudeBedrockEnv(env);
12315
- if (shouldStripAnthropicApiKey(isBedrock)) {
12322
+ const method = chatEnv ? chatEnv.REPLICAS_CLAUDE_AUTH_METHOD : ENGINE_ENV.REPLICAS_CLAUDE_AUTH_METHOD;
12323
+ const isBedrock = method === "bedrock" || env.REPLICAS_CLAUDE_AUTH_METHOD === "bedrock" || env.CLAUDE_CODE_USE_BEDROCK === "1";
12324
+ if (method === "oauth" || method === "bedrock" || method === "foundry" || isBedrock) {
12316
12325
  env.ANTHROPIC_API_KEY = void 0;
12317
12326
  }
12318
- if (ENGINE_ENV.REPLICAS_CLAUDE_AUTH_METHOD === "ollama") env.ANTHROPIC_API_KEY = "";
12327
+ if (method === "ollama") env.ANTHROPIC_API_KEY = "";
12319
12328
  if (isBedrock) {
12320
12329
  env.CLAUDE_CODE_USE_BEDROCK = "1";
12321
12330
  env.CLAUDE_CODE_USE_MANTLE = "1";
@@ -12331,13 +12340,6 @@ function buildClaudeAgentEnv(overrides) {
12331
12340
  env.CLAUDE_CODE_EMIT_SESSION_STATE_EVENTS = "1";
12332
12341
  return env;
12333
12342
  }
12334
- function shouldStripAnthropicApiKey(isBedrock) {
12335
- const method = ENGINE_ENV.REPLICAS_CLAUDE_AUTH_METHOD;
12336
- return method === "oauth" || method === "bedrock" || method === "foundry" || isBedrock;
12337
- }
12338
- function isClaudeBedrockEnv(env) {
12339
- return ENGINE_ENV.REPLICAS_CLAUDE_AUTH_METHOD === "bedrock" || env.REPLICAS_CLAUDE_AUTH_METHOD === "bedrock" || env.CLAUDE_CODE_USE_BEDROCK === "1";
12340
- }
12341
12343
 
12342
12344
  // src/utils/agent-additional-directories.ts
12343
12345
  async function getAgentAdditionalDirectories() {
@@ -12349,6 +12351,90 @@ async function getAgentAdditionalDirectories() {
12349
12351
  }
12350
12352
  }
12351
12353
 
12354
+ // src/managers/chat-claude-credentials.ts
12355
+ var EXHAUSTED_RETRY_MS = 60 * 60 * 1e3;
12356
+ var AUTH_SELECTOR_KEYS = [
12357
+ "ANTHROPIC_API_KEY",
12358
+ "ANTHROPIC_AUTH_TOKEN",
12359
+ "ANTHROPIC_BASE_URL",
12360
+ "CLAUDE_CODE_USE_BEDROCK",
12361
+ "CLAUDE_CODE_USE_FOUNDRY"
12362
+ ];
12363
+ var ChatClaudeCredentials = class {
12364
+ constructor(chatId) {
12365
+ this.chatId = chatId;
12366
+ }
12367
+ chatId;
12368
+ credential = null;
12369
+ exhausted = /* @__PURE__ */ new Map();
12370
+ get method() {
12371
+ return this.credential?.type;
12372
+ }
12373
+ snapshot() {
12374
+ const credential = this.credential;
12375
+ if (!credential?.scope) return void 0;
12376
+ return {
12377
+ method: credential.type,
12378
+ scope: credential.scope,
12379
+ ...credential.revision ? { revision: credential.revision } : {},
12380
+ ...credential.account ? { account: credential.account } : {}
12381
+ };
12382
+ }
12383
+ /** The process env authenticated as this credential, without touching the workspace's. */
12384
+ env() {
12385
+ const env = { ...process.env, CLAUDE_CODE_OAUTH_TOKEN: void 0 };
12386
+ if (!this.credential) return env;
12387
+ for (const key of AUTH_SELECTOR_KEYS) env[key] = void 0;
12388
+ applyAuthEnvTransition({
12389
+ prevMethod: ENGINE_ENV.REPLICAS_CLAUDE_AUTH_METHOD ?? "none",
12390
+ authKeys: CLAUDE_AUTH_ENV_KEYS,
12391
+ authKeysByMethod: CLAUDE_AUTH_ENV_KEYS_BY_METHOD,
12392
+ newEnvVars: claudeAuthEnvFromResponse(this.credential),
12393
+ envs: [env]
12394
+ });
12395
+ if (this.credential.type === "oauth") env.CLAUDE_CODE_OAUTH_TOKEN = this.credential.accessToken;
12396
+ return env;
12397
+ }
12398
+ markExhausted(credential) {
12399
+ this.exhausted.set(`${credential.method}|${credential.scope}`, { credential, at: Date.now() });
12400
+ }
12401
+ async refresh() {
12402
+ const live = this.snapshot();
12403
+ const excludeCredentials = this.spent().filter((spent) => spent.method !== live?.method || spent.scope !== live?.scope);
12404
+ try {
12405
+ await this.request(excludeCredentials.length > 0 ? { excludeCredentials } : {});
12406
+ } catch (error) {
12407
+ if (!this.credential) throw error;
12408
+ console.warn(`[ChatClaudeCredentials] Keeping the current credential for chat ${this.chatId}:`, error);
12409
+ }
12410
+ }
12411
+ async fetchFreshCredentials(failureReason, failureKind, failedCredential = this.snapshot(), allowedMethods) {
12412
+ const failedMethod = this.credential?.type;
12413
+ const excludeCredentials = this.spent();
12414
+ try {
12415
+ await this.request({
12416
+ ...failedMethod ? { failedMethod } : {},
12417
+ ...failedCredential?.method === failedMethod ? { failedCredential } : {},
12418
+ failureReason,
12419
+ failureKind,
12420
+ ...excludeCredentials.length > 0 ? { excludeCredentials } : {},
12421
+ ...allowedMethods ? { allowedMethods: [...allowedMethods] } : {}
12422
+ });
12423
+ return createSuccessResult();
12424
+ } catch (error) {
12425
+ console.error(`[ChatClaudeCredentials] Failed to fetch fresh credentials for chat ${this.chatId}:`, error);
12426
+ return credentialSwapError(error);
12427
+ }
12428
+ }
12429
+ spent() {
12430
+ const cutoff = Date.now() - EXHAUSTED_RETRY_MS;
12431
+ return [...this.exhausted.values()].filter(({ at }) => at >= cutoff).map(({ credential }) => credential);
12432
+ }
12433
+ async request(body) {
12434
+ this.credential = await requestClaudeCredentials({ ...body, chatId: this.chatId });
12435
+ }
12436
+ };
12437
+
12352
12438
  // src/utils/linear-event-forwarder.ts
12353
12439
  function isLinearThoughtEvent(event) {
12354
12440
  return event.content.type === "thought";
@@ -13071,8 +13157,8 @@ function supportsClaudeThinkingDisplay(model) {
13071
13157
  const normalized = (normalizeClaudeModel(model) ?? model).toLowerCase();
13072
13158
  return AGENT_MODELS.claude.includes(normalized) || /^claude-(?:opus|sonnet|haiku)-[4-9]/.test(normalized);
13073
13159
  }
13074
- function toClaudeCodeModel(model) {
13075
- if (ENGINE_ENV.REPLICAS_CLAUDE_AUTH_METHOD !== "bedrock" && ENGINE_ENV.CLAUDE_CODE_USE_BEDROCK !== "1") {
13160
+ function toClaudeCodeModel(model, bedrock) {
13161
+ if (!bedrock) {
13076
13162
  return model;
13077
13163
  }
13078
13164
  switch (normalizeClaudeModel(model)) {
@@ -13086,6 +13172,8 @@ function toClaudeCodeModel(model) {
13086
13172
  return CLAUDE_OPUS_5_BEDROCK_MODEL;
13087
13173
  case CLAUDE_OPUS_4_8_MODEL:
13088
13174
  return "opus";
13175
+ case CLAUDE_SONNET_5_5_MODEL:
13176
+ return CLAUDE_SONNET_5_5_BEDROCK_MODEL;
13089
13177
  case CLAUDE_SONNET_5_MODEL:
13090
13178
  return "sonnet";
13091
13179
  case CLAUDE_HAIKU_4_5_MODEL:
@@ -13245,8 +13333,12 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13245
13333
  currentGoal = null;
13246
13334
  goalClear = null;
13247
13335
  lastRequest = null;
13336
+ chatId;
13337
+ chatCredentials = null;
13338
+ turnCredentials = null;
13248
13339
  constructor(options) {
13249
13340
  super({ ...options, provider: AGENT.CLAUDE });
13341
+ this.chatId = options.chatId;
13250
13342
  this.historyFilePath = options.historyFilePath ?? join16(homedir11(), ".replicas", "claude", "history.jsonl");
13251
13343
  this.historyFile = new CodexHistoryFile(this.historyFilePath);
13252
13344
  this.initializeManager(this.processMessageInternal.bind(this));
@@ -13543,8 +13635,10 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13543
13635
  await this.goalClear?.catch(() => {
13544
13636
  });
13545
13637
  try {
13638
+ this.turnCredentials = request.chatCredentials && this.chatId ? this.chatCredentials ??= new ChatClaudeCredentials(this.chatId) : null;
13639
+ await this.turnCredentials?.refresh();
13546
13640
  while (true) {
13547
- const attemptedCredential = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.claude;
13641
+ const attemptedCredential = this.turnCredentials ? this.turnCredentials.snapshot() : ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.claude;
13548
13642
  try {
13549
13643
  await this.executeQuery(currentRequest, { skipUserMessageRecord: attempt > 0 });
13550
13644
  return;
@@ -13553,7 +13647,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13553
13647
  const quotaKind = _ClaudeManager.quotaLimitKind(error);
13554
13648
  if (quotaKind) {
13555
13649
  const detail = error instanceof ClaudeQuotaError ? error.message : extractErrorText(error);
13556
- const fallback = quotaFallbacks < MAX_QUOTA_FALLBACKS ? await this.fallBackCredential(quotaKind, detail) : { outcome: "unavailable" };
13650
+ const fallback = quotaFallbacks < MAX_QUOTA_FALLBACKS ? await this.fallBackCredential(quotaKind, detail, this.turnCredentials ?? void 0) : { outcome: "unavailable" };
13557
13651
  if (fallback.outcome === "switched") {
13558
13652
  quotaFallbacks++;
13559
13653
  await this.tearDownSession();
@@ -13574,7 +13668,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13574
13668
  error
13575
13669
  );
13576
13670
  this.setAuthRetrying(true);
13577
- const refreshed = await claudeTokenManager.fetchFreshCredentials(
13671
+ const refreshed = await (this.turnCredentials ?? claudeTokenManager).fetchFreshCredentials(
13578
13672
  error instanceof Error ? error.message : String(error),
13579
13673
  "rejected",
13580
13674
  attemptedCredential
@@ -13657,8 +13751,11 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13657
13751
  [this.claudeAuthFailureMessage()]
13658
13752
  );
13659
13753
  }
13754
+ claudeAuthMethod() {
13755
+ return this.turnCredentials ? this.turnCredentials.method ?? "unknown" : resolveClaudeAuthMethodForMessage();
13756
+ }
13660
13757
  claudeAuthFailureMessage() {
13661
- switch (resolveClaudeAuthMethodForMessage()) {
13758
+ switch (this.claudeAuthMethod()) {
13662
13759
  case "oauth":
13663
13760
  return "Claude Code OAuth authentication failed after refreshing credentials. Reconnect Claude Code in Settings \u2192 Agents and try again.";
13664
13761
  case "api_key":
@@ -13726,12 +13823,13 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13726
13823
  this.buildCombinedInstructions(customInstructions, true),
13727
13824
  "Background tasks must have a concrete completion condition. Use foreground commands for sequential work and managed workspace services for servers. Reserve persistent Monitor tasks for ongoing watches the user requested. You may end a turn while actual background work continues, but do not promise a later update unless a task was successfully launched. Report completion or failure when its notification arrives; do not restart timed-out work automatically."
13728
13825
  ].filter(Boolean).join("\n\n");
13729
- const resolvedModel = normalizeClaudeModel(model) || (ENGINE_ENV.REPLICAS_CLAUDE_AUTH_METHOD === "ollama" ? DEFAULT_OLLAMA_MODEL : void 0) || DEFAULT_CLAUDE_MODEL;
13730
- const claudeCodeModel = toClaudeCodeModel(resolvedModel);
13826
+ const resolvedModel = normalizeClaudeModel(model) || (this.claudeAuthMethod() === "ollama" ? DEFAULT_OLLAMA_MODEL : void 0) || DEFAULT_CLAUDE_MODEL;
13827
+ const claudeCodeModel = toClaudeCodeModel(resolvedModel, this.turnCredentials ? this.turnCredentials.method === "bedrock" : ENGINE_ENV.REPLICAS_CLAUDE_AUTH_METHOD === "bedrock" || ENGINE_ENV.CLAUDE_CODE_USE_BEDROCK === "1");
13731
13828
  const resolvedPermissionMode = planMode ? "plan" : "bypassPermissions";
13732
13829
  const resolvedFastMode = Boolean(fastMode && canUseClaudeFastMode(resolvedModel));
13733
13830
  const signature = {
13734
- credential: JSON.stringify(ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.claude),
13831
+ // Prefixed so a session never carries one side's auth env over to the other.
13832
+ credential: this.turnCredentials ? `chat:${JSON.stringify(this.turnCredentials.snapshot())}` : JSON.stringify(ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.claude),
13735
13833
  combinedInstructions,
13736
13834
  thinkingLevel,
13737
13835
  enableInteractiveTools: Boolean(enableInteractiveTools),
@@ -13831,7 +13929,10 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13831
13929
  }
13832
13930
  /** Query inputs shared by real sessions and slash-command discovery. */
13833
13931
  async buildSharedQueryOptions() {
13834
- const env = buildClaudeAgentEnv(this.isRelay ? { CLAUDE_CODE_STREAM_CLOSE_TIMEOUT: "900000" } : void 0);
13932
+ const env = buildClaudeAgentEnv(
13933
+ this.isRelay ? { CLAUDE_CODE_STREAM_CLOSE_TIMEOUT: "900000" } : void 0,
13934
+ this.turnCredentials?.env()
13935
+ );
13835
13936
  const additionalDirectories = await getAgentAdditionalDirectories();
13836
13937
  let plugins = [];
13837
13938
  let enableAllSkills = false;
@@ -13891,7 +13992,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13891
13992
  ...shared.enableAllSkills ? { skills: "all" } : {},
13892
13993
  env: {
13893
13994
  ...shared.env,
13894
- ...ENGINE_ENV.REPLICAS_CLAUDE_AUTH_METHOD === "ollama" ? {
13995
+ ...this.claudeAuthMethod() === "ollama" ? {
13895
13996
  ANTHROPIC_DEFAULT_SONNET_MODEL: resolvedModel,
13896
13997
  ANTHROPIC_DEFAULT_OPUS_MODEL: resolvedModel,
13897
13998
  ANTHROPIC_DEFAULT_HAIKU_MODEL: resolvedModel
@@ -61407,6 +61508,7 @@ var ChatService = class {
61407
61508
  onMessageStarted,
61408
61509
  onUsageUpdate: onProviderUsage,
61409
61510
  fallbackContext,
61511
+ chatId: persisted.id,
61410
61512
  additionalInstructions,
61411
61513
  linearSessionId: persisted.parentChatId === null ? ENGINE_ENV.REPLICAS_LINEAR_SESSION_ID : void 0,
61412
61514
  ...persisted.provider === "relay" ? { relayParentChatId: persisted.id } : {}
@@ -3,13 +3,13 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  publishedPullRequestUrls
6
- } from "./chunk-2J5TLHIA.js";
6
+ } from "./chunk-4Q7E2QOZ.js";
7
7
  import {
8
8
  isRecord
9
9
  } from "./chunk-UZSNFLDQ.js";
10
10
  import {
11
11
  shouldRefreshPullRequests
12
- } from "./chunk-VT557AFP.js";
12
+ } from "./chunk-RLBC7EZ4.js";
13
13
  import "./chunk-VEQXQN22.js";
14
14
 
15
15
  // src/services/post-tool-pr-notifier.ts
@@ -11,7 +11,7 @@ import {
11
11
  relaySubagentResponseSchema,
12
12
  spawnRelaySubagentRequestSchema,
13
13
  waitRelaySubagentRequestSchema
14
- } from "./chunk-VT557AFP.js";
14
+ } from "./chunk-RLBC7EZ4.js";
15
15
  import "./chunk-VEQXQN22.js";
16
16
 
17
17
  // src/relay-mcp.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.923",
3
+ "version": "0.1.925",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",
@@ -39,7 +39,7 @@
39
39
  "author": "Replicas",
40
40
  "license": "MIT",
41
41
  "dependencies": {
42
- "@anthropic-ai/claude-agent-sdk": "0.3.280",
42
+ "@anthropic-ai/claude-agent-sdk": "0.3.284",
43
43
  "@anthropic-ai/sdk": "0.128.0",
44
44
  "@connectrpc/connect-node": "1.7.0",
45
45
  "@cursor/sdk": "1.0.19",