@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,186 @@
|
|
|
1
|
+
import { D as ZCodeFamily, i as ZCodeClientModel, o as ZCodeConsoleClient, u as ZCodeRawBalance } from "./console-client-54wUcPDA.js";
|
|
2
|
+
import { Context } from "@deepseek-ai/cordis";
|
|
3
|
+
//#region src/contracts/catalog.d.ts
|
|
4
|
+
/** 网关承载的协议族;当前只有 Anthropic Messages。 */
|
|
5
|
+
type ZCodeApiKind = 'anthropic-messages';
|
|
6
|
+
/** pi-ai 的思考等级全集,顺序即选择器展示顺序。 */
|
|
7
|
+
declare const ZCODE_REASONING_LEVELS: readonly ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
8
|
+
type ZCodeReasoningLevel = typeof ZCODE_REASONING_LEVELS[number];
|
|
9
|
+
/** 思考等级 → 线上取值;`null` 表示该等级不受支持。 */
|
|
10
|
+
type ZCodeThinkingLevelMap = Partial<Record<ZCodeReasoningLevel, string | null>>;
|
|
11
|
+
/** 一个可在 DSH 中使用的 ZCode 模型。 */
|
|
12
|
+
interface ZCodeModel {
|
|
13
|
+
/** 网关模型 id(如 `GLM-5.3`),发请求时原样使用。 */
|
|
14
|
+
readonly id: string;
|
|
15
|
+
/** 选择器显示名。 */
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly description?: string;
|
|
18
|
+
readonly family?: string;
|
|
19
|
+
readonly api: ZCodeApiKind;
|
|
20
|
+
/** 该协议族的完整请求端点前缀(不含 `/messages`)。 */
|
|
21
|
+
readonly baseURL: string;
|
|
22
|
+
readonly reasoning: boolean;
|
|
23
|
+
readonly thinkingLevelMap?: ZCodeThinkingLevelMap;
|
|
24
|
+
readonly input: readonly ('text' | 'image')[];
|
|
25
|
+
readonly contextWindow: number;
|
|
26
|
+
readonly maxTokens: number;
|
|
27
|
+
/** 是否支持工具调用。 */
|
|
28
|
+
readonly tools: boolean;
|
|
29
|
+
/** 是否支持结构化输出。 */
|
|
30
|
+
readonly structuredOutput?: boolean;
|
|
31
|
+
/** 模型归属的账号家族;换家族后同一模型可能不可用。 */
|
|
32
|
+
readonly accountFamily: ZCodeFamily;
|
|
33
|
+
/** 该模型在额度接口里的 capability 原文(如 `model:glm-5.3`)。 */
|
|
34
|
+
readonly capability?: string;
|
|
35
|
+
}
|
|
36
|
+
/** 额度周期:由窗口时长推导,上游没有这个字段。 */
|
|
37
|
+
type ZCodeBalancePeriod = 'daily' | 'weekly' | 'monthly' | 'one_time' |
|
|
38
|
+
/** 窗口不对应任何标准周期(例如「激活到套餐结束」的剩余时段)。 */
|
|
39
|
+
'custom' | 'unknown';
|
|
40
|
+
/** 额度条目:某个模型在某个周期内的用量。 */
|
|
41
|
+
interface ZCodeBalanceEntry {
|
|
42
|
+
/** 上游额度 id。 */
|
|
43
|
+
readonly entitlementId: string;
|
|
44
|
+
/** 展示名(如 `GLM-5.3`)。 */
|
|
45
|
+
readonly showName: string;
|
|
46
|
+
/** 对应的 capability(如 `model:glm-5.3`)。 */
|
|
47
|
+
readonly capability?: string;
|
|
48
|
+
readonly totalUnits: number;
|
|
49
|
+
readonly usedUnits: number;
|
|
50
|
+
readonly remainingUnits: number;
|
|
51
|
+
/** 周期,由 {@link deriveBalancePeriod} 从窗口时长推导。 */
|
|
52
|
+
readonly period: ZCodeBalancePeriod;
|
|
53
|
+
/** 周期与过期时间的 epoch 毫秒;上游返回的是 Unix 秒。 */
|
|
54
|
+
readonly periodStart?: number | undefined;
|
|
55
|
+
readonly periodEnd?: number | undefined;
|
|
56
|
+
readonly expiresAt?: number | undefined;
|
|
57
|
+
/** 该额度所属套餐 id;同一模型在多份套餐下会有多条额度。 */
|
|
58
|
+
readonly planId?: string | undefined;
|
|
59
|
+
}
|
|
60
|
+
/** 套餐记录。 */
|
|
61
|
+
interface ZCodePlanEntry {
|
|
62
|
+
readonly planId: string;
|
|
63
|
+
readonly name?: string;
|
|
64
|
+
readonly status?: string;
|
|
65
|
+
readonly endsAt?: string;
|
|
66
|
+
}
|
|
67
|
+
/** 目录快照。 */
|
|
68
|
+
interface ZCodeCatalog {
|
|
69
|
+
/** 快照生成时间(epoch ms)。 */
|
|
70
|
+
readonly fetchedAt: number;
|
|
71
|
+
/**
|
|
72
|
+
* `balance`:清单与额度来自账号权益,可信;
|
|
73
|
+
* `builtin`:额度接口不可读,只用了内置兜底清单。
|
|
74
|
+
*/
|
|
75
|
+
readonly source: 'balance' | 'builtin';
|
|
76
|
+
readonly models: readonly ZCodeModel[];
|
|
77
|
+
/** 账号当前生效的套餐。 */
|
|
78
|
+
readonly plans: readonly ZCodePlanEntry[];
|
|
79
|
+
/** 额度条目(可能包含目录里没出现的模型)。 */
|
|
80
|
+
readonly balances: readonly ZCodeBalanceEntry[];
|
|
81
|
+
/** 解析期间的降级说明,用于界面提示。 */
|
|
82
|
+
readonly warnings: readonly string[];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 把 `capability` 还原成模型 id。
|
|
86
|
+
*
|
|
87
|
+
* 上游写法是 `model:<小写 id>`(如 `model:glm-5.3`),而网关接受的模型 id
|
|
88
|
+
* 是官方大小写形态(`GLM-5.3`)。这里只剥前缀并保留原始大小写,大小写归一
|
|
89
|
+
* 交给 {@link normalizeModelId}。
|
|
90
|
+
*/
|
|
91
|
+
declare function modelIdOfCapability(capability: string): string | undefined;
|
|
92
|
+
/** 把模型 id 归一成官方大小写;未命中时原样返回。 */
|
|
93
|
+
declare function normalizeModelId(id: string): string;
|
|
94
|
+
/** 目录中真正可用的模型(当前全部可对话,保留过滤钩子便于将来扩展)。 */
|
|
95
|
+
declare function selectableModels(catalog: ZCodeCatalog): readonly ZCodeModel[];
|
|
96
|
+
/** 按 id 找模型。 */
|
|
97
|
+
declare function findModel(catalog: ZCodeCatalog, id: string): ZCodeModel | undefined;
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/host/catalog.d.ts
|
|
100
|
+
/**
|
|
101
|
+
* 未在 `client/configs` 里描述时的兜底能力。
|
|
102
|
+
*
|
|
103
|
+
* 取 GLM-5 系列的实际取值:40 万上下文、8 万最大输出。宁可保守(更早提示
|
|
104
|
+
* 上下文超限),也不要把上限猜高导致请求被网关拒绝。
|
|
105
|
+
*/
|
|
106
|
+
declare const ZCODE_FALLBACK_CONTEXT_WINDOW = 400000;
|
|
107
|
+
declare const ZCODE_FALLBACK_MAX_TOKENS = 80000;
|
|
108
|
+
/**
|
|
109
|
+
* 内置兜底模型清单。
|
|
110
|
+
*
|
|
111
|
+
* 与 ZCode 内置 provider 规则的 `builtinModelIds` 一致;只在额度接口不可读时
|
|
112
|
+
* 使用,用于保证未登录状态下的选择器不是空的。
|
|
113
|
+
*/
|
|
114
|
+
declare const ZCODE_BUILTIN_MODEL_IDS: readonly string[];
|
|
115
|
+
/**
|
|
116
|
+
* 思考等级映射。
|
|
117
|
+
*
|
|
118
|
+
* GLM 系列在 Anthropic 协议下用 `thinking` 块表达推理,pi-ai 的等级键与上游
|
|
119
|
+
* 取值不是一一对应:`off` 表示不请求思考,其余按强度映射到上游 `low` /
|
|
120
|
+
* `high` / `max` 三档。上游只认这三档,因此中间等级向上取整而不是透传,
|
|
121
|
+
* 否则会得到 400。
|
|
122
|
+
*/
|
|
123
|
+
declare function thinkingLevelMapOf(levels: readonly string[] | undefined): {
|
|
124
|
+
map: ZCodeThinkingLevelMap;
|
|
125
|
+
reasoning: boolean;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* 上游是否因凭据失效而拒绝。
|
|
129
|
+
*
|
|
130
|
+
* ZCode 的账号令牌有有效期,过期后额度接口返回 HTTP 401(无错误信封)。
|
|
131
|
+
* 这个状态与「网络不通」「没有套餐」的处理方式完全不同,必须先分开。
|
|
132
|
+
*/
|
|
133
|
+
declare function isUnauthorized(error: unknown): boolean;
|
|
134
|
+
/** 把一个额度 capability 投影成模型。 */
|
|
135
|
+
declare function toModel(params: {
|
|
136
|
+
readonly id: string;
|
|
137
|
+
readonly capability?: string;
|
|
138
|
+
readonly clientModel?: ZCodeClientModel;
|
|
139
|
+
readonly family: ZCodeFamily;
|
|
140
|
+
}): ZCodeModel;
|
|
141
|
+
/** 从额度条目推导模型 id 列表(保序去重)。 */
|
|
142
|
+
declare function modelIdsFromBalances(balances: readonly ZCodeBalanceEntry[]): string[];
|
|
143
|
+
/** 把额度条目归一成契约形状(周期由窗口时长推导)。 */
|
|
144
|
+
declare function toBalanceEntries(balances: readonly ZCodeRawBalance[]): ZCodeBalanceEntry[];
|
|
145
|
+
/**
|
|
146
|
+
* 同一模型在多份套餐下会有多条额度,逐条展示会让界面出现重复行。
|
|
147
|
+
*
|
|
148
|
+
* 这里按「模型 + 周期」合并:保留额度最大的那条作为主额度,把其余总量累加。
|
|
149
|
+
* 累加是有意义的——两份套餐的同一模型日额度确实可以叠加使用;但**不合并
|
|
150
|
+
* 不同周期**,否则会掩盖"日额度用完但活动额度还有"。
|
|
151
|
+
*/
|
|
152
|
+
declare function mergeBalanceEntries(entries: readonly ZCodeBalanceEntry[]): ZCodeBalanceEntry[];
|
|
153
|
+
/** 目录服务依赖。 */
|
|
154
|
+
interface ZCodeCatalogServiceOptions {
|
|
155
|
+
readonly client: ZCodeConsoleClient;
|
|
156
|
+
/** 当前账号 JWT;未登录返回 undefined。 */
|
|
157
|
+
readonly resolveToken: () => Promise<string | undefined>;
|
|
158
|
+
/** 当前账号家族;未登录时为 undefined。 */
|
|
159
|
+
readonly resolveFamily: () => Promise<ZCodeFamily | undefined>;
|
|
160
|
+
readonly logger?: Pick<Context['logger'], 'warn' | 'info'>;
|
|
161
|
+
/** 快照最短复用时间(毫秒)。 */
|
|
162
|
+
readonly staleAfterMs?: number;
|
|
163
|
+
readonly now?: () => number;
|
|
164
|
+
}
|
|
165
|
+
/** 目录服务。 */
|
|
166
|
+
declare class ZCodeCatalogService {
|
|
167
|
+
private current;
|
|
168
|
+
private inflight;
|
|
169
|
+
private readonly options;
|
|
170
|
+
constructor(options: ZCodeCatalogServiceOptions);
|
|
171
|
+
private get now();
|
|
172
|
+
/** 当前快照;从未刷新过时返回 undefined。 */
|
|
173
|
+
snapshot(): ZCodeCatalog | undefined;
|
|
174
|
+
/** 快照是否已过期。 */
|
|
175
|
+
isStale(): boolean;
|
|
176
|
+
/** 失效快照,强制下次刷新走网络。 */
|
|
177
|
+
invalidate(): void;
|
|
178
|
+
/** 已过期才刷新,否则复用。 */
|
|
179
|
+
refreshIfStale(): Promise<ZCodeCatalog>;
|
|
180
|
+
/** 强制刷新;并发调用合并成一次请求。 */
|
|
181
|
+
refresh(): Promise<ZCodeCatalog>;
|
|
182
|
+
private load;
|
|
183
|
+
private builtinCatalog;
|
|
184
|
+
}
|
|
185
|
+
//#endregion
|
|
186
|
+
export { selectableModels as C, normalizeModelId as S, ZCodePlanEntry as _, ZCodeCatalogServiceOptions as a, findModel as b, modelIdsFromBalances as c, toModel as d, ZCODE_REASONING_LEVELS as f, ZCodeModel as g, ZCodeCatalog as h, ZCodeCatalogService as i, thinkingLevelMapOf as l, ZCodeBalanceEntry as m, ZCODE_FALLBACK_CONTEXT_WINDOW as n, isUnauthorized as o, ZCodeApiKind as p, ZCODE_FALLBACK_MAX_TOKENS as r, mergeBalanceEntries as s, ZCODE_BUILTIN_MODEL_IDS as t, toBalanceEntries as u, ZCodeReasoningLevel as v, modelIdOfCapability as x, ZCodeThinkingLevelMap as y };
|
package/lib/catalog.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as ZCodeCatalogServiceOptions, c as modelIdsFromBalances, d as toModel, i as ZCodeCatalogService, l as thinkingLevelMapOf, n as ZCODE_FALLBACK_CONTEXT_WINDOW, o as isUnauthorized, r as ZCODE_FALLBACK_MAX_TOKENS, s as mergeBalanceEntries, t as ZCODE_BUILTIN_MODEL_IDS, u as toBalanceEntries } from "./catalog-CnI_VsFm.js";
|
|
2
|
+
export { ZCODE_BUILTIN_MODEL_IDS, ZCODE_FALLBACK_CONTEXT_WINDOW, ZCODE_FALLBACK_MAX_TOKENS, ZCodeCatalogService, ZCodeCatalogServiceOptions, isUnauthorized, mergeBalanceEntries, modelIdsFromBalances, thinkingLevelMapOf, toBalanceEntries, toModel };
|
package/lib/catalog.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as isUnauthorized, c as thinkingLevelMapOf, i as ZCodeCatalogService, l as toBalanceEntries, n as ZCODE_FALLBACK_CONTEXT_WINDOW, o as mergeBalanceEntries, r as ZCODE_FALLBACK_MAX_TOKENS, s as modelIdsFromBalances, t as ZCODE_BUILTIN_MODEL_IDS, u as toModel } from "./catalog-Br2Bp6dD.js";
|
|
2
|
+
export { ZCODE_BUILTIN_MODEL_IDS, ZCODE_FALLBACK_CONTEXT_WINDOW, ZCODE_FALLBACK_MAX_TOKENS, ZCodeCatalogService, isUnauthorized, mergeBalanceEntries, modelIdsFromBalances, thinkingLevelMapOf, toBalanceEntries, toModel };
|