dsh-wtq-pool 0.0.0-stage → 1.0.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 ADDED
@@ -0,0 +1,712 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "dsh-wtq-pool",
3
+ factory: (require) => {
4
+ var module = { exports: {} };
5
+ var exports = module.exports;
6
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
+ //#region \0rolldown/runtime.js
8
+ var __create = Object.create;
9
+ var __defProp = Object.defineProperty;
10
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
+ var __getOwnPropNames = Object.getOwnPropertyNames;
12
+ var __getProtoOf = Object.getPrototypeOf;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
16
+ key = keys[i];
17
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
18
+ get: ((k) => from[k]).bind(null, key),
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ return to;
23
+ };
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
25
+ value: mod,
26
+ enumerable: true
27
+ }) : target, mod));
28
+ //#endregion
29
+ let react = require("react");
30
+ react = __toESM(react, 1);
31
+ //#region src/panel-route.ts
32
+ /**
33
+ * The panel's route prefix.
34
+ *
35
+ * Both halves of this plugin need the same location: the host half mounts the
36
+ * panel's routes under it, and the settings card frames that same address.
37
+ * Sharing the one literal is what stops the two from drifting into a frame that
38
+ * points at nothing.
39
+ *
40
+ * @module dsh-wtq-pool/panel-route
41
+ */
42
+ /** The route prefix every panel route sits under. */
43
+ const PANEL_BASE = "/plugins/dsh-wtq-pool";
44
+ //#endregion
45
+ //#region src/client/panel-url.ts
46
+ /** The panel's URL, carrying the appearance the embedding page is showing. */
47
+ function panelUrl(appearance) {
48
+ const params = new URLSearchParams({
49
+ base: appearance.base === "dark" ? "dark" : "light",
50
+ lang: appearance.lang.toLowerCase().startsWith("en") ? "en" : "zh-CN"
51
+ });
52
+ return `${PANEL_BASE}/panel?${params.toString()}`;
53
+ }
54
+ //#endregion
55
+ //#region src/client/composer.tsx
56
+ /**
57
+ * The composer credit readout.
58
+ *
59
+ * Sits in the composer's tool row and shows the balance of the account that will
60
+ * serve the next request, but only while the selected model belongs to this
61
+ * plugin. That condition is the point: the row is shared with the shell's own
62
+ * controls, so a plugin that drew there unconditionally would be occupying space
63
+ * the user did not ask it to occupy. The host hands every entry the session's
64
+ * selection through `useProjection('modelSelection')`, which is what the model
65
+ * picker writes and what the next request will use, so the readout cannot
66
+ * disagree with the model actually in effect.
67
+ *
68
+ * Everything shown comes from the plugin's own host half over the panel bridge:
69
+ * this module makes no upstream call of its own and never reads a token.
70
+ *
71
+ * @module dsh-wtq-pool/client/composer
72
+ */
73
+ const composerZh = {
74
+ "composer.title": "账号积分",
75
+ "composer.account": "账号",
76
+ "composer.balance": "积分",
77
+ "composer.switching": "切换中…",
78
+ "composer.click": "点击切换账号",
79
+ "composer.refresh": "刷新积分",
80
+ "composer.refreshing": "正在刷新…",
81
+ "composer.refused": "这个账号无法切换,刷新后重试",
82
+ "composer.saved": "已设为优先;积分面板暂不可用,恢复后自动生效",
83
+ "composer.unavailable": "已设为优先,但该账号现在不能服务(冷却或已停用),恢复后自动生效",
84
+ "composer.planQuota": "套餐",
85
+ "composer.addOnQuota": "资源包",
86
+ "composer.never": "不过期",
87
+ "composer.monthly": "月度",
88
+ "composer.days": "天"
89
+ };
90
+ const composerEn = {
91
+ "composer.title": "Account credits",
92
+ "composer.account": "Account",
93
+ "composer.balance": "Credits",
94
+ "composer.switching": "Switching…",
95
+ "composer.click": "Click to switch account",
96
+ "composer.refresh": "Refresh credits",
97
+ "composer.refreshing": "Refreshing…",
98
+ "composer.refused": "That account cannot be switched; refresh and try again",
99
+ "composer.saved": "Set as preferred; the credits panel is unavailable right now and it takes over once it recovers",
100
+ "composer.unavailable": "Set as preferred, but that account cannot serve right now (cooling or switched off); it takes over once it recovers",
101
+ "composer.planQuota": "Plan",
102
+ "composer.addOnQuota": "Add-on",
103
+ "composer.never": "never expires",
104
+ "composer.monthly": "monthly",
105
+ "composer.days": " days"
106
+ };
107
+ /**
108
+ * How often the readout re-reads a cached balance, once it has one.
109
+ *
110
+ * A credit balance moves on the scale of model calls, not seconds, and the host
111
+ * answers from the account probe's own cache - so this is a poll of a cached
112
+ * value, not an upstream read per tick. The host half is what guarantees that:
113
+ * `xd.composerPoints` answers from cache, and the only network it can start is
114
+ * the one background refresh that fills a stale cache.
115
+ */
116
+ const REFRESH_INTERVAL_MS = 3e5;
117
+ /**
118
+ * How often the readout asks again while it has no number yet.
119
+ *
120
+ * The host answers `total: null` for an account whose credits it has not read
121
+ * yet - the first seconds after a session starts, while the account probe is
122
+ * still filling its cache. That is "not read yet", not "no credits": treating it
123
+ * as final would leave the readout showing a dash for a full refresh interval,
124
+ * which is the whole of the time the user is looking at it.
125
+ */
126
+ const WARMUP_INTERVAL_MS = 5e3;
127
+ /** How long the faster cadence may run before the readout settles down. */
128
+ const WARMUP_WINDOW_MS = 12e4;
129
+ /**
130
+ * The id the readout registers under.
131
+ *
132
+ * Stable and namespaced so a reload replaces its own entry rather than adding a
133
+ * second one beside it.
134
+ */
135
+ const COMPOSER_SLOT_ID = "dsh-wtq-pool-composer-points";
136
+ function packageText(pack, t) {
137
+ const name = pack.packageName || t(pack.nameKey === "credits.planQuota" ? "composer.planQuota" : pack.nameKey === "credits.addOnQuota" ? "composer.addOnQuota" : "composer.balance");
138
+ const at = typeof pack.roundExpiresAtMs === "number" ? pack.roundExpiresAtMs : pack.expiresAtMs;
139
+ let when = "";
140
+ if (typeof at === "number" && at > Date.now()) {
141
+ const date = new Date(at);
142
+ when = date.getMonth() + 1 + "/" + date.getDate();
143
+ } else if (pack.neverExpires === true) when = t("composer.never");
144
+ else if (pack.monthly === true) when = t("composer.monthly");
145
+ else if (typeof pack.validDays === "number") when = pack.validDays + t("composer.days");
146
+ const remain = typeof pack.remain === "number" ? formatCredits(pack.remain) : "—";
147
+ return name + " " + remain + (when === "" ? "" : " · " + when);
148
+ }
149
+ /** The selected route, out of the host's `modelSelection` projection. */
150
+ function selectionOf(projection) {
151
+ if (projection === null || typeof projection !== "object") return void 0;
152
+ const row = projection.next ?? projection.lastUsed;
153
+ if (row === null || typeof row !== "object") return void 0;
154
+ const provider = row.provider;
155
+ const model = row.model;
156
+ if (typeof provider !== "string" || provider === "") return void 0;
157
+ if (typeof model !== "string" || model === "") return void 0;
158
+ return {
159
+ provider,
160
+ model
161
+ };
162
+ }
163
+ /**
164
+ * How long one panel-channel call may take from the client side.
165
+ *
166
+ * The refresh channel spends up to its own server-side budget re-probing
167
+ * accounts; everything else answers from cache. The figure covers the former
168
+ * with margin, so a cache read never times out while a real pass still fits.
169
+ */
170
+ const INVOKE_TIMEOUT_MS = 2e4;
171
+ /**
172
+ * Ask the plugin's own host half one channel, over the panel bridge's route.
173
+ *
174
+ * The fetch carries its own deadline: the host side bounds what a channel may
175
+ * spend, but the panel bridge itself imposes no call-length cap, so a stuck
176
+ * route would otherwise leave the readout's promise pending forever.
177
+ */
178
+ async function invoke(channel, payload) {
179
+ const response = await fetch(`${PANEL_BASE}/invoke`, {
180
+ method: "POST",
181
+ headers: { "Content-Type": "application/json" },
182
+ credentials: "same-origin",
183
+ body: JSON.stringify({
184
+ channel,
185
+ payload
186
+ }),
187
+ signal: AbortSignal.timeout(INVOKE_TIMEOUT_MS)
188
+ });
189
+ const body = await response.json().catch(() => ({}));
190
+ if (!response.ok) throw new Error(typeof body.error === "string" ? body.error : `HTTP ${response.status}`);
191
+ return body.result ?? {};
192
+ }
193
+ /** Group the digits so a four-figure balance stays readable in a narrow row. */
194
+ function formatCredits(value) {
195
+ return Number.isInteger(value) ? value.toLocaleString() : value.toLocaleString(void 0, { maximumFractionDigits: 2 });
196
+ }
197
+ /** The one balance the readout shows, or undefined when there is none yet. */
198
+ function balanceOf(document) {
199
+ return document !== null && typeof document.total === "number" ? document.total : void 0;
200
+ }
201
+ /** The margin kept between the popup and the edge of the window. */
202
+ const PANEL_MARGIN = 8;
203
+ /** The popup's own width cap, in px. */
204
+ const PANEL_MAX_WIDTH = 360;
205
+ /**
206
+ * The width the popup is padded out to, in px.
207
+ *
208
+ * The stylesheet sizes the box to its contents, and a real row is only an
209
+ * address and a balance, so the box collapsed to roughly 220px and read as
210
+ * cramped next to the composer. A floor keeps that space without forcing the
211
+ * box wide for rows that do not need it.
212
+ */
213
+ const PANEL_MIN_WIDTH = 280;
214
+ /** How tall the popup is allowed to get, in px. */
215
+ const PANEL_MAX_HEIGHT = 320;
216
+ /**
217
+ * Where the popup sits, given its trigger's box.
218
+ *
219
+ * Anchored above the trigger and right-aligned to it - the composer row is at
220
+ * the bottom of the window, so above is where the room is. Flipped below when
221
+ * the trigger is near the top and the popup would not fit above it: a fixed
222
+ * position is not scrolled into view by anything, so the rows above the trigger
223
+ * would simply be cut off, and so would the popup's own first rows.
224
+ *
225
+ * Right-aligned by pinning `right`, not by a width this code would have to
226
+ * guess: the stylesheet sizes the box to its contents, so a two-column table of
227
+ * account and balance costs what it needs. A left edge plus a fixed width could
228
+ * only be right-aligned by knowing that width here, and the fixed 360px box it
229
+ * produced sat around rows that never filled it.
230
+ *
231
+ * The cap counts the column the right anchor already took, so the box stops at
232
+ * the window's left edge. Subtracting only the margin let a wide box hang past
233
+ * that edge whenever the trigger sat away from the right one.
234
+ */
235
+ function positionStyle(rect) {
236
+ const above = rect.top - PANEL_MARGIN >= PANEL_MAX_HEIGHT;
237
+ const right = typeof window === "undefined" ? PANEL_MARGIN : Math.max(PANEL_MARGIN, window.innerWidth - rect.right);
238
+ const width = typeof window === "undefined" ? PANEL_MAX_WIDTH : Math.max(0, Math.min(PANEL_MAX_WIDTH, window.innerWidth - right - PANEL_MARGIN));
239
+ const floor = Math.min(PANEL_MIN_WIDTH, width);
240
+ return {
241
+ right: right + "px",
242
+ minWidth: floor + "px",
243
+ maxWidth: width + "px",
244
+ top: (above ? rect.top - PANEL_MARGIN : rect.bottom + PANEL_MARGIN) + "px",
245
+ transform: above ? "translateY(-100%)" : void 0
246
+ };
247
+ }
248
+ const CSS = `
249
+ .xd-points{position:relative;display:inline-flex;align-items:center;min-width:0}
250
+ .xd-points-btn{border:0;background:transparent;color:inherit;font:inherit;font-size:12px;line-height:1;display:inline-flex;align-items:center;gap:5px;padding:4px 7px;border-radius:999px;cursor:pointer;max-width:220px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
251
+ .xd-points-btn:hover{background:var(--dsw-alias-bg-layer-3,rgba(127,127,127,.12))}
252
+ .xd-points-mark{display:inline-block;width:6px;height:6px;flex:0 0 auto;border-radius:50%;background:var(--dsw-alias-state-success-primary,#4f9f7c)}
253
+ .xd-points-panel{position:fixed;z-index:40;box-sizing:border-box;width:max-content;max-width:${PANEL_MAX_WIDTH}px;max-height:${PANEL_MAX_HEIGHT}px;overflow:auto;padding:8px;border-radius:12px;background:var(--dsw-alias-bg-layer-2,#1c1d21);color:var(--dsw-alias-label-primary,#e8e8ea);box-shadow:0 8px 28px rgba(0,0,0,.28);border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.25))}
254
+ .xd-points-table{width:100%;border-collapse:collapse;font-size:11px;line-height:1.4}
255
+ .xd-points-table th{text-align:left;font-weight:600;padding:4px 6px;color:var(--dsw-alias-label-tertiary,#8b8d93)}
256
+ .xd-points-table td{padding:4px 6px;vertical-align:top}
257
+ /* The row reuses the trigger's button, which is sized for a chip standing alone
258
+ in the composer: its 12px type, 1px leading and 220px cap all fight the cell,
259
+ and its padding would stack on the cell's and double the row's height. Those
260
+ are restated for the table, so the row follows the popup's own type and a long
261
+ account name is bounded by the cell instead of stretching the panel. */
262
+ .xd-points-table .xd-points-btn{font-size:inherit;line-height:inherit;padding:0;max-width:250px}
263
+ /* The selected row's name is a disabled button. The hosts disagree about how to
264
+ dim one - PI-Desktop has a global button:disabled rule that fades it, DeepSeek
265
+ Harness has none - so the fade is stated here and both read the same. */
266
+ .xd-points-table .xd-points-btn:disabled{opacity:.5}
267
+ /* A fixed green rather than the host's success token: that one resolves to a
268
+ saturated #22c55e here, which reads brighter than the same dot in the
269
+ PI-Desktop build of this plugin. The two panels are one product, so they carry
270
+ one colour. */
271
+ .xd-points-dot{display:inline-block;width:6px;height:6px;margin-right:6px;border-radius:50%;background:#4f9f7c;vertical-align:middle}
272
+ .xd-points-row{cursor:pointer}
273
+ .xd-points-row:hover{background:var(--dsw-alias-bg-layer-3,rgba(127,127,127,.12))}
274
+ .xd-points-row.is-active{cursor:default}
275
+ .xd-points-packs{margin:2px 0 0;padding:0;list-style:none;color:var(--dsw-alias-label-tertiary,#8b8d93)}
276
+ .xd-points-bar{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:6px}
277
+ .xd-points-refresh{border:0;background:transparent;color:var(--dsw-alias-label-tertiary,#8b8d93);font:inherit;font-size:12px;padding:3px 8px;border-radius:999px;cursor:pointer}
278
+ .xd-points-refresh:hover:not(:disabled){background:var(--dsw-alias-bg-layer-3,rgba(127,127,127,.12));color:var(--dsw-alias-label-primary,#e8e8ea)}
279
+ .xd-points-refresh:disabled{opacity:.5;cursor:default}
280
+ `;
281
+ /**
282
+ * Inject the readout's stylesheet once per document.
283
+ *
284
+ * Keyed on the tag's own data attribute so a plugin reload does not stack a
285
+ * second copy, and guarded because the module is evaluated where a document may
286
+ * not exist at all.
287
+ */
288
+ function injectStyle() {
289
+ if (typeof document === "undefined") return;
290
+ const id = "dsh-wtq-pool/composer-points.css";
291
+ if (document.querySelector(`style[data-plugin-css="${id}"]`) !== null) return;
292
+ const tag = document.createElement("style");
293
+ tag.dataset["plugin"] = "dsh-wtq-pool";
294
+ tag.dataset["pluginCss"] = id;
295
+ tag.textContent = CSS;
296
+ document.head.appendChild(tag);
297
+ }
298
+ injectStyle();
299
+ /**
300
+ * The readout.
301
+ *
302
+ * Returns nothing at all - not a hidden node - while the switch is off or the
303
+ * selected model is another plugin's. The row is shared, so the honest state is
304
+ * to be absent from it.
305
+ */
306
+ function ComposerPoints(props) {
307
+ const t = (key) => {
308
+ return (typeof document !== "undefined" && document.documentElement.lang.toLowerCase().startsWith("en") ? composerEn : composerZh)[key] ?? composerEn[key] ?? key;
309
+ };
310
+ const useProjection = props.useProjection;
311
+ const selection = selectionOf(useProjection === void 0 ? void 0 : useProjection("modelSelection"));
312
+ const provider = selection?.provider ?? "";
313
+ const model = selection?.model ?? "";
314
+ const route = provider + "\n" + model;
315
+ const routeRef = react.useRef({ route });
316
+ if (routeRef.current.route !== route) routeRef.current = { route };
317
+ const [points, setPoints] = react.useState(null);
318
+ const [busy, setBusy] = react.useState(false);
319
+ const [refreshing, setRefreshing] = react.useState(false);
320
+ const [open, setOpen] = react.useState(false);
321
+ const [errorFor, setErrorFor] = react.useState("");
322
+ const [error, setError] = react.useState("");
323
+ const rootRef = react.useRef(null);
324
+ const panelRef = react.useRef(null);
325
+ const restartPollRef = react.useRef(() => {});
326
+ react.useEffect(() => {
327
+ if (provider === "" || model === "") {
328
+ setPoints(null);
329
+ return;
330
+ }
331
+ setPoints(null);
332
+ let stopped = false;
333
+ let timer = 0;
334
+ let startedAt = Date.now();
335
+ const schedule = (current) => {
336
+ const ours = current !== null && current.ours === true;
337
+ const settled = current !== null && typeof current.total === "number";
338
+ const warming = ours && Date.now() - startedAt < WARMUP_WINDOW_MS;
339
+ window.clearTimeout(timer);
340
+ timer = window.setTimeout(pull, settled || !warming ? REFRESH_INTERVAL_MS : WARMUP_INTERVAL_MS);
341
+ };
342
+ const pull = () => {
343
+ invoke("xd.composerPoints", {
344
+ provider,
345
+ model
346
+ }).then((next) => {
347
+ if (stopped) return;
348
+ const shown = next.show === true ? next : null;
349
+ setPoints(shown);
350
+ schedule(next);
351
+ }).catch(() => {
352
+ if (stopped) return;
353
+ setPoints(null);
354
+ schedule(null);
355
+ });
356
+ };
357
+ restartPollRef.current = () => {
358
+ window.clearTimeout(timer);
359
+ startedAt = Date.now();
360
+ pull();
361
+ };
362
+ pull();
363
+ return () => {
364
+ stopped = true;
365
+ window.clearTimeout(timer);
366
+ restartPollRef.current = () => {};
367
+ };
368
+ }, [provider, model]);
369
+ react.useEffect(() => {
370
+ if (!open) return void 0;
371
+ const onPointer = (event) => {
372
+ const target = event.target;
373
+ if (target === null) return;
374
+ if (rootRef.current?.contains(target) === true) return;
375
+ if (panelRef.current?.contains(target) === true) return;
376
+ setOpen(false);
377
+ };
378
+ const onKey = (event) => {
379
+ if (event.key === "Escape") setOpen(false);
380
+ };
381
+ document.addEventListener("pointerdown", onPointer, true);
382
+ document.addEventListener("keydown", onKey);
383
+ return () => {
384
+ document.removeEventListener("pointerdown", onPointer, true);
385
+ document.removeEventListener("keydown", onKey);
386
+ };
387
+ }, [open]);
388
+ react.useEffect(() => {
389
+ setOpen(false);
390
+ setError("");
391
+ setErrorFor("");
392
+ setBusy(false);
393
+ setRefreshing(false);
394
+ }, [provider, model]);
395
+ react.useEffect(() => {
396
+ if (errorFor === "") return;
397
+ if ((points?.accounts ?? []).find((account) => account.id === errorFor)?.active === true) {
398
+ setError("");
399
+ setErrorFor("");
400
+ }
401
+ }, [points, errorFor]);
402
+ const balance = balanceOf(points);
403
+ if (points === null) return null;
404
+ const pick = (account) => {
405
+ if (busy || account.active === true) return;
406
+ const requestedRoute = routeRef.current;
407
+ setBusy(true);
408
+ setError("");
409
+ invoke("xd.composerPrefer", {
410
+ provider,
411
+ model,
412
+ source: points.source ?? "",
413
+ region: points.region ?? "",
414
+ accountId: account.id ?? "",
415
+ accountLabel: account.label ?? ""
416
+ }).then((next) => {
417
+ if (routeRef.current !== requestedRoute) return;
418
+ setBusy(false);
419
+ if (next.saved !== true) {
420
+ setError(t("composer.refused"));
421
+ setErrorFor("");
422
+ return;
423
+ }
424
+ if (next.show !== true) {
425
+ setError(t("composer.saved"));
426
+ setErrorFor(account.id ?? "");
427
+ return;
428
+ }
429
+ setPoints(next);
430
+ restartPollRef.current();
431
+ if (next.unavailable === true) {
432
+ setError(t("composer.unavailable"));
433
+ setErrorFor(account.id ?? "");
434
+ return;
435
+ }
436
+ setOpen(false);
437
+ }).catch((failure) => {
438
+ if (routeRef.current !== requestedRoute) return;
439
+ setBusy(false);
440
+ setError(failure instanceof Error ? failure.message : String(failure));
441
+ });
442
+ };
443
+ const refresh = () => {
444
+ if (refreshing || busy) return;
445
+ const requestedRoute = routeRef.current;
446
+ setRefreshing(true);
447
+ setError("");
448
+ invoke("xd.composerRefresh", {
449
+ provider,
450
+ model
451
+ }).then((next) => {
452
+ if (routeRef.current !== requestedRoute) return;
453
+ setRefreshing(false);
454
+ if (next.show === true) setPoints(next);
455
+ }).catch((failure) => {
456
+ if (routeRef.current !== requestedRoute) return;
457
+ setRefreshing(false);
458
+ setError(failure instanceof Error ? failure.message : String(failure));
459
+ });
460
+ };
461
+ const accounts = Array.isArray(points.accounts) ? points.accounts : [];
462
+ const rect = open && rootRef.current !== null ? rootRef.current.getBoundingClientRect() : null;
463
+ return react.createElement("span", {
464
+ className: "xd-points",
465
+ ref: rootRef
466
+ }, react.createElement("button", {
467
+ type: "button",
468
+ className: "xd-points-btn",
469
+ title: t("composer.click"),
470
+ "aria-expanded": open,
471
+ onClick: () => setOpen((value) => !value)
472
+ }, react.createElement("span", {
473
+ className: "xd-points-mark",
474
+ "aria-hidden": "true"
475
+ }), balance === void 0 ? "—" : formatCredits(balance)), open && rect !== null ? react.createElement("div", {
476
+ className: "xd-points-panel",
477
+ ref: panelRef,
478
+ role: "dialog",
479
+ "aria-label": t("composer.title"),
480
+ style: positionStyle(rect)
481
+ }, react.createElement("div", { className: "xd-points-bar" }, react.createElement("span", null, t("composer.title")), react.createElement("button", {
482
+ type: "button",
483
+ className: "xd-points-refresh",
484
+ disabled: refreshing || busy,
485
+ onClick: refresh
486
+ }, refreshing ? t("composer.refreshing") : t("composer.refresh"))), error === "" ? null : react.createElement("p", { role: "alert" }, error), busy ? react.createElement("p", null, t("composer.switching")) : null, react.createElement("table", { className: "xd-points-table" }, react.createElement("thead", null, react.createElement("tr", null, react.createElement("th", null, t("composer.account")), react.createElement("th", null, t("composer.balance")))), react.createElement("tbody", null, accounts.map((account, index) => react.createElement("tr", {
487
+ key: account.id ?? account.label ?? String(index),
488
+ className: "xd-points-row" + (account.active === true ? " is-active" : "")
489
+ }, react.createElement("td", null, account.active === true ? react.createElement("span", {
490
+ className: "xd-points-dot",
491
+ "aria-hidden": "true"
492
+ }) : null, react.createElement("button", {
493
+ type: "button",
494
+ className: "xd-points-btn",
495
+ title: account.label ?? "",
496
+ disabled: account.active === true || busy,
497
+ onClick: () => pick(account)
498
+ }, account.label ?? "—")), react.createElement("td", null, typeof account.total === "number" ? formatCredits(account.total) : account.plan ?? "—", points.source === "qoder" && Array.isArray(account.packages) ? react.createElement("ul", { className: "xd-points-packs" }, account.packages.map((pack, index) => react.createElement("li", { key: index }, packageText(pack, t)))) : null)))))) : null);
499
+ }
500
+ //#endregion
501
+ //#region src/ids.ts
502
+ /**
503
+ * The two names this plugin is identified by.
504
+ *
505
+ * The client half has to key its Plugins-page entries with them, and the host
506
+ * half has to register under the same row id: a keyed slot's key is
507
+ * `<package name>#<loader row id>`, so a mismatch in either half silently costs
508
+ * the plugin its Configure control. Keeping both literals here is what stops the
509
+ * two halves from drifting apart.
510
+ *
511
+ * @module dsh-wtq-pool/ids
512
+ */
513
+ /** The npm package name this plugin is published and installed under. */
514
+ const PLUGIN_NAME = "dsh-wtq-pool";
515
+ /**
516
+ * The loader row id this plugin's own patch inserts.
517
+ *
518
+ * `cordis.patch.yml` inserts this id, the host reads it back to key the plugin's
519
+ * row page, and the settings namespace is this same id - so the entry's settings
520
+ * form and its client card address one another by it.
521
+ */
522
+ const ROW_ID = "llm-dsh-xdpool";
523
+ //#endregion
524
+ //#region src/client/index.tsx
525
+ /**
526
+ * The card this plugin puts on the Plugins page.
527
+ *
528
+ * The card is deliberately thin: it frames the panel, and the panel itself is
529
+ * the whole surface. A card that re-implemented the pool in React would be a
530
+ * second surface to keep in step with the first, so the card owns text,
531
+ * placement and the state a settings form needs - nothing else.
532
+ *
533
+ * @module dsh-wtq-pool/client
534
+ */
535
+ const inject = ["slots", "locale"];
536
+ /** The locale namespace this card's copy lives under. */
537
+ const NAMESPACE = "settings.dsh-wtq-pool";
538
+ const zh = {
539
+ "row.title": "WTQ Pool",
540
+ "row.desc": "把本机 WorkBuddy、Trae、Qoder 的桌面登录合并成一个会自动换号的模型池。",
541
+ "card.title": "账号池",
542
+ "card.hint": "下方是完整面板:账号、模型选择、签到与连接检查都在这一页里。",
543
+ "card.open": "重新载入面板",
544
+ "card.frameTitle": "账号池面板",
545
+ "card.missing": "面板资源没有装好,重新安装这个插件即可。"
546
+ };
547
+ const en = {
548
+ "row.title": "WTQ Pool",
549
+ "row.desc": "Merges this machine’s WorkBuddy, Trae and Qoder desktop sign-ins into one model pool that fails over on its own.",
550
+ "card.title": "Account pool",
551
+ "card.hint": "The full panel sits below: accounts, model selection, check-in and the connection check are all on this page.",
552
+ "card.open": "Reload panel",
553
+ "card.frameTitle": "Account pool panel",
554
+ "card.missing": "The panel assets are missing; reinstalling this plugin restores them."
555
+ };
556
+ /**
557
+ * The embedded panel.
558
+ *
559
+ * of the Plugins page and the Plugins page's out of the panel: the panel was
560
+ * written as a whole page, and the frame is the boundary that lets it stay one.
561
+ *
562
+ * The frame is only mounted for the full page. The row's inline summary is asked
563
+ * for on the list itself, where a 70vh frame would be the wrong control
564
+ * entirely - the host supplies `view` for exactly that distinction.
565
+ */
566
+ function PanelCard({ t, view }) {
567
+ const [generation, setGeneration] = react.useState(0);
568
+ const [measured, setMeasured] = react.useState(0);
569
+ const frameRef = react.useRef(null);
570
+ const appearance = react.useMemo(() => {
571
+ if (typeof document === "undefined") return {
572
+ base: "light",
573
+ lang: "zh-CN"
574
+ };
575
+ const root = document.documentElement;
576
+ return {
577
+ base: root.dataset["base"] === "dark" || root.dataset["base"] === void 0 && typeof window !== "undefined" && window.matchMedia?.("(prefers-color-scheme: dark)").matches === true ? "dark" : "light",
578
+ lang: root.lang === "" ? "zh-CN" : root.lang
579
+ };
580
+ }, [generation]);
581
+ react.useEffect(() => {
582
+ if (view === "summary") return void 0;
583
+ const frame = frameRef.current;
584
+ const measure = () => {
585
+ const doc = frame === null ? null : frame.contentDocument;
586
+ if (doc === null || doc.body === null) return;
587
+ const height = Math.min(FRAME_MAX_HEIGHT, doc.body.scrollHeight + FRAME_BORDER);
588
+ setMeasured((current) => current === height ? current : height);
589
+ };
590
+ const timer = window.setInterval(measure, 400);
591
+ return () => window.clearInterval(timer);
592
+ }, [view, generation]);
593
+ if (view === "summary") return react.createElement("p", { style: SUMMARY_STYLE }, t("row.desc"));
594
+ return react.createElement("section", { style: CARD_STYLE }, react.createElement("header", { style: HEAD_STYLE }, react.createElement("div", null, react.createElement("strong", null, t("card.title")), react.createElement("p", { style: HINT_STYLE }, t("card.hint"))), react.createElement("button", {
595
+ type: "button",
596
+ style: BUTTON_STYLE,
597
+ onClick: () => {
598
+ setMeasured(0);
599
+ setGeneration((value) => value + 1);
600
+ const frame = frameRef.current;
601
+ if (frame !== null) frame.src = panelUrl(appearance);
602
+ }
603
+ }, t("card.open"))), react.createElement("iframe", {
604
+ key: generation,
605
+ ref: frameRef,
606
+ title: t("card.frameTitle"),
607
+ src: panelUrl(appearance),
608
+ style: measured === 0 ? FRAME_PENDING : {
609
+ ...FRAME_PENDING,
610
+ height: measured,
611
+ minHeight: 0
612
+ }
613
+ }));
614
+ }
615
+ const SUMMARY_STYLE = {
616
+ margin: 0,
617
+ opacity: .75,
618
+ fontSize: 13
619
+ };
620
+ const CARD_STYLE = {
621
+ display: "flex",
622
+ flexDirection: "column",
623
+ gap: 12
624
+ };
625
+ const HEAD_STYLE = {
626
+ display: "flex",
627
+ alignItems: "flex-start",
628
+ justifyContent: "space-between",
629
+ gap: 12
630
+ };
631
+ const HINT_STYLE = {
632
+ margin: "4px 0 0",
633
+ opacity: .7,
634
+ fontSize: 12
635
+ };
636
+ const BUTTON_STYLE = {
637
+ flex: "0 0 auto",
638
+ cursor: "pointer"
639
+ };
640
+ const FRAME_PENDING = {
641
+ width: "100%",
642
+ height: "72vh",
643
+ minHeight: 460,
644
+ border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.25))",
645
+ borderRadius: 10,
646
+ background: "transparent",
647
+ boxSizing: "border-box"
648
+ };
649
+ const FRAME_BORDER = 2;
650
+ const FRAME_MAX_HEIGHT = 1900;
651
+ /**
652
+ * Register the card on the Plugins page.
653
+ *
654
+ * Two seats, because the host keys them differently and shows them in different
655
+ * places: the bundle page (opened from the plugin's own card) keys on the
656
+ * package name, and the row page (the "Configure" control beside the plugin's
657
+ * loader row) keys on `<package name>#<row id>`. Registering both is what puts
658
+ * the panel where the plugin is configured rather than in the generic settings
659
+ * list.
660
+ *
661
+ * Every step is guarded: a slot this host line does not declare must cost the
662
+ * card, not the provider. The host services keep serving either way.
663
+ */
664
+ function apply(ctx) {
665
+ try {
666
+ ctx.effect(() => ctx.locale.register(NAMESPACE, {
667
+ zh: {
668
+ ...zh,
669
+ ...composerZh
670
+ },
671
+ en: {
672
+ ...en,
673
+ ...composerEn
674
+ }
675
+ }), "dsh-wtq-pool: copy");
676
+ ctx.locale.bind(NAMESPACE);
677
+ } catch (error) {
678
+ console.error("[dsh-wtq-pool] the copy did not register (the labels fall back to their keys):", error);
679
+ }
680
+ try {
681
+ const seat = (slotName, key) => {
682
+ try {
683
+ ctx.slots.inject(slotName, () => ctx.slots.register({
684
+ name: slotName,
685
+ key,
686
+ locale: NAMESPACE
687
+ }, PanelCard));
688
+ } catch (error) {
689
+ console.error(`[dsh-wtq-pool] the card did not mount into ${slotName} (the providers are unaffected):`, error);
690
+ }
691
+ };
692
+ seat("plugins.bundle.config", PLUGIN_NAME);
693
+ seat("plugins.row.config", `${PLUGIN_NAME}#${ROW_ID}`);
694
+ try {
695
+ ctx.slots.inject("conversation.input.left", () => ctx.slots.register({
696
+ name: "conversation.input.left",
697
+ id: COMPOSER_SLOT_ID,
698
+ order: 4
699
+ }, ComposerPoints));
700
+ } catch (error) {
701
+ console.error("[dsh-wtq-pool] the composer readout did not mount (the providers are unaffected):", error);
702
+ }
703
+ } catch (error) {
704
+ console.error("[dsh-wtq-pool] the cards did not mount (the providers are unaffected):", error);
705
+ }
706
+ }
707
+ //#endregion
708
+ exports.apply = apply;
709
+ exports.inject = inject;
710
+ return module.exports;
711
+ }
712
+ });