dsh-any-deepseek 0.0.36 → 0.0.38

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.
package/lib/client.js CHANGED
@@ -54,7 +54,13 @@ window.__ModuleLoader__.load({
54
54
  return channel === void 0 ? "供应组" : `供应组 · ${channel.label}`;
55
55
  }
56
56
  const channel = response.channels.find((candidate) => candidate.id === id);
57
- return channel === void 0 ? "未找到" : channel.label;
57
+ if (channel === void 0) return "未找到";
58
+ if (response.supply?.viaFallback === true) {
59
+ const member = response.supply.serving;
60
+ const servingChannel = response.channels.find((candidate) => candidate.id === member);
61
+ return servingChannel === void 0 ? "供应组(自动)" : `供应组(自动)· ${servingChannel.label}`;
62
+ }
63
+ return channel.label;
58
64
  }
59
65
  /**
60
66
  * Load per-channel balances.
@@ -225,6 +231,29 @@ window.__ModuleLoader__.load({
225
231
  }
226
232
  }
227
233
  /**
234
+ * Load the channel list, but let a FAILURE be a failure.
235
+ *
236
+ * 🔴 Why this exists next to {@link fetchChannels} (2026-11-18): that one answers a dead route with
237
+ * an empty list, which is the right shape for the PANEL — an empty table is a truthful rendering of
238
+ * a deployment whose HTTP surface did not come up, and the user is looking right at it.
239
+ *
240
+ * For the sidebar's provider line it is the wrong shape. An empty response has no `current`, so
241
+ * `currentProviderLabel` returns `undefined` and the line DISAPPEARS. At the old 5-minute cadence
242
+ * that was a rare blink; the line now polls every 15 seconds, so silently accepting "no current"
243
+ * would turn one transient failure into the line vanishing ~5760 times a day — a 20× increase in
244
+ * exactly the defect this release is fixing (a line that misdescribes the live supplier).
245
+ *
246
+ * ⇒ Same route, opposite contract: this one rejects, so the caller can KEEP the last known name
247
+ * instead of replacing a true fact with silence.
248
+ * @returns the response, with `current` guaranteed present in the JSON shape we validate.
249
+ * @throws when the route is unreachable, non-200, or answers something that is not a channel list.
250
+ */
251
+ async function fetchChannelsStrict() {
252
+ const response = await fetch(`${BASE}/channels`, { headers: { accept: "application/json" } });
253
+ if (!response.ok) throw new Error(`/channels answered ${response.status}`);
254
+ return await response.json();
255
+ }
256
+ /**
228
257
  * Load aggregates.
229
258
  * @param group - `channel` for the per-relay table, `day` for the timeline.
230
259
  * @param from - inclusive ISO lower bound.
@@ -845,6 +874,14 @@ window.__ModuleLoader__.load({
845
874
  " 位)"
846
875
  ]
847
876
  }),
877
+ !groupSelected && supply?.viaFallback === true && supply.serving !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
878
+ className: "ad-rowDetail ad-groupLive ad-groupSwitch",
879
+ children: [
880
+ "自动接管中:",
881
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: rows.find((row) => row.id === supply.serving)?.label ?? supply.serving }),
882
+ "(你选的渠道没余额了;充值后会自动回到它)"
883
+ ]
884
+ }),
848
885
  groupSelected && supply?.lastSwitch !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
849
886
  className: "ad-rowDetail ad-groupSwitch",
850
887
  children: [
@@ -1683,8 +1720,11 @@ window.__ModuleLoader__.load({
1683
1720
  * and that is exactly how the sidebar came to name a supplier that had already been switched away
1684
1721
  * from: the selection is instantaneous, the usage figure is a daily cumulative.
1685
1722
  *
1686
- * ⚠️ Its failure is swallowed on purpose: a missing channel list must not blank the usage figure
1687
- * that did arrive (and vice versa — the two never overwrite each other's state).
1723
+ * ⚠️ **A failure keeps the last known name; it does not blank the line.** This is why the loader
1724
+ * is strict (`fetchChannelsStrict`) rather than the lenient `fetchChannels` the panel uses: that
1725
+ * one answers a dead route with an EMPTY list, which has no `current`, which renders as nothing.
1726
+ * At a 15-second cadence the lenient shape would make the line disappear thousands of times a day
1727
+ * — turning the fix into the same class of defect it was written to remove.
1688
1728
  */
1689
1729
  const readProvider = (0, react.useCallback)(async () => {
1690
1730
  try {
@@ -1766,7 +1806,7 @@ window.__ModuleLoader__.load({
1766
1806
  ]
1767
1807
  }), provider === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1768
1808
  className: "ad-usageRow ad-providerRow",
1769
- title: "当前供应商(请求正在走的那个渠道)。最多 15 秒延迟;切换渠道后回到本窗口会立刻重读。",
1809
+ title: channels?.supply?.viaFallback === true && channels.current !== "__group__" ? "当前供应商:你选的渠道没有余额了,请求已自动改由供应组承担。把那个渠道充值后它会立刻回到使用(不用任何操作)。" : "当前供应商(请求正在走的那个渠道)。最多 15 秒延迟;切换渠道后回到本窗口会立刻重读。",
1770
1810
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1771
1811
  className: "ad-usageDot ad-providerDot",
1772
1812
  "aria-hidden": "true"
@@ -1817,7 +1857,7 @@ window.__ModuleLoader__.load({
1817
1857
  start.setHours(0, 0, 0, 0);
1818
1858
  return fetchStats("day", start.toISOString());
1819
1859
  },
1820
- loadChannels: () => fetchChannels()
1860
+ loadChannels: () => fetchChannelsStrict()
1821
1861
  })
1822
1862
  }, UsageBadge);
1823
1863
  } catch (error) {
package/lib/failover.d.ts CHANGED
@@ -72,6 +72,49 @@ export interface SupplySwitch {
72
72
  code: string;
73
73
  atMs: number;
74
74
  }
75
+ /** What the adapter knows when deciding whether a dead channel may fall back into the group. */
76
+ export interface FallbackDecisionInput {
77
+ /** The failure code from the attempt on the DIRECTLY selected channel. */
78
+ code: string | undefined;
79
+ /**
80
+ * Whether ANY chunk reached the consumer.
81
+ *
82
+ * 🔴 Same load-bearing guard as {@link canSwitchAttempt}, and for the identical reason: once a
83
+ * chunk is yielded it is in the session and on screen, so continuing on another supplier would
84
+ * splice two models into one message with no seam.
85
+ */
86
+ emitted: boolean;
87
+ /**
88
+ * Whether `current` names a CHANNEL rather than the supply group.
89
+ *
90
+ * ⛔ When the group is already serving, its own walk owns this decision (`canSwitchAttempt`).
91
+ * Two mechanisms acting on one failure would double-attempt the same member.
92
+ */
93
+ selectionIsChannel: boolean;
94
+ /** How many resolvable members the group has, EXCLUDING the channel that just failed. */
95
+ groupCandidates: number;
96
+ }
97
+ /**
98
+ * Whether a plain-channel request may fall back into the supply group.
99
+ *
100
+ * ## Why this is a separate decision from the group's own walk
101
+ *
102
+ * The group walk answers "which OTHER member serves this request"; this answers "should a request
103
+ * that was NOT walking the group start walking it, because the chosen channel ran out of money".
104
+ * They share the emitted guard and the switch set's philosophy, but they differ in the trigger set
105
+ * (narrower — {@link OUT_OF_CREDIT_CODES}) and in what they must leave alone: this one never
106
+ * applies when the group is already the selection.
107
+ *
108
+ * ⚠️ **It is a per-request decision, not a persisted mode change.** `current` stays what the user
109
+ * chose. That is not timidity — writing settings from a request path is a revision bump in the
110
+ * middle of a request, which is the exact shape of the「保存时好时坏」defect (decision 85). The
111
+ * consequence is stated rather than hidden: while the chosen channel has no credit, EVERY request
112
+ * pays one wasted quota refusal on it first, then serves from the group. Same price as the priority
113
+ * order (decision 97), and the same benefit: topping the channel up restores it with no action.
114
+ * @param input - the four facts the decision depends on.
115
+ * @returns true only when the fallback is both useful and safe.
116
+ */
117
+ export declare function canFallBackToGroup(input: FallbackDecisionInput): boolean;
75
118
  /**
76
119
  * What the last request did, for the panel only.
77
120
  *
@@ -83,6 +126,27 @@ export interface SupplySwitch {
83
126
  export declare class SupplyStatus {
84
127
  /** The member that last served successfully. */
85
128
  private servedId;
129
+ /**
130
+ * The `current` value in force when {@link servedId} was recorded.
131
+ *
132
+ * 🔴 Why a reading needs its own provenance (2026-11-19). `serving` answers "which channel served
133
+ * the last successful request", and that is only meaningful against the selection that request
134
+ * ran under. Without this, a user who switches from a channel to another channel would keep
135
+ * seeing the previous name rendered as if it were live — the 2026-11-18 wrong-name defect, one
136
+ * layer down. The panel now reports `serving` ONLY when this still matches the live `current`;
137
+ * otherwise the reading is stale and saying nothing is the honest answer.
138
+ */
139
+ private servedFor;
140
+ /**
141
+ * Whether the last successful request reached that channel by falling back into the group.
142
+ *
143
+ * 🔴 This is the fact that makes the safety net VISIBLE (owner request 2026-11-19). With a plain
144
+ * channel selected, a request can now be served by a group MEMBER after the chosen channel runs
145
+ * out of credit. Without this flag the sidebar would print the member's own label as though the
146
+ * user had selected it — a confident wrong answer about where the request went, which is exactly
147
+ * the defect of 2026-11-18 one layer down.
148
+ */
149
+ private servedViaFallback;
86
150
  /** The last switch, if any since the process started (or since the group was re-read). */
87
151
  private switchRecord;
88
152
  /** Whether the most recent request found no usable member at all. */
@@ -100,8 +164,13 @@ export declare class SupplyStatus {
100
164
  * @param members - the configured ordered member ids.
101
165
  */
102
166
  bind(members: readonly string[]): void;
103
- /** Record that `id` served this request successfully. */
104
- noteServed(id: string): void;
167
+ /**
168
+ * Record that `id` served this request successfully.
169
+ * @param id - the channel that actually produced the response.
170
+ * @param forCurrent - the `current` value this request was routed under.
171
+ * @param viaFallback - whether it served after a plain-channel selection fell back into the group.
172
+ */
173
+ noteServed(id: string, forCurrent: string, viaFallback?: boolean): void;
105
174
  /** Record one move from a member that could not serve to the one tried next. */
106
175
  noteSwitch(from: string, to: string, code: string, atMs: number): void;
107
176
  /**
@@ -115,8 +184,35 @@ export declare class SupplyStatus {
115
184
  * @param exhausted - whether the list ran out (true) or the request failed with members left.
116
185
  */
117
186
  noteFailure(lastTried: string | undefined, exhausted: boolean): void;
187
+ /**
188
+ * Whether the last successful request reached its supplier by falling back into the group.
189
+ *
190
+ * ⛔ Only meaningful together with {@link servingUnder}: a stale reading from before a selection
191
+ * change must not be reported as a live fallback.
192
+ */
193
+ get servedByFallback(): boolean;
194
+ /**
195
+ * Whether the member that last served belongs to the currently bound group list.
196
+ *
197
+ * 🔴 This is what makes the safety net VISIBLE (owner request 2026-11-19). With a plain channel
198
+ * selected, a request can now be served by a group member after the chosen channel runs out of
199
+ * credit. Saying so requires two facts together — "who served" and "is that one of the group's
200
+ * members" — and neither alone is enough: the same channel may be both `current` and a member.
201
+ * @param id - a channel id, typically {@link servingUnder}.
202
+ * @returns true when `id` is in the bound member list.
203
+ */
204
+ isMember(id: string | undefined): boolean;
118
205
  /** The member that last served, or undefined when nothing has served yet / the last request failed. */
119
206
  get serving(): string | undefined;
207
+ /**
208
+ * The member that last served, but only if that reading still applies to `current`.
209
+ *
210
+ * 🔴 This is what a reader should use. {@link serving} alone cannot distinguish "this is who is
211
+ * serving now" from "this is who served before the user changed the selection".
212
+ * @param current - the live `current` value.
213
+ * @returns the serving channel id, or undefined when the reading is stale or absent.
214
+ */
215
+ servingUnder(current: string | undefined): string | undefined;
120
216
  /** The most recent switch, or undefined when none has happened. */
121
217
  get lastSwitch(): SupplySwitch | undefined;
122
218
  /** Whether the most recent request found no usable member. */
package/lib/index.js CHANGED
@@ -748,6 +748,35 @@ function selectChannel(channels, current, groupMembers = []) {
748
748
  };
749
749
  }
750
750
  /**
751
+ * The supply group's members, resolved and ordered: the ONE definition of "who is in the group".
752
+ *
753
+ * 🔴 Extracted for the safety-net path (2026-11-19). Two callers now need it — the router, which
754
+ * needs a head plus alternates, and the adapter's fallback, which needs the ordered ids to append
755
+ * to a single-channel request that ran out of credit. If each derived the order itself they would
756
+ * eventually disagree about what "priority 1" means, and the disagreement would be invisible: both
757
+ * would look correct on their own.
758
+ *
759
+ * Dangling ids are dropped here and nowhere else, and the caller is told which ones — the panel
760
+ * lists them, because a group that quietly shrinks is how "three relays" becomes "one relay".
761
+ * @param channels - every resolved channel.
762
+ * @param members - the configured ordered member ids; index 0 is the highest priority.
763
+ * @returns the ordered resolvable channels, plus the member ids that resolve to nothing.
764
+ */
765
+ function groupMembers(channels, members) {
766
+ const byId = new Map(channels.map((channel) => [channel.id, channel]));
767
+ const ordered = [];
768
+ const dangling = [];
769
+ for (const id of members) {
770
+ const channel = byId.get(id);
771
+ if (channel === void 0) dangling.push(id);
772
+ else ordered.push(channel);
773
+ }
774
+ return {
775
+ ordered,
776
+ dangling
777
+ };
778
+ }
779
+ /**
751
780
  * Resolve the supply group into an ordered candidate list, highest priority first.
752
781
  *
753
782
  * ## Why dangling members are SKIPPED rather than fatal
@@ -764,33 +793,24 @@ function selectChannel(channels, current, groupMembers = []) {
764
793
  * @returns the ordered candidates, or a failure.
765
794
  */
766
795
  function selectFromGroup(channels, members) {
767
- const byId = new Map(channels.map((channel) => [channel.id, channel]));
768
- const resolvable = members.filter((id) => byId.has(id));
769
- if (resolvable.length === 0) return {
796
+ const { ordered } = groupMembers(channels, members);
797
+ if (ordered.length === 0) return {
770
798
  ok: false,
771
799
  failure: {
772
800
  code: "GROUP_EMPTY",
773
801
  detail: members.length === 0 ? "the supply group has no members; add channels to it in Settings → Any DeepSeek" : `the supply group names no channel that exists (${members.join(", ")}); fix it in Settings → Any DeepSeek`
774
802
  }
775
803
  };
776
- const [head, ...rest] = resolvable;
777
- const headChannel = byId.get(head);
778
- if (headChannel === void 0) return {
779
- ok: false,
780
- failure: {
781
- code: "GROUP_EMPTY",
782
- detail: "the supply group resolved to nothing usable"
783
- }
784
- };
804
+ const [head, ...rest] = ordered;
785
805
  return {
786
806
  ok: true,
787
- channel: headChannel,
807
+ channel: head,
788
808
  source: {
789
809
  kind: "group",
790
810
  index: 0,
791
- of: resolvable.length
811
+ of: ordered.length
792
812
  },
793
- alternates: rest.flatMap((id) => byId.get(id) ?? [])
813
+ alternates: rest
794
814
  };
795
815
  }
796
816
  //#endregion
@@ -861,6 +881,48 @@ function canSwitchAttempt(input) {
861
881
  return !input.emitted && input.hasNext && shouldFailover(input.code);
862
882
  }
863
883
  /**
884
+ * Codes that mean "this account has no credit left", as opposed to any other failure.
885
+ *
886
+ * 🔴 Deliberately NARROWER than {@link CHANNEL_UNUSABLE_CODES}, and the difference is the whole
887
+ * point of the safety net this list serves. Owner request 2026-11-19:
888
+ * 「当使用非供应组渠道 用到无费用时 自动切换到供应组。目的是确保 token 供应不中断」.
889
+ *
890
+ * The trigger is 「无费用」 — out of credit. A dead key (`AUTH`) or a channel whose key was never
891
+ * configured (`MISSING_CREDENTIAL`) is ALSO terminal, but falling back into the supply group for
892
+ * those would be answering a question the owner did not ask: a mistyped key is a configuration
893
+ * error to fix, not a reason to silently route elsewhere, and routing around it would hide it.
894
+ * Those two are still fatal for a plain channel selection (decision: no silent fallback), so they
895
+ * stay OUT of this set. If the owner ever wants them in, this comment is where the change starts.
896
+ */
897
+ const OUT_OF_CREDIT_CODES = /* @__PURE__ */ new Set(["QUOTA", "ACCOUNT_QUOTA"]);
898
+ /**
899
+ * Whether a plain-channel request may fall back into the supply group.
900
+ *
901
+ * ## Why this is a separate decision from the group's own walk
902
+ *
903
+ * The group walk answers "which OTHER member serves this request"; this answers "should a request
904
+ * that was NOT walking the group start walking it, because the chosen channel ran out of money".
905
+ * They share the emitted guard and the switch set's philosophy, but they differ in the trigger set
906
+ * (narrower — {@link OUT_OF_CREDIT_CODES}) and in what they must leave alone: this one never
907
+ * applies when the group is already the selection.
908
+ *
909
+ * ⚠️ **It is a per-request decision, not a persisted mode change.** `current` stays what the user
910
+ * chose. That is not timidity — writing settings from a request path is a revision bump in the
911
+ * middle of a request, which is the exact shape of the「保存时好时坏」defect (decision 85). The
912
+ * consequence is stated rather than hidden: while the chosen channel has no credit, EVERY request
913
+ * pays one wasted quota refusal on it first, then serves from the group. Same price as the priority
914
+ * order (decision 97), and the same benefit: topping the channel up restores it with no action.
915
+ * @param input - the four facts the decision depends on.
916
+ * @returns true only when the fallback is both useful and safe.
917
+ */
918
+ function canFallBackToGroup(input) {
919
+ if (input.emitted) return false;
920
+ if (!input.selectionIsChannel) return false;
921
+ if (input.groupCandidates <= 0) return false;
922
+ if (input.code === void 0) return false;
923
+ return OUT_OF_CREDIT_CODES.has(input.code);
924
+ }
925
+ /**
864
926
  * What the last request did, for the panel only.
865
927
  *
866
928
  * 🔴 **Nothing here is an input to routing.** The owner's rule is "always start at 1", so a value
@@ -871,6 +933,27 @@ function canSwitchAttempt(input) {
871
933
  var SupplyStatus = class {
872
934
  /** The member that last served successfully. */
873
935
  servedId;
936
+ /**
937
+ * The `current` value in force when {@link servedId} was recorded.
938
+ *
939
+ * 🔴 Why a reading needs its own provenance (2026-11-19). `serving` answers "which channel served
940
+ * the last successful request", and that is only meaningful against the selection that request
941
+ * ran under. Without this, a user who switches from a channel to another channel would keep
942
+ * seeing the previous name rendered as if it were live — the 2026-11-18 wrong-name defect, one
943
+ * layer down. The panel now reports `serving` ONLY when this still matches the live `current`;
944
+ * otherwise the reading is stale and saying nothing is the honest answer.
945
+ */
946
+ servedFor;
947
+ /**
948
+ * Whether the last successful request reached that channel by falling back into the group.
949
+ *
950
+ * 🔴 This is the fact that makes the safety net VISIBLE (owner request 2026-11-19). With a plain
951
+ * channel selected, a request can now be served by a group MEMBER after the chosen channel runs
952
+ * out of credit. Without this flag the sidebar would print the member's own label as though the
953
+ * user had selected it — a confident wrong answer about where the request went, which is exactly
954
+ * the defect of 2026-11-18 one layer down.
955
+ */
956
+ servedViaFallback = false;
874
957
  /** The last switch, if any since the process started (or since the group was re-read). */
875
958
  switchRecord;
876
959
  /** Whether the most recent request found no usable member at all. */
@@ -892,13 +975,22 @@ var SupplyStatus = class {
892
975
  if (signature === this.signature) return;
893
976
  this.signature = signature;
894
977
  this.servedId = void 0;
978
+ this.servedFor = void 0;
979
+ this.servedViaFallback = false;
895
980
  this.switchRecord = void 0;
896
981
  this.exhausted = false;
897
982
  this.lastTriedId = void 0;
898
983
  }
899
- /** Record that `id` served this request successfully. */
900
- noteServed(id) {
984
+ /**
985
+ * Record that `id` served this request successfully.
986
+ * @param id - the channel that actually produced the response.
987
+ * @param forCurrent - the `current` value this request was routed under.
988
+ * @param viaFallback - whether it served after a plain-channel selection fell back into the group.
989
+ */
990
+ noteServed(id, forCurrent, viaFallback = false) {
901
991
  this.servedId = id;
992
+ this.servedFor = forCurrent;
993
+ this.servedViaFallback = viaFallback;
902
994
  this.exhausted = false;
903
995
  this.lastTriedId = void 0;
904
996
  }
@@ -923,13 +1015,50 @@ var SupplyStatus = class {
923
1015
  */
924
1016
  noteFailure(lastTried, exhausted) {
925
1017
  this.servedId = void 0;
1018
+ this.servedFor = void 0;
1019
+ this.servedViaFallback = false;
926
1020
  this.exhausted = exhausted;
927
1021
  this.lastTriedId = lastTried;
928
1022
  }
1023
+ /**
1024
+ * Whether the last successful request reached its supplier by falling back into the group.
1025
+ *
1026
+ * ⛔ Only meaningful together with {@link servingUnder}: a stale reading from before a selection
1027
+ * change must not be reported as a live fallback.
1028
+ */
1029
+ get servedByFallback() {
1030
+ return this.servedViaFallback;
1031
+ }
1032
+ /**
1033
+ * Whether the member that last served belongs to the currently bound group list.
1034
+ *
1035
+ * 🔴 This is what makes the safety net VISIBLE (owner request 2026-11-19). With a plain channel
1036
+ * selected, a request can now be served by a group member after the chosen channel runs out of
1037
+ * credit. Saying so requires two facts together — "who served" and "is that one of the group's
1038
+ * members" — and neither alone is enough: the same channel may be both `current` and a member.
1039
+ * @param id - a channel id, typically {@link servingUnder}.
1040
+ * @returns true when `id` is in the bound member list.
1041
+ */
1042
+ isMember(id) {
1043
+ if (id === void 0 || this.signature === "") return false;
1044
+ return this.signature.split("\0").includes(id);
1045
+ }
929
1046
  /** The member that last served, or undefined when nothing has served yet / the last request failed. */
930
1047
  get serving() {
931
1048
  return this.servedId;
932
1049
  }
1050
+ /**
1051
+ * The member that last served, but only if that reading still applies to `current`.
1052
+ *
1053
+ * 🔴 This is what a reader should use. {@link serving} alone cannot distinguish "this is who is
1054
+ * serving now" from "this is who served before the user changed the selection".
1055
+ * @param current - the live `current` value.
1056
+ * @returns the serving channel id, or undefined when the reading is stale or absent.
1057
+ */
1058
+ servingUnder(current) {
1059
+ const live = current ?? "";
1060
+ return this.servedFor === live ? this.servedId : void 0;
1061
+ }
933
1062
  /** The most recent switch, or undefined when none has happened. */
934
1063
  get lastSwitch() {
935
1064
  return this.switchRecord;
@@ -1710,8 +1839,28 @@ var AnyDeepSeekAdapter = class extends LlmAdapter {
1710
1839
  yield failureChunk(selection.failure);
1711
1840
  return;
1712
1841
  }
1713
- const candidates = [selection.channel, ...selection.alternates];
1842
+ const head = selection.channel;
1843
+ /** Mutable on purpose: the safety net appends the group's members mid-request. */
1844
+ const candidates = [head, ...selection.alternates];
1714
1845
  const fromGroup = selection.source.kind === "group";
1846
+ /**
1847
+ * The supply group as an ordered fallback list, prepared BEFORE the first attempt.
1848
+ *
1849
+ * 🔴 Owner request 2026-11-19: 「当使用非供应组渠道 用到无费用时 自动切换到供应组。目的是确保
1850
+ * token 供应不中断」. The group already knows how to walk itself; what was missing is permission
1851
+ * for a request that chose a SINGLE channel to continue inside it when that channel runs out of
1852
+ * money.
1853
+ *
1854
+ * ⛔ Empty when the group is already serving: its own walk owns that decision, and two
1855
+ * mechanisms acting on one failure would attempt the same member twice.
1856
+ *
1857
+ * ⚠️ The failed channel is excluded. It is `current`, so a user may well have put it in the
1858
+ * group too; re-attempting it immediately would spend a guaranteed second refusal on the same
1859
+ * dead account, which is not "供应不中断", it is a loop.
1860
+ */
1861
+ const groupFallback = fromGroup ? [] : groupMembers(this.deps.channels(), supply.members).ordered.filter((channel) => channel.id !== head.id);
1862
+ /** Whether the safety net has already fired for this request (it may fire at most once). */
1863
+ let fellBack = false;
1715
1864
  /** Every attempt this request made, for the message on total failure. */
1716
1865
  const tried = [];
1717
1866
  for (let position = 0; position < candidates.length; position++) {
@@ -1834,7 +1983,7 @@ var AnyDeepSeekAdapter = class extends LlmAdapter {
1834
1983
  }
1835
1984
  await record();
1836
1985
  if (failure === void 0) {
1837
- if (fromGroup) supply.status.noteServed(channel.id);
1986
+ supply.status.noteServed(channel.id, this.deps.current() ?? "", fellBack);
1838
1987
  return;
1839
1988
  }
1840
1989
  const code = failure.code;
@@ -1848,16 +1997,27 @@ var AnyDeepSeekAdapter = class extends LlmAdapter {
1848
1997
  emitted,
1849
1998
  hasNext: position + 1 < candidates.length
1850
1999
  })) {
1851
- if (fromGroup) supply.status.noteSwitch(channel.id, candidates[position + 1].id, code, this.deps.now().getTime());
2000
+ if (fromGroup || fellBack) supply.status.noteSwitch(channel.id, candidates[position + 1].id, code, this.deps.now().getTime());
1852
2001
  continue;
1853
2002
  }
1854
- if (fromGroup) supply.status.noteFailure(channel.id, position + 1 >= candidates.length);
2003
+ if (!fellBack && canFallBackToGroup({
2004
+ code,
2005
+ emitted,
2006
+ selectionIsChannel: !fromGroup,
2007
+ groupCandidates: groupFallback.length
2008
+ })) {
2009
+ fellBack = true;
2010
+ candidates.push(...groupFallback);
2011
+ supply.status.noteSwitch(channel.id, groupFallback[0].id, code, this.deps.now().getTime());
2012
+ continue;
2013
+ }
2014
+ if (fromGroup || fellBack) supply.status.noteFailure(channel.id, position + 1 >= candidates.length);
1855
2015
  yield {
1856
2016
  type: "finish",
1857
2017
  reason: {
1858
2018
  kind: "error",
1859
2019
  failure: {
1860
- message: describeFailure(failure, tried, emitted),
2020
+ message: describeFailure(failure, tried, emitted, !fromGroup),
1861
2021
  code
1862
2022
  }
1863
2023
  }
@@ -1875,18 +2035,26 @@ var AnyDeepSeekAdapter = class extends LlmAdapter {
1875
2035
  /**
1876
2036
  * Turn a terminal failure into the message the user reads.
1877
2037
  *
1878
- * 🔴 The attempt trail is appended only when the group actually walked (`tried.length > 1`). A
1879
- * single-attempt failure gains nothing from "tried: X" — the user already knows which supplier was
1880
- * live — and adding it unconditionally would bury the real error under routing noise.
2038
+ * 🔴 The attempt trail is appended only when more than one supplier was tried. A single-attempt
2039
+ * failure gains nothing from "tried: X" — the user already knows which supplier was live — and
2040
+ * adding it unconditionally would bury the real error under routing noise.
2041
+ *
2042
+ * ⚠️ **Which sentence is used is not cosmetic** (2026-11-19). A request that started on a plain
2043
+ * channel and fell back says "every supply-group member failed" only if the CHOSEN channel is also
2044
+ * mentioned — otherwise the reader sees a trail beginning with a channel they picked and a claim
2045
+ * about group members, and concludes the group was selected all along.
1881
2046
  * @param failure - the last attempt's error.
1882
2047
  * @param tried - every attempt, in order.
1883
2048
  * @param emitted - whether content had already reached the consumer.
2049
+ * @param startedOnChannel - whether the request began on a directly selected channel (not the group).
1884
2050
  * @returns the message to send to the harness.
1885
2051
  */
1886
- function describeFailure(failure, tried, emitted) {
2052
+ function describeFailure(failure, tried, emitted, startedOnChannel) {
1887
2053
  if (tried.length <= 1) return failure.message;
1888
2054
  const trail = tried.map((attempt) => `${attempt.label}(${attempt.code})`).join(" → ");
1889
- return emitted ? `${failure.message} — already streaming from ${tried[tried.length - 1].label}, so the group did not switch (tried: ${trail})` : `${failure.message} — every supply-group member failed (tried: ${trail})`;
2055
+ if (emitted) return `${failure.message} — already streaming from ${tried[tried.length - 1].label}, so the group did not switch (tried: ${trail})`;
2056
+ if (startedOnChannel) return `${failure.message} — your selected channel and every supply-group member failed (tried: ${trail})`;
2057
+ return `${failure.message} — every supply-group member failed (tried: ${trail})`;
1890
2058
  }
1891
2059
  /** Turn a routing failure into a terminal chunk. */
1892
2060
  function failureChunk(failure) {
@@ -3219,7 +3387,8 @@ function apply(ctx, config) {
3219
3387
  const live = channels();
3220
3388
  const known = new Set(live.map((channel) => channel.id));
3221
3389
  const order = members.filter((id) => known.has(id));
3222
- const serving = status.serving;
3390
+ const selection = current() ?? "";
3391
+ const serving = status.servingUnder(selection);
3223
3392
  const position = serving === void 0 ? -1 : order.indexOf(serving);
3224
3393
  const last = status.lastSwitch;
3225
3394
  const lastTried = status.lastTried;
@@ -3229,6 +3398,15 @@ function apply(ctx, config) {
3229
3398
  ...serving === void 0 ? {} : { serving },
3230
3399
  position,
3231
3400
  exhausted: status.isExhausted,
3401
+ /**
3402
+ * 🔴 Whether the last successful request left the CHOSEN channel for this member.
3403
+ *
3404
+ * With a plain channel selected, the sidebar must say 「没余额,已自动切到供应组 · X」 rather
3405
+ * than naming X as if the user had picked it. Two facts are needed together and neither
3406
+ * is enough alone, so both travel: `servedByFallback` says WHY, `isMember` confirms the
3407
+ * served channel really is one of the group's.
3408
+ */
3409
+ viaFallback: status.servedByFallback && status.isMember(serving),
3232
3410
  ...lastTried === void 0 ? {} : { lastTried },
3233
3411
  ...last === void 0 ? {} : { lastSwitch: last }
3234
3412
  };
package/lib/route.d.ts CHANGED
@@ -82,6 +82,25 @@ export type RouteResult = {
82
82
  * @returns the selected channel plus its ordered alternates, or the reason there is none.
83
83
  */
84
84
  export declare function selectChannel(channels: readonly ResolvedChannel[], current: string | undefined, groupMembers?: readonly string[]): RouteResult;
85
+ /**
86
+ * The supply group's members, resolved and ordered: the ONE definition of "who is in the group".
87
+ *
88
+ * 🔴 Extracted for the safety-net path (2026-11-19). Two callers now need it — the router, which
89
+ * needs a head plus alternates, and the adapter's fallback, which needs the ordered ids to append
90
+ * to a single-channel request that ran out of credit. If each derived the order itself they would
91
+ * eventually disagree about what "priority 1" means, and the disagreement would be invisible: both
92
+ * would look correct on their own.
93
+ *
94
+ * Dangling ids are dropped here and nowhere else, and the caller is told which ones — the panel
95
+ * lists them, because a group that quietly shrinks is how "three relays" becomes "one relay".
96
+ * @param channels - every resolved channel.
97
+ * @param members - the configured ordered member ids; index 0 is the highest priority.
98
+ * @returns the ordered resolvable channels, plus the member ids that resolve to nothing.
99
+ */
100
+ export declare function groupMembers(channels: readonly ResolvedChannel[], members: readonly string[]): {
101
+ ordered: ResolvedChannel[];
102
+ dangling: string[];
103
+ };
85
104
  /**
86
105
  * Whether `current` names a channel that exists at all.
87
106
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-any-deepseek",
3
- "version": "0.0.36",
3
+ "version": "0.0.38",
4
4
  "description": "One DeepSeek V4.1 Flash provider for DeepSeek Harness: paste a key per channel, switch channels manually, token usage booked per real upstream.",
5
5
  "license": "MIT",
6
6
  "repository": {