@acosmi/sdk-ts 1.0.2 → 1.2.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,10 +1,53 @@
1
- import { S as ServerMetadata, T as TokenResponse, a as TokenSet, C as ClientRegistration, M as ModelCapabilities, b as ChatRequest, c as ManagedModel, d as ModelCoefficient, Q as QuotaSummary, 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-C3Z_84Bv.cjs';
2
- export { I as APIResponse, J as AnthropicContentBlock, K as AnthropicUsage, L as BucketClassCommercial, R as BucketClassGeneric, U as BucketInfo, V as BucketRow, X as BusinessError, Y as ChatContentBlock, Z as ChatMessage, _ as ChatUsage, $ as ConsumeRecord, a0 as EffortConfig, a1 as GeoLoc, a2 as HTTPError, a3 as ModelNotFoundError, a4 as NetworkError, a5 as Notification, a6 as NotificationUnreadCount, a7 as OpenAIChatChoice, a8 as OpenAIChatMessage, a9 as OpenAIChatResponse, aa as OpenAIFunctionCall, ab as OpenAIStreamChoice, ac as OpenAIStreamChunk, ad as OpenAIStreamDelta, ae as OpenAIStreamToolCall, af as OpenAIToolCall, ag as OpenAIUsage, ah as OrderTerminalError, ai as OutputConfig, aj as ProviderFormat, ak as RateLimitError, al as ServerTool, am as ServerToolTypeWebSearch, an as SkillStoreListItem, ao as StreamError, ap as ThinkingConfig, aq as ThinkingHigh, ar as ThinkingHighMinMaxTokens, as as ThinkingMax, at as ThinkingMaxFallbackMaxTokens, au as ThinkingOff, av as ToolListResponse, aw as ToolProvider, ax as WebSearchConfig, ay as WebSearchSource, az as YudaoPageResult, aA as anthropicResponseTextContent, aB as anthropicResponseThinkingContent, aC as anthropicResponseToolUseBlocks, aD as apiResponseBusinessError, aE as apiResponseGetMessage, aF as bucketInfoIsCommercial, aG as bucketRowIsCommercial, aH as getAdapter, aI as getAdapterForModel, aJ as newThinkingConfig, aK as newWebSearchTool, aL as parseNotificationEvent, aM as parseSettlement, aN as parseSourcesEvent, aO as tokenSetIsExpired } from './index-C3Z_84Bv.cjs';
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.cjs';
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.cjs';
3
3
  import { M as MinimalSanitizeConfig } from './index-nvLKgCm9.cjs';
4
4
  export { i as sanitize } from './index-nvLKgCm9.cjs';
5
5
  export { AnthropicAdapter } from './adapters/anthropic.cjs';
6
6
  export { OpenAIAdapter } from './adapters/openai.cjs';
7
7
 
8
+ /**
9
+ * 判断 ManagedModel 是否声明支持指定输入模态.
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 顺序第一个
44
+ *
45
+ * 全部不满足返 null. 调用方收到 null 应:
46
+ * - 提示用户在管理后台/网关侧开启桌面视觉 sidecar 模型, 或
47
+ * - 降级停掉依赖截图的工作流, 而不是硬选一个非视觉模型送图.
48
+ */
49
+ declare function findDesktopVisualUnderstandingModel(models: ManagedModel[]): ManagedModel | null;
50
+
8
51
  /**
9
52
  * 从 well-known 端点获取 Desktop OAuth 服务元数据。
10
53
  *
@@ -297,10 +340,182 @@ interface BlockMeta {
297
340
  */
298
341
  declare function extractAnthropicBlockMeta(eventType: string, data: string, blockTypeMap: Map<number, BlockMeta>): [number, string, boolean];
299
342
 
300
- /** 根据模型能力和请求参数自动组装 beta header 列表 */
301
- declare function buildBetas(caps: ModelCapabilities, req: ChatRequest): string[];
302
- /** 合并两个字符串数组并去重, 保留顺序 */
303
- declare function uniqueMerge(base: string[], extra: string[]): string[];
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
+ }
304
519
 
305
520
  type FilterStatus = 'ok' | 'admin-bypass' | 'internal-bypass' | 'disabled-by-flag' | 'fallback-tkdist-error' | 'fallback-tkdist-deployment-skew' | 'fallback-no-buckets' | 'fallback-missing-userid' | '';
306
521
  declare const FilterStatusOK: FilterStatus;
@@ -590,6 +805,37 @@ declare class Client {
590
805
  }, signal?: AbortSignal): Promise<Response>;
591
806
  }
592
807
 
808
+ declare module '@acosmi/sdk-ts' {
809
+ interface Client {
810
+ /** SDK-facing cloud agent run gateway. */
811
+ readonly agentRuns: AgentRunsClient;
812
+ }
813
+ }
814
+ declare class AgentRunsClient {
815
+ private readonly client;
816
+ constructor(client: Client);
817
+ create(req: AgentRunCreateRequest, signal?: AbortSignal): Promise<AgentRunCreateResponse>;
818
+ get(runId: string, signal?: AbortSignal): Promise<AgentRun>;
819
+ stream(runId: string, opts?: AgentRunStreamOptions, signal?: AbortSignal): AsyncIterable<AgentRunStreamEvent>;
820
+ cancel(runId: string, signal?: AbortSignal): Promise<AgentRun>;
821
+ listArtifacts(runId: string, signal?: AbortSignal): Promise<AgentRunArtifact[]>;
822
+ downloadArtifact(runId: string, artifactId: string, signal?: AbortSignal): Promise<AgentRunDownload>;
823
+ submitLocalToolResult(runId: string, result: AgentRunLocalToolResult, signal?: AbortSignal): Promise<AgentRun>;
824
+ run(req: AgentRunCreateRequest, opts?: AgentRunRunOptions, signal?: AbortSignal): AsyncIterable<AgentRunStreamEvent>;
825
+ runWithLocalTools(req: AgentRunCreateRequest, handlers: Record<string, AgentRunLocalToolHandler>, opts?: AgentRunWithLocalToolsOptions, signal?: AbortSignal): AsyncIterable<AgentRunStreamEvent>;
826
+ private runGen;
827
+ private runWithLocalToolsGen;
828
+ private invokeLocalTool;
829
+ private streamGen;
830
+ private requestAPI;
831
+ private requestRaw;
832
+ }
833
+
834
+ /** 根据模型能力和请求参数自动组装 beta header 列表 */
835
+ declare function buildBetas(caps: ModelCapabilities, req: ChatRequest): string[];
836
+ /** 合并两个字符串数组并去重, 保留顺序 */
837
+ declare function uniqueMerge(base: string[], extra: string[]): string[];
838
+
593
839
  declare module '@acosmi/sdk-ts' {
594
840
  interface Client {
595
841
  /** 查询当前用户的权益余额 (聚合) */
@@ -833,4 +1079,4 @@ declare module '@acosmi/sdk-ts' {
833
1079
  }
834
1080
  }
835
1081
 
836
- export { 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, 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, isSSLError, modelScopes, newFileTokenStore, newTokenSet, refreshToken, register, revokeToken, skillScopes, uniqueMerge };
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 };
@@ -1,10 +1,53 @@
1
- import { S as ServerMetadata, T as TokenResponse, a as TokenSet, C as ClientRegistration, M as ModelCapabilities, b as ChatRequest, c as ManagedModel, d as ModelCoefficient, Q as QuotaSummary, 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-C3Z_84Bv.js';
2
- export { I as APIResponse, J as AnthropicContentBlock, K as AnthropicUsage, L as BucketClassCommercial, R as BucketClassGeneric, U as BucketInfo, V as BucketRow, X as BusinessError, Y as ChatContentBlock, Z as ChatMessage, _ as ChatUsage, $ as ConsumeRecord, a0 as EffortConfig, a1 as GeoLoc, a2 as HTTPError, a3 as ModelNotFoundError, a4 as NetworkError, a5 as Notification, a6 as NotificationUnreadCount, a7 as OpenAIChatChoice, a8 as OpenAIChatMessage, a9 as OpenAIChatResponse, aa as OpenAIFunctionCall, ab as OpenAIStreamChoice, ac as OpenAIStreamChunk, ad as OpenAIStreamDelta, ae as OpenAIStreamToolCall, af as OpenAIToolCall, ag as OpenAIUsage, ah as OrderTerminalError, ai as OutputConfig, aj as ProviderFormat, ak as RateLimitError, al as ServerTool, am as ServerToolTypeWebSearch, an as SkillStoreListItem, ao as StreamError, ap as ThinkingConfig, aq as ThinkingHigh, ar as ThinkingHighMinMaxTokens, as as ThinkingMax, at as ThinkingMaxFallbackMaxTokens, au as ThinkingOff, av as ToolListResponse, aw as ToolProvider, ax as WebSearchConfig, ay as WebSearchSource, az as YudaoPageResult, aA as anthropicResponseTextContent, aB as anthropicResponseThinkingContent, aC as anthropicResponseToolUseBlocks, aD as apiResponseBusinessError, aE as apiResponseGetMessage, aF as bucketInfoIsCommercial, aG as bucketRowIsCommercial, aH as getAdapter, aI as getAdapterForModel, aJ as newThinkingConfig, aK as newWebSearchTool, aL as parseNotificationEvent, aM as parseSettlement, aN as parseSourcesEvent, aO as tokenSetIsExpired } from './index-C3Z_84Bv.js';
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';
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';
6
6
  export { OpenAIAdapter } from './adapters/openai.js';
7
7
 
8
+ /**
9
+ * 判断 ManagedModel 是否声明支持指定输入模态.
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 顺序第一个
44
+ *
45
+ * 全部不满足返 null. 调用方收到 null 应:
46
+ * - 提示用户在管理后台/网关侧开启桌面视觉 sidecar 模型, 或
47
+ * - 降级停掉依赖截图的工作流, 而不是硬选一个非视觉模型送图.
48
+ */
49
+ declare function findDesktopVisualUnderstandingModel(models: ManagedModel[]): ManagedModel | null;
50
+
8
51
  /**
9
52
  * 从 well-known 端点获取 Desktop OAuth 服务元数据。
10
53
  *
@@ -297,10 +340,182 @@ interface BlockMeta {
297
340
  */
298
341
  declare function extractAnthropicBlockMeta(eventType: string, data: string, blockTypeMap: Map<number, BlockMeta>): [number, string, boolean];
299
342
 
300
- /** 根据模型能力和请求参数自动组装 beta header 列表 */
301
- declare function buildBetas(caps: ModelCapabilities, req: ChatRequest): string[];
302
- /** 合并两个字符串数组并去重, 保留顺序 */
303
- declare function uniqueMerge(base: string[], extra: string[]): string[];
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
+ }
304
519
 
305
520
  type FilterStatus = 'ok' | 'admin-bypass' | 'internal-bypass' | 'disabled-by-flag' | 'fallback-tkdist-error' | 'fallback-tkdist-deployment-skew' | 'fallback-no-buckets' | 'fallback-missing-userid' | '';
306
521
  declare const FilterStatusOK: FilterStatus;
@@ -590,6 +805,37 @@ declare class Client {
590
805
  }, signal?: AbortSignal): Promise<Response>;
591
806
  }
592
807
 
808
+ declare module '@acosmi/sdk-ts' {
809
+ interface Client {
810
+ /** SDK-facing cloud agent run gateway. */
811
+ readonly agentRuns: AgentRunsClient;
812
+ }
813
+ }
814
+ declare class AgentRunsClient {
815
+ private readonly client;
816
+ constructor(client: Client);
817
+ create(req: AgentRunCreateRequest, signal?: AbortSignal): Promise<AgentRunCreateResponse>;
818
+ get(runId: string, signal?: AbortSignal): Promise<AgentRun>;
819
+ stream(runId: string, opts?: AgentRunStreamOptions, signal?: AbortSignal): AsyncIterable<AgentRunStreamEvent>;
820
+ cancel(runId: string, signal?: AbortSignal): Promise<AgentRun>;
821
+ listArtifacts(runId: string, signal?: AbortSignal): Promise<AgentRunArtifact[]>;
822
+ downloadArtifact(runId: string, artifactId: string, signal?: AbortSignal): Promise<AgentRunDownload>;
823
+ submitLocalToolResult(runId: string, result: AgentRunLocalToolResult, signal?: AbortSignal): Promise<AgentRun>;
824
+ run(req: AgentRunCreateRequest, opts?: AgentRunRunOptions, signal?: AbortSignal): AsyncIterable<AgentRunStreamEvent>;
825
+ runWithLocalTools(req: AgentRunCreateRequest, handlers: Record<string, AgentRunLocalToolHandler>, opts?: AgentRunWithLocalToolsOptions, signal?: AbortSignal): AsyncIterable<AgentRunStreamEvent>;
826
+ private runGen;
827
+ private runWithLocalToolsGen;
828
+ private invokeLocalTool;
829
+ private streamGen;
830
+ private requestAPI;
831
+ private requestRaw;
832
+ }
833
+
834
+ /** 根据模型能力和请求参数自动组装 beta header 列表 */
835
+ declare function buildBetas(caps: ModelCapabilities, req: ChatRequest): string[];
836
+ /** 合并两个字符串数组并去重, 保留顺序 */
837
+ declare function uniqueMerge(base: string[], extra: string[]): string[];
838
+
593
839
  declare module '@acosmi/sdk-ts' {
594
840
  interface Client {
595
841
  /** 查询当前用户的权益余额 (聚合) */
@@ -833,4 +1079,4 @@ declare module '@acosmi/sdk-ts' {
833
1079
  }
834
1080
  }
835
1081
 
836
- export { 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, 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, isSSLError, modelScopes, newFileTokenStore, newTokenSet, refreshToken, register, revokeToken, skillScopes, uniqueMerge };
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 };