@huaweidevtools/aishell-dsh-client-credentials 0.0.0-stage → 0.0.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js ADDED
@@ -0,0 +1,1308 @@
1
+ window.__ModuleLoader__.load({ id: "@huaweidevtools/aishell-dsh-client-credentials", factory: (require) => {
2
+ "use strict";
3
+ var module = { exports: {} }; var exports = module.exports;
4
+ //#region rolldown:runtime
5
+ var __create = Object.create;
6
+ var __defProp = Object.defineProperty;
7
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
8
+ var __getOwnPropNames = Object.getOwnPropertyNames;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
13
+ key = keys[i];
14
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
+ get: ((k) => from[k]).bind(null, key),
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
22
+ value: mod,
23
+ enumerable: true
24
+ }) : target, mod));
25
+
26
+ //#endregion
27
+ const __deepseek_ai_dsh_client_store = __toESM(require("@deepseek-ai/dsh-client-store"));
28
+ const react = __toESM(require("react"));
29
+ const react_jsx_runtime = __toESM(require("react/jsx-runtime"));
30
+
31
+ //#region src/client/credential-status.ts
32
+ /**
33
+ * Where a user obtains credentials.
34
+ *
35
+ * API Explorer's page for `CreateTemporaryAccessKeyByToken` — the operation
36
+ * that mints a temporary AK/SK/security-token triple from an IAM token. Linked
37
+ * from both forms because the alternative, a permanent access key created in
38
+ * "My Credentials", has no expiry and cannot be scoped down; steering users to
39
+ * the temporary kind is the point of showing this at all.
40
+ *
41
+ * Not fetched or validated at build time: it is a console URL whose content
42
+ * changes independently of this plugin, and a stale check would be worse than
43
+ * none.
44
+ */
45
+ const CREDENTIAL_URL = "https://console.huaweicloud.com/apiexplorer/#/openapi/IAM/doc?version=v3&api=CreateTemporaryAccessKeyByToken";
46
+
47
+ //#endregion
48
+ //#region src/client/AishellCredentialsSection.tsx
49
+ /**
50
+ * Status dot for one field label.
51
+ *
52
+ * Filled and green when the field is stored, hollow and muted when it is not.
53
+ * The glyph carries the state as well as the colour, so it survives a
54
+ * colour-blind reader and a screenshot.
55
+ */
56
+ function StatusDot({ present }) {
57
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
58
+ "aria-hidden": true,
59
+ style: {
60
+ color: present ? "var(--dsw-alias-state-success-primary)" : "var(--dsw-alias-label-quaternary)",
61
+ flex: "none"
62
+ },
63
+ children: present ? "●" : "○"
64
+ });
65
+ }
66
+ /** Render the credentials form. */
67
+ function AishellCredentialsSection(props) {
68
+ const { save, clear } = props;
69
+ const status = props.useCredentials((snapshot) => snapshot);
70
+ const t = props.t;
71
+ const [ak, setAk] = (0, react.useState)("");
72
+ const [sk, setSk] = (0, react.useState)("");
73
+ const [token, setToken] = (0, react.useState)("");
74
+ const [saving, setSaving] = (0, react.useState)(false);
75
+ const [error, setError] = (0, react.useState)(void 0);
76
+ const [saved, setSaved] = (0, react.useState)(false);
77
+ const onSubmit = async (e) => {
78
+ e.preventDefault();
79
+ if (!ak || !sk) {
80
+ setError("Access Key and Secret Key are required");
81
+ return;
82
+ }
83
+ setSaving(true);
84
+ setError(void 0);
85
+ setSaved(false);
86
+ try {
87
+ const verdict = await save(ak, sk, token || void 0);
88
+ if (verdict.ok) {
89
+ setAk("");
90
+ setSk("");
91
+ setToken("");
92
+ setSaved(true);
93
+ } else setError(verdict.error ?? "凭据保存失败");
94
+ } catch (err) {
95
+ setError(err instanceof Error ? err.message : String(err));
96
+ } finally {
97
+ setSaving(false);
98
+ }
99
+ };
100
+ const onClear = async () => {
101
+ setSaving(true);
102
+ setError(void 0);
103
+ try {
104
+ const verdict = await clear();
105
+ if (!verdict.ok) setError(verdict.error ?? "清除凭据失败");
106
+ else setSaved(false);
107
+ } catch (err) {
108
+ setError(err instanceof Error ? err.message : String(err));
109
+ } finally {
110
+ setSaving(false);
111
+ }
112
+ };
113
+ const inputStyle = {
114
+ boxSizing: "border-box",
115
+ width: "100%",
116
+ height: 32,
117
+ padding: "0 10px",
118
+ border: "0.5px solid var(--dsw-alias-border-l4)",
119
+ borderRadius: 8,
120
+ font: "inherit",
121
+ fontSize: 14,
122
+ lineHeight: "22px",
123
+ background: "var(--dsw-alias-bg-layer-1)",
124
+ color: "var(--dsw-alias-label-primary)"
125
+ };
126
+ const labelStyle = {
127
+ display: "inline-flex",
128
+ alignItems: "center",
129
+ gap: 10,
130
+ fontSize: 12,
131
+ lineHeight: "18px",
132
+ fontWeight: 500,
133
+ color: "var(--dsw-alias-label-secondary)"
134
+ };
135
+ const fieldStyle = {
136
+ display: "flex",
137
+ flexDirection: "column",
138
+ gap: 6
139
+ };
140
+ const hintStyle = {
141
+ fontSize: 11,
142
+ lineHeight: "16px",
143
+ color: "var(--dsw-alias-label-quaternary)"
144
+ };
145
+ const primaryButtonStyle = {
146
+ background: "var(--dsw-alias-button-primary-fill)",
147
+ color: "var(--dsw-alias-label-primary-foreground)",
148
+ border: "none",
149
+ borderRadius: 8,
150
+ padding: "6px 16px",
151
+ fontSize: 14,
152
+ cursor: "pointer"
153
+ };
154
+ const secondaryButtonStyle = {
155
+ border: "0.5px solid var(--dsw-alias-border-l3)",
156
+ background: "transparent",
157
+ color: "var(--dsw-alias-label-primary)",
158
+ borderRadius: 8,
159
+ padding: "6px 16px",
160
+ fontSize: 14,
161
+ cursor: "pointer"
162
+ };
163
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
164
+ style: {
165
+ display: "flex",
166
+ flexDirection: "column",
167
+ gap: 12,
168
+ maxWidth: 720,
169
+ color: "var(--dsw-alias-label-primary)"
170
+ },
171
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
172
+ style: {
173
+ margin: "0 0 4px",
174
+ fontSize: 16,
175
+ lineHeight: "24px",
176
+ fontWeight: 500,
177
+ color: "var(--dsw-alias-label-primary)"
178
+ },
179
+ children: "AI Shell"
180
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
181
+ style: {
182
+ margin: 0,
183
+ fontSize: 14,
184
+ lineHeight: "22px",
185
+ color: "var(--dsw-alias-label-tertiary)"
186
+ },
187
+ children: t("section.settings.summary")
188
+ })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
189
+ style: {
190
+ display: "flex",
191
+ flexDirection: "column",
192
+ gap: 12,
193
+ borderTop: "0.5px solid var(--dsw-alias-border-l4)",
194
+ paddingTop: 12
195
+ },
196
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
197
+ style: {
198
+ margin: "0 0 4px",
199
+ fontSize: 14,
200
+ lineHeight: "20px",
201
+ fontWeight: 500,
202
+ color: "var(--dsw-alias-label-secondary)"
203
+ },
204
+ children: t("section.credentials.title")
205
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
206
+ style: {
207
+ margin: 0,
208
+ fontSize: 12,
209
+ lineHeight: "18px",
210
+ color: "var(--dsw-alias-label-tertiary)"
211
+ },
212
+ children: [
213
+ t("section.credentials.hint.prefix"),
214
+ " ",
215
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
216
+ href: CREDENTIAL_URL,
217
+ target: "_blank",
218
+ rel: "noreferrer noopener",
219
+ style: {
220
+ color: "var(--dsw-alias-button-primary-fill)",
221
+ textDecoration: "underline"
222
+ },
223
+ children: t("section.credentials.hint.link")
224
+ }),
225
+ " ",
226
+ t("section.credentials.hint.suffix")
227
+ ]
228
+ })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("form", {
229
+ onSubmit,
230
+ style: {
231
+ display: "flex",
232
+ flexDirection: "column",
233
+ gap: 12
234
+ },
235
+ children: [
236
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
237
+ style: fieldStyle,
238
+ children: [
239
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
240
+ style: labelStyle,
241
+ children: [
242
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StatusDot, { present: status.hasAccessKey }),
243
+ t("section.field.accessKey"),
244
+ status.accessKeyIdHint && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
245
+ style: {
246
+ color: "var(--dsw-alias-label-tertiary)",
247
+ fontWeight: 400
248
+ },
249
+ children: [
250
+ "(",
251
+ status.accessKeyIdHint,
252
+ ")"
253
+ ]
254
+ })
255
+ ]
256
+ }),
257
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
258
+ type: "password",
259
+ value: ak,
260
+ onChange: (e) => setAk(e.target.value),
261
+ style: inputStyle,
262
+ placeholder: t("section.field.accessKey.placeholder"),
263
+ "aria-label": t("section.field.accessKey"),
264
+ autoComplete: "off"
265
+ }),
266
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
267
+ style: hintStyle,
268
+ children: t("section.field.accessKey.hint")
269
+ })
270
+ ]
271
+ }),
272
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
273
+ style: fieldStyle,
274
+ children: [
275
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
276
+ style: labelStyle,
277
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(StatusDot, { present: status.hasSecretKey }), t("section.field.secretKey")]
278
+ }),
279
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
280
+ type: "password",
281
+ value: sk,
282
+ onChange: (e) => setSk(e.target.value),
283
+ style: inputStyle,
284
+ placeholder: t("section.field.secretKey.placeholder"),
285
+ "aria-label": t("section.field.secretKey"),
286
+ autoComplete: "off"
287
+ }),
288
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
289
+ style: hintStyle,
290
+ children: t("section.field.secretKey.hint")
291
+ })
292
+ ]
293
+ }),
294
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
295
+ style: fieldStyle,
296
+ children: [
297
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
298
+ style: labelStyle,
299
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(StatusDot, { present: status.hasSecurityToken }), t("section.field.token")]
300
+ }),
301
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
302
+ type: "password",
303
+ value: token,
304
+ onChange: (e) => setToken(e.target.value),
305
+ style: inputStyle,
306
+ placeholder: t("section.field.token.placeholder"),
307
+ "aria-label": t("section.field.token"),
308
+ autoComplete: "off"
309
+ }),
310
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
311
+ style: hintStyle,
312
+ children: t("section.field.token.hint")
313
+ })
314
+ ]
315
+ }),
316
+ error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
317
+ style: {
318
+ margin: 0,
319
+ fontSize: 12,
320
+ lineHeight: "18px",
321
+ color: "var(--dsw-alias-state-warn-label)"
322
+ },
323
+ children: error
324
+ }),
325
+ saved && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
326
+ style: {
327
+ margin: 0,
328
+ fontSize: 12,
329
+ lineHeight: "18px",
330
+ color: "var(--dsw-alias-state-success-primary)"
331
+ },
332
+ children: t("section.credentials.saved")
333
+ }),
334
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
335
+ style: {
336
+ display: "flex",
337
+ gap: 8
338
+ },
339
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
340
+ type: "submit",
341
+ disabled: saving || !ak || !sk,
342
+ style: {
343
+ ...primaryButtonStyle,
344
+ opacity: saving || !ak || !sk ? .5 : 1,
345
+ cursor: saving || !ak || !sk ? "default" : "pointer"
346
+ },
347
+ children: saving ? t("section.credentials.saving") : t("section.credentials.save")
348
+ }), (status.hasAccessKey || status.hasSecretKey) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
349
+ type: "button",
350
+ onClick: onClear,
351
+ disabled: saving,
352
+ style: {
353
+ ...secondaryButtonStyle,
354
+ opacity: saving ? .5 : 1,
355
+ cursor: saving ? "default" : "pointer"
356
+ },
357
+ children: t("section.credentials.clear")
358
+ })]
359
+ })
360
+ ]
361
+ })]
362
+ })]
363
+ });
364
+ }
365
+
366
+ //#endregion
367
+ //#region src/client/permission-mode.ts
368
+ /**
369
+ * Host permission route, written document-relative for the same reason as the
370
+ * credential route: the served index carries `<base href="./">`, so the
371
+ * request lands on the origin that holds the browser session cookie the
372
+ * route's authentication fence requires.
373
+ */
374
+ const PERMISSION_ROUTE = "api/aishell/permission";
375
+ /** Narrow an unknown value to a mode. */
376
+ function asMode(value) {
377
+ return value === "read_only" || value === "read_write" ? value : void 0;
378
+ }
379
+ /**
380
+ * Read the current mode from the Host route.
381
+ *
382
+ * @returns the mode, or `undefined` when it could not be read — a broken link
383
+ * must not be rendered as a working lock, so an unreadable mode is
384
+ * reported as unknown, never as `read_only`.
385
+ */
386
+ async function readPermissionMode() {
387
+ try {
388
+ const response = await fetch(PERMISSION_ROUTE);
389
+ const body = await response.json();
390
+ if (body.ok !== true) return void 0;
391
+ return asMode(body.mode);
392
+ } catch {
393
+ return void 0;
394
+ }
395
+ }
396
+ /**
397
+ * Write the mode through the Host route.
398
+ *
399
+ * @param mode - the mode to apply.
400
+ * @returns the mode the server reports afterwards, or `undefined` on failure.
401
+ */
402
+ async function writePermissionMode(mode) {
403
+ try {
404
+ const response = await fetch(PERMISSION_ROUTE, {
405
+ method: "POST",
406
+ headers: { "content-type": "application/json" },
407
+ body: JSON.stringify({ mode })
408
+ });
409
+ const body = await response.json();
410
+ if (body.ok !== true) return void 0;
411
+ return asMode(body.mode);
412
+ } catch {
413
+ return void 0;
414
+ }
415
+ }
416
+ /**
417
+ * Subscribe a control to the permission mode.
418
+ *
419
+ * Reads once on mount. The mode is server state that only a person changes, so
420
+ * there is no poll — a second surface flipping it is not a case this handles;
421
+ * each surface re-reads on its own mount.
422
+ *
423
+ * @returns the current mode, a busy flag, and the toggle.
424
+ */
425
+ function usePermissionMode() {
426
+ const [mode, setMode] = (0, react.useState)(void 0);
427
+ const [busy, setBusy] = (0, react.useState)(false);
428
+ (0, react.useEffect)(() => {
429
+ let live = true;
430
+ (async () => {
431
+ const read = await readPermissionMode();
432
+ if (live && read !== void 0) setMode(read);
433
+ })();
434
+ return () => {
435
+ live = false;
436
+ };
437
+ }, []);
438
+ const toggle = () => {
439
+ if (mode === void 0 || busy) return;
440
+ const next = mode === "read_only" ? "read_write" : "read_only";
441
+ setBusy(true);
442
+ (async () => {
443
+ const applied = await writePermissionMode(next);
444
+ if (applied !== void 0) setMode(applied);
445
+ setBusy(false);
446
+ })();
447
+ };
448
+ return {
449
+ mode,
450
+ busy,
451
+ toggle
452
+ };
453
+ }
454
+
455
+ //#endregion
456
+ //#region src/client/huawei-mark.ts
457
+ /**
458
+ * The Huawei mark and its brand colour, shared by both credential chips.
459
+ *
460
+ * Extracted so the composer chip and the hero chip cannot drift apart: they
461
+ * report the same thing, and a colour or path change in one must not leave the
462
+ * other behind.
463
+ *
464
+ * @module @huaweidevtools/aishell-dsh-client-credentials/client/huawei-mark
465
+ */
466
+ /** Huawei logo path (from simple-icons/huawei), drawn in a 24×24 viewBox. */
467
+ const HUAWEI_LOGO_PATH = "M3.67 6.14S1.82 7.91 1.72 9.78v.35c.08 1.51 1.22 2.4 1.22 2.4 1.83 1.79 6.26 4.04 7.3 4.55 0 0 .06.03.1-.01l.02-.04v-.04C7.52 10.8 3.67 6.14 3.67 6.14zM9.65 18.6c-.02-.08-.1-.08-.1-.08l-7.38.26c.8 1.43 2.15 2.53 3.56 2.2.96-.25 3.16-1.78 3.88-2.3.06-.05.04-.09.04-.09zm.08-.78C6.49 15.63.21 12.28.21 12.28c-.15.46-.2.9-.21 1.3v.07c0 1.07.4 1.82.4 1.82.8 1.69 2.34 2.2 2.34 2.2.7.3 1.4.31 1.4.31.12.02 4.4 0 5.54 0 .05 0 .08-.05.08-.05v-.06c0-.03-.03-.05-.03-.05zM9.06 3.19a3.42 3.42 0 00-2.57 3.15v.41c.03.6.16 1.05.16 1.05.66 2.9 3.86 7.65 4.55 8.65.05.05.1.03.1.03a.1.1 0 00.06-.1c1.06-10.6-1.11-13.42-1.11-13.42-.32.02-1.19.23-1.19.23zm8.299 2.27s-.49-1.8-2.44-2.28c0 0-.57-.14-1.17-.22 0 0-2.18 2.81-1.12 13.43.01.07.06.08.06.08.07.03.1-.03.1-.03.72-1.03 3.9-5.76 4.55-8.64 0 0 .36-1.4.02-2.34zm-2.92 13.07s-.07 0-.09.05c0 0-.01.07.03.1.7.51 2.85 2 3.88 2.3 0 0 .16.05.43.06h.14c.69-.02 1.9-.37 3-2.26l-7.4-.25zm7.83-8.41c.14-2.06-1.94-3.97-1.94-3.98 0 0-3.85 4.66-6.67 10.8 0 0-.03.08.02.13l.04.01h.06c1.06-.53 5.46-2.77 7.28-4.54 0 0 1.15-.93 1.21-2.42zm1.52 2.14s-6.28 3.37-9.52 5.55c0 0-.05.04-.03.11 0 0 .03.06.07.06 1.16 0 5.56 0 5.67-.02 0 0 .57-.02 1.27-.29 0 0 1.56-.5 2.37-2.27 0 0 .73-1.45.17-3.14z";
468
+ /**
469
+ * Huawei brand red, rgb(207, 10, 44).
470
+ *
471
+ * A literal rather than a theme token: the theme's alias set carries no brand
472
+ * or danger colour (checked — no `danger`/`error`/`critical` alias exists), so
473
+ * there is nothing to reference and the value does not follow light/dark. It
474
+ * is the brand mark's own colour, so it is meant to stay fixed.
475
+ */
476
+ const HUAWEI_RED = "rgb(207, 10, 44)";
477
+ /**
478
+ * Class carried by the clickable account-name control on both chips.
479
+ *
480
+ * A class rather than inline styles because `:hover` and `:focus-visible`
481
+ * cannot be expressed inline, and the two chips must look identical on both.
482
+ */
483
+ const CHIP_CLASS = "aishell-account-hint";
484
+ /**
485
+ * Inject the hover/focus rule once per document.
486
+ *
487
+ * The background token matches what the ContextMeter trigger and the sidebar
488
+ * gear pill use on hover, so the affordance reads the same as the rest of the
489
+ * chrome. Guarded by an id check so a second mount (or the other chip) does
490
+ * not duplicate the rule.
491
+ */
492
+ function ensureChipStyles() {
493
+ if (typeof document === "undefined") return;
494
+ if (document.getElementById("aishell-account-hint-style")) return;
495
+ const style = document.createElement("style");
496
+ style.id = "aishell-account-hint-style";
497
+ style.textContent = `.${CHIP_CLASS}:hover{background:var(--dsw-alias-interactive-bg-hover)}.${CHIP_CLASS}:focus-visible{outline:2px solid var(--dsw-alias-label-primary);outline-offset:-2px}`;
498
+ document.head.appendChild(style);
499
+ }
500
+
501
+ //#endregion
502
+ //#region src/client/open-settings.ts
503
+ /**
504
+ * Open DSH's Settings modal.
505
+ *
506
+ * DSH exposes no service API for this — the modal's open state is
507
+ * component-local inside `SettingsRoot`, toggled only by its trigger button.
508
+ * The trigger is the `button[aria-haspopup="dialog"]` inside the
509
+ * `[data-slot="sidebar.settings"]` outlet, which is a stable, slot-key + ARIA
510
+ * based selector rather than a hashed CSS-module class. Clicking it is the
511
+ * same gesture the sidebar gear makes.
512
+ *
513
+ * Shared by both credential chips so they cannot diverge; the hero chip opens
514
+ * Settings from the same affordance the composer chip uses.
515
+ *
516
+ * @module @huaweidevtools/aishell-dsh-client-credentials/client/open-settings
517
+ */
518
+ /** The Settings modal's trigger, identified by slot key and ARIA contract. */
519
+ const SETTINGS_TRIGGER_SELECTOR = "[data-slot=\"sidebar.settings\"] button[aria-haspopup=\"dialog\"]";
520
+ /**
521
+ * Click DSH's Settings trigger on the user's behalf.
522
+ *
523
+ * A missing trigger is reported on the console rather than thrown. There is
524
+ * nothing to click when the sidebar has not mounted, and throwing inside a
525
+ * click handler would surface as an unhandled rejection; but staying silent
526
+ * would make a selector drift indistinguishable from a dead click, since a
527
+ * `??=`-style no-op leaves no trace anywhere. The warning is the only signal
528
+ * that this selector needs updating.
529
+ */
530
+ function openSettings() {
531
+ const trigger = document.querySelector(SETTINGS_TRIGGER_SELECTOR);
532
+ if (trigger === null) {
533
+ console.warn(`[aishell] Settings trigger not found (${SETTINGS_TRIGGER_SELECTOR}); DSH's sidebar layout may have changed — the chip's click opens nothing.`);
534
+ return;
535
+ }
536
+ trigger.click();
537
+ }
538
+
539
+ //#endregion
540
+ //#region src/client/AishellAccountHint.tsx
541
+ ensureChipStyles();
542
+ /**
543
+ * Render the current account hint, or a setup prompt when credentials are
544
+ * absent. The hooks-compartment subscription keeps the chip live: saving
545
+ * credentials in Settings publishes a new snapshot through the shared store,
546
+ * and the chip updates in place without a remount — the prompt disappears
547
+ * the moment a hint lands.
548
+ *
549
+ * A layout effect promotes the host dock container (the parent element) to
550
+ * `display:flex; justify-content:space-between` so this chip shares a row
551
+ * with ContextMeter instead of stacking above it. The effect restores the
552
+ * original display on cleanup so it never leaks into other dock entries.
553
+ */
554
+ function AishellAccountHint(props) {
555
+ const status = props.useCredentials((snapshot) => snapshot);
556
+ const hint = status.accessKeyIdHint;
557
+ const configured = Boolean(hint);
558
+ const t = props.t;
559
+ const { mode, busy, toggle } = usePermissionMode();
560
+ const ref = (0, react.useRef)(null);
561
+ (0, react.useEffect)(() => {
562
+ const host = ref.current?.parentElement;
563
+ if (!host) return;
564
+ const priorDisplay = host.style.display;
565
+ const priorJustify = host.style.justifyContent;
566
+ const priorAlign = host.style.alignItems;
567
+ host.style.display = "flex";
568
+ host.style.justifyContent = "space-between";
569
+ host.style.alignItems = "center";
570
+ return () => {
571
+ host.style.display = priorDisplay;
572
+ host.style.justifyContent = priorJustify;
573
+ host.style.alignItems = priorAlign;
574
+ };
575
+ }, []);
576
+ const pillStyle = {
577
+ display: "inline-flex",
578
+ alignItems: "center",
579
+ gap: 6,
580
+ flex: "none",
581
+ padding: "1px 8px",
582
+ font: "inherit",
583
+ fontSize: "var(--dsh-content-font-size-secondary, 13px)",
584
+ fontVariantNumeric: "tabular-nums",
585
+ lineHeight: "calc(20px + var(--dsh-content-font-delta-secondary, 0px))",
586
+ background: "transparent",
587
+ border: "none",
588
+ borderRadius: 24,
589
+ cursor: "pointer",
590
+ userSelect: "none",
591
+ whiteSpace: "nowrap"
592
+ };
593
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
594
+ ref,
595
+ style: {
596
+ display: "inline-flex",
597
+ alignItems: "center",
598
+ gap: 0,
599
+ marginLeft: "auto",
600
+ flex: "none"
601
+ },
602
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
603
+ type: "button",
604
+ className: CHIP_CLASS,
605
+ "aria-label": configured ? hint : t("account.unconfigured"),
606
+ onClick: openSettings,
607
+ style: {
608
+ ...pillStyle,
609
+ color: configured ? "var(--dsw-alias-label-tertiary)" : "var(--dsw-alias-state-warn-label)",
610
+ maxWidth: "100%",
611
+ overflow: "hidden",
612
+ textOverflow: "ellipsis"
613
+ },
614
+ title: configured ? hint : t("account.unconfigured"),
615
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
616
+ "aria-hidden": true,
617
+ width: "14",
618
+ height: "14",
619
+ viewBox: "0 0 24 24",
620
+ fill: "currentColor",
621
+ style: {
622
+ color: configured ? HUAWEI_RED : "var(--dsw-alias-state-warn-label)",
623
+ flex: "none"
624
+ },
625
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: HUAWEI_LOGO_PATH })
626
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
627
+ style: {
628
+ overflow: "hidden",
629
+ textOverflow: "ellipsis"
630
+ },
631
+ children: configured ? hint : t("account.unconfigured")
632
+ })]
633
+ }), configured && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
634
+ type: "button",
635
+ className: CHIP_CLASS,
636
+ onClick: () => {
637
+ toggle();
638
+ },
639
+ disabled: mode === void 0 || busy,
640
+ "aria-label": mode === "read_write" ? t("mode.switchToReadonly") : t("mode.switchToReadwrite"),
641
+ style: {
642
+ ...pillStyle,
643
+ color: mode === void 0 ? "var(--dsw-alias-label-tertiary)" : mode === "read_only" ? "var(--dsw-alias-state-success-primary)" : "var(--dsw-alias-state-warn-label)",
644
+ opacity: mode === void 0 || busy ? .6 : 1,
645
+ cursor: mode === void 0 || busy ? "default" : "pointer"
646
+ },
647
+ title: mode === void 0 ? t("mode.unavailable.hint") : mode === "read_only" ? t("mode.readonly.hint") : t("mode.readwrite.hint"),
648
+ children: mode === void 0 ? t("mode.unavailable") : mode === "read_only" ? t("mode.readonly") : t("mode.readwrite")
649
+ })]
650
+ });
651
+ }
652
+
653
+ //#endregion
654
+ //#region src/client/AishellHeroChip.tsx
655
+ ensureChipStyles();
656
+ function AishellHeroChip(props) {
657
+ const status = props.useCredentials((snapshot) => snapshot);
658
+ const t = props.t;
659
+ const configured = Boolean(status.accessKeyIdHint);
660
+ const { mode, busy, toggle } = usePermissionMode();
661
+ const pillStyle = {
662
+ display: "inline-flex",
663
+ alignItems: "center",
664
+ gap: 5,
665
+ flex: "none",
666
+ padding: "1px 8px",
667
+ font: "inherit",
668
+ fontSize: "var(--dsh-content-font-size-secondary, 13px)",
669
+ lineHeight: "calc(20px + var(--dsh-content-font-delta-secondary, 0px))",
670
+ background: "transparent",
671
+ border: "none",
672
+ borderRadius: 24,
673
+ cursor: "pointer",
674
+ userSelect: "none",
675
+ whiteSpace: "nowrap"
676
+ };
677
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
678
+ style: {
679
+ display: "inline-flex",
680
+ alignItems: "center",
681
+ gap: 2,
682
+ minWidth: 0,
683
+ order: 1,
684
+ flex: "none"
685
+ },
686
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
687
+ type: "button",
688
+ className: CHIP_CLASS,
689
+ "aria-label": configured ? status.accessKeyIdHint : t("account.unconfigured"),
690
+ onClick: openSettings,
691
+ style: {
692
+ ...pillStyle,
693
+ color: configured ? "var(--dsw-alias-label-tertiary)" : "var(--dsw-alias-state-warn-label)",
694
+ maxWidth: 220,
695
+ overflow: "hidden",
696
+ textOverflow: "ellipsis"
697
+ },
698
+ title: configured ? status.accessKeyIdHint : t("account.unconfigured"),
699
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
700
+ "aria-hidden": true,
701
+ width: "14",
702
+ height: "14",
703
+ viewBox: "0 0 24 24",
704
+ fill: "currentColor",
705
+ style: {
706
+ color: configured ? HUAWEI_RED : "var(--dsw-alias-state-warn-label)",
707
+ flex: "none"
708
+ },
709
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: HUAWEI_LOGO_PATH })
710
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
711
+ style: {
712
+ overflow: "hidden",
713
+ textOverflow: "ellipsis"
714
+ },
715
+ children: configured ? status.accessKeyIdHint : t("account.unconfigured")
716
+ })]
717
+ }), configured && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
718
+ type: "button",
719
+ onClick: () => {
720
+ toggle();
721
+ },
722
+ disabled: mode === void 0 || busy,
723
+ "aria-label": mode === "read_write" ? t("mode.switchToReadonly") : t("mode.switchToReadwrite"),
724
+ title: mode === void 0 ? t("mode.unavailable.hint") : mode === "read_only" ? t("mode.readonly.hint") : t("mode.readwrite.hint"),
725
+ style: {
726
+ ...pillStyle,
727
+ color: mode === void 0 ? "var(--dsw-alias-label-tertiary)" : mode === "read_only" ? "var(--dsw-alias-state-success-primary)" : "var(--dsw-alias-state-warn-label)",
728
+ opacity: mode === void 0 || busy ? .6 : 1,
729
+ cursor: mode === void 0 || busy ? "default" : "pointer"
730
+ },
731
+ children: mode === void 0 ? t("mode.unavailable") : mode === "read_only" ? t("mode.readonly") : t("mode.readwrite")
732
+ })]
733
+ });
734
+ }
735
+
736
+ //#endregion
737
+ //#region src/client/CredentialRequestForm.tsx
738
+ /**
739
+ * The masked credential form.
740
+ *
741
+ * Submitting saves through the Host route; the Host then tells the waiting tool
742
+ * call there is now a credential, and clears the pending flag this component
743
+ * renders from — so a successful submit does not need to unmount itself.
744
+ */
745
+ function CredentialRequestForm(props) {
746
+ const t = props.t;
747
+ const { save, dismiss } = props;
748
+ const [ak, setAk] = (0, react.useState)("");
749
+ const [sk, setSk] = (0, react.useState)("");
750
+ const [token, setToken] = (0, react.useState)("");
751
+ const [saving, setSaving] = (0, react.useState)(false);
752
+ const [error, setError] = (0, react.useState)(void 0);
753
+ const onSubmit = async (event) => {
754
+ event.preventDefault();
755
+ setSaving(true);
756
+ setError(void 0);
757
+ try {
758
+ const verdict = await save(ak, sk, token === "" ? void 0 : token);
759
+ if (!verdict.ok) {
760
+ setError(verdict.error ?? t("form.failed"));
761
+ return;
762
+ }
763
+ setAk("");
764
+ setSk("");
765
+ setToken("");
766
+ } catch (err) {
767
+ setError(err instanceof Error ? err.message : String(err));
768
+ } finally {
769
+ setSaving(false);
770
+ }
771
+ };
772
+ const fieldStyle = {
773
+ display: "flex",
774
+ flexDirection: "column",
775
+ gap: 6
776
+ };
777
+ const labelStyle = {
778
+ display: "inline-flex",
779
+ alignItems: "center",
780
+ gap: 10,
781
+ fontSize: 12,
782
+ lineHeight: "18px",
783
+ fontWeight: 500,
784
+ color: "var(--dsw-alias-label-secondary)"
785
+ };
786
+ const inputStyle = {
787
+ boxSizing: "border-box",
788
+ width: "100%",
789
+ height: 32,
790
+ padding: "0 10px",
791
+ border: "0.5px solid var(--dsw-alias-border-l4)",
792
+ borderRadius: 8,
793
+ font: "inherit",
794
+ fontSize: 14,
795
+ lineHeight: "22px",
796
+ background: "var(--dsw-alias-bg-layer-1)",
797
+ color: "var(--dsw-alias-label-primary)"
798
+ };
799
+ const buttonStyle = (disabled$1) => ({
800
+ height: 32,
801
+ padding: "0 14px",
802
+ border: "none",
803
+ borderRadius: 8,
804
+ font: "inherit",
805
+ fontSize: 14,
806
+ cursor: disabled$1 ? "default" : "pointer",
807
+ opacity: disabled$1 ? .5 : 1
808
+ });
809
+ const disabled = saving || !ak || !sk;
810
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
811
+ role: "group",
812
+ "aria-label": t("form.title"),
813
+ style: {
814
+ padding: "6px calc(var(--dsh-composer-side-clearance) + 16px) 10px",
815
+ display: "flex",
816
+ justifyContent: "center"
817
+ },
818
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("form", {
819
+ onSubmit,
820
+ style: {
821
+ width: "100%",
822
+ maxWidth: "var(--dsh-chat-content-width)",
823
+ background: "var(--dsw-specific-input-major)",
824
+ boxShadow: "var(--dsw-elevation-panel)",
825
+ border: "0.5px solid var(--dsw-alias-border-l2-darkmode-thin)",
826
+ borderRadius: 20,
827
+ padding: "16px 20px",
828
+ display: "flex",
829
+ flexDirection: "column",
830
+ gap: 12
831
+ },
832
+ children: [
833
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
834
+ style: {
835
+ display: "flex",
836
+ flexDirection: "column",
837
+ gap: 4
838
+ },
839
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
840
+ style: {
841
+ fontSize: 14,
842
+ fontWeight: 500,
843
+ lineHeight: "22px"
844
+ },
845
+ children: t("form.title")
846
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
847
+ style: {
848
+ fontSize: 12,
849
+ lineHeight: "18px",
850
+ color: "var(--dsw-alias-label-tertiary)"
851
+ },
852
+ children: [
853
+ t("section.credentials.hint.prefix"),
854
+ " ",
855
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
856
+ href: CREDENTIAL_URL,
857
+ target: "_blank",
858
+ rel: "noreferrer noopener",
859
+ style: {
860
+ color: "var(--dsw-alias-button-primary-fill)",
861
+ textDecoration: "underline"
862
+ },
863
+ children: t("section.credentials.hint.link")
864
+ }),
865
+ " ",
866
+ t("section.credentials.hint.suffix")
867
+ ]
868
+ })]
869
+ }),
870
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
871
+ style: fieldStyle,
872
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
873
+ style: labelStyle,
874
+ children: t("section.field.accessKey")
875
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
876
+ type: "password",
877
+ value: ak,
878
+ onChange: (e) => setAk(e.target.value),
879
+ style: inputStyle,
880
+ placeholder: t("section.field.accessKey.placeholder"),
881
+ "aria-label": t("section.field.accessKey"),
882
+ autoComplete: "off",
883
+ autoFocus: true
884
+ })]
885
+ }),
886
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
887
+ style: fieldStyle,
888
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
889
+ style: labelStyle,
890
+ children: t("section.field.secretKey")
891
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
892
+ type: "password",
893
+ value: sk,
894
+ onChange: (e) => setSk(e.target.value),
895
+ style: inputStyle,
896
+ placeholder: t("section.field.secretKey.placeholder"),
897
+ "aria-label": t("section.field.secretKey"),
898
+ autoComplete: "off"
899
+ })]
900
+ }),
901
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
902
+ style: fieldStyle,
903
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
904
+ style: labelStyle,
905
+ children: t("section.field.token")
906
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
907
+ type: "password",
908
+ value: token,
909
+ onChange: (e) => setToken(e.target.value),
910
+ style: inputStyle,
911
+ placeholder: t("section.field.token.placeholder"),
912
+ "aria-label": t("section.field.token"),
913
+ autoComplete: "off"
914
+ })]
915
+ }),
916
+ error !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
917
+ style: {
918
+ margin: 0,
919
+ fontSize: 12,
920
+ lineHeight: "18px",
921
+ color: "var(--dsw-alias-state-warn-label)"
922
+ },
923
+ children: error
924
+ }),
925
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
926
+ style: {
927
+ display: "flex",
928
+ gap: 8
929
+ },
930
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
931
+ type: "submit",
932
+ disabled,
933
+ style: {
934
+ ...buttonStyle(disabled),
935
+ background: "var(--dsw-alias-button-primary-fill)",
936
+ color: "var(--dsw-alias-label-primary-foreground)"
937
+ },
938
+ children: saving ? t("section.credentials.saving") : t("form.submit")
939
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
940
+ type: "button",
941
+ onClick: dismiss,
942
+ disabled: saving,
943
+ style: {
944
+ ...buttonStyle(saving),
945
+ background: "transparent",
946
+ color: "var(--dsw-alias-label-primary)",
947
+ border: "0.5px solid var(--dsw-alias-border-l4)"
948
+ },
949
+ children: t("form.dismiss")
950
+ })]
951
+ })
952
+ ]
953
+ })
954
+ });
955
+ }
956
+
957
+ //#endregion
958
+ //#region src/client/CredentialFormInteraction.ts
959
+ /** Monotonic source of `key`s, module-scoped like the approval panel's. */
960
+ let nextKey = 0;
961
+ /**
962
+ * Build an interaction for one session.
963
+ *
964
+ * @param sessionId - the conversation the form belongs to.
965
+ */
966
+ function credentialFormInteraction(sessionId) {
967
+ nextKey += 1;
968
+ return {
969
+ kind: "aishell-credential-form",
970
+ key: `aishell-credential-form:${String(nextKey)}`,
971
+ sessionId
972
+ };
973
+ }
974
+ /**
975
+ * Test whether a pending interaction is this domain's form.
976
+ *
977
+ * The `select` in the composer chain needs a runtime check, and this is the one
978
+ * place that knows what makes one — a kind tag rather than `instanceof`, which
979
+ * a factory-produced object cannot offer.
980
+ *
981
+ * @param value - the session's pending interaction, or `undefined`.
982
+ */
983
+ function isCredentialForm(value) {
984
+ return value?.kind === "aishell-credential-form";
985
+ }
986
+ /**
987
+ * Route the Host exposes to abandon a pending credential request.
988
+ *
989
+ * Sits with the other credential routes: `clear`, `reset`, and this one all end
990
+ * a credential state, and keeping them together is what makes the route table
991
+ * readable. Without it a person who does not want to enter credentials would
992
+ * leave the blocked tool call waiting until the turn ended.
993
+ */
994
+ const DISMISS_ROUTE = "api/aishell/credentials/dismiss";
995
+
996
+ //#endregion
997
+ //#region src/client/credential-form-visibility.ts
998
+ /**
999
+ * Build the visibility state machine.
1000
+ *
1001
+ * @param publish - how to put an interaction in front of the composer.
1002
+ */
1003
+ function createCredentialFormVisibility(publish) {
1004
+ let open;
1005
+ let withdraw;
1006
+ const clear = () => {
1007
+ withdraw?.();
1008
+ withdraw = void 0;
1009
+ open = void 0;
1010
+ };
1011
+ return {
1012
+ current: () => open,
1013
+ sync: (sessionId) => {
1014
+ if (sessionId === "") {
1015
+ if (open === void 0) return;
1016
+ clear();
1017
+ return;
1018
+ }
1019
+ if (open?.sessionId === sessionId) return;
1020
+ withdraw?.();
1021
+ const interaction = credentialFormInteraction(sessionId);
1022
+ open = interaction;
1023
+ withdraw = publish(interaction);
1024
+ },
1025
+ dispose: () => {
1026
+ if (open === void 0) return;
1027
+ clear();
1028
+ }
1029
+ };
1030
+ }
1031
+
1032
+ //#endregion
1033
+ //#region src/client/locales.ts
1034
+ /**
1035
+ * aishell credentials locale dictionaries.
1036
+ *
1037
+ * @module @huaweidevtools/aishell-dsh-client-credentials/client/locales
1038
+ */
1039
+ /** Dictionary namespace owned by this plugin. */
1040
+ const NS = "aishell";
1041
+ /** Simplified Chinese dictionary (the key-set source of truth). */
1042
+ const zh = {
1043
+ "account.unconfigured": "未配置华为云 IAM 凭据",
1044
+ "mode.readonly": "只读",
1045
+ "mode.readwrite": "读写",
1046
+ "mode.unavailable": "权限模式不可用",
1047
+ "mode.readonly.hint": "当前:只读 — 只允许查询云资源,点击切换为读写",
1048
+ "mode.readwrite.hint": "当前:读写 — 允许变更云资源,点击切换为只读",
1049
+ "mode.unavailable.hint": "无法从 MCP 服务器读取权限模式;切换按钮暂不可用",
1050
+ "mode.switchToReadonly": "切换为只读模式",
1051
+ "mode.switchToReadwrite": "切换为读写模式",
1052
+ "section.settings.summary": "华为云 AI Shell 设置。",
1053
+ "section.credentials.title": "凭据",
1054
+ "section.credentials.hint.prefix": "需要进行华为云 IAM 认证,建议从",
1055
+ "section.credentials.hint.link": "API Explorer",
1056
+ "section.credentials.hint.suffix": "获取临时凭据,避免使用永久凭据。",
1057
+ "section.credentials.saved": "校验通过,已存入 keyring。",
1058
+ "section.credentials.save": "保存",
1059
+ "section.credentials.saving": "保存中…",
1060
+ "section.credentials.clear": "清除",
1061
+ "form.title": "需要华为云凭据",
1062
+ "form.submit": "提交",
1063
+ "form.dismiss": "取消",
1064
+ "form.failed": "保存凭据失败",
1065
+ "section.field.accessKey": "Access Key",
1066
+ "section.field.accessKey.placeholder": "华为云 Access Key",
1067
+ "section.field.accessKey.hint": "Access Key 与 Secret Key 须同时填写,只填其一时不会保存。",
1068
+ "section.field.secretKey": "Secret Key",
1069
+ "section.field.secretKey.placeholder": "华为云 Secret Key",
1070
+ "section.field.secretKey.hint": "与 Access Key 配对使用,不在任何界面回显。",
1071
+ "section.field.token": "Security Token(可选)",
1072
+ "section.field.token.placeholder": "华为云 Security Token",
1073
+ "section.field.token.hint": "仅临时凭据需要填写。"
1074
+ };
1075
+ /** English dictionary. */
1076
+ const en = {
1077
+ "account.unconfigured": "No Huawei Cloud IAM credentials",
1078
+ "mode.readonly": "Read-only",
1079
+ "mode.readwrite": "Read-write",
1080
+ "mode.unavailable": "Mode unavailable",
1081
+ "mode.readonly.hint": "Read-only — cloud queries only. Click for read-write",
1082
+ "mode.readwrite.hint": "Read-write — cloud changes allowed. Click for read-only",
1083
+ "mode.unavailable.hint": "Could not read the permission mode from the MCP server; the toggle is unavailable",
1084
+ "mode.switchToReadonly": "Switch to read-only mode",
1085
+ "mode.switchToReadwrite": "Switch to read-write mode",
1086
+ "section.settings.summary": "Huawei Cloud AI Shell settings.",
1087
+ "section.credentials.title": "Credentials",
1088
+ "section.credentials.hint.prefix": "Authenticate against Huawei Cloud IAM. Obtain temporary credentials from",
1089
+ "section.credentials.hint.link": "API Explorer",
1090
+ "section.credentials.hint.suffix": "and avoid permanent ones.",
1091
+ "section.credentials.saved": "Verified and saved to keyring.",
1092
+ "section.credentials.save": "Save",
1093
+ "section.credentials.saving": "Saving…",
1094
+ "section.credentials.clear": "Clear",
1095
+ "form.title": "Huawei Cloud credentials required",
1096
+ "form.submit": "Submit",
1097
+ "form.dismiss": "Cancel",
1098
+ "form.failed": "Could not save credentials",
1099
+ "section.field.accessKey": "Access Key",
1100
+ "section.field.accessKey.placeholder": "Huawei Access Key",
1101
+ "section.field.accessKey.hint": "Access Key and Secret Key are stored as a pair; one without the other is not saved.",
1102
+ "section.field.secretKey": "Secret Key",
1103
+ "section.field.secretKey.placeholder": "Huawei Secret Key",
1104
+ "section.field.secretKey.hint": "Used together with the Access Key; never displayed again.",
1105
+ "section.field.token": "Security Token (optional)",
1106
+ "section.field.token.placeholder": "Huawei Security Token",
1107
+ "section.field.token.hint": "Required only for temporary credentials."
1108
+ };
1109
+
1110
+ //#endregion
1111
+ //#region src/client/index.ts
1112
+ /** Host entry id (= settings namespace) this page reads status from. */
1113
+ const AISHELL_CREDENTIALS_NS = "aishell-client-credentials";
1114
+ /**
1115
+ * Host credential route, written document-relative: the served index carries
1116
+ * `<base href="./">`, so the leading slash is stripped and the request lands on
1117
+ * the same origin that served the page — which is what carries the browser
1118
+ * session cookie the route's authentication fence requires.
1119
+ */
1120
+ const CREDENTIALS_ROUTE = "api/aishell/credentials";
1121
+ /** Clear route; the Host's fetch registry has no DELETE, so clearing is a POST. */
1122
+ const CLEAR_ROUTE = "api/aishell/credentials/clear";
1123
+ /**
1124
+ * The MCP server's own credential store, cleared through the ops-deploy
1125
+ * plugin's route.
1126
+ *
1127
+ * Clearing is a two-store operation: this plugin's store (CLEAR_ROUTE) and the
1128
+ * MCP server's, which keeps its own copy scoped to this client. Only the first
1129
+ * existed until the scope work made the second reachable, and the half-cleared
1130
+ * state it left — Settings showing "no credentials" while cloud calls still
1131
+ * worked — is the bug this fixes.
1132
+ *
1133
+ * An absolute host route owned by another package, reached the same way the
1134
+ * permission-mode route already is: by URL, not by import.
1135
+ */
1136
+ const SERVER_CREDENTIALS_ROUTE = "api/aishell/credentials/reset";
1137
+ /**
1138
+ * POST one JSON body to a Host credential route and read back its verdict.
1139
+ * A non-JSON or unreadable body is reported as a transport failure rather than
1140
+ * thrown, so the form shows a message instead of an unhandled rejection.
1141
+ */
1142
+ async function postJson(route, body) {
1143
+ try {
1144
+ const response = await fetch(route, {
1145
+ method: "POST",
1146
+ ...body === void 0 ? {} : {
1147
+ headers: { "content-type": "application/json" },
1148
+ body: JSON.stringify(body)
1149
+ }
1150
+ });
1151
+ const verdict = await response.json();
1152
+ return verdict;
1153
+ } catch (error) {
1154
+ return {
1155
+ ok: false,
1156
+ error: `无法连接宿主凭据服务:${error instanceof Error ? error.message : String(error)}`
1157
+ };
1158
+ }
1159
+ }
1160
+ /**
1161
+ * Store one credential through the Host route.
1162
+ *
1163
+ * Both surfaces that collect a credential — the Settings section and the
1164
+ * composer form shown while an MCP call is blocked — go through this, so a
1165
+ * field added to one cannot be silently missing from the other's body. The
1166
+ * route is the same one the Settings section has always used, so IAM
1167
+ * verification, storage and the account chip behave identically whichever
1168
+ * surface collected the value.
1169
+ *
1170
+ * An absent SecurityToken is omitted rather than sent empty: the Host reads an
1171
+ * empty string as absent anyway, so sending it would only make the wire shape
1172
+ * depend on which form was used.
1173
+ */
1174
+ function saveCredential(accessKeyId, secretAccessKey, securityToken) {
1175
+ return postJson(CREDENTIALS_ROUTE, {
1176
+ accessKeyId,
1177
+ secretAccessKey,
1178
+ ...securityToken === void 0 ? {} : { securityToken }
1179
+ });
1180
+ }
1181
+ /**
1182
+ * Clear both credential stores, reporting the first failure.
1183
+ *
1184
+ * The order matters: this plugin's store goes first, because it is the one
1185
+ * whose absence *stops* the chat from authenticating. A failure there leaves
1186
+ * both stores intact (nothing cleared, nothing to misreport). A failure on the
1187
+ * second leaves a state the user can still act on — no credentials in Settings,
1188
+ * a server copy that a second attempt or a server restart will clear — which is
1189
+ * why the message names which half failed rather than saying "clear failed".
1190
+ *
1191
+ * The second store is best-effort by design: if the MCP server is unreachable
1192
+ * or older than `credential/reset`, the local clear has already succeeded and
1193
+ * saying so is more accurate than reporting the whole action as failed.
1194
+ */
1195
+ async function clearBothStores() {
1196
+ const local = await postJson(CLEAR_ROUTE);
1197
+ if (!local.ok) return local;
1198
+ try {
1199
+ const response = await fetch(SERVER_CREDENTIALS_ROUTE, { method: "POST" });
1200
+ if (!response.ok) {
1201
+ const body = await response.json();
1202
+ return {
1203
+ ok: false,
1204
+ error: typeof body.error === "string" ? body.error : `本机凭据已清除,但服务端凭据未清除(HTTP ${response.status})`
1205
+ };
1206
+ }
1207
+ } catch (error) {
1208
+ return {
1209
+ ok: false,
1210
+ error: "本机凭据已清除,但无法连接 MCP 服务器清除服务端凭据:" + (error instanceof Error ? error.message : String(error))
1211
+ };
1212
+ }
1213
+ return { ok: true };
1214
+ }
1215
+ /** Required services. */
1216
+ const inject = [
1217
+ "slots",
1218
+ "locale",
1219
+ "configForms",
1220
+ "uiSession"
1221
+ ];
1222
+ function apply(ctx) {
1223
+ ctx.effect(() => ctx.locale.register(NS, {
1224
+ zh,
1225
+ en
1226
+ }), "aishell-credentials: dictionaries");
1227
+ const t = ctx.locale.bind(NS);
1228
+ const form = ctx.configForms.get(AISHELL_CREDENTIALS_NS);
1229
+ const status = (0, __deepseek_ai_dsh_client_store.createSnapshotStore)({
1230
+ hasAccessKey: false,
1231
+ hasSecretKey: false,
1232
+ hasSecurityToken: false,
1233
+ accessKeyIdHint: "",
1234
+ lastError: ""
1235
+ });
1236
+ const derive = () => {
1237
+ const value = form.getSnapshot().value;
1238
+ const stored = value?.credentialsStored === true;
1239
+ status.set({
1240
+ hasAccessKey: stored,
1241
+ hasSecretKey: stored,
1242
+ hasSecurityToken: stored,
1243
+ accessKeyIdHint: value?.accessKeyIdHint ?? "",
1244
+ lastError: value?.lastError ?? ""
1245
+ });
1246
+ };
1247
+ ctx.effect(() => form.subscribe(derive), "aishell-credentials: credential presence");
1248
+ derive();
1249
+ ctx.effect(() => ctx.configForms.whileServed([AISHELL_CREDENTIALS_NS], () => ctx.slots.inject("settings.section", () => ctx.slots.register({
1250
+ name: "settings.section",
1251
+ id: "aishell",
1252
+ order: 50,
1253
+ label: () => "AI Shell",
1254
+ locale: NS,
1255
+ inject: () => ({
1256
+ hooks: { credentials: status },
1257
+ t,
1258
+ save: saveCredential,
1259
+ clear: () => clearBothStores()
1260
+ })
1261
+ }, AishellCredentialsSection))), "aishell-credentials: settings section");
1262
+ ctx.effect(() => ctx.slots.inject("conversation.composer.dock", () => ctx.slots.register({
1263
+ name: "conversation.composer.dock",
1264
+ id: "aishell-account",
1265
+ order: 30,
1266
+ locale: NS,
1267
+ inject: () => ({
1268
+ hooks: { credentials: status },
1269
+ t
1270
+ })
1271
+ }, AishellAccountHint)), "aishell-credentials: account hint chip");
1272
+ ctx.effect(() => ctx.slots.inject("conversation.hero.workspace", () => {
1273
+ const dispose = ctx.slots.register({
1274
+ name: "conversation.hero.workspace",
1275
+ priority: -1,
1276
+ locale: NS,
1277
+ inject: () => ({ hooks: { credentials: status } })
1278
+ }, AishellHeroChip);
1279
+ return dispose;
1280
+ }), "aishell-credentials: hero account chip");
1281
+ ctx.effect(() => ctx.slots.inject("conversation.composer", () => ctx.slots.register({
1282
+ name: "conversation.composer",
1283
+ select: ({ pendingInteraction }) => isCredentialForm(pendingInteraction) ? pendingInteraction : null,
1284
+ locale: NS,
1285
+ inject: () => ({
1286
+ save: saveCredential,
1287
+ dismiss: () => {
1288
+ fetch(DISMISS_ROUTE, { method: "POST" });
1289
+ }
1290
+ })
1291
+ }, CredentialRequestForm)), "aishell-credentials: credential form");
1292
+ const publishCredentialForm = ctx.uiSession.registerPendingInteraction(() => 0);
1293
+ const visibility = createCredentialFormVisibility((interaction) => publishCredentialForm(interaction, () => Promise.resolve()));
1294
+ const syncCredentialForm = () => {
1295
+ visibility.sync(form.getSnapshot().value?.credentialRequestSession ?? "");
1296
+ };
1297
+ ctx.effect(() => form.subscribe(syncCredentialForm), "aishell-credentials: credential form visibility");
1298
+ syncCredentialForm();
1299
+ ctx.effect(() => () => {
1300
+ visibility.dispose();
1301
+ }, "aishell-credentials: credential form teardown");
1302
+ }
1303
+
1304
+ //#endregion
1305
+ exports.apply = apply
1306
+ exports.inject = inject
1307
+ return module.exports; } });
1308
+ //# sourceMappingURL=client.js.map