@acosmi/sdk-ts 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- import { M as ManagedModel, I as InputModality, S as ServerMetadata, T as TokenResponse, a as TokenSet, C as ClientRegistration, b as ModelCoefficient, Q as QuotaSummary, c as ModelCapabilities, d as ChatRequest, P as ProviderAdapter, e as ChatResponse, A as AnthropicResponse, f as StreamEvent, g as SourcesEvent, h as StreamSettlement, E as EntitlementBalance, B as BalanceDetail, i as EntitlementItem, j as ConsumeRecordPage, k as ModelByQuotaResponse, l as ModelBucket, m as TokenPackage, n as PayPayload, O as Order, o as OrderStatus, W as WalletStats, p as Transaction, q as SkillStoreQuery, r as SkillStoreItem, s as SkillBrowseResponse, t as SkillBrowseListResponse, u as SkillSummary, v as CertificationStatus, G as GenerateSkillRequest, w as GenerateSkillResult, x as OptimizeSkillRequest, y as OptimizeSkillResult, z as ToolView, N as NotificationList, D as DeviceRegistration, F as NotificationPreference, H as WSEvent } from './index-B2Uuh21R.js';
2
- export { J as APIResponse, K as AnthropicContentBlock, L as AnthropicUsage, R as BucketClassCommercial, U as BucketClassGeneric, V as BucketInfo, X as BucketRow, Y as BusinessError, Z as ChatContentBlock, _ as ChatMessage, $ as ChatUsage, a0 as ConsumeRecord, a1 as EffortConfig, a2 as GeoLoc, a3 as HTTPError, a4 as ModelNotFoundError, a5 as NetworkError, a6 as Notification, a7 as NotificationUnreadCount, a8 as OpenAIChatChoice, a9 as OpenAIChatMessage, aa as OpenAIChatResponse, ab as OpenAIFunctionCall, ac as OpenAIStreamChoice, ad as OpenAIStreamChunk, ae as OpenAIStreamDelta, af as OpenAIStreamToolCall, ag as OpenAIToolCall, ah as OpenAIUsage, ai as OrderTerminalError, aj as OutputConfig, ak as ProviderFormat, al as RateLimitError, am as ServerTool, an as ServerToolTypeWebSearch, ao as SkillStoreListItem, ap as StreamError, aq as ThinkingConfig, ar as ThinkingHigh, as as ThinkingHighMinMaxTokens, at as ThinkingMax, au as ThinkingMaxFallbackMaxTokens, av as ThinkingOff, aw as ToolListResponse, ax as ToolProvider, ay as WebSearchConfig, az as WebSearchSource, aA as YudaoPageResult, aB as anthropicResponseTextContent, aC as anthropicResponseThinkingContent, aD as anthropicResponseToolUseBlocks, aE as apiResponseBusinessError, aF as apiResponseGetMessage, aG as bucketInfoIsCommercial, aH as bucketRowIsCommercial, aI as getAdapter, aJ as getAdapterForModel, aK as newThinkingConfig, aL as newWebSearchTool, aM as parseNotificationEvent, aN as parseSettlement, aO as parseSourcesEvent, aP as tokenSetIsExpired } from './index-B2Uuh21R.js';
1
+ import { M as ManagedModel, I as InputModality, S as ServerMetadata, T as TokenResponse, a as TokenSet, C as ClientRegistration, B as BusinessError, b as ModelCoefficient, Q as QuotaSummary, c as ModelCapabilities, d as ChatRequest, P as ProviderAdapter, e as ChatResponse, A as AnthropicResponse, f as StreamEvent, g as SourcesEvent, h as StreamSettlement, E as EntitlementBalance, i as BalanceDetail, j as EntitlementItem, k as ConsumeRecordPage, l as ModelByQuotaResponse, m as ModelBucket, n as TokenPackage, o as PayPayload, O as Order, p as OrderStatus, W as WalletStats, q as Transaction, r as SkillStoreQuery, s as SkillStoreItem, t as SkillBrowseResponse, u as SkillBrowseListResponse, v as SkillSummary, w as CertificationStatus, G as GenerateSkillRequest, x as GenerateSkillResult, y as OptimizeSkillRequest, z as OptimizeSkillResult, D as ToolView, N as NotificationList, F as DeviceRegistration, H as NotificationPreference, J as WSEvent } from './index-28x02ITB.js';
2
+ export { K as APIResponse, L as AnthropicContentBlock, R as AnthropicUsage, U as BucketClassCommercial, V as BucketClassGeneric, X as BucketInfo, Y as BucketRow, Z as ChatContentBlock, _ as ChatMessage, $ as ChatUsage, a0 as ConsumeRecord, a1 as EffortConfig, a2 as GeoLoc, a3 as HTTPError, a4 as ModelNotFoundError, a5 as NetworkError, a6 as Notification, a7 as NotificationUnreadCount, a8 as OpenAIChatChoice, a9 as OpenAIChatMessage, aa as OpenAIChatResponse, ab as OpenAIFunctionCall, ac as OpenAIStreamChoice, ad as OpenAIStreamChunk, ae as OpenAIStreamDelta, af as OpenAIStreamToolCall, ag as OpenAIToolCall, ah as OpenAIUsage, ai as OrderTerminalError, aj as OutputConfig, ak as ProviderFormat, al as RateLimitError, am as ServerTool, an as ServerToolTypeWebSearch, ao as SkillStoreListItem, ap as StreamError, aq as ThinkingConfig, ar as ThinkingHigh, as as ThinkingHighMinMaxTokens, at as ThinkingMax, au as ThinkingMaxFallbackMaxTokens, av as ThinkingOff, aw as ToolListResponse, ax as ToolProvider, ay as WebSearchConfig, az as WebSearchSource, aA as YudaoPageResult, aB as anthropicResponseTextContent, aC as anthropicResponseThinkingContent, aD as anthropicResponseToolUseBlocks, aE as apiResponseBusinessError, aF as apiResponseGetMessage, aG as bucketInfoIsCommercial, aH as bucketRowIsCommercial, aI as getAdapter, aJ as getAdapterForModel, aK as newThinkingConfig, aL as newWebSearchTool, aM as parseNotificationEvent, aN as parseSettlement, aO as parseSourcesEvent, aP as tokenSetIsExpired } from './index-28x02ITB.js';
3
3
  import { M as MinimalSanitizeConfig } from './index-nvLKgCm9.js';
4
4
  export { i as sanitize } from './index-nvLKgCm9.js';
5
5
  export { AnthropicAdapter } from './adapters/anthropic.js';
@@ -148,8 +148,24 @@ declare const ScopeWallet = "wallet";
148
148
  declare const ScopeWalletReadonly = "wallet:readonly";
149
149
  /** @deprecated */
150
150
  declare const ScopeProfile = "profile";
151
+ declare const ScopeComplianceEvidenceRead = "compliance:evidence:read";
152
+ declare const ScopeComplianceEvidenceWrite = "compliance:evidence:write";
153
+ declare const ScopeComplianceTimestampIssue = "compliance:timestamp:issue";
154
+ declare const ScopeComplianceTimestampVerify = "compliance:timestamp:verify";
155
+ declare const ScopeComplianceContractSigningRead = "compliance:contract_signing:read";
156
+ declare const ScopeComplianceContractSigningWrite = "compliance:contract_signing:write";
157
+ declare const ScopeComplianceSealManage = "compliance:seal:manage";
158
+ declare const ScopeComplianceSealApprovalRequest = "compliance:seal_approval:request";
159
+ declare const ScopeComplianceSealApprovalApprove = "compliance:seal_approval:approve";
160
+ declare const ScopeComplianceSealUseExecute = "compliance:seal_use:execute";
161
+ declare const ScopeComplianceReportsRead = "compliance:reports:read";
162
+ declare const ScopeComplianceReportsPublish = "compliance:reports:publish";
163
+ /** 类型联合:合规域细粒度 scope。Java compliance verifier 只按细粒度匹配, 不做分组展开。 */
164
+ 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 ScopeComplianceReportsPublish;
151
165
  /** 全部分组 scope (推荐) */
152
166
  declare function allScopes(): string[];
167
+ /** 全部合规域 scope。OAuth 申请合规权限时使用; 谨慎一次性申请全部, 推荐按业务最小集合申请。 */
168
+ declare function complianceScopes(): ComplianceScope[];
153
169
  /** 模型服务相关 scope */
154
170
  declare function modelScopes(): string[];
155
171
  /** 商城/钱包 scope */
@@ -157,6 +173,340 @@ declare function commerceScopes(): string[];
157
173
  /** 技能/工具 scope */
158
174
  declare function skillScopes(): string[];
159
175
 
176
+ /**
177
+ * Compliance envelope 稳定业务状态。
178
+ *
179
+ * 字面量与 Java {@code EnvelopeStatusEnum} 的 `name()` 一致(这是 enum,是 wire 上的实际
180
+ * 字符串);前端按这些字符串分支展示文案。
181
+ */
182
+ type ComplianceEnvelopeStatus = 'DRAFT' | 'CONTRACT_READY' | 'APPROVED' | 'SIGN_PENDING' | 'PENDING_EVIDENCE' | 'PENDING_RECONCILIATION' | 'SUCCESS' | 'FAILED' | 'CANCELED';
183
+ /** Compliance 用印审批稳定状态。 */
184
+ type ComplianceSealApprovalStatus = 'DRAFT' | 'SUBMITTED' | 'APPROVED' | 'REJECTED' | 'CANCELED' | 'USED' | 'EXPIRED';
185
+ /** Provider 业务状态(前端可见的脱敏视图,不暴露下游内部字段)。 */
186
+ type ComplianceProviderStatus = 'pending' | 'success' | 'failed' | 'unknown' | 'retrying';
187
+ /**
188
+ * 计费 / 履约的对外稳定状态视图。distribution compliance-billing 内部 API
189
+ * (quote/reserve/commit/cancel/reconcile) 不暴露给前端 — 前端只能看见这 4 个语义。
190
+ */
191
+ type ComplianceBillingDisplayStatus = 'reserved' | 'committed' | 'canceled' | 'pending_reconciliation';
192
+ /** 高风险动作 step-up — 重新做 OAuth introspection 或重新登录,提升 token 等级后再尝试。 */
193
+ declare const ErrComplianceStepUpRequired = "COMPLIANCE_STEP_UP_REQUIRED";
194
+ /** envelope 闸门关闭 — 审批 gate 等条件未同时就绪,前端展示"功能开放中"。 */
195
+ declare const ErrEnvelopeGateClosed = "ENVELOPE_GATE_CLOSED";
196
+ /** 履约 provider 未配置 — 受控环境材料缺失时业务路径会一致拒绝,不要前端重试。 */
197
+ declare const ErrProviderNotConfigured = "PROVIDER_NOT_CONFIGURED";
198
+ /** Provider 返回 unknown / retrying — 客户必须等待对账,前端展示"处理中(人工核对)"。 */
199
+ declare const ErrProviderUnknownNoRetry = "PROVIDER_REQUEST_UNKNOWN_NO_RETRY";
200
+ /** callback 不能直接确认扣费 — 后端守门,前端无需处理,记录到审计日志展示即可。 */
201
+ declare const ErrBillingCallbackCannotCommit = "BILLING_CALLBACK_CANNOT_COMMIT";
202
+ /** provider 成功但本地未验证通过,不允许扣费。 */
203
+ declare const ErrBillingCommitRequiresLocalVerify = "BILLING_COMMIT_REQUIRES_LOCAL_VERIFY";
204
+ /** distribution compliance-billing 必须 S2S — 前端误调用时拿到该错误码,禁止 retry。 */
205
+ declare const ErrBillingS2sForbidden = "BILLING_S2S_FORBIDDEN";
206
+ /** 审批 gate 各类失败语义(前端展示"审批中 / 审批已用 / 审批失效")。 */
207
+ declare const ErrSealApprovalNotApproved = "SEAL_APPROVAL_STATE_NOT_APPROVED";
208
+ declare const ErrSealApprovalExpired = "SEAL_APPROVAL_EXPIRED";
209
+ declare const ErrSealApprovalNonceUsed = "SEAL_APPROVAL_NONCE_USED";
210
+ declare const ErrSealApprovalContractHashMismatch = "SEAL_APPROVAL_CONTRACT_HASH_MISMATCH";
211
+ declare const ErrSealApprovalSealMismatch = "SEAL_APPROVAL_SEAL_MISMATCH";
212
+ declare const ErrSealApprovalLocationMismatch = "SEAL_APPROVAL_LOCATION_MISMATCH";
213
+ declare const ErrSealApprovalTransactorMismatch = "SEAL_APPROVAL_TRANSACTOR_MISMATCH";
214
+ /** 用印重复消费防护 — 前端遇到该错误必须刷新审批单状态,不允许"换一次 nonce 再试"。 */
215
+ declare const ErrSealUseAlreadyConsumed = "SEAL_USE_ALREADY_CONSUMED";
216
+ /** 该错误码联合用于前端选择性展示文案;非穷举式 enum,后端保留新增空间。 */
217
+ 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;
218
+ /**
219
+ * 判定一个错误码是否属于"需要前端引导用户重新认证/审批"的高级语义,
220
+ * 而不是简单 retry。这类错误前端不允许在 UI 层做自动重试。
221
+ */
222
+ declare function isComplianceTerminalError(code: string): boolean;
223
+ /**
224
+ * "是否允许在 UI 上呈现为'扣费已确认'"的判定。
225
+ * provider 状态为 unknown / retrying / pending 时一律不展示为已确认。
226
+ */
227
+ declare function isBillingConfirmable(providerStatus: ComplianceProviderStatus | undefined, billingStatus: ComplianceBillingDisplayStatus | undefined): boolean;
228
+
229
+ type ComplianceAssetType = 'CONTRACT' | 'CODE' | 'IMAGE' | 'DOCUMENT' | 'ARCHIVE' | 'HASH_ONLY' | 'URL_SNAPSHOT' | 'RELEASE' | 'LOG' | 'OTHER';
230
+ type ComplianceHashAlgorithm = 'sha256' | 'sha512' | 'sm3';
231
+ type ComplianceDigestSource = 'CLIENT' | 'COMPLIANCE_SERVICE' | 'PROVIDER';
232
+ type CompliancePrivacyLevel = 'public' | 'private';
233
+ /** 证据资产对外稳定视图。对应后端 EvidenceAssetRespVO。 */
234
+ interface EvidenceAsset {
235
+ id: number;
236
+ /** 业务编号;SDK / 前端引用时优先使用 evidenceNo。 */
237
+ evidenceNo: string;
238
+ /** publish 后的公开 verify code;DRAFT / 非 public privacy 时为 null。 */
239
+ publicVerifyCode?: string | null;
240
+ assetType: ComplianceAssetType | string;
241
+ name: string;
242
+ mimeType?: string | null;
243
+ size?: number | null;
244
+ hashAlgorithm: ComplianceHashAlgorithm | string;
245
+ /** 资产 hash(hex 字符串)。 */
246
+ contentHash: string;
247
+ canonicalizationProfile?: string | null;
248
+ digestSource: ComplianceDigestSource | string;
249
+ privacyLevel: CompliancePrivacyLevel | string;
250
+ status: string;
251
+ }
252
+ /** 创建证据资产请求;与 Java EvidenceAssetCreateReq 对齐。 */
253
+ interface CreateEvidenceAssetRequest {
254
+ /** AssetTypeEnum.name()。 */
255
+ assetType: ComplianceAssetType | string;
256
+ name: string;
257
+ mimeType?: string;
258
+ /** 'sha256' / 'sha512' / 'sm3'。 */
259
+ hashAlgorithm: ComplianceHashAlgorithm | string;
260
+ /** hex 字符串;hash-only 资产必填。 */
261
+ declaredHash?: string;
262
+ /** CLIENT / COMPLIANCE_SERVICE / PROVIDER。 */
263
+ digestSource?: ComplianceDigestSource | string;
264
+ /** 原文 base64;hash-only 时缺省即可。 */
265
+ contentBase64?: string;
266
+ /** public / private(默认 private)。 */
267
+ privacyLevel?: CompliancePrivacyLevel | string;
268
+ source?: string;
269
+ }
270
+ /** 公开 verify 结果。隐私边界:不暴露 PII / 合同原文 / storage / provider raw。 */
271
+ interface PublicEvidenceVerifyResult {
272
+ evidenceNo: string;
273
+ assetType: string;
274
+ hashAlgorithm: string;
275
+ contentHash: string;
276
+ size?: number | null;
277
+ canonicalizationProfile?: string | null;
278
+ verifiedAt: string;
279
+ packageId?: number | null;
280
+ manifestHash?: string | null;
281
+ packageHash?: string | null;
282
+ manifestOfflineVerify: boolean;
283
+ }
284
+ type ComplianceTimestampVerificationStatus = 'PENDING' | 'VERIFIED' | 'FAILED' | 'LOCAL_VERIFY_FAILED' | 'UNKNOWN' | 'RETRYING';
285
+ /** 时间章 token 对外视图(不含 provider/object/tsa 内部字段)。 */
286
+ interface TimestampToken {
287
+ id: number;
288
+ assetId: number;
289
+ policyOid?: string | null;
290
+ serialNumber?: string | null;
291
+ /** gen_time ISO-8601;UNKNOWN/PENDING 状态可能为 null。 */
292
+ genTime?: string | null;
293
+ accuracy?: string | null;
294
+ verificationStatus: ComplianceTimestampVerificationStatus | string;
295
+ verifiedAt?: string | null;
296
+ verificationError?: string | null;
297
+ }
298
+ /** 申请时间章请求。`provider` 字段已从服务端契约下线;SDK 永远不传。 */
299
+ interface IssueTimestampRequest {
300
+ name?: string;
301
+ mimeType?: string;
302
+ hashAlgorithm: ComplianceHashAlgorithm | string;
303
+ /** 客户端声明 digest(hex);contentBase64 非空时作为校验值。 */
304
+ digest?: string;
305
+ contentBase64?: string;
306
+ }
307
+ /** verify 请求 / 结果。 */
308
+ interface VerifyTimestampRequest {
309
+ tokenId: number;
310
+ }
311
+ interface TimestampVerifyResult {
312
+ passed: boolean;
313
+ reason: string;
314
+ }
315
+ interface EvidencePackage {
316
+ id: number;
317
+ assetId: number;
318
+ timestampTokenId?: number | null;
319
+ chainId: string;
320
+ packageVersion: string;
321
+ hashAlgorithm: string;
322
+ manifestHash: string;
323
+ packageHash: string;
324
+ status: string;
325
+ }
326
+ interface ComplianceReport {
327
+ id: number;
328
+ reportNo: string;
329
+ reportType: string;
330
+ status: string;
331
+ assetId?: number | null;
332
+ packageId?: number | null;
333
+ publicUrlToken?: string | null;
334
+ publishedAt?: string | null;
335
+ bodyHash?: string | null;
336
+ }
337
+ interface CreateReportRequest {
338
+ assetId: number;
339
+ packageId: number;
340
+ }
341
+ /** 离线复核下载 VO;建议调用方持久化作为长期可重复验证依据。 */
342
+ interface ReportDownload {
343
+ id: number;
344
+ reportNo: string;
345
+ reportType: string;
346
+ status: string;
347
+ bodyHash?: string | null;
348
+ publishedAt?: string | null;
349
+ assetEvidenceNo?: string | null;
350
+ assetHashAlgorithm?: string | null;
351
+ assetContentHash?: string | null;
352
+ packageManifestHash?: string | null;
353
+ packageHash?: string | null;
354
+ packageHashAlgorithm?: string | null;
355
+ timestampSerialNumber?: string | null;
356
+ timestampGenTime?: string | null;
357
+ timestampVerificationStatus?: string | null;
358
+ }
359
+ interface SigningEnvelope {
360
+ id: number;
361
+ envelopeNo: string;
362
+ applicantUserId?: string | null;
363
+ status: string;
364
+ primaryContractId?: number | null;
365
+ contractHash?: string | null;
366
+ hashAlgorithm?: string | null;
367
+ billingGroupId?: string | null;
368
+ chainId?: string | null;
369
+ requestId?: string | null;
370
+ pendingReason?: string | null;
371
+ signedAt?: string | null;
372
+ evidenceReadyAt?: string | null;
373
+ committedAt?: string | null;
374
+ }
375
+ /** 创建 envelope 请求;只保留调用方业务字段,内部主体快照和履约通道由后端推导。 */
376
+ interface CreateSigningEnvelopeRequest {
377
+ envelopeNo?: string;
378
+ requestId?: string;
379
+ /** 调用方稳定 idempotency-key(不传则由 Idempotency-Key header 兜底)。 */
380
+ idempotencyKey?: string;
381
+ billingGroupId?: string;
382
+ chainId?: string;
383
+ }
384
+ /** sign 请求;service 默认闸门关闭,SDK 写示例必须处理 ENVELOPE_GATE_CLOSED 错误。 */
385
+ interface SignEnvelopeRequest {
386
+ approvalRequestId?: number;
387
+ contractId?: number;
388
+ contractHash?: string;
389
+ sealId?: number;
390
+ signLocationType?: string;
391
+ signLocationPayload?: string;
392
+ transactorId?: number;
393
+ requestId?: string;
394
+ idempotencyKey?: string;
395
+ }
396
+ /** H5 短链请求。 */
397
+ interface CreateH5SigningUrlRequest extends SignEnvelopeRequest {
398
+ }
399
+ interface SealApproval {
400
+ id: number;
401
+ envelopeId?: number | null;
402
+ contractId?: number | null;
403
+ contractHash?: string | null;
404
+ hashAlgorithm?: string | null;
405
+ sealId?: number | null;
406
+ applicantUserId?: string | null;
407
+ approverUserId?: string | null;
408
+ transactorId?: number | null;
409
+ signLocationType?: string | null;
410
+ signLocationPayload?: string | null;
411
+ reason?: string | null;
412
+ expiresAt?: string | null;
413
+ status: string;
414
+ approvedAt?: string | null;
415
+ rejectedAt?: string | null;
416
+ canceledAt?: string | null;
417
+ }
418
+ /** 提交审批;provider 侧字段由后端归一,SDK 调用方不传。 */
419
+ interface SubmitSealApprovalRequest {
420
+ envelopeId?: number;
421
+ contractId?: number;
422
+ contractHash?: string;
423
+ hashAlgorithm?: string;
424
+ sealId?: number;
425
+ approverUserId?: string;
426
+ transactorId?: number;
427
+ signLocationType?: string;
428
+ signLocationPayload?: string;
429
+ reason?: string;
430
+ }
431
+ interface ApproveSealApprovalQuery {
432
+ expiresAt?: string;
433
+ note?: string;
434
+ }
435
+ interface RejectSealApprovalQuery {
436
+ reason?: string;
437
+ }
438
+ interface CancelSealApprovalQuery {
439
+ reason?: string;
440
+ }
441
+ type ComplianceProviderRequestStatus = 'PENDING' | 'SUCCESS' | 'FAILED' | 'UNKNOWN' | 'RETRYING';
442
+ interface ProviderRequestStatusView {
443
+ id: number;
444
+ status: ComplianceProviderRequestStatus | string;
445
+ /** SUCCESS / FAILED 终态。 */
446
+ terminal: boolean;
447
+ /** 当前状态是否允许 SDK 安全重试请求(仅对 RETRYING 为 true)。 */
448
+ retryable: boolean;
449
+ businessNo?: string | null;
450
+ contractNo?: string | null;
451
+ sealId?: string | null;
452
+ attemptCount?: number | null;
453
+ reconciliationStatus?: string | null;
454
+ nextRetryAt?: string | null;
455
+ requestedAt?: string | null;
456
+ respondedAt?: string | null;
457
+ }
458
+ /** Compliance 写操作选项;写操作不自动 retry,不自动 401 重放。 */
459
+ interface ComplianceWriteOptions {
460
+ /**
461
+ * 调用方稳定的幂等键。写操作强烈建议持久化;缺省时服务端按 UUID 兜底,但调用方
462
+ * 在重试 / 恢复时无法对账。
463
+ */
464
+ idempotencyKey?: string;
465
+ signal?: AbortSignal;
466
+ }
467
+ /** 轮询参数(exponential backoff)。 */
468
+ interface CompliancePollOptions {
469
+ /** 总超时(ms),缺省 60s。 */
470
+ timeoutMs?: number;
471
+ /** 初始 interval(ms),缺省 1000。 */
472
+ initialIntervalMs?: number;
473
+ /** interval 倍增上限(ms),缺省 5000。 */
474
+ maxIntervalMs?: number;
475
+ /** 倍增系数,缺省 1.5。 */
476
+ multiplier?: number;
477
+ signal?: AbortSignal;
478
+ }
479
+
480
+ /**
481
+ * SDK 内部 symbolic key;用于代码分支判断与文档。**不是 wire contract**。
482
+ */
483
+ 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';
484
+ /** 单个错误的 SDK 视图。 */
485
+ interface ComplianceErrorInfo {
486
+ /** Java numeric error code (wire contract)。 */
487
+ code: number;
488
+ /** 服务端原始 message(中文,可变);仅用于日志/展示。 */
489
+ message: string;
490
+ /** SDK 分支判断用 symbolic key。 */
491
+ key: ComplianceErrorKey;
492
+ /** 是否安全自动重试 — compliance 写接口几乎全为 false。 */
493
+ retryable: boolean;
494
+ /** 是否已经是终态 — 用户必须用新 idempotency-key 重新发起。 */
495
+ terminal: boolean;
496
+ /** 高风险动作需要 step-up / introspection。 */
497
+ stepUpRequired: boolean;
498
+ }
499
+ /**
500
+ * 把一个 BusinessError 分类为 compliance 视图。
501
+ * 非 compliance 段位的错误码会回退到 UNKNOWN_COMPLIANCE_ERROR,调用方应该当作业务错误处理。
502
+ */
503
+ declare function classifyComplianceError(err: BusinessError): ComplianceErrorInfo;
504
+ /**
505
+ * 判断 BusinessError 是否属于 compliance 段位(1-031-xxx-xxx)。
506
+ * 不在段位的错误码可能来自其它 yudao 模块,按通用业务错误处理即可。
507
+ */
508
+ declare function isComplianceBusinessError(err: BusinessError): boolean;
509
+
160
510
  /**
161
511
  * Token 持久化接口
162
512
  * 桌面智能体可自行实现 (如 macOS Keychain / Windows Credential Manager)
@@ -327,196 +677,6 @@ declare function effectivePolicy(p: RetryPolicy | null | undefined): Required<Re
327
677
  */
328
678
  declare function computeBackoff(p: Required<RetryPolicy>, attempt: number, err: unknown): number;
329
679
 
330
- /** SDK 为单个 content block 缓存的元数据 */
331
- interface BlockMeta {
332
- type: string;
333
- ephemeral: boolean;
334
- }
335
- /**
336
- * 按 Anthropic SSE 事件类型解析 data, 更新 blockTypeMap, 返回 [index, type, ephemeral]。
337
- *
338
- * 仅当事件为 content_block_start / content_block_delta / content_block_stop
339
- * 时返回非空 type; 其他事件返回空 type, 调用方据此判别是否填充 StreamEvent 元数据字段。
340
- */
341
- declare function extractAnthropicBlockMeta(eventType: string, data: string, blockTypeMap: Map<number, BlockMeta>): [number, string, boolean];
342
-
343
- type AgentRunStatus = 'queued' | 'running' | 'completed' | 'failed' | 'cancelled';
344
- interface AgentRunLocalContextPolicy {
345
- enabled?: boolean;
346
- readonly?: boolean;
347
- maxBytes?: number;
348
- allowedTools?: string[];
349
- }
350
- interface AgentRunArtifactPolicy {
351
- enabled?: boolean;
352
- maxFiles?: number;
353
- }
354
- interface AgentRunCreateRequest {
355
- appId: string;
356
- mode?: string;
357
- sessionId?: string;
358
- input: string;
359
- messages?: unknown[];
360
- model?: string;
361
- activeSkillIds?: string[];
362
- knowledgeBaseIds?: string[];
363
- metadata?: Record<string, string>;
364
- localContextPolicy?: AgentRunLocalContextPolicy;
365
- artifactPolicy?: AgentRunArtifactPolicy;
366
- }
367
- interface AgentRun {
368
- runId: string;
369
- sessionId: string;
370
- appId?: string;
371
- mode?: string;
372
- status: AgentRunStatus;
373
- createdAt?: string;
374
- startedAt?: string;
375
- completedAt?: string;
376
- error?: AgentRunErrorPayload;
377
- metadata?: Record<string, string>;
378
- }
379
- interface AgentRunCreateResponse {
380
- runId: string;
381
- sessionId: string;
382
- status: AgentRunStatus;
383
- }
384
- interface AgentRunArtifact {
385
- id: string;
386
- filename: string;
387
- contentType?: string;
388
- size?: number;
389
- type?: string;
390
- metadata?: Record<string, string>;
391
- }
392
- interface AgentRunArtifactList {
393
- artifacts: AgentRunArtifact[];
394
- }
395
- interface AgentRunDownload {
396
- data: Uint8Array;
397
- filename: string;
398
- contentType?: string;
399
- }
400
- interface AgentRunUsage {
401
- inputTokens?: number;
402
- outputTokens?: number;
403
- totalTokens?: number;
404
- cacheReadTokens?: number;
405
- cacheCreateTokens?: number;
406
- exact?: boolean;
407
- source?: string;
408
- [key: string]: unknown;
409
- }
410
- interface AgentRunSettlement {
411
- requestId?: string;
412
- status?: string;
413
- consumeStatus?: string;
414
- inputTokens?: number;
415
- outputTokens?: number;
416
- totalTokens?: number;
417
- cacheReadTokens?: number;
418
- cacheCreateTokens?: number;
419
- tokenRemaining?: number;
420
- callRemaining?: number;
421
- retryQueued?: boolean;
422
- exact?: boolean;
423
- [key: string]: unknown;
424
- }
425
- interface AgentRunErrorPayload {
426
- code?: string;
427
- message: string;
428
- stage?: string;
429
- retryable?: boolean;
430
- raw?: unknown;
431
- }
432
- interface AgentRunLocalToolResult {
433
- requestId: string;
434
- ok: boolean;
435
- content?: unknown;
436
- error?: string;
437
- }
438
- interface AgentRunLocalToolHandlerContext {
439
- runId: string;
440
- requestId: string;
441
- name: string;
442
- signal: AbortSignal;
443
- }
444
- type AgentRunLocalToolHandler = (input: unknown, context: AgentRunLocalToolHandlerContext) => Promise<unknown> | unknown;
445
- interface AgentRunStreamOptions {
446
- /**
447
- * true by default. When enabled, an error event is converted into
448
- * AgentRunStreamError after the event has been parsed.
449
- */
450
- throwOnError?: boolean;
451
- }
452
- interface AgentRunRunOptions extends AgentRunStreamOptions {
453
- }
454
- interface AgentRunWithLocalToolsOptions extends AgentRunRunOptions {
455
- timeoutMs?: number;
456
- onEvent?: (event: AgentRunStreamEvent) => void | Promise<void>;
457
- }
458
- type AgentRunStreamEvent = {
459
- type: 'run_started';
460
- runId: string;
461
- sessionId: string;
462
- } | {
463
- type: 'status';
464
- status: AgentRunStatus | string;
465
- message?: string;
466
- } | {
467
- type: 'text_delta';
468
- text: string;
469
- } | {
470
- type: 'reasoning_delta';
471
- text: string;
472
- } | {
473
- type: 'tool_call';
474
- id: string;
475
- name: string;
476
- input?: unknown;
477
- } | {
478
- type: 'tool_result';
479
- id: string;
480
- name?: string;
481
- result?: unknown;
482
- error?: string;
483
- } | {
484
- type: 'local_tool_request';
485
- requestId: string;
486
- name: string;
487
- input: unknown;
488
- } | {
489
- type: 'artifact';
490
- artifact: AgentRunArtifact;
491
- } | {
492
- type: 'sources';
493
- sources: unknown;
494
- } | {
495
- type: 'usage';
496
- usage: AgentRunUsage;
497
- } | {
498
- type: 'settle';
499
- settlement: AgentRunSettlement;
500
- } | {
501
- type: 'error';
502
- error: AgentRunErrorPayload;
503
- } | {
504
- type: 'done';
505
- runId: string;
506
- status: AgentRunStatus | string;
507
- };
508
- declare class AgentRunStreamError extends Error {
509
- event: Extract<AgentRunStreamEvent, {
510
- type: 'error';
511
- }>;
512
- code: string;
513
- stage: string;
514
- retryable: boolean;
515
- constructor(event: Extract<AgentRunStreamEvent, {
516
- type: 'error';
517
- }>);
518
- }
519
-
520
680
  type FilterStatus = 'ok' | 'admin-bypass' | 'internal-bypass' | 'disabled-by-flag' | 'fallback-tkdist-error' | 'fallback-tkdist-deployment-skew' | 'fallback-no-buckets' | 'fallback-missing-userid' | '';
521
681
  declare const FilterStatusOK: FilterStatus;
522
682
  declare const FilterStatusAdminBypass: FilterStatus;
@@ -548,6 +708,17 @@ interface Config {
548
708
  * 计费安全: 自定义 SafeToRetry 时, 严禁让 POST chat/messages 通过, 否则双扣
549
709
  */
550
710
  retryPolicy?: RetryPolicy;
711
+ /**
712
+ * Compliance (时间章 / 电子证据 / 合同签署) API 根地址。
713
+ *
714
+ * Java compliance 模块的 controller 注册在 `/compliance/...` 下,部署到
715
+ * `/admin-api/*` 前缀。未配置时默认 `${serverURL}/admin-api`,也可显式覆盖到
716
+ * 独立 ingress(如 `https://compliance.example.com`)。
717
+ *
718
+ * 该地址不被 `/api/v4` 拼接路径复用,compliance 调用走自己的子 client
719
+ * `client.compliance.*`,不与既有模型网关 API 冲突。
720
+ */
721
+ complianceBaseURL?: string;
551
722
  }
552
723
  interface Deferred<T> {
553
724
  promise: Promise<T>;
@@ -572,6 +743,8 @@ declare class Client {
572
743
  /** SDK 内部使用 — 业务方法 (mixin) 通过 this.* 访问以下字段 */
573
744
  /** 服务器根地址 (已 trim 尾随 /) */
574
745
  serverURL: string;
746
+ /** Compliance API 根地址 (已 trim 尾随 /); null = 走默认 ${serverURL}/admin-api */
747
+ complianceBaseURL: string | null;
575
748
  /** OAuth metadata (lazy loaded) */
576
749
  meta: ServerMetadata | null;
577
750
  /** 当前 token (内存) */
@@ -757,6 +930,16 @@ declare class Client {
757
930
  event: StreamSettlement;
758
931
  }, void, void>;
759
932
  apiURL(path: string): string;
933
+ /**
934
+ * Compliance API URL 拼接。
935
+ *
936
+ * `complianceBaseURL` 已配置时直接拼接;未配置时默认
937
+ * `${serverURL}/admin-api` + path,匹配 Java compliance controller 的
938
+ * `/compliance/...` 路径。
939
+ *
940
+ * 不复用 `apiURL`:apiURL 强制追加 `/api/v4`,与 compliance 路径不同。
941
+ */
942
+ complianceURL(path: string): string;
760
943
  /** GET/POST/... 通用 JSON 调用 (返回 result 已 typed) */
761
944
  doJSON<T>(method: string, path: string, body: unknown | null, signal?: AbortSignal): Promise<T>;
762
945
  /** 与 doJSON 相同, 但返回响应 Headers (用于提取 X-Token-Remaining 等) */
@@ -805,6 +988,317 @@ declare class Client {
805
988
  }, signal?: AbortSignal): Promise<Response>;
806
989
  }
807
990
 
991
+ declare module '@acosmi/sdk-ts' {
992
+ interface Client {
993
+ /** SDK-facing 时间章与电子证据 / 合同签署能力。 */
994
+ readonly compliance: ComplianceClient;
995
+ }
996
+ }
997
+ /**
998
+ * 当 compliance polling 检测到终态失败 / 已过 timeout / step-up 时抛出。
999
+ *
1000
+ * 分类逻辑:终态失败优先于 timeout;timeout 不算 retryable,调用方必须用新 idempotency-key
1001
+ * 重新发起整条链路。
1002
+ */
1003
+ declare class CompliancePollError extends Error {
1004
+ readonly kind: 'timeout' | 'terminal_failure' | 'step_up_required' | 'unknown';
1005
+ readonly lastInfo?: ComplianceErrorInfo;
1006
+ constructor(message: string, kind: 'timeout' | 'terminal_failure' | 'step_up_required' | 'unknown', lastInfo?: ComplianceErrorInfo);
1007
+ }
1008
+ declare class ComplianceClient {
1009
+ private readonly client;
1010
+ constructor(client: Client);
1011
+ /** 创建证据资产(写)。 */
1012
+ createEvidenceAsset(req: CreateEvidenceAssetRequest, opts?: ComplianceWriteOptions): Promise<EvidenceAsset>;
1013
+ /** 读 — 证据资产详情。 */
1014
+ getEvidenceAsset(id: number, signal?: AbortSignal): Promise<EvidenceAsset>;
1015
+ /**
1016
+ * 公开 verify。隐私边界:返回字段不含 PII / 合同原文 / storage / provider raw。
1017
+ * 服务端不要求 compliance scope(公开端点);但 SDK 仍带上 token 以便审计。
1018
+ */
1019
+ verifyEvidencePublic(params: {
1020
+ evidenceNo?: string;
1021
+ publicVerifyCode?: string;
1022
+ }, signal?: AbortSignal): Promise<PublicEvidenceVerifyResult>;
1023
+ /** 申请时间章(写)。SDK 永远不传 provider 字段。 */
1024
+ issueTimestamp(req: IssueTimestampRequest, opts?: ComplianceWriteOptions): Promise<TimestampToken>;
1025
+ /** 给已有资产申请时间章。SDK 永远不传 provider 字段。 */
1026
+ issueTimestampForAsset(assetId: number, opts?: ComplianceWriteOptions): Promise<TimestampToken>;
1027
+ /** 读 — 时间章 token 详情。 */
1028
+ getTimestamp(id: number, signal?: AbortSignal): Promise<TimestampToken>;
1029
+ /** verify — 本地离线校验已申请的时间章。 */
1030
+ verifyTimestamp(req: VerifyTimestampRequest, opts?: ComplianceWriteOptions): Promise<TimestampVerifyResult>;
1031
+ /**
1032
+ * 轮询到 VERIFIED 终态。
1033
+ * - VERIFIED → 返回 token;
1034
+ * - FAILED / LOCAL_VERIFY_FAILED → 抛 {@link CompliancePollError} kind='terminal_failure';
1035
+ * - UNKNOWN / RETRYING / PENDING → 继续轮询直到 timeout;
1036
+ * - timeout → 抛 {@link CompliancePollError} kind='timeout'。
1037
+ */
1038
+ waitForTimestampVerified(id: number, opts?: CompliancePollOptions): Promise<TimestampToken>;
1039
+ /** 构建证据包(写)。 */
1040
+ buildEvidencePackage(assetId: number, timestampTokenId?: number, opts?: ComplianceWriteOptions): Promise<EvidencePackage>;
1041
+ /** 创建证据报告(写)。 */
1042
+ createReport(req: CreateReportRequest, opts?: ComplianceWriteOptions): Promise<ComplianceReport>;
1043
+ /** 读 — 报告详情。 */
1044
+ getReport(id: number, signal?: AbortSignal): Promise<ComplianceReport>;
1045
+ /**
1046
+ * 发布报告(写,step-up 必须)。
1047
+ *
1048
+ * 缺少 step-up 时服务端会返回 `COMPLIANCE_STEP_UP_REQUIRED`(数值码
1049
+ * 1031000013)。SDK 不会自动重试;调用方需要引导用户重新做 OAuth introspection 或
1050
+ * 重新登录后再次调用本方法(使用同一 idempotency-key)。
1051
+ */
1052
+ publishReport(id: number, opts?: ComplianceWriteOptions): Promise<ComplianceReport>;
1053
+ /**
1054
+ * 下载报告(读)。返回 {@link ReportDownload}:报告 hash + 资产 hash + 证据包 hash +
1055
+ * 时间章 serial/genTime,足以离线复核。
1056
+ * 不返回 bodyCanonicalJson / storage key / subject snapshot id。
1057
+ */
1058
+ downloadReport(id: number, signal?: AbortSignal): Promise<ReportDownload>;
1059
+ /** 创建 envelope(写)。返回 envelope id。 */
1060
+ createSigningEnvelope(req: CreateSigningEnvelopeRequest, opts?: ComplianceWriteOptions): Promise<number>;
1061
+ /** 读 — envelope 详情。租户由服务端从 compliance token principal 推导。 */
1062
+ getSigningEnvelope(envelopeId: number, signal?: AbortSignal): Promise<SigningEnvelope>;
1063
+ /**
1064
+ * 正式签署(写,step-up 必须)。
1065
+ *
1066
+ * 服务端闸门关闭时会一致返回 `ENVELOPE_GATE_CLOSED` (1031004004)。
1067
+ * SDK 不重试、不伪成功;调用方应该将该错误展示为"功能未开放"。
1068
+ */
1069
+ signEnvelope(envelopeId: number, req: SignEnvelopeRequest, opts?: ComplianceWriteOptions): Promise<void>;
1070
+ /**
1071
+ * 创建 H5 签署短链(写,step-up 必须)。
1072
+ *
1073
+ * 同上:服务端闸门关闭时 SDK 不重试。
1074
+ */
1075
+ createH5SigningUrl(envelopeId: number, req: CreateH5SigningUrlRequest, opts?: ComplianceWriteOptions): Promise<string>;
1076
+ /** 同步 provider 状态(写但只读对账,不创建新 provider 请求)。 */
1077
+ syncSigningEnvelopeStatus(envelopeId: number, opts?: ComplianceWriteOptions): Promise<void>;
1078
+ submitSealApproval(req: SubmitSealApprovalRequest, opts?: ComplianceWriteOptions): Promise<number>;
1079
+ approveSealApproval(id: number, query: ApproveSealApprovalQuery, opts?: ComplianceWriteOptions): Promise<void>;
1080
+ rejectSealApproval(id: number, query: RejectSealApprovalQuery, opts?: ComplianceWriteOptions): Promise<void>;
1081
+ cancelSealApproval(id: number, query: CancelSealApprovalQuery, opts?: ComplianceWriteOptions): Promise<void>;
1082
+ listPendingSealApprovals(signal?: AbortSignal): Promise<SealApproval[]>;
1083
+ getSealApproval(id: number, signal?: AbortSignal): Promise<SealApproval>;
1084
+ getProviderRequest(id: number, signal?: AbortSignal): Promise<ProviderRequestStatusView>;
1085
+ /**
1086
+ * 轮询 provider request 到 SUCCESS / FAILED 终态。
1087
+ * - SUCCESS / FAILED → 返回最后视图;
1088
+ * - UNKNOWN / RETRYING / PENDING → 继续轮询;
1089
+ * - timeout → 抛 {@link CompliancePollError} kind='timeout',不自动重发原 provider 请求。
1090
+ *
1091
+ * SUCCESS 不代表 billing 已 commit;调用方仍需通过业务侧 envelope / asset 终态判断。
1092
+ */
1093
+ waitForProviderRequestTerminal(id: number, opts?: CompliancePollOptions): Promise<ProviderRequestStatusView>;
1094
+ classifyError(err: unknown): ComplianceErrorInfo | null;
1095
+ /**
1096
+ * 读路径:GET / 公开 verify。允许 401 单次刷新后重放(GET 幂等安全)。
1097
+ * 与 client.doJSONFullInternal 行为一致;不复用其代码因为 base URL 不同。
1098
+ */
1099
+ private read;
1100
+ /**
1101
+ * 写路径:POST。
1102
+ * - 发送前 ensureToken 一次确保 token fresh。
1103
+ * - 不自动 401 重放:401 → 抛 HTTPError;调用方必须自己刷新 token 后用同一
1104
+ * idempotency-key 重新发起,避免 provider 侧重复请求。
1105
+ * - 不走 doRequestWithRetry:写操作不允许 5xx/timeout 自动重试。
1106
+ */
1107
+ private write;
1108
+ private executeJson;
1109
+ private poll;
1110
+ }
1111
+
1112
+ /** SDK 为单个 content block 缓存的元数据 */
1113
+ interface BlockMeta {
1114
+ type: string;
1115
+ ephemeral: boolean;
1116
+ }
1117
+ /**
1118
+ * 按 Anthropic SSE 事件类型解析 data, 更新 blockTypeMap, 返回 [index, type, ephemeral]。
1119
+ *
1120
+ * 仅当事件为 content_block_start / content_block_delta / content_block_stop
1121
+ * 时返回非空 type; 其他事件返回空 type, 调用方据此判别是否填充 StreamEvent 元数据字段。
1122
+ */
1123
+ declare function extractAnthropicBlockMeta(eventType: string, data: string, blockTypeMap: Map<number, BlockMeta>): [number, string, boolean];
1124
+
1125
+ type AgentRunStatus = 'queued' | 'running' | 'completed' | 'failed' | 'cancelled';
1126
+ interface AgentRunLocalContextPolicy {
1127
+ enabled?: boolean;
1128
+ readonly?: boolean;
1129
+ maxBytes?: number;
1130
+ allowedTools?: string[];
1131
+ }
1132
+ interface AgentRunArtifactPolicy {
1133
+ enabled?: boolean;
1134
+ maxFiles?: number;
1135
+ }
1136
+ interface AgentRunCreateRequest {
1137
+ appId: string;
1138
+ mode?: string;
1139
+ sessionId?: string;
1140
+ input: string;
1141
+ messages?: unknown[];
1142
+ model?: string;
1143
+ activeSkillIds?: string[];
1144
+ knowledgeBaseIds?: string[];
1145
+ metadata?: Record<string, string>;
1146
+ localContextPolicy?: AgentRunLocalContextPolicy;
1147
+ artifactPolicy?: AgentRunArtifactPolicy;
1148
+ }
1149
+ interface AgentRun {
1150
+ runId: string;
1151
+ sessionId: string;
1152
+ appId?: string;
1153
+ mode?: string;
1154
+ status: AgentRunStatus;
1155
+ createdAt?: string;
1156
+ startedAt?: string;
1157
+ completedAt?: string;
1158
+ error?: AgentRunErrorPayload;
1159
+ metadata?: Record<string, string>;
1160
+ }
1161
+ interface AgentRunCreateResponse {
1162
+ runId: string;
1163
+ sessionId: string;
1164
+ status: AgentRunStatus;
1165
+ }
1166
+ interface AgentRunArtifact {
1167
+ id: string;
1168
+ filename: string;
1169
+ contentType?: string;
1170
+ size?: number;
1171
+ type?: string;
1172
+ metadata?: Record<string, string>;
1173
+ }
1174
+ interface AgentRunArtifactList {
1175
+ artifacts: AgentRunArtifact[];
1176
+ }
1177
+ interface AgentRunDownload {
1178
+ data: Uint8Array;
1179
+ filename: string;
1180
+ contentType?: string;
1181
+ }
1182
+ interface AgentRunUsage {
1183
+ inputTokens?: number;
1184
+ outputTokens?: number;
1185
+ totalTokens?: number;
1186
+ cacheReadTokens?: number;
1187
+ cacheCreateTokens?: number;
1188
+ exact?: boolean;
1189
+ source?: string;
1190
+ [key: string]: unknown;
1191
+ }
1192
+ interface AgentRunSettlement {
1193
+ requestId?: string;
1194
+ status?: string;
1195
+ consumeStatus?: string;
1196
+ inputTokens?: number;
1197
+ outputTokens?: number;
1198
+ totalTokens?: number;
1199
+ cacheReadTokens?: number;
1200
+ cacheCreateTokens?: number;
1201
+ tokenRemaining?: number;
1202
+ callRemaining?: number;
1203
+ retryQueued?: boolean;
1204
+ exact?: boolean;
1205
+ [key: string]: unknown;
1206
+ }
1207
+ interface AgentRunErrorPayload {
1208
+ code?: string;
1209
+ message: string;
1210
+ stage?: string;
1211
+ retryable?: boolean;
1212
+ raw?: unknown;
1213
+ }
1214
+ interface AgentRunLocalToolResult {
1215
+ requestId: string;
1216
+ ok: boolean;
1217
+ content?: unknown;
1218
+ error?: string;
1219
+ }
1220
+ interface AgentRunLocalToolHandlerContext {
1221
+ runId: string;
1222
+ requestId: string;
1223
+ name: string;
1224
+ signal: AbortSignal;
1225
+ }
1226
+ type AgentRunLocalToolHandler = (input: unknown, context: AgentRunLocalToolHandlerContext) => Promise<unknown> | unknown;
1227
+ interface AgentRunStreamOptions {
1228
+ /**
1229
+ * true by default. When enabled, an error event is converted into
1230
+ * AgentRunStreamError after the event has been parsed.
1231
+ */
1232
+ throwOnError?: boolean;
1233
+ }
1234
+ interface AgentRunRunOptions extends AgentRunStreamOptions {
1235
+ }
1236
+ interface AgentRunWithLocalToolsOptions extends AgentRunRunOptions {
1237
+ timeoutMs?: number;
1238
+ onEvent?: (event: AgentRunStreamEvent) => void | Promise<void>;
1239
+ }
1240
+ type AgentRunStreamEvent = {
1241
+ type: 'run_started';
1242
+ runId: string;
1243
+ sessionId: string;
1244
+ } | {
1245
+ type: 'status';
1246
+ status: AgentRunStatus | string;
1247
+ message?: string;
1248
+ } | {
1249
+ type: 'text_delta';
1250
+ text: string;
1251
+ } | {
1252
+ type: 'reasoning_delta';
1253
+ text: string;
1254
+ } | {
1255
+ type: 'tool_call';
1256
+ id: string;
1257
+ name: string;
1258
+ input?: unknown;
1259
+ } | {
1260
+ type: 'tool_result';
1261
+ id: string;
1262
+ name?: string;
1263
+ result?: unknown;
1264
+ error?: string;
1265
+ } | {
1266
+ type: 'local_tool_request';
1267
+ requestId: string;
1268
+ name: string;
1269
+ input: unknown;
1270
+ } | {
1271
+ type: 'artifact';
1272
+ artifact: AgentRunArtifact;
1273
+ } | {
1274
+ type: 'sources';
1275
+ sources: unknown;
1276
+ } | {
1277
+ type: 'usage';
1278
+ usage: AgentRunUsage;
1279
+ } | {
1280
+ type: 'settle';
1281
+ settlement: AgentRunSettlement;
1282
+ } | {
1283
+ type: 'error';
1284
+ error: AgentRunErrorPayload;
1285
+ } | {
1286
+ type: 'done';
1287
+ runId: string;
1288
+ status: AgentRunStatus | string;
1289
+ };
1290
+ declare class AgentRunStreamError extends Error {
1291
+ event: Extract<AgentRunStreamEvent, {
1292
+ type: 'error';
1293
+ }>;
1294
+ code: string;
1295
+ stage: string;
1296
+ retryable: boolean;
1297
+ constructor(event: Extract<AgentRunStreamEvent, {
1298
+ type: 'error';
1299
+ }>);
1300
+ }
1301
+
808
1302
  declare module '@acosmi/sdk-ts' {
809
1303
  interface Client {
810
1304
  /** SDK-facing cloud agent run gateway. */
@@ -1079,4 +1573,4 @@ declare module '@acosmi/sdk-ts' {
1079
1573
  }
1080
1574
  }
1081
1575
 
1082
- 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 AuthorizeResult, BalanceDetail, type BlockMeta, type BugReportResult, type BugView, CertificationStatus, ChatRequest, ChatResponse, Client, ClientRegistration, type Config, ConsumeRecordPage, DefaultRetryPolicy, DeviceRegistration, EntitlementBalance, EntitlementItem, ErrAuthDenied, ErrBrowserOpen, ErrDiscovery, ErrRegistration, ErrSSLProxy, ErrTimeout, ErrTokenExchange, EventAuthURL, EventComplete, EventError, FileTokenStore, type FilterStatus, FilterStatusAdminBypass, FilterStatusDisabledByFlag, FilterStatusFallbackMissingUser, FilterStatusFallbackNoBuckets, FilterStatusFallbackTkdistError, FilterStatusFallbackTkdistSkew, FilterStatusInternalBypass, FilterStatusOK, FilterStatusUnknown, GenerateSkillRequest, GenerateSkillResult, InMemoryTokenStore, InputModality, LocalStorageTokenStore, type LoginErrCode, type LoginEvent, type LoginEventType, type LoginOptions, ManagedModel, ModelBucket, ModelByQuotaResponse, ModelCapabilities, ModelCoefficient, NotificationList, NotificationPreference, OptimizeSkillRequest, OptimizeSkillResult, Order, OrderStatus, PayPayload, ProviderAdapter, QuotaSummary, type RetryPolicy, type RetryRequestInfo, ScopeAI, ScopeAccount, ScopeEntitlements, ScopeModels, ScopeModelsChat, ScopeProfile, ScopeSkillStore, ScopeSkills, ScopeTokenPackages, ScopeTools, ScopeToolsExecute, ScopeWallet, ScopeWalletReadonly, ServerMetadata, SkillBrowseListResponse, SkillBrowseResponse, SkillStoreItem, SkillStoreQuery, SkillSummary, SourcesEvent, StreamEvent, StreamSettlement, TokenPackage, TokenResponse, TokenSet, type TokenStore, ToolView, Transaction, type WSConfig, WSEvent, WalletStats, allScopes, authorize, buildBetas, commerceScopes, computeBackoff, defaultRetryable, defaultSafeToRetry, discover, effectivePolicy, exchangeCode, extractAnthropicBlockMeta, fileLockDefaults, findDesktopVisualUnderstandingModel, findFirstModelByInputModality, isSSLError, modelScopes, modelSupportsImageInput, modelSupportsInputModality, newFileTokenStore, newTokenSet, refreshToken, register, revokeToken, skillScopes, uniqueMerge };
1576
+ 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 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, DefaultRetryPolicy, DeviceRegistration, EntitlementBalance, EntitlementItem, ErrAuthDenied, ErrBillingCallbackCannotCommit, ErrBillingCommitRequiresLocalVerify, ErrBillingS2sForbidden, ErrBrowserOpen, ErrComplianceStepUpRequired, ErrDiscovery, ErrEnvelopeGateClosed, ErrProviderNotConfigured, ErrProviderUnknownNoRetry, ErrRegistration, ErrSSLProxy, ErrSealApprovalContractHashMismatch, ErrSealApprovalExpired, ErrSealApprovalLocationMismatch, ErrSealApprovalNonceUsed, ErrSealApprovalNotApproved, ErrSealApprovalSealMismatch, ErrSealApprovalTransactorMismatch, ErrSealUseAlreadyConsumed, ErrTimeout, ErrTokenExchange, 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, OptimizeSkillRequest, OptimizeSkillResult, Order, OrderStatus, PayPayload, ProviderAdapter, type ProviderRequestStatusView, type PublicEvidenceVerifyResult, QuotaSummary, type RejectSealApprovalQuery, type ReportDownload, type RetryPolicy, type RetryRequestInfo, ScopeAI, ScopeAccount, ScopeComplianceContractSigningRead, ScopeComplianceContractSigningWrite, ScopeComplianceEvidenceRead, ScopeComplianceEvidenceWrite, ScopeComplianceReportsPublish, ScopeComplianceReportsRead, 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, allScopes, authorize, buildBetas, classifyComplianceError, commerceScopes, complianceScopes, computeBackoff, defaultRetryable, defaultSafeToRetry, discover, effectivePolicy, exchangeCode, extractAnthropicBlockMeta, fileLockDefaults, findDesktopVisualUnderstandingModel, findFirstModelByInputModality, isBillingConfirmable, isComplianceBusinessError, isComplianceTerminalError, isSSLError, modelScopes, modelSupportsImageInput, modelSupportsInputModality, newFileTokenStore, newTokenSet, refreshToken, register, revokeToken, skillScopes, uniqueMerge };