omdsh-dev/dsh-llm-fallbacks ↗★ 21

dsh-llm-fallbacks

在LLM请求失败时自动切换至备用服务商或模型链。 适合对服务稳定性要求高、需规避限流或欠费中断的用户。支持Web、配置文件和TUI配置。

套件
dsh-llm-fallbacks
相容性
待驗證
Harness 依賴範圍
^0.2.0-rc.2
Cordis 依賴範圍
^4.0.2
版本
0.6.5
授權
MIT
最近更新
2026年9月29日

同名套件的其他儲存庫

安裝

$npx -p @deepseek-ai/dsh dsh plugin --profile web add github:omdsh-dev/dsh-llm-fallbacks

Configuration surfaces

The plugin's settings live in a shared fallbacks: namespace, editable from three surfaces:

SurfaceWhat it isNotes
Web settings cardSettings → Plugins → FallbacksFull GUI editor for the fallbacks: namespace; writes the shared settings document
$DSH_HOME/settings.yamlfallbacks: section in the dsh settings documentThe shared source of truth — the same file the web card writes; readable and editable everywhere, including scripted setups
TUI /settingsfallbacks section in the dsh-tui settings screendsh-tui ≥ v0.8.5; native fields for simple keys, JSON text fields for complex structures (see dsh-tui profile (terminal))

Pick the surface that matches your front end: web users get the card, terminal users get /settings, and the YAML file works everywhere. (/fallbacks and /fallbacks config are diagnostics — read-only views, not edit surfaces.)

Minimal configuration

Add a fallbacks: section to the shared settings document ($DSH_HOME/settings.yaml — see Configuration surfaces):

fallbacks:
  rootChain:               # all-day chain: leading entries = fallback walk, last = Default model (official)
    - anthropic/claude-3-5-sonnet          # walked first
    - deepseek-official/deepseek-flash  # last resort (Flash or Pro)
  timeSlots:               # optional: rotate the effective root chain by wall-clock windows
    - kind: preset         # frozen UTC+8 window; only the chain is editable
      preset: liang-peak   # Monday–Friday 09:00–12:00 and 14:00–18:00
      chain:
        - anthropic/claude-3-5-sonnet
    - kind: custom         # custom window (may wrap midnight)
      name: evening        # optional display name
      start: '22:00'
      end: '02:00'
      days: [1, 5]         # optional; omitted/empty = every day (0=Sunday…6=Saturday)
      chain:
        - openai/gpt-4o
  roles:                   # optional: declare role entities, then reference them from rules
    list:
      - id: reviewer       # unique id; "inherit" is reserved
        persona: Code-review subagents
        chain:
          - openai/gpt-4o-mini
        fallback: inherit-root   # role chain first, then the inherited rootChain
    rules:                 # subagent-only: rules never match root requests
      - role: reviewer     # all subagents → the reviewer role

Build the section up in four steps:

1. Configure content. There is no feature switch in the section — the plugin intervenes exactly when something is configured: a non-empty rootChain, at least one timeSlots row, or one declared role. An empty section is a complete no-op, and the Plugins-page row toggle is the master switch (disabling the plugin row stops it entirely).

2. Set the all-day rootChain. Leading entries are the fallback chain, walked first when a request fails; the last entry is the Default model.

Conformance: the last entry must be exactly one official model — deepseek-official/deepseek-flash or deepseek-official/deepseek-v4-pro (XOR). The settings card and gateway reject any other tail on save; a legacy non-official tail warns at startup and keeps working as a fallback-only walk, but cannot be saved as-is. The retired deepseek-v4-flash id is no longer a legal tail — a saved tail with it now warns, goes inert (slot rows + virtual picker), and blocks save until a legal tail is picked. The official Pro tail is catalog-served as deepseek-official/deepseek-v4-pro (dsh 0.2.0-rc.2) and selectable in the card; a hand-written legacy deepseek-official/deepseek-pro tail — never catalog-served — reads back as non-conforming (no migration; re-pick the tail). The plugin does not probe catalog availability — a chain containing deepseek-official/deepseek-v4-pro dispatches to it like any other exact entry, and on the virtual route the stream() delegate serves the first dispatchable exact head of the effective chain, so a chain with a working entry before Pro still routes to that earlier entry.

3. Add timeSlots (optional). Rows rotate the effective root chain by wall-clock windows. Preset rows use frozen UTC+8 windows (only their chain is editable; while a preset row exists, tz locks to Asia/Shanghai); custom rows take start/end (may wrap midnight) and an optional days list. The first row whose window contains the current moment wins; no match → the all-day rootChain. Rotation is a routing seed — it applies on the next root request and consumes no cooldown (see Time slots).

4. Add roles (optional). Declare role entities in roles.list (id, persona, chain, optional fallback policy), then map subagents to them with roles.rules. Rules never match root requests — with no rule match (or on a root request) the built-in inherit role applies and appends the rootChain.

Full reference (role entities, fallback strategies, rules, selectors, preset roles, time-slot presets) → docs/configuration.md.

Upgrade note (breaking, behavior change): the config-level enabled switch is removed — a stored section still carrying enabled: true/false loads cleanly (the key is ignored and stripped on the next save), but the switch no longer gates anything. If you relied on enabled: false to keep the plugin inert, empty the section (or disable the plugin row on the Plugins page) instead.

Usage

The tool is run from this repository (clone + pnpm install). Its sources do ship in the npm tarball, but there is no runnable entry there — no bin is registered and tsx is a dev dependency — so a registry install cannot run it. It is a read-only report by default: it walks a session root, classifies every pre-V3 log into exactly one refusal class and prints per-class counts. Nothing is written unless --apply is given.

git clone https://github.com/omdsh-dev/dsh-llm-fallbacks.git
cd dsh-llm-fallbacks
pnpm install
pnpm repair:session-logs                             # read-only report (the default)
pnpm repair:session-logs -- --root ~/.dsh/sessions   # explicit session root
pnpm repair:session-logs -- --apply                  # publish a repaired successor generation

--dry-run no longer exists: the report is the default mode, and --dry-run is rejected as an unknown argument (exit 2).

FlagMeaning
--root DIRsession root to walk (default: $DSH_HOME or ~/.dsh, then /sessions)
--applyrun the rules' proofs and publish a current-generation successor beside each repaired original (requires a resolved released catalog)
--class NAMErestrict what --apply repairs to one refusal class; the listing, the class table and the exit code still cover every log, and the repairable verdict is always computed over the full policy, so it can never hide a refusal or promise a repair this invocation cannot perform
--catalog PATHexplicit released catalog path (package directory, a directory holding it, or its module entry file). The resolved module is executed, not parsed — the same privilege as running this tool — and must declare a current format version ≥ 3; a below-version catalog, or a file candidate owned by a different package, is refused (exit 2) rather than trusted to verify its own output
--backupcopy the original generation to .bak before publishing; a run that publishes nothing removes the copy it created again (a pre-existing one is never touched, and one holding different bytes blocks the repair until you inspect and delete it)
--drop-legacy-eventsopt-in lossy recovery for legacy fallbacks/switch rows (see below)
--jsonmachine-readable report instead of the text report
--quietsuppress the per-log lines and the by-class table (warnings and errors are never suppressed)
--help, -hprint the usage text (including the --apply precondition) and exit 0

The original generation is never modified and never truncated; rollback is deleting the published successor, which makes the original the generation dsh opens again.

--apply precondition: run it only while NO dsh instance is writing the sessions under --root. The publisher links the successor into the session directory without observing the host's flock lease (that lease is host-internal and cannot be taken from this repo), so a dsh that is still appending to the old generation would be orphaned once the host prefers the successor. Stop dsh first.

Runtime floor: Node ≥ 22.15. Reading and writing need node:zlib zstd, which that release added (engines.node allows >= 22); an older runtime fails closed with an actionable message instead of a module-link stack trace.

Two policies, and ok-truncated. A log's class and its ok come from the host loader's policy — the one that decides whether the GUI opens the session — but that policy can swallow a refusal and drop every row after it. Every ok log is therefore cross-checked with the same loader policy under strict recovery (one axis apart, so a refusal there means rows were dropped rather than "not current-shaped"): when it refuses, the log is reported ok-truncated (a strictRefusal reason in --json, an ok-truncated count in the summary) because the session opens without the rows that refusal swallowed. Such sessions still exit 0 — they do load.

Discovery never fails open. A namespace/session directory that cannot be read, a canonical generation below the format floor that is a symlink or not a regular file, and a leftover session.repair.*.jsonl.zstd.tmp are reported (a skipped/staleStagingFiles entry, always printed and never hidden by --quiet), suppress the "no session log …" line, and make the run exit 1. Symlinks are reported, never followed: a repair writes beside the generation it repairs, which must stay inside --root. An unreadable --root is fatal (exit 2) — never an empty report.

--apply refuses a revision it did not decode. The digest of the bytes this run read is compared with the file before anything is staged, so a concurrent append is refused before the first write. If the source moves after a publication this run created, that successor is removed again; if it moves after accepting a pre-existing identical successor, the failure names that file and says to delete it — never "nothing was published".

A closed report stream is not a store event. Piping the report into a consumer that stops reading (pnpm repair:session-logs -- | head -n 5) closes stdout, and the next write would otherwise raise an unhandled EPIPE. Instead the tool stops writing to that stream (with no stack trace), still finishes the run — an --apply pass publishes every remaining successor — and exits with the exit code below, which always describes what happened to the store, never whether the reader stayed. A stream error that is not a closed pipe (a full disk, an I/O failure) is not swallowed: it still surfaces as an uncaught error.

Exit codes: 0 = every log loads (a session that opens with rows dropped under the strict policy is ok-truncated and still exits 0); 1 = at least one log is still refused/unrepairable, a repair failed, a log was left unpublished (including one --class excluded), an input could not be inspected (a skipped path), or a stale session.repair.*.jsonl.zstd.tmp was found under the root; 2 = fatal (bad arguments, a missing or unreadable --root, --apply without a resolved catalog, a catalog below format v3, --apply --drop-legacy-events without --backup, or a runtime without node:zlib zstd).