dsh-aperture 0.1.0 → 0.2.0
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/LICENSE +21 -21
- package/README.en.md +155 -207
- package/README.md +156 -195
- package/client/aperture.js +1522 -0
- package/cordis.patch.yml +3 -2
- package/lib/index.d.ts +11 -2
- package/lib/index.js +18 -5
- package/lib/panel.d.ts +113 -0
- package/lib/panel.js +271 -0
- package/lib/registry.d.ts +1 -5
- package/lib/registry.js +0 -14
- package/lib/remote.d.ts +79 -0
- package/lib/remote.js +120 -0
- package/lib/report.d.ts +111 -9
- package/lib/report.js +107 -79
- package/lib/runtime.d.ts +4 -9
- package/lib/runtime.js +6 -23
- package/lib/types.d.ts +1 -1
- package/package.json +20 -9
- package/lib/command.d.ts +0 -21
- package/lib/command.js +0 -58
|
@@ -0,0 +1,1522 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dsh-aperture` 浏览器半边:**设置 → 插件 → Aperture** 标签页。
|
|
3
|
+
*
|
|
4
|
+
* 扩展点与接线方式对齐参考实现 `@xiaoyuyu6420/dsh-backup`(`backupPanel` + 插件标签页):
|
|
5
|
+
*
|
|
6
|
+
* - 用 `settings.plugins.tab` 注册一个**列表槽位**标签页,而不是往「插件配置」里塞卡片;
|
|
7
|
+
* - 注入面只有 `slots` / `locale` / `remote` 三个服务,**不注入设置传输**——配置读写与
|
|
8
|
+
* 发现结果一样,都经自己的 `aperturePanel` Remote 命名空间往返,标签页因此不关心设置
|
|
9
|
+
* 文档长什么样;
|
|
10
|
+
* - 标签页只拿两个 prop:`panel`(端点集合)与 `t`(字典,因为注册时声明了 `locale`)。
|
|
11
|
+
*
|
|
12
|
+
* **这个文件就是构建产物。** DSH 的客户端模块系统只要求一个经典脚本,用
|
|
13
|
+
* `window.__ModuleLoader__.load({ id, factory })` 的握手把自己报上去;它不要求这份脚本
|
|
14
|
+
* 经过打包器,也不检查它是否被压缩过。因此这里直接写 CJS 工厂体,用 `createElement`
|
|
15
|
+
* 而不是 JSX:仓库不必为此引入打包器,也不必把一个编译产物提交进版本库。
|
|
16
|
+
*
|
|
17
|
+
* 运行时只 `require('react')`(DSH 平台基线模块),不需要 `dsh.client.external`。
|
|
18
|
+
*
|
|
19
|
+
* @module dsh-aperture/client
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
window.__ModuleLoader__.load({
|
|
23
|
+
id: 'dsh-aperture',
|
|
24
|
+
factory: (require) => {
|
|
25
|
+
const React = require('react');
|
|
26
|
+
const h = React.createElement;
|
|
27
|
+
|
|
28
|
+
/** 字典命名空间(本插件拥有)。标签页的 `locale` 声明与 `ctx.locale.bind` 都用它。 */
|
|
29
|
+
const NS = 'settings.aperturePanel';
|
|
30
|
+
/** 宿主半边的 Remote 命名空间(`src/remote.ts`)。 */
|
|
31
|
+
const PANEL = 'aperturePanel';
|
|
32
|
+
/** 包名,取自 package.json,同时是端点 id 的前缀。 */
|
|
33
|
+
const PACKAGE = 'dsh-aperture';
|
|
34
|
+
/** 样式表归属标记;卸载与热替换时按它回收。 */
|
|
35
|
+
const STYLE_MARK = 'data-dsh-aperture';
|
|
36
|
+
|
|
37
|
+
// ---------------------------------------------------------------- 端点契约
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 一个 strict 结果编解码器。
|
|
41
|
+
*
|
|
42
|
+
* 浏览器半边挂载贡献时强制要求每个参数与结果的编解码器都是 `strict`、带非空类型符号
|
|
43
|
+
* 与可用的 `parse`。生成器会塞进 zod schema;本插件的形状很小,手写校验就够了——手写
|
|
44
|
+
* 反而能在宿主与界面漂移时报出具体字段名(`…status.models[3].contextWindow:期望 number`)。
|
|
45
|
+
*
|
|
46
|
+
* 字段类型是一行小文法:
|
|
47
|
+
* - `'string'` / `'number'` / `'boolean'`:基本类型;
|
|
48
|
+
* - 末尾 `?`:可省略(宿主没给这个字段);
|
|
49
|
+
* - 末尾 `|null`:允许 `null`(参数里表示「撤销这一条覆盖」);
|
|
50
|
+
* - 末尾 `[]`:数组;
|
|
51
|
+
* - 直接给另一个 codec:嵌套对象;`opt(...)` 表示它可省略;`list(...)` 表示对象数组。
|
|
52
|
+
*
|
|
53
|
+
* @param {string} typeSymbol - 类型符号,注册表要求非空。
|
|
54
|
+
* @param {Record<string, string|object>} fields - 字段与类型。
|
|
55
|
+
* @returns {object} 编解码器。
|
|
56
|
+
*/
|
|
57
|
+
function codec(typeSymbol, fields) {
|
|
58
|
+
return Object.freeze({
|
|
59
|
+
mode: 'strict',
|
|
60
|
+
typeSymbol,
|
|
61
|
+
schema: {
|
|
62
|
+
parse(value, at) {
|
|
63
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
64
|
+
throw new TypeError(`${at ?? typeSymbol}:期望一个对象`);
|
|
65
|
+
}
|
|
66
|
+
const parsed = {};
|
|
67
|
+
for (const [name, kind] of Object.entries(fields)) {
|
|
68
|
+
// 嵌套时报错带完整路径(`…status.models[0].contextWindow`);顶层就是类型符号。
|
|
69
|
+
const path = at === undefined ? `${typeSymbol}.${name}` : `${at}.${name}`;
|
|
70
|
+
const field = value[name];
|
|
71
|
+
if (field === undefined) {
|
|
72
|
+
if (isOptional(kind)) continue;
|
|
73
|
+
throw new TypeError(`${path}:缺字段`);
|
|
74
|
+
}
|
|
75
|
+
parsed[name] = parseKind(path, kind, field);
|
|
76
|
+
}
|
|
77
|
+
return parsed;
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** 一个字段是否可省略。 */
|
|
84
|
+
function isOptional(kind) {
|
|
85
|
+
return typeof kind === 'string' ? kind.endsWith('?') : kind.optional === true;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** 可省略的嵌套对象字段。 */
|
|
89
|
+
function opt(inner) {
|
|
90
|
+
return Object.freeze({ codec: inner, optional: true });
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** 由另一个 codec 描述的对象数组字段。 */
|
|
94
|
+
function list(inner) {
|
|
95
|
+
return Object.freeze({ list: inner });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** 允许 `null` 的嵌套字段(`null` 与「缺字段」是两件事,因此不能靠 `?`)。 */
|
|
99
|
+
function nullable(inner) {
|
|
100
|
+
return Object.freeze({ nullable: inner });
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 按类型说明校验一个值。
|
|
105
|
+
*
|
|
106
|
+
* @param {string} path - 出错信息里的字段路径。
|
|
107
|
+
* @param {string|object} kind - 类型说明。
|
|
108
|
+
* @param {*} value - 待校验的值。
|
|
109
|
+
* @returns {*} 校验过的值。
|
|
110
|
+
*/
|
|
111
|
+
function parseKind(path, kind, value) {
|
|
112
|
+
if (typeof kind === 'object' && kind !== null) {
|
|
113
|
+
if (kind.list !== undefined) {
|
|
114
|
+
if (!Array.isArray(value)) throw new TypeError(`${path}:期望数组`);
|
|
115
|
+
return value.map((item, index) => parseKind(`${path}[${index}]`, kind.list, item));
|
|
116
|
+
}
|
|
117
|
+
if (kind.codec !== undefined) return kind.codec.schema.parse(value, path);
|
|
118
|
+
if (kind.nullable !== undefined) {
|
|
119
|
+
return value === null ? null : parseKind(path, kind.nullable, value);
|
|
120
|
+
}
|
|
121
|
+
// 直接给了另一个 codec,就是「这里是它描述的那个嵌套对象」。
|
|
122
|
+
if (typeof kind.schema?.parse === 'function') return kind.schema.parse(value, path);
|
|
123
|
+
throw new TypeError(`${path}:类型说明写错了`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
let spec = kind;
|
|
127
|
+
if (spec.endsWith('?')) spec = spec.slice(0, -1);
|
|
128
|
+
const nullable = spec.endsWith('|null');
|
|
129
|
+
if (nullable) spec = spec.slice(0, -'|null'.length);
|
|
130
|
+
const items = spec.endsWith('[]');
|
|
131
|
+
const type = items ? spec.slice(0, -2) : spec;
|
|
132
|
+
|
|
133
|
+
if (value === null) {
|
|
134
|
+
if (nullable) return null;
|
|
135
|
+
throw new TypeError(`${path}:期望 ${type},收到 null`);
|
|
136
|
+
}
|
|
137
|
+
if (items) {
|
|
138
|
+
if (!Array.isArray(value)) throw new TypeError(`${path}:期望数组`);
|
|
139
|
+
return value.map((item, index) => {
|
|
140
|
+
if (typeof item !== type) {
|
|
141
|
+
throw new TypeError(`${path}[${index}]:期望 ${type},收到 ${typeof item}`);
|
|
142
|
+
}
|
|
143
|
+
return item;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
if (typeof value !== type) throw new TypeError(`${path}:期望 ${type},收到 ${typeof value}`);
|
|
147
|
+
return value;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** 一个参数编解码器。
|
|
151
|
+
*
|
|
152
|
+
* `acceptsUndefined` 与「可省略」是一回事:`save` 的调用方常常只想改其中一个字段,
|
|
153
|
+
* 没提到的那个必须原样传过去。
|
|
154
|
+
*
|
|
155
|
+
* @param {string} typeSymbol - 类型符号。
|
|
156
|
+
* @param {'string' | 'boolean'} type - 允许的类型;`string` 另外允许 `null`(撤销覆盖)。
|
|
157
|
+
* @returns {object} 参数编解码器。
|
|
158
|
+
*/
|
|
159
|
+
function optionalParam(typeSymbol, type) {
|
|
160
|
+
return Object.freeze({
|
|
161
|
+
mode: 'strict',
|
|
162
|
+
typeSymbol,
|
|
163
|
+
acceptsUndefined: true,
|
|
164
|
+
schema: {
|
|
165
|
+
parse(value) {
|
|
166
|
+
if (value === undefined) return undefined;
|
|
167
|
+
if (type === 'string' && value === null) return null;
|
|
168
|
+
if (typeof value !== type) throw new TypeError(`${typeSymbol}:期望 ${type},收到 ${typeof value}`);
|
|
169
|
+
return value;
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* 一个参数编解码器。
|
|
177
|
+
*
|
|
178
|
+
* 类型说明用与字段同一套文法(数组、嵌套对象、`null` 都在其中),因此参数与结果只有一份规则。
|
|
179
|
+
* 可省略表示「这一项不碰」:省略编号会让同一个端点少传一个参数,而不是传一个空值。
|
|
180
|
+
*
|
|
181
|
+
* @param {string} typeSymbol - 类型符号。
|
|
182
|
+
* @param {string|object} kind - 类型说明。
|
|
183
|
+
* @returns {object} 参数编解码器。
|
|
184
|
+
*/
|
|
185
|
+
function param(typeSymbol, kind) {
|
|
186
|
+
return Object.freeze({
|
|
187
|
+
mode: 'strict',
|
|
188
|
+
typeSymbol,
|
|
189
|
+
schema: {
|
|
190
|
+
parse(value) {
|
|
191
|
+
if (value === undefined) return undefined;
|
|
192
|
+
return parseKind(typeSymbol, kind, value);
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** 动作结果。 */
|
|
199
|
+
const ACTION = codec(`${PACKAGE}/types#action`, { ok: 'boolean', summary: 'string' });
|
|
200
|
+
/** 表单要显示的配置。 */
|
|
201
|
+
const CONFIGURATION = codec(`${PACKAGE}/types#configuration`, {
|
|
202
|
+
baseUrl: 'string',
|
|
203
|
+
sync: 'boolean',
|
|
204
|
+
baseUrlOverridden: 'boolean',
|
|
205
|
+
syncOverridden: 'boolean',
|
|
206
|
+
writable: 'boolean',
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
/** 一个模型的覆盖(`aperture.models` 里那一条)。 */
|
|
210
|
+
const OVERRIDE = codec(`${PACKAGE}/types#modelOverride`, {
|
|
211
|
+
name: 'string?',
|
|
212
|
+
api: 'string?',
|
|
213
|
+
contextWindow: 'number?',
|
|
214
|
+
maxTokens: 'number?',
|
|
215
|
+
input: 'string[]?',
|
|
216
|
+
thinking: 'boolean?',
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
/** 一条事实的来源;未知来源原样显示。 */
|
|
220
|
+
const PROVENANCE = codec(`${PACKAGE}/types#provenance`, {
|
|
221
|
+
limits: 'string',
|
|
222
|
+
reasoning: 'string',
|
|
223
|
+
input: 'string',
|
|
224
|
+
name: 'string',
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
/** 报告里的一个模型。 */
|
|
228
|
+
const MODEL = codec(`${PACKAGE}/types#model`, {
|
|
229
|
+
id: 'string',
|
|
230
|
+
name: 'string',
|
|
231
|
+
route: 'string?',
|
|
232
|
+
protocol: 'string?',
|
|
233
|
+
endpoints: 'string[]',
|
|
234
|
+
contextWindow: 'number?',
|
|
235
|
+
maxTokens: 'number?',
|
|
236
|
+
input: 'string[]',
|
|
237
|
+
reasoning: 'boolean',
|
|
238
|
+
provenance: PROVENANCE,
|
|
239
|
+
override: opt(OVERRIDE),
|
|
240
|
+
alias: 'string?',
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
/** 报告里的一条路由。 */
|
|
244
|
+
const ROUTE = codec(`${PACKAGE}/types#route`, {
|
|
245
|
+
provider: 'string',
|
|
246
|
+
api: 'string?',
|
|
247
|
+
baseURL: 'string?',
|
|
248
|
+
models: 'number',
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
/** 最近一次刷新的状态。 */
|
|
252
|
+
const REFRESH = codec(`${PACKAGE}/types#refresh`, {
|
|
253
|
+
trigger: 'string',
|
|
254
|
+
at: 'string',
|
|
255
|
+
durationMs: 'number',
|
|
256
|
+
ok: 'boolean',
|
|
257
|
+
error: 'string?',
|
|
258
|
+
catalog: codec(`${PACKAGE}/types#catalog`, {
|
|
259
|
+
available: 'boolean',
|
|
260
|
+
entries: 'number',
|
|
261
|
+
reason: 'string?',
|
|
262
|
+
}),
|
|
263
|
+
endpoint: opt(codec(`${PACKAGE}/types#endpoint`, { url: 'string', listed: 'number' })),
|
|
264
|
+
sync: opt(codec(`${PACKAGE}/types#sync`, {
|
|
265
|
+
applied: 'boolean',
|
|
266
|
+
ops: 'number',
|
|
267
|
+
routes: 'string[]',
|
|
268
|
+
reason: 'string?',
|
|
269
|
+
})),
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
/** 标签页要显示的整份报告。 */
|
|
273
|
+
const STATUS = codec(`${PACKAGE}/types#status`, {
|
|
274
|
+
place: 'string',
|
|
275
|
+
refresh: opt(REFRESH),
|
|
276
|
+
routes: list(ROUTE),
|
|
277
|
+
models: list(MODEL),
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* `edit` 的补丁:只带界面改动过的字段,缺字段表示不碰,`null` 表示这一条覆盖不要了。
|
|
282
|
+
*/
|
|
283
|
+
const PATCH = codec(`${PACKAGE}/types#modelPatch`, {
|
|
284
|
+
name: 'string|null?',
|
|
285
|
+
api: 'string|null?',
|
|
286
|
+
contextWindow: 'number|null?',
|
|
287
|
+
maxTokens: 'number|null?',
|
|
288
|
+
input: 'string[]|null?',
|
|
289
|
+
thinking: 'boolean|null?',
|
|
290
|
+
alias: 'string|null?',
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* 一个端点的浏览器侧调用描述符。
|
|
295
|
+
*
|
|
296
|
+
* `acceptsUndefined` 由参数自己的编解码器决定,而不是一律为真:只有「可省略」的参数
|
|
297
|
+
* (`save` 的地址与开关,没提到就原样不碰)才接受 `undefined`。`edit` 的补丁必须显式给出,
|
|
298
|
+
* 因为 `null` 是有含义的(撤销覆盖),缺省不能顺便也当成撤销。
|
|
299
|
+
*
|
|
300
|
+
* @param {string} method - 端点方法名(也是宿主服务上的方法名)。
|
|
301
|
+
* @param {Array} parameters - `[参数名, 编解码器]` 对,顺序与宿主方法一致。
|
|
302
|
+
* @param {object} result - 结果编解码器。
|
|
303
|
+
* @returns {object} 描述符。
|
|
304
|
+
*/
|
|
305
|
+
function descriptor(method, parameters, result) {
|
|
306
|
+
return Object.freeze({
|
|
307
|
+
id: `${PACKAGE}#${PANEL}/${method}`,
|
|
308
|
+
service: PANEL,
|
|
309
|
+
namespace: PANEL,
|
|
310
|
+
method,
|
|
311
|
+
invocation: Object.freeze({ kind: 'direct' }),
|
|
312
|
+
parameters: Object.freeze(parameters.map(([name, param]) => Object.freeze({
|
|
313
|
+
name,
|
|
314
|
+
wire: name,
|
|
315
|
+
source: 'json',
|
|
316
|
+
codec: param,
|
|
317
|
+
acceptsUndefined: param.acceptsUndefined === true,
|
|
318
|
+
}))),
|
|
319
|
+
result,
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* 与宿主半边 `PANEL_INVOCATIONS` 一一对应的贡献。
|
|
325
|
+
*
|
|
326
|
+
* 端点名不能与命名空间服务自己的成员重名:api-gateway 为每个命名空间建一个
|
|
327
|
+
* `RemoteNamespaceService`,端点会成为它的属性,撞上 `remove` / `has` / `install` /
|
|
328
|
+
* `name` / `ctx` 这类预置名字时 `validateContribution` 会拒绝**整份**贡献,界面因此
|
|
329
|
+
* 安静地什么都不出现。「撤下路由」叫 `withdraw` 就是这个原因。
|
|
330
|
+
*/
|
|
331
|
+
const REMOTE = Object.freeze({
|
|
332
|
+
package: PACKAGE,
|
|
333
|
+
descriptors: Object.freeze([
|
|
334
|
+
descriptor('status', [], STATUS),
|
|
335
|
+
descriptor('refresh', [], ACTION),
|
|
336
|
+
descriptor('withdraw', [], ACTION),
|
|
337
|
+
descriptor('configuration', [], CONFIGURATION),
|
|
338
|
+
descriptor('save', [
|
|
339
|
+
['baseUrl', optionalParam(`${PACKAGE}/types#baseUrl`, 'string')],
|
|
340
|
+
['sync', optionalParam(`${PACKAGE}/types#sync`, 'boolean')],
|
|
341
|
+
], ACTION),
|
|
342
|
+
descriptor('edit', [
|
|
343
|
+
['id', param(`${PACKAGE}/types#modelId`, 'string')],
|
|
344
|
+
['patch', param(`${PACKAGE}/types#modelPatch`, nullable(PATCH))],
|
|
345
|
+
], ACTION),
|
|
346
|
+
]),
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* 把 `RemoteResult` 拆成值,失败则抛人话。
|
|
351
|
+
*
|
|
352
|
+
* @param {{ok: boolean}} result - 端点应答。
|
|
353
|
+
* @returns {object} 端点值。
|
|
354
|
+
*/
|
|
355
|
+
function unwrap(result) {
|
|
356
|
+
if (result.ok) return result.value;
|
|
357
|
+
const detail = result.error && result.error.message ? result.error.message : '未知原因';
|
|
358
|
+
throw new Error(`面板暂时连不上后台(${detail});若反复出现请重启 dsh web。`);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// -------------------------------------------------------------------- 样式
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* 注入标签页样式。
|
|
365
|
+
*
|
|
366
|
+
* 标签页在独立 bundle 里,用不了仓库的 CSS module 管线,因此样式随包分发、按 effect
|
|
367
|
+
* 生命周期注入,并在卸载时移除。选择器全部收在 `[data-dsh-aperture]` 之下;颜色只引用
|
|
368
|
+
* dsh web 的主题 token(`--dsw-alias-*`,各带回落值),深浅色自动跟随。
|
|
369
|
+
*
|
|
370
|
+
* 尺寸与形状照抄官方设置页的「模型」卡片(`@deepseek-ai/dsh-client-ui-settings-models`):
|
|
371
|
+
* 输入框 32px / 8px 圆角 / `.5px` 边框,卡片与编辑区 12px 圆角、14px 16px 内边距,参数
|
|
372
|
+
* 用 `minmax(160px, 1fr)` 的栅格加 12px 小标签,行内动作按钮 28px,正文按钮 36px 胶囊。
|
|
373
|
+
* 那份 CSS 是构建产物里的字面量,可以逐条对照,因此界面不必赌一个没有类型声明的组件
|
|
374
|
+
* API 也能与官方标签页长得一样。
|
|
375
|
+
*
|
|
376
|
+
* @returns {Function} 卸载时移除样式表的 disposer。
|
|
377
|
+
*/
|
|
378
|
+
function installStyles() {
|
|
379
|
+
if (document.querySelector(`style[${STYLE_MARK}]`) !== null) return () => {};
|
|
380
|
+
const element = document.createElement('style');
|
|
381
|
+
element.setAttribute(STYLE_MARK, '');
|
|
382
|
+
element.textContent = `
|
|
383
|
+
[${STYLE_MARK}] { display: flex; flex-direction: column; gap: 12px; max-width: 720px; min-width: 0; color: var(--dsw-alias-label-primary, inherit); }
|
|
384
|
+
[${STYLE_MARK}] .dap-title { font-size: 16px; font-weight: 500; line-height: 24px; }
|
|
385
|
+
[${STYLE_MARK}] .dap-subtitle { margin: 0; font-size: 14px; line-height: 22px; color: var(--dsw-alias-label-tertiary, rgba(127,127,127,.9)); }
|
|
386
|
+
[${STYLE_MARK}] .dap-section { display: flex; flex-direction: column; gap: 12px; padding: 14px 16px; border: .5px solid var(--dsw-alias-border-l2, rgba(127,127,127,.3)); border-radius: 12px; background: var(--dsw-alias-bg-layer-2, transparent); }
|
|
387
|
+
[${STYLE_MARK}] .dap-head { display: flex; flex-direction: column; gap: 2px; flex: 1 1 auto; min-width: 0; }
|
|
388
|
+
[${STYLE_MARK}] .dap-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
|
|
389
|
+
[${STYLE_MARK}] .dap-label { font-size: 12px; font-weight: 500; line-height: 18px; color: var(--dsw-alias-label-secondary, inherit); }
|
|
390
|
+
[${STYLE_MARK}] .dap-hint { margin: 0; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary, rgba(127,127,127,.9)); }
|
|
391
|
+
|
|
392
|
+
/* 输入控件照抄官方:32px 高、8px 圆角、.5px 的 l4 边框、bg-layer-1 底、聚焦只换边框色。
|
|
393
|
+
select 的箭头是官方那段内联 SVG(颜色写死,深浅色下都够用)。 */
|
|
394
|
+
[${STYLE_MARK}] .dap-input { box-sizing: border-box; width: 100%; min-width: 0; height: 32px; font: inherit; font-size: 14px; line-height: 22px; padding: 0 10px; border: .5px solid var(--dsw-alias-border-l4, rgba(127,127,127,.4)); border-radius: 8px; background: var(--dsw-alias-bg-layer-1, transparent); color: var(--dsw-alias-label-primary, inherit); }
|
|
395
|
+
[${STYLE_MARK}] .dap-input:focus { border-color: var(--dsw-alias-brand-primary, rgba(127,127,127,.6)); outline: none; }
|
|
396
|
+
[${STYLE_MARK}] .dap-input::placeholder { color: var(--dsw-alias-label-dimmed, rgba(127,127,127,.6)); }
|
|
397
|
+
[${STYLE_MARK}] .dap-input:disabled { opacity: .6; cursor: default; }
|
|
398
|
+
[${STYLE_MARK}] select.dap-input { max-width: 240px; cursor: pointer; appearance: none; padding-right: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%2381858C' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); background-position: right 12px center; background-repeat: no-repeat; background-size: 12px 12px; }
|
|
399
|
+
|
|
400
|
+
[${STYLE_MARK}] .dap-tag { flex: none; padding: 1px 6px; border: .5px solid var(--dsw-alias-border-l3, rgba(127,127,127,.4)); border-radius: 4px; font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-secondary, inherit); }
|
|
401
|
+
[${STYLE_MARK}] .dap-check { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; line-height: 22px; }
|
|
402
|
+
[${STYLE_MARK}] .dap-check > input { accent-color: var(--dsw-alias-brand-primary, rgba(127,127,127,.6)); }
|
|
403
|
+
[${STYLE_MARK}] .dap-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
|
|
404
|
+
[${STYLE_MARK}] .dap-actions[data-align="end"] { justify-content: flex-end; }
|
|
405
|
+
[${STYLE_MARK}] .dap-button { box-sizing: border-box; display: inline-flex; justify-content: center; align-items: center; gap: 4px; height: 36px; padding: 0 14px; border: none; border-radius: 18px; background: none; color: var(--dsw-alias-label-primary, inherit); font: inherit; font-size: 14px; line-height: 22px; cursor: pointer; }
|
|
406
|
+
[${STYLE_MARK}] .dap-button:not([data-primary="true"]) { border: .5px solid var(--dsw-alias-border-l3, rgba(127,127,127,.4)); }
|
|
407
|
+
[${STYLE_MARK}] .dap-button:not([data-primary="true"]):hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover-solid, var(--dsw-alias-interactive-bg-hover, rgba(127,127,127,.12))); }
|
|
408
|
+
[${STYLE_MARK}] .dap-button[data-danger="true"] { border: none; color: var(--dsw-alias-state-error-primary, #d9534f); }
|
|
409
|
+
[${STYLE_MARK}] .dap-button[data-danger="true"]:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover-danger, rgba(217,83,79,.12)); }
|
|
410
|
+
[${STYLE_MARK}] .dap-button:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-border-l3, rgba(127,127,127,.4)); }
|
|
411
|
+
/* 主按钮的底色与文字是一对 token,不能只换底色。--dsw-alias-brand-primary 在浅色主题里是
|
|
412
|
+
近黑、在深色主题里是近白,而继承来的正文色恰好与它同色——只写 background 就是「深底深字」。
|
|
413
|
+
--dsw-alias-label-primary-foreground 就是为这种底色准备的对比色。禁用态用主题自己的
|
|
414
|
+
dimmed 填充 + label-secondary:官方的整颗 opacity: .4 会把底色与文字一起压向页面底色,
|
|
415
|
+
两个都变浅之后反而谁也看不清(浅色主题下大约 1.4:1)。 */
|
|
416
|
+
[${STYLE_MARK}] .dap-button[data-primary="true"] { background: var(--dsw-alias-button-primary-fill, var(--dsw-alias-brand-primary, rgba(127,127,127,.5))); color: var(--dsw-alias-label-primary-foreground, #fff); }
|
|
417
|
+
[${STYLE_MARK}] .dap-button[data-primary="true"]:hover:not(:disabled) { background: var(--dsw-alias-button-primary-hover, var(--dsw-alias-brand-primary, rgba(127,127,127,.5))); }
|
|
418
|
+
[${STYLE_MARK}] .dap-button[data-primary="true"]:disabled { opacity: 1; background: var(--dsw-alias-button-primary-dimmed, rgba(127,127,127,.18)); color: var(--dsw-alias-label-secondary, rgba(127,127,127,.9)); }
|
|
419
|
+
[${STYLE_MARK}] .dap-button:disabled { cursor: default; }
|
|
420
|
+
|
|
421
|
+
[${STYLE_MARK}] .dap-banner { margin: 0; font-size: 12px; line-height: 18px; white-space: pre-wrap; }
|
|
422
|
+
[${STYLE_MARK}] .dap-banner[data-ok="false"] { color: var(--dsw-alias-state-error-primary, #d9534f); }
|
|
423
|
+
[${STYLE_MARK}] .dap-banner[data-ok="true"] { color: var(--dsw-alias-state-success-primary, inherit); }
|
|
424
|
+
/* 状态段是一串「标签 + 值」,不用表格:值本身可能是地址或一列路由名,会很长。 */
|
|
425
|
+
[${STYLE_MARK}] .dap-facts { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; }
|
|
426
|
+
[${STYLE_MARK}] .dap-fact { display: flex; gap: 12px; padding: 5px 0; border-top: .5px solid var(--dsw-alias-border-l2, rgba(127,127,127,.18)); }
|
|
427
|
+
[${STYLE_MARK}] .dap-fact:first-child { border-top: none; padding-top: 0; }
|
|
428
|
+
[${STYLE_MARK}] .dap-fact > dt { flex: 0 0 84px; font-size: 12px; line-height: 22px; color: var(--dsw-alias-label-tertiary, rgba(127,127,127,.9)); }
|
|
429
|
+
[${STYLE_MARK}] .dap-fact > dd { margin: 0; min-width: 0; font-size: 14px; line-height: 22px; word-break: break-word; }
|
|
430
|
+
|
|
431
|
+
[${STYLE_MARK}] .dap-group { display: flex; flex-direction: column; gap: 8px; }
|
|
432
|
+
[${STYLE_MARK}] .dap-group-head { display: flex; flex-direction: column; gap: 2px; }
|
|
433
|
+
[${STYLE_MARK}] .dap-group-title { font-size: 12px; font-weight: 500; line-height: 18px; color: var(--dsw-alias-label-secondary, inherit); }
|
|
434
|
+
[${STYLE_MARK}] .dap-group-meta { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary, rgba(127,127,127,.9)); }
|
|
435
|
+
[${STYLE_MARK}] .dap-models { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
|
|
436
|
+
[${STYLE_MARK}] .dap-model { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border: .5px solid var(--dsw-alias-border-l4, rgba(127,127,127,.3)); border-radius: 10px; }
|
|
437
|
+
[${STYLE_MARK}] .dap-model-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
|
|
438
|
+
[${STYLE_MARK}] .dap-model-identity { display: inline-flex; gap: 6px; align-items: center; min-width: 0; }
|
|
439
|
+
[${STYLE_MARK}] .dap-model-id { font-family: var(--ds-font-family-code, monospace); font-size: 13px; line-height: 20px; overflow-wrap: anywhere; }
|
|
440
|
+
[${STYLE_MARK}] .dap-model-name { font-size: 14px; font-weight: 500; line-height: 22px; }
|
|
441
|
+
[${STYLE_MARK}] .dap-model-actions { display: inline-flex; gap: 4px; align-items: center; margin-left: auto; }
|
|
442
|
+
[${STYLE_MARK}] .dap-model-actions .dap-button { height: 28px; padding: 0 10px; border-radius: 14px; font-size: 12px; line-height: 18px; }
|
|
443
|
+
[${STYLE_MARK}] .dap-model-facts { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary, inherit); }
|
|
444
|
+
[${STYLE_MARK}] .dap-model-meta { margin: 0; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary, rgba(127,127,127,.9)); }
|
|
445
|
+
|
|
446
|
+
/* 编辑区与官方一样是卡片里的一块浅色面:12px 圆角、14px 16px 内边距,参数排成
|
|
447
|
+
minmax(160px, 1fr) 的栅格,标签 12px 在上,动作右对齐。 */
|
|
448
|
+
[${STYLE_MARK}] .dap-editor { display: flex; flex-direction: column; gap: 14px; padding: 14px 16px; border-radius: 12px; background: var(--dsw-alias-bg-module-platform, var(--dsw-alias-bg-layer-1, transparent)); }
|
|
449
|
+
[${STYLE_MARK}] .dap-editor-head { display: flex; gap: 8px; align-items: baseline; }
|
|
450
|
+
[${STYLE_MARK}] .dap-editor-title { font-size: 14px; font-weight: 500; line-height: 22px; }
|
|
451
|
+
[${STYLE_MARK}] .dap-editor-route { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary, rgba(127,127,127,.9)); }
|
|
452
|
+
[${STYLE_MARK}] .dap-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
|
|
453
|
+
[${STYLE_MARK}] .dap-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
|
|
454
|
+
[${STYLE_MARK}] .dap-field > label { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary, rgba(127,127,127,.9)); }
|
|
455
|
+
[${STYLE_MARK}] .dap-field-note { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary, rgba(127,127,127,.9)); }
|
|
456
|
+
[${STYLE_MARK}] .dap-error { margin: 0; font-size: 12px; line-height: 18px; color: var(--dsw-alias-state-error-primary, #d9534f); }
|
|
457
|
+
[${STYLE_MARK}] .dap-chevron { display: inline-flex; transition: transform 120ms ease; }
|
|
458
|
+
[${STYLE_MARK}] .dap-chevron[data-open="true"] { transform: rotate(90deg); }
|
|
459
|
+
`;
|
|
460
|
+
document.head.append(element);
|
|
461
|
+
return () => element.remove();
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// -------------------------------------------------------------------- 字典
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* 中英文字典。
|
|
468
|
+
*
|
|
469
|
+
* 注册时必须一次交齐所有内置语言,缺一个都会在注册处被拒绝;中文是本插件的主语言,
|
|
470
|
+
* 英文只求达意。`{name}` 是插值占位符(由 locale 服务替换)。
|
|
471
|
+
*/
|
|
472
|
+
const zh = {
|
|
473
|
+
tab: 'Aperture',
|
|
474
|
+
title: 'Aperture 模型发现',
|
|
475
|
+
subtitle: '把实例通告的模型发布成 llm-pi-ai 的 provider 路由。',
|
|
476
|
+
loading: '正在读取状态…',
|
|
477
|
+
addressLabel: '实例地址',
|
|
478
|
+
addressPlaceholder: 'https://ai.example.ts.net',
|
|
479
|
+
addressDormant: '没有实例地址:发现处于休眠,插件不探测,也不会写入 llm-pi-ai。',
|
|
480
|
+
syncLabel: '同步到 llm-pi-ai',
|
|
481
|
+
syncOn: '写入 provider 字典',
|
|
482
|
+
syncOff: '只探测,不写入',
|
|
483
|
+
overridden: '已覆盖',
|
|
484
|
+
reset: '撤销覆盖',
|
|
485
|
+
save: '保存',
|
|
486
|
+
saving: '保存中…',
|
|
487
|
+
cancel: '取消',
|
|
488
|
+
refresh: '立即刷新',
|
|
489
|
+
refreshing: '正在发现…',
|
|
490
|
+
withdraw: '撤掉已发布的路由',
|
|
491
|
+
withdrawing: '正在撤下…',
|
|
492
|
+
readOnly: '当前设置文档不接受写入,表单只读。',
|
|
493
|
+
|
|
494
|
+
statusHeading: '最近一次刷新',
|
|
495
|
+
noAddress: '未配置地址',
|
|
496
|
+
neverRefreshed: '尚未完成任何刷新:稍后会自动重试,也可以按「立即刷新」。',
|
|
497
|
+
refreshOk: '成功',
|
|
498
|
+
refreshFailed: '失败',
|
|
499
|
+
factTrigger: '触发',
|
|
500
|
+
factTime: '时间',
|
|
501
|
+
factDuration: '耗时',
|
|
502
|
+
factResult: '结果',
|
|
503
|
+
factCatalog: '清单',
|
|
504
|
+
catalogEntries: '{count} 个条目',
|
|
505
|
+
catalogUnavailable: '不可用({reason})',
|
|
506
|
+
factEndpoint: '端点',
|
|
507
|
+
endpointListed: '{url} 列出了 {count} 行',
|
|
508
|
+
factSync: '设置',
|
|
509
|
+
syncApplied: '向 llm-pi-ai 写入 {count} 个操作({routes})',
|
|
510
|
+
syncOnlyRemoval: '仅移除',
|
|
511
|
+
syncSkipped: '未写入({reason})',
|
|
512
|
+
|
|
513
|
+
modelsHeading: '模型与路由',
|
|
514
|
+
modelsCount: '{count} 个模型',
|
|
515
|
+
modelsMetaOverride: '已覆盖 {count} 个模型,其余沿用发现值与清单',
|
|
516
|
+
modelsMetaInherit: '全部沿用发现值与清单',
|
|
517
|
+
noModels: '未发现任何模型。',
|
|
518
|
+
modelsError: '未发现任何内容:{error}',
|
|
519
|
+
unservedHeading: '未服务:没有本插件可发布的端点',
|
|
520
|
+
unservedHint: '填上协议可以让它在对应路由上发布。',
|
|
521
|
+
unservedEndpoints: '通告的端点:{list}',
|
|
522
|
+
noEndpoints: '未通告任何端点',
|
|
523
|
+
pendingTag: '待保存',
|
|
524
|
+
unservedTag: '未服务',
|
|
525
|
+
advancedHide: '收起',
|
|
526
|
+
|
|
527
|
+
factContextWindow: '{count} 上下文窗口',
|
|
528
|
+
factMaxTokens: '{count} 输出',
|
|
529
|
+
modalityText: '文本',
|
|
530
|
+
modalityImage: '图像',
|
|
531
|
+
modalityNone: '无模态',
|
|
532
|
+
factReasoningOn: '推理',
|
|
533
|
+
factReasoningOff: '无推理',
|
|
534
|
+
factAlias: '清单别名 {alias}',
|
|
535
|
+
sourceAperture: 'aperture',
|
|
536
|
+
sourceNote: '来自 {source}',
|
|
537
|
+
sourceModelsDev: 'models.dev',
|
|
538
|
+
sourceConfig: '配置',
|
|
539
|
+
sourceDefault: '默认',
|
|
540
|
+
|
|
541
|
+
edit: '编辑',
|
|
542
|
+
noAlias: '未收录',
|
|
543
|
+
noChanges: '没有要保存的改动。',
|
|
544
|
+
editName: '显示名',
|
|
545
|
+
editAlias: '清单别名',
|
|
546
|
+
editContextWindow: '上下文',
|
|
547
|
+
editMaxTokens: '最大输出',
|
|
548
|
+
editInput: '输入模态',
|
|
549
|
+
editReasoning: '推理',
|
|
550
|
+
editApi: '协议',
|
|
551
|
+
editHint: '显示名、容量与模态留空表示这一项不覆盖,回落到发现值;协议与推理的「跟随发现」同理。',
|
|
552
|
+
effectiveHint: '生效 {value}',
|
|
553
|
+
effectiveSource: '生效 {value} · 来自 {source}',
|
|
554
|
+
optionAuto: '跟随发现',
|
|
555
|
+
optionOn: '开',
|
|
556
|
+
optionOff: '关',
|
|
557
|
+
invalidNumber: '{field} 必须是不小于 1 的整数。',
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
const en = {
|
|
561
|
+
tab: 'Aperture',
|
|
562
|
+
title: 'Aperture model discovery',
|
|
563
|
+
subtitle: 'Publish the models your instance advertises as llm-pi-ai provider routes.',
|
|
564
|
+
loading: 'Reading state…',
|
|
565
|
+
addressLabel: 'Instance address',
|
|
566
|
+
addressPlaceholder: 'https://ai.example.ts.net',
|
|
567
|
+
addressDormant: 'No instance address: discovery is dormant, so nothing is probed and nothing is written to llm-pi-ai.',
|
|
568
|
+
syncLabel: 'Sync into llm-pi-ai',
|
|
569
|
+
syncOn: 'writes the provider dictionary',
|
|
570
|
+
syncOff: 'probe only, write nothing',
|
|
571
|
+
overridden: 'overridden',
|
|
572
|
+
reset: 'Reset',
|
|
573
|
+
save: 'Save',
|
|
574
|
+
saving: 'Saving…',
|
|
575
|
+
cancel: 'Cancel',
|
|
576
|
+
refresh: 'Refresh now',
|
|
577
|
+
refreshing: 'Discovering…',
|
|
578
|
+
withdraw: 'Withdraw published routes',
|
|
579
|
+
withdrawing: 'Withdrawing…',
|
|
580
|
+
readOnly: 'This deployment does not accept settings writes, so the form is read-only.',
|
|
581
|
+
|
|
582
|
+
statusHeading: 'Last refresh',
|
|
583
|
+
noAddress: 'no address configured',
|
|
584
|
+
neverRefreshed: 'No refresh has finished yet: one is retried shortly, or press “Refresh now”.',
|
|
585
|
+
refreshOk: 'succeeded',
|
|
586
|
+
refreshFailed: 'failed',
|
|
587
|
+
factTrigger: 'Trigger',
|
|
588
|
+
factTime: 'Time',
|
|
589
|
+
factDuration: 'Took',
|
|
590
|
+
factResult: 'Result',
|
|
591
|
+
factCatalog: 'Catalog',
|
|
592
|
+
catalogEntries: '{count} entries',
|
|
593
|
+
catalogUnavailable: 'unavailable ({reason})',
|
|
594
|
+
factEndpoint: 'Endpoint',
|
|
595
|
+
endpointListed: '{url} listed {count} rows',
|
|
596
|
+
factSync: 'Settings',
|
|
597
|
+
syncApplied: 'wrote {count} operations to llm-pi-ai ({routes})',
|
|
598
|
+
syncOnlyRemoval: 'removals only',
|
|
599
|
+
syncSkipped: 'not written ({reason})',
|
|
600
|
+
|
|
601
|
+
modelsHeading: 'Models and routes',
|
|
602
|
+
modelsCount: '{count} models',
|
|
603
|
+
modelsMetaOverride: '{count} models overridden, the rest inherit discovery and the catalog',
|
|
604
|
+
modelsMetaInherit: 'everything inherits discovery and the catalog',
|
|
605
|
+
noModels: 'No models discovered.',
|
|
606
|
+
modelsError: 'Nothing discovered: {error}',
|
|
607
|
+
unservedHeading: 'Unserved: no endpoint this plugin can publish',
|
|
608
|
+
unservedHint: 'Filling in a protocol publishes it on the matching route.',
|
|
609
|
+
unservedEndpoints: 'Advertised endpoints: {list}',
|
|
610
|
+
noEndpoints: 'no endpoints advertised',
|
|
611
|
+
pendingTag: 'unsaved',
|
|
612
|
+
unservedTag: 'unserved',
|
|
613
|
+
advancedHide: 'Collapse',
|
|
614
|
+
|
|
615
|
+
factContextWindow: '{count} context window',
|
|
616
|
+
factMaxTokens: '{count} output',
|
|
617
|
+
modalityText: 'text',
|
|
618
|
+
modalityImage: 'image',
|
|
619
|
+
modalityNone: 'no modality',
|
|
620
|
+
factReasoningOn: 'reasoning',
|
|
621
|
+
factReasoningOff: 'no reasoning',
|
|
622
|
+
factAlias: 'catalog alias {alias}',
|
|
623
|
+
sourceAperture: 'aperture',
|
|
624
|
+
sourceNote: '来自 {source}',
|
|
625
|
+
sourceModelsDev: 'models.dev',
|
|
626
|
+
sourceConfig: 'config',
|
|
627
|
+
sourceDefault: 'default',
|
|
628
|
+
|
|
629
|
+
edit: 'Edit',
|
|
630
|
+
noAlias: 'not in the catalog',
|
|
631
|
+
noChanges: 'Nothing to save.',
|
|
632
|
+
editName: 'Display name',
|
|
633
|
+
editAlias: 'Catalog alias',
|
|
634
|
+
editContextWindow: 'Context',
|
|
635
|
+
editMaxTokens: 'Max output',
|
|
636
|
+
editInput: 'Input modalities',
|
|
637
|
+
editReasoning: 'Reasoning',
|
|
638
|
+
editApi: 'Protocol',
|
|
639
|
+
editHint: 'An empty display name, capacity or modality drops that override and falls back to discovery; the same goes for “follow discovery” on protocol and reasoning.',
|
|
640
|
+
effectiveHint: 'in effect: {value}',
|
|
641
|
+
effectiveSource: 'in effect: {value} · from {source}',
|
|
642
|
+
optionAuto: 'follow discovery',
|
|
643
|
+
optionOn: 'on',
|
|
644
|
+
optionOff: 'off',
|
|
645
|
+
invalidNumber: '{field} must be an integer of at least 1.',
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
|
|
649
|
+
// ------------------------------------------------------------------ 标签页
|
|
650
|
+
|
|
651
|
+
/** 一个错误的人话形式。 */
|
|
652
|
+
function textOf(error) {
|
|
653
|
+
return error instanceof Error ? error.message : String(error);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/** token 计数的千位分隔符;跟随浏览器语言。 */
|
|
657
|
+
function formatCount(value) {
|
|
658
|
+
return value.toLocaleString();
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
/** ISO 时间戳 → 本地时间;宿主只报 ISO,时区是浏览器的事。 */
|
|
662
|
+
function formatTime(iso) {
|
|
663
|
+
const at = new Date(iso);
|
|
664
|
+
return Number.isNaN(at.getTime()) ? iso : at.toLocaleString();
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
/** 事实来源 → 字典键;未知来源原样显示。 */
|
|
668
|
+
const SOURCE_KEYS = {
|
|
669
|
+
aperture: 'sourceAperture',
|
|
670
|
+
'models.dev': 'sourceModelsDev',
|
|
671
|
+
config: 'sourceConfig',
|
|
672
|
+
default: 'sourceDefault',
|
|
673
|
+
};
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* 把 `{name}` 占位符换成实参。
|
|
677
|
+
*
|
|
678
|
+
* locale 服务自己做这件事;这里只是为了在没有注入 `t` 时(测试、以及渲染器还没绑定字典时)
|
|
679
|
+
* 用同一套规则兜底——否则字典里的模板会原样漏到界面上。
|
|
680
|
+
*
|
|
681
|
+
* @param {string} template - 字典里的模板。
|
|
682
|
+
* @param {Record<string, *>} params - 实参。
|
|
683
|
+
* @returns {string} 填好的字符串。
|
|
684
|
+
*/
|
|
685
|
+
function interpolate(template, params) {
|
|
686
|
+
if (params === undefined) return template;
|
|
687
|
+
return template.replace(/\{(\w+)\}/gu, (match, name) => (
|
|
688
|
+
Object.prototype.hasOwnProperty.call(params, name) ? String(params[name]) : match
|
|
689
|
+
));
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* 「Aperture」标签页。
|
|
694
|
+
*
|
|
695
|
+
* 只持有视图状态:配置与报告分别由一个 effect 拉取,动作按下后再拉一次。**effect 的
|
|
696
|
+
* 依赖里刻意不放注入面**——`inject` 面由渲染器每次渲染重新组装,把它的身份放进依赖会
|
|
697
|
+
* 让 effect 每渲染一次就重跑一次,进而无限循环。因此这里用自增计数器当刷新信号。
|
|
698
|
+
*
|
|
699
|
+
* @param {object} props - 渲染器交过来的 `panel` 与 `t`。
|
|
700
|
+
* @returns {object} 标签页元素。
|
|
701
|
+
*/
|
|
702
|
+
function ApertureTab(props) {
|
|
703
|
+
const panel = props.panel;
|
|
704
|
+
const t = typeof props.t === 'function' ? props.t : (key, params) => interpolate(zh[key] ?? key, params);
|
|
705
|
+
|
|
706
|
+
const [configuration, setConfiguration] = React.useState(null);
|
|
707
|
+
const [draft, setDraft] = React.useState(null);
|
|
708
|
+
const [report, setReport] = React.useState(null);
|
|
709
|
+
const [banner, setBanner] = React.useState(null);
|
|
710
|
+
const [busy, setBusy] = React.useState('');
|
|
711
|
+
const [drafts, setDrafts] = React.useState({});
|
|
712
|
+
const [opened, setOpened] = React.useState({});
|
|
713
|
+
const [configRevision, setConfigRevision] = React.useState(0);
|
|
714
|
+
const [reportRevision, setReportRevision] = React.useState(0);
|
|
715
|
+
|
|
716
|
+
React.useEffect(() => {
|
|
717
|
+
let cancelled = false;
|
|
718
|
+
panel.configuration().then(
|
|
719
|
+
(next) => {
|
|
720
|
+
if (cancelled) return;
|
|
721
|
+
setConfiguration(next);
|
|
722
|
+
setDraft({ baseUrl: next.baseUrl, sync: next.sync });
|
|
723
|
+
},
|
|
724
|
+
(error) => {
|
|
725
|
+
if (!cancelled) setBanner({ ok: false, text: textOf(error) });
|
|
726
|
+
},
|
|
727
|
+
);
|
|
728
|
+
return () => {
|
|
729
|
+
cancelled = true;
|
|
730
|
+
};
|
|
731
|
+
}, [configRevision]);
|
|
732
|
+
|
|
733
|
+
React.useEffect(() => {
|
|
734
|
+
let cancelled = false;
|
|
735
|
+
panel.status().then(
|
|
736
|
+
(next) => {
|
|
737
|
+
if (!cancelled) setReport(next);
|
|
738
|
+
},
|
|
739
|
+
(error) => {
|
|
740
|
+
if (!cancelled) setBanner({ ok: false, text: textOf(error) });
|
|
741
|
+
},
|
|
742
|
+
);
|
|
743
|
+
return () => {
|
|
744
|
+
cancelled = true;
|
|
745
|
+
};
|
|
746
|
+
}, [reportRevision]);
|
|
747
|
+
|
|
748
|
+
/** 跑一个动作:期间禁用按钮,结束后把结果贴出来并按需重读。 */
|
|
749
|
+
const run = (key, action, after) => {
|
|
750
|
+
setBusy(key);
|
|
751
|
+
setBanner(null);
|
|
752
|
+
void (async () => {
|
|
753
|
+
try {
|
|
754
|
+
const result = await action();
|
|
755
|
+
setBanner({ ok: result.ok, text: result.summary });
|
|
756
|
+
} catch (error) {
|
|
757
|
+
setBanner({ ok: false, text: textOf(error) });
|
|
758
|
+
} finally {
|
|
759
|
+
setBusy('');
|
|
760
|
+
after();
|
|
761
|
+
}
|
|
762
|
+
})();
|
|
763
|
+
};
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* 一个模型此刻在表单里长什么样。
|
|
767
|
+
*
|
|
768
|
+
* 取的都是**生效值**,这样输入框里显示的永远是此刻真正在用的东西;提交时逐字段与这份
|
|
769
|
+
* 快照比较,只有改动过的字段才会被发出去(没提到的字段保持原样,因此界面不编辑的
|
|
770
|
+
* `reasoningEfforts` 之类不会被顺手抹掉)。
|
|
771
|
+
*
|
|
772
|
+
* @param {object} model - 报告里的一个模型。
|
|
773
|
+
* @returns {object} 八个字段的初值。
|
|
774
|
+
*/
|
|
775
|
+
const initialOf = (model) => ({
|
|
776
|
+
name: model.name,
|
|
777
|
+
alias: model.alias ?? '',
|
|
778
|
+
contextWindow: model.contextWindow === undefined ? '' : String(model.contextWindow),
|
|
779
|
+
maxTokens: model.maxTokens === undefined ? '' : String(model.maxTokens),
|
|
780
|
+
text: model.input.includes('text'),
|
|
781
|
+
image: model.input.includes('image'),
|
|
782
|
+
reasoning: model.override !== undefined && model.override.thinking !== undefined
|
|
783
|
+
? (model.override.thinking ? 'on' : 'off')
|
|
784
|
+
: 'auto',
|
|
785
|
+
api: (model.override !== undefined && model.override.api) || '',
|
|
786
|
+
});
|
|
787
|
+
|
|
788
|
+
/** 一个模型的当前草稿;没改过就是生效值本身。 */
|
|
789
|
+
const draftOf = (model) => drafts[model.id] ?? initialOf(model);
|
|
790
|
+
|
|
791
|
+
/** 改一个字段;用函数式更新,同一个 tick 里连着改几个字段也不会互相覆盖。 */
|
|
792
|
+
const edit = (model, field, value) => {
|
|
793
|
+
setDrafts((current) => ({
|
|
794
|
+
...current,
|
|
795
|
+
[model.id]: { ...(current[model.id] ?? initialOf(model)), [field]: value },
|
|
796
|
+
}));
|
|
797
|
+
};
|
|
798
|
+
|
|
799
|
+
/** 改动的字段 → 补丁;没变的不进补丁,非法值只报字段名。 */
|
|
800
|
+
const patchOf = (draft, initial) => {
|
|
801
|
+
const patch = {};
|
|
802
|
+
const bad = [];
|
|
803
|
+
|
|
804
|
+
if (draft.name !== initial.name) patch.name = draft.name.trim() === '' ? null : draft.name.trim();
|
|
805
|
+
if (draft.alias !== initial.alias) patch.alias = draft.alias.trim();
|
|
806
|
+
|
|
807
|
+
for (const [field, label] of [['contextWindow', 'editContextWindow'], ['maxTokens', 'editMaxTokens']]) {
|
|
808
|
+
if (draft[field] === initial[field]) continue;
|
|
809
|
+
const raw = draft[field].trim();
|
|
810
|
+
if (raw === '') {
|
|
811
|
+
patch[field] = null;
|
|
812
|
+
continue;
|
|
813
|
+
}
|
|
814
|
+
const value = Number(raw);
|
|
815
|
+
if (!Number.isInteger(value) || value < 1) bad.push(t(label));
|
|
816
|
+
else patch[field] = value;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
if (draft.api !== initial.api) patch.api = draft.api === '' ? null : draft.api;
|
|
820
|
+
if (draft.reasoning !== initial.reasoning) {
|
|
821
|
+
patch.thinking = draft.reasoning === 'auto' ? null : draft.reasoning === 'on';
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
const wanted = [draft.text ? 'text' : undefined, draft.image ? 'image' : undefined].filter(Boolean);
|
|
825
|
+
const before = [initial.text ? 'text' : undefined, initial.image ? 'image' : undefined].filter(Boolean);
|
|
826
|
+
if (wanted.join('+') !== before.join('+')) patch.input = wanted.length === 0 ? null : wanted;
|
|
827
|
+
|
|
828
|
+
return { patch, bad };
|
|
829
|
+
};
|
|
830
|
+
|
|
831
|
+
/**
|
|
832
|
+
* 保存这一行的改动。
|
|
833
|
+
*
|
|
834
|
+
* 一行一个保存按钮,写下去的就只有这一行——多行同时开着也不会互相牵连,版本校验也只
|
|
835
|
+
* 管这一次写入。保存成功后收起面板:这一行的覆盖标签与事实都会跟着变,收起才看得见。
|
|
836
|
+
*
|
|
837
|
+
* @param {object} model - 报告里的一个模型。
|
|
838
|
+
*/
|
|
839
|
+
const submit = (model) => {
|
|
840
|
+
const { patch, bad } = patchOf(draftOf(model), initialOf(model));
|
|
841
|
+
if (bad.length > 0) {
|
|
842
|
+
setBanner({ ok: false, text: t('invalidNumber', { field: bad.join('、') }) });
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
if (Object.keys(patch).length === 0) {
|
|
846
|
+
setBanner({ ok: true, text: t('noChanges') });
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
run('edit', () => panel.edit(model.id, patch), () => {
|
|
850
|
+
dropDraft(model.id);
|
|
851
|
+
close(model.id);
|
|
852
|
+
setConfigRevision((value) => value + 1);
|
|
853
|
+
setReportRevision((value) => value + 1);
|
|
854
|
+
});
|
|
855
|
+
};
|
|
856
|
+
|
|
857
|
+
/** 丢掉一行的草稿:输入框回到生效值。 */
|
|
858
|
+
const dropDraft = (id) => {
|
|
859
|
+
setDrafts((current) => {
|
|
860
|
+
const { [id]: _dropped, ...kept } = current;
|
|
861
|
+
return kept;
|
|
862
|
+
});
|
|
863
|
+
};
|
|
864
|
+
|
|
865
|
+
/** 收起一行(草稿已经丢掉或写入成功)。 */
|
|
866
|
+
const close = (id) => setOpened((state) => ({ ...state, [id]: false }));
|
|
867
|
+
|
|
868
|
+
/** 取消这一行的编辑:草稿丢掉、面板收起,什么都不写。 */
|
|
869
|
+
const cancel = (model) => {
|
|
870
|
+
dropDraft(model.id);
|
|
871
|
+
close(model.id);
|
|
872
|
+
setBanner(null);
|
|
873
|
+
};
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* 撤销这一行的覆盖:只把**报告里写着确实被覆盖过**的字段清掉。
|
|
877
|
+
*
|
|
878
|
+
* 不是整条删掉:`aperture.models` 里那条可能还有界面根本不编辑的键(例如
|
|
879
|
+
* `reasoningEfforts`),整条删掉等于把用户手写的东西一起扔掉。因此这里只把已知被覆盖的
|
|
880
|
+
* 字段逐个置空——与保存走同一个端点,只是补丁全是 `null`。万一报告的覆盖里出现了界面
|
|
881
|
+
* 不认识的键(宿主以后加了字段),整条删掉是唯一能让这一行真的回落到发现值的做法。
|
|
882
|
+
*
|
|
883
|
+
* @param {object} model - 报告里的一个模型。
|
|
884
|
+
*/
|
|
885
|
+
const clearOverrides = (model) => {
|
|
886
|
+
const overrides = model.override ?? {};
|
|
887
|
+
const patch = {};
|
|
888
|
+
if (overrides.name !== undefined) patch.name = null;
|
|
889
|
+
if (overrides.api !== undefined) patch.api = null;
|
|
890
|
+
if (overrides.contextWindow !== undefined) patch.contextWindow = null;
|
|
891
|
+
if (overrides.maxTokens !== undefined) patch.maxTokens = null;
|
|
892
|
+
if (overrides.input !== undefined) patch.input = null;
|
|
893
|
+
if (overrides.thinking !== undefined) patch.thinking = null;
|
|
894
|
+
// 别名在 `modelAliases` 里,是另一张表;显示的别名可能来自清单,因此这里只是
|
|
895
|
+
// 「不要再覆盖」,宿主看到用户层没有这个键就什么都不写。
|
|
896
|
+
if (model.alias !== undefined) patch.alias = '';
|
|
897
|
+
|
|
898
|
+
const payload = Object.keys(patch).length === 0 ? null : patch;
|
|
899
|
+
run('revert', () => panel.edit(model.id, payload), () => {
|
|
900
|
+
dropDraft(model.id);
|
|
901
|
+
close(model.id);
|
|
902
|
+
setConfigRevision((value) => value + 1);
|
|
903
|
+
setReportRevision((value) => value + 1);
|
|
904
|
+
});
|
|
905
|
+
};
|
|
906
|
+
|
|
907
|
+
if (configuration === null || draft === null) {
|
|
908
|
+
return h(
|
|
909
|
+
'div',
|
|
910
|
+
{ [STYLE_MARK]: '', 'aria-busy': 'true' },
|
|
911
|
+
h('p', { className: 'dap-subtitle' }, banner === null ? t('loading') : banner.text),
|
|
912
|
+
);
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
const disabled = busy !== '' || !configuration.writable;
|
|
916
|
+
const dirty = draft.baseUrl !== configuration.baseUrl || draft.sync !== configuration.sync;
|
|
917
|
+
const dormant = draft.baseUrl.trim().length === 0;
|
|
918
|
+
|
|
919
|
+
/** 「标签 + 值」的一行;没有标签时就是一个整行的值(错误什么的)。 */
|
|
920
|
+
const fact = (key, label, value) => h(
|
|
921
|
+
'div',
|
|
922
|
+
{ className: 'dap-fact', key },
|
|
923
|
+
label === null ? null : h('dt', null, label),
|
|
924
|
+
h('dd', null, value),
|
|
925
|
+
);
|
|
926
|
+
|
|
927
|
+
/** 状态段:最近一次刷新决定了什么。 */
|
|
928
|
+
const statusFacts = (current) => {
|
|
929
|
+
const refresh = current.refresh;
|
|
930
|
+
if (refresh === undefined) {
|
|
931
|
+
return h('p', { className: 'dap-hint' }, t('neverRefreshed'));
|
|
932
|
+
}
|
|
933
|
+
return h(
|
|
934
|
+
'dl',
|
|
935
|
+
{ className: 'dap-facts' },
|
|
936
|
+
fact('trigger', t('factTrigger'), refresh.trigger),
|
|
937
|
+
fact('time', t('factTime'), formatTime(refresh.at)),
|
|
938
|
+
fact('duration', t('factDuration'), `${refresh.durationMs}ms`),
|
|
939
|
+
fact('result', t('factResult'), refresh.ok ? t('refreshOk') : t('refreshFailed')),
|
|
940
|
+
refresh.error === undefined ? null : fact('error', null, refresh.error),
|
|
941
|
+
fact(
|
|
942
|
+
'catalog',
|
|
943
|
+
t('factCatalog'),
|
|
944
|
+
refresh.catalog.available
|
|
945
|
+
? t('catalogEntries', { count: formatCount(refresh.catalog.entries) })
|
|
946
|
+
: t('catalogUnavailable', { reason: refresh.catalog.reason ?? '—' }),
|
|
947
|
+
),
|
|
948
|
+
refresh.endpoint === undefined
|
|
949
|
+
? null
|
|
950
|
+
: fact('endpoint', t('factEndpoint'), t('endpointListed', {
|
|
951
|
+
url: refresh.endpoint.url,
|
|
952
|
+
count: refresh.endpoint.listed,
|
|
953
|
+
})),
|
|
954
|
+
refresh.sync === undefined
|
|
955
|
+
? null
|
|
956
|
+
: fact('sync', t('factSync'), refresh.sync.applied
|
|
957
|
+
? t('syncApplied', {
|
|
958
|
+
count: refresh.sync.ops,
|
|
959
|
+
routes: refresh.sync.routes.join(', ') || t('syncOnlyRemoval'),
|
|
960
|
+
})
|
|
961
|
+
: t('syncSkipped', { reason: refresh.sync.reason ?? '—' })),
|
|
962
|
+
);
|
|
963
|
+
};
|
|
964
|
+
|
|
965
|
+
/** 一个模型那几项生效的事实。 */
|
|
966
|
+
const modelFacts = (model) => {
|
|
967
|
+
const facts = [];
|
|
968
|
+
if (model.contextWindow !== undefined) {
|
|
969
|
+
facts.push(t('factContextWindow', { count: formatCount(model.contextWindow) }));
|
|
970
|
+
}
|
|
971
|
+
if (model.maxTokens !== undefined) facts.push(t('factMaxTokens', { count: formatCount(model.maxTokens) }));
|
|
972
|
+
facts.push(model.input.length === 0
|
|
973
|
+
? t('modalityNone')
|
|
974
|
+
: model.input.map((item) => t(item === 'image' ? 'modalityImage' : 'modalityText')).join('+'));
|
|
975
|
+
facts.push(model.reasoning ? t('factReasoningOn') : t('factReasoningOff'));
|
|
976
|
+
if (model.alias !== undefined && model.alias !== '') facts.push(t('factAlias', { alias: model.alias }));
|
|
977
|
+
return facts.join(' · ');
|
|
978
|
+
};
|
|
979
|
+
|
|
980
|
+
/** 披露箭头;展开时转 90 度(官方那份也是自己画的内联 SVG)。 */
|
|
981
|
+
const chevron = (open) => h(
|
|
982
|
+
'span',
|
|
983
|
+
{ className: 'dap-chevron', 'data-open': open ? 'true' : 'false' },
|
|
984
|
+
h(
|
|
985
|
+
'svg',
|
|
986
|
+
{ width: '12', height: '12', viewBox: '0 0 16 16', fill: 'none', 'aria-hidden': 'true' },
|
|
987
|
+
h('path', {
|
|
988
|
+
d: 'M6 3.5L10.5 8L6 12.5',
|
|
989
|
+
stroke: 'currentColor',
|
|
990
|
+
strokeWidth: '1.5',
|
|
991
|
+
strokeLinecap: 'round',
|
|
992
|
+
strokeLinejoin: 'round',
|
|
993
|
+
}),
|
|
994
|
+
),
|
|
995
|
+
);
|
|
996
|
+
|
|
997
|
+
/**
|
|
998
|
+
* 一个参数格子:标签在上、控件在下(官方的 `modelAdvanced` 栅格就是这样)。
|
|
999
|
+
*
|
|
1000
|
+
* @param {string} key - React key 与控件 id。
|
|
1001
|
+
* @param {string} label - 12px 的小标签。
|
|
1002
|
+
* @param {object} control - 控件元素。
|
|
1003
|
+
* @param {string} [note] - 生效值一类的补充说明。
|
|
1004
|
+
* @returns {object} 一个栅格单元。
|
|
1005
|
+
*/
|
|
1006
|
+
const field = (key, label, control, note) => h(
|
|
1007
|
+
'div',
|
|
1008
|
+
{ className: 'dap-field', key },
|
|
1009
|
+
h('label', { htmlFor: key }, label),
|
|
1010
|
+
control,
|
|
1011
|
+
note === undefined ? null : h('span', { className: 'dap-field-note' }, note),
|
|
1012
|
+
);
|
|
1013
|
+
|
|
1014
|
+
/** 一个 `<select>` 的选项。 */
|
|
1015
|
+
const option = (value, label) => h('option', { value, key: value === '' ? 'auto' : value }, label);
|
|
1016
|
+
|
|
1017
|
+
/**
|
|
1018
|
+
* 一个字段旁边的注脚:当前生效的值,以及它从哪里来。
|
|
1019
|
+
*
|
|
1020
|
+
* 来源跟着**它描述的那个字段**走:「容量 1,048,576 · 来自 aperture」和输入框摆在一起
|
|
1021
|
+
* 才读得懂。把四项来源串成一句话挂在行尾,用户得自己把每一项对回去,而一张十一行模型
|
|
1022
|
+
* 的清单每行再挂一串,正文就被诊断信息盖住了。
|
|
1023
|
+
*
|
|
1024
|
+
* @param {string} value - 当前生效的值。
|
|
1025
|
+
* @param {string} [source] - 来源代号;没有来源时(例如协议是推导出来的)只说值。
|
|
1026
|
+
* @returns {string} 注脚。
|
|
1027
|
+
*/
|
|
1028
|
+
const inEffect = (value, source) => source === undefined
|
|
1029
|
+
? t('effectiveHint', { value })
|
|
1030
|
+
: t('effectiveSource', { value, source: t(SOURCE_KEYS[source] ?? source) });
|
|
1031
|
+
|
|
1032
|
+
/** 编辑面板里的一个文本输入框。 */
|
|
1033
|
+
const textField = (model, name, label, options = {}) => {
|
|
1034
|
+
const id = `dap-model-${model.id}-${name}`;
|
|
1035
|
+
return field(
|
|
1036
|
+
id,
|
|
1037
|
+
label,
|
|
1038
|
+
h('input', {
|
|
1039
|
+
id,
|
|
1040
|
+
className: 'dap-input',
|
|
1041
|
+
type: 'text',
|
|
1042
|
+
inputMode: options.numeric === true ? 'numeric' : undefined,
|
|
1043
|
+
spellCheck: false,
|
|
1044
|
+
autoComplete: 'off',
|
|
1045
|
+
placeholder: options.placeholder,
|
|
1046
|
+
value: draftOf(model)[name],
|
|
1047
|
+
disabled: !configuration.writable,
|
|
1048
|
+
onChange: (event) => edit(model, name, event.target.value),
|
|
1049
|
+
}),
|
|
1050
|
+
options.note,
|
|
1051
|
+
);
|
|
1052
|
+
};
|
|
1053
|
+
|
|
1054
|
+
/**
|
|
1055
|
+
* 一个模型的编辑面板:展开后才出现的全部字段,以及这一行的三个动作。
|
|
1056
|
+
*
|
|
1057
|
+
* 与官方那张卡片同一套形状——12px 圆角的面、`minmax(160px, 1fr)` 的参数栅格、
|
|
1058
|
+
* 12px 的小标签,右对齐的动作行(危险动作在左、主按钮在右)。
|
|
1059
|
+
*
|
|
1060
|
+
* @param {object} model - 报告里的一个模型。
|
|
1061
|
+
* @returns {object} 编辑面板。
|
|
1062
|
+
*/
|
|
1063
|
+
const editor = (model) => {
|
|
1064
|
+
const current = draftOf(model);
|
|
1065
|
+
const overridden = model.override !== undefined && Object.keys(model.override).length > 0;
|
|
1066
|
+
const { patch } = patchOf(current, initialOf(model));
|
|
1067
|
+
const count = (value) => (value === undefined ? '—' : formatCount(value));
|
|
1068
|
+
const modalities = model.input.length === 0
|
|
1069
|
+
? t('modalityNone')
|
|
1070
|
+
: model.input.map((item) => t(item === 'image' ? 'modalityImage' : 'modalityText')).join('+');
|
|
1071
|
+
const toggle = (name, id) => h(
|
|
1072
|
+
'label',
|
|
1073
|
+
{ className: 'dap-check', htmlFor: id },
|
|
1074
|
+
h('input', {
|
|
1075
|
+
id,
|
|
1076
|
+
type: 'checkbox',
|
|
1077
|
+
checked: current[name],
|
|
1078
|
+
disabled: !configuration.writable,
|
|
1079
|
+
onChange: (event) => edit(model, name, event.target.checked),
|
|
1080
|
+
}),
|
|
1081
|
+
t(name === 'text' ? 'modalityText' : 'modalityImage'),
|
|
1082
|
+
);
|
|
1083
|
+
|
|
1084
|
+
return h(
|
|
1085
|
+
'div',
|
|
1086
|
+
{ className: 'dap-editor' },
|
|
1087
|
+
h(
|
|
1088
|
+
'div',
|
|
1089
|
+
{ className: 'dap-editor-head' },
|
|
1090
|
+
h('code', { className: 'dap-editor-title dap-model-id' }, model.id),
|
|
1091
|
+
h('span', { className: 'dap-editor-route' }, [
|
|
1092
|
+
model.route === undefined ? t('unservedTag') : model.route,
|
|
1093
|
+
model.protocol === undefined ? undefined : ` · ${model.protocol}`,
|
|
1094
|
+
].filter((part) => part !== undefined).join('')),
|
|
1095
|
+
),
|
|
1096
|
+
h(
|
|
1097
|
+
'div',
|
|
1098
|
+
{ className: 'dap-fields' },
|
|
1099
|
+
textField(model, 'name', t('editName'), {
|
|
1100
|
+
placeholder: model.name,
|
|
1101
|
+
// 输入框里显示的就是这个值,注脚只要说它从哪儿来。
|
|
1102
|
+
note: t('sourceNote', { source: t(SOURCE_KEYS[model.provenance.name] ?? model.provenance.name) }),
|
|
1103
|
+
}),
|
|
1104
|
+
textField(model, 'alias', t('editAlias'), { placeholder: t('noAlias') }),
|
|
1105
|
+
textField(model, 'contextWindow', t('editContextWindow'), {
|
|
1106
|
+
numeric: true,
|
|
1107
|
+
note: inEffect(count(model.contextWindow), model.provenance.limits),
|
|
1108
|
+
}),
|
|
1109
|
+
textField(model, 'maxTokens', t('editMaxTokens'), {
|
|
1110
|
+
numeric: true,
|
|
1111
|
+
note: inEffect(count(model.maxTokens), model.provenance.limits),
|
|
1112
|
+
}),
|
|
1113
|
+
field(
|
|
1114
|
+
`dap-model-${model.id}-input`,
|
|
1115
|
+
t('editInput'),
|
|
1116
|
+
h(
|
|
1117
|
+
'div',
|
|
1118
|
+
{ className: 'dap-row' },
|
|
1119
|
+
toggle('text', `dap-model-${model.id}-text`),
|
|
1120
|
+
toggle('image', `dap-model-${model.id}-image`),
|
|
1121
|
+
),
|
|
1122
|
+
inEffect(modalities, model.provenance.input),
|
|
1123
|
+
),
|
|
1124
|
+
field(
|
|
1125
|
+
`dap-model-${model.id}-reasoning`,
|
|
1126
|
+
t('editReasoning'),
|
|
1127
|
+
h(
|
|
1128
|
+
'select',
|
|
1129
|
+
{
|
|
1130
|
+
id: `dap-model-${model.id}-reasoning`,
|
|
1131
|
+
className: 'dap-input',
|
|
1132
|
+
value: current.reasoning,
|
|
1133
|
+
disabled: !configuration.writable,
|
|
1134
|
+
onChange: (event) => edit(model, 'reasoning', event.target.value),
|
|
1135
|
+
},
|
|
1136
|
+
option('auto', t('optionAuto')),
|
|
1137
|
+
option('on', t('optionOn')),
|
|
1138
|
+
option('off', t('optionOff')),
|
|
1139
|
+
),
|
|
1140
|
+
inEffect(model.reasoning ? t('optionOn') : t('optionOff'), model.provenance.reasoning),
|
|
1141
|
+
),
|
|
1142
|
+
field(
|
|
1143
|
+
`dap-model-${model.id}-api`,
|
|
1144
|
+
t('editApi'),
|
|
1145
|
+
h(
|
|
1146
|
+
'select',
|
|
1147
|
+
{
|
|
1148
|
+
id: `dap-model-${model.id}-api`,
|
|
1149
|
+
className: 'dap-input',
|
|
1150
|
+
value: current.api,
|
|
1151
|
+
disabled: !configuration.writable,
|
|
1152
|
+
onChange: (event) => edit(model, 'api', event.target.value),
|
|
1153
|
+
},
|
|
1154
|
+
option('', t('optionAuto')),
|
|
1155
|
+
option('openai-completions', 'openai-completions'),
|
|
1156
|
+
option('anthropic-messages', 'anthropic-messages'),
|
|
1157
|
+
),
|
|
1158
|
+
// 协议是从通告的端点上推导出来的,没有来源可报,只说当前是哪一种。
|
|
1159
|
+
inEffect(model.protocol ?? '—'),
|
|
1160
|
+
),
|
|
1161
|
+
),
|
|
1162
|
+
h('p', { className: 'dap-field-note' }, t('editHint')),
|
|
1163
|
+
model.route === undefined ? h('p', { className: 'dap-field-note' }, t('unservedHint')) : null,
|
|
1164
|
+
h(
|
|
1165
|
+
'div',
|
|
1166
|
+
{ className: 'dap-actions', 'data-align': 'end' },
|
|
1167
|
+
overridden
|
|
1168
|
+
? h('button', {
|
|
1169
|
+
id: `dap-model-${model.id}-revert`,
|
|
1170
|
+
type: 'button',
|
|
1171
|
+
className: 'dap-button',
|
|
1172
|
+
'data-danger': 'true',
|
|
1173
|
+
disabled: disabled,
|
|
1174
|
+
onClick: () => clearOverrides(model),
|
|
1175
|
+
}, busy === 'revert' ? t('saving') : t('reset'))
|
|
1176
|
+
: null,
|
|
1177
|
+
h('button', {
|
|
1178
|
+
id: `dap-model-${model.id}-cancel`,
|
|
1179
|
+
type: 'button',
|
|
1180
|
+
className: 'dap-button',
|
|
1181
|
+
disabled: busy !== '',
|
|
1182
|
+
onClick: () => cancel(model),
|
|
1183
|
+
}, t('cancel')),
|
|
1184
|
+
h('button', {
|
|
1185
|
+
id: `dap-model-${model.id}-save`,
|
|
1186
|
+
type: 'button',
|
|
1187
|
+
className: 'dap-button',
|
|
1188
|
+
'data-primary': 'true',
|
|
1189
|
+
// 没改动就没什么可保存的(官方那张卡片的「应用」也是这样)。
|
|
1190
|
+
disabled: disabled || Object.keys(patch).length === 0,
|
|
1191
|
+
onClick: () => submit(model),
|
|
1192
|
+
}, busy === 'edit' ? t('saving') : t('save')),
|
|
1193
|
+
),
|
|
1194
|
+
);
|
|
1195
|
+
};
|
|
1196
|
+
|
|
1197
|
+
/** 一个模型一行:收起时只有 id、标签与生效的事实,点「编辑」才展开面板。 */
|
|
1198
|
+
const modelRow = (model) => {
|
|
1199
|
+
const { patch } = patchOf(draftOf(model), initialOf(model));
|
|
1200
|
+
const overridden = model.override !== undefined && Object.keys(model.override).length > 0;
|
|
1201
|
+
const open = opened[model.id] === true;
|
|
1202
|
+
|
|
1203
|
+
return h(
|
|
1204
|
+
'li',
|
|
1205
|
+
{ className: 'dap-model', key: model.id },
|
|
1206
|
+
h(
|
|
1207
|
+
'div',
|
|
1208
|
+
{ className: 'dap-model-head' },
|
|
1209
|
+
h(
|
|
1210
|
+
'span',
|
|
1211
|
+
{ className: 'dap-model-identity' },
|
|
1212
|
+
h('code', { className: 'dap-model-id' }, model.id),
|
|
1213
|
+
model.name === model.id ? null : h('span', { className: 'dap-model-name' }, model.name),
|
|
1214
|
+
),
|
|
1215
|
+
overridden ? h('span', { className: 'dap-tag' }, t('overridden')) : null,
|
|
1216
|
+
model.route === undefined ? h('span', { className: 'dap-tag' }, t('unservedTag')) : null,
|
|
1217
|
+
Object.keys(patch).length > 0 ? h('span', { className: 'dap-tag' }, t('pendingTag')) : null,
|
|
1218
|
+
h(
|
|
1219
|
+
'span',
|
|
1220
|
+
{ className: 'dap-model-actions' },
|
|
1221
|
+
h('button', {
|
|
1222
|
+
id: `dap-model-${model.id}-toggle`,
|
|
1223
|
+
type: 'button',
|
|
1224
|
+
className: 'dap-button',
|
|
1225
|
+
'aria-label': t('edit'),
|
|
1226
|
+
'aria-expanded': open ? 'true' : 'false',
|
|
1227
|
+
disabled: busy !== '',
|
|
1228
|
+
onClick: () => setOpened((state) => ({ ...state, [model.id]: !open })),
|
|
1229
|
+
}, chevron(open), open ? t('advancedHide') : t('edit')),
|
|
1230
|
+
),
|
|
1231
|
+
),
|
|
1232
|
+
h('div', { className: 'dap-model-facts' }, modelFacts(model)),
|
|
1233
|
+
model.route === undefined
|
|
1234
|
+
? h('p', { className: 'dap-model-meta' }, t('unservedEndpoints', {
|
|
1235
|
+
list: model.endpoints.length === 0 ? t('noEndpoints') : model.endpoints.join(', '),
|
|
1236
|
+
}))
|
|
1237
|
+
: null,
|
|
1238
|
+
open ? editor(model) : null,
|
|
1239
|
+
);
|
|
1240
|
+
};
|
|
1241
|
+
|
|
1242
|
+
/** 一条路由的分组头:`provider · 协议` 一行,`→ 地址 · N 个模型` 一行。 */
|
|
1243
|
+
const groupHead = (title, meta) => h(
|
|
1244
|
+
'div',
|
|
1245
|
+
{ className: 'dap-group-head' },
|
|
1246
|
+
h('span', { className: 'dap-group-title' }, title),
|
|
1247
|
+
h('span', { className: 'dap-group-meta' }, meta),
|
|
1248
|
+
);
|
|
1249
|
+
|
|
1250
|
+
/**
|
|
1251
|
+
* 模型清单:先按路由分组,最后是没有任何路由能服务的那些。
|
|
1252
|
+
*
|
|
1253
|
+
* 头部只说一句「已覆盖几个,其余沿用发现值与清单」(官方「模型」卡片左半边那句);
|
|
1254
|
+
* 右边没有官方的「撤销全部覆盖」——这里按行改,撤销也按行做,一次管一整份清单的动作
|
|
1255
|
+
* 没有对应场景。
|
|
1256
|
+
*
|
|
1257
|
+
* 每一行收起时只是一条事实,点「编辑」才展开面板:报告是这张标签页的主要用途,不该被
|
|
1258
|
+
* 一地输入框淹掉。
|
|
1259
|
+
*
|
|
1260
|
+
* @param {object} current - 报告。
|
|
1261
|
+
* @returns {object} 模型段。
|
|
1262
|
+
*/
|
|
1263
|
+
const modelList = (current) => {
|
|
1264
|
+
const overridden = current.models.filter(
|
|
1265
|
+
(model) => model.override !== undefined && Object.keys(model.override).length > 0,
|
|
1266
|
+
);
|
|
1267
|
+
|
|
1268
|
+
const head = h(
|
|
1269
|
+
'div',
|
|
1270
|
+
{ className: 'dap-row' },
|
|
1271
|
+
h(
|
|
1272
|
+
'div',
|
|
1273
|
+
{ className: 'dap-head' },
|
|
1274
|
+
h('div', { className: 'dap-title' }, t('modelsHeading')),
|
|
1275
|
+
h('p', { className: 'dap-hint' }, overridden.length === 0
|
|
1276
|
+
? t('modelsMetaInherit')
|
|
1277
|
+
: t('modelsMetaOverride', { count: overridden.length })),
|
|
1278
|
+
),
|
|
1279
|
+
);
|
|
1280
|
+
|
|
1281
|
+
if (current.models.length === 0) {
|
|
1282
|
+
return [
|
|
1283
|
+
head,
|
|
1284
|
+
h('p', { className: 'dap-hint' }, current.refresh !== undefined && current.refresh.error !== undefined
|
|
1285
|
+
? t('modelsError', { error: current.refresh.error })
|
|
1286
|
+
: t('noModels')),
|
|
1287
|
+
];
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
const groups = [];
|
|
1291
|
+
for (const route of current.routes) {
|
|
1292
|
+
const models = current.models.filter((model) => model.route === route.provider);
|
|
1293
|
+
if (models.length === 0) continue;
|
|
1294
|
+
const title = route.api === undefined ? route.provider : `${route.provider} · ${route.api}`;
|
|
1295
|
+
const meta = [
|
|
1296
|
+
route.baseURL === undefined ? undefined : `→ ${route.baseURL}`,
|
|
1297
|
+
t('modelsCount', { count: models.length }),
|
|
1298
|
+
].filter((part) => part !== undefined).join(' · ');
|
|
1299
|
+
groups.push(h(
|
|
1300
|
+
'div',
|
|
1301
|
+
{ className: 'dap-group', key: route.provider },
|
|
1302
|
+
groupHead(title, meta),
|
|
1303
|
+
h('ul', { className: 'dap-models' }, models.map(modelRow)),
|
|
1304
|
+
));
|
|
1305
|
+
}
|
|
1306
|
+
const unserved = current.models.filter((model) => model.route === undefined);
|
|
1307
|
+
if (unserved.length > 0) {
|
|
1308
|
+
groups.push(h(
|
|
1309
|
+
'div',
|
|
1310
|
+
{ className: 'dap-group', key: 'unserved' },
|
|
1311
|
+
groupHead(t('unservedHeading'), t('modelsCount', { count: unserved.length })),
|
|
1312
|
+
h('ul', { className: 'dap-models' }, unserved.map(modelRow)),
|
|
1313
|
+
));
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
return [head, groups];
|
|
1317
|
+
};
|
|
1318
|
+
|
|
1319
|
+
return h(
|
|
1320
|
+
'div',
|
|
1321
|
+
{ [STYLE_MARK]: '', 'aria-busy': busy !== '' ? 'true' : 'false' },
|
|
1322
|
+
h(
|
|
1323
|
+
'div',
|
|
1324
|
+
null,
|
|
1325
|
+
h('div', { className: 'dap-title' }, t('title')),
|
|
1326
|
+
h('p', { className: 'dap-subtitle' }, dormant ? t('addressDormant') : t('subtitle')),
|
|
1327
|
+
),
|
|
1328
|
+
|
|
1329
|
+
h(
|
|
1330
|
+
'div',
|
|
1331
|
+
{ className: 'dap-section' },
|
|
1332
|
+
h(
|
|
1333
|
+
'div',
|
|
1334
|
+
{ className: 'dap-row' },
|
|
1335
|
+
h('label', { className: 'dap-label', htmlFor: 'dap-base-url' }, t('addressLabel')),
|
|
1336
|
+
h('input', {
|
|
1337
|
+
id: 'dap-base-url',
|
|
1338
|
+
className: 'dap-input',
|
|
1339
|
+
type: 'text',
|
|
1340
|
+
spellCheck: false,
|
|
1341
|
+
autoComplete: 'off',
|
|
1342
|
+
placeholder: t('addressPlaceholder'),
|
|
1343
|
+
value: draft.baseUrl,
|
|
1344
|
+
disabled,
|
|
1345
|
+
onChange: (event) => setDraft({ baseUrl: event.target.value, sync: draft.sync }),
|
|
1346
|
+
}),
|
|
1347
|
+
configuration.baseUrlOverridden
|
|
1348
|
+
? h('span', { className: 'dap-tag' }, t('overridden'))
|
|
1349
|
+
: null,
|
|
1350
|
+
configuration.baseUrlOverridden
|
|
1351
|
+
? h('button', {
|
|
1352
|
+
type: 'button',
|
|
1353
|
+
className: 'dap-button',
|
|
1354
|
+
disabled,
|
|
1355
|
+
onClick: () => run('reset', () => panel.save(null, undefined), () => setConfigRevision((value) => value + 1)),
|
|
1356
|
+
}, t('reset'))
|
|
1357
|
+
: null,
|
|
1358
|
+
),
|
|
1359
|
+
h(
|
|
1360
|
+
'div',
|
|
1361
|
+
{ className: 'dap-row' },
|
|
1362
|
+
h(
|
|
1363
|
+
'label',
|
|
1364
|
+
{ className: 'dap-check', htmlFor: 'dap-sync' },
|
|
1365
|
+
h('input', {
|
|
1366
|
+
id: 'dap-sync',
|
|
1367
|
+
type: 'checkbox',
|
|
1368
|
+
checked: draft.sync,
|
|
1369
|
+
disabled,
|
|
1370
|
+
onChange: (event) => setDraft({ baseUrl: draft.baseUrl, sync: event.target.checked }),
|
|
1371
|
+
}),
|
|
1372
|
+
t('syncLabel'),
|
|
1373
|
+
),
|
|
1374
|
+
h('span', { className: 'dap-tag' }, draft.sync ? t('syncOn') : t('syncOff')),
|
|
1375
|
+
configuration.syncOverridden
|
|
1376
|
+
? h('span', { className: 'dap-tag' }, t('overridden'))
|
|
1377
|
+
: null,
|
|
1378
|
+
),
|
|
1379
|
+
configuration.writable ? null : h('p', { className: 'dap-banner', 'data-ok': 'false' }, t('readOnly')),
|
|
1380
|
+
h(
|
|
1381
|
+
'div',
|
|
1382
|
+
{ className: 'dap-actions' },
|
|
1383
|
+
h('button', {
|
|
1384
|
+
type: 'button',
|
|
1385
|
+
className: 'dap-button',
|
|
1386
|
+
'data-primary': 'true',
|
|
1387
|
+
disabled: disabled || !dirty,
|
|
1388
|
+
onClick: () => run('save', () => panel.save(draft.baseUrl, draft.sync), () => {
|
|
1389
|
+
setConfigRevision((value) => value + 1);
|
|
1390
|
+
setReportRevision((value) => value + 1);
|
|
1391
|
+
}),
|
|
1392
|
+
}, busy === 'save' ? t('saving') : t('save')),
|
|
1393
|
+
h('button', {
|
|
1394
|
+
type: 'button',
|
|
1395
|
+
className: 'dap-button',
|
|
1396
|
+
disabled: busy !== '' || !dirty,
|
|
1397
|
+
onClick: () => setDraft({ baseUrl: configuration.baseUrl, sync: configuration.sync }),
|
|
1398
|
+
}, t('cancel')),
|
|
1399
|
+
),
|
|
1400
|
+
),
|
|
1401
|
+
|
|
1402
|
+
h(
|
|
1403
|
+
'div',
|
|
1404
|
+
{ className: 'dap-section' },
|
|
1405
|
+
h(
|
|
1406
|
+
'div',
|
|
1407
|
+
{ className: 'dap-actions' },
|
|
1408
|
+
h('button', {
|
|
1409
|
+
type: 'button',
|
|
1410
|
+
className: 'dap-button',
|
|
1411
|
+
disabled,
|
|
1412
|
+
onClick: () => run('refresh', () => panel.refresh(), () => setReportRevision((value) => value + 1)),
|
|
1413
|
+
}, busy === 'refresh' ? t('refreshing') : t('refresh')),
|
|
1414
|
+
h('button', {
|
|
1415
|
+
type: 'button',
|
|
1416
|
+
className: 'dap-button',
|
|
1417
|
+
disabled,
|
|
1418
|
+
onClick: () => run('withdraw', () => panel.withdraw(), () => setReportRevision((value) => value + 1)),
|
|
1419
|
+
}, busy === 'withdraw' ? t('withdrawing') : t('withdraw')),
|
|
1420
|
+
),
|
|
1421
|
+
banner === null
|
|
1422
|
+
? null
|
|
1423
|
+
: h('p', { className: 'dap-banner', 'data-ok': banner.ok ? 'true' : 'false' }, banner.text),
|
|
1424
|
+
report === null
|
|
1425
|
+
? null
|
|
1426
|
+
: h('p', { className: 'dap-hint' }, `Aperture:${report.place.length === 0 ? t('noAddress') : report.place}`),
|
|
1427
|
+
),
|
|
1428
|
+
|
|
1429
|
+
report === null
|
|
1430
|
+
? null
|
|
1431
|
+
: h(
|
|
1432
|
+
'div',
|
|
1433
|
+
{ className: 'dap-section' },
|
|
1434
|
+
h('div', { className: 'dap-title' }, t('statusHeading')),
|
|
1435
|
+
statusFacts(report),
|
|
1436
|
+
),
|
|
1437
|
+
|
|
1438
|
+
report === null
|
|
1439
|
+
? null
|
|
1440
|
+
: h('div', { className: 'dap-section' }, modelList(report)),
|
|
1441
|
+
);
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
// ---------------------------------------------------------------- 插件本体
|
|
1445
|
+
|
|
1446
|
+
/**
|
|
1447
|
+
* 把 `aperturePanel` 贡献挂到客户端的 Remote 服务上。
|
|
1448
|
+
*
|
|
1449
|
+
* `apply` 必须保持同步:宿主 Cordis 会卸载 async apply 里 `await` 之后注册的
|
|
1450
|
+
* `ctx.effect`。因此异步的 `$mount` 在一个**同步注册**的 effect 工厂内部完成,失败
|
|
1451
|
+
* 落 console.error。
|
|
1452
|
+
*
|
|
1453
|
+
* @param {object} ctx - 客户端根上下文。
|
|
1454
|
+
*/
|
|
1455
|
+
function mountRemote(ctx) {
|
|
1456
|
+
ctx.effect(() => {
|
|
1457
|
+
let mounted = null;
|
|
1458
|
+
let pending = true;
|
|
1459
|
+
let unloaded = false;
|
|
1460
|
+
void (async () => {
|
|
1461
|
+
try {
|
|
1462
|
+
mounted = await ctx.remote.$mount(REMOTE);
|
|
1463
|
+
} catch (error) {
|
|
1464
|
+
console.error('dsh-aperture: aperturePanel 贡献挂载失败', error);
|
|
1465
|
+
}
|
|
1466
|
+
pending = false;
|
|
1467
|
+
if (unloaded) void mounted?.();
|
|
1468
|
+
})();
|
|
1469
|
+
return () => {
|
|
1470
|
+
unloaded = true;
|
|
1471
|
+
if (!pending) void mounted?.();
|
|
1472
|
+
};
|
|
1473
|
+
}, 'dsh-aperture: remote contribution');
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
/**
|
|
1477
|
+
* 浏览器插件主体:字典、样式、Remote 贡献,以及插件标签页。
|
|
1478
|
+
*
|
|
1479
|
+
* `ctx.slots.inject` 是必需的,不是可选的:`settings.plugins.tab` 由设置区自己声明,
|
|
1480
|
+
* 那个声明完全可能在本插件 `apply` 之后才发生,直接 register 会撞上「槽位尚未声明」。
|
|
1481
|
+
*
|
|
1482
|
+
* @param {object} ctx - 客户端根上下文。
|
|
1483
|
+
*/
|
|
1484
|
+
function apply(ctx) {
|
|
1485
|
+
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'dsh-aperture: dictionaries');
|
|
1486
|
+
ctx.effect(() => installStyles(), 'dsh-aperture: stylesheet');
|
|
1487
|
+
mountRemote(ctx);
|
|
1488
|
+
|
|
1489
|
+
ctx.inject(['remote.aperturePanel'], (scope) => {
|
|
1490
|
+
const t = scope.locale.bind(NS);
|
|
1491
|
+
const namespace = () => scope.remote.aperturePanel;
|
|
1492
|
+
const panel = {
|
|
1493
|
+
status: async () => unwrap(await namespace().status()),
|
|
1494
|
+
refresh: async () => unwrap(await namespace().refresh()),
|
|
1495
|
+
withdraw: async () => unwrap(await namespace().withdraw()),
|
|
1496
|
+
configuration: async () => unwrap(await namespace().configuration()),
|
|
1497
|
+
save: async (baseUrl, sync) => unwrap(await namespace().save(baseUrl, sync)),
|
|
1498
|
+
edit: async (id, patch) => unwrap(await namespace().edit(id, patch)),
|
|
1499
|
+
};
|
|
1500
|
+
scope.slots.inject('settings.plugins.tab', () => scope.slots.register({
|
|
1501
|
+
name: 'settings.plugins.tab',
|
|
1502
|
+
id: 'aperture',
|
|
1503
|
+
order: 40,
|
|
1504
|
+
label: () => t('tab'),
|
|
1505
|
+
locale: NS,
|
|
1506
|
+
inject: () => ({ panel }),
|
|
1507
|
+
}, ApertureTab));
|
|
1508
|
+
});
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
const module = { exports: {} };
|
|
1512
|
+
module.exports.name = PACKAGE;
|
|
1513
|
+
/** 本插件依赖的客户端服务:槽位、字典与 Remote 调用面。 */
|
|
1514
|
+
module.exports.inject = ['slots', 'locale', 'remote'];
|
|
1515
|
+
module.exports.apply = apply;
|
|
1516
|
+
/** 字典命名空间(测试与排查用)。 */
|
|
1517
|
+
module.exports.NS = NS;
|
|
1518
|
+
/** 上报给 Remote 注册表的贡献(测试与排查用)。 */
|
|
1519
|
+
module.exports.REMOTE = REMOTE;
|
|
1520
|
+
return module.exports;
|
|
1521
|
+
},
|
|
1522
|
+
});
|