@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.
@@ -0,0 +1,90 @@
1
+ /**
2
+ * The credential form's Host-side control.
3
+ *
4
+ * ## What this is for
5
+ *
6
+ * `aishell__auth` needs credentials that are not there. It cannot collect them
7
+ * — a credential a tool returns is a credential in the transcript — so it asks
8
+ * for the form to be put on screen, the person fills it, and the model calls
9
+ * `auth` again.
10
+ *
11
+ * ## Why the settings document carries the request
12
+ *
13
+ * The two halves live apart: the tool runs on the host, the form is browser
14
+ * code. The host cannot reach the browser over the fetch channel — that channel
15
+ * is browser→host only — so the request has to ride something the browser
16
+ * already watches. The settings document is exactly that: the browser half
17
+ * subscribes to this entry's config through `configForms`, and a volatile field
18
+ * written by the host shows up there.
19
+ *
20
+ * The document carries **only** a request token and a session id. Never a
21
+ * credential, never a verdict — those travel the other way, over the
22
+ * credential route, and the browser never receives a stored secret at all.
23
+ *
24
+ * ## Why the token, not a boolean
25
+ *
26
+ * The browser has to tell "a new request" from "the request it already opened".
27
+ * With a boolean, a second `auth` failure while the form is up would look
28
+ * identical to the first and the form would not re-open after the person
29
+ * cancelled it. The token changes on every request, and the browser compares it
30
+ * to the last one it acted on.
31
+ *
32
+ * ## Why nothing is awaited
33
+ *
34
+ * The tool cannot wait for the person — a tool call has no way to be paused for
35
+ * a human. So `auth` fails, the form appears, and the model calls again. That
36
+ * round trip is the whole protocol, and it is why the failure message and the
37
+ * form are worded as a pair.
38
+ *
39
+ * @module @huaweidevtools/aishell-dsh-client-credentials/form-request
40
+ */
41
+ /** Field of this entry's config that carries one pending request. */
42
+ export declare const FORM_REQUEST_FIELD = "credentialFormRequest";
43
+ /** What the browser reads out of that field. */
44
+ export interface CredentialFormRequest {
45
+ /**
46
+ * Identity of this request; a fresh value means "open the form again even if
47
+ * you opened one before".
48
+ */
49
+ readonly token: string;
50
+ /** Conversation to render the form in. */
51
+ readonly sessionId: string;
52
+ }
53
+ /** Writes one path-addressed edit into this entry's settings document. */
54
+ export type RecordField = (value: string) => void;
55
+ /**
56
+ * Build a request for one session, minting its token.
57
+ *
58
+ * The token is minted here rather than by the caller so a request cannot be
59
+ * recorded without one — the browser's "is this new?" test would then be
60
+ * comparing against nothing, and the form would not reopen after a cancel.
61
+ *
62
+ * @param sessionId - the conversation the form should render in.
63
+ * @returns the request, and its encoded form for the settings document.
64
+ */
65
+ export declare function formRequest(sessionId: string): {
66
+ readonly request: CredentialFormRequest;
67
+ readonly encoded: string;
68
+ };
69
+ /**
70
+ * Serialize a request for the settings document.
71
+ *
72
+ * The document holds strings — a volatile `string` field is what the browser
73
+ * half reads through `configForms` — so the request is JSON. Encoding rather
74
+ * than reshaping the config into several fields keeps the request atomic: the
75
+ * browser cannot observe a new token with an old session.
76
+ *
77
+ * @param request - the request to encode.
78
+ */
79
+ export declare function encodeRequest(request: CredentialFormRequest): string;
80
+ /**
81
+ * Read a request back out of the document.
82
+ *
83
+ * Anything unreadable reads as no request: a corrupt field should show nothing,
84
+ * not open a form bound to a session that does not exist.
85
+ *
86
+ * @param raw - the stored string, if any.
87
+ * @returns the request, or `undefined` when there is none usable.
88
+ */
89
+ export declare function decodeRequest(raw: string | undefined): CredentialFormRequest | undefined;
90
+ //# sourceMappingURL=form-request.d.ts.map
@@ -31,15 +31,24 @@ export interface Config {
31
31
  /** Readable verification failure the client form displays; set when the IAM check rejects. */
32
32
  lastError: Volatile<string>;
33
33
  /**
34
- * Session waiting for credentials, or `''` when none is.
34
+ * A pending request to open the credential form, or `''`.
35
35
  *
36
- * The session id rather than a boolean because the browser needs both facts
37
- * and they arrive together: "show the form" and "show it in this
38
- * conversation". `conversation.composer` is session-scoped, so a form without
39
- * a session has nowhere to render. Empty string rather than `undefined` so
40
- * the setting stays one string type across the wire.
36
+ * Written by `aishell__auth` when it finds no credentials; read by the
37
+ * browser half, which opens the form in the named session. A JSON token plus
38
+ * session id — see `./form-request.ts` for why it is a token and not a
39
+ * boolean, and why it travels the settings document rather than the fetch
40
+ * channel.
41
41
  */
42
- credentialRequestSession: Volatile<string>;
42
+ credentialFormRequest: Volatile<string>;
43
+ /**
44
+ * Token of the form request the person cancelled, or `''`.
45
+ *
46
+ * Written by the cancel route, read (and cleared) by `aishell__auth`. It
47
+ * exists so a model whose call failed does not retry forever: without it, the
48
+ * only observable difference between "the person said no" and "the person has
49
+ * not answered yet" is nothing.
50
+ */
51
+ credentialFormCancelled: Volatile<string>;
43
52
  }
44
53
  /**
45
54
  * Settings schema for this entry. Secrets are deliberately absent: they travel
@@ -50,50 +59,15 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
50
59
  credentialsStored: z<boolean, boolean, "volatile-defined">;
51
60
  accessKeyIdHint: z<string, string, "volatile-defined">;
52
61
  lastError: z<string, string, "volatile-defined">;
53
- credentialRequestSession: z<string, string, "volatile-defined">;
62
+ credentialFormRequest: z<string, string, "volatile-defined">;
63
+ credentialFormCancelled: z<string, string, "volatile-defined">;
54
64
  }>>, Schemastery.ObjectT<NoInfer<{
55
65
  credentialsStored: z<boolean, boolean, "volatile-defined">;
56
66
  accessKeyIdHint: z<string, string, "volatile-defined">;
57
67
  lastError: z<string, string, "volatile-defined">;
58
- credentialRequestSession: z<string, string, "volatile-defined">;
68
+ credentialFormRequest: z<string, string, "volatile-defined">;
69
+ credentialFormCancelled: z<string, string, "volatile-defined">;
59
70
  }>>, "plain">;
60
- /**
61
- * What the credential form collects, as the asking package expects it back.
62
- *
63
- * Declared here rather than imported from `aishell-ops-deploy`: the two
64
- * packages communicate over a Cordis event, not an import (see the event
65
- * declaration below), and the form has no business depending on the MCP
66
- * plugin's types. The shape is the contract; both sides state it.
67
- *
68
- * No region: the credential store holds none, and the region belongs to
69
- * whoever is calling. The asking package adds its own when the answer reaches
70
- * it.
71
- */
72
- interface SuppliedCredentials {
73
- readonly ak: string;
74
- readonly sk: string;
75
- /** Present only for STS credentials. */
76
- readonly securityToken?: string;
77
- }
78
- declare module '@deepseek-ai/cordis' {
79
- interface Events {
80
- /**
81
- * The MCP server asked for credentials and the store has none: show the
82
- * form, and call `settle` when the person is done.
83
- *
84
- * Declared (not imported) on both sides because it is the whole interface
85
- * between the credentials UI and the MCP plugin — the same shape the
86
- * permission switch's route uses, one step less direct.
87
- *
88
- * @mode emit
89
- */
90
- 'aishell/credential-request'(request: {
91
- readonly settle: (credentials: SuppliedCredentials | undefined) => void;
92
- readonly signal: AbortSignal | undefined;
93
- readonly sessionId: string | undefined;
94
- }): void;
95
- }
96
- }
97
71
  declare module '@deepseek-ai/cordis' {
98
72
  interface Events {
99
73
  /**
@@ -122,9 +96,10 @@ export interface CredentialRoutesDeps {
122
96
  /** Reads the cached account-name hint for the status response. */
123
97
  readonly hint: () => string;
124
98
  /**
125
- * Announces that the stored credentials changed, so consumers that hold a
126
- * snapshot of them (the MCP subprocess env) can rebuild. Called only after
127
- * the store actually changed — a rejected save stores nothing and stays silent.
99
+ * Announces that the stored credentials changed, so consumers that cached
100
+ * something derived from them (a resolved account identity, a sandbox key)
101
+ * can drop it. Called only after the store actually changed — a rejected save
102
+ * stores nothing and stays silent.
128
103
  */
129
104
  readonly notifyChanged: () => void;
130
105
  }
@@ -144,5 +119,4 @@ export declare function createCredentialRoutes(deps: CredentialRoutesDeps): {
144
119
  export declare const name = "aishell-client-credentials";
145
120
  export declare const inject: string[];
146
121
  export declare function apply(ctx: Context, config: Config): void;
147
- export {};
148
122
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Idempotent credential-status reconcile.
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.
13
+ *
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).
17
+ *
18
+ * @module @huaweidevtools/aishell-dsh-client-credentials/reconcile
19
+ */
20
+ import type { SignCredentials } from '@huaweidevtools/aishell-dsh-credentials-store/signer';
21
+ import type { SettingsPathOp } from '@deepseek-ai/dsh-settings';
22
+ /** One path-addressed status edit, shaped as `ctx.settings.mutate` takes. */
23
+ export type StatusOp = SettingsPathOp;
24
+ /** Records non-secret status the browser half reads; a refused write only logs. */
25
+ export type RecordStatus = (ops: readonly StatusOp[]) => void;
26
+ /** Verifies AK/SK (and optional token) against Huawei Cloud IAM; resolves the account name. */
27
+ export type VerifyCredentials = (ak: string, sk: string, token?: string) => Promise<string>;
28
+ /** Reads the recorded presence flag this plugin last wrote. */
29
+ export type ReadStored = () => boolean;
30
+ /** Reads the recorded account-name hint this plugin last wrote, or `null` when none. */
31
+ export type ReadHint = () => string | null;
32
+ /** Collaborators the reconciler runs against; injected so they are testable. */
33
+ export interface CredentialReconcilerDeps {
34
+ /** Verifies against IAM; resolves the account (domain) name. */
35
+ readonly verify: VerifyCredentials;
36
+ /** Records the non-secret status the browser half reads. */
37
+ readonly recordStatus: RecordStatus;
38
+ /** Read the recorded `credentialsStored` mirror this plugin owns. */
39
+ readonly readStored: ReadStored;
40
+ /** Read the recorded `accessKeyIdHint` mirror this plugin owns. */
41
+ readonly readHint: ReadHint;
42
+ /** Reads the stored pair; the bundle entry is decoded inside it. */
43
+ readonly readPair: () => SignCredentials | undefined;
44
+ }
45
+ /** The reconcile state machine; driven by a timer and the GET-route hook. */
46
+ export interface CredentialReconciler {
47
+ /**
48
+ * Re-derive the status from the store. Idempotent at steady state: when
49
+ * nothing changed it records nothing and verifies nothing. Call this on boot,
50
+ * on a timer, and on every GET to the status route.
51
+ */
52
+ readonly reconcile: () => void;
53
+ /**
54
+ * Drop the verify baseline so an in-flight verification's late result is
55
+ * discarded. Call this from the `clear` route: a verify that resolves after
56
+ * the store was emptied must not record a hint for credentials that are gone.
57
+ */
58
+ readonly resetVerifyBaseline: () => void;
59
+ }
60
+ /**
61
+ * Build the reconcile state machine.
62
+ *
63
+ * Two facts are reconciled independently, because they are independent:
64
+ * - `credentialsStored` — are AK/SK in the store right now?
65
+ * - `accessKeyIdHint` — what account name did IAM verification return?
66
+ *
67
+ * The hint is re-derived only when the credential material changed since the
68
+ * last verification. That single trigger covers both reasons to re-verify — a
69
+ * first-seen credential (the material has never been fingerprinted) and a
70
+ * rotation (the material differs from the last verified set) — and it keeps a
71
+ * failing verification (expired STS, IAM outage) from retrying every tick: the
72
+ * retry keys on the material changing, not on time alone, and a failed verify
73
+ * still records the fingerprint. Cleared by `resetVerifyBaseline` so a
74
+ * clear-then-rotate re-verifies from scratch.
75
+ *
76
+ * @param deps - collaborators. `readStored`/`readHint` read this plugin's own
77
+ * mirror so reconcile never depends on config flow-back timing.
78
+ */
79
+ export declare function createCredentialReconciler(deps: CredentialReconcilerDeps): CredentialReconciler;
80
+ //# sourceMappingURL=reconcile.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@huaweidevtools/aishell-dsh-client-credentials",
3
- "description": "AI Shell credentials settings panel — web form for storing Huawei Cloud AK/SK in the credential store",
4
- "version": "0.0.1-beta.1",
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.3",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -41,25 +41,28 @@
41
41
  },
42
42
  "license": "Apache-2.0",
43
43
  "dependencies": {
44
- "@huaweidevtools/aishell-dsh-credentials-store": "0.0.1-beta.1"
44
+ "@huaweidevtools/aishell-dsh-credentials-store": "0.0.1-beta.3"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@deepseek-ai/cordis": "^4.0.4",
48
- "@deepseek-ai/dsh-settings": "0.2.0-rc.1 || 0.2.1-alpha.1 || ^0.2.1"
48
+ "@deepseek-ai/dsh-client-connection": "0.2.0-rc.1 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1",
49
+ "@deepseek-ai/dsh-settings": "0.2.0-rc.1 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1",
50
+ "@deepseek-ai/dsh-tools": "0.2.0-rc.1 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1"
49
51
  },
50
52
  "devDependencies": {
51
53
  "@deepseek-ai/cordis": "^4.0.4",
52
54
  "@deepseek-ai/cordis-plugin-loader": "^1.0.5",
53
- "@deepseek-ai/dsh-client-connection": "0.2.0-rc.1",
54
- "@deepseek-ai/dsh-client-locale": "0.2.0-rc.1",
55
- "@deepseek-ai/dsh-client-store": "0.2.0-rc.1",
56
- "@deepseek-ai/dsh-client-ui-conversation": "0.2.0-rc.1",
57
- "@deepseek-ai/dsh-client-ui-renderer": "0.2.0-rc.1",
58
- "@deepseek-ai/dsh-client-ui-session": "0.2.0-rc.1",
59
- "@deepseek-ai/dsh-client-ui-settings": "0.2.0-rc.1",
60
- "@deepseek-ai/dsh-client-ui-slots": "0.2.0-rc.1",
61
- "@deepseek-ai/dsh-session": "0.2.0-rc.1",
62
- "@deepseek-ai/dsh-settings": "0.2.0-rc.1",
55
+ "@deepseek-ai/dsh-client-connection": "0.2.0-rc.1 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1",
56
+ "@deepseek-ai/dsh-client-locale": "0.2.0-rc.1 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1",
57
+ "@deepseek-ai/dsh-client-store": "0.2.0-rc.1 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1",
58
+ "@deepseek-ai/dsh-client-ui-conversation": "0.2.0-rc.1 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1",
59
+ "@deepseek-ai/dsh-client-ui-renderer": "0.2.0-rc.1 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1",
60
+ "@deepseek-ai/dsh-client-ui-session": "0.2.0-rc.1 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1",
61
+ "@deepseek-ai/dsh-client-ui-settings": "0.2.0-rc.1 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1",
62
+ "@deepseek-ai/dsh-client-ui-slots": "0.2.0-rc.1 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1",
63
+ "@deepseek-ai/dsh-session": "0.2.0-rc.1 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1",
64
+ "@deepseek-ai/dsh-settings": "0.2.0-rc.1 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1",
65
+ "@deepseek-ai/dsh-tools": "0.2.0-rc.1 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1",
63
66
  "@deepseek-ai/schemastery": "3.18.4",
64
67
  "@types/react": "~18.3.1",
65
68
  "react": "^18.2.0",
@@ -1,34 +0,0 @@
1
- /**
2
- * AI Shell credentials settings section.
3
- *
4
- * Renders three password inputs (Access Key ID, Secret Access Key, optional
5
- * Security Token) with a save button. The plaintext goes straight to the
6
- * Host's authenticated credential route, which verifies it against Huawei
7
- * Cloud IAM and transfers it into the credential store; the route answers with
8
- * the verdict in that same round trip, so no polling is needed. Presence of
9
- * already-stored credentials arrives through the `credentials` hooks
10
- * compartment as the Host-written non-secret fields — values never cross the
11
- * wire in either direction.
12
- */
13
- import { type ReactNode } from 'react';
14
- import type { SnapshotStore } from '@deepseek-ai/dsh-client-store';
15
- import type { InjectFace, PropsLocale, PropsRuntime, TranslateNS } from '@deepseek-ai/dsh-client-ui-slots';
16
- import { type CredentialStatus, type SaveVerdict } from './credential-status.ts';
17
- /** Injected callbacks bound in apply() and spread as props by the renderer. */
18
- export interface AishellCredentialsInjected {
19
- hooks: {
20
- /** Credential presence + verification verdict, rebound by the renderer as useCredentials. */
21
- credentials: SnapshotStore<CredentialStatus>;
22
- };
23
- /** Translator bound to the `aishell` namespace. */
24
- t: TranslateNS<'aishell'>;
25
- /** Store AK/SK/SecurityToken through the Host credential route (Host verifies against IAM, then transfers to the credential store). */
26
- save: (accessKeyId: string, secretAccessKey: string, securityToken?: string) => Promise<SaveVerdict>;
27
- /** Clear all credentials from the credential store. */
28
- clear: () => Promise<SaveVerdict>;
29
- }
30
- /** Full component props: section owner share + locale seat + inject face. */
31
- export type AishellCredentialsSectionProps = PropsRuntime<'settings.section'> & PropsLocale<'aishell'> & InjectFace<AishellCredentialsInjected>;
32
- /** Render the credentials form. */
33
- export declare function AishellCredentialsSection(props: AishellCredentialsSectionProps): ReactNode;
34
- //# sourceMappingURL=AishellCredentialsSection.d.ts.map
@@ -1,27 +0,0 @@
1
- /**
2
- * Open DSH's Settings modal.
3
- *
4
- * DSH exposes no service API for this — the modal's open state is
5
- * component-local inside `SettingsRoot`, toggled only by its trigger button.
6
- * The trigger is the `button[aria-haspopup="dialog"]` inside the
7
- * `[data-slot="sidebar.settings"]` outlet, which is a stable, slot-key + ARIA
8
- * based selector rather than a hashed CSS-module class. Clicking it is the
9
- * same gesture the sidebar gear makes.
10
- *
11
- * Shared by both credential chips so they cannot diverge; the hero chip opens
12
- * Settings from the same affordance the composer chip uses.
13
- *
14
- * @module @huaweidevtools/aishell-dsh-client-credentials/client/open-settings
15
- */
16
- /**
17
- * Click DSH's Settings trigger on the user's behalf.
18
- *
19
- * A missing trigger is reported on the console rather than thrown. There is
20
- * nothing to click when the sidebar has not mounted, and throwing inside a
21
- * click handler would surface as an unhandled rejection; but staying silent
22
- * would make a selector drift indistinguishable from a dead click, since a
23
- * `??=`-style no-op leaves no trace anywhere. The warning is the only signal
24
- * that this selector needs updating.
25
- */
26
- export declare function openSettings(): void;
27
- //# sourceMappingURL=open-settings.d.ts.map