dsh-aperture 0.3.1 → 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.
- package/README.en.md +8 -7
- package/README.md +8 -7
- 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 +32 -13
- 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/types.d.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Aperture 发现流水线的共享词汇表。
|
|
3
|
-
*
|
|
4
|
-
* 该流水线是一条纯函数链——端点响应进,provider profile 出——因此每个阶段都在这里
|
|
5
|
-
* 命名自己的类型,而不去碰 Cordis 或设置的接缝:只有 `src/index.ts` 和 `src/sync.ts`
|
|
6
|
-
* 会接触服务。
|
|
7
|
-
*
|
|
8
|
-
* @module dsh-aperture/types
|
|
9
|
-
*/
|
|
10
|
-
/** 一个已发现模型可以声明的一种请求模态。 */
|
|
11
|
-
export type Modality = 'text' | 'image';
|
|
12
|
-
/**
|
|
13
|
-
* 本插件发布的协议格式。两者都由已安装的 `dsh-llm-pi-ai` 适配器服务,这就是发现
|
|
14
|
-
* 过程从不转换载荷的原因:它只决定每个模型在网关的哪些端点上应答。
|
|
15
|
-
*/
|
|
16
|
-
export type ApertureProtocol = 'openai-completions' | 'anthropic-messages';
|
|
17
|
-
/** 一项已归一化的事实的来源,用于报告中的诊断。 */
|
|
18
|
-
export type FactSource = 'aperture' | 'models.dev' | 'config' | 'default';
|
|
19
|
-
/** 已发现模型携带的每个值的来源。 */
|
|
20
|
-
export interface ModelProvenance {
|
|
21
|
-
/** `contextWindow` 与 `maxTokens` 的来源。 */
|
|
22
|
-
readonly limits: FactSource;
|
|
23
|
-
/** `reasoning` 的来源。 */
|
|
24
|
-
readonly reasoning: FactSource;
|
|
25
|
-
/** `input` 的来源。 */
|
|
26
|
-
readonly input: FactSource;
|
|
27
|
-
/** `name` 的来源。 */
|
|
28
|
-
readonly name: FactSource;
|
|
29
|
-
}
|
|
30
|
-
/** 经过归一化、补全与配置合并后的一个模型。 */
|
|
31
|
-
export interface DiscoveredModel {
|
|
32
|
-
/** Aperture 接受的模型 id。 */
|
|
33
|
-
readonly id: string;
|
|
34
|
-
/** 供选择器使用的显示名。 */
|
|
35
|
-
readonly name: string;
|
|
36
|
-
/**
|
|
37
|
-
* 模型可访问所用的协议,由网关的 `supported_endpoints` 推导得出。网关没有提供
|
|
38
|
-
* 本插件可服务的端点时缺失。
|
|
39
|
-
*/
|
|
40
|
-
readonly protocol?: ApertureProtocol;
|
|
41
|
-
/** 网关为该模型通告的每一个端点,用于诊断。 */
|
|
42
|
-
readonly endpoints: readonly string[];
|
|
43
|
-
/** 请求与响应合计的最大上下文长度,以 token 计。 */
|
|
44
|
-
readonly contextWindow?: number;
|
|
45
|
-
/** 最大输出 token 数。 */
|
|
46
|
-
readonly maxTokens?: number;
|
|
47
|
-
/** 为该模型声明的请求模态。 */
|
|
48
|
-
readonly input: readonly Modality[];
|
|
49
|
-
/** 该模型是否接受推理档位控制。 */
|
|
50
|
-
readonly reasoning: boolean;
|
|
51
|
-
/** 网关上报的上游 provider id,在上报时提供。 */
|
|
52
|
-
readonly provider?: string;
|
|
53
|
-
/** 每项事实的来源。 */
|
|
54
|
-
readonly provenance: ModelProvenance;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* 插件 `models` 配置列表中的一条条目。
|
|
58
|
-
*
|
|
59
|
-
* id 也被端点通告的条目只覆盖它声明的字段;命名未知 id 的条目会作为额外模型加入,
|
|
60
|
-
* 网关少报时正是靠这一点保持可用。
|
|
61
|
-
*/
|
|
62
|
-
export interface ConfiguredModel {
|
|
63
|
-
/** 模型 id;与端点通告的 id 匹配,或新增一个。 */
|
|
64
|
-
readonly id: string;
|
|
65
|
-
/** 显示名。 */
|
|
66
|
-
readonly name?: string;
|
|
67
|
-
/** 协议覆盖;也是服务 Aperture 只在未服务端点上通告的模型的唯一方式。 */
|
|
68
|
-
readonly api?: string;
|
|
69
|
-
/** 上下文容量,以 token 计。 */
|
|
70
|
-
readonly contextWindow?: number;
|
|
71
|
-
/** 输出容量,以 token 计。 */
|
|
72
|
-
readonly maxTokens?: number;
|
|
73
|
-
/** 请求模态。 */
|
|
74
|
-
readonly input?: readonly Modality[];
|
|
75
|
-
/** 强制打开(`true`)或关闭(`false`)推理能力。 */
|
|
76
|
-
readonly thinking?: boolean;
|
|
77
|
-
/** 显式可选的推理档位:key = 档位,value = 协议格式中的写法。 */
|
|
78
|
-
readonly reasoningEfforts?: Readonly<Record<string, string | null>>;
|
|
79
|
-
}
|
|
80
|
-
/** 流水线把一个网关变成 provider profile 所需的全部内容。 */
|
|
81
|
-
export interface BuildOptions {
|
|
82
|
-
/** 配置的覆盖项与额外项。 */
|
|
83
|
-
readonly models: readonly ConfiguredModel[];
|
|
84
|
-
/** 非空时把清单限制为这些 id。 */
|
|
85
|
-
readonly enabledModelIds: readonly string[];
|
|
86
|
-
/**
|
|
87
|
-
* 网关模型 id → 清单模型 id,在两者不一致时使用。
|
|
88
|
-
*
|
|
89
|
-
* 网关会改名:这个网关把 DeepSeek 的 flash 模型服务为 `deepseek-flash`,把 Kimi
|
|
90
|
-
* 的服务为 `k3`,任何评分规则都无法在不猜测的情况下弥合这一差异。
|
|
91
|
-
*/
|
|
92
|
-
readonly modelAliases: Readonly<Record<string, string>>;
|
|
93
|
-
/** 是否采纳 models.dev 的输入模态(图像)。 */
|
|
94
|
-
readonly images: 'ignore' | 'metadata';
|
|
95
|
-
/** `auto` 映射推理能力;`off` 把每个模型都声明为非推理。 */
|
|
96
|
-
readonly reasoning: 'auto' | 'off';
|
|
97
|
-
}
|
|
98
|
-
/** 一次清单查找可以为模型贡献的元数据。 */
|
|
99
|
-
export interface CatalogMetadata {
|
|
100
|
-
/** 上下文容量,以 token 计。 */
|
|
101
|
-
readonly contextWindow?: number;
|
|
102
|
-
/** 输出容量,以 token 计。 */
|
|
103
|
-
readonly maxTokens?: number;
|
|
104
|
-
/** 该模型是否接受推理档位控制。 */
|
|
105
|
-
readonly reasoning?: boolean;
|
|
106
|
-
/** 请求模态。 */
|
|
107
|
-
readonly input?: readonly Modality[];
|
|
108
|
-
/** 人类可读的名称。 */
|
|
109
|
-
readonly name?: string;
|
|
110
|
-
}
|
|
111
|
-
/** 为一个端点通告的模型查找清单元数据。 */
|
|
112
|
-
export type CatalogLookup = (model: {
|
|
113
|
-
readonly id: string;
|
|
114
|
-
readonly provider?: string;
|
|
115
|
-
readonly providerName?: string;
|
|
116
|
-
}) => CatalogMetadata | undefined;
|
package/lib/types.js
DELETED
package/lib/url.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 单个 Aperture 实例的 URL 归一化。
|
|
3
|
-
*
|
|
4
|
-
* 配置里给的是实例根地址——`https://ai.example.ts.net`——本插件与 pi-ai 适配器
|
|
5
|
-
* 访问的每个端点都由它推导出来。结尾的 `/v1` 会被容忍并剥掉,而不是报错:VS Code
|
|
6
|
-
* 那个参考实现用的是相反的习惯,带着这种习惯过来的用户不该撞上 `/v1/v1`。
|
|
7
|
-
*
|
|
8
|
-
* @module dsh-aperture/url
|
|
9
|
-
*/
|
|
10
|
-
/** 去掉 URL 字符串结尾的所有正斜杠。 */
|
|
11
|
-
function stripTrailingSlashes(value) {
|
|
12
|
-
return value.replace(/\/+$/u, '');
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* 归一化配置里的实例根地址;若没有一个可用,则报告这一点。
|
|
16
|
-
*
|
|
17
|
-
* 只给主机名时按 HTTPS 假定,查询串与片段被丢弃,结尾的 `/v1`(连同任意多个
|
|
18
|
-
* 结尾斜杠)被去掉,这样调用方永远从实例根地址开始拼路径。
|
|
19
|
-
*
|
|
20
|
-
* @param raw - 原样保留的配置值。
|
|
21
|
-
* @returns 去掉结尾斜杠的归一化根地址;当值为空、或不是绝对的 HTTP(S) URL 时
|
|
22
|
-
* 返回 `undefined`。
|
|
23
|
-
*/
|
|
24
|
-
export function normalizeBaseUrl(raw) {
|
|
25
|
-
const trimmed = raw?.trim();
|
|
26
|
-
if (!trimmed) {
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
const withScheme = /^[a-z][a-z\d+\-.]*:\/\//iu.test(trimmed) ? trimmed : `https://${trimmed}`;
|
|
30
|
-
let url;
|
|
31
|
-
try {
|
|
32
|
-
url = new URL(withScheme);
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
url.hash = '';
|
|
41
|
-
url.search = '';
|
|
42
|
-
const path = stripTrailingSlashes(url.pathname).replace(/\/v1$/u, '');
|
|
43
|
-
url.pathname = path || '/';
|
|
44
|
-
return stripTrailingSlashes(url.toString());
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* 列出某个实例所服务模型的端点。
|
|
48
|
-
* @param instanceRoot - 归一化后的实例根地址。
|
|
49
|
-
* @returns 绝对地址的模型清单 URL。
|
|
50
|
-
*/
|
|
51
|
-
export function buildModelsEndpoint(instanceRoot) {
|
|
52
|
-
return `${stripTrailingSlashes(instanceRoot)}/v1/models`;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* 某种协议下,一条 pi-ai 路由必须携带的 `baseURL`。
|
|
56
|
-
*
|
|
57
|
-
* `openai-completions` 会在路由的 `baseURL` 后面追加 `/chat/completions`,所以它
|
|
58
|
-
* 拿到的是带 `/v1` 的根地址;`anthropic-messages` 走 provider SDK,SDK 自己会追加
|
|
59
|
-
* `/v1/messages`,所以它拿到的是裸的实例根地址。
|
|
60
|
-
* @param instanceRoot - 归一化后的实例根地址。
|
|
61
|
-
* @param protocol - 该路由的协议格式。
|
|
62
|
-
* @returns 该路由的 `baseURL`。
|
|
63
|
-
*/
|
|
64
|
-
export function buildRouteBaseUrl(instanceRoot, protocol) {
|
|
65
|
-
const root = stripTrailingSlashes(instanceRoot);
|
|
66
|
-
return protocol === 'openai-completions' ? `${root}/v1` : root;
|
|
67
|
-
}
|