dsh-aperture 0.2.0 → 0.3.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/README.en.md +93 -120
- package/README.md +83 -121
- package/client/aperture.js +1175 -1131
- package/cordis.patch.yml +33 -44
- package/icon.svg +125 -0
- package/lib/aperture.d.ts +6 -8
- package/lib/aperture.js +6 -8
- package/lib/catalog.d.ts +0 -2
- package/lib/catalog.js +0 -4
- package/lib/config.d.ts +106 -89
- package/lib/config.js +79 -37
- package/lib/index.d.ts +28 -31
- package/lib/index.js +46 -52
- package/lib/metadata/extract.d.ts +7 -13
- package/lib/metadata/extract.js +7 -25
- package/lib/metadata/modelsdev.d.ts +9 -11
- package/lib/metadata/modelsdev.js +21 -23
- package/lib/metadata/utils.d.ts +0 -2
- package/lib/metadata/utils.js +0 -14
- package/lib/panel.d.ts +29 -56
- package/lib/panel.js +83 -91
- package/lib/profile.d.ts +5 -13
- package/lib/profile.js +25 -28
- package/lib/registry.d.ts +10 -15
- package/lib/registry.js +23 -21
- package/lib/remote.d.ts +14 -29
- package/lib/remote.js +13 -37
- package/lib/report.d.ts +24 -19
- package/lib/report.js +21 -29
- package/lib/runtime.d.ts +18 -12
- package/lib/runtime.js +40 -32
- package/lib/sync.d.ts +12 -25
- package/lib/sync.js +41 -55
- package/lib/types.d.ts +3 -5
- package/lib/types.js +3 -3
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +24 -16
- package/lib/namespaces.d.ts +0 -12
- package/lib/namespaces.js +0 -12
package/lib/remote.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 配置页与宿主之间的 Typert Remote 面:`aperturePanel` 命名空间。
|
|
3
3
|
*
|
|
4
|
-
* 描述符是手工登记的,因为生成它们的 Typert 生成器并不随 DSH
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* 描述符是手工登记的,因为生成它们的 Typert 生成器并不随 DSH 发布,而这一步的规范本身很小:
|
|
5
|
+
* 宿主半边用 `src-json` 编解码器,浏览器半边带 strict 校验,两端共享同一组端点名;参数按描述符
|
|
6
|
+
* 里的顺序位置传入宿主方法,因此两边的名字与顺序必须一致。
|
|
7
7
|
*
|
|
8
|
-
* 端点 id 的 `#` 之前是包名,之后是
|
|
9
|
-
* 共用的文法一致。
|
|
8
|
+
* 端点 id 的 `#` 之前是包名,之后是 `<命名空间>/<方法>`。
|
|
10
9
|
*
|
|
11
10
|
* @module dsh-aperture/remote
|
|
12
11
|
*/
|
|
@@ -36,27 +35,22 @@ function panelDescriptor(method, parameters = []) {
|
|
|
36
35
|
/**
|
|
37
36
|
* 本插件暴露给浏览器的全部端点。
|
|
38
37
|
*
|
|
39
|
-
* 端点名有一处不显眼的约束:api-gateway 在客户端为每个命名空间建一个
|
|
40
|
-
* `
|
|
41
|
-
* `
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* `assertMethodAvailable` / `remove` —— 「撤下路由」因此叫 `withdraw` 而不是 `remove`。
|
|
38
|
+
* 端点名有一处不显眼的约束:api-gateway 在客户端为每个命名空间建一个 `RemoteNamespaceService`,
|
|
39
|
+
* 端点会成为它的属性,因此与它自己的成员重名会被 `validateContribution` 拒绝,**整份贡献一起
|
|
40
|
+
* 撤回**(浏览器里只剩一行 console.error,界面安静地什么都不出现)。预置名有 `ctx` / `empty` /
|
|
41
|
+
* `invokeRemote` / `methods` / `name` / `namespace` 与 `has` / `install` / `installDirect` /
|
|
42
|
+
* `installScoped` / `assertMethodAvailable` / `remove`——新端点起名时先对一遍这份名单。
|
|
45
43
|
*/
|
|
46
44
|
export const PANEL_INVOCATIONS = [
|
|
47
45
|
panelDescriptor('status'),
|
|
48
46
|
panelDescriptor('refresh'),
|
|
49
|
-
panelDescriptor('withdraw'),
|
|
50
|
-
panelDescriptor('configuration'),
|
|
51
|
-
panelDescriptor('save', ['baseUrl', 'sync']),
|
|
52
47
|
panelDescriptor('edit', ['id', 'patch']),
|
|
53
48
|
];
|
|
54
49
|
/**
|
|
55
50
|
* 登记进 Typert 注册表的贡献。
|
|
56
51
|
*
|
|
57
|
-
* `schemas`/`model`
|
|
58
|
-
*
|
|
59
|
-
* 带 strict 校验,两者按同一份契约工作。
|
|
52
|
+
* `schemas`/`model` 是生成器的产物,这里没有生成器,因此它们如实为空:本插件不导出可复用的
|
|
53
|
+
* schema,也没有需要反射的业务类型。端点本身仍然完整。
|
|
60
54
|
*/
|
|
61
55
|
export const PANEL_CONTRIBUTION = {
|
|
62
56
|
package: PANEL_PACKAGE,
|
|
@@ -68,7 +62,7 @@ export const PANEL_CONTRIBUTION = {
|
|
|
68
62
|
/**
|
|
69
63
|
* `aperturePanel` 宿主服务:方法与描述符一一对应,实现全部委托给 {@link PanelOps}。
|
|
70
64
|
*
|
|
71
|
-
* 方法签名必须与描述符的参数顺序一致——`
|
|
65
|
+
* 方法签名必须与描述符的参数顺序一致——`edit` 的两个形参名字与描述符里的两个参数同名,
|
|
72
66
|
* 顺序也相同,网关就是按描述符顺序把 wire 参数位置传入的。
|
|
73
67
|
*/
|
|
74
68
|
export class AperturePanelService extends TypertRemoteService {
|
|
@@ -89,24 +83,6 @@ export class AperturePanelService extends TypertRemoteService {
|
|
|
89
83
|
refresh() {
|
|
90
84
|
return this.ops.refresh();
|
|
91
85
|
}
|
|
92
|
-
/** 撤下本插件发布的路由。方法名受端点名约束,见 {@link PANEL_INVOCATIONS}。 */
|
|
93
|
-
withdraw() {
|
|
94
|
-
return this.ops.withdraw();
|
|
95
|
-
}
|
|
96
|
-
/** 标签页表单要显示的配置。 */
|
|
97
|
-
configuration() {
|
|
98
|
-
return this.ops.configuration();
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* 写入配置。
|
|
102
|
-
*
|
|
103
|
-
* @param baseUrl - 新地址;`null` 撤销覆盖,`undefined` 不碰。
|
|
104
|
-
* @param sync - 新开关;`undefined` 不碰。
|
|
105
|
-
* @returns 成败与一句人话。
|
|
106
|
-
*/
|
|
107
|
-
save(baseUrl, sync) {
|
|
108
|
-
return this.ops.save(baseUrl, sync);
|
|
109
|
-
}
|
|
110
86
|
/**
|
|
111
87
|
* 写入一个模型的参数。
|
|
112
88
|
*
|
package/lib/report.d.ts
CHANGED
|
@@ -1,25 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 报告:配置页的状态段与模型清单。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* 这里是**结构化数据**,不是拼好的句子:配置页是双语的,把中文句子拼在宿主半边就等于让英文
|
|
5
|
+
* 界面显示中文,而「哪个模型属于哪条路由」「这条事实是谁给的」本来就是数据。宿主只把发现过程
|
|
6
|
+
* 决定了什么摆齐——哪个端点应答了、哪些模型进了哪条路由、哪个模型没有端点能服务、每条事实来自
|
|
7
|
+
* 哪里、哪些字段是用户写下的覆盖——措辞与排版交给界面。
|
|
8
8
|
*
|
|
9
9
|
* @module dsh-aperture/report
|
|
10
10
|
*/
|
|
11
11
|
import type { ResolvedConfig } from './config.ts';
|
|
12
12
|
import type { RefreshOutcome } from './runtime.ts';
|
|
13
13
|
import type { FactSource, Modality } from './types.ts';
|
|
14
|
-
/** 报告里的一个模型的覆盖(`aperture.models` 里对应那一条)。 */
|
|
15
|
-
export interface PanelModelOverride {
|
|
16
|
-
readonly name?: string;
|
|
17
|
-
readonly api?: string;
|
|
18
|
-
readonly contextWindow?: number;
|
|
19
|
-
readonly maxTokens?: number;
|
|
20
|
-
readonly input?: readonly Modality[];
|
|
21
|
-
readonly thinking?: boolean;
|
|
22
|
-
}
|
|
23
14
|
/** 报告里的一个模型。 */
|
|
24
15
|
export interface PanelModel {
|
|
25
16
|
/** Aperture 接受的模型 id。 */
|
|
@@ -47,8 +38,14 @@ export interface PanelModel {
|
|
|
47
38
|
readonly input: FactSource;
|
|
48
39
|
readonly name: FactSource;
|
|
49
40
|
};
|
|
50
|
-
/**
|
|
51
|
-
|
|
41
|
+
/**
|
|
42
|
+
* 用户层里这一行自己写下的键(含界面不编辑的,例如 `reasoningEfforts`;别名写成 `alias`)。
|
|
43
|
+
*
|
|
44
|
+
* 这是「覆盖」的唯一判据,且只能从用户层读——官方也是这么定义的:看字段在不在用户层里,
|
|
45
|
+
* 而不是拿值与默认值比。解析后的配置用不得:schema 会把没写的数组字段补成 `[]`,界面就会
|
|
46
|
+
* 在一行什么都没写过的模型上挂一颗永远撤不掉的「已覆盖」。
|
|
47
|
+
*/
|
|
48
|
+
readonly overrideKeys?: readonly string[];
|
|
52
49
|
/** 用户写下的清单别名(`aperture.modelAliases` 里对应那一项)。 */
|
|
53
50
|
readonly alias?: string;
|
|
54
51
|
}
|
|
@@ -97,7 +94,7 @@ export interface PanelRefresh {
|
|
|
97
94
|
readonly reason?: string;
|
|
98
95
|
};
|
|
99
96
|
}
|
|
100
|
-
/**
|
|
97
|
+
/** 配置页要显示的整份报告。 */
|
|
101
98
|
export interface PanelReport {
|
|
102
99
|
/** 实例地址(已归一化);没有配置时为空串,措辞交给界面。 */
|
|
103
100
|
readonly place: string;
|
|
@@ -108,11 +105,19 @@ export interface PanelReport {
|
|
|
108
105
|
/** 逐模型清单:先是各条路由承载的模型,最后是没有任何路由的模型。 */
|
|
109
106
|
readonly models: readonly PanelModel[];
|
|
110
107
|
}
|
|
108
|
+
/** 用户层里写下的东西:报告要照着它说「哪些是这一行自己写的」。 */
|
|
109
|
+
export interface DeclaredOverrides {
|
|
110
|
+
/** 用户层 `aperture.models` 的原样条目。 */
|
|
111
|
+
readonly models?: readonly Record<string, unknown>[];
|
|
112
|
+
/** 用户层 `aperture.modelAliases` 里写过的模型 id。 */
|
|
113
|
+
readonly aliasIds?: readonly string[];
|
|
114
|
+
}
|
|
111
115
|
/**
|
|
112
116
|
* 组装报告。
|
|
113
117
|
*
|
|
114
118
|
* @param outcome - 最近一次刷新;一次都没完成过时传 `undefined`。
|
|
115
|
-
* @param config -
|
|
119
|
+
* @param config - 当前生效配置。
|
|
120
|
+
* @param declared - 用户层里写下的覆盖;缺省即「什么都没写过」。
|
|
116
121
|
* @returns 报告。
|
|
117
122
|
*/
|
|
118
|
-
export declare function buildReport(outcome: RefreshOutcome | undefined, config: ResolvedConfig): PanelReport;
|
|
123
|
+
export declare function buildReport(outcome: RefreshOutcome | undefined, config: ResolvedConfig, declared?: DeclaredOverrides): PanelReport;
|
package/lib/report.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 报告:配置页的状态段与模型清单。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* 这里是**结构化数据**,不是拼好的句子:配置页是双语的,把中文句子拼在宿主半边就等于让英文
|
|
5
|
+
* 界面显示中文,而「哪个模型属于哪条路由」「这条事实是谁给的」本来就是数据。宿主只把发现过程
|
|
6
|
+
* 决定了什么摆齐——哪个端点应答了、哪些模型进了哪条路由、哪个模型没有端点能服务、每条事实来自
|
|
7
|
+
* 哪里、哪些字段是用户写下的覆盖——措辞与排版交给界面。
|
|
8
8
|
*
|
|
9
9
|
* @module dsh-aperture/report
|
|
10
10
|
*/
|
|
@@ -12,11 +12,22 @@
|
|
|
12
12
|
* 组装报告。
|
|
13
13
|
*
|
|
14
14
|
* @param outcome - 最近一次刷新;一次都没完成过时传 `undefined`。
|
|
15
|
-
* @param config -
|
|
15
|
+
* @param config - 当前生效配置。
|
|
16
|
+
* @param declared - 用户层里写下的覆盖;缺省即「什么都没写过」。
|
|
16
17
|
* @returns 报告。
|
|
17
18
|
*/
|
|
18
|
-
export function buildReport(outcome, config) {
|
|
19
|
-
const
|
|
19
|
+
export function buildReport(outcome, config, declared = {}) {
|
|
20
|
+
const keys = new Map();
|
|
21
|
+
for (const entry of declared.models ?? []) {
|
|
22
|
+
const id = typeof entry.id === 'string' ? entry.id.trim() : '';
|
|
23
|
+
if (id.length === 0)
|
|
24
|
+
continue;
|
|
25
|
+
keys.set(id, Object.keys(entry).filter((key) => key !== 'id'));
|
|
26
|
+
}
|
|
27
|
+
for (const id of declared.aliasIds ?? []) {
|
|
28
|
+
// 别名是另一张表,但对界面来说它是这一行的覆盖之一:撤的时候一起撤。
|
|
29
|
+
keys.set(id, [...(keys.get(id) ?? []), 'alias']);
|
|
30
|
+
}
|
|
20
31
|
const routes = (outcome?.routes ?? []).map((route) => ({
|
|
21
32
|
provider: route.provider,
|
|
22
33
|
...(route.profile.api === undefined ? {} : { api: route.profile.api }),
|
|
@@ -27,7 +38,7 @@ export function buildReport(outcome, config) {
|
|
|
27
38
|
const routed = new Set();
|
|
28
39
|
const describe = (model, route) => {
|
|
29
40
|
routed.add(model.id);
|
|
30
|
-
const
|
|
41
|
+
const declaredKeys = keys.get(model.id) ?? [];
|
|
31
42
|
const alias = config.modelAliases[model.id];
|
|
32
43
|
return {
|
|
33
44
|
id: model.id,
|
|
@@ -40,7 +51,7 @@ export function buildReport(outcome, config) {
|
|
|
40
51
|
input: model.input,
|
|
41
52
|
reasoning: model.reasoning,
|
|
42
53
|
provenance: model.provenance,
|
|
43
|
-
...(
|
|
54
|
+
...(declaredKeys.length === 0 ? {} : { overrideKeys: declaredKeys }),
|
|
44
55
|
...(alias === undefined ? {} : { alias }),
|
|
45
56
|
};
|
|
46
57
|
};
|
|
@@ -60,25 +71,6 @@ export function buildReport(outcome, config) {
|
|
|
60
71
|
models,
|
|
61
72
|
};
|
|
62
73
|
}
|
|
63
|
-
/**
|
|
64
|
-
* 把一条覆盖收成报告要显示的那几个字段。
|
|
65
|
-
*
|
|
66
|
-
* `reasoningEfforts` 这类界面不编辑的字段不报出去:写入是按字段合并的,界面没提到的字段原样
|
|
67
|
-
* 留在设置文档里,因此不必(也不该)把它搬进报告再搬回去。
|
|
68
|
-
*
|
|
69
|
-
* @param entry - `aperture.models` 里的一条。
|
|
70
|
-
* @returns 只含界面会显示与编辑的字段的覆盖。
|
|
71
|
-
*/
|
|
72
|
-
function trim(entry) {
|
|
73
|
-
return {
|
|
74
|
-
...(entry.name === undefined ? {} : { name: entry.name }),
|
|
75
|
-
...(entry.api === undefined ? {} : { api: entry.api }),
|
|
76
|
-
...(entry.contextWindow === undefined ? {} : { contextWindow: entry.contextWindow }),
|
|
77
|
-
...(entry.maxTokens === undefined ? {} : { maxTokens: entry.maxTokens }),
|
|
78
|
-
...(entry.input === undefined ? {} : { input: entry.input }),
|
|
79
|
-
...(entry.thinking === undefined ? {} : { thinking: entry.thinking }),
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
74
|
/**
|
|
83
75
|
* 把一次刷新收成报告要显示的字段。
|
|
84
76
|
*
|
package/lib/runtime.d.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 发现运行时:同一时刻只跑一次刷新,只记住一个结果。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* 刷新有四个来路(插件加载、设置变更、刷新间隔、配置页),其中两条容易重叠——本插件写入的
|
|
5
|
+
* 设置变更会唤醒触发这次写入的同一个 watcher。因此刷新是单飞的:途中到达的请求若正在跑的那
|
|
6
|
+
* 一轮读的就是此刻这份配置就并进它,否则排在它后面(见 {@link ApertureRuntime.refresh});
|
|
7
|
+
* 排队者共享同一轮,所以再多的调用方也只多跑一轮。
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
* 文档里已经生效的那一份。
|
|
9
|
+
* 记住的结果只是设置文档里那份的影子:配置页报告它,真正服务请求的是文档里已生效的那份。
|
|
11
10
|
*
|
|
12
11
|
* @module dsh-aperture/runtime
|
|
13
12
|
*/
|
|
14
|
-
import type {
|
|
13
|
+
import type { SettingsForms } from '@deepseek-ai/dsh-settings';
|
|
15
14
|
import { ModelCatalog, type CatalogLoad } from './catalog.ts';
|
|
16
15
|
import { type ResolvedConfig } from './config.ts';
|
|
17
16
|
import { type RoutePlan } from './profile.ts';
|
|
@@ -56,7 +55,7 @@ export interface RuntimeDeps {
|
|
|
56
55
|
/** 当前生效的配置,每次刷新都会重新读取。 */
|
|
57
56
|
readonly config: () => ResolvedConfig;
|
|
58
57
|
/** 设置服务;插件把它声明为必需注入。 */
|
|
59
|
-
readonly settings:
|
|
58
|
+
readonly settings: SettingsForms;
|
|
60
59
|
/** 具名 logger。 */
|
|
61
60
|
readonly logger: RuntimeLogger;
|
|
62
61
|
/** models.dev 缓存,在各次刷新之间共享。 */
|
|
@@ -66,7 +65,8 @@ export interface RuntimeDeps {
|
|
|
66
65
|
export declare class ApertureRuntime {
|
|
67
66
|
private readonly deps;
|
|
68
67
|
private running;
|
|
69
|
-
|
|
68
|
+
/** 正在跑的那一轮读的是哪一份配置;用来判断排队者该并进它还是排到它后面。 */
|
|
69
|
+
private runningConfig;
|
|
70
70
|
private latest;
|
|
71
71
|
/**
|
|
72
72
|
* @param deps - 宿主服务与配置活引用(thunk)。
|
|
@@ -75,9 +75,15 @@ export declare class ApertureRuntime {
|
|
|
75
75
|
/** 最近一次已完成的刷新(如果完成过)。 */
|
|
76
76
|
last(): RefreshOutcome | undefined;
|
|
77
77
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
78
|
+
* 刷新;已有刷新在运行时,等它收尾之后再决定是并进新的一轮,还是自己起一轮。
|
|
79
|
+
*
|
|
80
|
+
* 承诺是「返回的那一轮读的是**此刻**的配置」:正在跑的那一轮若读的就是此刻这份配置,
|
|
81
|
+
* 调用方并进它;否则等它收尾再重问一次。设置界面刚写完配置就来重读报告时,等的必须是
|
|
82
|
+
* 读过新配置的那一轮——等正在跑的那一轮回来等于拿回过期报告,界面于是「保存了却没变」。
|
|
83
|
+
* 配置身份可以直接比:设置服务每次提交都换一份深冻结的解析结果,没变就还是同一个对象。
|
|
84
|
+
*
|
|
85
|
+
* @param trigger - 触发来源;出现在配置页的状态段里。
|
|
86
|
+
* @returns 本次调用所参与的那一轮刷新的结果。
|
|
81
87
|
*/
|
|
82
88
|
refresh(trigger: string): Promise<RefreshOutcome>;
|
|
83
89
|
/** 执行一次刷新,绝不抛出异常。 */
|
package/lib/runtime.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 发现运行时:同一时刻只跑一次刷新,只记住一个结果。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* 刷新有四个来路(插件加载、设置变更、刷新间隔、配置页),其中两条容易重叠——本插件写入的
|
|
5
|
+
* 设置变更会唤醒触发这次写入的同一个 watcher。因此刷新是单飞的:途中到达的请求若正在跑的那
|
|
6
|
+
* 一轮读的就是此刻这份配置就并进它,否则排在它后面(见 {@link ApertureRuntime.refresh});
|
|
7
|
+
* 排队者共享同一轮,所以再多的调用方也只多跑一轮。
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
* 文档里已经生效的那一份。
|
|
9
|
+
* 记住的结果只是设置文档里那份的影子:配置页报告它,真正服务请求的是文档里已生效的那份。
|
|
11
10
|
*
|
|
12
11
|
* @module dsh-aperture/runtime
|
|
13
12
|
*/
|
|
14
13
|
import { fetchModelsListing } from "./aperture.js";
|
|
15
14
|
import { ModelCatalog } from "./catalog.js";
|
|
16
|
-
import {} from "./config.js";
|
|
15
|
+
import { DEFAULT_TIMEOUT_MS } from "./config.js";
|
|
17
16
|
import { buildProfilePlan } from "./profile.js";
|
|
18
17
|
import { buildRegistry } from "./registry.js";
|
|
19
18
|
import { applySync } from "./sync.js";
|
|
@@ -21,7 +20,8 @@ import { applySync } from "./sync.js";
|
|
|
21
20
|
export class ApertureRuntime {
|
|
22
21
|
deps;
|
|
23
22
|
running;
|
|
24
|
-
|
|
23
|
+
/** 正在跑的那一轮读的是哪一份配置;用来判断排队者该并进它还是排到它后面。 */
|
|
24
|
+
runningConfig;
|
|
25
25
|
latest;
|
|
26
26
|
/**
|
|
27
27
|
* @param deps - 宿主服务与配置活引用(thunk)。
|
|
@@ -34,34 +34,41 @@ export class ApertureRuntime {
|
|
|
34
34
|
return this.latest;
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
37
|
+
* 刷新;已有刷新在运行时,等它收尾之后再决定是并进新的一轮,还是自己起一轮。
|
|
38
|
+
*
|
|
39
|
+
* 承诺是「返回的那一轮读的是**此刻**的配置」:正在跑的那一轮若读的就是此刻这份配置,
|
|
40
|
+
* 调用方并进它;否则等它收尾再重问一次。设置界面刚写完配置就来重读报告时,等的必须是
|
|
41
|
+
* 读过新配置的那一轮——等正在跑的那一轮回来等于拿回过期报告,界面于是「保存了却没变」。
|
|
42
|
+
* 配置身份可以直接比:设置服务每次提交都换一份深冻结的解析结果,没变就还是同一个对象。
|
|
43
|
+
*
|
|
44
|
+
* @param trigger - 触发来源;出现在配置页的状态段里。
|
|
45
|
+
* @returns 本次调用所参与的那一轮刷新的结果。
|
|
40
46
|
*/
|
|
41
47
|
async refresh(trigger) {
|
|
42
48
|
if (this.running !== undefined) {
|
|
43
|
-
this.
|
|
44
|
-
|
|
49
|
+
if (this.runningConfig === this.deps.config())
|
|
50
|
+
return this.running;
|
|
51
|
+
await this.running;
|
|
52
|
+
return this.refresh(trigger);
|
|
45
53
|
}
|
|
46
|
-
|
|
54
|
+
const config = this.deps.config();
|
|
55
|
+
const run = this.run(trigger, config);
|
|
56
|
+
this.running = run;
|
|
57
|
+
this.runningConfig = config;
|
|
47
58
|
try {
|
|
48
|
-
return await
|
|
59
|
+
return await run;
|
|
49
60
|
}
|
|
50
61
|
finally {
|
|
51
62
|
this.running = undefined;
|
|
52
|
-
|
|
53
|
-
this.queued = undefined;
|
|
54
|
-
if (queued !== undefined) {
|
|
55
|
-
void this.refresh(queued);
|
|
56
|
-
}
|
|
63
|
+
this.runningConfig = undefined;
|
|
57
64
|
}
|
|
58
65
|
}
|
|
59
66
|
/** 执行一次刷新,绝不抛出异常。 */
|
|
60
|
-
async run(trigger) {
|
|
67
|
+
async run(trigger, config) {
|
|
61
68
|
const started = Date.now();
|
|
62
69
|
const at = new Date();
|
|
63
70
|
try {
|
|
64
|
-
return await this.execute(trigger, started, at);
|
|
71
|
+
return await this.execute(trigger, config, started, at);
|
|
65
72
|
}
|
|
66
73
|
catch (error) {
|
|
67
74
|
// 上面的任何代码都不允许 reject:所有调用方都是即发即忘的 `void`,而在宿主的
|
|
@@ -84,8 +91,7 @@ export class ApertureRuntime {
|
|
|
84
91
|
}
|
|
85
92
|
}
|
|
86
93
|
/** 一次刷新的主体。 */
|
|
87
|
-
async execute(trigger, started, at) {
|
|
88
|
-
const config = this.deps.config();
|
|
94
|
+
async execute(trigger, config, started, at) {
|
|
89
95
|
if (config.instanceRoot === undefined) {
|
|
90
96
|
const outcome = {
|
|
91
97
|
trigger,
|
|
@@ -102,11 +108,11 @@ export class ApertureRuntime {
|
|
|
102
108
|
this.latest = outcome;
|
|
103
109
|
return outcome;
|
|
104
110
|
}
|
|
105
|
-
const catalog = await this.deps.catalog.load(config.modelMetadataUrl,
|
|
111
|
+
const catalog = await this.deps.catalog.load(config.modelMetadataUrl, DEFAULT_TIMEOUT_MS);
|
|
106
112
|
let listed;
|
|
107
113
|
let endpoint;
|
|
108
114
|
try {
|
|
109
|
-
const listing = await fetchModelsListing(config.instanceRoot, { timeoutMs:
|
|
115
|
+
const listing = await fetchModelsListing(config.instanceRoot, { timeoutMs: DEFAULT_TIMEOUT_MS });
|
|
110
116
|
listed = listing.entries;
|
|
111
117
|
endpoint = listing.endpoint;
|
|
112
118
|
}
|
|
@@ -133,7 +139,6 @@ export class ApertureRuntime {
|
|
|
133
139
|
models: config.models,
|
|
134
140
|
enabledModelIds: config.enabledModelIds,
|
|
135
141
|
modelAliases: config.modelAliases,
|
|
136
|
-
defaultContextWindow: config.defaultContextWindow,
|
|
137
142
|
images: config.images,
|
|
138
143
|
reasoning: config.reasoning,
|
|
139
144
|
}, catalog.lookup);
|
|
@@ -145,7 +150,6 @@ export class ApertureRuntime {
|
|
|
145
150
|
anthropicDisplayName: config.anthropicDisplayName,
|
|
146
151
|
...(config.apiKeyEnv === undefined ? {} : { apiKeyEnv: config.apiKeyEnv }),
|
|
147
152
|
headers: config.headers,
|
|
148
|
-
placeholderCredential: config.placeholderCredential,
|
|
149
153
|
configured: config.models,
|
|
150
154
|
});
|
|
151
155
|
const sync = await this.publish(config, plan);
|
|
@@ -168,11 +172,15 @@ export class ApertureRuntime {
|
|
|
168
172
|
}
|
|
169
173
|
/** 写入方案,或说明为什么没有写入任何内容。 */
|
|
170
174
|
async publish(config, plan) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
175
|
+
// 关掉同步是「撤下本插件的路由」,不是「什么都不做」:留着一份不再由配置决定的清单,
|
|
176
|
+
// 界面看不出还有谁在服务,用户只能自己去翻 `llm-pi-ai` 段。空方案正好表达撤下——
|
|
177
|
+
// `planSync` 会把每个拥有但不再需要的路由键 unset 掉。
|
|
178
|
+
const routes = config.sync ? plan.routes : [];
|
|
174
179
|
try {
|
|
175
|
-
|
|
180
|
+
const outcome = await applySync(this.deps.settings, routes, plan.ownedRoutes);
|
|
181
|
+
return config.sync || outcome.applied
|
|
182
|
+
? outcome
|
|
183
|
+
: { ...outcome, reason: '同步已关闭,本插件没有发布过路由' };
|
|
176
184
|
}
|
|
177
185
|
catch (error) {
|
|
178
186
|
this.deps.logger.warn('发布发现的清单失败:%s', message(error));
|
package/lib/sync.d.ts
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 写入阶段:把方案发布到 `llm-pi-ai` 配置段。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* 别的东西,就必须重新实现一套协议格式,而本插件之所以存在,正是因为不必如此。
|
|
4
|
+
* 该配置段属于另一个插件(`@deepseek-ai/dsh-llm-pi-ai`),而设置接缝不做归属检查,因此
|
|
5
|
+
* 写入它是被允许的,也是被认可的机制而非变通:宿主把 pi-ai 适配器组合为休眠状态,并声明
|
|
6
|
+
* 「哪些 provider 运行由用户的设置文档决定」。
|
|
8
7
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* 自身的组合层不会被视作漂移。
|
|
13
|
-
*
|
|
14
|
-
* 它只写入本插件拥有的路由键,且使用路径寻址的 op,因此配置段中其他每个 provider 都
|
|
15
|
-
* 原样保留。
|
|
16
|
-
*
|
|
17
|
-
* 它绝不会在发现失败后运行:不可达的网关会保留已经在服务的清单,因为在瞬时网络错误
|
|
18
|
-
* 下删除可用模型的刷新,比什么都不做的刷新更糟。
|
|
8
|
+
* 三条性质使这一写入可以安全重复:没有变化时是空操作(比较对象是**已解析的**配置段,因此
|
|
9
|
+
* 部署自身的组合层不算漂移);只写入本插件拥有的路由键,且用路径寻址的 op,配置段里其他
|
|
10
|
+
* provider 原样保留;绝不在发现失败后运行——瞬时网络错误下删除可用模型比什么都不做更糟。
|
|
19
11
|
*
|
|
20
12
|
* @module dsh-aperture/sync
|
|
21
13
|
*/
|
|
22
|
-
import type {
|
|
14
|
+
import type { SettingsForms, SettingsPathOp } from '@deepseek-ai/dsh-settings';
|
|
23
15
|
import type { RoutePlan } from './profile.ts';
|
|
16
|
+
/** pi-ai 适配器注册的设置命名空间,也是本插件写入的那一个。 */
|
|
17
|
+
export declare const PI_AI_NAMESPACE = "llm-pi-ai";
|
|
24
18
|
/** 一次发布尝试的结果。 */
|
|
25
19
|
export interface SyncOutcome {
|
|
26
20
|
/** 是否发出了写入。 */
|
|
@@ -50,19 +44,12 @@ export declare function planSync(current: unknown, routes: readonly RoutePlan[],
|
|
|
50
44
|
* @param ownedRoutes - 本插件拥有的每个路由键。
|
|
51
45
|
* @returns 发生了什么;未写入任何内容时包含原因。
|
|
52
46
|
*/
|
|
53
|
-
export declare function applySync(settings:
|
|
54
|
-
/**
|
|
55
|
-
* 从配置段中撤出本插件拥有的每条路由。
|
|
56
|
-
* @param settings - 设置服务。
|
|
57
|
-
* @param ownedRoutes - 要移除的路由键。
|
|
58
|
-
* @returns 发生了什么。
|
|
59
|
-
*/
|
|
60
|
-
export declare function clearRoutes(settings: SettingsProvider, ownedRoutes: readonly string[]): Promise<SyncOutcome>;
|
|
47
|
+
export declare function applySync(settings: SettingsForms, routes: readonly RoutePlan[], ownedRoutes: readonly string[]): Promise<SyncOutcome>;
|
|
61
48
|
/**
|
|
62
49
|
* 结构化 JSON 相等性。
|
|
63
50
|
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
51
|
+
* 之所以自己写而不导入,是因为这里比较的值恰好都是 JSON:本插件生成的 profile,以及设置
|
|
52
|
+
* 接缝从文档里解析回来的 profile。键顺序不属于这种同一性,因此被归一化掉。
|
|
66
53
|
*
|
|
67
54
|
* @param left - 一个 JSON 值。
|
|
68
55
|
* @param right - 另一个。
|