@lmzhen/dsh-evolution-client-kit 0.32.5 → 0.32.6
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/README.md +3 -15
- package/lib/generated/fallbacks.generated.js +3 -2
- package/lib/generated/routes.generated.js +7 -2
- package/lib/index.js +418 -3
- package/lib/types/action.d.ts +42 -0
- package/lib/types/action.js +46 -0
- package/lib/types/async-resource.d.ts +48 -0
- package/lib/types/async-resource.js +96 -0
- package/lib/types/generated/fallbacks.generated.d.ts +1 -1
- package/lib/types/generated/fallbacks.generated.js +4 -1
- package/lib/types/generated/routes.generated.d.ts +6 -1
- package/lib/types/generated/routes.generated.js +5 -0
- package/lib/types/index.d.ts +10 -0
- package/lib/types/index.js +6 -0
- package/lib/types/seam.d.ts +1 -1
- package/lib/types/settings-gateway.d.ts +68 -0
- package/lib/types/settings-gateway.js +52 -0
- package/lib/types/settings-seat.d.ts +20 -0
- package/lib/types/settings-seat.js +116 -0
- package/lib/types/surface.d.ts +10 -0
- package/lib/types/surface.js +10 -0
- package/lib/types/workbench-view.d.ts +30 -0
- package/lib/types/workbench-view.js +60 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
# @lmzhen/dsh-evolution-client-kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Internal browser-only library shared by the evolution sidebar panels. It is not a plugin row and exposes no command, panel, or model tool of its own.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
It owns the client seam types, sidebar registration lifecycle, workspace identity, route/client contracts, fallback command metadata, generated state types, and design tokens. Panel packages consume these exports instead of carrying separate copies.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
## 什么时候会用到
|
|
10
|
-
|
|
11
|
-
只在开发/排障面板时。
|
|
12
|
-
|
|
13
|
-
## 默认 / 前提
|
|
14
|
-
|
|
15
|
-
随客户端包自动工作。
|
|
16
|
-
|
|
17
|
-
## 边界
|
|
18
|
-
|
|
19
|
-
普通用户不需要知道。
|
|
7
|
+
Files under `src/generated/` and the generated token surfaces are derived from their owning sources. Do not hand-edit them; update the source and rerun the corresponding generator.
|
|
@@ -6,13 +6,14 @@
|
|
|
6
6
|
*/
|
|
7
7
|
const FALLBACKS = {
|
|
8
8
|
approval: { command: "/evolution pending … /evolution approve <id> … /evolution reject <id> … /evolution release <id>" },
|
|
9
|
-
"skill-history": { command: "/evolution
|
|
9
|
+
"skill-history": { command: "/evolution skill undo <name> [--to v<N>](查看:/evolution skill history <name>)" },
|
|
10
10
|
"skill-health": { command: "/evolution skills refresh(健康行:/evolution doctor)" },
|
|
11
11
|
merge: { command: "/evolution merge status / pending / approve <id> / report" },
|
|
12
12
|
diagnostics: {
|
|
13
13
|
command: "/evolution doctor",
|
|
14
14
|
platformCli: "dsh --json /evolution doctor"
|
|
15
|
-
}
|
|
15
|
+
},
|
|
16
|
+
settings: { command: "/evolution policy set <id> <value>(查看:/evolution policy)" }
|
|
16
17
|
};
|
|
17
18
|
//#endregion
|
|
18
19
|
export { FALLBACKS };
|
|
@@ -10,7 +10,8 @@ const ROUTES = {
|
|
|
10
10
|
pending: "/api/dsh-evolution/approval/pending",
|
|
11
11
|
preview: "/api/dsh-evolution/approval/preview",
|
|
12
12
|
approve: "/api/dsh-evolution/approval/approve",
|
|
13
|
-
reject: "/api/dsh-evolution/approval/reject"
|
|
13
|
+
reject: "/api/dsh-evolution/approval/reject",
|
|
14
|
+
release: "/api/dsh-evolution/approval/release"
|
|
14
15
|
},
|
|
15
16
|
"skill-history": {
|
|
16
17
|
skills: "/api/dsh-evolution/skill-history/skills",
|
|
@@ -29,7 +30,11 @@ const ROUTES = {
|
|
|
29
30
|
body: "/api/dsh-evolution/merge/body",
|
|
30
31
|
history: "/api/dsh-evolution/merge/history"
|
|
31
32
|
},
|
|
32
|
-
diagnostics: { view: "/api/dsh-evolution/diagnostics" }
|
|
33
|
+
diagnostics: { view: "/api/dsh-evolution/diagnostics" },
|
|
34
|
+
settings: {
|
|
35
|
+
describe: "/api/dsh-evolution/settings/describe",
|
|
36
|
+
mutate: "/api/dsh-evolution/settings/mutate"
|
|
37
|
+
}
|
|
33
38
|
};
|
|
34
39
|
//#endregion
|
|
35
40
|
export { ROUTES };
|
package/lib/index.js
CHANGED
|
@@ -3,12 +3,13 @@ import { FALLBACKS } from "./generated/fallbacks.generated.js";
|
|
|
3
3
|
import "./generated/contracts.generated.js";
|
|
4
4
|
import { Block, FailureBlock, failureText, loadStateOf } from "./generated/states.generated.js";
|
|
5
5
|
import { TOKENS, TOKEN_CSS, tokenVars } from "./tokens.js";
|
|
6
|
+
import { createElement, useState } from "react";
|
|
6
7
|
//#region lib/types/panel.js
|
|
7
8
|
function interpolate(text, values) {
|
|
8
9
|
if (values === void 0) return text;
|
|
9
10
|
return text.replace(/\{(\w+)\}/g, (_match, key) => String(values[key] ?? ""));
|
|
10
11
|
}
|
|
11
|
-
function injectStyles(doc, css, tagId) {
|
|
12
|
+
function injectStyles$1(doc, css, tagId) {
|
|
12
13
|
if (doc === void 0) return () => {};
|
|
13
14
|
doc.querySelector("style[data-plugin-css=\"" + tagId + "\"]")?.remove();
|
|
14
15
|
const tag = doc.createElement("style");
|
|
@@ -37,7 +38,7 @@ function registerSidebarPanel(ctx, spec) {
|
|
|
37
38
|
return () => {};
|
|
38
39
|
}
|
|
39
40
|
}, spec.namespace + ": locale");
|
|
40
|
-
ctx.effect(() => injectStyles(typeof document === "undefined" ? void 0 : document, spec.styles.css, spec.styles.tagId), spec.namespace + ": styles");
|
|
41
|
+
ctx.effect(() => injectStyles$1(typeof document === "undefined" ? void 0 : document, spec.styles.css, spec.styles.tagId), spec.namespace + ": styles");
|
|
41
42
|
const fallback = spec.dictionaries[spec.fallback ?? "zh"];
|
|
42
43
|
const lookup = (key) => {
|
|
43
44
|
const own = fallback[key] ?? key;
|
|
@@ -65,6 +66,197 @@ function registerSidebarPanel(ctx, spec) {
|
|
|
65
66
|
});
|
|
66
67
|
}
|
|
67
68
|
//#endregion
|
|
69
|
+
//#region lib/types/workbench-view.js
|
|
70
|
+
function injectStyles(doc, css, tagId) {
|
|
71
|
+
if (doc === void 0) return () => {};
|
|
72
|
+
doc.querySelector("style[data-plugin-css=\"" + tagId + "\"]")?.remove();
|
|
73
|
+
const tag = doc.createElement("style");
|
|
74
|
+
tag.setAttribute("data-plugin-css", tagId);
|
|
75
|
+
tag.textContent = css;
|
|
76
|
+
doc.head.appendChild(tag);
|
|
77
|
+
return () => {
|
|
78
|
+
tag.remove();
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Register one view into `evolution.workbench.view`.
|
|
83
|
+
* @param ctx - client cordis context.
|
|
84
|
+
* @param spec - view identity, copy, styles, component and face factory.
|
|
85
|
+
*/
|
|
86
|
+
function registerWorkbenchView(ctx, spec) {
|
|
87
|
+
const seam = ctx;
|
|
88
|
+
let registered = false;
|
|
89
|
+
ctx.effect(() => {
|
|
90
|
+
try {
|
|
91
|
+
const dispose = seam.locale.register(spec.namespace, spec.dictionaries);
|
|
92
|
+
registered = true;
|
|
93
|
+
return dispose;
|
|
94
|
+
} catch (error) {
|
|
95
|
+
ctx.logger.warn(spec.namespace + ": locale refused (" + String(error) + "); the view falls back to the bundle copy");
|
|
96
|
+
return () => {};
|
|
97
|
+
}
|
|
98
|
+
}, spec.namespace + ": locale");
|
|
99
|
+
ctx.effect(() => injectStyles(typeof document === "undefined" ? void 0 : document, spec.styles.css, spec.styles.tagId), spec.namespace + ": styles");
|
|
100
|
+
const fallback = spec.dictionaries.zh;
|
|
101
|
+
const lookup = (key) => {
|
|
102
|
+
const own = fallback[key] ?? key;
|
|
103
|
+
if (!registered) return own;
|
|
104
|
+
try {
|
|
105
|
+
return seam.locale.bind(spec.namespace)(key);
|
|
106
|
+
} catch {
|
|
107
|
+
return own;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const t = (key, values) => {
|
|
111
|
+
const template = lookup(key);
|
|
112
|
+
if (values === void 0) return template;
|
|
113
|
+
return template.replace(/\{(\w+)\}/g, (match, slot) => values[slot] === void 0 ? match : String(values[slot]));
|
|
114
|
+
};
|
|
115
|
+
seam.slots.inject("evolution.workbench.view", function* () {
|
|
116
|
+
yield seam.slots.register({
|
|
117
|
+
name: "evolution.workbench.view",
|
|
118
|
+
id: spec.id,
|
|
119
|
+
order: spec.order,
|
|
120
|
+
label: () => t("entry.label"),
|
|
121
|
+
inject: () => spec.face(t)
|
|
122
|
+
}, spec.component);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region lib/types/settings-seat.js
|
|
127
|
+
const SETTINGS_DESCRIBE = ROUTES.settings.describe;
|
|
128
|
+
const SETTINGS_MUTATE = ROUTES.settings.mutate;
|
|
129
|
+
const EMPTY = Object.freeze({
|
|
130
|
+
status: "unavailable",
|
|
131
|
+
value: void 0,
|
|
132
|
+
user: void 0,
|
|
133
|
+
writable: false,
|
|
134
|
+
base: void 0,
|
|
135
|
+
revision: void 0,
|
|
136
|
+
reason: "transport"
|
|
137
|
+
});
|
|
138
|
+
function snapshotFrom(value, ns) {
|
|
139
|
+
if (typeof value !== "object" || value === null) return EMPTY;
|
|
140
|
+
const list = value.namespaces;
|
|
141
|
+
if (!Array.isArray(list)) return EMPTY;
|
|
142
|
+
const item = list.find((candidate) => typeof candidate === "object" && candidate !== null && candidate.ns === ns);
|
|
143
|
+
return item === void 0 ? {
|
|
144
|
+
...EMPTY,
|
|
145
|
+
reason: "not-served"
|
|
146
|
+
} : item;
|
|
147
|
+
}
|
|
148
|
+
async function describe(namespace) {
|
|
149
|
+
try {
|
|
150
|
+
const response = await fetch(SETTINGS_DESCRIBE, { headers: { accept: "application/json" } });
|
|
151
|
+
if (!response.ok) return EMPTY;
|
|
152
|
+
const body = await response.json();
|
|
153
|
+
if (body.ok !== true) return EMPTY;
|
|
154
|
+
return snapshotFrom(body.data, namespace);
|
|
155
|
+
} catch {
|
|
156
|
+
return EMPTY;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async function write(namespace, ops, expectedRevision) {
|
|
160
|
+
try {
|
|
161
|
+
const response = await fetch(SETTINGS_MUTATE, {
|
|
162
|
+
method: "POST",
|
|
163
|
+
headers: {
|
|
164
|
+
"content-type": "application/json",
|
|
165
|
+
accept: "application/json"
|
|
166
|
+
},
|
|
167
|
+
body: JSON.stringify({
|
|
168
|
+
ns: namespace,
|
|
169
|
+
ops,
|
|
170
|
+
...expectedRevision === void 0 ? {} : { expectedRevision }
|
|
171
|
+
})
|
|
172
|
+
});
|
|
173
|
+
if (!response.ok) return { ok: false };
|
|
174
|
+
const body = await response.json();
|
|
175
|
+
return {
|
|
176
|
+
ok: body.ok === true,
|
|
177
|
+
snapshot: snapshotFrom(body.data, namespace)
|
|
178
|
+
};
|
|
179
|
+
} catch {
|
|
180
|
+
return { ok: false };
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function createForm(namespace, ctx) {
|
|
184
|
+
let snapshot = {
|
|
185
|
+
...EMPTY,
|
|
186
|
+
reason: "seat-missing"
|
|
187
|
+
};
|
|
188
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
189
|
+
let started = false;
|
|
190
|
+
let listening = false;
|
|
191
|
+
const notify = () => {
|
|
192
|
+
for (const listener of listeners) listener();
|
|
193
|
+
};
|
|
194
|
+
const refresh = async () => {
|
|
195
|
+
snapshot = await describe(namespace);
|
|
196
|
+
notify();
|
|
197
|
+
};
|
|
198
|
+
const start = () => {
|
|
199
|
+
if (started) return;
|
|
200
|
+
started = true;
|
|
201
|
+
if (!listening) {
|
|
202
|
+
listening = true;
|
|
203
|
+
(ctx.get?.("remote"))?.$on?.("settings/document-updated", (changed) => {
|
|
204
|
+
if (changed === namespace) refresh();
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
refresh();
|
|
208
|
+
};
|
|
209
|
+
const form = {
|
|
210
|
+
getSnapshot: () => snapshot,
|
|
211
|
+
subscribe: (listener) => {
|
|
212
|
+
listeners.add(listener);
|
|
213
|
+
start();
|
|
214
|
+
return () => {
|
|
215
|
+
listeners.delete(listener);
|
|
216
|
+
};
|
|
217
|
+
},
|
|
218
|
+
set: async (field, value) => await form.mutate([{
|
|
219
|
+
op: "set",
|
|
220
|
+
path: [field],
|
|
221
|
+
value
|
|
222
|
+
}]),
|
|
223
|
+
unset: async (field) => await form.mutate([{
|
|
224
|
+
op: "unset",
|
|
225
|
+
path: [field]
|
|
226
|
+
}]),
|
|
227
|
+
mutate: async (ops, expectedRevision) => {
|
|
228
|
+
const outcome = await write(namespace, ops, expectedRevision ?? snapshot.revision);
|
|
229
|
+
if (outcome.snapshot !== void 0) {
|
|
230
|
+
snapshot = outcome.snapshot;
|
|
231
|
+
notify();
|
|
232
|
+
} else await refresh();
|
|
233
|
+
return outcome.ok;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
return form;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Build one cached form per family namespace over the family settings routes.
|
|
240
|
+
* @param ctx - the client plugin context (remote subscription is optional).
|
|
241
|
+
* @returns the seat; each namespace is served by /api/dsh-evolution/settings/*.
|
|
242
|
+
*/
|
|
243
|
+
const seats = /* @__PURE__ */ new WeakMap();
|
|
244
|
+
function createSettingsSeat(ctx) {
|
|
245
|
+
const cached = seats.get(ctx);
|
|
246
|
+
if (cached !== void 0) return cached;
|
|
247
|
+
const forms = /* @__PURE__ */ new Map();
|
|
248
|
+
const seat = { get(namespace) {
|
|
249
|
+
let form = forms.get(namespace);
|
|
250
|
+
if (form === void 0) {
|
|
251
|
+
form = createForm(namespace, ctx);
|
|
252
|
+
forms.set(namespace, form);
|
|
253
|
+
}
|
|
254
|
+
return form;
|
|
255
|
+
} };
|
|
256
|
+
seats.set(ctx, seat);
|
|
257
|
+
return seat;
|
|
258
|
+
}
|
|
259
|
+
//#endregion
|
|
68
260
|
//#region lib/types/workspace.js
|
|
69
261
|
/**
|
|
70
262
|
* Best-effort workspace id; a seat that is absent or refuses leaves the panel in local scope.
|
|
@@ -81,4 +273,227 @@ function panelWorkspaceId(ctx) {
|
|
|
81
273
|
} catch {}
|
|
82
274
|
}
|
|
83
275
|
//#endregion
|
|
84
|
-
|
|
276
|
+
//#region lib/types/async-resource.js
|
|
277
|
+
/**
|
|
278
|
+
* One read operation's lifecycle: initial load, background refresh, stale-answer
|
|
279
|
+
* suppression, and an explicit failure slot. Consumers derive `empty` from a
|
|
280
|
+
* successful `data` value; this type never conflates "not loaded yet" with
|
|
281
|
+
* "loaded and empty".
|
|
282
|
+
* @module @lmzhen/dsh-evolution-client-kit
|
|
283
|
+
*/
|
|
284
|
+
/**
|
|
285
|
+
* Serialize one resource's reads without remounting the consumer.
|
|
286
|
+
*/
|
|
287
|
+
var AsyncResource = class {
|
|
288
|
+
#state = Object.freeze({
|
|
289
|
+
status: "loading",
|
|
290
|
+
refreshing: false,
|
|
291
|
+
data: void 0,
|
|
292
|
+
failure: void 0,
|
|
293
|
+
generation: 0
|
|
294
|
+
});
|
|
295
|
+
#listeners = /* @__PURE__ */ new Set();
|
|
296
|
+
#generation = 0;
|
|
297
|
+
#controller;
|
|
298
|
+
#disposed = false;
|
|
299
|
+
/** @returns the stable snapshot for uSES. */
|
|
300
|
+
getSnapshot() {
|
|
301
|
+
return this.#state;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Observe snapshot replacements.
|
|
305
|
+
* @param listener - called after each publish.
|
|
306
|
+
* @returns the disposer.
|
|
307
|
+
*/
|
|
308
|
+
subscribe(listener) {
|
|
309
|
+
this.#listeners.add(listener);
|
|
310
|
+
return () => {
|
|
311
|
+
this.#listeners.delete(listener);
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Run one read. A prior read is aborted; only this generation may publish.
|
|
316
|
+
* @param load - loader receiving the cancellation signal.
|
|
317
|
+
* @returns settlement after this generation commits or is superseded.
|
|
318
|
+
*/
|
|
319
|
+
async load(load) {
|
|
320
|
+
if (this.#disposed) return;
|
|
321
|
+
const generation = this.#generation + 1;
|
|
322
|
+
this.#generation = generation;
|
|
323
|
+
this.#controller?.abort();
|
|
324
|
+
const controller = new AbortController();
|
|
325
|
+
this.#controller = controller;
|
|
326
|
+
const previous = this.#state;
|
|
327
|
+
this.#publish({
|
|
328
|
+
status: previous.data === void 0 ? "loading" : "ready",
|
|
329
|
+
refreshing: previous.data !== void 0,
|
|
330
|
+
data: previous.data,
|
|
331
|
+
failure: previous.failure,
|
|
332
|
+
generation
|
|
333
|
+
});
|
|
334
|
+
try {
|
|
335
|
+
const data = await load(controller.signal);
|
|
336
|
+
if (this.#disposed || generation !== this.#generation) return;
|
|
337
|
+
this.#publish({
|
|
338
|
+
status: "ready",
|
|
339
|
+
refreshing: false,
|
|
340
|
+
data,
|
|
341
|
+
failure: void 0,
|
|
342
|
+
generation
|
|
343
|
+
});
|
|
344
|
+
} catch (failure) {
|
|
345
|
+
if (this.#disposed || generation !== this.#generation || controller.signal.aborted) return;
|
|
346
|
+
this.#publish({
|
|
347
|
+
status: previous.data === void 0 ? "error" : "ready",
|
|
348
|
+
refreshing: false,
|
|
349
|
+
data: previous.data,
|
|
350
|
+
failure,
|
|
351
|
+
generation
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
/** Drop the current value and return to the initial loading state. */
|
|
356
|
+
reset() {
|
|
357
|
+
this.#generation += 1;
|
|
358
|
+
this.#controller?.abort();
|
|
359
|
+
this.#controller = void 0;
|
|
360
|
+
this.#publish({
|
|
361
|
+
status: "loading",
|
|
362
|
+
refreshing: false,
|
|
363
|
+
data: void 0,
|
|
364
|
+
failure: void 0,
|
|
365
|
+
generation: this.#generation
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
/** Abort the in-flight read and stop notifying. */
|
|
369
|
+
dispose() {
|
|
370
|
+
this.#disposed = true;
|
|
371
|
+
this.#generation += 1;
|
|
372
|
+
this.#controller?.abort();
|
|
373
|
+
this.#controller = void 0;
|
|
374
|
+
this.#listeners.clear();
|
|
375
|
+
}
|
|
376
|
+
#publish(state) {
|
|
377
|
+
this.#state = Object.freeze(state);
|
|
378
|
+
for (const listener of this.#listeners) listener();
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region lib/types/action.js
|
|
383
|
+
/**
|
|
384
|
+
* Command-only actions. Approval decisions are a separate host API and must never
|
|
385
|
+
* be represented as a copyable command here.
|
|
386
|
+
* @module @lmzhen/dsh-evolution-client-kit
|
|
387
|
+
*/
|
|
388
|
+
/**
|
|
389
|
+
* Copy one command and report the host verdict.
|
|
390
|
+
* @param action - the command action.
|
|
391
|
+
* @param writeClipboard - platform clipboard writer.
|
|
392
|
+
* @param confirm - optional in-UI confirmation.
|
|
393
|
+
* @returns the settled copy status.
|
|
394
|
+
*/
|
|
395
|
+
async function copyAction(action, writeClipboard, confirm) {
|
|
396
|
+
if (action.enabled === false) return "idle";
|
|
397
|
+
if (confirm !== void 0 && !confirm(action)) return "idle";
|
|
398
|
+
if (action.confirm !== void 0 && !action.confirm(action)) return "idle";
|
|
399
|
+
try {
|
|
400
|
+
return await writeClipboard(action.command) ? "copied" : "failed";
|
|
401
|
+
} catch {
|
|
402
|
+
return "failed";
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Render one command-copy action with real success/failure feedback.
|
|
407
|
+
* @param props - action, clipboard writer, and localized labels.
|
|
408
|
+
* @returns the button and its status line.
|
|
409
|
+
*/
|
|
410
|
+
function CommandCopyButton({ action, writeClipboard, labels, className }) {
|
|
411
|
+
const [status, setStatus] = useState("idle");
|
|
412
|
+
const text = status === "copying" ? labels.copying : status === "copied" ? labels.copied : status === "failed" ? labels.failed : labels.copy;
|
|
413
|
+
return createElement("span", { className }, createElement("button", {
|
|
414
|
+
type: "button",
|
|
415
|
+
disabled: action.enabled === false || status === "copying",
|
|
416
|
+
"aria-label": action.label,
|
|
417
|
+
onClick: () => {
|
|
418
|
+
setStatus("copying");
|
|
419
|
+
copyAction(action, writeClipboard).then(setStatus);
|
|
420
|
+
}
|
|
421
|
+
}, action.label), createElement("span", {
|
|
422
|
+
role: "status",
|
|
423
|
+
"aria-live": "polite"
|
|
424
|
+
}, text === labels.copy ? "" : text));
|
|
425
|
+
}
|
|
426
|
+
//#endregion
|
|
427
|
+
//#region lib/types/surface.js
|
|
428
|
+
/**
|
|
429
|
+
* Shared opaque page surface. Skin images may sit behind the shell; every
|
|
430
|
+
* reading surface must paint the platform's base layer before text can be read.
|
|
431
|
+
* @module @lmzhen/dsh-evolution-client-kit
|
|
432
|
+
*/
|
|
433
|
+
/** Class consumers put on the root of a full-page reading surface. */
|
|
434
|
+
const PAGE_SURFACE_CLASS = "evolution-page-surface";
|
|
435
|
+
/** Stylesheet for {@link PAGE_SURFACE_CLASS}; consumers append it to their own CSS. */
|
|
436
|
+
const PAGE_SURFACE_CSS = ".evolution-page-surface{min-height:100%;background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-primary)}";
|
|
437
|
+
//#endregion
|
|
438
|
+
//#region lib/types/settings-gateway.js
|
|
439
|
+
/**
|
|
440
|
+
* Save one atomic op list and always read back.
|
|
441
|
+
* @param options - namespace, bound scope, mutation transport, and ops.
|
|
442
|
+
* @returns the write verdict plus the separate read-back verdict.
|
|
443
|
+
*/
|
|
444
|
+
async function saveSettings(options) {
|
|
445
|
+
const revision = options.scope.getSnapshot().revision;
|
|
446
|
+
let written = false;
|
|
447
|
+
let failure;
|
|
448
|
+
try {
|
|
449
|
+
written = (await options.api.mutate({
|
|
450
|
+
ns: options.namespace,
|
|
451
|
+
ops: options.ops,
|
|
452
|
+
...revision === void 0 ? {} : { expectedRevision: revision }
|
|
453
|
+
})).result.ok;
|
|
454
|
+
} catch (error) {
|
|
455
|
+
failure = error;
|
|
456
|
+
}
|
|
457
|
+
let readback = "ok";
|
|
458
|
+
try {
|
|
459
|
+
await options.scope.load();
|
|
460
|
+
} catch (error) {
|
|
461
|
+
readback = "failed";
|
|
462
|
+
failure ??= error;
|
|
463
|
+
}
|
|
464
|
+
return failure === void 0 ? {
|
|
465
|
+
written,
|
|
466
|
+
readback
|
|
467
|
+
} : {
|
|
468
|
+
written,
|
|
469
|
+
readback,
|
|
470
|
+
failure
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Bind each namespace once and reuse that scope for every later save.
|
|
475
|
+
* @param binder - the platform settings-scope service.
|
|
476
|
+
* @param api - the mutation transport.
|
|
477
|
+
* @returns a lookup that creates one gateway per namespace.
|
|
478
|
+
*/
|
|
479
|
+
function createSettingsGatewayCache(binder, api) {
|
|
480
|
+
const cache = /* @__PURE__ */ new Map();
|
|
481
|
+
return (namespace) => {
|
|
482
|
+
const existing = cache.get(namespace);
|
|
483
|
+
if (existing !== void 0) return existing;
|
|
484
|
+
const scope = binder.bind({ namespace });
|
|
485
|
+
const gateway = {
|
|
486
|
+
scope,
|
|
487
|
+
save: async (ops) => await saveSettings({
|
|
488
|
+
namespace,
|
|
489
|
+
scope,
|
|
490
|
+
api,
|
|
491
|
+
ops
|
|
492
|
+
})
|
|
493
|
+
};
|
|
494
|
+
cache.set(namespace, gateway);
|
|
495
|
+
return gateway;
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
//#endregion
|
|
499
|
+
export { AsyncResource, Block, CommandCopyButton, FALLBACKS, FailureBlock, PAGE_SURFACE_CLASS, PAGE_SURFACE_CSS, ROUTES, TOKENS, TOKEN_CSS, copyAction, createSettingsGatewayCache, createSettingsSeat, failureText, loadStateOf, panelWorkspaceId, registerSidebarPanel, registerWorkbenchView, saveSettings, tokenVars };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
/** One user-facing action whose effect is copying an exact command. */
|
|
3
|
+
export interface ActionRef {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly label: string;
|
|
6
|
+
readonly command: string;
|
|
7
|
+
/** False renders the action disabled with no clipboard attempt. */
|
|
8
|
+
readonly enabled?: boolean;
|
|
9
|
+
/** Optional in-UI confirmation before the write; the callback owns the dialog. */
|
|
10
|
+
readonly confirm?: (action: ActionRef) => boolean;
|
|
11
|
+
}
|
|
12
|
+
/** User-facing copy states; `copied` is set only after the clipboard accepted the text. */
|
|
13
|
+
export type CopyStatus = 'idle' | 'copying' | 'copied' | 'failed';
|
|
14
|
+
/** Labels the host surface supplies in its own language. */
|
|
15
|
+
export interface CommandCopyLabels {
|
|
16
|
+
readonly copy: string;
|
|
17
|
+
readonly copying: string;
|
|
18
|
+
readonly copied: string;
|
|
19
|
+
readonly failed: string;
|
|
20
|
+
}
|
|
21
|
+
/** Props for the shared copy control. */
|
|
22
|
+
export interface CommandCopyButtonProps {
|
|
23
|
+
readonly action: ActionRef;
|
|
24
|
+
readonly writeClipboard: (text: string) => Promise<boolean>;
|
|
25
|
+
readonly labels: CommandCopyLabels;
|
|
26
|
+
readonly className?: string | undefined;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Copy one command and report the host verdict.
|
|
30
|
+
* @param action - the command action.
|
|
31
|
+
* @param writeClipboard - platform clipboard writer.
|
|
32
|
+
* @param confirm - optional in-UI confirmation.
|
|
33
|
+
* @returns the settled copy status.
|
|
34
|
+
*/
|
|
35
|
+
export declare function copyAction(action: ActionRef, writeClipboard: (text: string) => Promise<boolean>, confirm?: (action: ActionRef) => boolean): Promise<CopyStatus>;
|
|
36
|
+
/**
|
|
37
|
+
* Render one command-copy action with real success/failure feedback.
|
|
38
|
+
* @param props - action, clipboard writer, and localized labels.
|
|
39
|
+
* @returns the button and its status line.
|
|
40
|
+
*/
|
|
41
|
+
export declare function CommandCopyButton({ action, writeClipboard, labels, className }: CommandCopyButtonProps): ReactNode;
|
|
42
|
+
//# sourceMappingURL=action.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command-only actions. Approval decisions are a separate host API and must never
|
|
3
|
+
* be represented as a copyable command here.
|
|
4
|
+
* @module @lmzhen/dsh-evolution-client-kit
|
|
5
|
+
*/
|
|
6
|
+
import { createElement, useState } from 'react';
|
|
7
|
+
/**
|
|
8
|
+
* Copy one command and report the host verdict.
|
|
9
|
+
* @param action - the command action.
|
|
10
|
+
* @param writeClipboard - platform clipboard writer.
|
|
11
|
+
* @param confirm - optional in-UI confirmation.
|
|
12
|
+
* @returns the settled copy status.
|
|
13
|
+
*/
|
|
14
|
+
export async function copyAction(action, writeClipboard, confirm) {
|
|
15
|
+
if (action.enabled === false)
|
|
16
|
+
return 'idle';
|
|
17
|
+
if (confirm !== undefined && !confirm(action))
|
|
18
|
+
return 'idle';
|
|
19
|
+
if (action.confirm !== undefined && !action.confirm(action))
|
|
20
|
+
return 'idle';
|
|
21
|
+
try {
|
|
22
|
+
return await writeClipboard(action.command) ? 'copied' : 'failed';
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return 'failed';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Render one command-copy action with real success/failure feedback.
|
|
30
|
+
* @param props - action, clipboard writer, and localized labels.
|
|
31
|
+
* @returns the button and its status line.
|
|
32
|
+
*/
|
|
33
|
+
export function CommandCopyButton({ action, writeClipboard, labels, className }) {
|
|
34
|
+
const [status, setStatus] = useState('idle');
|
|
35
|
+
const text = status === 'copying' ? labels.copying : status === 'copied' ? labels.copied : status === 'failed' ? labels.failed : labels.copy;
|
|
36
|
+
return createElement('span', { className }, createElement('button', {
|
|
37
|
+
type: 'button',
|
|
38
|
+
disabled: action.enabled === false || status === 'copying',
|
|
39
|
+
'aria-label': action.label,
|
|
40
|
+
onClick: () => {
|
|
41
|
+
setStatus('copying');
|
|
42
|
+
void copyAction(action, writeClipboard).then(setStatus);
|
|
43
|
+
},
|
|
44
|
+
}, action.label), createElement('span', { role: 'status', 'aria-live': 'polite' }, text === labels.copy ? '' : text));
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=action.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One read operation's lifecycle: initial load, background refresh, stale-answer
|
|
3
|
+
* suppression, and an explicit failure slot. Consumers derive `empty` from a
|
|
4
|
+
* successful `data` value; this type never conflates "not loaded yet" with
|
|
5
|
+
* "loaded and empty".
|
|
6
|
+
* @module @lmzhen/dsh-evolution-client-kit
|
|
7
|
+
*/
|
|
8
|
+
/** The three settled states; `refreshing` is orthogonal so old data can stay visible. */
|
|
9
|
+
export type AsyncStatus = 'loading' | 'ready' | 'error';
|
|
10
|
+
/** Immutable snapshot published to render hooks. */
|
|
11
|
+
export interface AsyncState<T> {
|
|
12
|
+
readonly status: AsyncStatus;
|
|
13
|
+
/** A newer read is in flight while `data` remains the previous successful value. */
|
|
14
|
+
readonly refreshing: boolean;
|
|
15
|
+
/** Last successful value; undefined before the first success or after reset. */
|
|
16
|
+
readonly data: T | undefined;
|
|
17
|
+
/** Latest failure, cleared by the next successful read. */
|
|
18
|
+
readonly failure: unknown;
|
|
19
|
+
/** Monotonic request id; only the latest generation may publish. */
|
|
20
|
+
readonly generation: number;
|
|
21
|
+
}
|
|
22
|
+
/** A loader may use the signal to cancel work when a newer read supersedes it. */
|
|
23
|
+
export type AsyncLoader<T> = (signal: AbortSignal) => Promise<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Serialize one resource's reads without remounting the consumer.
|
|
26
|
+
*/
|
|
27
|
+
export declare class AsyncResource<T> {
|
|
28
|
+
#private;
|
|
29
|
+
/** @returns the stable snapshot for uSES. */
|
|
30
|
+
getSnapshot(): AsyncState<T>;
|
|
31
|
+
/**
|
|
32
|
+
* Observe snapshot replacements.
|
|
33
|
+
* @param listener - called after each publish.
|
|
34
|
+
* @returns the disposer.
|
|
35
|
+
*/
|
|
36
|
+
subscribe(listener: () => void): () => void;
|
|
37
|
+
/**
|
|
38
|
+
* Run one read. A prior read is aborted; only this generation may publish.
|
|
39
|
+
* @param load - loader receiving the cancellation signal.
|
|
40
|
+
* @returns settlement after this generation commits or is superseded.
|
|
41
|
+
*/
|
|
42
|
+
load(load: AsyncLoader<T>): Promise<void>;
|
|
43
|
+
/** Drop the current value and return to the initial loading state. */
|
|
44
|
+
reset(): void;
|
|
45
|
+
/** Abort the in-flight read and stop notifying. */
|
|
46
|
+
dispose(): void;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=async-resource.d.ts.map
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One read operation's lifecycle: initial load, background refresh, stale-answer
|
|
3
|
+
* suppression, and an explicit failure slot. Consumers derive `empty` from a
|
|
4
|
+
* successful `data` value; this type never conflates "not loaded yet" with
|
|
5
|
+
* "loaded and empty".
|
|
6
|
+
* @module @lmzhen/dsh-evolution-client-kit
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Serialize one resource's reads without remounting the consumer.
|
|
10
|
+
*/
|
|
11
|
+
export class AsyncResource {
|
|
12
|
+
#state = Object.freeze({
|
|
13
|
+
status: 'loading',
|
|
14
|
+
refreshing: false,
|
|
15
|
+
data: undefined,
|
|
16
|
+
failure: undefined,
|
|
17
|
+
generation: 0,
|
|
18
|
+
});
|
|
19
|
+
#listeners = new Set();
|
|
20
|
+
#generation = 0;
|
|
21
|
+
#controller;
|
|
22
|
+
#disposed = false;
|
|
23
|
+
/** @returns the stable snapshot for uSES. */
|
|
24
|
+
getSnapshot() {
|
|
25
|
+
return this.#state;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Observe snapshot replacements.
|
|
29
|
+
* @param listener - called after each publish.
|
|
30
|
+
* @returns the disposer.
|
|
31
|
+
*/
|
|
32
|
+
subscribe(listener) {
|
|
33
|
+
this.#listeners.add(listener);
|
|
34
|
+
return () => { this.#listeners.delete(listener); };
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Run one read. A prior read is aborted; only this generation may publish.
|
|
38
|
+
* @param load - loader receiving the cancellation signal.
|
|
39
|
+
* @returns settlement after this generation commits or is superseded.
|
|
40
|
+
*/
|
|
41
|
+
async load(load) {
|
|
42
|
+
if (this.#disposed)
|
|
43
|
+
return;
|
|
44
|
+
const generation = this.#generation + 1;
|
|
45
|
+
this.#generation = generation;
|
|
46
|
+
this.#controller?.abort();
|
|
47
|
+
const controller = new AbortController();
|
|
48
|
+
this.#controller = controller;
|
|
49
|
+
const previous = this.#state;
|
|
50
|
+
this.#publish({
|
|
51
|
+
status: previous.data === undefined ? 'loading' : 'ready',
|
|
52
|
+
refreshing: previous.data !== undefined,
|
|
53
|
+
data: previous.data,
|
|
54
|
+
failure: previous.failure,
|
|
55
|
+
generation,
|
|
56
|
+
});
|
|
57
|
+
try {
|
|
58
|
+
const data = await load(controller.signal);
|
|
59
|
+
if (this.#disposed || generation !== this.#generation)
|
|
60
|
+
return;
|
|
61
|
+
this.#publish({ status: 'ready', refreshing: false, data, failure: undefined, generation });
|
|
62
|
+
}
|
|
63
|
+
catch (failure) {
|
|
64
|
+
if (this.#disposed || generation !== this.#generation || controller.signal.aborted)
|
|
65
|
+
return;
|
|
66
|
+
this.#publish({
|
|
67
|
+
status: previous.data === undefined ? 'error' : 'ready',
|
|
68
|
+
refreshing: false,
|
|
69
|
+
data: previous.data,
|
|
70
|
+
failure,
|
|
71
|
+
generation,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** Drop the current value and return to the initial loading state. */
|
|
76
|
+
reset() {
|
|
77
|
+
this.#generation += 1;
|
|
78
|
+
this.#controller?.abort();
|
|
79
|
+
this.#controller = undefined;
|
|
80
|
+
this.#publish({ status: 'loading', refreshing: false, data: undefined, failure: undefined, generation: this.#generation });
|
|
81
|
+
}
|
|
82
|
+
/** Abort the in-flight read and stop notifying. */
|
|
83
|
+
dispose() {
|
|
84
|
+
this.#disposed = true;
|
|
85
|
+
this.#generation += 1;
|
|
86
|
+
this.#controller?.abort();
|
|
87
|
+
this.#controller = undefined;
|
|
88
|
+
this.#listeners.clear();
|
|
89
|
+
}
|
|
90
|
+
#publish(state) {
|
|
91
|
+
this.#state = Object.freeze(state);
|
|
92
|
+
for (const listener of this.#listeners)
|
|
93
|
+
listener();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=async-resource.js.map
|
|
@@ -4,5 +4,5 @@ import type { FallbackHint } from './contracts.generated.ts';
|
|
|
4
4
|
* COMMAND_FALLBACKS (the ONE home). When the platform's connection carrier is absent (E-325) the
|
|
5
5
|
* panels render this hint instead of a bare HTTP failure — same use case, command face.
|
|
6
6
|
*/
|
|
7
|
-
export declare const FALLBACKS: Readonly<Record<'approval' | 'skill-history' | 'skill-health' | 'merge' | 'diagnostics', FallbackHint>>;
|
|
7
|
+
export declare const FALLBACKS: Readonly<Record<'approval' | 'skill-history' | 'skill-health' | 'merge' | 'diagnostics' | 'settings', FallbackHint>>;
|
|
8
8
|
//# sourceMappingURL=fallbacks.generated.d.ts.map
|
|
@@ -9,7 +9,7 @@ export const FALLBACKS = {
|
|
|
9
9
|
command: '/evolution pending … /evolution approve <id> … /evolution reject <id> … /evolution release <id>',
|
|
10
10
|
},
|
|
11
11
|
'skill-history': {
|
|
12
|
-
command: '/evolution
|
|
12
|
+
command: '/evolution skill undo <name> [--to v<N>](查看:/evolution skill history <name>)',
|
|
13
13
|
},
|
|
14
14
|
'skill-health': {
|
|
15
15
|
command: '/evolution skills refresh(健康行:/evolution doctor)',
|
|
@@ -21,5 +21,8 @@ export const FALLBACKS = {
|
|
|
21
21
|
command: '/evolution doctor',
|
|
22
22
|
platformCli: 'dsh --json /evolution doctor',
|
|
23
23
|
},
|
|
24
|
+
settings: {
|
|
25
|
+
command: '/evolution policy set <id> <value>(查看:/evolution policy)',
|
|
26
|
+
},
|
|
24
27
|
};
|
|
25
28
|
//# sourceMappingURL=fallbacks.generated.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** One host data-plane surface the browser half can call. */
|
|
2
|
-
export type SurfaceId = 'approval' | 'skill-history' | 'skill-health' | 'merge' | 'diagnostics';
|
|
2
|
+
export type SurfaceId = 'approval' | 'skill-history' | 'skill-health' | 'merge' | 'diagnostics' | 'settings';
|
|
3
3
|
/**
|
|
4
4
|
* Every family host path, generated from evolution-core's HOST_ROUTES (the ONE declaration).
|
|
5
5
|
* A browser half cannot import the host package at runtime (client bundles keep @deepseek-ai/*
|
|
@@ -12,6 +12,7 @@ export declare const ROUTES: {
|
|
|
12
12
|
readonly preview: "/api/dsh-evolution/approval/preview";
|
|
13
13
|
readonly approve: "/api/dsh-evolution/approval/approve";
|
|
14
14
|
readonly reject: "/api/dsh-evolution/approval/reject";
|
|
15
|
+
readonly release: "/api/dsh-evolution/approval/release";
|
|
15
16
|
};
|
|
16
17
|
readonly 'skill-history': {
|
|
17
18
|
readonly skills: "/api/dsh-evolution/skill-history/skills";
|
|
@@ -35,5 +36,9 @@ export declare const ROUTES: {
|
|
|
35
36
|
readonly diagnostics: {
|
|
36
37
|
readonly view: "/api/dsh-evolution/diagnostics";
|
|
37
38
|
};
|
|
39
|
+
readonly settings: {
|
|
40
|
+
readonly describe: "/api/dsh-evolution/settings/describe";
|
|
41
|
+
readonly mutate: "/api/dsh-evolution/settings/mutate";
|
|
42
|
+
};
|
|
38
43
|
};
|
|
39
44
|
//# sourceMappingURL=routes.generated.d.ts.map
|
|
@@ -11,6 +11,7 @@ export const ROUTES = {
|
|
|
11
11
|
preview: '/api/dsh-evolution/approval/preview',
|
|
12
12
|
approve: '/api/dsh-evolution/approval/approve',
|
|
13
13
|
reject: '/api/dsh-evolution/approval/reject',
|
|
14
|
+
release: '/api/dsh-evolution/approval/release',
|
|
14
15
|
},
|
|
15
16
|
'skill-history': {
|
|
16
17
|
skills: '/api/dsh-evolution/skill-history/skills',
|
|
@@ -34,5 +35,9 @@ export const ROUTES = {
|
|
|
34
35
|
diagnostics: {
|
|
35
36
|
view: '/api/dsh-evolution/diagnostics',
|
|
36
37
|
},
|
|
38
|
+
settings: {
|
|
39
|
+
describe: '/api/dsh-evolution/settings/describe',
|
|
40
|
+
mutate: '/api/dsh-evolution/settings/mutate',
|
|
41
|
+
},
|
|
37
42
|
};
|
|
38
43
|
//# sourceMappingURL=routes.generated.js.map
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
/** Shared browser seams and panel lifecycle for the evolution family. */
|
|
2
2
|
export type { ClientSeam, ConfigFormLike, ConfigFormSnapshotLike, ConfigFormsSeat, ConfigPathOpLike, LocaleSeat, PanelBodyOptions, PanelRowOptions, SettingsFace, SlotsSeat } from './seam.ts';
|
|
3
3
|
export { registerSidebarPanel, type SidebarPanelSpec, type Translate } from './panel.ts';
|
|
4
|
+
export { registerWorkbenchView } from './workbench-view.ts';
|
|
5
|
+
export { createSettingsSeat } from './settings-seat.ts';
|
|
6
|
+
export type { WorkbenchViewSpec } from './workbench-view.ts';
|
|
4
7
|
export { panelWorkspaceId } from './workspace.ts';
|
|
8
|
+
export { AsyncResource } from './async-resource.ts';
|
|
9
|
+
export { CommandCopyButton, copyAction } from './action.ts';
|
|
10
|
+
export type { ActionRef, CommandCopyButtonProps, CommandCopyLabels, CopyStatus } from './action.ts';
|
|
11
|
+
export type { AsyncLoader, AsyncState, AsyncStatus } from './async-resource.ts';
|
|
5
12
|
export { ROUTES } from './generated/routes.generated.ts';
|
|
6
13
|
export { FALLBACKS } from './generated/fallbacks.generated.ts';
|
|
7
14
|
export * from './generated/contracts.generated.ts';
|
|
8
15
|
export * from './generated/states.generated.ts';
|
|
9
16
|
export { TOKEN_CSS, TOKENS, tokenVars } from './tokens.ts';
|
|
17
|
+
export { PAGE_SURFACE_CLASS, PAGE_SURFACE_CSS } from './surface.ts';
|
|
18
|
+
export { createSettingsGatewayCache, saveSettings } from './settings-gateway.ts';
|
|
19
|
+
export type { SettingsBinderLike, SettingsGateway, SettingsMutationApi, SettingsSaveResult, SettingsScopeLike } from './settings-gateway.ts';
|
|
10
20
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/types/index.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
export { registerSidebarPanel } from "./panel.js";
|
|
2
|
+
export { registerWorkbenchView } from "./workbench-view.js";
|
|
3
|
+
export { createSettingsSeat } from "./settings-seat.js";
|
|
2
4
|
export { panelWorkspaceId } from "./workspace.js";
|
|
5
|
+
export { AsyncResource } from "./async-resource.js";
|
|
6
|
+
export { CommandCopyButton, copyAction } from "./action.js";
|
|
3
7
|
export { ROUTES } from "./generated/routes.generated.js";
|
|
4
8
|
export { FALLBACKS } from "./generated/fallbacks.generated.js";
|
|
5
9
|
export * from "./generated/contracts.generated.js";
|
|
6
10
|
export * from "./generated/states.generated.js";
|
|
7
11
|
export { TOKEN_CSS, TOKENS, tokenVars } from "./tokens.js";
|
|
12
|
+
export { PAGE_SURFACE_CLASS, PAGE_SURFACE_CSS } from "./surface.js";
|
|
13
|
+
export { createSettingsGatewayCache, saveSettings } from "./settings-gateway.js";
|
|
8
14
|
//# sourceMappingURL=index.js.map
|
package/lib/types/seam.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ export interface ConfigFormLike<T = Record<string, unknown>> {
|
|
|
66
66
|
mutate(ops: readonly ConfigPathOpLike[], expectedRevision?: number): Promise<boolean>;
|
|
67
67
|
}
|
|
68
68
|
export interface ConfigFormsSeat {
|
|
69
|
-
get(entryId: string): ConfigFormLike;
|
|
69
|
+
get<T = Record<string, unknown>>(entryId: string): ConfigFormLike<T> | undefined;
|
|
70
70
|
}
|
|
71
71
|
export interface SettingsFace {
|
|
72
72
|
merge?: ConfigFormLike;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One namespace's settings gateway: one scope for reads, one revision-fenced
|
|
3
|
+
* write, and a read-back in `finally`. The gateway owns no subscription — the
|
|
4
|
+
* platform settings scope already listens to document updates and resets.
|
|
5
|
+
* @module @lmzhen/dsh-evolution-client-kit
|
|
6
|
+
*/
|
|
7
|
+
import type { ConfigPathOpLike } from './seam.ts';
|
|
8
|
+
/** The read side of a platform settings scope. */
|
|
9
|
+
export interface SettingsScopeLike {
|
|
10
|
+
/** @returns the current namespace snapshot; only `revision` is read here. */
|
|
11
|
+
getSnapshot(): {
|
|
12
|
+
readonly revision?: number | undefined;
|
|
13
|
+
};
|
|
14
|
+
/** Queue a fresh describe and settle after it publishes or is superseded. */
|
|
15
|
+
load(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
/** The write transport; one call carries the complete op list. */
|
|
18
|
+
export interface SettingsMutationApi {
|
|
19
|
+
mutate(input: {
|
|
20
|
+
readonly ns: string;
|
|
21
|
+
readonly ops: readonly ConfigPathOpLike[];
|
|
22
|
+
readonly expectedRevision?: number;
|
|
23
|
+
}): Promise<{
|
|
24
|
+
readonly result: {
|
|
25
|
+
readonly ok: boolean;
|
|
26
|
+
};
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
/** Write verdict and the independent read-back verdict. */
|
|
30
|
+
export interface SettingsSaveResult {
|
|
31
|
+
/** True only when the Host accepted the write. */
|
|
32
|
+
readonly written: boolean;
|
|
33
|
+
/** Read-back outcome; never derived from `written`. */
|
|
34
|
+
readonly readback: 'ok' | 'failed';
|
|
35
|
+
/** Transport/write failure, retained when the read-back was still attempted. */
|
|
36
|
+
readonly failure?: unknown;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Save one atomic op list and always read back.
|
|
40
|
+
* @param options - namespace, bound scope, mutation transport, and ops.
|
|
41
|
+
* @returns the write verdict plus the separate read-back verdict.
|
|
42
|
+
*/
|
|
43
|
+
export declare function saveSettings(options: {
|
|
44
|
+
readonly namespace: string;
|
|
45
|
+
readonly scope: SettingsScopeLike;
|
|
46
|
+
readonly api: SettingsMutationApi;
|
|
47
|
+
readonly ops: readonly ConfigPathOpLike[];
|
|
48
|
+
}): Promise<SettingsSaveResult>;
|
|
49
|
+
/** The platform binder face; one call per namespace is the whole contract. */
|
|
50
|
+
export interface SettingsBinderLike {
|
|
51
|
+
bind(spec: {
|
|
52
|
+
readonly namespace: string;
|
|
53
|
+
}): SettingsScopeLike;
|
|
54
|
+
}
|
|
55
|
+
/** One cached namespace gateway. */
|
|
56
|
+
export interface SettingsGateway {
|
|
57
|
+
readonly scope: SettingsScopeLike;
|
|
58
|
+
/** Save through this gateway's cached scope. */
|
|
59
|
+
save(ops: readonly ConfigPathOpLike[]): Promise<SettingsSaveResult>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Bind each namespace once and reuse that scope for every later save.
|
|
63
|
+
* @param binder - the platform settings-scope service.
|
|
64
|
+
* @param api - the mutation transport.
|
|
65
|
+
* @returns a lookup that creates one gateway per namespace.
|
|
66
|
+
*/
|
|
67
|
+
export declare function createSettingsGatewayCache(binder: SettingsBinderLike, api: SettingsMutationApi): (namespace: string) => SettingsGateway;
|
|
68
|
+
//# sourceMappingURL=settings-gateway.d.ts.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Save one atomic op list and always read back.
|
|
3
|
+
* @param options - namespace, bound scope, mutation transport, and ops.
|
|
4
|
+
* @returns the write verdict plus the separate read-back verdict.
|
|
5
|
+
*/
|
|
6
|
+
export async function saveSettings(options) {
|
|
7
|
+
const revision = options.scope.getSnapshot().revision;
|
|
8
|
+
let written = false;
|
|
9
|
+
let failure;
|
|
10
|
+
try {
|
|
11
|
+
const response = await options.api.mutate({
|
|
12
|
+
ns: options.namespace,
|
|
13
|
+
ops: options.ops,
|
|
14
|
+
...(revision === undefined ? {} : { expectedRevision: revision }),
|
|
15
|
+
});
|
|
16
|
+
written = response.result.ok;
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
failure = error;
|
|
20
|
+
}
|
|
21
|
+
let readback = 'ok';
|
|
22
|
+
try {
|
|
23
|
+
await options.scope.load();
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
readback = 'failed';
|
|
27
|
+
failure ??= error;
|
|
28
|
+
}
|
|
29
|
+
return failure === undefined ? { written, readback } : { written, readback, failure };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Bind each namespace once and reuse that scope for every later save.
|
|
33
|
+
* @param binder - the platform settings-scope service.
|
|
34
|
+
* @param api - the mutation transport.
|
|
35
|
+
* @returns a lookup that creates one gateway per namespace.
|
|
36
|
+
*/
|
|
37
|
+
export function createSettingsGatewayCache(binder, api) {
|
|
38
|
+
const cache = new Map();
|
|
39
|
+
return (namespace) => {
|
|
40
|
+
const existing = cache.get(namespace);
|
|
41
|
+
if (existing !== undefined)
|
|
42
|
+
return existing;
|
|
43
|
+
const scope = binder.bind({ namespace });
|
|
44
|
+
const gateway = {
|
|
45
|
+
scope,
|
|
46
|
+
save: async (ops) => await saveSettings({ namespace, scope, api, ops }),
|
|
47
|
+
};
|
|
48
|
+
cache.set(namespace, gateway);
|
|
49
|
+
return gateway;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=settings-gateway.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Family settings data plane, adapted to the card's form shape.
|
|
3
|
+
*
|
|
4
|
+
* The platform RPC only serves its own namespace allowlist, so `connection.api.settings`
|
|
5
|
+
* cannot read family namespaces even though the host settings provider has them.
|
|
6
|
+
* These forms talk to the family's exact routes, which call the SAME platform
|
|
7
|
+
* settings provider (schema validation, revision fencing, redaction and storage
|
|
8
|
+
* stay platform-owned).
|
|
9
|
+
* @module @lmzhen/dsh-evolution-client-kit
|
|
10
|
+
*/
|
|
11
|
+
import type { ConfigFormsSeat } from './seam.ts';
|
|
12
|
+
interface ContextLike {
|
|
13
|
+
get?: (name: string) => unknown;
|
|
14
|
+
remote?: {
|
|
15
|
+
$on?: (event: string, listener: (namespace: string) => void) => () => void;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export declare function createSettingsSeat(ctx: ContextLike): ConfigFormsSeat;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=settings-seat.d.ts.map
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { ROUTES } from "./generated/routes.generated.js";
|
|
2
|
+
const SETTINGS_DESCRIBE = ROUTES.settings.describe;
|
|
3
|
+
const SETTINGS_MUTATE = ROUTES.settings.mutate;
|
|
4
|
+
const EMPTY = Object.freeze({
|
|
5
|
+
status: 'unavailable', value: undefined, user: undefined, writable: false, base: undefined, revision: undefined, reason: 'transport',
|
|
6
|
+
});
|
|
7
|
+
function snapshotFrom(value, ns) {
|
|
8
|
+
if (typeof value !== 'object' || value === null)
|
|
9
|
+
return EMPTY;
|
|
10
|
+
const list = value.namespaces;
|
|
11
|
+
if (!Array.isArray(list))
|
|
12
|
+
return EMPTY;
|
|
13
|
+
const item = list.find(candidate => typeof candidate === 'object' && candidate !== null && candidate.ns === ns);
|
|
14
|
+
return item === undefined ? { ...EMPTY, reason: 'not-served' } : item;
|
|
15
|
+
}
|
|
16
|
+
async function describe(namespace) {
|
|
17
|
+
try {
|
|
18
|
+
const response = await fetch(SETTINGS_DESCRIBE, { headers: { accept: 'application/json' } });
|
|
19
|
+
if (!response.ok)
|
|
20
|
+
return EMPTY;
|
|
21
|
+
const body = await response.json();
|
|
22
|
+
if (body.ok !== true)
|
|
23
|
+
return EMPTY;
|
|
24
|
+
return snapshotFrom(body.data, namespace);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return EMPTY;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function write(namespace, ops, expectedRevision) {
|
|
31
|
+
try {
|
|
32
|
+
const response = await fetch(SETTINGS_MUTATE, {
|
|
33
|
+
method: 'POST',
|
|
34
|
+
headers: { 'content-type': 'application/json', accept: 'application/json' },
|
|
35
|
+
body: JSON.stringify({ ns: namespace, ops, ...(expectedRevision === undefined ? {} : { expectedRevision }) }),
|
|
36
|
+
});
|
|
37
|
+
if (!response.ok)
|
|
38
|
+
return { ok: false };
|
|
39
|
+
const body = await response.json();
|
|
40
|
+
return { ok: body.ok === true, snapshot: snapshotFrom(body.data, namespace) };
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return { ok: false };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function createForm(namespace, ctx) {
|
|
47
|
+
let snapshot = { ...EMPTY, reason: 'seat-missing' };
|
|
48
|
+
const listeners = new Set();
|
|
49
|
+
let started = false;
|
|
50
|
+
let listening = false;
|
|
51
|
+
const notify = () => { for (const listener of listeners)
|
|
52
|
+
listener(); };
|
|
53
|
+
const refresh = async () => {
|
|
54
|
+
snapshot = await describe(namespace);
|
|
55
|
+
notify();
|
|
56
|
+
};
|
|
57
|
+
const start = () => {
|
|
58
|
+
if (started)
|
|
59
|
+
return;
|
|
60
|
+
started = true;
|
|
61
|
+
if (!listening) {
|
|
62
|
+
listening = true;
|
|
63
|
+
const remote = ctx.get?.('remote');
|
|
64
|
+
remote?.$on?.('settings/document-updated', (changed) => { if (changed === namespace)
|
|
65
|
+
void refresh(); });
|
|
66
|
+
}
|
|
67
|
+
void refresh();
|
|
68
|
+
};
|
|
69
|
+
const form = {
|
|
70
|
+
getSnapshot: () => snapshot,
|
|
71
|
+
subscribe: (listener) => {
|
|
72
|
+
listeners.add(listener);
|
|
73
|
+
start();
|
|
74
|
+
return () => { listeners.delete(listener); };
|
|
75
|
+
},
|
|
76
|
+
set: async (field, value) => (await form.mutate([{ op: 'set', path: [field], value }])),
|
|
77
|
+
unset: async (field) => (await form.mutate([{ op: 'unset', path: [field] }])),
|
|
78
|
+
mutate: async (ops, expectedRevision) => {
|
|
79
|
+
const revision = expectedRevision ?? snapshot.revision;
|
|
80
|
+
const outcome = await write(namespace, ops, revision);
|
|
81
|
+
if (outcome.snapshot !== undefined) {
|
|
82
|
+
snapshot = outcome.snapshot;
|
|
83
|
+
notify();
|
|
84
|
+
}
|
|
85
|
+
else
|
|
86
|
+
await refresh();
|
|
87
|
+
return outcome.ok;
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
return form;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Build one cached form per family namespace over the family settings routes.
|
|
94
|
+
* @param ctx - the client plugin context (remote subscription is optional).
|
|
95
|
+
* @returns the seat; each namespace is served by /api/dsh-evolution/settings/*.
|
|
96
|
+
*/
|
|
97
|
+
const seats = new WeakMap();
|
|
98
|
+
export function createSettingsSeat(ctx) {
|
|
99
|
+
const cached = seats.get(ctx);
|
|
100
|
+
if (cached !== undefined)
|
|
101
|
+
return cached;
|
|
102
|
+
const forms = new Map();
|
|
103
|
+
const seat = {
|
|
104
|
+
get(namespace) {
|
|
105
|
+
let form = forms.get(namespace);
|
|
106
|
+
if (form === undefined) {
|
|
107
|
+
form = createForm(namespace, ctx);
|
|
108
|
+
forms.set(namespace, form);
|
|
109
|
+
}
|
|
110
|
+
return form;
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
seats.set(ctx, seat);
|
|
114
|
+
return seat;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=settings-seat.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared opaque page surface. Skin images may sit behind the shell; every
|
|
3
|
+
* reading surface must paint the platform's base layer before text can be read.
|
|
4
|
+
* @module @lmzhen/dsh-evolution-client-kit
|
|
5
|
+
*/
|
|
6
|
+
/** Class consumers put on the root of a full-page reading surface. */
|
|
7
|
+
export declare const PAGE_SURFACE_CLASS = "evolution-page-surface";
|
|
8
|
+
/** Stylesheet for {@link PAGE_SURFACE_CLASS}; consumers append it to their own CSS. */
|
|
9
|
+
export declare const PAGE_SURFACE_CSS = ".evolution-page-surface{min-height:100%;background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-primary)}";
|
|
10
|
+
//# sourceMappingURL=surface.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared opaque page surface. Skin images may sit behind the shell; every
|
|
3
|
+
* reading surface must paint the platform's base layer before text can be read.
|
|
4
|
+
* @module @lmzhen/dsh-evolution-client-kit
|
|
5
|
+
*/
|
|
6
|
+
/** Class consumers put on the root of a full-page reading surface. */
|
|
7
|
+
export const PAGE_SURFACE_CLASS = 'evolution-page-surface';
|
|
8
|
+
/** Stylesheet for {@link PAGE_SURFACE_CLASS}; consumers append it to their own CSS. */
|
|
9
|
+
export const PAGE_SURFACE_CSS = '.evolution-page-surface{min-height:100%;background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-primary)}';
|
|
10
|
+
//# sourceMappingURL=surface.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared registration for a view inside the single evolution workbench page.
|
|
3
|
+
* A feature package owns its locale, styles and face; the workbench owns the page.
|
|
4
|
+
* @module @lmzhen/dsh-evolution-client-kit
|
|
5
|
+
*/
|
|
6
|
+
import type { Context as ClientContext } from '@deepseek-ai/cordis';
|
|
7
|
+
import type { ReactNode } from 'react';
|
|
8
|
+
/** One feature view contribution. */
|
|
9
|
+
export interface WorkbenchViewSpec<Face> {
|
|
10
|
+
readonly id: string;
|
|
11
|
+
readonly order: number;
|
|
12
|
+
readonly namespace: string;
|
|
13
|
+
readonly dictionaries: {
|
|
14
|
+
readonly zh: Record<string, string>;
|
|
15
|
+
readonly en: Record<string, string>;
|
|
16
|
+
};
|
|
17
|
+
readonly styles: {
|
|
18
|
+
readonly css: string;
|
|
19
|
+
readonly tagId: string;
|
|
20
|
+
};
|
|
21
|
+
readonly component: (props: never) => ReactNode;
|
|
22
|
+
readonly face: (t: (key: string, values?: Readonly<Record<string, string | number>>) => string) => Face;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Register one view into `evolution.workbench.view`.
|
|
26
|
+
* @param ctx - client cordis context.
|
|
27
|
+
* @param spec - view identity, copy, styles, component and face factory.
|
|
28
|
+
*/
|
|
29
|
+
export declare function registerWorkbenchView<Face>(ctx: ClientContext, spec: WorkbenchViewSpec<Face>): void;
|
|
30
|
+
//# sourceMappingURL=workbench-view.d.ts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
function injectStyles(doc, css, tagId) {
|
|
2
|
+
if (doc === undefined)
|
|
3
|
+
return () => { };
|
|
4
|
+
const previous = doc.querySelector('style[data-plugin-css="' + tagId + '"]');
|
|
5
|
+
previous?.remove();
|
|
6
|
+
const tag = doc.createElement('style');
|
|
7
|
+
tag.setAttribute('data-plugin-css', tagId);
|
|
8
|
+
tag.textContent = css;
|
|
9
|
+
doc.head.appendChild(tag);
|
|
10
|
+
return () => { tag.remove(); };
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Register one view into `evolution.workbench.view`.
|
|
14
|
+
* @param ctx - client cordis context.
|
|
15
|
+
* @param spec - view identity, copy, styles, component and face factory.
|
|
16
|
+
*/
|
|
17
|
+
export function registerWorkbenchView(ctx, spec) {
|
|
18
|
+
const seam = ctx;
|
|
19
|
+
let registered = false;
|
|
20
|
+
ctx.effect(() => {
|
|
21
|
+
try {
|
|
22
|
+
const dispose = seam.locale.register(spec.namespace, spec.dictionaries);
|
|
23
|
+
registered = true;
|
|
24
|
+
return dispose;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
ctx.logger.warn(spec.namespace + ': locale refused (' + String(error) + '); the view falls back to the bundle copy');
|
|
28
|
+
return () => { };
|
|
29
|
+
}
|
|
30
|
+
}, spec.namespace + ': locale');
|
|
31
|
+
ctx.effect(() => injectStyles(typeof document === 'undefined' ? undefined : document, spec.styles.css, spec.styles.tagId), spec.namespace + ': styles');
|
|
32
|
+
const fallback = spec.dictionaries.zh;
|
|
33
|
+
const lookup = (key) => {
|
|
34
|
+
const own = fallback[key] ?? key;
|
|
35
|
+
if (!registered)
|
|
36
|
+
return own;
|
|
37
|
+
try {
|
|
38
|
+
return seam.locale.bind(spec.namespace)(key);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return own;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const t = (key, values) => {
|
|
45
|
+
const template = lookup(key);
|
|
46
|
+
if (values === undefined)
|
|
47
|
+
return template;
|
|
48
|
+
return template.replace(/\{(\w+)\}/g, (match, slot) => values[slot] === undefined ? match : String(values[slot]));
|
|
49
|
+
};
|
|
50
|
+
seam.slots.inject('evolution.workbench.view', function* () {
|
|
51
|
+
yield seam.slots.register({
|
|
52
|
+
name: 'evolution.workbench.view',
|
|
53
|
+
id: spec.id,
|
|
54
|
+
order: spec.order,
|
|
55
|
+
label: () => t('entry.label'),
|
|
56
|
+
inject: () => spec.face(t),
|
|
57
|
+
}, spec.component);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=workbench-view.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lmzhen/dsh-evolution-client-kit",
|
|
3
3
|
"description": "Shared browser seams and lifecycle for the evolution family sidebar panels (community build)",
|
|
4
|
-
"version": "0.32.
|
|
4
|
+
"version": "0.32.6",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|