dsh-connect-workbuddy 5.19.0 → 5.20.0

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
@@ -477,6 +477,34 @@ window.__ModuleLoader__.load({
477
477
  });
478
478
  }
479
479
  /**
480
+ * Build the next `regions` FIELD carrying one region's CN gateway override
481
+ * (issue #220).
482
+ *
483
+ * Same whole-slot merge as every other helper here: only `cnBase` changes, so
484
+ * setting a host cannot drop the model directory, the pool preferences or the
485
+ * switches that share this slot. An empty string is written as-is rather than
486
+ * deleting the key — it means "back to the built-in gateway", which must survive
487
+ * a read-back, and `resolveCnGateway('')` already reads both the same way.
488
+ */
489
+ function nextRegionCnBase(value, region, cnBase) {
490
+ return nextRegionSlots(regionsMapOf(value), region, {
491
+ ...regionSlotOf(value, region),
492
+ cnBase
493
+ });
494
+ }
495
+ /**
496
+ * Read one region's saved CN gateway override, or `''` when it has none.
497
+ *
498
+ * Deliberately tolerant of a non-string: the settings mirror can hold whatever a
499
+ * previous version wrote, and throwing here would take out the whole capabilities
500
+ * panel over one malformed field. A value that is not a string is treated as
501
+ * "not configured", which is exactly how `resolveCnGateway` treats it.
502
+ */
503
+ function regionCnBaseOf(value, region) {
504
+ const raw = regionSlotOf(value, region)["cnBase"];
505
+ return typeof raw === "string" ? raw : "";
506
+ }
507
+ /**
480
508
  * Whether one region's sidebar credit line is shown. Opt-out: only an explicit
481
509
  * `false` hides it, so a config written before this switch existed keeps the
482
510
  * line visible exactly as a fresh install does.
@@ -1296,6 +1324,32 @@ window.__ModuleLoader__.load({
1296
1324
  });
1297
1325
  }
1298
1326
  /**
1327
+ * Write the CN gateway override (issue #220), with the same landed-check as
1328
+ * every other settings write.
1329
+ *
1330
+ * Carries the region's whole slot through untouched — only `cnBase` changes —
1331
+ * so writing a host cannot drop the model directory, the pool preferences or
1332
+ * the switches that live beside it in the same slot.
1333
+ *
1334
+ * Validation is deliberately NOT here: the caller runs `resolveCnGateway` before
1335
+ * calling, because the rejection reason has to be worded for the user ("not a
1336
+ * known CN brand" vs "must be https"), and a bare `WorkBuddySettingsWriteError`
1337
+ * cannot say that. This function's only job is landing the value.
1338
+ *
1339
+ * @param scope - the bound settings scope for this plugin's namespace.
1340
+ * @param region - the region being written (always `cn` today: the international
1341
+ * gateways follow the credential's brand domain and have no counterpart).
1342
+ * @param cnBase - the validated base URL, or `''` to restore the built-in gateway.
1343
+ * @param slot - the region's COMPLETE next slot (caller owns the merge).
1344
+ * @throws {WorkBuddySettingsWriteError} when neither writer persists the value.
1345
+ */
1346
+ async function writeRegionCnBase(scope, region, cnBase, slot) {
1347
+ await writeField(scope, "regions", region, slot, (readBack) => {
1348
+ const stored = readBack;
1349
+ return stored !== null && stored !== void 0 && stored["cnBase"] === cnBase;
1350
+ });
1351
+ }
1352
+ /**
1299
1353
  * Show or hide one region's sidebar credit line, with the same landed-check as
1300
1354
  * every other settings write.
1301
1355
  *
@@ -1420,6 +1474,127 @@ window.__ModuleLoader__.load({
1420
1474
  });
1421
1475
  }
1422
1476
  //#endregion
1477
+ //#region src/cn-gateway.ts
1478
+ /**
1479
+ * The CN region's gateway host, and the ONE place an override is validated.
1480
+ *
1481
+ * ## Why this exists (issue #220)
1482
+ *
1483
+ * The CN chat gateway was the single hard-coded constant
1484
+ * `https://copilot.tencent.com`. In a corporate network that filters on the TLS
1485
+ * ClientHello's SNI, that name is reset before the handshake completes — while
1486
+ * the SAME network lets the WorkBuddy desktop app work, because the app reads a
1487
+ * failover list from its own config and uses `wb.tencentbuddy.com` as well.
1488
+ *
1489
+ * The reporter measured (2026-11-06): `copilot.tencent.com` answers
1490
+ * `ECONNRESET` in <100ms while `wb.tencentbuddy.com` answers a normal
1491
+ * `401 Authorization Required`. This module is what lets such a user point the
1492
+ * plugin at a host their network actually permits.
1493
+ *
1494
+ * ## Why an allowlist, and not "any URL you like"
1495
+ *
1496
+ * The value feeds `Authorization: Bearer <token>` on every CN request, plus the
1497
+ * refresh-token exchange. A free-form base is therefore a **credential
1498
+ * exfiltration primitive**: whoever can edit the settings (a synced profile, a
1499
+ * shared dotfile, a pasted "fix" from a forum post) could redirect a live
1500
+ * WorkBuddy token to a host they run. That is a strictly worse failure than the
1501
+ * timeout it fixes, and it is invisible — the requests would keep succeeding.
1502
+ *
1503
+ * So the override names a HOST from a closed set, never a URL from the open
1504
+ * internet. The set is the CN product's own brand registrable domains, measured
1505
+ * 2026-11-06 to answer the chat, billing, catalog and busy routes identically
1506
+ * (see `docs/CN_GATEWAY_FALLBACK.md`):
1507
+ *
1508
+ * copilot.tencent.com the shipping default
1509
+ * wb.tencentbuddy.com what the desktop app's failover.json lists
1510
+ * www.workbuddy.cn the brand host
1511
+ * www.codebuddy.cn the sibling brand host, also the billing base
1512
+ *
1513
+ * Each is admitted by REGISTRABLE domain, so any subdomain of those brands
1514
+ * qualifies and a lookalike (`wb.tencentbuddy.com.evil.example`) cannot —
1515
+ * the same rule `knownRegionOf` already applies to credential domains.
1516
+ *
1517
+ * ## What an override does NOT change
1518
+ *
1519
+ * `Origin` / `Referer` stay on the billing base (see `originReferer`): they
1520
+ * describe which web app the request comes from, not which socket it reaches.
1521
+ * Rewriting them from the override would make the identity claim disagree with
1522
+ * itself for no benefit — the gateway reads them as "this is the CN web app".
1523
+ *
1524
+ * @module dsh-connect-workbuddy/cn-gateway
1525
+ */
1526
+ /** The CN chat gateway the plugin has always used. */
1527
+ const CN_GATEWAY_DEFAULT = "https://copilot.tencent.com";
1528
+ /**
1529
+ * Hosts an override may name, as registrable domains.
1530
+ *
1531
+ * A closed set is the security boundary described in this module's header. Adding
1532
+ * a host here is a deliberate act that must come with a measurement showing it
1533
+ * answers the CN routes, not with a guess about the brand.
1534
+ */
1535
+ const ALLOWED_CN_DOMAINS = [
1536
+ "copilot.tencent.com",
1537
+ "tencentbuddy.com",
1538
+ "workbuddy.cn",
1539
+ "codebuddy.cn"
1540
+ ];
1541
+ /**
1542
+ * Whether `hostname` belongs to one of the CN brands above.
1543
+ *
1544
+ * Matched on the registrable domain (`host === domain` or `host.endsWith('.' +
1545
+ * domain)`), so `wb.tencentbuddy.com` and `copilot.internal.tencentbuddy.com`
1546
+ * both qualify while `tencentbuddy.com.evil.example` does not.
1547
+ */
1548
+ function isKnownCnHost(hostname) {
1549
+ const lowered = hostname.trim().toLowerCase();
1550
+ if (lowered === "") return false;
1551
+ return ALLOWED_CN_DOMAINS.some((domain) => lowered === domain || lowered.endsWith(`.${domain}`));
1552
+ }
1553
+ /**
1554
+ * Resolve the CN gateway base from an optional user-supplied value.
1555
+ *
1556
+ * An ABSENT or blank value is the normal case and yields the default with
1557
+ * `overridden: false`. A non-blank value must pass every check or the caller
1558
+ * gets `ok: false` and is expected to say so rather than silently falling back:
1559
+ * a user who typed a host and got the default anyway has no way to tell the
1560
+ * setting was ignored, and would keep debugging a network they already fixed.
1561
+ */
1562
+ function resolveCnGateway(value) {
1563
+ const raw = typeof value === "string" ? value.trim() : "";
1564
+ if (raw === "") return {
1565
+ ok: true,
1566
+ base: CN_GATEWAY_DEFAULT,
1567
+ host: "copilot.tencent.com",
1568
+ overridden: false
1569
+ };
1570
+ let parsed;
1571
+ try {
1572
+ parsed = new URL(raw);
1573
+ } catch {
1574
+ return {
1575
+ ok: false,
1576
+ reason: "malformed",
1577
+ value: raw
1578
+ };
1579
+ }
1580
+ if (parsed.protocol !== "https:") return {
1581
+ ok: false,
1582
+ reason: "insecure",
1583
+ value: raw
1584
+ };
1585
+ if (!isKnownCnHost(parsed.hostname)) return {
1586
+ ok: false,
1587
+ reason: "unknown-host",
1588
+ value: raw
1589
+ };
1590
+ return {
1591
+ ok: true,
1592
+ base: `https://${parsed.hostname.toLowerCase()}`,
1593
+ host: parsed.hostname.toLowerCase(),
1594
+ overridden: true
1595
+ };
1596
+ }
1597
+ //#endregion
1423
1598
  //#region src/client/panel-switch.ts
1424
1599
  /**
1425
1600
  * Whether the OPTIONAL sidebar panel is switched on, as the browser half sees
@@ -4006,7 +4181,7 @@ window.__ModuleLoader__.load({
4006
4181
  changeDeviceMode(mode);
4007
4182
  }
4008
4183
  }, t(mode === "virtual" ? "row.deviceModeVirtual" : "row.deviceModeReal"));
4009
- })), (0, react.createElement)("span", { className: "dsm-workbuddy-hint" }, modeHintBlocked ? t("row.deviceModeRealUnsupported") : deviceMode === "real" ? t("row.deviceModeHintReal") : t("row.deviceModeHintVirtual"))), (0, react.createElement)("div", { className: `dsm-workbuddy-pool-table${pool.checkinSupported ? " dsm-workbuddy-pool-table-checkin" : ""}` }, (0, react.createElement)("div", { className: "dsm-workbuddy-pool-row dsm-workbuddy-pool-row-head" }, (0, react.createElement)("span", null, t("row.poolColumnAccount")), (0, react.createElement)("span", null, t("row.poolColumnCredits")), (0, react.createElement)("span", null, t("row.poolColumnProbe")), pool.checkinSupported ? (0, react.createElement)("span", null, t("row.poolColumnCheckin")) : null, (0, react.createElement)("span", null)), ...(() => {
4184
+ })), (0, react.createElement)("span", { className: "dsm-workbuddy-hint" }, modeHintBlocked ? t("row.deviceModeRealUnsupported") : deviceMode === "real" ? t("row.deviceModeHintReal") : t("row.deviceModeHintVirtual"))), (0, react.createElement)("div", { className: `dsm-workbuddy-pool-table${pool.checkinSupported ? " dsm-workbuddy-pool-table-checkin" : ""}` }, (0, react.createElement)("div", { className: "dsm-workbuddy-pool-row dsm-workbuddy-pool-row-head" }, (0, react.createElement)("span", { className: "dsm-workbuddy-pool-col-account" }, t("row.poolColumnAccount")), (0, react.createElement)("span", null, t("row.poolColumnCredits")), (0, react.createElement)("span", null, t("row.poolColumnProbe")), pool.checkinSupported ? (0, react.createElement)("span", null, t("row.poolColumnCheckin")) : null, (0, react.createElement)("span", null)), ...(() => {
4010
4185
  const ordered = sortAccountsByOrder(pool.accounts, orderIds);
4011
4186
  let memberSeen = 0;
4012
4187
  let memberTotal = 0;
@@ -6181,7 +6356,7 @@ window.__ModuleLoader__.load({
6181
6356
  .dsm-btn-outline:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-dimmed);background:rgba(255,255,255,.04)}
6182
6357
  .dsm-btn-primary{background:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}
6183
6358
  .dsm-btn-primary:hover:not(:disabled){opacity:.9}
6184
- .dsm-workbuddy-usage{display:flex;flex-direction:column;gap:16px;margin:0;padding:16px 0 4px;background:var(--dsw-alias-bg-layer-1,#17181b);border-radius:12px}
6359
+ .dsm-workbuddy-usage{--dsm-workbuddy-surface:var(--dsw-alias-bg-layer-1,#17181b);display:flex;flex-direction:column;gap:16px;margin:0;padding:16px 0 4px;background:var(--dsw-alias-bg-layer-1,#17181b);border-radius:12px}
6185
6360
  /* The provider bar: one CARD per region, side by side.
6186
6361
  *
6187
6362
  * COPIED FROM dsh-connect-trae, rule for rule, because an approximation of it
@@ -6253,8 +6428,33 @@ window.__ModuleLoader__.load({
6253
6428
  * ON TOP of that gap and doubled the distance (measured: 32px where the rhythm
6254
6429
  * is 16px).
6255
6430
  *
6256
- * The bottom rule stays: it is the tabs' underline, not spacing. */
6257
- .dsm-workbuddy-panels{display:flex;align-items:stretch;gap:2px;margin:0;border-bottom:1px solid var(--dsw-alias-border-l1,rgba(127,127,127,.24))}
6431
+ * The bottom rule stays: it is the tabs' underline, not spacing.
6432
+ *
6433
+ * STICKY, so the strip cannot be scrolled away from the sections it switches
6434
+ * (learned from dsh-connect-trae 4.9.0, same migration). This is NOT a decision
6435
+ * to take over scrolling: the Settings panel's own .options column scrolls, and
6436
+ * the card must not add a second scroller inside it — so there is no height:100%
6437
+ * and no overflow here either. But "not scrolling" is not the same as "may
6438
+ * disappear": the pool sits below the fold, and by the time the reader scrolls
6439
+ * down to it the five tabs are off the top, so switching sections means
6440
+ * scrolling the whole page back up first.
6441
+ *
6442
+ * The background is not decoration: it is what stops the rows sliding under a
6443
+ * transparent strip and showing through the gaps between the labels — and under
6444
+ * a wallpaper (issue #209) a transparent one would be unreadable outright.
6445
+ *
6446
+ * It paints --dsm-workbuddy-surface, NOT a hard-coded layer. That variable is
6447
+ * declared beside the fill on every surface's own .dsm-workbuddy-usage rule
6448
+ * (card / page / settings), which is the element whose opaque area the strip sits
6449
+ * inside. The three do not agree — the page paints layer-3 while the other two
6450
+ * paint layer-1 — so a strip pinned to either constant becomes a visibly lighter
6451
+ * bar over the other. One variable, declared where the fill is declared, is what
6452
+ * keeps the two from drifting; a test requires every declarer to declare it.
6453
+ *
6454
+ * top:-1px rather than 0, because the strip's own border-bottom is drawn
6455
+ * OUTSIDE the box and 0 leaves a 1px slit for the scrolling rows to show
6456
+ * through. */
6457
+ .dsm-workbuddy-panels{position:sticky;top:-1px;z-index:2;display:flex;align-items:stretch;gap:2px;margin:0;border-bottom:1px solid var(--dsw-alias-border-l1,rgba(127,127,127,.24));background:var(--dsm-workbuddy-surface,var(--dsw-alias-bg-layer-1,#17181b))}
6258
6458
  .dsm-workbuddy-panel-tab{appearance:none;font:inherit;cursor:pointer;border:0;background:transparent;padding:7px 11px;margin-bottom:-1px;border-bottom:2px solid transparent;color:var(--dsw-alias-label-tertiary,#999);font-size:13px;font-weight:600;line-height:20px;white-space:nowrap;transition:color .15s,border-color .15s}
6259
6459
  .dsm-workbuddy-panel-tab:hover:not(.dsm-workbuddy-panel-tab-active){color:var(--dsw-alias-label-primary,#e6e6e6)}
6260
6460
  .dsm-workbuddy-panel-tab:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#5686fe);outline-offset:1px}
@@ -6305,6 +6505,23 @@ window.__ModuleLoader__.load({
6305
6505
  CONTRAST colour, so a ticked box painted itself as a heavy black pill — the
6306
6506
  loudest object in a section made of plain 13px text. */
6307
6507
  .dsm-workbuddy-pref input{flex:none;cursor:pointer;accent-color:var(--dsw-alias-brand-primary,#5686fe)}
6508
+ /* ── The CN gateway override (issue #220) ─────────────────────────────────────
6509
+ * One bordered block so it does not read as a fifth switch: every other control
6510
+ * in this section is a checkbox that commits on the click, this one is a text
6511
+ * field that needs an explicit Save. Giving it a card of its own is what says
6512
+ * "this answers a different question".
6513
+ *
6514
+ * The row wraps, and the input takes the whole width when it does: a host name is
6515
+ * long (https://wb.tencentbuddy.com is 26 characters) and a half-width input in
6516
+ * the panel column would show about eight of them. */
6517
+ .dsm-workbuddy-cnbase{display:flex;flex-direction:column;gap:8px;padding:10px 12px;border:1px solid var(--dsw-alias-border-l2,#3a3d45);border-radius:10px;background:var(--dsw-alias-bg-layer-2,#24262c)}
6518
+ .dsm-workbuddy-cnbase-row{display:flex;flex-direction:column;gap:8px}
6519
+ .dsm-workbuddy-cnbase-input{box-sizing:border-box;width:100%;padding:6px 10px;border:1px solid var(--dsw-alias-border-l2,#3a3d45);border-radius:8px;background:var(--dsw-alias-bg-layer-3,#2a2c33);color:var(--dsw-alias-label-primary,#e6e6e6);font:inherit;font-size:13px;font-family:ui-monospace,SFMono-Regular,Menlo,monospace}
6520
+ .dsm-workbuddy-cnbase-input:disabled{opacity:.5;cursor:default}
6521
+ .dsm-workbuddy-cnbase-input:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#5686fe);outline-offset:1px}
6522
+ .dsm-workbuddy-cnbase-error{margin:0;font-size:12px;line-height:17px;color:var(--dsw-alias-state-error-primary,#ef4444)}
6523
+ .dsm-workbuddy-cnbase-notice{margin:0;font-size:12px;line-height:17px;color:var(--dsw-alias-state-success-primary,#22a06b)}
6524
+ .dsm-workbuddy-cnbase-actions{display:flex;align-items:center;justify-content:flex-end;gap:8px}
6308
6525
  .dsm-workbuddy-pref-check,.dsm-workbuddy-image-tool-check,.dsm-workbuddy-video-tool-check,.dsm-workbuddy-cli-bridge-check,.dsm-workbuddy-sidebar-panel-check,.dsm-workbuddy-upstream-check,.dsm-workbuddy-channel-continue-check{inline-size:15px;block-size:15px;margin:3px 0 0}
6309
6526
  /* The upstream-identity switches are their own group, so they get a divider
6310
6527
  above them instead of relying on spacing alone: they change the request the
@@ -6713,6 +6930,20 @@ window.__ModuleLoader__.load({
6713
6930
  .dsm-workbuddy-pool-table:not(.dsm-workbuddy-pool-table-checkin) .dsm-workbuddy-pool-row{grid-template-columns:1.6fr 1fr 1.3fr 1.7fr}
6714
6931
  .dsm-workbuddy-pool-row:first-child{border-top:0}
6715
6932
  .dsm-workbuddy-pool-row-head{padding:8px 14px;background:var(--dsw-alias-bg-layer-3,#2a2c33);color:var(--dsw-alias-label-tertiary,#999);font-size:11px;font-weight:600;letter-spacing:.02em;text-transform:uppercase}
6933
+ /* WHERE THE LABELED COLUMN ACTUALLY STARTS (learned from dsh-connect-trae, which
6934
+ carries the same rule for the same reason).
6935
+ *
6936
+ * The account cell's first element is the membership checkbox, so the account
6937
+ * NAME begins well inside the track. Measured at the plugin page's 1120px: the
6938
+ * header cell starts at x=65 and the name at x=103 — a 38px gap. Flush to the
6939
+ * cell edge, the word 「账号」 floated in the padding and pointed at nothing.
6940
+ *
6941
+ * 38px is the checkbox (13px) plus the cell's 8px gap plus the vertical
6942
+ * centring slack of an 18px glyph in a 20px label; rounded to the value that
6943
+ * measured flush rather than derived, because the two cells do not share a
6944
+ * box. The narrow form hides the whole header row, so this offset never has to
6945
+ * be re-tuned for the stacked layout. */
6946
+ .dsm-workbuddy-pool-col-account{padding-inline-start:38px}
6716
6947
  .dsm-workbuddy-pool-row-current{background:rgba(86,134,254,.07)}
6717
6948
  /* The serving row, made findable at a glance: a left accent bar plus the tint.
6718
6949
  The bar is what distinguishes it in a long table, where a 7%-opacity wash
@@ -7035,9 +7266,18 @@ window.__ModuleLoader__.load({
7035
7266
  .dsm-workbuddy-pool-row-actions{display:flex;gap:6px;align-items:center;justify-content:flex-end;flex:none}
7036
7267
  .dsm-workbuddy-pool-row-actions .dsm-workbuddy-pool-small-btn{white-space:nowrap}
7037
7268
  .dsm-workbuddy-pool-row-actions .dsm-workbuddy-pool-small-btn{padding:2px 10px;font-size:12px}
7038
- /* This account's own test model (issue #61). Narrower than the section-level
7039
- picker so a long model name cannot push the two buttons out of the row. */
7040
- @media (max-width:760px){.dsm-workbuddy-pool-row{grid-template-columns:1fr 1fr;row-gap:6px}.dsm-workbuddy-pool-select{max-width:180px}}
7269
+ /* The picker's cap, narrowed on a phone. NOTE this @media measures the VIEWPORT,
7270
+ which is why it is the only rule left here that is allowed to: it exists for
7271
+ the Plugins page at phone width, where the viewport IS the constraint. The
7272
+ ROW's own narrow form is the @container block further down — a media query
7273
+ cannot express it, because inside the Settings panel the viewport is 1400px
7274
+ while the table gets 564px.
7275
+ *
7276
+ * The row's re-grid that used to live here was the source of that panel's
7277
+ * 2x2 defect: it fired at phone widths only, so the 564px column kept the
7278
+ * five-track desktop grid and clipped every cell. Removed rather than left
7279
+ * behind, because a second, half-correct narrow form is worse than none. */
7280
+ @media (max-width:760px){.dsm-workbuddy-pool-select{max-width:180px}}
7041
7281
  /* The settings rows (target model, probe size) are flex with a content column
7042
7282
  * that grows and a control that does not. In the Settings panel the control was
7043
7283
  * squeezed to a sliver: max-width:260px caps it but nothing gives it a floor,
@@ -7077,6 +7317,34 @@ window.__ModuleLoader__.load({
7077
7317
  /* The column headers describe tracks that no longer exist. */
7078
7318
  .dsm-workbuddy-pool-row-head{display:none}
7079
7319
  .dsm-workbuddy-pool-account{flex:1 1 100%;align-items:center}
7320
+ /* THE ACCOUNT CELL'S OWN COLUMN, collapsed the same way — and this is the
7321
+ rule that actually decides the row height (learned from dsh-connect-trae
7322
+ 4.9.0, which shipped the outer half of this fix and measured 138px rows).
7323
+ *
7324
+ * Collapsing only .dsm-workbuddy-pool-account above is NOT enough: that is
7325
+ * just a flex wrapper. The cells that stack are one level deeper, inside
7326
+ * .dsm-workbuddy-pool-account-name, which declares flex-direction:column so
7327
+ * that the name, the rank badge with its ↑/↓ arrows, the 「当前使用」 pill and
7328
+ * the 「测试于 …」 line read as a small card when the table is WIDE.
7329
+ *
7330
+ * In the Settings column they have no reason to keep one line each: measured
7331
+ * at 549px, that block was 81px of the row's 157px — five lines (name, rank +
7332
+ * arrows, current badge, tested-at), while the three facts beside it sat on
7333
+ * one 18px line. The row therefore read as "one tall account block and three
7334
+ * strays", and every extra row cost the reader two thirds of a screen.
7335
+ *
7336
+ * Read as a sentence it is one line — 「用户7520607992 · 第 1 位 ↑↓ · 当前使用 ·
7337
+ * 测试于 11/06, 03:57」 — so it wraps among itself instead of stacking. The
7338
+ * margins the wide form needs (2px above the badge, 2px above the current pill)
7339
+ * go away with the stacking: in a wrapped row they become uneven leading. */
7340
+ .dsm-workbuddy-pool-account-name{flex-direction:row;flex-wrap:wrap;align-items:baseline;gap:2px 8px}
7341
+ .dsm-workbuddy-pool-account-name .dsm-workbuddy-pool-order{margin-top:0}
7342
+ .dsm-workbuddy-pool-account-name .dsm-workbuddy-pool-current-tag{align-self:center;margin-top:0}
7343
+ /* The name still has to be allowed to SHRINK. The <b> carries nowrap + ellipsis,
7344
+ whose whole point is that a long account name ends in "…" rather than
7345
+ pushing the line — but as a flex item it defaults to min-width:auto, i.e.
7346
+ its content width, and then the ellipsis can never engage. */
7347
+ .dsm-workbuddy-pool-account-name b{min-width:0;max-width:100%}
7080
7348
  /* The three middle facts, laid out as one line of the same sentence. */
7081
7349
  .dsm-workbuddy-pool-credits{flex:0 1 auto;flex-direction:row;flex-wrap:wrap;align-items:baseline;gap:2px 8px}
7082
7350
  .dsm-workbuddy-pool-probe{flex:1 1 auto;flex-direction:row;flex-wrap:wrap;align-items:baseline;gap:2px 8px}
@@ -7209,7 +7477,7 @@ window.__ModuleLoader__.load({
7209
7477
  .dsm-workbuddy-page-icon{width:40px;height:40px;border-radius:9px;align-self:flex-start;margin-top:14px}
7210
7478
  .dsm-workbuddy-page-title{margin:0;font-size:20px;font-weight:600;line-height:1.4}
7211
7479
  .dsm-workbuddy-page-desc{margin:0;font-size:13px;line-height:1.5;color:var(--dsw-alias-label-tertiary,#999)}
7212
- .dsm-workbuddy-page-body .dsm-workbuddy-usage{padding:20px 20px 8px;border:1px solid var(--dsw-alias-border-l2,#36373b);background:var(--dsw-alias-bg-layer-3,#202126);border-radius:12px}
7480
+ .dsm-workbuddy-page-body .dsm-workbuddy-usage{--dsm-workbuddy-surface:var(--dsw-alias-bg-layer-3,#202126);padding:20px 20px 8px;border:1px solid var(--dsw-alias-border-l2,#36373b);background:var(--dsw-alias-bg-layer-3,#202126);border-radius:12px}
7213
7481
  /* ---- 设置面板里的一节(settings.section,5.19.0)------------------------
7214
7482
  面板内容列本来就窄(800px 面板减 188px 导航),而且它自己滚动。所以这一页
7215
7483
  不去抢整页的高度与居中:height:100% 会在列里撑出第二根滚动条,860px 的
@@ -7241,7 +7509,7 @@ window.__ModuleLoader__.load({
7241
7509
  .dsm-workbuddy-settings .dsm-workbuddy-settings-head,
7242
7510
  .dsm-workbuddy-page .dsm-workbuddy-page-head{background:var(--dsw-alias-bg-layer-1,#17181b);border-radius:12px;padding:10px 12px}
7243
7511
  /* 这一页的内容区不能有内边距,否则底色会缩进一截,与页头对不齐。 */
7244
- .dsm-workbuddy-settings .dsm-workbuddy-page-body .dsm-workbuddy-usage{padding:0;border:0;border-radius:0;background:var(--dsw-alias-bg-layer-1,#17181b)}.dsm-workbuddy-panel-icon{display:block;border-radius:4px;flex:none}
7512
+ .dsm-workbuddy-settings .dsm-workbuddy-page-body .dsm-workbuddy-usage{--dsm-workbuddy-surface:var(--dsw-alias-bg-layer-1,#17181b);padding:0;border:0;border-radius:0;background:var(--dsw-alias-bg-layer-1,#17181b)}.dsm-workbuddy-panel-icon{display:block;border-radius:4px;flex:none}
7245
7513
  /* ---- 设备头档位与逐账号参数弹窗 ------------------------------------------
7246
7514
  档位那一行贴着账号表:它同时决定"这台机器对外声称自己是谁"和"每行的齿轮能
7247
7515
  不能用",埋进「更多设置」会让齿轮看起来时好时坏。
@@ -8386,6 +8654,15 @@ window.__ModuleLoader__.load({
8386
8654
  const [sidebarPanelOn, setSidebarPanelOn] = (0, react.useState)(void 0);
8387
8655
  const [sidebarPanelBusy, setSidebarPanelBusy] = (0, react.useState)(false);
8388
8656
  /**
8657
+ * The CN gateway editor's draft (issue #220). `undefined` = "not edited", so
8658
+ * the field shows the SAVED value and a background refresh cannot overwrite
8659
+ * what the user is typing — the same rule the model drafts follow.
8660
+ */
8661
+ const [cnBaseDraft, setCnBaseDraft] = (0, react.useState)(void 0);
8662
+ const [cnBaseSaving, setCnBaseSaving] = (0, react.useState)(false);
8663
+ const [cnBaseError, setCnBaseError] = (0, react.useState)(void 0);
8664
+ const [cnBaseNotice, setCnBaseNotice] = (0, react.useState)(void 0);
8665
+ /**
8389
8666
  * The quick-adjust pins of the CLI route (model, effort, region order) made
8390
8667
  * by THIS card instance.
8391
8668
  *
@@ -10046,6 +10323,117 @@ window.__ModuleLoader__.load({
10046
10323
  * NOT gated on the active tab's provider: the row is a property of the whole
10047
10324
  * plugin, not of one region, and a signed-out card can still turn it on.
10048
10325
  */
10326
+ /**
10327
+ * The CN gateway override editor (issue #220).
10328
+ *
10329
+ * A DRAFT + explicit Save, unlike the switches above it: a host name is typed,
10330
+ * so committing per keystroke would write `https://w`, `https://wb`, … — six
10331
+ * settings writes and six `warn` log lines for one word. The switches commit on
10332
+ * the click precisely because a click IS a complete statement; a text field is
10333
+ * not.
10334
+ *
10335
+ * CN only. The international gateways follow the credential's own brand domain
10336
+ * (`workbuddy.ai` / `codebuddy.ai`), where an override against a host of a
10337
+ * DIFFERENT brand is rejected by the upstream — there is no "equivalent host"
10338
+ * to fall back to, so the control is absent on that tab rather than present and
10339
+ * unusable.
10340
+ *
10341
+ * The draft is validated HERE and not by the Host: the Host falls back to the
10342
+ * built-in gateway and logs, which keeps a running process correct but tells a
10343
+ * half-attending user nothing. Refusing the save with the specific rule it
10344
+ * broke ("not https" vs "not a CN brand") is what makes the setting findable.
10345
+ */
10346
+ const cnBaseSaved = regionCnBaseOf(settingsScope?.getSnapshot().value, "cn");
10347
+ const cnBaseDraftValue = cnBaseDraft ?? cnBaseSaved;
10348
+ const cnBaseDirty = cnBaseDraft !== void 0 && cnBaseDraft.trim() !== cnBaseSaved.trim();
10349
+ const cnBasePreview = resolveCnGateway(cnBaseDraftValue);
10350
+ const saveCnBase = async () => {
10351
+ if (settingsScope === void 0 || cnBaseSaving) return;
10352
+ const resolved = cnBasePreview;
10353
+ if (!resolved.ok) {
10354
+ setCnBaseError(resolved.reason === "malformed" ? t("row.cnBaseInvalidMalformed") : resolved.reason === "insecure" ? t("row.cnBaseInvalidInsecure") : t("row.cnBaseInvalidHost"));
10355
+ return;
10356
+ }
10357
+ setCnBaseSaving(true);
10358
+ setCnBaseError(void 0);
10359
+ try {
10360
+ const next = resolved.overridden ? resolved.base : "";
10361
+ await writeRegionCnBase(settingsScope, "cn", next, nextRegionCnBase(settingsScope.getSnapshot().value, "cn", next));
10362
+ if (mounted.current) {
10363
+ setCnBaseDraft(void 0);
10364
+ setCnBaseNotice(t(next === "" ? "row.cnBaseCleared" : "row.cnBaseSaved"));
10365
+ }
10366
+ await refreshUsage("cn");
10367
+ } catch (error) {
10368
+ if (mounted.current) setCnBaseError(error instanceof Error ? error.message : t("row.requestFailed"));
10369
+ } finally {
10370
+ if (mounted.current) setCnBaseSaving(false);
10371
+ }
10372
+ };
10373
+ const cnBasePreference = activeRegion !== "cn" ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
10374
+ className: "dsm-workbuddy-cnbase",
10375
+ title: t("row.cnBaseHint"),
10376
+ children: [
10377
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
10378
+ className: "dsm-workbuddy-cnbase-row",
10379
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
10380
+ className: "dsm-workbuddy-pref-copy",
10381
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
10382
+ className: "dsm-workbuddy-pref-label",
10383
+ children: t("row.cnBaseLabel")
10384
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
10385
+ className: "dsm-workbuddy-pref-hint",
10386
+ children: t("row.cnBaseHint")
10387
+ })]
10388
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
10389
+ type: "url",
10390
+ className: "dsm-workbuddy-cnbase-input",
10391
+ value: cnBaseDraftValue,
10392
+ placeholder: t("row.cnBasePlaceholder"),
10393
+ disabled: !canWrite || saving || cnBaseSaving,
10394
+ spellCheck: false,
10395
+ autoComplete: "off",
10396
+ onChange: (event) => {
10397
+ setCnBaseDraft(event.target.value);
10398
+ setCnBaseError(void 0);
10399
+ setCnBaseNotice(void 0);
10400
+ }
10401
+ })]
10402
+ }),
10403
+ cnBaseError !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
10404
+ className: "dsm-workbuddy-cnbase-error",
10405
+ role: "alert",
10406
+ children: cnBaseError
10407
+ }) : null,
10408
+ cnBaseError === void 0 && cnBaseNotice !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
10409
+ className: "dsm-workbuddy-cnbase-notice",
10410
+ role: "status",
10411
+ children: cnBaseNotice
10412
+ }) : null,
10413
+ cnBaseDirty ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
10414
+ className: "dsm-workbuddy-cnbase-actions",
10415
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
10416
+ type: "button",
10417
+ className: "dsm-btn dsm-btn-outline",
10418
+ disabled: cnBaseSaving,
10419
+ onClick: () => {
10420
+ setCnBaseDraft(void 0);
10421
+ setCnBaseError(void 0);
10422
+ setCnBaseNotice(void 0);
10423
+ },
10424
+ children: t("row.poolDiscard")
10425
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
10426
+ type: "button",
10427
+ className: "dsm-btn dsm-btn-primary",
10428
+ disabled: cnBaseSaving,
10429
+ onClick: () => {
10430
+ saveCnBase();
10431
+ },
10432
+ children: cnBaseSaving ? t("row.poolSaving") : t("row.poolSaved")
10433
+ })]
10434
+ }) : null
10435
+ ]
10436
+ });
10049
10437
  const sidebarPanelPreference = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
10050
10438
  className: "dsm-workbuddy-pref",
10051
10439
  title: t("row.sidebarPanelHint"),
@@ -10961,6 +11349,7 @@ window.__ModuleLoader__.load({
10961
11349
  className: "dsm-workbuddy-panel-note",
10962
11350
  children: t("row.panelCapabilitiesHint")
10963
11351
  }),
11352
+ cnBasePreference,
10964
11353
  creditPreferences,
10965
11354
  upstreamSwitches,
10966
11355
  channelRejectContinuePreference,
@@ -10996,6 +11385,19 @@ window.__ModuleLoader__.load({
10996
11385
  children: status.domain === void 0 || status.domain === "" ? t("row.modelUnknown") : status.domain
10997
11386
  })]
10998
11387
  }),
11388
+ status.region === "cn" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
11389
+ className: "dsm-workbuddy-diag-row",
11390
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
11391
+ className: "dsm-workbuddy-diag-label",
11392
+ children: t("row.diagCnBase")
11393
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
11394
+ className: "dsm-workbuddy-diag-value dsm-workbuddy-diag-mono",
11395
+ children: (() => {
11396
+ const resolved = resolveCnGateway(regionCnBaseOf(settingsScope?.getSnapshot().value, "cn"));
11397
+ return resolved.ok && resolved.overridden ? resolved.base : t("row.diagCnBaseDefault");
11398
+ })()
11399
+ })]
11400
+ }) : null,
10999
11401
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
11000
11402
  className: "dsm-workbuddy-diag-row",
11001
11403
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
@@ -13026,7 +13428,7 @@ window.__ModuleLoader__.load({
13026
13428
  "row.panelAccounts": "Accounts",
13027
13429
  "row.panelModels": "Models",
13028
13430
  "row.panelCapabilities": "Capabilities",
13029
- "row.panelCapabilitiesHint": "What the plugin may do on your behalf. Each switch takes effect on the click — there is no Save button in this section.",
13431
+ "row.panelCapabilitiesHint": "What the plugin may do on your behalf. The switches take effect on the click — there is no Save button for them. The one field at the top (the CN gateway) is a draft and saves on its own button, because a half-typed host must never become the live one.",
13030
13432
  "row.panelDiag": "Diagnostics",
13031
13433
  "row.panelAria": "Card sections",
13032
13434
  "row.diagHint": "What this card actually read, so a report can quote it. Nothing here changes a setting.",
@@ -13397,6 +13799,16 @@ window.__ModuleLoader__.load({
13397
13799
  "row.channelRejectContinueText": "Text sent:",
13398
13800
  "row.cliBridgeLabel": "Let the local CodeBuddy CLI do the work",
13399
13801
  "row.cliBridgeHint": "Adds the codebuddy_ask tool and the /codebuddy command. Each call spends CodeBuddy quota. injectResult only affects /codebuddy — its result is injected back into the session, costing one DSH turn when the session is idle; tool calls never read it. Rate-limited: 6 turns per session per hour, 20 per process per hour, one turn at a time. Off by default.",
13802
+ "row.cnBaseLabel": "CN gateway host",
13803
+ "row.cnBaseHint": "Leave empty to use copilot.tencent.com. Set it only if your network resets that host by TLS SNI (connection fails in milliseconds while the WorkBuddy desktop app still works) — the app itself falls back to wb.tencentbuddy.com. Accepted hosts: any subdomain of copilot.tencent.com, tencentbuddy.com, workbuddy.cn or codebuddy.cn, over https. Chat, billing, catalog and check-in all follow it; your account and region do not change.",
13804
+ "row.cnBasePlaceholder": "https://wb.tencentbuddy.com",
13805
+ "row.cnBaseInvalidMalformed": "That is not a full URL. Include https:// and the host, e.g. https://wb.tencentbuddy.com",
13806
+ "row.cnBaseInvalidInsecure": "Only https is accepted — a plaintext host would send your token in the clear.",
13807
+ "row.cnBaseInvalidHost": "That host is not one of the CN brands. Use a subdomain of copilot.tencent.com, tencentbuddy.com, workbuddy.cn or codebuddy.cn.",
13808
+ "row.cnBaseSaved": "CN gateway saved. New requests use it; originals/CORS headers keep naming the CN web app.",
13809
+ "row.cnBaseCleared": "Back to the built-in CN gateway.",
13810
+ "row.diagCnBase": "CN gateway",
13811
+ "row.diagCnBaseDefault": "built-in (copilot.tencent.com)",
13400
13812
  "row.sidebarPanelLabel": "Show WorkBuddy in the sidebar",
13401
13813
  "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.",
13402
13814
  "row.cliBridgeModelLabel": "CLI model",
@@ -13550,7 +13962,7 @@ window.__ModuleLoader__.load({
13550
13962
  "row.panelAccounts": "账号",
13551
13963
  "row.panelModels": "模型",
13552
13964
  "row.panelCapabilities": "能力",
13553
- "row.panelCapabilitiesHint": "插件可以替你做什么。这些开关点一下立即生效 —— 这一区里没有保存按钮。",
13965
+ "row.panelCapabilitiesHint": "插件可以替你做什么。这些开关点一下立即生效 —— 开关没有保存按钮。顶上那个「CN 网关主机」是草稿,由它自己的按钮保存:一个打到一半的主机名绝不该成为生效值。",
13554
13966
  "row.panelDiag": "诊断",
13555
13967
  "row.panelAria": "卡片分区",
13556
13968
  "row.diagHint": "这张卡片实际读到了什么,方便贴进问题反馈。这里没有任何会改动设置的控件。",
@@ -13921,6 +14333,16 @@ window.__ModuleLoader__.load({
13921
14333
  "row.channelRejectContinueText": "发送的文本:",
13922
14334
  "row.cliBridgeLabel": "允许调用本机 CodeBuddy CLI 干活",
13923
14335
  "row.cliBridgeHint": "开启后多出 codebuddy_ask 工具与 /codebuddy 指令;每次调用花 CodeBuddy 配额。injectResult 只影响 /codebuddy:其结果回注会话,会话空闲时多花一次 DSH 回合;工具调用不读它。限流:每会话每小时 6 回合、每进程每小时 20 回合、同时只跑一个回合。默认关闭。",
14336
+ "row.cnBaseLabel": "CN 网关主机",
14337
+ "row.cnBaseHint": "留空即用 copilot.tencent.com。只有当你的网络按 TLS SNI 重置这个域名时才需要填(连接在毫秒级就失败,而同一台机器上的 WorkBuddy 桌面端正常——客户端自己会退回 wb.tencentbuddy.com)。可填 copilot.tencent.com、tencentbuddy.com、workbuddy.cn、codebuddy.cn 任一域名下的子域,且必须是 https。聊天、计费、模型目录、签到都会跟着走;账号与区域不会变。",
14338
+ "row.cnBasePlaceholder": "https://wb.tencentbuddy.com",
14339
+ "row.cnBaseInvalidMalformed": "这不是一个完整 URL。请带上 https:// 与主机名,例如 https://wb.tencentbuddy.com",
14340
+ "row.cnBaseInvalidInsecure": "只接受 https——明文主机会把你的 token 裸发出去。",
14341
+ "row.cnBaseInvalidHost": "这个主机不在 CN 品牌里。请用 copilot.tencent.com、tencentbuddy.com、workbuddy.cn、codebuddy.cn 下的子域。",
14342
+ "row.cnBaseSaved": "CN 网关已保存,新请求即刻使用它;Origin/Referer 仍然自称 CN 网页端。",
14343
+ "row.cnBaseCleared": "已回到内置 CN 网关。",
14344
+ "row.diagCnBase": "CN 网关",
14345
+ "row.diagCnBaseDefault": "内置(copilot.tencent.com)",
13924
14346
  "row.sidebarPanelLabel": "在侧边栏显示 WorkBuddy",
13925
14347
  "row.sidebarPanelHint": "在 DSH 侧边栏加一个 WorkBuddy 行,点开就是这张卡片的整页版。默认关闭:这一行占的是所有插件共用的全局侧边栏座位,而「插件」页本来就能看到同样的内容。点一下即生效,不用保存;页面开着时关掉它,会直接回到对话。",
13926
14348
  "row.cliBridgeModelLabel": "CLI 模型",