@acosmi/sdk-ts 1.4.1 → 1.4.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.
@@ -1,1027 +0,0 @@
1
- /** OAuth Authorization Server 元数据 (RFC 8414) */
2
- interface ServerMetadata {
3
- issuer: string;
4
- authorization_endpoint: string;
5
- token_endpoint: string;
6
- revocation_endpoint: string;
7
- registration_endpoint: string;
8
- scopes_supported: string[];
9
- }
10
- /** OAuth token 响应 */
11
- interface TokenResponse {
12
- access_token: string;
13
- token_type: string;
14
- expires_in: number;
15
- refresh_token?: string;
16
- scope?: string;
17
- }
18
- /** 持久化 token 对 */
19
- interface TokenSet {
20
- access_token: string;
21
- refresh_token: string;
22
- /** ISO 8601 格式 */
23
- expires_at: string;
24
- scope: string;
25
- client_id: string;
26
- server_url: string;
27
- }
28
- /** token 是否已过期 (提前 30 秒视为过期) */
29
- declare function tokenSetIsExpired(t: TokenSet): boolean;
30
- /** 动态注册响应 */
31
- interface ClientRegistration {
32
- client_id: string;
33
- client_secret?: string;
34
- }
35
- /** 模型能力矩阵 — 下游通过此结构决定 UI 功能开关和 Beta Header 注入 */
36
- interface ModelCapabilities {
37
- supports_thinking: boolean;
38
- supports_adaptive_thinking: boolean;
39
- /** 交错思考 (Interleaved Thinking) */
40
- supports_isp: boolean;
41
- supports_web_search: boolean;
42
- supports_tool_search: boolean;
43
- supports_structured_output: boolean;
44
- supports_effort: boolean;
45
- /** 模型是否支持 thinking_level="max" 强度档 (深度思考) */
46
- supports_max_effort: boolean;
47
- /** Opus 4.6 独有 (Speed="fast") */
48
- supports_fast_mode: boolean;
49
- /** Auto 模式 (模型自主选择工具/搜索策略) */
50
- supports_auto_mode: boolean;
51
- supports_1m_context: boolean;
52
- supports_prompt_cache: boolean;
53
- /** 通过 context-management beta 控制 */
54
- supports_cache_editing: boolean;
55
- /** Claude 4 内置 */
56
- supports_token_efficient: boolean;
57
- supports_redact_thinking: boolean;
58
- max_input_tokens: number;
59
- max_output_tokens: number;
60
- /**
61
- * 桌面视觉理解 sidecar 能力 (v1.2+):
62
- * 为 true 表示该模型适合作为桌面截图解析 sidecar — 输入 screenshot,
63
- * 输出结构化 UI/视觉描述, 供非多模态主模型消费 (CrabCode desktop automation /
64
- * computer-use 选模型时使用).
65
- *
66
- * 与 ManagedModel.inputModalities=['image'] 是正交两件事:
67
- * - inputModalities 描述"模型能不能吃图片输入"
68
- * - supports_desktop_visual_understanding 描述"模型是不是被运营标记为
69
- * 适合做桌面 UI 解析的 sidecar" (有些通用视觉模型并不擅长 UI 解析)
70
- *
71
- * 调用方不应通过模型名 substring 推断此能力; 必须读上游下发字段.
72
- */
73
- supports_desktop_visual_understanding?: boolean;
74
- }
75
- /**
76
- * 模型可接收的用户输入模态 (v1.2+).
77
- *
78
- * - 'text': 文本输入
79
- * - 'image': 截图 / 图片输入 (多模态)
80
- *
81
- * ManagedModel.inputModalities 包含 'image' 才允许向该模型直接发图;
82
- * 缺失字段时调用方应保守按 text-only / unknown 处理.
83
- */
84
- type InputModality = 'text' | 'image';
85
- /** BucketClass 字面量常量 — V30 二轮审计 D-P1-3 修复 */
86
- declare const BucketClassCommercial = "COMMERCIAL";
87
- declare const BucketClassGeneric = "GENERIC";
88
- /**
89
- * 用户在某 modelId 上的桶余额聚合视图 (V30 entitlement-listing).
90
- *
91
- * 多桶聚合规则 (上游 nexus-v4 计算后下发, 全部单位为 ETU):
92
- * - quotaEtu / usedEtu / remainingEtu: 该 modelId 下用户全部 active 桶求和
93
- * - sharedPoolEtu: 求和量中"来自通配桶"的部分 (跨模型可消耗)
94
- * - bucketClass / expiresAt: 取最高优先级桶
95
- * - expired: 全部桶都过期才置 true
96
- */
97
- interface BucketInfo {
98
- quotaEtu: number;
99
- usedEtu: number;
100
- remainingEtu: number;
101
- sharedPoolEtu?: number;
102
- expiresAt?: string;
103
- bucketClass: string;
104
- expired?: boolean;
105
- /** v0.19+ — GENERIC alive 桶 tokenRemaining 求和 ("免费余额", 真实可消费) */
106
- freeRemainingEtu: number;
107
- /** v0.19+ — COMMERCIAL alive 桶 tokenRemaining 求和 ("付费余额") */
108
- paidRemainingEtu: number;
109
- }
110
- /** 大小写不敏感判定 — 与 buildBucketView (managed_model.go) EqualFold 语义对齐 */
111
- declare function bucketInfoIsCommercial(b: BucketInfo | null | undefined): boolean;
112
- /** 托管模型 */
113
- interface ManagedModel {
114
- id: string;
115
- name: string;
116
- provider: string;
117
- modelId: string;
118
- maxTokens: number;
119
- isEnabled: boolean;
120
- pricePerMTok?: number;
121
- isDefault?: boolean;
122
- contextWindow?: number;
123
- capabilities: ModelCapabilities;
124
- /**
125
- * 上游 gateway 为此模型启用的请求格式列表
126
- * 取值: "anthropic" | "openai"
127
- * 空值表示上游未声明, SDK 回落 provider 硬编码分支 (向后兼容)
128
- */
129
- supported_formats?: string[];
130
- /**
131
- * 上游建议客户端优先使用的格式
132
- * 取值: "anthropic" | "openai"; 空值等价于 supported_formats[0]
133
- */
134
- preferred_format?: string;
135
- /**
136
- * 当前用户在此模型上的桶余额聚合 (V0.18 V30 entitlement-listing).
137
- *
138
- * 仅当调用方为非 admin 用户 (web user / desktop OAuth) 时上游才会返回此字段:
139
- * - admin / X-Internal-Bypass 调用 → 缺失
140
- * - 普通用户 → 非空, 含 quota/used/remaining 求和
141
- */
142
- bucketInfo?: BucketInfo;
143
- /**
144
- * 模型可接收的用户输入模态 (v1.2+, CrabCode desktop automation / computer-use 选模型用).
145
- *
146
- * 取值: 'text' | 'image' 的子集. 'image' 表示模型可直接接收 screenshot/image 输入.
147
- *
148
- * 兼容上游字段名 input_modalities (snake_case) — listModels 在写缓存前会做归一化.
149
- *
150
- * **缺失语义**: 上游未下发时该字段为 undefined, 调用方必须保守按 text-only / unknown
151
- * 处理, 严禁默认假设支持 image. 同样严禁用模型名 substring 反推 modality.
152
- */
153
- inputModalities?: InputModality[];
154
- }
155
- /** 单桶视图 — QuotaSummary.freeBuckets/paidBuckets 元素 */
156
- interface BucketRow {
157
- bucketId: string;
158
- /** 精确桶为具体 modelId, 通配桶为 "*" */
159
- modelId: string;
160
- /** COMMERCIAL | GENERIC */
161
- bucketClass: string;
162
- tokenQuota: number;
163
- tokenUsed: number;
164
- tokenRemaining: number;
165
- /** 永久桶为 undefined */
166
- expiresAt?: string;
167
- expired?: boolean;
168
- }
169
- declare function bucketRowIsCommercial(r: BucketRow | null | undefined): boolean;
170
- /**
171
- * GET /api/v4/entitlements/quota-summary 返回体, 调用 client.getQuotaSummary 获取.
172
- *
173
- * 设计目的: 个人中心钱包栏一次性展示"我还有多少免费 + 多少付费"+ 各自最近到期时间.
174
- */
175
- interface QuotaSummary {
176
- /** GENERIC (免费/赠送) alive 桶 tokenRemaining 求和 */
177
- freeTotalEtu: number;
178
- /** COMMERCIAL (付费购买) alive 桶 tokenRemaining 求和 */
179
- paidTotalEtu: number;
180
- /** GENERIC 桶详情 (含过期, UI 列流水); 空时为空数组 */
181
- freeBuckets: BucketRow[];
182
- /** COMMERCIAL 桶详情 (含过期); 空时为空数组 */
183
- paidBuckets: BucketRow[];
184
- /** GENERIC alive 桶中最早到期; 永久桶/无 alive 时缺失 */
185
- nextFreeExpiresAt?: string;
186
- /** COMMERCIAL alive 桶中最早到期; 同上 */
187
- nextPaidExpiresAt?: string;
188
- }
189
- /** 聊天消息 (简单文本格式, CrabClaw 使用) */
190
- interface ChatMessage {
191
- role: string;
192
- content: string;
193
- }
194
- /** Anthropic 响应内容块 */
195
- interface ChatContentBlock {
196
- type: string;
197
- text?: string;
198
- citations?: unknown;
199
- thinking?: string;
200
- signature?: string;
201
- data?: string;
202
- id?: string;
203
- name?: string;
204
- /** json.RawMessage in Go */
205
- input?: unknown;
206
- server_name?: string;
207
- caller?: unknown;
208
- tool_use_id?: string;
209
- content?: unknown;
210
- is_error?: boolean;
211
- }
212
- /** Anthropic 格式 token 用量 */
213
- interface ChatUsage {
214
- input_tokens: number;
215
- output_tokens: number;
216
- cache_creation_input_tokens?: number;
217
- cache_read_input_tokens?: number;
218
- }
219
- /** 三档思考级别 (v0.9.0) */
220
- declare const ThinkingOff = "off";
221
- declare const ThinkingHigh = "high";
222
- declare const ThinkingMax = "max";
223
- /** 标准思考最低 maxTokens — CrabCode 默认 MAX_OUTPUT_TOKENS_DEFAULT = 32_000 */
224
- declare const ThinkingHighMinMaxTokens = 32000;
225
- /** 深度思考回退 maxTokens — Opus 4.6 上限 128K */
226
- declare const ThinkingMaxFallbackMaxTokens = 128000;
227
- /** 控制模型思考行为 */
228
- interface ThinkingConfig {
229
- /** "enabled" | "disabled" | "adaptive" */
230
- type: string;
231
- /** 仅 type="enabled" 时 (旧模型回退) */
232
- budget_tokens?: number;
233
- /** 思考级别 (v0.9.0): "off" | "high" | "max" */
234
- level?: string;
235
- /** "none" | "summary" | "" (默认空=完整) */
236
- display?: string;
237
- }
238
- /** 根据三档 level 创建配置 */
239
- declare function newThinkingConfig(level: string): ThinkingConfig;
240
- /** 服务端工具定义 — SDK 将工具 schema 合入 API 请求的 tools 数组 */
241
- interface ServerTool {
242
- type: string;
243
- name: string;
244
- config?: Record<string, unknown>;
245
- }
246
- /** Server Tool 类型常量 */
247
- declare const ServerToolTypeWebSearch = "web_search_20250305";
248
- /** 地理位置 */
249
- interface GeoLoc {
250
- /** ISO 3166-1 alpha-2 */
251
- country: string;
252
- city?: string;
253
- }
254
- /** ServerTool.config 结构 (type=web_search_20250305) */
255
- interface WebSearchConfig {
256
- /** 每请求最大搜索次数, 默认 8 */
257
- max_uses?: number;
258
- /** 域名白名单 (与 blocked_domains 互斥) */
259
- allowed_domains?: string[];
260
- /** 域名黑名单 (与 allowed_domains 互斥) */
261
- blocked_domains?: string[];
262
- user_location?: GeoLoc;
263
- }
264
- /** 控制推理努力级别 */
265
- interface EffortConfig {
266
- /** "low" | "medium" | "high" | "max" */
267
- level: string;
268
- }
269
- /** 控制输出格式 (结构化输出) */
270
- interface OutputConfig {
271
- /** "json_schema" | "" */
272
- format?: string;
273
- schema?: unknown;
274
- }
275
- /**
276
- * 创建搜索 Server Tool 的便捷方法
277
- * allowed_domains 与 blocked_domains 互斥, 同时传入抛 Error
278
- */
279
- declare function newWebSearchTool(cfg?: WebSearchConfig | null): ServerTool;
280
- /**
281
- * 聊天请求
282
- *
283
- * 基础字段供 CrabClaw 使用, 扩展字段供 CrabCode 使用。
284
- * 所有新增字段零值不改变行为 (向后兼容)。
285
- *
286
- * 注意:扩展字段(rawMessages/system/tools/...)不会被原样 JSON.stringify,
287
- * 而由 buildRequestBody (adapter) 选择性序列化到请求体。
288
- */
289
- interface ChatRequest {
290
- messages?: ChatMessage[];
291
- stream?: boolean;
292
- max_tokens?: number;
293
- /** 复杂消息体 (含 content blocks / 多模态), 非 nil 时优先于 messages */
294
- rawMessages?: unknown;
295
- /** string 或 ContentBlock[] */
296
- system?: unknown;
297
- /** 标准工具定义 (Tool[]) */
298
- tools?: unknown;
299
- temperature?: number;
300
- thinking?: ThinkingConfig;
301
- metadata?: Record<string, string>;
302
- /** 显式 beta (SDK 自动合并) */
303
- betas?: string[];
304
- /** 服务端工具 (buildRequestBody 合入 tools 数组) */
305
- serverTools?: ServerTool[];
306
- /** "" | "fast" (Fast Mode) */
307
- speed?: string;
308
- effort?: EffortConfig;
309
- outputConfig?: OutputConfig;
310
- /** 任意扩展字段 (buildRequestBody 合入请求体) */
311
- extraBody?: Record<string, unknown>;
312
- /**
313
- * v0.13.0: OpenAI wire format 原生字段。AnthropicAdapter 忽略,
314
- * OpenAIAdapter 按 OpenAI 规范序列化。
315
- *
316
- * 对应 OpenAI `parallel_tool_calls` 顶层字段, undefined = 不设置 (沿用上游默认 true)。
317
- */
318
- parallelToolCalls?: boolean;
319
- }
320
- /** 联网搜索结果来源 (与后端 adk/stream_helpers.go SourceItem 对齐) */
321
- interface WebSearchSource {
322
- title: string;
323
- url: string;
324
- snippet?: string;
325
- }
326
- /** 搜索来源事件 (从 SSE "sources" 事件解析) */
327
- interface SourcesEvent {
328
- sources: WebSearchSource[];
329
- session_id?: string;
330
- }
331
- /**
332
- * 从 StreamEvent 中解析搜索来源
333
- * 返回 null 表示该事件不是 sources 类型
334
- */
335
- declare function parseSourcesEvent(ev: StreamEvent): SourcesEvent | null;
336
- interface OpenAIChatResponse {
337
- id: string;
338
- /** "chat.completion" */
339
- object: string;
340
- model: string;
341
- choices: OpenAIChatChoice[];
342
- usage: OpenAIUsage;
343
- }
344
- interface OpenAIChatChoice {
345
- index: number;
346
- message: OpenAIChatMessage;
347
- /** "stop", "tool_calls", "length" */
348
- finish_reason: string;
349
- }
350
- interface OpenAIChatMessage {
351
- role: string;
352
- content: string;
353
- tool_calls?: OpenAIToolCall[];
354
- /** GLM/DeepSeek thinking */
355
- reasoning_content?: string;
356
- }
357
- interface OpenAIToolCall {
358
- id: string;
359
- /** "function" */
360
- type: string;
361
- function: OpenAIFunctionCall;
362
- }
363
- interface OpenAIFunctionCall {
364
- name: string;
365
- arguments: string;
366
- }
367
- interface OpenAIUsage {
368
- prompt_tokens: number;
369
- completion_tokens: number;
370
- total_tokens: number;
371
- }
372
- /** OpenAI SSE delta 格式 */
373
- interface OpenAIStreamChunk {
374
- id: string;
375
- /** "chat.completion.chunk" */
376
- object: string;
377
- choices: OpenAIStreamChoice[];
378
- usage?: OpenAIUsage;
379
- }
380
- interface OpenAIStreamChoice {
381
- index: number;
382
- delta: OpenAIStreamDelta;
383
- finish_reason: string | null;
384
- }
385
- interface OpenAIStreamDelta {
386
- role?: string;
387
- content?: string;
388
- reasoning_content?: string;
389
- tool_calls?: OpenAIStreamToolCall[];
390
- }
391
- interface OpenAIStreamToolCall {
392
- index: number;
393
- id?: string;
394
- type?: string;
395
- function: OpenAIFunctionCall;
396
- }
397
- /**
398
- * 同步聊天响应 (Anthropic format, v0.4.1)
399
- *
400
- * tokenRemaining / callRemaining / modelTokenRemaining* 不在 wire JSON 中, 由 client 从 Header 填充。
401
- * 哨兵 -1 表示服务端未返回。
402
- */
403
- interface ChatResponse {
404
- id: string;
405
- type: string;
406
- model: string;
407
- role: string;
408
- content: ChatContentBlock[];
409
- stop_reason: string;
410
- usage: ChatUsage;
411
- /** -1 表示服务端未返回 */
412
- tokenRemaining: number;
413
- callRemaining: number;
414
- modelTokenRemaining: number;
415
- modelTokenRemainingETU: number;
416
- }
417
- /**
418
- * Anthropic 内容块
419
- * 覆盖: text / thinking / redacted_thinking / tool_use / tool_result /
420
- * server_tool_use / mcp_tool_use / mcp_tool_result
421
- */
422
- interface AnthropicContentBlock {
423
- type: string;
424
- text?: string;
425
- /** tool_use / server_tool_use / mcp_tool_use block ID */
426
- id?: string;
427
- /** tool_use function name */
428
- name?: string;
429
- /** tool_use arguments (json.RawMessage) */
430
- input?: unknown;
431
- /** thinking block content */
432
- thinking?: string;
433
- /** text — web_search 搜索引用 */
434
- citations?: unknown;
435
- /** thinking — Anthropic 签名 (后续请求必须回传) */
436
- signature?: string;
437
- /** redacted_thinking — base64 编码的被审查思考内容 */
438
- data?: string;
439
- /** server_tool_use / mcp_tool_use / mcp_tool_result — 服务端工具来源 */
440
- server_name?: string;
441
- /** mcp_tool_use — MCP 调用者上下文 */
442
- caller?: unknown;
443
- /** tool_result / mcp_tool_result — 工具执行结果 */
444
- tool_use_id?: string;
445
- content?: unknown;
446
- is_error?: boolean;
447
- }
448
- /** Anthropic token 用量 */
449
- interface AnthropicUsage {
450
- input_tokens: number;
451
- output_tokens: number;
452
- cache_creation_input_tokens?: number;
453
- cache_read_input_tokens?: number;
454
- }
455
- /**
456
- * Anthropic 原生格式同步响应
457
- * POST /managed-models/:id/anthropic 返回此格式 (无 response.Success 包装)
458
- */
459
- interface AnthropicResponse {
460
- id: string;
461
- /** "message" */
462
- type: string;
463
- /** "assistant" */
464
- role: string;
465
- content: AnthropicContentBlock[];
466
- model: string;
467
- stop_reason: string;
468
- stop_sequence?: string | null;
469
- usage: AnthropicUsage;
470
- }
471
- /** 提取所有 text 类型内容块的文本,拼接返回 */
472
- declare function anthropicResponseTextContent(r: AnthropicResponse): string;
473
- /** 提取所有 thinking 类型内容块的文本,拼接返回 */
474
- declare function anthropicResponseThinkingContent(r: AnthropicResponse): string;
475
- /** 返回所有 tool_use 类型的内容块 */
476
- declare function anthropicResponseToolUseBlocks(r: AnthropicResponse): AnthropicContentBlock[];
477
- /**
478
- * SSE 流式事件
479
- *
480
- * v0.11.0 新增 blockIndex/blockType/ephemeral 三字段 (in-band content block 元数据)。
481
- * 零值等价 v0.10.0 行为, 未识别的事件三字段全部零值。
482
- */
483
- interface StreamEvent {
484
- event: string;
485
- data: string;
486
- /** 对齐 Anthropic content_block_start/delta/stop 的 index 字段 */
487
- blockIndex?: number;
488
- /** 由 content_block_start 解析得到, delta/stop 从 index→type 映射查出 */
489
- blockType?: string;
490
- /** 网关标记此 block 下一轮不应回传 */
491
- ephemeral?: boolean;
492
- }
493
- /**
494
- * 流式结算事件 (从 settled SSE 事件解析)
495
- * 包含本次请求的 token 消耗及结算后的剩余余额
496
- */
497
- interface StreamSettlement {
498
- requestId: string;
499
- consumeStatus: string;
500
- inputTokens: number;
501
- outputTokens: number;
502
- totalTokens: number;
503
- /** 结算后剩余 token (-1 表示服务端未返回) */
504
- tokenRemaining: number;
505
- /** 结算后剩余调用次数 (-1 表示服务端未返回) */
506
- callRemaining: number;
507
- }
508
- /** 从 settled 类型的 StreamEvent 中解析结算信息. 不是 settled 类型则返回 null. */
509
- declare function parseSettlement(ev: StreamEvent): StreamSettlement | null;
510
- /** 权益余额 (聚合) */
511
- interface EntitlementBalance {
512
- totalTokenQuota: number;
513
- totalTokenUsed: number;
514
- totalTokenRemaining: number;
515
- totalCallQuota: number;
516
- totalCallUsed: number;
517
- totalCallRemaining: number;
518
- activeEntitlements: number;
519
- }
520
- /** 单条权益明细 */
521
- interface EntitlementItem {
522
- id: string;
523
- type: string;
524
- status: string;
525
- tokenQuota: number;
526
- tokenUsed: number;
527
- tokenRemaining: number;
528
- callQuota: number;
529
- callUsed: number;
530
- callRemaining: number;
531
- expiresAt?: string;
532
- sourceId?: string;
533
- sourceType?: string;
534
- remark?: string;
535
- createdAt: string;
536
- }
537
- /** 详细余额 (含每条权益明细) */
538
- interface BalanceDetail {
539
- totalTokenQuota: number;
540
- totalTokenUsed: number;
541
- totalTokenRemaining: number;
542
- totalCallQuota: number;
543
- totalCallUsed: number;
544
- totalCallRemaining: number;
545
- activeEntitlements: number;
546
- entitlements: EntitlementItem[];
547
- }
548
- /** 核销记录 */
549
- interface ConsumeRecord {
550
- id: string;
551
- entitlementId: string;
552
- requestId: string;
553
- modelId?: string;
554
- tokensConsumed: number;
555
- status: string;
556
- createdAt: string;
557
- }
558
- /** 核销记录分页响应 */
559
- interface ConsumeRecordPage {
560
- records: ConsumeRecord[];
561
- total: number;
562
- page: number;
563
- pageSize: number;
564
- }
565
- /**
566
- * 单桶视图 (用户多桶 hero / 模型切换提示用)
567
- *
568
- * 字段名仍叫 ETU 但 T3 死代码清除后 = raw token (V29 系数管理已退役)。
569
- */
570
- interface ModelBucket {
571
- bucketId: string;
572
- entitlementId: string;
573
- /** "*" = 通配 */
574
- modelId: string;
575
- /** COMMERCIAL / GENERIC */
576
- bucketClass: string;
577
- tokenQuota: number;
578
- tokenUsed: number;
579
- tokenRemaining: number;
580
- callQuota: number;
581
- callUsed: number;
582
- callRemaining: number;
583
- allowedModelsJson?: string;
584
- }
585
- /** GetByModel 响应; primaryBucket 在 bucketId 为空时表示无可用桶。 */
586
- interface ModelByQuotaResponse {
587
- modelId: string;
588
- /** 折算后剩余 (调度判定用) */
589
- etuRemaining: number;
590
- /** 反系数估算的原始 token (UI 展示用) */
591
- rawTokenRemaining: number;
592
- hasQuota: boolean;
593
- primaryBucket?: ModelBucket;
594
- }
595
- /** 单条模型系数 (SDK TTL 8s 缓存源) */
596
- interface ModelCoefficient {
597
- modelId: string;
598
- tenantId: string;
599
- inputCoef: number;
600
- outputCoef: number;
601
- cacheReadCoef: number;
602
- cacheCreationCoef: number;
603
- version: number;
604
- effectiveAt: string;
605
- }
606
- /** 流量包商品。price 用 string (Go json.Number) 避免浮点精度丢失。 */
607
- interface TokenPackage {
608
- id: string;
609
- name: string;
610
- description?: string;
611
- tokenQuota: number;
612
- callQuota?: number;
613
- price: string;
614
- validDays: number;
615
- isEnabled: boolean;
616
- sortOrder?: number;
617
- }
618
- /** 订单。amount 用 string (Go json.Number) 避免精度丢失。 */
619
- interface Order {
620
- id: string;
621
- packageId: string;
622
- packageName?: string;
623
- amount: string;
624
- status: string;
625
- payUrl?: string;
626
- createdAt: string;
627
- }
628
- /** 订单状态 */
629
- interface OrderStatus {
630
- orderId: string;
631
- status: string;
632
- }
633
- /** 下单请求 */
634
- interface PayPayload {
635
- payMethod?: string;
636
- }
637
- /** 钱包统计。金额使用 string (Go json.Number) 避免浮点精度丢失 (金融安全) */
638
- interface WalletStats {
639
- balance: string;
640
- monthlyConsumption: string;
641
- monthlyRecharge: string;
642
- transactionCount: number;
643
- }
644
- /** 交易记录 */
645
- interface Transaction {
646
- id: string;
647
- type: string;
648
- amount: string;
649
- remark?: string;
650
- createdAt: string;
651
- }
652
- interface SkillStoreItem {
653
- id: string;
654
- pluginId: string;
655
- key: string;
656
- name: string;
657
- description: string;
658
- icon: string;
659
- category: string;
660
- inputSchema: string;
661
- outputSchema: string;
662
- timeout: number;
663
- retryCount: number;
664
- retryDelay: number;
665
- version: string;
666
- totalCalls: number;
667
- avgDurationMs: number;
668
- successRate: number;
669
- isEnabled: boolean;
670
- securityLevel: string;
671
- securityScore: number;
672
- scope: string;
673
- status: string;
674
- downloadCount: number;
675
- readme: string;
676
- tags: string[];
677
- author: string;
678
- publisherId: string;
679
- isPublished: boolean;
680
- pluginName: string;
681
- pluginIcon: string;
682
- updatedAt: string;
683
- visibility?: string;
684
- certificationStatus?: string;
685
- source?: string;
686
- }
687
- /** 技能商店搜索参数 (非 wire 类型, 用于 client 方法参数) */
688
- interface SkillStoreQuery {
689
- category?: string;
690
- keyword?: string;
691
- tag?: string;
692
- }
693
- /** 技能统计概览 */
694
- interface SkillSummary {
695
- installed: number;
696
- created: number;
697
- total: number;
698
- storeAvailable: number;
699
- }
700
- /** 技能商店分页浏览响应 */
701
- interface SkillBrowseResponse {
702
- items: SkillStoreItem[];
703
- total: number;
704
- page: number;
705
- pageSize: number;
706
- }
707
- /**
708
- * 技能商店列表项(轻量,仅含浏览所需字段)
709
- * 配合服务端 fields=minimal 参数使用,响应体积缩减 90%+
710
- */
711
- interface SkillStoreListItem {
712
- id: string;
713
- key: string;
714
- name: string;
715
- description: string;
716
- icon: string;
717
- category: string;
718
- version: string;
719
- author: string;
720
- downloadCount: number;
721
- tags: string[];
722
- certificationStatus?: string;
723
- visibility?: string;
724
- source?: string;
725
- updatedAt: string;
726
- }
727
- /** 技能商店轻量浏览响应 */
728
- interface SkillBrowseListResponse {
729
- items: SkillStoreListItem[];
730
- total: number;
731
- page: number;
732
- pageSize: number;
733
- }
734
- /** 技能认证状态响应 */
735
- interface CertificationStatus {
736
- skillId: string;
737
- certificationStatus: string;
738
- certifiedAt?: number;
739
- securityLevel?: string;
740
- securityScore: number;
741
- report?: unknown;
742
- }
743
- interface GenerateSkillRequest {
744
- purpose: string;
745
- examples?: string[];
746
- inputHints?: string;
747
- outputHints?: string;
748
- category?: string;
749
- language?: string;
750
- }
751
- interface GenerateSkillResult {
752
- skillName: string;
753
- skillKey: string;
754
- description: string;
755
- skillMd: string;
756
- inputSchema: string;
757
- outputSchema: string;
758
- testCases: string[];
759
- readme: string;
760
- category: string;
761
- tags: string[];
762
- timeout: number;
763
- }
764
- interface OptimizeSkillRequest {
765
- skillName: string;
766
- description?: string;
767
- inputSchema?: string;
768
- outputSchema?: string;
769
- readme?: string;
770
- aspects?: string[];
771
- }
772
- interface OptimizeSkillResult {
773
- optimizedSkill: GenerateSkillResult;
774
- changes: string[];
775
- score: number;
776
- }
777
- interface ToolView {
778
- id: string;
779
- key: string;
780
- name: string;
781
- description: string;
782
- icon: string;
783
- category: string;
784
- inputSchema: string;
785
- outputSchema: string;
786
- timeout: number;
787
- isEnabled: boolean;
788
- provider?: ToolProvider;
789
- }
790
- interface ToolProvider {
791
- id: string;
792
- name: string;
793
- icon: string;
794
- sourceType: string;
795
- mcpEndpoint?: string;
796
- isEnabled: boolean;
797
- }
798
- interface ToolListResponse {
799
- skills: ToolView[];
800
- total: number;
801
- }
802
- /** 下载限流错误 (429) */
803
- declare class RateLimitError extends Error {
804
- retryAfter: string;
805
- raw: string;
806
- constructor(message: string, retryAfter: string, raw: string);
807
- }
808
- /**
809
- * API 业务层错误 (HTTP 200 但 code != 0)
810
- * tk-dist 代理透传 yudao 响应, HTTP 状态码为 200, 业务错误在 JSON code 字段
811
- */
812
- declare class BusinessError extends Error {
813
- code: number;
814
- constructor(code: number, message: string);
815
- }
816
- /**
817
- * 订单到达非成功终态 (FAILED/CANCELLED/CLOSED/EXPIRED/REFUNDED)
818
- * waitForPayment 在订单终态为非成功时抛此错误
819
- */
820
- declare class OrderTerminalError extends Error {
821
- orderId: string;
822
- status: string;
823
- constructor(orderId: string, status: string);
824
- }
825
- /**
826
- * 模型缓存未命中且 listModels 刷新后仍未找到。
827
- *
828
- * 历史上 getCachedModel miss 时硬返 ManagedModel{provider:"anthropic"} 占位,
829
- * 导致未预热场景下的 chat 请求按 AnthropicAdapter 编码, 被发到错误端点。
830
- * v0.13.x 改为 miss → listModels 自动刷新一次; 仍 miss → 抛此错误。
831
- */
832
- declare class ModelNotFoundError extends Error {
833
- modelId: string;
834
- constructor(modelId: string);
835
- }
836
- /**
837
- * 结构化 HTTP 非 2xx 错误.
838
- *
839
- * 用 instanceof 提取:
840
- * try { ... } catch (e) {
841
- * if (e instanceof HTTPError && e.statusCode === 429) { ... }
842
- * }
843
- */
844
- declare class HTTPError extends Error {
845
- statusCode: number;
846
- /** anthropic.error.type / openai.error.type, 缺失为空 */
847
- type: string;
848
- /** Retry-After 头解析的秒数, 0 表示未提供或解析失败 */
849
- retryAfter: number;
850
- /** 原始响应体 (截断到 maxErrorBodySize) */
851
- body: string;
852
- constructor(statusCode: number, opts?: {
853
- type?: string;
854
- message?: string;
855
- retryAfter?: number;
856
- body?: string;
857
- });
858
- }
859
- /**
860
- * 结构化网络层错误 (传输失败, 区别于上游业务错误).
861
- *
862
- * 包装 fetch 抛出的错误 — 含 timeout / EOF / connection refused / DNS 失败等.
863
- * retry policy: isTimeout / isEOF 任一为 true → 默认可重试.
864
- */
865
- declare class NetworkError extends Error {
866
- /** 操作描述, e.g. "POST /v1/messages" */
867
- op: string;
868
- /** 请求 URL (脱敏后) */
869
- url: string;
870
- cause?: unknown;
871
- timeout: boolean;
872
- eof: boolean;
873
- constructor(op: string, url: string, cause: unknown, opts?: {
874
- timeout?: boolean;
875
- eof?: boolean;
876
- });
877
- isTimeout(): boolean;
878
- isEOF(): boolean;
879
- }
880
- /**
881
- * 流式失败事件的结构化表示。
882
- *
883
- * 由 gateway 的 `managed_model_stream_failed` 事件解析得到。客户端可通过
884
- * instanceof 提取并按 code/retryable 决策。
885
- */
886
- declare class StreamError extends Error {
887
- /** 例: "empty_response" / "rate_limit" / "overloaded" / "" */
888
- code: string;
889
- /** 例: "provider" / "settlement" */
890
- stage: string;
891
- /** 用户友好提示 (中文); 历史字段, 与 rawError 区分 */
892
- userMessage: string;
893
- /** gateway 原始 error 字符串 */
894
- rawError: string;
895
- /** 客户端是否值得重试 */
896
- retryable: boolean;
897
- constructor(opts?: {
898
- code?: string;
899
- stage?: string;
900
- message?: string;
901
- rawError?: string;
902
- retryable?: boolean;
903
- });
904
- }
905
- /** nexus-v4 标准响应。兼容 yudao 格式 (msg) 和 nexus-v4 格式 (message) */
906
- interface APIResponse<T> {
907
- code: number;
908
- message?: string;
909
- msg?: string;
910
- data: T;
911
- }
912
- /** 优先返回 message, 降级到 msg (兼容 yudao 透传) */
913
- declare function apiResponseGetMessage<T>(r: APIResponse<T>): string;
914
- /** 检查业务层错误码 — code != 0 时抛 BusinessError */
915
- declare function apiResponseBusinessError<T>(r: APIResponse<T>): BusinessError | null;
916
- /** yudao 分页响应格式 (tk-dist 代理透传) */
917
- interface YudaoPageResult<T> {
918
- list: T[];
919
- total: number;
920
- }
921
- /** 单条通知 */
922
- interface Notification {
923
- id: string;
924
- title: string;
925
- content: string;
926
- /** system | billing | security | task | commission | entitlement */
927
- type: string;
928
- isRead: boolean;
929
- createdAt: string;
930
- }
931
- /** 分页通知列表 */
932
- interface NotificationList {
933
- list: Notification[];
934
- unreadCount: number;
935
- total: number;
936
- page: number;
937
- pageSize: number;
938
- }
939
- /** 未读通知计数 */
940
- interface NotificationUnreadCount {
941
- unreadCount: number;
942
- }
943
- /** 通知偏好 (按类型+渠道) */
944
- interface NotificationPreference {
945
- typeCode: string;
946
- channelInApp: boolean;
947
- channelEmail: boolean;
948
- channelSms: boolean;
949
- channelPush: boolean;
950
- }
951
- /** 推送设备注册 */
952
- interface DeviceRegistration {
953
- /** android | ios | harmony */
954
- platform: string;
955
- token: string;
956
- appVersion: string;
957
- }
958
- /** 服务端推送事件 */
959
- interface WSEvent {
960
- type: string;
961
- topic?: string;
962
- /** json.RawMessage in Go */
963
- data?: unknown;
964
- connId?: string;
965
- timestamp?: string;
966
- message?: string;
967
- }
968
- /**
969
- * 从 WSEvent 中解析通知
970
- * 返回 null 表示该事件不是系统通知
971
- */
972
- declare function parseNotificationEvent(ev: WSEvent): Notification | null;
973
-
974
- /** 标识请求格式 */
975
- declare enum ProviderFormat {
976
- /** Anthropic 原生格式 */
977
- Anthropic = 0,
978
- /** OpenAI 兼容格式 */
979
- OpenAI = 1
980
- }
981
- /** 将 ChatRequest 转换为特定格式的 adapter 接口 */
982
- interface ProviderAdapter {
983
- /** 此 adapter 使用的请求格式 */
984
- format(): ProviderFormat;
985
- /**
986
- * API 路径后缀
987
- * Anthropic: "/anthropic", OpenAI: "/chat"
988
- */
989
- endpointSuffix(): string;
990
- /**
991
- * 将 ChatRequest 转换为 HTTP body (object → JSON.stringify)
992
- * caps 用于条件化字段注入 (如 betas)
993
- */
994
- buildRequestBody(caps: ModelCapabilities, req: ChatRequest): Record<string, unknown>;
995
- /** 解析同步响应 body 为 ChatResponse */
996
- parseResponse(body: Uint8Array | string): ChatResponse;
997
- /**
998
- * 解析一行 SSE data 为 StreamEvent
999
- * 返回 { event, done }; done=true 表示流结束 ([DONE] 或 message_stop)
1000
- */
1001
- parseStreamLine(eventType: string, data: string): {
1002
- event: StreamEvent;
1003
- done: boolean;
1004
- };
1005
- }
1006
-
1007
- /**
1008
- * 根据 provider 返回对应的 adapter (v0.5.0 遗留 API, 向后兼容)
1009
- * 新代码应使用 getAdapterForModel
1010
- */
1011
- declare function getAdapter(provider: string): ProviderAdapter;
1012
- /**
1013
- * 按 ManagedModel 的 preferred_format / supported_formats 选择 adapter
1014
- *
1015
- * 决策顺序:
1016
- * 1. preferred_format 非空 → 按其值返回 (anthropic | openai)
1017
- * 2. supported_formats 含 "anthropic" → AnthropicAdapter
1018
- * 3. supported_formats 含 "openai" → OpenAIAdapter
1019
- * 4. 两字段均空 (旧上游) → 回落 provider 名硬编码 (原 getAdapter 行为)
1020
- *
1021
- * 这使得 dashscope / zhipu / deepseek 等 provider 的模型如果上游启用了
1022
- * Anthropic 兼容端点, 也能走 /anthropic 路径, 不再被 provider 字符串硬编码到 /chat
1023
- * 导致 tool_reference 400.
1024
- */
1025
- declare function getAdapterForModel(m: ManagedModel): ProviderAdapter;
1026
-
1027
- export { type ChatUsage as $, type AnthropicResponse as A, BusinessError as B, type ClientRegistration as C, type ToolView as D, type EntitlementBalance as E, type DeviceRegistration as F, type GenerateSkillRequest as G, type NotificationPreference as H, type InputModality as I, type WSEvent as J, type APIResponse as K, type AnthropicContentBlock as L, type ManagedModel as M, type NotificationList as N, type Order as O, type ProviderAdapter as P, type QuotaSummary as Q, type AnthropicUsage as R, type ServerMetadata as S, type TokenSet as T, BucketClassCommercial as U, BucketClassGeneric as V, type WalletStats as W, type BucketInfo as X, type BucketRow as Y, type ChatContentBlock as Z, type ChatMessage as _, type TokenResponse as a, type ConsumeRecord as a0, type EffortConfig as a1, type GeoLoc as a2, HTTPError as a3, ModelNotFoundError as a4, NetworkError as a5, type Notification as a6, type NotificationUnreadCount as a7, type OpenAIChatChoice as a8, type OpenAIChatMessage as a9, type YudaoPageResult as aA, anthropicResponseTextContent as aB, anthropicResponseThinkingContent as aC, anthropicResponseToolUseBlocks as aD, apiResponseBusinessError as aE, apiResponseGetMessage as aF, bucketInfoIsCommercial as aG, bucketRowIsCommercial as aH, getAdapter as aI, getAdapterForModel as aJ, newThinkingConfig as aK, newWebSearchTool as aL, parseNotificationEvent as aM, parseSettlement as aN, parseSourcesEvent as aO, tokenSetIsExpired as aP, type OpenAIChatResponse as aa, type OpenAIFunctionCall as ab, type OpenAIStreamChoice as ac, type OpenAIStreamChunk as ad, type OpenAIStreamDelta as ae, type OpenAIStreamToolCall as af, type OpenAIToolCall as ag, type OpenAIUsage as ah, OrderTerminalError as ai, type OutputConfig as aj, ProviderFormat as ak, RateLimitError as al, type ServerTool as am, ServerToolTypeWebSearch as an, type SkillStoreListItem as ao, StreamError as ap, type ThinkingConfig as aq, ThinkingHigh as ar, ThinkingHighMinMaxTokens as as, ThinkingMax as at, ThinkingMaxFallbackMaxTokens as au, ThinkingOff as av, type ToolListResponse as aw, type ToolProvider as ax, type WebSearchConfig as ay, type WebSearchSource as az, type ModelCoefficient as b, type ModelCapabilities as c, type ChatRequest as d, type ChatResponse as e, type StreamEvent as f, type SourcesEvent as g, type StreamSettlement as h, type BalanceDetail as i, type EntitlementItem as j, type ConsumeRecordPage as k, type ModelByQuotaResponse as l, type ModelBucket as m, type TokenPackage as n, type PayPayload as o, type OrderStatus as p, type Transaction as q, type SkillStoreQuery as r, type SkillStoreItem as s, type SkillBrowseResponse as t, type SkillBrowseListResponse as u, type SkillSummary as v, type CertificationStatus as w, type GenerateSkillResult as x, type OptimizeSkillRequest as y, type OptimizeSkillResult as z };