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

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. */
@@ -199,7 +311,7 @@ function AishellAccountHint(props) {
199
311
  const configured = Boolean(hint);
200
312
  const t = props.t;
201
313
  const openCredentialForm = props.openCredentialForm;
202
- const { mode, busy, toggle } = usePermissionMode();
314
+ const { mode, busy, toggle, confirmation, cancelConfirmation, confirmToggle } = usePermissionMode();
203
315
  const ref = (0, react.useRef)(null);
204
316
  (0, react.useEffect)(() => {
205
317
  const host = ref.current?.parentElement;
@@ -242,54 +354,63 @@ function AishellAccountHint(props) {
242
354
  marginLeft: "auto",
243
355
  flex: "none"
244
356
  },
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", {
357
+ children: [
358
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
359
+ type: "button",
360
+ className: CHIP_CLASS,
361
+ "aria-label": configured ? hint : t("account.unconfigured"),
362
+ onClick: openCredentialForm,
270
363
  style: {
364
+ ...pillStyle,
365
+ color: configured ? "var(--dsw-alias-label-tertiary)" : "var(--dsw-alias-state-warn-label)",
366
+ maxWidth: "100%",
271
367
  overflow: "hidden",
272
368
  textOverflow: "ellipsis"
273
369
  },
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
- })]
370
+ title: configured ? hint : t("account.unconfigured"),
371
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
372
+ "aria-hidden": true,
373
+ width: "14",
374
+ height: "14",
375
+ viewBox: "0 0 24 24",
376
+ fill: "currentColor",
377
+ style: {
378
+ color: configured ? HUAWEI_RED : "var(--dsw-alias-state-warn-label)",
379
+ flex: "none"
380
+ },
381
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: HUAWEI_LOGO_PATH })
382
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
383
+ style: {
384
+ overflow: "hidden",
385
+ textOverflow: "ellipsis"
386
+ },
387
+ children: configured ? hint : t("account.unconfigured")
388
+ })]
389
+ }),
390
+ configured && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
391
+ type: "button",
392
+ className: CHIP_CLASS,
393
+ onClick: () => {
394
+ toggle();
395
+ },
396
+ disabled: mode === void 0 || busy,
397
+ "aria-label": mode === "read_write" ? t("mode.switchToReadonly") : t("mode.switchToReadwrite"),
398
+ style: {
399
+ ...pillStyle,
400
+ color: mode === void 0 ? "var(--dsw-alias-label-tertiary)" : mode === "read_only" ? "var(--dsw-alias-state-success-primary)" : "var(--dsw-alias-state-warn-label)",
401
+ opacity: mode === void 0 || busy ? .6 : 1,
402
+ cursor: mode === void 0 || busy ? "default" : "pointer"
403
+ },
404
+ title: mode === void 0 ? t("mode.unavailable.hint") : mode === "read_only" ? t("mode.readonly.hint") : t("mode.readwrite.hint"),
405
+ children: mode === void 0 ? t("mode.unavailable") : mode === "read_only" ? t("mode.readonly") : t("mode.readwrite")
406
+ }),
407
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PermissionRiskDialog, {
408
+ confirmation,
409
+ onCancel: cancelConfirmation,
410
+ onConfirm: confirmToggle,
411
+ t
412
+ })
413
+ ]
293
414
  });
294
415
  }
295
416
 
@@ -298,7 +419,7 @@ function AishellAccountHint(props) {
298
419
  function AishellHeroChip(props) {
299
420
  const blank = props.useSession((session) => session.blank);
300
421
  const status = props.useCredentials((snapshot) => snapshot);
301
- const { mode, busy, toggle } = usePermissionMode();
422
+ const { mode, busy, toggle, confirmation, cancelConfirmation, confirmToggle } = usePermissionMode();
302
423
  const t = props.t;
303
424
  const openCredentialForm = props.openCredentialForm;
304
425
  const configured = Boolean(status.accessKeyIdHint);
@@ -390,53 +511,62 @@ function AishellHeroChip(props) {
390
511
  marginLeft: presetOffset ?? 0,
391
512
  flex: "none"
392
513
  },
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", {
514
+ children: [
515
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
516
+ type: "button",
517
+ className: CHIP_CLASS,
518
+ "aria-label": configured ? status.accessKeyIdHint : t("account.unconfigured"),
519
+ onClick: openCredentialForm,
418
520
  style: {
521
+ ...pillStyle,
522
+ color: configured ? "var(--dsw-alias-label-tertiary)" : "var(--dsw-alias-state-warn-label)",
523
+ maxWidth: 220,
419
524
  overflow: "hidden",
420
525
  textOverflow: "ellipsis"
421
526
  },
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
- })]
527
+ title: configured ? status.accessKeyIdHint : t("account.unconfigured"),
528
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
529
+ "aria-hidden": true,
530
+ width: "14",
531
+ height: "14",
532
+ viewBox: "0 0 24 24",
533
+ fill: "currentColor",
534
+ style: {
535
+ color: configured ? HUAWEI_RED : "var(--dsw-alias-state-warn-label)",
536
+ flex: "none"
537
+ },
538
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: HUAWEI_LOGO_PATH })
539
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
540
+ style: {
541
+ overflow: "hidden",
542
+ textOverflow: "ellipsis"
543
+ },
544
+ children: configured ? status.accessKeyIdHint : t("account.unconfigured")
545
+ })]
546
+ }),
547
+ configured && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
548
+ type: "button",
549
+ onClick: () => {
550
+ toggle();
551
+ },
552
+ disabled: mode === void 0 || busy,
553
+ "aria-label": mode === "read_write" ? t("mode.switchToReadonly") : t("mode.switchToReadwrite"),
554
+ title: mode === void 0 ? t("mode.unavailable.hint") : mode === "read_only" ? t("mode.readonly.hint") : t("mode.readwrite.hint"),
555
+ style: {
556
+ ...pillStyle,
557
+ color: mode === void 0 ? "var(--dsw-alias-label-tertiary)" : mode === "read_only" ? "var(--dsw-alias-state-success-primary)" : "var(--dsw-alias-state-warn-label)",
558
+ opacity: mode === void 0 || busy ? .6 : 1,
559
+ cursor: mode === void 0 || busy ? "default" : "pointer"
560
+ },
561
+ children: mode === void 0 ? t("mode.unavailable") : mode === "read_only" ? t("mode.readonly") : t("mode.readwrite")
562
+ }),
563
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PermissionRiskDialog, {
564
+ confirmation,
565
+ onCancel: cancelConfirmation,
566
+ onConfirm: confirmToggle,
567
+ t
568
+ })
569
+ ]
440
570
  });
441
571
  }
442
572
 
@@ -1623,6 +1753,12 @@ const zh = {
1623
1753
  "mode.unavailable.hint": "无法读取权限模式;切换按钮暂不可用",
1624
1754
  "mode.switchToReadonly": "切换为只读模式",
1625
1755
  "mode.switchToReadwrite": "切换为读写模式",
1756
+ "mode.confirm.title": "确认切换为读写模式?",
1757
+ "mode.confirm.description": "切换为读写后,智能体可以直接变更你的华为云账号,包括:创建、修改和删除云资源;变更安全组、网络与权限配置,可能导致服务中断;按实际用量产生费用,资源在销毁前会持续计费;被删除的资源通常无法恢复。",
1758
+ "mode.confirm.acknowledge": "我已了解上述影响,并愿意继续",
1759
+ "mode.confirm.cancel": "保持只读",
1760
+ "mode.confirm.enable": "切换为读写",
1761
+ "mode.confirm.close": "关闭",
1626
1762
  "section.credentials.hint.prefix": "建议从",
1627
1763
  "section.credentials.hint.link": "API Explorer",
1628
1764
  "section.credentials.hint.suffix": "获取临时凭据,避免使用永久凭据。",
@@ -1673,6 +1809,12 @@ const en = {
1673
1809
  "mode.unavailable.hint": "Could not read the permission mode; the toggle is unavailable",
1674
1810
  "mode.switchToReadonly": "Switch to read-only mode",
1675
1811
  "mode.switchToReadwrite": "Switch to read-write mode",
1812
+ "mode.confirm.title": "Switch to read-write?",
1813
+ "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. ",
1814
+ "mode.confirm.acknowledge": "I understand these impacts and want to continue",
1815
+ "mode.confirm.cancel": "Stay read-only",
1816
+ "mode.confirm.enable": "Switch to read-write",
1817
+ "mode.confirm.close": "Close",
1676
1818
  "section.credentials.hint.prefix": "Obtain temporary credentials from",
1677
1819
  "section.credentials.hint.link": "API Explorer",
1678
1820
  "section.credentials.hint.suffix": "and avoid permanent ones.",
@@ -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
@@ -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
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.15",
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.15"
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",