dsh-xdpool 2.6.7 → 2.7.1

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
@@ -7,6 +7,7 @@ window.__ModuleLoader__.load({
7
7
  //#endregion
8
8
  let react = require("react");
9
9
  let react_jsx_runtime = require("react/jsx-runtime");
10
+ let react_dom = require("react-dom");
10
11
  //#region src/client/sidebar-row.ts
11
12
  /**
12
13
  * The `sidebarRow` switch, read and written from one place.
@@ -211,6 +212,29 @@ window.__ModuleLoader__.load({
211
212
  */
212
213
  const POOL_CHANNELS_PATH = "/plugins/dsh-xdpool/channels";
213
214
  /**
215
+ * The Doubao lane's session.
216
+ *
217
+ * POST starts an interactive browser sign-in and answers once it lands;
218
+ * GET reports whether a session is stored; DELETE forgets it.
219
+ */
220
+ const POOL_DOUBAO_SESSION_PATH = "/plugins/dsh-xdpool/doubao/session";
221
+ /** The Doubao quota: the windows the account has, with their reset countdowns. */
222
+ const POOL_DOUBAO_QUOTA_PATH = "/plugins/dsh-xdpool/doubao/quota";
223
+ /**
224
+ * The `reason` the channel document carries when the login-channel route is
225
+ * already owned by another plugin.
226
+ *
227
+ * The pack we vendor is byte-identical to the one the sibling login-channel
228
+ * build mounts, and both claim the same fetch route; the host has no query for
229
+ * what is already registered, so the loser of that race can only tell it lost.
230
+ * Both halves need the same string — the host to say it, the card to choose
231
+ * between "this host cannot run the channels" and "another plugin already runs
232
+ * them", which are opposite sentences — so it is declared with the other wire
233
+ * constants rather than in `channels.ts`, which the browser bundle may not
234
+ * import for value.
235
+ */
236
+ const ROUTE_OWNED_ELSEWHERE = "already-mounted-elsewhere";
237
+ /**
214
238
  * The routing chains, and the whole model roster a member may name.
215
239
  *
216
240
  * One route for both because the editor cannot be drawn without the roster: a
@@ -2409,8 +2433,11 @@ window.__ModuleLoader__.load({
2409
2433
  (0, react.useEffect)(() => {
2410
2434
  if (shared !== void 0) setOwn(shared);
2411
2435
  }, [shared]);
2412
- (0, react.useEffect)(() => () => {
2413
- mounted.current = false;
2436
+ (0, react.useEffect)(() => {
2437
+ mounted.current = true;
2438
+ return () => {
2439
+ mounted.current = false;
2440
+ };
2414
2441
  }, []);
2415
2442
  /**
2416
2443
  * Poll only while this page is mounted.
@@ -2840,7 +2867,16 @@ window.__ModuleLoader__.load({
2840
2867
  * "TRAE" a bare "T", which looks sparse at 40px. CamelCase splitting resolves
2841
2868
  * both: LobsterAI -> LA, Loomy -> L, TRAE -> TR, MiniMax Code -> MM.
2842
2869
  */
2870
+ /**
2871
+ * Initials for a name the generic rule cannot letter.
2872
+ *
2873
+ * A Chinese display name has no ASCII letters to take, so the rule below returns an empty
2874
+ * mark — a channel with a blank tile. Doubao is the first such name.
2875
+ */
2876
+ const INITIALS_BY_NAME = { 豆包: "DB" };
2843
2877
  function channelInitials(name) {
2878
+ const fixed = INITIALS_BY_NAME[name.trim()];
2879
+ if (fixed !== void 0) return fixed;
2844
2880
  const segments = name.split(/\s+/u).flatMap((word) => word.replace(/([a-z0-9])([A-Z])/gu, "$1 $2").split(" ")).map((segment) => [...segment].filter((character) => /[0-9A-Za-z]/u.test(character)).join("")).filter((segment) => segment !== "");
2845
2881
  if (segments.length >= 2) return (([...segments[0] ?? ""][0] ?? "") + ([...segments[1] ?? ""][0] ?? "")).toUpperCase();
2846
2882
  return [...segments[0] ?? ""].slice(0, 2).join("").toUpperCase();
@@ -8385,8 +8421,11 @@ window.__ModuleLoader__.load({
8385
8421
  /** The pair currently being measured, so only one button shows a spinner. */
8386
8422
  const [probing, setProbing] = (0, react.useState)(void 0);
8387
8423
  const mounted = (0, react.useRef)(true);
8388
- (0, react.useEffect)(() => () => {
8389
- mounted.current = false;
8424
+ (0, react.useEffect)(() => {
8425
+ mounted.current = true;
8426
+ return () => {
8427
+ mounted.current = false;
8428
+ };
8390
8429
  }, []);
8391
8430
  /**
8392
8431
  * Ask the host to run one real request against a model, and keep the reading.
@@ -9919,10 +9958,13 @@ window.__ModuleLoader__.load({
9919
9958
  const mounted = (0, react.useRef)(true);
9920
9959
  /** Timers for in-flight logins, keyed by channel id. */
9921
9960
  const timers = (0, react.useRef)(/* @__PURE__ */ new Map());
9922
- (0, react.useEffect)(() => () => {
9923
- mounted.current = false;
9924
- for (const handle of timers.current.values()) window.clearInterval(handle);
9925
- timers.current.clear();
9961
+ (0, react.useEffect)(() => {
9962
+ mounted.current = true;
9963
+ return () => {
9964
+ mounted.current = false;
9965
+ for (const handle of timers.current.values()) window.clearInterval(handle);
9966
+ timers.current.clear();
9967
+ };
9926
9968
  }, []);
9927
9969
  const load = (0, react.useCallback)(async (signal) => {
9928
9970
  try {
@@ -10201,6 +10243,16 @@ window.__ModuleLoader__.load({
10201
10243
  t,
10202
10244
  ui: ui[channel.id] ?? IDLE,
10203
10245
  connectedCount: connectedFor(channel).length,
10246
+ /**
10247
+ * When the pack is mounted ELSEWHERE, this page cannot log anybody in.
10248
+ *
10249
+ * `account.create` is answered by the pack, and the pack that owns it lives in
10250
+ * another plugin — so pressing the button produced the host's "not supported"
10251
+ * line for a channel that works perfectly well, on a page the user was told to
10252
+ * use. The row says where the sign-in actually is instead of offering a button
10253
+ * that cannot work.
10254
+ */
10255
+ ownedElsewhere: status?.reason === ROUTE_OWNED_ELSEWHERE,
10204
10256
  onSignIn: () => {
10205
10257
  signIn(channel);
10206
10258
  },
@@ -10209,7 +10261,7 @@ window.__ModuleLoader__.load({
10209
10261
  ]
10210
10262
  });
10211
10263
  }
10212
- function ChannelRow({ channel, t, ui, connectedCount, onSignIn, onCancel }) {
10264
+ function ChannelRow({ channel, t, ui, connectedCount, onSignIn, onCancel, ownedElsewhere }) {
10213
10265
  const busy = ui.phase === "signing-in";
10214
10266
  const icon = channelIcon(channel.id);
10215
10267
  const tileMark = icon === void 0 ? { initials: channelInitials(channel.name) } : { icon };
@@ -10264,7 +10316,10 @@ window.__ModuleLoader__.load({
10264
10316
  children: t?.("agg.clear") ?? "Cancel"
10265
10317
  })
10266
10318
  ] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
10267
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
10319
+ ownedElsewhere === true ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
10320
+ className: "dsm-xdpool-channel-hint",
10321
+ children: t?.("chan.ownedElsewhereRow") ?? "在「我们的免费模型」里登录"
10322
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
10268
10323
  type: "button",
10269
10324
  className: "dsm-xdpool-btn",
10270
10325
  onClick: onSignIn,
@@ -10430,8 +10485,11 @@ window.__ModuleLoader__.load({
10430
10485
  /** True once the drafts were seeded from the server, so later polls don't stomp edits. */
10431
10486
  const seeded = (0, react.useRef)(false);
10432
10487
  const mounted = (0, react.useRef)(true);
10433
- (0, react.useEffect)(() => () => {
10434
- mounted.current = false;
10488
+ (0, react.useEffect)(() => {
10489
+ mounted.current = true;
10490
+ return () => {
10491
+ mounted.current = false;
10492
+ };
10435
10493
  }, []);
10436
10494
  const load = (0, react.useCallback)(async (signal) => {
10437
10495
  try {
@@ -11233,8 +11291,11 @@ window.__ModuleLoader__.load({
11233
11291
  /** True once the server's values were adopted, so polls do not stomp edits. */
11234
11292
  const seeded = (0, react.useRef)(false);
11235
11293
  const mounted = (0, react.useRef)(true);
11236
- (0, react.useEffect)(() => () => {
11237
- mounted.current = false;
11294
+ (0, react.useEffect)(() => {
11295
+ mounted.current = true;
11296
+ return () => {
11297
+ mounted.current = false;
11298
+ };
11238
11299
  }, []);
11239
11300
  const load = (0, react.useCallback)(async (signal) => {
11240
11301
  try {
@@ -11686,6 +11747,262 @@ window.__ModuleLoader__.load({
11686
11747
  ]
11687
11748
  });
11688
11749
  }
11750
+ //#endregion
11751
+ //#region src/client/DoubaoPage.tsx
11752
+ /**
11753
+ * The Doubao card: sign in, then read the quota.
11754
+ *
11755
+ * WHAT THIS SURFACE IS FOR
11756
+ *
11757
+ * Doubao's models already appear in the picker (the channel lane serves them), so this card
11758
+ * is not a second model list. It is the two things that have no other home:
11759
+ *
11760
+ * - the SIGN-IN, because Doubao's QR entrance is closed and the only door left is a
11761
+ * browser window this plugin starts;
11762
+ * - the QUOTA, because Doubao reports promotional windows with reset countdowns and
11763
+ * nothing else in the plugin knows how to read them.
11764
+ *
11765
+ * THE COPY SAYS WHAT ACTUALLY HAPPENS
11766
+ *
11767
+ * The button opens a Chromium window and waits. A user who is told "sign in" and sees a blank
11768
+ * panel for a minute concludes the feature is broken, so the waiting states name the step
11769
+ * they are on and the window stays open for the whole budget.
11770
+ *
11771
+ * @module dsh-xdpool/client/DoubaoPage
11772
+ */
11773
+ /** How the card describes one window. */
11774
+ function windowLabel(window) {
11775
+ if (typeof window.label === "string" && window.label !== "") return window.label;
11776
+ if (window.type === "five_hour") return "5 小时限额";
11777
+ if (window.type === "weekly") return "周额度";
11778
+ if (window.type === "incentive") return "活动赠送额度";
11779
+ return "额度";
11780
+ }
11781
+ /** A countdown, or a plain statement when the window has no reset. */
11782
+ function resetText(window) {
11783
+ if (window.resetUnknown === true || window.resetsAt === void 0 || window.resetsAt <= 0) return "用后开始计算";
11784
+ const left = window.resetsAt - Date.now();
11785
+ if (left <= 0) return "已重置";
11786
+ const hours = Math.floor(left / 36e5);
11787
+ const days = Math.floor(hours / 24);
11788
+ if (days > 0) return `${String(days)} 天 ${String(hours % 24)} 小时后重置`;
11789
+ const minutes = Math.floor(left % 36e5 / 6e4);
11790
+ return `${String(hours)} 小时 ${String(minutes)} 分后重置`;
11791
+ }
11792
+ function DoubaoPage({ t }) {
11793
+ const [signedIn, setSignedIn] = (0, react.useState)(false);
11794
+ const [busy, setBusy] = (0, react.useState)(false);
11795
+ const [message, setMessage] = (0, react.useState)(void 0);
11796
+ const [error, setError] = (0, react.useState)(void 0);
11797
+ const [windows, setWindows] = (0, react.useState)([]);
11798
+ const [exhausted, setExhausted] = (0, react.useState)(false);
11799
+ const mounted = (0, react.useRef)(true);
11800
+ const poll = (0, react.useRef)(void 0);
11801
+ (0, react.useEffect)(() => {
11802
+ mounted.current = true;
11803
+ return () => {
11804
+ mounted.current = false;
11805
+ if (poll.current !== void 0) window.clearTimeout(poll.current);
11806
+ };
11807
+ }, []);
11808
+ /** Read the session and, when there is one, the quota. */
11809
+ const load = (0, react.useCallback)(async () => {
11810
+ try {
11811
+ const body = await (await fetch(POOL_DOUBAO_SESSION_PATH, { credentials: "same-origin" })).json().catch(() => void 0);
11812
+ if (!mounted.current) return;
11813
+ const signed = body?.signedIn === true;
11814
+ setSignedIn(signed);
11815
+ if (!signed) {
11816
+ setWindows([]);
11817
+ return;
11818
+ }
11819
+ const quota = await (await fetch(POOL_DOUBAO_QUOTA_PATH, { credentials: "same-origin" })).json().catch(() => void 0);
11820
+ if (!mounted.current) return;
11821
+ setWindows(Array.isArray(quota?.windows) ? quota.windows : []);
11822
+ setExhausted(quota?.exhausted === true);
11823
+ if (typeof quota?.error === "string" && quota.error !== "") setError(quota.error);
11824
+ } catch (cause) {
11825
+ if (mounted.current) setError(cause instanceof Error ? cause.message : String(cause));
11826
+ }
11827
+ }, []);
11828
+ /** Open the sign-in browser and wait for it. */
11829
+ const signIn = (0, react.useCallback)(async () => {
11830
+ setError(void 0);
11831
+ setMessage("已打开浏览器,请在弹出的窗口里扫码或短信登录…");
11832
+ setBusy(true);
11833
+ try {
11834
+ const body = await (await fetch(POOL_DOUBAO_SESSION_PATH, {
11835
+ method: "POST",
11836
+ credentials: "same-origin"
11837
+ })).json().catch(() => void 0);
11838
+ if (!mounted.current) return;
11839
+ if (body?.signedIn === true) {
11840
+ setMessage(body.message ?? "登录成功");
11841
+ load();
11842
+ return;
11843
+ }
11844
+ setMessage(body?.message ?? "没有等到登录完成,可以再试一次");
11845
+ } catch (cause) {
11846
+ if (mounted.current) setError(cause instanceof Error ? cause.message : String(cause));
11847
+ } finally {
11848
+ if (mounted.current) setBusy(false);
11849
+ }
11850
+ }, [load]);
11851
+ /** Forget the session. */
11852
+ const signOut = (0, react.useCallback)(async () => {
11853
+ setError(void 0);
11854
+ setMessage(void 0);
11855
+ setBusy(true);
11856
+ try {
11857
+ await fetch(POOL_DOUBAO_SESSION_PATH, {
11858
+ method: "DELETE",
11859
+ credentials: "same-origin"
11860
+ });
11861
+ if (!mounted.current) return;
11862
+ setSignedIn(false);
11863
+ setWindows([]);
11864
+ setMessage("已退出登录");
11865
+ } catch (cause) {
11866
+ if (mounted.current) setError(cause instanceof Error ? cause.message : String(cause));
11867
+ } finally {
11868
+ if (mounted.current) setBusy(false);
11869
+ }
11870
+ }, []);
11871
+ (0, react.useEffect)(() => {
11872
+ load();
11873
+ }, [load]);
11874
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
11875
+ className: "dsm-xdpool-doubao",
11876
+ children: [
11877
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { children: DOUBAO_CSS }),
11878
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
11879
+ className: "dsm-xdpool-doubao-head",
11880
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
11881
+ className: "dsm-xdpool-doubao-id",
11882
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
11883
+ className: "dsm-xdpool-doubao-mark",
11884
+ children: "DB"
11885
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
11886
+ className: "dsm-xdpool-doubao-title",
11887
+ children: "豆包 · 字节跳动"
11888
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
11889
+ className: "dsm-xdpool-doubao-sub",
11890
+ children: signedIn ? t?.("doubao.ready") ?? "已登录,会话保存在本机" : t?.("doubao.sub") ?? "浏览器扫码登录一次,对话与工作任务模型都能用"
11891
+ })] })]
11892
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
11893
+ className: "dsm-xdpool-doubao-acts",
11894
+ children: signedIn ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
11895
+ type: "button",
11896
+ className: "dsm-xdpool-doubao-btn",
11897
+ disabled: busy,
11898
+ onClick: () => {
11899
+ load();
11900
+ },
11901
+ children: t?.("doubao.refresh") ?? "刷新额度"
11902
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
11903
+ type: "button",
11904
+ className: "dsm-xdpool-doubao-btn",
11905
+ disabled: busy,
11906
+ onClick: () => {
11907
+ signOut();
11908
+ },
11909
+ children: t?.("doubao.signOut") ?? "退出登录"
11910
+ })] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
11911
+ type: "button",
11912
+ className: "dsm-xdpool-doubao-btn",
11913
+ "data-tone": "primary",
11914
+ disabled: busy,
11915
+ onClick: () => {
11916
+ signIn();
11917
+ },
11918
+ children: busy ? t?.("doubao.waiting") ?? "等待登录…" : t?.("doubao.signIn") ?? "扫码登录"
11919
+ })
11920
+ })]
11921
+ }),
11922
+ message === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
11923
+ className: "dsm-xdpool-doubao-note",
11924
+ children: message
11925
+ }),
11926
+ error === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
11927
+ className: "dsm-xdpool-doubao-error",
11928
+ children: error
11929
+ }),
11930
+ signedIn ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
11931
+ exhausted ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
11932
+ className: "dsm-xdpool-doubao-error",
11933
+ children: "额度已用完,等待窗口重置。"
11934
+ }) : null,
11935
+ windows.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
11936
+ className: "dsm-xdpool-doubao-hint",
11937
+ children: "这个账号暂时没有可显示的额度窗口。"
11938
+ }) : windows.map((window, index) => {
11939
+ const percent = typeof window.usedPercent === "number" ? window.usedPercent : 0;
11940
+ const used = typeof window.usedAmount === "number" ? window.usedAmount : void 0;
11941
+ const total = typeof window.totalAmount === "number" ? window.totalAmount : void 0;
11942
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
11943
+ className: "dsm-xdpool-doubao-window",
11944
+ children: [
11945
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
11946
+ className: "dsm-xdpool-doubao-window-head",
11947
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
11948
+ className: "dsm-xdpool-doubao-window-name",
11949
+ children: windowLabel(window)
11950
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
11951
+ className: "dsm-xdpool-doubao-window-reset",
11952
+ children: resetText(window)
11953
+ })]
11954
+ }),
11955
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
11956
+ className: "dsm-xdpool-doubao-bar",
11957
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
11958
+ className: "dsm-xdpool-doubao-bar-fill",
11959
+ "data-exhausted": percent >= 100 ? "true" : "false",
11960
+ style: { width: `${String(Math.min(100, Math.max(0, percent)))}%` }
11961
+ })
11962
+ }),
11963
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
11964
+ className: "dsm-xdpool-doubao-window-foot",
11965
+ children: used === void 0 || total === void 0 ? `已用 ${String(Math.round(percent))}%` : `已用 ${String(used)} / ${String(total)}`
11966
+ })
11967
+ ]
11968
+ }, `${window.type ?? "w"}-${String(index)}`);
11969
+ }),
11970
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
11971
+ className: "dsm-xdpool-doubao-hint",
11972
+ children: t?.("doubao.modelsNote") ?? "模型在对话的模型选择器里:豆包 快速 / 2.1 Turbo / 2.1 Lite / 2.1 Pro / 自动 / 生图。"
11973
+ })
11974
+ ] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
11975
+ className: "dsm-xdpool-doubao-hint",
11976
+ children: t?.("doubao.why") ?? "豆包已关闭第三方扫码入口(服务端返回 2035),所以这里拉起一个浏览器窗口:在窗口里扫码或填手机号,登录成功后会话自动取回并保存在本机。"
11977
+ })
11978
+ ]
11979
+ });
11980
+ }
11981
+ /** The card's own stylesheet, travelling with the component. */
11982
+ const DOUBAO_CSS = `
11983
+ .dsm-xdpool-doubao{display:flex;flex-direction:column;gap:11px;padding:14px 16px 16px;border-radius:14px;border:1px solid color-mix(in srgb, var(--dsw-alias-border-l2,#ffffff1f) 82%, transparent);background:color-mix(in srgb, var(--dsw-alias-bg-layer-2,#1c1e22) 70%, transparent)}
11984
+ .dsm-xdpool-doubao-head{display:flex;align-items:flex-start;gap:12px;flex-wrap:wrap}
11985
+ .dsm-xdpool-doubao-id{display:flex;align-items:center;gap:10px;min-width:0}
11986
+ .dsm-xdpool-doubao-mark{width:34px;height:34px;border-radius:9px;display:grid;place-items:center;font-size:12px;font-weight:700;letter-spacing:.02em;color:#fff;background:linear-gradient(135deg,#4B7BF5,#2E5BD8);flex:none}
11987
+ .dsm-xdpool-doubao-title{font-size:13.5px;font-weight:650;color:var(--dsw-alias-label-primary,#e8eaf0)}
11988
+ .dsm-xdpool-doubao-sub{margin-top:2px;font-size:11px;line-height:16px;color:var(--dsw-alias-label-tertiary,#8a90a0)}
11989
+ .dsm-xdpool-doubao-acts{margin-left:auto;display:flex;gap:8px;flex:none}
11990
+ .dsm-xdpool-doubao-btn{appearance:none;-webkit-appearance:none;padding:5px 13px;border-radius:8px;cursor:pointer;font:inherit;font-size:12px;line-height:18px;border:1px solid color-mix(in srgb, var(--dsw-alias-border-l2,#ffffff1f) 95%, transparent);background:transparent;color:var(--dsw-alias-label-secondary,#b9bfcc);white-space:nowrap}
11991
+ .dsm-xdpool-doubao-btn:hover:not(:disabled){border-color:color-mix(in srgb, #3B6FD4 55%, transparent);color:var(--dsw-alias-label-primary,#e8eaf0)}
11992
+ .dsm-xdpool-doubao-btn:disabled{opacity:.5;cursor:not-allowed}
11993
+ .dsm-xdpool-doubao-btn[data-tone='primary']{border-color:color-mix(in srgb, #3B6FD4 62%, transparent);background:color-mix(in srgb, #3B6FD4 16%, transparent);color:#6E9AF0;font-weight:600}
11994
+ .dsm-xdpool-doubao-note{margin:0;font-size:11.5px;line-height:17px;color:var(--dsw-alias-state-success-primary,#22a06b)}
11995
+ .dsm-xdpool-doubao-error{margin:0;font-size:11.5px;line-height:17px;color:var(--dsw-alias-state-error-primary,#e5534b)}
11996
+ .dsm-xdpool-doubao-hint{margin:0;font-size:11px;line-height:16px;color:var(--dsw-alias-label-tertiary,#8a90a0)}
11997
+ .dsm-xdpool-doubao-window{display:flex;flex-direction:column;gap:6px;padding:10px 12px;border-radius:10px;background:color-mix(in srgb, #3B6FD4 8%, transparent);border:1px solid color-mix(in srgb, #3B6FD4 24%, transparent)}
11998
+ .dsm-xdpool-doubao-window-head{display:flex;align-items:baseline;gap:10px}
11999
+ .dsm-xdpool-doubao-window-name{font-size:12px;font-weight:600;color:var(--dsw-alias-label-primary,#e8eaf0)}
12000
+ .dsm-xdpool-doubao-window-reset{margin-left:auto;font-size:10.5px;color:var(--dsw-alias-label-tertiary,#8a90a0)}
12001
+ .dsm-xdpool-doubao-bar{height:6px;border-radius:999px;background:color-mix(in srgb, var(--dsw-alias-label-primary,#e8eaf0) 10%, transparent);overflow:hidden}
12002
+ .dsm-xdpool-doubao-bar-fill{display:block;height:100%;border-radius:999px;background:#3B6FD4;transition:width .2s ease}
12003
+ .dsm-xdpool-doubao-bar-fill[data-exhausted='true']{background:#e5534b}
12004
+ .dsm-xdpool-doubao-window-foot{font-size:10.5px;color:var(--dsw-alias-label-secondary,#b9bfcc);font-variant-numeric:tabular-nums}
12005
+ `;
11689
12006
  //#endregion
11690
12007
  //#region src/client/region-card.tsx
11691
12008
  /**
@@ -12035,6 +12352,64 @@ window.__ModuleLoader__.load({
12035
12352
  return paidSiblingOf(model, models);
12036
12353
  }
12037
12354
  //#endregion
12355
+ //#region src/doubao-models.ts
12356
+ /**
12357
+ * The models Doubao publishes.
12358
+ *
12359
+ * Every id was read off a real request the desktop app sent, not inferred. ⚠️ The encoding is
12360
+ * MIXED: `seed-lite-7b` is a string slug, `3`/`5`/`9` are numeric enum values — they travel as
12361
+ * JSON strings either way and must be forwarded verbatim, never parsed to a number.
12362
+ */
12363
+ const DOUBAO_MODELS = [
12364
+ {
12365
+ id: "0",
12366
+ name: "豆包 快速",
12367
+ reasoning: false
12368
+ },
12369
+ {
12370
+ id: "3",
12371
+ name: "豆包 2.1 Turbo",
12372
+ badge: "专家",
12373
+ reasoning: true
12374
+ },
12375
+ {
12376
+ id: "seed-lite-7b",
12377
+ name: "豆包 2.1 Lite",
12378
+ badge: "工作任务",
12379
+ reasoning: true
12380
+ },
12381
+ {
12382
+ id: "5",
12383
+ name: "豆包 2.1 Pro",
12384
+ badge: "工作任务",
12385
+ reasoning: true
12386
+ },
12387
+ {
12388
+ id: "9",
12389
+ name: "自动",
12390
+ badge: "工作任务",
12391
+ reasoning: true
12392
+ },
12393
+ {
12394
+ id: "image-gen",
12395
+ name: "豆包 生图",
12396
+ reasoning: true
12397
+ }
12398
+ ];
12399
+ /** The listing rows the card and the lane both show. */
12400
+ function doubaoListing() {
12401
+ return DOUBAO_MODELS.map((model) => {
12402
+ const parts = [];
12403
+ if (model.badge !== void 0 && model.badge !== "") parts.push(model.badge);
12404
+ if (model.reasoning === true) parts.push("推理");
12405
+ return {
12406
+ id: model.id,
12407
+ name: model.name,
12408
+ ...parts.length === 0 ? {} : { description: parts.join(" · ") }
12409
+ };
12410
+ });
12411
+ }
12412
+ //#endregion
12038
12413
  //#region src/client/ChannelPoolSection.tsx
12039
12414
  /**
12040
12415
  * Account-pool page, scan-channel section.
@@ -12158,6 +12533,57 @@ window.__ModuleLoader__.load({
12158
12533
  * moment a login lands), so the newest entry wins: it is the one whose
12159
12534
  * credential was written last.
12160
12535
  */
12536
+ /**
12537
+ * Doubao's account, described in the pack's account shape.
12538
+ *
12539
+ * The lane is the plugin's own, so this reads its session route and translates the answer
12540
+ * into the row the rest of this page already knows how to draw. `undefined` means "no
12541
+ * session", which is the ordinary state before a sign-in.
12542
+ */
12543
+ async function readDoubaoAccount() {
12544
+ try {
12545
+ const body = await (await fetch(POOL_DOUBAO_SESSION_PATH, { credentials: "same-origin" })).json().catch(() => void 0);
12546
+ if (body?.signedIn !== true) return void 0;
12547
+ return {
12548
+ id: "doubao:session",
12549
+ provider: "doubao",
12550
+ nickname: body.savedAt === void 0 ? "豆包账号" : `豆包(${String(body.savedAt).slice(0, 10)} 登录)`,
12551
+ enabled: true
12552
+ };
12553
+ } catch {
12554
+ return;
12555
+ }
12556
+ }
12557
+ /**
12558
+ * Doubao's quota, in the pack's balance row shape.
12559
+ *
12560
+ * The card prints one number per account, so it is the NARROWEST window: that is the one
12561
+ * that stops the next request, and reporting the widest would overstate what is left.
12562
+ */
12563
+ async function readDoubaoBalance() {
12564
+ try {
12565
+ const body = await (await fetch(POOL_DOUBAO_QUOTA_PATH, { credentials: "same-origin" })).json().catch(() => void 0);
12566
+ if (body?.signedIn !== true) return [];
12567
+ const windows = Array.isArray(body.windows) ? body.windows : [];
12568
+ if (windows.length === 0) return [{
12569
+ accountId: "doubao:session",
12570
+ nickname: "豆包账号",
12571
+ ...typeof body.error === "string" && body.error !== "" ? { error: body.error } : {}
12572
+ }];
12573
+ const lowest = windows.reduce((low, window) => {
12574
+ const used = typeof window.usedPercent === "number" ? window.usedPercent : 0;
12575
+ return Math.min(low, Math.max(0, 100 - used));
12576
+ }, 100);
12577
+ return [{
12578
+ accountId: "doubao:session",
12579
+ nickname: "豆包账号",
12580
+ balance: Math.round(lowest),
12581
+ extra: { unit: "%" }
12582
+ }];
12583
+ } catch {
12584
+ return [];
12585
+ }
12586
+ }
12161
12587
  function dedupeAccounts(accounts) {
12162
12588
  const byNickname = /* @__PURE__ */ new Map();
12163
12589
  const order = [];
@@ -12256,8 +12682,11 @@ window.__ModuleLoader__.load({
12256
12682
  * from painting over a newer wave-1 one.
12257
12683
  */
12258
12684
  const loadSeq = (0, react.useRef)(0);
12259
- (0, react.useEffect)(() => () => {
12260
- mountedRef.current = false;
12685
+ (0, react.useEffect)(() => {
12686
+ mountedRef.current = true;
12687
+ return () => {
12688
+ mountedRef.current = false;
12689
+ };
12261
12690
  }, []);
12262
12691
  const markBusy = (provider, on) => {
12263
12692
  setBusy((previous) => {
@@ -12273,11 +12702,38 @@ window.__ModuleLoader__.load({
12273
12702
  const channels = (await fetchChannels()).filter((channel) => !REGION_OWNED_CHANNELS.has(channel.id));
12274
12703
  const statusAnswer = await cachedProviderStatus(channels.map((channel) => channel.id));
12275
12704
  const statuses = providerStatusesFrom(statusAnswer);
12276
- const scanProviders = channels.map((channel) => channel.id).filter((id) => (statuses.get(id)?.accountsTotal ?? 0) > 0);
12705
+ /**
12706
+ * Doubao is added to the scan list by hand.
12707
+ *
12708
+ * `provider.status` counts accounts by walking the PACK's pools, and Doubao has no pack
12709
+ * adapter — so its count is always zero, and a filter keyed on that count drops the
12710
+ * channel before anything can be drawn. A signed-in Doubao session would then exist,
12711
+ * work, and appear nowhere on this page.
12712
+ */
12713
+ const doubaoAccount = await readDoubaoAccount();
12714
+ const scanProviders = channels.map((channel) => channel.id).filter((id) => (statuses.get(id)?.accountsTotal ?? 0) > 0 || id === "doubao" && doubaoAccount !== void 0);
12277
12715
  const perProvider = await Promise.all(scanProviders.map(async (provider) => {
12278
12716
  const wantBalances = channels.find((channel) => channel.id === provider)?.credits !== void 0;
12279
- const accountsPromise = callPack("account.list", { provider });
12280
- const modelsPromise = callPack("model.list", { provider });
12717
+ /**
12718
+ * Doubao answers from THIS plugin's routes, not from the pack.
12719
+ *
12720
+ * `account.list` and `model.list` are pack RPCs, and the pack has no Doubao adapter —
12721
+ * both answer "unknown provider". Calling them anyway would draw a card reading
12722
+ * "0 accounts, 0 models" for a lane that has one session and six models, and the
12723
+ * empty numbers would look like a failed sign-in.
12724
+ */
12725
+ const accountsPromise = provider === "doubao" ? Promise.resolve({
12726
+ ok: true,
12727
+ value: { accounts: doubaoAccount === void 0 ? [] : [doubaoAccount] }
12728
+ }) : callPack("account.list", { provider });
12729
+ const modelsPromise = provider === "doubao" ? Promise.resolve({
12730
+ ok: true,
12731
+ value: { models: doubaoListing().map((model) => ({
12732
+ id: model.id,
12733
+ name: model.name,
12734
+ ...model.description === void 0 ? {} : { description: model.description }
12735
+ })) }
12736
+ }) : callPack("model.list", { provider });
12281
12737
  const [accounts, models] = await Promise.all([accountsPromise.catch(() => refused("account.list failed")), modelsPromise.catch(() => refused("model.list failed"))]);
12282
12738
  const modelRows = modelsFrom(models.value);
12283
12739
  const modelEmptyBecauseRefused = modelRows.length === 0 && models.ok !== true;
@@ -12513,6 +12969,22 @@ window.__ModuleLoader__.load({
12513
12969
  balancePending: true
12514
12970
  } : entry));
12515
12971
  try {
12972
+ /**
12973
+ * Doubao reports its own balance, from its quota route.
12974
+ *
12975
+ * `credits.balances` is a pack RPC with no Doubao adapter, so it answers "unsupported
12976
+ * provider" and the card printed "no balance reported" under a signed-in account.
12977
+ */
12978
+ if (provider === "doubao") {
12979
+ const rows = await readDoubaoBalance();
12980
+ setEntries((previous) => previous.map((entry) => entry.channel.id === provider ? {
12981
+ ...entry,
12982
+ balancePending: false,
12983
+ balanceError: void 0,
12984
+ balances: rows
12985
+ } : entry));
12986
+ return;
12987
+ }
12516
12988
  const envelope = await callPack("credits.balances", force ? {
12517
12989
  provider,
12518
12990
  force: true
@@ -12646,6 +13118,26 @@ window.__ModuleLoader__.load({
12646
13118
  }
12647
13119
  markBusy(provider, true);
12648
13120
  try {
13121
+ /**
13122
+ * Doubao's account IS the session, so its actions are the session's.
13123
+ *
13124
+ * `account.delete` / `test` / `refresh` are pack RPCs addressed to the pack's credential
13125
+ * store, and Doubao has no entry there — every one of them answered "unsupported
13126
+ * provider", so the buttons did nothing and the row could not be removed.
13127
+ */
13128
+ if (provider === "doubao") {
13129
+ if (action === "delete") await fetch(POOL_DOUBAO_SESSION_PATH, {
13130
+ method: "DELETE",
13131
+ credentials: "same-origin"
13132
+ });
13133
+ else if (action === "refresh") await fetch(POOL_DOUBAO_QUOTA_PATH, { credentials: "same-origin" });
13134
+ else if (action === "test") await fetch(POOL_DOUBAO_SESSION_PATH, { credentials: "same-origin" });
13135
+ if (!mountedRef.current) return;
13136
+ invalidatePoolSnapshot();
13137
+ await load();
13138
+ setNotice(action === "delete" ? "已删除豆包会话" : "已刷新");
13139
+ return;
13140
+ }
12649
13141
  const enabledNow = entries.find((item) => item.channel.id === provider)?.accounts.find((account) => account.id === accountId)?.enabled !== false;
12650
13142
  const envelope = await callPack(action === "refresh" ? "account.refresh" : action === "test" ? "account.test" : action === "delete" ? "account.delete" : "account.update", action === "toggle" ? {
12651
13143
  accountId,
@@ -13492,7 +13984,7 @@ window.__ModuleLoader__.load({
13492
13984
  *
13493
13985
  * @module dsh-xdpool/version
13494
13986
  */
13495
- const POOL_VERSION = "2.6.7";
13987
+ const POOL_VERSION = "2.7.1";
13496
13988
  //#endregion
13497
13989
  //#region src/client/PoolCard.tsx
13498
13990
  /**
@@ -13886,6 +14378,10 @@ window.__ModuleLoader__.load({
13886
14378
  id: "gateway",
13887
14379
  label: t?.("shell.tabGateway") ?? "Gateway"
13888
14380
  },
14381
+ {
14382
+ id: "doubao",
14383
+ label: t?.("shell.tabDoubao") ?? "Doubao"
14384
+ },
13889
14385
  {
13890
14386
  id: "backup",
13891
14387
  label: t?.("shell.tabBackup") ?? "Backup"
@@ -13938,7 +14434,7 @@ window.__ModuleLoader__.load({
13938
14434
  * Whether a region's model pane is showing the WHOLE roster.
13939
14435
  *
13940
14436
  * Per region, and default off, because the pane opens on a card the user
13941
- * scrolled to reach: fourteen full rows of mostly-disabled models pushed
14437
+ * scrolled to reach: thirteen full rows of mostly-disabled models pushed
13942
14438
  * everything else a screen and a half further down (the reported "无限往下
13943
14439
  * 续"). The enabled rows are what "my models" means; the rest are one click
13944
14440
  * away and the button says how many there are.
@@ -14775,7 +15271,7 @@ window.__ModuleLoader__.load({
14775
15271
  children: page === "aggregate" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AggregatePage, { t }) : page === "channels" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChannelsPage, { t }) : page === "ledger" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LedgerPage, {
14776
15272
  t,
14777
15273
  usage
14778
- }) : page === "routing" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RoutingPage, { t }) : page === "gateway" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GatewayPage, { t }) : page === "backup" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BackupPanel, { t }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
15274
+ }) : page === "routing" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RoutingPage, { t }) : page === "doubao" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DoubaoPage, { t }) : page === "gateway" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GatewayPage, { t }) : page === "backup" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BackupPanel, { t }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
14779
15275
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { children: POOL_CARD_CSS }),
14780
15276
  usage === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
14781
15277
  className: "dsm-xdpool-card dsm-xdpool-usage",
@@ -16492,7 +16988,7 @@ window.__ModuleLoader__.load({
16492
16988
  "aria-hidden": "true"
16493
16989
  })
16494
16990
  }),
16495
- !open ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
16991
+ !open ? null : (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
16496
16992
  ref: panelRef,
16497
16993
  className: "dsm-xdpool-dotpanel",
16498
16994
  role: "dialog",
@@ -16560,7 +17056,7 @@ window.__ModuleLoader__.load({
16560
17056
  })
16561
17057
  }) : null
16562
17058
  ] })]
16563
- })
17059
+ }), document.body)
16564
17060
  ]
16565
17061
  });
16566
17062
  }
@@ -16885,6 +17381,14 @@ window.__ModuleLoader__.load({
16885
17381
  "agg.noKeyNeeded": "No key needed",
16886
17382
  "agg.models": "{count} models",
16887
17383
  "agg.unsupported": "This vendor signs in via OAuth/ADC, which this lane cannot drive.",
17384
+ "doubao.ready": "Signed in; the session is stored locally",
17385
+ "doubao.sub": "One browser sign-in, then the chat and work-task models are available",
17386
+ "doubao.signIn": "Sign in with a browser",
17387
+ "doubao.signOut": "Sign out",
17388
+ "doubao.waiting": "Waiting for sign-in…",
17389
+ "doubao.refresh": "Refresh quota",
17390
+ "doubao.why": "Doubao has closed third-party QR login (the server answers 2035), so this opens a browser window: scan or enter a phone number there, and the session is taken back and stored on this machine.",
17391
+ "doubao.modelsNote": "The models are in the conversation picker: Doubao Quick / 2.1 Turbo / 2.1 Lite / 2.1 Pro / Auto / Image.",
16888
17392
  "agg.listingYes": "Model list available",
16889
17393
  "agg.saved": "Saved",
16890
17394
  "agg.cleared": "Cleared",
@@ -16983,6 +17487,7 @@ window.__ModuleLoader__.load({
16983
17487
  "chan.pending": "The login channels are still loading…",
16984
17488
  "chan.unavailable": "The login channels could not start on this host.",
16985
17489
  "chan.ownedElsewhere": "These login channels are already served by another plugin — the same thirteen sign-in methods are one click away on that build’s own page.",
17490
+ "chan.ownedElsewhereRow": "Sign in on the “Our Free Model” page",
16986
17491
  "chan.empty": "No channel is connected yet.",
16987
17492
  "shell.brand": "XD Pool",
16988
17493
  "shell.star": "Star",
@@ -17009,6 +17514,7 @@ window.__ModuleLoader__.load({
17009
17514
  "shell.tabRouting": "Routing",
17010
17515
  "shell.subRouting": "Chains that try models in order, so one busy or rate-limited model falls through to the next.",
17011
17516
  "shell.tabGateway": "Gateway",
17517
+ "shell.tabDoubao": "Doubao",
17012
17518
  "shell.tabBackup": "Backup",
17013
17519
  "shell.subGateway": "Open the pool to the other devices on your network.",
17014
17520
  "gw.title": "Gateway",
@@ -17481,6 +17987,14 @@ window.__ModuleLoader__.load({
17481
17987
  "agg.noKeyNeeded": "无需 key",
17482
17988
  "agg.models": "{count} 个模型",
17483
17989
  "agg.unsupported": "该厂商需要 OAuth/ADC 授权,这条通道暂时接不了。",
17990
+ "doubao.ready": "已登录,会话保存在本机",
17991
+ "doubao.sub": "浏览器扫码登录一次,对话与工作任务模型都能用",
17992
+ "doubao.signIn": "扫码登录",
17993
+ "doubao.signOut": "退出登录",
17994
+ "doubao.waiting": "等待登录…",
17995
+ "doubao.refresh": "刷新额度",
17996
+ "doubao.why": "豆包已关闭第三方扫码入口(服务端返回 2035),所以这里拉起一个浏览器窗口:在窗口里扫码或填手机号,登录成功后会话自动取回并保存在本机。",
17997
+ "doubao.modelsNote": "模型在对话的模型选择器里:豆包 快速 / 2.1 Turbo / 2.1 Lite / 2.1 Pro / 自动 / 生图。",
17484
17998
  "agg.listingYes": "支持拉取模型列表",
17485
17999
  "agg.saved": "已保存",
17486
18000
  "agg.cleared": "已清除",
@@ -17579,6 +18093,7 @@ window.__ModuleLoader__.load({
17579
18093
  "chan.pending": "扫码登录通道正在加载…",
17580
18094
  "chan.unavailable": "本机上扫码登录通道没能启动。",
17581
18095
  "chan.ownedElsewhere": "这些扫码登录通道已经由另一个插件接管了——同样这十三种登录方式,在它自己的页面上点一下就能用。",
18096
+ "chan.ownedElsewhereRow": "在「我们的免费模型」里登录",
17582
18097
  "chan.empty": "还没有任何渠道连上来。",
17583
18098
  "shell.brand": "XD Pool",
17584
18099
  "shell.star": "点Star",
@@ -17605,6 +18120,7 @@ window.__ModuleLoader__.load({
17605
18120
  "shell.tabRouting": "路由",
17606
18121
  "shell.subRouting": "把几个模型串成一条链,按顺序试;一个忙了或被限流,就自动落到下一个。",
17607
18122
  "shell.tabGateway": "网关",
18123
+ "shell.tabDoubao": "豆包",
17608
18124
  "shell.tabBackup": "备份",
17609
18125
  "shell.subGateway": "把账号池开放给同网络里的其它设备。",
17610
18126
  "gw.title": "网关",