@huaweidevtools/aishell-dsh-client-credentials 0.0.2 → 0.0.4

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.
@@ -7,7 +7,7 @@
7
7
  export declare const NS: "aishell";
8
8
  /** Simplified Chinese dictionary (the key-set source of truth). */
9
9
  export declare const zh: {
10
- readonly 'account.unconfigured': "未配置华为云 IAM 凭据";
10
+ readonly 'account.unconfigured': "未配置凭据";
11
11
  readonly 'mode.readonly': "只读";
12
12
  readonly 'mode.readwrite': "读写";
13
13
  readonly 'mode.unavailable': "权限模式不可用";
@@ -16,19 +16,21 @@ export declare const zh: {
16
16
  readonly 'mode.unavailable.hint': "无法从 MCP 服务器读取权限模式;切换按钮暂不可用";
17
17
  readonly 'mode.switchToReadonly': "切换为只读模式";
18
18
  readonly 'mode.switchToReadwrite': "切换为读写模式";
19
- readonly 'section.settings.summary': "华为云 AI Shell 设置。";
20
- readonly 'section.credentials.title': "凭据";
21
19
  readonly 'section.credentials.hint.prefix': "需要进行华为云 IAM 认证,建议从";
22
20
  readonly 'section.credentials.hint.link': "API Explorer";
23
21
  readonly 'section.credentials.hint.suffix': "获取临时凭据,避免使用永久凭据。";
24
- readonly 'section.credentials.saved': "校验通过,已存入 keyring。";
25
- readonly 'section.credentials.save': "保存";
26
22
  readonly 'section.credentials.saving': "保存中…";
27
- readonly 'section.credentials.clear': "清除";
28
23
  readonly 'form.title': "需要华为云凭据";
24
+ readonly 'form.title.manual': "配置华为云凭据";
29
25
  readonly 'form.submit': "提交";
30
26
  readonly 'form.dismiss': "取消";
31
27
  readonly 'form.failed': "保存凭据失败";
28
+ readonly 'form.clear': "清除";
29
+ readonly 'form.clearing': "清除中…";
30
+ readonly 'form.clear.failed': "清除凭据失败";
31
+ readonly 'error.unreachable': "无法连接宿主凭据服务:";
32
+ readonly 'error.clear.serverFailed': "本机凭据已清除,但服务端凭据未清除(HTTP {status})";
33
+ readonly 'error.clear.serverUnreachable': "本机凭据已清除,但无法连接 MCP 服务器清除服务端凭据:";
32
34
  readonly 'section.field.accessKey': "Access Key";
33
35
  readonly 'section.field.accessKey.placeholder': "华为云 Access Key";
34
36
  readonly 'section.field.accessKey.hint': "Access Key 与 Secret Key 须同时填写,只填其一时不会保存。";
@@ -41,7 +43,7 @@ export declare const zh: {
41
43
  };
42
44
  /** English dictionary. */
43
45
  export declare const en: {
44
- readonly 'account.unconfigured': "No Huawei Cloud IAM credentials";
46
+ readonly 'account.unconfigured': "No credentials";
45
47
  readonly 'mode.readonly': "Read-only";
46
48
  readonly 'mode.readwrite': "Read-write";
47
49
  readonly 'mode.unavailable': "Mode unavailable";
@@ -50,19 +52,21 @@ export declare const en: {
50
52
  readonly 'mode.unavailable.hint': "Could not read the permission mode from the MCP server; the toggle is unavailable";
51
53
  readonly 'mode.switchToReadonly': "Switch to read-only mode";
52
54
  readonly 'mode.switchToReadwrite': "Switch to read-write mode";
53
- readonly 'section.settings.summary': "Huawei Cloud AI Shell settings.";
54
- readonly 'section.credentials.title': "Credentials";
55
55
  readonly 'section.credentials.hint.prefix': "Authenticate against Huawei Cloud IAM. Obtain temporary credentials from";
56
56
  readonly 'section.credentials.hint.link': "API Explorer";
57
57
  readonly 'section.credentials.hint.suffix': "and avoid permanent ones.";
58
- readonly 'section.credentials.saved': "Verified and saved to keyring.";
59
- readonly 'section.credentials.save': "Save";
60
58
  readonly 'section.credentials.saving': "Saving…";
61
- readonly 'section.credentials.clear': "Clear";
62
59
  readonly 'form.title': "Huawei Cloud credentials required";
60
+ readonly 'form.title.manual': "Configure Huawei Cloud credentials";
63
61
  readonly 'form.submit': "Submit";
64
62
  readonly 'form.dismiss': "Cancel";
65
63
  readonly 'form.failed': "Could not save credentials";
64
+ readonly 'form.clear': "Clear";
65
+ readonly 'form.clearing': "Clearing…";
66
+ readonly 'form.clear.failed': "Could not clear credentials";
67
+ readonly 'error.unreachable': "Could not reach the host credential service: ";
68
+ readonly 'error.clear.serverFailed': "Local credentials were cleared, but the server copy was not (HTTP {status})";
69
+ readonly 'error.clear.serverUnreachable': "Local credentials were cleared, but the MCP server could not be reached to clear the server copy: ";
66
70
  readonly 'section.field.accessKey': "Access Key";
67
71
  readonly 'section.field.accessKey.placeholder': "Huawei Access Key";
68
72
  readonly 'section.field.accessKey.hint': "Access Key and Secret Key are stored as a pair; one without the other is not saved.";
@@ -0,0 +1,88 @@
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 { CredentialsStore } from '@huaweidevtools/aishell-dsh-credentials-store';
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
+ /** Store account names for the Huawei Cloud credentials this reconciler reads. */
33
+ export interface ReconcileAccounts {
34
+ readonly accessKey: string;
35
+ readonly secretKey: string;
36
+ readonly securityToken: string;
37
+ }
38
+ /** Collaborators the reconciler runs against; injected so they are testable. */
39
+ export interface CredentialReconcilerDeps {
40
+ /** Durable credential store; only `get` is read here, so a `Pick` suffices. */
41
+ readonly store: Pick<CredentialsStore, 'get'>;
42
+ /** Verifies against IAM; resolves the account (domain) name. */
43
+ readonly verify: VerifyCredentials;
44
+ /** Records the non-secret status the browser half reads. */
45
+ readonly recordStatus: RecordStatus;
46
+ /** Read the recorded `credentialsStored` mirror this plugin owns. */
47
+ readonly readStored: ReadStored;
48
+ /** Read the recorded `accessKeyIdHint` mirror this plugin owns. */
49
+ readonly readHint: ReadHint;
50
+ /** Credential store account names to read AK/SK/STS from. */
51
+ readonly accounts: ReconcileAccounts;
52
+ }
53
+ /** The reconcile state machine; driven by a timer and the GET-route hook. */
54
+ export interface CredentialReconciler {
55
+ /**
56
+ * Re-derive the status from the store. Idempotent at steady state: when
57
+ * nothing changed it records nothing and verifies nothing. Call this on boot,
58
+ * on a timer, and on every GET to the status route.
59
+ */
60
+ readonly reconcile: () => void;
61
+ /**
62
+ * Drop the verify baseline so an in-flight verification's late result is
63
+ * discarded. Call this from the `clear` route: a verify that resolves after
64
+ * the store was emptied must not record a hint for credentials that are gone.
65
+ */
66
+ readonly resetVerifyBaseline: () => void;
67
+ }
68
+ /**
69
+ * Build the reconcile state machine.
70
+ *
71
+ * Two facts are reconciled independently, because they are independent:
72
+ * - `credentialsStored` — are AK/SK in the store right now?
73
+ * - `accessKeyIdHint` — what account name did IAM verification return?
74
+ *
75
+ * The hint is re-derived only when the credential material changed since the
76
+ * last verification. That single trigger covers both reasons to re-verify — a
77
+ * first-seen credential (the material has never been fingerprinted) and a
78
+ * rotation (the material differs from the last verified set) — and it keeps a
79
+ * failing verification (expired STS, IAM outage) from retrying every tick: the
80
+ * retry keys on the material changing, not on time alone, and a failed verify
81
+ * still records the fingerprint. Cleared by `resetVerifyBaseline` so a
82
+ * clear-then-rotate re-verifies from scratch.
83
+ *
84
+ * @param deps - collaborators. `readStored`/`readHint` read this plugin's own
85
+ * mirror so reconcile never depends on config flow-back timing.
86
+ */
87
+ export declare function createCredentialReconciler(deps: CredentialReconcilerDeps): CredentialReconciler;
88
+ //# 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.2",
3
+ "description": "AI Shell credentials — chip-opened web form for storing Huawei Cloud AK/SK in the credential store",
4
+ "version": "0.0.4",
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.2"
44
+ "@huaweidevtools/aishell-dsh-credentials-store": "0.0.4"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@deepseek-ai/cordis": "^4.0.4",
@@ -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