dsh-usage-state 0.4.0 → 0.4.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/README.en.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # dsh-usage-state
2
2
 
3
- See your **account balance** or **coding-plan quota** at a glance in [DSH (DeepSeek Harness)](https://github.com/deepseek-ai) — right under the composer stats row.
3
+ See your **account balance** or **coding-plan quota** at a glance in [DSH (DeepSeek Harness)](https://github.com/deepseek-ai) — on its own line above the composer input, as wide as the input card.
4
4
 
5
5
  > 中文说明见 [README.md](README.md)。
6
6
 
7
7
  ```
8
- below the composer stats: z.ai / GLM · 5h 12% (4h0m) ▓▓▓░░░░░ · 7d 59% (3d17h) ▓▓▓▓▓░░░
8
+ its own line above the composer input: z.ai / GLM · 5h 12% (4h0m) ▓▓▓░░░░░ · 7d 59% (3d17h) ▓▓▓▓▓░░░
9
9
  DeepSeek · ¥58.13
10
10
  hover any segment: Source DeepSeek · Mode API balance · Granted 0 · Topped up 58.13
11
11
  ```
@@ -14,7 +14,7 @@ hover any segment: Source DeepSeek · Mode API balance · Granted 0 ·
14
14
 
15
15
  - **Works with zero configuration**: the plugin figures out which data source and mode a provider needs, and reuses the API key DSH already has.
16
16
  - **Configured per provider, not per model** — readings are account-level, so each provider gets one setting: `Auto` / `API` / `Coding Plan` / `Hidden`. The model list is informational.
17
- - **One line, always visible**: directly below the composer's stats row (the native stats row and its popover are left untouched, not replaced) — no hover, no click.
17
+ - **One line, always visible**: its own line above the composer input (DSH 0.2 mounts it at `conversation.input.dock`, width-matched to the input card; the native stats row and context meter are left untouched, not replaced) — no hover, no click.
18
18
  - **Never invents data**: a failed refresh keeps the last good value and marks it stale (`12m ago ⚠`); rejected keys, endpoint errors and network problems each get a readable reason.
19
19
  - **Hover details**: source and mode, the window's absolute reset time, the granted/topped-up split of a balance, the failure reason with the provider's own message.
20
20
  - **Bilingual** (zh / en), following the DSH locale setting.
@@ -55,7 +55,7 @@ Nothing showing up after installing? See the troubleshooting table at the end of
55
55
 
56
56
  1. Open **Settings → Usage state**: one row per provider configured in DSH.
57
57
  2. Leave it on **Auto** (it detects the data source and its primary mode), or pick `API` / `Coding Plan` / `Hidden`; use ↑↓ to reorder.
58
- 3. The reading appears directly below the composer's stats row.
58
+ 3. The reading appears on its own line above the composer input, as wide as the input card.
59
59
 
60
60
  If a source needs an endpoint or a key (a self-hosted Sub2API, or a provider without a credential yet), expand that row's **Advanced** block to override the source, set the endpoint, name the credential, or paste a key (written to the DSH credential store).
61
61
 
@@ -101,6 +101,8 @@ Expanding **Advanced** lets you override the source and endpoint, name a credent
101
101
 
102
102
  - **0.2 line only**: `engines.dsh` = `>=0.2.0-rc.2 <0.3.0-0` (this is what dsh-market's badge and install gate read). On an earlier host, install `0.3.2`.
103
103
  - `peerDependencies` carry `@deepseek-ai/dsh-settings` (`^0.2.0-rc.2`) and `@deepseek-ai/schemastery` (`^3.18.2`). The first one is deliberate: the runtime install gate only reads `@deepseek-ai/dsh*` peers, so declaring it makes a 0.1.x host **refuse the install** instead of accepting it and then failing to boot. Both are platform-provided; pnpm may print a `missing peer` warning for them, which is expected.
104
+ - Version `0.4.2` moves the status line to `conversation.input.dock`, giving it **its own line above the composer input** — DSH 0.2 turned the old below-the-input position into a shared row of pills next to the platform's stats and context meter (revisions 19/20).
105
+ - Version `0.4.1` fixes `0.4.0`'s missing readings: the browser half's RPC contribution lacked the `create()` factory 0.2 requires, so `remote.usageState` never mounted — the UI showed **no readings at all** and mislabelled the cause as `Mode not supported`. The same release stops swallowing a rejected mount, says "reading" while the catalog is absent, and adds **real 0.2 registry contract tests** (revision 18). **Use `0.4.1`, not `0.4.0`.**
104
106
  - Version `0.4.0` migrates to the 0.2 settings model (`Config` + `configForms`, with cross-entry config read through `configEditor`). Verification and results: [`docs/implementation.md`](docs/implementation.md) §10; rationale: [`docs/design-consensus.md`](docs/design-consensus.md) revision 17.
105
107
  - Version `0.3.2` (last of the 0.1 line) only widened `engines.dsh`; **its claimed 0.2 compatibility was wrong** — on `0.2.0-rc.2` it fails the entire web boot because `settingsScope` does not exist there.
106
108
  - Published to npm as [`dsh-usage-state`](https://www.npmjs.com/package/dsh-usage-state); GitHub installs work too.
package/README.md CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  **中文** | [English](README.en.md)
4
4
 
5
- 在 [DSH(DeepSeek Harness)](https://github.com/deepseek-ai) 里一眼看到你的**账户余额**或**套餐额度**——就在输入框统计行的正下方。
5
+ 在 [DSH(DeepSeek Harness)](https://github.com/deepseek-ai) 里一眼看到你的**账户余额**或**套餐额度**——就在输入框上方、与输入卡片同宽的一行(原生统计行与其弹窗原样保留、不做替换)。
6
6
 
7
7
  > A minimal DSH plugin that shows your account **balance** (API mode) or **coding-plan quota** (5h / 7d / 30d) for the model you are using, right under the composer.
8
8
 
9
9
  ```
10
- 输入框统计行下方: z.ai / GLM · 5h 12% (4h0m) ▓▓▓░░░░░ · 7d 59% (3d17h) ▓▓▓▓▓░░░
10
+ 输入框上方独立一行: z.ai / GLM · 5h 12% (4h0m) ▓▓▓░░░░░ · 7d 59% (3d17h) ▓▓▓▓▓░░░
11
11
  DeepSeek · ¥58.13
12
12
  悬停任意一段: Source DeepSeek · Mode API balance · Granted 0 · Topped up 58.13
13
13
  ```
@@ -16,7 +16,7 @@
16
16
 
17
17
  - **零配置可用**:按 provider 自动识别该用哪个数据源与模式,DSH 里配过的密钥会被自动复用,不填任何东西就能看到读数。
18
18
  - **账户级配置**:余额与额度是账户级的,所以每个供应商只配一次(`自动` / `API` / `Coding Plan` / `隐藏`),模型清单只作展示。
19
- - **始终可见一行**:固定在输入框统计行的正下方(原生统计行与其弹窗原样保留、不做替换),不需要悬停或点击。
19
+ - **始终可见一行**:独占一行、位于输入框上方(DSH 0.2 把它挂在 `conversation.input.dock`,与输入卡片同宽居中;原生统计行与上下文计量器原样保留、不做替换),不需要悬停或点击。
20
20
  - **失败不撒谎**:请求失败时保留上次成功值并标明「多久之前 + ⚠」,**绝不显示 0 或伪造数据**;密钥无效、接口报错、网络不可达会分别给出可读原因。
21
21
  - **悬浮提示**:每段文字悬停显示一行放不下的信息——数据源与模式、窗口的绝对重置时刻、余额的赠送/充值构成、失败原因与原始消息。
22
22
  - **中英双语**:跟随 DSH 的语言设置(`locale.preference`),设置页与状态行都不含硬编码文案。
@@ -57,7 +57,7 @@ dsh plugin --profile web add /path/to/dsh-usage-state
57
57
 
58
58
  1. 打开 **设置 → 用量状态**:DSH 里配置的每个供应商一行。
59
59
  2. 保持默认的 **自动** 即可(它会识别数据源与主模式);需要时改成 `API` / `Coding Plan` / `隐藏`,或用 ↑↓ 调整顺序。
60
- 3. 该供应商的账户读数会出现在输入框统计行的正下方。
60
+ 3. 该供应商的账户读数会出现在输入框上方、与输入卡片同宽的一行。
61
61
 
62
62
  若某个数据源需要端点或密钥(例如自建的 Sub2API、或尚未配置的 z.ai),展开该行的 **高级**:可覆盖数据源、填接口地址、指定凭据名、粘贴密钥(写入 DSH 凭据库)。
63
63
 
@@ -65,7 +65,7 @@ dsh plugin --profile web add /path/to/dsh-usage-state
65
65
 
66
66
  ## 截图
67
67
 
68
- 输入框统计行正下方的账户读数(图示为 OpenCode Zen Go 的三个窗口,悬停任意一段可看数据源、模式与绝对重置时刻):
68
+ 输入框上方独占一行的账户读数(图示为 OpenCode Zen Go 的三个窗口,悬停任意一段可看数据源、模式与绝对重置时刻):
69
69
 
70
70
  ![输入框下方的账户读数](https://raw.githubusercontent.com/takboo/dsh-usage-state/main/assets/screenshots/status-line.webp)
71
71
 
@@ -125,6 +125,8 @@ dsh plugin --profile web add /path/to/dsh-usage-state
125
125
 
126
126
  - **只支持 DSH 0.2 线**:`engines.dsh` = `>=0.2.0-rc.2 <0.3.0-0`(市场读它做徽标与"可安装"判定)。0.2 之前的宿主请装 `0.3.2`。
127
127
  - `peerDependencies` 里有 `@deepseek-ai/dsh-settings`(`^0.2.0-rc.2`)与 `@deepseek-ai/schemastery`(`^3.18.2`):前者是**故意的**——平台的运行时安装闸门只读 `@deepseek-ai/dsh*` 的 peer,声明它可以让 0.1.x 宿主在**安装时**就拒绝,而不是装上之后把启动搞崩;两者都由平台提供,pnpm 可能为此打一行 `missing peer` 警告,属预期。
128
+ - 版本 `0.4.2`:状态行迁到 `conversation.input.dock`,成为**输入框上方的独立一行**(0.1 时代它在输入框之下,而 0.2 把那个位置改成了与平台统计、上下文计量器共排的一排 pill——见修订 19/20)。
129
+ - 版本 `0.4.1`:修 `0.4.0` 的读数缺失——客户端 RPC contribution 的参数 codec 少了 0.2 要求的 `create()`,`remote.usageState` 因此从未挂载,界面表现为**没有任何读数**并误报 `Mode not supported`。同一轮还让挂载失败不再被静默吞掉、catalog 未到时改说「读取中」,并把**真实 0.2 registry 契约测试**写进单测(修订 18)。**请用 `0.4.1`,不要用 `0.4.0`。**
128
130
  - 版本 `0.4.0`:迁到 0.2 原生设置模型(`Config` + `configForms`,宿主侧 `configEditor` 读跨条目配置)。验证方式与结论见 [`docs/implementation.md`](docs/implementation.md) §10、决策见 [`docs/design-consensus.md`](docs/design-consensus.md) 修订 17。
129
131
  - 版本 `0.3.2`(0.1 线末版):仅放宽 `engines.dsh`;**它声称的 0.2 兼容是错的**(0.3.2 在 0.2.0-rc.2 上会因 `settingsScope` 不存在而让整个 web 启动失败)。
130
132
  - 同名发布在 npm([`dsh-usage-state`](https://www.npmjs.com/package/dsh-usage-state)),也可从 GitHub 直接安装。
package/lib/client.js CHANGED
@@ -7,6 +7,47 @@ window.__ModuleLoader__.load({
7
7
  let react = require("react");
8
8
  let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
9
9
  let react_jsx_runtime = require("react/jsx-runtime");
10
+ //#region src/client/contribution.ts
11
+ /** Absent or boolean — the one parameter this plugin's RPC takes. */
12
+ const forceSchema = { parse: (value) => value === void 0 ? void 0 : value === true };
13
+ /**
14
+ * A strict codec built without zod: `schema` is what the wire decodes through, and
15
+ * `create()` is the factory the platform's registry calls to obtain it.
16
+ */
17
+ const booleanOrUndefined = {
18
+ mode: "strict",
19
+ typeSymbol: "dsh-usage-state#Force",
20
+ create: () => forceSchema
21
+ };
22
+ const srcJson = { mode: "src-json" };
23
+ /** Must mirror `src/host/typert.ts`: the wire endpoint is `<namespace>/<method>`. */
24
+ const CONTRIBUTION = {
25
+ package: "dsh-usage-state",
26
+ descriptors: [{
27
+ id: "dsh-usage-state#usageState/getState",
28
+ service: "usageState",
29
+ namespace: "usageState",
30
+ method: "getState",
31
+ invocation: { kind: "direct" },
32
+ parameters: [{
33
+ name: "force",
34
+ wire: "force",
35
+ source: "json",
36
+ acceptsUndefined: true,
37
+ codec: booleanOrUndefined
38
+ }],
39
+ result: srcJson
40
+ }, {
41
+ id: "dsh-usage-state#usageState/describeCredentials",
42
+ service: "usageState",
43
+ namespace: "usageState",
44
+ method: "describeCredentials",
45
+ invocation: { kind: "direct" },
46
+ parameters: [],
47
+ result: srcJson
48
+ }]
49
+ };
50
+ //#endregion
10
51
  //#region src/shared/config.ts
11
52
  const DEFAULT_CONFIG = {
12
53
  models: [],
@@ -1067,6 +1108,10 @@ window.__ModuleLoader__.load({
1067
1108
  function describeStatus(input) {
1068
1109
  const { status, snapshot, display, now } = input;
1069
1110
  if (status.kind === "hidden") return [];
1111
+ if (status.kind === "loading") return [{
1112
+ kind: "state",
1113
+ state: "loading"
1114
+ }];
1070
1115
  if (status.kind === "unconfigured") return [{
1071
1116
  kind: "state",
1072
1117
  state: "unconfigured"
@@ -1223,24 +1268,31 @@ window.__ModuleLoader__.load({
1223
1268
  //#endregion
1224
1269
  //#region src/client/StatusLine.tsx
1225
1270
  /**
1226
- * The composer mount point: one line directly under the platform's stats row, so
1227
- * it reads as that row's second line rather than a stray block.
1271
+ * The composer mount point: one full-width line in the composer stack, directly
1272
+ * above the input card.
1273
+ *
1274
+ * `conversation.input.dock` is a stretched column child (`.composerStack` is a column
1275
+ * flex with no `align-items`), so the width comes from the card's own custom
1276
+ * property, exactly like the platform's queued-message dock in that slot. It is
1277
+ * **not** the row below the card: `conversation.composer.dock` there is one centered
1278
+ * flex row shared with the platform's stats pill and the context meter, where a
1279
+ * contribution can only ever be a pill beside them (revisions 19 and 20).
1228
1280
  */
1229
1281
  const DOCK_STYLE = {
1230
1282
  display: "flex",
1231
1283
  alignItems: "center",
1232
1284
  justifyContent: "center",
1233
- gap: "8px",
1234
- fontSize: "var(--dsh-content-font-size-secondary, 13px)",
1235
- lineHeight: "calc(20px + var(--dsh-content-font-delta-secondary, 0px))",
1285
+ gap: "6px",
1286
+ font: "inherit",
1287
+ lineHeight: "inherit",
1236
1288
  fontVariantNumeric: "tabular-nums",
1237
1289
  whiteSpace: "nowrap",
1238
- overflow: "hidden",
1239
- textOverflow: "ellipsis",
1290
+ flexWrap: "wrap",
1291
+ rowGap: "2px",
1240
1292
  width: "100%",
1241
- maxWidth: "var(--dsh-chat-content-width)",
1293
+ maxWidth: "var(--dsh-composer-card-max-width)",
1242
1294
  margin: "0 auto",
1243
- padding: "4px calc(var(--dsh-composer-side-clearance) + 16px) 0"
1295
+ padding: "0 var(--dsh-composer-side-clearance)"
1244
1296
  };
1245
1297
  const LABEL_STYLE = { color: "var(--dsw-alias-label-tertiary)" };
1246
1298
  const SEPARATOR_STYLE = { color: "var(--dsw-alias-separator-primary, var(--dsw-alias-label-dimmed))" };
@@ -1287,12 +1339,15 @@ window.__ModuleLoader__.load({
1287
1339
  }
1288
1340
  }
1289
1341
  /** Map a provider resolution onto what the line can say about it. */
1290
- function statusOf(resolution) {
1342
+ function statusOf(resolution, catalogEmpty) {
1291
1343
  switch (resolution.reason) {
1292
1344
  case "hidden": return { kind: "hidden" };
1293
1345
  case "needs-endpoint": return { kind: "needs-endpoint" };
1294
1346
  case "unknown-source":
1295
- case "unsupported": return resolution.sourceId === null ? { kind: "unconfigured" } : { kind: "unsupported" };
1347
+ case "unsupported":
1348
+ if (resolution.sourceId === null) return { kind: "unconfigured" };
1349
+ if (catalogEmpty) return { kind: "loading" };
1350
+ return { kind: "unsupported" };
1296
1351
  case "auto":
1297
1352
  case "configured":
1298
1353
  if (resolution.key === void 0 || resolution.sourceId === null || resolution.mode === null) return { kind: "unconfigured" };
@@ -1323,11 +1378,15 @@ window.__ModuleLoader__.load({
1323
1378
  provider: current.provider,
1324
1379
  config,
1325
1380
  catalog: state.catalog
1326
- }));
1381
+ }), state.catalog.length === 0);
1327
1382
  const snapshot = status.kind === "ready" ? state.snapshots[status.key] : void 0;
1328
1383
  const sourceLabel = status.kind === "ready" ? state.catalog.find((entry) => entry.id === status.sourceId)?.displayName ?? status.sourceId : "";
1329
1384
  const fullParts = statusParts({
1330
- segments: describeStatus({
1385
+ segments: state.catalog.length === 0 && state.status === "error" && state.error !== void 0 ? [{
1386
+ kind: "state",
1387
+ state: "error",
1388
+ errorDetail: state.error
1389
+ }] : describeStatus({
1331
1390
  sourceLabel,
1332
1391
  status,
1333
1392
  snapshot,
@@ -1574,9 +1633,9 @@ window.__ModuleLoader__.load({
1574
1633
  //#endregion
1575
1634
  //#region src/client/slots.ts
1576
1635
  const STATUS_LINE_SLOTS = [{
1577
- name: "conversation.composer.dock",
1636
+ name: "conversation.input.dock",
1578
1637
  id: "usage-state",
1579
- order: 1,
1638
+ order: 200,
1580
1639
  locale: "usage-state"
1581
1640
  }];
1582
1641
  //#endregion
@@ -1722,6 +1781,21 @@ window.__ModuleLoader__.load({
1722
1781
  this.publish({ credentialsError: messageOf(error) });
1723
1782
  }
1724
1783
  }
1784
+ /**
1785
+ * Record that the RPC contribution never mounted.
1786
+ *
1787
+ * Without this the only symptom is an empty catalog, which every surface reads
1788
+ * as "nothing configured yet" — the real cause has to be nameable, because it is
1789
+ * a plugin/host contract failure, not something the user can configure away.
1790
+ */
1791
+ failRemote(message) {
1792
+ this.publish({
1793
+ status: "error",
1794
+ error: message,
1795
+ catalog: [],
1796
+ snapshots: {}
1797
+ });
1798
+ }
1725
1799
  };
1726
1800
  //#endregion
1727
1801
  //#region src/client/index.tsx
@@ -1735,40 +1809,6 @@ window.__ModuleLoader__.load({
1735
1809
  ];
1736
1810
  const USAGE_STATE_NS = "usage-state";
1737
1811
  const POLL_INTERVAL_MS = 3e4;
1738
- /** Hand-rolled codecs: the browser bundle must not carry zod. */
1739
- const booleanOrUndefined = {
1740
- mode: "strict",
1741
- typeSymbol: "dsh-usage-state#Force",
1742
- schema: { parse: (value) => value === void 0 ? void 0 : value === true }
1743
- };
1744
- const srcJson = { mode: "src-json" };
1745
- /** Must mirror `src/host/typert.ts`: the wire endpoint is `<namespace>/<method>`. */
1746
- const CONTRIBUTION = {
1747
- package: "dsh-usage-state",
1748
- descriptors: [{
1749
- id: "dsh-usage-state#usageState/getState",
1750
- service: "usageState",
1751
- namespace: "usageState",
1752
- method: "getState",
1753
- invocation: { kind: "direct" },
1754
- parameters: [{
1755
- name: "force",
1756
- wire: "force",
1757
- source: "json",
1758
- acceptsUndefined: true,
1759
- codec: booleanOrUndefined
1760
- }],
1761
- result: srcJson
1762
- }, {
1763
- id: "dsh-usage-state#usageState/describeCredentials",
1764
- service: "usageState",
1765
- namespace: "usageState",
1766
- method: "describeCredentials",
1767
- invocation: { kind: "direct" },
1768
- parameters: [],
1769
- result: srcJson
1770
- }]
1771
- };
1772
1812
  function apply(ctx) {
1773
1813
  ctx.effect(() => ctx.locale.register(LOCALE_NS, {
1774
1814
  zh,
@@ -1815,7 +1855,11 @@ window.__ModuleLoader__.load({
1815
1855
  store.refresh(false);
1816
1856
  store.refreshModels();
1817
1857
  store.refreshCredentials();
1818
- }, () => void 0);
1858
+ }, (error) => {
1859
+ const message = error instanceof Error ? error.message : String(error);
1860
+ console.error("dsh-usage-state: remote contribution did not mount", error);
1861
+ store.failRemote(message);
1862
+ });
1819
1863
  return () => {
1820
1864
  cancelled = true;
1821
1865
  dispose?.();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-usage-state",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "type": "module",
5
5
  "description": "DSH plugin: show account balance (API mode) or coding-plan quota (5h/7d/30d) for the model in use",
6
6
  "license": "MIT",
@@ -28,12 +28,14 @@
28
28
  "./package.json": "./package.json"
29
29
  },
30
30
  "devDependencies": {
31
+ "@deepseek-ai/cordis": "^4.0.4",
31
32
  "@deepseek-ai/dsh-client-locale": "^0.2.0-rc.2",
32
33
  "@deepseek-ai/dsh-client-store": "^0.2.0-rc.2",
33
34
  "@deepseek-ai/dsh-client-ui-conversation": "^0.2.0-rc.2",
34
35
  "@deepseek-ai/dsh-client-ui-primitives": "^0.2.0-rc.2",
35
36
  "@deepseek-ai/dsh-client-ui-slots": "^0.2.0-rc.2",
36
37
  "@deepseek-ai/dsh-typert-loader": "^0.2.0-rc.2",
38
+ "@deepseek-ai/dsh-typert-registry": "^0.2.0-rc.2",
37
39
  "@deepseek-ai/schemastery": "^3.18.2",
38
40
  "@types/node": "^24.0.0",
39
41
  "@types/react": "~18.3.1",