@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
96 lines • 5 kB
JavaScript
/**
* Shipped defaults are declared as model families (bare ids, no provider prefix).
* `canonicalizeFallbackChains` expands them against the live registry, so the chain
* follows Fable 5 whichever provider serves it - the builtin Anthropic provider, the
* Anthropic Subscription extension, a gateway, or Bedrock.
*
* The Fable ladders never leave Anthropic. A previous shipped default was removed because it
* led with cross-family rungs (`k3`, `kimi-k3`), which moved a Claude session onto another
* vendor mid-turn and could rank a guaranteed-refusal OAuth lane first. There is still
* deliberately no wildcard lane.
*
* Opus 5.5 is the one chain that leaves Anthropic, by the owner's order (senpi#6699): Fable 5.2
* at medium effort, then Kimi K3.1 Pro at max (its highest level), and nothing after. No Opus
* rung follows, since Anthropic meters Opus on its own quota window and a rate limit on
* Opus 5.5 also holds every other Opus rung on that account (senpi#6385).
*
* Rungs stay on current-generation Opus: a Claude session must never step down to
* `claude-opus-4-8` or `claude-opus-4-6` (senpi#3727).
*/
export const DEFAULT_FALLBACK_CHAINS = {
// Fable rungs carry no explicit level so fallback inherits the session's current thinking effort (senpi#4103).
"claude-fable-5-2": ["claude-opus-5-5", "claude-opus-5"],
"claude-fable-5-1": ["claude-opus-5-5", "claude-opus-5"],
"claude-fable-5": ["claude-opus-5-5", "claude-opus-5"],
"claude-opus-5-5": ["claude-fable-5-2:medium", "kimi-k3.1-pro:max"],
};
function cloneDefaultFallbackChains() {
const chains = {};
for (const [key, entries] of Object.entries(DEFAULT_FALLBACK_CHAINS)) {
chains[key] = [...entries];
}
return chains;
}
function isPlainObject(value) {
return value !== null && typeof value === "object" && !Array.isArray(value);
}
function isStringArray(value) {
return Array.isArray(value) && value.every((entry) => typeof entry === "string");
}
/**
* User chains layer over the shipped defaults per key instead of replacing the
* whole map. Configuring an unrelated model must not silently delete a default
* chain: that left the defaulted model with no client chain at all, which in
* turn disabled the server-fallback abort and handed model choice back to the
* provider. A same-named key still replaces that default outright (never a
* union), and an explicit empty array removes a default the user does not want -
* as a tombstone honored at both bare-family and canonical-provider granularity.
*
* Cross-scope replacement (global vs project) stays wholesale and is handled by
* `deepMergeSettings`; this only resolves defaults against the merged result.
*/
function resolveFallbackChains(value, sessionPolicy) {
const base = () => (sessionPolicy ? {} : cloneDefaultFallbackChains());
if (value === undefined || !isPlainObject(value))
return base();
const chains = base();
for (const [key, entries] of Object.entries(value)) {
if (!isStringArray(entries))
return base();
// An empty list stays in the map as a tombstone: canonicalization needs it to
// suppress the expanded default for that family or provider variant, and
// dropping it here would let the shipped default reappear after expansion.
chains[key] = [...entries];
}
return chains;
}
/**
* `sessionPolicy`: the chains were supplied by the session's opener (`open_session.retryFallback`,
* `set_retry_fallback`), so they are the session's whole policy and the shipped defaults are not merged
* back under them (senpi#4673). Settings-file chains still layer over the defaults.
*/
export function resolveRetryFallbackSettings(settings, options = {}) {
return {
modelFallback: typeof settings?.modelFallback === "boolean" ? settings.modelFallback : true,
chains: resolveFallbackChains(settings?.fallbackChains, options.sessionPolicy === true),
revertPolicy: settings?.fallbackRevertPolicy === "never" ? "never" : "cooldown-expiry",
};
}
export function resolveAbortServerSideFallback(settings) {
return typeof settings?.abortServerSideFallback === "boolean" ? settings.abortServerSideFallback : true;
}
export const DEFAULT_HINTED_WAIT_CAP_MS = 300_000;
export const DEFAULT_PROBE_BACK_MAX_MS = 3_600_000;
export function resolveHintPolicySettings(settings) {
const hintedWaitCapMs = typeof settings?.hintedWaitCapMs === "number" && settings.hintedWaitCapMs >= 0
? settings.hintedWaitCapMs
: DEFAULT_HINTED_WAIT_CAP_MS;
const probeBackMaxMs = typeof settings?.probeBackMaxMs === "number" && settings.probeBackMaxMs >= 0
? settings.probeBackMaxMs
: DEFAULT_PROBE_BACK_MAX_MS;
if (probeBackMaxMs <= hintedWaitCapMs) {
return { hintedWaitCapMs: DEFAULT_HINTED_WAIT_CAP_MS, probeBackMaxMs: DEFAULT_PROBE_BACK_MAX_MS };
}
return { hintedWaitCapMs, probeBackMaxMs };
}
//# sourceMappingURL=settings.js.map