@mastra/code-sdk 1.10.2-alpha.0 → 1.11.0-alpha.10

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.
Files changed (67) hide show
  1. package/dist/acp/agent.d.ts +3 -3
  2. package/dist/acp/agent.d.ts.map +1 -1
  3. package/dist/acp/agent.js +95 -22
  4. package/dist/acp/agent.js.map +1 -1
  5. package/dist/acp/runtime.d.ts.map +1 -1
  6. package/dist/acp/runtime.js +18 -10
  7. package/dist/acp/runtime.js.map +1 -1
  8. package/dist/agents/memory.d.ts +3 -1
  9. package/dist/agents/memory.d.ts.map +1 -1
  10. package/dist/agents/memory.js +34 -23
  11. package/dist/agents/memory.js.map +1 -1
  12. package/dist/agents/model.d.ts +4 -39
  13. package/dist/agents/model.d.ts.map +1 -1
  14. package/dist/agents/model.js +31 -93
  15. package/dist/agents/model.js.map +1 -1
  16. package/dist/agents/prompts/agent-instructions.js +1 -1
  17. package/dist/auth/account-rotation-processor.d.ts +26 -54
  18. package/dist/auth/account-rotation-processor.d.ts.map +1 -1
  19. package/dist/auth/account-rotation-processor.js +105 -154
  20. package/dist/auth/account-rotation-processor.js.map +1 -1
  21. package/dist/auth/index.js +2 -2
  22. package/dist/auth/providers/kimi-coding.js +2 -1
  23. package/dist/auth/providers/kimi-coding.js.map +1 -1
  24. package/dist/auth/providers/xai.js +2 -1
  25. package/dist/auth/providers/xai.js.map +1 -1
  26. package/dist/auth/storage.js +1 -1
  27. package/dist/auth/types.d.ts +1 -0
  28. package/dist/auth/types.d.ts.map +1 -1
  29. package/dist/clipboard/index.js +1 -1
  30. package/dist/constants.d.ts +2 -0
  31. package/dist/constants.d.ts.map +1 -1
  32. package/dist/constants.js +3 -1
  33. package/dist/constants.js.map +1 -1
  34. package/dist/headless/cli.d.ts.map +1 -1
  35. package/dist/headless/cli.js +9 -4
  36. package/dist/headless/cli.js.map +1 -1
  37. package/dist/headless/run-mc.d.ts.map +1 -1
  38. package/dist/headless/run-mc.js +46 -42
  39. package/dist/headless/run-mc.js.map +1 -1
  40. package/dist/index.d.ts +5 -5
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +33 -28
  43. package/dist/index.js.map +1 -1
  44. package/dist/lsp/server.js +1 -1
  45. package/dist/onboarding/om-settings.d.ts +1 -0
  46. package/dist/onboarding/om-settings.d.ts.map +1 -1
  47. package/dist/onboarding/om-settings.js +10 -1
  48. package/dist/onboarding/om-settings.js.map +1 -1
  49. package/dist/onboarding/settings.js +2 -2
  50. package/dist/providers/openai-codex.js +1 -1
  51. package/dist/schedules/run-script.js +1 -1
  52. package/dist/schema.d.ts +34 -19
  53. package/dist/schema.d.ts.map +1 -1
  54. package/dist/schema.js +11 -5
  55. package/dist/schema.js.map +1 -1
  56. package/dist/utils/open-url.d.ts +10 -0
  57. package/dist/utils/open-url.d.ts.map +1 -0
  58. package/dist/utils/open-url.js +30 -0
  59. package/dist/utils/open-url.js.map +1 -0
  60. package/dist/utils/project.js +2 -2
  61. package/dist/utils/signals-pubsub.d.ts +32 -4
  62. package/dist/utils/signals-pubsub.d.ts.map +1 -1
  63. package/dist/utils/signals-pubsub.js +207 -28
  64. package/dist/utils/signals-pubsub.js.map +1 -1
  65. package/dist/utils/slash-command-processor.js +1 -1
  66. package/dist/utils/update-check.js +1 -1
  67. package/package.json +10 -10
@@ -1 +1 @@
1
- {"version":3,"file":"account-rotation-processor.d.ts","sourceRoot":"","sources":["../../src/auth/account-rotation-processor.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAcpH,OAAO,KAAK,EAAE,eAAe,EAAsB,MAAM,YAAY,CAAC;AAEtE,eAAO,MAAM,wBAAwB,mCAAmC,CAAC;AAEzE,yEAAyE;AACzE,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE;QAAE,E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C,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAgDxE"}
1
+ {"version":3,"file":"account-rotation-processor.d.ts","sourceRoot":"","sources":["../../src/auth/account-rotation-processor.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAYpH,OAAO,KAAK,EAAE,eAAe,EAAsB,MAAM,YAAY,CAAC;AAEtE,eAAO,MAAM,wBAAwB,mCAAmC,CAAC;AAEzE,yEAAyE;AACzE,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC3C,EAAE,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACzC,MAAM,EACF,YAAY,GACZ,iBAAiB,GACjB,aAAa,GACb,gBAAgB,GAChB,mBAAmB,GACnB,mBAAmB,GACnB,qBAAqB,CAAC;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,iFAAiF;AACjF,MAAM,MAAM,uBAAuB,GAAG,eAAe,GAAG;IACtD;;;;;;OAMG;IACH,yBAAyB,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,iBAAiB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CACzG,CAAC;AA0CF,sDAAsD;AACtD,eAAO,MAAM,wBAAwB,EAAG,gCAAyC,CAAC;AAElF,2DAA2D;AAC3D,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,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A;KAAE,CAAC;IAsI7E;;;;OAIG;YACW,oBAAoB;IAuElC;;;;;;;;;OASG;YACW,YAAY;IAQ1B,0EAA0E;YAC5D,qBAAqB;IAqDnC;;;;;;OAMG;YACW,sBAAsB;CAiCrC;AAED;;;;;;;;GAQG;AACH,qBAAa,2BAA4B,YAAW,SAAS;IAG/C,OAAO,CAAC,QAAQ,CAAC,OAAO;IAFpC,QAAQ,CAAC,EAAE,EAAG,iCAAiC,CAAU;gBAE5B,OAAO,EAAE;QAAE,eAAe,EAAE,eAAe,CAAA;KAAE;IAEpE,YAAY,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAgDxE"}
@@ -1,10 +1,8 @@
1
1
  import { getOAuthProviders } from "./storage.js";
2
2
  import { ProviderAuthRequiredError } from "./provider-auth-error.js";
3
- import { resolveModePackFallbackChain } from "../onboarding/packs.js";
4
- import { findModePackForModel, loadSettings, resolveModePackModels } from "../onboarding/settings.js";
5
3
  import { resolveCredentialStore } from "../agents/credential-resolver.js";
6
4
  import { getRequestAccountSelection, isRequestAccountRoutingExhausted, markRequestAccountRoutingExhausted, setRequestAccountSelection } from "./account-routing-context.js";
7
- import { listResolvableModePacks, resolveModel, resolveRequestThinkingLevel } from "../agents/model.js";
5
+ import { resolveModel, resolveRequestThinkingLevel } from "../agents/model.js";
8
6
  import { TripWire } from "@mastra/core/agent";
9
7
  //#region src/auth/account-rotation-processor.ts
10
8
  /**
@@ -61,14 +59,10 @@ const NETWORK_ERROR_CODES = /* @__PURE__ */ new Set([
61
59
  ]);
62
60
  const NETWORK_MESSAGE_PATTERN = /fetch failed|network error|socket hang up|getaddrinfo|econnrefused|enotfound|etimedout|connection (?:refused|reset|closed|timed out)|other side closed|write epipe/i;
63
61
  const MAX_CAUSE_DEPTH = 4;
64
- /** Persisted data-part type for a fallback-pack hop. */
65
- const PACK_FALLBACK_PART_TYPE = "data-mastracode-pack-fallback";
66
- /**
67
- * Session-state key the processor sets when a pack hop happens. The TUI
68
- * listens for it on the typed `state_changed` controller event (data parts
69
- * never ride controller message events) and applies thread stickiness.
70
- */
71
- const PACK_FALLBACK_STATE_KEY = "mastracodePendingPackFallback";
62
+ /** Persisted data-part type for a model-route hop. */
63
+ const MODEL_FALLBACK_PART_TYPE = "data-mastracode-model-fallback";
64
+ /** Session-state key set when account rotation advances the model route. */
65
+ const MODEL_FALLBACK_STATE_KEY = "mastracodePendingModelFallback";
72
66
  function isErrorWithCode(error) {
73
67
  return typeof error === "object" && error !== null && "code" in error;
74
68
  }
@@ -246,19 +240,19 @@ function accountSwitchNoticeText(data) {
246
240
  }
247
241
  return `Switched ${provider} account: ${data.from?.label ?? "unknown"} → ${data.to.label} (${reason})`;
248
242
  }
249
- /** Transcript line for a pack-fallback hop; shared by the live info event and the TUI's history render. */
250
- function packFallbackNoticeText(data) {
243
+ /** Transcript line for a model-route hop; shared by the live info event and the TUI's history render. */
244
+ function modelFallbackNoticeText(data) {
251
245
  const reason = REASON_TEXT[data.reason] ?? data.reason;
252
- return `Switched model pack: ${data.from.label} → ${data.to.label} (${reason})`;
246
+ return `Switched model route: ${data.from.label} → ${data.to.label} (${reason})`;
253
247
  }
254
248
  /**
255
- * Whether a persisted pack-fallback reason is one this build understands.
249
+ * Whether a persisted model-fallback reason is one this build understands.
256
250
  * `REASON_TEXT` also covers the account-switch reasons, so the notice text
257
251
  * alone would happily render a foreign value such as `rate-limit` as a
258
- * pack-fallback reason; history parsed from another build's part must be
252
+ * model-fallback reason; history parsed from another build's part must be
259
253
  * rejected instead.
260
254
  */
261
- function isPackFallbackReason(value) {
255
+ function isModelFallbackReason(value) {
262
256
  return value === "pool-exhausted" || value === "persistent-outage";
263
257
  }
264
258
  async function emitAccountSwitchPart(args, data) {
@@ -284,19 +278,9 @@ function providerFromSession(args) {
284
278
  function getRoutingController(args) {
285
279
  return args.requestContext?.get("controller");
286
280
  }
287
- /**
288
- * A12: the account a pack/model route targets, or `undefined` when the route
289
- * is `Automatic` (no entry — insertion order, full pool rotation).
290
- *
291
- * A targeted route is *exclusive*: only that account may serve the route, so
292
- * rotation must never spill the request onto a sibling subscription's quota.
293
- * A heavy model on one subscription can burn that subscription's quota in
294
- * hours; spilling it into a second subscription defeats the point of having
295
- * one.
296
- */
297
- function getRouteTargetAccountId(settingsPath, route) {
298
- if (!route) return void 0;
299
- return loadSettings(settingsPath).models.packAccountPreferences?.[route.packId]?.[route.modelId];
281
+ /** A targeted route is exclusive; an entry without accountId uses automatic pool rotation. */
282
+ function getRouteTargetAccountId(route) {
283
+ return route?.accountId;
300
284
  }
301
285
  function getRequestActiveAccount(args, store, providerId) {
302
286
  if (isRequestAccountRoutingExhausted(args.requestContext, providerId)) return void 0;
@@ -304,26 +288,22 @@ function getRequestActiveAccount(args, store, providerId) {
304
288
  if (selectedId) return store.listAccounts?.(providerId).find((account) => account.id === selectedId);
305
289
  return store.getActiveAccount?.(providerId) ?? store.listAccounts?.(providerId).find((account) => account.active);
306
290
  }
307
- function resolveAccountRoute(args, settingsPath, explicit) {
291
+ function resolveAccountRoute(args, explicit) {
308
292
  const controller = getRoutingController(args);
309
293
  const state = controller?.getState?.();
310
- const pending = state?.mastracodePendingPackFallback;
311
- const pendingMatchesThread = pending && typeof pending.toPackId === "string" && typeof pending.toModelId === "string" && (pending.threadId === void 0 || pending.threadId === controller?.threadId);
312
- const resolvedModelId = explicit?.modelId ?? (pendingMatchesThread ? pending.toModelId : void 0) ?? (typeof controller?.session?.modelId === "string" ? controller.session.modelId : void 0);
313
- if (typeof resolvedModelId !== "string" || resolvedModelId.length === 0) return null;
314
- const modelId = resolvedModelId;
315
- const settings = loadSettings(settingsPath);
316
- const packs = listResolvableModePacks(settings);
317
- const modeId = typeof controller?.session?.modeId === "string" && controller.session.modeId.length > 0 ? controller.session.modeId : "build";
318
- const explicitPackId = explicit?.packId ?? (pendingMatchesThread ? pending.toPackId : void 0) ?? (typeof state?.activeModelPackId === "string" ? state.activeModelPackId : settings.models.activeModelPackId);
319
- const pack = explicitPackId ? packs.find((candidate) => candidate.id === explicitPackId) : findModePackForModel(settings, packs, modelId, modeId, void 0);
320
- if (!pack || resolveModePackModels(settings, pack)[modeId] !== modelId) return null;
321
- const providerId = providerFromModelId(modelId);
322
- return providerId ? {
323
- packId: pack.id,
324
- modelId,
325
- providerId
326
- } : null;
294
+ const pending = state?.mastracodePendingModelFallback;
295
+ const pendingMatchesThread = pending && typeof pending.toEntryId === "string" && typeof pending.toModelId === "string" && (pending.threadId === void 0 || pending.threadId === controller?.threadId);
296
+ const routeEntries = Array.isArray((state?.modelRoute)?.entries) ? (state?.modelRoute).entries ?? [] : [];
297
+ const entry = explicit ? explicit : pendingMatchesThread ? routeEntries.find((candidate) => candidate.id === pending.toEntryId && candidate.modelId === pending.toModelId) : routeEntries.find((candidate) => candidate.modelId === controller?.session?.modelId);
298
+ if (!entry || typeof entry.id !== "string" || typeof entry.modelId !== "string") return null;
299
+ const providerId = providerFromModelId(entry.modelId);
300
+ if (!providerId) return null;
301
+ return {
302
+ entryId: entry.id,
303
+ modelId: entry.modelId,
304
+ providerId,
305
+ ...typeof entry.accountId === "string" ? { accountId: entry.accountId } : {}
306
+ };
327
307
  }
328
308
  /**
329
309
  * A14: `Automatic` rotation starts *at* the persisted active account and walks
@@ -338,9 +318,9 @@ function orderAccountsFromActive(accounts, activeId) {
338
318
  if (index <= 0) return accounts;
339
319
  return [...accounts.slice(index), ...accounts.slice(0, index)];
340
320
  }
341
- async function applyPreferredAccountRoute(args, store, settingsPath, route) {
321
+ async function applyPreferredAccountRoute(args, store, route) {
342
322
  store.reload();
343
- const preferredId = getRouteTargetAccountId(settingsPath, route);
323
+ const preferredId = getRouteTargetAccountId(route);
344
324
  const accounts = store.listAccounts?.(route.providerId) ?? [];
345
325
  if (accounts.length === 0 && preferredId === void 0) return false;
346
326
  const tried = getTriedInstances(args.state);
@@ -394,22 +374,18 @@ var AccountRotationProcessor = class {
394
374
  await this.gateChainHop(args, error);
395
375
  return { retry: false };
396
376
  }
397
- const cascade = await this.getPackCascade(args);
398
- const currentPack = cascade?.packs[cascade.position];
399
- const cascadeModelId = currentPack ? cascade.models[currentPack.packId]?.[cascade.modeId] : void 0;
400
- const providerId = providerFromError(error) ?? (typeof cascadeModelId === "string" ? providerFromModelId(cascadeModelId) : void 0) ?? (cascade ? void 0 : providerFromSession(args));
377
+ const cascade = await this.getModelRouteCascade(args);
378
+ const currentEntry = cascade?.entries[cascade.position];
379
+ const providerId = providerFromError(error) ?? (currentEntry ? providerFromModelId(currentEntry.modelId) : void 0) ?? (cascade ? void 0 : providerFromSession(args));
401
380
  if (!providerId) {
402
- await this.emitPackFallbackPart(args, classification.kind === "hop" ? "persistent-outage" : "pool-exhausted");
381
+ await this.emitModelFallbackPart(args, classification.kind === "hop" ? "persistent-outage" : "pool-exhausted");
403
382
  return { retry: false };
404
383
  }
405
384
  const store = resolveCredentialStore(args.requestContext) ?? this.options.credentialStore;
406
385
  store.reload();
407
386
  const accounts = store.listAccounts?.(providerId) ?? [];
408
387
  const active = getRequestActiveAccount(args, store, providerId);
409
- const route = currentPack && typeof cascadeModelId === "string" ? resolveAccountRoute(args, this.options.settingsPath, {
410
- packId: currentPack.packId,
411
- modelId: cascadeModelId
412
- }) : resolveAccountRoute(args, this.options.settingsPath);
388
+ const route = currentEntry ? resolveAccountRoute(args, currentEntry) : resolveAccountRoute(args);
413
389
  if (classification.kind === "rotate" && classification.reason === "auth-failed" && active) {
414
390
  const forced = getForcedRefreshInstances(state);
415
391
  const refreshKey = `${providerId}:${active?.id ?? "active"}`;
@@ -418,7 +394,7 @@ var AccountRotationProcessor = class {
418
394
  if (await store.forceRefreshActiveAccount(providerId, active?.id) !== void 0) return { retry: true };
419
395
  }
420
396
  }
421
- const targetAccountId = route?.providerId === providerId ? getRouteTargetAccountId(this.options.settingsPath, route) : void 0;
397
+ const targetAccountId = route?.providerId === providerId ? getRouteTargetAccountId(route) : void 0;
422
398
  if (classification.kind === "hop") return this.declarePoolUnavailable(args, providerId, "persistent-outage", targetAccountId !== void 0);
423
399
  if (targetAccountId !== void 0) return this.declarePoolUnavailable(args, providerId, "pool-exhausted", true);
424
400
  const tried = getTriedInstances(state);
@@ -446,78 +422,59 @@ var AccountRotationProcessor = class {
446
422
  return { retry: true };
447
423
  }
448
424
  /**
449
- * The request's pack cascade, computed once from the session's pack and
450
- * cached in processor state. Truncated at the first pack that lacks the
451
- * session mode's model — mirroring getDynamicModel's truncation — so the
452
- * cascade never promises a hop core's fallback array cannot make. The
453
- * position advances per hop, so a second hop in the same turn reports B→C
454
- * even though the session modelId still points at pack A (stickiness lands
455
- * TUI-side only after the part renders). Returns null when the session has
456
- * no active pack or the pack has no fallback chain.
425
+ * Resolve the request's host-supplied model route once and cache the reachable
426
+ * prefix in processor state. Resolution mirrors getDynamicModel so a hop is
427
+ * never announced for an entry core cannot reach.
457
428
  */
458
- async getPackCascade(args) {
459
- if (args.state.packCascade !== void 0) return args.state.packCascade ?? null;
460
- const controller = args.requestContext?.get("controller");
461
- const modelId = controller?.session?.modelId;
462
- if (typeof modelId !== "string" || modelId.length === 0) {
463
- args.state.packCascade = null;
429
+ async getModelRouteCascade(args) {
430
+ if (args.state.modelRouteCascade !== void 0) return args.state.modelRouteCascade ?? null;
431
+ const controller = getRoutingController(args);
432
+ const state = controller?.getState?.();
433
+ const route = (state?.modelRoute)?.entries;
434
+ const pending = state?.mastracodePendingModelFallback;
435
+ const startIndex = pending && typeof pending.toEntryId === "string" && (pending.threadId === void 0 || pending.threadId === controller?.threadId) ? route?.findIndex((entry) => entry.id === pending.toEntryId) : route?.findIndex((entry) => entry.modelId === controller?.session?.modelId);
436
+ if (!route || startIndex === void 0 || startIndex < 0 || route.length - startIndex < 2) {
437
+ args.state.modelRouteCascade = null;
464
438
  return null;
465
439
  }
466
- const modeId = typeof controller?.session?.modeId === "string" && controller.session.modeId.length > 0 ? controller.session.modeId : "build";
467
- const settings = loadSettings(this.options.settingsPath);
468
- const packs = listResolvableModePacks(settings);
469
- const controllerState = controller?.getState?.();
470
- const statePackId = controllerState?.activeModelPackId ?? settings.models.activeModelPackId;
471
- const activePack = findModePackForModel(settings, packs, modelId, modeId, typeof statePackId === "string" ? statePackId : void 0);
472
- const chain = activePack ? resolveModePackFallbackChain(settings.models.packFallbacks ?? {}, activePack.id, settings.customModelPacks) : [];
473
- if (chain.length < 2) {
474
- args.state.packCascade = null;
475
- return null;
476
- }
477
- const resolvedPacks = [];
478
- const models = {};
479
- for (const packId of chain) {
480
- const pack = packs.find((candidate) => candidate.id === packId);
481
- const packModels = pack ? resolveModePackModels(settings, pack) : {};
482
- if (resolvedPacks.length > 0) {
483
- const entryModelId = packModels[modeId];
484
- if (!entryModelId) break;
485
- try {
486
- resolveModel(entryModelId, {
487
- thinkingLevel: resolveRequestThinkingLevel({
488
- state: { thinkingLevel: controllerState?.thinkingLevel },
489
- session: { modeId }
490
- }, this.options.settingsPath),
491
- remapForCodexOAuth: true,
492
- requestContext: args.requestContext
493
- });
494
- } catch {
495
- break;
496
- }
440
+ const thinkingLevel = resolveRequestThinkingLevel({
441
+ state: { thinkingLevel: state?.thinkingLevel },
442
+ session: { modeId: typeof controller?.session?.modeId === "string" ? controller.session.modeId : "build" }
443
+ }, this.options.settingsPath);
444
+ const entries = [];
445
+ for (const entry of route.slice(startIndex)) {
446
+ if (typeof entry.id !== "string" || entry.id.length === 0 || typeof entry.modelId !== "string" || entry.modelId.length === 0) break;
447
+ if (entries.length > 0) try {
448
+ resolveModel(entry.modelId, {
449
+ thinkingLevel,
450
+ remapForCodexOAuth: true,
451
+ requestContext: args.requestContext
452
+ });
453
+ } catch {
454
+ break;
497
455
  }
498
- resolvedPacks.push({
499
- packId,
500
- label: pack?.name ?? packId
456
+ entries.push({
457
+ id: entry.id,
458
+ label: typeof entry.label === "string" && entry.label.length > 0 ? entry.label : entry.id,
459
+ modelId: entry.modelId,
460
+ ...typeof entry.accountId === "string" ? { accountId: entry.accountId } : {}
501
461
  });
502
- models[packId] = packModels;
503
462
  }
504
- if (resolvedPacks.length < 2) {
505
- args.state.packCascade = null;
463
+ if (entries.length < 2) {
464
+ args.state.modelRouteCascade = null;
506
465
  return null;
507
466
  }
508
467
  const cascade = {
509
- packs: resolvedPacks,
510
- models,
511
- modeId,
468
+ entries,
512
469
  position: 0
513
470
  };
514
- args.state.packCascade = cascade;
471
+ args.state.modelRouteCascade = cascade;
515
472
  return cascade;
516
473
  }
517
474
  /**
518
- * Q14 gate: 400/unknown/unattributable errors never hop packs. Core's
475
+ * Q14 gate: 400/unknown/unattributable errors never advance routes. Core's
519
476
  * fallback array advances on ANY thrown error except TripWire
520
- * (llm-execution-step.ts), so when the session's pack has a chain and the
477
+ * (llm-execution-step.ts), so when the session route has another entry and the
521
478
  * current entry is non-last, a bare `retry: false` would silently hop on an
522
479
  * error class the user excluded from hop triggers. TripWire is the only
523
480
  * no-advance escape: the runner rethrows it and the fallback loop declines
@@ -525,77 +482,71 @@ var AccountRotationProcessor = class {
525
482
  * plain `retry: false` surface the error exactly as before.
526
483
  */
527
484
  async gateChainHop(args, error) {
528
- const cascade = await this.getPackCascade(args);
485
+ const cascade = await this.getModelRouteCascade(args);
529
486
  if (!cascade) return;
530
- if (cascade.position >= cascade.packs.length - 1) return;
487
+ if (cascade.position >= cascade.entries.length - 1) return;
531
488
  throw new TripWire(error instanceof Error ? error.message : String(error), {}, this.id);
532
489
  }
533
- /**
534
- * Emit the pack-fallback part when a configured chain has a next pack and
535
- * queue the thread stickiness trigger. Core's fallback array does the hop
536
- * itself on `retry: false`; this only announces it. The cascade is
537
- * truncated exactly like getDynamicModel's chain (missing mode model or
538
- * unresolvable model), so an announced hop is always one core can make;
539
- * the toModelId guard stays as defense against a stale cache.
540
- */
541
- async emitPackFallbackPart(args, reason) {
542
- const cascade = await this.getPackCascade(args);
490
+ /** Announce and persist the next model-route hop before core advances. */
491
+ async emitModelFallbackPart(args, reason) {
492
+ const cascade = await this.getModelRouteCascade(args);
543
493
  if (!cascade) return;
544
- const from = cascade.packs[cascade.position];
545
- const to = cascade.packs[cascade.position + 1];
494
+ const from = cascade.entries[cascade.position];
495
+ const to = cascade.entries[cascade.position + 1];
546
496
  if (!from || !to) return;
547
- const toModelId = cascade.models[to.packId]?.[cascade.modeId];
548
- if (!toModelId) return;
549
497
  const controller = args.requestContext?.get("controller");
550
498
  const at = (/* @__PURE__ */ new Date()).toISOString();
551
499
  const threadId = typeof controller?.threadId === "string" ? controller.threadId : void 0;
552
500
  const pending = {
553
- fromPackId: from.packId,
554
- toPackId: to.packId,
555
- toModelId,
501
+ fromEntryId: from.id,
502
+ toEntryId: to.id,
503
+ toModelId: to.modelId,
556
504
  ...threadId ? { threadId } : {},
557
505
  reason,
558
506
  at
559
507
  };
560
508
  await controller?.setThreadSetting?.({
561
- key: PACK_FALLBACK_STATE_KEY,
509
+ key: MODEL_FALLBACK_STATE_KEY,
562
510
  value: pending
563
511
  });
564
512
  const data = {
565
- from,
566
- to,
513
+ from: {
514
+ entryId: from.id,
515
+ label: from.label
516
+ },
517
+ to: {
518
+ entryId: to.id,
519
+ label: to.label
520
+ },
567
521
  reason,
568
522
  at
569
523
  };
570
524
  try {
571
525
  await args.writer?.custom({
572
- type: PACK_FALLBACK_PART_TYPE,
526
+ type: MODEL_FALLBACK_PART_TYPE,
573
527
  data
574
528
  });
575
529
  } catch (error) {
576
530
  await controller?.setThreadSetting?.({
577
- key: PACK_FALLBACK_STATE_KEY,
531
+ key: MODEL_FALLBACK_STATE_KEY,
578
532
  value: void 0
579
533
  });
580
534
  throw error;
581
535
  }
582
- await controller?.setState?.({ [PACK_FALLBACK_STATE_KEY]: pending });
536
+ await controller?.setState?.({ [MODEL_FALLBACK_STATE_KEY]: pending });
583
537
  args.state.startNoticeEmitted = false;
584
- const targetRoute = resolveAccountRoute(args, this.options.settingsPath, {
585
- packId: to.packId,
586
- modelId: toModelId
587
- });
588
- if (targetRoute) await applyPreferredAccountRoute(args, resolveCredentialStore(args.requestContext) ?? this.options.credentialStore, this.options.settingsPath, targetRoute).catch(() => void 0);
538
+ const targetRoute = resolveAccountRoute(args, to);
539
+ if (targetRoute) await applyPreferredAccountRoute(args, resolveCredentialStore(args.requestContext) ?? this.options.credentialStore, targetRoute).catch(() => void 0);
589
540
  controller?.emitEvent?.({
590
541
  type: "info",
591
- message: packFallbackNoticeText(data)
542
+ message: modelFallbackNoticeText(data)
592
543
  });
593
544
  cascade.position++;
594
545
  }
595
546
  /**
596
547
  * Pool done for this request: every instance recorded in the tried-set and
597
548
  * a `to: null` part emitted. Returns `retry: false` so core's fallback
598
- * array can hop to the next pack (announced by `emitPackFallbackPart`).
549
+ * array can hop to the next route entry (announced by `emitModelFallbackPart`).
599
550
  * Silent on the account part when the provider has no registry at all —
600
551
  * there are no accounts to declare unavailable, but the hop still applies.
601
552
  */
@@ -603,7 +554,7 @@ var AccountRotationProcessor = class {
603
554
  const store = resolveCredentialStore(args.requestContext) ?? this.options.credentialStore;
604
555
  const accounts = store.listAccounts?.(providerId) ?? [];
605
556
  if (accounts.length === 0) {
606
- await this.emitPackFallbackPart(args, reason);
557
+ await this.emitModelFallbackPart(args, reason);
607
558
  return { retry: false };
608
559
  }
609
560
  const tried = getTriedInstances(args.state);
@@ -620,7 +571,7 @@ var AccountRotationProcessor = class {
620
571
  at: (/* @__PURE__ */ new Date()).toISOString(),
621
572
  ...exclusive ? { exclusive: true } : {}
622
573
  });
623
- await this.emitPackFallbackPart(args, reason);
574
+ await this.emitModelFallbackPart(args, reason);
624
575
  return { retry: false };
625
576
  }
626
577
  };
@@ -642,9 +593,9 @@ var AccountStartNoticeProcessor = class {
642
593
  async processInput(args) {
643
594
  if (args.state.startNoticeEmitted) return args.messageList;
644
595
  const store = resolveCredentialStore(args.requestContext) ?? this.options.credentialStore;
645
- const route = resolveAccountRoute(args, this.options.settingsPath);
596
+ const route = resolveAccountRoute(args);
646
597
  if (route) {
647
- if (await applyPreferredAccountRoute(args, store, this.options.settingsPath, route) || getRouteTargetAccountId(this.options.settingsPath, route) !== void 0) {
598
+ if (await applyPreferredAccountRoute(args, store, route) || getRouteTargetAccountId(route) !== void 0) {
648
599
  args.state.startNoticeEmitted = true;
649
600
  return args.messageList;
650
601
  }
@@ -671,6 +622,6 @@ var AccountStartNoticeProcessor = class {
671
622
  }
672
623
  };
673
624
  //#endregion
674
- export { ACCOUNT_SWITCH_PART_TYPE, AccountRotationProcessor, AccountStartNoticeProcessor, PACK_FALLBACK_PART_TYPE, PACK_FALLBACK_STATE_KEY, PROVIDER_DISPLAY_NAMES, accountSwitchNoticeText, classifyRotationError, isAccountSwitchReason, isPackFallbackReason, packFallbackNoticeText, providerFromError, providerFromModelId };
625
+ export { ACCOUNT_SWITCH_PART_TYPE, AccountRotationProcessor, AccountStartNoticeProcessor, MODEL_FALLBACK_PART_TYPE, MODEL_FALLBACK_STATE_KEY, PROVIDER_DISPLAY_NAMES, accountSwitchNoticeText, classifyRotationError, isAccountSwitchReason, isModelFallbackReason, modelFallbackNoticeText, providerFromError, providerFromModelId };
675
626
 
676
627
  //# sourceMappingURL=account-rotation-processor.js.map