@huaweidevtools/aishell-dsh-client-credentials 0.0.15 → 0.0.17

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
@@ -266,10 +266,12 @@ const CHIP_STYLE_KEY = `${PLUGIN_ID$1}/chip-hover`;
266
266
  * a disposer that removes the tag, and the `data-plugin` markers so
267
267
  * `removeOwnedStyles` can also reach it. The disposer is what makes a reload
268
268
  * pick up an edited rule — the fiber tears down, the tag goes, and the next
269
- * materialization writes the new text. A module-level install with an id guard
270
- * fails exactly there: the tag outlives the module (the loader only sweeps
271
- * `data-plugin` tags), the guard then sees it and returns, and the old CSS
272
- * stays in force for the life of the page.
269
+ * materialization writes the new text.
270
+ *
271
+ * A module-level install guarded by an id cannot do that: the tag outlives the
272
+ * module because the loader sweeps only `data-plugin` tags, so the guard finds
273
+ * it on the next materialization and returns, and the page keeps the rule from
274
+ * before the edit for its whole life.
273
275
  *
274
276
  * Call once from `apply()`, not from the components: the rule is shared by
275
277
  * both chips (they carry the same `CHIP_CLASS`), so one sheet serves them and
@@ -1934,8 +1936,8 @@ async function clearBothStores(t) {
1934
1936
  * Read the credential prefills the host has in its environment.
1935
1937
  *
1936
1938
  * Failure is not an event: a host with nothing in its environment answers an
1937
- * empty object, and a route that cannot be reached answers `{}` too, because a
1938
- * form that starts empty is exactly the behaviour before this existed.
1939
+ * empty object, and a route that cannot be reached answers `{}` too. A form
1940
+ * that starts empty is the ordinary case, so there is nothing to report.
1939
1941
  *
1940
1942
  * @returns the prefills, or an empty object.
1941
1943
  */
package/lib/index.js CHANGED
@@ -1039,12 +1039,12 @@ const MAX_FORM_ROUNDS = 10;
1039
1039
  *
1040
1040
  * ## Why no instruction follows
1041
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.
1042
+ * The message states the fact and stops. Adding "do not call auth again until
1043
+ * they say to" reads as a permission rule to be interpreted, and a model given
1044
+ * a rule it cannot evaluate narrates its uncertainty instead of acting: asked
1045
+ * to look again, it reasons about whether that counts as consent, and neither
1046
+ * retries nor explains. The fact is what the model needs; what follows from it
1047
+ * is its judgement.
1048
1048
  */
1049
1049
  var CredentialEntryCancelled = class extends Error {
1050
1050
  constructor() {
@@ -2242,7 +2242,7 @@ function readEnvPrefill(env) {
2242
2242
  * mirror so reconcile never depends on config flow-back timing.
2243
2243
  */
2244
2244
  function createCredentialReconciler(deps) {
2245
- const { verify, recordStatus, readStored, readHint, readPair } = deps;
2245
+ const { verify, isRejection: isRejection$1, recordStatus, readStored, readHint, readPair, discard } = deps;
2246
2246
  let lastVerifyFingerprint = "";
2247
2247
  const materialFingerprint = (ak, sk, token) => `${ak}\n${sk}\n${token ?? ""}`;
2248
2248
  return {
@@ -2276,7 +2276,21 @@ function createCredentialReconciler(deps) {
2276
2276
  path: ["accessKeyIdHint"],
2277
2277
  value: accountName
2278
2278
  }]);
2279
- }).catch(() => {});
2279
+ }).catch((error) => {
2280
+ if (isRejection$1(error)) {
2281
+ discard();
2282
+ lastVerifyFingerprint = "";
2283
+ recordStatus([{
2284
+ op: "set",
2285
+ path: ["credentialsStored"],
2286
+ value: false
2287
+ }, {
2288
+ op: "unset",
2289
+ path: ["accessKeyIdHint"]
2290
+ }]);
2291
+ return;
2292
+ }
2293
+ });
2280
2294
  },
2281
2295
  resetVerifyBaseline: () => {
2282
2296
  lastVerifyFingerprint = "";
@@ -2368,15 +2382,15 @@ const MAX_BODY_BYTES = 8 * 1024;
2368
2382
  * answer from the same endpoint (profile: `GET /v3/projects`, with the account
2369
2383
  * name read best-effort from `/v3/auth/domains`).
2370
2384
  *
2371
- * ## Why not a local domains-only call
2385
+ * ## Why the shared verifier rather than a narrower call
2372
2386
  *
2373
- * This used to call `/v3/auth/domains` directly, because the only fact this
2374
- * route needed was the account name shown in the composer chip. That made it a
2375
- * second, narrower notion of validity: `/v3/projects` rejects a credential with
2376
- * no visible project, while `/v3/auth/domains` accepts it — so the form said
2377
- * "saved" for credentials the tools would then refuse. One verifier removes
2378
- * that gap, and the project list it returns is exactly what a caller needs
2379
- * before planning a deployment.
2387
+ * The form's own question is "is this pair valid", and the answer has to agree
2388
+ * with the one the tools get — otherwise it accepts credentials the tools then
2389
+ * refuse. A narrower check would do exactly that: `/v3/projects` rejects a
2390
+ * credential with no visible project, while a domains-only call accepts it, so
2391
+ * the form would say "saved" for a pair that fails on the first real call. One
2392
+ * verifier removes that gap, and the project list it returns is what a caller
2393
+ * needs before planning a deployment anyway.
2380
2394
  *
2381
2395
  * ## The region
2382
2396
  *
@@ -2388,7 +2402,9 @@ const MAX_BODY_BYTES = 8 * 1024;
2388
2402
  * elsewhere.
2389
2403
  *
2390
2404
  * @returns the account name (domain name), falling back to the account id.
2391
- * @throws Error with a user-readable message when verification fails.
2405
+ * @throws {CredentialRejectedError} when IAM refused the credential itself —
2406
+ * the only failure that says the stored pair is unusable.
2407
+ * @throws {Error} for every other failure, with a user-readable message.
2392
2408
  */
2393
2409
  async function verifyCredentials$1(ak, sk, securityToken) {
2394
2410
  const result = await verifyCredentials({
@@ -2396,10 +2412,45 @@ async function verifyCredentials$1(ak, sk, securityToken) {
2396
2412
  sk,
2397
2413
  ...securityToken === void 0 ? {} : { securityToken }
2398
2414
  }, { region: VERIFY_REGION });
2399
- if (!result.ok) throw new Error(result.message);
2400
- return result.account.name;
2415
+ if (result.ok) return result.account.name;
2416
+ if (isRejection(result.status)) throw new CredentialRejectedError(result.message);
2417
+ throw new Error(result.message);
2418
+ }
2419
+ /**
2420
+ * Whether IAM's answer is about the credential rather than about the call.
2421
+ *
2422
+ * The distinction decides whether the stored pair is discarded, so it is drawn
2423
+ * narrowly. Only 401 and 403 mean "this credential is not usable":
2424
+ *
2425
+ * - `0` never reached IAM — a DNS failure, a proxy, a timeout. The credential
2426
+ * may be perfectly good, and clearing it would log the person out because
2427
+ * their network blipped.
2428
+ * - A 5xx is IAM failing rather than refusing. Same conclusion.
2429
+ * - A 200 that failed business validation (no visible project, projects from
2430
+ * two accounts) arrives with the credential ACCEPTED — the answer is about
2431
+ * authorisation or account shape, and re-entering the same pair changes
2432
+ * nothing.
2433
+ *
2434
+ * @param status - the HTTP status IAM answered with, or `0`.
2435
+ * @returns whether the credential was refused.
2436
+ */
2437
+ function isRejection(status) {
2438
+ return status === 401 || status === 403;
2401
2439
  }
2402
2440
  /**
2441
+ * IAM refused the credential itself.
2442
+ *
2443
+ * A distinct type because the caller does something a plain failure must not
2444
+ * trigger: it discards what is stored. The type is what keeps that decision
2445
+ * from being re-derived, differently, at every call site.
2446
+ */
2447
+ var CredentialRejectedError = class extends Error {
2448
+ constructor(..._args) {
2449
+ super(..._args);
2450
+ this.name = "CredentialRejectedError";
2451
+ }
2452
+ };
2453
+ /**
2403
2454
  * Region used to route the verification call.
2404
2455
  *
2405
2456
  * Not a setting: see {@link verifyCredentials}. Any region replica answers the
@@ -2413,10 +2464,32 @@ function jsonError(status, message) {
2413
2464
  error: message
2414
2465
  }, { status });
2415
2466
  }
2416
- /** Read a bounded JSON object body, or throw a user-readable message. */
2467
+ /**
2468
+ * Read a bounded JSON object body, or throw a user-readable message.
2469
+ *
2470
+ * ## Why the bound is checked before the read finishes
2471
+ *
2472
+ * The body is drained first and measured after, which is the only order the
2473
+ * `Request` API allows: it exposes no streaming reader for a buffered route.
2474
+ * That means the bound cannot prevent the memory a large body costs — it stops
2475
+ * a hostile body from being *parsed* and from reaching any code that assumes a
2476
+ * credential, which is what it is for here. The transport's own request cap is
2477
+ * the memory bound; this one guards the next step.
2478
+ *
2479
+ * ## Why bytes and not `text.length`
2480
+ *
2481
+ * `text.length` counts UTF-16 code units, so a body of three-byte characters
2482
+ * measures a third of its real size and slips under a bound it should not. The
2483
+ * limit is stated in bytes, so it is compared in bytes.
2484
+ *
2485
+ * @param request - the buffered request.
2486
+ * @returns the parsed object.
2487
+ * @throws when the body is too large, is not JSON, or is not an object.
2488
+ */
2417
2489
  async function readJsonBody(request) {
2418
2490
  const text = await request.text();
2419
- if (text.length > MAX_BODY_BYTES) throw new Error("Request body too large.");
2491
+ const bytes = new TextEncoder().encode(text).length;
2492
+ if (bytes > MAX_BODY_BYTES) throw new Error("Request body too large.");
2420
2493
  let parsed;
2421
2494
  try {
2422
2495
  parsed = JSON.parse(text);
@@ -2509,7 +2582,17 @@ function createCredentialRoutes(deps) {
2509
2582
  });
2510
2583
  },
2511
2584
  clear: () => {
2512
- clearCredentials(store);
2585
+ try {
2586
+ clearCredentials(store);
2587
+ } catch (error) {
2588
+ const message = `Could not clear the stored credentials: ${error instanceof Error ? error.message : String(error)}`;
2589
+ recordStatus([{
2590
+ op: "set",
2591
+ path: ["lastError"],
2592
+ value: message
2593
+ }]);
2594
+ return Promise.resolve(jsonError(500, message));
2595
+ }
2513
2596
  recordStatus([
2514
2597
  {
2515
2598
  op: "set",
@@ -2576,6 +2659,37 @@ function apply(ctx, config) {
2576
2659
  ctx.logger.warn(error);
2577
2660
  });
2578
2661
  };
2662
+ /**
2663
+ * Answer one form request, named by the token in the body.
2664
+ *
2665
+ * The cancel and confirm routes differ only in which outcome they record, so
2666
+ * they share this. Both need the same three things, and each is a failure
2667
+ * this has to get right:
2668
+ *
2669
+ * - **The body is read defensively.** A malformed one earns a `400` rather
2670
+ * than an exception, so the browser always receives JSON it can render.
2671
+ * - **The token decides which request is answered.** The browser can
2672
+ * deliver a stale answer after a reconnect, and settling whichever
2673
+ * request happens to be pending would end a form the person is looking
2674
+ * at — or, worse, tell a model the user declined something they did not.
2675
+ * - **An unmatched token is not an error.** The request it named is
2676
+ * already gone; there is nothing to do and the browser needs no message.
2677
+ *
2678
+ * @param kind - the outcome to record against the named request.
2679
+ * @returns the route handler.
2680
+ */
2681
+ const settleByToken = (kind) => async (request) => {
2682
+ let body;
2683
+ try {
2684
+ body = await request.json();
2685
+ } catch {
2686
+ return jsonError(400, "Request body is not valid JSON.");
2687
+ }
2688
+ const token = body?.token;
2689
+ if (typeof token !== "string" || token === "") return jsonError(400, "token is required.");
2690
+ if (pendingForm !== void 0 && pendingForm.request.token === token) settleFormRequest({ kind }, pendingForm);
2691
+ return Response.json({ ok: true });
2692
+ };
2579
2693
  /** Apply one batch of ops to the mirror. */
2580
2694
  const mirrorOps = (ops) => {
2581
2695
  for (const op of ops) if (op.path[0] === "credentialsStored") recordedStored = op.op === "set" && op.value === true;
@@ -2615,10 +2729,15 @@ function apply(ctx, config) {
2615
2729
  });
2616
2730
  const reconciler = createCredentialReconciler({
2617
2731
  verify: verifyCredentials$1,
2732
+ isRejection: (error) => error instanceof CredentialRejectedError,
2618
2733
  recordStatus,
2619
2734
  readStored: () => recordedStored,
2620
2735
  readHint: () => recordedHint,
2621
- readPair: () => readStoredPair(store)
2736
+ readPair: () => readStoredPair(store),
2737
+ discard: () => {
2738
+ clearCredentials(store);
2739
+ ctx.emit("aishell/credentials-updated");
2740
+ }
2622
2741
  });
2623
2742
  ctx.effect(() => ctx.connection.fetch.register({
2624
2743
  path: CREDENTIALS_PATH,
@@ -2641,47 +2760,13 @@ function apply(ctx, config) {
2641
2760
  path: CANCEL_PATH,
2642
2761
  methods: ["POST"],
2643
2762
  requestBody: "buffered",
2644
- fetch: async (request) => {
2645
- let body;
2646
- try {
2647
- body = await request.json();
2648
- } catch {
2649
- return Response.json({
2650
- ok: false,
2651
- error: "Request body is not valid JSON."
2652
- }, { status: 400 });
2653
- }
2654
- const token = body?.token;
2655
- if (typeof token !== "string" || token === "") return Response.json({
2656
- ok: false,
2657
- error: "token is required."
2658
- }, { status: 400 });
2659
- if (pendingForm !== void 0 && pendingForm.request.token === token) settleFormRequest({ kind: "cancelled" }, pendingForm);
2660
- return Response.json({ ok: true });
2661
- }
2763
+ fetch: settleByToken("cancelled")
2662
2764
  }), "aishell-credentials: cancel route");
2663
2765
  ctx.effect(() => ctx.connection.fetch.register({
2664
2766
  path: CONFIRM_PATH,
2665
2767
  methods: ["POST"],
2666
2768
  requestBody: "buffered",
2667
- fetch: async (request) => {
2668
- let body;
2669
- try {
2670
- body = await request.json();
2671
- } catch {
2672
- return Response.json({
2673
- ok: false,
2674
- error: "Request body is not valid JSON."
2675
- }, { status: 400 });
2676
- }
2677
- const token = body?.token;
2678
- if (typeof token !== "string" || token === "") return Response.json({
2679
- ok: false,
2680
- error: "token is required."
2681
- }, { status: 400 });
2682
- if (pendingForm !== void 0 && pendingForm.request.token === token) settleFormRequest({ kind: "submitted" }, pendingForm);
2683
- return Response.json({ ok: true });
2684
- }
2769
+ fetch: settleByToken("submitted")
2685
2770
  }), "aishell-credentials: confirm route");
2686
2771
  ctx.effect(() => ctx.connection.fetch.register({
2687
2772
  path: PREFILL_PATH,
@@ -15,19 +15,17 @@
15
15
  * `aishell__auth`; `退出` clears the credential.
16
16
  * - **Not signed in** — both ways to obtain a credential, side by side.
17
17
  *
18
- * An earlier version spread this across four pages (`choose` / `manual` /
19
- * `waiting` plus a "deciding" state) and moved between them as the probe
20
- * answered. The pages were the same card wearing different hats — the person
21
- * sees one panel either way — and the transitions were visible: fields appeared
22
- * and were replaced a moment later. One upright card with a button that reports
23
- * its own state is both smaller and calmer.
18
+ * One panel with a button that reports its own state, rather than a page per
19
+ * step. The person sees one card either way, so separate pages would be the
20
+ * same layout repeated — and the transitions between them would be visible:
21
+ * fields appearing and being replaced a moment later as the probe answered.
24
22
  *
25
23
  * ## Why the browser route reports itself in place
26
24
  *
27
25
  * The button is the status: `checking` while the probe runs, `login` once it
28
26
  * passes, `unsupported` when it fails, `cancel` while a login is in flight with
29
- * the countdown beside it. A separate page for "waiting" was a second layout to
30
- * keep in step with the first for no gain.
27
+ * the countdown beside it. A separate "waiting" page would be a second layout
28
+ * to keep in step with this one, for no gain.
31
29
  *
32
30
  * @module @huaweidevtools/aishell-dsh-client-credentials/client/CredentialRequestForm
33
31
  */
@@ -8,21 +8,17 @@
8
8
  *
9
9
  * ## One way the form comes up
10
10
  *
11
- * A chip opens it. That is the whole model.
12
- *
13
- * There used to be a second source — the Host publishing which session had a
14
- * tool call blocked on credentials — and this module reconciled the two, with
15
- * rules about which one owned the form and how a takeover republished the
16
- * interaction. That request channel is gone: no tool call blocks on credentials
17
- * any more, so a Host request cannot arrive, and every rule about outranking
18
- * one describes a situation that cannot happen.
19
- *
20
- * The rules that remain are the ones a single door needs:
11
+ * A chip opens it, and that is the whole model. Every rule here exists to serve
12
+ * that single door:
21
13
  *
22
14
  * - An open while the form is already up is a no-op. Publishing a second
23
15
  * interaction would remount the component and discard what was typed.
24
16
  * - A close, or a dispose, withdraws it, and the ordinary composer comes back.
25
17
  *
18
+ * No other producer exists, so no rule is needed for one. A second source would
19
+ * need rules about which owns the form and how a takeover republishes it — and
20
+ * those rules would be describing a situation the system cannot reach.
21
+ *
26
22
  * ## Why a closure and not a class
27
23
  *
28
24
  * Written as a factory because the browser half is compiled by oxc, and a class
@@ -68,8 +64,8 @@ export interface CredentialFormVisibility {
68
64
  * thing (one login at a time, one credential store), so publishing a
69
65
  * second card would give two conversations a live form over one store.
70
66
  * Moving the person to the card they already have is the honest answer,
71
- * and it is also what makes the chip work after a conversation switch:
72
- * refusing used to leave every later click doing nothing until a reload.
67
+ * and it is what keeps the chip alive across a conversation switch: the
68
+ * card is still on screen, just not in the conversation that was clicked.
73
69
  *
74
70
  * @param sessionId - the conversation the person is acting in.
75
71
  */
@@ -5,17 +5,16 @@
5
5
  * presentation: the presence descriptor the Host reports, the verdict its route
6
6
  * answers with, and the link to where a credential comes from.
7
7
  *
8
- * ## Why it exists
8
+ * ## Why it is its own module
9
9
  *
10
- * Four modules need these, and every one of them used to reach into
11
- * `AishellCredentialsSection.tsx` for them — two chips and the composer form
12
- * importing from a component they do not render. That file is gone now (the
13
- * form replaced it), and the shared contract stays here: a module neither the
14
- * form nor the chips owns. Same reasoning as `huawei-mark.ts`: the second
10
+ * Several modules need these — two chips and the form — and none of them owns
11
+ * the other. A shared contract belongs in a file that no consumer is the author
12
+ * of; importing it from one component would make that component's internals a
13
+ * public interface by accident. Same reasoning as `huawei-mark.ts`: the second
15
14
  * consumer is when the shared part earns its own module.
16
15
  *
17
- * The paragraph that follows each is the contract the Host half implements; it
18
- * is stated here because this file is now where both sides read it.
16
+ * The paragraph that follows each declaration is the contract the Host half
17
+ * implements; it is stated here because this file is where both sides read it.
19
18
  *
20
19
  * @module @huaweidevtools/aishell-dsh-client-credentials/client/credential-status
21
20
  */
@@ -34,10 +34,12 @@ export declare const CHIP_CLASS = "aishell-account-hint";
34
34
  * a disposer that removes the tag, and the `data-plugin` markers so
35
35
  * `removeOwnedStyles` can also reach it. The disposer is what makes a reload
36
36
  * pick up an edited rule — the fiber tears down, the tag goes, and the next
37
- * materialization writes the new text. A module-level install with an id guard
38
- * fails exactly there: the tag outlives the module (the loader only sweeps
39
- * `data-plugin` tags), the guard then sees it and returns, and the old CSS
40
- * stays in force for the life of the page.
37
+ * materialization writes the new text.
38
+ *
39
+ * A module-level install guarded by an id cannot do that: the tag outlives the
40
+ * module because the loader sweeps only `data-plugin` tags, so the guard finds
41
+ * it on the next materialization and returns, and the page keeps the rule from
42
+ * before the edit for its whole life.
41
43
  *
42
44
  * Call once from `apply()`, not from the components: the rule is shared by
43
45
  * both chips (they carry the same `CHIP_CLASS`), so one sheet serves them and
@@ -9,10 +9,10 @@
9
9
  * verified account name come back through `ctx.configForms`, which the chips
10
10
  * and the form read.
11
11
  *
12
- * There is no Settings section any more: the form is the one credential
13
- * surface, opened either by a chip click (the visibility state machine's
14
- * manual posture) or by a tool call blocked on credentials (the Host-mirrored
15
- * posture). Both render the same component in `conversation.composer`.
12
+ * The form is the one credential surface, and a chip click is what opens it.
13
+ * It renders in `conversation.composer`, and there is no Settings section
14
+ * beside it: one place to enter a credential means one place to look when none
15
+ * is working.
16
16
  *
17
17
  * @module @huaweidevtools/aishell-dsh-client-credentials/client
18
18
  */
@@ -12,18 +12,18 @@
12
12
  * person there, wait for the cloud to post a credential back. That is
13
13
  * {@link startBrowserLogin}, and it binds **its own** port.
14
14
  *
15
- * These were one function, and it was wrong in two ways that only show up when
16
- * a person takes their time:
17
- *
18
- * - **The port was held from the moment the card opened.** The probe binds a
19
- * socket to answer its question and now releases it immediately; keeping it
20
- * until someone clicked meant anyone who read the card and walked away held
21
- * a port for as long as the page lived.
22
- * - **The login window started before the person did.** The `login_url` names
23
- * the port it was projected for and the service states how long it stays
24
- * valid. Both were fixed at probe time, so a card left open for a while
25
- * offered a URL that had already expired — and a countdown ran down on a
26
- * sign-in nobody had begun.
15
+ * These are two operations rather than one, and merging them breaks in two
16
+ * ways that only show up when a person takes their time:
17
+ *
18
+ * - **A shared port would be held from the moment the card opened.** The
19
+ * probe binds a socket to answer its question and releases it immediately;
20
+ * a port kept until someone clicked would be held for as long as the page
21
+ * lived, by anyone who merely read the card.
22
+ * - **A login window would start before the person did.** The `login_url`
23
+ * names the port it was projected for and the service states how long it
24
+ * stays valid. Fixed at probe time, a card left open for a while would
25
+ * offer a URL that had already expired — and a countdown would run down on
26
+ * a sign-in nobody had begun.
27
27
  *
28
28
  * So each operation binds what it needs and releases it when its own job ends.
29
29
  * The probe's port is closed as soon as the browser has answered; the login's
@@ -1,19 +1,22 @@
1
1
  /**
2
2
  * Idempotent credential-status reconcile.
3
3
  *
4
- * The replacement for the old one-shot boot check in `apply()`. That check was
5
- * an else-if chain: the "set `credentialsStored`" branch and the "verify and
6
- * record the account name" branch were mutually exclusive, so on the boot where
7
- * `credentialsStored` flipped to true the hint branch was unreachable — the
8
- * account chips kept showing "unconfigured" until a second restart. Nothing
9
- * ever re-read the store after boot either, so credentials written after boot
10
- * (the env's `sync-hw-creds` writes them every minute) stayed invisible to the
11
- * UI. Independent branches fix the former; the caller's timer and GET-route
12
- * hook fix the latter.
4
+ * Derives `credentialsStored` and `accessKeyIdHint` from the store, and records
5
+ * only what changed. The two derivations are independent on purpose: a boot
6
+ * where the presence flag flips to true must still reach the branch that
7
+ * verifies and records the account name, or the chips show "unconfigured" until
8
+ * something else triggers a restart.
13
9
  *
14
- * Kept as a factory — not inlined in `apply()` — so the whole decision table
15
- * is drivable from a spec with a `MemoryBackend` and a fake verifier, never a
16
- * real keyring or IAM call (see `docs/memory.md` §15).
10
+ * Nothing re-reads the store on its own, so a credential written while the
11
+ * process is running — the environment's `sync-hw-creds` writes them every
12
+ * minute — would stay invisible to the UI. The caller's timer and the GET
13
+ * route's hook provide those re-reads; this module only has to be safe to call
14
+ * repeatedly, which it is: at steady state it records nothing and verifies
15
+ * nothing.
16
+ *
17
+ * Kept as a factory — not inlined in `apply()` — so the whole decision table is
18
+ * drivable from a spec with a `MemoryBackend` and a fake verifier, never a real
19
+ * keyring or IAM call.
17
20
  *
18
21
  * @module @huaweidevtools/aishell-dsh-client-credentials/reconcile
19
22
  */
@@ -31,8 +34,17 @@ export type ReadStored = () => boolean;
31
34
  export type ReadHint = () => string | null;
32
35
  /** Collaborators the reconciler runs against; injected so they are testable. */
33
36
  export interface CredentialReconcilerDeps {
34
- /** Verifies against IAM; resolves the account (domain) name. */
37
+ /**
38
+ * Verifies against IAM; resolves the account (domain) name.
39
+ *
40
+ * A rejection — IAM refusing the credential itself — must be distinguishable
41
+ * from a transient failure, because only a rejection discards what is stored.
42
+ * `isRejection` is how the caller says which it got; the reconciler never
43
+ * re-derives that judgement from a message.
44
+ */
35
45
  readonly verify: VerifyCredentials;
46
+ /** Whether a verify failure means the credential itself was refused. */
47
+ readonly isRejection: (error: unknown) => boolean;
36
48
  /** Records the non-secret status the browser half reads. */
37
49
  readonly recordStatus: RecordStatus;
38
50
  /** Read the recorded `credentialsStored` mirror this plugin owns. */
@@ -41,6 +53,15 @@ export interface CredentialReconcilerDeps {
41
53
  readonly readHint: ReadHint;
42
54
  /** Reads the stored pair; the bundle entry is decoded inside it. */
43
55
  readonly readPair: () => SignCredentials | undefined;
56
+ /**
57
+ * Discard the stored credentials.
58
+ *
59
+ * Called only when IAM refused them. A credential that IAM rejects cannot be
60
+ * used for anything this product does, so keeping it leaves the interface
61
+ * showing an account name beside a form asking the person to sign in — a
62
+ * state that states two opposite things at once.
63
+ */
64
+ readonly discard: () => void;
44
65
  }
45
66
  /** The reconcile state machine; driven by a timer and the GET-route hook. */
46
67
  export interface CredentialReconciler {
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.15",
4
+ "version": "0.0.17",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "license": "Apache-2.0",
44
44
  "dependencies": {
45
- "@huaweidevtools/aishell-dsh-credentials-store": "0.0.15"
45
+ "@huaweidevtools/aishell-dsh-credentials-store": "0.0.17"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "@deepseek-ai/cordis": "^4.0.4",