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
@@ -1,3 +1,4 @@
1
+ //#region src/aperture.d.ts
1
2
  /**
2
3
  * 端点问询:`GET {instance}/v1/models`。
3
4
  *
@@ -9,19 +10,19 @@
9
10
  */
10
11
  /** 一份成功的清单。 */
11
12
  export interface ModelsListing {
12
- /** 按端点顺序排列的原始模型条目。 */
13
- readonly entries: readonly unknown[];
14
- /** 应答的 URL。 */
15
- readonly endpoint: string;
13
+ /** 按端点顺序排列的原始模型条目。 */
14
+ readonly entries: readonly unknown[];
15
+ /** 应答的 URL。 */
16
+ readonly endpoint: string;
16
17
  }
17
18
  /** 一次问询的请求选项。 */
18
19
  export interface FetchModelsOptions {
19
- /** 随请求发送的、`accept` 之外的请求头。 */
20
- readonly headers?: Readonly<Record<string, string>>;
21
- /** 经过这么多毫秒后中止请求。 */
22
- readonly timeoutMs?: number;
23
- /** 调用方的取消信号,与超时组合使用。 */
24
- readonly signal?: AbortSignal;
20
+ /** 随请求发送的、`accept` 之外的请求头。 */
21
+ readonly headers?: Readonly<Record<string, string>>;
22
+ /** 经过这么多毫秒后中止请求。 */
23
+ readonly timeoutMs?: number;
24
+ /** 调用方的取消信号,与超时组合使用。 */
25
+ readonly signal?: AbortSignal;
25
26
  }
26
27
  /**
27
28
  * 问询一个 Aperture 实例,获取它服务的模型。
@@ -44,3 +45,4 @@ export declare function fetchModelsListing(instanceRoot: string, options?: Fetch
44
45
  * @throws 当响应体不是可识别的清单时抛出 Error。
45
46
  */
46
47
  export declare function readEntries(body: unknown, endpoint: string): readonly unknown[];
48
+ //#endregion
@@ -0,0 +1,25 @@
1
+ import { CatalogLookup } from "./types.js";
2
+ //#region src/catalog.d.ts
3
+ /** 一次清单加载的结果,用于诊断报告。 */
4
+ export interface CatalogLoad {
5
+ /** 查找器,在加载到可用文档时提供。 */
6
+ readonly lookup?: CatalogLookup;
7
+ /** 已索引条目的数量,在加载成功时提供。 */
8
+ readonly entries: number;
9
+ /** 没有可用查找器的原因,在不可用时提供。 */
10
+ readonly reason?: string;
11
+ }
12
+ /** 一个清单 URL 的进程生命周期缓存。 */
13
+ export declare class ModelCatalog {
14
+ private loaded;
15
+ /**
16
+ * 加载(或复用)某个 URL 上的清单。
17
+ * @param url - 清单 URL;为空则禁用查找。
18
+ * @param timeoutMs - 每次请求的超时时间。
19
+ * @returns 加载结果;从不抛出。
20
+ */
21
+ load(url: string, timeoutMs: number): Promise<CatalogLoad>;
22
+ /** 抓取、解析并索引一份清单文档。 */
23
+ private fetchCatalog;
24
+ }
25
+ //#endregion
@@ -0,0 +1,204 @@
1
+ import z from "@deepseek-ai/schemastery";
2
+ //#region src/config.d.ts
3
+ /** 本插件拥有、并可通过它配置的设置命名空间。 */
4
+ export declare const APERTURE_NAMESPACE = "aperture";
5
+ /** 默认清单地址;参考实现用的是同一份文档。 */
6
+ export declare const DEFAULT_MODEL_METADATA_URL = "https://models.dev/models.json";
7
+ /** 当 Aperture 与清单都没给出容量时,为模型假定的上下文容量。 */
8
+ export declare const DEFAULT_CONTEXT_WINDOW = 128000;
9
+ /** 访问网关与清单的单次请求超时。没有哪个部署需要为此改一次配置。 */
10
+ export declare const DEFAULT_TIMEOUT_MS = 20000;
11
+ /** 插件配置。 */
12
+ export interface Config {
13
+ /** Aperture 实例根地址,例如 `https://ai.example.ts.net`。留空则关闭发现。 */
14
+ baseUrl?: string;
15
+ /** 承载 Chat Completions 模型的路由键;Responses、Anthropic 路由及显示名都从它推出来。 */
16
+ route?: string;
17
+ /** 按请求解析的凭据引用;留空则改为发布一个占位请求头。 */
18
+ apiKeyEnv?: string;
19
+ /** 每条路由的请求都会带上的额外请求头;它们优先于占位凭据。 */
20
+ headers?: Record<string, string>;
21
+ /** 非空时,只发现这些模型 id。 */
22
+ enabledModelIds?: string[];
23
+ /** 网关模型 id → models.dev 模型 id,用于两边写法不同的 id。 */
24
+ modelAliases?: Record<string, string>;
25
+ /** 覆盖与追加,按 id 合并。 */
26
+ models?: Array<{
27
+ id: string;
28
+ name?: string;
29
+ api?: string;
30
+ contextWindow?: number;
31
+ maxTokens?: number;
32
+ input?: Array<'text' | 'image'>;
33
+ thinking?: boolean;
34
+ reasoningEfforts?: Record<string, string | null>;
35
+ }>;
36
+ /** models.dev 清单地址;留空则关闭这次补齐。 */
37
+ modelMetadataUrl?: string;
38
+ /** `metadata` 接受清单里的输入模态;`ignore` 声明为纯文本。 */
39
+ images?: 'ignore' | 'metadata';
40
+ /** `auto` 映射模型的推理能力;`off` 声明所有模型都不推理。 */
41
+ reasoning?: 'auto' | 'off';
42
+ /** 是否把发现的模型清单写进 `llm-pi-ai` 段。 */
43
+ sync?: boolean;
44
+ /** 自动刷新间隔(分钟);`0` 表示只在加载时与配置变更时刷新。 */
45
+ refreshIntervalMinutes?: number;
46
+ }
47
+ /**
48
+ * {@link Config} 的运行时 schema。
49
+ *
50
+ * 根节点上的 `.volatile()` 让整份配置成为活引用:`apply` 拿到的是 `Ref`,读值走
51
+ * `.get()`,每次变更都是对同一引用的 `updateVolatile`。校验与默认值照旧——volatile
52
+ * 只改变结果如何被持有。
53
+ */
54
+ export declare const Config: z<NoInfer<Schemastery.ObjectS<NoInfer<{
55
+ baseUrl: z<string, string, "defined">;
56
+ route: z<string, string, "defined">;
57
+ apiKeyEnv: z<string, string, "defined">;
58
+ headers: z<import("@deepseek-ai/cosmokit").Dict<string, string>, import("@deepseek-ai/cosmokit").Dict<string, string>, "defined">;
59
+ enabledModelIds: z<string[], string[], "defined">;
60
+ modelAliases: z<import("@deepseek-ai/cosmokit").Dict<string, string>, import("@deepseek-ai/cosmokit").Dict<string, string>, "defined">;
61
+ models: z<({
62
+ id?: string | null | undefined;
63
+ name?: string | null | undefined;
64
+ api?: string | null | undefined;
65
+ contextWindow?: number | null | undefined;
66
+ maxTokens?: number | null | undefined;
67
+ input?: ("text" | "image")[] | null | undefined;
68
+ thinking?: boolean | null | undefined;
69
+ reasoningEfforts?: import("@deepseek-ai/cosmokit").Dict<string | null, string> | null | undefined;
70
+ } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<NoInfer<{
71
+ /** 模型 id;与已发现的 id 对应,或者新增一个网关没有列出的模型。 */
72
+ id: z<string, string, "defined">;
73
+ /** 选择器里显示的名字。 */
74
+ name: z<string, string, "plain">;
75
+ /** 协议覆盖:OpenAI Chat Completions、OpenAI Responses 或 Anthropic Messages。 */
76
+ api: z<string, string, "plain">;
77
+ /** 上下文容量(token 数)。 */
78
+ contextWindow: z<number, number, "plain">;
79
+ /** 输出能力(token 数)。 */
80
+ maxTokens: z<number, number, "plain">;
81
+ /** 请求模态。 */
82
+ input: z<("text" | "image")[], ("text" | "image")[], "plain">;
83
+ /** 强制打开或关闭推理能力。 */
84
+ thinking: z<boolean, boolean, "plain">;
85
+ /** 提供的推理档位:键 = 档位,值 = 协议里的写法。 */
86
+ reasoningEfforts: z<import("@deepseek-ai/cosmokit").Dict<string | null, string>, import("@deepseek-ai/cosmokit").Dict<string | null, string>, "plain">;
87
+ }>>[], "defined">;
88
+ modelMetadataUrl: z<string, string, "defined">;
89
+ images: z<"ignore" | "metadata", "ignore" | "metadata", "defined">;
90
+ reasoning: z<"auto" | "off", "auto" | "off", "defined">;
91
+ sync: z<boolean, boolean, "defined">;
92
+ refreshIntervalMinutes: z<number, number, "defined">;
93
+ }>>>, NoInfer<Schemastery.ObjectT<NoInfer<{
94
+ baseUrl: z<string, string, "defined">;
95
+ route: z<string, string, "defined">;
96
+ apiKeyEnv: z<string, string, "defined">;
97
+ headers: z<import("@deepseek-ai/cosmokit").Dict<string, string>, import("@deepseek-ai/cosmokit").Dict<string, string>, "defined">;
98
+ enabledModelIds: z<string[], string[], "defined">;
99
+ modelAliases: z<import("@deepseek-ai/cosmokit").Dict<string, string>, import("@deepseek-ai/cosmokit").Dict<string, string>, "defined">;
100
+ models: z<({
101
+ id?: string | null | undefined;
102
+ name?: string | null | undefined;
103
+ api?: string | null | undefined;
104
+ contextWindow?: number | null | undefined;
105
+ maxTokens?: number | null | undefined;
106
+ input?: ("text" | "image")[] | null | undefined;
107
+ thinking?: boolean | null | undefined;
108
+ reasoningEfforts?: import("@deepseek-ai/cosmokit").Dict<string | null, string> | null | undefined;
109
+ } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<NoInfer<{
110
+ /** 模型 id;与已发现的 id 对应,或者新增一个网关没有列出的模型。 */
111
+ id: z<string, string, "defined">;
112
+ /** 选择器里显示的名字。 */
113
+ name: z<string, string, "plain">;
114
+ /** 协议覆盖:OpenAI Chat Completions、OpenAI Responses 或 Anthropic Messages。 */
115
+ api: z<string, string, "plain">;
116
+ /** 上下文容量(token 数)。 */
117
+ contextWindow: z<number, number, "plain">;
118
+ /** 输出能力(token 数)。 */
119
+ maxTokens: z<number, number, "plain">;
120
+ /** 请求模态。 */
121
+ input: z<("text" | "image")[], ("text" | "image")[], "plain">;
122
+ /** 强制打开或关闭推理能力。 */
123
+ thinking: z<boolean, boolean, "plain">;
124
+ /** 提供的推理档位:键 = 档位,值 = 协议里的写法。 */
125
+ reasoningEfforts: z<import("@deepseek-ai/cosmokit").Dict<string | null, string>, import("@deepseek-ai/cosmokit").Dict<string | null, string>, "plain">;
126
+ }>>[], "defined">;
127
+ modelMetadataUrl: z<string, string, "defined">;
128
+ images: z<"ignore" | "metadata", "ignore" | "metadata", "defined">;
129
+ reasoning: z<"auto" | "off", "auto" | "off", "defined">;
130
+ sync: z<boolean, boolean, "defined">;
131
+ refreshIntervalMinutes: z<number, number, "defined">;
132
+ }>>>, "volatile">;
133
+ /**
134
+ * Loader 交到 `apply` 手里的配置活引用。
135
+ *
136
+ * `.get()` 返回深冻结快照,且只在值真的变了之后才换引用——这正是 {@link memoizedConfig}
137
+ * 与运行时单飞判定所依赖的「配置版本」。
138
+ */
139
+ export type ConfigRef = ReturnType<typeof Config>;
140
+ /**
141
+ * 取活引用里的那份普通配置值。
142
+ *
143
+ * 根级 volatile 只改变配置**怎么被持有**,解析与校验照旧(非法值仍在 `Config(raw)` 当场
144
+ * 抛出,默认值也已补齐),所以这里只把活引用读成一份快照,交给不关心「活」的那几层。
145
+ *
146
+ * @param ref - Loader 交到 `apply` 手里的配置活引用。
147
+ * @returns 当前那份深冻结的普通配置值。
148
+ */
149
+ export declare function configValue(ref: ConfigRef): FilledConfig;
150
+ /**
151
+ * 默认值补齐之后的配置。
152
+ *
153
+ * {@link Config} 是**用户可写**的形状(每个键可选);schema 输出的那份不是——每个字段
154
+ * 都带 `.default()`。把这个事实写进类型,调用方就不必对着一堆必然存在的字段写 `??`。
155
+ */
156
+ export type FilledConfig = Required<Config>;
157
+ /** 校验过的配置:默认值已全部补齐,根地址已归一化。 */
158
+ export interface ResolvedConfig {
159
+ /** 归一化后的实例根地址;关闭发现时为 `undefined`。 */
160
+ readonly instanceRoot: string | undefined;
161
+ /** 原样保留的配置值,供诊断使用。 */
162
+ readonly rawBaseUrl: string;
163
+ readonly route: string;
164
+ readonly responsesRoute: string;
165
+ readonly anthropicRoute: string;
166
+ readonly displayName: string;
167
+ readonly responsesDisplayName: string;
168
+ readonly anthropicDisplayName: string;
169
+ /** 凭据引用;未配置时为 `undefined`。 */
170
+ readonly apiKeyEnv: string | undefined;
171
+ readonly headers: Readonly<Record<string, string>>;
172
+ readonly enabledModelIds: readonly string[];
173
+ readonly modelAliases: Readonly<Record<string, string>>;
174
+ readonly models: NonNullable<Config['models']>;
175
+ readonly modelMetadataUrl: string;
176
+ readonly images: 'ignore' | 'metadata';
177
+ readonly reasoning: 'auto' | 'off';
178
+ readonly sync: boolean;
179
+ readonly refreshIntervalMinutes: number;
180
+ }
181
+ /**
182
+ * 解析一段配置,只拒绝那些自身就矛盾的错误。
183
+ *
184
+ * `baseUrl` 缺失或不可用**不**算错误:插件照常挂载但处于休眠,这样 profile 可以在还没人
185
+ * 填地址时就先带着这一行。路由键则必须拒绝——写错的路由键无法靠后续写入补救,插件会静默地
186
+ * 什么都不发布。
187
+ *
188
+ * @param config - 已补齐默认值的 `aperture` 段(`configValue` 的返回值,不是活引用)。
189
+ * @returns 校验过的配置。
190
+ * @throws Error 当路由键不合文法、或模型覆盖自身重复/无法服务时抛出,并在消息里点名字段。
191
+ */
192
+ export declare function resolveConfig(config: Config): ResolvedConfig;
193
+ /**
194
+ * 把「解析当前的配置段」包成一个按源缓存的 thunk。
195
+ *
196
+ * 配置活引用的 `.get()` 只在值真的变了之后才换快照,没变就还是同一个对象,因此返回值可以
197
+ * 直接当**配置版本**用。不缓存的话每次调用都是新对象,运行时的版本判断永远不成立,于是每次
198
+ * 刷新都会多排一轮。
199
+ *
200
+ * @param source - 生效配置段的活引用(每次编辑都就地换掉它的内容)。
201
+ * @returns 解析后的配置;源没换时返回同一个对象。
202
+ */
203
+ export declare function memoizedConfig(source: () => Config): () => ResolvedConfig;
204
+ //#endregion
@@ -0,0 +1,37 @@
1
+ import { ModelsListing, fetchModelsListing } from "./aperture.js";
2
+ import { ConfiguredModel, DiscoveredModel, FactSource, Modality, ModelProvenance } from "./types.js";
3
+ import { ModelCatalog } from "./catalog.js";
4
+ import { APERTURE_NAMESPACE, Config, ConfigRef, DEFAULT_CONTEXT_WINDOW, DEFAULT_MODEL_METADATA_URL, ResolvedConfig, configValue, resolveConfig } from "./config.js";
5
+ import { DEFAULT_PLACEHOLDER_CREDENTIAL, ProfileOptions, ProfilePlan, RoutePlan, buildProfilePlan } from "./profile.js";
6
+ import { PI_AI_NAMESPACE, SyncOutcome, applySync, planSync } from "./sync.js";
7
+ import { DeclaredOverrides, PanelModel, PanelRefresh, PanelReport, PanelRoute, buildReport } from "./report.js";
8
+ import { PanelAction, PanelDeps, PanelModelPatch, PanelOps, createPanelOps } from "./panel.js";
9
+ import { RegistryResult, buildRegistry, classifyProtocol, isDeepSeekFamily } from "./registry.js";
10
+ import { AperturePanelService, PANEL_CONTRIBUTION, PANEL_INVOCATIONS, PANEL_NAMESPACE, PANEL_PACKAGE } from "./remote.js";
11
+ import { buildModelsEndpoint, buildRouteBaseUrl, normalizeBaseUrl } from "./url.js";
12
+ import { Context } from "@deepseek-ai/cordis";
13
+ //#region src/index.d.ts
14
+ /** 出现在加载器诊断里的插件名。 */
15
+ export declare const name = "dsh-aperture";
16
+ /**
17
+ * settings 是必需依赖:把发现的模型清单发布进 `llm-pi-ai` **就是**本插件的职责,而同一次
18
+ * 注册又让插件自己的 `aperture` 段变得可编辑。声明它意味着框架会把插件挂在 PENDING 直到
19
+ * settings 就绪,provider 被替换时卸载插件、恢复后重新加载——而不是留下一个已加载却无处
20
+ * 发布的实例。
21
+ *
22
+ * `typert` 则刻意**不**声明:配置页只是顺手提供的便利,没有它的部署(例如 headless profile)
23
+ * 也该照样获得发现能力,因此它在下面按需注入,不在就安静跳过。
24
+ */
25
+ export declare const inject: string[];
26
+ /**
27
+ * 发布网关的模型清单:现在发布,之后有任何变化也发布。
28
+ *
29
+ * @param ctx - 插件上下文,其中 `settings` 已就绪。
30
+ * @param config - 组合层的 `aperture` 段,已按 `Config` schema 校验并带上默认值;根级 volatile
31
+ * 使它成为活引用,读值走 `config.get()`。
32
+ * @throws Error 当配置自身矛盾(路由键不合文法、模型覆盖重复或无法服务),或存储的 `aperture`
33
+ * 段非法时抛出——框架的失败路径正是“坏配置要响亮”的实现方式。
34
+ */
35
+ export declare function apply(ctx: Context, config: ConfigRef): void;
36
+ //#endregion
37
+ export { APERTURE_NAMESPACE, type Config as ApertureConfig, AperturePanelService, Config, type ConfigRef, type ConfiguredModel, DEFAULT_CONTEXT_WINDOW, DEFAULT_MODEL_METADATA_URL, DEFAULT_PLACEHOLDER_CREDENTIAL, type DeclaredOverrides, type DiscoveredModel, type FactSource, type Modality, ModelCatalog, type ModelProvenance, type ModelsListing, PANEL_CONTRIBUTION, PANEL_INVOCATIONS, PANEL_NAMESPACE, PANEL_PACKAGE, PI_AI_NAMESPACE, type PanelAction, type PanelDeps, type PanelModel, type PanelModelPatch, type PanelOps, type PanelRefresh, type PanelReport, type PanelRoute, type ProfileOptions, type ProfilePlan, type RegistryResult, type ResolvedConfig, type RoutePlan, type SyncOutcome, applySync, buildModelsEndpoint, buildProfilePlan, buildRegistry, buildReport, buildRouteBaseUrl, classifyProtocol, configValue, createPanelOps, fetchModelsListing, isDeepSeekFamily, normalizeBaseUrl, planSync, resolveConfig };
@@ -1,30 +1,20 @@
1
- /**
2
- * 提取 Aperture 模型条目对自身所述的事实。
3
- *
4
- * 网关的列表是容量的权威来源:它知道每个上游之前的代理会接受什么,并且在上游更换模型时
5
- * 依然正确。因此每个字段都列出网关被观察到用过的所有写法,第一个成立的答案胜出。
6
- *
7
- * 下面的写法是参考 VS Code 扩展清单的超集,再加上本插件在真实 Aperture 实例上实际观察到的
8
- * 几个(`context_window_tokens`、`max_output_tokens`、`display_name`),参考的清单早于它们。
9
- *
10
- * @module dsh-aperture/metadata/extract
11
- */
12
- import type { Modality } from '../types.ts';
1
+ import { Modality } from "../types.js";
2
+ //#region src/metadata/extract.d.ts
13
3
  /** 一个模型条目所述的容量事实。 */
14
4
  export interface ExtractedLimits {
15
- /** 请求与响应合计的最大上下文窗口,条目给出时才有。 */
16
- contextWindow?: number;
17
- /** 最大输出 token 数,条目给出时才有。 */
18
- maxTokens?: number;
5
+ /** 请求与响应合计的最大上下文窗口,条目给出时才有。 */
6
+ contextWindow?: number;
7
+ /** 最大输出 token 数,条目给出时才有。 */
8
+ maxTokens?: number;
19
9
  }
20
10
  /** 一个模型条目所述的能力事实。 */
21
11
  export interface ExtractedCapabilities {
22
- /** 条目是否声称支持推理强度控制。 */
23
- reasoning?: boolean;
24
- /** 条目是否声称支持工具调用。 */
25
- toolCalling?: boolean;
26
- /** 条目声称的请求模态。 */
27
- input?: Modality[];
12
+ /** 条目是否声称支持推理强度控制。 */
13
+ reasoning?: boolean;
14
+ /** 条目是否声称支持工具调用。 */
15
+ toolCalling?: boolean;
16
+ /** 条目声称的请求模态。 */
17
+ input?: Modality[];
28
18
  }
29
19
  /**
30
20
  * 读取一个条目所述的容量,可位于顶层,或嵌套在 `metadata`、`limit`、`limits` 之下。
@@ -39,8 +29,8 @@ export declare function extractDisplayName(value: unknown): string | undefined;
39
29
  export declare function extractEndpoints(value: unknown): string[];
40
30
  /** 读取条目上报的上游 provider 身份。 */
41
31
  export declare function extractProvider(value: unknown): {
42
- id?: string;
43
- name?: string;
32
+ id?: string;
33
+ name?: string;
44
34
  } | undefined;
45
35
  /**
46
36
  * 读取一个条目所述的能力事实。
@@ -54,3 +44,4 @@ export declare function extractProvider(value: unknown): {
54
44
  export declare function extractCapabilities(value: unknown): ExtractedCapabilities | undefined;
55
45
  /** 一个条目究竟是不是可用的模型行。 */
56
46
  export declare function extractModelId(value: unknown): string | undefined;
47
+ //#endregion
@@ -0,0 +1,40 @@
1
+ import { CatalogLookup, CatalogMetadata } from "../types.js";
2
+ //#region src/metadata/modelsdev.d.ts
3
+ /** 一个已索引的清单条目。 */
4
+ interface CatalogEntry {
5
+ readonly modelId: string;
6
+ readonly modelName?: string;
7
+ readonly providerAliases: readonly string[];
8
+ readonly metadata: CatalogMetadata;
9
+ }
10
+ /** 已索引的 models.dev 清单,按单个模型的 id 与 provider 提示查询。 */
11
+ export declare class ModelCatalogIndex {
12
+ private readonly byKey;
13
+ private readonly entries;
14
+ /**
15
+ * @param entries - 每一个可用的清单条目。
16
+ */
17
+ constructor(entries: readonly CatalogEntry[]);
18
+ /** 该索引持有的可用条目数量。 */
19
+ get size(): number;
20
+ /**
21
+ * 为一个网关模型解析出最佳清单条目。
22
+ * @param modelId - 网关公布的 id。
23
+ * @param providerHints - 网关上报的上游 provider id 与名称。
24
+ * @returns 胜出条目的元数据;无任何匹配时为 `undefined`。
25
+ */
26
+ lookup(modelId: string, providerHints?: readonly string[]): CatalogMetadata | undefined;
27
+ }
28
+ /**
29
+ * 在一份已解析的 models.dev 文档之上构建查找。
30
+ *
31
+ * 接受该文档发布过的所有形态:当前扁平的 `{ "<provider>/<model>": { … } }` 映射、值携带
32
+ * `models` 的旧式 provider 键映射,以及在 `providers` 或 `models` 之下包装上述任一形态的对象。
33
+ *
34
+ * @param document - 已解析的 JSON,或任何其他值。
35
+ * @returns 该查找;文档不含可用条目时为 `undefined`。
36
+ */
37
+ export declare function buildCatalogLookup(document: unknown): CatalogLookup | undefined;
38
+ /** 仅构建索引,并暴露其大小以用于诊断。 */
39
+ export declare function buildCatalogIndex(document: unknown): ModelCatalogIndex | undefined;
40
+ //#endregion
@@ -1,3 +1,4 @@
1
+ //#region src/metadata/utils.d.ts
1
2
  /**
2
3
  * Aperture 与 models.dev 返回的松散类型 JSON 的防御式读取器。每一个都接受
3
4
  * `unknown`,并以 `undefined` 作答而不是抛错:一条格式错误的条目不能让整个清单
@@ -25,3 +26,4 @@ export declare function normalizeKey(value: string | undefined): string;
25
26
  export declare function slugKey(value: string | undefined): string;
26
27
  /** 最后一个 `/` 之后的全部内容;没有 `/` 时即整个值。 */
27
28
  export declare function suffixAfterSlash(value: string): string;
29
+ //#endregion
@@ -0,0 +1,71 @@
1
+ import { Modality } from "./types.js";
2
+ import { ResolvedConfig } from "./config.js";
3
+ import { ApertureRuntime } from "./runtime.js";
4
+ import { PanelReport } from "./report.js";
5
+ import { SettingsForms } from "@deepseek-ai/dsh-settings";
6
+ //#region src/panel.d.ts
7
+ /**
8
+ * 界面为单个模型写下的参数。
9
+ *
10
+ * 补丁是**稀疏**的:界面只发改动过的字段,没提到的原样留在设置文档里——因此界面完全不编辑的
11
+ * `reasoningEfforts` 也不会被顺手抹掉。`null` 是「这条覆盖不要了」,即把字段从 `models` 的那
12
+ * 一条里删掉,回落到发现值与清单。
13
+ */
14
+ export interface PanelModelPatch {
15
+ /** 显示名。 */
16
+ readonly name?: string | null;
17
+ /** 协议覆盖;也是让「未服务」的模型变得可服务的唯一方式。 */
18
+ readonly api?: string | null;
19
+ /** 上下文容量,以 token 计。 */
20
+ readonly contextWindow?: number | null;
21
+ /** 最大输出,以 token 计。 */
22
+ readonly maxTokens?: number | null;
23
+ /** 请求模态。 */
24
+ readonly input?: readonly Modality[] | null;
25
+ /** 强制打开(`true`)或关闭(`false`)推理。 */
26
+ readonly thinking?: boolean | null;
27
+ /** 清单别名(`aperture.modelAliases`);空串或 `null` 表示不设。 */
28
+ readonly alias?: string | null;
29
+ }
30
+ /** 一次动作的结果:成败与一句人话。 */
31
+ export interface PanelAction {
32
+ /** 动作是否落地。 */
33
+ readonly ok: boolean;
34
+ /** 面向用户的说明。 */
35
+ readonly summary: string;
36
+ }
37
+ /** 配置页可以调用的端点。 */
38
+ export interface PanelOps {
39
+ /** 最近一次刷新做了什么;不触发任何工作。 */
40
+ status(): PanelReport;
41
+ /** 立刻重新发现并发布。 */
42
+ refresh(): Promise<PanelAction>;
43
+ /**
44
+ * 写入一个模型的参数。
45
+ *
46
+ * 一次只动一个模型:界面上一行一个「保存」,版本校验也只管这一次写入。空串与 `null` 都表示
47
+ * 「这一项不覆盖」。写完等一轮重新发现落地才返回:报告里的容量、模态、协议都是刷新算出来的
48
+ * 事实,不等它就是「保存了却没变」。地址与同步开关不走这里,它们直接交给页主的设置表单。
49
+ *
50
+ * @param id - 模型 id(Aperture 接受的那个)。
51
+ * @param patch - 要改的字段;`null` 表示撤销这个模型的全部覆盖(含别名)。
52
+ */
53
+ edit(id: string, patch: PanelModelPatch | null): Promise<PanelAction>;
54
+ }
55
+ /** 端点背后的东西。 */
56
+ export interface PanelDeps {
57
+ /** 发现运行时,报告与刷新都来自它。 */
58
+ readonly runtime: ApertureRuntime;
59
+ /** 当前生效配置的活引用(thunk)。 */
60
+ readonly config: () => ResolvedConfig;
61
+ /** 设置服务:读 `aperture` 段的用户层,也写它。 */
62
+ readonly settings: SettingsForms;
63
+ }
64
+ /**
65
+ * 组装端点。
66
+ *
67
+ * @param deps - 运行时、配置活引用与设置服务。
68
+ * @returns 三个端点;`status` 是同步的,读一份已经算好的结果不该等待。
69
+ */
70
+ export declare function createPanelOps(deps: PanelDeps): PanelOps;
71
+ //#endregion
@@ -0,0 +1,55 @@
1
+ import { ConfiguredModel, DiscoveredModel } from "./types.js";
2
+ import { PiAiProviderProfile } from "@deepseek-ai/dsh-llm-pi-ai";
3
+ //#region src/profile.d.ts
4
+ /** 无凭据路由发送的占位凭据的默认值。 */
5
+ export declare const DEFAULT_PLACEHOLDER_CREDENTIAL = "dsh-aperture";
6
+ /** 一次发布过程所需的全部内容。 */
7
+ export interface ProfileOptions {
8
+ /** 归一化后的实例根。 */
9
+ readonly instanceRoot: string;
10
+ /** 拥有 OpenAI Chat Completions 模型的路由键。 */
11
+ readonly route: string;
12
+ /** 拥有 OpenAI Responses 模型的路由键。 */
13
+ readonly responsesRoute: string;
14
+ /** 拥有 Anthropic Messages 模型的路由键。 */
15
+ readonly anthropicRoute: string;
16
+ /** OpenAI Chat Completions 路由的选择器标签。 */
17
+ readonly displayName: string;
18
+ /** OpenAI Responses 路由的选择器标签。 */
19
+ readonly responsesDisplayName: string;
20
+ /** Anthropic 路由的选择器标签。 */
21
+ readonly anthropicDisplayName: string;
22
+ /** 凭据引用;部署配置了才有。 */
23
+ readonly apiKeyEnv?: string;
24
+ /** 额外的路由头;它们优先于占位头。 */
25
+ readonly headers: Readonly<Record<string, string>>;
26
+ /** 已配置的逐模型覆盖项,用于查询显式的推理档位。 */
27
+ readonly configured: readonly ConfiguredModel[];
28
+ }
29
+ /** 一条可写入 `llm-pi-ai` 配置段的路由。 */
30
+ export interface RoutePlan {
31
+ /** provider 路由键。 */
32
+ readonly provider: string;
33
+ /** profile 本身,与将被存储的内容完全一致。 */
34
+ readonly profile: PiAiProviderProfile;
35
+ /** 该路由发布的模型,用于报告。 */
36
+ readonly models: readonly DiscoveredModel[];
37
+ }
38
+ /** 完整的发布方案。 */
39
+ export interface ProfilePlan {
40
+ /** 至少含一个模型的路由,顺序稳定。 */
41
+ readonly routes: readonly RoutePlan[];
42
+ /** 没有任何路由可以服务的已发现模型。 */
43
+ readonly unserved: readonly DiscoveredModel[];
44
+ /** 本插件拥有的每个路由键,无论它当前是否有模型。 */
45
+ readonly ownedRoutes: readonly string[];
46
+ }
47
+ /**
48
+ * 把归一化后的注册表变成 provider profile。
49
+ *
50
+ * @param models - 所有已发现的模型。
51
+ * @param options - 路由与凭据配置。
52
+ * @returns 要发布的路由,以及未能被服务的模型。
53
+ */
54
+ export declare function buildProfilePlan(models: readonly DiscoveredModel[], options: ProfileOptions): ProfilePlan;
55
+ //#endregion
@@ -0,0 +1,31 @@
1
+ import { ApertureProtocol, BuildOptions, CatalogLookup, DiscoveredModel } from "./types.js";
2
+ //#region src/registry.d.ts
3
+ /** 一次归一化的结果。 */
4
+ export interface RegistryResult {
5
+ /** 所有模型,包括没有路由能服务的那些(它们的 `protocol` 缺失)。 */
6
+ readonly models: readonly DiscoveredModel[];
7
+ /** 没有任何已配置路由能服务的子集。 */
8
+ readonly unserved: readonly DiscoveredModel[];
9
+ }
10
+ /**
11
+ * 归一化、补全并合并一份网关清单。
12
+ *
13
+ * @param entries - 按端点顺序排列的原始模型行。
14
+ * @param options - 配置开关。
15
+ * @param lookup - 清单元数据查找器,在已加载时提供。
16
+ * @returns 每个模型及其来源,以及没有路由能服务的那些模型。
17
+ */
18
+ export declare function buildRegistry(entries: readonly unknown[], options: BuildOptions, lookup?: CatalogLookup): RegistryResult;
19
+ /**
20
+ * 决定一个模型通告的端点适配哪条路由。
21
+ *
22
+ * 完全没有通告端点的清单按 OpenAI 兼容处理:不上报传输方式的网关绝大多数就是普通
23
+ * Chat Completions 代理,而没有路由的模型无论如何都不可用。
24
+ *
25
+ * @param endpoints - 通告的端点路径。
26
+ * @returns 可服务的协议;没有适配的协议时为 `undefined`。
27
+ */
28
+ export declare function classifyProtocol(endpoints: readonly string[]): ApertureProtocol | undefined;
29
+ /** 判断一个模型是否属于 DeepSeek 推理方言。 */
30
+ export declare function isDeepSeekFamily(model: DiscoveredModel): boolean;
31
+ //#endregion
@@ -0,0 +1,29 @@
1
+ //#region src/relay.d.ts
2
+ /**
3
+ * 把工作搬到 HMR 事务之外去跑的一条通道。
4
+ *
5
+ * `loader/volatile-update` 是在**已经打开的事务里**同步发出来的:设置写入自己就是那个事务
6
+ * (`dsh-config-editor` 把整次写入包在 `hmr.runExclusive()` 里),而事务的印记是一条
7
+ * AsyncLocalStorage —— 从事件处理器里起的 promise 链会一直带着它,事件那一轮早跑完了也不掉。
8
+ * 于是那条链上任何一次「再写设置」都被 HMR 判成事务嵌套而拒绝(`HMR transactions cannot be
9
+ * nested`),而本插件发现完就要写设置:保存地址之后那一轮发现永远写不进去(配置页上说的是
10
+ * 「没写(HMR transactions cannot be nested)」)。
11
+ *
12
+ * 因此工作不挂在事件处理器那条链上,而是交给这里。通道在**模块作用域**被拉起(模块求值不在任何
13
+ * 事务里),事务里只负责把「有活干了」这件事叫醒它;作业在通道自己的上下文里启动,整轮刷新于是
14
+ * 从头到尾都在事务之外,调用方拿到的仍是那个作业的结果。
15
+ *
16
+ * 通道按模块持有而不是按插件实例:源码热重载会在事务里重建插件(`hmr` 的 `partialReload`),
17
+ * 实例里拉起的通道会跟着带上事务的印记;本模块通常留在模块缓存里,那条通道因此仍然是干净的。
18
+ * 代价是连本模块一起重载时通道会跟着重建——那一代实例要等下次重启才写得进去。
19
+ *
20
+ * @module dsh-aperture/relay
21
+ */
22
+ /**
23
+ * 在 HMR 事务之外跑一件事。
24
+ *
25
+ * @param job - 要跑的工作;它以及它引发的全部异步续体都在事务之外执行。
26
+ * @returns 该工作的结果。
27
+ */
28
+ export declare function outside<T>(job: () => Promise<T> | T): Promise<T>;
29
+ //#endregion