@deepwhale/llm 1.0.10 → 1.0.12
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 +21 -21
- package/package.json +1 -1
- package/dist/anthropic-client.d.ts +0 -147
- package/dist/anthropic-client.d.ts.map +0 -1
- package/dist/anthropic-client.js +0 -443
- package/dist/anthropic-client.js.map +0 -1
- package/dist/canonicalize-schema.d.ts +0 -40
- package/dist/canonicalize-schema.d.ts.map +0 -1
- package/dist/canonicalize-schema.js +0 -93
- package/dist/canonicalize-schema.js.map +0 -1
- package/dist/deepseek-client.d.ts +0 -106
- package/dist/deepseek-client.d.ts.map +0 -1
- package/dist/deepseek-client.js +0 -457
- package/dist/deepseek-client.js.map +0 -1
- package/dist/index.d.ts +0 -26
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -27
- package/dist/index.js.map +0 -1
- package/dist/parse.d.ts +0 -53
- package/dist/parse.d.ts.map +0 -1
- package/dist/parse.js +0 -299
- package/dist/parse.js.map +0 -1
- package/dist/pricing-config.d.ts +0 -104
- package/dist/pricing-config.d.ts.map +0 -1
- package/dist/pricing-config.js +0 -186
- package/dist/pricing-config.js.map +0 -1
- package/dist/pricing.default.toml +0 -46
- package/dist/types.d.ts +0 -288
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -70
- package/dist/types.js.map +0 -1
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
# deepwhale 默认 pricing (2026-06)
|
|
2
|
-
# 用户可在 ~/.deepwhale/pricing.toml 覆盖 (--pricing-config <path> 后续可加, 1b.5 走 env)。
|
|
3
|
-
# **per-model currency**: DeepSeek CNY, Anthropic USD。不在 UI 层做汇率换算。
|
|
4
|
-
#
|
|
5
|
-
# **当前生产 model 2 个** (Q 拍板 2026-06-03): flash + pro.
|
|
6
|
-
# Only production DeepSeek models are supported. (Q 拍板 2026-06-04, Task 2 Gap 4 留痕)
|
|
7
|
-
# 不再加 deepseek-chat / deepseek-reasoner 老 alias — 那些是 1a/1b era 历史,
|
|
8
|
-
# 2026-07-24 后服务端 hard-fail, 老 session replay 走 R7 中间路径 (base 2 字段, cost 字段 absent).
|
|
9
|
-
#
|
|
10
|
-
# **信源唯一性**: DeepSeek pricing 永远以 https://api-docs.deepseek.com/quick_start/pricing
|
|
11
|
-
# 为唯一信源。Q 在 2026-06-03 review 时贴出官方 "模型细节" 页截屏纠正我之前 commit 用的
|
|
12
|
-
# 0.5/0.1/1.0 (来自 1b 时代印象 + 二手源, 未核对官方). 实际官方:
|
|
13
|
-
# - cache_miss_per_m = input 缓存未命中 (1M tokens)
|
|
14
|
-
# - cache_hit_per_m = input 缓存命中 (1M tokens)
|
|
15
|
-
# - completion_per_m = output (1M tokens)
|
|
16
|
-
# 注意: 1b follow-up P1 改的 0.01/0.1 fix 是 **公式 1000× off** — pricing 数字本身的 0.1
|
|
17
|
-
# 看上去像 0.1 ¥/M 但其实只是 0.5→0.1 cache hit 巧合小, 真正的官方是 0.02¥/M (5× off 真实价).
|
|
18
|
-
|
|
19
|
-
[models.deepseek-v4-flash]
|
|
20
|
-
cache_miss_per_m = 1.0 # ¥1 /M tokens (input 缓存未命中, 官方 api-docs.deepseek.com 2026-06)
|
|
21
|
-
cache_hit_per_m = 0.02 # ¥0.02 /M tokens (input 缓存命中, 官方)
|
|
22
|
-
completion_per_m = 2.0 # ¥2 /M tokens (output, 官方)
|
|
23
|
-
currency = "CNY"
|
|
24
|
-
|
|
25
|
-
[models.deepseek-v4-pro]
|
|
26
|
-
cache_miss_per_m = 3.0 # ¥3 /M tokens (input 缓存未命中, 官方)
|
|
27
|
-
cache_hit_per_m = 0.025 # ¥0.025 /M tokens (input 缓存命中, 官方)
|
|
28
|
-
completion_per_m = 6.0 # ¥6 /M tokens (output, 官方)
|
|
29
|
-
currency = "CNY"
|
|
30
|
-
|
|
31
|
-
# Anthropic Claude Sonnet 4.5 (2026-06 official first-party API pricing)
|
|
32
|
-
# https://platform.claude.com/docs/en/about-claude/pricing
|
|
33
|
-
[models.claude-sonnet-4-5]
|
|
34
|
-
cache_miss_per_m = 3.0 # $3 /M tokens (input)
|
|
35
|
-
cache_hit_per_m = 0.30 # $0.30 /M tokens (cache read, 1h TTL — 不是 5min ephemeral $0.06)
|
|
36
|
-
completion_per_m = 15.0 # $15 /M tokens
|
|
37
|
-
currency = "USD"
|
|
38
|
-
|
|
39
|
-
# Anthropic Claude Opus 4.5 (2026-06 official first-party API pricing)
|
|
40
|
-
# P1 plan correction (2026-06-03): user 核对官方 pricing 页后纠正
|
|
41
|
-
# 之前值 $24/$0.48/$120 是错的 (类似某种旧/特殊模式价格, 不适合 first-party default)
|
|
42
|
-
[models.claude-opus-4-5]
|
|
43
|
-
cache_miss_per_m = 5.0 # $5 /M
|
|
44
|
-
cache_hit_per_m = 0.50 # $0.50 /M (cache read, 1h TTL — 不是 5min ephemeral $0.48)
|
|
45
|
-
completion_per_m = 25.0 # $25 /M (不是 $120)
|
|
46
|
-
currency = "USD"
|
package/dist/types.d.ts
DELETED
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @deepwhale/llm — 公共类型
|
|
3
|
-
*
|
|
4
|
-
* Sprint 0.3 范围:非流式 chat + 5 个 LLMError 子类。
|
|
5
|
-
* Sprint 1a 扩展:system/tool role + tool_calls + stream() + usage + retry metadata。
|
|
6
|
-
* Sprint 1b 再加:prompt cache、cost accounting、canonical schema。
|
|
7
|
-
*/
|
|
8
|
-
import type { Brand } from '@deepwhale/core';
|
|
9
|
-
/** 模型 ID 的品牌类型,避免把 'deepseek-chat' 当成任意 string 传来传去。 */
|
|
10
|
-
export type ModelId = Brand<string, 'ModelId'>;
|
|
11
|
-
/** Role 联合 — Sprint 1a 加 'system' / 'tool'(tool loop 需要)。 */
|
|
12
|
-
export type Role = 'system' | 'user' | 'assistant' | 'tool';
|
|
13
|
-
/**
|
|
14
|
-
* LLM 调用的 tool 调用描述。Sprint 1a 最小:
|
|
15
|
-
* - id: 由 LLM 返回,tool 响应里 echo 回去
|
|
16
|
-
* - name: tool 名(去 registry 查)
|
|
17
|
-
* - args: tool 参数对象(已 JSON 解析,不是 string)
|
|
18
|
-
*
|
|
19
|
-
* Sprint 1b+ 会在 tool_loop 里用这个 type guard args 是否合法(schema 校验)。
|
|
20
|
-
*/
|
|
21
|
-
export interface ToolCall {
|
|
22
|
-
readonly id: string;
|
|
23
|
-
readonly name: string;
|
|
24
|
-
readonly args: Record<string, unknown>;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* 单条 chat message。Sprint 1a:
|
|
28
|
-
* - role: 加 'system' / 'tool'
|
|
29
|
-
* - content: assistant 在有 tool_calls 时可为空字符串(OAI spec)
|
|
30
|
-
* - tool_calls: assistant 消息携带
|
|
31
|
-
* - tool_call_id: tool 消息携带,echo 上面那个 id
|
|
32
|
-
* - name: tool 消息携带,工具名(OAI 协议要求,便于审计)
|
|
33
|
-
*
|
|
34
|
-
* Sprint 1c-revive-2-D-21.1 (2026-06-06, 修 DeepSeek V4 thinking 400 bug):
|
|
35
|
-
* - reasoning_content: assistant 消息可携带 (DeepSeek V4 默认开 thinking mode,
|
|
36
|
-
* 多轮必须回传上轮 reasoning_content, 否则 400 "reasoning_content must be
|
|
37
|
-
* passed back to the API"). 取消 Sprint 1a "机制 3 简化" 拍板 (parse.ts:45-46
|
|
38
|
-
* 当时主动丢掉, sprint 1b+ 也没补回 — 直到 D-21.1 走完才知道是 v4 默认开
|
|
39
|
-
* thinking 才暴露).
|
|
40
|
-
* - Optional: 不开 thinking 的 model (V3 旧 alias) 没有这个字段, 不破坏兼容.
|
|
41
|
-
* - Only meaningful for 'assistant' role. OAI 协议 system / user / tool
|
|
42
|
-
* 都不带 reasoning_content.
|
|
43
|
-
* - Wire: deepseek-client.toWireMessage 透传到 OAI request body.
|
|
44
|
-
* - Session 持久化: session-adapter 写 'assistant' event 时带 reasoning_content,
|
|
45
|
-
* reload 时还原回 ChatMessage. 跨 reload 续聊不丢 thinking.
|
|
46
|
-
*/
|
|
47
|
-
export interface ChatMessage {
|
|
48
|
-
role: Role;
|
|
49
|
-
content: string;
|
|
50
|
-
tool_calls?: ReadonlyArray<ToolCall>;
|
|
51
|
-
tool_call_id?: string;
|
|
52
|
-
name?: string;
|
|
53
|
-
/**
|
|
54
|
-
* DeepSeek V4 thinking mode 思维链. 多轮必须回传, 否则 400.
|
|
55
|
-
* 非 thinking model 不返, 字段 absent.
|
|
56
|
-
*/
|
|
57
|
-
reasoning_content?: string;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Token usage 来自 LLM 响应。Sprint 1a: OAI 标准 + cached_tokens。
|
|
61
|
-
* Sprint 1b: 加 cache_hit_rate / cost_turn / tokens_uncached (可观测性)。
|
|
62
|
-
* Sprint 1b.5: 加 cost_currency (¥ / $) 让 UI 决 symbol, 不在 UI 层做汇率换算.
|
|
63
|
-
*
|
|
64
|
-
* OAI 标准字段 + DeepSeek 扩展:
|
|
65
|
-
* - prompt_tokens / completion_tokens / total_tokens
|
|
66
|
-
* - cached_tokens (DeepSeek V4 起, 命中 cache 的 token 数)
|
|
67
|
-
*
|
|
68
|
-
* Sprint 1b 扩展 (Prefix-cache 可观测性):
|
|
69
|
-
* - cache_hit_rate: 0..1, cached_tokens / prompt_tokens。LLM 不返 cached_tokens 时 undefined。
|
|
70
|
-
* - cost_turn: 本次 turn 估算费用, 按 pricing config 算 (Sprint 1b.5 抽 config.toml)。
|
|
71
|
-
* - tokens_uncached: prompt_tokens - cached_tokens, 方便人眼扫读"实际新付的 token"。
|
|
72
|
-
*
|
|
73
|
-
* Sprint 1b.5 扩展 (per-model currency, 不引入汇率换算):
|
|
74
|
-
* - cost_currency: 'CNY' | 'USD' — 跟 cost_turn 同步存在或同步 absent。
|
|
75
|
-
* UI 读这个字段决定显示 ¥ 还是 $, 不在数字层做换算。
|
|
76
|
-
* cost_turn absent 时 cost_currency 也必须 absent (不变量)。
|
|
77
|
-
*/
|
|
78
|
-
export interface Usage {
|
|
79
|
-
prompt_tokens: number;
|
|
80
|
-
completion_tokens: number;
|
|
81
|
-
total_tokens: number;
|
|
82
|
-
cached_tokens?: number;
|
|
83
|
-
/** 0..1, cached_tokens / prompt_tokens。LLM 不返 cached_tokens 时 undefined。 */
|
|
84
|
-
cache_hit_rate?: number;
|
|
85
|
-
/**
|
|
86
|
-
* 本 turn 估算费用, pricing config 算 (Sprint 1b.5 抽 config.toml)。
|
|
87
|
-
* 数字单位: currency (CNY ¥ 或 USD $). 不在 UI 层做汇率换算。
|
|
88
|
-
*/
|
|
89
|
-
cost_turn?: number;
|
|
90
|
-
/** Currency 跟 cost_turn 同步存在, UI 读这个决 symbol (¥ / $). */
|
|
91
|
-
cost_currency?: 'CNY' | 'USD';
|
|
92
|
-
/** prompt_tokens - cached_tokens, "实际新付"的 token 数, 方便人眼扫读。 */
|
|
93
|
-
tokens_uncached?: number;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* 旧的 `computeCostBreakdown` (Sprint 1b, hardcode V4-Flash pricing) 已整体迁移到
|
|
97
|
-
* `pricing-config.ts:computeCost`, 同时:
|
|
98
|
-
* - 接收 `PricingConfig` + `ModelId` 参数 (per-model currency)
|
|
99
|
-
* - 接收 `pricing: undefined` (显式表达"没 pricing 也走纯函数 2 字段路径")
|
|
100
|
-
* - 返 `CostBreakdownResult` 联合类型 (3 种路径, 显式表达无 pricing 也能算 cache 字段)
|
|
101
|
-
* - 行为兼容: 公式 (V4-Flash pricing 1.0/0.5/0.1 等数字没变) + 边界 (cached=undefined → undefined)
|
|
102
|
-
*
|
|
103
|
-
* R7 设计原则: pricing 是观测, 不让成功 LLM 响应因"缺价格表"失败; silent fallback 制造假成本更危险。
|
|
104
|
-
* 缺 pricing 时不静默 fallback 到硬编码, 也不抛错, 走"base 2 字段, cost 字段 absent"路径。
|
|
105
|
-
* 找不到 model 的 warning 责任在 caller (client/mode 边界), 纯函数零副作用。
|
|
106
|
-
*
|
|
107
|
-
* Sprint 1a: cache_hit_rate 仅做总 cost 估算, 没暴露。Sprint 1b 起可观测。
|
|
108
|
-
*/
|
|
109
|
-
/** chat() 完整调用的返回值。Sprint 1a 加 tool_calls + usage. */
|
|
110
|
-
export interface ChatResult {
|
|
111
|
-
model: ModelId;
|
|
112
|
-
content: string;
|
|
113
|
-
tool_calls?: ReadonlyArray<ToolCall>;
|
|
114
|
-
/**
|
|
115
|
-
* DeepSeek V4 thinking mode 思维链. 多轮必须回传, 否则 400.
|
|
116
|
-
* Sprint 1c-revive-2-D-21.1 (2026-06-06): parse.ts 不再主动丢这个字段,
|
|
117
|
-
* 而是从 LLM 响应 (choices[0].message.reasoning_content) 提取, 给 caller
|
|
118
|
-
* (tool-loop / session-adapter) 透传.
|
|
119
|
-
*/
|
|
120
|
-
reasoning_content?: string;
|
|
121
|
-
usage?: Usage;
|
|
122
|
-
/**
|
|
123
|
-
* finish_reason:
|
|
124
|
-
* - 'stop': 自然结束
|
|
125
|
-
* - 'tool_calls': LLM 决定调工具
|
|
126
|
-
* - 'length': 触达 max_tokens
|
|
127
|
-
* - 'content_filter': 触发安全过滤
|
|
128
|
-
*/
|
|
129
|
-
finish_reason?: 'stop' | 'tool_calls' | 'length' | 'content_filter';
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* 流式 chunk。Sprint 1a 极简:
|
|
133
|
-
* - delta.content: 增量文本(可能为空,如纯 tool_calls 增量)
|
|
134
|
-
* - delta.tool_calls: 增量 tool_call(Sprint 1a 一次性返回完整,Sprint 1b+ 再支持 incremental)
|
|
135
|
-
* - usage: 只在最后一个 chunk 出现(OAI 协议)
|
|
136
|
-
* - finish_reason: 同 ChatResult
|
|
137
|
-
*
|
|
138
|
-
* Sprint 1c-revive-2-D-21.1 (2026-06-06): delta.reasoning_content 增量
|
|
139
|
-
* 思维链. stream 期间逐 chunk 累加到 working, final ChatResult 拿到完整
|
|
140
|
-
* reasoning_content. 跟 content 一样, 有可能为空字符串 (纯 tool_call 增量).
|
|
141
|
-
*/
|
|
142
|
-
export interface ChatChunk {
|
|
143
|
-
delta: {
|
|
144
|
-
content?: string;
|
|
145
|
-
tool_calls?: ReadonlyArray<ToolCall>;
|
|
146
|
-
/**
|
|
147
|
-
* DeepSeek V4 thinking mode 增量. 累加给 final.reasoning_content.
|
|
148
|
-
*/
|
|
149
|
-
reasoning_content?: string;
|
|
150
|
-
};
|
|
151
|
-
usage?: Usage;
|
|
152
|
-
finish_reason?: ChatResult['finish_reason'];
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* LLM 客户端的抽象接口。Sprint 1a 加 stream() + tools/tool_choice 字段。
|
|
156
|
-
*
|
|
157
|
-
* - chat(): 非流式,一次性返回完整结果
|
|
158
|
-
* - stream(): 流式,逐 chunk 回调(onChunk 同步;onComplete 异步 return final)
|
|
159
|
-
*
|
|
160
|
-
* @throws APIKeyMissingError — API key 未设置
|
|
161
|
-
* @throws LLMRateLimitError — 429(retry 透传后仍未恢复)
|
|
162
|
-
* @throws LLMAuthError — 401/403
|
|
163
|
-
* @throws LLMNetworkError — 网络/DNS 失败
|
|
164
|
-
* @throws LLMUnknownError — 其它 5xx 或 JSON 解析失败
|
|
165
|
-
* @throws LLMStreamError — SSE 解析中途断流
|
|
166
|
-
*/
|
|
167
|
-
export interface LLMClient {
|
|
168
|
-
readonly model: ModelId;
|
|
169
|
-
/**
|
|
170
|
-
* 发送一组 messages,拿到助手完整回复(非流式)。
|
|
171
|
-
*
|
|
172
|
-
* Sprint 1a 新增:
|
|
173
|
-
* - tools: 工具 schema 列表(LLM 看到后可能决定调)
|
|
174
|
-
* - tool_choice: 'auto' / 'none' / 'required'(OAI 标准)
|
|
175
|
-
*
|
|
176
|
-
* retry: 内部对 429 / 5xx / network error 自动指数退避(默认 3 次),
|
|
177
|
-
* 全失败才抛 LLMError。Sprint 1a 简化为固定 3 次。
|
|
178
|
-
*/
|
|
179
|
-
chat(messages: ChatMessage[], options?: {
|
|
180
|
-
signal?: AbortSignal;
|
|
181
|
-
tools?: ReadonlyArray<LLMToolSchema>;
|
|
182
|
-
tool_choice?: 'auto' | 'none' | 'required';
|
|
183
|
-
}): Promise<ChatResult>;
|
|
184
|
-
/**
|
|
185
|
-
* 流式 chat。Sprint 1a 新增。
|
|
186
|
-
*
|
|
187
|
-
* 用法:
|
|
188
|
-
* for await (const chunk of client.stream(messages, { onChunk })) {
|
|
189
|
-
* // chunk = ChatChunk
|
|
190
|
-
* }
|
|
191
|
-
*
|
|
192
|
-
* 也支持 callback 模式(更简单,适合 REPL):
|
|
193
|
-
* await client.stream(messages, { onChunk: (c) => out.write(c.delta.content ?? '') });
|
|
194
|
-
*
|
|
195
|
-
* retry 行为: 内部 stream 重连在 Sprint 1a **不做**(流式断流语义复杂),
|
|
196
|
-
* 整个 stream 失败抛 LLMError 让 caller 决定(Sprint 1b+ 补断点续传)。
|
|
197
|
-
*/
|
|
198
|
-
stream(messages: ChatMessage[], options: {
|
|
199
|
-
signal?: AbortSignal;
|
|
200
|
-
tools?: ReadonlyArray<LLMToolSchema>;
|
|
201
|
-
tool_choice?: 'auto' | 'none' | 'required';
|
|
202
|
-
onChunk: (chunk: ChatChunk) => void;
|
|
203
|
-
}): Promise<ChatResult>;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Sprint 1a 极简:复用 OpenAI function-calling 协议 + ToolInputSchema 兼容形态。
|
|
207
|
-
*
|
|
208
|
-
* 不用 import @deepwhale/coding-agent 避免循环依赖 — Tool 那边把 schema 转成
|
|
209
|
-
* 这个形态即可(structural typing,运行时不影响)。
|
|
210
|
-
*/
|
|
211
|
-
export interface LLMToolSchema {
|
|
212
|
-
name: string;
|
|
213
|
-
description: string;
|
|
214
|
-
parameters: LLMToolParametersSchema;
|
|
215
|
-
}
|
|
216
|
-
/** OAI function-calling 参数 schema(简化形态,跟 coding-agent 的 ToolInputSchema 兼容)。 */
|
|
217
|
-
export interface LLMToolParametersSchema {
|
|
218
|
-
readonly type: 'object';
|
|
219
|
-
readonly properties: Record<string, LLMToolParamSchema>;
|
|
220
|
-
readonly required?: ReadonlyArray<string>;
|
|
221
|
-
}
|
|
222
|
-
export type LLMToolParamSchema = {
|
|
223
|
-
type: 'string';
|
|
224
|
-
description: string;
|
|
225
|
-
enum?: ReadonlyArray<string>;
|
|
226
|
-
} | {
|
|
227
|
-
type: 'number';
|
|
228
|
-
description: string;
|
|
229
|
-
minimum?: number;
|
|
230
|
-
maximum?: number;
|
|
231
|
-
} | {
|
|
232
|
-
type: 'boolean';
|
|
233
|
-
description: string;
|
|
234
|
-
} | {
|
|
235
|
-
type: 'array';
|
|
236
|
-
description: string;
|
|
237
|
-
items: LLMToolParamSchema;
|
|
238
|
-
};
|
|
239
|
-
/** Sprint 1a:SSE 流中途断流专用。Sprint 1b 再加 retry/续传。 */
|
|
240
|
-
export declare class LLMStreamError extends Error implements LLMError {
|
|
241
|
-
readonly name: "LLMStreamError";
|
|
242
|
-
readonly isLLMError: true;
|
|
243
|
-
constructor(message: string, options?: {
|
|
244
|
-
cause?: unknown;
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
export interface LLMError {
|
|
248
|
-
readonly isLLMError: true;
|
|
249
|
-
readonly name: string;
|
|
250
|
-
readonly message: string;
|
|
251
|
-
readonly cause?: unknown;
|
|
252
|
-
}
|
|
253
|
-
/** 类型守卫:通过 isLLMError 标签识别 LLM 派生的 Error。 */
|
|
254
|
-
export declare function isLLMError(err: unknown): err is LLMError;
|
|
255
|
-
export declare class APIKeyMissingError extends Error implements LLMError {
|
|
256
|
-
readonly name: "APIKeyMissingError";
|
|
257
|
-
readonly isLLMError: true;
|
|
258
|
-
constructor(message: string);
|
|
259
|
-
}
|
|
260
|
-
export declare class LLMRateLimitError extends Error implements LLMError {
|
|
261
|
-
readonly name: "LLMRateLimitError";
|
|
262
|
-
readonly isLLMError: true;
|
|
263
|
-
readonly status: 429;
|
|
264
|
-
constructor(message: string);
|
|
265
|
-
}
|
|
266
|
-
export declare class LLMAuthError extends Error implements LLMError {
|
|
267
|
-
readonly name: "LLMAuthError";
|
|
268
|
-
readonly isLLMError: true;
|
|
269
|
-
readonly status: number;
|
|
270
|
-
constructor(status: number, message: string);
|
|
271
|
-
}
|
|
272
|
-
export declare class LLMNetworkError extends Error implements LLMError {
|
|
273
|
-
readonly name: "LLMNetworkError";
|
|
274
|
-
readonly isLLMError: true;
|
|
275
|
-
constructor(message: string, options?: {
|
|
276
|
-
cause?: unknown;
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
export declare class LLMUnknownError extends Error implements LLMError {
|
|
280
|
-
readonly name: "LLMUnknownError";
|
|
281
|
-
readonly isLLMError: true;
|
|
282
|
-
readonly status?: number;
|
|
283
|
-
constructor(message: string, options?: {
|
|
284
|
-
cause?: unknown;
|
|
285
|
-
status?: number;
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE7C,wDAAwD;AACxD,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAE/C,6DAA6D;AAC7D,MAAM,MAAM,IAAI,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;AAE5D;;;;;;;GAOG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACxC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,IAA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,UAAU,EAAG,IAAI,CAAU;IACpC,QAAQ,CAAC,MAAM,EAAG,GAAG,CAAU;gBACnB,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,YAAa,SAAQ,KAAM,YAAW,QAAQ;IACzD,SAAkB,IAAI,EAAG,cAAc,CAAU;IACjD,QAAQ,CAAC,UAAU,EAAG,IAAI,CAAU;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBACZ,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAI5C;AAED,qBAAa,eAAgB,SAAQ,KAAM,YAAW,QAAQ;IAC5D,SAAkB,IAAI,EAAG,iBAAiB,CAAU;IACpD,QAAQ,CAAC,UAAU,EAAG,IAAI,CAAU;gBACxB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAM3D;AAED,qBAAa,eAAgB,SAAQ,KAAM,YAAW,QAAQ;IAC5D,SAAkB,IAAI,EAAG,iBAAiB,CAAU;IACpD,QAAQ,CAAC,UAAU,EAAG,IAAI,CAAU;IACpC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBACb,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;CAO5E"}
|
package/dist/types.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @deepwhale/llm — 公共类型
|
|
3
|
-
*
|
|
4
|
-
* Sprint 0.3 范围:非流式 chat + 5 个 LLMError 子类。
|
|
5
|
-
* Sprint 1a 扩展:system/tool role + tool_calls + stream() + usage + retry metadata。
|
|
6
|
-
* Sprint 1b 再加:prompt cache、cost accounting、canonical schema。
|
|
7
|
-
*/
|
|
8
|
-
/** Sprint 1a:SSE 流中途断流专用。Sprint 1b 再加 retry/续传。 */
|
|
9
|
-
export class LLMStreamError extends Error {
|
|
10
|
-
name = 'LLMStreamError';
|
|
11
|
-
isLLMError = true;
|
|
12
|
-
constructor(message, options) {
|
|
13
|
-
super(message);
|
|
14
|
-
if (options?.cause !== undefined) {
|
|
15
|
-
this.cause = options.cause;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
/** 类型守卫:通过 isLLMError 标签识别 LLM 派生的 Error。 */
|
|
20
|
-
export function isLLMError(err) {
|
|
21
|
-
return err instanceof Error && err.isLLMError === true;
|
|
22
|
-
}
|
|
23
|
-
export class APIKeyMissingError extends Error {
|
|
24
|
-
name = 'APIKeyMissingError';
|
|
25
|
-
isLLMError = true;
|
|
26
|
-
constructor(message) {
|
|
27
|
-
super(message);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export class LLMRateLimitError extends Error {
|
|
31
|
-
name = 'LLMRateLimitError';
|
|
32
|
-
isLLMError = true;
|
|
33
|
-
status = 429;
|
|
34
|
-
constructor(message) {
|
|
35
|
-
super(message);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
export class LLMAuthError extends Error {
|
|
39
|
-
name = 'LLMAuthError';
|
|
40
|
-
isLLMError = true;
|
|
41
|
-
status;
|
|
42
|
-
constructor(status, message) {
|
|
43
|
-
super(message);
|
|
44
|
-
this.status = status;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
export class LLMNetworkError extends Error {
|
|
48
|
-
name = 'LLMNetworkError';
|
|
49
|
-
isLLMError = true;
|
|
50
|
-
constructor(message, options) {
|
|
51
|
-
super(message);
|
|
52
|
-
if (options?.cause !== undefined) {
|
|
53
|
-
this.cause = options.cause;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
export class LLMUnknownError extends Error {
|
|
58
|
-
name = 'LLMUnknownError';
|
|
59
|
-
isLLMError = true;
|
|
60
|
-
status;
|
|
61
|
-
constructor(message, options) {
|
|
62
|
-
super(message);
|
|
63
|
-
if (options?.cause !== undefined) {
|
|
64
|
-
this.cause = options.cause;
|
|
65
|
-
}
|
|
66
|
-
if (options?.status !== undefined)
|
|
67
|
-
this.status = options.status;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAkPH,mDAAmD;AACnD,MAAM,OAAO,cAAe,SAAQ,KAAK;IACrB,IAAI,GAAG,gBAAyB,CAAC;IAC1C,UAAU,GAAG,IAAa,CAAC;IACpC,YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,OAAO,EAAE,KAAK,KAAK,SAAS,EAAE,CAAC;YAChC,IAA4B,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QACtD,CAAC;IACH,CAAC;CACF;AAeD,6CAA6C;AAC7C,MAAM,UAAU,UAAU,CAAC,GAAY;IACrC,OAAO,GAAG,YAAY,KAAK,IAAK,GAAgC,CAAC,UAAU,KAAK,IAAI,CAAC;AACvF,CAAC;AAED,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IACzB,IAAI,GAAG,oBAA6B,CAAC;IAC9C,UAAU,GAAG,IAAa,CAAC;IACpC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAED,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACxB,IAAI,GAAG,mBAA4B,CAAC;IAC7C,UAAU,GAAG,IAAa,CAAC;IAC3B,MAAM,GAAG,GAAY,CAAC;IAC/B,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAED,MAAM,OAAO,YAAa,SAAQ,KAAK;IACnB,IAAI,GAAG,cAAuB,CAAC;IACxC,UAAU,GAAG,IAAa,CAAC;I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