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
package/lib/remote.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 标签页与宿主之间的 Typert Remote 面:`aperturePanel` 命名空间。
|
|
3
|
+
*
|
|
4
|
+
* 描述符是手工登记的,因为生成它们的 Typert 生成器并不随 DSH 发布,而这一步的规范本身
|
|
5
|
+
* 很小:宿主半边用 `src-json` 编解码器,浏览器半边带 strict 校验,两端共享同一组端点名。
|
|
6
|
+
* 参数按描述符里的顺序位置传入宿主方法,因此两边的名字与顺序必须一致。
|
|
7
|
+
*
|
|
8
|
+
* 端点 id 的 `#` 之前是包名,之后是 `<命名空间>/<方法>`;这与网关、注册表和客户端三方
|
|
9
|
+
* 共用的文法一致。
|
|
10
|
+
*
|
|
11
|
+
* @module dsh-aperture/remote
|
|
12
|
+
*/
|
|
13
|
+
import { TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol';
|
|
14
|
+
/** 包名,同时是端点 id 的前缀。 */
|
|
15
|
+
export const PANEL_PACKAGE = 'dsh-aperture';
|
|
16
|
+
/** 线上命名空间,也是浏览器半边注入的服务名(`remote.aperturePanel`)。 */
|
|
17
|
+
export const PANEL_NAMESPACE = 'aperturePanel';
|
|
18
|
+
/**
|
|
19
|
+
* 一个端点的宿主侧调用描述符。
|
|
20
|
+
*
|
|
21
|
+
* @param method - 端点方法名,同时也是宿主服务上的方法名。
|
|
22
|
+
* @param parameters - 参数名,按宿主方法的形参顺序;省略即无参数。
|
|
23
|
+
* @returns 一个结果为 JSON 的直调描述符。
|
|
24
|
+
*/
|
|
25
|
+
function panelDescriptor(method, parameters = []) {
|
|
26
|
+
return {
|
|
27
|
+
id: `${PANEL_PACKAGE}#${PANEL_NAMESPACE}/${method}`,
|
|
28
|
+
service: PANEL_NAMESPACE,
|
|
29
|
+
namespace: PANEL_NAMESPACE,
|
|
30
|
+
method,
|
|
31
|
+
invocation: { kind: 'direct' },
|
|
32
|
+
parameters: parameters.map((name) => ({ name, wire: name, source: 'json', codec: { mode: 'src-json' } })),
|
|
33
|
+
result: { mode: 'src-json' },
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 本插件暴露给浏览器的全部端点。
|
|
38
|
+
*
|
|
39
|
+
* 端点名有一处不显眼的约束:api-gateway 在客户端为每个命名空间建一个
|
|
40
|
+
* `RemoteNamespaceService`,端点会成为它的属性,因此与它自己的成员重名会被
|
|
41
|
+
* `validateContribution` 拒绝,**整份贡献一起撤回**(浏览器里只剩一行 console.error,
|
|
42
|
+
* 界面安静地什么都不出现)。它预置的名字是 `ctx` / `empty` / `invokeRemote` / `methods`
|
|
43
|
+
* / `name` / `namespace` 与 `has` / `install` / `installDirect` / `installScoped` /
|
|
44
|
+
* `assertMethodAvailable` / `remove` —— 「撤下路由」因此叫 `withdraw` 而不是 `remove`。
|
|
45
|
+
*/
|
|
46
|
+
export const PANEL_INVOCATIONS = [
|
|
47
|
+
panelDescriptor('status'),
|
|
48
|
+
panelDescriptor('refresh'),
|
|
49
|
+
panelDescriptor('withdraw'),
|
|
50
|
+
panelDescriptor('configuration'),
|
|
51
|
+
panelDescriptor('save', ['baseUrl', 'sync']),
|
|
52
|
+
panelDescriptor('edit', ['id', 'patch']),
|
|
53
|
+
];
|
|
54
|
+
/**
|
|
55
|
+
* 登记进 Typert 注册表的贡献。
|
|
56
|
+
*
|
|
57
|
+
* `schemas`/`model` 是生成器的产物,这里没有生成器,因此它们如实为空:本插件不导出可
|
|
58
|
+
* 复用的 schema,也没有需要反射的业务类型。端点本身仍然完整——宿主注册 `src-json`、浏览器
|
|
59
|
+
* 带 strict 校验,两者按同一份契约工作。
|
|
60
|
+
*/
|
|
61
|
+
export const PANEL_CONTRIBUTION = {
|
|
62
|
+
package: PANEL_PACKAGE,
|
|
63
|
+
face: 'host',
|
|
64
|
+
schemas: [],
|
|
65
|
+
invocations: PANEL_INVOCATIONS,
|
|
66
|
+
model: { services: [], events: [], objects: [] },
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* `aperturePanel` 宿主服务:方法与描述符一一对应,实现全部委托给 {@link PanelOps}。
|
|
70
|
+
*
|
|
71
|
+
* 方法签名必须与描述符的参数顺序一致——`save` 的两个形参名字与描述符里的两个参数同名,
|
|
72
|
+
* 顺序也相同,网关就是按描述符顺序把 wire 参数位置传入的。
|
|
73
|
+
*/
|
|
74
|
+
export class AperturePanelService extends TypertRemoteService {
|
|
75
|
+
ops;
|
|
76
|
+
/**
|
|
77
|
+
* @param ctx - 挂载上下文。
|
|
78
|
+
* @param ops - 端点实现。
|
|
79
|
+
*/
|
|
80
|
+
constructor(ctx, ops) {
|
|
81
|
+
super(ctx, PANEL_NAMESPACE);
|
|
82
|
+
this.ops = ops;
|
|
83
|
+
}
|
|
84
|
+
/** 最近一次刷新的报告。 */
|
|
85
|
+
status() {
|
|
86
|
+
return this.ops.status();
|
|
87
|
+
}
|
|
88
|
+
/** 立刻重新发现并发布。 */
|
|
89
|
+
refresh() {
|
|
90
|
+
return this.ops.refresh();
|
|
91
|
+
}
|
|
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
|
+
/**
|
|
111
|
+
* 写入一个模型的参数。
|
|
112
|
+
*
|
|
113
|
+
* @param id - 模型 id。
|
|
114
|
+
* @param patch - 要改的字段;`null` 表示撤销这个模型的全部覆盖。
|
|
115
|
+
* @returns 成败与一句人话。
|
|
116
|
+
*/
|
|
117
|
+
edit(id, patch) {
|
|
118
|
+
return this.ops.edit(id, patch);
|
|
119
|
+
}
|
|
120
|
+
}
|
package/lib/report.d.ts
CHANGED
|
@@ -1,16 +1,118 @@
|
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
+
/** 报告里的一个模型。 */
|
|
24
|
+
export interface PanelModel {
|
|
25
|
+
/** Aperture 接受的模型 id。 */
|
|
26
|
+
readonly id: string;
|
|
27
|
+
/** 显示名(可能来自清单或覆盖)。 */
|
|
28
|
+
readonly name: string;
|
|
29
|
+
/** 承载它的路由键;没有任何路由能服务时缺失。 */
|
|
30
|
+
readonly route?: string;
|
|
31
|
+
/** 网关通告的协议;未通告时缺失。 */
|
|
32
|
+
readonly protocol?: string;
|
|
33
|
+
/** 网关为该模型通告的每一个端点,用于诊断。 */
|
|
34
|
+
readonly endpoints: readonly string[];
|
|
35
|
+
/** 生效的上下文容量,以 token 计。 */
|
|
36
|
+
readonly contextWindow?: number;
|
|
37
|
+
/** 生效的最大输出,以 token 计。 */
|
|
38
|
+
readonly maxTokens?: number;
|
|
39
|
+
/** 生效的请求模态。 */
|
|
40
|
+
readonly input: readonly Modality[];
|
|
41
|
+
/** 生效的推理能力。 */
|
|
42
|
+
readonly reasoning: boolean;
|
|
43
|
+
/** 每项事实的来源;界面按语言渲染它。 */
|
|
44
|
+
readonly provenance: {
|
|
45
|
+
readonly limits: FactSource;
|
|
46
|
+
readonly reasoning: FactSource;
|
|
47
|
+
readonly input: FactSource;
|
|
48
|
+
readonly name: FactSource;
|
|
49
|
+
};
|
|
50
|
+
/** 用户为这个模型写下的覆盖;用来预填编辑表单。 */
|
|
51
|
+
readonly override?: PanelModelOverride;
|
|
52
|
+
/** 用户写下的清单别名(`aperture.modelAliases` 里对应那一项)。 */
|
|
53
|
+
readonly alias?: string;
|
|
54
|
+
}
|
|
55
|
+
/** 报告里的一条已发布路由。 */
|
|
56
|
+
export interface PanelRoute {
|
|
57
|
+
/** provider 路由键。 */
|
|
58
|
+
readonly provider: string;
|
|
59
|
+
/** 服务它的协议;本插件自己拼的方案里一定有,类型上仍是可选(`PiAiProviderProfile`)。 */
|
|
60
|
+
readonly api?: string;
|
|
61
|
+
/** 路由的 baseURL,同上。 */
|
|
62
|
+
readonly baseURL?: string;
|
|
63
|
+
/** 该路由承载的模型数。 */
|
|
64
|
+
readonly models: number;
|
|
65
|
+
}
|
|
66
|
+
/** 最近一次刷新做了什么。 */
|
|
67
|
+
export interface PanelRefresh {
|
|
68
|
+
/** 触发来源。 */
|
|
69
|
+
readonly trigger: string;
|
|
70
|
+
/** ISO 时间戳;界面按本地时区渲染。 */
|
|
71
|
+
readonly at: string;
|
|
72
|
+
/** 耗时。 */
|
|
73
|
+
readonly durationMs: number;
|
|
74
|
+
/** 发现与发布是否都成功。 */
|
|
75
|
+
readonly ok: boolean;
|
|
76
|
+
/** 失败原因。 */
|
|
77
|
+
readonly error?: string;
|
|
78
|
+
/** 清单提供了什么。 */
|
|
79
|
+
readonly catalog: {
|
|
80
|
+
/** 清单是否可用。 */
|
|
81
|
+
readonly available: boolean;
|
|
82
|
+
/** 条目数。 */
|
|
83
|
+
readonly entries: number;
|
|
84
|
+
/** 清单不可用时的原因。 */
|
|
85
|
+
readonly reason?: string;
|
|
86
|
+
};
|
|
87
|
+
/** 应答的端点与它列出的行数。 */
|
|
88
|
+
readonly endpoint?: {
|
|
89
|
+
readonly url: string;
|
|
90
|
+
readonly listed: number;
|
|
91
|
+
};
|
|
92
|
+
/** 设置写入的结果。 */
|
|
93
|
+
readonly sync?: {
|
|
94
|
+
readonly applied: boolean;
|
|
95
|
+
readonly ops: number;
|
|
96
|
+
readonly routes: readonly string[];
|
|
97
|
+
readonly reason?: string;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/** 标签页要显示的整份报告。 */
|
|
101
|
+
export interface PanelReport {
|
|
102
|
+
/** 实例地址(已归一化);没有配置时为空串,措辞交给界面。 */
|
|
103
|
+
readonly place: string;
|
|
104
|
+
/** 最近一次刷新;还一次都没跑过时为缺失。 */
|
|
105
|
+
readonly refresh?: PanelRefresh;
|
|
106
|
+
/** 已发布的路由。 */
|
|
107
|
+
readonly routes: readonly PanelRoute[];
|
|
108
|
+
/** 逐模型清单:先是各条路由承载的模型,最后是没有任何路由的模型。 */
|
|
109
|
+
readonly models: readonly PanelModel[];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 组装报告。
|
|
113
|
+
*
|
|
114
|
+
* @param outcome - 最近一次刷新;一次都没完成过时传 `undefined`。
|
|
115
|
+
* @param config - 当前生效配置:用户写下的覆盖与别名只在这里读得到。
|
|
116
|
+
* @returns 报告。
|
|
117
|
+
*/
|
|
118
|
+
export declare function buildReport(outcome: RefreshOutcome | undefined, config: ResolvedConfig): PanelReport;
|
package/lib/report.js
CHANGED
|
@@ -1,89 +1,117 @@
|
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
? ` 清单:不可用(${outcome.catalog.reason ?? '原因未知'})`
|
|
28
|
-
: ` 清单:${outcome.catalog.entries} 个条目`);
|
|
29
|
-
if (outcome.endpoint !== undefined) {
|
|
30
|
-
lines.push(` 端点:${outcome.endpoint} 列出了 ${outcome.listed} 行`);
|
|
31
|
-
}
|
|
32
|
-
if (outcome.routes.length === 0) {
|
|
33
|
-
lines.push(' 路由:无');
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
for (const route of outcome.routes) {
|
|
37
|
-
lines.push(` 路由 ${route.provider}:${route.models.length} 个模型,经由 ${route.profile.api} → ${route.profile.baseURL}`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (outcome.unserved.length > 0) {
|
|
41
|
-
lines.push(` 未服务:${outcome.unserved.length} 个模型(${outcome.unserved.map((model) => model.id).join(', ')})`);
|
|
42
|
-
}
|
|
43
|
-
const sync = outcome.sync;
|
|
44
|
-
if (sync !== undefined) {
|
|
45
|
-
lines.push(sync.applied
|
|
46
|
-
? ` 设置:向 llm-pi-ai 写入 ${sync.ops} 个操作(${sync.routes.join(', ') || '仅移除'})`
|
|
47
|
-
: ` 设置:未写入(${sync.reason ?? '原因未知'})`);
|
|
48
|
-
}
|
|
49
|
-
return lines.join('\n');
|
|
50
|
-
}
|
|
51
|
-
/** 按路由分组的逐模型清单,带来源信息。 */
|
|
52
|
-
export function formatModels(outcome) {
|
|
53
|
-
if (outcome === undefined) {
|
|
54
|
-
return '尚未完成任何刷新;请运行 /aperture refresh';
|
|
55
|
-
}
|
|
56
|
-
if (outcome.models.length === 0) {
|
|
57
|
-
return outcome.error === undefined ? '未发现任何模型' : `未发现任何内容:${outcome.error}`;
|
|
58
|
-
}
|
|
59
|
-
const lines = [];
|
|
11
|
+
/**
|
|
12
|
+
* 组装报告。
|
|
13
|
+
*
|
|
14
|
+
* @param outcome - 最近一次刷新;一次都没完成过时传 `undefined`。
|
|
15
|
+
* @param config - 当前生效配置:用户写下的覆盖与别名只在这里读得到。
|
|
16
|
+
* @returns 报告。
|
|
17
|
+
*/
|
|
18
|
+
export function buildReport(outcome, config) {
|
|
19
|
+
const overrides = new Map(config.models.map((entry) => [entry.id, entry]));
|
|
20
|
+
const routes = (outcome?.routes ?? []).map((route) => ({
|
|
21
|
+
provider: route.provider,
|
|
22
|
+
...(route.profile.api === undefined ? {} : { api: route.profile.api }),
|
|
23
|
+
...(route.profile.baseURL === undefined ? {} : { baseURL: route.profile.baseURL }),
|
|
24
|
+
models: route.models.length,
|
|
25
|
+
}));
|
|
26
|
+
const models = [];
|
|
60
27
|
const routed = new Set();
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
28
|
+
const describe = (model, route) => {
|
|
29
|
+
routed.add(model.id);
|
|
30
|
+
const override = overrides.get(model.id);
|
|
31
|
+
const alias = config.modelAliases[model.id];
|
|
32
|
+
return {
|
|
33
|
+
id: model.id,
|
|
34
|
+
name: model.name,
|
|
35
|
+
...(route === undefined ? {} : { route }),
|
|
36
|
+
...(model.protocol === undefined ? {} : { protocol: model.protocol }),
|
|
37
|
+
endpoints: model.endpoints,
|
|
38
|
+
...(model.contextWindow === undefined ? {} : { contextWindow: model.contextWindow }),
|
|
39
|
+
...(model.maxTokens === undefined ? {} : { maxTokens: model.maxTokens }),
|
|
40
|
+
input: model.input,
|
|
41
|
+
reasoning: model.reasoning,
|
|
42
|
+
provenance: model.provenance,
|
|
43
|
+
...(override === undefined ? {} : { override: trim(override) }),
|
|
44
|
+
...(alias === undefined ? {} : { alias }),
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
for (const route of outcome?.routes ?? []) {
|
|
48
|
+
for (const model of route.models)
|
|
49
|
+
models.push(describe(model, route.provider));
|
|
67
50
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const endpoints = model.endpoints.length === 0 ? '未通告任何端点' : model.endpoints.join(', ');
|
|
73
|
-
lines.push(` ${model.id} — ${endpoints}`);
|
|
74
|
-
}
|
|
51
|
+
// 没有任何路由能服务的模型跟在后面:它们没有协议可用,或者被配置挡掉了。
|
|
52
|
+
for (const model of outcome?.models ?? []) {
|
|
53
|
+
if (!routed.has(model.id))
|
|
54
|
+
models.push(describe(model));
|
|
75
55
|
}
|
|
76
|
-
return
|
|
56
|
+
return {
|
|
57
|
+
place: config.instanceRoot ?? config.rawBaseUrl,
|
|
58
|
+
...(outcome === undefined ? {} : { refresh: refresh(outcome) }),
|
|
59
|
+
routes,
|
|
60
|
+
models,
|
|
61
|
+
};
|
|
77
62
|
}
|
|
78
|
-
/**
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return
|
|
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
|
+
/**
|
|
83
|
+
* 把一次刷新收成报告要显示的字段。
|
|
84
|
+
*
|
|
85
|
+
* @param outcome - 已完成的刷新。
|
|
86
|
+
* @returns 状态段的数据。
|
|
87
|
+
*/
|
|
88
|
+
function refresh(outcome) {
|
|
89
|
+
const catalog = outcome.catalog;
|
|
90
|
+
const sync = outcome.sync;
|
|
91
|
+
return {
|
|
92
|
+
trigger: outcome.trigger,
|
|
93
|
+
at: outcome.at.toISOString(),
|
|
94
|
+
durationMs: outcome.durationMs,
|
|
95
|
+
ok: outcome.ok,
|
|
96
|
+
...(outcome.error === undefined ? {} : { error: outcome.error }),
|
|
97
|
+
catalog: {
|
|
98
|
+
// `lookup` 在清单不可用时缺失;报告只报可用性,不报这个函数本身。
|
|
99
|
+
available: catalog.lookup !== undefined,
|
|
100
|
+
entries: catalog.entries,
|
|
101
|
+
...(catalog.reason === undefined ? {} : { reason: catalog.reason }),
|
|
102
|
+
},
|
|
103
|
+
...(outcome.endpoint === undefined
|
|
104
|
+
? {}
|
|
105
|
+
: { endpoint: { url: outcome.endpoint, listed: outcome.listed } }),
|
|
106
|
+
...(sync === undefined
|
|
107
|
+
? {}
|
|
108
|
+
: {
|
|
109
|
+
sync: {
|
|
110
|
+
applied: sync.applied,
|
|
111
|
+
ops: sync.ops,
|
|
112
|
+
routes: sync.routes,
|
|
113
|
+
...(sync.reason === undefined ? {} : { reason: sync.reason }),
|
|
114
|
+
},
|
|
115
|
+
}),
|
|
116
|
+
};
|
|
89
117
|
}
|
package/lib/runtime.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 发现运行时:同一时刻只跑一次刷新,只记住一个结果。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* 刷新来自四个方向——插件加载、设置变更、刷新间隔,以及设置界面的标签页——其中两个
|
|
5
5
|
* 很容易重叠,因为本插件自己写入并提交的设置变更会唤醒触发这次写入的同一个 watcher。
|
|
6
6
|
* 因此刷新是单飞(single-flight)的:在刷新过程中到达的请求会把自己记为下一次运行,
|
|
7
7
|
* 而不是启动第二次,循环会用最新配置再跑一遍。
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* 记住的结果就是设置文档里那一份的影子:标签页报告的就是它,而真正服务请求的,是
|
|
10
|
+
* 文档里已经生效的那一份。
|
|
11
11
|
*
|
|
12
12
|
* @module dsh-aperture/runtime
|
|
13
13
|
*/
|
|
@@ -76,15 +76,10 @@ export declare class ApertureRuntime {
|
|
|
76
76
|
last(): RefreshOutcome | undefined;
|
|
77
77
|
/**
|
|
78
78
|
* 刷新;若已有刷新在运行,则把本次刷新排在其后。
|
|
79
|
-
* @param trigger -
|
|
79
|
+
* @param trigger - 触发来源;出现在标签页的状态段里。
|
|
80
80
|
* @returns 本次调用所参与的那次刷新的结果。
|
|
81
81
|
*/
|
|
82
82
|
refresh(trigger: string): Promise<RefreshOutcome>;
|
|
83
|
-
/**
|
|
84
|
-
* 从设置文档中撤出本插件的路由。
|
|
85
|
-
* @returns 供命令界面展示的可读结果。
|
|
86
|
-
*/
|
|
87
|
-
remove(): Promise<string>;
|
|
88
83
|
/** 执行一次刷新,绝不抛出异常。 */
|
|
89
84
|
private run;
|
|
90
85
|
/** 一次刷新的主体。 */
|
package/lib/runtime.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 发现运行时:同一时刻只跑一次刷新,只记住一个结果。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* 刷新来自四个方向——插件加载、设置变更、刷新间隔,以及设置界面的标签页——其中两个
|
|
5
5
|
* 很容易重叠,因为本插件自己写入并提交的设置变更会唤醒触发这次写入的同一个 watcher。
|
|
6
6
|
* 因此刷新是单飞(single-flight)的:在刷新过程中到达的请求会把自己记为下一次运行,
|
|
7
7
|
* 而不是启动第二次,循环会用最新配置再跑一遍。
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* 记住的结果就是设置文档里那一份的影子:标签页报告的就是它,而真正服务请求的,是
|
|
10
|
+
* 文档里已经生效的那一份。
|
|
11
11
|
*
|
|
12
12
|
* @module dsh-aperture/runtime
|
|
13
13
|
*/
|
|
14
14
|
import { fetchModelsListing } from "./aperture.js";
|
|
15
15
|
import { ModelCatalog } from "./catalog.js";
|
|
16
|
-
import {
|
|
16
|
+
import {} from "./config.js";
|
|
17
17
|
import { buildProfilePlan } from "./profile.js";
|
|
18
18
|
import { buildRegistry } from "./registry.js";
|
|
19
|
-
import { applySync
|
|
19
|
+
import { applySync } from "./sync.js";
|
|
20
20
|
/** 单飞(single-flight)的发现与发布。 */
|
|
21
21
|
export class ApertureRuntime {
|
|
22
22
|
deps;
|
|
@@ -35,7 +35,7 @@ export class ApertureRuntime {
|
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* 刷新;若已有刷新在运行,则把本次刷新排在其后。
|
|
38
|
-
* @param trigger -
|
|
38
|
+
* @param trigger - 触发来源;出现在标签页的状态段里。
|
|
39
39
|
* @returns 本次调用所参与的那次刷新的结果。
|
|
40
40
|
*/
|
|
41
41
|
async refresh(trigger) {
|
|
@@ -56,23 +56,6 @@ export class ApertureRuntime {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
/**
|
|
60
|
-
* 从设置文档中撤出本插件的路由。
|
|
61
|
-
* @returns 供命令界面展示的可读结果。
|
|
62
|
-
*/
|
|
63
|
-
async remove() {
|
|
64
|
-
const config = this.deps.config();
|
|
65
|
-
const owned = [config.route, config.anthropicRoute];
|
|
66
|
-
try {
|
|
67
|
-
const outcome = await clearRoutes(this.deps.settings, owned);
|
|
68
|
-
return outcome.applied
|
|
69
|
-
? `已从 "${PI_AI_NAMESPACE}" 配置段移除 ${outcome.ops} 条路由:${owned.join(', ')}`
|
|
70
|
-
: `未移除任何内容:${outcome.reason ?? '原因未知'}`;
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
return `移除路由失败:${message(error)}`;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
59
|
/** 执行一次刷新,绝不抛出异常。 */
|
|
77
60
|
async run(trigger) {
|
|
78
61
|
const started = Date.now();
|
package/lib/types.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export type Modality = 'text' | 'image';
|
|
|
14
14
|
* 过程从不转换载荷的原因:它只决定每个模型在网关的哪些端点上应答。
|
|
15
15
|
*/
|
|
16
16
|
export type ApertureProtocol = 'openai-completions' | 'anthropic-messages';
|
|
17
|
-
/**
|
|
17
|
+
/** 一项已归一化的事实的来源,用于报告中的诊断。 */
|
|
18
18
|
export type FactSource = 'aperture' | 'models.dev' | 'config' | 'default';
|
|
19
19
|
/** 已发现模型携带的每个值的来源。 */
|
|
20
20
|
export interface ModelProvenance {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-aperture",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Discover the models an Aperture gateway advertises and publish them to DeepSeek Harness as llm-pi-ai provider routes. 探测 Aperture 网关暴露的模型,并自动写入 DSH 的 llm-pi-ai 设置,使其出现在模型选择器中。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -10,11 +10,13 @@
|
|
|
10
10
|
"types": "./lib/index.d.ts",
|
|
11
11
|
"default": "./lib/index.js"
|
|
12
12
|
},
|
|
13
|
+
"./client": "./client/aperture.js",
|
|
13
14
|
"./package.json": "./package.json",
|
|
14
15
|
"./cordis.patch.yml": "./cordis.patch.yml"
|
|
15
16
|
},
|
|
16
17
|
"files": [
|
|
17
18
|
"lib",
|
|
19
|
+
"client",
|
|
18
20
|
"cordis.patch.yml",
|
|
19
21
|
"README.md",
|
|
20
22
|
"README.en.md",
|
|
@@ -23,7 +25,7 @@
|
|
|
23
25
|
"scripts": {
|
|
24
26
|
"build": "tsc -p tsconfig.json",
|
|
25
27
|
"prepare": "tsc -p tsconfig.json",
|
|
26
|
-
"typecheck": "tsc -p tsconfig.test.json",
|
|
28
|
+
"typecheck": "tsc -p tsconfig.test.json && node --check client/aperture.js",
|
|
27
29
|
"test": "node --test --test-isolation=none \"test/**/*.test.ts\"",
|
|
28
30
|
"test:live": "node --test --test-isolation=none test/live.test.ts",
|
|
29
31
|
"inspect": "node scripts/inspect-live.mjs"
|
|
@@ -44,26 +46,35 @@
|
|
|
44
46
|
"url": "git+https://github.com/he0119/dsh-aperture.git"
|
|
45
47
|
},
|
|
46
48
|
"engines": {
|
|
47
|
-
"node": "
|
|
49
|
+
"node": ">=24.0.0"
|
|
48
50
|
},
|
|
49
51
|
"dsh": {
|
|
50
52
|
"bundle": {
|
|
51
53
|
"patch": "./cordis.patch.yml"
|
|
54
|
+
},
|
|
55
|
+
"client": {
|
|
56
|
+
"platform": "web",
|
|
57
|
+
"inject": [
|
|
58
|
+
"@deepseek-ai/dsh-client-locale",
|
|
59
|
+
"@deepseek-ai/dsh-client-runtime",
|
|
60
|
+
"@deepseek-ai/dsh-client-ui-settings"
|
|
61
|
+
]
|
|
52
62
|
}
|
|
53
63
|
},
|
|
54
64
|
"peerDependencies": {
|
|
55
65
|
"@deepseek-ai/cordis": "^4.0.2",
|
|
56
|
-
"@deepseek-ai/dsh-commands": "^0.1.5-rc.2",
|
|
57
66
|
"@deepseek-ai/dsh-settings": "^0.1.5-rc.2",
|
|
67
|
+
"@deepseek-ai/dsh-typert-protocol": "^0.1.5-rc.2",
|
|
58
68
|
"@deepseek-ai/schemastery": "^3.18.2"
|
|
59
69
|
},
|
|
60
70
|
"devDependencies": {
|
|
61
71
|
"@deepseek-ai/cordis": "4.0.2",
|
|
62
|
-
"@deepseek-ai/dsh-
|
|
63
|
-
"@deepseek-ai/dsh-llm": "0.1.5-rc.
|
|
64
|
-
"@deepseek-ai/dsh-
|
|
65
|
-
"@deepseek-ai/dsh-settings": "0.1.5-rc.
|
|
66
|
-
"@deepseek-ai/dsh-
|
|
72
|
+
"@deepseek-ai/dsh-llm": "0.1.5-rc.3",
|
|
73
|
+
"@deepseek-ai/dsh-llm-pi-ai": "0.1.5-rc.3",
|
|
74
|
+
"@deepseek-ai/dsh-settings": "0.1.5-rc.3",
|
|
75
|
+
"@deepseek-ai/dsh-settings-file": "^0.1.5-rc.3",
|
|
76
|
+
"@deepseek-ai/dsh-typert-protocol": "^0.1.5-rc.3",
|
|
77
|
+
"@deepseek-ai/dsh-typert-registry": "^0.1.5-rc.3",
|
|
67
78
|
"@deepseek-ai/schemastery": "3.18.2",
|
|
68
79
|
"@types/node": "^22.20.0",
|
|
69
80
|
"typescript": "^5.9.0"
|
package/lib/command.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `/aperture` 命令。
|
|
3
|
-
*
|
|
4
|
-
* 发现过程按设计是静默的——它在加载时与配置变更时运行,并发布自己发现的内容——因此
|
|
5
|
-
* 该命令是让它可被观测的界面,也是不编辑文件就能强制刷新的唯一途径。
|
|
6
|
-
*
|
|
7
|
-
* @module dsh-aperture/command
|
|
8
|
-
*/
|
|
9
|
-
import type { Context } from '@deepseek-ai/cordis';
|
|
10
|
-
import type { ResolvedConfig } from './config.ts';
|
|
11
|
-
import { type ApertureRuntime } from './runtime.ts';
|
|
12
|
-
/** 注册的命令名,不含前导斜杠。 */
|
|
13
|
-
export declare const COMMAND_NAME = "aperture";
|
|
14
|
-
/**
|
|
15
|
-
* 在命令注册表上注册 `/aperture`。
|
|
16
|
-
*
|
|
17
|
-
* @param ctx - 带有 `commands` 服务的上下文。
|
|
18
|
-
* @param runtime - 发现运行时。
|
|
19
|
-
* @param config - 返回当前生效配置的活引用(thunk)。
|
|
20
|
-
*/
|
|
21
|
-
export declare function registerApertureCommand(ctx: Context, runtime: ApertureRuntime, config: () => ResolvedConfig): void;
|