@huaweidevtools/aishell-dsh-client-credentials 0.0.1-beta.7 → 0.0.1-beta.8

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
@@ -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 — what the card
681
- * has always been. `waiting` is a browser login in flight.
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
- * Starts on `manual`, which is what the card has always been, and moves to
684
- * `choose` only once the probe has proved a browser login is possible here.
685
- * The other order — opening on `choose` and falling back — would show a
686
- * browser button that does nothing while the probe is in flight, and would
687
- * land a deployment that cannot do this on a page it has no use for.
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)("manual");
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 (handle !== null && !interacted.current) setPage("choose");
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
- const outcome = await raceCancellation(pending, signal);
1010
- if (outcome.kind === "cancelled") throw new CredentialEntryCancelled();
1011
- if (outcome.kind === "aborted") throw new CredentialEntryCancelled();
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
- * The person said no, and the call must end rather than ask again.
1030
+ * Credential entry ended without a credential.
1031
+ *
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.
1023
1035
  *
1024
- * Its own type so the message can be the whole instruction: a model reading a
1025
- * generic failure has every reason to retry, which is exactly wrong once the
1026
- * person has answered.
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 credential entry. Stop here and tell them why Huawei Cloud authentication is needed for what they asked. Do not call auth again until they say to.");
1051
+ super("用户取消了认证流程。 / The user cancelled the authentication flow.");
1031
1052
  this.name = "CredentialEntryCancelled";
1032
1053
  }
1033
1054
  };
@@ -2550,21 +2571,34 @@ function apply(ctx, config) {
2550
2571
  reconciler.reconcile();
2551
2572
  const reconcileTimer = setInterval(reconciler.reconcile, 3e4);
2552
2573
  ctx.effect(() => () => clearInterval(reconcileTimer), "aishell-credentials: status reconcile timer");
2553
- registerAuthTool(ctx, store, { requestForm: (sessionId) => {
2554
- if (ns === void 0) return void 0;
2555
- if (pendingForm !== void 0) return pendingForm.outcome;
2556
- const pending = formRequest(sessionId);
2557
- pendingForm = pending;
2558
- ctx.settings.mutate(ns, [{
2559
- op: "set",
2560
- path: [FORM_REQUEST_FIELD],
2561
- value: pending.encoded
2562
- }]).catch((error) => {
2563
- ctx.logger.warn(error);
2564
- if (pendingForm === pending) pending.settle({ kind: "cancelled" });
2565
- });
2566
- return pending.outcome;
2567
- } });
2574
+ registerAuthTool(ctx, store, {
2575
+ requestForm: (sessionId) => {
2576
+ if (ns === void 0) return void 0;
2577
+ if (pendingForm !== void 0) return pendingForm.outcome;
2578
+ const pending = formRequest(sessionId);
2579
+ pendingForm = pending;
2580
+ ctx.settings.mutate(ns, [{
2581
+ op: "set",
2582
+ path: [FORM_REQUEST_FIELD],
2583
+ value: pending.encoded
2584
+ }]).catch((error) => {
2585
+ ctx.logger.warn(error);
2586
+ if (pendingForm === pending) {
2587
+ pendingForm = void 0;
2588
+ pending.settle({ kind: "cancelled" });
2589
+ }
2590
+ });
2591
+ return pending.outcome;
2592
+ },
2593
+ releaseForm: () => {
2594
+ const pending = pendingForm;
2595
+ if (pending !== void 0) {
2596
+ pendingForm = void 0;
2597
+ pending.settle({ kind: "cancelled" });
2598
+ }
2599
+ loginFlow.cancel();
2600
+ }
2601
+ });
2568
2602
  ctx.effect(() => ctx.settings.configure({ auto: false }, ctx.fiber));
2569
2603
  }
2570
2604
 
@@ -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.7",
4
+ "version": "0.0.1-beta.8",
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.7"
44
+ "@huaweidevtools/aishell-dsh-credentials-store": "0.0.1-beta.8"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@deepseek-ai/cordis": "^4.0.4",