dsh-aperture 0.1.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.
@@ -0,0 +1,48 @@
1
+ # dsh-aperture 的 bundle patch。在 profile 里装上这个包就够了:
2
+ # `dsh plugin --profile web add dsh-aperture` 会协调 `dsh.profile.bundles`,
3
+ # 这段 insert 负责加行。启动前可以先只看组合结果——`dsh --profile web
4
+ # --dump-config` 会打印出 "# == dsh-aperture" 这一层。
5
+ #
6
+ # 下面是本插件 `aperture:` 设置命名空间的**组合层**。用户层是
7
+ # `$DSH_HOME/settings.yaml` 里的 `aperture:` 段,它覆盖这一行。注意:更靠后的
8
+ # patch 层会替换整行的 `config`,而不是与它深度合并,所以覆盖这一行的 profile
9
+ # 必须把自己仍然想要的每个键重新写全。
10
+ #
11
+ # 这里只有 `baseUrl` 值得设置,其余键存在的意义是让默认值可被发现。完整说明见 README.md。
12
+ - insert:
13
+ - id: aperture
14
+ name: 'dsh-aperture'
15
+ config:
16
+ # Aperture 实例根地址,例如 https://ai.example.ts.net——必填。
17
+ # `/v1` 由插件追加;这里的值若自带结尾的 `/v1`,会被容忍并剥掉。
18
+ # 留空则插件照常挂载但处于休眠:不发现任何模型,也不写任何东西。
19
+ baseUrl: ''
20
+
21
+ # 本插件在 llm-pi-ai 的 `providers` 字典里拥有的两条路由。
22
+ # Aperture 的 `supported_endpoints` 里列了 `/v1/chat/completions` 的模型
23
+ # 走 `route`;列了 `/v1/messages` 的走 `anthropicRoute`;
24
+ # 两者都不提供的模型被记为“没有可服务的端点”,不发布到任何地方。
25
+ route: aperture
26
+ anthropicRoute: aperture-anthropic
27
+
28
+ # 凭据引用,由凭据服务接缝按请求解析。网关靠网络身份认证(Tailscale)时留空:
29
+ # 插件随后只会写入 pi-ai 要求的占位请求头,不保存任何密钥。
30
+ apiKeyEnv: ''
31
+
32
+ # `auto` 把模型的推理能力映射成 reasoningEfforts;
33
+ # `off` 声明所有发现的模型都不推理。
34
+ reasoning: auto
35
+
36
+ # `ignore` 声明纯文本;`metadata` 会接受 models.dev 为某些模型声明的输入模态(图片)。
37
+ images: ignore
38
+
39
+ # 用于补齐 Aperture 没有说明的部分的 models.dev 清单。
40
+ # 置为空串会关闭这次拉取;发现本身不受影响。
41
+ modelMetadataUrl: 'https://models.dev/models.json'
42
+
43
+ # 是否把发现的模型清单写进 llm-pi-ai 设置段。
44
+ # false = 只发现不写入(`/aperture` 命令照常汇报)。
45
+ sync: true
46
+
47
+ # 自动刷新间隔(分钟)。0(默认)表示只在加载时、配置变更时和 `/aperture refresh` 时刷新。
48
+ refreshIntervalMinutes: 0
@@ -0,0 +1,48 @@
1
+ /**
2
+ * 端点问询:`GET {instance}/v1/models`。
3
+ *
4
+ * 这是插件为发现过程发出的唯一网络调用,并且刻意与 `dsh-llm-pi-ai` 自己的
5
+ * "fetch available models" 动作所读取的清单端点相同 —— 那个动作一次只采纳一份
6
+ * 草稿,而本插件才是让清单自行刷新的东西。
7
+ *
8
+ * @module dsh-aperture/aperture
9
+ */
10
+ /** 一份成功的清单。 */
11
+ export interface ModelsListing {
12
+ /** 按端点顺序排列的原始模型条目。 */
13
+ readonly entries: readonly unknown[];
14
+ /** 应答的 URL。 */
15
+ readonly endpoint: string;
16
+ }
17
+ /** 一次问询的请求选项。 */
18
+ export interface FetchModelsOptions {
19
+ /** 随请求发送的、`accept` 之外的请求头。 */
20
+ readonly headers?: Readonly<Record<string, string>>;
21
+ /** 经过这么多毫秒后中止请求。 */
22
+ readonly timeoutMs?: number;
23
+ /** 调用方的取消信号,与超时组合使用。 */
24
+ readonly signal?: AbortSignal;
25
+ }
26
+ /**
27
+ * 问询一个 Aperture 实例,获取它服务的模型。
28
+ *
29
+ * @param instanceRoot - 一个已归一化的实例根。
30
+ * @param options - 请求头、超时与调用方取消信号。
31
+ * @returns 按端点顺序排列的原始条目。
32
+ * @throws 当请求失败、端点拒绝、应答过大,或响应体不是模型清单时,抛出带有端点
33
+ * 名称的 Error。
34
+ */
35
+ export declare function fetchModelsListing(instanceRoot: string, options?: FetchModelsOptions): Promise<ModelsListing>;
36
+ /**
37
+ * 从清单响应体中读取出模型行。
38
+ *
39
+ * 存在 `data` 数组时以它为准;否则读取 `models` 对象,且只有值为对象的属性才算
40
+ * 模型。其他任何形状都会被拒绝,而不是被静默当作空清单读取,因为空清单会覆盖掉
41
+ * 一份可用的清单。
42
+ *
43
+ * @param body - 已解析的响应。
44
+ * @param endpoint - 应答的 URL,用于诊断。
45
+ * @returns 按端点顺序排列的原始模型行。
46
+ * @throws 当响应体不是可识别的清单时抛出 Error。
47
+ */
48
+ export declare function readEntries(body: unknown, endpoint: string): readonly unknown[];
@@ -0,0 +1,109 @@
1
+ /**
2
+ * 端点问询:`GET {instance}/v1/models`。
3
+ *
4
+ * 这是插件为发现过程发出的唯一网络调用,并且刻意与 `dsh-llm-pi-ai` 自己的
5
+ * "fetch available models" 动作所读取的清单端点相同 —— 那个动作一次只采纳一份
6
+ * 草稿,而本插件才是让清单自行刷新的东西。
7
+ *
8
+ * @module dsh-aperture/aperture
9
+ */
10
+ import { asRecord } from "./metadata/utils.js";
11
+ import { buildModelsEndpoint } from "./url.js";
12
+ /** 有界读取:远超此值的模型清单不是模型清单。 */
13
+ const MAX_RESPONSE_BYTES = 4 * 1024 * 1024;
14
+ /**
15
+ * 问询一个 Aperture 实例,获取它服务的模型。
16
+ *
17
+ * @param instanceRoot - 一个已归一化的实例根。
18
+ * @param options - 请求头、超时与调用方取消信号。
19
+ * @returns 按端点顺序排列的原始条目。
20
+ * @throws 当请求失败、端点拒绝、应答过大,或响应体不是模型清单时,抛出带有端点
21
+ * 名称的 Error。
22
+ */
23
+ export async function fetchModelsListing(instanceRoot, options = {}) {
24
+ const endpoint = buildModelsEndpoint(instanceRoot);
25
+ const timeoutMs = options.timeoutMs ?? 20_000;
26
+ const timeout = AbortSignal.timeout(timeoutMs);
27
+ const signal = options.signal === undefined ? timeout : AbortSignal.any([options.signal, timeout]);
28
+ let response;
29
+ try {
30
+ response = await fetch(endpoint, {
31
+ method: 'GET',
32
+ headers: {
33
+ accept: 'application/json',
34
+ ...options.headers,
35
+ },
36
+ signal,
37
+ });
38
+ }
39
+ catch (error) {
40
+ throw new Error(`${endpoint} 无法访问:${describeError(error)}`, { cause: error });
41
+ }
42
+ if (!response.ok) {
43
+ const detail = await readErrorDetail(response);
44
+ throw new Error(`${endpoint} 应答 HTTP ${response.status}${detail === undefined ? '' : `: ${detail}`}`);
45
+ }
46
+ const declaredLength = Number(response.headers.get('content-length') ?? '');
47
+ if (Number.isFinite(declaredLength) && declaredLength > MAX_RESPONSE_BYTES) {
48
+ throw new Error(`${endpoint} 应答了 ${declaredLength} 字节,超出 ${MAX_RESPONSE_BYTES} 字节的清单上限`);
49
+ }
50
+ const text = await response.text();
51
+ if (text.length > MAX_RESPONSE_BYTES) {
52
+ throw new Error(`${endpoint} 应答了 ${text.length} 字节,超出 ${MAX_RESPONSE_BYTES} 字节的清单上限`);
53
+ }
54
+ let body;
55
+ try {
56
+ body = JSON.parse(text);
57
+ }
58
+ catch (error) {
59
+ throw new Error(`${endpoint} 没有应答 JSON:${describeError(error)}`, { cause: error });
60
+ }
61
+ return { entries: readEntries(body, endpoint), endpoint };
62
+ }
63
+ /**
64
+ * 从清单响应体中读取出模型行。
65
+ *
66
+ * 存在 `data` 数组时以它为准;否则读取 `models` 对象,且只有值为对象的属性才算
67
+ * 模型。其他任何形状都会被拒绝,而不是被静默当作空清单读取,因为空清单会覆盖掉
68
+ * 一份可用的清单。
69
+ *
70
+ * @param body - 已解析的响应。
71
+ * @param endpoint - 应答的 URL,用于诊断。
72
+ * @returns 按端点顺序排列的原始模型行。
73
+ * @throws 当响应体不是可识别的清单时抛出 Error。
74
+ */
75
+ export function readEntries(body, endpoint) {
76
+ const record = asRecord(body);
77
+ if (!record) {
78
+ throw new Error(`${endpoint} 没有应答 JSON 对象`);
79
+ }
80
+ if (Array.isArray(record.data)) {
81
+ return record.data;
82
+ }
83
+ const models = asRecord(record.models);
84
+ if (models) {
85
+ return Object.values(models).filter((value) => asRecord(value) !== undefined);
86
+ }
87
+ throw new Error(`${endpoint} 既没有应答 "data" 数组,也没有应答 "models" 对象`);
88
+ }
89
+ /** 读取错误响应体的一小段,用于诊断。 */
90
+ async function readErrorDetail(response) {
91
+ try {
92
+ const text = await response.text();
93
+ const trimmed = text.trim();
94
+ return trimmed.length === 0 ? undefined : trimmed.slice(0, 500);
95
+ }
96
+ catch {
97
+ return undefined;
98
+ }
99
+ }
100
+ /** 把一个未知的可抛出对象渲染成单行原因。 */
101
+ function describeError(error) {
102
+ if (error instanceof Error) {
103
+ const cause = error.cause;
104
+ return cause instanceof Error && cause.message !== error.message
105
+ ? `${error.message} (${cause.message})`
106
+ : error.message;
107
+ }
108
+ return String(error);
109
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * 可选的第二来源:models.dev。
3
+ *
4
+ * Aperture 会设定模型的容量,但很少说明某个模型是否会推理,对输入模态则完全不
5
+ * 提。models.dev 会为同一批模型回答这两个问题,只是 id 有时才对得上,因此该文档
6
+ * 只索引一次,之后按评分查询(见 `metadata/modelsdev.ts`)。
7
+ *
8
+ * 这次抓取在任何意义上都是可选的:把 `modelMetadataUrl` 留空的部署,或者清单不
9
+ * 可达的部署,得到的是仅来自网关的清单,而不是一次失败的刷新。
10
+ *
11
+ * @module dsh-aperture/catalog
12
+ */
13
+ import type { CatalogLookup } from './types.ts';
14
+ /** 一次清单加载的结果,用于诊断报告。 */
15
+ export interface CatalogLoad {
16
+ /** 查找器,在加载到可用文档时提供。 */
17
+ readonly lookup?: CatalogLookup;
18
+ /** 已索引条目的数量,在加载成功时提供。 */
19
+ readonly entries: number;
20
+ /** 没有可用查找器的原因,在不可用时提供。 */
21
+ readonly reason?: string;
22
+ }
23
+ /** 一个清单 URL 的进程生命周期缓存。 */
24
+ export declare class ModelCatalog {
25
+ private loaded;
26
+ /**
27
+ * 加载(或复用)某个 URL 上的清单。
28
+ * @param url - 清单 URL;为空则禁用查找。
29
+ * @param timeoutMs - 每次请求的超时时间。
30
+ * @returns 加载结果;从不抛出。
31
+ */
32
+ load(url: string, timeoutMs: number): Promise<CatalogLoad>;
33
+ /** 丢弃缓存的文档,使下次加载重新抓取。 */
34
+ clear(): void;
35
+ /** 抓取、解析并索引一份清单文档。 */
36
+ private fetchCatalog;
37
+ }
package/lib/catalog.js ADDED
@@ -0,0 +1,78 @@
1
+ /**
2
+ * 可选的第二来源:models.dev。
3
+ *
4
+ * Aperture 会设定模型的容量,但很少说明某个模型是否会推理,对输入模态则完全不
5
+ * 提。models.dev 会为同一批模型回答这两个问题,只是 id 有时才对得上,因此该文档
6
+ * 只索引一次,之后按评分查询(见 `metadata/modelsdev.ts`)。
7
+ *
8
+ * 这次抓取在任何意义上都是可选的:把 `modelMetadataUrl` 留空的部署,或者清单不
9
+ * 可达的部署,得到的是仅来自网关的清单,而不是一次失败的刷新。
10
+ *
11
+ * @module dsh-aperture/catalog
12
+ */
13
+ import { buildCatalogLookup } from "./metadata/modelsdev.js";
14
+ /** 有界读取:清单远小于此值,而重定向到巨大的东西则不是清单。 */
15
+ const MAX_CATALOG_BYTES = 16 * 1024 * 1024;
16
+ /** 一个清单 URL 的进程生命周期缓存。 */
17
+ export class ModelCatalog {
18
+ loaded;
19
+ /**
20
+ * 加载(或复用)某个 URL 上的清单。
21
+ * @param url - 清单 URL;为空则禁用查找。
22
+ * @param timeoutMs - 每次请求的超时时间。
23
+ * @returns 加载结果;从不抛出。
24
+ */
25
+ async load(url, timeoutMs) {
26
+ if (url.length === 0) {
27
+ return { entries: 0, reason: '未配置清单 URL' };
28
+ }
29
+ if (this.loaded?.url === url) {
30
+ return this.loaded.value;
31
+ }
32
+ const value = await this.fetchCatalog(url, timeoutMs);
33
+ this.loaded = { url, value };
34
+ return value;
35
+ }
36
+ /** 丢弃缓存的文档,使下次加载重新抓取。 */
37
+ clear() {
38
+ this.loaded = undefined;
39
+ }
40
+ /** 抓取、解析并索引一份清单文档。 */
41
+ async fetchCatalog(url, timeoutMs) {
42
+ let body;
43
+ try {
44
+ const response = await fetch(url, {
45
+ headers: { accept: 'application/json' },
46
+ signal: AbortSignal.timeout(timeoutMs),
47
+ });
48
+ if (!response.ok) {
49
+ return { entries: 0, reason: `${url} 应答 HTTP ${response.status}` };
50
+ }
51
+ const text = await response.text();
52
+ if (text.length > MAX_CATALOG_BYTES) {
53
+ return { entries: 0, reason: `${url} 应答了 ${text.length} 字节,超出清单上限` };
54
+ }
55
+ body = JSON.parse(text);
56
+ }
57
+ catch (error) {
58
+ return { entries: 0, reason: `${url} 无法读取:${error instanceof Error ? error.message : String(error)}` };
59
+ }
60
+ const lookup = buildCatalogLookup(body);
61
+ if (lookup === undefined) {
62
+ return { entries: 0, reason: `${url} 中没有可用的模型元数据` };
63
+ }
64
+ return { lookup, entries: countEntries(body) };
65
+ }
66
+ }
67
+ /** 统计一份清单文档包含的模型条目数,仅用于报告。 */
68
+ function countEntries(document) {
69
+ if (document === null || typeof document !== 'object') {
70
+ return 0;
71
+ }
72
+ const root = document;
73
+ const wrapped = root.providers ?? root.models;
74
+ if (wrapped !== null && typeof wrapped === 'object') {
75
+ return Object.keys(wrapped).length;
76
+ }
77
+ return Object.keys(root).length;
78
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * `/aperture` 命令。
3
+ *
4
+ * 发现过程按设计是静默的——它在加载时与配置变更时运行,并发布自己发现的内容——因此
5
+ * 该命令是让它可被观测的界面,也是不编辑文件就能强制刷新的唯一途径。
6
+ *
7
+ * @module dsh-aperture/command
8
+ */
9
+ import type { Context } from '@deepseek-ai/cordis';
10
+ import type { ResolvedConfig } from './config.ts';
11
+ import { type ApertureRuntime } from './runtime.ts';
12
+ /** 注册的命令名,不含前导斜杠。 */
13
+ export declare const COMMAND_NAME = "aperture";
14
+ /**
15
+ * 在命令注册表上注册 `/aperture`。
16
+ *
17
+ * @param ctx - 带有 `commands` 服务的上下文。
18
+ * @param runtime - 发现运行时。
19
+ * @param config - 返回当前生效配置的活引用(thunk)。
20
+ */
21
+ export declare function registerApertureCommand(ctx: Context, runtime: ApertureRuntime, config: () => ResolvedConfig): void;
package/lib/command.js ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * `/aperture` 命令。
3
+ *
4
+ * 发现过程按设计是静默的——它在加载时与配置变更时运行,并发布自己发现的内容——因此
5
+ * 该命令是让它可被观测的界面,也是不编辑文件就能强制刷新的唯一途径。
6
+ *
7
+ * @module dsh-aperture/command
8
+ */
9
+ import { formatModels, formatStatus } from "./report.js";
10
+ import { message } from "./runtime.js";
11
+ /** 注册的命令名,不含前导斜杠。 */
12
+ export const COMMAND_NAME = 'aperture';
13
+ /** 该命令接受的子命令。 */
14
+ const USAGE = [
15
+ '用法:/aperture [status|models|refresh|remove]',
16
+ ' status 最近一次刷新做了什么(默认)',
17
+ ' models 每个已发现的模型、它所在的路由,以及每条事实的来源',
18
+ ' refresh 重新发现并重新发布',
19
+ ' remove 从 llm-pi-ai 设置配置段中撤出本插件的路由',
20
+ ].join('\n');
21
+ /**
22
+ * 在命令注册表上注册 `/aperture`。
23
+ *
24
+ * @param ctx - 带有 `commands` 服务的上下文。
25
+ * @param runtime - 发现运行时。
26
+ * @param config - 返回当前生效配置的活引用(thunk)。
27
+ */
28
+ export function registerApertureCommand(ctx, runtime, config) {
29
+ ctx.commands.register({
30
+ name: COMMAND_NAME,
31
+ description: 'Aperture 模型发现:状态、已发现的模型、刷新、移除',
32
+ recordInput: false,
33
+ handler: async ({ rawInput }) => {
34
+ const [subCommand] = rawInput.trim().split(/\s+/u).filter((token) => token.length > 0);
35
+ try {
36
+ switch (subCommand) {
37
+ case undefined:
38
+ case 'status':
39
+ return { kind: 'success', text: formatStatus(runtime.last(), config()) };
40
+ case 'models':
41
+ return { kind: 'success', text: formatModels(runtime.last()) };
42
+ case 'refresh': {
43
+ const outcome = await runtime.refresh('命令');
44
+ const text = formatStatus(outcome, config());
45
+ return outcome.ok ? { kind: 'success', text } : { kind: 'error', text };
46
+ }
47
+ case 'remove':
48
+ return { kind: 'success', text: await runtime.remove() };
49
+ default:
50
+ return { kind: 'error', text: `未知子命令 "${subCommand}"\n${USAGE}` };
51
+ }
52
+ }
53
+ catch (error) {
54
+ return { kind: 'error', text: `/aperture ${subCommand ?? ''} 执行失败:${message(error)}` };
55
+ }
56
+ },
57
+ });
58
+ }
@@ -0,0 +1,197 @@
1
+ /**
2
+ * 配置 schema 与解析。
3
+ *
4
+ * 本插件拥有一个设置命名空间 `aperture`:它的组合层是 bundle 里
5
+ * `cordis.patch.yml` 的那一行,用户层是 `$DSH_HOME/settings.yaml` 里的
6
+ * `aperture:` 段。而它发布出去的一切都写进**另一个**命名空间 `llm-pi-ai`——
7
+ * 真正提供这些路由的适配器。这个分工就是整个设计:本插件决定有哪些模型,
8
+ * 那个适配器决定怎么跟它们说话。
9
+ *
10
+ * @module dsh-aperture/config
11
+ */
12
+ import z from '@deepseek-ai/schemastery';
13
+ export { APERTURE_NAMESPACE, PI_AI_NAMESPACE } from './namespaces.ts';
14
+ /** 默认清单地址;参考实现用的是同一份文档。 */
15
+ export declare const DEFAULT_MODEL_METADATA_URL = "https://models.dev/models.json";
16
+ /** 当 Aperture 与清单都没给出容量时,为模型假定的上下文容量。 */
17
+ export declare const DEFAULT_CONTEXT_WINDOW = 128000;
18
+ /** 插件配置。 */
19
+ export interface Config {
20
+ /** Aperture 实例根地址,例如 `https://ai.example.ts.net`。留空则关闭发现。 */
21
+ baseUrl?: string;
22
+ /** 承载 OpenAI 兼容模型的路由键。 */
23
+ route?: string;
24
+ /** 承载 Anthropic Messages 模型的路由键。 */
25
+ anthropicRoute?: string;
26
+ /** OpenAI 兼容路由在选择器里显示的名字。 */
27
+ displayName?: string;
28
+ /** Anthropic 路由在选择器里显示的名字。 */
29
+ anthropicDisplayName?: string;
30
+ /** 按请求解析的凭据引用;留空则改为发布一个占位请求头。 */
31
+ apiKeyEnv?: string;
32
+ /** 占位凭据的值;空串表示不发布占位请求头。 */
33
+ placeholderCredential?: string;
34
+ /** 每条路由的请求都会带上的额外请求头;它们优先于占位凭据。 */
35
+ headers?: Record<string, string>;
36
+ /** 非空时,只发现这些模型 id。 */
37
+ enabledModelIds?: string[];
38
+ /**
39
+ * 网关模型 id → models.dev 模型 id,用于清单里写法不同的 id
40
+ * (`deepseek-flash` → `deepseek/deepseek-v4-flash`)。
41
+ */
42
+ modelAliases?: Record<string, string>;
43
+ /** 覆盖与追加,按 id 合并。 */
44
+ models?: Array<{
45
+ id: string;
46
+ name?: string;
47
+ api?: string;
48
+ contextWindow?: number;
49
+ maxTokens?: number;
50
+ input?: Array<'text' | 'image'>;
51
+ thinking?: boolean;
52
+ reasoningEfforts?: Record<string, string | null>;
53
+ }>;
54
+ /** models.dev 清单地址;留空则关闭这次补齐。 */
55
+ modelMetadataUrl?: string;
56
+ /** 没有任何来源给出容量时使用的上下文容量。 */
57
+ defaultContextWindow?: number;
58
+ /** `metadata` 接受清单里的输入模态;`ignore` 声明为纯文本。 */
59
+ images?: 'ignore' | 'metadata';
60
+ /** `auto` 映射模型的推理能力;`off` 声明所有模型都不推理。 */
61
+ reasoning?: 'auto' | 'off';
62
+ /** 是否把发现的模型清单写进 `llm-pi-ai` 段。 */
63
+ sync?: boolean;
64
+ /** 自动刷新间隔(分钟);`0` 表示只在加载时与配置变更时刷新。 */
65
+ refreshIntervalMinutes?: number;
66
+ /** 访问网关与清单的单次请求超时。 */
67
+ timeoutMs?: number;
68
+ }
69
+ /** {@link Config} 的运行时 schema。 */
70
+ export declare const Config: z<Schemastery.ObjectS<{
71
+ baseUrl: z<string, string>;
72
+ route: z<string, string>;
73
+ anthropicRoute: z<string, string>;
74
+ displayName: z<string, string>;
75
+ anthropicDisplayName: z<string, string>;
76
+ apiKeyEnv: z<string, string>;
77
+ placeholderCredential: z<string, string>;
78
+ headers: z<import("@deepseek-ai/cosmokit").Dict<string, string>, import("@deepseek-ai/cosmokit").Dict<string, string>>;
79
+ enabledModelIds: z<string[], string[]>;
80
+ modelAliases: z<import("@deepseek-ai/cosmokit").Dict<string, string>, import("@deepseek-ai/cosmokit").Dict<string, string>>;
81
+ models: z<({
82
+ id?: string | null | undefined;
83
+ name?: string | null | undefined;
84
+ api?: string | null | undefined;
85
+ contextWindow?: number | null | undefined;
86
+ maxTokens?: number | null | undefined;
87
+ input?: ("text" | "image")[] | null | undefined;
88
+ thinking?: boolean | null | undefined;
89
+ reasoningEfforts?: import("@deepseek-ai/cosmokit").Dict<string | null, string> | null | undefined;
90
+ } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<{
91
+ /** 模型 id;与已发现的 id 对应,或者新增一个网关没有列出的模型。 */
92
+ id: z<string, string>;
93
+ /** 选择器里显示的名字。 */
94
+ name: z<string, string>;
95
+ /** 协议覆盖:`openai-completions` 或 `anthropic-messages`。 */
96
+ api: z<string, string>;
97
+ /** 上下文容量(token 数)。 */
98
+ contextWindow: z<number, number>;
99
+ /** 输出能力(token 数)。 */
100
+ maxTokens: z<number, number>;
101
+ /** 请求模态。 */
102
+ input: z<("text" | "image")[], ("text" | "image")[]>;
103
+ /** 强制打开或关闭推理能力。 */
104
+ thinking: z<boolean, boolean>;
105
+ /** 提供的推理档位:键 = 档位,值 = 协议里的写法。 */
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
+ defaultContextWindow: z<number, number>;
110
+ images: z<"ignore" | "metadata", "ignore" | "metadata">;
111
+ reasoning: z<"auto" | "off", "auto" | "off">;
112
+ sync: z<boolean, boolean>;
113
+ refreshIntervalMinutes: z<number, number>;
114
+ timeoutMs: z<number, number>;
115
+ }>, Schemastery.ObjectT<{
116
+ baseUrl: z<string, string>;
117
+ route: z<string, string>;
118
+ anthropicRoute: z<string, string>;
119
+ displayName: z<string, string>;
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>>;
126
+ models: z<({
127
+ id?: string | null | undefined;
128
+ name?: string | null | undefined;
129
+ api?: string | null | undefined;
130
+ contextWindow?: number | null | undefined;
131
+ maxTokens?: number | null | undefined;
132
+ input?: ("text" | "image")[] | null | undefined;
133
+ thinking?: boolean | null | undefined;
134
+ reasoningEfforts?: import("@deepseek-ai/cosmokit").Dict<string | null, string> | null | undefined;
135
+ } & import("@deepseek-ai/cosmokit").Dict)[], Schemastery.ObjectT<{
136
+ /** 模型 id;与已发现的 id 对应,或者新增一个网关没有列出的模型。 */
137
+ id: z<string, string>;
138
+ /** 选择器里显示的名字。 */
139
+ name: z<string, string>;
140
+ /** 协议覆盖:`openai-completions` 或 `anthropic-messages`。 */
141
+ api: z<string, string>;
142
+ /** 上下文容量(token 数)。 */
143
+ contextWindow: z<number, number>;
144
+ /** 输出能力(token 数)。 */
145
+ maxTokens: z<number, number>;
146
+ /** 请求模态。 */
147
+ input: z<("text" | "image")[], ("text" | "image")[]>;
148
+ /** 强制打开或关闭推理能力。 */
149
+ thinking: z<boolean, boolean>;
150
+ /** 提供的推理档位:键 = 档位,值 = 协议里的写法。 */
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
+ defaultContextWindow: z<number, number>;
155
+ images: z<"ignore" | "metadata", "ignore" | "metadata">;
156
+ reasoning: z<"auto" | "off", "auto" | "off">;
157
+ sync: z<boolean, boolean>;
158
+ refreshIntervalMinutes: z<number, number>;
159
+ timeoutMs: z<number, number>;
160
+ }>>;
161
+ /** 校验过的配置:默认值已全部补齐,根地址已归一化。 */
162
+ export interface ResolvedConfig {
163
+ /** 归一化后的实例根地址;关闭发现时为 `undefined`。 */
164
+ readonly instanceRoot: string | undefined;
165
+ /** 原样保留的配置值,供诊断使用。 */
166
+ readonly rawBaseUrl: string;
167
+ readonly route: string;
168
+ readonly anthropicRoute: string;
169
+ readonly displayName: string;
170
+ readonly anthropicDisplayName: string;
171
+ /** 凭据引用;未配置时为 `undefined`。 */
172
+ readonly apiKeyEnv: string | undefined;
173
+ readonly placeholderCredential: string;
174
+ readonly headers: Readonly<Record<string, string>>;
175
+ readonly enabledModelIds: readonly string[];
176
+ readonly modelAliases: Readonly<Record<string, string>>;
177
+ readonly models: NonNullable<Config['models']>;
178
+ readonly modelMetadataUrl: string;
179
+ readonly defaultContextWindow: number;
180
+ readonly images: 'ignore' | 'metadata';
181
+ readonly reasoning: 'auto' | 'off';
182
+ readonly sync: boolean;
183
+ readonly refreshIntervalMinutes: number;
184
+ readonly timeoutMs: number;
185
+ }
186
+ /**
187
+ * 解析一段配置,只拒绝那些自身就矛盾的错误。
188
+ *
189
+ * `baseUrl` 缺失或不可用**不**算错误:插件照常挂载但处于休眠,这样 profile 可以在
190
+ * 还没人填地址时就先带着这一行——这也正是该设置命名空间能变得可编辑的原因。
191
+ * 路由键则必须拒绝,因为写错的路由键无法靠后续写入补救:插件会静默地什么都不发布。
192
+ *
193
+ * @param config - 解析好的 `aperture` 段。
194
+ * @returns 校验过的配置。
195
+ * @throws Error 当路由键不合文法、或两条路由相同时抛出,并在消息里点名字段。
196
+ */
197
+ export declare function resolveConfig(config: Config): ResolvedConfig;