@tnnevol/dsh-zcode 0.0.0-stage → 6.0.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/LICENSE +202 -0
- package/compatibility.json +29 -0
- package/cordis.patch.yml +12 -0
- package/icon.png +0 -0
- package/lib/auth-B99K5y4S.d.ts +150 -0
- package/lib/auth-BrDmmPY2.js +206 -0
- package/lib/auth-routes.d.ts +2 -0
- package/lib/auth-routes.js +2 -0
- package/lib/auth.d.ts +2 -0
- package/lib/auth.js +2 -0
- package/lib/catalog-Br2Bp6dD.js +685 -0
- package/lib/catalog-CnI_VsFm.d.ts +186 -0
- package/lib/catalog.d.ts +2 -0
- package/lib/catalog.js +2 -0
- package/lib/client.js +47491 -0
- package/lib/console-client-54wUcPDA.d.ts +220 -0
- package/lib/identity-DE3rOYuE.js +61 -0
- package/lib/index.d.ts +263 -0
- package/lib/index.js +1544 -0
- package/lib/routes-DhHLL5UC.d.ts +244 -0
- package/lib/routes-vzWlp-oN.js +307 -0
- package/lib/style.css +1 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +135 -3
- package/README.md +0 -3
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
//#region src/contracts/identity.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* ZCode 供应商身份与网关地址:host 与 client 共用的契约。
|
|
4
|
+
*
|
|
5
|
+
* 本插件只注册**一个** DSH 供应商 `ZCode`(路由 `dsh-zcode`),承载 ZCode
|
|
6
|
+
* Start Plan 的模型。账号体系有两个「家族」(BigModel 国内 / Z.ai 海外),
|
|
7
|
+
* 两者的登录入口、额度与网关完全相同,仅授权页域名不同;模型清单由账号
|
|
8
|
+
* 权益动态决定,因此不在这里枚举。
|
|
9
|
+
*
|
|
10
|
+
* 路由 id 带 `dsh-` 前缀是刻意的:`zcode` / `zhipu` 可能已被用户在内置目录里
|
|
11
|
+
* 手工声明,带前缀的 id 不会与用户配置撞名。
|
|
12
|
+
*
|
|
13
|
+
* @module dsh-zcode/identity
|
|
14
|
+
*/
|
|
15
|
+
/** 账号家族:BigModel(国内)与 Z.ai(海外)。 */
|
|
16
|
+
type ZCodeFamily = 'bigmodel' | 'zai';
|
|
17
|
+
/** 两个家族按固定顺序排列,用于界面与目录的稳定展示。 */
|
|
18
|
+
declare const ZCODE_FAMILIES: readonly ZCodeFamily[];
|
|
19
|
+
/** 本插件注册的唯一供应商路由。 */
|
|
20
|
+
declare const ZCODE_PROVIDER = "dsh-zcode";
|
|
21
|
+
/** 模型选择器分组与设置页显示的供应商名称。 */
|
|
22
|
+
declare const ZCODE_PROVIDER_NAME = "zcode";
|
|
23
|
+
/** 家族显示名。 */
|
|
24
|
+
declare const ZCODE_FAMILY_LABELS: Readonly<Record<ZCodeFamily, string>>;
|
|
25
|
+
/** ZCode 控制面根地址(OAuth、额度、客户端配置都在这个域下)。 */
|
|
26
|
+
declare const ZCODE_ORIGIN = "https://zcode.z.ai";
|
|
27
|
+
/**
|
|
28
|
+
* 推理端点的两种策略。
|
|
29
|
+
*
|
|
30
|
+
* 官方开源项目(`zai-org/ZCode` 的 `official-coding-plan-gateway.ts`)把
|
|
31
|
+
* `open.bigmodel.cn/api/anthropic/v1/messages` 改写成
|
|
32
|
+
* `<origin>/api/v1/ultra/anthropic/v1/messages`——官方模型流量走 `ultra`。
|
|
33
|
+
*
|
|
34
|
+
* 两条端点的差异(2026-10-25 实测):
|
|
35
|
+
* - `start-plan`(`zcode-plan/anthropic`):消耗 Start Plan 套餐额度,用账号 JWT。
|
|
36
|
+
* 网关会校验请求的 `system` 是否为官方 agent 原文,未注入前缀时返回
|
|
37
|
+
* HTTP 405 + 业务码 `3012`;按 `start-plan-prefix.ts` 注入后正常放行。
|
|
38
|
+
* - `ultra`(`ultra/anthropic`):用家族 MaaS 令牌,按量计费;
|
|
39
|
+
* 余额为 0 时返回 HTTP 429 + 业务码 `1113`。
|
|
40
|
+
*
|
|
41
|
+
* 默认走 `start-plan`:只订套餐、没有按量余额的账号只有这条路可用。
|
|
42
|
+
*/
|
|
43
|
+
type ZCodeEndpointPlan = 'start-plan' | 'ultra';
|
|
44
|
+
/** 两种策略对应的端点前缀。 */
|
|
45
|
+
declare const ZCODE_ANTHROPIC_BASE_URLS: Readonly<Record<ZCodeEndpointPlan, string>>;
|
|
46
|
+
/** 默认策略:Start Plan(账号若只有套餐额度,这是唯一有意义的选择)。 */
|
|
47
|
+
declare const DEFAULT_ZCODE_ENDPOINT_PLAN: ZCodeEndpointPlan;
|
|
48
|
+
/** Start Plan 的 Anthropic 兼容推理端点前缀(默认策略,保留旧名便于引用)。 */
|
|
49
|
+
declare const ZCODE_ANTHROPIC_BASE_URL: string;
|
|
50
|
+
/** 端点策略的展示名。 */
|
|
51
|
+
declare const ZCODE_ENDPOINT_PLAN_LABELS: Readonly<Record<ZCodeEndpointPlan, string>>;
|
|
52
|
+
/**
|
|
53
|
+
* 请求 user-agent。
|
|
54
|
+
*
|
|
55
|
+
* ZCode 网关按客户端身份做来源归因,`ZCode/` 前缀与官方客户端保持同一形态;
|
|
56
|
+
* 版本号取本插件跟踪的客户端版本(见 {@link ZCODE_CLIENT_VERSION})。
|
|
57
|
+
*/
|
|
58
|
+
declare const ZCODE_CLIENT_VERSION = "3.16.3";
|
|
59
|
+
/** 完整 user-agent 串。 */
|
|
60
|
+
declare const ZCODE_USER_AGENT = "ZCode/3.16.3 ai-sdk/provider-utils/4.0.27 runtime/node.js/24";
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/host/console-client.d.ts
|
|
63
|
+
/** 上游业务错误。 */
|
|
64
|
+
declare class ZCodeConsoleError extends Error {
|
|
65
|
+
/** 上游业务码(`code` 字段),HTTP 层失败时为 undefined。 */
|
|
66
|
+
readonly code: number | undefined;
|
|
67
|
+
/** HTTP 状态码。 */
|
|
68
|
+
readonly status: number;
|
|
69
|
+
/** 上游原始响应片段,便于排查。 */
|
|
70
|
+
readonly detail?: string | undefined;
|
|
71
|
+
constructor(message: string,
|
|
72
|
+
/** 上游业务码(`code` 字段),HTTP 层失败时为 undefined。 */
|
|
73
|
+
code: number | undefined,
|
|
74
|
+
/** HTTP 状态码。 */
|
|
75
|
+
status: number,
|
|
76
|
+
/** 上游原始响应片段,便于排查。 */
|
|
77
|
+
detail?: string | undefined);
|
|
78
|
+
}
|
|
79
|
+
/** 授权码换取结果。 */
|
|
80
|
+
interface ZCodeOAuthInit {
|
|
81
|
+
readonly flowId: string;
|
|
82
|
+
readonly authorizeUrl: string;
|
|
83
|
+
/** 过期时间(epoch ms)。 */
|
|
84
|
+
readonly expiresAt: number;
|
|
85
|
+
readonly intervalSeconds: number;
|
|
86
|
+
}
|
|
87
|
+
/** 授权码换取的凭据载体。 */
|
|
88
|
+
type ZCodeOAuthPoll = {
|
|
89
|
+
readonly status: 'pending';
|
|
90
|
+
} | {
|
|
91
|
+
readonly status: 'ready';
|
|
92
|
+
readonly zcodeJwt: string;
|
|
93
|
+
readonly accessToken?: string;
|
|
94
|
+
readonly refreshToken?: string;
|
|
95
|
+
readonly expiresAt?: number;
|
|
96
|
+
readonly user?: {
|
|
97
|
+
readonly userId?: string | undefined;
|
|
98
|
+
readonly email?: string | undefined;
|
|
99
|
+
readonly name?: string | undefined;
|
|
100
|
+
readonly avatar?: string | undefined;
|
|
101
|
+
};
|
|
102
|
+
} | {
|
|
103
|
+
readonly status: 'failed';
|
|
104
|
+
readonly message: string;
|
|
105
|
+
};
|
|
106
|
+
/** 额度接口的原始条目。 */
|
|
107
|
+
interface ZCodeRawBalance {
|
|
108
|
+
readonly capability?: string | undefined;
|
|
109
|
+
readonly showName: string;
|
|
110
|
+
readonly totalUnits: number;
|
|
111
|
+
readonly usedUnits: number;
|
|
112
|
+
readonly remainingUnits: number;
|
|
113
|
+
/** 上游没有 period 字段;周期由窗口时长推导(见宽松度推导)。 */
|
|
114
|
+
readonly periodStartSeconds?: number | undefined;
|
|
115
|
+
readonly periodEndSeconds?: number | undefined;
|
|
116
|
+
readonly expiresAtSeconds?: number | undefined;
|
|
117
|
+
/** 已用尽额度里也可能是 0,用它区分「未发放」与「已用完」。 */
|
|
118
|
+
readonly availableUnits?: number | undefined;
|
|
119
|
+
/** 该额度条目所属套餐 id。 */
|
|
120
|
+
readonly planId?: string | undefined;
|
|
121
|
+
}
|
|
122
|
+
/** 额度接口的原始套餐条目。 */
|
|
123
|
+
interface ZCodeRawPlan {
|
|
124
|
+
readonly planId: string;
|
|
125
|
+
readonly name?: string | undefined;
|
|
126
|
+
readonly status?: string | undefined;
|
|
127
|
+
readonly endsAt?: string | undefined;
|
|
128
|
+
}
|
|
129
|
+
/** 额度快照(业务层聚合结果)。 */
|
|
130
|
+
interface ZCodeBalanceSnapshot {
|
|
131
|
+
readonly plans: readonly ZCodeRawPlan[];
|
|
132
|
+
readonly balances: readonly ZCodeRawBalance[];
|
|
133
|
+
}
|
|
134
|
+
/** 客户端配置里的模型能力。 */
|
|
135
|
+
interface ZCodeClientModel {
|
|
136
|
+
readonly modelId: string;
|
|
137
|
+
readonly name: string;
|
|
138
|
+
readonly contextWindow?: number | undefined;
|
|
139
|
+
readonly maxCompletionTokens?: number | undefined;
|
|
140
|
+
readonly reasoningLevels?: readonly string[] | undefined;
|
|
141
|
+
readonly defaultReasoningLevel?: string | undefined;
|
|
142
|
+
readonly supportsImage?: boolean | undefined;
|
|
143
|
+
readonly description?: string | undefined;
|
|
144
|
+
}
|
|
145
|
+
/** 客户端配置快照。 */
|
|
146
|
+
interface ZCodeClientConfigSnapshot {
|
|
147
|
+
readonly models: readonly ZCodeClientModel[];
|
|
148
|
+
/** 验证码配置;`skipModelRequest` 为 true 表示模型请求不做人机校验。 */
|
|
149
|
+
readonly captcha?: {
|
|
150
|
+
readonly enabled: boolean;
|
|
151
|
+
readonly skipModelRequest: boolean;
|
|
152
|
+
readonly region?: string | undefined;
|
|
153
|
+
};
|
|
154
|
+
/** Start Plan 预览权益(未订阅时的展示口径)。 */
|
|
155
|
+
readonly startPlanEntitlements?: readonly {
|
|
156
|
+
readonly showName: string;
|
|
157
|
+
readonly grantUnits: number;
|
|
158
|
+
}[];
|
|
159
|
+
}
|
|
160
|
+
/** 代理端点映射(官方客户端把家族端点改写到 ZCode 域)。 */
|
|
161
|
+
interface ZCodeAgentConfigSnapshot {
|
|
162
|
+
readonly proxyMapping: readonly {
|
|
163
|
+
readonly from: string;
|
|
164
|
+
readonly to: string;
|
|
165
|
+
readonly zcodeAuthorizationHeader?: string;
|
|
166
|
+
}[];
|
|
167
|
+
readonly codingPlanSignatureEnabled?: boolean;
|
|
168
|
+
}
|
|
169
|
+
/** 请求选项。 */
|
|
170
|
+
interface ZCodeClientOptions {
|
|
171
|
+
/** 网络实现;默认 `globalThis.fetch`,便于测试注入。 */
|
|
172
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
173
|
+
/** 每请求超时(毫秒)。 */
|
|
174
|
+
readonly timeoutMs?: number;
|
|
175
|
+
/** 生成稳定的设备标识;默认随机 UUID。 */
|
|
176
|
+
readonly deviceMid?: () => string;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* ZCode 客户端身份头。
|
|
180
|
+
*
|
|
181
|
+
* `x-client-language` / `x-client-timezone` / `x-os-*` 参与网关的来源归因,
|
|
182
|
+
* 固定成稳定值比"跟随运行环境"更可靠:服务端对同一账号看到一致指纹。
|
|
183
|
+
*/
|
|
184
|
+
declare function zcodeSourceHeaders(deviceMid: string): Record<string, string>;
|
|
185
|
+
/** 推理请求头:在客户端身份头上补 Anthropic 协议头与凭据。 */
|
|
186
|
+
declare function zcodeModelHeaders(deviceMid: string, token: string): Record<string, string>;
|
|
187
|
+
/** ZCode 控制面客户端。 */
|
|
188
|
+
declare class ZCodeConsoleClient {
|
|
189
|
+
private readonly fetchImpl;
|
|
190
|
+
private readonly timeoutMs;
|
|
191
|
+
private readonly deviceMidFactory;
|
|
192
|
+
private cachedDeviceMid;
|
|
193
|
+
constructor(options?: ZCodeClientOptions);
|
|
194
|
+
/** 当前设备标识;首次调用时生成并缓存,保证同一进程内稳定。 */
|
|
195
|
+
deviceMid(): string;
|
|
196
|
+
/** 注入固定设备标识(从磁盘恢复时使用)。 */
|
|
197
|
+
setDeviceMid(value: string): void;
|
|
198
|
+
private request;
|
|
199
|
+
/**
|
|
200
|
+
* 用桌面端授权码换取凭据。
|
|
201
|
+
*
|
|
202
|
+
* 浏览器授权完成后由上游回跳带授权码,这里用 code 换取 `data.token` 与
|
|
203
|
+
* `data.<family>.access_token`。`redirect_uri` 与 `state` 必须与授权时逐字一致。
|
|
204
|
+
*/
|
|
205
|
+
exchangeDesktopCode(family: ZCodeFamily, code: string, redirectUri: string, state: string): Promise<ZCodeOAuthPoll>;
|
|
206
|
+
/**
|
|
207
|
+
* 读取 Start Plan 额度。
|
|
208
|
+
*
|
|
209
|
+
* 这里是目录的真源:`balances[].capabilities` 决定账号此刻能用哪些模型。
|
|
210
|
+
*/
|
|
211
|
+
balance(zcodeJwt: string): Promise<ZCodeBalanceSnapshot>;
|
|
212
|
+
/** 读取客户端配置:模型能力、验证码策略、Start Plan 预览权益。 */
|
|
213
|
+
clientConfigs(zcodeJwt: string): Promise<ZCodeClientConfigSnapshot>;
|
|
214
|
+
/** 读取 agent 运行时配置(官方客户端的端点改写映射)。 */
|
|
215
|
+
agentConfigs(zcodeJwt: string): Promise<ZCodeAgentConfigSnapshot>;
|
|
216
|
+
}
|
|
217
|
+
/** 推理端点完整地址。 */
|
|
218
|
+
declare function zcodeMessagesUrl(baseURL?: string): string;
|
|
219
|
+
//#endregion
|
|
220
|
+
export { ZCODE_PROVIDER as C, ZCodeFamily as D, ZCodeEndpointPlan as E, ZCODE_ORIGIN as S, ZCODE_USER_AGENT as T, ZCODE_ANTHROPIC_BASE_URLS as _, ZCodeClientOptions as a, ZCODE_FAMILIES as b, ZCodeOAuthInit as c, ZCodeRawPlan as d, zcodeMessagesUrl as f, ZCODE_ANTHROPIC_BASE_URL as g, DEFAULT_ZCODE_ENDPOINT_PLAN as h, ZCodeClientModel as i, ZCodeOAuthPoll as l, zcodeSourceHeaders as m, ZCodeBalanceSnapshot as n, ZCodeConsoleClient as o, zcodeModelHeaders as p, ZCodeClientConfigSnapshot as r, ZCodeConsoleError as s, ZCodeAgentConfigSnapshot as t, ZCodeRawBalance as u, ZCODE_CLIENT_VERSION as v, ZCODE_PROVIDER_NAME as w, ZCODE_FAMILY_LABELS as x, ZCODE_ENDPOINT_PLAN_LABELS as y };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
//#region src/contracts/identity.ts
|
|
2
|
+
/** 两个家族按固定顺序排列,用于界面与目录的稳定展示。 */
|
|
3
|
+
const ZCODE_FAMILIES = ["bigmodel", "zai"];
|
|
4
|
+
/** 本插件注册的唯一供应商路由。 */
|
|
5
|
+
const ZCODE_PROVIDER = "dsh-zcode";
|
|
6
|
+
/** 模型选择器分组与设置页显示的供应商名称。 */
|
|
7
|
+
const ZCODE_PROVIDER_NAME = "zcode";
|
|
8
|
+
/** 家族显示名。 */
|
|
9
|
+
const ZCODE_FAMILY_LABELS = {
|
|
10
|
+
bigmodel: "BigModel",
|
|
11
|
+
zai: "Z.ai"
|
|
12
|
+
};
|
|
13
|
+
/** ZCode 控制面根地址(OAuth、额度、客户端配置都在这个域下)。 */
|
|
14
|
+
const ZCODE_ORIGIN = "https://zcode.z.ai";
|
|
15
|
+
/**
|
|
16
|
+
* 桌面端登录用的「授权码换令牌」端点。
|
|
17
|
+
*
|
|
18
|
+
* 浏览器授权完成后回跳到插件同源路由,再用本端点换取两份凭据:
|
|
19
|
+
* `data.token`(Start Plan 用)与 `data.<family>.access_token`(家族业务令牌)。
|
|
20
|
+
*/
|
|
21
|
+
const ZCODE_OAUTH_TOKEN_URL = `${ZCODE_ORIGIN}/api/v1/oauth/token`;
|
|
22
|
+
/** Start Plan 额度与权益接口。 */
|
|
23
|
+
const ZCODE_BALANCE_URL = `${ZCODE_ORIGIN}/api/v1/zcode-plan/billing/balance`;
|
|
24
|
+
/** 客户端运行时配置(验证码开关、Start Plan 预览权益、模型能力)。 */
|
|
25
|
+
const ZCODE_CLIENT_CONFIGS_URL = `${ZCODE_ORIGIN}/api/v1/client/configs`;
|
|
26
|
+
/** Agent 运行时配置(代理端点映射、签名开关)。 */
|
|
27
|
+
const ZCODE_AGENT_CONFIGS_URL = `${ZCODE_ORIGIN}/api/v1/agent/configs`;
|
|
28
|
+
/** 两种策略对应的端点前缀。 */
|
|
29
|
+
const ZCODE_ANTHROPIC_BASE_URLS = {
|
|
30
|
+
"start-plan": `${ZCODE_ORIGIN}/api/v1/zcode-plan/anthropic`,
|
|
31
|
+
ultra: `${ZCODE_ORIGIN}/api/v1/ultra/anthropic`
|
|
32
|
+
};
|
|
33
|
+
/** 默认策略:Start Plan(账号若只有套餐额度,这是唯一有意义的选择)。 */
|
|
34
|
+
const DEFAULT_ZCODE_ENDPOINT_PLAN = "start-plan";
|
|
35
|
+
/** Start Plan 的 Anthropic 兼容推理端点前缀(默认策略,保留旧名便于引用)。 */
|
|
36
|
+
const ZCODE_ANTHROPIC_BASE_URL = ZCODE_ANTHROPIC_BASE_URLS["start-plan"];
|
|
37
|
+
/** 端点策略的展示名。 */
|
|
38
|
+
const ZCODE_ENDPOINT_PLAN_LABELS = {
|
|
39
|
+
"start-plan": "Start Plan(套餐额度)",
|
|
40
|
+
ultra: "Ultra(按量余额)"
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* 请求 user-agent。
|
|
44
|
+
*
|
|
45
|
+
* ZCode 网关按客户端身份做来源归因,`ZCode/` 前缀与官方客户端保持同一形态;
|
|
46
|
+
* 版本号取本插件跟踪的客户端版本(见 {@link ZCODE_CLIENT_VERSION})。
|
|
47
|
+
*/
|
|
48
|
+
const ZCODE_CLIENT_VERSION = "3.16.3";
|
|
49
|
+
/** 完整 user-agent 串。 */
|
|
50
|
+
const ZCODE_USER_AGENT = `ZCode/${ZCODE_CLIENT_VERSION} ai-sdk/provider-utils/4.0.27 runtime/node.js/24`;
|
|
51
|
+
/** Anthropic 协议版本头。 */
|
|
52
|
+
const ZCODE_ANTHROPIC_VERSION = "2023-06-01";
|
|
53
|
+
/**
|
|
54
|
+
* 中段 system 注入的 beta 标记。
|
|
55
|
+
*
|
|
56
|
+
* 官方客户端在允许模型接收「对话中插入 system 消息」时带这个头;缺失时
|
|
57
|
+
* 网关仍可用,但中段 system 会被静默忽略,因此固定发送。
|
|
58
|
+
*/
|
|
59
|
+
const ZCODE_ANTHROPIC_BETA = "mid-conversation-system-2026-04-07";
|
|
60
|
+
//#endregion
|
|
61
|
+
export { ZCODE_USER_AGENT as _, ZCODE_ANTHROPIC_BETA as a, ZCODE_CLIENT_CONFIGS_URL as c, ZCODE_FAMILIES as d, ZCODE_FAMILY_LABELS as f, ZCODE_PROVIDER_NAME as g, ZCODE_PROVIDER as h, ZCODE_ANTHROPIC_BASE_URLS as i, ZCODE_CLIENT_VERSION as l, ZCODE_ORIGIN as m, ZCODE_AGENT_CONFIGS_URL as n, ZCODE_ANTHROPIC_VERSION as o, ZCODE_OAUTH_TOKEN_URL as p, ZCODE_ANTHROPIC_BASE_URL as r, ZCODE_BALANCE_URL as s, DEFAULT_ZCODE_ENDPOINT_PLAN as t, ZCODE_ENDPOINT_PLAN_LABELS as u };
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { C as ZCODE_PROVIDER, D as ZCodeFamily, E as ZCodeEndpointPlan, S as ZCODE_ORIGIN, T as ZCODE_USER_AGENT, _ as ZCODE_ANTHROPIC_BASE_URLS, a as ZCodeClientOptions, b as ZCODE_FAMILIES, c as ZCodeOAuthInit, d as ZCodeRawPlan, f as zcodeMessagesUrl, g as ZCODE_ANTHROPIC_BASE_URL, h as DEFAULT_ZCODE_ENDPOINT_PLAN, i as ZCodeClientModel, l as ZCodeOAuthPoll, m as zcodeSourceHeaders, n as ZCodeBalanceSnapshot, o as ZCodeConsoleClient, p as zcodeModelHeaders, r as ZCodeClientConfigSnapshot, s as ZCodeConsoleError, t as ZCodeAgentConfigSnapshot, u as ZCodeRawBalance, v as ZCODE_CLIENT_VERSION, w as ZCODE_PROVIDER_NAME, x as ZCODE_FAMILY_LABELS, y as ZCODE_ENDPOINT_PLAN_LABELS } from "./console-client-54wUcPDA.js";
|
|
2
|
+
import { a as zcodeAuthPath, c as ZCodeCredentialRecord, i as ZCodeCredentialStore, l as ZCodeLoginChallenge, n as ZCodeAuthServiceOptions, o as ZCodeAccountInfo, r as ZCODE_AUTH_FILENAME, s as ZCodeAuthStatus, t as ZCodeAuthService } from "./auth-B99K5y4S.js";
|
|
3
|
+
import { C as selectableModels, S as normalizeModelId, _ as ZCodePlanEntry, a as ZCodeCatalogServiceOptions, b as findModel, c as modelIdsFromBalances, d as toModel, f as ZCODE_REASONING_LEVELS, g as ZCodeModel, h as ZCodeCatalog, i as ZCodeCatalogService, l as thinkingLevelMapOf, m as ZCodeBalanceEntry, n as ZCODE_FALLBACK_CONTEXT_WINDOW, p as ZCodeApiKind, r as ZCODE_FALLBACK_MAX_TOKENS, t as ZCODE_BUILTIN_MODEL_IDS, u as toBalanceEntries, v as ZCodeReasoningLevel, x as modelIdOfCapability, y as ZCodeThinkingLevelMap } from "./catalog-CnI_VsFm.js";
|
|
4
|
+
import { C as zcodePreferencesPath, D as ZCodeUsageVisibility, E as ZCodePreferences, O as normalizePreferences, S as ZCodePreferencesStore, T as ZCODE_REFRESH_MINUTES, _ as ZCodeRouteStatus, a as trustedRequest, b as toPiModel, c as ZCodeUsageService, d as ZCodeUsageWindow, f as remainingPercent, g as ZCodeProviderRuntimeOptions, h as ZCodeProviderRuntime, i as registerZCodeRoutes, l as ZCodeUsageServiceOptions, m as usagePercent, n as ZCODE_ORIGIN_NOT_TRUSTED, o as ZCodeUsageFailure, p as resetAfterMs, r as ZCodeRoutesOptions, s as ZCodeUsageResult, t as ZCODE_CATALOG_UNAVAILABLE, u as ZCodeUsage, v as createZCodeProfile, w as DEFAULT_ZCODE_PREFERENCES, x as ZCODE_PREFERENCES_FILENAME, y as createZCodeProvider } from "./routes-DhHLL5UC.js";
|
|
5
|
+
import { ContentBlock, GenerateOptions, LlmAdapter, LlmModelInfo, LlmResolvedModelInfo, ReasoningEffortId, RequestMessage, StreamChunk, TokenUsage, ToolSchema } from "@deepseek-ai/dsh-llm";
|
|
6
|
+
import { Context } from "@deepseek-ai/cordis";
|
|
7
|
+
//#region src/host/start-plan-prefix.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Start Plan 端点的准入前缀。
|
|
10
|
+
*
|
|
11
|
+
* 实测结论(2026-10-25,抓包 + 逐项二分):`/api/v1/zcode-plan/anthropic`
|
|
12
|
+
* 会在网关侧校验 `system` 是否为官方 agent 原文——两段内容必须逐字一致,
|
|
13
|
+
* `system[0]` 少一个字母都会被判 `3012`;`system[1]` 必须作为完整前缀出现,
|
|
14
|
+
* 其后可以继续追加内容。除此之外请求头只需要三个,工具声明、metadata、
|
|
15
|
+
* device_id 与各类 `x-zcode-*` 头都与放行无关。
|
|
16
|
+
*
|
|
17
|
+
* 这两段文字是 ZCode 官方 agent 的系统提示词。插件把它们作为**前缀**放在
|
|
18
|
+
* 自己构造的 system 之前,以满足该校验;DSH 自己的指令接在其后。
|
|
19
|
+
* 上游若改动提示词,这里会失配并退回 `3012`,届时需要重新采集。
|
|
20
|
+
*
|
|
21
|
+
* @module dsh-zcode/start-plan-prefix
|
|
22
|
+
*/
|
|
23
|
+
/** 第一段:固定 42 字符的 agent 身份行,必须逐字一致。 */
|
|
24
|
+
declare const START_PLAN_PREFIX_HEAD: string;
|
|
25
|
+
/**
|
|
26
|
+
* 第二段:官方 agent 的行为提示词,必须作为完整前缀出现。
|
|
27
|
+
*
|
|
28
|
+
* 只做前缀匹配,因此可以在它之后追加插件自己的约束。
|
|
29
|
+
*/
|
|
30
|
+
declare const START_PLAN_PREFIX_BODY: string;
|
|
31
|
+
/** 注入到 system 最前面的两段前缀。 */
|
|
32
|
+
declare function startPlanSystemPrefix(): readonly {
|
|
33
|
+
readonly type: 'text';
|
|
34
|
+
readonly text: string;
|
|
35
|
+
}[];
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/host/http/translate.d.ts
|
|
38
|
+
/** 一条 Anthropic 消息。 */
|
|
39
|
+
interface AnthropicMessage {
|
|
40
|
+
role: 'user' | 'assistant';
|
|
41
|
+
content: readonly unknown[];
|
|
42
|
+
}
|
|
43
|
+
/** 从消息里取出纯文本(system 消息或拼接用)。 */
|
|
44
|
+
declare function messageText(message: RequestMessage): string;
|
|
45
|
+
/** 取出首条 system 消息的文本;没有则返回 undefined。 */
|
|
46
|
+
declare function leadingSystem(messages: readonly RequestMessage[]): string | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* 把 DSH 消息转换成 Anthropic 消息数组。
|
|
49
|
+
*
|
|
50
|
+
* - system 消息由调用方单独放进 `system` 字段,这里跳过;
|
|
51
|
+
* - `tool-call` 块转成 `tool_use`;
|
|
52
|
+
* - 工具结果消息转成带 `tool_result` 块的 user 消息(Anthropic 要求如此);
|
|
53
|
+
* - 图片块转成 base64 image 块(由调用方提供读取字节的能力)。
|
|
54
|
+
*/
|
|
55
|
+
declare function toAnthropicMessages(messages: readonly RequestMessage[], readImage?: (block: Extract<ContentBlock, {
|
|
56
|
+
type: 'image';
|
|
57
|
+
}>) => Promise<{
|
|
58
|
+
mediaType: string;
|
|
59
|
+
data: string;
|
|
60
|
+
} | undefined>): Promise<AnthropicMessage[]>;
|
|
61
|
+
/** DSH 工具声明 → Anthropic tools。 */
|
|
62
|
+
declare function toAnthropicTools(tools: readonly ToolSchema[] | undefined): readonly unknown[] | undefined;
|
|
63
|
+
/** DSH 思考等级 → Anthropic `output_config.effort`。 */
|
|
64
|
+
declare function toEffort(level: string | undefined, map?: Readonly<Record<string, string | null>>): string;
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/host/http/adapter.d.ts
|
|
67
|
+
/** 一个可执行模型。 */
|
|
68
|
+
interface ZCodeHttpModel {
|
|
69
|
+
readonly id: string;
|
|
70
|
+
readonly name: string;
|
|
71
|
+
readonly contextWindow: number;
|
|
72
|
+
readonly maxTokens: number;
|
|
73
|
+
readonly reasoning: boolean;
|
|
74
|
+
readonly efforts?: readonly {
|
|
75
|
+
readonly id: ReturnType<typeof ReasoningEffortId>;
|
|
76
|
+
readonly name: string;
|
|
77
|
+
}[];
|
|
78
|
+
/** 等级 → 上游字符串;与 efforts 同源,用于把所选等级翻译成请求字段。 */
|
|
79
|
+
readonly thinkingLevelMap?: Readonly<Record<string, string | null>>;
|
|
80
|
+
readonly inputModalities?: readonly ('text' | 'image')[];
|
|
81
|
+
}
|
|
82
|
+
/** 通道依赖。 */
|
|
83
|
+
interface ZCodeHttpAdapterOptions {
|
|
84
|
+
/** 当前模型清单(每次调用读取,目录刷新后立刻生效)。 */
|
|
85
|
+
readonly models: () => readonly ZCodeHttpModel[];
|
|
86
|
+
/** 当前端点策略与凭据。 */
|
|
87
|
+
readonly baseUrl: () => string;
|
|
88
|
+
readonly apiKey: () => Promise<string | undefined>;
|
|
89
|
+
/** 设备标识,写入 metadata 与请求头。 */
|
|
90
|
+
readonly deviceId: () => string;
|
|
91
|
+
/** 客户端身份头。 */
|
|
92
|
+
readonly headers?: () => Record<string, string>;
|
|
93
|
+
/** 读取图片附件为 base64;不支持图片时返回 undefined。 */
|
|
94
|
+
/**
|
|
95
|
+
* 把图片附件读成 base64。
|
|
96
|
+
*
|
|
97
|
+
* 必须是异步:附件字节由宿主的附件服务异步读取并按路由上限压缩。
|
|
98
|
+
* 返回 undefined 表示该图跳过(例如读取失败),不影响整条请求。
|
|
99
|
+
*/
|
|
100
|
+
readonly readImage?: (block: Extract<ContentBlock, {
|
|
101
|
+
type: 'image';
|
|
102
|
+
}>) => Promise<{
|
|
103
|
+
mediaType: string;
|
|
104
|
+
data: string;
|
|
105
|
+
} | undefined>;
|
|
106
|
+
readonly logger?: {
|
|
107
|
+
warn(message: string): void;
|
|
108
|
+
};
|
|
109
|
+
/** 便于测试注入。 */
|
|
110
|
+
readonly fetchImpl?: typeof fetch;
|
|
111
|
+
}
|
|
112
|
+
/** 自行发送的适配器。 */
|
|
113
|
+
declare class ZCodeHttpAdapter extends LlmAdapter {
|
|
114
|
+
private readonly options;
|
|
115
|
+
constructor(options: ZCodeHttpAdapterOptions);
|
|
116
|
+
providerInfo(provider: string): {
|
|
117
|
+
readonly id: string;
|
|
118
|
+
readonly name: string;
|
|
119
|
+
};
|
|
120
|
+
listModels(provider: string): Promise<readonly LlmModelInfo[]>;
|
|
121
|
+
resolveModel(provider: string, model: string): Promise<LlmResolvedModelInfo>;
|
|
122
|
+
stream(options: GenerateOptions): AsyncIterable<StreamChunk>;
|
|
123
|
+
/** 端点策略(诊断用)。 */
|
|
124
|
+
planOf(baseUrl: string): ZCodeEndpointPlan;
|
|
125
|
+
}
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/host/http/messages-client.d.ts
|
|
128
|
+
/** 官方 agent 的两段 system 前缀在发出前的固定形态。 */
|
|
129
|
+
interface SystemPrefix {
|
|
130
|
+
readonly head: string;
|
|
131
|
+
readonly body: string;
|
|
132
|
+
}
|
|
133
|
+
/** 一次请求所需的全部输入。 */
|
|
134
|
+
interface MessagesRequest {
|
|
135
|
+
readonly baseUrl: string;
|
|
136
|
+
readonly apiKey: string;
|
|
137
|
+
readonly model: string;
|
|
138
|
+
readonly maxTokens: number;
|
|
139
|
+
/** DSH 自己的系统提示词;会接在官方前缀之后。 */
|
|
140
|
+
readonly system: string | undefined;
|
|
141
|
+
/** Anthropic 格式的消息数组(已转换)。 */
|
|
142
|
+
readonly messages: readonly unknown[];
|
|
143
|
+
/** 工具声明(已转换为 Anthropic 格式)。 */
|
|
144
|
+
readonly tools: readonly unknown[] | undefined;
|
|
145
|
+
/** 思考强度;开启推理时写入 `output_config.effort`。 */
|
|
146
|
+
readonly effort?: string;
|
|
147
|
+
/** 是否启用思考。 */
|
|
148
|
+
readonly thinking?: boolean;
|
|
149
|
+
readonly temperature?: number;
|
|
150
|
+
readonly signal?: AbortSignal;
|
|
151
|
+
/** 设备标识:写入 `metadata.user_id`,与请求头同源。 */
|
|
152
|
+
readonly deviceId: string;
|
|
153
|
+
readonly sessionId?: string;
|
|
154
|
+
/** 请求头(客户端身份)。 */
|
|
155
|
+
readonly extraHeaders?: Record<string, string>;
|
|
156
|
+
/** 发生限流重试时的观察回调(用于日志与诊断)。 */
|
|
157
|
+
readonly onRateLimit?: (info: {
|
|
158
|
+
readonly attempt: number;
|
|
159
|
+
readonly status: number;
|
|
160
|
+
readonly businessCode: string | undefined;
|
|
161
|
+
readonly delayMs: number;
|
|
162
|
+
}) => void;
|
|
163
|
+
}
|
|
164
|
+
/** 解析后的流事件。 */
|
|
165
|
+
type MessagesEvent = {
|
|
166
|
+
readonly kind: 'message-start';
|
|
167
|
+
readonly model: string;
|
|
168
|
+
readonly usage?: TokenUsage;
|
|
169
|
+
} | {
|
|
170
|
+
readonly kind: 'block-start';
|
|
171
|
+
readonly index: number;
|
|
172
|
+
readonly blockType: 'text' | 'thinking' | 'tool_use';
|
|
173
|
+
readonly id?: string;
|
|
174
|
+
readonly name?: string;
|
|
175
|
+
} | {
|
|
176
|
+
readonly kind: 'text-delta';
|
|
177
|
+
readonly index: number;
|
|
178
|
+
readonly text: string;
|
|
179
|
+
} | {
|
|
180
|
+
readonly kind: 'thinking-delta';
|
|
181
|
+
readonly index: number;
|
|
182
|
+
readonly text: string;
|
|
183
|
+
} | {
|
|
184
|
+
readonly kind: 'signature-delta';
|
|
185
|
+
readonly index: number;
|
|
186
|
+
readonly signature: string;
|
|
187
|
+
} | {
|
|
188
|
+
readonly kind: 'tool-delta';
|
|
189
|
+
readonly index: number;
|
|
190
|
+
readonly id: string;
|
|
191
|
+
readonly name?: string;
|
|
192
|
+
readonly argumentsDelta: string;
|
|
193
|
+
} | {
|
|
194
|
+
readonly kind: 'block-stop';
|
|
195
|
+
readonly index: number;
|
|
196
|
+
} | {
|
|
197
|
+
readonly kind: 'message-delta';
|
|
198
|
+
readonly stopReason: string;
|
|
199
|
+
readonly usage?: TokenUsage;
|
|
200
|
+
} | {
|
|
201
|
+
readonly kind: 'error';
|
|
202
|
+
readonly message: string;
|
|
203
|
+
readonly errorType?: string;
|
|
204
|
+
};
|
|
205
|
+
/** 把上游 usage 投影成 DSH 计数(字段互斥)。 */
|
|
206
|
+
declare function toUsage(raw: unknown): TokenUsage;
|
|
207
|
+
/** 组装请求体:把 DSH system 接在官方前缀之后,并补齐官方附加字段。 */
|
|
208
|
+
declare function buildMessagesBody(request: MessagesRequest, prefix: SystemPrefix): Record<string, unknown>;
|
|
209
|
+
/** 解析一条 SSE `data:` 载荷;无法识别时返回 undefined。 */
|
|
210
|
+
declare function parseEvent(payload: string): MessagesEvent | undefined;
|
|
211
|
+
/**
|
|
212
|
+
* 发出请求并按行解析流。
|
|
213
|
+
*
|
|
214
|
+
* 用 `for await` 逐块读,遇到 `data:` 行就解析;`[DONE]` 与空行跳过。
|
|
215
|
+
*/
|
|
216
|
+
declare function streamMessages(request: MessagesRequest, prefix: SystemPrefix, fetchImpl?: typeof fetch): AsyncIterable<MessagesEvent>;
|
|
217
|
+
//#endregion
|
|
218
|
+
//#region src/contracts/routes.d.ts
|
|
219
|
+
/**
|
|
220
|
+
* 插件同源 Web 路由:宿主注册、浏览器调用,两端引用同一份常量。
|
|
221
|
+
*
|
|
222
|
+
* 不用 Remote API 命名空间,是因为这里只有低频率、无状态的读写;同源 HTTP
|
|
223
|
+
* 路由的信任边界由宿主侧 `trustedRequest` 把关,与其他账号插件一致。
|
|
224
|
+
*
|
|
225
|
+
* @module dsh-zcode/routes
|
|
226
|
+
*/
|
|
227
|
+
/** 本插件 Web 路由的前缀。 */
|
|
228
|
+
declare const ZCODE_ROUTE_PREFIX = "/plugins/dsh-zcode";
|
|
229
|
+
declare const ZCODE_ROUTES: {
|
|
230
|
+
/** 账号状态(含进行中的登录挑战)。 */
|
|
231
|
+
readonly status: "/plugins/dsh-zcode/auth/status";
|
|
232
|
+
/** 开始授权;响应带授权地址。 */
|
|
233
|
+
readonly login: "/plugins/dsh-zcode/auth/login";
|
|
234
|
+
/** 桌面授权码流程的回调地址:浏览器登录后回跳到这里完成换取。 */
|
|
235
|
+
readonly callback: "/plugins/dsh-zcode/auth/callback";
|
|
236
|
+
/** 取消进行中的登录,不删除已保存凭据。 */
|
|
237
|
+
readonly cancel: "/plugins/dsh-zcode/auth/cancel";
|
|
238
|
+
/** 退出登录并删除凭据。 */
|
|
239
|
+
readonly logout: "/plugins/dsh-zcode/auth/logout";
|
|
240
|
+
/** Start Plan 额度。 */
|
|
241
|
+
readonly usage: "/plugins/dsh-zcode/usage";
|
|
242
|
+
/** 当前模型目录快照。 */
|
|
243
|
+
readonly catalog: "/plugins/dsh-zcode/catalog";
|
|
244
|
+
/** 强制刷新模型目录。 */
|
|
245
|
+
readonly catalogRefresh: "/plugins/dsh-zcode/catalog/refresh";
|
|
246
|
+
/** 插件偏好设置。 */
|
|
247
|
+
readonly preferences: "/plugins/dsh-zcode/preferences";
|
|
248
|
+
};
|
|
249
|
+
//#endregion
|
|
250
|
+
//#region src/index.d.ts
|
|
251
|
+
/** 稳定的宿主插件名。 */
|
|
252
|
+
declare const name = "dsh-zcode-plugin";
|
|
253
|
+
/**
|
|
254
|
+
* 模型层是硬依赖;Web 路由是可选增强。
|
|
255
|
+
*
|
|
256
|
+
* headless / tui 一类的 profile 没有 `webServer`,插件仍应提供服务;
|
|
257
|
+
* 详情页与同源路由通过 `ctx.inject(['webServer'], …)` 只在 Web 装配下注册。
|
|
258
|
+
* 否则插件会停在 pending,模型路由也不会注册(表现为 `NO_ADAPTER`)。
|
|
259
|
+
*/
|
|
260
|
+
declare const inject: string[];
|
|
261
|
+
declare function apply(ctx: Context): void;
|
|
262
|
+
//#endregion
|
|
263
|
+
export { DEFAULT_ZCODE_ENDPOINT_PLAN, DEFAULT_ZCODE_PREFERENCES, type MessagesEvent, type MessagesRequest, START_PLAN_PREFIX_BODY, START_PLAN_PREFIX_HEAD, type SystemPrefix, ZCODE_ANTHROPIC_BASE_URL, ZCODE_ANTHROPIC_BASE_URLS, ZCODE_AUTH_FILENAME, ZCODE_BUILTIN_MODEL_IDS, ZCODE_CATALOG_UNAVAILABLE, ZCODE_CLIENT_VERSION, ZCODE_ENDPOINT_PLAN_LABELS, ZCODE_FALLBACK_CONTEXT_WINDOW, ZCODE_FALLBACK_MAX_TOKENS, ZCODE_FAMILIES, ZCODE_FAMILY_LABELS, ZCODE_ORIGIN, ZCODE_ORIGIN_NOT_TRUSTED, ZCODE_PREFERENCES_FILENAME, ZCODE_PROVIDER, ZCODE_PROVIDER_NAME, ZCODE_REASONING_LEVELS, ZCODE_REFRESH_MINUTES, ZCODE_ROUTES, ZCODE_ROUTE_PREFIX, ZCODE_USER_AGENT, type ZCodeAccountInfo, type ZCodeAgentConfigSnapshot, type ZCodeApiKind, ZCodeAuthService, type ZCodeAuthServiceOptions, type ZCodeAuthStatus, type ZCodeBalanceEntry, type ZCodeBalanceSnapshot, type ZCodeCatalog, ZCodeCatalogService, type ZCodeCatalogServiceOptions, type ZCodeClientConfigSnapshot, type ZCodeClientModel, type ZCodeClientOptions, ZCodeConsoleClient, ZCodeConsoleError, type ZCodeCredentialRecord, ZCodeCredentialStore, type ZCodeEndpointPlan, type ZCodeFamily, ZCodeHttpAdapter, type ZCodeHttpAdapterOptions, type ZCodeHttpModel, type ZCodeLoginChallenge, type ZCodeModel, type ZCodeOAuthInit, type ZCodeOAuthPoll, type ZCodePlanEntry, type ZCodePreferences, ZCodePreferencesStore, ZCodeProviderRuntime, type ZCodeProviderRuntimeOptions, type ZCodeRawBalance, type ZCodeRawPlan, type ZCodeReasoningLevel, type ZCodeRouteStatus, type ZCodeRoutesOptions, type ZCodeThinkingLevelMap, type ZCodeUsage, type ZCodeUsageFailure, type ZCodeUsageResult, ZCodeUsageService, type ZCodeUsageServiceOptions, type ZCodeUsageVisibility, type ZCodeUsageWindow, apply, buildMessagesBody, createZCodeProfile, createZCodeProvider, findModel, inject, leadingSystem, messageText, modelIdOfCapability, modelIdsFromBalances, name, normalizeModelId, normalizePreferences, parseEvent, registerZCodeRoutes, remainingPercent, resetAfterMs, selectableModels, startPlanSystemPrefix, streamMessages, thinkingLevelMapOf, toAnthropicMessages, toAnthropicTools, toBalanceEntries, toEffort, toModel, toPiModel, toUsage, trustedRequest, usagePercent, zcodeAuthPath, zcodeMessagesUrl, zcodeModelHeaders, zcodePreferencesPath, zcodeSourceHeaders };
|