@huaweidevtools/aishell-dsh-client-credentials 0.0.36 → 0.0.38
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 +132 -28
- package/lib/types/client/locales.d.ts +4 -2
- package/lib/types/client/permission-mode.d.ts +99 -12
- package/package.json +18 -18
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,84 @@ async function readPermissionMode() {
|
|
|
91
94
|
}
|
|
92
95
|
}
|
|
93
96
|
/**
|
|
94
|
-
*
|
|
97
|
+
* Delays between read attempts while the mode is unknown.
|
|
98
|
+
*
|
|
99
|
+
* A Host answers a read once `api/aishell/permission` is registered; while the
|
|
100
|
+
* route is absent the answer is `undefined`. A conversation the browser
|
|
101
|
+
* restores can reach the page inside that window, so the schedule below gives
|
|
102
|
+
* the read a second attempt: short at first, because the route appears within
|
|
103
|
+
* a round trip of the Host being ready, and longer as the wait goes on, because
|
|
104
|
+
* each attempt costs a request.
|
|
105
|
+
*
|
|
106
|
+
* The list is finite: a mode that stays unreadable is answered by the manual
|
|
107
|
+
* re-read on the control, not by a request every few seconds for the life of
|
|
108
|
+
* the page. Together the delays cover roughly twenty seconds of start-up.
|
|
109
|
+
*/
|
|
110
|
+
const MODE_READ_RETRY_DELAYS_MS = [
|
|
111
|
+
200,
|
|
112
|
+
500,
|
|
113
|
+
1e3,
|
|
114
|
+
2e3,
|
|
115
|
+
3e3,
|
|
116
|
+
5e3,
|
|
117
|
+
8e3
|
|
118
|
+
];
|
|
119
|
+
/**
|
|
120
|
+
* How long to wait before the next read, given how many have failed.
|
|
121
|
+
*
|
|
122
|
+
* @param failedAttempts - consecutive reads that returned no mode.
|
|
123
|
+
* @returns the delay in milliseconds; the final entry repeats.
|
|
124
|
+
*/
|
|
125
|
+
function modeReadRetryDelay(failedAttempts) {
|
|
126
|
+
const last = MODE_READ_RETRY_DELAYS_MS.length - 1;
|
|
127
|
+
return MODE_READ_RETRY_DELAYS_MS[Math.min(Math.max(failedAttempts, 0), last)];
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Read the mode, retrying over the start-up window.
|
|
131
|
+
*
|
|
132
|
+
* A successful read is the server's answer and ends the loop, so the ordinary
|
|
133
|
+
* case costs one request. Retries cover the interval in which the Host has not
|
|
134
|
+
* registered the route yet and answers `undefined`; a mode that has been read
|
|
135
|
+
* is final until the person changes it.
|
|
136
|
+
*
|
|
137
|
+
* Attempts are bounded by {@link MODE_READ_RETRY_DELAYS_MS}. `undefined` then
|
|
138
|
+
* means "still unknown", not "the mode is absent", and the control stays
|
|
139
|
+
* interactive so the person can ask again without reloading the page.
|
|
140
|
+
*
|
|
141
|
+
* @param deps - the read, the liveness check, and an optional sleep.
|
|
142
|
+
* @returns the mode once one is read, or `undefined` when the caller went away
|
|
143
|
+
* or the attempts ran out.
|
|
144
|
+
*/
|
|
145
|
+
async function readPermissionModeUntilKnown(deps) {
|
|
146
|
+
const sleep = deps.sleep ?? ((ms) => new Promise((resolve) => {
|
|
147
|
+
setTimeout(resolve, ms);
|
|
148
|
+
}));
|
|
149
|
+
for (let failed = 0; failed <= MODE_READ_RETRY_DELAYS_MS.length; failed += 1) {
|
|
150
|
+
const mode = await deps.read();
|
|
151
|
+
if (mode !== void 0) return mode;
|
|
152
|
+
if (!deps.isLive() || failed === MODE_READ_RETRY_DELAYS_MS.length) return void 0;
|
|
153
|
+
await sleep(modeReadRetryDelay(failed));
|
|
154
|
+
if (!deps.isLive()) return void 0;
|
|
155
|
+
}
|
|
156
|
+
/* v8 ignore next -- the loop returns on the final iteration */
|
|
157
|
+
return void 0;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Write one Session's mode through the Host route.
|
|
95
161
|
*
|
|
162
|
+
* @param sessionId - the conversation the switch belongs to.
|
|
96
163
|
* @param mode - the mode to apply.
|
|
97
164
|
* @returns the mode the server reports afterwards, or `undefined` on failure.
|
|
98
165
|
*/
|
|
99
|
-
async function writePermissionMode(mode) {
|
|
166
|
+
async function writePermissionMode(sessionId, mode) {
|
|
100
167
|
try {
|
|
101
168
|
const response = await fetch(PERMISSION_ROUTE, {
|
|
102
169
|
method: "POST",
|
|
103
170
|
headers: { "content-type": "application/json" },
|
|
104
|
-
body: JSON.stringify({
|
|
171
|
+
body: JSON.stringify({
|
|
172
|
+
session: sessionId,
|
|
173
|
+
mode
|
|
174
|
+
})
|
|
105
175
|
});
|
|
106
176
|
const body = await response.json();
|
|
107
177
|
if (body.ok !== true) return void 0;
|
|
@@ -113,9 +183,19 @@ async function writePermissionMode(mode) {
|
|
|
113
183
|
/**
|
|
114
184
|
* Subscribe a control to the permission mode.
|
|
115
185
|
*
|
|
116
|
-
* Reads
|
|
117
|
-
*
|
|
118
|
-
*
|
|
186
|
+
* Reads on mount, and reads again when the person asks. The mode is server
|
|
187
|
+
* state that only a person changes, so there is no poll: each surface re-reads
|
|
188
|
+
* on its own mount, and a press on an unknown-mode control is the one other
|
|
189
|
+
* trigger.
|
|
190
|
+
*
|
|
191
|
+
* ## Why the read retries
|
|
192
|
+
*
|
|
193
|
+
* The mode lives in the Host process, and a page can render before that process
|
|
194
|
+
* has put `api/aishell/permission` in place — a restored conversation reaches
|
|
195
|
+
* the browser before the Host finishes registering its routes. A read in that
|
|
196
|
+
* window answers nothing about the mode, so the first read retries over a short
|
|
197
|
+
* schedule rather than reporting "unknown" from one attempt. The control a
|
|
198
|
+
* person presses reads again, which covers a window that was still too early.
|
|
119
199
|
*
|
|
120
200
|
* ## Why the confirmation lives here rather than in a chip
|
|
121
201
|
*
|
|
@@ -138,28 +218,44 @@ async function writePermissionMode(mode) {
|
|
|
138
218
|
* dialogs racing over one value. It is one hook whose surface can be swapped
|
|
139
219
|
* under it.
|
|
140
220
|
*
|
|
221
|
+
* @param sessionId - the conversation whose mode this control reads and writes.
|
|
222
|
+
* One per chip: the mode belongs to a Session, so the hook cannot answer
|
|
223
|
+
* without knowing which.
|
|
141
224
|
* @returns the current mode, a busy flag, the gated toggle, and the
|
|
142
225
|
* confirmation state for a pending read-write flip.
|
|
143
226
|
*/
|
|
144
|
-
function usePermissionMode() {
|
|
227
|
+
function usePermissionMode(sessionId) {
|
|
145
228
|
const [mode, setMode] = (0, react.useState)(void 0);
|
|
146
229
|
const [busy, setBusy] = (0, react.useState)(false);
|
|
147
230
|
const [confirmation, setConfirmation] = (0, react.useState)(void 0);
|
|
231
|
+
/**
|
|
232
|
+
* Bumped by {@link reread} to run the read again.
|
|
233
|
+
*
|
|
234
|
+
* A counter rather than a flag, so each press is a state change: a flag
|
|
235
|
+
* returned to `false` on completion either swallows a press made during a
|
|
236
|
+
* read or re-runs the effect on a value that did not change. The previous
|
|
237
|
+
* effect's cleanup runs before the new one, so its loop stops rather than
|
|
238
|
+
* overlapping.
|
|
239
|
+
*/
|
|
240
|
+
const [readGeneration, setReadGeneration] = (0, react.useState)(0);
|
|
148
241
|
(0, react.useEffect)(() => {
|
|
149
242
|
let live = true;
|
|
150
243
|
(async () => {
|
|
151
|
-
const read = await
|
|
244
|
+
const read = await readPermissionModeUntilKnown({
|
|
245
|
+
read: () => readPermissionMode(sessionId),
|
|
246
|
+
isLive: () => live
|
|
247
|
+
});
|
|
152
248
|
if (live && read !== void 0) setMode(read);
|
|
153
249
|
})();
|
|
154
250
|
return () => {
|
|
155
251
|
live = false;
|
|
156
252
|
};
|
|
157
|
-
}, []);
|
|
253
|
+
}, [sessionId, readGeneration]);
|
|
158
254
|
/** Write the mode the control should land on, from whatever is current. */
|
|
159
255
|
const apply$1 = (next) => {
|
|
160
256
|
setBusy(true);
|
|
161
257
|
(async () => {
|
|
162
|
-
const applied = await writePermissionMode(next);
|
|
258
|
+
const applied = await writePermissionMode(sessionId, next);
|
|
163
259
|
if (applied !== void 0) setMode(applied);
|
|
164
260
|
setBusy(false);
|
|
165
261
|
})();
|
|
@@ -190,13 +286,17 @@ function usePermissionMode() {
|
|
|
190
286
|
setConfirmation(void 0);
|
|
191
287
|
apply$1("read_write");
|
|
192
288
|
};
|
|
289
|
+
const reread = () => {
|
|
290
|
+
setReadGeneration((generation) => generation + 1);
|
|
291
|
+
};
|
|
193
292
|
return {
|
|
194
293
|
mode,
|
|
195
294
|
busy,
|
|
196
295
|
toggle,
|
|
197
296
|
confirmation,
|
|
198
297
|
cancelConfirmation,
|
|
199
|
-
confirmToggle
|
|
298
|
+
confirmToggle,
|
|
299
|
+
reread
|
|
200
300
|
};
|
|
201
301
|
}
|
|
202
302
|
|
|
@@ -313,7 +413,7 @@ function AishellAccountHint(props) {
|
|
|
313
413
|
const configured = Boolean(hint);
|
|
314
414
|
const t = props.t;
|
|
315
415
|
const openCredentialForm = props.openCredentialForm;
|
|
316
|
-
const { mode, busy, toggle, confirmation, cancelConfirmation, confirmToggle } = usePermissionMode();
|
|
416
|
+
const { mode, busy, toggle, confirmation, cancelConfirmation, confirmToggle, reread } = usePermissionMode(props.sessionId);
|
|
317
417
|
const ref = (0, react.useRef)(null);
|
|
318
418
|
(0, react.useEffect)(() => {
|
|
319
419
|
const host = ref.current?.parentElement;
|
|
@@ -393,15 +493,16 @@ function AishellAccountHint(props) {
|
|
|
393
493
|
type: "button",
|
|
394
494
|
className: CHIP_CLASS,
|
|
395
495
|
onClick: () => {
|
|
396
|
-
|
|
496
|
+
if (mode === void 0) reread();
|
|
497
|
+
else toggle();
|
|
397
498
|
},
|
|
398
|
-
disabled:
|
|
399
|
-
"aria-label": mode === "read_write" ? t("mode.switchToReadonly") : t("mode.switchToReadwrite"),
|
|
499
|
+
disabled: busy,
|
|
500
|
+
"aria-label": mode === void 0 ? t("mode.unavailable.retry") : mode === "read_write" ? t("mode.switchToReadonly") : t("mode.switchToReadwrite"),
|
|
400
501
|
style: {
|
|
401
502
|
...pillStyle,
|
|
402
503
|
color: mode === void 0 ? "var(--dsw-alias-label-tertiary)" : mode === "read_only" ? "var(--dsw-alias-state-success-primary)" : "var(--dsw-alias-state-warn-label)",
|
|
403
|
-
opacity:
|
|
404
|
-
cursor:
|
|
504
|
+
opacity: busy ? .6 : 1,
|
|
505
|
+
cursor: busy ? "default" : "pointer"
|
|
405
506
|
},
|
|
406
507
|
title: mode === void 0 ? t("mode.unavailable.hint") : mode === "read_only" ? t("mode.readonly.hint") : t("mode.readwrite.hint"),
|
|
407
508
|
children: mode === void 0 ? t("mode.unavailable") : mode === "read_only" ? t("mode.readonly") : t("mode.readwrite")
|
|
@@ -421,7 +522,7 @@ function AishellAccountHint(props) {
|
|
|
421
522
|
function AishellHeroChip(props) {
|
|
422
523
|
const blank = props.useSession((session) => session.blank);
|
|
423
524
|
const status = props.useCredentials((snapshot) => snapshot);
|
|
424
|
-
const { mode, busy, toggle, confirmation, cancelConfirmation, confirmToggle } = usePermissionMode();
|
|
525
|
+
const { mode, busy, toggle, confirmation, cancelConfirmation, confirmToggle, reread } = usePermissionMode(props.sessionId);
|
|
425
526
|
const t = props.t;
|
|
426
527
|
const openCredentialForm = props.openCredentialForm;
|
|
427
528
|
const configured = Boolean(status.accessKeyIdHint);
|
|
@@ -549,16 +650,17 @@ function AishellHeroChip(props) {
|
|
|
549
650
|
configured && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
550
651
|
type: "button",
|
|
551
652
|
onClick: () => {
|
|
552
|
-
|
|
653
|
+
if (mode === void 0) reread();
|
|
654
|
+
else toggle();
|
|
553
655
|
},
|
|
554
|
-
disabled:
|
|
555
|
-
"aria-label": mode === "read_write" ? t("mode.switchToReadonly") : t("mode.switchToReadwrite"),
|
|
656
|
+
disabled: busy,
|
|
657
|
+
"aria-label": mode === void 0 ? t("mode.unavailable.retry") : mode === "read_write" ? t("mode.switchToReadonly") : t("mode.switchToReadwrite"),
|
|
556
658
|
title: mode === void 0 ? t("mode.unavailable.hint") : mode === "read_only" ? t("mode.readonly.hint") : t("mode.readwrite.hint"),
|
|
557
659
|
style: {
|
|
558
660
|
...pillStyle,
|
|
559
661
|
color: mode === void 0 ? "var(--dsw-alias-label-tertiary)" : mode === "read_only" ? "var(--dsw-alias-state-success-primary)" : "var(--dsw-alias-state-warn-label)",
|
|
560
|
-
opacity:
|
|
561
|
-
cursor:
|
|
662
|
+
opacity: busy ? .6 : 1,
|
|
663
|
+
cursor: busy ? "default" : "pointer"
|
|
562
664
|
},
|
|
563
665
|
children: mode === void 0 ? t("mode.unavailable") : mode === "read_only" ? t("mode.readonly") : t("mode.readwrite")
|
|
564
666
|
}),
|
|
@@ -1899,7 +2001,8 @@ const zh = {
|
|
|
1899
2001
|
"mode.unavailable": "权限模式不可用",
|
|
1900
2002
|
"mode.readonly.hint": "当前:只读 — 只允许查询云资源,点击切换为读写",
|
|
1901
2003
|
"mode.readwrite.hint": "当前:读写 — 允许变更云资源,点击切换为只读",
|
|
1902
|
-
"mode.unavailable.hint": "
|
|
2004
|
+
"mode.unavailable.hint": "无法读取权限模式;点击重试",
|
|
2005
|
+
"mode.unavailable.retry": "重新读取权限模式",
|
|
1903
2006
|
"mode.switchToReadonly": "切换为只读模式",
|
|
1904
2007
|
"mode.switchToReadwrite": "切换为读写模式",
|
|
1905
2008
|
"mode.confirm.title": "确认切换为读写模式?",
|
|
@@ -1955,7 +2058,8 @@ const en = {
|
|
|
1955
2058
|
"mode.unavailable": "Mode unavailable",
|
|
1956
2059
|
"mode.readonly.hint": "Read-only — cloud queries only. Click for read-write",
|
|
1957
2060
|
"mode.readwrite.hint": "Read-write — cloud changes allowed. Click for read-only",
|
|
1958
|
-
"mode.unavailable.hint": "Could not read the permission mode;
|
|
2061
|
+
"mode.unavailable.hint": "Could not read the permission mode; click to retry",
|
|
2062
|
+
"mode.unavailable.retry": "Read the permission mode again",
|
|
1959
2063
|
"mode.switchToReadonly": "Switch to read-only mode",
|
|
1960
2064
|
"mode.switchToReadwrite": "Switch to read-write mode",
|
|
1961
2065
|
"mode.confirm.title": "Switch to read-write?",
|
|
@@ -13,7 +13,8 @@ export declare const zh: {
|
|
|
13
13
|
readonly 'mode.unavailable': "权限模式不可用";
|
|
14
14
|
readonly 'mode.readonly.hint': "当前:只读 — 只允许查询云资源,点击切换为读写";
|
|
15
15
|
readonly 'mode.readwrite.hint': "当前:读写 — 允许变更云资源,点击切换为只读";
|
|
16
|
-
readonly 'mode.unavailable.hint': "
|
|
16
|
+
readonly 'mode.unavailable.hint': "无法读取权限模式;点击重试";
|
|
17
|
+
readonly 'mode.unavailable.retry': "重新读取权限模式";
|
|
17
18
|
readonly 'mode.switchToReadonly': "切换为只读模式";
|
|
18
19
|
readonly 'mode.switchToReadwrite': "切换为读写模式";
|
|
19
20
|
readonly 'mode.confirm.title': "确认切换为读写模式?";
|
|
@@ -69,7 +70,8 @@ export declare const en: {
|
|
|
69
70
|
readonly 'mode.unavailable': "Mode unavailable";
|
|
70
71
|
readonly 'mode.readonly.hint': "Read-only — cloud queries only. Click for read-write";
|
|
71
72
|
readonly 'mode.readwrite.hint': "Read-write — cloud changes allowed. Click for read-only";
|
|
72
|
-
readonly 'mode.unavailable.hint': "Could not read the permission mode;
|
|
73
|
+
readonly 'mode.unavailable.hint': "Could not read the permission mode; click to retry";
|
|
74
|
+
readonly 'mode.unavailable.retry': "Read the permission mode again";
|
|
73
75
|
readonly 'mode.switchToReadonly': "Switch to read-only mode";
|
|
74
76
|
readonly 'mode.switchToReadwrite': "Switch to read-write mode";
|
|
75
77
|
readonly 'mode.confirm.title': "Switch to read-write?";
|
|
@@ -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,78 @@ 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
|
-
*
|
|
65
|
+
* Delays between read attempts while the mode is unknown.
|
|
66
|
+
*
|
|
67
|
+
* A Host answers a read once `api/aishell/permission` is registered; while the
|
|
68
|
+
* route is absent the answer is `undefined`. A conversation the browser
|
|
69
|
+
* restores can reach the page inside that window, so the schedule below gives
|
|
70
|
+
* the read a second attempt: short at first, because the route appears within
|
|
71
|
+
* a round trip of the Host being ready, and longer as the wait goes on, because
|
|
72
|
+
* each attempt costs a request.
|
|
73
|
+
*
|
|
74
|
+
* The list is finite: a mode that stays unreadable is answered by the manual
|
|
75
|
+
* re-read on the control, not by a request every few seconds for the life of
|
|
76
|
+
* the page. Together the delays cover roughly twenty seconds of start-up.
|
|
77
|
+
*/
|
|
78
|
+
export declare const MODE_READ_RETRY_DELAYS_MS: readonly [200, 500, 1000, 2000, 3000, 5000, 8000];
|
|
79
|
+
/**
|
|
80
|
+
* How long to wait before the next read, given how many have failed.
|
|
81
|
+
*
|
|
82
|
+
* @param failedAttempts - consecutive reads that returned no mode.
|
|
83
|
+
* @returns the delay in milliseconds; the final entry repeats.
|
|
84
|
+
*/
|
|
85
|
+
export declare function modeReadRetryDelay(failedAttempts: number): number;
|
|
86
|
+
/** What {@link readPermissionModeUntilKnown} reads through. */
|
|
87
|
+
export interface ModeReadDeps {
|
|
88
|
+
/** One attempt; resolves `undefined` when it could not answer. */
|
|
89
|
+
readonly read: () => Promise<PermissionMode | undefined>;
|
|
90
|
+
/**
|
|
91
|
+
* Whether the caller is still mounted.
|
|
92
|
+
*
|
|
93
|
+
* Checked before each retry, so a read belongs to the surface that started
|
|
94
|
+
* it: a chip that unmounted stops asking, and no request goes out naming a
|
|
95
|
+
* conversation no page is showing.
|
|
96
|
+
*/
|
|
97
|
+
readonly isLive: () => boolean;
|
|
98
|
+
/** Wait between attempts; injectable so a spec drives the schedule directly. */
|
|
99
|
+
readonly sleep?: (ms: number) => Promise<void>;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Read the mode, retrying over the start-up window.
|
|
103
|
+
*
|
|
104
|
+
* A successful read is the server's answer and ends the loop, so the ordinary
|
|
105
|
+
* case costs one request. Retries cover the interval in which the Host has not
|
|
106
|
+
* registered the route yet and answers `undefined`; a mode that has been read
|
|
107
|
+
* is final until the person changes it.
|
|
63
108
|
*
|
|
109
|
+
* Attempts are bounded by {@link MODE_READ_RETRY_DELAYS_MS}. `undefined` then
|
|
110
|
+
* means "still unknown", not "the mode is absent", and the control stays
|
|
111
|
+
* interactive so the person can ask again without reloading the page.
|
|
112
|
+
*
|
|
113
|
+
* @param deps - the read, the liveness check, and an optional sleep.
|
|
114
|
+
* @returns the mode once one is read, or `undefined` when the caller went away
|
|
115
|
+
* or the attempts ran out.
|
|
116
|
+
*/
|
|
117
|
+
export declare function readPermissionModeUntilKnown(deps: ModeReadDeps): Promise<PermissionMode | undefined>;
|
|
118
|
+
/**
|
|
119
|
+
* Write one Session's mode through the Host route.
|
|
120
|
+
*
|
|
121
|
+
* @param sessionId - the conversation the switch belongs to.
|
|
64
122
|
* @param mode - the mode to apply.
|
|
65
123
|
* @returns the mode the server reports afterwards, or `undefined` on failure.
|
|
66
124
|
*/
|
|
67
|
-
export declare function writePermissionMode(mode: PermissionMode): Promise<PermissionMode | undefined>;
|
|
125
|
+
export declare function writePermissionMode(sessionId: string, mode: PermissionMode): Promise<PermissionMode | undefined>;
|
|
68
126
|
/** State and toggle for a permission-mode control. */
|
|
69
127
|
export interface PermissionModeControl {
|
|
70
128
|
/** Mode in effect, or `undefined` while unknown. */
|
|
@@ -79,7 +137,9 @@ export interface PermissionModeControl {
|
|
|
79
137
|
* once the person acknowledges. A flip back to read-only gives up access,
|
|
80
138
|
* which needs no warning, so it applies immediately.
|
|
81
139
|
*
|
|
82
|
-
* No-op while unknown or busy.
|
|
140
|
+
* No-op while unknown or busy. A press on an unknown-mode control belongs to
|
|
141
|
+
* {@link reread}: there is no current mode to flip away from, and the control
|
|
142
|
+
* that reaches this function has one meaning per state.
|
|
83
143
|
*/
|
|
84
144
|
readonly toggle: () => void;
|
|
85
145
|
/**
|
|
@@ -95,6 +155,20 @@ export interface PermissionModeControl {
|
|
|
95
155
|
readonly cancelConfirmation: () => void;
|
|
96
156
|
/** Apply the awaited read-write flip; the confirmation must be open. */
|
|
97
157
|
readonly confirmToggle: () => void;
|
|
158
|
+
/**
|
|
159
|
+
* Read the mode again, for a control showing "unavailable".
|
|
160
|
+
*
|
|
161
|
+
* Starts a fresh read. Its first attempt is immediate, so a Host that has
|
|
162
|
+
* registered the route since answers within a round trip and the control
|
|
163
|
+
* updates at once; a Host still not ready resumes the schedule from its
|
|
164
|
+
* shortest delay, which keeps a press immediate rather than making it wait
|
|
165
|
+
* out a delay that a previous read already used.
|
|
166
|
+
*
|
|
167
|
+
* One read runs at a time: the new generation unmounts the previous effect
|
|
168
|
+
* first, whose loop stops before its next retry, so repeated presses cannot
|
|
169
|
+
* accumulate loops.
|
|
170
|
+
*/
|
|
171
|
+
readonly reread: () => void;
|
|
98
172
|
}
|
|
99
173
|
/** The gate shown before a flip to read-write. */
|
|
100
174
|
export interface PermissionConfirmation {
|
|
@@ -106,9 +180,19 @@ export interface PermissionConfirmation {
|
|
|
106
180
|
/**
|
|
107
181
|
* Subscribe a control to the permission mode.
|
|
108
182
|
*
|
|
109
|
-
* Reads
|
|
110
|
-
*
|
|
111
|
-
*
|
|
183
|
+
* Reads on mount, and reads again when the person asks. The mode is server
|
|
184
|
+
* state that only a person changes, so there is no poll: each surface re-reads
|
|
185
|
+
* on its own mount, and a press on an unknown-mode control is the one other
|
|
186
|
+
* trigger.
|
|
187
|
+
*
|
|
188
|
+
* ## Why the read retries
|
|
189
|
+
*
|
|
190
|
+
* The mode lives in the Host process, and a page can render before that process
|
|
191
|
+
* has put `api/aishell/permission` in place — a restored conversation reaches
|
|
192
|
+
* the browser before the Host finishes registering its routes. A read in that
|
|
193
|
+
* window answers nothing about the mode, so the first read retries over a short
|
|
194
|
+
* schedule rather than reporting "unknown" from one attempt. The control a
|
|
195
|
+
* person presses reads again, which covers a window that was still too early.
|
|
112
196
|
*
|
|
113
197
|
* ## Why the confirmation lives here rather than in a chip
|
|
114
198
|
*
|
|
@@ -131,8 +215,11 @@ export interface PermissionConfirmation {
|
|
|
131
215
|
* dialogs racing over one value. It is one hook whose surface can be swapped
|
|
132
216
|
* under it.
|
|
133
217
|
*
|
|
218
|
+
* @param sessionId - the conversation whose mode this control reads and writes.
|
|
219
|
+
* One per chip: the mode belongs to a Session, so the hook cannot answer
|
|
220
|
+
* without knowing which.
|
|
134
221
|
* @returns the current mode, a busy flag, the gated toggle, and the
|
|
135
222
|
* confirmation state for a pending read-write flip.
|
|
136
223
|
*/
|
|
137
|
-
export declare function usePermissionMode(): PermissionModeControl;
|
|
224
|
+
export declare function usePermissionMode(sessionId: string): PermissionModeControl;
|
|
138
225
|
//# 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.38",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -43,32 +43,32 @@
|
|
|
43
43
|
},
|
|
44
44
|
"license": "Apache-2.0",
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@deepseek-ai/dsh-client-store": "0.2.2-rc.
|
|
46
|
+
"@deepseek-ai/dsh-client-store": "0.2.2-rc.5",
|
|
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.38"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@deepseek-ai/cordis": "^4.1.0",
|
|
53
|
-
"@deepseek-ai/dsh-client-connection": "0.2.2-rc.
|
|
54
|
-
"@deepseek-ai/dsh-settings": "0.2.2-rc.
|
|
55
|
-
"@deepseek-ai/dsh-tools": "0.2.2-rc.
|
|
53
|
+
"@deepseek-ai/dsh-client-connection": "0.2.2-rc.5",
|
|
54
|
+
"@deepseek-ai/dsh-settings": "0.2.2-rc.5",
|
|
55
|
+
"@deepseek-ai/dsh-tools": "0.2.2-rc.5"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@deepseek-ai/cordis": "^4.1.0",
|
|
59
59
|
"@deepseek-ai/cordis-plugin-loader": "^1.1.0",
|
|
60
|
-
"@deepseek-ai/dsh-client-connection": "0.2.2-rc.
|
|
61
|
-
"@deepseek-ai/dsh-client-locale": "0.2.2-rc.
|
|
62
|
-
"@deepseek-ai/dsh-client-ui-conversation": "0.2.2-rc.
|
|
63
|
-
"@deepseek-ai/dsh-client-ui-primitives": "0.2.2-rc.
|
|
64
|
-
"@deepseek-ai/dsh-client-ui-renderer": "0.2.2-rc.
|
|
65
|
-
"@deepseek-ai/dsh-client-ui-session": "0.2.2-rc.
|
|
66
|
-
"@deepseek-ai/dsh-client-ui-settings": "0.2.2-rc.
|
|
67
|
-
"@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.
|
|
68
|
-
"@deepseek-ai/dsh-client-ui-workspace": "0.2.2-rc.
|
|
69
|
-
"@deepseek-ai/dsh-session": "0.2.2-rc.
|
|
70
|
-
"@deepseek-ai/dsh-settings": "0.2.2-rc.
|
|
71
|
-
"@deepseek-ai/dsh-tools": "0.2.2-rc.
|
|
60
|
+
"@deepseek-ai/dsh-client-connection": "0.2.2-rc.5",
|
|
61
|
+
"@deepseek-ai/dsh-client-locale": "0.2.2-rc.5",
|
|
62
|
+
"@deepseek-ai/dsh-client-ui-conversation": "0.2.2-rc.5",
|
|
63
|
+
"@deepseek-ai/dsh-client-ui-primitives": "0.2.2-rc.5",
|
|
64
|
+
"@deepseek-ai/dsh-client-ui-renderer": "0.2.2-rc.5",
|
|
65
|
+
"@deepseek-ai/dsh-client-ui-session": "0.2.2-rc.5",
|
|
66
|
+
"@deepseek-ai/dsh-client-ui-settings": "0.2.2-rc.5",
|
|
67
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.5",
|
|
68
|
+
"@deepseek-ai/dsh-client-ui-workspace": "0.2.2-rc.5",
|
|
69
|
+
"@deepseek-ai/dsh-session": "0.2.2-rc.5",
|
|
70
|
+
"@deepseek-ai/dsh-settings": "0.2.2-rc.5",
|
|
71
|
+
"@deepseek-ai/dsh-tools": "0.2.2-rc.5",
|
|
72
72
|
"@deepseek-ai/schemastery": "3.19.0",
|
|
73
73
|
"@types/react": "~18.3.1",
|
|
74
74
|
"react": "^18.2.0",
|