dsh-thinking-levels 0.7.2-beta.1 → 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -68,7 +68,8 @@ window.__ModuleLoader__.load({
68
68
  "card.capabilities.contextHint": "选择预设或输入整数(2000–1000000),写入 llm-pi-ai 供上下文压力/压缩使用,无需重启即对下一请求生效。",
69
69
  "input.context.title": "上下文窗口",
70
70
  "input.context.globalHint": "全局生效:作用于所有使用该模型的会话(清除可恢复默认)",
71
- "input.context.unset": "ctx 未设",
71
+ "input.context.unset": "未设",
72
+ "input.context.custom": "自定义",
72
73
  "input.context.noModel": "暂无会话模型",
73
74
  "input.context.customPlaceholder": "自定义整数,如 256000",
74
75
  "input.context.apply": "应用",
@@ -135,7 +136,8 @@ window.__ModuleLoader__.load({
135
136
  "card.capabilities.contextHint": "Pick a preset or enter an integer (2000–1000000); written to llm-pi-ai for context pressure/compaction and applied to the next request without a restart.",
136
137
  "input.context.title": "Context window",
137
138
  "input.context.globalHint": "Applies globally to every session using this model (Clear restores the default)",
138
- "input.context.unset": "ctx unset",
139
+ "input.context.unset": "Unset",
140
+ "input.context.custom": "Custom",
139
141
  "input.context.noModel": "No session model yet",
140
142
  "input.context.customPlaceholder": "Custom integer, e.g. 256000",
141
143
  "input.context.apply": "Apply",
@@ -202,7 +204,8 @@ window.__ModuleLoader__.load({
202
204
  "card.capabilities.contextHint": "プリセットを選ぶか整数を入力(2000–1000000)。llm-pi-ai に書き込まれ、コンテキスト圧力/圧縮に使用され、再起動なしで次のリクエストに反映されます。",
203
205
  "input.context.title": "コンテキストウィンドウ",
204
206
  "input.context.globalHint": "グローバルに有効:このモデルを使用するすべてのセッションに適用されます(クリアで既定値に戻ります)",
205
- "input.context.unset": "ctx 未設定",
207
+ "input.context.unset": "未設定",
208
+ "input.context.custom": "カスタム",
206
209
  "input.context.noModel": "セッションモデルがまだありません",
207
210
  "input.context.customPlaceholder": "カスタム整数(例:256000)",
208
211
  "input.context.apply": "適用",
@@ -269,7 +272,8 @@ window.__ModuleLoader__.load({
269
272
  "card.capabilities.contextHint": "프리셋을 선택하거나 정수를 입력하세요(2000–1000000). llm-pi-ai에 기록되어 컨텍스트 압력/압축에 사용되며, 재시작 없이 다음 요청에 반영됩니다.",
270
273
  "input.context.title": "컨텍스트 창",
271
274
  "input.context.globalHint": "전역 적용: 이 모델을 사용하는 모든 세션에 적용됩니다(지우면 기본값 복원)",
272
- "input.context.unset": "ctx 미설정",
275
+ "input.context.unset": "미설정",
276
+ "input.context.custom": "사용자 지정",
273
277
  "input.context.noModel": "세션 모델이 아직 없습니다",
274
278
  "input.context.customPlaceholder": "사용자 지정 정수(예: 256000)",
275
279
  "input.context.apply": "적용",
@@ -422,7 +426,7 @@ window.__ModuleLoader__.load({
422
426
  "string-thinking",
423
427
  "ant-ling"
424
428
  ];
425
- const rowStyle = {
429
+ const rowStyle$1 = {
426
430
  display: "flex",
427
431
  alignItems: "center",
428
432
  justifyContent: "space-between",
@@ -459,7 +463,7 @@ window.__ModuleLoader__.load({
459
463
  lineHeight: "18px",
460
464
  color: "var(--dsw-alias-label-tertiary)"
461
465
  };
462
- const hintStyle$1 = {
466
+ const hintStyle = {
463
467
  margin: "6px 0 0",
464
468
  fontSize: "12px",
465
469
  lineHeight: "18px",
@@ -881,7 +885,7 @@ window.__ModuleLoader__.load({
881
885
  if (unavailable) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
882
886
  style: sectionStyle,
883
887
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
884
- style: hintStyle$1,
888
+ style: hintStyle,
885
889
  children: t("card.capabilities.unavailable")
886
890
  })
887
891
  });
@@ -891,7 +895,7 @@ window.__ModuleLoader__.load({
891
895
  style: fieldLabelStyle,
892
896
  children: t("card.capabilities")
893
897
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
894
- style: hintStyle$1,
898
+ style: hintStyle,
895
899
  children: t("card.capabilities.empty")
896
900
  })]
897
901
  });
@@ -906,7 +910,7 @@ window.__ModuleLoader__.load({
906
910
  children: t("card.capabilities")
907
911
  }),
908
912
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
909
- style: hintStyle$1,
913
+ style: hintStyle,
910
914
  children: t("card.capabilities.hint")
911
915
  }),
912
916
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
@@ -941,7 +945,7 @@ window.__ModuleLoader__.load({
941
945
  }, preset.key))]
942
946
  }),
943
947
  visible.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
944
- style: hintStyle$1,
948
+ style: hintStyle,
945
949
  children: t("card.capabilities.noMatches")
946
950
  }) : providerIds.map((providerId) => {
947
951
  const providerEntries = visible.filter((entry) => entry.providerId === providerId);
@@ -1320,7 +1324,7 @@ window.__ModuleLoader__.load({
1320
1324
  }, providerId);
1321
1325
  }),
1322
1326
  readonly ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1323
- style: hintStyle$1,
1327
+ style: hintStyle,
1324
1328
  children: t("card.readonly")
1325
1329
  }) : null
1326
1330
  ]
@@ -1417,7 +1421,7 @@ window.__ModuleLoader__.load({
1417
1421
  children: t("card.unavailable")
1418
1422
  }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1419
1423
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1420
- style: rowStyle,
1424
+ style: rowStyle$1,
1421
1425
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
1422
1426
  htmlFor: "plugin-config-thinking-levels-level",
1423
1427
  style: labelStyle$1,
@@ -1437,7 +1441,7 @@ window.__ModuleLoader__.load({
1437
1441
  })]
1438
1442
  }),
1439
1443
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1440
- style: rowStyle,
1444
+ style: rowStyle$1,
1441
1445
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
1442
1446
  htmlFor: "plugin-config-thinking-levels-enabled",
1443
1447
  style: labelStyle$1,
@@ -1453,7 +1457,7 @@ window.__ModuleLoader__.load({
1453
1457
  })]
1454
1458
  }),
1455
1459
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1456
- style: rowStyle,
1460
+ style: rowStyle$1,
1457
1461
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
1458
1462
  htmlFor: "plugin-config-thinking-levels-downgrade",
1459
1463
  style: labelStyle$1,
@@ -1469,7 +1473,7 @@ window.__ModuleLoader__.load({
1469
1473
  })]
1470
1474
  }),
1471
1475
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1472
- style: rowStyle,
1476
+ style: rowStyle$1,
1473
1477
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
1474
1478
  htmlFor: "plugin-config-thinking-levels-upgrade",
1475
1479
  style: labelStyle$1,
@@ -1505,12 +1509,21 @@ window.__ModuleLoader__.load({
1505
1509
  //#region src/client/context-quick.tsx
1506
1510
  /**
1507
1511
  * Context-window quick control for the composer tool row
1508
- * (`conversation.input.right`, the seat just left of the send button and next
1509
- * to the model/effort select).
1512
+ * (`conversation.input.right`, the seat just left of the model/effort select).
1510
1513
  *
1511
- * It targets the CURRENT session's active model (read from the trajectory
1512
- * view's latest assistant request) and lets the user cap that model's context
1513
- * window on the fly — presets, a custom integer, or clear to restore.
1514
+ * This is the compat (DSH < 0.1.2-alpha.1) implementation: it targets the
1515
+ * CURRENT session's active model and lets the user cap that model's context
1516
+ * window on the fly. The trigger is a compact pill showing the committed value
1517
+ * only; the popover holds one slider row over the shared presets, a collapsed
1518
+ * custom-integer editor and Clear — no preset button grid.
1519
+ *
1520
+ * Model source: the session `useConversation` seat (selector hook over
1521
+ * `ConversationSnapshot`), whose `views.get('trajectory')` carries the request
1522
+ * ledger. Every renderer standard seat is a `useSyncExternalStoreWithSelector`
1523
+ * selector hook, never a bare getter — calling one without a selector throws
1524
+ * `TypeError: <minified> is not a function` inside the binding shim. A harness
1525
+ * line that does not provide the seat renders nothing at all here instead of a
1526
+ * dead control.
1514
1527
  *
1515
1528
  * Two model families are served, each with its own writable settings
1516
1529
  * namespace (both consumed live by `resolveModelInfo(...).context.contextWindow`,
@@ -1521,14 +1534,20 @@ window.__ModuleLoader__.load({
1521
1534
  * namespace): writes the catalog model's `contextWindow` when the model is
1522
1535
  * listed, otherwise caps via `defaultContextWindow`.
1523
1536
  *
1524
- * Kept dependency-free beyond react + the injected scopes: the trigger is a
1525
- * plain pill, the popover renders inline (absolutely positioned above the tool
1526
- * row), and validation reuses the shared `validateContextWindow`.
1537
+ * Write discipline: dragging the slider only moves a local draft; the settings
1538
+ * write happens once per gesture (pointer release, key release, blur), so a
1539
+ * drag never floods the host with intermediate values.
1540
+ *
1541
+ * Kept dependency-free beyond react + the injected scopes: plain HTML controls
1542
+ * with token-based inline styling, and validation reuses the shared
1543
+ * `validateContextWindow`.
1527
1544
  */
1528
1545
  /** The official DeepSeek provider route owned by the llm-deepseek adapter. */
1529
1546
  const DEEPSEEK_PROVIDER = "deepseek-official";
1530
1547
  /** llm-deepseek's native default context capacity (DEFAULT_CONTEXT_WINDOW). */
1531
1548
  const DEEPSEEK_DEFAULT_WINDOW = 1e6;
1549
+ /** Slider stop an unset window parks on: the thumb needs a position, the readout stays "unset". */
1550
+ const UNSET_STOP_INDEX = CONTEXT_WINDOW_PRESETS.findIndex((preset) => preset.value === 256e3);
1532
1551
  const pillStyle = {
1533
1552
  display: "inline-flex",
1534
1553
  alignItems: "center",
@@ -1550,7 +1569,7 @@ window.__ModuleLoader__.load({
1550
1569
  bottom: "calc(100% + 8px)",
1551
1570
  right: "0",
1552
1571
  zIndex: 1200,
1553
- minWidth: "240px",
1572
+ minWidth: "260px",
1554
1573
  padding: "10px",
1555
1574
  background: "var(--dsw-alias-bg-layer-3, rgba(127,127,127,0.05))",
1556
1575
  color: "var(--dsw-alias-label-primary)",
@@ -1566,62 +1585,78 @@ window.__ModuleLoader__.load({
1566
1585
  inset: 0,
1567
1586
  zIndex: 1199
1568
1587
  };
1569
- const labelStyle = {
1570
- margin: 0,
1588
+ const rowStyle = {
1589
+ display: "flex",
1590
+ alignItems: "center",
1591
+ gap: "8px",
1571
1592
  fontSize: "12px",
1572
1593
  lineHeight: "18px",
1573
1594
  color: "var(--dsw-alias-label-secondary)"
1574
1595
  };
1575
- const hintStyle = {
1576
- margin: 0,
1577
- fontSize: "11px",
1578
- lineHeight: "16px",
1596
+ const labelStyle = {
1597
+ flex: "0 0 auto",
1598
+ minWidth: "0",
1599
+ overflow: "hidden",
1600
+ textOverflow: "ellipsis",
1601
+ whiteSpace: "nowrap",
1579
1602
  color: "var(--dsw-alias-label-tertiary)"
1580
1603
  };
1581
- const presetRowStyle = {
1582
- display: "flex",
1583
- flexWrap: "wrap",
1584
- gap: "5px"
1604
+ const sliderStyle = {
1605
+ flex: "1 1 auto",
1606
+ minWidth: "56px",
1607
+ height: "14px",
1608
+ margin: "0",
1609
+ accentColor: "var(--dsw-alias-state-business-primary)",
1610
+ cursor: "pointer"
1585
1611
  };
1586
- const presetStyle = {
1587
- height: "22px",
1588
- padding: "0 8px",
1589
- background: "var(--dsw-alias-bg-surface, #fff)",
1590
- color: "var(--dsw-alias-label-secondary)",
1591
- border: "1px solid var(--dsw-alias-border-l2)",
1592
- borderRadius: "5px",
1593
- fontSize: "11px",
1594
- lineHeight: "16px",
1612
+ const valueStyle = {
1613
+ flex: "0 0 auto",
1614
+ minWidth: "40px",
1615
+ textAlign: "right",
1616
+ color: "var(--dsw-alias-label-primary)",
1595
1617
  fontFamily: "var(--ds-font-family-code, monospace)",
1618
+ fontVariantNumeric: "tabular-nums"
1619
+ };
1620
+ const glyphButtonStyle = {
1621
+ flex: "0 0 auto",
1622
+ height: "18px",
1623
+ padding: "0 5px",
1624
+ border: "1px solid transparent",
1625
+ borderRadius: "4px",
1626
+ background: "transparent",
1627
+ color: "var(--dsw-alias-label-tertiary)",
1628
+ font: "inherit",
1629
+ cursor: "pointer"
1630
+ };
1631
+ const actionButtonStyle = {
1632
+ flex: "0 0 auto",
1633
+ height: "18px",
1634
+ padding: "0 6px",
1635
+ border: "1px solid transparent",
1636
+ borderRadius: "4px",
1637
+ background: "transparent",
1638
+ color: "var(--dsw-alias-label-secondary)",
1639
+ font: "inherit",
1596
1640
  cursor: "pointer"
1597
1641
  };
1642
+ const customRowStyle = {
1643
+ display: "flex",
1644
+ alignItems: "center",
1645
+ gap: "6px"
1646
+ };
1598
1647
  const inputStyle = {
1599
1648
  flex: "1 1 auto",
1600
1649
  minWidth: "0",
1601
- background: "var(--dsw-alias-bg-surface, #fff)",
1602
- color: "var(--dsw-alias-label-primary)",
1650
+ boxSizing: "border-box",
1651
+ padding: "2px 6px",
1603
1652
  border: "1px solid var(--dsw-alias-border-l2)",
1604
1653
  borderRadius: "5px",
1605
- padding: "3px 8px",
1606
- fontSize: "12px",
1607
- fontFamily: "var(--ds-font-family-code, monospace)",
1608
- boxSizing: "border-box"
1609
- };
1610
- const actionStyle = {
1611
- height: "24px",
1612
- padding: "0 10px",
1613
1654
  background: "var(--dsw-alias-bg-surface, #fff)",
1614
1655
  color: "var(--dsw-alias-label-primary)",
1615
- border: "1px solid var(--dsw-alias-border-l2)",
1616
- borderRadius: "5px",
1617
- fontSize: "12px",
1618
- lineHeight: "18px",
1619
- cursor: "pointer"
1656
+ font: "inherit"
1620
1657
  };
1621
1658
  const errorStyle = {
1622
- margin: 0,
1623
- fontSize: "11px",
1624
- lineHeight: "16px",
1659
+ flex: "0 0 auto",
1625
1660
  color: "var(--dsw-alias-danger, #e5484d)"
1626
1661
  };
1627
1662
  /** The user-layer `providers` value of the llm-pi-ai namespace, when present. */
@@ -1646,13 +1681,24 @@ window.__ModuleLoader__.load({
1646
1681
  };
1647
1682
  }
1648
1683
  /**
1649
- * The current session's active model, reconstructed from the trajectory view's
1684
+ * The stable trajectory selector: the seat memoizes its selection on the
1685
+ * selector reference, so it must not be a fresh closure per render. Selecting
1686
+ * the trajectory view snapshot (a store-owned reference, not a derived object)
1687
+ * keeps the selected value stable between snapshots — a selector that built a
1688
+ * new object would re-render forever.
1689
+ * @param snapshot - the current conversation snapshot.
1690
+ * @returns the trajectory view snapshot, absent while the view is unregistered.
1691
+ */
1692
+ const selectTrajectory = (snapshot) => snapshot.views?.get?.("trajectory");
1693
+ /**
1694
+ * The current session's active model, taken from the trajectory ledger's
1650
1695
  * latest assistant request prompt config. Absent for a blank session (no
1651
- * request yet) — the control then renders read-only/disabled.
1696
+ * request yet) — the control then renders disabled.
1697
+ * @param trajectory - the trajectory view snapshot, when the view is registered.
1652
1698
  */
1653
- function activeModelOf(session) {
1654
- if (typeof session !== "object" || session === null) return void 0;
1655
- const requests = (session.views?.get?.("trajectory"))?.requests ?? [];
1699
+ function activeModelOf(trajectory) {
1700
+ if (typeof trajectory !== "object" || trajectory === null) return void 0;
1701
+ const requests = trajectory.requests ?? [];
1656
1702
  for (let index = requests.length - 1; index >= 0; index -= 1) {
1657
1703
  const config = requests[index]?.prompt?.config;
1658
1704
  if (requests[index]?.purpose === "assistant" && typeof config?.provider === "string" && typeof config?.model === "string") return {
@@ -1667,15 +1713,47 @@ window.__ModuleLoader__.load({
1667
1713
  return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : void 0;
1668
1714
  }
1669
1715
  /**
1670
- * The composer context-window quick control: a pill showing the current
1671
- * session model's context window that opens an inline popover with preset
1672
- * quick-picks, a custom integer input and a clear (restore default) action.
1716
+ * The slider stop nearest to a committed token count; a window that matches no
1717
+ * preset still parks the thumb on its closest stop.
1718
+ * @param value - the committed context window, when one is set.
1719
+ * @returns the stop index, or the unset park position.
1720
+ */
1721
+ function stopIndexOf(value) {
1722
+ if (value === void 0) return UNSET_STOP_INDEX;
1723
+ let best = 0;
1724
+ let bestDistance = Number.POSITIVE_INFINITY;
1725
+ CONTEXT_WINDOW_PRESETS.forEach((preset, index) => {
1726
+ const distance = Math.abs(preset.value - value);
1727
+ if (distance < bestDistance) {
1728
+ bestDistance = distance;
1729
+ best = index;
1730
+ }
1731
+ });
1732
+ return best;
1733
+ }
1734
+ /**
1735
+ * The composer context-window quick control. Renders nothing when this harness
1736
+ * line provides no conversation seat, so a missing seat never leaves a dead
1737
+ * control (or a crash) in the tool row.
1738
+ * @param props - injected scopes, session standard seats, copy.
1739
+ */
1740
+ function ContextQuick(props) {
1741
+ const useConversation = props.useConversation;
1742
+ if (typeof useConversation !== "function") return null;
1743
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ContextQuickControl, {
1744
+ ...props,
1745
+ useConversation
1746
+ });
1747
+ }
1748
+ /**
1749
+ * The bound control: a value pill that opens a one-row slider popover
1750
+ * (preset slider, committed value, collapsed custom-integer editor, Clear).
1673
1751
  * Custom gateways and official DeepSeek models are both supported (see module
1674
1752
  * doc for the namespace each writes).
1675
- * @param props - injected scopes, session standard seats, copy.
1753
+ * @param props - injected scopes, the present conversation seat, copy.
1676
1754
  */
1677
- function ContextQuick({ useSession, piAiScope, deepseekScope, t }) {
1678
- const active = activeModelOf(useSession());
1755
+ function ContextQuickControl({ useConversation, piAiScope, deepseekScope, t }) {
1756
+ const active = activeModelOf(useConversation(selectTrajectory));
1679
1757
  const official = active !== void 0 && active.provider === DEEPSEEK_PROVIDER;
1680
1758
  const piSnapshot = (0, react.useSyncExternalStore)((listener) => piAiScope.subscribe(listener), () => piAiScope.getSnapshot());
1681
1759
  const dsSnapshot = (0, react.useSyncExternalStore)((listener) => deepseekScope.subscribe(listener), () => deepseekScope.getSnapshot());
@@ -1698,13 +1776,19 @@ window.__ModuleLoader__.load({
1698
1776
  writableTarget = model !== void 0;
1699
1777
  }
1700
1778
  const [open, setOpen] = (0, react.useState)(false);
1779
+ const [draft, setDraft] = (0, react.useState)(null);
1780
+ const [custom, setCustom] = (0, react.useState)(false);
1701
1781
  const [raw, setRaw] = (0, react.useState)("");
1702
1782
  const [error, setError] = (0, react.useState)(null);
1703
1783
  const [busy, setBusy] = (0, react.useState)(false);
1704
1784
  const disabled = readonly || busy || active === void 0 || !writableTarget;
1785
+ const stop = draft ?? stopIndexOf(currentWindow);
1705
1786
  /** Commit (or delete) the active model's context window. */
1706
1787
  const commitWindow = (value) => {
1707
- if (active === void 0 || snapshot.status !== "ready" || !writableTarget) return;
1788
+ if (active === void 0 || snapshot.status !== "ready" || !writableTarget) {
1789
+ setDraft(null);
1790
+ return;
1791
+ }
1708
1792
  setBusy(true);
1709
1793
  if (official) {
1710
1794
  const models = (deepseekSectionOf(dsSnapshot).models ?? []).map((model) => ({ ...model }));
@@ -1722,8 +1806,10 @@ window.__ModuleLoader__.load({
1722
1806
  };
1723
1807
  })) : deepseekScope.set("defaultContextWindow", value === void 0 ? DEEPSEEK_DEFAULT_WINDOW : value)).then(() => {
1724
1808
  setBusy(false);
1809
+ setDraft(null);
1725
1810
  }).catch(() => {
1726
1811
  setBusy(false);
1812
+ setDraft(null);
1727
1813
  });
1728
1814
  return;
1729
1815
  }
@@ -1731,21 +1817,23 @@ window.__ModuleLoader__.load({
1731
1817
  const entry = next[active.provider]?.models?.find((candidate) => typeof candidate === "object" && candidate !== null && candidate["id"] === active.model);
1732
1818
  if (entry === void 0) {
1733
1819
  setBusy(false);
1820
+ setDraft(null);
1734
1821
  return;
1735
1822
  }
1736
1823
  if (value === void 0) delete entry["contextWindow"];
1737
1824
  else entry["contextWindow"] = value;
1738
1825
  piAiScope.set("providers", next).then(() => {
1739
1826
  setBusy(false);
1827
+ setDraft(null);
1740
1828
  }).catch(() => {
1741
1829
  setBusy(false);
1830
+ setDraft(null);
1742
1831
  });
1743
1832
  };
1744
- /** Pick one preset immediately. */
1745
- const pickPreset = (value) => {
1746
- setRaw(String(value));
1747
- setError(null);
1748
- commitWindow(value);
1833
+ /** Write the stop the gesture landed on; a drag only moves the draft. */
1834
+ const commitStop = () => {
1835
+ if (disabled || draft === null) return;
1836
+ commitWindow(CONTEXT_WINDOW_PRESETS[draft]?.value);
1749
1837
  };
1750
1838
  /** Validate and commit the custom input; empty clears. */
1751
1839
  const applyCustom = () => {
@@ -1763,115 +1851,136 @@ window.__ModuleLoader__.load({
1763
1851
  setError(null);
1764
1852
  commitWindow(validation.value);
1765
1853
  };
1766
- const triggerLabel = currentWindow === void 0 ? t("input.context.unset") : formatContextWindow(currentWindow);
1854
+ const value = draft === null ? currentWindow === void 0 ? t("input.context.unset") : formatContextWindow(currentWindow) : formatContextWindow(CONTEXT_WINDOW_PRESETS[draft]?.value ?? 0);
1767
1855
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1768
- style: {
1769
- position: "relative",
1770
- display: "inline-flex"
1771
- },
1856
+ style: { position: "relative" },
1772
1857
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1773
1858
  type: "button",
1774
1859
  disabled,
1860
+ "aria-expanded": open,
1861
+ "aria-label": t("input.context.title"),
1862
+ title: active === void 0 ? t("input.context.noModel") : `${active.provider}/${active.model}`,
1775
1863
  style: {
1776
1864
  ...pillStyle,
1777
1865
  cursor: disabled ? "default" : "pointer",
1778
1866
  opacity: disabled ? .55 : 1
1779
1867
  },
1780
- title: active === void 0 ? t("input.context.noModel") : `${active.provider}/${active.model}`,
1781
1868
  onClick: () => {
1782
- setOpen((current) => !current);
1869
+ setOpen((value) => !value);
1870
+ setError(null);
1783
1871
  },
1784
- children: triggerLabel
1872
+ children: value
1785
1873
  }), open ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1786
1874
  style: backdropStyle,
1787
- onClick: () => setOpen(false)
1875
+ onClick: () => {
1876
+ setOpen(false);
1877
+ setError(null);
1878
+ }
1788
1879
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1789
1880
  style: popStyle,
1790
- role: "dialog",
1881
+ role: "group",
1791
1882
  "aria-label": t("input.context.title"),
1792
- children: [
1793
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
1794
- style: labelStyle,
1795
- children: [t("input.context.title"), active !== void 0 ? ` · ${active.provider}/${active.model}` : ""]
1796
- }),
1797
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1798
- style: hintStyle,
1799
- children: t("input.context.globalHint")
1800
- }),
1801
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1802
- style: presetRowStyle,
1803
- children: CONTEXT_WINDOW_PRESETS.map((preset) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1883
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1884
+ style: rowStyle,
1885
+ children: [
1886
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1887
+ style: labelStyle,
1888
+ title: t("input.context.globalHint"),
1889
+ children: t("input.context.title")
1890
+ }),
1891
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1892
+ type: "range",
1893
+ min: 0,
1894
+ max: CONTEXT_WINDOW_PRESETS.length - 1,
1895
+ step: 1,
1896
+ value: stop,
1897
+ disabled,
1898
+ "aria-label": t("input.context.title"),
1899
+ style: {
1900
+ ...sliderStyle,
1901
+ cursor: disabled ? "default" : "pointer",
1902
+ opacity: disabled ? .55 : 1
1903
+ },
1904
+ onChange: (event) => {
1905
+ setDraft(Number(event.currentTarget.value));
1906
+ },
1907
+ onPointerUp: commitStop,
1908
+ onKeyUp: commitStop,
1909
+ onBlur: commitStop
1910
+ }),
1911
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1912
+ style: valueStyle,
1913
+ children: value
1914
+ }),
1915
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1804
1916
  type: "button",
1805
1917
  disabled,
1918
+ "aria-label": t("input.context.custom"),
1919
+ "aria-expanded": custom,
1920
+ title: t("input.context.custom"),
1806
1921
  style: {
1807
- ...presetStyle,
1922
+ ...glyphButtonStyle,
1808
1923
  cursor: disabled ? "default" : "pointer",
1809
- opacity: disabled ? .5 : 1
1924
+ opacity: disabled ? .55 : 1
1810
1925
  },
1811
- onClick: () => pickPreset(preset.value),
1812
- children: preset.label
1813
- }, preset.value))
1814
- }),
1815
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1816
- style: {
1817
- display: "flex",
1818
- gap: "6px",
1819
- alignItems: "center"
1820
- },
1821
- children: [
1822
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1823
- type: "text",
1824
- value: raw,
1825
- disabled,
1826
- placeholder: t("input.context.customPlaceholder"),
1827
- style: inputStyle,
1828
- onChange: (event) => {
1829
- setRaw(event.currentTarget.value);
1830
- },
1831
- onKeyDown: (event) => {
1832
- if (event.key === "Enter") {
1833
- setOpen(false);
1834
- applyCustom();
1835
- }
1836
- }
1837
- }),
1838
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1839
- type: "button",
1840
- disabled,
1841
- style: {
1842
- ...actionStyle,
1843
- cursor: disabled ? "default" : "pointer",
1844
- opacity: disabled ? .5 : 1
1845
- },
1846
- onClick: () => {
1847
- setOpen(false);
1848
- applyCustom();
1849
- },
1850
- children: t("input.context.apply")
1851
- }),
1852
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1853
- type: "button",
1854
- disabled,
1855
- style: {
1856
- ...actionStyle,
1857
- cursor: disabled ? "default" : "pointer",
1858
- opacity: disabled ? .5 : 1
1859
- },
1860
- onClick: () => {
1861
- setOpen(false);
1862
- setRaw("");
1863
- setError(null);
1864
- commitWindow(void 0);
1865
- },
1866
- children: t("input.context.clear")
1867
- })
1868
- ]
1869
- }),
1870
- error !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1871
- style: errorStyle,
1872
- children: error
1873
- })
1874
- ]
1926
+ onClick: () => {
1927
+ setCustom((open) => !open);
1928
+ setError(null);
1929
+ },
1930
+ children: "⋯"
1931
+ }),
1932
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1933
+ type: "button",
1934
+ disabled: disabled || currentWindow === void 0,
1935
+ style: {
1936
+ ...actionButtonStyle,
1937
+ cursor: disabled || currentWindow === void 0 ? "default" : "pointer",
1938
+ opacity: disabled || currentWindow === void 0 ? .55 : 1
1939
+ },
1940
+ onClick: () => {
1941
+ setDraft(null);
1942
+ setError(null);
1943
+ setRaw("");
1944
+ commitWindow(void 0);
1945
+ },
1946
+ children: t("input.context.clear")
1947
+ })
1948
+ ]
1949
+ }), custom ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1950
+ style: customRowStyle,
1951
+ children: [
1952
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1953
+ type: "text",
1954
+ inputMode: "numeric",
1955
+ value: raw,
1956
+ disabled,
1957
+ placeholder: t("input.context.customPlaceholder"),
1958
+ "aria-label": t("input.context.customPlaceholder"),
1959
+ style: inputStyle,
1960
+ onChange: (event) => {
1961
+ setRaw(event.currentTarget.value);
1962
+ },
1963
+ onKeyDown: (event) => {
1964
+ if (event.key === "Enter") applyCustom();
1965
+ }
1966
+ }),
1967
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1968
+ type: "button",
1969
+ disabled,
1970
+ style: {
1971
+ ...actionButtonStyle,
1972
+ cursor: disabled ? "default" : "pointer",
1973
+ opacity: disabled ? .55 : 1
1974
+ },
1975
+ onClick: applyCustom,
1976
+ children: t("input.context.apply")
1977
+ }),
1978
+ error !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1979
+ style: errorStyle,
1980
+ children: error
1981
+ })
1982
+ ]
1983
+ }) : null]
1875
1984
  })] }) : null]
1876
1985
  });
1877
1986
  }
@@ -1890,19 +1999,12 @@ window.__ModuleLoader__.load({
1890
1999
  * @param ctx - client root context.
1891
2000
  */
1892
2001
  function apply(ctx) {
1893
- ctx.effect(() => {
1894
- const disposers = [
1895
- ctx.locale.register(NS, {
1896
- zh,
1897
- en
1898
- }),
1899
- ctx.locale.register(NS, "ja", ja),
1900
- ctx.locale.register(NS, "ko", ko)
1901
- ];
1902
- return () => {
1903
- for (const dispose of disposers) dispose();
1904
- };
1905
- }, "dsh-thinking-levels: dictionaries");
2002
+ ctx.effect(() => ctx.locale.register(NS, {
2003
+ zh,
2004
+ en,
2005
+ ja,
2006
+ ko
2007
+ }), "dsh-thinking-levels: dictionaries");
1906
2008
  ctx.slots.inject("settings.plugin.item", function* () {
1907
2009
  yield ctx.slots.register({
1908
2010
  name: "settings.plugin.item",