@huaweidevtools/aishell-dsh-client-credentials 0.0.1-beta.1 → 0.0.1-beta.3
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/LICENSE +1 -1
- package/lib/client.js +323 -541
- package/lib/index.js +463 -122
- package/lib/types/auth-tool.d.ts +98 -0
- package/lib/types/client/AishellAccountHint.d.ts +10 -3
- package/lib/types/client/AishellHeroChip.d.ts +22 -11
- package/lib/types/client/CredentialFormInteraction.d.ts +4 -12
- package/lib/types/client/CredentialRequestForm.d.ts +53 -16
- package/lib/types/client/credential-form-visibility.d.ts +30 -17
- package/lib/types/client/credential-status.d.ts +5 -6
- package/lib/types/client/huawei-mark.d.ts +18 -6
- package/lib/types/client/index.d.ts +9 -5
- package/lib/types/client/locales.d.ts +14 -14
- package/lib/types/client/permission-mode.d.ts +3 -3
- package/lib/types/form-request.d.ts +90 -0
- package/lib/types/index.d.ts +24 -50
- package/lib/types/reconcile.d.ts +80 -0
- package/package.json +17 -14
- package/lib/types/client/AishellCredentialsSection.d.ts +0 -34
- package/lib/types/client/open-settings.d.ts +0 -27
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
|
-
*
|
|
486
|
-
*
|
|
487
|
-
*
|
|
488
|
-
*
|
|
489
|
-
*
|
|
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
|
-
|
|
493
|
-
|
|
494
|
-
|
|
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
|
-
*
|
|
150
|
+
* Mount the chips' hover/focus rule for the owning plugin's lifetime.
|
|
505
151
|
*
|
|
506
|
-
*
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
* `
|
|
510
|
-
*
|
|
511
|
-
*
|
|
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.
|
|
512
161
|
*
|
|
513
|
-
*
|
|
514
|
-
*
|
|
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.
|
|
515
165
|
*
|
|
516
|
-
* @
|
|
166
|
+
* @param ctx - the browser-half plugin context whose effect owns the tag.
|
|
517
167
|
*/
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
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();
|
|
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
|
|
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:
|
|
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
|
|
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
|
-
|
|
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:
|
|
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,22 +440,42 @@ 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
|
/**
|
|
739
463
|
* The masked credential form.
|
|
740
464
|
*
|
|
741
|
-
* Submitting saves through the Host route; the
|
|
742
|
-
*
|
|
743
|
-
*
|
|
465
|
+
* Submitting saves through the Host route; the form then closes itself, and the
|
|
466
|
+
* chip flipping to the account name is the feedback that it worked. There is no
|
|
467
|
+
* request behind an open form — a chip opened it — so nothing else takes it
|
|
468
|
+
* down.
|
|
744
469
|
*/
|
|
745
470
|
function CredentialRequestForm(props) {
|
|
746
471
|
const t = props.t;
|
|
747
|
-
const { save,
|
|
472
|
+
const { save, clear, close, cancel } = props;
|
|
473
|
+
const status = props.useCredentials((snapshot) => snapshot);
|
|
748
474
|
const [ak, setAk] = (0, react.useState)("");
|
|
749
475
|
const [sk, setSk] = (0, react.useState)("");
|
|
750
476
|
const [token, setToken] = (0, react.useState)("");
|
|
751
477
|
const [saving, setSaving] = (0, react.useState)(false);
|
|
478
|
+
const [clearing, setClearing] = (0, react.useState)(false);
|
|
752
479
|
const [error, setError] = (0, react.useState)(void 0);
|
|
753
480
|
const onSubmit = async (event) => {
|
|
754
481
|
event.preventDefault();
|
|
@@ -763,12 +490,28 @@ function CredentialRequestForm(props) {
|
|
|
763
490
|
setAk("");
|
|
764
491
|
setSk("");
|
|
765
492
|
setToken("");
|
|
493
|
+
close();
|
|
766
494
|
} catch (err) {
|
|
767
495
|
setError(err instanceof Error ? err.message : String(err));
|
|
768
496
|
} finally {
|
|
769
497
|
setSaving(false);
|
|
770
498
|
}
|
|
771
499
|
};
|
|
500
|
+
const onClear = async () => {
|
|
501
|
+
setClearing(true);
|
|
502
|
+
setError(void 0);
|
|
503
|
+
try {
|
|
504
|
+
const verdict = await clear();
|
|
505
|
+
if (!verdict.ok) setError(verdict.error ?? t("form.clear.failed"));
|
|
506
|
+
} catch (err) {
|
|
507
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
508
|
+
} finally {
|
|
509
|
+
setClearing(false);
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
const onCancel = () => {
|
|
513
|
+
cancel();
|
|
514
|
+
};
|
|
772
515
|
const fieldStyle = {
|
|
773
516
|
display: "flex",
|
|
774
517
|
flexDirection: "column",
|
|
@@ -806,10 +549,12 @@ function CredentialRequestForm(props) {
|
|
|
806
549
|
cursor: disabled$1 ? "default" : "pointer",
|
|
807
550
|
opacity: disabled$1 ? .5 : 1
|
|
808
551
|
});
|
|
809
|
-
const
|
|
552
|
+
const busy = saving || clearing;
|
|
553
|
+
const disabled = busy || !ak || !sk;
|
|
554
|
+
const hasCredentials = status.hasAccessKey || status.hasSecretKey;
|
|
810
555
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
811
556
|
role: "group",
|
|
812
|
-
"aria-label": t("form.title"),
|
|
557
|
+
"aria-label": t("form.title.manual"),
|
|
813
558
|
style: {
|
|
814
559
|
padding: "6px calc(var(--dsh-composer-side-clearance) + 16px) 10px",
|
|
815
560
|
display: "flex",
|
|
@@ -842,7 +587,7 @@ function CredentialRequestForm(props) {
|
|
|
842
587
|
fontWeight: 500,
|
|
843
588
|
lineHeight: "22px"
|
|
844
589
|
},
|
|
845
|
-
children: t("form.title")
|
|
590
|
+
children: t("form.title.manual")
|
|
846
591
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
847
592
|
style: {
|
|
848
593
|
fontSize: 12,
|
|
@@ -869,9 +614,19 @@ function CredentialRequestForm(props) {
|
|
|
869
614
|
}),
|
|
870
615
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
871
616
|
style: fieldStyle,
|
|
872
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.
|
|
617
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
873
618
|
style: labelStyle,
|
|
874
|
-
children: t("section.field.accessKey")
|
|
619
|
+
children: [t("section.field.accessKey"), status.accessKeyIdHint && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
620
|
+
style: {
|
|
621
|
+
color: "var(--dsw-alias-label-tertiary)",
|
|
622
|
+
fontWeight: 400
|
|
623
|
+
},
|
|
624
|
+
children: [
|
|
625
|
+
"(",
|
|
626
|
+
status.accessKeyIdHint,
|
|
627
|
+
")"
|
|
628
|
+
]
|
|
629
|
+
})]
|
|
875
630
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
876
631
|
type: "password",
|
|
877
632
|
value: ak,
|
|
@@ -927,27 +682,45 @@ function CredentialRequestForm(props) {
|
|
|
927
682
|
display: "flex",
|
|
928
683
|
gap: 8
|
|
929
684
|
},
|
|
930
|
-
children: [
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
685
|
+
children: [
|
|
686
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
687
|
+
type: "submit",
|
|
688
|
+
disabled,
|
|
689
|
+
style: {
|
|
690
|
+
...buttonStyle(disabled),
|
|
691
|
+
background: "var(--dsw-alias-button-primary-fill)",
|
|
692
|
+
color: "var(--dsw-alias-label-primary-foreground)"
|
|
693
|
+
},
|
|
694
|
+
children: saving ? t("section.credentials.saving") : t("form.submit")
|
|
695
|
+
}),
|
|
696
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
697
|
+
type: "button",
|
|
698
|
+
onClick: onCancel,
|
|
699
|
+
disabled: busy,
|
|
700
|
+
style: {
|
|
701
|
+
...buttonStyle(busy),
|
|
702
|
+
background: "transparent",
|
|
703
|
+
color: "var(--dsw-alias-label-primary)",
|
|
704
|
+
border: "0.5px solid var(--dsw-alias-border-l4)"
|
|
705
|
+
},
|
|
706
|
+
children: t("form.dismiss")
|
|
707
|
+
}),
|
|
708
|
+
hasCredentials && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
709
|
+
type: "button",
|
|
710
|
+
onClick: () => {
|
|
711
|
+
onClear();
|
|
712
|
+
},
|
|
713
|
+
disabled: busy,
|
|
714
|
+
style: {
|
|
715
|
+
...buttonStyle(busy),
|
|
716
|
+
background: "transparent",
|
|
717
|
+
color: "var(--dsw-alias-label-primary)",
|
|
718
|
+
border: "0.5px solid var(--dsw-alias-border-l4)",
|
|
719
|
+
marginLeft: "auto"
|
|
720
|
+
},
|
|
721
|
+
children: clearing ? t("form.clearing") : t("form.clear")
|
|
722
|
+
})
|
|
723
|
+
]
|
|
951
724
|
})
|
|
952
725
|
]
|
|
953
726
|
})
|
|
@@ -983,15 +756,35 @@ function credentialFormInteraction(sessionId) {
|
|
|
983
756
|
function isCredentialForm(value) {
|
|
984
757
|
return value?.kind === "aishell-credential-form";
|
|
985
758
|
}
|
|
759
|
+
|
|
760
|
+
//#endregion
|
|
761
|
+
//#region src/form-request.ts
|
|
986
762
|
/**
|
|
987
|
-
*
|
|
763
|
+
* Read a request back out of the document.
|
|
764
|
+
*
|
|
765
|
+
* Anything unreadable reads as no request: a corrupt field should show nothing,
|
|
766
|
+
* not open a form bound to a session that does not exist.
|
|
988
767
|
*
|
|
989
|
-
*
|
|
990
|
-
*
|
|
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.
|
|
768
|
+
* @param raw - the stored string, if any.
|
|
769
|
+
* @returns the request, or `undefined` when there is none usable.
|
|
993
770
|
*/
|
|
994
|
-
|
|
771
|
+
function decodeRequest(raw) {
|
|
772
|
+
if (raw === void 0 || raw === "") return void 0;
|
|
773
|
+
let parsed;
|
|
774
|
+
try {
|
|
775
|
+
parsed = JSON.parse(raw);
|
|
776
|
+
} catch {
|
|
777
|
+
return void 0;
|
|
778
|
+
}
|
|
779
|
+
if (parsed === null || typeof parsed !== "object") return void 0;
|
|
780
|
+
const candidate = parsed;
|
|
781
|
+
if (typeof candidate.token !== "string" || candidate.token === "") return void 0;
|
|
782
|
+
if (typeof candidate.sessionId !== "string" || candidate.sessionId === "") return void 0;
|
|
783
|
+
return {
|
|
784
|
+
token: candidate.token,
|
|
785
|
+
sessionId: candidate.sessionId
|
|
786
|
+
};
|
|
787
|
+
}
|
|
995
788
|
|
|
996
789
|
//#endregion
|
|
997
790
|
//#region src/client/credential-form-visibility.ts
|
|
@@ -1010,18 +803,16 @@ function createCredentialFormVisibility(publish) {
|
|
|
1010
803
|
};
|
|
1011
804
|
return {
|
|
1012
805
|
current: () => open,
|
|
1013
|
-
|
|
1014
|
-
if (
|
|
1015
|
-
if (open === void 0) return;
|
|
1016
|
-
clear();
|
|
1017
|
-
return;
|
|
1018
|
-
}
|
|
1019
|
-
if (open?.sessionId === sessionId) return;
|
|
1020
|
-
withdraw?.();
|
|
806
|
+
open: (sessionId) => {
|
|
807
|
+
if (open !== void 0) return;
|
|
1021
808
|
const interaction = credentialFormInteraction(sessionId);
|
|
1022
809
|
open = interaction;
|
|
1023
810
|
withdraw = publish(interaction);
|
|
1024
811
|
},
|
|
812
|
+
close: () => {
|
|
813
|
+
if (open === void 0) return;
|
|
814
|
+
clear();
|
|
815
|
+
},
|
|
1025
816
|
dispose: () => {
|
|
1026
817
|
if (open === void 0) return;
|
|
1027
818
|
clear();
|
|
@@ -1040,28 +831,28 @@ function createCredentialFormVisibility(publish) {
|
|
|
1040
831
|
const NS = "aishell";
|
|
1041
832
|
/** Simplified Chinese dictionary (the key-set source of truth). */
|
|
1042
833
|
const zh = {
|
|
1043
|
-
"account.unconfigured": "
|
|
834
|
+
"account.unconfigured": "未配置凭据",
|
|
1044
835
|
"mode.readonly": "只读",
|
|
1045
836
|
"mode.readwrite": "读写",
|
|
1046
837
|
"mode.unavailable": "权限模式不可用",
|
|
1047
838
|
"mode.readonly.hint": "当前:只读 — 只允许查询云资源,点击切换为读写",
|
|
1048
839
|
"mode.readwrite.hint": "当前:读写 — 允许变更云资源,点击切换为只读",
|
|
1049
|
-
"mode.unavailable.hint": "
|
|
840
|
+
"mode.unavailable.hint": "无法读取权限模式;切换按钮暂不可用",
|
|
1050
841
|
"mode.switchToReadonly": "切换为只读模式",
|
|
1051
842
|
"mode.switchToReadwrite": "切换为读写模式",
|
|
1052
|
-
"section.settings.summary": "华为云 AI Shell 设置。",
|
|
1053
|
-
"section.credentials.title": "凭据",
|
|
1054
843
|
"section.credentials.hint.prefix": "需要进行华为云 IAM 认证,建议从",
|
|
1055
844
|
"section.credentials.hint.link": "API Explorer",
|
|
1056
845
|
"section.credentials.hint.suffix": "获取临时凭据,避免使用永久凭据。",
|
|
1057
|
-
"section.credentials.saved": "校验通过,已存入 keyring。",
|
|
1058
|
-
"section.credentials.save": "保存",
|
|
1059
846
|
"section.credentials.saving": "保存中…",
|
|
1060
|
-
"section.credentials.clear": "清除",
|
|
1061
847
|
"form.title": "需要华为云凭据",
|
|
848
|
+
"form.title.manual": "配置华为云凭据",
|
|
1062
849
|
"form.submit": "提交",
|
|
1063
850
|
"form.dismiss": "取消",
|
|
1064
851
|
"form.failed": "保存凭据失败",
|
|
852
|
+
"form.clear": "清除",
|
|
853
|
+
"form.clearing": "清除中…",
|
|
854
|
+
"form.clear.failed": "清除凭据失败",
|
|
855
|
+
"error.unreachable": "无法连接宿主凭据服务:",
|
|
1065
856
|
"section.field.accessKey": "Access Key",
|
|
1066
857
|
"section.field.accessKey.placeholder": "华为云 Access Key",
|
|
1067
858
|
"section.field.accessKey.hint": "Access Key 与 Secret Key 须同时填写,只填其一时不会保存。",
|
|
@@ -1074,28 +865,28 @@ const zh = {
|
|
|
1074
865
|
};
|
|
1075
866
|
/** English dictionary. */
|
|
1076
867
|
const en = {
|
|
1077
|
-
"account.unconfigured": "No
|
|
868
|
+
"account.unconfigured": "No credentials",
|
|
1078
869
|
"mode.readonly": "Read-only",
|
|
1079
870
|
"mode.readwrite": "Read-write",
|
|
1080
871
|
"mode.unavailable": "Mode unavailable",
|
|
1081
872
|
"mode.readonly.hint": "Read-only — cloud queries only. Click for read-write",
|
|
1082
873
|
"mode.readwrite.hint": "Read-write — cloud changes allowed. Click for read-only",
|
|
1083
|
-
"mode.unavailable.hint": "Could not read the permission mode
|
|
874
|
+
"mode.unavailable.hint": "Could not read the permission mode; the toggle is unavailable",
|
|
1084
875
|
"mode.switchToReadonly": "Switch to read-only mode",
|
|
1085
876
|
"mode.switchToReadwrite": "Switch to read-write mode",
|
|
1086
|
-
"section.settings.summary": "Huawei Cloud AI Shell settings.",
|
|
1087
|
-
"section.credentials.title": "Credentials",
|
|
1088
877
|
"section.credentials.hint.prefix": "Authenticate against Huawei Cloud IAM. Obtain temporary credentials from",
|
|
1089
878
|
"section.credentials.hint.link": "API Explorer",
|
|
1090
879
|
"section.credentials.hint.suffix": "and avoid permanent ones.",
|
|
1091
|
-
"section.credentials.saved": "Verified and saved to keyring.",
|
|
1092
|
-
"section.credentials.save": "Save",
|
|
1093
880
|
"section.credentials.saving": "Saving…",
|
|
1094
|
-
"section.credentials.clear": "Clear",
|
|
1095
881
|
"form.title": "Huawei Cloud credentials required",
|
|
882
|
+
"form.title.manual": "Configure Huawei Cloud credentials",
|
|
1096
883
|
"form.submit": "Submit",
|
|
1097
884
|
"form.dismiss": "Cancel",
|
|
1098
885
|
"form.failed": "Could not save credentials",
|
|
886
|
+
"form.clear": "Clear",
|
|
887
|
+
"form.clearing": "Clearing…",
|
|
888
|
+
"form.clear.failed": "Could not clear credentials",
|
|
889
|
+
"error.unreachable": "Could not reach the host credential service: ",
|
|
1099
890
|
"section.field.accessKey": "Access Key",
|
|
1100
891
|
"section.field.accessKey.placeholder": "Huawei Access Key",
|
|
1101
892
|
"section.field.accessKey.hint": "Access Key and Secret Key are stored as a pair; one without the other is not saved.",
|
|
@@ -1120,26 +911,17 @@ const AISHELL_CREDENTIALS_NS = "aishell-client-credentials";
|
|
|
1120
911
|
const CREDENTIALS_ROUTE = "api/aishell/credentials";
|
|
1121
912
|
/** Clear route; the Host's fetch registry has no DELETE, so clearing is a POST. */
|
|
1122
913
|
const CLEAR_ROUTE = "api/aishell/credentials/clear";
|
|
1123
|
-
/**
|
|
1124
|
-
|
|
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";
|
|
914
|
+
/** Cancel route; names the request token the person declined. */
|
|
915
|
+
const CANCEL_ROUTE = "api/aishell/credentials/cancel";
|
|
1137
916
|
/**
|
|
1138
917
|
* POST one JSON body to a Host credential route and read back its verdict.
|
|
1139
918
|
* A non-JSON or unreadable body is reported as a transport failure rather than
|
|
1140
919
|
* thrown, so the form shows a message instead of an unhandled rejection.
|
|
920
|
+
*
|
|
921
|
+
* @param t - the form's translator; the failure copy is user-visible, so it
|
|
922
|
+
* follows the active locale like every other string in the form.
|
|
1141
923
|
*/
|
|
1142
|
-
async function postJson(route, body) {
|
|
924
|
+
async function postJson(route, t, body) {
|
|
1143
925
|
try {
|
|
1144
926
|
const response = await fetch(route, {
|
|
1145
927
|
method: "POST",
|
|
@@ -1153,64 +935,38 @@ async function postJson(route, body) {
|
|
|
1153
935
|
} catch (error) {
|
|
1154
936
|
return {
|
|
1155
937
|
ok: false,
|
|
1156
|
-
error:
|
|
938
|
+
error: t("error.unreachable") + (error instanceof Error ? error.message : String(error))
|
|
1157
939
|
};
|
|
1158
940
|
}
|
|
1159
941
|
}
|
|
1160
942
|
/**
|
|
1161
943
|
* Store one credential through the Host route.
|
|
1162
944
|
*
|
|
1163
|
-
* Both
|
|
1164
|
-
*
|
|
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.
|
|
945
|
+
* Both ways the form comes up — a chip click and a blocked tool call — go
|
|
946
|
+
* through this, so there is exactly one body shape for the credential route.
|
|
1169
947
|
*
|
|
1170
948
|
* An absent SecurityToken is omitted rather than sent empty: the Host reads an
|
|
1171
949
|
* empty string as absent anyway, so sending it would only make the wire shape
|
|
1172
950
|
* depend on which form was used.
|
|
1173
951
|
*/
|
|
1174
|
-
function saveCredential(accessKeyId, secretAccessKey, securityToken) {
|
|
1175
|
-
return postJson(CREDENTIALS_ROUTE, {
|
|
952
|
+
function saveCredential(t, accessKeyId, secretAccessKey, securityToken) {
|
|
953
|
+
return postJson(CREDENTIALS_ROUTE, t, {
|
|
1176
954
|
accessKeyId,
|
|
1177
955
|
secretAccessKey,
|
|
1178
956
|
...securityToken === void 0 ? {} : { securityToken }
|
|
1179
957
|
});
|
|
1180
958
|
}
|
|
1181
959
|
/**
|
|
1182
|
-
* Clear
|
|
960
|
+
* Clear the stored credentials.
|
|
1183
961
|
*
|
|
1184
|
-
*
|
|
1185
|
-
*
|
|
1186
|
-
*
|
|
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".
|
|
962
|
+
* One store, one write: the credentials live in the host's keyring and nowhere
|
|
963
|
+
* else, so this is the local clear and its failure is the only one there is to
|
|
964
|
+
* report.
|
|
1190
965
|
*
|
|
1191
|
-
*
|
|
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.
|
|
966
|
+
* @param t - the form's translator; the failure copy is user-visible.
|
|
1194
967
|
*/
|
|
1195
|
-
async function clearBothStores() {
|
|
1196
|
-
|
|
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 };
|
|
968
|
+
async function clearBothStores(t) {
|
|
969
|
+
return postJson(CLEAR_ROUTE, t);
|
|
1214
970
|
}
|
|
1215
971
|
/** Required services. */
|
|
1216
972
|
const inject = [
|
|
@@ -1225,6 +981,7 @@ function apply(ctx) {
|
|
|
1225
981
|
en
|
|
1226
982
|
}), "aishell-credentials: dictionaries");
|
|
1227
983
|
const t = ctx.locale.bind(NS);
|
|
984
|
+
installChipStyles(ctx);
|
|
1228
985
|
const form = ctx.configForms.get(AISHELL_CREDENTIALS_NS);
|
|
1229
986
|
const status = (0, __deepseek_ai_dsh_client_store.createSnapshotStore)({
|
|
1230
987
|
hasAccessKey: false,
|
|
@@ -1246,35 +1003,64 @@ function apply(ctx) {
|
|
|
1246
1003
|
};
|
|
1247
1004
|
ctx.effect(() => form.subscribe(derive), "aishell-credentials: credential presence");
|
|
1248
1005
|
derive();
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1006
|
+
const publishCredentialForm = ctx.uiSession.registerPendingInteraction(() => 0);
|
|
1007
|
+
const visibility = createCredentialFormVisibility((interaction) => publishCredentialForm(interaction, () => Promise.resolve()));
|
|
1008
|
+
let lastRequestToken;
|
|
1009
|
+
const applyFormRequest = () => {
|
|
1010
|
+
const request = decodeRequest(form.getSnapshot().value?.credentialFormRequest);
|
|
1011
|
+
if (request === void 0 || request.token === lastRequestToken) return;
|
|
1012
|
+
lastRequestToken = request.token;
|
|
1013
|
+
visibility.open(request.sessionId);
|
|
1014
|
+
pendingRequestToken = request.token;
|
|
1015
|
+
};
|
|
1016
|
+
let pendingRequestToken;
|
|
1017
|
+
ctx.effect(() => form.subscribe(applyFormRequest), "aishell-credentials: form requests");
|
|
1018
|
+
applyFormRequest();
|
|
1019
|
+
ctx.effect(() => () => {
|
|
1020
|
+
visibility.dispose();
|
|
1021
|
+
}, "aishell-credentials: credential form teardown");
|
|
1022
|
+
/**
|
|
1023
|
+
* Record a cancel against the request it belongs to.
|
|
1024
|
+
*
|
|
1025
|
+
* Only when this form was opened by a request: a chip-opened form has no
|
|
1026
|
+
* request behind it, and recording a cancel for one would make the *next*
|
|
1027
|
+
* `auth` call believe the person refused a question nobody asked.
|
|
1028
|
+
*/
|
|
1029
|
+
const cancelRequest = () => {
|
|
1030
|
+
const token = pendingRequestToken;
|
|
1031
|
+
pendingRequestToken = void 0;
|
|
1032
|
+
if (token === void 0) return;
|
|
1033
|
+
fetch(CANCEL_ROUTE, {
|
|
1034
|
+
method: "POST",
|
|
1035
|
+
headers: { "content-type": "application/json" },
|
|
1036
|
+
body: JSON.stringify({ token })
|
|
1037
|
+
}).catch(() => {});
|
|
1038
|
+
};
|
|
1262
1039
|
ctx.effect(() => ctx.slots.inject("conversation.composer.dock", () => ctx.slots.register({
|
|
1263
1040
|
name: "conversation.composer.dock",
|
|
1264
1041
|
id: "aishell-account",
|
|
1265
1042
|
order: 30,
|
|
1266
1043
|
locale: NS,
|
|
1267
|
-
inject: () => ({
|
|
1044
|
+
inject: (sessionId) => ({
|
|
1268
1045
|
hooks: { credentials: status },
|
|
1269
|
-
t
|
|
1046
|
+
t,
|
|
1047
|
+
openCredentialForm: () => {
|
|
1048
|
+
visibility.open(sessionId);
|
|
1049
|
+
}
|
|
1270
1050
|
})
|
|
1271
1051
|
}, AishellAccountHint)), "aishell-credentials: account hint chip");
|
|
1272
|
-
ctx.effect(() => ctx.slots.inject("conversation.
|
|
1052
|
+
ctx.effect(() => ctx.slots.inject("conversation.input.dock", () => {
|
|
1273
1053
|
const dispose = ctx.slots.register({
|
|
1274
|
-
name: "conversation.
|
|
1275
|
-
|
|
1054
|
+
name: "conversation.input.dock",
|
|
1055
|
+
id: "aishell-hero",
|
|
1056
|
+
order: 10,
|
|
1276
1057
|
locale: NS,
|
|
1277
|
-
inject: () => ({
|
|
1058
|
+
inject: (sessionId) => ({
|
|
1059
|
+
hooks: { credentials: status },
|
|
1060
|
+
openCredentialForm: () => {
|
|
1061
|
+
visibility.open(sessionId);
|
|
1062
|
+
}
|
|
1063
|
+
})
|
|
1278
1064
|
}, AishellHeroChip);
|
|
1279
1065
|
return dispose;
|
|
1280
1066
|
}), "aishell-credentials: hero account chip");
|
|
@@ -1283,22 +1069,18 @@ function apply(ctx) {
|
|
|
1283
1069
|
select: ({ pendingInteraction }) => isCredentialForm(pendingInteraction) ? pendingInteraction : null,
|
|
1284
1070
|
locale: NS,
|
|
1285
1071
|
inject: () => ({
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1072
|
+
hooks: { credentials: status },
|
|
1073
|
+
save: (ak, sk, token) => saveCredential(t, ak, sk, token),
|
|
1074
|
+
clear: () => clearBothStores(t),
|
|
1075
|
+
close: () => {
|
|
1076
|
+
visibility.close();
|
|
1077
|
+
},
|
|
1078
|
+
cancel: () => {
|
|
1079
|
+
cancelRequest();
|
|
1080
|
+
visibility.close();
|
|
1289
1081
|
}
|
|
1290
1082
|
})
|
|
1291
1083
|
}, 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
1084
|
}
|
|
1303
1085
|
|
|
1304
1086
|
//#endregion
|