@huaweidevtools/aishell-dsh-client-credentials 0.0.35 → 0.0.37
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 +22 -12
- package/lib/types/client/permission-mode.d.ts +15 -8
- package/package.json +2 -2
package/lib/client.js
CHANGED
|
@@ -74,15 +74,18 @@ function asMode(value) {
|
|
|
74
74
|
return value === "read_only" || value === "read_write" ? value : void 0;
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
|
-
* Read
|
|
77
|
+
* Read one Session's mode from the Host route.
|
|
78
78
|
*
|
|
79
|
+
* @param sessionId - the conversation the chip is drawn in. Required: the route
|
|
80
|
+
* refuses a request that names none rather than answering with a
|
|
81
|
+
* process-wide value the chip would render as this conversation's own.
|
|
79
82
|
* @returns the mode, or `undefined` when it could not be read — a broken link
|
|
80
83
|
* must not be rendered as a working lock, so an unreadable mode is
|
|
81
84
|
* reported as unknown, never as `read_only`.
|
|
82
85
|
*/
|
|
83
|
-
async function readPermissionMode() {
|
|
86
|
+
async function readPermissionMode(sessionId) {
|
|
84
87
|
try {
|
|
85
|
-
const response = await fetch(PERMISSION_ROUTE);
|
|
88
|
+
const response = await fetch(`${PERMISSION_ROUTE}?session=${encodeURIComponent(sessionId)}`);
|
|
86
89
|
const body = await response.json();
|
|
87
90
|
if (body.ok !== true) return void 0;
|
|
88
91
|
return asMode(body.mode);
|
|
@@ -91,17 +94,21 @@ async function readPermissionMode() {
|
|
|
91
94
|
}
|
|
92
95
|
}
|
|
93
96
|
/**
|
|
94
|
-
* Write
|
|
97
|
+
* Write one Session's mode through the Host route.
|
|
95
98
|
*
|
|
99
|
+
* @param sessionId - the conversation the switch belongs to.
|
|
96
100
|
* @param mode - the mode to apply.
|
|
97
101
|
* @returns the mode the server reports afterwards, or `undefined` on failure.
|
|
98
102
|
*/
|
|
99
|
-
async function writePermissionMode(mode) {
|
|
103
|
+
async function writePermissionMode(sessionId, mode) {
|
|
100
104
|
try {
|
|
101
105
|
const response = await fetch(PERMISSION_ROUTE, {
|
|
102
106
|
method: "POST",
|
|
103
107
|
headers: { "content-type": "application/json" },
|
|
104
|
-
body: JSON.stringify({
|
|
108
|
+
body: JSON.stringify({
|
|
109
|
+
session: sessionId,
|
|
110
|
+
mode
|
|
111
|
+
})
|
|
105
112
|
});
|
|
106
113
|
const body = await response.json();
|
|
107
114
|
if (body.ok !== true) return void 0;
|
|
@@ -138,28 +145,31 @@ async function writePermissionMode(mode) {
|
|
|
138
145
|
* dialogs racing over one value. It is one hook whose surface can be swapped
|
|
139
146
|
* under it.
|
|
140
147
|
*
|
|
148
|
+
* @param sessionId - the conversation whose mode this control reads and writes.
|
|
149
|
+
* One per chip: the mode belongs to a Session, so the hook cannot answer
|
|
150
|
+
* without knowing which.
|
|
141
151
|
* @returns the current mode, a busy flag, the gated toggle, and the
|
|
142
152
|
* confirmation state for a pending read-write flip.
|
|
143
153
|
*/
|
|
144
|
-
function usePermissionMode() {
|
|
154
|
+
function usePermissionMode(sessionId) {
|
|
145
155
|
const [mode, setMode] = (0, react.useState)(void 0);
|
|
146
156
|
const [busy, setBusy] = (0, react.useState)(false);
|
|
147
157
|
const [confirmation, setConfirmation] = (0, react.useState)(void 0);
|
|
148
158
|
(0, react.useEffect)(() => {
|
|
149
159
|
let live = true;
|
|
150
160
|
(async () => {
|
|
151
|
-
const read = await readPermissionMode();
|
|
161
|
+
const read = await readPermissionMode(sessionId);
|
|
152
162
|
if (live && read !== void 0) setMode(read);
|
|
153
163
|
})();
|
|
154
164
|
return () => {
|
|
155
165
|
live = false;
|
|
156
166
|
};
|
|
157
|
-
}, []);
|
|
167
|
+
}, [sessionId]);
|
|
158
168
|
/** Write the mode the control should land on, from whatever is current. */
|
|
159
169
|
const apply$1 = (next) => {
|
|
160
170
|
setBusy(true);
|
|
161
171
|
(async () => {
|
|
162
|
-
const applied = await writePermissionMode(next);
|
|
172
|
+
const applied = await writePermissionMode(sessionId, next);
|
|
163
173
|
if (applied !== void 0) setMode(applied);
|
|
164
174
|
setBusy(false);
|
|
165
175
|
})();
|
|
@@ -313,7 +323,7 @@ function AishellAccountHint(props) {
|
|
|
313
323
|
const configured = Boolean(hint);
|
|
314
324
|
const t = props.t;
|
|
315
325
|
const openCredentialForm = props.openCredentialForm;
|
|
316
|
-
const { mode, busy, toggle, confirmation, cancelConfirmation, confirmToggle } = usePermissionMode();
|
|
326
|
+
const { mode, busy, toggle, confirmation, cancelConfirmation, confirmToggle } = usePermissionMode(props.sessionId);
|
|
317
327
|
const ref = (0, react.useRef)(null);
|
|
318
328
|
(0, react.useEffect)(() => {
|
|
319
329
|
const host = ref.current?.parentElement;
|
|
@@ -421,7 +431,7 @@ function AishellAccountHint(props) {
|
|
|
421
431
|
function AishellHeroChip(props) {
|
|
422
432
|
const blank = props.useSession((session) => session.blank);
|
|
423
433
|
const status = props.useCredentials((snapshot) => snapshot);
|
|
424
|
-
const { mode, busy, toggle, confirmation, cancelConfirmation, confirmToggle } = usePermissionMode();
|
|
434
|
+
const { mode, busy, toggle, confirmation, cancelConfirmation, confirmToggle } = usePermissionMode(props.sessionId);
|
|
425
435
|
const t = props.t;
|
|
426
436
|
const openCredentialForm = props.openCredentialForm;
|
|
427
437
|
const configured = Boolean(status.accessKeyIdHint);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Client half of the permission-mode switch, shared by both chips.
|
|
3
3
|
*
|
|
4
|
-
* The mode lives in the host process (`aishell-deploy`)
|
|
5
|
-
* writes it; this module owns the fetch and the state hook
|
|
6
|
-
* and the hero chip cannot drift apart.
|
|
4
|
+
* The mode lives in the host process (`aishell-deploy`), one per Session. A
|
|
5
|
+
* Host route reads and writes it; this module owns the fetch and the state hook
|
|
6
|
+
* so the composer chip and the hero chip cannot drift apart.
|
|
7
7
|
*
|
|
8
8
|
* @module @huaweidevtools/aishell-dsh-client-credentials/client/permission-mode
|
|
9
9
|
*/
|
|
@@ -51,20 +51,24 @@ export declare function toggleOutcome(mode: PermissionMode | undefined): ToggleO
|
|
|
51
51
|
*/
|
|
52
52
|
export declare function mayApply(acknowledged: boolean): boolean;
|
|
53
53
|
/**
|
|
54
|
-
* Read
|
|
54
|
+
* Read one Session's mode from the Host route.
|
|
55
55
|
*
|
|
56
|
+
* @param sessionId - the conversation the chip is drawn in. Required: the route
|
|
57
|
+
* refuses a request that names none rather than answering with a
|
|
58
|
+
* process-wide value the chip would render as this conversation's own.
|
|
56
59
|
* @returns the mode, or `undefined` when it could not be read — a broken link
|
|
57
60
|
* must not be rendered as a working lock, so an unreadable mode is
|
|
58
61
|
* reported as unknown, never as `read_only`.
|
|
59
62
|
*/
|
|
60
|
-
export declare function readPermissionMode(): Promise<PermissionMode | undefined>;
|
|
63
|
+
export declare function readPermissionMode(sessionId: string): Promise<PermissionMode | undefined>;
|
|
61
64
|
/**
|
|
62
|
-
* Write
|
|
65
|
+
* Write one Session's mode through the Host route.
|
|
63
66
|
*
|
|
67
|
+
* @param sessionId - the conversation the switch belongs to.
|
|
64
68
|
* @param mode - the mode to apply.
|
|
65
69
|
* @returns the mode the server reports afterwards, or `undefined` on failure.
|
|
66
70
|
*/
|
|
67
|
-
export declare function writePermissionMode(mode: PermissionMode): Promise<PermissionMode | undefined>;
|
|
71
|
+
export declare function writePermissionMode(sessionId: string, mode: PermissionMode): Promise<PermissionMode | undefined>;
|
|
68
72
|
/** State and toggle for a permission-mode control. */
|
|
69
73
|
export interface PermissionModeControl {
|
|
70
74
|
/** Mode in effect, or `undefined` while unknown. */
|
|
@@ -131,8 +135,11 @@ export interface PermissionConfirmation {
|
|
|
131
135
|
* dialogs racing over one value. It is one hook whose surface can be swapped
|
|
132
136
|
* under it.
|
|
133
137
|
*
|
|
138
|
+
* @param sessionId - the conversation whose mode this control reads and writes.
|
|
139
|
+
* One per chip: the mode belongs to a Session, so the hook cannot answer
|
|
140
|
+
* without knowing which.
|
|
134
141
|
* @returns the current mode, a busy flag, the gated toggle, and the
|
|
135
142
|
* confirmation state for a pending read-write flip.
|
|
136
143
|
*/
|
|
137
|
-
export declare function usePermissionMode(): PermissionModeControl;
|
|
144
|
+
export declare function usePermissionMode(sessionId: string): PermissionModeControl;
|
|
138
145
|
//# sourceMappingURL=permission-mode.d.ts.map
|
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.
|
|
4
|
+
"version": "0.0.37",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@deepseek-ai/dsh-client-store": "0.2.2-rc.1 || 0.2.2-rc.2 || 0.2.2-rc.3",
|
|
47
47
|
"immer": "^10.1.3",
|
|
48
48
|
"zustand": "~4.5.7",
|
|
49
|
-
"@huaweidevtools/aishell-dsh-credentials-store": "0.0.
|
|
49
|
+
"@huaweidevtools/aishell-dsh-credentials-store": "0.0.37"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@deepseek-ai/cordis": "^4.1.0",
|