@huaweidevtools/aishell-dsh-client-credentials 0.0.2 → 0.0.4

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
@@ -28,342 +28,6 @@ const __deepseek_ai_dsh_client_store = __toESM(require("@deepseek-ai/dsh-client-
28
28
  const react = __toESM(require("react"));
29
29
  const react_jsx_runtime = __toESM(require("react/jsx-runtime"));
30
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
31
  //#region src/client/permission-mode.ts
368
32
  /**
369
33
  * Host permission route, written document-relative for the same reason as the
@@ -454,15 +118,6 @@ function usePermissionMode() {
454
118
 
455
119
  //#endregion
456
120
  //#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
121
  /** Huawei logo path (from simple-icons/huawei), drawn in a 24×24 viewBox. */
467
122
  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
123
  /**
@@ -482,67 +137,54 @@ const HUAWEI_RED = "rgb(207, 10, 44)";
482
137
  */
483
138
  const CHIP_CLASS = "aishell-account-hint";
484
139
  /**
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.
140
+ * Plugin id stamped on the style tag, and the same marker the build-time CSS
141
+ * modules carry (`shared/tsdown.client.ts` sets `dataset.plugin` + a
142
+ * `dataset.pluginCss` dedupe key). The loader's `removeOwnedStyles` sweeps
143
+ * `style[data-plugin="<id>"]` on module teardown, so a tag written here is
144
+ * reachable by the same mechanism as the generated ones.
491
145
  */
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
146
+ const PLUGIN_ID = "@huaweidevtools/aishell-dsh-client-credentials";
147
+ /** Dedupe key for the one sheet this module owns. */
148
+ const CHIP_STYLE_KEY = `${PLUGIN_ID}/chip-hover`;
503
149
  /**
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.
150
+ * Mount the chips' hover/focus rule for the owning plugin's lifetime.
512
151
  *
513
- * Shared by both credential chips so they cannot diverge; the hero chip opens
514
- * Settings from the same affordance the composer chip uses.
152
+ * The shape follows `dsh-client-ui-theme`'s `installThemeStyles`, which is the
153
+ * framework's own answer for runtime-authored CSS: one `ctx.effect` per sheet,
154
+ * a disposer that removes the tag, and the `data-plugin` markers so
155
+ * `removeOwnedStyles` can also reach it. The disposer is what makes a reload
156
+ * 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.
515
161
  *
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.
162
+ * Call once from `apply()`, not from the components: the rule is shared by
163
+ * both chips (they carry the same `CHIP_CLASS`), so one sheet serves them and
164
+ * two installers would fight over the same dedupe key.
522
165
  *
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.
166
+ * @param ctx - the browser-half plugin context whose effect owns the tag.
529
167
  */
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();
168
+ function installChipStyles(ctx) {
169
+ if (typeof document === "undefined") return;
170
+ ctx.effect(() => {
171
+ const tag = document.createElement("style");
172
+ tag.dataset.plugin = PLUGIN_ID;
173
+ tag.dataset.pluginCss = CHIP_STYLE_KEY;
174
+ tag.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}`;
175
+ document.head.appendChild(tag);
176
+ return () => {
177
+ tag.remove();
178
+ };
179
+ }, "aishell-credentials: chip hover styles");
537
180
  }
538
181
 
539
182
  //#endregion
540
183
  //#region src/client/AishellAccountHint.tsx
541
- ensureChipStyles();
542
184
  /**
543
185
  * Render the current account hint, or a setup prompt when credentials are
544
186
  * absent. The hooks-compartment subscription keeps the chip live: saving
545
- * credentials in Settings publishes a new snapshot through the shared store,
187
+ * credentials in the form publishes a new snapshot through the shared store,
546
188
  * and the chip updates in place without a remount — the prompt disappears
547
189
  * the moment a hint lands.
548
190
  *
@@ -556,6 +198,7 @@ function AishellAccountHint(props) {
556
198
  const hint = status.accessKeyIdHint;
557
199
  const configured = Boolean(hint);
558
200
  const t = props.t;
201
+ const openCredentialForm = props.openCredentialForm;
559
202
  const { mode, busy, toggle } = usePermissionMode();
560
203
  const ref = (0, react.useRef)(null);
561
204
  (0, react.useEffect)(() => {
@@ -603,7 +246,7 @@ function AishellAccountHint(props) {
603
246
  type: "button",
604
247
  className: CHIP_CLASS,
605
248
  "aria-label": configured ? hint : t("account.unconfigured"),
606
- onClick: openSettings,
249
+ onClick: openCredentialForm,
607
250
  style: {
608
251
  ...pillStyle,
609
252
  color: configured ? "var(--dsw-alias-label-tertiary)" : "var(--dsw-alias-state-warn-label)",
@@ -652,12 +295,73 @@ function AishellAccountHint(props) {
652
295
 
653
296
  //#endregion
654
297
  //#region src/client/AishellHeroChip.tsx
655
- ensureChipStyles();
656
298
  function AishellHeroChip(props) {
299
+ const blank = props.useSession((session) => session.blank);
657
300
  const status = props.useCredentials((snapshot) => snapshot);
301
+ const { mode, busy, toggle } = usePermissionMode();
658
302
  const t = props.t;
303
+ const openCredentialForm = props.openCredentialForm;
659
304
  const configured = Boolean(status.accessKeyIdHint);
660
- const { mode, busy, toggle } = usePermissionMode();
305
+ const wrapperRef = (0, react.useRef)(null);
306
+ const [presetOffset, setPresetOffset] = (0, react.useState)(null);
307
+ const presetOffsetRef = (0, react.useRef)(null);
308
+ const applyOffset = (offset) => {
309
+ presetOffsetRef.current = offset;
310
+ setPresetOffset(offset);
311
+ };
312
+ (0, react.useLayoutEffect)(() => {
313
+ let observer;
314
+ let observedRow;
315
+ const measure = () => {
316
+ const wrapper = wrapperRef.current;
317
+ if (wrapper === null) return;
318
+ let stack = wrapper.parentElement;
319
+ while (stack !== null && getComputedStyle(stack).display === "contents") stack = stack.parentElement;
320
+ const preset = stack?.querySelector("[data-slot=\"conversation.hero.agentPreset\"] > *") ?? null;
321
+ if (stack === null || preset === null) {
322
+ applyOffset(null);
323
+ return;
324
+ }
325
+ const offset = Math.round(preset.getBoundingClientRect().right - stack.getBoundingClientRect().left + 6);
326
+ if (!(offset > 0)) {
327
+ applyOffset(null);
328
+ return;
329
+ }
330
+ applyOffset(offset);
331
+ const row = preset.closest("[data-slot=\"conversation.hero.agentPreset\"]")?.parentElement ?? null;
332
+ if (row === null || row === observedRow) return;
333
+ observedRow = row;
334
+ observer?.disconnect();
335
+ observer = new ResizeObserver(measure);
336
+ for (const target of row.querySelectorAll("button")) observer.observe(target);
337
+ };
338
+ presetOffsetRef.current = null;
339
+ const SWEEP_CAP_MS = 5e3;
340
+ const deadline = Date.now() + SWEEP_CAP_MS;
341
+ let settled = false;
342
+ let sweepTimer = 0;
343
+ const sweep = () => {
344
+ if (settled) return;
345
+ if (presetOffsetRef.current !== null || Date.now() > deadline) {
346
+ settled = true;
347
+ return;
348
+ }
349
+ measure();
350
+ if (presetOffsetRef.current !== null) {
351
+ settled = true;
352
+ return;
353
+ }
354
+ sweepTimer = window.setTimeout(sweep, 100);
355
+ };
356
+ sweepTimer = window.setTimeout(sweep, 100);
357
+ return () => {
358
+ settled = true;
359
+ observer?.disconnect();
360
+ window.clearTimeout(sweepTimer);
361
+ };
362
+ }, [blank]);
363
+ if (!blank) return null;
364
+ const placed = presetOffset !== null;
661
365
  const pillStyle = {
662
366
  display: "inline-flex",
663
367
  alignItems: "center",
@@ -675,19 +379,22 @@ function AishellHeroChip(props) {
675
379
  whiteSpace: "nowrap"
676
380
  };
677
381
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
382
+ ref: wrapperRef,
678
383
  style: {
679
384
  display: "inline-flex",
680
385
  alignItems: "center",
681
386
  gap: 2,
682
387
  minWidth: 0,
683
- order: 1,
388
+ visibility: placed ? "visible" : "hidden",
389
+ marginTop: -33,
390
+ marginLeft: presetOffset ?? 0,
684
391
  flex: "none"
685
392
  },
686
393
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
687
394
  type: "button",
688
395
  className: CHIP_CLASS,
689
396
  "aria-label": configured ? status.accessKeyIdHint : t("account.unconfigured"),
690
- onClick: openSettings,
397
+ onClick: openCredentialForm,
691
398
  style: {
692
399
  ...pillStyle,
693
400
  color: configured ? "var(--dsw-alias-label-tertiary)" : "var(--dsw-alias-state-warn-label)",
@@ -733,6 +440,23 @@ function AishellHeroChip(props) {
733
440
  });
734
441
  }
735
442
 
443
+ //#endregion
444
+ //#region src/client/credential-status.ts
445
+ /**
446
+ * Where a user obtains credentials.
447
+ *
448
+ * API Explorer's page for `CreateTemporaryAccessKeyByToken` — the operation
449
+ * that mints a temporary AK/SK/security-token triple from an IAM token. Linked
450
+ * from both forms because the alternative, a permanent access key created in
451
+ * "My Credentials", has no expiry and cannot be scoped down; steering users to
452
+ * the temporary kind is the point of showing this at all.
453
+ *
454
+ * Not fetched or validated at build time: it is a console URL whose content
455
+ * changes independently of this plugin, and a stale check would be worse than
456
+ * none.
457
+ */
458
+ const CREDENTIAL_URL = "https://console.huaweicloud.com/apiexplorer/#/openapi/IAM/doc?version=v3&api=CreateTemporaryAccessKeyByToken";
459
+
736
460
  //#endregion
737
461
  //#region src/client/CredentialRequestForm.tsx
738
462
  /**
@@ -740,16 +464,22 @@ function AishellHeroChip(props) {
740
464
  *
741
465
  * Submitting saves through the Host route; the Host then tells the waiting tool
742
466
  * 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.
467
+ * renders from — so a successful submit does not need to unmount itself. A
468
+ * manually-opened form has no request behind it, so it closes itself after a
469
+ * successful save (the chip flipping to the account name is the feedback).
744
470
  */
745
471
  function CredentialRequestForm(props) {
746
472
  const t = props.t;
747
- const { save, dismiss } = props;
473
+ const { save, clear, dismiss, closeManual } = props;
474
+ const status = props.useCredentials((snapshot) => snapshot);
748
475
  const [ak, setAk] = (0, react.useState)("");
749
476
  const [sk, setSk] = (0, react.useState)("");
750
477
  const [token, setToken] = (0, react.useState)("");
751
478
  const [saving, setSaving] = (0, react.useState)(false);
479
+ const [clearing, setClearing] = (0, react.useState)(false);
752
480
  const [error, setError] = (0, react.useState)(void 0);
481
+ const pending = props.pendingInteraction;
482
+ const manual = pending?.manual === true;
753
483
  const onSubmit = async (event) => {
754
484
  event.preventDefault();
755
485
  setSaving(true);
@@ -763,12 +493,32 @@ function CredentialRequestForm(props) {
763
493
  setAk("");
764
494
  setSk("");
765
495
  setToken("");
496
+ if (manual) closeManual();
766
497
  } catch (err) {
767
498
  setError(err instanceof Error ? err.message : String(err));
768
499
  } finally {
769
500
  setSaving(false);
770
501
  }
771
502
  };
503
+ const onClear = async () => {
504
+ setClearing(true);
505
+ setError(void 0);
506
+ try {
507
+ const verdict = await clear();
508
+ if (!verdict.ok) setError(verdict.error ?? t("form.clear.failed"));
509
+ } catch (err) {
510
+ setError(err instanceof Error ? err.message : String(err));
511
+ } finally {
512
+ setClearing(false);
513
+ }
514
+ };
515
+ const onCancel = () => {
516
+ if (manual) {
517
+ closeManual();
518
+ return;
519
+ }
520
+ dismiss();
521
+ };
772
522
  const fieldStyle = {
773
523
  display: "flex",
774
524
  flexDirection: "column",
@@ -806,10 +556,12 @@ function CredentialRequestForm(props) {
806
556
  cursor: disabled$1 ? "default" : "pointer",
807
557
  opacity: disabled$1 ? .5 : 1
808
558
  });
809
- const disabled = saving || !ak || !sk;
559
+ const busy = saving || clearing;
560
+ const disabled = busy || !ak || !sk;
561
+ const hasCredentials = status.hasAccessKey || status.hasSecretKey;
810
562
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
811
563
  role: "group",
812
- "aria-label": t("form.title"),
564
+ "aria-label": t(manual ? "form.title.manual" : "form.title"),
813
565
  style: {
814
566
  padding: "6px calc(var(--dsh-composer-side-clearance) + 16px) 10px",
815
567
  display: "flex",
@@ -842,7 +594,7 @@ function CredentialRequestForm(props) {
842
594
  fontWeight: 500,
843
595
  lineHeight: "22px"
844
596
  },
845
- children: t("form.title")
597
+ children: t(manual ? "form.title.manual" : "form.title")
846
598
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
847
599
  style: {
848
600
  fontSize: 12,
@@ -869,9 +621,19 @@ function CredentialRequestForm(props) {
869
621
  }),
870
622
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
871
623
  style: fieldStyle,
872
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
624
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
873
625
  style: labelStyle,
874
- children: t("section.field.accessKey")
626
+ children: [t("section.field.accessKey"), status.accessKeyIdHint && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
627
+ style: {
628
+ color: "var(--dsw-alias-label-tertiary)",
629
+ fontWeight: 400
630
+ },
631
+ children: [
632
+ "(",
633
+ status.accessKeyIdHint,
634
+ ")"
635
+ ]
636
+ })]
875
637
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
876
638
  type: "password",
877
639
  value: ak,
@@ -927,27 +689,45 @@ function CredentialRequestForm(props) {
927
689
  display: "flex",
928
690
  gap: 8
929
691
  },
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
- })]
692
+ children: [
693
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
694
+ type: "submit",
695
+ disabled,
696
+ style: {
697
+ ...buttonStyle(disabled),
698
+ background: "var(--dsw-alias-button-primary-fill)",
699
+ color: "var(--dsw-alias-label-primary-foreground)"
700
+ },
701
+ children: saving ? t("section.credentials.saving") : t("form.submit")
702
+ }),
703
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
704
+ type: "button",
705
+ onClick: onCancel,
706
+ disabled: busy,
707
+ style: {
708
+ ...buttonStyle(busy),
709
+ background: "transparent",
710
+ color: "var(--dsw-alias-label-primary)",
711
+ border: "0.5px solid var(--dsw-alias-border-l4)"
712
+ },
713
+ children: t("form.dismiss")
714
+ }),
715
+ hasCredentials && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
716
+ type: "button",
717
+ onClick: () => {
718
+ onClear();
719
+ },
720
+ disabled: busy,
721
+ style: {
722
+ ...buttonStyle(busy),
723
+ background: "transparent",
724
+ color: "var(--dsw-alias-label-primary)",
725
+ border: "0.5px solid var(--dsw-alias-border-l4)",
726
+ marginLeft: "auto"
727
+ },
728
+ children: clearing ? t("form.clearing") : t("form.clear")
729
+ })
730
+ ]
951
731
  })
952
732
  ]
953
733
  })
@@ -962,13 +742,15 @@ let nextKey = 0;
962
742
  * Build an interaction for one session.
963
743
  *
964
744
  * @param sessionId - the conversation the form belongs to.
745
+ * @param manual - true when a chip opened the form (no request behind it).
965
746
  */
966
- function credentialFormInteraction(sessionId) {
747
+ function credentialFormInteraction(sessionId, manual) {
967
748
  nextKey += 1;
968
749
  return {
969
750
  kind: "aishell-credential-form",
970
751
  key: `aishell-credential-form:${String(nextKey)}`,
971
- sessionId
752
+ sessionId,
753
+ manual
972
754
  };
973
755
  }
974
756
  /**
@@ -1003,24 +785,44 @@ const DISMISS_ROUTE = "api/aishell/credentials/dismiss";
1003
785
  function createCredentialFormVisibility(publish) {
1004
786
  let open;
1005
787
  let withdraw;
788
+ let manual = false;
1006
789
  const clear = () => {
1007
790
  withdraw?.();
1008
791
  withdraw = void 0;
1009
792
  open = void 0;
793
+ manual = false;
794
+ };
795
+ const publishFor = (sessionId, isManual) => {
796
+ withdraw?.();
797
+ const interaction = credentialFormInteraction(sessionId, isManual);
798
+ open = interaction;
799
+ manual = isManual;
800
+ withdraw = publish(interaction);
801
+ return interaction;
1010
802
  };
1011
803
  return {
1012
804
  current: () => open,
805
+ manual: () => manual && open !== void 0,
1013
806
  sync: (sessionId) => {
1014
807
  if (sessionId === "") {
1015
808
  if (open === void 0) return;
1016
809
  clear();
1017
810
  return;
1018
811
  }
1019
- if (open?.sessionId === sessionId) return;
1020
- withdraw?.();
1021
- const interaction = credentialFormInteraction(sessionId);
1022
- open = interaction;
1023
- withdraw = publish(interaction);
812
+ if (open?.sessionId === sessionId) {
813
+ if (!manual) return;
814
+ publishFor(sessionId, false);
815
+ return;
816
+ }
817
+ publishFor(sessionId, false);
818
+ },
819
+ open: (sessionId) => {
820
+ if (open !== void 0) return;
821
+ publishFor(sessionId, true);
822
+ },
823
+ close: () => {
824
+ if (open === void 0 || !manual) return;
825
+ clear();
1024
826
  },
1025
827
  dispose: () => {
1026
828
  if (open === void 0) return;
@@ -1040,7 +842,7 @@ function createCredentialFormVisibility(publish) {
1040
842
  const NS = "aishell";
1041
843
  /** Simplified Chinese dictionary (the key-set source of truth). */
1042
844
  const zh = {
1043
- "account.unconfigured": "未配置华为云 IAM 凭据",
845
+ "account.unconfigured": "未配置凭据",
1044
846
  "mode.readonly": "只读",
1045
847
  "mode.readwrite": "读写",
1046
848
  "mode.unavailable": "权限模式不可用",
@@ -1049,19 +851,21 @@ const zh = {
1049
851
  "mode.unavailable.hint": "无法从 MCP 服务器读取权限模式;切换按钮暂不可用",
1050
852
  "mode.switchToReadonly": "切换为只读模式",
1051
853
  "mode.switchToReadwrite": "切换为读写模式",
1052
- "section.settings.summary": "华为云 AI Shell 设置。",
1053
- "section.credentials.title": "凭据",
1054
854
  "section.credentials.hint.prefix": "需要进行华为云 IAM 认证,建议从",
1055
855
  "section.credentials.hint.link": "API Explorer",
1056
856
  "section.credentials.hint.suffix": "获取临时凭据,避免使用永久凭据。",
1057
- "section.credentials.saved": "校验通过,已存入 keyring。",
1058
- "section.credentials.save": "保存",
1059
857
  "section.credentials.saving": "保存中…",
1060
- "section.credentials.clear": "清除",
1061
858
  "form.title": "需要华为云凭据",
859
+ "form.title.manual": "配置华为云凭据",
1062
860
  "form.submit": "提交",
1063
861
  "form.dismiss": "取消",
1064
862
  "form.failed": "保存凭据失败",
863
+ "form.clear": "清除",
864
+ "form.clearing": "清除中…",
865
+ "form.clear.failed": "清除凭据失败",
866
+ "error.unreachable": "无法连接宿主凭据服务:",
867
+ "error.clear.serverFailed": "本机凭据已清除,但服务端凭据未清除(HTTP {status})",
868
+ "error.clear.serverUnreachable": "本机凭据已清除,但无法连接 MCP 服务器清除服务端凭据:",
1065
869
  "section.field.accessKey": "Access Key",
1066
870
  "section.field.accessKey.placeholder": "华为云 Access Key",
1067
871
  "section.field.accessKey.hint": "Access Key 与 Secret Key 须同时填写,只填其一时不会保存。",
@@ -1074,7 +878,7 @@ const zh = {
1074
878
  };
1075
879
  /** English dictionary. */
1076
880
  const en = {
1077
- "account.unconfigured": "No Huawei Cloud IAM credentials",
881
+ "account.unconfigured": "No credentials",
1078
882
  "mode.readonly": "Read-only",
1079
883
  "mode.readwrite": "Read-write",
1080
884
  "mode.unavailable": "Mode unavailable",
@@ -1083,19 +887,21 @@ const en = {
1083
887
  "mode.unavailable.hint": "Could not read the permission mode from the MCP server; the toggle is unavailable",
1084
888
  "mode.switchToReadonly": "Switch to read-only mode",
1085
889
  "mode.switchToReadwrite": "Switch to read-write mode",
1086
- "section.settings.summary": "Huawei Cloud AI Shell settings.",
1087
- "section.credentials.title": "Credentials",
1088
890
  "section.credentials.hint.prefix": "Authenticate against Huawei Cloud IAM. Obtain temporary credentials from",
1089
891
  "section.credentials.hint.link": "API Explorer",
1090
892
  "section.credentials.hint.suffix": "and avoid permanent ones.",
1091
- "section.credentials.saved": "Verified and saved to keyring.",
1092
- "section.credentials.save": "Save",
1093
893
  "section.credentials.saving": "Saving…",
1094
- "section.credentials.clear": "Clear",
1095
894
  "form.title": "Huawei Cloud credentials required",
895
+ "form.title.manual": "Configure Huawei Cloud credentials",
1096
896
  "form.submit": "Submit",
1097
897
  "form.dismiss": "Cancel",
1098
898
  "form.failed": "Could not save credentials",
899
+ "form.clear": "Clear",
900
+ "form.clearing": "Clearing…",
901
+ "form.clear.failed": "Could not clear credentials",
902
+ "error.unreachable": "Could not reach the host credential service: ",
903
+ "error.clear.serverFailed": "Local credentials were cleared, but the server copy was not (HTTP {status})",
904
+ "error.clear.serverUnreachable": "Local credentials were cleared, but the MCP server could not be reached to clear the server copy: ",
1099
905
  "section.field.accessKey": "Access Key",
1100
906
  "section.field.accessKey.placeholder": "Huawei Access Key",
1101
907
  "section.field.accessKey.hint": "Access Key and Secret Key are stored as a pair; one without the other is not saved.",
@@ -1127,7 +933,7 @@ const CLEAR_ROUTE = "api/aishell/credentials/clear";
1127
933
  * Clearing is a two-store operation: this plugin's store (CLEAR_ROUTE) and the
1128
934
  * MCP server's, which keeps its own copy scoped to this client. Only the first
1129
935
  * 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
936
+ * state it left — the chip showing "no credentials" while cloud calls still
1131
937
  * worked — is the bug this fixes.
1132
938
  *
1133
939
  * An absolute host route owned by another package, reached the same way the
@@ -1138,8 +944,11 @@ const SERVER_CREDENTIALS_ROUTE = "api/aishell/credentials/reset";
1138
944
  * POST one JSON body to a Host credential route and read back its verdict.
1139
945
  * A non-JSON or unreadable body is reported as a transport failure rather than
1140
946
  * thrown, so the form shows a message instead of an unhandled rejection.
947
+ *
948
+ * @param t - the form's translator; the failure copy is user-visible, so it
949
+ * follows the active locale like every other string in the form.
1141
950
  */
1142
- async function postJson(route, body) {
951
+ async function postJson(route, t, body) {
1143
952
  try {
1144
953
  const response = await fetch(route, {
1145
954
  method: "POST",
@@ -1153,26 +962,22 @@ async function postJson(route, body) {
1153
962
  } catch (error) {
1154
963
  return {
1155
964
  ok: false,
1156
- error: `无法连接宿主凭据服务:${error instanceof Error ? error.message : String(error)}`
965
+ error: t("error.unreachable") + (error instanceof Error ? error.message : String(error))
1157
966
  };
1158
967
  }
1159
968
  }
1160
969
  /**
1161
970
  * Store one credential through the Host route.
1162
971
  *
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.
972
+ * Both ways the form comes up — a chip click and a blocked MCP call — go
973
+ * through this, so there is exactly one body shape for the credential route.
1169
974
  *
1170
975
  * An absent SecurityToken is omitted rather than sent empty: the Host reads an
1171
976
  * empty string as absent anyway, so sending it would only make the wire shape
1172
977
  * depend on which form was used.
1173
978
  */
1174
- function saveCredential(accessKeyId, secretAccessKey, securityToken) {
1175
- return postJson(CREDENTIALS_ROUTE, {
979
+ function saveCredential(t, accessKeyId, secretAccessKey, securityToken) {
980
+ return postJson(CREDENTIALS_ROUTE, t, {
1176
981
  accessKeyId,
1177
982
  secretAccessKey,
1178
983
  ...securityToken === void 0 ? {} : { securityToken }
@@ -1184,16 +989,18 @@ function saveCredential(accessKeyId, secretAccessKey, securityToken) {
1184
989
  * The order matters: this plugin's store goes first, because it is the one
1185
990
  * whose absence *stops* the chat from authenticating. A failure there leaves
1186
991
  * 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
992
+ * second leaves a state the user can still act on — no credentials locally, a
993
+ * server copy that a second attempt or a server restart will clear — which is
1189
994
  * why the message names which half failed rather than saying "clear failed".
1190
995
  *
1191
996
  * The second store is best-effort by design: if the MCP server is unreachable
1192
997
  * or older than `credential/reset`, the local clear has already succeeded and
1193
998
  * saying so is more accurate than reporting the whole action as failed.
999
+ *
1000
+ * @param t - the form's translator; the failure copy is user-visible.
1194
1001
  */
1195
- async function clearBothStores() {
1196
- const local = await postJson(CLEAR_ROUTE);
1002
+ async function clearBothStores(t) {
1003
+ const local = await postJson(CLEAR_ROUTE, t);
1197
1004
  if (!local.ok) return local;
1198
1005
  try {
1199
1006
  const response = await fetch(SERVER_CREDENTIALS_ROUTE, { method: "POST" });
@@ -1201,13 +1008,13 @@ async function clearBothStores() {
1201
1008
  const body = await response.json();
1202
1009
  return {
1203
1010
  ok: false,
1204
- error: typeof body.error === "string" ? body.error : `本机凭据已清除,但服务端凭据未清除(HTTP ${response.status})`
1011
+ error: typeof body.error === "string" ? body.error : t("error.clear.serverFailed", { status: String(response.status) })
1205
1012
  };
1206
1013
  }
1207
1014
  } catch (error) {
1208
1015
  return {
1209
1016
  ok: false,
1210
- error: "本机凭据已清除,但无法连接 MCP 服务器清除服务端凭据:" + (error instanceof Error ? error.message : String(error))
1017
+ error: t("error.clear.serverUnreachable") + (error instanceof Error ? error.message : String(error))
1211
1018
  };
1212
1019
  }
1213
1020
  return { ok: true };
@@ -1225,6 +1032,7 @@ function apply(ctx) {
1225
1032
  en
1226
1033
  }), "aishell-credentials: dictionaries");
1227
1034
  const t = ctx.locale.bind(NS);
1035
+ installChipStyles(ctx);
1228
1036
  const form = ctx.configForms.get(AISHELL_CREDENTIALS_NS);
1229
1037
  const status = (0, __deepseek_ai_dsh_client_store.createSnapshotStore)({
1230
1038
  hasAccessKey: false,
@@ -1246,35 +1054,41 @@ function apply(ctx) {
1246
1054
  };
1247
1055
  ctx.effect(() => form.subscribe(derive), "aishell-credentials: credential presence");
1248
1056
  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");
1057
+ const publishCredentialForm = ctx.uiSession.registerPendingInteraction(() => 0);
1058
+ const visibility = createCredentialFormVisibility((interaction) => publishCredentialForm(interaction, () => Promise.resolve()));
1059
+ const syncCredentialForm = () => {
1060
+ visibility.sync(form.getSnapshot().value?.credentialRequestSession ?? "");
1061
+ };
1062
+ ctx.effect(() => form.subscribe(syncCredentialForm), "aishell-credentials: credential form visibility");
1063
+ syncCredentialForm();
1064
+ ctx.effect(() => () => {
1065
+ visibility.dispose();
1066
+ }, "aishell-credentials: credential form teardown");
1262
1067
  ctx.effect(() => ctx.slots.inject("conversation.composer.dock", () => ctx.slots.register({
1263
1068
  name: "conversation.composer.dock",
1264
1069
  id: "aishell-account",
1265
1070
  order: 30,
1266
1071
  locale: NS,
1267
- inject: () => ({
1072
+ inject: (sessionId) => ({
1268
1073
  hooks: { credentials: status },
1269
- t
1074
+ t,
1075
+ openCredentialForm: () => {
1076
+ visibility.open(sessionId);
1077
+ }
1270
1078
  })
1271
1079
  }, AishellAccountHint)), "aishell-credentials: account hint chip");
1272
- ctx.effect(() => ctx.slots.inject("conversation.hero.workspace", () => {
1080
+ ctx.effect(() => ctx.slots.inject("conversation.input.dock", () => {
1273
1081
  const dispose = ctx.slots.register({
1274
- name: "conversation.hero.workspace",
1275
- priority: -1,
1082
+ name: "conversation.input.dock",
1083
+ id: "aishell-hero",
1084
+ order: 10,
1276
1085
  locale: NS,
1277
- inject: () => ({ hooks: { credentials: status } })
1086
+ inject: (sessionId) => ({
1087
+ hooks: { credentials: status },
1088
+ openCredentialForm: () => {
1089
+ visibility.open(sessionId);
1090
+ }
1091
+ })
1278
1092
  }, AishellHeroChip);
1279
1093
  return dispose;
1280
1094
  }), "aishell-credentials: hero account chip");
@@ -1283,22 +1097,17 @@ function apply(ctx) {
1283
1097
  select: ({ pendingInteraction }) => isCredentialForm(pendingInteraction) ? pendingInteraction : null,
1284
1098
  locale: NS,
1285
1099
  inject: () => ({
1286
- save: saveCredential,
1100
+ hooks: { credentials: status },
1101
+ save: (ak, sk, token) => saveCredential(t, ak, sk, token),
1102
+ clear: () => clearBothStores(t),
1287
1103
  dismiss: () => {
1288
1104
  fetch(DISMISS_ROUTE, { method: "POST" });
1105
+ },
1106
+ closeManual: () => {
1107
+ visibility.close();
1289
1108
  }
1290
1109
  })
1291
1110
  }, 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
1111
  }
1303
1112
 
1304
1113
  //#endregion