dsh-wtq-pool 1.0.1 → 1.0.3
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/CHANGELOG.md +54 -36
- package/README.en.md +88 -31
- package/README.md +91 -34
- package/cordis.patch.yml +2 -0
- package/lib/client.js +115 -13
- package/lib/index.d.ts +31 -24
- package/lib/index.js +3671 -1188
- package/package.json +7 -27
- package/renderer/panel.css +12 -7
- package/renderer/panel.js +108 -12
- package/docs/index.html +0 -181
- package/docs/preview-composer.png +0 -0
- package/docs/preview-dark.png +0 -0
- package/docs/preview-data.js +0 -339
- package/docs/preview-models.png +0 -0
- package/docs/preview-page.png +0 -0
- package/docs/preview-panel.html +0 -95
- package/docs/preview-pool.png +0 -0
- package/docs/serve.cjs +0 -74
package/lib/client.js
CHANGED
|
@@ -202,6 +202,15 @@ window.__ModuleLoader__.load({
|
|
|
202
202
|
const PANEL_MARGIN = 8;
|
|
203
203
|
/** The popup's own width cap, in px. */
|
|
204
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;
|
|
205
214
|
/** How tall the popup is allowed to get, in px. */
|
|
206
215
|
const PANEL_MAX_HEIGHT = 320;
|
|
207
216
|
/**
|
|
@@ -211,16 +220,27 @@ window.__ModuleLoader__.load({
|
|
|
211
220
|
* the bottom of the window, so above is where the room is. Flipped below when
|
|
212
221
|
* the trigger is near the top and the popup would not fit above it: a fixed
|
|
213
222
|
* position is not scrolled into view by anything, so the rows above the trigger
|
|
214
|
-
* would simply be cut off, and so would the popup's own first rows.
|
|
215
|
-
*
|
|
216
|
-
*
|
|
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.
|
|
217
234
|
*/
|
|
218
235
|
function positionStyle(rect) {
|
|
219
|
-
const width = typeof window === "undefined" ? PANEL_MAX_WIDTH : Math.max(0, Math.min(PANEL_MAX_WIDTH, window.innerWidth - 16));
|
|
220
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);
|
|
221
240
|
return {
|
|
222
|
-
|
|
223
|
-
|
|
241
|
+
right: right + "px",
|
|
242
|
+
minWidth: floor + "px",
|
|
243
|
+
maxWidth: width + "px",
|
|
224
244
|
top: (above ? rect.top - PANEL_MARGIN : rect.bottom + PANEL_MARGIN) + "px",
|
|
225
245
|
transform: above ? "translateY(-100%)" : void 0
|
|
226
246
|
};
|
|
@@ -230,14 +250,28 @@ window.__ModuleLoader__.load({
|
|
|
230
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}
|
|
231
251
|
.xd-points-btn:hover{background:var(--dsw-alias-bg-layer-3,rgba(127,127,127,.12))}
|
|
232
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)}
|
|
233
|
-
.xd-points-panel{position:fixed;z-index:40;
|
|
234
|
-
.xd-points-table{width:100%;border-collapse:collapse;font-size:
|
|
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}
|
|
235
255
|
.xd-points-table th{text-align:left;font-weight:600;padding:4px 6px;color:var(--dsw-alias-label-tertiary,#8b8d93)}
|
|
236
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}
|
|
237
272
|
.xd-points-row{cursor:pointer}
|
|
238
273
|
.xd-points-row:hover{background:var(--dsw-alias-bg-layer-3,rgba(127,127,127,.12))}
|
|
239
274
|
.xd-points-row.is-active{cursor:default}
|
|
240
|
-
.xd-points-dot{display:inline-block;width:6px;height:6px;margin-right:6px;border-radius:50%;background:var(--dsw-alias-state-success-primary,#4f9f7c);vertical-align:middle}
|
|
241
275
|
.xd-points-packs{margin:2px 0 0;padding:0;list-style:none;color:var(--dsw-alias-label-tertiary,#8b8d93)}
|
|
242
276
|
.xd-points-bar{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:6px}
|
|
243
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}
|
|
@@ -289,6 +323,9 @@ window.__ModuleLoader__.load({
|
|
|
289
323
|
const rootRef = react.useRef(null);
|
|
290
324
|
const panelRef = react.useRef(null);
|
|
291
325
|
const restartPollRef = react.useRef(() => {});
|
|
326
|
+
react.useEffect(() => {
|
|
327
|
+
if (props.useProjection === void 0) console.warn("[dsh-wtq-pool] the composer slot passed no useProjection; the credits readout stays hidden");
|
|
328
|
+
}, []);
|
|
292
329
|
react.useEffect(() => {
|
|
293
330
|
if (provider === "" || model === "") {
|
|
294
331
|
setPoints(null);
|
|
@@ -311,6 +348,11 @@ window.__ModuleLoader__.load({
|
|
|
311
348
|
model
|
|
312
349
|
}).then((next) => {
|
|
313
350
|
if (stopped) return;
|
|
351
|
+
if (next.enabled === false) {
|
|
352
|
+
setPoints(null);
|
|
353
|
+
window.clearTimeout(timer);
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
314
356
|
const shown = next.show === true ? next : null;
|
|
315
357
|
setPoints(shown);
|
|
316
358
|
schedule(next);
|
|
@@ -344,11 +386,18 @@ window.__ModuleLoader__.load({
|
|
|
344
386
|
const onKey = (event) => {
|
|
345
387
|
if (event.key === "Escape") setOpen(false);
|
|
346
388
|
};
|
|
389
|
+
const onViewport = () => {
|
|
390
|
+
setOpen(false);
|
|
391
|
+
};
|
|
347
392
|
document.addEventListener("pointerdown", onPointer, true);
|
|
348
393
|
document.addEventListener("keydown", onKey);
|
|
394
|
+
window.addEventListener("scroll", onViewport, true);
|
|
395
|
+
window.addEventListener("resize", onViewport);
|
|
349
396
|
return () => {
|
|
350
397
|
document.removeEventListener("pointerdown", onPointer, true);
|
|
351
398
|
document.removeEventListener("keydown", onKey);
|
|
399
|
+
window.removeEventListener("scroll", onViewport, true);
|
|
400
|
+
window.removeEventListener("resize", onViewport);
|
|
352
401
|
};
|
|
353
402
|
}, [open]);
|
|
354
403
|
react.useEffect(() => {
|
|
@@ -458,6 +507,7 @@ window.__ModuleLoader__.load({
|
|
|
458
507
|
}) : null, react.createElement("button", {
|
|
459
508
|
type: "button",
|
|
460
509
|
className: "xd-points-btn",
|
|
510
|
+
title: account.label ?? "",
|
|
461
511
|
disabled: account.active === true || busy,
|
|
462
512
|
onClick: () => pick(account)
|
|
463
513
|
}, 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);
|
|
@@ -530,6 +580,8 @@ window.__ModuleLoader__.load({
|
|
|
530
580
|
*/
|
|
531
581
|
function PanelCard({ t, view }) {
|
|
532
582
|
const [generation, setGeneration] = react.useState(0);
|
|
583
|
+
const [measured, setMeasured] = react.useState(0);
|
|
584
|
+
const [missing, setMissing] = react.useState(false);
|
|
533
585
|
const frameRef = react.useRef(null);
|
|
534
586
|
const appearance = react.useMemo(() => {
|
|
535
587
|
if (typeof document === "undefined") return {
|
|
@@ -542,21 +594,57 @@ window.__ModuleLoader__.load({
|
|
|
542
594
|
lang: root.lang === "" ? "zh-CN" : root.lang
|
|
543
595
|
};
|
|
544
596
|
}, [generation]);
|
|
597
|
+
react.useEffect(() => {
|
|
598
|
+
if (view === "summary") return void 0;
|
|
599
|
+
let live = true;
|
|
600
|
+
setMissing(false);
|
|
601
|
+
const attempts = 3;
|
|
602
|
+
const probe = (remaining) => {
|
|
603
|
+
fetch(`${PANEL_BASE}/panel.css`).then((response) => {
|
|
604
|
+
if (!live) return;
|
|
605
|
+
if (response.ok || remaining <= 1) setMissing(!response.ok);
|
|
606
|
+
else setTimeout(() => probe(remaining - 1), 500);
|
|
607
|
+
}).catch(() => {
|
|
608
|
+
if (live && remaining <= 1) setMissing(true);
|
|
609
|
+
});
|
|
610
|
+
};
|
|
611
|
+
probe(attempts);
|
|
612
|
+
return () => {
|
|
613
|
+
live = false;
|
|
614
|
+
};
|
|
615
|
+
}, [view, generation]);
|
|
616
|
+
react.useEffect(() => {
|
|
617
|
+
if (view === "summary") return void 0;
|
|
618
|
+
const frame = frameRef.current;
|
|
619
|
+
const measure = () => {
|
|
620
|
+
const doc = frame === null ? null : frame.contentDocument;
|
|
621
|
+
if (doc === null || doc.body === null) return;
|
|
622
|
+
const height = Math.min(FRAME_MAX_HEIGHT, doc.body.scrollHeight + FRAME_BORDER);
|
|
623
|
+
setMeasured((current) => current === height ? current : height);
|
|
624
|
+
};
|
|
625
|
+
const timer = window.setInterval(measure, 400);
|
|
626
|
+
return () => window.clearInterval(timer);
|
|
627
|
+
}, [view, generation]);
|
|
545
628
|
if (view === "summary") return react.createElement("p", { style: SUMMARY_STYLE }, t("row.desc"));
|
|
546
629
|
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", {
|
|
547
630
|
type: "button",
|
|
548
631
|
style: BUTTON_STYLE,
|
|
549
632
|
onClick: () => {
|
|
633
|
+
setMeasured(0);
|
|
550
634
|
setGeneration((value) => value + 1);
|
|
551
635
|
const frame = frameRef.current;
|
|
552
636
|
if (frame !== null) frame.src = panelUrl(appearance);
|
|
553
637
|
}
|
|
554
|
-
}, t("card.open"))), react.createElement("iframe", {
|
|
638
|
+
}, t("card.open"))), missing ? react.createElement("div", { style: MISSING_STYLE }, t("card.missing")) : react.createElement("iframe", {
|
|
555
639
|
key: generation,
|
|
556
640
|
ref: frameRef,
|
|
557
641
|
title: t("card.frameTitle"),
|
|
558
642
|
src: panelUrl(appearance),
|
|
559
|
-
style:
|
|
643
|
+
style: measured === 0 ? FRAME_PENDING : {
|
|
644
|
+
...FRAME_PENDING,
|
|
645
|
+
height: measured,
|
|
646
|
+
minHeight: 0
|
|
647
|
+
}
|
|
560
648
|
}));
|
|
561
649
|
}
|
|
562
650
|
const SUMMARY_STYLE = {
|
|
@@ -584,13 +672,27 @@ window.__ModuleLoader__.load({
|
|
|
584
672
|
flex: "0 0 auto",
|
|
585
673
|
cursor: "pointer"
|
|
586
674
|
};
|
|
587
|
-
const
|
|
675
|
+
const FRAME_PENDING = {
|
|
588
676
|
width: "100%",
|
|
589
677
|
height: "72vh",
|
|
590
678
|
minHeight: 460,
|
|
591
679
|
border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.25))",
|
|
592
680
|
borderRadius: 10,
|
|
593
|
-
background: "transparent"
|
|
681
|
+
background: "transparent",
|
|
682
|
+
boxSizing: "border-box"
|
|
683
|
+
};
|
|
684
|
+
const FRAME_BORDER = 2;
|
|
685
|
+
const FRAME_MAX_HEIGHT = 1900;
|
|
686
|
+
const MISSING_STYLE = {
|
|
687
|
+
...FRAME_PENDING,
|
|
688
|
+
display: "flex",
|
|
689
|
+
alignItems: "center",
|
|
690
|
+
justifyContent: "center",
|
|
691
|
+
margin: 0,
|
|
692
|
+
padding: "0 16px",
|
|
693
|
+
opacity: .75,
|
|
694
|
+
fontSize: 13,
|
|
695
|
+
textAlign: "center"
|
|
594
696
|
};
|
|
595
697
|
/**
|
|
596
698
|
* Register the card on the Plugins page.
|
package/lib/index.d.ts
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
import z from "@deepseek-ai/schemastery";
|
|
2
|
+
import { IncomingMessage, ServerResponse } from "node:http";
|
|
2
3
|
import { SettingsPathOp } from "@deepseek-ai/dsh-settings";
|
|
3
|
-
//#region src/
|
|
4
|
+
//#region src/web-panel.d.ts
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* Merges every WorkBuddy, Trae and Qoder desktop sign-in on this machine into
|
|
8
|
-
* one model pool that fails over on its own:
|
|
9
|
-
*
|
|
10
|
-
* 1. discover every sign-in on this machine (read-only),
|
|
11
|
-
* 2. serve each vendor edition from its own loopback OpenAI-compatible
|
|
12
|
-
* endpoint,
|
|
13
|
-
* 3. publish those endpoints as six providers,
|
|
14
|
-
* 4. rotate to the next account whenever the upstream answers 429.
|
|
6
|
+
* The slice of the host's web server this plugin mounts into.
|
|
15
7
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* Upstream traffic uses the platform `fetch` rather than a host network bridge:
|
|
21
|
-
* a bridged response is buffered into text, and a provider contract needs the
|
|
22
|
-
* upstream SSE body relayed as it arrives. Nothing leaves this machine except
|
|
23
|
-
* to the three vendors' own endpoints.
|
|
8
|
+
* Hand-written rather than imported from the host package for the same reason
|
|
9
|
+
* the entry's other seams are: the plugin compiles against the capability it
|
|
10
|
+
* uses, and a host that grows a field does not become a compile error here.
|
|
24
11
|
*/
|
|
12
|
+
interface WebServerSeam {
|
|
13
|
+
register(route: {
|
|
14
|
+
kind: 'exact' | 'prefix';
|
|
15
|
+
path: string;
|
|
16
|
+
handler: (req: IncomingMessage, res: ServerResponse) => unknown;
|
|
17
|
+
}): () => void;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/host.d.ts
|
|
25
21
|
declare function onPanelInvoke(channel: any, payload: any): Promise<any>;
|
|
26
22
|
declare function onLoad(): Promise<void>;
|
|
27
23
|
declare function onUnload(): Promise<void>;
|
|
@@ -81,15 +77,25 @@ interface Config {
|
|
|
81
77
|
sourceDistributions?: Record<string, string>;
|
|
82
78
|
}
|
|
83
79
|
declare const Config: z<Config>;
|
|
80
|
+
/**
|
|
81
|
+
* The slice of `ctx.llm` this plugin uses.
|
|
82
|
+
*
|
|
83
|
+
* Declared structurally rather than imported so the same source still compiles
|
|
84
|
+
* against a host that predates one of the calls. The return types mirror the
|
|
85
|
+
* published handles: both registrations hand back a disposer (the real ones also
|
|
86
|
+
* carry `replace`, which this plugin does not use), and `registerModelDiscovery`
|
|
87
|
+
* returns the disposer the activation effect relies on. Calling any of them
|
|
88
|
+
* after the fiber is disposed throws, so a stale write cannot leave an orphan.
|
|
89
|
+
*/
|
|
84
90
|
interface LlmSeam {
|
|
85
|
-
registerAdapter(providerIds: string[], adapter: unknown): (
|
|
91
|
+
registerAdapter(providerIds: string[], adapter: unknown): () => void;
|
|
86
92
|
registerConfigurableProviders(rows: Array<{
|
|
87
93
|
provider: string;
|
|
88
94
|
displayName: string;
|
|
89
95
|
settingsNs: string;
|
|
90
96
|
settingsPath: string[];
|
|
91
97
|
declared: boolean;
|
|
92
|
-
}>): (
|
|
98
|
+
}>): () => void;
|
|
93
99
|
registerModelDiscovery(ns: string, fn: (request: {
|
|
94
100
|
provider?: string;
|
|
95
101
|
}, signal?: AbortSignal) => Promise<Array<{
|
|
@@ -98,7 +104,7 @@ interface LlmSeam {
|
|
|
98
104
|
contextWindow?: number;
|
|
99
105
|
maxTokens?: number;
|
|
100
106
|
inputModalities?: string[];
|
|
101
|
-
}>>): void;
|
|
107
|
+
}>>): () => void;
|
|
102
108
|
}
|
|
103
109
|
interface SettingsService {
|
|
104
110
|
configure?(presentation: {
|
|
@@ -128,8 +134,7 @@ interface ClientContext {
|
|
|
128
134
|
};
|
|
129
135
|
effect(callback: () => unknown, label?: string): unknown;
|
|
130
136
|
inject(names: string[], callback: (scoped: ClientContext) => unknown): unknown;
|
|
131
|
-
on(name: string, listener: (...args: unknown[]) => void): (
|
|
132
|
-
off?(name: string, listener: (...args: unknown[]) => void): void;
|
|
137
|
+
on(name: string, listener: (...args: unknown[]) => void): () => void;
|
|
133
138
|
get(name: string): unknown;
|
|
134
139
|
emit(name: string, ...args: unknown[]): void;
|
|
135
140
|
fiber?: {
|
|
@@ -140,6 +145,8 @@ interface ClientContext {
|
|
|
140
145
|
};
|
|
141
146
|
};
|
|
142
147
|
};
|
|
148
|
+
/** Present once `webServer` is injected; the panel routes mount into it. */
|
|
149
|
+
webServer?: WebServerSeam;
|
|
143
150
|
}
|
|
144
151
|
/**
|
|
145
152
|
* Activate the plugin.
|