@huaweidevtools/aishell-dsh-client-credentials 0.0.14 → 0.0.16

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
@@ -26,6 +26,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  //#endregion
27
27
  const __deepseek_ai_dsh_client_store = __toESM(require("@deepseek-ai/dsh-client-store"));
28
28
  const react = __toESM(require("react"));
29
+ const __deepseek_ai_dsh_client_ui_primitives = __toESM(require("@deepseek-ai/dsh-client-ui-primitives"));
29
30
  const react_jsx_runtime = __toESM(require("react/jsx-runtime"));
30
31
 
31
32
  //#region src/client/permission-mode.ts
@@ -36,6 +37,38 @@ const react_jsx_runtime = __toESM(require("react/jsx-runtime"));
36
37
  * route's authentication fence requires.
37
38
  */
38
39
  const PERMISSION_ROUTE = "api/aishell/permission";
40
+ /**
41
+ * Decide what a click does, from the mode in effect.
42
+ *
43
+ * Exported and pure so the direction that escalates is testable without a DOM
44
+ * renderer — see `tests/permission-gate.spec.ts`. The asymmetry is the whole
45
+ * point: read-write widens what the agent may do to a real account, so it asks
46
+ * first; read-only narrows it, so it does not.
47
+ *
48
+ * An unknown mode is `'none'` rather than `'confirm'`: it is not read-only, and
49
+ * offering the escalation gate against a session that may already be in
50
+ * read-write would ask the person to approve a mode they are already in.
51
+ *
52
+ * @param mode - the mode in effect, or `undefined` before one is read.
53
+ * @returns what the click should do.
54
+ */
55
+ function toggleOutcome(mode) {
56
+ if (mode === void 0) return "none";
57
+ return mode === "read_only" ? "confirm" : "apply";
58
+ }
59
+ /**
60
+ * Whether the gate's confirm button may write.
61
+ *
62
+ * One condition, named rather than inlined, because the chips and the hook must
63
+ * agree on it — a chip that enabled the button on a different condition would
64
+ * let an unacknowledged flip through.
65
+ *
66
+ * @param acknowledged - the acknowledgement box's state.
67
+ * @returns whether the read-write flip may run.
68
+ */
69
+ function mayApply(acknowledged) {
70
+ return acknowledged;
71
+ }
39
72
  /** Narrow an unknown value to a mode. */
40
73
  function asMode(value) {
41
74
  return value === "read_only" || value === "read_write" ? value : void 0;
@@ -84,11 +117,34 @@ async function writePermissionMode(mode) {
84
117
  * there is no poll — a second surface flipping it is not a case this handles;
85
118
  * each surface re-reads on its own mount.
86
119
  *
87
- * @returns the current mode, a busy flag, and the toggle.
120
+ * ## Why the confirmation lives here rather than in a chip
121
+ *
122
+ * Each chip calls this hook for itself, so nothing here is shared React state;
123
+ * what decided the placement is the shape of the interaction, not the count of
124
+ * callers. A flip and its confirmation are one gesture split across a dialog,
125
+ * and the fact that has to survive the split is "a read-write write is awaiting
126
+ * acknowledgement". Kept in a chip, that fact dies with a remount — and the
127
+ * chips do remount: the hero chip stops rendering the moment the first turn is
128
+ * accepted, so a confirmation opened on a blank session would lose its
129
+ * acknowledgement the instant the session existed.
130
+ *
131
+ * Holding it with the mode also keeps the write in one place: `confirmToggle`
132
+ * closes the gate and calls the same `apply` that `toggle` uses, so a confirmed
133
+ * flip and an immediate one cannot diverge in how they report the server's
134
+ * answer.
135
+ *
136
+ * Two mounts do not run concurrently today — the hero chip gates on
137
+ * `session.blank` and the composer chip needs a session — so this is not two
138
+ * dialogs racing over one value. It is one hook whose surface can be swapped
139
+ * under it.
140
+ *
141
+ * @returns the current mode, a busy flag, the gated toggle, and the
142
+ * confirmation state for a pending read-write flip.
88
143
  */
89
144
  function usePermissionMode() {
90
145
  const [mode, setMode] = (0, react.useState)(void 0);
91
146
  const [busy, setBusy] = (0, react.useState)(false);
147
+ const [confirmation, setConfirmation] = (0, react.useState)(void 0);
92
148
  (0, react.useEffect)(() => {
93
149
  let live = true;
94
150
  (async () => {
@@ -99,9 +155,8 @@ function usePermissionMode() {
99
155
  live = false;
100
156
  };
101
157
  }, []);
102
- const toggle = () => {
103
- if (mode === void 0 || busy) return;
104
- const next = mode === "read_only" ? "read_write" : "read_only";
158
+ /** Write the mode the control should land on, from whatever is current. */
159
+ const apply$1 = (next) => {
105
160
  setBusy(true);
106
161
  (async () => {
107
162
  const applied = await writePermissionMode(next);
@@ -109,13 +164,70 @@ function usePermissionMode() {
109
164
  setBusy(false);
110
165
  })();
111
166
  };
167
+ const toggle = () => {
168
+ if (busy) return;
169
+ const outcome = toggleOutcome(mode);
170
+ if (outcome === "none") return;
171
+ if (outcome === "confirm") {
172
+ setConfirmation({
173
+ acknowledged: false,
174
+ setAcknowledged: (acknowledged) => {
175
+ setConfirmation((current) => current === void 0 ? current : {
176
+ ...current,
177
+ acknowledged
178
+ });
179
+ }
180
+ });
181
+ return;
182
+ }
183
+ apply$1("read_only");
184
+ };
185
+ const cancelConfirmation = () => {
186
+ setConfirmation(void 0);
187
+ };
188
+ const confirmToggle = () => {
189
+ if (confirmation === void 0 || !mayApply(confirmation.acknowledged)) return;
190
+ setConfirmation(void 0);
191
+ apply$1("read_write");
192
+ };
112
193
  return {
113
194
  mode,
114
195
  busy,
115
- toggle
196
+ toggle,
197
+ confirmation,
198
+ cancelConfirmation,
199
+ confirmToggle
116
200
  };
117
201
  }
118
202
 
203
+ //#endregion
204
+ //#region src/client/PermissionRiskDialog.tsx
205
+ /**
206
+ * Render the gate when a read-write flip is waiting on the person.
207
+ *
208
+ * @param props - see {@link PermissionRiskDialogProps}.
209
+ * @returns the dialog, or `null` when nothing is pending.
210
+ */
211
+ function PermissionRiskDialog(props) {
212
+ const { confirmation, onCancel, onConfirm, t } = props;
213
+ if (confirmation === void 0) return null;
214
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__deepseek_ai_dsh_client_ui_primitives.RiskConfirmation, {
215
+ open: true,
216
+ title: t("mode.confirm.title"),
217
+ description: t("mode.confirm.description"),
218
+ acknowledgeLabel: t("mode.confirm.acknowledge"),
219
+ cancelLabel: t("mode.confirm.cancel"),
220
+ closeLabel: t("mode.confirm.close"),
221
+ confirmLabel: t("mode.confirm.enable"),
222
+ acknowledged: confirmation.acknowledged,
223
+ onAcknowledgedChange: (acknowledged) => {
224
+ confirmation.setAcknowledged(acknowledged);
225
+ },
226
+ onCancel,
227
+ onConfirm
228
+ });
229
+ }
230
+
119
231
  //#endregion
120
232
  //#region src/client/huawei-mark.ts
121
233
  /** Huawei logo path (from simple-icons/huawei), drawn in a 24×24 viewBox. */
@@ -154,10 +266,12 @@ const CHIP_STYLE_KEY = `${PLUGIN_ID$1}/chip-hover`;
154
266
  * a disposer that removes the tag, and the `data-plugin` markers so
155
267
  * `removeOwnedStyles` can also reach it. The disposer is what makes a reload
156
268
  * pick up an edited rule — the fiber tears down, the tag goes, and the next
157
- * materialization writes the new text. A module-level install with an id guard
158
- * fails exactly there: the tag outlives the module (the loader only sweeps
159
- * `data-plugin` tags), the guard then sees it and returns, and the old CSS
160
- * stays in force for the life of the page.
269
+ * materialization writes the new text.
270
+ *
271
+ * A module-level install guarded by an id cannot do that: the tag outlives the
272
+ * module because the loader sweeps only `data-plugin` tags, so the guard finds
273
+ * it on the next materialization and returns, and the page keeps the rule from
274
+ * before the edit for its whole life.
161
275
  *
162
276
  * Call once from `apply()`, not from the components: the rule is shared by
163
277
  * both chips (they carry the same `CHIP_CLASS`), so one sheet serves them and
@@ -199,7 +313,7 @@ function AishellAccountHint(props) {
199
313
  const configured = Boolean(hint);
200
314
  const t = props.t;
201
315
  const openCredentialForm = props.openCredentialForm;
202
- const { mode, busy, toggle } = usePermissionMode();
316
+ const { mode, busy, toggle, confirmation, cancelConfirmation, confirmToggle } = usePermissionMode();
203
317
  const ref = (0, react.useRef)(null);
204
318
  (0, react.useEffect)(() => {
205
319
  const host = ref.current?.parentElement;
@@ -242,54 +356,63 @@ function AishellAccountHint(props) {
242
356
  marginLeft: "auto",
243
357
  flex: "none"
244
358
  },
245
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
246
- type: "button",
247
- className: CHIP_CLASS,
248
- "aria-label": configured ? hint : t("account.unconfigured"),
249
- onClick: openCredentialForm,
250
- style: {
251
- ...pillStyle,
252
- color: configured ? "var(--dsw-alias-label-tertiary)" : "var(--dsw-alias-state-warn-label)",
253
- maxWidth: "100%",
254
- overflow: "hidden",
255
- textOverflow: "ellipsis"
256
- },
257
- title: configured ? hint : t("account.unconfigured"),
258
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
259
- "aria-hidden": true,
260
- width: "14",
261
- height: "14",
262
- viewBox: "0 0 24 24",
263
- fill: "currentColor",
264
- style: {
265
- color: configured ? HUAWEI_RED : "var(--dsw-alias-state-warn-label)",
266
- flex: "none"
267
- },
268
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: HUAWEI_LOGO_PATH })
269
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
359
+ children: [
360
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
361
+ type: "button",
362
+ className: CHIP_CLASS,
363
+ "aria-label": configured ? hint : t("account.unconfigured"),
364
+ onClick: openCredentialForm,
270
365
  style: {
366
+ ...pillStyle,
367
+ color: configured ? "var(--dsw-alias-label-tertiary)" : "var(--dsw-alias-state-warn-label)",
368
+ maxWidth: "100%",
271
369
  overflow: "hidden",
272
370
  textOverflow: "ellipsis"
273
371
  },
274
- children: configured ? hint : t("account.unconfigured")
275
- })]
276
- }), configured && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
277
- type: "button",
278
- className: CHIP_CLASS,
279
- onClick: () => {
280
- toggle();
281
- },
282
- disabled: mode === void 0 || busy,
283
- "aria-label": mode === "read_write" ? t("mode.switchToReadonly") : t("mode.switchToReadwrite"),
284
- style: {
285
- ...pillStyle,
286
- color: mode === void 0 ? "var(--dsw-alias-label-tertiary)" : mode === "read_only" ? "var(--dsw-alias-state-success-primary)" : "var(--dsw-alias-state-warn-label)",
287
- opacity: mode === void 0 || busy ? .6 : 1,
288
- cursor: mode === void 0 || busy ? "default" : "pointer"
289
- },
290
- title: mode === void 0 ? t("mode.unavailable.hint") : mode === "read_only" ? t("mode.readonly.hint") : t("mode.readwrite.hint"),
291
- children: mode === void 0 ? t("mode.unavailable") : mode === "read_only" ? t("mode.readonly") : t("mode.readwrite")
292
- })]
372
+ title: configured ? hint : t("account.unconfigured"),
373
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
374
+ "aria-hidden": true,
375
+ width: "14",
376
+ height: "14",
377
+ viewBox: "0 0 24 24",
378
+ fill: "currentColor",
379
+ style: {
380
+ color: configured ? HUAWEI_RED : "var(--dsw-alias-state-warn-label)",
381
+ flex: "none"
382
+ },
383
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: HUAWEI_LOGO_PATH })
384
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
385
+ style: {
386
+ overflow: "hidden",
387
+ textOverflow: "ellipsis"
388
+ },
389
+ children: configured ? hint : t("account.unconfigured")
390
+ })]
391
+ }),
392
+ configured && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
393
+ type: "button",
394
+ className: CHIP_CLASS,
395
+ onClick: () => {
396
+ toggle();
397
+ },
398
+ disabled: mode === void 0 || busy,
399
+ "aria-label": mode === "read_write" ? t("mode.switchToReadonly") : t("mode.switchToReadwrite"),
400
+ style: {
401
+ ...pillStyle,
402
+ color: mode === void 0 ? "var(--dsw-alias-label-tertiary)" : mode === "read_only" ? "var(--dsw-alias-state-success-primary)" : "var(--dsw-alias-state-warn-label)",
403
+ opacity: mode === void 0 || busy ? .6 : 1,
404
+ cursor: mode === void 0 || busy ? "default" : "pointer"
405
+ },
406
+ title: mode === void 0 ? t("mode.unavailable.hint") : mode === "read_only" ? t("mode.readonly.hint") : t("mode.readwrite.hint"),
407
+ children: mode === void 0 ? t("mode.unavailable") : mode === "read_only" ? t("mode.readonly") : t("mode.readwrite")
408
+ }),
409
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PermissionRiskDialog, {
410
+ confirmation,
411
+ onCancel: cancelConfirmation,
412
+ onConfirm: confirmToggle,
413
+ t
414
+ })
415
+ ]
293
416
  });
294
417
  }
295
418
 
@@ -298,7 +421,7 @@ function AishellAccountHint(props) {
298
421
  function AishellHeroChip(props) {
299
422
  const blank = props.useSession((session) => session.blank);
300
423
  const status = props.useCredentials((snapshot) => snapshot);
301
- const { mode, busy, toggle } = usePermissionMode();
424
+ const { mode, busy, toggle, confirmation, cancelConfirmation, confirmToggle } = usePermissionMode();
302
425
  const t = props.t;
303
426
  const openCredentialForm = props.openCredentialForm;
304
427
  const configured = Boolean(status.accessKeyIdHint);
@@ -390,53 +513,62 @@ function AishellHeroChip(props) {
390
513
  marginLeft: presetOffset ?? 0,
391
514
  flex: "none"
392
515
  },
393
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
394
- type: "button",
395
- className: CHIP_CLASS,
396
- "aria-label": configured ? status.accessKeyIdHint : t("account.unconfigured"),
397
- onClick: openCredentialForm,
398
- style: {
399
- ...pillStyle,
400
- color: configured ? "var(--dsw-alias-label-tertiary)" : "var(--dsw-alias-state-warn-label)",
401
- maxWidth: 220,
402
- overflow: "hidden",
403
- textOverflow: "ellipsis"
404
- },
405
- title: configured ? status.accessKeyIdHint : t("account.unconfigured"),
406
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
407
- "aria-hidden": true,
408
- width: "14",
409
- height: "14",
410
- viewBox: "0 0 24 24",
411
- fill: "currentColor",
412
- style: {
413
- color: configured ? HUAWEI_RED : "var(--dsw-alias-state-warn-label)",
414
- flex: "none"
415
- },
416
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: HUAWEI_LOGO_PATH })
417
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
516
+ children: [
517
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
518
+ type: "button",
519
+ className: CHIP_CLASS,
520
+ "aria-label": configured ? status.accessKeyIdHint : t("account.unconfigured"),
521
+ onClick: openCredentialForm,
418
522
  style: {
523
+ ...pillStyle,
524
+ color: configured ? "var(--dsw-alias-label-tertiary)" : "var(--dsw-alias-state-warn-label)",
525
+ maxWidth: 220,
419
526
  overflow: "hidden",
420
527
  textOverflow: "ellipsis"
421
528
  },
422
- children: configured ? status.accessKeyIdHint : t("account.unconfigured")
423
- })]
424
- }), configured && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
425
- type: "button",
426
- onClick: () => {
427
- toggle();
428
- },
429
- disabled: mode === void 0 || busy,
430
- "aria-label": mode === "read_write" ? t("mode.switchToReadonly") : t("mode.switchToReadwrite"),
431
- title: mode === void 0 ? t("mode.unavailable.hint") : mode === "read_only" ? t("mode.readonly.hint") : t("mode.readwrite.hint"),
432
- style: {
433
- ...pillStyle,
434
- color: mode === void 0 ? "var(--dsw-alias-label-tertiary)" : mode === "read_only" ? "var(--dsw-alias-state-success-primary)" : "var(--dsw-alias-state-warn-label)",
435
- opacity: mode === void 0 || busy ? .6 : 1,
436
- cursor: mode === void 0 || busy ? "default" : "pointer"
437
- },
438
- children: mode === void 0 ? t("mode.unavailable") : mode === "read_only" ? t("mode.readonly") : t("mode.readwrite")
439
- })]
529
+ title: configured ? status.accessKeyIdHint : t("account.unconfigured"),
530
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
531
+ "aria-hidden": true,
532
+ width: "14",
533
+ height: "14",
534
+ viewBox: "0 0 24 24",
535
+ fill: "currentColor",
536
+ style: {
537
+ color: configured ? HUAWEI_RED : "var(--dsw-alias-state-warn-label)",
538
+ flex: "none"
539
+ },
540
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: HUAWEI_LOGO_PATH })
541
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
542
+ style: {
543
+ overflow: "hidden",
544
+ textOverflow: "ellipsis"
545
+ },
546
+ children: configured ? status.accessKeyIdHint : t("account.unconfigured")
547
+ })]
548
+ }),
549
+ configured && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
550
+ type: "button",
551
+ onClick: () => {
552
+ toggle();
553
+ },
554
+ disabled: mode === void 0 || busy,
555
+ "aria-label": mode === "read_write" ? t("mode.switchToReadonly") : t("mode.switchToReadwrite"),
556
+ title: mode === void 0 ? t("mode.unavailable.hint") : mode === "read_only" ? t("mode.readonly.hint") : t("mode.readwrite.hint"),
557
+ style: {
558
+ ...pillStyle,
559
+ color: mode === void 0 ? "var(--dsw-alias-label-tertiary)" : mode === "read_only" ? "var(--dsw-alias-state-success-primary)" : "var(--dsw-alias-state-warn-label)",
560
+ opacity: mode === void 0 || busy ? .6 : 1,
561
+ cursor: mode === void 0 || busy ? "default" : "pointer"
562
+ },
563
+ children: mode === void 0 ? t("mode.unavailable") : mode === "read_only" ? t("mode.readonly") : t("mode.readwrite")
564
+ }),
565
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PermissionRiskDialog, {
566
+ confirmation,
567
+ onCancel: cancelConfirmation,
568
+ onConfirm: confirmToggle,
569
+ t
570
+ })
571
+ ]
440
572
  });
441
573
  }
442
574
 
@@ -1623,6 +1755,12 @@ const zh = {
1623
1755
  "mode.unavailable.hint": "无法读取权限模式;切换按钮暂不可用",
1624
1756
  "mode.switchToReadonly": "切换为只读模式",
1625
1757
  "mode.switchToReadwrite": "切换为读写模式",
1758
+ "mode.confirm.title": "确认切换为读写模式?",
1759
+ "mode.confirm.description": "切换为读写后,智能体可以直接变更你的华为云账号,包括:创建、修改和删除云资源;变更安全组、网络与权限配置,可能导致服务中断;按实际用量产生费用,资源在销毁前会持续计费;被删除的资源通常无法恢复。",
1760
+ "mode.confirm.acknowledge": "我已了解上述影响,并愿意继续",
1761
+ "mode.confirm.cancel": "保持只读",
1762
+ "mode.confirm.enable": "切换为读写",
1763
+ "mode.confirm.close": "关闭",
1626
1764
  "section.credentials.hint.prefix": "建议从",
1627
1765
  "section.credentials.hint.link": "API Explorer",
1628
1766
  "section.credentials.hint.suffix": "获取临时凭据,避免使用永久凭据。",
@@ -1673,6 +1811,12 @@ const en = {
1673
1811
  "mode.unavailable.hint": "Could not read the permission mode; the toggle is unavailable",
1674
1812
  "mode.switchToReadonly": "Switch to read-only mode",
1675
1813
  "mode.switchToReadwrite": "Switch to read-write mode",
1814
+ "mode.confirm.title": "Switch to read-write?",
1815
+ "mode.confirm.description": "In read-write mode the agent can change your Huawei Cloud account directly: create, modify and delete cloud resources; change security groups, networking and permission settings, which can interrupt running services; incur charges based on actual usage, with resources billed until they are destroyed; and delete resources that usually cannot be recovered. ",
1816
+ "mode.confirm.acknowledge": "I understand these impacts and want to continue",
1817
+ "mode.confirm.cancel": "Stay read-only",
1818
+ "mode.confirm.enable": "Switch to read-write",
1819
+ "mode.confirm.close": "Close",
1676
1820
  "section.credentials.hint.prefix": "Obtain temporary credentials from",
1677
1821
  "section.credentials.hint.link": "API Explorer",
1678
1822
  "section.credentials.hint.suffix": "and avoid permanent ones.",
@@ -1792,8 +1936,8 @@ async function clearBothStores(t) {
1792
1936
  * Read the credential prefills the host has in its environment.
1793
1937
  *
1794
1938
  * Failure is not an event: a host with nothing in its environment answers an
1795
- * empty object, and a route that cannot be reached answers `{}` too, because a
1796
- * form that starts empty is exactly the behaviour before this existed.
1939
+ * empty object, and a route that cannot be reached answers `{}` too. A form
1940
+ * that starts empty is the ordinary case, so there is nothing to report.
1797
1941
  *
1798
1942
  * @returns the prefills, or an empty object.
1799
1943
  */
package/lib/index.js CHANGED
@@ -1039,12 +1039,12 @@ const MAX_FORM_ROUNDS = 10;
1039
1039
  *
1040
1040
  * ## Why no instruction follows
1041
1041
  *
1042
- * An earlier version ended with "Do not call auth again until they say to."
1043
- * The intent was to stop a model retrying in a loop, but what it produced was
1044
- * a model that treated every later sentence from the person as a question
1045
- * about permission — asked to look again, it narrated its uncertainty about
1046
- * whether that counted as consent, and stalled instead of either retrying or
1047
- * explaining. The fact is enough; what follows it is the model's judgement.
1042
+ * The message states the fact and stops. Adding "do not call auth again until
1043
+ * they say to" reads as a permission rule to be interpreted, and a model given
1044
+ * a rule it cannot evaluate narrates its uncertainty instead of acting: asked
1045
+ * to look again, it reasons about whether that counts as consent, and neither
1046
+ * retries nor explains. The fact is what the model needs; what follows from it
1047
+ * is its judgement.
1048
1048
  */
1049
1049
  var CredentialEntryCancelled = class extends Error {
1050
1050
  constructor() {
@@ -2368,15 +2368,15 @@ const MAX_BODY_BYTES = 8 * 1024;
2368
2368
  * answer from the same endpoint (profile: `GET /v3/projects`, with the account
2369
2369
  * name read best-effort from `/v3/auth/domains`).
2370
2370
  *
2371
- * ## Why not a local domains-only call
2371
+ * ## Why the shared verifier rather than a narrower call
2372
2372
  *
2373
- * This used to call `/v3/auth/domains` directly, because the only fact this
2374
- * route needed was the account name shown in the composer chip. That made it a
2375
- * second, narrower notion of validity: `/v3/projects` rejects a credential with
2376
- * no visible project, while `/v3/auth/domains` accepts it — so the form said
2377
- * "saved" for credentials the tools would then refuse. One verifier removes
2378
- * that gap, and the project list it returns is exactly what a caller needs
2379
- * before planning a deployment.
2373
+ * The form's own question is "is this pair valid", and the answer has to agree
2374
+ * with the one the tools get — otherwise it accepts credentials the tools then
2375
+ * refuse. A narrower check would do exactly that: `/v3/projects` rejects a
2376
+ * credential with no visible project, while a domains-only call accepts it, so
2377
+ * the form would say "saved" for a pair that fails on the first real call. One
2378
+ * verifier removes that gap, and the project list it returns is what a caller
2379
+ * needs before planning a deployment anyway.
2380
2380
  *
2381
2381
  * ## The region
2382
2382
  *
@@ -2413,10 +2413,32 @@ function jsonError(status, message) {
2413
2413
  error: message
2414
2414
  }, { status });
2415
2415
  }
2416
- /** Read a bounded JSON object body, or throw a user-readable message. */
2416
+ /**
2417
+ * Read a bounded JSON object body, or throw a user-readable message.
2418
+ *
2419
+ * ## Why the bound is checked before the read finishes
2420
+ *
2421
+ * The body is drained first and measured after, which is the only order the
2422
+ * `Request` API allows: it exposes no streaming reader for a buffered route.
2423
+ * That means the bound cannot prevent the memory a large body costs — it stops
2424
+ * a hostile body from being *parsed* and from reaching any code that assumes a
2425
+ * credential, which is what it is for here. The transport's own request cap is
2426
+ * the memory bound; this one guards the next step.
2427
+ *
2428
+ * ## Why bytes and not `text.length`
2429
+ *
2430
+ * `text.length` counts UTF-16 code units, so a body of three-byte characters
2431
+ * measures a third of its real size and slips under a bound it should not. The
2432
+ * limit is stated in bytes, so it is compared in bytes.
2433
+ *
2434
+ * @param request - the buffered request.
2435
+ * @returns the parsed object.
2436
+ * @throws when the body is too large, is not JSON, or is not an object.
2437
+ */
2417
2438
  async function readJsonBody(request) {
2418
2439
  const text = await request.text();
2419
- if (text.length > MAX_BODY_BYTES) throw new Error("Request body too large.");
2440
+ const bytes = new TextEncoder().encode(text).length;
2441
+ if (bytes > MAX_BODY_BYTES) throw new Error("Request body too large.");
2420
2442
  let parsed;
2421
2443
  try {
2422
2444
  parsed = JSON.parse(text);
@@ -2509,7 +2531,17 @@ function createCredentialRoutes(deps) {
2509
2531
  });
2510
2532
  },
2511
2533
  clear: () => {
2512
- clearCredentials(store);
2534
+ try {
2535
+ clearCredentials(store);
2536
+ } catch (error) {
2537
+ const message = `Could not clear the stored credentials: ${error instanceof Error ? error.message : String(error)}`;
2538
+ recordStatus([{
2539
+ op: "set",
2540
+ path: ["lastError"],
2541
+ value: message
2542
+ }]);
2543
+ return Promise.resolve(jsonError(500, message));
2544
+ }
2513
2545
  recordStatus([
2514
2546
  {
2515
2547
  op: "set",
@@ -2576,6 +2608,37 @@ function apply(ctx, config) {
2576
2608
  ctx.logger.warn(error);
2577
2609
  });
2578
2610
  };
2611
+ /**
2612
+ * Answer one form request, named by the token in the body.
2613
+ *
2614
+ * The cancel and confirm routes differ only in which outcome they record, so
2615
+ * they share this. Both need the same three things, and each is a failure
2616
+ * this has to get right:
2617
+ *
2618
+ * - **The body is read defensively.** A malformed one earns a `400` rather
2619
+ * than an exception, so the browser always receives JSON it can render.
2620
+ * - **The token decides which request is answered.** The browser can
2621
+ * deliver a stale answer after a reconnect, and settling whichever
2622
+ * request happens to be pending would end a form the person is looking
2623
+ * at — or, worse, tell a model the user declined something they did not.
2624
+ * - **An unmatched token is not an error.** The request it named is
2625
+ * already gone; there is nothing to do and the browser needs no message.
2626
+ *
2627
+ * @param kind - the outcome to record against the named request.
2628
+ * @returns the route handler.
2629
+ */
2630
+ const settleByToken = (kind) => async (request) => {
2631
+ let body;
2632
+ try {
2633
+ body = await request.json();
2634
+ } catch {
2635
+ return jsonError(400, "Request body is not valid JSON.");
2636
+ }
2637
+ const token = body?.token;
2638
+ if (typeof token !== "string" || token === "") return jsonError(400, "token is required.");
2639
+ if (pendingForm !== void 0 && pendingForm.request.token === token) settleFormRequest({ kind }, pendingForm);
2640
+ return Response.json({ ok: true });
2641
+ };
2579
2642
  /** Apply one batch of ops to the mirror. */
2580
2643
  const mirrorOps = (ops) => {
2581
2644
  for (const op of ops) if (op.path[0] === "credentialsStored") recordedStored = op.op === "set" && op.value === true;
@@ -2641,47 +2704,13 @@ function apply(ctx, config) {
2641
2704
  path: CANCEL_PATH,
2642
2705
  methods: ["POST"],
2643
2706
  requestBody: "buffered",
2644
- fetch: async (request) => {
2645
- let body;
2646
- try {
2647
- body = await request.json();
2648
- } catch {
2649
- return Response.json({
2650
- ok: false,
2651
- error: "Request body is not valid JSON."
2652
- }, { status: 400 });
2653
- }
2654
- const token = body?.token;
2655
- if (typeof token !== "string" || token === "") return Response.json({
2656
- ok: false,
2657
- error: "token is required."
2658
- }, { status: 400 });
2659
- if (pendingForm !== void 0 && pendingForm.request.token === token) settleFormRequest({ kind: "cancelled" }, pendingForm);
2660
- return Response.json({ ok: true });
2661
- }
2707
+ fetch: settleByToken("cancelled")
2662
2708
  }), "aishell-credentials: cancel route");
2663
2709
  ctx.effect(() => ctx.connection.fetch.register({
2664
2710
  path: CONFIRM_PATH,
2665
2711
  methods: ["POST"],
2666
2712
  requestBody: "buffered",
2667
- fetch: async (request) => {
2668
- let body;
2669
- try {
2670
- body = await request.json();
2671
- } catch {
2672
- return Response.json({
2673
- ok: false,
2674
- error: "Request body is not valid JSON."
2675
- }, { status: 400 });
2676
- }
2677
- const token = body?.token;
2678
- if (typeof token !== "string" || token === "") return Response.json({
2679
- ok: false,
2680
- error: "token is required."
2681
- }, { status: 400 });
2682
- if (pendingForm !== void 0 && pendingForm.request.token === token) settleFormRequest({ kind: "submitted" }, pendingForm);
2683
- return Response.json({ ok: true });
2684
- }
2713
+ fetch: settleByToken("submitted")
2685
2714
  }), "aishell-credentials: confirm route");
2686
2715
  ctx.effect(() => ctx.connection.fetch.register({
2687
2716
  path: PREFILL_PATH,
@@ -15,19 +15,17 @@
15
15
  * `aishell__auth`; `退出` clears the credential.
16
16
  * - **Not signed in** — both ways to obtain a credential, side by side.
17
17
  *
18
- * An earlier version spread this across four pages (`choose` / `manual` /
19
- * `waiting` plus a "deciding" state) and moved between them as the probe
20
- * answered. The pages were the same card wearing different hats — the person
21
- * sees one panel either way — and the transitions were visible: fields appeared
22
- * and were replaced a moment later. One upright card with a button that reports
23
- * its own state is both smaller and calmer.
18
+ * One panel with a button that reports its own state, rather than a page per
19
+ * step. The person sees one card either way, so separate pages would be the
20
+ * same layout repeated — and the transitions between them would be visible:
21
+ * fields appearing and being replaced a moment later as the probe answered.
24
22
  *
25
23
  * ## Why the browser route reports itself in place
26
24
  *
27
25
  * The button is the status: `checking` while the probe runs, `login` once it
28
26
  * passes, `unsupported` when it fails, `cancel` while a login is in flight with
29
- * the countdown beside it. A separate page for "waiting" was a second layout to
30
- * keep in step with the first for no gain.
27
+ * the countdown beside it. A separate "waiting" page would be a second layout
28
+ * to keep in step with this one, for no gain.
31
29
  *
32
30
  * @module @huaweidevtools/aishell-dsh-client-credentials/client/CredentialRequestForm
33
31
  */
@@ -0,0 +1,56 @@
1
+ /**
2
+ * The read-write risk gate, shared by both permission chips.
3
+ *
4
+ * ## Why a flip to read-write asks first
5
+ *
6
+ * The mode is the one setting in this plugin set that changes what the agent may
7
+ * do to a real cloud account. Read-only is enforced by the host gate — mutations
8
+ * are refused there — so leaving it is the moment a mistake stops being
9
+ * recoverable: a destroyed resource usually does not come back, a security-group
10
+ * edit can take a running service off the network, and everything created bills
11
+ * until it is torn down. One click is too cheap an entry to that.
12
+ *
13
+ * The reverse direction does not ask. Read-only gives up access; there is no
14
+ * consequence to warn about, and a dialog there would train people to dismiss
15
+ * the one that matters.
16
+ *
17
+ * ## Why `RiskConfirmation` and not a bespoke dialog
18
+ *
19
+ * It is the framework's own primitive, and it is already the shape the shell
20
+ * uses for the sandbox's "Full access" gate — an acknowledgement checkbox that
21
+ * keeps the primary button dead until it is ticked. Using it here means the two
22
+ * escalations in this product look and behave the same, and it brings the modal
23
+ * layer, focus trap and escape handling with it rather than an approximation of
24
+ * them. It portals to the body, so being mounted inside the chips' `inline-flex`
25
+ * row costs nothing.
26
+ *
27
+ * ## Why the state lives in the hook, not here
28
+ *
29
+ * This renders what `usePermissionMode` holds. Both chips drive the same
30
+ * host-side switch, so a dialog owned per chip would be two independent gates
31
+ * over one value — open both, confirm in one, and the other still offers to
32
+ * enable a mode that is already current. See `permission-mode.ts`.
33
+ *
34
+ * @module @huaweidevtools/aishell-dsh-client-credentials/client/PermissionRiskDialog
35
+ */
36
+ import type { ReactNode } from 'react';
37
+ import type { TranslateNS } from '@deepseek-ai/dsh-client-ui-slots';
38
+ import type { PermissionConfirmation } from './permission-mode.ts';
39
+ /** Props: the gate's state, the two callbacks, and the dictionary. */
40
+ export interface PermissionRiskDialogProps {
41
+ /** The pending confirmation, or `undefined` when none is open. */
42
+ readonly confirmation: PermissionConfirmation | undefined;
43
+ /** Dismiss without flipping. */
44
+ readonly onCancel: () => void;
45
+ /** Apply the flip; the acknowledgement must be ticked. */
46
+ readonly onConfirm: () => void;
47
+ readonly t: TranslateNS<'aishell'>;
48
+ }
49
+ /**
50
+ * Render the gate when a read-write flip is waiting on the person.
51
+ *
52
+ * @param props - see {@link PermissionRiskDialogProps}.
53
+ * @returns the dialog, or `null` when nothing is pending.
54
+ */
55
+ export declare function PermissionRiskDialog(props: PermissionRiskDialogProps): ReactNode;
56
+ //# sourceMappingURL=PermissionRiskDialog.d.ts.map
@@ -8,21 +8,17 @@
8
8
  *
9
9
  * ## One way the form comes up
10
10
  *
11
- * A chip opens it. That is the whole model.
12
- *
13
- * There used to be a second source — the Host publishing which session had a
14
- * tool call blocked on credentials — and this module reconciled the two, with
15
- * rules about which one owned the form and how a takeover republished the
16
- * interaction. That request channel is gone: no tool call blocks on credentials
17
- * any more, so a Host request cannot arrive, and every rule about outranking
18
- * one describes a situation that cannot happen.
19
- *
20
- * The rules that remain are the ones a single door needs:
11
+ * A chip opens it, and that is the whole model. Every rule here exists to serve
12
+ * that single door:
21
13
  *
22
14
  * - An open while the form is already up is a no-op. Publishing a second
23
15
  * interaction would remount the component and discard what was typed.
24
16
  * - A close, or a dispose, withdraws it, and the ordinary composer comes back.
25
17
  *
18
+ * No other producer exists, so no rule is needed for one. A second source would
19
+ * need rules about which owns the form and how a takeover republishes it — and
20
+ * those rules would be describing a situation the system cannot reach.
21
+ *
26
22
  * ## Why a closure and not a class
27
23
  *
28
24
  * Written as a factory because the browser half is compiled by oxc, and a class
@@ -68,8 +64,8 @@ export interface CredentialFormVisibility {
68
64
  * thing (one login at a time, one credential store), so publishing a
69
65
  * second card would give two conversations a live form over one store.
70
66
  * Moving the person to the card they already have is the honest answer,
71
- * and it is also what makes the chip work after a conversation switch:
72
- * refusing used to leave every later click doing nothing until a reload.
67
+ * and it is what keeps the chip alive across a conversation switch: the
68
+ * card is still on screen, just not in the conversation that was clicked.
73
69
  *
74
70
  * @param sessionId - the conversation the person is acting in.
75
71
  */
@@ -5,17 +5,16 @@
5
5
  * presentation: the presence descriptor the Host reports, the verdict its route
6
6
  * answers with, and the link to where a credential comes from.
7
7
  *
8
- * ## Why it exists
8
+ * ## Why it is its own module
9
9
  *
10
- * Four modules need these, and every one of them used to reach into
11
- * `AishellCredentialsSection.tsx` for them — two chips and the composer form
12
- * importing from a component they do not render. That file is gone now (the
13
- * form replaced it), and the shared contract stays here: a module neither the
14
- * form nor the chips owns. Same reasoning as `huawei-mark.ts`: the second
10
+ * Several modules need these — two chips and the form — and none of them owns
11
+ * the other. A shared contract belongs in a file that no consumer is the author
12
+ * of; importing it from one component would make that component's internals a
13
+ * public interface by accident. Same reasoning as `huawei-mark.ts`: the second
15
14
  * consumer is when the shared part earns its own module.
16
15
  *
17
- * The paragraph that follows each is the contract the Host half implements; it
18
- * is stated here because this file is now where both sides read it.
16
+ * The paragraph that follows each declaration is the contract the Host half
17
+ * implements; it is stated here because this file is where both sides read it.
19
18
  *
20
19
  * @module @huaweidevtools/aishell-dsh-client-credentials/client/credential-status
21
20
  */
@@ -34,10 +34,12 @@ export declare const CHIP_CLASS = "aishell-account-hint";
34
34
  * a disposer that removes the tag, and the `data-plugin` markers so
35
35
  * `removeOwnedStyles` can also reach it. The disposer is what makes a reload
36
36
  * pick up an edited rule — the fiber tears down, the tag goes, and the next
37
- * materialization writes the new text. A module-level install with an id guard
38
- * fails exactly there: the tag outlives the module (the loader only sweeps
39
- * `data-plugin` tags), the guard then sees it and returns, and the old CSS
40
- * stays in force for the life of the page.
37
+ * materialization writes the new text.
38
+ *
39
+ * A module-level install guarded by an id cannot do that: the tag outlives the
40
+ * module because the loader sweeps only `data-plugin` tags, so the guard finds
41
+ * it on the next materialization and returns, and the page keeps the rule from
42
+ * before the edit for its whole life.
41
43
  *
42
44
  * Call once from `apply()`, not from the components: the rule is shared by
43
45
  * both chips (they carry the same `CHIP_CLASS`), so one sheet serves them and
@@ -9,10 +9,10 @@
9
9
  * verified account name come back through `ctx.configForms`, which the chips
10
10
  * and the form read.
11
11
  *
12
- * There is no Settings section any more: the form is the one credential
13
- * surface, opened either by a chip click (the visibility state machine's
14
- * manual posture) or by a tool call blocked on credentials (the Host-mirrored
15
- * posture). Both render the same component in `conversation.composer`.
12
+ * The form is the one credential surface, and a chip click is what opens it.
13
+ * It renders in `conversation.composer`, and there is no Settings section
14
+ * beside it: one place to enter a credential means one place to look when none
15
+ * is working.
16
16
  *
17
17
  * @module @huaweidevtools/aishell-dsh-client-credentials/client
18
18
  */
@@ -16,6 +16,12 @@ export declare const zh: {
16
16
  readonly 'mode.unavailable.hint': "无法读取权限模式;切换按钮暂不可用";
17
17
  readonly 'mode.switchToReadonly': "切换为只读模式";
18
18
  readonly 'mode.switchToReadwrite': "切换为读写模式";
19
+ readonly 'mode.confirm.title': "确认切换为读写模式?";
20
+ readonly 'mode.confirm.description': string;
21
+ readonly 'mode.confirm.acknowledge': "我已了解上述影响,并愿意继续";
22
+ readonly 'mode.confirm.cancel': "保持只读";
23
+ readonly 'mode.confirm.enable': "切换为读写";
24
+ readonly 'mode.confirm.close': "关闭";
19
25
  readonly 'section.credentials.hint.prefix': "建议从";
20
26
  readonly 'section.credentials.hint.link': "API Explorer";
21
27
  readonly 'section.credentials.hint.suffix': "获取临时凭据,避免使用永久凭据。";
@@ -66,6 +72,12 @@ export declare const en: {
66
72
  readonly 'mode.unavailable.hint': "Could not read the permission mode; the toggle is unavailable";
67
73
  readonly 'mode.switchToReadonly': "Switch to read-only mode";
68
74
  readonly 'mode.switchToReadwrite': "Switch to read-write mode";
75
+ readonly 'mode.confirm.title': "Switch to read-write?";
76
+ readonly 'mode.confirm.description': string;
77
+ readonly 'mode.confirm.acknowledge': "I understand these impacts and want to continue";
78
+ readonly 'mode.confirm.cancel': "Stay read-only";
79
+ readonly 'mode.confirm.enable': "Switch to read-write";
80
+ readonly 'mode.confirm.close': "Close";
69
81
  readonly 'section.credentials.hint.prefix': "Obtain temporary credentials from";
70
82
  readonly 'section.credentials.hint.link': "API Explorer";
71
83
  readonly 'section.credentials.hint.suffix': "and avoid permanent ones.";
@@ -16,6 +16,40 @@
16
16
  export declare const PERMISSION_ROUTE = "api/aishell/permission";
17
17
  /** The two modes, as the server spells them. */
18
18
  export type PermissionMode = 'read_only' | 'read_write';
19
+ /**
20
+ * What a click on the mode button should do.
21
+ *
22
+ * `'confirm'` — open the risk gate and wait; `'apply'` — flip now; `'none'` —
23
+ * the control is not actionable.
24
+ */
25
+ export type ToggleOutcome = 'confirm' | 'apply' | 'none';
26
+ /**
27
+ * Decide what a click does, from the mode in effect.
28
+ *
29
+ * Exported and pure so the direction that escalates is testable without a DOM
30
+ * renderer — see `tests/permission-gate.spec.ts`. The asymmetry is the whole
31
+ * point: read-write widens what the agent may do to a real account, so it asks
32
+ * first; read-only narrows it, so it does not.
33
+ *
34
+ * An unknown mode is `'none'` rather than `'confirm'`: it is not read-only, and
35
+ * offering the escalation gate against a session that may already be in
36
+ * read-write would ask the person to approve a mode they are already in.
37
+ *
38
+ * @param mode - the mode in effect, or `undefined` before one is read.
39
+ * @returns what the click should do.
40
+ */
41
+ export declare function toggleOutcome(mode: PermissionMode | undefined): ToggleOutcome;
42
+ /**
43
+ * Whether the gate's confirm button may write.
44
+ *
45
+ * One condition, named rather than inlined, because the chips and the hook must
46
+ * agree on it — a chip that enabled the button on a different condition would
47
+ * let an unacknowledged flip through.
48
+ *
49
+ * @param acknowledged - the acknowledgement box's state.
50
+ * @returns whether the read-write flip may run.
51
+ */
52
+ export declare function mayApply(acknowledged: boolean): boolean;
19
53
  /**
20
54
  * Read the current mode from the Host route.
21
55
  *
@@ -37,8 +71,37 @@ export interface PermissionModeControl {
37
71
  readonly mode: PermissionMode | undefined;
38
72
  /** True while a write is in flight. */
39
73
  readonly busy: boolean;
40
- /** Flip to the other mode. No-op while unknown or busy. */
74
+ /**
75
+ * Handle one click on the mode button.
76
+ *
77
+ * A flip **to read-write** is the one that changes what the agent may do to a
78
+ * real cloud account, so this asks for confirmation first and only writes
79
+ * once the person acknowledges. A flip back to read-only gives up access,
80
+ * which needs no warning, so it applies immediately.
81
+ *
82
+ * No-op while unknown or busy.
83
+ */
41
84
  readonly toggle: () => void;
85
+ /**
86
+ * The risk confirmation's state, or `undefined` when it is closed.
87
+ *
88
+ * Present only while a read-write flip is waiting on the person. It belongs
89
+ * with the mode state rather than beside the button because opening the gate
90
+ * and later writing the mode are one gesture split across a dialog: the chip
91
+ * that asked has to still be the one that writes when the person confirms.
92
+ */
93
+ readonly confirmation: PermissionConfirmation | undefined;
94
+ /** Dismiss the confirmation without flipping. */
95
+ readonly cancelConfirmation: () => void;
96
+ /** Apply the awaited read-write flip; the confirmation must be open. */
97
+ readonly confirmToggle: () => void;
98
+ }
99
+ /** The gate shown before a flip to read-write. */
100
+ export interface PermissionConfirmation {
101
+ /** Whether the acknowledgement box is ticked; the confirm button is dead until it is. */
102
+ readonly acknowledged: boolean;
103
+ /** Tick or untick the acknowledgement box. */
104
+ readonly setAcknowledged: (acknowledged: boolean) => void;
42
105
  }
43
106
  /**
44
107
  * Subscribe a control to the permission mode.
@@ -47,7 +110,29 @@ export interface PermissionModeControl {
47
110
  * there is no poll — a second surface flipping it is not a case this handles;
48
111
  * each surface re-reads on its own mount.
49
112
  *
50
- * @returns the current mode, a busy flag, and the toggle.
113
+ * ## Why the confirmation lives here rather than in a chip
114
+ *
115
+ * Each chip calls this hook for itself, so nothing here is shared React state;
116
+ * what decided the placement is the shape of the interaction, not the count of
117
+ * callers. A flip and its confirmation are one gesture split across a dialog,
118
+ * and the fact that has to survive the split is "a read-write write is awaiting
119
+ * acknowledgement". Kept in a chip, that fact dies with a remount — and the
120
+ * chips do remount: the hero chip stops rendering the moment the first turn is
121
+ * accepted, so a confirmation opened on a blank session would lose its
122
+ * acknowledgement the instant the session existed.
123
+ *
124
+ * Holding it with the mode also keeps the write in one place: `confirmToggle`
125
+ * closes the gate and calls the same `apply` that `toggle` uses, so a confirmed
126
+ * flip and an immediate one cannot diverge in how they report the server's
127
+ * answer.
128
+ *
129
+ * Two mounts do not run concurrently today — the hero chip gates on
130
+ * `session.blank` and the composer chip needs a session — so this is not two
131
+ * dialogs racing over one value. It is one hook whose surface can be swapped
132
+ * under it.
133
+ *
134
+ * @returns the current mode, a busy flag, the gated toggle, and the
135
+ * confirmation state for a pending read-write flip.
51
136
  */
52
137
  export declare function usePermissionMode(): PermissionModeControl;
53
138
  //# sourceMappingURL=permission-mode.d.ts.map
@@ -12,18 +12,18 @@
12
12
  * person there, wait for the cloud to post a credential back. That is
13
13
  * {@link startBrowserLogin}, and it binds **its own** port.
14
14
  *
15
- * These were one function, and it was wrong in two ways that only show up when
16
- * a person takes their time:
17
- *
18
- * - **The port was held from the moment the card opened.** The probe binds a
19
- * socket to answer its question and now releases it immediately; keeping it
20
- * until someone clicked meant anyone who read the card and walked away held
21
- * a port for as long as the page lived.
22
- * - **The login window started before the person did.** The `login_url` names
23
- * the port it was projected for and the service states how long it stays
24
- * valid. Both were fixed at probe time, so a card left open for a while
25
- * offered a URL that had already expired — and a countdown ran down on a
26
- * sign-in nobody had begun.
15
+ * These are two operations rather than one, and merging them breaks in two
16
+ * ways that only show up when a person takes their time:
17
+ *
18
+ * - **A shared port would be held from the moment the card opened.** The
19
+ * probe binds a socket to answer its question and releases it immediately;
20
+ * a port kept until someone clicked would be held for as long as the page
21
+ * lived, by anyone who merely read the card.
22
+ * - **A login window would start before the person did.** The `login_url`
23
+ * names the port it was projected for and the service states how long it
24
+ * stays valid. Fixed at probe time, a card left open for a while would
25
+ * offer a URL that had already expired — and a countdown would run down on
26
+ * a sign-in nobody had begun.
27
27
  *
28
28
  * So each operation binds what it needs and releases it when its own job ends.
29
29
  * The probe's port is closed as soon as the browser has answered; the login's
@@ -1,19 +1,22 @@
1
1
  /**
2
2
  * Idempotent credential-status reconcile.
3
3
  *
4
- * The replacement for the old one-shot boot check in `apply()`. That check was
5
- * an else-if chain: the "set `credentialsStored`" branch and the "verify and
6
- * record the account name" branch were mutually exclusive, so on the boot where
7
- * `credentialsStored` flipped to true the hint branch was unreachable — the
8
- * account chips kept showing "unconfigured" until a second restart. Nothing
9
- * ever re-read the store after boot either, so credentials written after boot
10
- * (the env's `sync-hw-creds` writes them every minute) stayed invisible to the
11
- * UI. Independent branches fix the former; the caller's timer and GET-route
12
- * hook fix the latter.
4
+ * Derives `credentialsStored` and `accessKeyIdHint` from the store, and records
5
+ * only what changed. The two derivations are independent on purpose: a boot
6
+ * where the presence flag flips to true must still reach the branch that
7
+ * verifies and records the account name, or the chips show "unconfigured" until
8
+ * something else triggers a restart.
13
9
  *
14
- * Kept as a factory — not inlined in `apply()` — so the whole decision table
15
- * is drivable from a spec with a `MemoryBackend` and a fake verifier, never a
16
- * real keyring or IAM call (see `docs/memory.md` §15).
10
+ * Nothing re-reads the store on its own, so a credential written while the
11
+ * process is running — the environment's `sync-hw-creds` writes them every
12
+ * minute — would stay invisible to the UI. The caller's timer and the GET
13
+ * route's hook provide those re-reads; this module only has to be safe to call
14
+ * repeatedly, which it is: at steady state it records nothing and verifies
15
+ * nothing.
16
+ *
17
+ * Kept as a factory — not inlined in `apply()` — so the whole decision table is
18
+ * drivable from a spec with a `MemoryBackend` and a fake verifier, never a real
19
+ * keyring or IAM call.
17
20
  *
18
21
  * @module @huaweidevtools/aishell-dsh-client-credentials/reconcile
19
22
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@huaweidevtools/aishell-dsh-client-credentials",
3
3
  "description": "AI Shell credentials — chip-opened web form for storing Huawei Cloud AK/SK in the credential store",
4
- "version": "0.0.14",
4
+ "version": "0.0.16",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "license": "Apache-2.0",
44
44
  "dependencies": {
45
- "@huaweidevtools/aishell-dsh-credentials-store": "0.0.14"
45
+ "@huaweidevtools/aishell-dsh-credentials-store": "0.0.16"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "@deepseek-ai/cordis": "^4.0.4",
@@ -57,6 +57,7 @@
57
57
  "@deepseek-ai/dsh-client-locale": "0.2.0-rc.1 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5",
58
58
  "@deepseek-ai/dsh-client-store": "0.2.0-rc.1 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5",
59
59
  "@deepseek-ai/dsh-client-ui-conversation": "0.2.0-rc.1 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5",
60
+ "@deepseek-ai/dsh-client-ui-primitives": "0.2.0-rc.1 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5",
60
61
  "@deepseek-ai/dsh-client-ui-renderer": "0.2.0-rc.1 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5",
61
62
  "@deepseek-ai/dsh-client-ui-session": "0.2.0-rc.1 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5",
62
63
  "@deepseek-ai/dsh-client-ui-settings": "0.2.0-rc.1 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.4 || 0.2.1-rc.5",