@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.
- package/CHANGELOG.md +28 -0
- package/README.md +8 -3
- package/dist/browser/index.mjs +1920 -1898
- package/dist/browser/index.mjs.map +1 -1
- package/dist/index.mjs +1920 -1898
- package/dist/index.mjs.map +1 -1
- package/dist/node/adapters/anthropic.cjs +6 -4
- package/dist/node/adapters/anthropic.cjs.map +1 -1
- package/dist/node/adapters/anthropic.d.cts +1 -1
- package/dist/node/adapters/anthropic.d.ts +1 -1
- package/dist/node/adapters/anthropic.mjs +6 -4
- package/dist/node/adapters/anthropic.mjs.map +1 -1
- package/dist/node/adapters/openai.cjs +4 -2
- package/dist/node/adapters/openai.cjs.map +1 -1
- package/dist/node/adapters/openai.d.cts +2 -64
- package/dist/node/adapters/openai.d.ts +2 -64
- package/dist/node/adapters/openai.mjs +4 -2
- package/dist/node/adapters/openai.mjs.map +1 -1
- package/dist/node/index-DEA6LXw6.d.cts +409 -0
- package/dist/node/index-DEA6LXw6.d.ts +409 -0
- package/dist/node/index.cjs +1920 -1898
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +1439 -866
- package/dist/node/index.d.ts +1439 -866
- package/dist/node/index.mjs +1920 -1898
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/openai-BDodfhsG.d.cts +125 -0
- package/dist/node/openai-vfUUgdvL.d.ts +125 -0
- package/examples/agent-runs-stream.ts +118 -0
- package/examples/auth-oauth-flow.ts +97 -0
- package/examples/core-chat.ts +85 -0
- package/package.json +5 -2
- package/dist/node/index-CbG9NqE-.d.cts +0 -1027
- package/dist/node/index-CbG9NqE-.d.ts +0 -1027
package/dist/node/index.d.cts
CHANGED
|
@@ -1,52 +1,188 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { A as AnthropicResponse } from './openai-BDodfhsG.cjs';
|
|
2
|
+
export { a as AnthropicContentBlock, b as AnthropicUsage, O as OpenAIAdapter, c as anthropicResponseTextContent, d as anthropicResponseThinkingContent, e as anthropicResponseToolUseBlocks } from './openai-BDodfhsG.cjs';
|
|
3
|
+
import { M as ManagedModel, Q as QuotaSummary, a as ModelCapabilities, C as ChatRequest, P as ProviderAdapter, b as ChatResponse, S as StreamEvent, c as SourcesEvent, d as StreamSettlement, I as InputModality } from './index-DEA6LXw6.cjs';
|
|
4
|
+
export { B as BucketClassCommercial, e as BucketClassGeneric, f as BucketInfo, g as BucketRow, h as ChatContentBlock, i as ChatMessage, j as ChatUsage, E as EffortConfig, G as GeoLoc, O as OutputConfig, k as ProviderFormat, l as ServerTool, m as ServerToolTypeWebSearch, T as ThinkingConfig, n as ThinkingHigh, o as ThinkingHighMinMaxTokens, p as ThinkingMax, q as ThinkingMaxFallbackMaxTokens, r as ThinkingOff, W as WebSearchConfig, s as WebSearchSource, t as bucketInfoIsCommercial, u as bucketRowIsCommercial, v as getAdapter, w as getAdapterForModel, x as newThinkingConfig, y as newWebSearchTool, z as parseSettlement, A as parseSourcesEvent } from './index-DEA6LXw6.cjs';
|
|
3
5
|
import { M as MinimalSanitizeConfig } from './index-nvLKgCm9.cjs';
|
|
4
6
|
export { i as sanitize } from './index-nvLKgCm9.cjs';
|
|
5
7
|
export { AnthropicAdapter } from './adapters/anthropic.cjs';
|
|
6
|
-
export { OpenAIAdapter } from './adapters/openai.cjs';
|
|
7
8
|
|
|
9
|
+
/** 权益余额 (聚合) */
|
|
10
|
+
interface EntitlementBalance {
|
|
11
|
+
totalTokenQuota: number;
|
|
12
|
+
totalTokenUsed: number;
|
|
13
|
+
totalTokenRemaining: number;
|
|
14
|
+
totalCallQuota: number;
|
|
15
|
+
totalCallUsed: number;
|
|
16
|
+
totalCallRemaining: number;
|
|
17
|
+
activeEntitlements: number;
|
|
18
|
+
}
|
|
19
|
+
/** 单条权益明细 */
|
|
20
|
+
interface EntitlementItem {
|
|
21
|
+
id: string;
|
|
22
|
+
type: string;
|
|
23
|
+
status: string;
|
|
24
|
+
tokenQuota: number;
|
|
25
|
+
tokenUsed: number;
|
|
26
|
+
tokenRemaining: number;
|
|
27
|
+
callQuota: number;
|
|
28
|
+
callUsed: number;
|
|
29
|
+
callRemaining: number;
|
|
30
|
+
expiresAt?: string;
|
|
31
|
+
sourceId?: string;
|
|
32
|
+
sourceType?: string;
|
|
33
|
+
remark?: string;
|
|
34
|
+
createdAt: string;
|
|
35
|
+
}
|
|
36
|
+
/** 详细余额 (含每条权益明细) */
|
|
37
|
+
interface BalanceDetail {
|
|
38
|
+
totalTokenQuota: number;
|
|
39
|
+
totalTokenUsed: number;
|
|
40
|
+
totalTokenRemaining: number;
|
|
41
|
+
totalCallQuota: number;
|
|
42
|
+
totalCallUsed: number;
|
|
43
|
+
totalCallRemaining: number;
|
|
44
|
+
activeEntitlements: number;
|
|
45
|
+
entitlements: EntitlementItem[];
|
|
46
|
+
}
|
|
47
|
+
/** 核销记录 */
|
|
48
|
+
interface ConsumeRecord {
|
|
49
|
+
id: string;
|
|
50
|
+
entitlementId: string;
|
|
51
|
+
requestId: string;
|
|
52
|
+
modelId?: string;
|
|
53
|
+
tokensConsumed: number;
|
|
54
|
+
status: string;
|
|
55
|
+
createdAt: string;
|
|
56
|
+
}
|
|
57
|
+
/** 核销记录分页响应 */
|
|
58
|
+
interface ConsumeRecordPage {
|
|
59
|
+
records: ConsumeRecord[];
|
|
60
|
+
total: number;
|
|
61
|
+
page: number;
|
|
62
|
+
pageSize: number;
|
|
63
|
+
}
|
|
8
64
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* 语义:
|
|
12
|
-
* - model 为 null/undefined → false
|
|
13
|
-
* - model.inputModalities 缺失或非数组 → false (保守, 未声明不当支持)
|
|
14
|
-
* - 大小写敏感 (上游契约即小写 'text' | 'image')
|
|
15
|
-
*/
|
|
16
|
-
declare function modelSupportsInputModality(model: ManagedModel | null | undefined, modality: InputModality): boolean;
|
|
17
|
-
/** 等价 modelSupportsInputModality(model, 'image') — 调用方常见快捷判定. */
|
|
18
|
-
declare function modelSupportsImageInput(model: ManagedModel | null | undefined): boolean;
|
|
19
|
-
/**
|
|
20
|
-
* 在 catalog 中按 catalog 顺序查找首个支持指定模态的模型.
|
|
21
|
-
*
|
|
22
|
-
* 选择规则:
|
|
23
|
-
* 1. isEnabled !== false (默认开, 显式 false 才剔除)
|
|
24
|
-
* 2. inputModalities 包含指定模态
|
|
25
|
-
* 3. 命中后按 catalog 顺序返回第一个; 未命中返 null
|
|
26
|
-
*
|
|
27
|
-
* 注意: 该 helper 不读 isDefault, 调用方需要 "默认优先" 请用
|
|
28
|
-
* findDesktopVisualUnderstandingModel 或自行排序.
|
|
29
|
-
*/
|
|
30
|
-
declare function findFirstModelByInputModality(models: ManagedModel[], modality: InputModality): ManagedModel | null;
|
|
31
|
-
/**
|
|
32
|
-
* 在 catalog 中选出最适合做 "桌面视觉理解 sidecar" 的模型.
|
|
33
|
-
*
|
|
34
|
-
* 设计目的: CrabCode desktop automation 链路里, 主模型不一定多模态;
|
|
35
|
-
* 截图先送 sidecar 解析成结构化 UI 描述, 再喂主模型. 这里选 sidecar 模型
|
|
36
|
-
* 严格走运营标注的 supports_desktop_visual_understanding capability, 不靠
|
|
37
|
-
* 模型名猜.
|
|
38
|
-
*
|
|
39
|
-
* 选择规则 (按用户指定顺序):
|
|
40
|
-
* 1. isEnabled !== false
|
|
41
|
-
* 2. capabilities.supports_desktop_visual_understanding === true
|
|
42
|
-
* 3. inputModalities 包含 'image' (必须真能吃图)
|
|
43
|
-
* 4. 命中集合中优先 isDefault === true; 否则返回 catalog 顺序第一个
|
|
65
|
+
* 单桶视图 (用户多桶 hero / 模型切换提示用)
|
|
44
66
|
*
|
|
45
|
-
*
|
|
46
|
-
* - 提示用户在管理后台/网关侧开启桌面视觉 sidecar 模型, 或
|
|
47
|
-
* - 降级停掉依赖截图的工作流, 而不是硬选一个非视觉模型送图.
|
|
67
|
+
* 字段名仍叫 ETU 但 T3 死代码清除后 = raw token (V29 系数管理已退役)。
|
|
48
68
|
*/
|
|
49
|
-
|
|
69
|
+
interface ModelBucket {
|
|
70
|
+
bucketId: string;
|
|
71
|
+
entitlementId: string;
|
|
72
|
+
/** "*" = 通配 */
|
|
73
|
+
modelId: string;
|
|
74
|
+
/** COMMERCIAL / GENERIC */
|
|
75
|
+
bucketClass: string;
|
|
76
|
+
tokenQuota: number;
|
|
77
|
+
tokenUsed: number;
|
|
78
|
+
tokenRemaining: number;
|
|
79
|
+
callQuota: number;
|
|
80
|
+
callUsed: number;
|
|
81
|
+
callRemaining: number;
|
|
82
|
+
allowedModelsJson?: string;
|
|
83
|
+
}
|
|
84
|
+
/** GetByModel 响应; primaryBucket 在 bucketId 为空时表示无可用桶。 */
|
|
85
|
+
interface ModelByQuotaResponse {
|
|
86
|
+
modelId: string;
|
|
87
|
+
/** 折算后剩余 (调度判定用) */
|
|
88
|
+
etuRemaining: number;
|
|
89
|
+
/** 反系数估算的原始 token (UI 展示用) */
|
|
90
|
+
rawTokenRemaining: number;
|
|
91
|
+
hasQuota: boolean;
|
|
92
|
+
primaryBucket?: ModelBucket;
|
|
93
|
+
}
|
|
94
|
+
/** 单条模型系数 (SDK TTL 8s 缓存源) */
|
|
95
|
+
interface ModelCoefficient {
|
|
96
|
+
modelId: string;
|
|
97
|
+
tenantId: string;
|
|
98
|
+
inputCoef: number;
|
|
99
|
+
outputCoef: number;
|
|
100
|
+
cacheReadCoef: number;
|
|
101
|
+
cacheCreationCoef: number;
|
|
102
|
+
version: number;
|
|
103
|
+
effectiveAt: string;
|
|
104
|
+
}
|
|
105
|
+
/** 流量包商品。price 用 string (Go json.Number) 避免浮点精度丢失。 */
|
|
106
|
+
interface TokenPackage {
|
|
107
|
+
id: string;
|
|
108
|
+
name: string;
|
|
109
|
+
description?: string;
|
|
110
|
+
tokenQuota: number;
|
|
111
|
+
callQuota?: number;
|
|
112
|
+
price: string;
|
|
113
|
+
validDays: number;
|
|
114
|
+
isEnabled: boolean;
|
|
115
|
+
sortOrder?: number;
|
|
116
|
+
}
|
|
117
|
+
/** 订单。amount 用 string (Go json.Number) 避免精度丢失。 */
|
|
118
|
+
interface Order {
|
|
119
|
+
id: string;
|
|
120
|
+
packageId: string;
|
|
121
|
+
packageName?: string;
|
|
122
|
+
amount: string;
|
|
123
|
+
status: string;
|
|
124
|
+
payUrl?: string;
|
|
125
|
+
createdAt: string;
|
|
126
|
+
}
|
|
127
|
+
/** 订单状态 */
|
|
128
|
+
interface OrderStatus {
|
|
129
|
+
orderId: string;
|
|
130
|
+
status: string;
|
|
131
|
+
}
|
|
132
|
+
/** 下单请求 */
|
|
133
|
+
interface PayPayload {
|
|
134
|
+
payMethod?: string;
|
|
135
|
+
}
|
|
136
|
+
/** 钱包统计。金额使用 string (Go json.Number) 避免浮点精度丢失 (金融安全) */
|
|
137
|
+
interface WalletStats {
|
|
138
|
+
balance: string;
|
|
139
|
+
monthlyConsumption: string;
|
|
140
|
+
monthlyRecharge: string;
|
|
141
|
+
transactionCount: number;
|
|
142
|
+
}
|
|
143
|
+
/** 交易记录 */
|
|
144
|
+
interface Transaction {
|
|
145
|
+
id: string;
|
|
146
|
+
type: string;
|
|
147
|
+
amount: string;
|
|
148
|
+
remark?: string;
|
|
149
|
+
createdAt: string;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** OAuth Authorization Server 元数据 (RFC 8414) */
|
|
153
|
+
interface ServerMetadata {
|
|
154
|
+
issuer: string;
|
|
155
|
+
authorization_endpoint: string;
|
|
156
|
+
token_endpoint: string;
|
|
157
|
+
revocation_endpoint: string;
|
|
158
|
+
registration_endpoint: string;
|
|
159
|
+
scopes_supported: string[];
|
|
160
|
+
}
|
|
161
|
+
/** OAuth token 响应 */
|
|
162
|
+
interface TokenResponse {
|
|
163
|
+
access_token: string;
|
|
164
|
+
token_type: string;
|
|
165
|
+
expires_in: number;
|
|
166
|
+
refresh_token?: string;
|
|
167
|
+
scope?: string;
|
|
168
|
+
}
|
|
169
|
+
/** 持久化 token 对 */
|
|
170
|
+
interface TokenSet {
|
|
171
|
+
access_token: string;
|
|
172
|
+
refresh_token: string;
|
|
173
|
+
/** ISO 8601 格式 */
|
|
174
|
+
expires_at: string;
|
|
175
|
+
scope: string;
|
|
176
|
+
client_id: string;
|
|
177
|
+
server_url: string;
|
|
178
|
+
}
|
|
179
|
+
/** token 是否已过期 (提前 30 秒视为过期) */
|
|
180
|
+
declare function tokenSetIsExpired(t: TokenSet): boolean;
|
|
181
|
+
/** 动态注册响应 */
|
|
182
|
+
interface ClientRegistration {
|
|
183
|
+
client_id: string;
|
|
184
|
+
client_secret?: string;
|
|
185
|
+
}
|
|
50
186
|
|
|
51
187
|
/** OAuth metadata profile — 决定 well-known 端点的路径后缀 */
|
|
52
188
|
type OAuthMetadataProfile = 'web' | 'desktop';
|
|
@@ -245,489 +381,106 @@ declare function revokeToken(meta: ServerMetadata, token: string, signal?: Abort
|
|
|
245
381
|
*/
|
|
246
382
|
declare function newTokenSet(resp: TokenResponse, clientID: string, serverURL: string): TokenSet;
|
|
247
383
|
|
|
248
|
-
declare const ScopeAI = "ai";
|
|
249
|
-
declare const ScopeSkills = "skills";
|
|
250
|
-
declare const ScopeAccount = "account";
|
|
251
|
-
/** @deprecated 旧细粒度 scope, 保留向后兼容, 新代码请用分组 scope */
|
|
252
|
-
declare const ScopeModels = "models";
|
|
253
|
-
/** @deprecated */
|
|
254
|
-
declare const ScopeModelsChat = "models:chat";
|
|
255
|
-
/** @deprecated */
|
|
256
|
-
declare const ScopeEntitlements = "entitlements";
|
|
257
|
-
/** @deprecated */
|
|
258
|
-
declare const ScopeTokenPackages = "token-packages";
|
|
259
|
-
/** @deprecated */
|
|
260
|
-
declare const ScopeSkillStore = "skill_store";
|
|
261
|
-
/** @deprecated */
|
|
262
|
-
declare const ScopeTools = "tools";
|
|
263
|
-
/** @deprecated */
|
|
264
|
-
declare const ScopeToolsExecute = "tools:execute";
|
|
265
|
-
/** @deprecated */
|
|
266
|
-
declare const ScopeWallet = "wallet";
|
|
267
|
-
/** @deprecated */
|
|
268
|
-
declare const ScopeWalletReadonly = "wallet:readonly";
|
|
269
|
-
/** @deprecated */
|
|
270
|
-
declare const ScopeProfile = "profile";
|
|
271
|
-
declare const ScopeComplianceEvidenceRead = "compliance:evidence:read";
|
|
272
|
-
declare const ScopeComplianceEvidenceWrite = "compliance:evidence:write";
|
|
273
|
-
declare const ScopeComplianceTimestampIssue = "compliance:timestamp:issue";
|
|
274
|
-
declare const ScopeComplianceTimestampVerify = "compliance:timestamp:verify";
|
|
275
|
-
declare const ScopeComplianceContractSigningRead = "compliance:contract_signing:read";
|
|
276
|
-
declare const ScopeComplianceContractSigningWrite = "compliance:contract_signing:write";
|
|
277
|
-
declare const ScopeComplianceSealManage = "compliance:seal:manage";
|
|
278
|
-
declare const ScopeComplianceSealApprovalRequest = "compliance:seal_approval:request";
|
|
279
|
-
declare const ScopeComplianceSealApprovalApprove = "compliance:seal_approval:approve";
|
|
280
|
-
declare const ScopeComplianceSealUseExecute = "compliance:seal_use:execute";
|
|
281
|
-
declare const ScopeComplianceReportsRead = "compliance:reports:read";
|
|
282
|
-
declare const ScopeComplianceReportsWrite = "compliance:reports:write";
|
|
283
|
-
declare const ScopeComplianceReportsPublish = "compliance:reports:publish";
|
|
284
|
-
/** 类型联合:合规域细粒度 scope。Java compliance verifier 只按细粒度匹配, 不做分组展开。 */
|
|
285
|
-
type ComplianceScope = typeof ScopeComplianceEvidenceRead | typeof ScopeComplianceEvidenceWrite | typeof ScopeComplianceTimestampIssue | typeof ScopeComplianceTimestampVerify | typeof ScopeComplianceContractSigningRead | typeof ScopeComplianceContractSigningWrite | typeof ScopeComplianceSealManage | typeof ScopeComplianceSealApprovalRequest | typeof ScopeComplianceSealApprovalApprove | typeof ScopeComplianceSealUseExecute | typeof ScopeComplianceReportsRead | typeof ScopeComplianceReportsWrite | typeof ScopeComplianceReportsPublish;
|
|
286
|
-
/** 全部分组 scope (推荐) */
|
|
287
|
-
declare function allScopes(): string[];
|
|
288
|
-
/** 全部合规域 scope。OAuth 申请合规权限时使用; 谨慎一次性申请全部, 推荐按业务最小集合申请。 */
|
|
289
|
-
declare function complianceScopes(): ComplianceScope[];
|
|
290
|
-
/** 模型服务相关 scope */
|
|
291
|
-
declare function modelScopes(): string[];
|
|
292
|
-
/** 商城/钱包 scope */
|
|
293
|
-
declare function commerceScopes(): string[];
|
|
294
|
-
/** 技能/工具 scope */
|
|
295
|
-
declare function skillScopes(): string[];
|
|
296
|
-
|
|
297
384
|
/**
|
|
298
|
-
*
|
|
385
|
+
* Token 持久化接口
|
|
386
|
+
* 桌面智能体可自行实现 (如 macOS Keychain / Windows Credential Manager)
|
|
299
387
|
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
388
|
+
* 跨端约定:
|
|
389
|
+
* - Save: 写入持久化, 失败抛 Error
|
|
390
|
+
* - Load: 读取, 不存在返回 null (与 Go IsNotExist 行为一致)
|
|
391
|
+
* - Clear: 删除, 不存在不抛错 (Logout 后 Clear 不应报错, [RC-11])
|
|
392
|
+
* - withLock (v1.0.2 新增, 可选): 跨进程临界区. Client 在 refresh token rotation
|
|
393
|
+
* 场景下用此包裹 "load → check → refresh → save" 整段, 防多进程共享同一 store
|
|
394
|
+
* (典型: FileTokenStore 默认 ~/.acosmi/tokens.json) 撞 HTTP 400 refresh token
|
|
395
|
+
* not found. 不实现时 Client 自动回退到仅进程内串行 (LocalStorage / InMemory
|
|
396
|
+
* 单进程语义无需此方法).
|
|
302
397
|
*/
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
398
|
+
interface TokenStore {
|
|
399
|
+
save(tokens: TokenSet): Promise<void>;
|
|
400
|
+
load(): Promise<TokenSet | null>;
|
|
401
|
+
clear(): Promise<void>;
|
|
402
|
+
withLock?<T>(fn: () => Promise<T>): Promise<T>;
|
|
403
|
+
}
|
|
308
404
|
/**
|
|
309
|
-
*
|
|
310
|
-
*
|
|
405
|
+
* 基于文件的 token 存储 (开发/测试用)
|
|
406
|
+
* 生产环境建议替换为系统钥匙串实现
|
|
407
|
+
*
|
|
408
|
+
* 默认路径: ~/.acosmi/tokens.json
|
|
409
|
+
*
|
|
410
|
+
* 浏览器环境调用 new FileTokenStore() 会抛错 — 浏览器请用 LocalStorageTokenStore 或 InMemoryTokenStore.
|
|
311
411
|
*/
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
declare
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
412
|
+
/** 跨进程文件锁配置 (v1.0.2). 公开常量是为了让 caller / 测试可观察, 不建议生产代码改. */
|
|
413
|
+
declare const fileLockDefaults: {
|
|
414
|
+
/** 获取锁的超时上限 (毫秒). refresh 流程含网络 < 30s, 30s 已远超正常完成时间. */
|
|
415
|
+
readonly acquireTimeoutMs: 30000;
|
|
416
|
+
/** 旧锁判定阈值 (毫秒). 锁文件 mtime 早于此值视为 stale 进程崩溃残留, 自动 break. */
|
|
417
|
+
readonly staleMs: 60000;
|
|
418
|
+
/** 重试间隔基数 (毫秒). 真实间隔 = base + random(0, jitter). */
|
|
419
|
+
readonly retryBaseMs: 30;
|
|
420
|
+
readonly retryJitterMs: 70;
|
|
421
|
+
};
|
|
422
|
+
declare class FileTokenStore implements TokenStore {
|
|
423
|
+
private path;
|
|
424
|
+
/** 进程内串行化 (Promise chain) — 与跨进程 flock 配合, 避免单进程内并发持锁产生死锁式互等. */
|
|
425
|
+
private chain;
|
|
426
|
+
constructor(path?: string);
|
|
427
|
+
private resolvePath;
|
|
428
|
+
/** 进程内串行 (维持 v1.0.1 单进程语义). flock 之外另一层防御: 如果用户自己就是单进程
|
|
429
|
+
* 并发场景, 不必每次都进 flock 旁路文件 IO. */
|
|
430
|
+
private withChain;
|
|
431
|
+
/**
|
|
432
|
+
* 跨进程临界区. 用 sidecar `<path>.lock` 文件 + O_EXCL 创建语义实现互斥:
|
|
433
|
+
* - 创建成功 = 持有锁; 写入 pid+timestamp 便于诊断
|
|
434
|
+
* - 创建失败 (EEXIST) = 别的进程持锁, backoff 重试
|
|
435
|
+
* - 锁文件 mtime > staleMs = 进程崩溃残留, unlink 后重试
|
|
436
|
+
* - acquireTimeoutMs 超时 = 抛错 (caller 应作为 transient error 处理, 上层 retry)
|
|
437
|
+
*
|
|
438
|
+
* 注意: O_EXCL 在 NFS 上不保证原子; FileTokenStore 适用于本地文件系统 (典型用户家目录).
|
|
439
|
+
* 真要跨机共享 token, 应实现自定义 Keychain / 数据库 store, 不要用 FileTokenStore.
|
|
440
|
+
*/
|
|
441
|
+
withLock<T>(fn: () => Promise<T>): Promise<T>;
|
|
442
|
+
/**
|
|
443
|
+
* 写入 token. 流程:
|
|
444
|
+
* 1. mkdir -p (默认路径目录)
|
|
445
|
+
* 2. 写入 `<path>.tmp.<pid>`
|
|
446
|
+
* 3. fsync 后 rename 到正式路径 (POSIX 上 rename(2) 同分区原子, Windows 上 ReplaceFile)
|
|
447
|
+
*
|
|
448
|
+
* 选择 atomic rename 而非直接 writeFile: 多进程并发或本进程崩溃时, 读端永远看到的是
|
|
449
|
+
* 完整的旧/新 JSON, 不会读到截断半文件 (Client.create.store.load 可能在另一进程
|
|
450
|
+
* 写入中间触发, atomic rename 避免它解析失败).
|
|
451
|
+
*/
|
|
452
|
+
save(tokens: TokenSet): Promise<void>;
|
|
453
|
+
load(): Promise<TokenSet | null>;
|
|
454
|
+
clear(): Promise<void>;
|
|
455
|
+
}
|
|
339
456
|
/**
|
|
340
|
-
*
|
|
341
|
-
*
|
|
457
|
+
* 创建文件 token 存储 (与 Go NewFileTokenStore 等价)
|
|
458
|
+
* @param path 自定义路径; 空则使用默认 ~/.acosmi/tokens.json
|
|
342
459
|
*/
|
|
343
|
-
declare function
|
|
460
|
+
declare function newFileTokenStore(path?: string): FileTokenStore;
|
|
344
461
|
/**
|
|
345
|
-
*
|
|
346
|
-
*
|
|
462
|
+
* 基于 LocalStorage 的 token 存储 (浏览器)
|
|
463
|
+
*
|
|
464
|
+
* 仅在浏览器环境可用 (检测 globalThis.localStorage)。
|
|
465
|
+
* 不持久化跨设备同步, 适合单机 SPA 使用。
|
|
347
466
|
*/
|
|
348
|
-
declare
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
hashAlgorithm: ComplianceHashAlgorithm | string;
|
|
366
|
-
/** 资产 hash(hex 字符串)。 */
|
|
367
|
-
contentHash: string;
|
|
368
|
-
canonicalizationProfile?: string | null;
|
|
369
|
-
digestSource: ComplianceDigestSource | string;
|
|
370
|
-
privacyLevel: CompliancePrivacyLevel | string;
|
|
371
|
-
status: string;
|
|
372
|
-
}
|
|
373
|
-
/** 创建证据资产请求;与 Java EvidenceAssetCreateReq 对齐。 */
|
|
374
|
-
interface CreateEvidenceAssetRequest {
|
|
375
|
-
/** AssetTypeEnum.name()。 */
|
|
376
|
-
assetType: ComplianceAssetType | string;
|
|
377
|
-
name: string;
|
|
378
|
-
mimeType?: string;
|
|
379
|
-
/** 'sha256' / 'sha512' / 'sm3'。 */
|
|
380
|
-
hashAlgorithm: ComplianceHashAlgorithm | string;
|
|
381
|
-
/** hex 字符串;hash-only 资产必填。 */
|
|
382
|
-
declaredHash?: string;
|
|
383
|
-
/** CLIENT / COMPLIANCE_SERVICE / PROVIDER。 */
|
|
384
|
-
digestSource?: ComplianceDigestSource | string;
|
|
385
|
-
/** 原文 base64;hash-only 时缺省即可。 */
|
|
386
|
-
contentBase64?: string;
|
|
387
|
-
/** public / private(默认 private)。 */
|
|
388
|
-
privacyLevel?: CompliancePrivacyLevel | string;
|
|
389
|
-
source?: string;
|
|
390
|
-
}
|
|
391
|
-
/** 公开 verify 结果。隐私边界:不暴露 PII / 合同原文 / storage / provider raw。 */
|
|
392
|
-
interface PublicEvidenceVerifyResult {
|
|
393
|
-
evidenceNo: string;
|
|
394
|
-
assetType: string;
|
|
395
|
-
hashAlgorithm: string;
|
|
396
|
-
contentHash: string;
|
|
397
|
-
size?: number | null;
|
|
398
|
-
canonicalizationProfile?: string | null;
|
|
399
|
-
verifiedAt: string;
|
|
400
|
-
packageId?: number | null;
|
|
401
|
-
manifestHash?: string | null;
|
|
402
|
-
packageHash?: string | null;
|
|
403
|
-
manifestOfflineVerify: boolean;
|
|
404
|
-
}
|
|
405
|
-
type ComplianceTimestampVerificationStatus = 'PENDING' | 'VERIFIED' | 'FAILED' | 'LOCAL_VERIFY_FAILED' | 'UNKNOWN' | 'RETRYING';
|
|
406
|
-
/** 时间章 token 对外视图(不含 provider/object/tsa 内部字段)。 */
|
|
407
|
-
interface TimestampToken {
|
|
408
|
-
id: number;
|
|
409
|
-
assetId: number;
|
|
410
|
-
policyOid?: string | null;
|
|
411
|
-
serialNumber?: string | null;
|
|
412
|
-
/** gen_time ISO-8601;UNKNOWN/PENDING 状态可能为 null。 */
|
|
413
|
-
genTime?: string | null;
|
|
414
|
-
accuracy?: string | null;
|
|
415
|
-
verificationStatus: ComplianceTimestampVerificationStatus | string;
|
|
416
|
-
verifiedAt?: string | null;
|
|
417
|
-
verificationError?: string | null;
|
|
418
|
-
}
|
|
419
|
-
/** 申请时间章请求。`provider` 字段已从服务端契约下线;SDK 永远不传。 */
|
|
420
|
-
interface IssueTimestampRequest {
|
|
421
|
-
name?: string;
|
|
422
|
-
mimeType?: string;
|
|
423
|
-
hashAlgorithm: ComplianceHashAlgorithm | string;
|
|
424
|
-
/** 客户端声明 digest(hex);contentBase64 非空时作为校验值。 */
|
|
425
|
-
digest?: string;
|
|
426
|
-
contentBase64?: string;
|
|
427
|
-
}
|
|
428
|
-
/** verify 请求 / 结果。 */
|
|
429
|
-
interface VerifyTimestampRequest {
|
|
430
|
-
tokenId: number;
|
|
431
|
-
}
|
|
432
|
-
interface TimestampVerifyResult {
|
|
433
|
-
passed: boolean;
|
|
434
|
-
reason: string;
|
|
435
|
-
}
|
|
436
|
-
interface EvidencePackage {
|
|
437
|
-
id: number;
|
|
438
|
-
assetId: number;
|
|
439
|
-
timestampTokenId?: number | null;
|
|
440
|
-
chainId: string;
|
|
441
|
-
packageVersion: string;
|
|
442
|
-
hashAlgorithm: string;
|
|
443
|
-
manifestHash: string;
|
|
444
|
-
packageHash: string;
|
|
445
|
-
status: string;
|
|
446
|
-
}
|
|
447
|
-
interface ComplianceReport {
|
|
448
|
-
id: number;
|
|
449
|
-
reportNo: string;
|
|
450
|
-
reportType: string;
|
|
451
|
-
status: string;
|
|
452
|
-
assetId?: number | null;
|
|
453
|
-
packageId?: number | null;
|
|
454
|
-
publicUrlToken?: string | null;
|
|
455
|
-
publishedAt?: string | null;
|
|
456
|
-
bodyHash?: string | null;
|
|
457
|
-
}
|
|
458
|
-
interface CreateReportRequest {
|
|
459
|
-
assetId: number;
|
|
460
|
-
packageId: number;
|
|
461
|
-
}
|
|
462
|
-
/** 离线复核下载 VO;建议调用方持久化作为长期可重复验证依据。 */
|
|
463
|
-
interface ReportDownload {
|
|
464
|
-
id: number;
|
|
465
|
-
reportNo: string;
|
|
466
|
-
reportType: string;
|
|
467
|
-
status: string;
|
|
468
|
-
bodyHash?: string | null;
|
|
469
|
-
publishedAt?: string | null;
|
|
470
|
-
assetEvidenceNo?: string | null;
|
|
471
|
-
assetHashAlgorithm?: string | null;
|
|
472
|
-
assetContentHash?: string | null;
|
|
473
|
-
packageManifestHash?: string | null;
|
|
474
|
-
packageHash?: string | null;
|
|
475
|
-
packageHashAlgorithm?: string | null;
|
|
476
|
-
timestampSerialNumber?: string | null;
|
|
477
|
-
timestampGenTime?: string | null;
|
|
478
|
-
timestampVerificationStatus?: string | null;
|
|
479
|
-
}
|
|
480
|
-
interface SigningEnvelope {
|
|
481
|
-
id: number;
|
|
482
|
-
envelopeNo: string;
|
|
483
|
-
applicantUserId?: string | null;
|
|
484
|
-
status: string;
|
|
485
|
-
primaryContractId?: number | null;
|
|
486
|
-
contractHash?: string | null;
|
|
487
|
-
hashAlgorithm?: string | null;
|
|
488
|
-
billingGroupId?: string | null;
|
|
489
|
-
chainId?: string | null;
|
|
490
|
-
requestId?: string | null;
|
|
491
|
-
pendingReason?: string | null;
|
|
492
|
-
signedAt?: string | null;
|
|
493
|
-
evidenceReadyAt?: string | null;
|
|
494
|
-
committedAt?: string | null;
|
|
495
|
-
}
|
|
496
|
-
/** 创建 envelope 请求;只保留调用方业务字段,内部主体快照和履约通道由后端推导。 */
|
|
497
|
-
interface CreateSigningEnvelopeRequest {
|
|
498
|
-
envelopeNo?: string;
|
|
499
|
-
requestId?: string;
|
|
500
|
-
/** 调用方稳定 idempotency-key(不传则由 Idempotency-Key header 兜底)。 */
|
|
501
|
-
idempotencyKey?: string;
|
|
502
|
-
billingGroupId?: string;
|
|
503
|
-
chainId?: string;
|
|
504
|
-
}
|
|
505
|
-
/** sign 请求;service 默认闸门关闭,SDK 写示例必须处理 ENVELOPE_GATE_CLOSED 错误。 */
|
|
506
|
-
interface SignEnvelopeRequest {
|
|
507
|
-
approvalRequestId?: number;
|
|
508
|
-
contractId?: number;
|
|
509
|
-
contractHash?: string;
|
|
510
|
-
sealId?: number;
|
|
511
|
-
signLocationType?: string;
|
|
512
|
-
signLocationPayload?: string;
|
|
513
|
-
transactorId?: number;
|
|
514
|
-
requestId?: string;
|
|
515
|
-
idempotencyKey?: string;
|
|
516
|
-
}
|
|
517
|
-
/** H5 短链请求。 */
|
|
518
|
-
interface CreateH5SigningUrlRequest extends SignEnvelopeRequest {
|
|
519
|
-
}
|
|
520
|
-
interface SealApproval {
|
|
521
|
-
id: number;
|
|
522
|
-
envelopeId?: number | null;
|
|
523
|
-
contractId?: number | null;
|
|
524
|
-
contractHash?: string | null;
|
|
525
|
-
hashAlgorithm?: string | null;
|
|
526
|
-
sealId?: number | null;
|
|
527
|
-
applicantUserId?: string | null;
|
|
528
|
-
approverUserId?: string | null;
|
|
529
|
-
transactorId?: number | null;
|
|
530
|
-
signLocationType?: string | null;
|
|
531
|
-
signLocationPayload?: string | null;
|
|
532
|
-
reason?: string | null;
|
|
533
|
-
expiresAt?: string | null;
|
|
534
|
-
status: string;
|
|
535
|
-
approvedAt?: string | null;
|
|
536
|
-
rejectedAt?: string | null;
|
|
537
|
-
canceledAt?: string | null;
|
|
538
|
-
}
|
|
539
|
-
/** 提交审批;provider 侧字段由后端归一,SDK 调用方不传。 */
|
|
540
|
-
interface SubmitSealApprovalRequest {
|
|
541
|
-
envelopeId?: number;
|
|
542
|
-
contractId?: number;
|
|
543
|
-
contractHash?: string;
|
|
544
|
-
hashAlgorithm?: string;
|
|
545
|
-
sealId?: number;
|
|
546
|
-
approverUserId?: string;
|
|
547
|
-
transactorId?: number;
|
|
548
|
-
signLocationType?: string;
|
|
549
|
-
signLocationPayload?: string;
|
|
550
|
-
reason?: string;
|
|
551
|
-
}
|
|
552
|
-
interface ApproveSealApprovalQuery {
|
|
553
|
-
expiresAt?: string;
|
|
554
|
-
note?: string;
|
|
555
|
-
}
|
|
556
|
-
interface RejectSealApprovalQuery {
|
|
557
|
-
reason?: string;
|
|
558
|
-
}
|
|
559
|
-
interface CancelSealApprovalQuery {
|
|
560
|
-
reason?: string;
|
|
561
|
-
}
|
|
562
|
-
type ComplianceProviderRequestStatus = 'PENDING' | 'SUCCESS' | 'FAILED' | 'UNKNOWN' | 'RETRYING';
|
|
563
|
-
interface ProviderRequestStatusView {
|
|
564
|
-
id: number;
|
|
565
|
-
status: ComplianceProviderRequestStatus | string;
|
|
566
|
-
/** SUCCESS / FAILED 终态。 */
|
|
567
|
-
terminal: boolean;
|
|
568
|
-
/** 当前状态是否允许 SDK 安全重试请求(仅对 RETRYING 为 true)。 */
|
|
569
|
-
retryable: boolean;
|
|
570
|
-
businessNo?: string | null;
|
|
571
|
-
contractNo?: string | null;
|
|
572
|
-
sealId?: string | null;
|
|
573
|
-
attemptCount?: number | null;
|
|
574
|
-
reconciliationStatus?: string | null;
|
|
575
|
-
nextRetryAt?: string | null;
|
|
576
|
-
requestedAt?: string | null;
|
|
577
|
-
respondedAt?: string | null;
|
|
578
|
-
}
|
|
579
|
-
/** Compliance 写操作选项;写操作不自动 retry,不自动 401 重放。 */
|
|
580
|
-
interface ComplianceWriteOptions {
|
|
581
|
-
/**
|
|
582
|
-
* 调用方稳定的幂等键。写操作强烈建议持久化;缺省时服务端按 UUID 兜底,但调用方
|
|
583
|
-
* 在重试 / 恢复时无法对账。
|
|
584
|
-
*/
|
|
585
|
-
idempotencyKey?: string;
|
|
586
|
-
signal?: AbortSignal;
|
|
587
|
-
}
|
|
588
|
-
/** 轮询参数(exponential backoff)。 */
|
|
589
|
-
interface CompliancePollOptions {
|
|
590
|
-
/** 总超时(ms),缺省 60s。 */
|
|
591
|
-
timeoutMs?: number;
|
|
592
|
-
/** 初始 interval(ms),缺省 1000。 */
|
|
593
|
-
initialIntervalMs?: number;
|
|
594
|
-
/** interval 倍增上限(ms),缺省 5000。 */
|
|
595
|
-
maxIntervalMs?: number;
|
|
596
|
-
/** 倍增系数,缺省 1.5。 */
|
|
597
|
-
multiplier?: number;
|
|
598
|
-
signal?: AbortSignal;
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
/**
|
|
602
|
-
* SDK 内部 symbolic key;用于代码分支判断与文档。**不是 wire contract**。
|
|
603
|
-
*/
|
|
604
|
-
type ComplianceErrorKey = 'COMPLIANCE_UNAUTHORIZED' | 'COMPLIANCE_INSUFFICIENT_SCOPE' | 'COMPLIANCE_STEP_UP_REQUIRED' | 'COMPLIANCE_TOKEN_INVALID' | 'SUBJECT_SNAPSHOT_REQUIRED' | 'SUBJECT_SNAPSHOT_NOT_FOUND' | 'SUBJECT_SNAPSHOT_TENANT_MISMATCH' | 'EVIDENCE_ASSET_NOT_FOUND' | 'EVIDENCE_ASSET_HASH_MISMATCH' | 'EVIDENCE_ASSET_PAYLOAD_REQUIRED' | 'TIMESTAMP_TOKEN_NOT_FOUND' | 'TIMESTAMP_PROVIDER_FAILED' | 'TIMESTAMP_PROVIDER_UNKNOWN' | 'TIMESTAMP_LOCAL_VERIFY_FAILED' | 'TIMESTAMP_PROVIDER_NOT_AVAILABLE' | 'EVIDENCE_PACKAGE_NOT_FOUND' | 'EVIDENCE_PACKAGE_TIMESTAMP_REQUIRED' | 'EVIDENCE_PACKAGE_MANIFEST_HASH_MISMATCH' | 'REPORT_NOT_FOUND' | 'REPORT_ALREADY_PUBLISHED' | 'REPORT_DRAFT_REQUIRED' | 'EVIDENCE_VERIFY_TARGET_REQUIRED' | 'EVIDENCE_VERIFY_TARGET_NOT_FOUND' | 'PROVIDER_REQUEST_UNKNOWN_NO_RETRY' | 'PROVIDER_CALLBACK_SOURCE_INVALID' | 'PROVIDER_NOT_CONFIGURED' | 'PROVIDER_REQUEST_NOT_FOUND' | 'PROVIDER_REQUEST_IDEMPOTENCY_REQUIRED' | 'PROVIDER_REQUEST_STATUS_NOT_TERMINAL' | 'ENVELOPE_NOT_FOUND' | 'ENVELOPE_TENANT_MISMATCH' | 'ENVELOPE_STATE_NOT_ALLOWED' | 'ENVELOPE_GATE_CLOSED' | 'CONTRACT_NOT_FOUND' | 'CONTRACT_HASH_MISMATCH' | 'PROVIDER_AUTHORIZATION_NOT_CONFIRMED' | 'ENVELOPE_EVIDENCE_NOT_READY' | 'SEAL_ASSET_NOT_FOUND' | 'SEAL_APPROVAL_NOT_FOUND' | 'SEAL_APPROVAL_STATE_NOT_APPROVED' | 'SEAL_APPROVAL_EXPIRED' | 'SEAL_APPROVAL_ALREADY_USED' | 'SEAL_APPROVAL_NONCE_USED' | 'SEAL_APPROVAL_SEAL_MISMATCH' | 'SEAL_APPROVAL_LOCATION_MISMATCH' | 'SEAL_APPROVAL_TRANSACTOR_MISMATCH' | 'SEAL_APPROVAL_CONTRACT_HASH_MISMATCH' | 'SEAL_APPROVAL_INVALID_TRANSITION' | 'SEAL_USE_ALREADY_CONSUMED' | 'AUDIT_CHAIN_TAMPER_DETECTED' | 'BILLING_COMMIT_REQUIRES_LOCAL_VERIFY' | 'BILLING_COMMIT_REQUIRES_PROVIDER_SUCCESS' | 'BILLING_CALLBACK_CANNOT_COMMIT' | 'BILLING_PROVIDER_UNKNOWN_NOT_COMMITTABLE' | 'BILLING_S2S_FORBIDDEN' | 'UNKNOWN_COMPLIANCE_ERROR';
|
|
605
|
-
/** 单个错误的 SDK 视图。 */
|
|
606
|
-
interface ComplianceErrorInfo {
|
|
607
|
-
/** Java numeric error code (wire contract)。 */
|
|
608
|
-
code: number;
|
|
609
|
-
/** 服务端原始 message(中文,可变);仅用于日志/展示。 */
|
|
610
|
-
message: string;
|
|
611
|
-
/** SDK 分支判断用 symbolic key。 */
|
|
612
|
-
key: ComplianceErrorKey;
|
|
613
|
-
/** 是否安全自动重试 — compliance 写接口几乎全为 false。 */
|
|
614
|
-
retryable: boolean;
|
|
615
|
-
/** 是否已经是终态 — 用户必须用新 idempotency-key 重新发起。 */
|
|
616
|
-
terminal: boolean;
|
|
617
|
-
/** 高风险动作需要 step-up / introspection。 */
|
|
618
|
-
stepUpRequired: boolean;
|
|
619
|
-
}
|
|
620
|
-
/**
|
|
621
|
-
* 把一个 BusinessError 分类为 compliance 视图。
|
|
622
|
-
* 非 compliance 段位的错误码会回退到 UNKNOWN_COMPLIANCE_ERROR,调用方应该当作业务错误处理。
|
|
623
|
-
*/
|
|
624
|
-
declare function classifyComplianceError(err: BusinessError): ComplianceErrorInfo;
|
|
625
|
-
/**
|
|
626
|
-
* 判断 BusinessError 是否属于 compliance 段位(1-031-xxx-xxx)。
|
|
627
|
-
* 不在段位的错误码可能来自其它 yudao 模块,按通用业务错误处理即可。
|
|
628
|
-
*/
|
|
629
|
-
declare function isComplianceBusinessError(err: BusinessError): boolean;
|
|
630
|
-
|
|
631
|
-
/**
|
|
632
|
-
* Token 持久化接口
|
|
633
|
-
* 桌面智能体可自行实现 (如 macOS Keychain / Windows Credential Manager)
|
|
634
|
-
*
|
|
635
|
-
* 跨端约定:
|
|
636
|
-
* - Save: 写入持久化, 失败抛 Error
|
|
637
|
-
* - Load: 读取, 不存在返回 null (与 Go IsNotExist 行为一致)
|
|
638
|
-
* - Clear: 删除, 不存在不抛错 (Logout 后 Clear 不应报错, [RC-11])
|
|
639
|
-
* - withLock (v1.0.2 新增, 可选): 跨进程临界区. Client 在 refresh token rotation
|
|
640
|
-
* 场景下用此包裹 "load → check → refresh → save" 整段, 防多进程共享同一 store
|
|
641
|
-
* (典型: FileTokenStore 默认 ~/.acosmi/tokens.json) 撞 HTTP 400 refresh token
|
|
642
|
-
* not found. 不实现时 Client 自动回退到仅进程内串行 (LocalStorage / InMemory
|
|
643
|
-
* 单进程语义无需此方法).
|
|
644
|
-
*/
|
|
645
|
-
interface TokenStore {
|
|
646
|
-
save(tokens: TokenSet): Promise<void>;
|
|
647
|
-
load(): Promise<TokenSet | null>;
|
|
648
|
-
clear(): Promise<void>;
|
|
649
|
-
withLock?<T>(fn: () => Promise<T>): Promise<T>;
|
|
650
|
-
}
|
|
651
|
-
/**
|
|
652
|
-
* 基于文件的 token 存储 (开发/测试用)
|
|
653
|
-
* 生产环境建议替换为系统钥匙串实现
|
|
654
|
-
*
|
|
655
|
-
* 默认路径: ~/.acosmi/tokens.json
|
|
656
|
-
*
|
|
657
|
-
* 浏览器环境调用 new FileTokenStore() 会抛错 — 浏览器请用 LocalStorageTokenStore 或 InMemoryTokenStore.
|
|
658
|
-
*/
|
|
659
|
-
/** 跨进程文件锁配置 (v1.0.2). 公开常量是为了让 caller / 测试可观察, 不建议生产代码改. */
|
|
660
|
-
declare const fileLockDefaults: {
|
|
661
|
-
/** 获取锁的超时上限 (毫秒). refresh 流程含网络 < 30s, 30s 已远超正常完成时间. */
|
|
662
|
-
readonly acquireTimeoutMs: 30000;
|
|
663
|
-
/** 旧锁判定阈值 (毫秒). 锁文件 mtime 早于此值视为 stale 进程崩溃残留, 自动 break. */
|
|
664
|
-
readonly staleMs: 60000;
|
|
665
|
-
/** 重试间隔基数 (毫秒). 真实间隔 = base + random(0, jitter). */
|
|
666
|
-
readonly retryBaseMs: 30;
|
|
667
|
-
readonly retryJitterMs: 70;
|
|
668
|
-
};
|
|
669
|
-
declare class FileTokenStore implements TokenStore {
|
|
670
|
-
private path;
|
|
671
|
-
/** 进程内串行化 (Promise chain) — 与跨进程 flock 配合, 避免单进程内并发持锁产生死锁式互等. */
|
|
672
|
-
private chain;
|
|
673
|
-
constructor(path?: string);
|
|
674
|
-
private resolvePath;
|
|
675
|
-
/** 进程内串行 (维持 v1.0.1 单进程语义). flock 之外另一层防御: 如果用户自己就是单进程
|
|
676
|
-
* 并发场景, 不必每次都进 flock 旁路文件 IO. */
|
|
677
|
-
private withChain;
|
|
678
|
-
/**
|
|
679
|
-
* 跨进程临界区. 用 sidecar `<path>.lock` 文件 + O_EXCL 创建语义实现互斥:
|
|
680
|
-
* - 创建成功 = 持有锁; 写入 pid+timestamp 便于诊断
|
|
681
|
-
* - 创建失败 (EEXIST) = 别的进程持锁, backoff 重试
|
|
682
|
-
* - 锁文件 mtime > staleMs = 进程崩溃残留, unlink 后重试
|
|
683
|
-
* - acquireTimeoutMs 超时 = 抛错 (caller 应作为 transient error 处理, 上层 retry)
|
|
684
|
-
*
|
|
685
|
-
* 注意: O_EXCL 在 NFS 上不保证原子; FileTokenStore 适用于本地文件系统 (典型用户家目录).
|
|
686
|
-
* 真要跨机共享 token, 应实现自定义 Keychain / 数据库 store, 不要用 FileTokenStore.
|
|
687
|
-
*/
|
|
688
|
-
withLock<T>(fn: () => Promise<T>): Promise<T>;
|
|
689
|
-
/**
|
|
690
|
-
* 写入 token. 流程:
|
|
691
|
-
* 1. mkdir -p (默认路径目录)
|
|
692
|
-
* 2. 写入 `<path>.tmp.<pid>`
|
|
693
|
-
* 3. fsync 后 rename 到正式路径 (POSIX 上 rename(2) 同分区原子, Windows 上 ReplaceFile)
|
|
694
|
-
*
|
|
695
|
-
* 选择 atomic rename 而非直接 writeFile: 多进程并发或本进程崩溃时, 读端永远看到的是
|
|
696
|
-
* 完整的旧/新 JSON, 不会读到截断半文件 (Client.create.store.load 可能在另一进程
|
|
697
|
-
* 写入中间触发, atomic rename 避免它解析失败).
|
|
698
|
-
*/
|
|
699
|
-
save(tokens: TokenSet): Promise<void>;
|
|
700
|
-
load(): Promise<TokenSet | null>;
|
|
701
|
-
clear(): Promise<void>;
|
|
702
|
-
}
|
|
703
|
-
/**
|
|
704
|
-
* 创建文件 token 存储 (与 Go NewFileTokenStore 等价)
|
|
705
|
-
* @param path 自定义路径; 空则使用默认 ~/.acosmi/tokens.json
|
|
706
|
-
*/
|
|
707
|
-
declare function newFileTokenStore(path?: string): FileTokenStore;
|
|
708
|
-
/**
|
|
709
|
-
* 基于 LocalStorage 的 token 存储 (浏览器)
|
|
710
|
-
*
|
|
711
|
-
* 仅在浏览器环境可用 (检测 globalThis.localStorage)。
|
|
712
|
-
* 不持久化跨设备同步, 适合单机 SPA 使用。
|
|
713
|
-
*/
|
|
714
|
-
declare class LocalStorageTokenStore implements TokenStore {
|
|
715
|
-
private key;
|
|
716
|
-
constructor(key?: string);
|
|
717
|
-
save(tokens: TokenSet): Promise<void>;
|
|
718
|
-
load(): Promise<TokenSet | null>;
|
|
719
|
-
clear(): Promise<void>;
|
|
720
|
-
}
|
|
721
|
-
/**
|
|
722
|
-
* 内存 token 存储 (不持久化, 进程重启即丢失)
|
|
723
|
-
* 适合: 测试 / Deno script / 短期 SDK 调用 / 不希望落盘的安全场景
|
|
724
|
-
*/
|
|
725
|
-
declare class InMemoryTokenStore implements TokenStore {
|
|
726
|
-
private tokens;
|
|
727
|
-
save(tokens: TokenSet): Promise<void>;
|
|
728
|
-
load(): Promise<TokenSet | null>;
|
|
729
|
-
clear(): Promise<void>;
|
|
730
|
-
}
|
|
467
|
+
declare class LocalStorageTokenStore implements TokenStore {
|
|
468
|
+
private key;
|
|
469
|
+
constructor(key?: string);
|
|
470
|
+
save(tokens: TokenSet): Promise<void>;
|
|
471
|
+
load(): Promise<TokenSet | null>;
|
|
472
|
+
clear(): Promise<void>;
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* 内存 token 存储 (不持久化, 进程重启即丢失)
|
|
476
|
+
* 适合: 测试 / Deno script / 短期 SDK 调用 / 不希望落盘的安全场景
|
|
477
|
+
*/
|
|
478
|
+
declare class InMemoryTokenStore implements TokenStore {
|
|
479
|
+
private tokens;
|
|
480
|
+
save(tokens: TokenSet): Promise<void>;
|
|
481
|
+
load(): Promise<TokenSet | null>;
|
|
482
|
+
clear(): Promise<void>;
|
|
483
|
+
}
|
|
731
484
|
|
|
732
485
|
/** 表示一次 retry 评估的请求快照 — 仅供 SafeToRetry 闸门使用 */
|
|
733
486
|
interface RetryRequestInfo {
|
|
@@ -1150,167 +903,668 @@ declare class Client {
|
|
|
1150
903
|
|
|
1151
904
|
declare module '@acosmi/sdk-ts' {
|
|
1152
905
|
interface Client {
|
|
1153
|
-
/**
|
|
1154
|
-
|
|
906
|
+
/**
|
|
907
|
+
* 配置请求前的底线防御 (体积 / deny-list / 深度)。
|
|
908
|
+
* 传空值 {} 关闭 (所有字段为零 = 禁用)。
|
|
909
|
+
* 并发安全, 可在任意时间调用。
|
|
910
|
+
*/
|
|
911
|
+
setDefensiveSanitize(cfg: MinimalSanitizeConfig): void;
|
|
912
|
+
/**
|
|
913
|
+
* 开启后, 每次请求前 SDK 会从 rawMessages 中剥除带 acosmi_ephemeral:true 标记的 block,
|
|
914
|
+
* 并联动剥除引用已剥 tool_use 的 tool_result, 避免 provider 报 "tool_use_id 不存在".
|
|
915
|
+
*
|
|
916
|
+
* 标记来源: 网关在响应 content_block_start 中 in-band 注入; 消费者把上一轮 assistant
|
|
917
|
+
* 回复原样拼回 history 即可触发剥离。
|
|
918
|
+
*/
|
|
919
|
+
setAutoStripEphemeralHistory(on: boolean): void;
|
|
920
|
+
/**
|
|
921
|
+
* 在 buildChatRequest 开头调用, 把配置化的防御策略应用到 req。
|
|
922
|
+
* 未配置时立即返回, 零开销。
|
|
923
|
+
*
|
|
924
|
+
* 失败时抛错 — 调用方应放弃本次请求。
|
|
925
|
+
*/
|
|
926
|
+
applyRequestSanitizers(req: ChatRequest): void;
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
/** 下载限流错误 (429) */
|
|
931
|
+
declare class RateLimitError extends Error {
|
|
932
|
+
retryAfter: string;
|
|
933
|
+
raw: string;
|
|
934
|
+
constructor(message: string, retryAfter: string, raw: string);
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* API 业务层错误 (HTTP 200 但 code != 0)
|
|
938
|
+
* tk-dist 代理透传 yudao 响应, HTTP 状态码为 200, 业务错误在 JSON code 字段
|
|
939
|
+
*/
|
|
940
|
+
declare class BusinessError extends Error {
|
|
941
|
+
code: number;
|
|
942
|
+
constructor(code: number, message: string);
|
|
943
|
+
}
|
|
944
|
+
/**
|
|
945
|
+
* 订单到达非成功终态 (FAILED/CANCELLED/CLOSED/EXPIRED/REFUNDED)
|
|
946
|
+
* waitForPayment 在订单终态为非成功时抛此错误
|
|
947
|
+
*/
|
|
948
|
+
declare class OrderTerminalError extends Error {
|
|
949
|
+
orderId: string;
|
|
950
|
+
status: string;
|
|
951
|
+
constructor(orderId: string, status: string);
|
|
952
|
+
}
|
|
953
|
+
/**
|
|
954
|
+
* 模型缓存未命中且 listModels 刷新后仍未找到。
|
|
955
|
+
*
|
|
956
|
+
* 历史上 getCachedModel miss 时硬返 ManagedModel{provider:"anthropic"} 占位,
|
|
957
|
+
* 导致未预热场景下的 chat 请求按 AnthropicAdapter 编码, 被发到错误端点。
|
|
958
|
+
* v0.13.x 改为 miss → listModels 自动刷新一次; 仍 miss → 抛此错误。
|
|
959
|
+
*/
|
|
960
|
+
declare class ModelNotFoundError extends Error {
|
|
961
|
+
modelId: string;
|
|
962
|
+
constructor(modelId: string);
|
|
963
|
+
}
|
|
964
|
+
/**
|
|
965
|
+
* 结构化 HTTP 非 2xx 错误.
|
|
966
|
+
*
|
|
967
|
+
* 用 instanceof 提取:
|
|
968
|
+
* try { ... } catch (e) {
|
|
969
|
+
* if (e instanceof HTTPError && e.statusCode === 429) { ... }
|
|
970
|
+
* }
|
|
971
|
+
*/
|
|
972
|
+
declare class HTTPError extends Error {
|
|
973
|
+
statusCode: number;
|
|
974
|
+
/** anthropic.error.type / openai.error.type, 缺失为空 */
|
|
975
|
+
type: string;
|
|
976
|
+
/** Retry-After 头解析的秒数, 0 表示未提供或解析失败 */
|
|
977
|
+
retryAfter: number;
|
|
978
|
+
/** 原始响应体 (截断到 maxErrorBodySize) */
|
|
979
|
+
body: string;
|
|
980
|
+
constructor(statusCode: number, opts?: {
|
|
981
|
+
type?: string;
|
|
982
|
+
message?: string;
|
|
983
|
+
retryAfter?: number;
|
|
984
|
+
body?: string;
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* 结构化网络层错误 (传输失败, 区别于上游业务错误).
|
|
989
|
+
*
|
|
990
|
+
* 包装 fetch 抛出的错误 — 含 timeout / EOF / connection refused / DNS 失败等.
|
|
991
|
+
* retry policy: isTimeout / isEOF 任一为 true → 默认可重试.
|
|
992
|
+
*/
|
|
993
|
+
declare class NetworkError extends Error {
|
|
994
|
+
/** 操作描述, e.g. "POST /v1/messages" */
|
|
995
|
+
op: string;
|
|
996
|
+
/** 请求 URL (脱敏后) */
|
|
997
|
+
url: string;
|
|
998
|
+
cause?: unknown;
|
|
999
|
+
timeout: boolean;
|
|
1000
|
+
eof: boolean;
|
|
1001
|
+
constructor(op: string, url: string, cause: unknown, opts?: {
|
|
1002
|
+
timeout?: boolean;
|
|
1003
|
+
eof?: boolean;
|
|
1004
|
+
});
|
|
1005
|
+
isTimeout(): boolean;
|
|
1006
|
+
isEOF(): boolean;
|
|
1007
|
+
}
|
|
1008
|
+
/**
|
|
1009
|
+
* 流式失败事件的结构化表示。
|
|
1010
|
+
*
|
|
1011
|
+
* 由 gateway 的 `managed_model_stream_failed` 事件解析得到。客户端可通过
|
|
1012
|
+
* instanceof 提取并按 code/retryable 决策。
|
|
1013
|
+
*/
|
|
1014
|
+
declare class StreamError extends Error {
|
|
1015
|
+
/** 例: "empty_response" / "rate_limit" / "overloaded" / "" */
|
|
1016
|
+
code: string;
|
|
1017
|
+
/** 例: "provider" / "settlement" */
|
|
1018
|
+
stage: string;
|
|
1019
|
+
/** 用户友好提示 (中文); 历史字段, 与 rawError 区分 */
|
|
1020
|
+
userMessage: string;
|
|
1021
|
+
/** gateway 原始 error 字符串 */
|
|
1022
|
+
rawError: string;
|
|
1023
|
+
/** 客户端是否值得重试 */
|
|
1024
|
+
retryable: boolean;
|
|
1025
|
+
constructor(opts?: {
|
|
1026
|
+
code?: string;
|
|
1027
|
+
stage?: string;
|
|
1028
|
+
message?: string;
|
|
1029
|
+
rawError?: string;
|
|
1030
|
+
retryable?: boolean;
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
/** nexus-v4 标准响应。兼容 yudao 格式 (msg) 和 nexus-v4 格式 (message) */
|
|
1035
|
+
interface APIResponse<T> {
|
|
1036
|
+
code: number;
|
|
1037
|
+
message?: string;
|
|
1038
|
+
msg?: string;
|
|
1039
|
+
data: T;
|
|
1040
|
+
}
|
|
1041
|
+
/** 优先返回 message, 降级到 msg (兼容 yudao 透传) */
|
|
1042
|
+
declare function apiResponseGetMessage<T>(r: APIResponse<T>): string;
|
|
1043
|
+
/** 检查业务层错误码 — code != 0 时抛 BusinessError */
|
|
1044
|
+
declare function apiResponseBusinessError<T>(r: APIResponse<T>): BusinessError | null;
|
|
1045
|
+
/** yudao 分页响应格式 (tk-dist 代理透传) */
|
|
1046
|
+
interface YudaoPageResult<T> {
|
|
1047
|
+
list: T[];
|
|
1048
|
+
total: number;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
declare const ScopeAI = "ai";
|
|
1052
|
+
declare const ScopeSkills = "skills";
|
|
1053
|
+
declare const ScopeAccount = "account";
|
|
1054
|
+
/** @deprecated 旧细粒度 scope, 保留向后兼容, 新代码请用分组 scope */
|
|
1055
|
+
declare const ScopeModels = "models";
|
|
1056
|
+
/** @deprecated */
|
|
1057
|
+
declare const ScopeModelsChat = "models:chat";
|
|
1058
|
+
/** @deprecated */
|
|
1059
|
+
declare const ScopeEntitlements = "entitlements";
|
|
1060
|
+
/** @deprecated */
|
|
1061
|
+
declare const ScopeTokenPackages = "token-packages";
|
|
1062
|
+
/** @deprecated */
|
|
1063
|
+
declare const ScopeSkillStore = "skill_store";
|
|
1064
|
+
/** @deprecated */
|
|
1065
|
+
declare const ScopeTools = "tools";
|
|
1066
|
+
/** @deprecated */
|
|
1067
|
+
declare const ScopeToolsExecute = "tools:execute";
|
|
1068
|
+
/** @deprecated */
|
|
1069
|
+
declare const ScopeWallet = "wallet";
|
|
1070
|
+
/** @deprecated */
|
|
1071
|
+
declare const ScopeWalletReadonly = "wallet:readonly";
|
|
1072
|
+
/** @deprecated */
|
|
1073
|
+
declare const ScopeProfile = "profile";
|
|
1074
|
+
/** 全部分组 scope (推荐) */
|
|
1075
|
+
declare function allScopes(): string[];
|
|
1076
|
+
/** 模型服务相关 scope */
|
|
1077
|
+
declare function modelScopes(): string[];
|
|
1078
|
+
/** 商城/钱包 scope */
|
|
1079
|
+
declare function commerceScopes(): string[];
|
|
1080
|
+
/** 技能/工具 scope */
|
|
1081
|
+
declare function skillScopes(): string[];
|
|
1082
|
+
|
|
1083
|
+
interface OpenAIChatResponse {
|
|
1084
|
+
id: string;
|
|
1085
|
+
/** "chat.completion" */
|
|
1086
|
+
object: string;
|
|
1087
|
+
model: string;
|
|
1088
|
+
choices: OpenAIChatChoice[];
|
|
1089
|
+
usage: OpenAIUsage;
|
|
1090
|
+
}
|
|
1091
|
+
interface OpenAIChatChoice {
|
|
1092
|
+
index: number;
|
|
1093
|
+
message: OpenAIChatMessage;
|
|
1094
|
+
/** "stop", "tool_calls", "length" */
|
|
1095
|
+
finish_reason: string;
|
|
1096
|
+
}
|
|
1097
|
+
interface OpenAIChatMessage {
|
|
1098
|
+
role: string;
|
|
1099
|
+
content: string;
|
|
1100
|
+
tool_calls?: OpenAIToolCall[];
|
|
1101
|
+
/** GLM/DeepSeek thinking */
|
|
1102
|
+
reasoning_content?: string;
|
|
1103
|
+
}
|
|
1104
|
+
interface OpenAIToolCall {
|
|
1105
|
+
id: string;
|
|
1106
|
+
/** "function" */
|
|
1107
|
+
type: string;
|
|
1108
|
+
function: OpenAIFunctionCall;
|
|
1109
|
+
}
|
|
1110
|
+
interface OpenAIFunctionCall {
|
|
1111
|
+
name: string;
|
|
1112
|
+
arguments: string;
|
|
1113
|
+
}
|
|
1114
|
+
interface OpenAIUsage {
|
|
1115
|
+
prompt_tokens: number;
|
|
1116
|
+
completion_tokens: number;
|
|
1117
|
+
total_tokens: number;
|
|
1118
|
+
}
|
|
1119
|
+
/** OpenAI SSE delta 格式 */
|
|
1120
|
+
interface OpenAIStreamChunk {
|
|
1121
|
+
id: string;
|
|
1122
|
+
/** "chat.completion.chunk" */
|
|
1123
|
+
object: string;
|
|
1124
|
+
choices: OpenAIStreamChoice[];
|
|
1125
|
+
usage?: OpenAIUsage;
|
|
1126
|
+
}
|
|
1127
|
+
interface OpenAIStreamChoice {
|
|
1128
|
+
index: number;
|
|
1129
|
+
delta: OpenAIStreamDelta;
|
|
1130
|
+
finish_reason: string | null;
|
|
1131
|
+
}
|
|
1132
|
+
interface OpenAIStreamDelta {
|
|
1133
|
+
role?: string;
|
|
1134
|
+
content?: string;
|
|
1135
|
+
reasoning_content?: string;
|
|
1136
|
+
tool_calls?: OpenAIStreamToolCall[];
|
|
1137
|
+
}
|
|
1138
|
+
interface OpenAIStreamToolCall {
|
|
1139
|
+
index: number;
|
|
1140
|
+
id?: string;
|
|
1141
|
+
type?: string;
|
|
1142
|
+
function: OpenAIFunctionCall;
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
/**
|
|
1146
|
+
* 判断 ManagedModel 是否声明支持指定输入模态.
|
|
1147
|
+
*
|
|
1148
|
+
* 语义:
|
|
1149
|
+
* - model 为 null/undefined → false
|
|
1150
|
+
* - model.inputModalities 缺失或非数组 → false (保守, 未声明不当支持)
|
|
1151
|
+
* - 大小写敏感 (上游契约即小写 'text' | 'image')
|
|
1152
|
+
*/
|
|
1153
|
+
declare function modelSupportsInputModality(model: ManagedModel | null | undefined, modality: InputModality): boolean;
|
|
1154
|
+
/** 等价 modelSupportsInputModality(model, 'image') — 调用方常见快捷判定. */
|
|
1155
|
+
declare function modelSupportsImageInput(model: ManagedModel | null | undefined): boolean;
|
|
1156
|
+
/**
|
|
1157
|
+
* 在 catalog 中按 catalog 顺序查找首个支持指定模态的模型.
|
|
1158
|
+
*
|
|
1159
|
+
* 选择规则:
|
|
1160
|
+
* 1. isEnabled !== false (默认开, 显式 false 才剔除)
|
|
1161
|
+
* 2. inputModalities 包含指定模态
|
|
1162
|
+
* 3. 命中后按 catalog 顺序返回第一个; 未命中返 null
|
|
1163
|
+
*
|
|
1164
|
+
* 注意: 该 helper 不读 isDefault, 调用方需要 "默认优先" 请用
|
|
1165
|
+
* findDesktopVisualUnderstandingModel 或自行排序.
|
|
1166
|
+
*/
|
|
1167
|
+
declare function findFirstModelByInputModality(models: ManagedModel[], modality: InputModality): ManagedModel | null;
|
|
1168
|
+
/**
|
|
1169
|
+
* 在 catalog 中选出最适合做 "桌面视觉理解 sidecar" 的模型.
|
|
1170
|
+
*
|
|
1171
|
+
* 设计目的: CrabCode desktop automation 链路里, 主模型不一定多模态;
|
|
1172
|
+
* 截图先送 sidecar 解析成结构化 UI 描述, 再喂主模型. 这里选 sidecar 模型
|
|
1173
|
+
* 严格走运营标注的 supports_desktop_visual_understanding capability, 不靠
|
|
1174
|
+
* 模型名猜.
|
|
1175
|
+
*
|
|
1176
|
+
* 选择规则 (按用户指定顺序):
|
|
1177
|
+
* 1. isEnabled !== false
|
|
1178
|
+
* 2. capabilities.supports_desktop_visual_understanding === true
|
|
1179
|
+
* 3. inputModalities 包含 'image' (必须真能吃图)
|
|
1180
|
+
* 4. 命中集合中优先 isDefault === true; 否则返回 catalog 顺序第一个
|
|
1181
|
+
*
|
|
1182
|
+
* 全部不满足返 null. 调用方收到 null 应:
|
|
1183
|
+
* - 提示用户在管理后台/网关侧开启桌面视觉 sidecar 模型, 或
|
|
1184
|
+
* - 降级停掉依赖截图的工作流, 而不是硬选一个非视觉模型送图.
|
|
1185
|
+
*/
|
|
1186
|
+
declare function findDesktopVisualUnderstandingModel(models: ManagedModel[]): ManagedModel | null;
|
|
1187
|
+
|
|
1188
|
+
/** SDK 为单个 content block 缓存的元数据 */
|
|
1189
|
+
interface BlockMeta {
|
|
1190
|
+
type: string;
|
|
1191
|
+
ephemeral: boolean;
|
|
1192
|
+
}
|
|
1193
|
+
/**
|
|
1194
|
+
* 按 Anthropic SSE 事件类型解析 data, 更新 blockTypeMap, 返回 [index, type, ephemeral]。
|
|
1195
|
+
*
|
|
1196
|
+
* 仅当事件为 content_block_start / content_block_delta / content_block_stop
|
|
1197
|
+
* 时返回非空 type; 其他事件返回空 type, 调用方据此判别是否填充 StreamEvent 元数据字段。
|
|
1198
|
+
*/
|
|
1199
|
+
declare function extractAnthropicBlockMeta(eventType: string, data: string, blockTypeMap: Map<number, BlockMeta>): [number, string, boolean];
|
|
1200
|
+
|
|
1201
|
+
/** 根据模型能力和请求参数自动组装 beta header 列表 */
|
|
1202
|
+
declare function buildBetas(caps: ModelCapabilities, req: ChatRequest): string[];
|
|
1203
|
+
/** 合并两个字符串数组并去重, 保留顺序 */
|
|
1204
|
+
declare function uniqueMerge(base: string[], extra: string[]): string[];
|
|
1205
|
+
|
|
1206
|
+
declare module '@acosmi/sdk-ts' {
|
|
1207
|
+
interface Client {
|
|
1208
|
+
/** 查询当前用户的权益余额 (聚合) */
|
|
1209
|
+
getBalance(signal?: AbortSignal): Promise<EntitlementBalance>;
|
|
1210
|
+
/** 查询详细余额 (含每条权益明细) */
|
|
1211
|
+
getBalanceDetail(signal?: AbortSignal): Promise<BalanceDetail>;
|
|
1212
|
+
/** 查询当前用户权益列表; status: "ACTIVE" / "EXPIRED" / "" (全部) */
|
|
1213
|
+
listEntitlements(status: string, signal?: AbortSignal): Promise<EntitlementItem[]>;
|
|
1214
|
+
/** 查询核销记录 (分页) */
|
|
1215
|
+
listConsumeRecords(page: number, pageSize: number, signal?: AbortSignal): Promise<ConsumeRecordPage>;
|
|
1216
|
+
/** 领取当月免费额度 — 幂等: 已领取时返回已有权益 */
|
|
1217
|
+
claimMonthlyFree(signal?: AbortSignal): Promise<EntitlementItem>;
|
|
1218
|
+
/** 查询当前用户在指定模型下的剩余 token (raw + ETU) */
|
|
1219
|
+
getByModel(modelID: string, signal?: AbortSignal): Promise<ModelByQuotaResponse>;
|
|
1220
|
+
/** 列出当前用户的全部桶 */
|
|
1221
|
+
listBuckets(signal?: AbortSignal): Promise<ModelBucket[]>;
|
|
1222
|
+
/** 拉取模型系数表; SDK 自带 8s TTL 内存缓存以减小调用风暴. */
|
|
1223
|
+
listCoefficients(signal?: AbortSignal): Promise<ModelCoefficient[]>;
|
|
1224
|
+
/** 手动失效系数缓存 (admin 调价后建议立即调一次) */
|
|
1225
|
+
invalidateCoefficientCache(): void;
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
declare module '@acosmi/sdk-ts' {
|
|
1230
|
+
interface Client {
|
|
1231
|
+
/** 获取商城流量包列表 (兼容 yudao 分页和直接数组两种格式) */
|
|
1232
|
+
listTokenPackages(signal?: AbortSignal): Promise<TokenPackage[]>;
|
|
1233
|
+
/** 获取流量包详情 */
|
|
1234
|
+
getTokenPackageDetail(packageID: string, signal?: AbortSignal): Promise<TokenPackage>;
|
|
1235
|
+
/** 购买流量包 (创建订单) */
|
|
1236
|
+
buyTokenPackage(packageID: string, payload: PayPayload | null, signal?: AbortSignal): Promise<Order>;
|
|
1237
|
+
/** 查询订单支付状态 */
|
|
1238
|
+
getOrderStatus(orderID: string, signal?: AbortSignal): Promise<OrderStatus>;
|
|
1239
|
+
/** 查询我的订单列表 */
|
|
1240
|
+
listMyOrders(signal?: AbortSignal): Promise<Order[]>;
|
|
1241
|
+
/**
|
|
1242
|
+
* 轮询订单支付状态直到终态
|
|
1243
|
+
* 成功支付返回 status; 终态失败抛 OrderTerminalError
|
|
1244
|
+
* pollIntervalMs <= 0 时默认 2 秒
|
|
1245
|
+
*/
|
|
1246
|
+
waitForPayment(orderID: string, pollIntervalMs: number, signal?: AbortSignal): Promise<OrderStatus>;
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
declare module '@acosmi/sdk-ts' {
|
|
1251
|
+
interface Client {
|
|
1252
|
+
/** 获取钱包统计 (余额/月消费/月充值) */
|
|
1253
|
+
getWalletStats(signal?: AbortSignal): Promise<WalletStats>;
|
|
1254
|
+
/** 获取最近交易记录 */
|
|
1255
|
+
getWalletTransactions(signal?: AbortSignal): Promise<Transaction[]>;
|
|
1155
1256
|
}
|
|
1156
1257
|
}
|
|
1258
|
+
|
|
1259
|
+
interface SkillStoreItem {
|
|
1260
|
+
id: string;
|
|
1261
|
+
pluginId: string;
|
|
1262
|
+
key: string;
|
|
1263
|
+
name: string;
|
|
1264
|
+
description: string;
|
|
1265
|
+
icon: string;
|
|
1266
|
+
category: string;
|
|
1267
|
+
inputSchema: string;
|
|
1268
|
+
outputSchema: string;
|
|
1269
|
+
timeout: number;
|
|
1270
|
+
retryCount: number;
|
|
1271
|
+
retryDelay: number;
|
|
1272
|
+
version: string;
|
|
1273
|
+
totalCalls: number;
|
|
1274
|
+
avgDurationMs: number;
|
|
1275
|
+
successRate: number;
|
|
1276
|
+
isEnabled: boolean;
|
|
1277
|
+
securityLevel: string;
|
|
1278
|
+
securityScore: number;
|
|
1279
|
+
scope: string;
|
|
1280
|
+
status: string;
|
|
1281
|
+
downloadCount: number;
|
|
1282
|
+
readme: string;
|
|
1283
|
+
tags: string[];
|
|
1284
|
+
author: string;
|
|
1285
|
+
publisherId: string;
|
|
1286
|
+
isPublished: boolean;
|
|
1287
|
+
pluginName: string;
|
|
1288
|
+
pluginIcon: string;
|
|
1289
|
+
updatedAt: string;
|
|
1290
|
+
visibility?: string;
|
|
1291
|
+
certificationStatus?: string;
|
|
1292
|
+
source?: string;
|
|
1293
|
+
}
|
|
1294
|
+
/** 技能商店搜索参数 (非 wire 类型, 用于 client 方法参数) */
|
|
1295
|
+
interface SkillStoreQuery {
|
|
1296
|
+
category?: string;
|
|
1297
|
+
keyword?: string;
|
|
1298
|
+
tag?: string;
|
|
1299
|
+
}
|
|
1300
|
+
/** 技能统计概览 */
|
|
1301
|
+
interface SkillSummary {
|
|
1302
|
+
installed: number;
|
|
1303
|
+
created: number;
|
|
1304
|
+
total: number;
|
|
1305
|
+
storeAvailable: number;
|
|
1306
|
+
}
|
|
1307
|
+
/** 技能商店分页浏览响应 */
|
|
1308
|
+
interface SkillBrowseResponse {
|
|
1309
|
+
items: SkillStoreItem[];
|
|
1310
|
+
total: number;
|
|
1311
|
+
page: number;
|
|
1312
|
+
pageSize: number;
|
|
1313
|
+
}
|
|
1157
1314
|
/**
|
|
1158
|
-
*
|
|
1159
|
-
*
|
|
1160
|
-
* 分类逻辑:终态失败优先于 timeout;timeout 不算 retryable,调用方必须用新 idempotency-key
|
|
1161
|
-
* 重新发起整条链路。
|
|
1315
|
+
* 技能商店列表项(轻量,仅含浏览所需字段)
|
|
1316
|
+
* 配合服务端 fields=minimal 参数使用,响应体积缩减 90%+
|
|
1162
1317
|
*/
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1318
|
+
interface SkillStoreListItem {
|
|
1319
|
+
id: string;
|
|
1320
|
+
key: string;
|
|
1321
|
+
name: string;
|
|
1322
|
+
description: string;
|
|
1323
|
+
icon: string;
|
|
1324
|
+
category: string;
|
|
1325
|
+
version: string;
|
|
1326
|
+
author: string;
|
|
1327
|
+
downloadCount: number;
|
|
1328
|
+
tags: string[];
|
|
1329
|
+
certificationStatus?: string;
|
|
1330
|
+
visibility?: string;
|
|
1331
|
+
source?: string;
|
|
1332
|
+
updatedAt: string;
|
|
1333
|
+
}
|
|
1334
|
+
/** 技能商店轻量浏览响应 */
|
|
1335
|
+
interface SkillBrowseListResponse {
|
|
1336
|
+
items: SkillStoreListItem[];
|
|
1337
|
+
total: number;
|
|
1338
|
+
page: number;
|
|
1339
|
+
pageSize: number;
|
|
1340
|
+
}
|
|
1341
|
+
/** 技能认证状态响应 */
|
|
1342
|
+
interface CertificationStatus {
|
|
1343
|
+
skillId: string;
|
|
1344
|
+
certificationStatus: string;
|
|
1345
|
+
certifiedAt?: number;
|
|
1346
|
+
securityLevel?: string;
|
|
1347
|
+
securityScore: number;
|
|
1348
|
+
report?: unknown;
|
|
1349
|
+
}
|
|
1350
|
+
interface GenerateSkillRequest {
|
|
1351
|
+
purpose: string;
|
|
1352
|
+
examples?: string[];
|
|
1353
|
+
inputHints?: string;
|
|
1354
|
+
outputHints?: string;
|
|
1355
|
+
category?: string;
|
|
1356
|
+
language?: string;
|
|
1357
|
+
}
|
|
1358
|
+
interface GenerateSkillResult {
|
|
1359
|
+
skillName: string;
|
|
1360
|
+
skillKey: string;
|
|
1361
|
+
description: string;
|
|
1362
|
+
skillMd: string;
|
|
1363
|
+
inputSchema: string;
|
|
1364
|
+
outputSchema: string;
|
|
1365
|
+
testCases: string[];
|
|
1366
|
+
readme: string;
|
|
1367
|
+
category: string;
|
|
1368
|
+
tags: string[];
|
|
1369
|
+
timeout: number;
|
|
1370
|
+
}
|
|
1371
|
+
interface OptimizeSkillRequest {
|
|
1372
|
+
skillName: string;
|
|
1373
|
+
description?: string;
|
|
1374
|
+
inputSchema?: string;
|
|
1375
|
+
outputSchema?: string;
|
|
1376
|
+
readme?: string;
|
|
1377
|
+
aspects?: string[];
|
|
1378
|
+
}
|
|
1379
|
+
interface OptimizeSkillResult {
|
|
1380
|
+
optimizedSkill: GenerateSkillResult;
|
|
1381
|
+
changes: string[];
|
|
1382
|
+
score: number;
|
|
1383
|
+
}
|
|
1384
|
+
interface ToolView {
|
|
1385
|
+
id: string;
|
|
1386
|
+
key: string;
|
|
1387
|
+
name: string;
|
|
1388
|
+
description: string;
|
|
1389
|
+
icon: string;
|
|
1390
|
+
category: string;
|
|
1391
|
+
inputSchema: string;
|
|
1392
|
+
outputSchema: string;
|
|
1393
|
+
timeout: number;
|
|
1394
|
+
isEnabled: boolean;
|
|
1395
|
+
provider?: ToolProvider;
|
|
1396
|
+
}
|
|
1397
|
+
interface ToolProvider {
|
|
1398
|
+
id: string;
|
|
1399
|
+
name: string;
|
|
1400
|
+
icon: string;
|
|
1401
|
+
sourceType: string;
|
|
1402
|
+
mcpEndpoint?: string;
|
|
1403
|
+
isEnabled: boolean;
|
|
1167
1404
|
}
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1405
|
+
interface ToolListResponse {
|
|
1406
|
+
skills: ToolView[];
|
|
1407
|
+
total: number;
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
declare module '@acosmi/sdk-ts' {
|
|
1411
|
+
interface Client {
|
|
1412
|
+
/** 浏览技能商店 (公共端点, 无需认证) */
|
|
1413
|
+
browseSkillStore(query: SkillStoreQuery, signal?: AbortSignal): Promise<SkillStoreItem[]>;
|
|
1414
|
+
/** 浏览公共技能商店 (V3 分页接口) */
|
|
1415
|
+
browseSkills(page: number, pageSize: number, category: string, keyword: string, tag: string, source: string, signal?: AbortSignal): Promise<SkillBrowseResponse>;
|
|
1416
|
+
/** 轻量浏览公共技能商店 (fields=minimal, 响应体积缩减 90%+) */
|
|
1417
|
+
browseSkillsList(page: number, pageSize: number, category: string, keyword: string, tag: string, source: string, signal?: AbortSignal): Promise<SkillBrowseListResponse>;
|
|
1418
|
+
/** 获取技能商店中某个技能的详情 (公共端点) */
|
|
1419
|
+
getSkillDetail(skillID: string, signal?: AbortSignal): Promise<SkillStoreItem>;
|
|
1420
|
+
/** 按 key 精确查找公共技能 (公共端点) */
|
|
1421
|
+
resolveSkill(key: string, signal?: AbortSignal): Promise<SkillStoreItem>;
|
|
1422
|
+
/** 安装技能到当前用户的租户空间 (需 OAuth scope: skill_store) */
|
|
1423
|
+
installSkill(skillID: string, signal?: AbortSignal): Promise<SkillStoreItem>;
|
|
1424
|
+
/**
|
|
1425
|
+
* 下载技能 ZIP 包 (公共端点, 双模式)
|
|
1426
|
+
* 有 token 时自动附带 (享受无限流), 无 token 时匿名 (受限流)
|
|
1427
|
+
* @returns [data, filename]; 限流时抛 RateLimitError
|
|
1428
|
+
*/
|
|
1429
|
+
downloadSkill(skillID: string, signal?: AbortSignal): Promise<{
|
|
1430
|
+
data: Uint8Array;
|
|
1431
|
+
filename: string;
|
|
1432
|
+
}>;
|
|
1433
|
+
/**
|
|
1434
|
+
* 上传技能 ZIP 包
|
|
1435
|
+
* @param scope "TENANT"
|
|
1436
|
+
* @param intent "PERSONAL" (仅自己用) 或 "PUBLIC_INTENT" (走认证→公开)
|
|
1437
|
+
*/
|
|
1438
|
+
uploadSkill(zipData: Uint8Array, scope: string, intent: string, signal?: AbortSignal): Promise<SkillStoreItem>;
|
|
1439
|
+
/** 获取技能统计概览 */
|
|
1440
|
+
getSkillSummary(signal?: AbortSignal): Promise<SkillSummary>;
|
|
1441
|
+
/** 触发技能认证管线 (异步) */
|
|
1442
|
+
certifySkill(skillID: string, signal?: AbortSignal): Promise<void>;
|
|
1443
|
+
/** 查询技能认证状态 */
|
|
1444
|
+
getCertificationStatus(skillID: string, signal?: AbortSignal): Promise<CertificationStatus>;
|
|
1445
|
+
/** 根据自然语言描述生成技能定义 (基于独立 LLM) */
|
|
1446
|
+
generateSkill(req: GenerateSkillRequest, signal?: AbortSignal): Promise<GenerateSkillResult>;
|
|
1447
|
+
/** 优化已有技能定义 */
|
|
1448
|
+
optimizeSkill(req: OptimizeSkillRequest, signal?: AbortSignal): Promise<OptimizeSkillResult>;
|
|
1449
|
+
/** 校验技能定义正确性 */
|
|
1450
|
+
validateSkill(skillName: string, signal?: AbortSignal): Promise<void>;
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
declare module '@acosmi/sdk-ts' {
|
|
1455
|
+
interface Client {
|
|
1456
|
+
/** 获取当前用户租户下的所有工具 (Skill 优先 + Plugin 兜底) */
|
|
1457
|
+
listTools(signal?: AbortSignal): Promise<ToolView[]>;
|
|
1458
|
+
/** 获取单个工具详情 */
|
|
1459
|
+
getTool(toolID: string, signal?: AbortSignal): Promise<ToolView>;
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
/** 单条通知 */
|
|
1464
|
+
interface Notification {
|
|
1465
|
+
id: string;
|
|
1466
|
+
title: string;
|
|
1467
|
+
content: string;
|
|
1468
|
+
/** system | billing | security | task | commission | entitlement */
|
|
1469
|
+
type: string;
|
|
1470
|
+
isRead: boolean;
|
|
1471
|
+
createdAt: string;
|
|
1472
|
+
}
|
|
1473
|
+
/** 分页通知列表 */
|
|
1474
|
+
interface NotificationList {
|
|
1475
|
+
list: Notification[];
|
|
1476
|
+
unreadCount: number;
|
|
1477
|
+
total: number;
|
|
1478
|
+
page: number;
|
|
1479
|
+
pageSize: number;
|
|
1480
|
+
}
|
|
1481
|
+
/** 未读通知计数 */
|
|
1482
|
+
interface NotificationUnreadCount {
|
|
1483
|
+
unreadCount: number;
|
|
1484
|
+
}
|
|
1485
|
+
/** 通知偏好 (按类型+渠道) */
|
|
1486
|
+
interface NotificationPreference {
|
|
1487
|
+
typeCode: string;
|
|
1488
|
+
channelInApp: boolean;
|
|
1489
|
+
channelEmail: boolean;
|
|
1490
|
+
channelSms: boolean;
|
|
1491
|
+
channelPush: boolean;
|
|
1492
|
+
}
|
|
1493
|
+
/** 推送设备注册 */
|
|
1494
|
+
interface DeviceRegistration {
|
|
1495
|
+
/** android | ios | harmony */
|
|
1496
|
+
platform: string;
|
|
1497
|
+
token: string;
|
|
1498
|
+
appVersion: string;
|
|
1499
|
+
}
|
|
1500
|
+
/** 服务端推送事件 */
|
|
1501
|
+
interface WSEvent {
|
|
1502
|
+
type: string;
|
|
1503
|
+
topic?: string;
|
|
1504
|
+
/** json.RawMessage in Go */
|
|
1505
|
+
data?: unknown;
|
|
1506
|
+
connId?: string;
|
|
1507
|
+
timestamp?: string;
|
|
1508
|
+
message?: string;
|
|
1509
|
+
}
|
|
1510
|
+
/**
|
|
1511
|
+
* 从 WSEvent 中解析通知
|
|
1512
|
+
* 返回 null 表示该事件不是系统通知
|
|
1513
|
+
*/
|
|
1514
|
+
declare function parseNotificationEvent(ev: WSEvent): Notification | null;
|
|
1515
|
+
|
|
1516
|
+
declare module '@acosmi/sdk-ts' {
|
|
1517
|
+
interface Client {
|
|
1518
|
+
/** 分页查询通知列表 */
|
|
1519
|
+
listNotifications(page: number, pageSize: number, typeFilter: string, signal?: AbortSignal): Promise<NotificationList>;
|
|
1520
|
+
/** 获取未读通知数量 */
|
|
1521
|
+
getUnreadCount(signal?: AbortSignal): Promise<number>;
|
|
1522
|
+
/** 标记单条通知已读 */
|
|
1523
|
+
markNotificationRead(id: string, signal?: AbortSignal): Promise<void>;
|
|
1524
|
+
/** 标记全部通知已读 */
|
|
1525
|
+
markAllNotificationsRead(signal?: AbortSignal): Promise<void>;
|
|
1526
|
+
/** 删除通知 */
|
|
1527
|
+
deleteNotification(id: string, signal?: AbortSignal): Promise<void>;
|
|
1528
|
+
/** 注册推送设备 token */
|
|
1529
|
+
registerDevice(reg: DeviceRegistration, signal?: AbortSignal): Promise<void>;
|
|
1530
|
+
/** 注销推送设备 token */
|
|
1531
|
+
unregisterDevice(token: string, signal?: AbortSignal): Promise<void>;
|
|
1532
|
+
/** 获取通知偏好设置 */
|
|
1533
|
+
listNotificationPreferences(signal?: AbortSignal): Promise<NotificationPreference[]>;
|
|
1534
|
+
/** 更新通知偏好 */
|
|
1535
|
+
updateNotificationPreference(typeCode: string, pref: NotificationPreference, signal?: AbortSignal): Promise<void>;
|
|
1536
|
+
}
|
|
1300
1537
|
}
|
|
1301
1538
|
|
|
1302
|
-
/**
|
|
1303
|
-
interface
|
|
1304
|
-
|
|
1305
|
-
|
|
1539
|
+
/** WebSocket 长连接配置 */
|
|
1540
|
+
interface WSConfig {
|
|
1541
|
+
/** 收到服务端事件回调 */
|
|
1542
|
+
onEvent?: (ev: WSEvent) => void;
|
|
1543
|
+
/** 连接建立回调 */
|
|
1544
|
+
onConnect?: () => void;
|
|
1545
|
+
/** 断线回调 */
|
|
1546
|
+
onDisconnect?: (err: unknown) => void;
|
|
1547
|
+
/** 自动订阅的主题 */
|
|
1548
|
+
topics?: string[];
|
|
1549
|
+
/** 最小重连间隔 (ms, 默认 2000) */
|
|
1550
|
+
reconnectMinMs?: number;
|
|
1551
|
+
/** 最大重连间隔 (ms, 默认 60000) */
|
|
1552
|
+
reconnectMaxMs?: number;
|
|
1553
|
+
/** 是否自动重连 (默认 true) */
|
|
1554
|
+
autoReconnect?: boolean;
|
|
1555
|
+
}
|
|
1556
|
+
declare module '@acosmi/sdk-ts' {
|
|
1557
|
+
interface Client {
|
|
1558
|
+
/**
|
|
1559
|
+
* 建立 WebSocket 长连接 — 等待首次连接成功或 abort。
|
|
1560
|
+
*/
|
|
1561
|
+
connect(cfg: WSConfig, signal?: AbortSignal): Promise<void>;
|
|
1562
|
+
/** 优雅断开 WebSocket 连接 */
|
|
1563
|
+
disconnect(): Promise<void>;
|
|
1564
|
+
/** WebSocket 是否已连接 */
|
|
1565
|
+
isConnected(): boolean;
|
|
1566
|
+
}
|
|
1306
1567
|
}
|
|
1307
|
-
/**
|
|
1308
|
-
* 按 Anthropic SSE 事件类型解析 data, 更新 blockTypeMap, 返回 [index, type, ephemeral]。
|
|
1309
|
-
*
|
|
1310
|
-
* 仅当事件为 content_block_start / content_block_delta / content_block_stop
|
|
1311
|
-
* 时返回非空 type; 其他事件返回空 type, 调用方据此判别是否填充 StreamEvent 元数据字段。
|
|
1312
|
-
*/
|
|
1313
|
-
declare function extractAnthropicBlockMeta(eventType: string, data: string, blockTypeMap: Map<number, BlockMeta>): [number, string, boolean];
|
|
1314
1568
|
|
|
1315
1569
|
type AgentRunStatus = 'queued' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
1316
1570
|
interface AgentRunLocalContextPolicy {
|
|
@@ -1488,221 +1742,540 @@ declare class AgentRunStreamError extends Error {
|
|
|
1488
1742
|
type: 'error';
|
|
1489
1743
|
}>);
|
|
1490
1744
|
}
|
|
1491
|
-
|
|
1492
|
-
declare module '@acosmi/sdk-ts' {
|
|
1493
|
-
interface Client {
|
|
1494
|
-
/** SDK-facing cloud agent run gateway. */
|
|
1495
|
-
readonly agentRuns: AgentRunsClient;
|
|
1496
|
-
}
|
|
1745
|
+
|
|
1746
|
+
declare module '@acosmi/sdk-ts' {
|
|
1747
|
+
interface Client {
|
|
1748
|
+
/** SDK-facing cloud agent run gateway. */
|
|
1749
|
+
readonly agentRuns: AgentRunsClient;
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
declare class AgentRunsClient {
|
|
1753
|
+
private readonly client;
|
|
1754
|
+
constructor(client: Client);
|
|
1755
|
+
create(req: AgentRunCreateRequest, signal?: AbortSignal): Promise<AgentRunCreateResponse>;
|
|
1756
|
+
get(runId: string, signal?: AbortSignal): Promise<AgentRun>;
|
|
1757
|
+
stream(runId: string, opts?: AgentRunStreamOptions, signal?: AbortSignal): AsyncIterable<AgentRunStreamEvent>;
|
|
1758
|
+
cancel(runId: string, signal?: AbortSignal): Promise<AgentRun>;
|
|
1759
|
+
listArtifacts(runId: string, signal?: AbortSignal): Promise<AgentRunArtifact[]>;
|
|
1760
|
+
downloadArtifact(runId: string, artifactId: string, signal?: AbortSignal): Promise<AgentRunDownload>;
|
|
1761
|
+
submitLocalToolResult(runId: string, result: AgentRunLocalToolResult, signal?: AbortSignal): Promise<AgentRun>;
|
|
1762
|
+
run(req: AgentRunCreateRequest, opts?: AgentRunRunOptions, signal?: AbortSignal): AsyncIterable<AgentRunStreamEvent>;
|
|
1763
|
+
runWithLocalTools(req: AgentRunCreateRequest, handlers: Record<string, AgentRunLocalToolHandler>, opts?: AgentRunWithLocalToolsOptions, signal?: AbortSignal): AsyncIterable<AgentRunStreamEvent>;
|
|
1764
|
+
private runGen;
|
|
1765
|
+
private runWithLocalToolsGen;
|
|
1766
|
+
private invokeLocalTool;
|
|
1767
|
+
private streamGen;
|
|
1768
|
+
private requestAPI;
|
|
1769
|
+
private requestRaw;
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
declare const ScopeComplianceEvidenceRead = "compliance:evidence:read";
|
|
1773
|
+
declare const ScopeComplianceEvidenceWrite = "compliance:evidence:write";
|
|
1774
|
+
declare const ScopeComplianceTimestampIssue = "compliance:timestamp:issue";
|
|
1775
|
+
declare const ScopeComplianceTimestampVerify = "compliance:timestamp:verify";
|
|
1776
|
+
declare const ScopeComplianceContractSigningRead = "compliance:contract_signing:read";
|
|
1777
|
+
declare const ScopeComplianceContractSigningWrite = "compliance:contract_signing:write";
|
|
1778
|
+
declare const ScopeComplianceSealManage = "compliance:seal:manage";
|
|
1779
|
+
declare const ScopeComplianceSealApprovalRequest = "compliance:seal_approval:request";
|
|
1780
|
+
declare const ScopeComplianceSealApprovalApprove = "compliance:seal_approval:approve";
|
|
1781
|
+
declare const ScopeComplianceSealUseExecute = "compliance:seal_use:execute";
|
|
1782
|
+
declare const ScopeComplianceReportsRead = "compliance:reports:read";
|
|
1783
|
+
declare const ScopeComplianceReportsWrite = "compliance:reports:write";
|
|
1784
|
+
declare const ScopeComplianceReportsPublish = "compliance:reports:publish";
|
|
1785
|
+
/** 类型联合:合规域细粒度 scope。Java compliance verifier 只按细粒度匹配, 不做分组展开。 */
|
|
1786
|
+
type ComplianceScope = typeof ScopeComplianceEvidenceRead | typeof ScopeComplianceEvidenceWrite | typeof ScopeComplianceTimestampIssue | typeof ScopeComplianceTimestampVerify | typeof ScopeComplianceContractSigningRead | typeof ScopeComplianceContractSigningWrite | typeof ScopeComplianceSealManage | typeof ScopeComplianceSealApprovalRequest | typeof ScopeComplianceSealApprovalApprove | typeof ScopeComplianceSealUseExecute | typeof ScopeComplianceReportsRead | typeof ScopeComplianceReportsWrite | typeof ScopeComplianceReportsPublish;
|
|
1787
|
+
/** 全部合规域 scope。OAuth 申请合规权限时使用; 谨慎一次性申请全部, 推荐按业务最小集合申请。 */
|
|
1788
|
+
declare function complianceScopes(): ComplianceScope[];
|
|
1789
|
+
|
|
1790
|
+
/**
|
|
1791
|
+
* Compliance envelope 稳定业务状态。
|
|
1792
|
+
*
|
|
1793
|
+
* 字面量与 Java {@code EnvelopeStatusEnum} 的 `name()` 一致(这是 enum,是 wire 上的实际
|
|
1794
|
+
* 字符串);前端按这些字符串分支展示文案。
|
|
1795
|
+
*/
|
|
1796
|
+
type ComplianceEnvelopeStatus = 'DRAFT' | 'CONTRACT_READY' | 'APPROVED' | 'SIGN_PENDING' | 'PENDING_EVIDENCE' | 'PENDING_RECONCILIATION' | 'SUCCESS' | 'FAILED' | 'CANCELED';
|
|
1797
|
+
/** Compliance 用印审批稳定状态。 */
|
|
1798
|
+
type ComplianceSealApprovalStatus = 'DRAFT' | 'SUBMITTED' | 'APPROVED' | 'REJECTED' | 'CANCELED' | 'USED' | 'EXPIRED';
|
|
1799
|
+
/** Provider 业务状态(前端可见的脱敏视图,不暴露下游内部字段)。 */
|
|
1800
|
+
type ComplianceProviderStatus = 'pending' | 'success' | 'failed' | 'unknown' | 'retrying';
|
|
1801
|
+
/**
|
|
1802
|
+
* 计费 / 履约的对外稳定状态视图。distribution compliance-billing 内部 API
|
|
1803
|
+
* (quote/reserve/commit/cancel/reconcile) 不暴露给前端 — 前端只能看见这 4 个语义。
|
|
1804
|
+
*/
|
|
1805
|
+
type ComplianceBillingDisplayStatus = 'reserved' | 'committed' | 'canceled' | 'pending_reconciliation';
|
|
1806
|
+
/** 高风险动作 step-up — 重新做 OAuth introspection 或重新登录,提升 token 等级后再尝试。 */
|
|
1807
|
+
declare const ErrComplianceStepUpRequired = "COMPLIANCE_STEP_UP_REQUIRED";
|
|
1808
|
+
/** envelope 闸门关闭 — 审批 gate 等条件未同时就绪,前端展示"功能开放中"。 */
|
|
1809
|
+
declare const ErrEnvelopeGateClosed = "ENVELOPE_GATE_CLOSED";
|
|
1810
|
+
/** 履约 provider 未配置 — 受控环境材料缺失时业务路径会一致拒绝,不要前端重试。 */
|
|
1811
|
+
declare const ErrProviderNotConfigured = "PROVIDER_NOT_CONFIGURED";
|
|
1812
|
+
/** Provider 返回 unknown / retrying — 客户必须等待对账,前端展示"处理中(人工核对)"。 */
|
|
1813
|
+
declare const ErrProviderUnknownNoRetry = "PROVIDER_REQUEST_UNKNOWN_NO_RETRY";
|
|
1814
|
+
/** callback 不能直接确认扣费 — 后端守门,前端无需处理,记录到审计日志展示即可。 */
|
|
1815
|
+
declare const ErrBillingCallbackCannotCommit = "BILLING_CALLBACK_CANNOT_COMMIT";
|
|
1816
|
+
/** provider 成功但本地未验证通过,不允许扣费。 */
|
|
1817
|
+
declare const ErrBillingCommitRequiresLocalVerify = "BILLING_COMMIT_REQUIRES_LOCAL_VERIFY";
|
|
1818
|
+
/** distribution compliance-billing 必须 S2S — 前端误调用时拿到该错误码,禁止 retry。 */
|
|
1819
|
+
declare const ErrBillingS2sForbidden = "BILLING_S2S_FORBIDDEN";
|
|
1820
|
+
/** 审批 gate 各类失败语义(前端展示"审批中 / 审批已用 / 审批失效")。 */
|
|
1821
|
+
declare const ErrSealApprovalNotApproved = "SEAL_APPROVAL_STATE_NOT_APPROVED";
|
|
1822
|
+
declare const ErrSealApprovalExpired = "SEAL_APPROVAL_EXPIRED";
|
|
1823
|
+
declare const ErrSealApprovalNonceUsed = "SEAL_APPROVAL_NONCE_USED";
|
|
1824
|
+
declare const ErrSealApprovalContractHashMismatch = "SEAL_APPROVAL_CONTRACT_HASH_MISMATCH";
|
|
1825
|
+
declare const ErrSealApprovalSealMismatch = "SEAL_APPROVAL_SEAL_MISMATCH";
|
|
1826
|
+
declare const ErrSealApprovalLocationMismatch = "SEAL_APPROVAL_LOCATION_MISMATCH";
|
|
1827
|
+
declare const ErrSealApprovalTransactorMismatch = "SEAL_APPROVAL_TRANSACTOR_MISMATCH";
|
|
1828
|
+
/** 用印重复消费防护 — 前端遇到该错误必须刷新审批单状态,不允许"换一次 nonce 再试"。 */
|
|
1829
|
+
declare const ErrSealUseAlreadyConsumed = "SEAL_USE_ALREADY_CONSUMED";
|
|
1830
|
+
/** 该错误码联合用于前端选择性展示文案;非穷举式 enum,后端保留新增空间。 */
|
|
1831
|
+
type ComplianceClientErrorCode = typeof ErrComplianceStepUpRequired | typeof ErrEnvelopeGateClosed | typeof ErrProviderNotConfigured | typeof ErrProviderUnknownNoRetry | typeof ErrBillingCallbackCannotCommit | typeof ErrBillingCommitRequiresLocalVerify | typeof ErrBillingS2sForbidden | typeof ErrSealApprovalNotApproved | typeof ErrSealApprovalExpired | typeof ErrSealApprovalNonceUsed | typeof ErrSealApprovalContractHashMismatch | typeof ErrSealApprovalSealMismatch | typeof ErrSealApprovalLocationMismatch | typeof ErrSealApprovalTransactorMismatch | typeof ErrSealUseAlreadyConsumed;
|
|
1832
|
+
/**
|
|
1833
|
+
* 判定一个错误码是否属于"需要前端引导用户重新认证/审批"的高级语义,
|
|
1834
|
+
* 而不是简单 retry。这类错误前端不允许在 UI 层做自动重试。
|
|
1835
|
+
*/
|
|
1836
|
+
declare function isComplianceTerminalError(code: string): boolean;
|
|
1837
|
+
/**
|
|
1838
|
+
* "是否允许在 UI 上呈现为'扣费已确认'"的判定。
|
|
1839
|
+
* provider 状态为 unknown / retrying / pending 时一律不展示为已确认。
|
|
1840
|
+
*/
|
|
1841
|
+
declare function isBillingConfirmable(providerStatus: ComplianceProviderStatus | undefined, billingStatus: ComplianceBillingDisplayStatus | undefined): boolean;
|
|
1842
|
+
|
|
1843
|
+
/** Compliance 写操作选项;写操作不自动 retry,不自动 401 重放。 */
|
|
1844
|
+
interface ComplianceWriteOptions {
|
|
1845
|
+
/**
|
|
1846
|
+
* 调用方稳定的幂等键。写操作强烈建议持久化;缺省时服务端按 UUID 兜底,但调用方
|
|
1847
|
+
* 在重试 / 恢复时无法对账。
|
|
1848
|
+
*/
|
|
1849
|
+
idempotencyKey?: string;
|
|
1850
|
+
signal?: AbortSignal;
|
|
1851
|
+
}
|
|
1852
|
+
/** 轮询参数(exponential backoff)。 */
|
|
1853
|
+
interface CompliancePollOptions {
|
|
1854
|
+
/** 总超时(ms),缺省 60s。 */
|
|
1855
|
+
timeoutMs?: number;
|
|
1856
|
+
/** 初始 interval(ms),缺省 1000。 */
|
|
1857
|
+
initialIntervalMs?: number;
|
|
1858
|
+
/** interval 倍增上限(ms),缺省 5000。 */
|
|
1859
|
+
maxIntervalMs?: number;
|
|
1860
|
+
/** 倍增系数,缺省 1.5。 */
|
|
1861
|
+
multiplier?: number;
|
|
1862
|
+
signal?: AbortSignal;
|
|
1863
|
+
}
|
|
1864
|
+
|
|
1865
|
+
type ComplianceAssetType = 'CONTRACT' | 'CODE' | 'IMAGE' | 'DOCUMENT' | 'ARCHIVE' | 'HASH_ONLY' | 'URL_SNAPSHOT' | 'RELEASE' | 'LOG' | 'OTHER';
|
|
1866
|
+
type ComplianceHashAlgorithm = 'sha256' | 'sha512' | 'sm3';
|
|
1867
|
+
type ComplianceDigestSource = 'CLIENT' | 'COMPLIANCE_SERVICE' | 'PROVIDER';
|
|
1868
|
+
type CompliancePrivacyLevel = 'public' | 'private';
|
|
1869
|
+
/** 证据资产对外稳定视图。对应后端 EvidenceAssetRespVO。 */
|
|
1870
|
+
interface EvidenceAsset {
|
|
1871
|
+
id: number;
|
|
1872
|
+
/** 业务编号;SDK / 前端引用时优先使用 evidenceNo。 */
|
|
1873
|
+
evidenceNo: string;
|
|
1874
|
+
/** publish 后的公开 verify code;DRAFT / 非 public privacy 时为 null。 */
|
|
1875
|
+
publicVerifyCode?: string | null;
|
|
1876
|
+
assetType: ComplianceAssetType | string;
|
|
1877
|
+
name: string;
|
|
1878
|
+
mimeType?: string | null;
|
|
1879
|
+
size?: number | null;
|
|
1880
|
+
hashAlgorithm: ComplianceHashAlgorithm | string;
|
|
1881
|
+
/** 资产 hash(hex 字符串)。 */
|
|
1882
|
+
contentHash: string;
|
|
1883
|
+
canonicalizationProfile?: string | null;
|
|
1884
|
+
digestSource: ComplianceDigestSource | string;
|
|
1885
|
+
privacyLevel: CompliancePrivacyLevel | string;
|
|
1886
|
+
status: string;
|
|
1887
|
+
}
|
|
1888
|
+
/** 创建证据资产请求;与 Java EvidenceAssetCreateReq 对齐。 */
|
|
1889
|
+
interface CreateEvidenceAssetRequest {
|
|
1890
|
+
/** AssetTypeEnum.name()。 */
|
|
1891
|
+
assetType: ComplianceAssetType | string;
|
|
1892
|
+
name: string;
|
|
1893
|
+
mimeType?: string;
|
|
1894
|
+
/** 'sha256' / 'sha512' / 'sm3'。 */
|
|
1895
|
+
hashAlgorithm: ComplianceHashAlgorithm | string;
|
|
1896
|
+
/** hex 字符串;hash-only 资产必填。 */
|
|
1897
|
+
declaredHash?: string;
|
|
1898
|
+
/** CLIENT / COMPLIANCE_SERVICE / PROVIDER。 */
|
|
1899
|
+
digestSource?: ComplianceDigestSource | string;
|
|
1900
|
+
/** 原文 base64;hash-only 时缺省即可。 */
|
|
1901
|
+
contentBase64?: string;
|
|
1902
|
+
/** public / private(默认 private)。 */
|
|
1903
|
+
privacyLevel?: CompliancePrivacyLevel | string;
|
|
1904
|
+
source?: string;
|
|
1905
|
+
}
|
|
1906
|
+
/** 公开 verify 结果。隐私边界:不暴露 PII / 合同原文 / storage / provider raw。 */
|
|
1907
|
+
interface PublicEvidenceVerifyResult {
|
|
1908
|
+
evidenceNo: string;
|
|
1909
|
+
assetType: string;
|
|
1910
|
+
hashAlgorithm: string;
|
|
1911
|
+
contentHash: string;
|
|
1912
|
+
size?: number | null;
|
|
1913
|
+
canonicalizationProfile?: string | null;
|
|
1914
|
+
verifiedAt: string;
|
|
1915
|
+
packageId?: number | null;
|
|
1916
|
+
manifestHash?: string | null;
|
|
1917
|
+
packageHash?: string | null;
|
|
1918
|
+
manifestOfflineVerify: boolean;
|
|
1919
|
+
}
|
|
1920
|
+
interface EvidencePackage {
|
|
1921
|
+
id: number;
|
|
1922
|
+
assetId: number;
|
|
1923
|
+
timestampTokenId?: number | null;
|
|
1924
|
+
chainId: string;
|
|
1925
|
+
packageVersion: string;
|
|
1926
|
+
hashAlgorithm: string;
|
|
1927
|
+
manifestHash: string;
|
|
1928
|
+
packageHash: string;
|
|
1929
|
+
status: string;
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
type ComplianceTimestampVerificationStatus = 'PENDING' | 'VERIFIED' | 'FAILED' | 'LOCAL_VERIFY_FAILED' | 'UNKNOWN' | 'RETRYING';
|
|
1933
|
+
/** 时间章 token 对外视图(不含 provider/object/tsa 内部字段)。 */
|
|
1934
|
+
interface TimestampToken {
|
|
1935
|
+
id: number;
|
|
1936
|
+
assetId: number;
|
|
1937
|
+
policyOid?: string | null;
|
|
1938
|
+
serialNumber?: string | null;
|
|
1939
|
+
/** gen_time ISO-8601;UNKNOWN/PENDING 状态可能为 null。 */
|
|
1940
|
+
genTime?: string | null;
|
|
1941
|
+
accuracy?: string | null;
|
|
1942
|
+
verificationStatus: ComplianceTimestampVerificationStatus | string;
|
|
1943
|
+
verifiedAt?: string | null;
|
|
1944
|
+
verificationError?: string | null;
|
|
1945
|
+
}
|
|
1946
|
+
/** 申请时间章请求。`provider` 字段已从服务端契约下线;SDK 永远不传。 */
|
|
1947
|
+
interface IssueTimestampRequest {
|
|
1948
|
+
name?: string;
|
|
1949
|
+
mimeType?: string;
|
|
1950
|
+
hashAlgorithm: ComplianceHashAlgorithm | string;
|
|
1951
|
+
/** 客户端声明 digest(hex);contentBase64 非空时作为校验值。 */
|
|
1952
|
+
digest?: string;
|
|
1953
|
+
contentBase64?: string;
|
|
1497
1954
|
}
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
create(req: AgentRunCreateRequest, signal?: AbortSignal): Promise<AgentRunCreateResponse>;
|
|
1502
|
-
get(runId: string, signal?: AbortSignal): Promise<AgentRun>;
|
|
1503
|
-
stream(runId: string, opts?: AgentRunStreamOptions, signal?: AbortSignal): AsyncIterable<AgentRunStreamEvent>;
|
|
1504
|
-
cancel(runId: string, signal?: AbortSignal): Promise<AgentRun>;
|
|
1505
|
-
listArtifacts(runId: string, signal?: AbortSignal): Promise<AgentRunArtifact[]>;
|
|
1506
|
-
downloadArtifact(runId: string, artifactId: string, signal?: AbortSignal): Promise<AgentRunDownload>;
|
|
1507
|
-
submitLocalToolResult(runId: string, result: AgentRunLocalToolResult, signal?: AbortSignal): Promise<AgentRun>;
|
|
1508
|
-
run(req: AgentRunCreateRequest, opts?: AgentRunRunOptions, signal?: AbortSignal): AsyncIterable<AgentRunStreamEvent>;
|
|
1509
|
-
runWithLocalTools(req: AgentRunCreateRequest, handlers: Record<string, AgentRunLocalToolHandler>, opts?: AgentRunWithLocalToolsOptions, signal?: AbortSignal): AsyncIterable<AgentRunStreamEvent>;
|
|
1510
|
-
private runGen;
|
|
1511
|
-
private runWithLocalToolsGen;
|
|
1512
|
-
private invokeLocalTool;
|
|
1513
|
-
private streamGen;
|
|
1514
|
-
private requestAPI;
|
|
1515
|
-
private requestRaw;
|
|
1955
|
+
/** verify 请求 / 结果。 */
|
|
1956
|
+
interface VerifyTimestampRequest {
|
|
1957
|
+
tokenId: number;
|
|
1516
1958
|
}
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
/** 合并两个字符串数组并去重, 保留顺序 */
|
|
1521
|
-
declare function uniqueMerge(base: string[], extra: string[]): string[];
|
|
1522
|
-
|
|
1523
|
-
declare module '@acosmi/sdk-ts' {
|
|
1524
|
-
interface Client {
|
|
1525
|
-
/** 查询当前用户的权益余额 (聚合) */
|
|
1526
|
-
getBalance(signal?: AbortSignal): Promise<EntitlementBalance>;
|
|
1527
|
-
/** 查询详细余额 (含每条权益明细) */
|
|
1528
|
-
getBalanceDetail(signal?: AbortSignal): Promise<BalanceDetail>;
|
|
1529
|
-
/** 查询当前用户权益列表; status: "ACTIVE" / "EXPIRED" / "" (全部) */
|
|
1530
|
-
listEntitlements(status: string, signal?: AbortSignal): Promise<EntitlementItem[]>;
|
|
1531
|
-
/** 查询核销记录 (分页) */
|
|
1532
|
-
listConsumeRecords(page: number, pageSize: number, signal?: AbortSignal): Promise<ConsumeRecordPage>;
|
|
1533
|
-
/** 领取当月免费额度 — 幂等: 已领取时返回已有权益 */
|
|
1534
|
-
claimMonthlyFree(signal?: AbortSignal): Promise<EntitlementItem>;
|
|
1535
|
-
/** 查询当前用户在指定模型下的剩余 token (raw + ETU) */
|
|
1536
|
-
getByModel(modelID: string, signal?: AbortSignal): Promise<ModelByQuotaResponse>;
|
|
1537
|
-
/** 列出当前用户的全部桶 */
|
|
1538
|
-
listBuckets(signal?: AbortSignal): Promise<ModelBucket[]>;
|
|
1539
|
-
/** 拉取模型系数表; SDK 自带 8s TTL 内存缓存以减小调用风暴. */
|
|
1540
|
-
listCoefficients(signal?: AbortSignal): Promise<ModelCoefficient[]>;
|
|
1541
|
-
/** 手动失效系数缓存 (admin 调价后建议立即调一次) */
|
|
1542
|
-
invalidateCoefficientCache(): void;
|
|
1543
|
-
}
|
|
1959
|
+
interface TimestampVerifyResult {
|
|
1960
|
+
passed: boolean;
|
|
1961
|
+
reason: string;
|
|
1544
1962
|
}
|
|
1545
1963
|
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1964
|
+
interface ComplianceReport {
|
|
1965
|
+
id: number;
|
|
1966
|
+
reportNo: string;
|
|
1967
|
+
reportType: string;
|
|
1968
|
+
status: string;
|
|
1969
|
+
assetId?: number | null;
|
|
1970
|
+
packageId?: number | null;
|
|
1971
|
+
publicUrlToken?: string | null;
|
|
1972
|
+
publishedAt?: string | null;
|
|
1973
|
+
bodyHash?: string | null;
|
|
1974
|
+
}
|
|
1975
|
+
interface CreateReportRequest {
|
|
1976
|
+
assetId: number;
|
|
1977
|
+
packageId: number;
|
|
1978
|
+
}
|
|
1979
|
+
/** 离线复核下载 VO;建议调用方持久化作为长期可重复验证依据。 */
|
|
1980
|
+
interface ReportDownload {
|
|
1981
|
+
id: number;
|
|
1982
|
+
reportNo: string;
|
|
1983
|
+
reportType: string;
|
|
1984
|
+
status: string;
|
|
1985
|
+
bodyHash?: string | null;
|
|
1986
|
+
publishedAt?: string | null;
|
|
1987
|
+
assetEvidenceNo?: string | null;
|
|
1988
|
+
assetHashAlgorithm?: string | null;
|
|
1989
|
+
assetContentHash?: string | null;
|
|
1990
|
+
packageManifestHash?: string | null;
|
|
1991
|
+
packageHash?: string | null;
|
|
1992
|
+
packageHashAlgorithm?: string | null;
|
|
1993
|
+
timestampSerialNumber?: string | null;
|
|
1994
|
+
timestampGenTime?: string | null;
|
|
1995
|
+
timestampVerificationStatus?: string | null;
|
|
1565
1996
|
}
|
|
1566
1997
|
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1998
|
+
interface SigningEnvelope {
|
|
1999
|
+
id: number;
|
|
2000
|
+
envelopeNo: string;
|
|
2001
|
+
applicantUserId?: string | null;
|
|
2002
|
+
status: string;
|
|
2003
|
+
primaryContractId?: number | null;
|
|
2004
|
+
contractHash?: string | null;
|
|
2005
|
+
hashAlgorithm?: string | null;
|
|
2006
|
+
billingGroupId?: string | null;
|
|
2007
|
+
chainId?: string | null;
|
|
2008
|
+
requestId?: string | null;
|
|
2009
|
+
pendingReason?: string | null;
|
|
2010
|
+
signedAt?: string | null;
|
|
2011
|
+
evidenceReadyAt?: string | null;
|
|
2012
|
+
committedAt?: string | null;
|
|
2013
|
+
}
|
|
2014
|
+
/** 创建 envelope 请求;只保留调用方业务字段,内部主体快照和履约通道由后端推导。 */
|
|
2015
|
+
interface CreateSigningEnvelopeRequest {
|
|
2016
|
+
envelopeNo?: string;
|
|
2017
|
+
requestId?: string;
|
|
2018
|
+
/** 调用方稳定 idempotency-key(不传则由 Idempotency-Key header 兜底)。 */
|
|
2019
|
+
idempotencyKey?: string;
|
|
2020
|
+
billingGroupId?: string;
|
|
2021
|
+
chainId?: string;
|
|
2022
|
+
}
|
|
2023
|
+
/** sign 请求;service 默认闸门关闭,SDK 写示例必须处理 ENVELOPE_GATE_CLOSED 错误。 */
|
|
2024
|
+
interface SignEnvelopeRequest {
|
|
2025
|
+
approvalRequestId?: number;
|
|
2026
|
+
contractId?: number;
|
|
2027
|
+
contractHash?: string;
|
|
2028
|
+
sealId?: number;
|
|
2029
|
+
signLocationType?: string;
|
|
2030
|
+
signLocationPayload?: string;
|
|
2031
|
+
transactorId?: number;
|
|
2032
|
+
requestId?: string;
|
|
2033
|
+
idempotencyKey?: string;
|
|
2034
|
+
}
|
|
2035
|
+
/** H5 短链请求。 */
|
|
2036
|
+
interface CreateH5SigningUrlRequest extends SignEnvelopeRequest {
|
|
1574
2037
|
}
|
|
1575
2038
|
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
}
|
|
2039
|
+
interface SealApproval {
|
|
2040
|
+
id: number;
|
|
2041
|
+
envelopeId?: number | null;
|
|
2042
|
+
contractId?: number | null;
|
|
2043
|
+
contractHash?: string | null;
|
|
2044
|
+
hashAlgorithm?: string | null;
|
|
2045
|
+
sealId?: number | null;
|
|
2046
|
+
applicantUserId?: string | null;
|
|
2047
|
+
approverUserId?: string | null;
|
|
2048
|
+
transactorId?: number | null;
|
|
2049
|
+
signLocationType?: string | null;
|
|
2050
|
+
signLocationPayload?: string | null;
|
|
2051
|
+
reason?: string | null;
|
|
2052
|
+
expiresAt?: string | null;
|
|
2053
|
+
status: string;
|
|
2054
|
+
approvedAt?: string | null;
|
|
2055
|
+
rejectedAt?: string | null;
|
|
2056
|
+
canceledAt?: string | null;
|
|
2057
|
+
}
|
|
2058
|
+
/** 提交审批;provider 侧字段由后端归一,SDK 调用方不传。 */
|
|
2059
|
+
interface SubmitSealApprovalRequest {
|
|
2060
|
+
envelopeId?: number;
|
|
2061
|
+
contractId?: number;
|
|
2062
|
+
contractHash?: string;
|
|
2063
|
+
hashAlgorithm?: string;
|
|
2064
|
+
sealId?: number;
|
|
2065
|
+
approverUserId?: string;
|
|
2066
|
+
transactorId?: number;
|
|
2067
|
+
signLocationType?: string;
|
|
2068
|
+
signLocationPayload?: string;
|
|
2069
|
+
reason?: string;
|
|
2070
|
+
}
|
|
2071
|
+
interface ApproveSealApprovalQuery {
|
|
2072
|
+
expiresAt?: string;
|
|
2073
|
+
note?: string;
|
|
2074
|
+
}
|
|
2075
|
+
interface RejectSealApprovalQuery {
|
|
2076
|
+
reason?: string;
|
|
2077
|
+
}
|
|
2078
|
+
interface CancelSealApprovalQuery {
|
|
2079
|
+
reason?: string;
|
|
1618
2080
|
}
|
|
1619
2081
|
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
2082
|
+
type ComplianceProviderRequestStatus = 'PENDING' | 'SUCCESS' | 'FAILED' | 'UNKNOWN' | 'RETRYING';
|
|
2083
|
+
interface ProviderRequestStatusView {
|
|
2084
|
+
id: number;
|
|
2085
|
+
status: ComplianceProviderRequestStatus | string;
|
|
2086
|
+
/** SUCCESS / FAILED 终态。 */
|
|
2087
|
+
terminal: boolean;
|
|
2088
|
+
/** 当前状态是否允许 SDK 安全重试请求(仅对 RETRYING 为 true)。 */
|
|
2089
|
+
retryable: boolean;
|
|
2090
|
+
businessNo?: string | null;
|
|
2091
|
+
contractNo?: string | null;
|
|
2092
|
+
sealId?: string | null;
|
|
2093
|
+
attemptCount?: number | null;
|
|
2094
|
+
reconciliationStatus?: string | null;
|
|
2095
|
+
nextRetryAt?: string | null;
|
|
2096
|
+
requestedAt?: string | null;
|
|
2097
|
+
respondedAt?: string | null;
|
|
1627
2098
|
}
|
|
1628
2099
|
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
/** 更新通知偏好 */
|
|
1648
|
-
updateNotificationPreference(typeCode: string, pref: NotificationPreference, signal?: AbortSignal): Promise<void>;
|
|
1649
|
-
}
|
|
2100
|
+
/**
|
|
2101
|
+
* SDK 内部 symbolic key;用于代码分支判断与文档。**不是 wire contract**。
|
|
2102
|
+
*/
|
|
2103
|
+
type ComplianceErrorKey = 'COMPLIANCE_UNAUTHORIZED' | 'COMPLIANCE_INSUFFICIENT_SCOPE' | 'COMPLIANCE_STEP_UP_REQUIRED' | 'COMPLIANCE_TOKEN_INVALID' | 'SUBJECT_SNAPSHOT_REQUIRED' | 'SUBJECT_SNAPSHOT_NOT_FOUND' | 'SUBJECT_SNAPSHOT_TENANT_MISMATCH' | 'EVIDENCE_ASSET_NOT_FOUND' | 'EVIDENCE_ASSET_HASH_MISMATCH' | 'EVIDENCE_ASSET_PAYLOAD_REQUIRED' | 'TIMESTAMP_TOKEN_NOT_FOUND' | 'TIMESTAMP_PROVIDER_FAILED' | 'TIMESTAMP_PROVIDER_UNKNOWN' | 'TIMESTAMP_LOCAL_VERIFY_FAILED' | 'TIMESTAMP_PROVIDER_NOT_AVAILABLE' | 'EVIDENCE_PACKAGE_NOT_FOUND' | 'EVIDENCE_PACKAGE_TIMESTAMP_REQUIRED' | 'EVIDENCE_PACKAGE_MANIFEST_HASH_MISMATCH' | 'REPORT_NOT_FOUND' | 'REPORT_ALREADY_PUBLISHED' | 'REPORT_DRAFT_REQUIRED' | 'EVIDENCE_VERIFY_TARGET_REQUIRED' | 'EVIDENCE_VERIFY_TARGET_NOT_FOUND' | 'PROVIDER_REQUEST_UNKNOWN_NO_RETRY' | 'PROVIDER_CALLBACK_SOURCE_INVALID' | 'PROVIDER_NOT_CONFIGURED' | 'PROVIDER_REQUEST_NOT_FOUND' | 'PROVIDER_REQUEST_IDEMPOTENCY_REQUIRED' | 'PROVIDER_REQUEST_STATUS_NOT_TERMINAL' | 'ENVELOPE_NOT_FOUND' | 'ENVELOPE_TENANT_MISMATCH' | 'ENVELOPE_STATE_NOT_ALLOWED' | 'ENVELOPE_GATE_CLOSED' | 'CONTRACT_NOT_FOUND' | 'CONTRACT_HASH_MISMATCH' | 'PROVIDER_AUTHORIZATION_NOT_CONFIRMED' | 'ENVELOPE_EVIDENCE_NOT_READY' | 'SEAL_ASSET_NOT_FOUND' | 'SEAL_APPROVAL_NOT_FOUND' | 'SEAL_APPROVAL_STATE_NOT_APPROVED' | 'SEAL_APPROVAL_EXPIRED' | 'SEAL_APPROVAL_ALREADY_USED' | 'SEAL_APPROVAL_NONCE_USED' | 'SEAL_APPROVAL_SEAL_MISMATCH' | 'SEAL_APPROVAL_LOCATION_MISMATCH' | 'SEAL_APPROVAL_TRANSACTOR_MISMATCH' | 'SEAL_APPROVAL_CONTRACT_HASH_MISMATCH' | 'SEAL_APPROVAL_INVALID_TRANSITION' | 'SEAL_USE_ALREADY_CONSUMED' | 'AUDIT_CHAIN_TAMPER_DETECTED' | 'BILLING_COMMIT_REQUIRES_LOCAL_VERIFY' | 'BILLING_COMMIT_REQUIRES_PROVIDER_SUCCESS' | 'BILLING_CALLBACK_CANNOT_COMMIT' | 'BILLING_PROVIDER_UNKNOWN_NOT_COMMITTABLE' | 'BILLING_S2S_FORBIDDEN' | 'UNKNOWN_COMPLIANCE_ERROR';
|
|
2104
|
+
/** 单个错误的 SDK 视图。 */
|
|
2105
|
+
interface ComplianceErrorInfo {
|
|
2106
|
+
/** Java numeric error code (wire contract)。 */
|
|
2107
|
+
code: number;
|
|
2108
|
+
/** 服务端原始 message(中文,可变);仅用于日志/展示。 */
|
|
2109
|
+
message: string;
|
|
2110
|
+
/** SDK 分支判断用 symbolic key。 */
|
|
2111
|
+
key: ComplianceErrorKey;
|
|
2112
|
+
/** 是否安全自动重试 — compliance 写接口几乎全为 false。 */
|
|
2113
|
+
retryable: boolean;
|
|
2114
|
+
/** 是否已经是终态 — 用户必须用新 idempotency-key 重新发起。 */
|
|
2115
|
+
terminal: boolean;
|
|
2116
|
+
/** 高风险动作需要 step-up / introspection。 */
|
|
2117
|
+
stepUpRequired: boolean;
|
|
1650
2118
|
}
|
|
2119
|
+
/**
|
|
2120
|
+
* 把一个 BusinessError 分类为 compliance 视图。
|
|
2121
|
+
* 非 compliance 段位的错误码会回退到 UNKNOWN_COMPLIANCE_ERROR,调用方应该当作业务错误处理。
|
|
2122
|
+
*/
|
|
2123
|
+
declare function classifyComplianceError(err: BusinessError): ComplianceErrorInfo;
|
|
2124
|
+
/**
|
|
2125
|
+
* 判断 BusinessError 是否属于 compliance 段位(1-031-xxx-xxx)。
|
|
2126
|
+
* 不在段位的错误码可能来自其它 yudao 模块,按通用业务错误处理即可。
|
|
2127
|
+
*/
|
|
2128
|
+
declare function isComplianceBusinessError(err: BusinessError): boolean;
|
|
1651
2129
|
|
|
1652
2130
|
declare module '@acosmi/sdk-ts' {
|
|
1653
2131
|
interface Client {
|
|
1654
|
-
/**
|
|
1655
|
-
|
|
1656
|
-
* 传空值 {} 关闭 (所有字段为零 = 禁用)。
|
|
1657
|
-
* 并发安全, 可在任意时间调用。
|
|
1658
|
-
*/
|
|
1659
|
-
setDefensiveSanitize(cfg: MinimalSanitizeConfig): void;
|
|
1660
|
-
/**
|
|
1661
|
-
* 开启后, 每次请求前 SDK 会从 rawMessages 中剥除带 acosmi_ephemeral:true 标记的 block,
|
|
1662
|
-
* 并联动剥除引用已剥 tool_use 的 tool_result, 避免 provider 报 "tool_use_id 不存在".
|
|
1663
|
-
*
|
|
1664
|
-
* 标记来源: 网关在响应 content_block_start 中 in-band 注入; 消费者把上一轮 assistant
|
|
1665
|
-
* 回复原样拼回 history 即可触发剥离。
|
|
1666
|
-
*/
|
|
1667
|
-
setAutoStripEphemeralHistory(on: boolean): void;
|
|
1668
|
-
/**
|
|
1669
|
-
* 在 buildChatRequest 开头调用, 把配置化的防御策略应用到 req。
|
|
1670
|
-
* 未配置时立即返回, 零开销。
|
|
1671
|
-
*
|
|
1672
|
-
* 失败时抛错 — 调用方应放弃本次请求。
|
|
1673
|
-
*/
|
|
1674
|
-
applyRequestSanitizers(req: ChatRequest): void;
|
|
2132
|
+
/** SDK-facing 时间章与电子证据 / 合同签署能力。 */
|
|
2133
|
+
readonly compliance: ComplianceClient;
|
|
1675
2134
|
}
|
|
1676
2135
|
}
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
topics?: string[];
|
|
1688
|
-
/** 最小重连间隔 (ms, 默认 2000) */
|
|
1689
|
-
reconnectMinMs?: number;
|
|
1690
|
-
/** 最大重连间隔 (ms, 默认 60000) */
|
|
1691
|
-
reconnectMaxMs?: number;
|
|
1692
|
-
/** 是否自动重连 (默认 true) */
|
|
1693
|
-
autoReconnect?: boolean;
|
|
2136
|
+
/**
|
|
2137
|
+
* 当 compliance polling 检测到终态失败 / 已过 timeout / step-up 时抛出。
|
|
2138
|
+
*
|
|
2139
|
+
* 分类逻辑:终态失败优先于 timeout;timeout 不算 retryable,调用方必须用新 idempotency-key
|
|
2140
|
+
* 重新发起整条链路。
|
|
2141
|
+
*/
|
|
2142
|
+
declare class CompliancePollError extends Error {
|
|
2143
|
+
readonly kind: 'timeout' | 'terminal_failure' | 'step_up_required' | 'unknown';
|
|
2144
|
+
readonly lastInfo?: ComplianceErrorInfo;
|
|
2145
|
+
constructor(message: string, kind: 'timeout' | 'terminal_failure' | 'step_up_required' | 'unknown', lastInfo?: ComplianceErrorInfo);
|
|
1694
2146
|
}
|
|
1695
|
-
declare
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
2147
|
+
declare class ComplianceClient {
|
|
2148
|
+
private readonly client;
|
|
2149
|
+
constructor(client: Client);
|
|
2150
|
+
/** 创建证据资产(写)。 */
|
|
2151
|
+
createEvidenceAsset(req: CreateEvidenceAssetRequest, opts?: ComplianceWriteOptions): Promise<EvidenceAsset>;
|
|
2152
|
+
/** 读 — 证据资产详情。 */
|
|
2153
|
+
getEvidenceAsset(id: number, signal?: AbortSignal): Promise<EvidenceAsset>;
|
|
2154
|
+
/**
|
|
2155
|
+
* 公开 verify。隐私边界:返回字段不含 PII / 合同原文 / storage / provider raw。
|
|
2156
|
+
*
|
|
2157
|
+
* 匿名可调用:未 login 时走匿名请求,不会抛 `not authorized, call login() first`。
|
|
2158
|
+
* 已 login / 已持有 token 时附带 `Authorization` 以保留审计上下文。public 端点不
|
|
2159
|
+
* 应要求认证 — 收到 401 直接抛 HTTPError,不触发 `forceRefresh`,也不做 refresh
|
|
2160
|
+
* replay。
|
|
2161
|
+
*/
|
|
2162
|
+
verifyEvidencePublic(params: {
|
|
2163
|
+
evidenceNo?: string;
|
|
2164
|
+
publicVerifyCode?: string;
|
|
2165
|
+
}, signal?: AbortSignal): Promise<PublicEvidenceVerifyResult>;
|
|
2166
|
+
/** 申请时间章(写)。SDK 永远不传 provider 字段。 */
|
|
2167
|
+
issueTimestamp(req: IssueTimestampRequest, opts?: ComplianceWriteOptions): Promise<TimestampToken>;
|
|
2168
|
+
/** 给已有资产申请时间章。SDK 永远不传 provider 字段。 */
|
|
2169
|
+
issueTimestampForAsset(assetId: number, opts?: ComplianceWriteOptions): Promise<TimestampToken>;
|
|
2170
|
+
/** 读 — 时间章 token 详情。 */
|
|
2171
|
+
getTimestamp(id: number, signal?: AbortSignal): Promise<TimestampToken>;
|
|
2172
|
+
/** verify — 本地离线校验已申请的时间章。 */
|
|
2173
|
+
verifyTimestamp(req: VerifyTimestampRequest, opts?: ComplianceWriteOptions): Promise<TimestampVerifyResult>;
|
|
2174
|
+
/**
|
|
2175
|
+
* 轮询到 VERIFIED 终态。
|
|
2176
|
+
* - VERIFIED → 返回 token;
|
|
2177
|
+
* - FAILED / LOCAL_VERIFY_FAILED → 抛 {@link CompliancePollError} kind='terminal_failure';
|
|
2178
|
+
* - UNKNOWN / RETRYING / PENDING → 继续轮询直到 timeout;
|
|
2179
|
+
* - timeout → 抛 {@link CompliancePollError} kind='timeout'。
|
|
2180
|
+
*/
|
|
2181
|
+
waitForTimestampVerified(id: number, opts?: CompliancePollOptions): Promise<TimestampToken>;
|
|
2182
|
+
/** 构建证据包(写)。 */
|
|
2183
|
+
buildEvidencePackage(assetId: number, timestampTokenId?: number, opts?: ComplianceWriteOptions): Promise<EvidencePackage>;
|
|
2184
|
+
/** 创建证据报告(写)。 */
|
|
2185
|
+
createReport(req: CreateReportRequest, opts?: ComplianceWriteOptions): Promise<ComplianceReport>;
|
|
2186
|
+
/** 读 — 报告详情。 */
|
|
2187
|
+
getReport(id: number, signal?: AbortSignal): Promise<ComplianceReport>;
|
|
2188
|
+
/**
|
|
2189
|
+
* 发布报告(写,step-up 必须)。
|
|
2190
|
+
*
|
|
2191
|
+
* `@status gated` — step-up 闸门未闭合前服务端会一致返回
|
|
2192
|
+
* `COMPLIANCE_STEP_UP_REQUIRED`(数值码 1031000013)。SDK 不会自动重试、不伪成功;
|
|
2193
|
+
* 调用方需要引导用户重新做 OAuth introspection 或重新登录后再次调用本方法
|
|
2194
|
+
*(使用同一 idempotency-key)。方法状态分级见 `docs/compliance.md` Method Status。
|
|
2195
|
+
*/
|
|
2196
|
+
publishReport(id: number, opts?: ComplianceWriteOptions): Promise<ComplianceReport>;
|
|
2197
|
+
/**
|
|
2198
|
+
* 下载报告(读)。返回 {@link ReportDownload}:报告 hash + 资产 hash + 证据包 hash +
|
|
2199
|
+
* 时间章 serial/genTime,足以离线复核。
|
|
2200
|
+
* 不返回 bodyCanonicalJson / storage key / subject snapshot id。
|
|
2201
|
+
*/
|
|
2202
|
+
downloadReport(id: number, signal?: AbortSignal): Promise<ReportDownload>;
|
|
2203
|
+
/** 创建 envelope(写)。返回 envelope id。 */
|
|
2204
|
+
createSigningEnvelope(req: CreateSigningEnvelopeRequest, opts?: ComplianceWriteOptions): Promise<number>;
|
|
2205
|
+
/** 读 — envelope 详情。租户由服务端从 compliance token principal 推导。 */
|
|
2206
|
+
getSigningEnvelope(envelopeId: number, signal?: AbortSignal): Promise<SigningEnvelope>;
|
|
2207
|
+
/**
|
|
2208
|
+
* 正式签署(写,step-up 必须)。
|
|
2209
|
+
*
|
|
2210
|
+
* `@status gated` — 服务端闸门关闭时会一致返回 `ENVELOPE_GATE_CLOSED` (1031004004)。
|
|
2211
|
+
* SDK 不重试、不伪成功;调用方应该将该错误展示为"功能未开放"。
|
|
2212
|
+
*/
|
|
2213
|
+
signEnvelope(envelopeId: number, req: SignEnvelopeRequest, opts?: ComplianceWriteOptions): Promise<void>;
|
|
2214
|
+
/**
|
|
2215
|
+
* 创建 H5 签署短链(写,step-up 必须)。
|
|
2216
|
+
*
|
|
2217
|
+
* `@status gated` — 同 {@link signEnvelope}:服务端闸门关闭时 SDK 不重试、不伪成功。
|
|
2218
|
+
*/
|
|
2219
|
+
createH5SigningUrl(envelopeId: number, req: CreateH5SigningUrlRequest, opts?: ComplianceWriteOptions): Promise<string>;
|
|
2220
|
+
/** 同步 provider 状态(写但只读对账,不创建新 provider 请求)。 */
|
|
2221
|
+
syncSigningEnvelopeStatus(envelopeId: number, opts?: ComplianceWriteOptions): Promise<void>;
|
|
2222
|
+
/**
|
|
2223
|
+
* 提交用印审批申请(写)。
|
|
2224
|
+
*
|
|
2225
|
+
* `@status production-ready` — 服务端以 `Idempotency-Key` + 业务请求指纹做重放保护:
|
|
2226
|
+
* 同 key + 同请求 → 返回原审批 id;同 key + 不同请求 → 拒绝复用幂等键。强烈建议调用方
|
|
2227
|
+
* 持久化 `idempotencyKey`,网络重试 / 任务恢复时复用,避免重复创建审批单。
|
|
2228
|
+
*/
|
|
2229
|
+
submitSealApproval(req: SubmitSealApprovalRequest, opts?: ComplianceWriteOptions): Promise<number>;
|
|
2230
|
+
/**
|
|
2231
|
+
* 审批通过用印申请(写,step-up 必须)。
|
|
2232
|
+
*
|
|
2233
|
+
* `@status gated` — step-up 未闭合前服务端会返回 `COMPLIANCE_STEP_UP_REQUIRED`。
|
|
2234
|
+
* SDK 不重试、不伪成功。方法状态分级见 `docs/compliance.md` Method Status。
|
|
2235
|
+
*/
|
|
2236
|
+
approveSealApproval(id: number, query: ApproveSealApprovalQuery, opts?: ComplianceWriteOptions): Promise<void>;
|
|
2237
|
+
rejectSealApproval(id: number, query: RejectSealApprovalQuery, opts?: ComplianceWriteOptions): Promise<void>;
|
|
2238
|
+
cancelSealApproval(id: number, query: CancelSealApprovalQuery, opts?: ComplianceWriteOptions): Promise<void>;
|
|
2239
|
+
listPendingSealApprovals(signal?: AbortSignal): Promise<SealApproval[]>;
|
|
2240
|
+
getSealApproval(id: number, signal?: AbortSignal): Promise<SealApproval>;
|
|
2241
|
+
getProviderRequest(id: number, signal?: AbortSignal): Promise<ProviderRequestStatusView>;
|
|
2242
|
+
/**
|
|
2243
|
+
* 轮询 provider request 到 SUCCESS / FAILED 终态。
|
|
2244
|
+
* - SUCCESS / FAILED → 返回最后视图;
|
|
2245
|
+
* - UNKNOWN / RETRYING / PENDING → 继续轮询;
|
|
2246
|
+
* - timeout → 抛 {@link CompliancePollError} kind='timeout',不自动重发原 provider 请求。
|
|
2247
|
+
*
|
|
2248
|
+
* SUCCESS 不代表 billing 已 commit;调用方仍需通过业务侧 envelope / asset 终态判断。
|
|
2249
|
+
*/
|
|
2250
|
+
waitForProviderRequestTerminal(id: number, opts?: CompliancePollOptions): Promise<ProviderRequestStatusView>;
|
|
2251
|
+
classifyError(err: unknown): ComplianceErrorInfo | null;
|
|
2252
|
+
/**
|
|
2253
|
+
* 读路径:GET / 公开 verify。允许 401 单次刷新后重放(GET 幂等安全)。
|
|
2254
|
+
* 与 client.doJSONFullInternal 行为一致;不复用其代码因为 base URL 不同。
|
|
2255
|
+
*/
|
|
2256
|
+
private read;
|
|
2257
|
+
/**
|
|
2258
|
+
* 公开读路径:public verify。
|
|
2259
|
+
*
|
|
2260
|
+
* 与 {@link read} 的区别 — public 端点不应要求认证:
|
|
2261
|
+
* - 无 token 时匿名请求:ensureToken 抛 `not authorized` 会被吞掉,继续匿名发送。
|
|
2262
|
+
* - 有 token 时附带 `Authorization`,保留后端审计上下文。
|
|
2263
|
+
* - 不做 401 refresh replay:401 直接抛 HTTPError,不触发 `forceRefresh`。
|
|
2264
|
+
*
|
|
2265
|
+
* URL 仍走 `client.complianceURL(path)`,不复用 `/api/v4`;底层复用
|
|
2266
|
+
* `client.doRequest`,不新增 fetch/axios 直连。
|
|
2267
|
+
*/
|
|
2268
|
+
private publicRead;
|
|
2269
|
+
/**
|
|
2270
|
+
* 写路径:POST。
|
|
2271
|
+
* - 发送前 ensureToken 一次确保 token fresh。
|
|
2272
|
+
* - 不自动 401 重放:401 → 抛 HTTPError;调用方必须自己刷新 token 后用同一
|
|
2273
|
+
* idempotency-key 重新发起,避免 provider 侧重复请求。
|
|
2274
|
+
* - 不走 doRequestWithRetry:写操作不允许 5xx/timeout 自动重试。
|
|
2275
|
+
*/
|
|
2276
|
+
private write;
|
|
2277
|
+
private executeJson;
|
|
2278
|
+
private poll;
|
|
1706
2279
|
}
|
|
1707
2280
|
|
|
1708
2281
|
/** POST /api/v4/crabcode_cli_feedback 返回体 */
|
|
@@ -1763,4 +2336,4 @@ declare module '@acosmi/sdk-ts' {
|
|
|
1763
2336
|
}
|
|
1764
2337
|
}
|
|
1765
2338
|
|
|
1766
|
-
export { type AgentRun, type AgentRunArtifact, type AgentRunArtifactList, type AgentRunArtifactPolicy, type AgentRunCreateRequest, type AgentRunCreateResponse, type AgentRunDownload, type AgentRunErrorPayload, type AgentRunLocalContextPolicy, type AgentRunLocalToolHandler, type AgentRunLocalToolHandlerContext, type AgentRunLocalToolResult, type AgentRunRunOptions, type AgentRunSettlement, type AgentRunStatus, AgentRunStreamError, type AgentRunStreamEvent, type AgentRunStreamOptions, type AgentRunUsage, type AgentRunWithLocalToolsOptions, AgentRunsClient, AnthropicResponse, type ApproveSealApprovalQuery, type AuthorizeResult, BalanceDetail, type BlockMeta, type BrowserRefreshMode, type BugReportResult, type BugView, BusinessError, type CancelSealApprovalQuery, CertificationStatus, ChatRequest, ChatResponse, Client, ClientRegistration, type ComplianceAssetType, type ComplianceBillingDisplayStatus, ComplianceClient, type ComplianceClientErrorCode, type ComplianceDigestSource, type ComplianceEnvelopeStatus, type ComplianceErrorInfo, type ComplianceErrorKey, type ComplianceHashAlgorithm, CompliancePollError, type CompliancePollOptions, type CompliancePrivacyLevel, type ComplianceProviderRequestStatus, type ComplianceProviderStatus, type ComplianceReport, type ComplianceScope, type ComplianceSealApprovalStatus, type ComplianceTimestampVerificationStatus, type ComplianceWriteOptions, type Config, ConsumeRecordPage, type CreateEvidenceAssetRequest, type CreateH5SigningUrlRequest, type CreateReportRequest, type CreateSigningEnvelopeRequest, type CreateWebAuthorizationRequestOptions, DefaultRetryPolicy, DeviceRegistration, EntitlementBalance, EntitlementItem, ErrAuthDenied, ErrBillingCallbackCannotCommit, ErrBillingCommitRequiresLocalVerify, ErrBillingS2sForbidden, ErrBrowserOpen, ErrComplianceStepUpRequired, ErrDiscovery, ErrEnvelopeGateClosed, ErrOAuthCORSBlocked, ErrProviderNotConfigured, ErrProviderUnknownNoRetry, ErrRefreshProxyFailed, ErrRegistration, ErrSSLProxy, ErrSealApprovalContractHashMismatch, ErrSealApprovalExpired, ErrSealApprovalLocationMismatch, ErrSealApprovalNonceUsed, ErrSealApprovalNotApproved, ErrSealApprovalSealMismatch, ErrSealApprovalTransactorMismatch, ErrSealUseAlreadyConsumed, ErrStateMismatch, ErrTimeout, ErrTokenExchange, ErrTokenExpired, EventAuthURL, EventComplete, EventError, type EvidenceAsset, type EvidencePackage, FileTokenStore, type FilterStatus, FilterStatusAdminBypass, FilterStatusDisabledByFlag, FilterStatusFallbackMissingUser, FilterStatusFallbackNoBuckets, FilterStatusFallbackTkdistError, FilterStatusFallbackTkdistSkew, FilterStatusInternalBypass, FilterStatusOK, FilterStatusUnknown, GenerateSkillRequest, GenerateSkillResult, InMemoryTokenStore, InputModality, type IssueTimestampRequest, LocalStorageTokenStore, type LoginErrCode, type LoginEvent, type LoginEventType, type LoginOptions, ManagedModel, ModelBucket, ModelByQuotaResponse, ModelCapabilities, ModelCoefficient, NotificationList, NotificationPreference, type OAuthMetadataProfile, OptimizeSkillRequest, OptimizeSkillResult, Order, OrderStatus, PayPayload, ProviderAdapter, type ProviderRequestStatusView, type PublicEvidenceVerifyResult, QuotaSummary, type RegisterWebOAuthClientOptions, type RejectSealApprovalQuery, type ReportDownload, type RetryPolicy, type RetryRequestInfo, ScopeAI, ScopeAccount, ScopeComplianceContractSigningRead, ScopeComplianceContractSigningWrite, ScopeComplianceEvidenceRead, ScopeComplianceEvidenceWrite, ScopeComplianceReportsPublish, ScopeComplianceReportsRead, ScopeComplianceReportsWrite, ScopeComplianceSealApprovalApprove, ScopeComplianceSealApprovalRequest, ScopeComplianceSealManage, ScopeComplianceSealUseExecute, ScopeComplianceTimestampIssue, ScopeComplianceTimestampVerify, ScopeEntitlements, ScopeModels, ScopeModelsChat, ScopeProfile, ScopeSkillStore, ScopeSkills, ScopeTokenPackages, ScopeTools, ScopeToolsExecute, ScopeWallet, ScopeWalletReadonly, type SealApproval, ServerMetadata, type SignEnvelopeRequest, type SigningEnvelope, SkillBrowseListResponse, SkillBrowseResponse, SkillStoreItem, SkillStoreQuery, SkillSummary, SourcesEvent, StreamEvent, StreamSettlement, type SubmitSealApprovalRequest, type TimestampToken, type TimestampVerifyResult, TokenPackage, TokenResponse, TokenSet, type TokenStore, ToolView, Transaction, type VerifyTimestampRequest, type WSConfig, WSEvent, WalletStats, type WebAuthorizationCallbackParams, type WebAuthorizationPending, type WebAuthorizationRequest, allScopes, authorize, buildBetas, classifyComplianceError, commerceScopes, completeWebAuthorizationRequest, complianceScopes, computeBackoff, createWebAuthorizationRequest, defaultRetryable, defaultSafeToRetry, discover, discoverWebOAuthMetadata, discoverWithProfile, effectivePolicy, exchangeCode, extractAnthropicBlockMeta, fileLockDefaults, findDesktopVisualUnderstandingModel, findFirstModelByInputModality, generateState, isBillingConfirmable, isComplianceBusinessError, isComplianceTerminalError, isSSLError, modelScopes, modelSupportsImageInput, modelSupportsInputModality, newFileTokenStore, newTokenSet, refreshToken, register, registerWebOAuthClient, revokeToken, skillScopes, uniqueMerge };
|
|
2339
|
+
export { type APIResponse, type AgentRun, type AgentRunArtifact, type AgentRunArtifactList, type AgentRunArtifactPolicy, type AgentRunCreateRequest, type AgentRunCreateResponse, type AgentRunDownload, type AgentRunErrorPayload, type AgentRunLocalContextPolicy, type AgentRunLocalToolHandler, type AgentRunLocalToolHandlerContext, type AgentRunLocalToolResult, type AgentRunRunOptions, type AgentRunSettlement, type AgentRunStatus, AgentRunStreamError, type AgentRunStreamEvent, type AgentRunStreamOptions, type AgentRunUsage, type AgentRunWithLocalToolsOptions, AgentRunsClient, AnthropicResponse, type ApproveSealApprovalQuery, type AuthorizeResult, type BalanceDetail, type BlockMeta, type BrowserRefreshMode, type BugReportResult, type BugView, BusinessError, type CancelSealApprovalQuery, type CertificationStatus, ChatRequest, ChatResponse, Client, type ClientRegistration, type ComplianceAssetType, type ComplianceBillingDisplayStatus, ComplianceClient, type ComplianceClientErrorCode, type ComplianceDigestSource, type ComplianceEnvelopeStatus, type ComplianceErrorInfo, type ComplianceErrorKey, type ComplianceHashAlgorithm, CompliancePollError, type CompliancePollOptions, type CompliancePrivacyLevel, type ComplianceProviderRequestStatus, type ComplianceProviderStatus, type ComplianceReport, type ComplianceScope, type ComplianceSealApprovalStatus, type ComplianceTimestampVerificationStatus, type ComplianceWriteOptions, type Config, type ConsumeRecord, type ConsumeRecordPage, type CreateEvidenceAssetRequest, type CreateH5SigningUrlRequest, type CreateReportRequest, type CreateSigningEnvelopeRequest, type CreateWebAuthorizationRequestOptions, DefaultRetryPolicy, type DeviceRegistration, type EntitlementBalance, type EntitlementItem, ErrAuthDenied, ErrBillingCallbackCannotCommit, ErrBillingCommitRequiresLocalVerify, ErrBillingS2sForbidden, ErrBrowserOpen, ErrComplianceStepUpRequired, ErrDiscovery, ErrEnvelopeGateClosed, ErrOAuthCORSBlocked, ErrProviderNotConfigured, ErrProviderUnknownNoRetry, ErrRefreshProxyFailed, ErrRegistration, ErrSSLProxy, ErrSealApprovalContractHashMismatch, ErrSealApprovalExpired, ErrSealApprovalLocationMismatch, ErrSealApprovalNonceUsed, ErrSealApprovalNotApproved, ErrSealApprovalSealMismatch, ErrSealApprovalTransactorMismatch, ErrSealUseAlreadyConsumed, ErrStateMismatch, ErrTimeout, ErrTokenExchange, ErrTokenExpired, EventAuthURL, EventComplete, EventError, type EvidenceAsset, type EvidencePackage, FileTokenStore, type FilterStatus, FilterStatusAdminBypass, FilterStatusDisabledByFlag, FilterStatusFallbackMissingUser, FilterStatusFallbackNoBuckets, FilterStatusFallbackTkdistError, FilterStatusFallbackTkdistSkew, FilterStatusInternalBypass, FilterStatusOK, FilterStatusUnknown, type GenerateSkillRequest, type GenerateSkillResult, HTTPError, InMemoryTokenStore, InputModality, type IssueTimestampRequest, LocalStorageTokenStore, type LoginErrCode, type LoginEvent, type LoginEventType, type LoginOptions, ManagedModel, type ModelBucket, type ModelByQuotaResponse, ModelCapabilities, type ModelCoefficient, ModelNotFoundError, NetworkError, type Notification, type NotificationList, type NotificationPreference, type NotificationUnreadCount, type OAuthMetadataProfile, type OpenAIChatChoice, type OpenAIChatMessage, type OpenAIChatResponse, type OpenAIFunctionCall, type OpenAIStreamChoice, type OpenAIStreamChunk, type OpenAIStreamDelta, type OpenAIStreamToolCall, type OpenAIToolCall, type OpenAIUsage, type OptimizeSkillRequest, type OptimizeSkillResult, type Order, type OrderStatus, OrderTerminalError, type PayPayload, ProviderAdapter, type ProviderRequestStatusView, type PublicEvidenceVerifyResult, QuotaSummary, RateLimitError, type RegisterWebOAuthClientOptions, type RejectSealApprovalQuery, type ReportDownload, type RetryPolicy, type RetryRequestInfo, ScopeAI, ScopeAccount, ScopeComplianceContractSigningRead, ScopeComplianceContractSigningWrite, ScopeComplianceEvidenceRead, ScopeComplianceEvidenceWrite, ScopeComplianceReportsPublish, ScopeComplianceReportsRead, ScopeComplianceReportsWrite, ScopeComplianceSealApprovalApprove, ScopeComplianceSealApprovalRequest, ScopeComplianceSealManage, ScopeComplianceSealUseExecute, ScopeComplianceTimestampIssue, ScopeComplianceTimestampVerify, ScopeEntitlements, ScopeModels, ScopeModelsChat, ScopeProfile, ScopeSkillStore, ScopeSkills, ScopeTokenPackages, ScopeTools, ScopeToolsExecute, ScopeWallet, ScopeWalletReadonly, type SealApproval, type ServerMetadata, type SignEnvelopeRequest, type SigningEnvelope, type SkillBrowseListResponse, type SkillBrowseResponse, type SkillStoreItem, type SkillStoreListItem, type SkillStoreQuery, type SkillSummary, SourcesEvent, StreamError, StreamEvent, StreamSettlement, type SubmitSealApprovalRequest, type TimestampToken, type TimestampVerifyResult, type TokenPackage, type TokenResponse, type TokenSet, type TokenStore, type ToolListResponse, type ToolProvider, type ToolView, type Transaction, type VerifyTimestampRequest, type WSConfig, type WSEvent, type WalletStats, type WebAuthorizationCallbackParams, type WebAuthorizationPending, type WebAuthorizationRequest, type YudaoPageResult, allScopes, apiResponseBusinessError, apiResponseGetMessage, authorize, buildBetas, classifyComplianceError, commerceScopes, completeWebAuthorizationRequest, complianceScopes, computeBackoff, createWebAuthorizationRequest, defaultRetryable, defaultSafeToRetry, discover, discoverWebOAuthMetadata, discoverWithProfile, effectivePolicy, exchangeCode, extractAnthropicBlockMeta, fileLockDefaults, findDesktopVisualUnderstandingModel, findFirstModelByInputModality, generateState, isBillingConfirmable, isComplianceBusinessError, isComplianceTerminalError, isSSLError, modelScopes, modelSupportsImageInput, modelSupportsInputModality, newFileTokenStore, newTokenSet, parseNotificationEvent, refreshToken, register, registerWebOAuthClient, revokeToken, skillScopes, tokenSetIsExpired, uniqueMerge };
|