dsh-connect-workbuddy 5.20.32 → 5.21.2

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
@@ -137,6 +137,33 @@ window.__ModuleLoader__.load({
137
137
  /** How long the card waits between polls while the user is scanning. */
138
138
  const OAUTH_POLL_INTERVAL_MS = 2e3;
139
139
  /**
140
+ * The refresh intervals the card offers, in milliseconds.
141
+ *
142
+ * SHARED between the Host (which validates the saved value) and the browser
143
+ * (which renders the dropdown), so the control and its validation cannot drift:
144
+ * a value the dropdown can produce is always a value the Host accepts, and the
145
+ * Host's fallback is always a value the dropdown can show.
146
+ *
147
+ * A CLOSED SET rather than a free number because this interval decides the
148
+ * plugin's upstream request volume — one credits read plus one check-in read per
149
+ * pooled account, per refresh.
150
+ */
151
+ const WORKBUDDY_POLL_INTERVALS_MS = [
152
+ 6e4,
153
+ 3e5,
154
+ 6e5,
155
+ 18e5,
156
+ 36e5
157
+ ];
158
+ /**
159
+ * The default refresh interval: 5 minutes.
160
+ *
161
+ * Moved off the old hard-coded 60 s. A 4-account pool at 60 s costs ~11,520
162
+ * requests a day for figures that move slowly; 5 minutes is a fifth of that and
163
+ * still five times finer than the 30-minute auto check-in heartbeat.
164
+ */
165
+ const WORKBUDDY_DEFAULT_POLL_INTERVAL_MS = 3e5;
166
+ /**
140
167
  * Plugin-owned account transfer endpoint: the batch export / import of
141
168
  * credentials between machines and between tools of the SAME format family.
142
169
  *
@@ -1087,6 +1114,50 @@ window.__ModuleLoader__.load({
1087
1114
  throw hostError instanceof Error ? hostError : new WorkBuddySettingsWriteError("sidebarPanel", "neither the Host save endpoint nor the settings scope persisted the value");
1088
1115
  }
1089
1116
  /**
1117
+ * Read the card's refresh interval out of a settings snapshot.
1118
+ *
1119
+ * Coerced against the offered set, and an unrecognized value reads as the
1120
+ * default. The direction matters: this number drives `setInterval`, so a typo in
1121
+ * the settings file must not become a sub-second poll. Coercing on READ as well
1122
+ * as on the Host means a stale browser mirror cannot arm a cadence the Host
1123
+ * would have refused.
1124
+ */
1125
+ function pollIntervalMsOf(value) {
1126
+ const raw = value?.pollIntervalMs;
1127
+ return typeof raw === "number" && WORKBUDDY_POLL_INTERVALS_MS.includes(raw) ? raw : WORKBUDDY_DEFAULT_POLL_INTERVAL_MS;
1128
+ }
1129
+ /**
1130
+ * Persist the card's refresh interval.
1131
+ *
1132
+ * Same two-writer shape as {@link writeSidebarPanelEnabled}: the Host endpoint is
1133
+ * authoritative, the settings scope is the fallback for an older Host. A plain
1134
+ * top-level number, so there is no sibling state to preserve.
1135
+ *
1136
+ * @param scope - the bound settings scope for this plugin's namespace.
1137
+ * @param intervalMs - one of {@link WORKBUDDY_POLL_INTERVALS_MS}.
1138
+ * @throws {WorkBuddySettingsWriteError} when neither writer persists the value.
1139
+ */
1140
+ async function writePollIntervalMs(scope, intervalMs) {
1141
+ let hostError;
1142
+ try {
1143
+ const authoritative = await saveViaHostEndpoint("pollIntervalMs", void 0, intervalMs);
1144
+ if (authoritative !== void 0) try {
1145
+ await scope.set("pollIntervalMs", authoritative["pollIntervalMs"]);
1146
+ } catch {}
1147
+ return;
1148
+ } catch (error) {
1149
+ hostError = error;
1150
+ }
1151
+ let delivered = false;
1152
+ try {
1153
+ delivered = await scope.set("pollIntervalMs", intervalMs) !== false;
1154
+ } catch {
1155
+ delivered = false;
1156
+ }
1157
+ if (delivered && pollIntervalMsOf(scope.getSnapshot().value) === intervalMs) return;
1158
+ throw hostError instanceof Error ? hostError : new WorkBuddySettingsWriteError("pollIntervalMs", "neither the Host save endpoint nor the settings scope persisted the value");
1159
+ }
1160
+ /**
1090
1161
  * Read the CodeBuddy-CLI route's PINNED model out of a settings snapshot.
1091
1162
  *
1092
1163
  * `''` is a real answer here, not a missing one: it means "nothing is pinned,
@@ -5765,6 +5836,27 @@ window.__ModuleLoader__.load({
5765
5836
  });
5766
5837
  }
5767
5838
  };
5839
+ /**
5840
+ * Turn a transport-level failure into something a person can act on.
5841
+ *
5842
+ * `fetch()` rejects with a bare `TypeError: Failed to fetch` whenever no HTTP
5843
+ * response arrives at all — the connection was reset, or the text could not be
5844
+ * posted. Rendered verbatim that reads like a bug in the plugin (issue #229:
5845
+ * the user saw "传输失败:Failed to fetch" and had nothing to go on). The two
5846
+ * causes worth naming are a file too large to upload and a local service that
5847
+ * is not answering; anything else keeps its own message, which is more
5848
+ * informative than a generic one.
5849
+ *
5850
+ * Note this is the CLIENT's guess: the server now answers 413 for an oversized
5851
+ * body, so a size problem usually arrives as a normal error response and never
5852
+ * reaches here. This path is what is left when the request dies before an
5853
+ * answer — which is also what a half-open local port looks like.
5854
+ */
5855
+ const transportMessage = (error, text) => {
5856
+ if (!(error instanceof TypeError)) return error instanceof Error ? error.message : String(error);
5857
+ const kilobytes = Math.round(new Blob([text]).size / 1024);
5858
+ return t("row.transferNoService", { size: String(kilobytes) });
5859
+ };
5768
5860
  const readImportFile = async (file) => {
5769
5861
  setPhase({ kind: "importing" });
5770
5862
  try {
@@ -5794,7 +5886,7 @@ window.__ModuleLoader__.load({
5794
5886
  } catch (error) {
5795
5887
  if (mounted.current) setPhase({
5796
5888
  kind: "error",
5797
- message: error instanceof Error ? error.message : String(error)
5889
+ message: transportMessage(error, importText.current)
5798
5890
  });
5799
5891
  }
5800
5892
  };
@@ -8910,7 +9002,19 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
8910
9002
  *
8911
9003
  * @module dsh-connect-workbuddy/client/WorkBuddyCard
8912
9004
  */
8913
- const POLL_INTERVAL_MS = 6e4;
9005
+ /**
9006
+ * The refresh cadence when the Host does not say.
9007
+ *
9008
+ * The Host answers with the SAVED interval on every document (see
9009
+ * `pollIntervalMs`), and that is what the card actually arms — this constant is
9010
+ * only the fallback for an older Host that cannot answer, so it stays a plain
9011
+ * number rather than a second source of truth.
9012
+ *
9013
+ * It is NOT a module-level `POLL_INTERVAL_MS` any more: the value is a setting
9014
+ * now, and a constant that the timer did not read would be exactly the kind of
9015
+ * duplicate that drifts from the control it describes.
9016
+ */
9017
+ const FALLBACK_POLL_INTERVAL_MS = 3e5;
8914
9018
  /**
8915
9019
  * Retry cadence for a status read that FAILED.
8916
9020
  *
@@ -9442,6 +9546,9 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
9442
9546
  */
9443
9547
  const [sidebarPanelOn, setSidebarPanelOn] = (0, react.useState)(void 0);
9444
9548
  const [sidebarPanelBusy, setSidebarPanelBusy] = (0, react.useState)(false);
9549
+ /** This card's own successful write of the refresh interval, if any. */
9550
+ const [pollIntervalOn, setPollIntervalOn] = (0, react.useState)(void 0);
9551
+ const [pollIntervalBusy, setPollIntervalBusy] = (0, react.useState)(false);
9445
9552
  /**
9446
9553
  * The CN gateway editor's draft (issue #220). `undefined` = "not edited", so
9447
9554
  * the field shows the SAVED value and a background refresh cannot overwrite
@@ -9705,6 +9812,18 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
9705
9812
  */
9706
9813
  const signedIn = status.status === "signed-in";
9707
9814
  /**
9815
+ * The refresh cadence to arm, from the Host's answer.
9816
+ *
9817
+ * Read off the ACTIVE region's document, which is the one the timer refreshes.
9818
+ * An absent or unrecognized value falls back to 5 minutes — the same coercion
9819
+ * the Host applies, so a hand-edited profile cannot make the card poll faster
9820
+ * than the setting allows.
9821
+ */
9822
+ const pollIntervalMs = (() => {
9823
+ const raw = "pollIntervalMs" in status ? status.pollIntervalMs : void 0;
9824
+ return typeof raw === "number" && WORKBUDDY_POLL_INTERVALS_MS.includes(raw) ? raw : FALLBACK_POLL_INTERVAL_MS;
9825
+ })();
9826
+ /**
9708
9827
  * Whether the ACTIVE region knows of any account at all.
9709
9828
  *
9710
9829
  * This is the poll's precondition in place of `status === 'signed-in'`. The
@@ -9719,7 +9838,7 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
9719
9838
  const controller = new AbortController();
9720
9839
  const timer = window.setInterval(() => {
9721
9840
  refreshUsage(activeRegion, controller.signal);
9722
- }, POLL_INTERVAL_MS);
9841
+ }, pollIntervalMs);
9723
9842
  return () => {
9724
9843
  window.clearInterval(timer);
9725
9844
  controller.abort();
@@ -9728,7 +9847,8 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
9728
9847
  open,
9729
9848
  activeRegion,
9730
9849
  refreshUsage,
9731
- status.status
9850
+ status.status,
9851
+ pollIntervalMs
9732
9852
  ]);
9733
9853
  /**
9734
9854
  * 设备头设置:卡片打开时读一次。
@@ -10085,6 +10205,35 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
10085
10205
  * see `panel-switch.ts`. Publishing only AFTER the write is verified keeps the
10086
10206
  * two from disagreeing: the row never appears for a value the Host refused.
10087
10207
  */
10208
+ /**
10209
+ * The refresh interval, read from the status document first and the settings
10210
+ * snapshot second.
10211
+ *
10212
+ * The document is the fresher of the two (the Host answers with the value it
10213
+ * actually stored), but the settings snapshot is what a save is verified
10214
+ * against, and it is also the only thing available before the first document
10215
+ * lands. Reading both, in that order, means the picker never shows a value the
10216
+ * timer is not using.
10217
+ */
10218
+ const pollIntervalValue = () => {
10219
+ if (pollIntervalOn !== void 0) return pollIntervalOn;
10220
+ const fromSettings = pollIntervalMsOf(settingsScope?.getSnapshot().value);
10221
+ if ("pollIntervalMs" in status && typeof status.pollIntervalMs === "number" && WORKBUDDY_POLL_INTERVALS_MS.includes(status.pollIntervalMs)) return status.pollIntervalMs;
10222
+ return fromSettings;
10223
+ };
10224
+ const changePollInterval = async (intervalMs) => {
10225
+ if (settingsScope === void 0) return;
10226
+ setPollIntervalBusy(true);
10227
+ try {
10228
+ await writePollIntervalMs(settingsScope, intervalMs);
10229
+ if (mounted.current) setPollIntervalOn(intervalMs);
10230
+ await refreshUsage(activeRegion);
10231
+ } catch (error) {
10232
+ if (mounted.current) setAccountError(error instanceof Error ? error.message : t("row.requestFailed"));
10233
+ } finally {
10234
+ if (mounted.current) setPollIntervalBusy(false);
10235
+ }
10236
+ };
10088
10237
  const toggleSidebarPanel = async (enabled) => {
10089
10238
  if (settingsScope === void 0) return;
10090
10239
  setSidebarPanelBusy(true);
@@ -11253,6 +11402,74 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
11253
11402
  }) : null
11254
11403
  ]
11255
11404
  });
11405
+ /**
11406
+ * The refresh cadence, as a five-option picker.
11407
+ *
11408
+ * It lives in the capability panel because it commits on the click like every
11409
+ * other control there — no Save button. A dropdown rather than a free number
11410
+ * because the offered set IS the validation: the same five values are what the
11411
+ * Host accepts, so the control cannot produce something the Host refuses.
11412
+ *
11413
+ * Placed last among the capability groups: it changes how often the plugin
11414
+ * ASKS, not what it may do, and it is the one control here whose effect is
11415
+ * purely about request volume.
11416
+ */
11417
+ const pollIntervalPreference = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
11418
+ className: "dsm-workbuddy-prefs",
11419
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
11420
+ className: "dsm-workbuddy-pref-hint",
11421
+ children: t("row.pollIntervalLead")
11422
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
11423
+ className: "dsm-workbuddy-pref dsm-workbuddy-upstream-pref",
11424
+ title: t("row.pollIntervalHint"),
11425
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
11426
+ className: "dsm-workbuddy-pref-copy",
11427
+ children: [
11428
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
11429
+ className: "dsm-workbuddy-pref-label",
11430
+ children: t("row.pollIntervalLabel")
11431
+ }),
11432
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
11433
+ className: "dsm-workbuddy-pref-hint",
11434
+ children: t("row.pollIntervalHint")
11435
+ }),
11436
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
11437
+ className: "dsm-workbuddy-credit-position",
11438
+ value: String(pollIntervalValue()),
11439
+ disabled: !canWrite || saving || poolBusy || pollIntervalBusy,
11440
+ "aria-label": t("row.pollIntervalAria"),
11441
+ onChange: (event) => {
11442
+ const next = Number(event.currentTarget.value);
11443
+ if (!WORKBUDDY_POLL_INTERVALS_MS.includes(next)) return;
11444
+ changePollInterval(next);
11445
+ },
11446
+ children: [
11447
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
11448
+ value: String(6e4),
11449
+ children: t("row.pollInterval1m")
11450
+ }),
11451
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
11452
+ value: String(3e5),
11453
+ children: t("row.pollInterval5m")
11454
+ }),
11455
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
11456
+ value: String(6e5),
11457
+ children: t("row.pollInterval10m")
11458
+ }),
11459
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
11460
+ value: String(18e5),
11461
+ children: t("row.pollInterval30m")
11462
+ }),
11463
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
11464
+ value: String(36e5),
11465
+ children: t("row.pollInterval60m")
11466
+ })
11467
+ ]
11468
+ })
11469
+ ]
11470
+ })
11471
+ })]
11472
+ });
11256
11473
  const sidebarPanelPreference = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
11257
11474
  className: "dsm-workbuddy-prefs",
11258
11475
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
@@ -12209,6 +12426,7 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
12209
12426
  channelRejectContinuePreference,
12210
12427
  dropAllThinkingPreference,
12211
12428
  sidebarPanelPreference,
12429
+ pollIntervalPreference,
12212
12430
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
12213
12431
  className: "dsm-workbuddy-prefs",
12214
12432
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
@@ -12662,28 +12880,6 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
12662
12880
  */
12663
12881
  const COMPOSER_CREDITS_REFRESH_INTERVAL_MS = 3e5;
12664
12882
  /**
12665
- * Refresh period for the panel's per-account table, while it stays open.
12666
- *
12667
- * Deliberately NOT the readout's five minutes. The table carries two things,
12668
- * and the faster-moving one decides the cadence:
12669
- *
12670
- * - the balance, which barely moves, and
12671
- * - each account's `excludedBy` ("被限流" / "模型繁忙"), which is derived from
12672
- * the pool's own cooldowns — and the SHORTEST of those is the model-scoped
12673
- * two-minute throttle (`MODEL_BUSY_COOLDOWN_MS`).
12674
- *
12675
- * At five minutes the table could state an account is 模型繁忙 long after the
12676
- * upstream let it serve again, and the pool card — which polls every 60 s
12677
- * (`POLL_INTERVAL_MS` in `WorkBuddyCard.tsx`) — would say it is fine at the same
12678
- * moment. Two surfaces disagreeing about one account is exactly the complaint
12679
- * this constant answers, so the table now converges on the card's cadence
12680
- * instead of its own.
12681
- *
12682
- * The cost is bounded and paid only while the panel is open: one `fetchCredits`
12683
- * per account per minute, the same read the card already makes when it is open.
12684
- */
12685
- const COMPOSER_ACCOUNT_REFRESH_INTERVAL_MS = 6e4;
12686
- /**
12687
12883
  * Provider routes whose credit balance this readout can show, mapped to the
12688
12884
  * region to read it from.
12689
12885
  *
@@ -12832,6 +13028,22 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
12832
13028
  const owned = provider === void 0 ? void 0 : WORKBUDDY_COMPOSER_PROVIDERS[provider];
12833
13029
  const activeRegion = region ?? owned;
12834
13030
  const [usage, setUsage] = (0, react.useState)(void 0);
13031
+ /**
13032
+ * The refresh cadence, taken from the SAME document the card polls.
13033
+ *
13034
+ * The panel used to hold its own 60s constant, and that was the whole reason
13035
+ * the two surfaces could contradict each other about one account: the card
13036
+ * re-ranked every minute while a panel opened at a different cadence drew a
13037
+ * frozen verdict. Sharing the Host's value means there is one cadence to
13038
+ * reason about, and changing it in the card changes it here too.
13039
+ *
13040
+ * An absent value (the panel opened before any document landed) falls back to
13041
+ * the same default the Host uses, so the first timer is never armed at 0.
13042
+ */
13043
+ const refreshIntervalMs = (() => {
13044
+ const raw = usage !== void 0 && "pollIntervalMs" in usage ? usage.pollIntervalMs : void 0;
13045
+ return typeof raw === "number" && WORKBUDDY_POLL_INTERVALS_MS.includes(raw) ? raw : WORKBUDDY_DEFAULT_POLL_INTERVAL_MS;
13046
+ })();
12835
13047
  const [accountCredits, setAccountCredits] = (0, react.useState)(void 0);
12836
13048
  const [switchingId, setSwitchingId] = (0, react.useState)(void 0);
12837
13049
  /**
@@ -13026,7 +13238,7 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
13026
13238
  if (cancelled) return;
13027
13239
  timer = window.setInterval(() => {
13028
13240
  fetchAccountCredits(controller.signal);
13029
- }, COMPOSER_ACCOUNT_REFRESH_INTERVAL_MS);
13241
+ }, refreshIntervalMs);
13030
13242
  });
13031
13243
  return () => {
13032
13244
  cancelled = true;
@@ -13036,7 +13248,8 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
13036
13248
  }, [
13037
13249
  open,
13038
13250
  activeRegion,
13039
- fetchAccountCredits
13251
+ fetchAccountCredits,
13252
+ refreshIntervalMs
13040
13253
  ]);
13041
13254
  (0, react.useEffect)(() => {
13042
13255
  if (!open) return void 0;
@@ -13641,6 +13854,16 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
13641
13854
  /** The provider ids this plugin registers, and the region each one serves. */
13642
13855
  const PROVIDER_REGIONS = /* @__PURE__ */ new Map([["workbuddy", "cn"], ["workbuddy-global", "global"]]);
13643
13856
  /**
13857
+ * Every provider id this plugin owns, as a list.
13858
+ *
13859
+ * Exported because on a `keyed` host the label seat is one registration PER
13860
+ * provider id — the registration side needs the same list the component uses to
13861
+ * decide "is this row mine", and two copies of it would drift. Order is
13862
+ * irrelevant to the registry (each id is its own cell); it is stable so the
13863
+ * diagnostics line reads the same on every boot.
13864
+ */
13865
+ const WORKBUDDY_PROVIDER_IDS = [...PROVIDER_REGIONS.keys()];
13866
+ /**
13644
13867
  * The region a provider id serves, or `undefined` for a provider that is not
13645
13868
  * this plugin's.
13646
13869
  *
@@ -13960,6 +14183,17 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
13960
14183
  * any other contributor (name + price + promotion + load + new-model mark), so
13961
14184
  * it should be the one that takes the cell when several want it.
13962
14185
  *
14186
+ * WHAT CHANGES WHEN THE HOST KEYS THE SLOT — and why the number stays. On a host
14187
+ * that declares this slot `keyed`, the seat is registered once per provider id
14188
+ * (see `modelLabelSeats` in `./model-label-seat.ts`), each `key` is its own
14189
+ * cell, and priority stops deciding WHO IS VISIBLE: qoder's `-101` and trae's
14190
+ * `-102` no longer share a cell with this `-105`, so none of the three can
14191
+ * shadow another. Priority keeps exactly one meaning inside a cell — the
14192
+ * tie-breaker between two registrations that claim the SAME provider id, where
14193
+ * an equal value throws and the lowest renders. The value is therefore not
14194
+ * lowered to keep winning an auction that no longer happens; it is kept because
14195
+ * it is this plugin's rank for its own rows.
14196
+ *
13963
14197
  * WHAT THIS PLUGIN DELIBERATELY DOES NOT DO. It does not read the slot ledger,
13964
14198
  * does not look for another plugin's registration, and does not render another
13965
14199
  * plugin's component. Foreign rows get the plain catalog name PLUS the model's
@@ -13996,6 +14230,21 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
13996
14230
  * provider published one. There is no forwarding and no consultation of other
13997
14231
  * plugins' registrations — see `MODEL_LABEL_PRIORITY`.
13998
14232
  *
14233
+ * WHY THE FOREIGN BRANCH STILL EXISTS ON A KEYED HOST. It is unreachable there —
14234
+ * each seat is registered under one provider id, the owner dispatches with
14235
+ * `entryKey: provider.id`, so a lookup only ever finds the entry whose key
14236
+ * matches the row it is drawing. But ONE build serves both contracts
14237
+ * (`./model-label-seat.ts` derives the seats from the host's declaration), and
14238
+ * on a `single` host this branch is not just reachable, it is the whole row:
14239
+ * that host renders one winner for every provider. Deleting it would fix the
14240
+ * keyed case by breaking the single one.
14241
+ *
14242
+ * Its continued presence is therefore also the cheapest possible check that the
14243
+ * seat keys are right: on a keyed host, reaching this branch with a WorkBuddy
14244
+ * provider id means a seat was registered under the wrong key, and the row has
14245
+ * silently degraded to the host's fallback — visible as a missing load badge on
14246
+ * exactly those rows, nowhere else.
14247
+ *
13999
14248
  * @param props - The host's model identity and the placement of this label.
14000
14249
  * @returns The catalog name, the promotion chip when one holds, the load badge
14001
14250
  * when the probe reported one, or a sibling's badge on a foreign row.
@@ -14085,6 +14334,114 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
14085
14334
  };
14086
14335
  }
14087
14336
  //#endregion
14337
+ //#region src/client/model-label-seat.ts
14338
+ /**
14339
+ * Read the declared kind of a slot, or `undefined` when it is not declared yet.
14340
+ *
14341
+ * `spec()` is the documented read-only accessor (`SlotRegistry.spec`), present
14342
+ * on 0.1.7 and on 0.2.2. It is also the only way to learn the kind: the
14343
+ * declaration lives in the host package, and a plugin's own `SlotMap`
14344
+ * augmentation says what this plugin HOPES the slot is, not what the running
14345
+ * host declared.
14346
+ *
14347
+ * Anything unexpected — no `spec` method on an older line, a throw from a
14348
+ * service that is not ready, a kind this build does not know — returns
14349
+ * `undefined`, and the caller falls back to the single-cell shape. That is the
14350
+ * conservative direction: it is what every released version of this plugin
14351
+ * already does.
14352
+ *
14353
+ * @param slots - The `slots` service (typed loosely: the accessor is optional).
14354
+ * @param key - The slot key to inspect.
14355
+ * @returns The declared kind, or `undefined`.
14356
+ */
14357
+ function declaredSlotKind(slots, key) {
14358
+ const face = slots;
14359
+ if (face === void 0 || typeof face.spec !== "function") return void 0;
14360
+ let spec;
14361
+ try {
14362
+ spec = face.spec(key);
14363
+ } catch {
14364
+ return;
14365
+ }
14366
+ const kind = spec?.kind;
14367
+ if (kind === "single" || kind === "list" || kind === "keyed" || kind === "chain") return kind;
14368
+ }
14369
+ /**
14370
+ * The registrations this plugin should make for the model-label seat.
14371
+ *
14372
+ * `keyed` yields ONE seat per provider id: each is its own cell, each renders
14373
+ * only the rows whose owner props carry that provider id, and a provider this
14374
+ * plugin does not own falls through to the owner's own fallback (the catalog
14375
+ * name, plus that model's `badge` on hosts that have one).
14376
+ *
14377
+ * Every other kind — including `undefined`, i.e. a host that cannot be
14378
+ * inspected — yields the single historical seat. That is not a degraded mode:
14379
+ * it is what `single` requires, and on a not-yet-declared slot it is what the
14380
+ * inject callback is about to find.
14381
+ *
14382
+ * An empty provider list under `keyed` would silently disable the label, so it
14383
+ * falls back to the single seat instead: a wrong-shaped registration that still
14384
+ * draws something beats a correct-shaped registration that draws nothing.
14385
+ *
14386
+ * @param params - Slot key, declared kind, this plugin's provider ids, priority.
14387
+ * @returns One or more `register()` option objects, in registration order.
14388
+ */
14389
+ function modelLabelSeats(params) {
14390
+ const { name, kind, providerIds, priority } = params;
14391
+ if (kind === "list" || kind === "chain") return [];
14392
+ if (kind === "keyed" && providerIds.length > 0) return providerIds.map((id) => ({
14393
+ name,
14394
+ key: id,
14395
+ priority
14396
+ }));
14397
+ return [{
14398
+ name,
14399
+ priority
14400
+ }];
14401
+ }
14402
+ /**
14403
+ * Claim every planned seat, atomically, and hand back ONE disposer.
14404
+ *
14405
+ * WHY ATOMIC. The seat list is 2-3 entries on a `keyed` host, and `register()`
14406
+ * can throw on any ONE of them — a rival plugin claiming the same provider id at
14407
+ * the same priority, or the declaration collapsing mid-loop. A plain `.map()`
14408
+ * would then leave the earlier seats landed on the ledger with their disposers
14409
+ * unreachable (they were only ever held by the array that the throw discarded),
14410
+ * which is worse than failing outright: the component stays mounted, the caller
14411
+ * believes registration failed, and nothing will ever release those cells. On a
14412
+ * `single` host it also means the identity keeps a live entry that the next
14413
+ * `inject` re-run cannot displace without a priority clash.
14414
+ *
14415
+ * So a partial failure is rolled back in reverse order before the error is
14416
+ * rethrown, exactly as if it had never been attempted. The rethrow is important:
14417
+ * each caller already has a catch that logs, and swallowing here would hide the
14418
+ * refusal from the diagnostics that exist to explain it.
14419
+ *
14420
+ * A disposal that itself throws must not mask the original error, hence the
14421
+ * inner catch — the registry treats a second dispose as a no-op, and a broken
14422
+ * one must not turn one failure into a crash.
14423
+ *
14424
+ * @param seats - The plan from {@link modelLabelSeats}, in registration order.
14425
+ * @param register - Claims one seat and returns its disposer.
14426
+ * @returns One disposer that releases every seat, in reverse registration order.
14427
+ */
14428
+ function registerModelLabelSeats(seats, register) {
14429
+ const claimed = [];
14430
+ try {
14431
+ for (const seat of seats) claimed.push(register(seat));
14432
+ } catch (error) {
14433
+ for (const dispose of [...claimed].reverse()) try {
14434
+ dispose();
14435
+ } catch {}
14436
+ throw error;
14437
+ }
14438
+ return () => {
14439
+ for (const dispose of [...claimed].reverse()) try {
14440
+ dispose();
14441
+ } catch {}
14442
+ };
14443
+ }
14444
+ //#endregion
14088
14445
  //#region src/client/CodebuddyLive.tsx
14089
14446
  /**
14090
14447
  * The composer pill that says what the CodeBuddy CLI route is doing RIGHT NOW.
@@ -14619,6 +14976,7 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
14619
14976
  "row.transferNoToken": "no token in this record",
14620
14977
  "row.transferCancel": "Cancel",
14621
14978
  "row.transferError": "Transfer failed: {message}",
14979
+ "row.transferNoService": "Could not reach the local plugin service ({size} KiB sent). The file may be too large, or the service may be restarting — try again, and if it keeps failing, trim the file and retry.",
14622
14980
  "row.poolTitle": "Account pool",
14623
14981
  "row.poolNoCandidate": "No account in this pool can be used right now.",
14624
14982
  "row.poolNoCandidateHint": "Members are rate-limited, out of credits, rejected, or unreachable. Rate limits, drained quotas and transient failures return to the pool on their own — at the time the upstream states, or after a 30-minute fallback. Only a rejected credential needs a new sign-in.",
@@ -14878,6 +15236,15 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
14878
15236
  "row.cnBaseCleared": "Back to the built-in CN gateway.",
14879
15237
  "row.diagCnBase": "CN gateway",
14880
15238
  "row.diagCnBaseDefault": "built-in (copilot.tencent.com)",
15239
+ "row.pollIntervalLead": "Refresh frequency",
15240
+ "row.pollIntervalLabel": "Refresh the account table",
15241
+ "row.pollIntervalHint": "How often the card re-reads credits and check-in state. One refresh costs a credits read plus a check-in read per pooled account, so this is the setting that decides the plugin's upstream request volume. The composer account panel follows this value, so the two never disagree about one account. Takes effect on the next poll — no Save needed.",
15242
+ "row.pollIntervalAria": "Refresh frequency for the account table",
15243
+ "row.pollInterval1m": "Every 1 minute",
15244
+ "row.pollInterval5m": "Every 5 minutes (default)",
15245
+ "row.pollInterval10m": "Every 10 minutes",
15246
+ "row.pollInterval30m": "Every 30 minutes",
15247
+ "row.pollInterval60m": "Every 60 minutes",
14881
15248
  "row.sidebarPanelLabel": "Show WorkBuddy in the sidebar",
14882
15249
  "row.sidebarPanelHint": "Adds a WorkBuddy row to the DSH sidebar that opens this card as a full page. Off by default: the row takes a global sidebar slot shared by every installed plugin, and the Plugins page already reaches the same content. Takes effect on the click — no Save needed — and switching it off while the page is open returns you to the conversation.",
14883
15250
  "row.cliBridgeModelLabel": "CLI model",
@@ -15163,6 +15530,7 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
15163
15530
  "row.transferNoToken": "此记录没有 token",
15164
15531
  "row.transferCancel": "取消",
15165
15532
  "row.transferError": "传输失败:{message}",
15533
+ "row.transferNoService": "与本地插件服务通信失败(本次发送 {size} KiB)。可能是文件过大,或服务正在重启——请重试;若持续失败,请精简文件后再导入。",
15166
15534
  "row.poolTitle": "账号池",
15167
15535
  "row.poolNoCandidate": "账号池里目前没有可用的账号。",
15168
15536
  "row.poolNoCandidateHint": "成员要么在限流冷却中、要么积分耗尽、要么凭据被拒、要么上游无响应。限流、积分耗尽与瞬时故障都会自动回池——按上游给出的恢复时间,没给时间就按 30 分钟兜底,不需要你操作;只有「凭据被拒」需要重新登录。",
@@ -15422,6 +15790,15 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
15422
15790
  "row.cnBaseCleared": "已回到内置 CN 网关。",
15423
15791
  "row.diagCnBase": "CN 网关",
15424
15792
  "row.diagCnBaseDefault": "内置(copilot.tencent.com)",
15793
+ "row.pollIntervalLead": "刷新频率",
15794
+ "row.pollIntervalLabel": "刷新账号表",
15795
+ "row.pollIntervalHint": "卡片多久重读一次积分与签到状态。每次刷新要为池内每个账号各读一次积分和一次签到状态,所以这一项决定插件的上游请求量。输入框的账号面板跟随同一个值,两处不会对同一个账号给出不同说法。下一次轮询即生效,不用保存。",
15796
+ "row.pollIntervalAria": "账号表的刷新频率",
15797
+ "row.pollInterval1m": "每 1 分钟",
15798
+ "row.pollInterval5m": "每 5 分钟(默认)",
15799
+ "row.pollInterval10m": "每 10 分钟",
15800
+ "row.pollInterval30m": "每 30 分钟",
15801
+ "row.pollInterval60m": "每 60 分钟",
15425
15802
  "row.sidebarPanelLabel": "在侧边栏显示 WorkBuddy",
15426
15803
  "row.sidebarPanelHint": "在 DSH 侧边栏加一个 WorkBuddy 行,点开就是这张卡片的整页版。默认关闭:这一行占的是所有插件共用的全局侧边栏座位,而「插件」页本来就能看到同样的内容。点一下即生效,不用保存;页面开着时关掉它,会直接回到对话。",
15427
15804
  "row.cliBridgeModelLabel": "CLI 模型",
@@ -15795,7 +16172,11 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
15795
16172
  * load stays silent — a warning that fires when nothing is wrong stops being
15796
16173
  * read.
15797
16174
  *
15798
- * Exported for the test; never called outside `rebindSlots`.
16175
+ * Exported for the test. Called from `rebindSlots` (once, before the inject
16176
+ * callback exists) and again from inside the inject callback (the only place
16177
+ * that can observe a DEFERRED refusal or a late-arriving `slotKind`). Two
16178
+ * callers, one state object: the later call always supersedes the earlier, and
16179
+ * the warning is deduplicated so one failure still produces one line.
15799
16180
  *
15800
16181
  * @param state - What the registration path recorded.
15801
16182
  * @param target - Where to publish; defaults to the global object.
@@ -15834,6 +16215,19 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
15834
16215
  rebinds: state.rebinds,
15835
16216
  failure: state.failure,
15836
16217
  claimed: state.dispose !== void 0,
16218
+ /**
16219
+ * Which shape the host's declaration allowed, and how many seats were
16220
+ * claimed for it.
16221
+ *
16222
+ * Without these two the picker has ONE symptom ("no badges") for two very
16223
+ * different situations: a `single` host where an equal-priority rival won
16224
+ * the cell, and a `keyed` host where a provider id was missed. `slotKind`
16225
+ * says which contract was in force; `seats` says what this plugin did with
16226
+ * it. `<provider count>` on a keyed host and `1` on a single host are the
16227
+ * only healthy pairs.
16228
+ */
16229
+ slotKind: state.slotKind,
16230
+ seats: state.seats,
15837
16231
  at: Date.now()
15838
16232
  };
15839
16233
  try {
@@ -15841,9 +16235,13 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
15841
16235
  } catch {
15842
16236
  return;
15843
16237
  }
15844
- if (state.failure !== void 0) try {
15845
- target.warn?.("[dsh-connect-workbuddy] the model-picker badges could not be registered: " + state.failure);
15846
- } catch {}
16238
+ if (state.failure !== void 0) {
16239
+ const warned = target;
16240
+ if (warned.__dshWorkBuddyModelLabelWarned__ !== state.failure) try {
16241
+ target.warn?.("[dsh-connect-workbuddy] the model-picker badges could not be registered: " + state.failure);
16242
+ warned.__dshWorkBuddyModelLabelWarned__ = state.failure;
16243
+ } catch {}
16244
+ }
15847
16245
  return view;
15848
16246
  }
15849
16247
  function apply(ctx) {
@@ -16042,6 +16440,18 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
16042
16440
  * ordering, the measured evidence, and the deliberate absence of any
16043
16441
  * inter-plugin coordination (project invariant, `docs/DESIGN.md` §零).
16044
16442
  *
16443
+ * HOW MANY SEATS, AND WHY THAT IS READ AT MOUNT. `single` holds one cell, so
16444
+ * exactly one registration is legal there. A `keyed` host gives each
16445
+ * `options.key` its own cell, and one cell per provider id is what this
16446
+ * plugin actually wants: it then draws its OWN rows and nothing else, qoder
16447
+ * and trae stop sharing a cell with it, and a provider with no contribution
16448
+ * falls through to the host's own fallback. Which of the two shapes is
16449
+ * legal is the HOST's declaration, not this plugin's choice, so the kind is
16450
+ * read from `ctx.slots.spec(...)` at mount and the seat list is derived from
16451
+ * it (`./model-label-seat.ts`). One build therefore serves both lines — and
16452
+ * a host that cannot be inspected gets the single seat, which is what every
16453
+ * released version of this plugin already does.
16454
+ *
16045
16455
  * THE COST IS PAID ON ANOTHER PLUGIN'S ROWS, and it is worth stating where
16046
16456
  * the registration happens: holding this cell means the host's own
16047
16457
  * `dsh-client-ui-deepseek-model-label-1017` badge is NOT rendered on the
@@ -16049,7 +16459,9 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
16049
16459
  * to fix by inspecting the slot ledger — it is the price of §零, recorded in
16050
16460
  * `docs/DESIGN.md` and argued in the 5.8.2 CHANGELOG. Issue #138 is a user
16051
16461
  * meeting that price for the first time; the disposition is to state it
16052
- * plainly rather than to coordinate at runtime.
16462
+ * plainly rather than to coordinate at runtime. On a `keyed` host that price
16463
+ * is not paid at all: each provider keeps its own cell, so 1017's badge
16464
+ * returns to the DeepSeek rows without anyone negotiating.
16053
16465
  */
16054
16466
  /**
16055
16467
  * WHY THIS RECORDS AN OUTCOME, not just a disposer.
@@ -16074,19 +16486,48 @@ ${u} ${p}-pool .sw input:checked+.sw-track::after{transform:translateX(16px)}
16074
16486
  const modelLabelVerdict = () => modelLabelVerdictOf(modelLabelState);
16075
16487
  const registerModelLabel = () => {
16076
16488
  modelLabelState.askedAt = Date.now();
16489
+ /**
16490
+ * The refusal path, shared by the eager and the deferred call.
16491
+ *
16492
+ * REPUBLISHES, and that is not cosmetic. `rebindSlots` publishes once, and
16493
+ * on the normal boot it publishes BEFORE this callback exists: `inject()`
16494
+ * defers the callback until `conversation.input.model` mounts, so the
16495
+ * published view is a snapshot of a registration that has not happened
16496
+ * yet. Without this line the failure lands in a state object that nothing
16497
+ * reads again, and `window.__dshWorkBuddyModelLabel__` keeps
16498
+ * `failure: undefined` with verdict `parent-not-mounted` — the exact
16499
+ * opposite of the truth, in the surface built to state it.
16500
+ */
16501
+ const refuse = (error) => {
16502
+ const message = error instanceof Error ? error.message : String(error);
16503
+ modelLabelState.failure = message;
16504
+ console.error("[dsh-connect-workbuddy] model label slot failed to register (host provider unaffected):", error);
16505
+ publishModelLabelState(modelLabelState);
16506
+ };
16077
16507
  try {
16078
16508
  return ctx.slots.inject("conversation.input.model.label", () => {
16079
16509
  modelLabelState.injectRanAt = Date.now();
16080
- return ctx.slots.register({
16510
+ const kind = declaredSlotKind(ctx.slots, "conversation.input.model.label");
16511
+ const seats = modelLabelSeats({
16081
16512
  name: "conversation.input.model.label",
16513
+ kind,
16514
+ providerIds: WORKBUDDY_PROVIDER_IDS,
16082
16515
  priority: MODEL_LABEL_PRIORITY
16083
- }, WorkBuddyModelLabel);
16516
+ });
16517
+ const registry = ctx.slots;
16518
+ try {
16519
+ const dispose = registerModelLabelSeats(seats, (seat) => registry.register(seat, WorkBuddyModelLabel));
16520
+ modelLabelState.slotKind = kind ?? "unknown";
16521
+ modelLabelState.seats = seats.length;
16522
+ publishModelLabelState(modelLabelState);
16523
+ return dispose;
16524
+ } catch (error) {
16525
+ refuse(error);
16526
+ return () => {};
16527
+ }
16084
16528
  });
16085
16529
  } catch (error) {
16086
- const message = error instanceof Error ? error.message : String(error);
16087
- modelLabelState.failure = message;
16088
- console.error("[dsh-connect-workbuddy] model label slot failed to register (host provider unaffected):", error);
16089
- return;
16530
+ return refuse(error);
16090
16531
  }
16091
16532
  };
16092
16533
  /**