@dsh-plus/subagent-model 0.3.32 → 0.3.34
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 +852 -134
- package/lib/index.d.ts +0 -2
- package/lib/index.js +2 -5
- package/package.json +14 -14
- package/src/client/card.tsx +4 -17
- package/src/client/draft.ts +2 -4
- package/src/client/i18n.ts +0 -2
- package/src/config.ts +1 -4
package/lib/client.js
CHANGED
|
@@ -4,11 +4,36 @@ window.__ModuleLoader__.load({
|
|
|
4
4
|
var module = { exports: {} };
|
|
5
5
|
var exports = module.exports;
|
|
6
6
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
|
-
|
|
7
|
+
//#region \0rolldown/runtime.js
|
|
8
|
+
var __create = Object.create;
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
11
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
12
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
16
|
+
key = keys[i];
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
18
|
+
get: ((k) => from[k]).bind(null, key),
|
|
19
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
25
|
+
value: mod,
|
|
26
|
+
enumerable: true
|
|
27
|
+
}) : target, mod));
|
|
28
|
+
//#endregion
|
|
8
29
|
let react = require("react");
|
|
30
|
+
react = __toESM(react, 1);
|
|
31
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
32
|
+
let _deepseek_ai_schemastery = require("@deepseek-ai/schemastery");
|
|
33
|
+
_deepseek_ai_schemastery = __toESM(_deepseek_ai_schemastery, 1);
|
|
9
34
|
require("@deepseek-ai/dsh-client-ui-primitives");
|
|
10
35
|
//#region ../shared/src/client/fields.tsx
|
|
11
|
-
/** 卡片按钮(与
|
|
36
|
+
/** 卡片按钮(与 ConfigShell 页脚同一套类名与视觉)。 */
|
|
12
37
|
function Button(props) {
|
|
13
38
|
const p = props.prefix ?? "dshp";
|
|
14
39
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
@@ -77,11 +102,26 @@ window.__ModuleLoader__.load({
|
|
|
77
102
|
}
|
|
78
103
|
//#endregion
|
|
79
104
|
//#region ../shared/src/client/card.tsx
|
|
105
|
+
/**
|
|
106
|
+
* 配置卡片外壳与排版件:`ConfigShell`(卡片级无边框分节)、`Section`(卡片内二级
|
|
107
|
+
* 分组)、`FieldGrid`(字段排布)、`Note`(只读说明)、`ListEditor`(数组型资源
|
|
108
|
+
* 统一编辑)、`CardLoading`(取值未到达占位)。
|
|
109
|
+
*
|
|
110
|
+
* 宿主页面(`plugins.row.config` / `plugins.bundle.config` 的 page 视图)自己画
|
|
111
|
+
* 标题、图标、面包屑与页面级内边距,视图只填内容区——所以这里不再自绘带边框
|
|
112
|
+
* 卡片(会形成卡片套卡片,把移动端可用宽度逐层扣掉),也不做折叠:page 视图
|
|
113
|
+
* 本身就是表单落地页。度量对齐官方设置页(dsh-client-ui-primitives 的
|
|
114
|
+
* settings-form):小节标题 13px/600、字段区零横向内边距、页脚非 sticky。
|
|
115
|
+
*
|
|
116
|
+
* 各插件 card.tsx 只填 children 字段区与 actions;类名前缀与样式由
|
|
117
|
+
* cardCss(prefix) 配套。
|
|
118
|
+
* @module @dsh-plus/shared/client/card
|
|
119
|
+
*/
|
|
80
120
|
const IDLE_STATUS = {
|
|
81
121
|
kind: "idle",
|
|
82
122
|
text: ""
|
|
83
123
|
};
|
|
84
|
-
function
|
|
124
|
+
function ConfigShell(props) {
|
|
85
125
|
const p = props.prefix;
|
|
86
126
|
const badge = props.statusBadge;
|
|
87
127
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
@@ -137,7 +177,7 @@ window.__ModuleLoader__.load({
|
|
|
137
177
|
]
|
|
138
178
|
});
|
|
139
179
|
}
|
|
140
|
-
/** 取值未到达时的占位:与
|
|
180
|
+
/** 取值未到达时的占位:与 ConfigShell 同形态,避免宿主页里闪一次卡片外壳。 */
|
|
141
181
|
function CardLoading(props) {
|
|
142
182
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
|
|
143
183
|
className: `${props.prefix}-section`,
|
|
@@ -149,14 +189,744 @@ window.__ModuleLoader__.load({
|
|
|
149
189
|
});
|
|
150
190
|
}
|
|
151
191
|
//#endregion
|
|
192
|
+
//#region ../shared/src/client/code-ops.ts
|
|
193
|
+
/** 是否为普通对象(配置文档的合法节点)。 */
|
|
194
|
+
function isPlainObject(value) {
|
|
195
|
+
if (value === null || typeof value !== "object") return false;
|
|
196
|
+
const proto = Object.getPrototypeOf(value);
|
|
197
|
+
return proto === Object.prototype || proto === null;
|
|
198
|
+
}
|
|
199
|
+
/** 从 V8 语法错误消息中取行列;新版带 `(line L column C)`,旧版只有偏移量。 */
|
|
200
|
+
function positionOf(message, text) {
|
|
201
|
+
const located = /\(line (\d+) column (\d+)\)/.exec(message);
|
|
202
|
+
if (located !== null) return {
|
|
203
|
+
line: Number(located[1]),
|
|
204
|
+
column: Number(located[2])
|
|
205
|
+
};
|
|
206
|
+
const offset = /at position (\d+)/.exec(message);
|
|
207
|
+
if (offset === null) return {
|
|
208
|
+
line: null,
|
|
209
|
+
column: null
|
|
210
|
+
};
|
|
211
|
+
const index = Math.min(Number(offset[1]), text.length);
|
|
212
|
+
const head = text.slice(0, index);
|
|
213
|
+
return {
|
|
214
|
+
line: head.split("\n").length,
|
|
215
|
+
column: index - head.lastIndexOf("\n")
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* 解析配置文档:必须是 JSON 对象(配置根节点为行级 Config 对象)。
|
|
220
|
+
* @param text - 编辑器全文。
|
|
221
|
+
* @returns 成功给出对象;失败给出原因与可定位的行列。
|
|
222
|
+
*/
|
|
223
|
+
function parseConfigJson(text) {
|
|
224
|
+
if (text.trim() === "") return {
|
|
225
|
+
ok: false,
|
|
226
|
+
reason: "empty",
|
|
227
|
+
message: "",
|
|
228
|
+
line: null,
|
|
229
|
+
column: null
|
|
230
|
+
};
|
|
231
|
+
let parsed;
|
|
232
|
+
try {
|
|
233
|
+
parsed = JSON.parse(text);
|
|
234
|
+
} catch (error) {
|
|
235
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
236
|
+
return {
|
|
237
|
+
ok: false,
|
|
238
|
+
reason: "syntax",
|
|
239
|
+
message,
|
|
240
|
+
...positionOf(message, text)
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
if (!isPlainObject(parsed)) return {
|
|
244
|
+
ok: false,
|
|
245
|
+
reason: "root",
|
|
246
|
+
message: "",
|
|
247
|
+
line: 1,
|
|
248
|
+
column: 1
|
|
249
|
+
};
|
|
250
|
+
return {
|
|
251
|
+
ok: true,
|
|
252
|
+
value: parsed
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
/** 两空格缩进格式化(解析失败时原样返回输入与失败信息)。 */
|
|
256
|
+
function formatConfigJson(text) {
|
|
257
|
+
const parsed = parseConfigJson(text);
|
|
258
|
+
if (!parsed.ok) return {
|
|
259
|
+
ok: false,
|
|
260
|
+
result: parsed
|
|
261
|
+
};
|
|
262
|
+
return {
|
|
263
|
+
ok: true,
|
|
264
|
+
text: `${JSON.stringify(parsed.value, null, 2)}\n`
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
/** 差分:对象删键 → unset;数组删元素 → 下标降序 unset(保持其余下标有效)。 */
|
|
268
|
+
function diffToOps(before, after) {
|
|
269
|
+
const ops = [];
|
|
270
|
+
walk(before, after, [], ops);
|
|
271
|
+
return ops;
|
|
272
|
+
}
|
|
273
|
+
function walk(before, after, path, ops) {
|
|
274
|
+
if (Array.isArray(after)) {
|
|
275
|
+
walkArray(before, after, path, ops);
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (isPlainObject(after)) {
|
|
279
|
+
walkObject(before, after, path, ops);
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
if (!Object.is(before, after)) ops.push({
|
|
283
|
+
op: "set",
|
|
284
|
+
path: [...path],
|
|
285
|
+
value: after
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
function walkObject(before, after, path, ops) {
|
|
289
|
+
if (!isPlainObject(before)) {
|
|
290
|
+
ops.push({
|
|
291
|
+
op: "set",
|
|
292
|
+
path: [...path],
|
|
293
|
+
value: after
|
|
294
|
+
});
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
for (const [key, value] of Object.entries(after)) {
|
|
298
|
+
if (!Object.hasOwn(before, key)) {
|
|
299
|
+
ops.push({
|
|
300
|
+
op: "set",
|
|
301
|
+
path: [...path, key],
|
|
302
|
+
value
|
|
303
|
+
});
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
walk(before[key], value, [...path, key], ops);
|
|
307
|
+
}
|
|
308
|
+
for (const key of Object.keys(before)) if (!Object.hasOwn(after, key)) ops.push({
|
|
309
|
+
op: "unset",
|
|
310
|
+
path: [...path, key]
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
function walkArray(before, after, path, ops) {
|
|
314
|
+
if (!Array.isArray(before)) {
|
|
315
|
+
ops.push({
|
|
316
|
+
op: "set",
|
|
317
|
+
path: [...path],
|
|
318
|
+
value: after
|
|
319
|
+
});
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
const shared = Math.min(before.length, after.length);
|
|
323
|
+
for (let index = 0; index < shared; index += 1) walk(before[index], after[index], [...path, String(index)], ops);
|
|
324
|
+
for (let index = before.length - 1; index >= after.length; index -= 1) ops.push({
|
|
325
|
+
op: "unset",
|
|
326
|
+
path: [...path, String(index)]
|
|
327
|
+
});
|
|
328
|
+
for (let index = before.length; index < after.length; index += 1) ops.push({
|
|
329
|
+
op: "set",
|
|
330
|
+
path: [...path, String(index)],
|
|
331
|
+
value: after[index]
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
/** schema JSON 里的密钥字段路径(`meta.role === 'secret'`):源码编辑器不呈现它们。 */
|
|
335
|
+
function secretPathsOf(schemaJson) {
|
|
336
|
+
const refs = refsOf(schemaJson);
|
|
337
|
+
if (refs === null) return [];
|
|
338
|
+
const root = schemaJson.uid;
|
|
339
|
+
if (typeof root !== "number") return [];
|
|
340
|
+
const out = [];
|
|
341
|
+
collectSecretPaths(refs, root, [], out, /* @__PURE__ */ new Set());
|
|
342
|
+
return out;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* 文档里 schema 未声明的键路径。
|
|
346
|
+
*
|
|
347
|
+
* schemastery 对未声明键**透传忽略**(不报错、不剥离),所以这类键会被原样写进
|
|
348
|
+
* 用户层并永久留存——典型来源是历史配置键与手写拼写错误。源码编辑器把它作为
|
|
349
|
+
* 非阻断警告列出来(迁移期新旧键并存时不至于挡住应用)。
|
|
350
|
+
*/
|
|
351
|
+
function unknownKeysOf(schemaJson, value) {
|
|
352
|
+
const refs = refsOf(schemaJson);
|
|
353
|
+
if (refs === null || !isPlainObject(value)) return [];
|
|
354
|
+
const root = schemaJson.uid;
|
|
355
|
+
if (typeof root !== "number") return [];
|
|
356
|
+
return [...unknownKeysAt(refs, root, value)].sort();
|
|
357
|
+
}
|
|
358
|
+
/** 返回「该节点下所有未被 schema 声明的键路径」的集合。 */
|
|
359
|
+
function unknownKeysAt(refs, index, value) {
|
|
360
|
+
const node = refs[String(index)];
|
|
361
|
+
if (node === void 0) return /* @__PURE__ */ new Set();
|
|
362
|
+
if (node.list !== void 0) return intersectBranches(refs, node.list, value);
|
|
363
|
+
if (node.inner !== void 0) {
|
|
364
|
+
if (Array.isArray(value)) {
|
|
365
|
+
const out = /* @__PURE__ */ new Set();
|
|
366
|
+
for (const [at, item] of value.entries()) for (const path of unknownKeysAt(refs, node.inner, item)) out.add(`${at}.${path}`);
|
|
367
|
+
return out;
|
|
368
|
+
}
|
|
369
|
+
return unknownKeysAt(refs, node.inner, value);
|
|
370
|
+
}
|
|
371
|
+
if (node.dict === void 0 || !isPlainObject(value)) return /* @__PURE__ */ new Set();
|
|
372
|
+
const out = /* @__PURE__ */ new Set();
|
|
373
|
+
for (const [key, child] of Object.entries(value)) {
|
|
374
|
+
const next = node.dict[key];
|
|
375
|
+
if (next === void 0) {
|
|
376
|
+
out.add(key);
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
for (const path of unknownKeysAt(refs, next, child)) out.add(`${key}.${path}`);
|
|
380
|
+
}
|
|
381
|
+
return out;
|
|
382
|
+
}
|
|
383
|
+
/** 联合类型:只在「对象型分支」之间取交集(标量分支不否决键判定)。 */
|
|
384
|
+
function intersectBranches(refs, list, value) {
|
|
385
|
+
const objectBranches = list.filter((branch) => refs[String(branch)]?.dict !== void 0);
|
|
386
|
+
if (objectBranches.length === 0) return /* @__PURE__ */ new Set();
|
|
387
|
+
let result = null;
|
|
388
|
+
for (const branch of objectBranches) {
|
|
389
|
+
const keys = unknownKeysAt(refs, branch, value);
|
|
390
|
+
if (result === null) {
|
|
391
|
+
result = keys;
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
for (const key of [...result]) if (!keys.has(key)) result.delete(key);
|
|
395
|
+
}
|
|
396
|
+
return result ?? /* @__PURE__ */ new Set();
|
|
397
|
+
}
|
|
398
|
+
function refsOf(schemaJson) {
|
|
399
|
+
if (!isPlainObject(schemaJson)) return null;
|
|
400
|
+
const refs = schemaJson.refs;
|
|
401
|
+
return isPlainObject(refs) ? refs : null;
|
|
402
|
+
}
|
|
403
|
+
function collectSecretPaths(refs, index, path, out, seen) {
|
|
404
|
+
const node = refs[String(index)];
|
|
405
|
+
if (node === void 0) return;
|
|
406
|
+
const marker = `${index}:${path.join(".")}`;
|
|
407
|
+
if (seen.has(marker)) return;
|
|
408
|
+
seen.add(marker);
|
|
409
|
+
if (node.meta?.role === "secret") {
|
|
410
|
+
out.push([...path]);
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
for (const [key, child] of Object.entries(node.dict ?? {})) collectSecretPaths(refs, child, [...path, key], out, seen);
|
|
414
|
+
if (typeof node.inner === "number") collectSecretPaths(refs, node.inner, path, out, seen);
|
|
415
|
+
for (const child of node.list ?? []) collectSecretPaths(refs, child, path, out, seen);
|
|
416
|
+
}
|
|
417
|
+
//#endregion
|
|
418
|
+
//#region ../shared/src/client/code-validate.ts
|
|
419
|
+
/**
|
|
420
|
+
* 配置源码编辑的模式校验:用宿主 `describe` 回传的 schema JSON 在浏览器本地
|
|
421
|
+
* 重建同一套 schemastery 校验(库 23KB 纯 JS,随 client bundle 打苞——浏览器端
|
|
422
|
+
* 没有宿主实例,不存在跨实例符号身份问题,见 docs/reference/官方机制参照.md
|
|
423
|
+
* 「客户端平台」)。
|
|
424
|
+
*
|
|
425
|
+
* 校验与宿主写入路径同源:`new Schema(json)` 后按同一份 volatile 投影调用,
|
|
426
|
+
* 因此本地拦下的错误与宿主 `settings/rejected` 的判据一致。
|
|
427
|
+
* @module @dsh-plus/shared/client/code-validate
|
|
428
|
+
*/
|
|
429
|
+
/** 重建结果按 schema JSON 对象身份缓存(describe 每次应答一个新对象,无泄漏风险)。 */
|
|
430
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
431
|
+
function rebuild(schemaJson) {
|
|
432
|
+
if (!isPlainObject(schemaJson)) return null;
|
|
433
|
+
const cached = cache.get(schemaJson);
|
|
434
|
+
if (cached !== void 0) return cached;
|
|
435
|
+
let built = null;
|
|
436
|
+
try {
|
|
437
|
+
built = new _deepseek_ai_schemastery.default(schemaJson);
|
|
438
|
+
} catch {
|
|
439
|
+
built = null;
|
|
440
|
+
}
|
|
441
|
+
cache.set(schemaJson, built);
|
|
442
|
+
return built;
|
|
443
|
+
}
|
|
444
|
+
/** 从 schemastery 错误消息里取路径前缀:`$.a.b expected number but got x` → `a.b`。 */
|
|
445
|
+
function pathOf(message) {
|
|
446
|
+
const located = /^\$\.([^\s]+)/.exec(message);
|
|
447
|
+
return located === null ? "" : located[1] ?? "";
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* 按宿主 schema 校验一份配置文档。
|
|
451
|
+
* @param schemaJson - `describe` 应答里的 `schema`(schemastery `toJSON()` 形态)。
|
|
452
|
+
* @param value - 编辑器解析出的对象。
|
|
453
|
+
* @returns 通过(含「未校验」标记)或问题清单。
|
|
454
|
+
*/
|
|
455
|
+
function validateAgainstSchema(schemaJson, value) {
|
|
456
|
+
const validate = rebuild(schemaJson);
|
|
457
|
+
if (validate === null) return {
|
|
458
|
+
ok: true,
|
|
459
|
+
validated: false
|
|
460
|
+
};
|
|
461
|
+
try {
|
|
462
|
+
validate(value);
|
|
463
|
+
return {
|
|
464
|
+
ok: true,
|
|
465
|
+
validated: true
|
|
466
|
+
};
|
|
467
|
+
} catch (error) {
|
|
468
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
469
|
+
return {
|
|
470
|
+
ok: false,
|
|
471
|
+
validated: true,
|
|
472
|
+
issues: [{
|
|
473
|
+
path: pathOf(message),
|
|
474
|
+
message
|
|
475
|
+
}]
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
//#endregion
|
|
480
|
+
//#region ../shared/src/client/styles.ts
|
|
481
|
+
/**
|
|
482
|
+
* 配置分节样式工厂(各插件 client 的公共收编版)。
|
|
483
|
+
*
|
|
484
|
+
* 目标宿主 dsh 0.2.1-alpha.2:插件页把配置视图放进已有页面级内边距的容器里
|
|
485
|
+
* (`div.detailSections[data-plugin-config]` 或 `section.detailSection[data-plugin-config]`),
|
|
486
|
+
* 外层无边框——故这里输出的是**无边框分节**(小节标题 13px/600、字段 12px 0、
|
|
487
|
+
* 横向零内边距、页脚非 sticky),度量对齐官方设置页
|
|
488
|
+
* (`@deepseek-ai/dsh-client-ui-primitives` 的 settings-form)。
|
|
489
|
+
*
|
|
490
|
+
* 移动端与可达性(767px 断点 + pointer:coarse,对齐 ui-mobile-fit 约定):
|
|
491
|
+
* - 窄屏 input/textarea 16px(防 iOS 聚焦缩放)、可点目标 ≥44px;
|
|
492
|
+
* - 页脚按钮等宽换行、状态文字独占一行。
|
|
493
|
+
* 沿用官方 data-plugin / data-plugin-css 约定(HMR 据此卸载),不覆盖上游选择器。
|
|
494
|
+
* @module @dsh-plus/shared/client/styles
|
|
495
|
+
*/
|
|
496
|
+
/** 生成全套分节 CSS;prefix 为插件类名前缀(如 'dne'),extra 为插件特有规则。 */
|
|
497
|
+
function cardCss(prefix, extra = "") {
|
|
498
|
+
return `
|
|
499
|
+
.${prefix}-section{box-sizing:border-box;flex-direction:column;width:100%;min-width:0;padding:16px 0;display:flex}
|
|
500
|
+
.${prefix}-sectionHead{align-items:center;gap:8px;min-width:0;display:flex}
|
|
501
|
+
.${prefix}-sectionTitle{min-width:0;color:var(--dsw-alias-label-primary);flex:1;margin:0;font-size:13px;font-weight:600;line-height:1.5}
|
|
502
|
+
.${prefix}-sectionBadge{white-space:nowrap;border-radius:999px;flex:none;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
|
|
503
|
+
.${prefix}-sectionDesc{color:var(--dsw-alias-label-tertiary);margin:4px 0 0;font-size:12px;line-height:1.5}
|
|
504
|
+
.${prefix}-sectionBody{flex-direction:column;min-width:0;display:flex}
|
|
505
|
+
.${prefix}-sectionFooter{align-items:center;gap:8px;padding-top:16px;display:flex;flex-wrap:wrap}
|
|
506
|
+
.${prefix}-pending{white-space:nowrap;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);border-radius:999px;flex:none;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
|
|
507
|
+
.${prefix}-statusOn{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary)}
|
|
508
|
+
.${prefix}-statusOff{color:var(--dsw-alias-label-tertiary)}
|
|
509
|
+
.${prefix}-field{flex-direction:column;gap:6px;padding:12px 0;display:flex}
|
|
510
|
+
.${prefix}-field+.${prefix}-field{border-top:1px solid var(--dsw-alias-border-l2)}
|
|
511
|
+
.${prefix}-head{align-items:center;gap:8px;display:flex}
|
|
512
|
+
.${prefix}-label{min-width:0;color:var(--dsw-alias-label-primary);flex:1;font-size:13px;font-weight:500;line-height:1.5}
|
|
513
|
+
.${prefix}-badge{white-space:nowrap;border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
|
|
514
|
+
.${prefix}-badgeSet{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary)}
|
|
515
|
+
.${prefix}-badgeUnset{color:var(--dsw-alias-label-tertiary)}
|
|
516
|
+
.${prefix}-input{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);height:34px;font:inherit;color:var(--dsw-alias-label-primary);border-radius:8px;padding:0 12px;font-size:13px;transition:border-color .18s,background .18s}
|
|
517
|
+
.${prefix}-input:hover:not(:disabled):not(:focus-visible){border-color:var(--dsw-alias-label-dimmed)}
|
|
518
|
+
.${prefix}-input:focus-visible{border-color:var(--dsw-alias-brand-primary);outline:none}
|
|
519
|
+
.${prefix}-input:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}
|
|
520
|
+
.${prefix}-inputInvalid{border-color:var(--dsw-alias-label-error)}
|
|
521
|
+
.${prefix}-textarea{box-sizing:border-box;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:12px;height:auto;line-height:1.6;min-height:120px;padding:8px 12px;resize:vertical;white-space:pre;width:100%}
|
|
522
|
+
.${prefix}-select{appearance:none;background:var(--dsw-alias-bg-module-platform);border:none;cursor:pointer;background-image:linear-gradient(45deg,transparent 50%,var(--dsw-alias-label-secondary) 50%),linear-gradient(135deg,var(--dsw-alias-label-secondary) 50%,transparent 50%);background-position:calc(100% - 16px) 50%,calc(100% - 11px) 50%;background-size:5px 5px;background-repeat:no-repeat;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;height:34px;box-sizing:border-box;border-radius:8px;padding:0 30px 0 12px;transition:background-color .18s}
|
|
523
|
+
.${prefix}-select:hover:not(:disabled){background-color:var(--dsw-alias-interactive-bg-hover)}
|
|
524
|
+
.${prefix}-hint{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5}
|
|
525
|
+
.${prefix}-invalid{color:var(--dsw-alias-label-error);margin:0;font-size:12px;line-height:1.5}
|
|
526
|
+
.${prefix}-checkRow{align-items:center;gap:10px;display:flex;padding:6px 0}
|
|
527
|
+
.${prefix}-checkRow label{color:var(--dsw-alias-label-primary);font-size:13px;line-height:1.5;cursor:pointer;flex:1;min-width:0}
|
|
528
|
+
/* 自绘圆角扁平开关(官方 UI 无可见原生 checkbox,选择类全走胶囊/菜单) */
|
|
529
|
+
.${prefix}-checkRow input{appearance:none;-webkit-appearance:none;position:relative;box-sizing:border-box;background:var(--dsw-alias-bg-module-platform);border:none;border-radius:999px;width:34px;height:20px;flex:none;cursor:pointer;transition:background .18s;margin:0}
|
|
530
|
+
.${prefix}-checkRow input::after{content:"";position:absolute;top:2px;left:2px;background:var(--dsw-alias-label-primary);border-radius:999px;width:16px;height:16px;transition:left .18s cubic-bezier(.4,0,.2,1)}
|
|
531
|
+
.${prefix}-checkRow input:checked{background:var(--dsw-alias-brand-primary)}
|
|
532
|
+
.${prefix}-checkRow input:checked::after{left:16px;background:var(--dsw-alias-bg-base)}
|
|
533
|
+
.${prefix}-checkRow input:disabled{opacity:.4;cursor:default}
|
|
534
|
+
.${prefix}-checkRow input:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px}
|
|
535
|
+
.${prefix}-groupLabel{color:var(--dsw-alias-label-secondary);font-size:12px;font-weight:600;padding:12px 0 2px;margin:0}
|
|
536
|
+
/* 分节(Section):卡片内的二级分组,与一级分节同度量、无边框 */
|
|
537
|
+
.${prefix}-sub{flex-direction:column;padding:12px 0 0;display:flex}
|
|
538
|
+
.${prefix}-subHead{align-items:center;gap:8px;min-width:0;display:flex}
|
|
539
|
+
.${prefix}-subTitle{min-width:0;color:var(--dsw-alias-label-secondary);flex:1;margin:0;font-size:12px;font-weight:600;line-height:1.5}
|
|
540
|
+
.${prefix}-subDesc{color:var(--dsw-alias-label-tertiary);margin:4px 0 0;font-size:12px;line-height:1.5}
|
|
541
|
+
.${prefix}-subBody{flex-direction:column;min-width:0;display:flex}
|
|
542
|
+
.${prefix}-subToggle{appearance:none;background:0 0;border:none;color:var(--dsw-alias-label-tertiary);cursor:pointer;font:inherit;font-size:12px;padding:2px 6px;border-radius:6px}
|
|
543
|
+
.${prefix}-subToggle:hover{color:var(--dsw-alias-label-primary)}
|
|
544
|
+
/* 字段排布(FieldGrid):窄屏单列,宽屏可两列 */
|
|
545
|
+
.${prefix}-grid{display:grid;grid-template-columns:1fr;min-width:0}
|
|
546
|
+
@media (min-width:768px){
|
|
547
|
+
.${prefix}-grid2{grid-template-columns:1fr 1fr;column-gap:16px}
|
|
548
|
+
}
|
|
549
|
+
/* 只读说明块(Note) */
|
|
550
|
+
.${prefix}-note{background:var(--dsw-alias-bg-module-platform);border-radius:8px;margin:12px 0 0;padding:10px 12px}
|
|
551
|
+
.${prefix}-noteTitle{color:var(--dsw-alias-label-secondary);margin:0;font-size:12px;font-weight:600;line-height:1.5}
|
|
552
|
+
.${prefix}-noteBody{color:var(--dsw-alias-label-tertiary);margin:4px 0 0;font-size:12px;line-height:1.5;white-space:pre-wrap}
|
|
553
|
+
/* 列表编辑器(ListEditor):条目头 + 折叠 + 行内操作 */
|
|
554
|
+
.${prefix}-list{flex-direction:column;gap:8px;padding:8px 0 0;display:flex}
|
|
555
|
+
.${prefix}-listItem{border:1px solid var(--dsw-alias-border-l2);border-radius:10px;padding:8px 12px}
|
|
556
|
+
.${prefix}-listItemHead{align-items:center;gap:8px;min-width:0;display:flex}
|
|
557
|
+
.${prefix}-listItemTitle{min-width:0;color:var(--dsw-alias-label-primary);flex:1;font-size:13px;font-weight:500;line-height:1.5;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
558
|
+
.${prefix}-listItemBody{flex-direction:column;min-width:0;display:flex;padding-top:4px}
|
|
559
|
+
.${prefix}-listActions{align-items:center;gap:4px;display:flex;flex-wrap:wrap}
|
|
560
|
+
.${prefix}-iconBtn{appearance:none;background:0 0;border:1px solid #0000;border-radius:6px;color:var(--dsw-alias-label-tertiary);cursor:pointer;font:inherit;font-size:12px;line-height:1.5;padding:2px 8px}
|
|
561
|
+
.${prefix}-iconBtn:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-border-l2)}
|
|
562
|
+
.${prefix}-iconBtn:disabled{opacity:.4;cursor:default}
|
|
563
|
+
.${prefix}-listAdd{align-self:flex-start}
|
|
564
|
+
.${prefix}-listAddRow{align-items:center;align-self:flex-start;gap:8px;display:flex;flex-wrap:wrap}
|
|
565
|
+
.${prefix}-listEmpty{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5;padding:4px 0}
|
|
566
|
+
.${prefix}-readOnly{color:var(--dsw-alias-label-tertiary);margin:12px 0 0;font-size:12px;line-height:1.5}
|
|
567
|
+
.${prefix}-warn{color:var(--dsw-alias-label-error);margin:12px 0 0;font-size:12px;line-height:1.5}
|
|
568
|
+
.${prefix}-status{min-width:0;color:var(--dsw-alias-label-secondary);flex:1;margin:0;font-size:12px;line-height:1.5}
|
|
569
|
+
.${prefix}-statusError{color:var(--dsw-alias-label-error)}
|
|
570
|
+
.${prefix}-btn{appearance:none;font:inherit;cursor:pointer;border:1px solid #0000;border-radius:8px;padding:5px 14px;font-size:13px;line-height:1.5}
|
|
571
|
+
.${prefix}-btnGhost{border-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);background:0 0}
|
|
572
|
+
.${prefix}-btnGhost:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-dimmed)}
|
|
573
|
+
.${prefix}-btnPrimary{background:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}
|
|
574
|
+
.${prefix}-btn:disabled{opacity:.4;cursor:default}
|
|
575
|
+
.${prefix}-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}
|
|
576
|
+
@media (max-width:767px){
|
|
577
|
+
.${prefix}-input,.${prefix}-select{font-size:16px;height:40px}
|
|
578
|
+
.${prefix}-checkRow{min-height:44px;padding:8px 0}
|
|
579
|
+
.${prefix}-status{flex-basis:100%;flex:none}
|
|
580
|
+
.${prefix}-btn{min-height:44px;flex:1;min-width:96px}
|
|
581
|
+
}
|
|
582
|
+
@media (pointer:coarse){
|
|
583
|
+
.${prefix}-btn{min-height:44px}
|
|
584
|
+
.${prefix}-checkRow{min-height:44px}
|
|
585
|
+
.${prefix}-input,.${prefix}-select{height:40px}
|
|
586
|
+
}
|
|
587
|
+
${extra}
|
|
588
|
+
`;
|
|
589
|
+
}
|
|
590
|
+
/** 源码编辑节的固定类名前缀。 */
|
|
591
|
+
const CODE_SECTION_PREFIX = "dshc";
|
|
592
|
+
/**
|
|
593
|
+
* 源码编辑节(ConfigCodeSection)专用样式:前缀固定 `dshc`,由 shared 自行注入
|
|
594
|
+
* (插件卡片不必知道它的存在)。基础规则复用 cardCss,只追加 details/摘要与
|
|
595
|
+
* 代码文本域的度量。
|
|
596
|
+
*/
|
|
597
|
+
function codeSectionCss() {
|
|
598
|
+
return cardCss(CODE_SECTION_PREFIX, `
|
|
599
|
+
.${CODE_SECTION_PREFIX}-details{padding:4px 0 0}
|
|
600
|
+
.${CODE_SECTION_PREFIX}-summary{color:var(--dsw-alias-label-primary);cursor:pointer;font-size:13px;font-weight:600;line-height:1.5;list-style:none;padding:8px 0}
|
|
601
|
+
.${CODE_SECTION_PREFIX}-summary::-webkit-details-marker{display:none}
|
|
602
|
+
.${CODE_SECTION_PREFIX}-summary::before{content:"▸";color:var(--dsw-alias-label-tertiary);display:inline-block;margin-right:6px;transition:transform .18s}
|
|
603
|
+
.${CODE_SECTION_PREFIX}-details[open] .${CODE_SECTION_PREFIX}-summary::before{transform:rotate(90deg)}
|
|
604
|
+
.${CODE_SECTION_PREFIX}-desc{color:var(--dsw-alias-label-tertiary);margin:0 0 8px;font-size:12px;line-height:1.5}
|
|
605
|
+
.${CODE_SECTION_PREFIX}-input{box-sizing:border-box;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:12px;height:auto;line-height:1.6;min-height:240px;padding:10px 12px;resize:vertical;tab-size:2;white-space:pre;width:100%}
|
|
606
|
+
.${CODE_SECTION_PREFIX}-foot{align-items:center;gap:8px;display:flex;flex-wrap:wrap;padding-top:12px}
|
|
607
|
+
.${CODE_SECTION_PREFIX}-foot .${CODE_SECTION_PREFIX}-btn:last-child{margin-left:auto}
|
|
608
|
+
@media (max-width:767px){
|
|
609
|
+
.${CODE_SECTION_PREFIX}-input{font-size:16px}
|
|
610
|
+
}
|
|
611
|
+
`);
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* 幂等注入样式标签(官方 data-plugin-css 约定);返回新标签,
|
|
615
|
+
* 已存在或环境无 document 时返回 null(调用方 effect 卸载用)。
|
|
616
|
+
*/
|
|
617
|
+
function injectCardStyle(pluginId, css) {
|
|
618
|
+
if (typeof document === "undefined") return null;
|
|
619
|
+
const tagId = `${pluginId}/card.css`;
|
|
620
|
+
if (document.querySelector(`style[data-plugin-css=${JSON.stringify(tagId)}]`) !== null) return null;
|
|
621
|
+
const tag = document.createElement("style");
|
|
622
|
+
tag.dataset.plugin = pluginId;
|
|
623
|
+
tag.dataset.pluginCss = tagId;
|
|
624
|
+
tag.textContent = css;
|
|
625
|
+
document.head.appendChild(tag);
|
|
626
|
+
return tag;
|
|
627
|
+
}
|
|
628
|
+
//#endregion
|
|
629
|
+
//#region ../shared/src/client/code-section.ts
|
|
630
|
+
/**
|
|
631
|
+
* 配置源码编辑节(自动追加到每张插件配置卡片页)。
|
|
632
|
+
*
|
|
633
|
+
* 形态:无边框分节,与 ConfigShell/Section 的小节度量一致;文档=宿主 `describe` 回传的
|
|
634
|
+
* volatile 投影(JSON,两空格缩进),校验=本地 JSON 语法 + schemastery 模式,
|
|
635
|
+
* 写回=官方 `settings.mutate` 路径 ops(密钥字段不进文档,也不会被写坏)。
|
|
636
|
+
*
|
|
637
|
+
* 本文件刻意不写 JSX:`@dsh-plus/shared` 的 client 纯逻辑测试用 `node --test`
|
|
638
|
+
* 直跑 .ts(Node 原生类型擦除不支持 JSX),而 `config-slots.ts` 会被测试导入,
|
|
639
|
+
* 因此这条导入链上的模块一律用 `createElement`。React 只经默认导入取用
|
|
640
|
+
* (react 是 CJS,Node ESM 下具名导入不保证可解析)。
|
|
641
|
+
* @module @dsh-plus/shared/client/code-section
|
|
642
|
+
*/
|
|
643
|
+
const { createElement: h$1, useEffect: useEffect$3, useMemo: useMemo$2, useState: useState$3, useSyncExternalStore: useSyncExternalStore$2 } = react.default;
|
|
644
|
+
const IDLE = {
|
|
645
|
+
kind: "idle",
|
|
646
|
+
text: ""
|
|
647
|
+
};
|
|
648
|
+
/** 文档播种文本:对象 → 两空格缩进 JSON。 */
|
|
649
|
+
function seedText(value) {
|
|
650
|
+
return value === void 0 ? "{}\n" : `${JSON.stringify(value, null, 2)}\n`;
|
|
651
|
+
}
|
|
652
|
+
/** 解析/校验失败的原因文案(逐条给出行列或字段路径)。 */
|
|
653
|
+
function problemLines(text, snapshot, t) {
|
|
654
|
+
const parsed = parseConfigJson(text);
|
|
655
|
+
if (!parsed.ok) {
|
|
656
|
+
if (parsed.reason === "empty") return {
|
|
657
|
+
problems: [t("codeInvalidEmpty")],
|
|
658
|
+
validated: false
|
|
659
|
+
};
|
|
660
|
+
if (parsed.reason === "root") return {
|
|
661
|
+
problems: [t("codeInvalidRoot")],
|
|
662
|
+
validated: false
|
|
663
|
+
};
|
|
664
|
+
const line = t("codeLine").replace("{line}", String(parsed.line ?? 0)).replace("{column}", String(parsed.column ?? 0));
|
|
665
|
+
return {
|
|
666
|
+
problems: [`${t("codeInvalidJson")}(${line})${parsed.message}`],
|
|
667
|
+
validated: false
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
const result = validateAgainstSchema(snapshot.schema, parsed.value);
|
|
671
|
+
if (result.ok) return {
|
|
672
|
+
problems: [],
|
|
673
|
+
validated: result.validated
|
|
674
|
+
};
|
|
675
|
+
return {
|
|
676
|
+
problems: result.issues.map((issue) => `${t("codeInvalidSchema")}:${issue.path === "" ? issue.message : `${issue.path} — ${issue.message}`}`),
|
|
677
|
+
validated: true
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
/** 与当前快照的差分(无改动时为空数组)。 */
|
|
681
|
+
function opsOf(text, snapshot) {
|
|
682
|
+
const parsed = parseConfigJson(text);
|
|
683
|
+
return parsed.ok ? diffToOps(snapshot.value, parsed.value) : [];
|
|
684
|
+
}
|
|
685
|
+
/** 应用:官方路径 ops 写回,成功后重载快照(revision 变化会重新播种文档)。 */
|
|
686
|
+
function applyOps(options) {
|
|
687
|
+
const { api, scope, ops, revision, t, setStatus, setApplying } = options;
|
|
688
|
+
setApplying(true);
|
|
689
|
+
api.mutate(ops, revision).then(() => {
|
|
690
|
+
setStatus({
|
|
691
|
+
kind: "ok",
|
|
692
|
+
text: t("codeApplied")
|
|
693
|
+
});
|
|
694
|
+
return scope.load();
|
|
695
|
+
}).catch((error) => {
|
|
696
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
697
|
+
setStatus({
|
|
698
|
+
kind: "error",
|
|
699
|
+
text: `${t("codeApplyFailed")}${message}`
|
|
700
|
+
});
|
|
701
|
+
}).finally(() => setApplying(false));
|
|
702
|
+
}
|
|
703
|
+
/** 草稿动作:应用(官方路径 ops 写回)、格式化、编辑与 Tab 缩进。 */
|
|
704
|
+
function draftHandlers(options) {
|
|
705
|
+
const { api, scope, t, snapshot, text, ops, setText, setStatus, setApplying } = options;
|
|
706
|
+
return {
|
|
707
|
+
onApply: () => {
|
|
708
|
+
applyOps({
|
|
709
|
+
api,
|
|
710
|
+
scope,
|
|
711
|
+
ops,
|
|
712
|
+
revision: snapshot.revision,
|
|
713
|
+
t,
|
|
714
|
+
setStatus,
|
|
715
|
+
setApplying
|
|
716
|
+
});
|
|
717
|
+
},
|
|
718
|
+
onFormat: () => {
|
|
719
|
+
const formatted = formatConfigJson(text);
|
|
720
|
+
if (formatted.ok) setText(formatted.text);
|
|
721
|
+
},
|
|
722
|
+
onChange: (event) => {
|
|
723
|
+
setText(event.target.value);
|
|
724
|
+
setStatus(IDLE);
|
|
725
|
+
},
|
|
726
|
+
onKeyDown: (event) => {
|
|
727
|
+
if (event.key !== "Tab") return;
|
|
728
|
+
event.preventDefault();
|
|
729
|
+
const target = event.currentTarget;
|
|
730
|
+
const { selectionStart, selectionEnd, value } = target;
|
|
731
|
+
setText(`${value.slice(0, selectionStart)} ${value.slice(selectionEnd)}`);
|
|
732
|
+
queueMicrotask(() => {
|
|
733
|
+
target.selectionStart = selectionStart + 2;
|
|
734
|
+
target.selectionEnd = selectionStart + 2;
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
/** 校验派生量:逐次编辑重算(problems 供提示与禁用判定,validated 区分「模式外」)。 */
|
|
740
|
+
function useCodeChecks(text, snapshot, t) {
|
|
741
|
+
const { problems, validated } = useMemo$2(() => problemLines(text, snapshot, t), [
|
|
742
|
+
text,
|
|
743
|
+
snapshot,
|
|
744
|
+
t
|
|
745
|
+
]);
|
|
746
|
+
return {
|
|
747
|
+
problems,
|
|
748
|
+
validated,
|
|
749
|
+
ops: useMemo$2(() => opsOf(text, snapshot), [text, snapshot]),
|
|
750
|
+
secrets: useMemo$2(() => secretPathsOf(snapshot.schema), [snapshot.schema]),
|
|
751
|
+
unknown: useMemo$2(() => {
|
|
752
|
+
const parsed = parseConfigJson(text);
|
|
753
|
+
return parsed.ok ? unknownKeysOf(snapshot.schema, parsed.value) : [];
|
|
754
|
+
}, [text, snapshot.schema])
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
/** 分节状态:快照订阅、文档文本、校验结果与草稿动作(主组件只做组装)。 */
|
|
758
|
+
function useCodeSection(props) {
|
|
759
|
+
const { ns, t, scope, api } = props;
|
|
760
|
+
const snapshot = useSyncExternalStore$2((listener) => scope.subscribe(listener), () => scope.getSnapshot());
|
|
761
|
+
const [text, setText] = useState$3(() => seedText(snapshot.value));
|
|
762
|
+
const [status, setStatus] = useState$3(IDLE);
|
|
763
|
+
const [applying, setApplying] = useState$3(false);
|
|
764
|
+
const [open, setOpen] = useState$3(false);
|
|
765
|
+
const revision = snapshot.revision;
|
|
766
|
+
const snapshotStatus = snapshot.status;
|
|
767
|
+
useEffect$3(() => {
|
|
768
|
+
setText(seedText(snapshot.value));
|
|
769
|
+
setStatus(IDLE);
|
|
770
|
+
}, [revision, snapshotStatus]);
|
|
771
|
+
useEffect$3(() => {
|
|
772
|
+
injectCardStyle("@dsh-plus/shared", codeSectionCss());
|
|
773
|
+
}, []);
|
|
774
|
+
const { problems, validated, ops, secrets, unknown } = useCodeChecks(text, snapshot, t);
|
|
775
|
+
const ready = snapshot.status === "ready";
|
|
776
|
+
const disabled = !ready || !snapshot.writable || applying;
|
|
777
|
+
return {
|
|
778
|
+
ready,
|
|
779
|
+
ns,
|
|
780
|
+
t,
|
|
781
|
+
scope,
|
|
782
|
+
snapshot,
|
|
783
|
+
text,
|
|
784
|
+
setText,
|
|
785
|
+
status,
|
|
786
|
+
setStatus,
|
|
787
|
+
applying,
|
|
788
|
+
setApplying,
|
|
789
|
+
open,
|
|
790
|
+
setOpen,
|
|
791
|
+
problems,
|
|
792
|
+
validated,
|
|
793
|
+
ops,
|
|
794
|
+
secrets,
|
|
795
|
+
unknown,
|
|
796
|
+
disabled,
|
|
797
|
+
canApply: !disabled && problems.length === 0 && ops.length > 0,
|
|
798
|
+
...draftHandlers({
|
|
799
|
+
api,
|
|
800
|
+
scope,
|
|
801
|
+
t,
|
|
802
|
+
snapshot,
|
|
803
|
+
text,
|
|
804
|
+
ops,
|
|
805
|
+
setText,
|
|
806
|
+
setStatus,
|
|
807
|
+
setApplying
|
|
808
|
+
})
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
/** 提示行:无改动 / 未校验 / 密钥计数 / 模式外键 / 不可用或只读。 */
|
|
812
|
+
function noteLines(state) {
|
|
813
|
+
const { t, ready, problems, validated, ops, secrets, unknown, snapshot } = state;
|
|
814
|
+
const notes = [];
|
|
815
|
+
if (problems.length === 0 && ops.length === 0 && ready) notes.push(h$1("p", {
|
|
816
|
+
className: "dshc-hint",
|
|
817
|
+
key: "no-change"
|
|
818
|
+
}, t("codeNoChanges")));
|
|
819
|
+
if (problems.length === 0 && !validated) notes.push(h$1("p", {
|
|
820
|
+
className: "dshc-hint",
|
|
821
|
+
key: "unvalidated"
|
|
822
|
+
}, t("codeUnvalidated")));
|
|
823
|
+
if (secrets.length > 0) notes.push(h$1("p", {
|
|
824
|
+
className: "dshc-hint",
|
|
825
|
+
key: "secrets"
|
|
826
|
+
}, t("codeSecretsNote").replace("{n}", String(secrets.length))));
|
|
827
|
+
if (unknown.length > 0) notes.push(h$1("p", {
|
|
828
|
+
className: "dshc-hint",
|
|
829
|
+
key: "unknown"
|
|
830
|
+
}, t("codeUnknownKeys").replace("{n}", String(unknown.length)).replace("{keys}", unknown.slice(0, 8).join("、"))));
|
|
831
|
+
if (snapshot.status === "unavailable") notes.push(h$1("p", {
|
|
832
|
+
className: "dshc-hint",
|
|
833
|
+
key: "unavailable"
|
|
834
|
+
}, t("codeUnavailable")));
|
|
835
|
+
else if (!snapshot.writable) notes.push(h$1("p", {
|
|
836
|
+
className: "dshc-hint",
|
|
837
|
+
key: "readonly"
|
|
838
|
+
}, t("codeReadOnly")));
|
|
839
|
+
return notes;
|
|
840
|
+
}
|
|
841
|
+
/** 页脚:状态行 + 格式化 / 应用按钮。 */
|
|
842
|
+
function codeFooter(state) {
|
|
843
|
+
const { t, status, disabled, canApply, applying, onFormat, onApply } = state;
|
|
844
|
+
return h$1("div", { className: "dshc-foot" }, status.kind === "idle" ? null : h$1("p", {
|
|
845
|
+
className: `dshc-status${status.kind === "error" ? " dshc-statusError" : ""}`,
|
|
846
|
+
role: "status"
|
|
847
|
+
}, status.text), h$1("button", {
|
|
848
|
+
type: "button",
|
|
849
|
+
className: "dshc-btn dshc-btnGhost",
|
|
850
|
+
disabled,
|
|
851
|
+
onClick: onFormat
|
|
852
|
+
}, t("codeFormat")), h$1("button", {
|
|
853
|
+
type: "button",
|
|
854
|
+
className: "dshc-btn dshc-btnPrimary",
|
|
855
|
+
disabled: !canApply,
|
|
856
|
+
onClick: onApply
|
|
857
|
+
}, applying ? t("codeApplying") : t("codeApply")));
|
|
858
|
+
}
|
|
859
|
+
function ConfigCodeSection(props) {
|
|
860
|
+
const state = useCodeSection(props);
|
|
861
|
+
const { ns, t, text, disabled, open, setOpen, status, problems, onChange, onKeyDown } = state;
|
|
862
|
+
return h$1("section", {
|
|
863
|
+
className: "dshc-section",
|
|
864
|
+
"aria-label": `${ns} ${t("codeSectionTitle")}`
|
|
865
|
+
}, h$1("details", {
|
|
866
|
+
className: "dshc-details",
|
|
867
|
+
open: open || status.kind === "error",
|
|
868
|
+
onToggle: (event) => {
|
|
869
|
+
setOpen(event.currentTarget.open);
|
|
870
|
+
}
|
|
871
|
+
}, h$1("summary", { className: "dshc-summary" }, t("codeSectionTitle")), h$1("p", { className: "dshc-desc" }, t("codeSectionDesc")), h$1("textarea", {
|
|
872
|
+
className: `dshc-input${problems.length > 0 ? " dshc-inputInvalid" : ""}`,
|
|
873
|
+
rows: 16,
|
|
874
|
+
spellCheck: false,
|
|
875
|
+
"aria-invalid": problems.length > 0 ? true : void 0,
|
|
876
|
+
value: text,
|
|
877
|
+
disabled,
|
|
878
|
+
onChange,
|
|
879
|
+
onKeyDown
|
|
880
|
+
}), problems.map((problem) => h$1("p", {
|
|
881
|
+
className: "dshc-invalid",
|
|
882
|
+
role: "alert",
|
|
883
|
+
key: problem
|
|
884
|
+
}, problem)), ...noteLines(state), codeFooter(state)));
|
|
885
|
+
}
|
|
886
|
+
//#endregion
|
|
152
887
|
//#region ../shared/src/client/config-slots.ts
|
|
888
|
+
/**
|
|
889
|
+
* 配置卡片的槽位注册助手(目标宿主:dsh 0.2.1-alpha.2)。
|
|
890
|
+
*
|
|
891
|
+
* 官方插件页(`dsh-client-ui-plugin-manager`)为第三方配置视图声明两个 keyed 槽位:
|
|
892
|
+
* - `plugins.row.config`(key = `<bundle 包名>#<row id>`):bundle 详情页对应行出现
|
|
893
|
+
* 「配置」入口,行配置页渲染 `view: 'summary'`(一行简介)与 `view: 'page'`
|
|
894
|
+
* (带保存控件的表单);
|
|
895
|
+
* - `plugins.bundle.config`(key = 包名):包详情页本体配置,仅渲染 `view: 'page'`。
|
|
896
|
+
*
|
|
897
|
+
* 页面自己画标题、图标、面包屑与页面级内边距(`detailSections` 内无边框容器),
|
|
898
|
+
* 故 page 视图输出无边框分节(见 card.tsx),summary 视图只返回一行文本。
|
|
899
|
+
* 旧 `settings.plugin.item` 槽位已随官方插件页迁移删除,不再注册。
|
|
900
|
+
*
|
|
901
|
+
* **源码编辑节自动追加**:注册时把插件组件包一层,page 视图在原卡片之后追加
|
|
902
|
+
* `ConfigCodeSection`(复用同一份 scope/api),summary 视图原样透传。因此「只要
|
|
903
|
+
* 插件存在可配置项」就有源码编辑入口,插件侧零接线;命名空间没有 volatile 字段时
|
|
904
|
+
* 它本身不出现在 describe 视图里,该节自然显示为不可用。
|
|
905
|
+
*
|
|
906
|
+
* @module @dsh-plus/shared/client/config-slots
|
|
907
|
+
*/
|
|
908
|
+
const { createElement: h, Fragment } = react.default;
|
|
153
909
|
/** dsh-plus 聚合 bundle 的包名(各插件 row 均经其补丁层插入 profile)。 */
|
|
154
910
|
const DSH_PLUS_BUNDLE = "@dsh-plus/bundle-main";
|
|
911
|
+
/** page 视图:插件卡片 + 自动追加的源码编辑节(summary 视图原样透传)。 */
|
|
912
|
+
function withCodeSection(component, ns) {
|
|
913
|
+
return function AutoConfigView(props) {
|
|
914
|
+
const card = h(component, props);
|
|
915
|
+
if (props.view !== "page") return card;
|
|
916
|
+
return h(Fragment, null, card, h(ConfigCodeSection, {
|
|
917
|
+
ns,
|
|
918
|
+
t: props.t,
|
|
919
|
+
scope: props.scope,
|
|
920
|
+
api: props.api
|
|
921
|
+
}));
|
|
922
|
+
};
|
|
923
|
+
}
|
|
155
924
|
/**
|
|
156
925
|
* 把一张配置卡片注册进插件页的两个配置槽位。
|
|
157
926
|
* 两个槽位都由 0.2.1-alpha.2 的插件页声明,任一缺席即报错——不做版本探测。
|
|
158
927
|
*/
|
|
159
928
|
function injectPluginConfigCard(slots, reg) {
|
|
929
|
+
const component = withCodeSection(reg.component, reg.ns);
|
|
160
930
|
const base = {
|
|
161
931
|
locale: reg.ns,
|
|
162
932
|
inject: reg.inject
|
|
@@ -165,14 +935,26 @@ window.__ModuleLoader__.load({
|
|
|
165
935
|
name: "plugins.row.config",
|
|
166
936
|
key: `${DSH_PLUS_BUNDLE}#${reg.rowId}`,
|
|
167
937
|
...base
|
|
168
|
-
},
|
|
938
|
+
}, component));
|
|
169
939
|
slots.inject("plugins.bundle.config", () => slots.register({
|
|
170
940
|
name: "plugins.bundle.config",
|
|
171
941
|
key: reg.pkg,
|
|
172
942
|
...base
|
|
173
|
-
},
|
|
943
|
+
}, component));
|
|
174
944
|
}
|
|
175
945
|
//#endregion
|
|
946
|
+
//#region ../shared/src/client/credentials.tsx
|
|
947
|
+
/**
|
|
948
|
+
* 凭据面(共享件):官方 settings-controller 的 `remote.credentials` 命名空间
|
|
949
|
+
* (describe/set/unset/onChange),复用官方 credentials seam,不另开 HTTP 端点。
|
|
950
|
+
* **值只写不读**——describe 只回「已配置 / 来源 / 可写」,没有任何方法回传值。
|
|
951
|
+
*
|
|
952
|
+
* 凭据与 settings 草稿相互独立:不进命名空间、不参与脏判定,保存即落
|
|
953
|
+
* `$DSH_HOME/.credentials.yaml` 并热生效(宿主每次工具调用重新 resolve),
|
|
954
|
+
* 因此改口令不需要保存卡片、也不需要 /reload 或重启。
|
|
955
|
+
* @module @dsh-plus/shared/client/credentials
|
|
956
|
+
*/
|
|
957
|
+
//#endregion
|
|
176
958
|
//#region ../shared/src/client/draft.ts
|
|
177
959
|
/**
|
|
178
960
|
* 单命名空间 staged 草稿(简单配置卡片共用):读 scope 快照、播种草稿、
|
|
@@ -201,7 +983,31 @@ window.__ModuleLoader__.load({
|
|
|
201
983
|
enabledOff: "未启用",
|
|
202
984
|
saveFailed: "保存失败,请检查填写内容。",
|
|
203
985
|
confirm: "确认",
|
|
204
|
-
cancel: "取消"
|
|
986
|
+
cancel: "取消",
|
|
987
|
+
listAdd: "新增",
|
|
988
|
+
listRemove: "删除",
|
|
989
|
+
listMoveUp: "上移",
|
|
990
|
+
listMoveDown: "下移",
|
|
991
|
+
listDuplicate: "复制",
|
|
992
|
+
listEmpty: "暂无条目。",
|
|
993
|
+
codeSectionTitle: "源码编辑(JSON)",
|
|
994
|
+
codeSectionDesc: "直接编辑本插件的可配置字段(仅 .volatile() 字段)。「应用」按官方路径编辑写回用户层,密钥字段不在此编辑器内。",
|
|
995
|
+
codeFormat: "格式化",
|
|
996
|
+
codeApply: "应用",
|
|
997
|
+
codeApplying: "应用中…",
|
|
998
|
+
codeApplied: "已应用。",
|
|
999
|
+
codeNoChanges: "与当前配置一致,无需应用。",
|
|
1000
|
+
codeInvalidJson: "JSON 语法错误",
|
|
1001
|
+
codeInvalidEmpty: "配置不能为空。",
|
|
1002
|
+
codeInvalidRoot: "根节点必须是对象。",
|
|
1003
|
+
codeInvalidSchema: "模式校验未通过",
|
|
1004
|
+
codeUnvalidated: "宿主未回传 schema,已跳过本地校验(写入仍由宿主把关)。",
|
|
1005
|
+
codeSecretsNote: "有 {n} 个密钥字段不在此编辑器内(在凭据区或行级配置中管理)。",
|
|
1006
|
+
codeUnknownKeys: "有 {n} 个键不在 schema 里({keys}):会被原样保留并被运行时忽略,建议删除。",
|
|
1007
|
+
codeUnavailable: "该行未激活或命名空间不可用,源码编辑不可用。",
|
|
1008
|
+
codeReadOnly: "当前部署无 settings provider,源码编辑只读。",
|
|
1009
|
+
codeApplyFailed: "应用失败:",
|
|
1010
|
+
codeLine: "第 {line} 行第 {column} 列"
|
|
205
1011
|
};
|
|
206
1012
|
const commonEn = {
|
|
207
1013
|
save: "Save",
|
|
@@ -218,7 +1024,31 @@ window.__ModuleLoader__.load({
|
|
|
218
1024
|
enabledOff: "Off",
|
|
219
1025
|
saveFailed: "Save failed; check the fields.",
|
|
220
1026
|
confirm: "Confirm",
|
|
221
|
-
cancel: "Cancel"
|
|
1027
|
+
cancel: "Cancel",
|
|
1028
|
+
listAdd: "Add",
|
|
1029
|
+
listRemove: "Remove",
|
|
1030
|
+
listMoveUp: "Move up",
|
|
1031
|
+
listMoveDown: "Move down",
|
|
1032
|
+
listDuplicate: "Duplicate",
|
|
1033
|
+
listEmpty: "No entries yet.",
|
|
1034
|
+
codeSectionTitle: "Source editor (JSON)",
|
|
1035
|
+
codeSectionDesc: "Edit this plugin’s configurable fields directly (only .volatile() fields). Apply writes back through the official path edits; secret fields never appear here.",
|
|
1036
|
+
codeFormat: "Format",
|
|
1037
|
+
codeApply: "Apply",
|
|
1038
|
+
codeApplying: "Applying…",
|
|
1039
|
+
codeApplied: "Applied.",
|
|
1040
|
+
codeNoChanges: "Identical to the current config; nothing to apply.",
|
|
1041
|
+
codeInvalidJson: "JSON syntax error",
|
|
1042
|
+
codeInvalidEmpty: "Config must not be empty.",
|
|
1043
|
+
codeInvalidRoot: "The root node must be an object.",
|
|
1044
|
+
codeInvalidSchema: "Schema validation failed",
|
|
1045
|
+
codeUnvalidated: "The host returned no schema, so local validation was skipped (writes are still validated by the host).",
|
|
1046
|
+
codeSecretsNote: "{n} secret field(s) are not editable here (manage them in the credentials section or at the row level).",
|
|
1047
|
+
codeUnknownKeys: "{n} key(s) are absent from the schema ({keys}): they are preserved verbatim and ignored at runtime; remove them.",
|
|
1048
|
+
codeUnavailable: "This row is inactive or its namespace is unavailable; the source editor is disabled.",
|
|
1049
|
+
codeReadOnly: "No settings provider in this deployment; the source editor is read-only.",
|
|
1050
|
+
codeApplyFailed: "Apply failed: ",
|
|
1051
|
+
codeLine: "line {line}, column {column}"
|
|
222
1052
|
};
|
|
223
1053
|
/**
|
|
224
1054
|
* own 覆盖同键合并(返回新对象,入参不可变)。
|
|
@@ -245,6 +1075,8 @@ window.__ModuleLoader__.load({
|
|
|
245
1075
|
let state = {
|
|
246
1076
|
status: "loading",
|
|
247
1077
|
value: void 0,
|
|
1078
|
+
schema: void 0,
|
|
1079
|
+
secrets: [],
|
|
248
1080
|
revision: void 0,
|
|
249
1081
|
writable: false
|
|
250
1082
|
};
|
|
@@ -270,6 +1102,8 @@ window.__ModuleLoader__.load({
|
|
|
270
1102
|
publish({
|
|
271
1103
|
status: "unavailable",
|
|
272
1104
|
value: void 0,
|
|
1105
|
+
schema: void 0,
|
|
1106
|
+
secrets: [],
|
|
273
1107
|
revision: void 0,
|
|
274
1108
|
writable: view.writable
|
|
275
1109
|
});
|
|
@@ -278,6 +1112,8 @@ window.__ModuleLoader__.load({
|
|
|
278
1112
|
publish({
|
|
279
1113
|
status: "ready",
|
|
280
1114
|
value: namespace.value,
|
|
1115
|
+
schema: namespace.schema,
|
|
1116
|
+
secrets: namespace.secrets,
|
|
281
1117
|
revision: namespace.revision,
|
|
282
1118
|
writable: view.writable
|
|
283
1119
|
});
|
|
@@ -311,6 +1147,10 @@ window.__ModuleLoader__.load({
|
|
|
311
1147
|
const response = await remote.update(ns, patch, expectedRevision);
|
|
312
1148
|
if (!response.ok) throw new Error(response.error.message ?? "settings update failed");
|
|
313
1149
|
},
|
|
1150
|
+
mutate: async (ops, expectedRevision) => {
|
|
1151
|
+
const response = await remote.mutate(ns, ops, expectedRevision);
|
|
1152
|
+
if (!response.ok) throw new Error(response.error.message ?? "settings mutate failed");
|
|
1153
|
+
},
|
|
314
1154
|
describe: async () => {
|
|
315
1155
|
const response = await remote.describe();
|
|
316
1156
|
if (!response.ok) throw new Error(response.error.message ?? "settings describe failed");
|
|
@@ -319,101 +1159,6 @@ window.__ModuleLoader__.load({
|
|
|
319
1159
|
};
|
|
320
1160
|
}
|
|
321
1161
|
//#endregion
|
|
322
|
-
//#region ../shared/src/client/styles.ts
|
|
323
|
-
/**
|
|
324
|
-
* 配置分节样式工厂(各插件 client 的公共收编版)。
|
|
325
|
-
*
|
|
326
|
-
* 目标宿主 dsh 0.2.1-alpha.2:插件页把配置视图放进已有页面级内边距的容器里
|
|
327
|
-
* (`div.detailSections[data-plugin-config]` 或 `section.detailSection[data-plugin-config]`),
|
|
328
|
-
* 外层无边框——故这里输出的是**无边框分节**(小节标题 13px/600、字段 12px 0、
|
|
329
|
-
* 横向零内边距、页脚非 sticky),度量对齐官方设置页
|
|
330
|
-
* (`@deepseek-ai/dsh-client-ui-primitives` 的 settings-form)。
|
|
331
|
-
*
|
|
332
|
-
* 移动端与可达性(767px 断点 + pointer:coarse,对齐 ui-mobile-fit 约定):
|
|
333
|
-
* - 窄屏 input/textarea 16px(防 iOS 聚焦缩放)、可点目标 ≥44px;
|
|
334
|
-
* - 页脚按钮等宽换行、状态文字独占一行。
|
|
335
|
-
* 沿用官方 data-plugin / data-plugin-css 约定(HMR 据此卸载),不覆盖上游选择器。
|
|
336
|
-
* @module @dsh-plus/shared/client/styles
|
|
337
|
-
*/
|
|
338
|
-
/** 生成全套分节 CSS;prefix 为插件类名前缀(如 'dne'),extra 为插件特有规则。 */
|
|
339
|
-
function cardCss(prefix, extra = "") {
|
|
340
|
-
return `
|
|
341
|
-
.${prefix}-section{box-sizing:border-box;flex-direction:column;width:100%;min-width:0;padding:16px 0;display:flex}
|
|
342
|
-
.${prefix}-sectionHead{align-items:center;gap:8px;min-width:0;display:flex}
|
|
343
|
-
.${prefix}-sectionTitle{min-width:0;color:var(--dsw-alias-label-primary);flex:1;margin:0;font-size:13px;font-weight:600;line-height:1.5}
|
|
344
|
-
.${prefix}-sectionBadge{white-space:nowrap;border-radius:999px;flex:none;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
|
|
345
|
-
.${prefix}-sectionDesc{color:var(--dsw-alias-label-tertiary);margin:4px 0 0;font-size:12px;line-height:1.5}
|
|
346
|
-
.${prefix}-sectionBody{flex-direction:column;min-width:0;display:flex}
|
|
347
|
-
.${prefix}-sectionFooter{align-items:center;gap:8px;padding-top:16px;display:flex;flex-wrap:wrap}
|
|
348
|
-
.${prefix}-pending{white-space:nowrap;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);border-radius:999px;flex:none;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
|
|
349
|
-
.${prefix}-statusOn{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary)}
|
|
350
|
-
.${prefix}-statusOff{color:var(--dsw-alias-label-tertiary)}
|
|
351
|
-
.${prefix}-field{flex-direction:column;gap:6px;padding:12px 0;display:flex}
|
|
352
|
-
.${prefix}-field+.${prefix}-field{border-top:1px solid var(--dsw-alias-border-l2)}
|
|
353
|
-
.${prefix}-head{align-items:center;gap:8px;display:flex}
|
|
354
|
-
.${prefix}-label{min-width:0;color:var(--dsw-alias-label-primary);flex:1;font-size:13px;font-weight:500;line-height:1.5}
|
|
355
|
-
.${prefix}-badge{white-space:nowrap;border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
|
|
356
|
-
.${prefix}-badgeSet{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary)}
|
|
357
|
-
.${prefix}-badgeUnset{color:var(--dsw-alias-label-tertiary)}
|
|
358
|
-
.${prefix}-input{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);height:34px;font:inherit;color:var(--dsw-alias-label-primary);border-radius:8px;padding:0 12px;font-size:13px;transition:border-color .18s,background .18s}
|
|
359
|
-
.${prefix}-input:hover:not(:disabled):not(:focus-visible){border-color:var(--dsw-alias-label-dimmed)}
|
|
360
|
-
.${prefix}-input:focus-visible{border-color:var(--dsw-alias-brand-primary);outline:none}
|
|
361
|
-
.${prefix}-input:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}
|
|
362
|
-
.${prefix}-inputInvalid{border-color:var(--dsw-alias-label-error)}
|
|
363
|
-
.${prefix}-select{appearance:none;background:var(--dsw-alias-bg-module-platform);border:none;cursor:pointer;background-image:linear-gradient(45deg,transparent 50%,var(--dsw-alias-label-secondary) 50%),linear-gradient(135deg,var(--dsw-alias-label-secondary) 50%,transparent 50%);background-position:calc(100% - 16px) 50%,calc(100% - 11px) 50%;background-size:5px 5px;background-repeat:no-repeat;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;height:34px;box-sizing:border-box;border-radius:8px;padding:0 30px 0 12px;transition:background-color .18s}
|
|
364
|
-
.${prefix}-select:hover:not(:disabled){background-color:var(--dsw-alias-interactive-bg-hover)}
|
|
365
|
-
.${prefix}-hint{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5}
|
|
366
|
-
.${prefix}-invalid{color:var(--dsw-alias-label-error);margin:0;font-size:12px;line-height:1.5}
|
|
367
|
-
.${prefix}-checkRow{align-items:center;gap:10px;display:flex;padding:6px 0}
|
|
368
|
-
.${prefix}-checkRow label{color:var(--dsw-alias-label-primary);font-size:13px;line-height:1.5;cursor:pointer;flex:1;min-width:0}
|
|
369
|
-
/* 自绘圆角扁平开关(官方 UI 无可见原生 checkbox,选择类全走胶囊/菜单) */
|
|
370
|
-
.${prefix}-checkRow input{appearance:none;-webkit-appearance:none;position:relative;box-sizing:border-box;background:var(--dsw-alias-bg-module-platform);border:none;border-radius:999px;width:34px;height:20px;flex:none;cursor:pointer;transition:background .18s;margin:0}
|
|
371
|
-
.${prefix}-checkRow input::after{content:"";position:absolute;top:2px;left:2px;background:var(--dsw-alias-label-primary);border-radius:999px;width:16px;height:16px;transition:left .18s cubic-bezier(.4,0,.2,1)}
|
|
372
|
-
.${prefix}-checkRow input:checked{background:var(--dsw-alias-brand-primary)}
|
|
373
|
-
.${prefix}-checkRow input:checked::after{left:16px;background:var(--dsw-alias-bg-base)}
|
|
374
|
-
.${prefix}-checkRow input:disabled{opacity:.4;cursor:default}
|
|
375
|
-
.${prefix}-checkRow input:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px}
|
|
376
|
-
.${prefix}-groupLabel{color:var(--dsw-alias-label-secondary);font-size:12px;font-weight:600;padding:12px 0 2px;margin:0}
|
|
377
|
-
.${prefix}-readOnly{color:var(--dsw-alias-label-tertiary);margin:12px 0 0;font-size:12px;line-height:1.5}
|
|
378
|
-
.${prefix}-warn{color:var(--dsw-alias-label-error);margin:12px 0 0;font-size:12px;line-height:1.5}
|
|
379
|
-
.${prefix}-status{min-width:0;color:var(--dsw-alias-label-secondary);flex:1;margin:0;font-size:12px;line-height:1.5}
|
|
380
|
-
.${prefix}-statusError{color:var(--dsw-alias-label-error)}
|
|
381
|
-
.${prefix}-btn{appearance:none;font:inherit;cursor:pointer;border:1px solid #0000;border-radius:8px;padding:5px 14px;font-size:13px;line-height:1.5}
|
|
382
|
-
.${prefix}-btnGhost{border-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);background:0 0}
|
|
383
|
-
.${prefix}-btnGhost:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-dimmed)}
|
|
384
|
-
.${prefix}-btnPrimary{background:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}
|
|
385
|
-
.${prefix}-btn:disabled{opacity:.4;cursor:default}
|
|
386
|
-
.${prefix}-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}
|
|
387
|
-
@media (max-width:767px){
|
|
388
|
-
.${prefix}-input,.${prefix}-select{font-size:16px;height:40px}
|
|
389
|
-
.${prefix}-checkRow{min-height:44px;padding:8px 0}
|
|
390
|
-
.${prefix}-status{flex-basis:100%;flex:none}
|
|
391
|
-
.${prefix}-btn{min-height:44px;flex:1;min-width:96px}
|
|
392
|
-
}
|
|
393
|
-
@media (pointer:coarse){
|
|
394
|
-
.${prefix}-btn{min-height:44px}
|
|
395
|
-
.${prefix}-checkRow{min-height:44px}
|
|
396
|
-
.${prefix}-input,.${prefix}-select{height:40px}
|
|
397
|
-
}
|
|
398
|
-
${extra}
|
|
399
|
-
`;
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* 幂等注入样式标签(官方 data-plugin-css 约定);返回新标签,
|
|
403
|
-
* 已存在或环境无 document 时返回 null(调用方 effect 卸载用)。
|
|
404
|
-
*/
|
|
405
|
-
function injectCardStyle(pluginId, css) {
|
|
406
|
-
if (typeof document === "undefined") return null;
|
|
407
|
-
const tagId = `${pluginId}/card.css`;
|
|
408
|
-
if (document.querySelector(`style[data-plugin-css=${JSON.stringify(tagId)}]`) !== null) return null;
|
|
409
|
-
const tag = document.createElement("style");
|
|
410
|
-
tag.dataset.plugin = pluginId;
|
|
411
|
-
tag.dataset.pluginCss = tagId;
|
|
412
|
-
tag.textContent = css;
|
|
413
|
-
document.head.appendChild(tag);
|
|
414
|
-
return tag;
|
|
415
|
-
}
|
|
416
|
-
//#endregion
|
|
417
1162
|
//#region src/ns.ts
|
|
418
1163
|
/**
|
|
419
1164
|
* settings 命名空间字面量(纯常量,零依赖)。
|
|
@@ -454,10 +1199,7 @@ ${extra}
|
|
|
454
1199
|
reasoningEffort: entry.reasoningEffort
|
|
455
1200
|
};
|
|
456
1201
|
}
|
|
457
|
-
return {
|
|
458
|
-
enabled: value.enabled,
|
|
459
|
-
rows
|
|
460
|
-
};
|
|
1202
|
+
return { rows };
|
|
461
1203
|
}
|
|
462
1204
|
function toPatch(draft) {
|
|
463
1205
|
const entries = {};
|
|
@@ -466,17 +1208,14 @@ ${extra}
|
|
|
466
1208
|
if (row === void 0) continue;
|
|
467
1209
|
entries[name] = row;
|
|
468
1210
|
}
|
|
469
|
-
return {
|
|
470
|
-
enabled: draft.enabled,
|
|
471
|
-
entries
|
|
472
|
-
};
|
|
1211
|
+
return { entries };
|
|
473
1212
|
}
|
|
474
1213
|
//#endregion
|
|
475
1214
|
//#region src/client/card.tsx
|
|
476
1215
|
/**
|
|
477
1216
|
* 「子代理模型配置」配置卡片:经 injectPluginConfigCard 注册(插件页 plugins.row.config /
|
|
478
1217
|
* plugins.bundle.config,view 分发 summary/page)。
|
|
479
|
-
* 外壳与基础控件走 @dsh-plus/shared/client 套件(
|
|
1218
|
+
* 外壳与基础控件走 @dsh-plus/shared/client 套件(ConfigShell/CheckRow/SelectField)。
|
|
480
1219
|
* 配置读写经共享层 ctx.remote.settings 直连(settingsScope 已由 configForms
|
|
481
1220
|
* 取代):value 为 schema 解析后的命名空间值
|
|
482
1221
|
* (enabled + entries),行集合 = 目录返回的已注册子代理 provider
|
|
@@ -710,13 +1449,6 @@ ${extra}
|
|
|
710
1449
|
prefix: "dsm",
|
|
711
1450
|
text: t("loading")
|
|
712
1451
|
});
|
|
713
|
-
const edit = (key, editValue) => {
|
|
714
|
-
setDraft({
|
|
715
|
-
...draft,
|
|
716
|
-
[key]: editValue
|
|
717
|
-
});
|
|
718
|
-
setStatus(IDLE_STATUS);
|
|
719
|
-
};
|
|
720
1452
|
const editRow = (name, row) => {
|
|
721
1453
|
setDraft({
|
|
722
1454
|
...draft,
|
|
@@ -745,14 +1477,10 @@ ${extra}
|
|
|
745
1477
|
const disabled = !snapshot.writable;
|
|
746
1478
|
const rowNames = Object.keys(draft.rows).sort();
|
|
747
1479
|
const providerCount = (catalog?.providers ?? []).length;
|
|
748
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(
|
|
1480
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ConfigShell, {
|
|
749
1481
|
prefix: "dsm",
|
|
750
1482
|
title: t("title"),
|
|
751
1483
|
description: t("description"),
|
|
752
|
-
statusBadge: {
|
|
753
|
-
text: t(draft.enabled ? "enabledOn" : "enabledOff"),
|
|
754
|
-
on: draft.enabled
|
|
755
|
-
},
|
|
756
1484
|
dirty,
|
|
757
1485
|
dirtyLabel: t("unsaved"),
|
|
758
1486
|
readOnlyNotice: disabled ? t("readOnly") : void 0,
|
|
@@ -770,14 +1498,6 @@ ${extra}
|
|
|
770
1498
|
onSave
|
|
771
1499
|
}),
|
|
772
1500
|
children: [
|
|
773
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CheckRow, {
|
|
774
|
-
prefix: "dsm",
|
|
775
|
-
id: "dsm-enabled",
|
|
776
|
-
label: t("enabled"),
|
|
777
|
-
checked: draft.enabled,
|
|
778
|
-
disabled,
|
|
779
|
-
onEdit: (v) => edit("enabled", v)
|
|
780
|
-
}),
|
|
781
1501
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CatalogStatus, {
|
|
782
1502
|
t,
|
|
783
1503
|
catalog,
|
|
@@ -812,7 +1532,6 @@ ${extra}
|
|
|
812
1532
|
title: "子代理模型配置",
|
|
813
1533
|
description: "为 subagent / subagent_fork 等子代理单独指定提供商、模型与思考程度,或继承主代理。",
|
|
814
1534
|
summaryLine: "为子代理单独指定提供商、模型与思考程度,或继承主代理。",
|
|
815
|
-
enabled: "启用插件",
|
|
816
1535
|
rowEnabled: "启用该行",
|
|
817
1536
|
provider: "提供商",
|
|
818
1537
|
model: "模型",
|
|
@@ -837,7 +1556,6 @@ ${extra}
|
|
|
837
1556
|
title: "Subagent model config",
|
|
838
1557
|
description: "Pick a provider, model, and thinking effort for subagent / subagent_fork children, or inherit from the main agent.",
|
|
839
1558
|
summaryLine: "Pick a provider, model, and thinking effort for subagent children, or inherit.",
|
|
840
|
-
enabled: "Enable plugin",
|
|
841
1559
|
rowEnabled: "Enable row",
|
|
842
1560
|
provider: "Provider",
|
|
843
1561
|
model: "Model",
|