dsh-aperture 0.3.0 → 0.3.2

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.
Files changed (50) hide show
  1. package/README.en.md +8 -7
  2. package/README.md +8 -7
  3. package/lib/client.js +1463 -0
  4. package/lib/client.js.map +1 -0
  5. package/lib/index.js +2084 -126
  6. package/lib/{aperture.d.ts → types/aperture.d.ts} +12 -10
  7. package/lib/types/catalog.d.ts +25 -0
  8. package/lib/types/config.d.ts +204 -0
  9. package/lib/types/index.d.ts +37 -0
  10. package/lib/{metadata → types/metadata}/extract.d.ts +15 -24
  11. package/lib/types/metadata/modelsdev.d.ts +40 -0
  12. package/lib/{metadata → types/metadata}/utils.d.ts +2 -0
  13. package/lib/types/panel.d.ts +71 -0
  14. package/lib/types/profile.d.ts +55 -0
  15. package/lib/types/registry.d.ts +31 -0
  16. package/lib/types/relay.d.ts +29 -0
  17. package/lib/types/remote.d.ts +54 -0
  18. package/lib/types/report.d.ts +115 -0
  19. package/lib/types/runtime.d.ts +87 -0
  20. package/lib/{sync.d.ts → types/sync.d.ts} +12 -23
  21. package/lib/types/types.d.ts +118 -0
  22. package/lib/{url.d.ts → types/url.d.ts} +5 -3
  23. package/package.json +32 -13
  24. package/client/aperture.js +0 -1566
  25. package/lib/aperture.js +0 -107
  26. package/lib/catalog.d.ts +0 -35
  27. package/lib/catalog.js +0 -74
  28. package/lib/config.d.ts +0 -214
  29. package/lib/config.js +0 -168
  30. package/lib/index.d.ts +0 -70
  31. package/lib/metadata/extract.js +0 -217
  32. package/lib/metadata/modelsdev.d.ts +0 -53
  33. package/lib/metadata/modelsdev.js +0 -302
  34. package/lib/metadata/utils.js +0 -86
  35. package/lib/panel.d.ts +0 -86
  36. package/lib/panel.js +0 -263
  37. package/lib/profile.d.ts +0 -62
  38. package/lib/profile.js +0 -158
  39. package/lib/registry.d.ts +0 -48
  40. package/lib/registry.js +0 -234
  41. package/lib/remote.d.ts +0 -64
  42. package/lib/remote.js +0 -96
  43. package/lib/report.d.ts +0 -123
  44. package/lib/report.js +0 -109
  45. package/lib/runtime.d.ts +0 -97
  46. package/lib/runtime.js +0 -194
  47. package/lib/sync.js +0 -176
  48. package/lib/types.d.ts +0 -116
  49. package/lib/types.js +0 -10
  50. package/lib/url.js +0 -67
package/lib/registry.js DELETED
@@ -1,234 +0,0 @@
1
- /**
2
- * 归一化阶段:一条原始网关条目,加上清单元数据,再加上配置,变成一个
3
- * `DiscoveredModel`。
4
- *
5
- * 三个决策只在这里做出,别处没有。
6
- *
7
- * **模型从哪个端点应答。** 端点由网关的 `supported_endpoints` 决定:只通过原生
8
- * `generateContent` 服务的 Gemini 模型 `dsh-llm-pi-ai` 根本够不到,发布到 OpenAI 兼容
9
- * 路由上只会得到一个每个请求都失败的模型。没有路由可服务的模型留在报告里,但不发布。
10
- *
11
- * **谁来决定模型的容量。** Aperture 优先(网关知道每个上游前面的代理接受什么),
12
- * models.dev 补它没说明的,配置兜底最后。兜底值只设定 `contextWindow`——没人声明过的
13
- * 输出上限保持缺失,免得把每个请求都限制在一个凭空捏造的数字上。
14
- *
15
- * **谁来决定模型是否会推理。** 依次是 Aperture、models.dev、插件的 `reasoning` 开关。
16
- * 错误的「是」会让用户选推理档位时付出一个 400 的代价,因此不从模型名猜测。
17
- *
18
- * @module dsh-aperture/registry
19
- */
20
- import { extractCapabilities, extractDisplayName, extractEndpoints, extractLimits, extractModelId, extractProvider, } from "./metadata/extract.js";
21
- import { DEFAULT_CONTEXT_WINDOW } from "./config.js";
22
- /** 每个 OpenAI 兼容模型都必须通告的端点。 */
23
- const OPENAI_ENDPOINT = '/v1/chat/completions';
24
- /** 每个 Anthropic Messages 模型都必须通告的端点。 */
25
- const ANTHROPIC_ENDPOINT = '/v1/messages';
26
- /**
27
- * 归一化、补全并合并一份网关清单。
28
- *
29
- * @param entries - 按端点顺序排列的原始模型行。
30
- * @param options - 配置开关。
31
- * @param lookup - 清单元数据查找器,在已加载时提供。
32
- * @returns 每个模型及其来源,以及没有路由能服务的那些模型。
33
- */
34
- export function buildRegistry(entries, options, lookup) {
35
- const enabled = new Set(options.enabledModelIds.map((id) => id.trim()).filter((id) => id.length > 0));
36
- const configuredById = new Map();
37
- for (const configured of options.models) {
38
- const id = configured.id.trim();
39
- if (id.length > 0 && !configuredById.has(id)) {
40
- configuredById.set(id, configured);
41
- }
42
- }
43
- const seen = new Set();
44
- const models = [];
45
- for (const entry of entries) {
46
- const id = extractModelId(entry);
47
- if (id === undefined || seen.has(id)) {
48
- continue;
49
- }
50
- if (enabled.size > 0 && !enabled.has(id)) {
51
- continue;
52
- }
53
- seen.add(id);
54
- models.push(fromEndpoint(entry, id, options, lookup));
55
- }
56
- // 配置里声明、但网关没有通告的模型仍会进入选择器;
57
- // 网关少报自己的清单时,正是靠这一点保持可用。
58
- for (const [id] of configuredById) {
59
- if (seen.has(id)) {
60
- continue;
61
- }
62
- seen.add(id);
63
- models.push(fromConfiguration(id, options, lookup));
64
- }
65
- const merged = models.map((model) => {
66
- const configured = configuredById.get(model.id);
67
- return configured === undefined ? model : applyConfigured(model, configured, options);
68
- });
69
- return {
70
- models: merged,
71
- unserved: merged.filter((model) => model.protocol === undefined),
72
- };
73
- }
74
- /** 归一化网关通告的一行。 */
75
- function fromEndpoint(entry, id, options, lookup) {
76
- const apertureLimits = extractLimits(entry);
77
- const capabilities = extractCapabilities(entry);
78
- const provider = extractProvider(entry);
79
- const endpoints = extractEndpoints(entry);
80
- const apertureName = extractDisplayName(entry);
81
- const catalog = lookupModel(lookup, id, provider, options.modelAliases);
82
- const protocol = classifyProtocol(endpoints);
83
- return {
84
- id,
85
- name: apertureName ?? catalog?.name ?? id,
86
- ...(protocol === undefined ? {} : { protocol }),
87
- endpoints,
88
- contextWindow: apertureLimits?.contextWindow ?? catalog?.contextWindow ?? DEFAULT_CONTEXT_WINDOW,
89
- ...resolveOutputCap(apertureLimits?.maxTokens ?? catalog?.maxTokens),
90
- input: options.images === 'metadata' ? (capabilities?.input ?? catalog?.input ?? ['text']) : ['text'],
91
- reasoning: options.reasoning === 'auto' && (capabilities?.reasoning ?? catalog?.reasoning ?? false),
92
- ...(provider?.id === undefined ? {} : { provider: provider.id }),
93
- provenance: {
94
- limits: limitsSource(apertureLimits, catalog),
95
- reasoning: factsSource(capabilities?.reasoning, catalog?.reasoning),
96
- input: factsSource(capabilities?.input, catalog?.input),
97
- name: apertureName !== undefined ? 'aperture' : catalog?.name !== undefined ? 'models.dev' : 'default',
98
- },
99
- };
100
- }
101
- /** 归一化一个只因配置点名而存在的模型。 */
102
- function fromConfiguration(id, options, lookup) {
103
- const catalog = lookupModel(lookup, id, undefined, options.modelAliases);
104
- return {
105
- id,
106
- name: catalog?.name ?? id,
107
- endpoints: [],
108
- contextWindow: catalog?.contextWindow ?? DEFAULT_CONTEXT_WINDOW,
109
- ...resolveOutputCap(catalog?.maxTokens),
110
- input: options.images === 'metadata' ? (catalog?.input ?? ['text']) : ['text'],
111
- reasoning: options.reasoning === 'auto' && (catalog?.reasoning ?? false),
112
- provenance: {
113
- limits: limitsSource(undefined, catalog),
114
- reasoning: factsSource(undefined, catalog?.reasoning),
115
- input: factsSource(undefined, catalog?.input),
116
- name: catalog?.name !== undefined ? 'models.dev' : 'default',
117
- },
118
- };
119
- }
120
- /** 把一条配置条目声明的字段应用到一个已发现的模型上。 */
121
- function applyConfigured(model, configured, options) {
122
- const protocol = protocolFromConfigured(configured) ?? model.protocol;
123
- const contextWindow = configured.contextWindow ?? model.contextWindow;
124
- const maxTokens = configured.maxTokens ?? model.maxTokens;
125
- const name = configured.name?.trim() || model.name;
126
- // 运行时 schema 给 `models[].input` 的缺省值是空数组,而空数组在别处等于「不接受任何
127
- // 模态」。因此空数组按**没写**处理,继续沿用发现到的模态(要声明纯文本请用
128
- // `images: ignore`,而不是 `input: []`)。
129
- const declaredInput = configured.input !== undefined && configured.input.length > 0
130
- ? configured.input
131
- : undefined;
132
- const input = declaredInput ?? model.input;
133
- return {
134
- id: model.id,
135
- name,
136
- ...(protocol === undefined ? {} : { protocol }),
137
- endpoints: model.endpoints,
138
- contextWindow: contextWindow ?? DEFAULT_CONTEXT_WINDOW,
139
- ...resolveOutputCap(maxTokens),
140
- input: declaredInput !== undefined || options.images === 'metadata' ? input : ['text'],
141
- reasoning: configured.thinking ?? model.reasoning,
142
- ...(model.provider === undefined ? {} : { provider: model.provider }),
143
- provenance: {
144
- limits: configured.contextWindow !== undefined || configured.maxTokens !== undefined
145
- ? 'config'
146
- : model.provenance.limits,
147
- reasoning: configured.thinking !== undefined ? 'config' : model.provenance.reasoning,
148
- input: declaredInput !== undefined ? 'config' : model.provenance.input,
149
- name: configured.name?.trim() ? 'config' : model.provenance.name,
150
- },
151
- };
152
- }
153
- /** 仅当确实有来源声明了输出上限时才带上它。 */
154
- function resolveOutputCap(maxTokens) {
155
- return maxTokens === undefined ? {} : { maxTokens };
156
- }
157
- /** 防御式地查询清单查找器:查找器绝不能导致刷新失败。 */
158
- function lookupModel(lookup, id, provider, aliases) {
159
- if (lookup === undefined) {
160
- return undefined;
161
- }
162
- const candidates = [aliases[id], id].filter((candidate) => typeof candidate === 'string' && candidate.trim().length > 0);
163
- for (const candidate of candidates) {
164
- try {
165
- const found = lookup({
166
- id: candidate,
167
- ...(provider?.id === undefined ? {} : { provider: provider.id }),
168
- ...(provider?.name === undefined ? {} : { providerName: provider.name }),
169
- });
170
- if (found !== undefined) {
171
- return found;
172
- }
173
- }
174
- catch {
175
- // 清单查找只是参考性的;坏掉的查找器不能导致刷新失败。
176
- }
177
- }
178
- return undefined;
179
- }
180
- /** 容量类事实的来源。 */
181
- function limitsSource(apertureLimits, catalog) {
182
- if (apertureLimits !== undefined) {
183
- return 'aperture';
184
- }
185
- return catalog?.contextWindow !== undefined || catalog?.maxTokens !== undefined ? 'models.dev' : 'default';
186
- }
187
- /** 一项 Aperture 与清单都会回答的能力事实的来源。 */
188
- function factsSource(apertureFact, catalogFact) {
189
- if (apertureFact !== undefined) {
190
- return 'aperture';
191
- }
192
- return catalogFact !== undefined ? 'models.dev' : 'default';
193
- }
194
- /** 把配置里的一种 `api` 写法映射到可服务的协议。 */
195
- function protocolFromConfigured(configured) {
196
- switch (configured.api?.trim()) {
197
- case 'openai-completions':
198
- return 'openai-completions';
199
- case 'anthropic-messages':
200
- return 'anthropic-messages';
201
- default:
202
- return undefined;
203
- }
204
- }
205
- /**
206
- * 决定一个模型通告的端点适配哪条路由。
207
- *
208
- * 完全没有通告端点的清单按 OpenAI 兼容处理:不上报传输方式的网关绝大多数就是普通
209
- * Chat Completions 代理,而没有路由的模型无论如何都不可用。
210
- *
211
- * @param endpoints - 通告的端点路径。
212
- * @returns 可服务的协议;没有适配的协议时为 `undefined`。
213
- */
214
- export function classifyProtocol(endpoints) {
215
- if (endpoints.length === 0) {
216
- return 'openai-completions';
217
- }
218
- if (endpoints.some((endpoint) => matchesEndpoint(endpoint, OPENAI_ENDPOINT))) {
219
- return 'openai-completions';
220
- }
221
- if (endpoints.some((endpoint) => matchesEndpoint(endpoint, ANTHROPIC_ENDPOINT))) {
222
- return 'anthropic-messages';
223
- }
224
- return undefined;
225
- }
226
- /** 判断一个通告的端点是否就是(或以之结尾)某个已知路径。 */
227
- function matchesEndpoint(advertised, known) {
228
- const path = advertised.split('?')[0]?.replace(/\/+$/u, '') ?? '';
229
- return path === known || path.endsWith(known);
230
- }
231
- /** 判断一个模型是否属于 DeepSeek 推理方言。 */
232
- export function isDeepSeekFamily(model) {
233
- return `${model.id} ${model.name} ${model.provider ?? ''}`.toLowerCase().includes('deepseek');
234
- }
package/lib/remote.d.ts DELETED
@@ -1,64 +0,0 @@
1
- /**
2
- * 配置页与宿主之间的 Typert Remote 面:`aperturePanel` 命名空间。
3
- *
4
- * 描述符是手工登记的,因为生成它们的 Typert 生成器并不随 DSH 发布,而这一步的规范本身很小:
5
- * 宿主半边用 `src-json` 编解码器,浏览器半边带 strict 校验,两端共享同一组端点名;参数按描述符
6
- * 里的顺序位置传入宿主方法,因此两边的名字与顺序必须一致。
7
- *
8
- * 端点 id 的 `#` 之前是包名,之后是 `<命名空间>/<方法>`。
9
- *
10
- * @module dsh-aperture/remote
11
- */
12
- import type { Context } from '@deepseek-ai/cordis';
13
- import type { InvocationDescriptor } from '@deepseek-ai/dsh-typert-protocol';
14
- import { TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol';
15
- import type { TypertContribution } from '@deepseek-ai/dsh-typert-registry';
16
- import type { PanelAction, PanelModelPatch, PanelOps } from './panel.ts';
17
- import type { PanelReport } from './report.ts';
18
- /** 包名,同时是端点 id 的前缀。 */
19
- export declare const PANEL_PACKAGE = "dsh-aperture";
20
- /** 线上命名空间,也是浏览器半边注入的服务名(`remote.aperturePanel`)。 */
21
- export declare const PANEL_NAMESPACE = "aperturePanel";
22
- /**
23
- * 本插件暴露给浏览器的全部端点。
24
- *
25
- * 端点名有一处不显眼的约束:api-gateway 在客户端为每个命名空间建一个 `RemoteNamespaceService`,
26
- * 端点会成为它的属性,因此与它自己的成员重名会被 `validateContribution` 拒绝,**整份贡献一起
27
- * 撤回**(浏览器里只剩一行 console.error,界面安静地什么都不出现)。预置名有 `ctx` / `empty` /
28
- * `invokeRemote` / `methods` / `name` / `namespace` 与 `has` / `install` / `installDirect` /
29
- * `installScoped` / `assertMethodAvailable` / `remove`——新端点起名时先对一遍这份名单。
30
- */
31
- export declare const PANEL_INVOCATIONS: readonly InvocationDescriptor[];
32
- /**
33
- * 登记进 Typert 注册表的贡献。
34
- *
35
- * `schemas`/`model` 是生成器的产物,这里没有生成器,因此它们如实为空:本插件不导出可复用的
36
- * schema,也没有需要反射的业务类型。端点本身仍然完整。
37
- */
38
- export declare const PANEL_CONTRIBUTION: TypertContribution;
39
- /**
40
- * `aperturePanel` 宿主服务:方法与描述符一一对应,实现全部委托给 {@link PanelOps}。
41
- *
42
- * 方法签名必须与描述符的参数顺序一致——`edit` 的两个形参名字与描述符里的两个参数同名,
43
- * 顺序也相同,网关就是按描述符顺序把 wire 参数位置传入的。
44
- */
45
- export declare class AperturePanelService extends TypertRemoteService {
46
- private readonly ops;
47
- /**
48
- * @param ctx - 挂载上下文。
49
- * @param ops - 端点实现。
50
- */
51
- constructor(ctx: Context, ops: PanelOps);
52
- /** 最近一次刷新的报告。 */
53
- status(): PanelReport;
54
- /** 立刻重新发现并发布。 */
55
- refresh(): Promise<PanelAction>;
56
- /**
57
- * 写入一个模型的参数。
58
- *
59
- * @param id - 模型 id。
60
- * @param patch - 要改的字段;`null` 表示撤销这个模型的全部覆盖。
61
- * @returns 成败与一句人话。
62
- */
63
- edit(id: string, patch: PanelModelPatch | null): Promise<PanelAction>;
64
- }
package/lib/remote.js DELETED
@@ -1,96 +0,0 @@
1
- /**
2
- * 配置页与宿主之间的 Typert Remote 面:`aperturePanel` 命名空间。
3
- *
4
- * 描述符是手工登记的,因为生成它们的 Typert 生成器并不随 DSH 发布,而这一步的规范本身很小:
5
- * 宿主半边用 `src-json` 编解码器,浏览器半边带 strict 校验,两端共享同一组端点名;参数按描述符
6
- * 里的顺序位置传入宿主方法,因此两边的名字与顺序必须一致。
7
- *
8
- * 端点 id 的 `#` 之前是包名,之后是 `<命名空间>/<方法>`。
9
- *
10
- * @module dsh-aperture/remote
11
- */
12
- import { TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol';
13
- /** 包名,同时是端点 id 的前缀。 */
14
- export const PANEL_PACKAGE = 'dsh-aperture';
15
- /** 线上命名空间,也是浏览器半边注入的服务名(`remote.aperturePanel`)。 */
16
- export const PANEL_NAMESPACE = 'aperturePanel';
17
- /**
18
- * 一个端点的宿主侧调用描述符。
19
- *
20
- * @param method - 端点方法名,同时也是宿主服务上的方法名。
21
- * @param parameters - 参数名,按宿主方法的形参顺序;省略即无参数。
22
- * @returns 一个结果为 JSON 的直调描述符。
23
- */
24
- function panelDescriptor(method, parameters = []) {
25
- return {
26
- id: `${PANEL_PACKAGE}#${PANEL_NAMESPACE}/${method}`,
27
- service: PANEL_NAMESPACE,
28
- namespace: PANEL_NAMESPACE,
29
- method,
30
- invocation: { kind: 'direct' },
31
- parameters: parameters.map((name) => ({ name, wire: name, source: 'json', codec: { mode: 'src-json' } })),
32
- result: { mode: 'src-json' },
33
- };
34
- }
35
- /**
36
- * 本插件暴露给浏览器的全部端点。
37
- *
38
- * 端点名有一处不显眼的约束:api-gateway 在客户端为每个命名空间建一个 `RemoteNamespaceService`,
39
- * 端点会成为它的属性,因此与它自己的成员重名会被 `validateContribution` 拒绝,**整份贡献一起
40
- * 撤回**(浏览器里只剩一行 console.error,界面安静地什么都不出现)。预置名有 `ctx` / `empty` /
41
- * `invokeRemote` / `methods` / `name` / `namespace` 与 `has` / `install` / `installDirect` /
42
- * `installScoped` / `assertMethodAvailable` / `remove`——新端点起名时先对一遍这份名单。
43
- */
44
- export const PANEL_INVOCATIONS = [
45
- panelDescriptor('status'),
46
- panelDescriptor('refresh'),
47
- panelDescriptor('edit', ['id', 'patch']),
48
- ];
49
- /**
50
- * 登记进 Typert 注册表的贡献。
51
- *
52
- * `schemas`/`model` 是生成器的产物,这里没有生成器,因此它们如实为空:本插件不导出可复用的
53
- * schema,也没有需要反射的业务类型。端点本身仍然完整。
54
- */
55
- export const PANEL_CONTRIBUTION = {
56
- package: PANEL_PACKAGE,
57
- face: 'host',
58
- schemas: [],
59
- invocations: PANEL_INVOCATIONS,
60
- model: { services: [], events: [], objects: [] },
61
- };
62
- /**
63
- * `aperturePanel` 宿主服务:方法与描述符一一对应,实现全部委托给 {@link PanelOps}。
64
- *
65
- * 方法签名必须与描述符的参数顺序一致——`edit` 的两个形参名字与描述符里的两个参数同名,
66
- * 顺序也相同,网关就是按描述符顺序把 wire 参数位置传入的。
67
- */
68
- export class AperturePanelService extends TypertRemoteService {
69
- ops;
70
- /**
71
- * @param ctx - 挂载上下文。
72
- * @param ops - 端点实现。
73
- */
74
- constructor(ctx, ops) {
75
- super(ctx, PANEL_NAMESPACE);
76
- this.ops = ops;
77
- }
78
- /** 最近一次刷新的报告。 */
79
- status() {
80
- return this.ops.status();
81
- }
82
- /** 立刻重新发现并发布。 */
83
- refresh() {
84
- return this.ops.refresh();
85
- }
86
- /**
87
- * 写入一个模型的参数。
88
- *
89
- * @param id - 模型 id。
90
- * @param patch - 要改的字段;`null` 表示撤销这个模型的全部覆盖。
91
- * @returns 成败与一句人话。
92
- */
93
- edit(id, patch) {
94
- return this.ops.edit(id, patch);
95
- }
96
- }
package/lib/report.d.ts DELETED
@@ -1,123 +0,0 @@
1
- /**
2
- * 报告:配置页的状态段与模型清单。
3
- *
4
- * 这里是**结构化数据**,不是拼好的句子:配置页是双语的,把中文句子拼在宿主半边就等于让英文
5
- * 界面显示中文,而「哪个模型属于哪条路由」「这条事实是谁给的」本来就是数据。宿主只把发现过程
6
- * 决定了什么摆齐——哪个端点应答了、哪些模型进了哪条路由、哪个模型没有端点能服务、每条事实来自
7
- * 哪里、哪些字段是用户写下的覆盖——措辞与排版交给界面。
8
- *
9
- * @module dsh-aperture/report
10
- */
11
- import type { ResolvedConfig } from './config.ts';
12
- import type { RefreshOutcome } from './runtime.ts';
13
- import type { FactSource, Modality } from './types.ts';
14
- /** 报告里的一个模型。 */
15
- export interface PanelModel {
16
- /** Aperture 接受的模型 id。 */
17
- readonly id: string;
18
- /** 显示名(可能来自清单或覆盖)。 */
19
- readonly name: string;
20
- /** 承载它的路由键;没有任何路由能服务时缺失。 */
21
- readonly route?: string;
22
- /** 网关通告的协议;未通告时缺失。 */
23
- readonly protocol?: string;
24
- /** 网关为该模型通告的每一个端点,用于诊断。 */
25
- readonly endpoints: readonly string[];
26
- /** 生效的上下文容量,以 token 计。 */
27
- readonly contextWindow?: number;
28
- /** 生效的最大输出,以 token 计。 */
29
- readonly maxTokens?: number;
30
- /** 生效的请求模态。 */
31
- readonly input: readonly Modality[];
32
- /** 生效的推理能力。 */
33
- readonly reasoning: boolean;
34
- /** 每项事实的来源;界面按语言渲染它。 */
35
- readonly provenance: {
36
- readonly limits: FactSource;
37
- readonly reasoning: FactSource;
38
- readonly input: FactSource;
39
- readonly name: FactSource;
40
- };
41
- /**
42
- * 用户层里这一行自己写下的键(含界面不编辑的,例如 `reasoningEfforts`;别名写成 `alias`)。
43
- *
44
- * 这是「覆盖」的唯一判据,且只能从用户层读——官方也是这么定义的:看字段在不在用户层里,
45
- * 而不是拿值与默认值比。解析后的配置用不得:schema 会把没写的数组字段补成 `[]`,界面就会
46
- * 在一行什么都没写过的模型上挂一颗永远撤不掉的「已覆盖」。
47
- */
48
- readonly overrideKeys?: readonly string[];
49
- /** 用户写下的清单别名(`aperture.modelAliases` 里对应那一项)。 */
50
- readonly alias?: string;
51
- }
52
- /** 报告里的一条已发布路由。 */
53
- export interface PanelRoute {
54
- /** provider 路由键。 */
55
- readonly provider: string;
56
- /** 服务它的协议;本插件自己拼的方案里一定有,类型上仍是可选(`PiAiProviderProfile`)。 */
57
- readonly api?: string;
58
- /** 路由的 baseURL,同上。 */
59
- readonly baseURL?: string;
60
- /** 该路由承载的模型数。 */
61
- readonly models: number;
62
- }
63
- /** 最近一次刷新做了什么。 */
64
- export interface PanelRefresh {
65
- /** 触发来源。 */
66
- readonly trigger: string;
67
- /** ISO 时间戳;界面按本地时区渲染。 */
68
- readonly at: string;
69
- /** 耗时。 */
70
- readonly durationMs: number;
71
- /** 发现与发布是否都成功。 */
72
- readonly ok: boolean;
73
- /** 失败原因。 */
74
- readonly error?: string;
75
- /** 清单提供了什么。 */
76
- readonly catalog: {
77
- /** 清单是否可用。 */
78
- readonly available: boolean;
79
- /** 条目数。 */
80
- readonly entries: number;
81
- /** 清单不可用时的原因。 */
82
- readonly reason?: string;
83
- };
84
- /** 应答的端点与它列出的行数。 */
85
- readonly endpoint?: {
86
- readonly url: string;
87
- readonly listed: number;
88
- };
89
- /** 设置写入的结果。 */
90
- readonly sync?: {
91
- readonly applied: boolean;
92
- readonly ops: number;
93
- readonly routes: readonly string[];
94
- readonly reason?: string;
95
- };
96
- }
97
- /** 配置页要显示的整份报告。 */
98
- export interface PanelReport {
99
- /** 实例地址(已归一化);没有配置时为空串,措辞交给界面。 */
100
- readonly place: string;
101
- /** 最近一次刷新;还一次都没跑过时为缺失。 */
102
- readonly refresh?: PanelRefresh;
103
- /** 已发布的路由。 */
104
- readonly routes: readonly PanelRoute[];
105
- /** 逐模型清单:先是各条路由承载的模型,最后是没有任何路由的模型。 */
106
- readonly models: readonly PanelModel[];
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
- }
115
- /**
116
- * 组装报告。
117
- *
118
- * @param outcome - 最近一次刷新;一次都没完成过时传 `undefined`。
119
- * @param config - 当前生效配置。
120
- * @param declared - 用户层里写下的覆盖;缺省即「什么都没写过」。
121
- * @returns 报告。
122
- */
123
- export declare function buildReport(outcome: RefreshOutcome | undefined, config: ResolvedConfig, declared?: DeclaredOverrides): PanelReport;
package/lib/report.js DELETED
@@ -1,109 +0,0 @@
1
- /**
2
- * 报告:配置页的状态段与模型清单。
3
- *
4
- * 这里是**结构化数据**,不是拼好的句子:配置页是双语的,把中文句子拼在宿主半边就等于让英文
5
- * 界面显示中文,而「哪个模型属于哪条路由」「这条事实是谁给的」本来就是数据。宿主只把发现过程
6
- * 决定了什么摆齐——哪个端点应答了、哪些模型进了哪条路由、哪个模型没有端点能服务、每条事实来自
7
- * 哪里、哪些字段是用户写下的覆盖——措辞与排版交给界面。
8
- *
9
- * @module dsh-aperture/report
10
- */
11
- /**
12
- * 组装报告。
13
- *
14
- * @param outcome - 最近一次刷新;一次都没完成过时传 `undefined`。
15
- * @param config - 当前生效配置。
16
- * @param declared - 用户层里写下的覆盖;缺省即「什么都没写过」。
17
- * @returns 报告。
18
- */
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
- }
31
- const routes = (outcome?.routes ?? []).map((route) => ({
32
- provider: route.provider,
33
- ...(route.profile.api === undefined ? {} : { api: route.profile.api }),
34
- ...(route.profile.baseURL === undefined ? {} : { baseURL: route.profile.baseURL }),
35
- models: route.models.length,
36
- }));
37
- const models = [];
38
- const routed = new Set();
39
- const describe = (model, route) => {
40
- routed.add(model.id);
41
- const declaredKeys = keys.get(model.id) ?? [];
42
- const alias = config.modelAliases[model.id];
43
- return {
44
- id: model.id,
45
- name: model.name,
46
- ...(route === undefined ? {} : { route }),
47
- ...(model.protocol === undefined ? {} : { protocol: model.protocol }),
48
- endpoints: model.endpoints,
49
- ...(model.contextWindow === undefined ? {} : { contextWindow: model.contextWindow }),
50
- ...(model.maxTokens === undefined ? {} : { maxTokens: model.maxTokens }),
51
- input: model.input,
52
- reasoning: model.reasoning,
53
- provenance: model.provenance,
54
- ...(declaredKeys.length === 0 ? {} : { overrideKeys: declaredKeys }),
55
- ...(alias === undefined ? {} : { alias }),
56
- };
57
- };
58
- for (const route of outcome?.routes ?? []) {
59
- for (const model of route.models)
60
- models.push(describe(model, route.provider));
61
- }
62
- // 没有任何路由能服务的模型跟在后面:它们没有协议可用,或者被配置挡掉了。
63
- for (const model of outcome?.models ?? []) {
64
- if (!routed.has(model.id))
65
- models.push(describe(model));
66
- }
67
- return {
68
- place: config.instanceRoot ?? config.rawBaseUrl,
69
- ...(outcome === undefined ? {} : { refresh: refresh(outcome) }),
70
- routes,
71
- models,
72
- };
73
- }
74
- /**
75
- * 把一次刷新收成报告要显示的字段。
76
- *
77
- * @param outcome - 已完成的刷新。
78
- * @returns 状态段的数据。
79
- */
80
- function refresh(outcome) {
81
- const catalog = outcome.catalog;
82
- const sync = outcome.sync;
83
- return {
84
- trigger: outcome.trigger,
85
- at: outcome.at.toISOString(),
86
- durationMs: outcome.durationMs,
87
- ok: outcome.ok,
88
- ...(outcome.error === undefined ? {} : { error: outcome.error }),
89
- catalog: {
90
- // `lookup` 在清单不可用时缺失;报告只报可用性,不报这个函数本身。
91
- available: catalog.lookup !== undefined,
92
- entries: catalog.entries,
93
- ...(catalog.reason === undefined ? {} : { reason: catalog.reason }),
94
- },
95
- ...(outcome.endpoint === undefined
96
- ? {}
97
- : { endpoint: { url: outcome.endpoint, listed: outcome.listed } }),
98
- ...(sync === undefined
99
- ? {}
100
- : {
101
- sync: {
102
- applied: sync.applied,
103
- ops: sync.ops,
104
- routes: sync.routes,
105
- ...(sync.reason === undefined ? {} : { reason: sync.reason }),
106
- },
107
- }),
108
- };
109
- }