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/config.d.ts
CHANGED
|
@@ -1,44 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 配置 schema 与解析。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* 本插件拥有自己的 entry(`aperture`,用户层就是 profile patch 里那一行的 `config`),
|
|
5
|
+
* 但发布出去的一切都写进**另一个** entry `llm-pi-ai`:本插件决定有哪些模型,那个适配器
|
|
6
|
+
* 决定怎么跟它们说话。
|
|
7
|
+
*
|
|
8
|
+
* 整份 schema 都是 volatile 的:设置接缝**只**暴露 volatile 字段(没有 volatile 节点的
|
|
9
|
+
* entry 不出现在 `describe()` 里,界面就无从编辑),而这里每个字段都只影响下一轮发现、
|
|
10
|
+
* 没有一项需要重启——于是配置改动被 Loader 当作就地换引用的活更新,插件不重新挂载,
|
|
11
|
+
* 正在跑的那轮刷新也不会被掐断。
|
|
9
12
|
*
|
|
10
13
|
* @module dsh-aperture/config
|
|
11
14
|
*/
|
|
12
15
|
import z from '@deepseek-ai/schemastery';
|
|
13
|
-
|
|
16
|
+
/** 本插件拥有、并可通过它配置的设置命名空间。 */
|
|
17
|
+
export declare const APERTURE_NAMESPACE = "aperture";
|
|
14
18
|
/** 默认清单地址;参考实现用的是同一份文档。 */
|
|
15
19
|
export declare const DEFAULT_MODEL_METADATA_URL = "https://models.dev/models.json";
|
|
16
20
|
/** 当 Aperture 与清单都没给出容量时,为模型假定的上下文容量。 */
|
|
17
21
|
export declare const DEFAULT_CONTEXT_WINDOW = 128000;
|
|
22
|
+
/** 访问网关与清单的单次请求超时。没有哪个部署需要为此改一次配置。 */
|
|
23
|
+
export declare const DEFAULT_TIMEOUT_MS = 20000;
|
|
18
24
|
/** 插件配置。 */
|
|
19
25
|
export interface Config {
|
|
20
26
|
/** Aperture 实例根地址,例如 `https://ai.example.ts.net`。留空则关闭发现。 */
|
|
21
27
|
baseUrl?: string;
|
|
22
|
-
/** 承载 OpenAI
|
|
28
|
+
/** 承载 OpenAI 兼容模型的路由键;Anthropic 那条路由与两者的显示名都从它推出来({@link derivedNames})。 */
|
|
23
29
|
route?: string;
|
|
24
|
-
/** 承载 Anthropic Messages 模型的路由键。 */
|
|
25
|
-
anthropicRoute?: string;
|
|
26
|
-
/** OpenAI 兼容路由在选择器里显示的名字。 */
|
|
27
|
-
displayName?: string;
|
|
28
|
-
/** Anthropic 路由在选择器里显示的名字。 */
|
|
29
|
-
anthropicDisplayName?: string;
|
|
30
30
|
/** 按请求解析的凭据引用;留空则改为发布一个占位请求头。 */
|
|
31
31
|
apiKeyEnv?: string;
|
|
32
|
-
/** 占位凭据的值;空串表示不发布占位请求头。 */
|
|
33
|
-
placeholderCredential?: string;
|
|
34
32
|
/** 每条路由的请求都会带上的额外请求头;它们优先于占位凭据。 */
|
|
35
33
|
headers?: Record<string, string>;
|
|
36
34
|
/** 非空时,只发现这些模型 id。 */
|
|
37
35
|
enabledModelIds?: string[];
|
|
38
|
-
/**
|
|
39
|
-
* 网关模型 id → models.dev 模型 id,用于清单里写法不同的 id
|
|
40
|
-
* (`deepseek-flash` → `deepseek/deepseek-v4-flash`)。
|
|
41
|
-
*/
|
|
36
|
+
/** 网关模型 id → models.dev 模型 id,用于两边写法不同的 id。 */
|
|
42
37
|
modelAliases?: Record<string, string>;
|
|
43
38
|
/** 覆盖与追加,按 id 合并。 */
|
|
44
39
|
models?: Array<{
|
|
@@ -53,8 +48,6 @@ export interface Config {
|
|
|
53
48
|
}>;
|
|
54
49
|
/** models.dev 清单地址;留空则关闭这次补齐。 */
|
|
55
50
|
modelMetadataUrl?: string;
|
|
56
|
-
/** 没有任何来源给出容量时使用的上下文容量。 */
|
|
57
|
-
defaultContextWindow?: number;
|
|
58
51
|
/** `metadata` 接受清单里的输入模态;`ignore` 声明为纯文本。 */
|
|
59
52
|
images?: 'ignore' | 'metadata';
|
|
60
53
|
/** `auto` 映射模型的推理能力;`off` 声明所有模型都不推理。 */
|
|
@@ -63,21 +56,21 @@ export interface Config {
|
|
|
63
56
|
sync?: boolean;
|
|
64
57
|
/** 自动刷新间隔(分钟);`0` 表示只在加载时与配置变更时刷新。 */
|
|
65
58
|
refreshIntervalMinutes?: number;
|
|
66
|
-
/** 访问网关与清单的单次请求超时。 */
|
|
67
|
-
timeoutMs?: number;
|
|
68
59
|
}
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
60
|
+
/**
|
|
61
|
+
* {@link Config} 的运行时 schema。
|
|
62
|
+
*
|
|
63
|
+
* 根节点上的 `.volatile()` 让整份配置成为活引用:`apply` 拿到的是 `Ref`,读值走
|
|
64
|
+
* `.get()`,每次变更都是对同一引用的 `updateVolatile`。校验与默认值照旧——volatile
|
|
65
|
+
* 只改变结果如何被持有。
|
|
66
|
+
*/
|
|
67
|
+
export declare const Config: z<NoInfer<Schemastery.ObjectS<NoInfer<{
|
|
68
|
+
baseUrl: z<string, string, "defined">;
|
|
69
|
+
route: z<string, string, "defined">;
|
|
70
|
+
apiKeyEnv: z<string, string, "defined">;
|
|
71
|
+
headers: z<import("@deepseek-ai/cosmokit").Dict<string, string>, import("@deepseek-ai/cosmokit").Dict<string, string>, "defined">;
|
|
72
|
+
enabledModelIds: z<string[], string[], "defined">;
|
|
73
|
+
modelAliases: z<import("@deepseek-ai/cosmokit").Dict<string, string>, import("@deepseek-ai/cosmokit").Dict<string, string>, "defined">;
|
|
81
74
|
models: z<({
|
|
82
75
|
id?: string | null | undefined;
|
|
83
76
|
name?: string | null | undefined;
|
|
@@ -87,42 +80,36 @@ export declare const Config: z<Schemastery.ObjectS<{
|
|
|
87
80
|
input?: ("text" | "image")[] | null | undefined;
|
|
88
81
|
thinking?: boolean | null | undefined;
|
|
89
82
|
reasoningEfforts?: import("@deepseek-ai/cosmokit").Dict<string | null, string> | null | undefined;
|
|
90
|
-
} & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<{
|
|
83
|
+
} & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<NoInfer<{
|
|
91
84
|
/** 模型 id;与已发现的 id 对应,或者新增一个网关没有列出的模型。 */
|
|
92
|
-
id: z<string, string>;
|
|
85
|
+
id: z<string, string, "defined">;
|
|
93
86
|
/** 选择器里显示的名字。 */
|
|
94
|
-
name: z<string, string>;
|
|
87
|
+
name: z<string, string, "plain">;
|
|
95
88
|
/** 协议覆盖:`openai-completions` 或 `anthropic-messages`。 */
|
|
96
|
-
api: z<string, string>;
|
|
89
|
+
api: z<string, string, "plain">;
|
|
97
90
|
/** 上下文容量(token 数)。 */
|
|
98
|
-
contextWindow: z<number, number>;
|
|
91
|
+
contextWindow: z<number, number, "plain">;
|
|
99
92
|
/** 输出能力(token 数)。 */
|
|
100
|
-
maxTokens: z<number, number>;
|
|
93
|
+
maxTokens: z<number, number, "plain">;
|
|
101
94
|
/** 请求模态。 */
|
|
102
|
-
input: z<("text" | "image")[], ("text" | "image")[]>;
|
|
95
|
+
input: z<("text" | "image")[], ("text" | "image")[], "plain">;
|
|
103
96
|
/** 强制打开或关闭推理能力。 */
|
|
104
|
-
thinking: z<boolean, boolean>;
|
|
97
|
+
thinking: z<boolean, boolean, "plain">;
|
|
105
98
|
/** 提供的推理档位:键 = 档位,值 = 协议里的写法。 */
|
|
106
|
-
reasoningEfforts: z<import("@deepseek-ai/cosmokit").Dict<string | null, string>, import("@deepseek-ai/cosmokit").Dict<string | null, string
|
|
107
|
-
}
|
|
108
|
-
modelMetadataUrl: z<string, string>;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
anthropicDisplayName: z<string, string>;
|
|
121
|
-
apiKeyEnv: z<string, string>;
|
|
122
|
-
placeholderCredential: z<string, string>;
|
|
123
|
-
headers: z<import("@deepseek-ai/cosmokit").Dict<string, string>, import("@deepseek-ai/cosmokit").Dict<string, string>>;
|
|
124
|
-
enabledModelIds: z<string[], string[]>;
|
|
125
|
-
modelAliases: z<import("@deepseek-ai/cosmokit").Dict<string, string>, import("@deepseek-ai/cosmokit").Dict<string, string>>;
|
|
99
|
+
reasoningEfforts: z<import("@deepseek-ai/cosmokit").Dict<string | null, string>, import("@deepseek-ai/cosmokit").Dict<string | null, string>, "plain">;
|
|
100
|
+
}>>[], "defined">;
|
|
101
|
+
modelMetadataUrl: z<string, string, "defined">;
|
|
102
|
+
images: z<"ignore" | "metadata", "ignore" | "metadata", "defined">;
|
|
103
|
+
reasoning: z<"auto" | "off", "auto" | "off", "defined">;
|
|
104
|
+
sync: z<boolean, boolean, "defined">;
|
|
105
|
+
refreshIntervalMinutes: z<number, number, "defined">;
|
|
106
|
+
}>>>, NoInfer<Schemastery.ObjectT<NoInfer<{
|
|
107
|
+
baseUrl: z<string, string, "defined">;
|
|
108
|
+
route: z<string, string, "defined">;
|
|
109
|
+
apiKeyEnv: z<string, string, "defined">;
|
|
110
|
+
headers: z<import("@deepseek-ai/cosmokit").Dict<string, string>, import("@deepseek-ai/cosmokit").Dict<string, string>, "defined">;
|
|
111
|
+
enabledModelIds: z<string[], string[], "defined">;
|
|
112
|
+
modelAliases: z<import("@deepseek-ai/cosmokit").Dict<string, string>, import("@deepseek-ai/cosmokit").Dict<string, string>, "defined">;
|
|
126
113
|
models: z<({
|
|
127
114
|
id?: string | null | undefined;
|
|
128
115
|
name?: string | null | undefined;
|
|
@@ -132,32 +119,54 @@ export declare const Config: z<Schemastery.ObjectS<{
|
|
|
132
119
|
input?: ("text" | "image")[] | null | undefined;
|
|
133
120
|
thinking?: boolean | null | undefined;
|
|
134
121
|
reasoningEfforts?: import("@deepseek-ai/cosmokit").Dict<string | null, string> | null | undefined;
|
|
135
|
-
} & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<{
|
|
122
|
+
} & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<NoInfer<{
|
|
136
123
|
/** 模型 id;与已发现的 id 对应,或者新增一个网关没有列出的模型。 */
|
|
137
|
-
id: z<string, string>;
|
|
124
|
+
id: z<string, string, "defined">;
|
|
138
125
|
/** 选择器里显示的名字。 */
|
|
139
|
-
name: z<string, string>;
|
|
126
|
+
name: z<string, string, "plain">;
|
|
140
127
|
/** 协议覆盖:`openai-completions` 或 `anthropic-messages`。 */
|
|
141
|
-
api: z<string, string>;
|
|
128
|
+
api: z<string, string, "plain">;
|
|
142
129
|
/** 上下文容量(token 数)。 */
|
|
143
|
-
contextWindow: z<number, number>;
|
|
130
|
+
contextWindow: z<number, number, "plain">;
|
|
144
131
|
/** 输出能力(token 数)。 */
|
|
145
|
-
maxTokens: z<number, number>;
|
|
132
|
+
maxTokens: z<number, number, "plain">;
|
|
146
133
|
/** 请求模态。 */
|
|
147
|
-
input: z<("text" | "image")[], ("text" | "image")[]>;
|
|
134
|
+
input: z<("text" | "image")[], ("text" | "image")[], "plain">;
|
|
148
135
|
/** 强制打开或关闭推理能力。 */
|
|
149
|
-
thinking: z<boolean, boolean>;
|
|
136
|
+
thinking: z<boolean, boolean, "plain">;
|
|
150
137
|
/** 提供的推理档位:键 = 档位,值 = 协议里的写法。 */
|
|
151
|
-
reasoningEfforts: z<import("@deepseek-ai/cosmokit").Dict<string | null, string>, import("@deepseek-ai/cosmokit").Dict<string | null, string
|
|
152
|
-
}
|
|
153
|
-
modelMetadataUrl: z<string, string>;
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
138
|
+
reasoningEfforts: z<import("@deepseek-ai/cosmokit").Dict<string | null, string>, import("@deepseek-ai/cosmokit").Dict<string | null, string>, "plain">;
|
|
139
|
+
}>>[], "defined">;
|
|
140
|
+
modelMetadataUrl: z<string, string, "defined">;
|
|
141
|
+
images: z<"ignore" | "metadata", "ignore" | "metadata", "defined">;
|
|
142
|
+
reasoning: z<"auto" | "off", "auto" | "off", "defined">;
|
|
143
|
+
sync: z<boolean, boolean, "defined">;
|
|
144
|
+
refreshIntervalMinutes: z<number, number, "defined">;
|
|
145
|
+
}>>>, "volatile">;
|
|
146
|
+
/**
|
|
147
|
+
* Loader 交到 `apply` 手里的配置活引用。
|
|
148
|
+
*
|
|
149
|
+
* `.get()` 返回深冻结快照,且只在值真的变了之后才换引用——这正是 {@link memoizedConfig}
|
|
150
|
+
* 与运行时单飞判定所依赖的「配置版本」。
|
|
151
|
+
*/
|
|
152
|
+
export type ConfigRef = ReturnType<typeof Config>;
|
|
153
|
+
/**
|
|
154
|
+
* 取活引用里的那份普通配置值。
|
|
155
|
+
*
|
|
156
|
+
* 根级 volatile 只改变配置**怎么被持有**,解析与校验照旧(非法值仍在 `Config(raw)` 当场
|
|
157
|
+
* 抛出,默认值也已补齐),所以这里只把活引用读成一份快照,交给不关心「活」的那几层。
|
|
158
|
+
*
|
|
159
|
+
* @param ref - Loader 交到 `apply` 手里的配置活引用。
|
|
160
|
+
* @returns 当前那份深冻结的普通配置值。
|
|
161
|
+
*/
|
|
162
|
+
export declare function configValue(ref: ConfigRef): FilledConfig;
|
|
163
|
+
/**
|
|
164
|
+
* 默认值补齐之后的配置。
|
|
165
|
+
*
|
|
166
|
+
* {@link Config} 是**用户可写**的形状(每个键可选);schema 输出的那份不是——每个字段
|
|
167
|
+
* 都带 `.default()`。把这个事实写进类型,调用方就不必对着一堆必然存在的字段写 `??`。
|
|
168
|
+
*/
|
|
169
|
+
export type FilledConfig = Required<Config>;
|
|
161
170
|
/** 校验过的配置:默认值已全部补齐,根地址已归一化。 */
|
|
162
171
|
export interface ResolvedConfig {
|
|
163
172
|
/** 归一化后的实例根地址;关闭发现时为 `undefined`。 */
|
|
@@ -170,28 +179,36 @@ export interface ResolvedConfig {
|
|
|
170
179
|
readonly anthropicDisplayName: string;
|
|
171
180
|
/** 凭据引用;未配置时为 `undefined`。 */
|
|
172
181
|
readonly apiKeyEnv: string | undefined;
|
|
173
|
-
readonly placeholderCredential: string;
|
|
174
182
|
readonly headers: Readonly<Record<string, string>>;
|
|
175
183
|
readonly enabledModelIds: readonly string[];
|
|
176
184
|
readonly modelAliases: Readonly<Record<string, string>>;
|
|
177
185
|
readonly models: NonNullable<Config['models']>;
|
|
178
186
|
readonly modelMetadataUrl: string;
|
|
179
|
-
readonly defaultContextWindow: number;
|
|
180
187
|
readonly images: 'ignore' | 'metadata';
|
|
181
188
|
readonly reasoning: 'auto' | 'off';
|
|
182
189
|
readonly sync: boolean;
|
|
183
190
|
readonly refreshIntervalMinutes: number;
|
|
184
|
-
readonly timeoutMs: number;
|
|
185
191
|
}
|
|
186
192
|
/**
|
|
187
193
|
* 解析一段配置,只拒绝那些自身就矛盾的错误。
|
|
188
194
|
*
|
|
189
|
-
* `baseUrl` 缺失或不可用**不**算错误:插件照常挂载但处于休眠,这样 profile
|
|
190
|
-
*
|
|
191
|
-
*
|
|
195
|
+
* `baseUrl` 缺失或不可用**不**算错误:插件照常挂载但处于休眠,这样 profile 可以在还没人
|
|
196
|
+
* 填地址时就先带着这一行。路由键则必须拒绝——写错的路由键无法靠后续写入补救,插件会静默地
|
|
197
|
+
* 什么都不发布。
|
|
192
198
|
*
|
|
193
|
-
* @param config -
|
|
199
|
+
* @param config - 已补齐默认值的 `aperture` 段(`configValue` 的返回值,不是活引用)。
|
|
194
200
|
* @returns 校验过的配置。
|
|
195
|
-
* @throws Error
|
|
201
|
+
* @throws Error 当路由键不合文法、或模型覆盖自身重复/无法服务时抛出,并在消息里点名字段。
|
|
196
202
|
*/
|
|
197
203
|
export declare function resolveConfig(config: Config): ResolvedConfig;
|
|
204
|
+
/**
|
|
205
|
+
* 把「解析当前的配置段」包成一个按源缓存的 thunk。
|
|
206
|
+
*
|
|
207
|
+
* 配置活引用的 `.get()` 只在值真的变了之后才换快照,没变就还是同一个对象,因此返回值可以
|
|
208
|
+
* 直接当**配置版本**用。不缓存的话每次调用都是新对象,运行时的版本判断永远不成立,于是每次
|
|
209
|
+
* 刷新都会多排一轮。
|
|
210
|
+
*
|
|
211
|
+
* @param source - 生效配置段的活引用(每次编辑都就地换掉它的内容)。
|
|
212
|
+
* @returns 解析后的配置;源没换时返回同一个对象。
|
|
213
|
+
*/
|
|
214
|
+
export declare function memoizedConfig(source: () => Config): () => ResolvedConfig;
|
package/lib/config.js
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 配置 schema 与解析。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* 本插件拥有自己的 entry(`aperture`,用户层就是 profile patch 里那一行的 `config`),
|
|
5
|
+
* 但发布出去的一切都写进**另一个** entry `llm-pi-ai`:本插件决定有哪些模型,那个适配器
|
|
6
|
+
* 决定怎么跟它们说话。
|
|
7
|
+
*
|
|
8
|
+
* 整份 schema 都是 volatile 的:设置接缝**只**暴露 volatile 字段(没有 volatile 节点的
|
|
9
|
+
* entry 不出现在 `describe()` 里,界面就无从编辑),而这里每个字段都只影响下一轮发现、
|
|
10
|
+
* 没有一项需要重启——于是配置改动被 Loader 当作就地换引用的活更新,插件不重新挂载,
|
|
11
|
+
* 正在跑的那轮刷新也不会被掐断。
|
|
9
12
|
*
|
|
10
13
|
* @module dsh-aperture/config
|
|
11
14
|
*/
|
|
12
15
|
import z from '@deepseek-ai/schemastery';
|
|
13
|
-
import { DEFAULT_PLACEHOLDER_CREDENTIAL } from "./profile.js";
|
|
14
16
|
import { normalizeBaseUrl } from "./url.js";
|
|
15
|
-
|
|
17
|
+
/** 本插件拥有、并可通过它配置的设置命名空间。 */
|
|
18
|
+
export const APERTURE_NAMESPACE = 'aperture';
|
|
16
19
|
/** 默认清单地址;参考实现用的是同一份文档。 */
|
|
17
20
|
export const DEFAULT_MODEL_METADATA_URL = 'https://models.dev/models.json';
|
|
18
21
|
/** 当 Aperture 与清单都没给出容量时,为模型假定的上下文容量。 */
|
|
19
22
|
export const DEFAULT_CONTEXT_WINDOW = 128_000;
|
|
23
|
+
/** 访问网关与清单的单次请求超时。没有哪个部署需要为此改一次配置。 */
|
|
24
|
+
export const DEFAULT_TIMEOUT_MS = 20_000;
|
|
20
25
|
/** provider 路由键的文法,与 Models 页面自身的规则一致。 */
|
|
21
26
|
const ROUTE_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
22
27
|
/** 一个配置好的模型:对已发现模型的覆盖,或者一个额外的模型。 */
|
|
@@ -38,53 +43,73 @@ const modelConfig = z.object({
|
|
|
38
43
|
/** 提供的推理档位:键 = 档位,值 = 协议里的写法。 */
|
|
39
44
|
reasoningEfforts: z.dict(z.union([z.string(), z.const(null)])),
|
|
40
45
|
});
|
|
41
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* {@link Config} 的运行时 schema。
|
|
48
|
+
*
|
|
49
|
+
* 根节点上的 `.volatile()` 让整份配置成为活引用:`apply` 拿到的是 `Ref`,读值走
|
|
50
|
+
* `.get()`,每次变更都是对同一引用的 `updateVolatile`。校验与默认值照旧——volatile
|
|
51
|
+
* 只改变结果如何被持有。
|
|
52
|
+
*/
|
|
42
53
|
export const Config = z.object({
|
|
43
54
|
baseUrl: z.string().default(''),
|
|
44
55
|
route: z.string().default('aperture'),
|
|
45
|
-
anthropicRoute: z.string().default('aperture-anthropic'),
|
|
46
|
-
displayName: z.string().default('Aperture'),
|
|
47
|
-
anthropicDisplayName: z.string().default('Aperture (Anthropic)'),
|
|
48
56
|
apiKeyEnv: z.string().default(''),
|
|
49
|
-
placeholderCredential: z.string().default(DEFAULT_PLACEHOLDER_CREDENTIAL),
|
|
50
57
|
headers: z.dict(z.string()).default({}),
|
|
51
58
|
enabledModelIds: z.array(z.string()).default([]),
|
|
52
59
|
modelAliases: z.dict(z.string()).default({}),
|
|
53
60
|
models: z.array(modelConfig).default([]),
|
|
54
61
|
modelMetadataUrl: z.string().default(DEFAULT_MODEL_METADATA_URL),
|
|
55
|
-
defaultContextWindow: z.number().step(1).min(1).default(DEFAULT_CONTEXT_WINDOW),
|
|
56
62
|
images: z.union([z.const('ignore'), z.const('metadata')]).default('ignore'),
|
|
57
63
|
reasoning: z.union([z.const('auto'), z.const('off')]).default('auto'),
|
|
58
64
|
sync: z.boolean().default(true),
|
|
59
65
|
refreshIntervalMinutes: z.number().min(0).max(24 * 60).default(0),
|
|
60
|
-
|
|
61
|
-
|
|
66
|
+
}).volatile();
|
|
67
|
+
/**
|
|
68
|
+
* 取活引用里的那份普通配置值。
|
|
69
|
+
*
|
|
70
|
+
* 根级 volatile 只改变配置**怎么被持有**,解析与校验照旧(非法值仍在 `Config(raw)` 当场
|
|
71
|
+
* 抛出,默认值也已补齐),所以这里只把活引用读成一份快照,交给不关心「活」的那几层。
|
|
72
|
+
*
|
|
73
|
+
* @param ref - Loader 交到 `apply` 手里的配置活引用。
|
|
74
|
+
* @returns 当前那份深冻结的普通配置值。
|
|
75
|
+
*/
|
|
76
|
+
export function configValue(ref) {
|
|
77
|
+
return (ref.get() ?? {});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 从一个路由键推出这一对路由的名字与显示名。
|
|
81
|
+
*
|
|
82
|
+
* 这三条事实曾经是三个可写字段,但一个部署要换的从来只是前缀:Anthropic 那条加
|
|
83
|
+
* `-anthropic` 后缀,显示名是路由键的标题写法(`aperture` → `Aperture`)。让它们互相
|
|
84
|
+
* 矛盾因此变成不可能,而不是要校验出来的错误。
|
|
85
|
+
*
|
|
86
|
+
* @param route - 已经过文法校验的 OpenAI 兼容路由键。
|
|
87
|
+
* @returns 三条推导出来的名字。
|
|
88
|
+
*/
|
|
89
|
+
function derivedNames(route) {
|
|
90
|
+
const displayName = route
|
|
91
|
+
.split('-')
|
|
92
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
93
|
+
.join(' ');
|
|
94
|
+
return { anthropicRoute: `${route}-anthropic`, displayName, anthropicDisplayName: `${displayName} (Anthropic)` };
|
|
95
|
+
}
|
|
62
96
|
/**
|
|
63
97
|
* 解析一段配置,只拒绝那些自身就矛盾的错误。
|
|
64
98
|
*
|
|
65
|
-
* `baseUrl` 缺失或不可用**不**算错误:插件照常挂载但处于休眠,这样 profile
|
|
66
|
-
*
|
|
67
|
-
*
|
|
99
|
+
* `baseUrl` 缺失或不可用**不**算错误:插件照常挂载但处于休眠,这样 profile 可以在还没人
|
|
100
|
+
* 填地址时就先带着这一行。路由键则必须拒绝——写错的路由键无法靠后续写入补救,插件会静默地
|
|
101
|
+
* 什么都不发布。
|
|
68
102
|
*
|
|
69
|
-
* @param config -
|
|
103
|
+
* @param config - 已补齐默认值的 `aperture` 段(`configValue` 的返回值,不是活引用)。
|
|
70
104
|
* @returns 校验过的配置。
|
|
71
|
-
* @throws Error
|
|
105
|
+
* @throws Error 当路由键不合文法、或模型覆盖自身重复/无法服务时抛出,并在消息里点名字段。
|
|
72
106
|
*/
|
|
73
107
|
export function resolveConfig(config) {
|
|
74
108
|
const rawBaseUrl = (config.baseUrl ?? '').trim();
|
|
75
109
|
const instanceRoot = normalizeBaseUrl(rawBaseUrl);
|
|
76
110
|
const route = (config.route ?? '').trim();
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
['route', route],
|
|
80
|
-
['anthropicRoute', anthropicRoute],
|
|
81
|
-
]) {
|
|
82
|
-
if (!ROUTE_PATTERN.test(value)) {
|
|
83
|
-
throw new Error(`${field} "${value}" 必须是小写连字符形式的 provider 路由名(需匹配 ${String(ROUTE_PATTERN)})`);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
if (route === anthropicRoute) {
|
|
87
|
-
throw new Error(`route 与 anthropicRoute 不能相同,两者都是 "${route}"`);
|
|
111
|
+
if (!ROUTE_PATTERN.test(route)) {
|
|
112
|
+
throw new Error(`route "${route}" 必须是小写连字符形式的 provider 路由名(需匹配 ${String(ROUTE_PATTERN)})`);
|
|
88
113
|
}
|
|
89
114
|
const models = config.models ?? [];
|
|
90
115
|
const seen = new Set();
|
|
@@ -106,21 +131,38 @@ export function resolveConfig(config) {
|
|
|
106
131
|
instanceRoot,
|
|
107
132
|
rawBaseUrl,
|
|
108
133
|
route,
|
|
109
|
-
|
|
110
|
-
displayName: (config.displayName ?? '').trim() || 'Aperture',
|
|
111
|
-
anthropicDisplayName: (config.anthropicDisplayName ?? '').trim() || 'Aperture (Anthropic)',
|
|
134
|
+
...derivedNames(route),
|
|
112
135
|
apiKeyEnv: apiKeyEnv.length === 0 ? undefined : apiKeyEnv,
|
|
113
|
-
placeholderCredential: config.placeholderCredential ?? DEFAULT_PLACEHOLDER_CREDENTIAL,
|
|
114
136
|
headers: config.headers ?? {},
|
|
115
137
|
enabledModelIds: config.enabledModelIds ?? [],
|
|
116
138
|
modelAliases: config.modelAliases ?? {},
|
|
117
139
|
models,
|
|
118
140
|
modelMetadataUrl: (config.modelMetadataUrl ?? '').trim(),
|
|
119
|
-
defaultContextWindow: config.defaultContextWindow ?? DEFAULT_CONTEXT_WINDOW,
|
|
120
141
|
images: config.images ?? 'ignore',
|
|
121
142
|
reasoning: config.reasoning ?? 'auto',
|
|
122
143
|
sync: config.sync ?? true,
|
|
123
144
|
refreshIntervalMinutes: config.refreshIntervalMinutes ?? 0,
|
|
124
|
-
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* 把「解析当前的配置段」包成一个按源缓存的 thunk。
|
|
149
|
+
*
|
|
150
|
+
* 配置活引用的 `.get()` 只在值真的变了之后才换快照,没变就还是同一个对象,因此返回值可以
|
|
151
|
+
* 直接当**配置版本**用。不缓存的话每次调用都是新对象,运行时的版本判断永远不成立,于是每次
|
|
152
|
+
* 刷新都会多排一轮。
|
|
153
|
+
*
|
|
154
|
+
* @param source - 生效配置段的活引用(每次编辑都就地换掉它的内容)。
|
|
155
|
+
* @returns 解析后的配置;源没换时返回同一个对象。
|
|
156
|
+
*/
|
|
157
|
+
export function memoizedConfig(source) {
|
|
158
|
+
let from;
|
|
159
|
+
let resolved;
|
|
160
|
+
return () => {
|
|
161
|
+
const current = source();
|
|
162
|
+
if (resolved === undefined || from !== current) {
|
|
163
|
+
from = current;
|
|
164
|
+
resolved = resolveConfig(current);
|
|
165
|
+
}
|
|
166
|
+
return resolved;
|
|
125
167
|
};
|
|
126
168
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -2,23 +2,19 @@
|
|
|
2
2
|
* dsh-aperture:发现 Aperture 网关所服务的模型,并把它们作为 `llm-pi-ai` 的
|
|
3
3
|
* provider 路由发布给 DeepSeek Harness。
|
|
4
4
|
*
|
|
5
|
-
* Aperture 是 Tailscale 的集中式 LLM
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* “获取可用模型”动作只接受用户当时还在编辑的一份草稿,而它写在文档里的局限是
|
|
10
|
-
* “一条路由的模型清单永远不会自己刷新”。
|
|
5
|
+
* Aperture 是 Tailscale 的集中式 LLM 网关:一个端点挡在团队有权使用的所有上游前面,靠网络
|
|
6
|
+
* 身份而不是密钥认证。harness 本来就会跟这样的网关说话——`dsh-llm-pi-ai` 讲 OpenAI 兼容的
|
|
7
|
+
* Chat Completions 与 Anthropic Messages,而这正是 Aperture 暴露的全部——但没有东西让模型
|
|
8
|
+
* 清单自己刷新:适配器自带的“获取可用模型”只接受一份当时还在编辑的草稿。
|
|
11
9
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* 的东西。
|
|
10
|
+
* 本插件就是缺的那一半:读 `GET {baseUrl}/v1/models`,逐个模型判断网关实际用哪种协议服务它,
|
|
11
|
+
* 用网关自己的字段加上 models.dev 定容量、写描述,最后写进 `llm-pi-ai` 的 provider 字典。
|
|
12
|
+
* 它不转换任何协议格式——这正是重点。
|
|
16
13
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* 界面——发现本身发生在插件加载、配置变更与刷新间隔到点上。
|
|
14
|
+
* 界面在「插件」页里:浏览器半边(`client/aperture.js`)把自己注册成插件管理页的**包级**配置页
|
|
15
|
+
* (`plugins.bundle.config`,键是包名),用来改实例地址与同步开关(关掉即撤下已发布的路由)、
|
|
16
|
+
* 立刻刷新,以及就地改单个模型的参数。除此之外没有别的界面——发现本身发生在插件加载、配置变更
|
|
17
|
+
* 与刷新间隔到点上。
|
|
22
18
|
*
|
|
23
19
|
* ```yaml
|
|
24
20
|
* - id: aperture
|
|
@@ -30,44 +26,45 @@
|
|
|
30
26
|
* @module dsh-aperture
|
|
31
27
|
*/
|
|
32
28
|
import type { Context } from '@deepseek-ai/cordis';
|
|
33
|
-
import { type
|
|
29
|
+
import { type ConfigRef } from './config.ts';
|
|
34
30
|
export { fetchModelsListing } from './aperture.ts';
|
|
35
31
|
export type { ModelsListing } from './aperture.ts';
|
|
36
32
|
export { ModelCatalog } from './catalog.ts';
|
|
37
|
-
export { APERTURE_NAMESPACE, DEFAULT_CONTEXT_WINDOW, DEFAULT_MODEL_METADATA_URL,
|
|
38
|
-
export type { Config as ApertureConfig, ResolvedConfig } from './config.ts';
|
|
33
|
+
export { APERTURE_NAMESPACE, DEFAULT_CONTEXT_WINDOW, DEFAULT_MODEL_METADATA_URL, resolveConfig, } from './config.ts';
|
|
34
|
+
export type { Config as ApertureConfig, ConfigRef, ResolvedConfig } from './config.ts';
|
|
39
35
|
export { createPanelOps } from './panel.ts';
|
|
40
|
-
export type { PanelAction,
|
|
36
|
+
export type { PanelAction, PanelDeps, PanelModelPatch, PanelOps } from './panel.ts';
|
|
41
37
|
export { buildReport } from './report.ts';
|
|
42
|
-
export type {
|
|
38
|
+
export type { DeclaredOverrides, PanelModel, PanelRefresh, PanelReport, PanelRoute } from './report.ts';
|
|
43
39
|
export { DEFAULT_PLACEHOLDER_CREDENTIAL, buildProfilePlan } from './profile.ts';
|
|
44
40
|
export type { ProfilePlan, ProfileOptions, RoutePlan } from './profile.ts';
|
|
45
41
|
export { buildRegistry, classifyProtocol, isDeepSeekFamily } from './registry.ts';
|
|
46
42
|
export type { RegistryResult } from './registry.ts';
|
|
47
43
|
export { AperturePanelService, PANEL_CONTRIBUTION, PANEL_INVOCATIONS, PANEL_NAMESPACE, PANEL_PACKAGE } from './remote.ts';
|
|
48
|
-
export {
|
|
44
|
+
export { PI_AI_NAMESPACE, applySync, planSync } from './sync.ts';
|
|
49
45
|
export type { SyncOutcome } from './sync.ts';
|
|
50
46
|
export type { ConfiguredModel, DiscoveredModel, FactSource, Modality, ModelProvenance } from './types.ts';
|
|
51
47
|
export { buildModelsEndpoint, buildRouteBaseUrl, normalizeBaseUrl } from './url.ts';
|
|
52
|
-
export { Config } from './config.ts';
|
|
48
|
+
export { Config, configValue } from './config.ts';
|
|
53
49
|
/** 出现在加载器诊断里的插件名。 */
|
|
54
50
|
export declare const name = "dsh-aperture";
|
|
55
51
|
/**
|
|
56
|
-
* settings
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
52
|
+
* settings 是必需依赖:把发现的模型清单发布进 `llm-pi-ai` **就是**本插件的职责,而同一次
|
|
53
|
+
* 注册又让插件自己的 `aperture` 段变得可编辑。声明它意味着框架会把插件挂在 PENDING 直到
|
|
54
|
+
* settings 就绪,provider 被替换时卸载插件、恢复后重新加载——而不是留下一个已加载却无处
|
|
55
|
+
* 发布的实例。
|
|
60
56
|
*
|
|
61
|
-
* `typert`
|
|
62
|
-
*
|
|
57
|
+
* `typert` 则刻意**不**声明:配置页只是顺手提供的便利,没有它的部署(例如 headless profile)
|
|
58
|
+
* 也该照样获得发现能力,因此它在下面按需注入,不在就安静跳过。
|
|
63
59
|
*/
|
|
64
60
|
export declare const inject: string[];
|
|
65
61
|
/**
|
|
66
62
|
* 发布网关的模型清单:现在发布,之后有任何变化也发布。
|
|
67
63
|
*
|
|
68
64
|
* @param ctx - 插件上下文,其中 `settings` 已就绪。
|
|
69
|
-
* @param config - 组合层的 `aperture` 段,已按
|
|
70
|
-
*
|
|
65
|
+
* @param config - 组合层的 `aperture` 段,已按 `Config` schema 校验并带上默认值;根级 volatile
|
|
66
|
+
* 使它成为活引用,读值走 `config.get()`。
|
|
67
|
+
* @throws Error 当配置自身矛盾(路由键不合文法、模型覆盖重复或无法服务),或存储的 `aperture`
|
|
71
68
|
* 段非法时抛出——框架的失败路径正是“坏配置要响亮”的实现方式。
|
|
72
69
|
*/
|
|
73
|
-
export declare function apply(ctx: Context, config:
|
|
70
|
+
export declare function apply(ctx: Context, config: ConfigRef): void;
|