@huaweidevtools/aishell-dsh-client-credentials 0.0.1-beta.7 → 0.0.1-beta.9
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 +36 -9
- package/lib/index.js +78 -29
- package/lib/types/auth-tool.d.ts +14 -0
- package/lib/types/client/locales.d.ts +2 -0
- package/package.json +2 -2
package/lib/client.js
CHANGED
|
@@ -677,16 +677,17 @@ function CredentialRequestForm(props) {
|
|
|
677
677
|
* Which page the card is on.
|
|
678
678
|
*
|
|
679
679
|
* `choose` is the first page: the browser entry, if this deployment has one,
|
|
680
|
-
* and the way to the manual form. `manual` is the AK/SK form
|
|
681
|
-
*
|
|
680
|
+
* and the way to the manual form. `manual` is the AK/SK form. `waiting` is a
|
|
681
|
+
* browser login in flight.
|
|
682
682
|
*
|
|
683
|
-
*
|
|
684
|
-
*
|
|
685
|
-
*
|
|
686
|
-
*
|
|
687
|
-
*
|
|
683
|
+
* The card opens on `choose` and settles on `manual` if the probe comes back
|
|
684
|
+
* negative, which is what the probe decides. Opening on `manual` and jumping
|
|
685
|
+
* to `choose` was worse in a way that is visible: the person saw the AK/SK
|
|
686
|
+
* fields, started reading them, and had them replaced underfoot a moment
|
|
687
|
+
* later. `undefined` is "not decided yet", and renders the card's frame with
|
|
688
|
+
* neither page's body — see `page === undefined` below.
|
|
688
689
|
*/
|
|
689
|
-
const [page, setPage] = (0, react.useState)(
|
|
690
|
+
const [page, setPage] = (0, react.useState)(void 0);
|
|
690
691
|
/** Seconds left before the login can no longer complete; `undefined` when idle. */
|
|
691
692
|
const [secondsLeft, setSecondsLeft] = (0, react.useState)(void 0);
|
|
692
693
|
/**
|
|
@@ -719,10 +720,11 @@ function CredentialRequestForm(props) {
|
|
|
719
720
|
return;
|
|
720
721
|
}
|
|
721
722
|
setBrowserLogin(handle ?? null);
|
|
722
|
-
if (
|
|
723
|
+
if (!interacted.current) setPage(handle === null ? "manual" : "choose");
|
|
723
724
|
}).catch(() => {
|
|
724
725
|
if (!live) return;
|
|
725
726
|
setBrowserLogin(null);
|
|
727
|
+
if (!interacted.current) setPage("manual");
|
|
726
728
|
});
|
|
727
729
|
return () => {
|
|
728
730
|
live = false;
|
|
@@ -1042,6 +1044,29 @@ function CredentialRequestForm(props) {
|
|
|
1042
1044
|
})]
|
|
1043
1045
|
})
|
|
1044
1046
|
] }),
|
|
1047
|
+
page === void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1048
|
+
style: {
|
|
1049
|
+
display: "flex",
|
|
1050
|
+
alignItems: "center",
|
|
1051
|
+
gap: 10
|
|
1052
|
+
},
|
|
1053
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1054
|
+
className: SPINNER_CLASS,
|
|
1055
|
+
style: {
|
|
1056
|
+
width: 16,
|
|
1057
|
+
height: 16
|
|
1058
|
+
},
|
|
1059
|
+
"aria-hidden": true
|
|
1060
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1061
|
+
role: "status",
|
|
1062
|
+
style: {
|
|
1063
|
+
fontSize: 14,
|
|
1064
|
+
lineHeight: "22px",
|
|
1065
|
+
color: "var(--dsw-alias-label-secondary)"
|
|
1066
|
+
},
|
|
1067
|
+
children: t("form.checking")
|
|
1068
|
+
})]
|
|
1069
|
+
}),
|
|
1045
1070
|
page === "manual" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
1046
1071
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1047
1072
|
style: {
|
|
@@ -1376,6 +1401,7 @@ const zh = {
|
|
|
1376
1401
|
"form.clear.failed": "清除凭据失败",
|
|
1377
1402
|
"error.unreachable": "无法连接宿主凭据服务:",
|
|
1378
1403
|
"form.intro": "需要进行华为云 IAM 认证",
|
|
1404
|
+
"form.checking": "正在检查登录方式…",
|
|
1379
1405
|
"form.browser.action": "浏览器登录",
|
|
1380
1406
|
"form.browser.aksk": "我有AK/SK",
|
|
1381
1407
|
"form.browser.decline": "暂不认证",
|
|
@@ -1420,6 +1446,7 @@ const en = {
|
|
|
1420
1446
|
"form.clear.failed": "Could not clear credentials",
|
|
1421
1447
|
"error.unreachable": "Could not reach the host credential service: ",
|
|
1422
1448
|
"form.intro": "Huawei Cloud IAM authentication is required",
|
|
1449
|
+
"form.checking": "Checking sign-in options…",
|
|
1423
1450
|
"form.browser.action": "Sign in with a browser",
|
|
1424
1451
|
"form.browser.aksk": "I have one",
|
|
1425
1452
|
"form.browser.decline": "Not now",
|
package/lib/index.js
CHANGED
|
@@ -1006,9 +1006,17 @@ async function runAuth(store, deps, sessionId, signal) {
|
|
|
1006
1006
|
for (let round = 0; round < MAX_FORM_ROUNDS; round += 1) {
|
|
1007
1007
|
const pending = deps.requestForm(sessionId);
|
|
1008
1008
|
if (pending === void 0) break;
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1009
|
+
let outcome;
|
|
1010
|
+
try {
|
|
1011
|
+
outcome = await raceCancellation(pending, signal);
|
|
1012
|
+
} catch (error) {
|
|
1013
|
+
deps.releaseForm();
|
|
1014
|
+
throw error;
|
|
1015
|
+
}
|
|
1016
|
+
if (outcome.kind === "cancelled" || outcome.kind === "aborted") {
|
|
1017
|
+
deps.releaseForm();
|
|
1018
|
+
throw new CredentialEntryCancelled();
|
|
1019
|
+
}
|
|
1012
1020
|
const pair = readStoredPair(store);
|
|
1013
1021
|
if (pair === void 0) continue;
|
|
1014
1022
|
const result = await verifyCredentials(pair, { region: VERIFY_REGION$1 });
|
|
@@ -1019,15 +1027,28 @@ async function runAuth(store, deps, sessionId, signal) {
|
|
|
1019
1027
|
/** How many form rounds one call will wait through before giving up. */
|
|
1020
1028
|
const MAX_FORM_ROUNDS = 10;
|
|
1021
1029
|
/**
|
|
1022
|
-
*
|
|
1030
|
+
* Credential entry ended without a credential.
|
|
1023
1031
|
*
|
|
1024
|
-
*
|
|
1025
|
-
*
|
|
1026
|
-
*
|
|
1032
|
+
* One message for both ways it ends — the person pressed cancel, or the turn
|
|
1033
|
+
* was stopped while the form was up. From the call's side they are the same
|
|
1034
|
+
* outcome: nothing was entered, so the call cannot continue.
|
|
1035
|
+
*
|
|
1036
|
+
* Bilingual, and stating only the fact. That is the shape `aishell-e2b` uses
|
|
1037
|
+
* for its blocked-call error: the reader is whichever language the session
|
|
1038
|
+
* runs in, and the message says what happened rather than what to do about it.
|
|
1039
|
+
*
|
|
1040
|
+
* ## Why no instruction follows
|
|
1041
|
+
*
|
|
1042
|
+
* An earlier version ended with "Do not call auth again until they say to."
|
|
1043
|
+
* The intent was to stop a model retrying in a loop, but what it produced was
|
|
1044
|
+
* a model that treated every later sentence from the person as a question
|
|
1045
|
+
* about permission — asked to look again, it narrated its uncertainty about
|
|
1046
|
+
* whether that counted as consent, and stalled instead of either retrying or
|
|
1047
|
+
* explaining. The fact is enough; what follows it is the model's judgement.
|
|
1027
1048
|
*/
|
|
1028
1049
|
var CredentialEntryCancelled = class extends Error {
|
|
1029
1050
|
constructor() {
|
|
1030
|
-
super("The user cancelled
|
|
1051
|
+
super("用户取消了认证流程。 / The user cancelled the authentication flow.");
|
|
1031
1052
|
this.name = "CredentialEntryCancelled";
|
|
1032
1053
|
}
|
|
1033
1054
|
};
|
|
@@ -2507,13 +2528,28 @@ function apply(ctx, config) {
|
|
|
2507
2528
|
path: [LOGIN_OUTCOME_FIELD],
|
|
2508
2529
|
value: encodeOutcome(outcome)
|
|
2509
2530
|
}]);
|
|
2510
|
-
if (outcome?.kind
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2531
|
+
if (outcome?.kind !== "succeeded") return;
|
|
2532
|
+
recordStatus([
|
|
2533
|
+
{
|
|
2534
|
+
op: "set",
|
|
2535
|
+
path: ["credentialsStored"],
|
|
2536
|
+
value: true
|
|
2537
|
+
},
|
|
2538
|
+
{
|
|
2539
|
+
op: "set",
|
|
2540
|
+
path: ["accessKeyIdHint"],
|
|
2541
|
+
value: outcome.accountName
|
|
2542
|
+
},
|
|
2543
|
+
{
|
|
2544
|
+
op: "unset",
|
|
2545
|
+
path: ["lastError"]
|
|
2516
2546
|
}
|
|
2547
|
+
]);
|
|
2548
|
+
announceCredentialsChanged();
|
|
2549
|
+
const pending = pendingForm;
|
|
2550
|
+
if (pending !== void 0) {
|
|
2551
|
+
pendingForm = void 0;
|
|
2552
|
+
pending.settle({ kind: "submitted" });
|
|
2517
2553
|
}
|
|
2518
2554
|
}
|
|
2519
2555
|
});
|
|
@@ -2550,21 +2586,34 @@ function apply(ctx, config) {
|
|
|
2550
2586
|
reconciler.reconcile();
|
|
2551
2587
|
const reconcileTimer = setInterval(reconciler.reconcile, 3e4);
|
|
2552
2588
|
ctx.effect(() => () => clearInterval(reconcileTimer), "aishell-credentials: status reconcile timer");
|
|
2553
|
-
registerAuthTool(ctx, store, {
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2589
|
+
registerAuthTool(ctx, store, {
|
|
2590
|
+
requestForm: (sessionId) => {
|
|
2591
|
+
if (ns === void 0) return void 0;
|
|
2592
|
+
if (pendingForm !== void 0) return pendingForm.outcome;
|
|
2593
|
+
const pending = formRequest(sessionId);
|
|
2594
|
+
pendingForm = pending;
|
|
2595
|
+
ctx.settings.mutate(ns, [{
|
|
2596
|
+
op: "set",
|
|
2597
|
+
path: [FORM_REQUEST_FIELD],
|
|
2598
|
+
value: pending.encoded
|
|
2599
|
+
}]).catch((error) => {
|
|
2600
|
+
ctx.logger.warn(error);
|
|
2601
|
+
if (pendingForm === pending) {
|
|
2602
|
+
pendingForm = void 0;
|
|
2603
|
+
pending.settle({ kind: "cancelled" });
|
|
2604
|
+
}
|
|
2605
|
+
});
|
|
2606
|
+
return pending.outcome;
|
|
2607
|
+
},
|
|
2608
|
+
releaseForm: () => {
|
|
2609
|
+
const pending = pendingForm;
|
|
2610
|
+
if (pending !== void 0) {
|
|
2611
|
+
pendingForm = void 0;
|
|
2612
|
+
pending.settle({ kind: "cancelled" });
|
|
2613
|
+
}
|
|
2614
|
+
loginFlow.cancel();
|
|
2615
|
+
}
|
|
2616
|
+
});
|
|
2568
2617
|
ctx.effect(() => ctx.settings.configure({ auto: false }, ctx.fiber));
|
|
2569
2618
|
}
|
|
2570
2619
|
|
package/lib/types/auth-tool.d.ts
CHANGED
|
@@ -83,6 +83,20 @@ export interface AuthToolDeps {
|
|
|
83
83
|
* case a call running outside an agent hits.
|
|
84
84
|
*/
|
|
85
85
|
readonly requestForm: (sessionId: string) => Promise<FormOutcome> | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* This call has stopped waiting on the form it asked for.
|
|
88
|
+
*
|
|
89
|
+
* Required, not optional, because the leak it prevents is invisible and
|
|
90
|
+
* permanent: the host shares one pending request between concurrent callers,
|
|
91
|
+
* so a call that walks away without saying so leaves that request in place.
|
|
92
|
+
* The next `auth` then joins a promise nobody will ever settle — no form is
|
|
93
|
+
* written to the document, so none appears, and the call waits until the
|
|
94
|
+
* turn ends.
|
|
95
|
+
*
|
|
96
|
+
* A person who aborts a turn is the ordinary way in. Nothing about that is
|
|
97
|
+
* an error, which is exactly why nothing else remembers to do this.
|
|
98
|
+
*/
|
|
99
|
+
readonly releaseForm: () => void;
|
|
86
100
|
}
|
|
87
101
|
/**
|
|
88
102
|
* Register the `auth` tool on the host's tool registry.
|
|
@@ -30,6 +30,7 @@ export declare const zh: {
|
|
|
30
30
|
readonly 'form.clear.failed': "清除凭据失败";
|
|
31
31
|
readonly 'error.unreachable': "无法连接宿主凭据服务:";
|
|
32
32
|
readonly 'form.intro': "需要进行华为云 IAM 认证";
|
|
33
|
+
readonly 'form.checking': "正在检查登录方式…";
|
|
33
34
|
readonly 'form.browser.action': "浏览器登录";
|
|
34
35
|
readonly 'form.browser.aksk': "我有AK/SK";
|
|
35
36
|
readonly 'form.browser.decline': "暂不认证";
|
|
@@ -74,6 +75,7 @@ export declare const en: {
|
|
|
74
75
|
readonly 'form.clear.failed': "Could not clear credentials";
|
|
75
76
|
readonly 'error.unreachable': "Could not reach the host credential service: ";
|
|
76
77
|
readonly 'form.intro': "Huawei Cloud IAM authentication is required";
|
|
78
|
+
readonly 'form.checking': "Checking sign-in options…";
|
|
77
79
|
readonly 'form.browser.action': "Sign in with a browser";
|
|
78
80
|
readonly 'form.browser.aksk': "I have one";
|
|
79
81
|
readonly 'form.browser.decline': "Not now";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huaweidevtools/aishell-dsh-client-credentials",
|
|
3
3
|
"description": "AI Shell credentials — chip-opened web form for storing Huawei Cloud AK/SK in the credential store",
|
|
4
|
-
"version": "0.0.1-beta.
|
|
4
|
+
"version": "0.0.1-beta.9",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"license": "Apache-2.0",
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@huaweidevtools/aishell-dsh-credentials-store": "0.0.1-beta.
|
|
44
|
+
"@huaweidevtools/aishell-dsh-credentials-store": "0.0.1-beta.9"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@deepseek-ai/cordis": "^4.0.4",
|