dsh-aperture 0.3.1 → 0.3.3
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 +11 -10
- package/README.md +11 -10
- package/lib/client.js +1463 -0
- package/lib/client.js.map +1 -0
- package/lib/index.js +2084 -131
- package/lib/{aperture.d.ts → types/aperture.d.ts} +12 -10
- package/lib/types/catalog.d.ts +25 -0
- package/lib/types/config.d.ts +204 -0
- package/lib/types/index.d.ts +37 -0
- package/lib/{metadata → types/metadata}/extract.d.ts +15 -24
- package/lib/types/metadata/modelsdev.d.ts +40 -0
- package/lib/{metadata → types/metadata}/utils.d.ts +2 -0
- package/lib/types/panel.d.ts +71 -0
- package/lib/types/profile.d.ts +55 -0
- package/lib/types/registry.d.ts +31 -0
- package/lib/{relay.d.ts → types/relay.d.ts} +2 -0
- package/lib/types/remote.d.ts +54 -0
- package/lib/types/report.d.ts +115 -0
- package/lib/types/runtime.d.ts +87 -0
- package/lib/{sync.d.ts → types/sync.d.ts} +12 -23
- package/lib/types/types.d.ts +118 -0
- package/lib/{url.d.ts → types/url.d.ts} +5 -3
- package/package.json +44 -22
- package/client/aperture.js +0 -1566
- package/lib/aperture.js +0 -107
- package/lib/catalog.d.ts +0 -35
- package/lib/catalog.js +0 -74
- package/lib/config.d.ts +0 -214
- package/lib/config.js +0 -168
- package/lib/index.d.ts +0 -70
- package/lib/metadata/extract.js +0 -217
- package/lib/metadata/modelsdev.d.ts +0 -53
- package/lib/metadata/modelsdev.js +0 -302
- package/lib/metadata/utils.js +0 -86
- package/lib/panel.d.ts +0 -86
- package/lib/panel.js +0 -263
- package/lib/profile.d.ts +0 -62
- package/lib/profile.js +0 -158
- package/lib/registry.d.ts +0 -48
- package/lib/registry.js +0 -234
- package/lib/relay.js +0 -63
- package/lib/remote.d.ts +0 -64
- package/lib/remote.js +0 -96
- package/lib/report.d.ts +0 -123
- package/lib/report.js +0 -109
- package/lib/runtime.d.ts +0 -97
- package/lib/runtime.js +0 -194
- package/lib/sync.js +0 -176
- package/lib/types.d.ts +0 -116
- package/lib/types.js +0 -10
- package/lib/url.js +0 -67
package/lib/panel.d.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 设置界面配置页的宿主半边。
|
|
3
|
-
*
|
|
4
|
-
* 配置页本身在浏览器里跑(`client/aperture.js`),这里只留下它读不到的那几样:最近一次刷新的
|
|
5
|
-
* 报告、立刻刷新,以及单个模型参数的写入。地址与同步开关**不在这里**——那两项就在页主递来的
|
|
6
|
-
* 设置表单快照里,配置页交给同一个 `form.mutate` 写,版本校验与冲突恢复都由设置接缝负责;
|
|
7
|
-
* 同一个命名空间上挂两条写路径,只会让「谁在什么时候写」说不清。
|
|
8
|
-
*
|
|
9
|
-
* 留下的写入口是模型参数,因为它们零碎:容量、模态、推理、协议落在 `models` 的对应条目上,清单
|
|
10
|
-
* 别名落在 `modelAliases[id]`,写入按字段合并——界面没提到的字段原样留着。合并与校验在这里做,
|
|
11
|
-
* 因为写进设置文档的坏值会让下一轮刷新的 `resolveConfig` 直接抛异常。报告则不是配置:把发现的
|
|
12
|
-
* 模型塞进设置文档会让「用户写了什么」与「插件发现了什么」混成同一份账。
|
|
13
|
-
*
|
|
14
|
-
* 端点都不抛异常:失败是界面要显示的结果之一,因此它是返回值里的字段。
|
|
15
|
-
*
|
|
16
|
-
* @module dsh-aperture/panel
|
|
17
|
-
*/
|
|
18
|
-
import type { SettingsForms } from '@deepseek-ai/dsh-settings';
|
|
19
|
-
import { type ResolvedConfig } from './config.ts';
|
|
20
|
-
import { type PanelReport } from './report.ts';
|
|
21
|
-
import { type ApertureRuntime } from './runtime.ts';
|
|
22
|
-
import type { Modality } from './types.ts';
|
|
23
|
-
/**
|
|
24
|
-
* 界面为单个模型写下的参数。
|
|
25
|
-
*
|
|
26
|
-
* 补丁是**稀疏**的:界面只发改动过的字段,没提到的原样留在设置文档里——因此界面完全不编辑的
|
|
27
|
-
* `reasoningEfforts` 也不会被顺手抹掉。`null` 是「这条覆盖不要了」,即把字段从 `models` 的那
|
|
28
|
-
* 一条里删掉,回落到发现值与清单。
|
|
29
|
-
*/
|
|
30
|
-
export interface PanelModelPatch {
|
|
31
|
-
/** 显示名。 */
|
|
32
|
-
readonly name?: string | null;
|
|
33
|
-
/** 协议覆盖;也是让「未服务」的模型变得可服务的唯一方式。 */
|
|
34
|
-
readonly api?: string | null;
|
|
35
|
-
/** 上下文容量,以 token 计。 */
|
|
36
|
-
readonly contextWindow?: number | null;
|
|
37
|
-
/** 最大输出,以 token 计。 */
|
|
38
|
-
readonly maxTokens?: number | null;
|
|
39
|
-
/** 请求模态。 */
|
|
40
|
-
readonly input?: readonly Modality[] | null;
|
|
41
|
-
/** 强制打开(`true`)或关闭(`false`)推理。 */
|
|
42
|
-
readonly thinking?: boolean | null;
|
|
43
|
-
/** 清单别名(`aperture.modelAliases`);空串或 `null` 表示不设。 */
|
|
44
|
-
readonly alias?: string | null;
|
|
45
|
-
}
|
|
46
|
-
/** 一次动作的结果:成败与一句人话。 */
|
|
47
|
-
export interface PanelAction {
|
|
48
|
-
/** 动作是否落地。 */
|
|
49
|
-
readonly ok: boolean;
|
|
50
|
-
/** 面向用户的说明。 */
|
|
51
|
-
readonly summary: string;
|
|
52
|
-
}
|
|
53
|
-
/** 配置页可以调用的端点。 */
|
|
54
|
-
export interface PanelOps {
|
|
55
|
-
/** 最近一次刷新做了什么;不触发任何工作。 */
|
|
56
|
-
status(): PanelReport;
|
|
57
|
-
/** 立刻重新发现并发布。 */
|
|
58
|
-
refresh(): Promise<PanelAction>;
|
|
59
|
-
/**
|
|
60
|
-
* 写入一个模型的参数。
|
|
61
|
-
*
|
|
62
|
-
* 一次只动一个模型:界面上一行一个「保存」,版本校验也只管这一次写入。空串与 `null` 都表示
|
|
63
|
-
* 「这一项不覆盖」。写完等一轮重新发现落地才返回:报告里的容量、模态、协议都是刷新算出来的
|
|
64
|
-
* 事实,不等它就是「保存了却没变」。地址与同步开关不走这里,它们直接交给页主的设置表单。
|
|
65
|
-
*
|
|
66
|
-
* @param id - 模型 id(Aperture 接受的那个)。
|
|
67
|
-
* @param patch - 要改的字段;`null` 表示撤销这个模型的全部覆盖(含别名)。
|
|
68
|
-
*/
|
|
69
|
-
edit(id: string, patch: PanelModelPatch | null): Promise<PanelAction>;
|
|
70
|
-
}
|
|
71
|
-
/** 端点背后的东西。 */
|
|
72
|
-
export interface PanelDeps {
|
|
73
|
-
/** 发现运行时,报告与刷新都来自它。 */
|
|
74
|
-
readonly runtime: ApertureRuntime;
|
|
75
|
-
/** 当前生效配置的活引用(thunk)。 */
|
|
76
|
-
readonly config: () => ResolvedConfig;
|
|
77
|
-
/** 设置服务:读 `aperture` 段的用户层,也写它。 */
|
|
78
|
-
readonly settings: SettingsForms;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* 组装端点。
|
|
82
|
-
*
|
|
83
|
-
* @param deps - 运行时、配置活引用与设置服务。
|
|
84
|
-
* @returns 三个端点;`status` 是同步的,读一份已经算好的结果不该等待。
|
|
85
|
-
*/
|
|
86
|
-
export declare function createPanelOps(deps: PanelDeps): PanelOps;
|
package/lib/panel.js
DELETED
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 设置界面配置页的宿主半边。
|
|
3
|
-
*
|
|
4
|
-
* 配置页本身在浏览器里跑(`client/aperture.js`),这里只留下它读不到的那几样:最近一次刷新的
|
|
5
|
-
* 报告、立刻刷新,以及单个模型参数的写入。地址与同步开关**不在这里**——那两项就在页主递来的
|
|
6
|
-
* 设置表单快照里,配置页交给同一个 `form.mutate` 写,版本校验与冲突恢复都由设置接缝负责;
|
|
7
|
-
* 同一个命名空间上挂两条写路径,只会让「谁在什么时候写」说不清。
|
|
8
|
-
*
|
|
9
|
-
* 留下的写入口是模型参数,因为它们零碎:容量、模态、推理、协议落在 `models` 的对应条目上,清单
|
|
10
|
-
* 别名落在 `modelAliases[id]`,写入按字段合并——界面没提到的字段原样留着。合并与校验在这里做,
|
|
11
|
-
* 因为写进设置文档的坏值会让下一轮刷新的 `resolveConfig` 直接抛异常。报告则不是配置:把发现的
|
|
12
|
-
* 模型塞进设置文档会让「用户写了什么」与「插件发现了什么」混成同一份账。
|
|
13
|
-
*
|
|
14
|
-
* 端点都不抛异常:失败是界面要显示的结果之一,因此它是返回值里的字段。
|
|
15
|
-
*
|
|
16
|
-
* @module dsh-aperture/panel
|
|
17
|
-
*/
|
|
18
|
-
import { APERTURE_NAMESPACE } from "./config.js";
|
|
19
|
-
import { buildReport } from "./report.js";
|
|
20
|
-
import { message } from "./runtime.js";
|
|
21
|
-
/** 把未知值当成一个普通对象;数组与 `null` 都不算。 */
|
|
22
|
-
function asRecord(input) {
|
|
23
|
-
return typeof input === 'object' && input !== null && !Array.isArray(input)
|
|
24
|
-
? input
|
|
25
|
-
: {};
|
|
26
|
-
}
|
|
27
|
-
/** 一个值是不是「没写」:空串、空数组、空字典都算。 */
|
|
28
|
-
function isEmpty(value) {
|
|
29
|
-
if (value === undefined || value === null)
|
|
30
|
-
return true;
|
|
31
|
-
if (typeof value === 'string')
|
|
32
|
-
return value.trim().length === 0;
|
|
33
|
-
if (Array.isArray(value))
|
|
34
|
-
return value.length === 0;
|
|
35
|
-
if (typeof value === 'object')
|
|
36
|
-
return Object.keys(value).length === 0;
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* 剔掉一条覆盖里的空值,只留 `id` 与真正写下的内容。
|
|
41
|
-
*
|
|
42
|
-
* 生效值里混着 schema 补出来的默认值(没写的数组字段会变成 `[]`)。原样写回用户层就成了用户
|
|
43
|
-
* 从没写过的覆盖,界面上那颗「已覆盖」会一直挂着,按「恢复默认」又撤不掉。
|
|
44
|
-
*
|
|
45
|
-
* @param entry - 生效值里的一条。
|
|
46
|
-
* @returns 可以写进用户层的那几条键。
|
|
47
|
-
*/
|
|
48
|
-
function prune(entry) {
|
|
49
|
-
return Object.fromEntries(Object.entries(entry).filter(([key, value]) => key === 'id' || !isEmpty(value)));
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* 用户层里写下的覆盖。
|
|
53
|
-
*
|
|
54
|
-
* 「有没有覆盖」只能从用户层读:生效值里分不出用户写下的值与 schema 补出来的默认值。
|
|
55
|
-
*
|
|
56
|
-
* @param settings - 设置服务。
|
|
57
|
-
* @returns `aperture.models` 的原样条目,以及写过别名的模型 id。
|
|
58
|
-
*/
|
|
59
|
-
function declaredOverrides(settings) {
|
|
60
|
-
const user = readSection(settings).user;
|
|
61
|
-
return {
|
|
62
|
-
models: (Array.isArray(user.models) ? user.models : []).map(asRecord),
|
|
63
|
-
aliasIds: Object.keys(asRecord(user.modelAliases)),
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* 读 `aperture` 段。
|
|
68
|
-
*
|
|
69
|
-
* `value` 是叠加默认值、组合层与用户层后的生效值,`user` 是用户层的原始片段——字段在不在
|
|
70
|
-
* `user` 里才是「有没有被覆盖」的判据,拿生效值去和组合层比会得出错误答案。
|
|
71
|
-
*
|
|
72
|
-
* @param settings - 设置服务。
|
|
73
|
-
* @returns 解析视图;命名空间尚未注册或描述符读不到时给出空值。
|
|
74
|
-
*/
|
|
75
|
-
function readSection(settings) {
|
|
76
|
-
let descriptor;
|
|
77
|
-
try {
|
|
78
|
-
descriptor = settings.describe({ redactSecrets: true }).find((entry) => entry.ns === APERTURE_NAMESPACE);
|
|
79
|
-
}
|
|
80
|
-
catch {
|
|
81
|
-
// `describe()` 会为**每个** entry 跑一遍解析,所以某个不相干的 entry 自己坏掉也会让整次
|
|
82
|
-
// 读取抛异常。页面宁可显示「未注册」也不要整块打不开——写入路径另有它自己的报错。
|
|
83
|
-
descriptor = undefined;
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
value: asRecord(descriptor?.value),
|
|
87
|
-
user: asRecord(descriptor?.user),
|
|
88
|
-
revision: descriptor?.revision,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* 把补丁合并进 `models` 里的一条覆盖。
|
|
93
|
-
*
|
|
94
|
-
* 只做**校验与合并**,不做任何写入:非法值在这里挡下来,因为写进设置文档的坏值会让下一轮刷新的
|
|
95
|
-
* `resolveConfig` 直接抛异常,而界面只能给用户一份再也刷新不出来的报告。
|
|
96
|
-
*
|
|
97
|
-
* @param base - 现有条目;没有时只带 `id`。
|
|
98
|
-
* @param patch - 界面发来的稀疏补丁。
|
|
99
|
-
* @returns 合并后的条目(已经没有任何字段时为 `undefined`),或一个错误。
|
|
100
|
-
*/
|
|
101
|
-
function mergeEntry(base, patch) {
|
|
102
|
-
const entry = { ...base };
|
|
103
|
-
if (patch.name !== undefined) {
|
|
104
|
-
const name = patch.name === null ? '' : patch.name.trim();
|
|
105
|
-
if (name.length === 0)
|
|
106
|
-
delete entry.name;
|
|
107
|
-
else
|
|
108
|
-
entry.name = name;
|
|
109
|
-
}
|
|
110
|
-
if (patch.api !== undefined) {
|
|
111
|
-
const api = patch.api === null ? '' : patch.api.trim();
|
|
112
|
-
if (api.length === 0)
|
|
113
|
-
delete entry.api;
|
|
114
|
-
else if (api !== 'openai-completions' && api !== 'anthropic-messages') {
|
|
115
|
-
return { error: `api "${api}" 无法服务;只能是 openai-completions 或 anthropic-messages` };
|
|
116
|
-
}
|
|
117
|
-
else
|
|
118
|
-
entry.api = api;
|
|
119
|
-
}
|
|
120
|
-
for (const field of ['contextWindow', 'maxTokens']) {
|
|
121
|
-
const value = patch[field];
|
|
122
|
-
if (value === undefined)
|
|
123
|
-
continue;
|
|
124
|
-
if (value === null) {
|
|
125
|
-
delete entry[field];
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
if (!Number.isInteger(value) || value < 1) {
|
|
129
|
-
return { error: `${field} 必须是不小于 1 的整数` };
|
|
130
|
-
}
|
|
131
|
-
entry[field] = value;
|
|
132
|
-
}
|
|
133
|
-
if (patch.input !== undefined) {
|
|
134
|
-
const input = patch.input === null ? [] : [...new Set(patch.input)];
|
|
135
|
-
if (input.some((item) => item !== 'text' && item !== 'image')) {
|
|
136
|
-
return { error: 'input 只能包含 text 或 image' };
|
|
137
|
-
}
|
|
138
|
-
if (input.length === 0)
|
|
139
|
-
delete entry.input;
|
|
140
|
-
else
|
|
141
|
-
entry.input = input;
|
|
142
|
-
}
|
|
143
|
-
if (patch.thinking !== undefined) {
|
|
144
|
-
if (patch.thinking === null)
|
|
145
|
-
delete entry.thinking;
|
|
146
|
-
else
|
|
147
|
-
entry.thinking = patch.thinking;
|
|
148
|
-
}
|
|
149
|
-
return Object.keys(entry).some((key) => key !== 'id') ? { entry } : {};
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* 组装端点。
|
|
153
|
-
*
|
|
154
|
-
* @param deps - 运行时、配置活引用与设置服务。
|
|
155
|
-
* @returns 三个端点;`status` 是同步的,读一份已经算好的结果不该等待。
|
|
156
|
-
*/
|
|
157
|
-
export function createPanelOps(deps) {
|
|
158
|
-
// 报告每次都按当前配置现组装:覆盖与别名本身是配置,改完必须立刻能在列表里看到。
|
|
159
|
-
const report = () => buildReport(deps.runtime.last(), deps.config(), declaredOverrides(deps.settings));
|
|
160
|
-
return {
|
|
161
|
-
status: report,
|
|
162
|
-
async refresh() {
|
|
163
|
-
// 刷新自己吞掉异常并把原因放进 outcome,因此这里只搬运它。
|
|
164
|
-
const outcome = await deps.runtime.refresh('设置界面');
|
|
165
|
-
return outcome.ok
|
|
166
|
-
? { ok: true, summary: '已重新发现并发布。' }
|
|
167
|
-
: { ok: false, summary: `刷新没有成功:${outcome.error ?? '原因未知'}` };
|
|
168
|
-
},
|
|
169
|
-
async edit(id, patch) {
|
|
170
|
-
const modelId = typeof id === 'string' ? id.trim() : '';
|
|
171
|
-
if (modelId.length === 0)
|
|
172
|
-
return { ok: false, summary: '缺少模型 id。' };
|
|
173
|
-
// 补丁必须显式给出:`null` 是「撤销这个模型的全部覆盖」,缺失是调用方写错了。
|
|
174
|
-
if (patch === undefined || (patch !== null && typeof patch !== 'object')) {
|
|
175
|
-
return { ok: false, summary: '缺少要写入的参数。' };
|
|
176
|
-
}
|
|
177
|
-
const section = readSection(deps.settings);
|
|
178
|
-
// `models` 是数组,而路径操作只能整段替换它,因此每次都算出完整的新数组再写回去。
|
|
179
|
-
// 基础取自生效值(组合层若也写过 models,它在界面上本来就是看得见的那些条目),但空值要
|
|
180
|
-
// 剔掉:schema 补出来的 `[]` 不该被写进用户层(见 `prune`)。
|
|
181
|
-
const before = (Array.isArray(section.value.models) ? section.value.models : []).map((entry) => prune(asRecord(entry)));
|
|
182
|
-
const aliases = asRecord(section.value.modelAliases);
|
|
183
|
-
// 撤销别名只在**用户层确实有**这个键时才写:界面显示的是生效别名,它可能来自组合层或
|
|
184
|
-
// 清单,而删一个不存在的键要么白写、要么被设置服务当成坏路径拒绝,两种都不该发生。
|
|
185
|
-
const owned = asRecord(section.user.modelAliases);
|
|
186
|
-
const index = before.findIndex((entry) => entry.id === modelId);
|
|
187
|
-
const currentAlias = typeof aliases[modelId] === 'string' ? aliases[modelId] : '';
|
|
188
|
-
let models = before;
|
|
189
|
-
const nextAliases = { ...aliases };
|
|
190
|
-
let revoked = false;
|
|
191
|
-
if (patch === null) {
|
|
192
|
-
// `null` 是「撤销这个模型的全部覆盖」:`models` 里那条与清单别名一起走。
|
|
193
|
-
models = before.filter((_, at) => at !== index);
|
|
194
|
-
if (currentAlias.length > 0)
|
|
195
|
-
delete nextAliases[modelId];
|
|
196
|
-
revoked = true;
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
const merged = mergeEntry(index === -1 ? { id: modelId } : before[index], patch);
|
|
200
|
-
if (merged.error !== undefined)
|
|
201
|
-
return { ok: false, summary: `"${modelId}":${merged.error}` };
|
|
202
|
-
// 就地替换而不是挪到末尾:一条覆盖的位置不该因为改了一个字段就变(界面上也一样,
|
|
203
|
-
// 列表顺序来自路由与发现顺序,不来自用户改过哪一条)。
|
|
204
|
-
if (index === -1) {
|
|
205
|
-
if (merged.entry !== undefined)
|
|
206
|
-
models = [...before, merged.entry];
|
|
207
|
-
}
|
|
208
|
-
else if (merged.entry === undefined) {
|
|
209
|
-
models = before.filter((_, at) => at !== index);
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
models = before.map((entry, at) => (at === index ? merged.entry : entry));
|
|
213
|
-
}
|
|
214
|
-
// 别名不进 `models`:它是「网关 id → 清单 id」的映射,与覆盖是两件事。
|
|
215
|
-
const alias = patch.alias === undefined ? currentAlias : (patch.alias ?? '').trim();
|
|
216
|
-
if (alias.length === 0)
|
|
217
|
-
delete nextAliases[modelId];
|
|
218
|
-
else
|
|
219
|
-
nextAliases[modelId] = alias;
|
|
220
|
-
}
|
|
221
|
-
const ops = [];
|
|
222
|
-
if (JSON.stringify(models) !== JSON.stringify(before)) {
|
|
223
|
-
ops.push({ op: 'set', path: ['models'], value: models });
|
|
224
|
-
}
|
|
225
|
-
// 别名逐键比对:改过的写、撤掉的删,没动过的连碰都不碰。
|
|
226
|
-
for (const key of new Set([...Object.keys(aliases), ...Object.keys(nextAliases)])) {
|
|
227
|
-
if (nextAliases[key] === aliases[key])
|
|
228
|
-
continue;
|
|
229
|
-
if (nextAliases[key] !== undefined) {
|
|
230
|
-
ops.push({ op: 'set', path: ['modelAliases', key], value: nextAliases[key] });
|
|
231
|
-
continue;
|
|
232
|
-
}
|
|
233
|
-
// 生效值里没有它了,但界面上那只是「回落到清单」;只有用户层写过才需要删。
|
|
234
|
-
if (Object.prototype.hasOwnProperty.call(owned, key)) {
|
|
235
|
-
ops.push({ op: 'unset', path: ['modelAliases', key] });
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
if (ops.length === 0)
|
|
239
|
-
return { ok: true, summary: '没有要保存的改动。' };
|
|
240
|
-
try {
|
|
241
|
-
// 带着刚读到的版本号写入:期间别人改过就拒绝,而不是覆盖他的改动。
|
|
242
|
-
await deps.settings.mutate(APERTURE_NAMESPACE, ops, section.revision);
|
|
243
|
-
// 写完等这一轮刷新落地再回答:这一行的容量、模态、协议都是刷新算出来的事实,不等它,
|
|
244
|
-
// 配置页重读报告时看到的还是旧值——「保存了却没变」就是这么来的。配置变更自己也会唤起
|
|
245
|
-
// 同一轮刷新(Loader 的 `loader/volatile-update`),运行时的单飞判定按配置版本合并,
|
|
246
|
-
// 因此这里通常并进那一轮,而不是另跑一轮。
|
|
247
|
-
const outcome = await deps.runtime.refresh('配置变更');
|
|
248
|
-
const saved = revoked
|
|
249
|
-
? `已撤销 "${modelId}" 的全部覆盖,回落到发现值与清单`
|
|
250
|
-
: `已保存 "${modelId}" 的参数`;
|
|
251
|
-
return {
|
|
252
|
-
ok: true,
|
|
253
|
-
summary: outcome.ok
|
|
254
|
-
? `${saved},并按新配置重新发现。`
|
|
255
|
-
: `${saved},但重新发现没有成功:${outcome.error ?? '原因未知'}`,
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
catch (error) {
|
|
259
|
-
return { ok: false, summary: `保存失败:${message(error)}` };
|
|
260
|
-
}
|
|
261
|
-
},
|
|
262
|
-
};
|
|
263
|
-
}
|
package/lib/profile.d.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 发布阶段:把发现的模型变成 `llm-pi-ai` provider profile。
|
|
3
|
-
*
|
|
4
|
-
* 这里不做任何负载转换:发布的两种协议都由已安装的 `dsh-llm-pi-ai` 适配器实现,剩下的
|
|
5
|
-
* 工作只是逐模型陈述适配器无法从一个无法识别的网关 URL 推断出的事实——模型有多大、接受
|
|
6
|
-
* 什么,以及它的推理控制如何在协议格式上传输。
|
|
7
|
-
*
|
|
8
|
-
* 该适配器的两个怪癖塑造了本模块:未随附在它清单里的路由必须声明 `api`、`baseURL` 与
|
|
9
|
-
* **非空**的 `models`,因此空无一物的协议不产生路由;它的 OpenAI 兼容路径在既无凭据、又
|
|
10
|
-
* 无非空 `authorization` 头时拒绝派发,所以没有配 `apiKeyEnv` 的路由会带上一个占位头。
|
|
11
|
-
*
|
|
12
|
-
* @module dsh-aperture/profile
|
|
13
|
-
*/
|
|
14
|
-
import type { PiAiProviderProfile } from '@deepseek-ai/dsh-llm-pi-ai';
|
|
15
|
-
import type { ConfiguredModel, DiscoveredModel } from './types.ts';
|
|
16
|
-
/** 无凭据路由发送的占位凭据的默认值。 */
|
|
17
|
-
export declare const DEFAULT_PLACEHOLDER_CREDENTIAL = "dsh-aperture";
|
|
18
|
-
/** 一次发布过程所需的全部内容。 */
|
|
19
|
-
export interface ProfileOptions {
|
|
20
|
-
/** 归一化后的实例根。 */
|
|
21
|
-
readonly instanceRoot: string;
|
|
22
|
-
/** 拥有 OpenAI 兼容模型的路由键。 */
|
|
23
|
-
readonly route: string;
|
|
24
|
-
/** 拥有 Anthropic Messages 模型的路由键。 */
|
|
25
|
-
readonly anthropicRoute: string;
|
|
26
|
-
/** OpenAI 兼容路由的选择器标签。 */
|
|
27
|
-
readonly displayName: string;
|
|
28
|
-
/** Anthropic 路由的选择器标签。 */
|
|
29
|
-
readonly anthropicDisplayName: string;
|
|
30
|
-
/** 凭据引用;部署配置了才有。 */
|
|
31
|
-
readonly apiKeyEnv?: string;
|
|
32
|
-
/** 额外的路由头;它们优先于占位头。 */
|
|
33
|
-
readonly headers: Readonly<Record<string, string>>;
|
|
34
|
-
/** 已配置的逐模型覆盖项,用于查询显式的推理档位。 */
|
|
35
|
-
readonly configured: readonly ConfiguredModel[];
|
|
36
|
-
}
|
|
37
|
-
/** 一条可写入 `llm-pi-ai` 配置段的路由。 */
|
|
38
|
-
export interface RoutePlan {
|
|
39
|
-
/** provider 路由键。 */
|
|
40
|
-
readonly provider: string;
|
|
41
|
-
/** profile 本身,与将被存储的内容完全一致。 */
|
|
42
|
-
readonly profile: PiAiProviderProfile;
|
|
43
|
-
/** 该路由发布的模型,用于报告。 */
|
|
44
|
-
readonly models: readonly DiscoveredModel[];
|
|
45
|
-
}
|
|
46
|
-
/** 完整的发布方案。 */
|
|
47
|
-
export interface ProfilePlan {
|
|
48
|
-
/** 至少含一个模型的路由,顺序稳定。 */
|
|
49
|
-
readonly routes: readonly RoutePlan[];
|
|
50
|
-
/** 没有任何路由可以服务的已发现模型。 */
|
|
51
|
-
readonly unserved: readonly DiscoveredModel[];
|
|
52
|
-
/** 本插件拥有的每个路由键,无论它当前是否有模型。 */
|
|
53
|
-
readonly ownedRoutes: readonly string[];
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* 把归一化后的注册表变成 provider profile。
|
|
57
|
-
*
|
|
58
|
-
* @param models - 所有已发现的模型。
|
|
59
|
-
* @param options - 路由与凭据配置。
|
|
60
|
-
* @returns 要发布的路由,以及未能被服务的模型。
|
|
61
|
-
*/
|
|
62
|
-
export declare function buildProfilePlan(models: readonly DiscoveredModel[], options: ProfileOptions): ProfilePlan;
|
package/lib/profile.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 发布阶段:把发现的模型变成 `llm-pi-ai` provider profile。
|
|
3
|
-
*
|
|
4
|
-
* 这里不做任何负载转换:发布的两种协议都由已安装的 `dsh-llm-pi-ai` 适配器实现,剩下的
|
|
5
|
-
* 工作只是逐模型陈述适配器无法从一个无法识别的网关 URL 推断出的事实——模型有多大、接受
|
|
6
|
-
* 什么,以及它的推理控制如何在协议格式上传输。
|
|
7
|
-
*
|
|
8
|
-
* 该适配器的两个怪癖塑造了本模块:未随附在它清单里的路由必须声明 `api`、`baseURL` 与
|
|
9
|
-
* **非空**的 `models`,因此空无一物的协议不产生路由;它的 OpenAI 兼容路径在既无凭据、又
|
|
10
|
-
* 无非空 `authorization` 头时拒绝派发,所以没有配 `apiKeyEnv` 的路由会带上一个占位头。
|
|
11
|
-
*
|
|
12
|
-
* @module dsh-aperture/profile
|
|
13
|
-
*/
|
|
14
|
-
import { isDeepSeekFamily } from "./registry.js";
|
|
15
|
-
import { buildRouteBaseUrl } from "./url.js";
|
|
16
|
-
/** 无凭据路由发送的占位凭据的默认值。 */
|
|
17
|
-
export const DEFAULT_PLACEHOLDER_CREDENTIAL = 'dsh-aperture';
|
|
18
|
-
/** 为 DeepSeek 方言模型提供的推理档位。 */
|
|
19
|
-
const DEEPSEEK_EFFORTS = { off: 'disabled', high: 'high', max: 'max' };
|
|
20
|
-
/**
|
|
21
|
-
* 为其他所有推理模型提供的推理档位。
|
|
22
|
-
*
|
|
23
|
-
* `off` 无值——适配器把它映射为「什么都不发」,对 OpenAI 兼容端点而言这就是把思考交给
|
|
24
|
-
* 模型自行决定。它之上的那一档是 Aperture 在它所代理的全部模型上都能接受的最宽写法;
|
|
25
|
-
* `minimal`、`xhigh`、`max` 都至少被某个上游以 400 拒绝过,因此发现的模型绝不提供,
|
|
26
|
-
* 更了解的部署可以在 `models` 里逐模型声明。
|
|
27
|
-
*/
|
|
28
|
-
const GENERIC_EFFORTS = { off: null, high: 'high' };
|
|
29
|
-
/**
|
|
30
|
-
* 把归一化后的注册表变成 provider profile。
|
|
31
|
-
*
|
|
32
|
-
* @param models - 所有已发现的模型。
|
|
33
|
-
* @param options - 路由与凭据配置。
|
|
34
|
-
* @returns 要发布的路由,以及未能被服务的模型。
|
|
35
|
-
*/
|
|
36
|
-
export function buildProfilePlan(models, options) {
|
|
37
|
-
const openai = models.filter((model) => model.protocol === 'openai-completions');
|
|
38
|
-
const anthropic = models.filter((model) => model.protocol === 'anthropic-messages');
|
|
39
|
-
const routes = [];
|
|
40
|
-
if (openai.length > 0) {
|
|
41
|
-
routes.push({
|
|
42
|
-
provider: options.route,
|
|
43
|
-
profile: buildProfile('openai-completions', openai, options),
|
|
44
|
-
models: openai,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
if (anthropic.length > 0) {
|
|
48
|
-
routes.push({
|
|
49
|
-
provider: options.anthropicRoute,
|
|
50
|
-
profile: buildProfile('anthropic-messages', anthropic, options),
|
|
51
|
-
models: anthropic,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
routes,
|
|
56
|
-
unserved: models.filter((model) => model.protocol === undefined),
|
|
57
|
-
ownedRoutes: [options.route, options.anthropicRoute],
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
/** 构建一种协议的路由 profile。 */
|
|
61
|
-
function buildProfile(protocol, models, options) {
|
|
62
|
-
const headers = routeHeaders(protocol, options);
|
|
63
|
-
return {
|
|
64
|
-
displayName: protocol === 'openai-completions' ? options.displayName : options.anthropicDisplayName,
|
|
65
|
-
api: protocol,
|
|
66
|
-
baseURL: buildRouteBaseUrl(options.instanceRoot, protocol),
|
|
67
|
-
...(options.apiKeyEnv === undefined ? {} : { apiKeyEnv: options.apiKeyEnv }),
|
|
68
|
-
...(headers === undefined ? {} : { headers }),
|
|
69
|
-
models: models.map((model) => buildModelEntry(model, protocol, options)),
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* 一条路由发送的头。
|
|
74
|
-
*
|
|
75
|
-
* 已配置的 `apiKeyEnv` 完全取代占位头——此后由凭据接缝提供。插件自身配置里的部署头在两种
|
|
76
|
-
* 情况下都优先于占位头,需要真实静态令牌的网关正是借此拿到它。
|
|
77
|
-
*
|
|
78
|
-
* @param protocol - 该路由的协议。
|
|
79
|
-
* @param options - 配置。
|
|
80
|
-
* @returns 头字典;该路由不需要任何头时为 `undefined`。
|
|
81
|
-
*/
|
|
82
|
-
function routeHeaders(protocol, options) {
|
|
83
|
-
const headers = {};
|
|
84
|
-
const hasCredential = options.apiKeyEnv !== undefined ||
|
|
85
|
-
Object.keys(options.headers).some((name) => {
|
|
86
|
-
const lower = name.toLowerCase();
|
|
87
|
-
return lower === 'authorization' || lower === 'x-api-key' || lower === 'cf-aig-authorization';
|
|
88
|
-
});
|
|
89
|
-
if (!hasCredential) {
|
|
90
|
-
if (protocol === 'openai-completions') {
|
|
91
|
-
headers.authorization = `Bearer ${DEFAULT_PLACEHOLDER_CREDENTIAL}`;
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
headers['x-api-key'] = DEFAULT_PLACEHOLDER_CREDENTIAL;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
Object.assign(headers, options.headers);
|
|
98
|
-
return Object.keys(headers).length === 0 ? undefined : headers;
|
|
99
|
-
}
|
|
100
|
-
/** 构建一条已配置的模型条目。 */
|
|
101
|
-
function buildModelEntry(model, protocol, options) {
|
|
102
|
-
const configured = options.configured.find((candidate) => candidate.id.trim() === model.id);
|
|
103
|
-
const reasoning = resolveReasoning(model, protocol, configured);
|
|
104
|
-
return {
|
|
105
|
-
id: model.id,
|
|
106
|
-
name: model.name,
|
|
107
|
-
...(model.contextWindow === undefined ? {} : { contextWindow: model.contextWindow }),
|
|
108
|
-
...(model.maxTokens === undefined ? {} : { maxTokens: model.maxTokens }),
|
|
109
|
-
input: [...model.input],
|
|
110
|
-
...reasoning,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
/** 解析一条模型条目携带的推理字段。 */
|
|
114
|
-
function resolveReasoning(model, protocol, configured) {
|
|
115
|
-
// 空字典等于什么都没声明。适配器会以「reasoningEfforts 是空的」为由拒绝**整段**写入——
|
|
116
|
-
// 于是所有路由一条都发布不出去,而用户写下 `{}` 想说的显然不是「这条模型没有任何推理
|
|
117
|
-
// 档位」(那该写 `false`)。适配器自己的建议是省略这个字段以沿用已安装清单的能力,
|
|
118
|
-
// 这里照它办。
|
|
119
|
-
const declared = configured?.reasoningEfforts;
|
|
120
|
-
if (declared !== undefined && Object.keys(declared).length > 0) {
|
|
121
|
-
return { reasoningEfforts: { ...declared }, ...compatFor(model, protocol) };
|
|
122
|
-
}
|
|
123
|
-
if (!model.reasoning) {
|
|
124
|
-
return {};
|
|
125
|
-
}
|
|
126
|
-
// Anthropic 传输通过 token 预算而非推理档位驱动思考,而网关的列表完全没说上游接受哪种
|
|
127
|
-
// 预算。因此除非部署另有声明,发现的 Anthropic 模型一律按不具备推理能力处理。
|
|
128
|
-
if (protocol === 'anthropic-messages' && configured?.thinking !== true) {
|
|
129
|
-
return {};
|
|
130
|
-
}
|
|
131
|
-
if (isDeepSeekFamily(model)) {
|
|
132
|
-
// 对 DeepSeek 方言而言 `off` 必须非 null:只有当该档位映射到某个值时,适配器才会
|
|
133
|
-
// 发送 `thinking: { type: "disabled" }`。
|
|
134
|
-
return { reasoningEfforts: { ...DEEPSEEK_EFFORTS }, ...compatFor(model, protocol) };
|
|
135
|
-
}
|
|
136
|
-
return { reasoningEfforts: { ...GENERIC_EFFORTS }, ...compatFor(model, protocol) };
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* 推理模型所需的 compat 块。
|
|
140
|
-
*
|
|
141
|
-
* pi-ai 从 provider id 与 base URL 推断协议格式兼容性,而 Aperture 的 URL 对它说明不了
|
|
142
|
-
* 什么,因此 DeepSeek 方言必须直接声明。`supportsReasoningEffort` 也要声明:URL 无法被
|
|
143
|
-
* pi-ai 归位的网关目前默认为 true,但真正让 `reasoning_effort` 传输出去的是这个开关。
|
|
144
|
-
*
|
|
145
|
-
* @param model - 被描述的模型。
|
|
146
|
-
* @param protocol - 该路由的协议。
|
|
147
|
-
* @returns compat 块,或空对象。
|
|
148
|
-
*/
|
|
149
|
-
function compatFor(model, protocol) {
|
|
150
|
-
if (protocol !== 'openai-completions') {
|
|
151
|
-
return {};
|
|
152
|
-
}
|
|
153
|
-
const compat = { supportsReasoningEffort: true };
|
|
154
|
-
if (isDeepSeekFamily(model)) {
|
|
155
|
-
compat.thinkingFormat = 'deepseek';
|
|
156
|
-
}
|
|
157
|
-
return { compat };
|
|
158
|
-
}
|
package/lib/registry.d.ts
DELETED
|
@@ -1,48 +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 type { ApertureProtocol, BuildOptions, CatalogLookup, DiscoveredModel } from './types.ts';
|
|
21
|
-
/** 一次归一化的结果。 */
|
|
22
|
-
export interface RegistryResult {
|
|
23
|
-
/** 所有模型,包括没有路由能服务的那些(它们的 `protocol` 缺失)。 */
|
|
24
|
-
readonly models: readonly DiscoveredModel[];
|
|
25
|
-
/** 没有任何已配置路由能服务的子集。 */
|
|
26
|
-
readonly unserved: readonly DiscoveredModel[];
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* 归一化、补全并合并一份网关清单。
|
|
30
|
-
*
|
|
31
|
-
* @param entries - 按端点顺序排列的原始模型行。
|
|
32
|
-
* @param options - 配置开关。
|
|
33
|
-
* @param lookup - 清单元数据查找器,在已加载时提供。
|
|
34
|
-
* @returns 每个模型及其来源,以及没有路由能服务的那些模型。
|
|
35
|
-
*/
|
|
36
|
-
export declare function buildRegistry(entries: readonly unknown[], options: BuildOptions, lookup?: CatalogLookup): RegistryResult;
|
|
37
|
-
/**
|
|
38
|
-
* 决定一个模型通告的端点适配哪条路由。
|
|
39
|
-
*
|
|
40
|
-
* 完全没有通告端点的清单按 OpenAI 兼容处理:不上报传输方式的网关绝大多数就是普通
|
|
41
|
-
* Chat Completions 代理,而没有路由的模型无论如何都不可用。
|
|
42
|
-
*
|
|
43
|
-
* @param endpoints - 通告的端点路径。
|
|
44
|
-
* @returns 可服务的协议;没有适配的协议时为 `undefined`。
|
|
45
|
-
*/
|
|
46
|
-
export declare function classifyProtocol(endpoints: readonly string[]): ApertureProtocol | undefined;
|
|
47
|
-
/** 判断一个模型是否属于 DeepSeek 推理方言。 */
|
|
48
|
-
export declare function isDeepSeekFamily(model: DiscoveredModel): boolean;
|