@acosmi/sdk-ts 2.0.1 → 2.1.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.
- package/CHANGELOG.md +17 -0
- package/README.md +240 -54
- package/dist/browser/index.mjs +403 -3
- package/dist/browser/index.mjs.map +1 -1
- package/dist/index.mjs +403 -3
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +421 -2
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +447 -3
- package/dist/node/index.d.ts +447 -3
- package/dist/node/index.mjs +403 -3
- package/dist/node/index.mjs.map +1 -1
- package/docs//345/274/200/345/217/221/344/270/216/345/217/221/345/270/203/346/211/213/345/206/214.md +115 -20
- package/package.json +1 -1
package/dist/node/index.d.cts
CHANGED
|
@@ -184,6 +184,13 @@ interface ClientRegistration {
|
|
|
184
184
|
client_secret?: string;
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
+
declare class OAuthTokenEndpointError extends Error {
|
|
188
|
+
readonly status: number;
|
|
189
|
+
readonly oauthError: string;
|
|
190
|
+
readonly errorDescription: string;
|
|
191
|
+
constructor(status: number, oauthError: string, errorDescription: string);
|
|
192
|
+
}
|
|
193
|
+
declare function isInvalidGrantError(err: unknown): boolean;
|
|
187
194
|
/** OAuth metadata profile — 决定 well-known 端点的路径后缀 */
|
|
188
195
|
type OAuthMetadataProfile = 'web' | 'desktop';
|
|
189
196
|
/**
|
|
@@ -564,13 +571,48 @@ declare const FilterStatusFallbackTkdistSkew: FilterStatus;
|
|
|
564
571
|
declare const FilterStatusFallbackNoBuckets: FilterStatus;
|
|
565
572
|
declare const FilterStatusFallbackMissingUser: FilterStatus;
|
|
566
573
|
declare const FilterStatusUnknown: FilterStatus;
|
|
574
|
+
/** Acosmi Gateway URL 默认值 — 与历史行为一致。 */
|
|
575
|
+
declare const DEFAULT_GATEWAY_BASE_URL = "https://acosmi.com";
|
|
576
|
+
/**
|
|
577
|
+
* normalizeGatewayBaseURL — Acosmi nexus-v4 API Gateway URL 的归一化与校验。
|
|
578
|
+
*
|
|
579
|
+
* 红线 (Phase 0 契约 §1-§2):
|
|
580
|
+
* 1. 仅允许 `http:` / `https:`;`ws:` / `wss:` 是 CrabCode `--sdk-url`
|
|
581
|
+
* RemoteIO 会话通道,不是 SDK API gateway URL,传入立刻抛错。
|
|
582
|
+
* 2. URL 必须可被 `new URL()` 解析;非法输入立刻抛错。
|
|
583
|
+
* 3. host 必须非空;query/hash 不允许 (gateway URL 不带 query)。
|
|
584
|
+
* 4. pathname 去尾 `/`;末段允许是 `/api/v4` (`apiURL()` 不会重复追加)。
|
|
585
|
+
* 5. 返回值是 `origin + pathname`,不带 query/hash/trailing slash。
|
|
586
|
+
*
|
|
587
|
+
* 该函数是公共 helper:CrabCode AppServer worker、CrabClaw 内部、外部第三方 SDK
|
|
588
|
+
* 都应在写入 Acosmi base 之前调用它一次,避免 ws/wss 误入 SDK API client。
|
|
589
|
+
*/
|
|
590
|
+
declare function normalizeGatewayBaseURL(input: unknown): string;
|
|
567
591
|
/** 客户端配置 */
|
|
568
592
|
interface Config {
|
|
569
593
|
/**
|
|
570
|
-
* nexus-v4 API 根地址 (默认 https://acosmi.com)。
|
|
571
|
-
*
|
|
594
|
+
* Acosmi nexus-v4 API Gateway 根地址 (默认 https://acosmi.com)。
|
|
595
|
+
*
|
|
596
|
+
* 该 URL 是 `@acosmi/sdk-ts` 调 Acosmi 云端 API 的根 — agent-runs /
|
|
597
|
+
* managed-models / notifications WS / compliance 都从它派生。SDK 内部
|
|
598
|
+
* `apiURL()` 会自动追加 `/api/v4`,调用方无需手动拼。
|
|
599
|
+
*
|
|
600
|
+
* 见 Phase 0 契约 `docs/audit/sdk-remote-control-contract-2026-05-27.md` §1-§2:
|
|
601
|
+
* - 协议: 仅允许 `http:` / `https:`;`ws:` / `wss:` 是 CrabCode `--sdk-url`
|
|
602
|
+
* RemoteIO 会话通道,不是 SDK gateway URL,传入将抛 `Error`。
|
|
603
|
+
* - `serverURL` / `baseURL` / `baseUrl` 三字段同语义,多写时 normalize 后必须相等。
|
|
572
604
|
*/
|
|
573
605
|
serverURL?: string;
|
|
606
|
+
/**
|
|
607
|
+
* `serverURL` 的标准 alias (推荐拼写)。语义、normalize、校验完全等同 serverURL。
|
|
608
|
+
* 见 Phase 0 契约 §2。同时传入 serverURL/baseURL/baseUrl 时三者 normalize 后必须相等。
|
|
609
|
+
*/
|
|
610
|
+
baseURL?: string;
|
|
611
|
+
/**
|
|
612
|
+
* `serverURL` 的 camelCase-小写 alias。语义、normalize、校验完全等同 serverURL。
|
|
613
|
+
* 见 Phase 0 契约 §2。
|
|
614
|
+
*/
|
|
615
|
+
baseUrl?: string;
|
|
574
616
|
/** token 持久化实现, 缺省时按平台选 (Node File / Browser LocalStorage / Memory) */
|
|
575
617
|
store?: TokenStore;
|
|
576
618
|
/** 自定义 fetch 实现 (默认 globalThis.fetch) */
|
|
@@ -696,6 +738,16 @@ declare class Client {
|
|
|
696
738
|
static create(cfg?: Config): Promise<Client>;
|
|
697
739
|
/** 是否已授权 (有可用 token) */
|
|
698
740
|
isAuthorized(): boolean;
|
|
741
|
+
/**
|
|
742
|
+
* 返回归一化后的 Acosmi Gateway URL (= `serverURL` 字段). readonly helper.
|
|
743
|
+
*
|
|
744
|
+
* Phase 0 §2 红线:
|
|
745
|
+
* - 不要 mutate `client.serverURL` 字段实现 base 切换; 用 per-base Client 实例.
|
|
746
|
+
* - 该值仅供日志/排查/上层缓存键使用, 不重新 normalize 它 (构造期已 normalize).
|
|
747
|
+
*/
|
|
748
|
+
getServerURL(): string;
|
|
749
|
+
/** `getServerURL()` 的 alias — Phase 0 §2 baseURL 与 serverURL 同义. */
|
|
750
|
+
getBaseURL(): string;
|
|
699
751
|
/** 当前 token 信息 (用于 CLI whoami 显示) */
|
|
700
752
|
getTokenSet(): TokenSet | null;
|
|
701
753
|
private getCachedClientID;
|
|
@@ -732,6 +784,7 @@ declare class Client {
|
|
|
732
784
|
private refreshCurrentTokenDirect;
|
|
733
785
|
private refreshCurrentTokenViaProxy;
|
|
734
786
|
private saveRefreshedToken;
|
|
787
|
+
private clearInvalidRefreshToken;
|
|
735
788
|
/** 互斥锁 helper (替代 Go sync.Mutex) */
|
|
736
789
|
private withMu;
|
|
737
790
|
/** v1.0.2: 跨进程临界区 helper. store.withLock 可选, 缺省则直接调用 fn (LocalStorage /
|
|
@@ -1362,6 +1415,14 @@ interface BillingPreflightResult {
|
|
|
1362
1415
|
declare const ScopeAI = "ai";
|
|
1363
1416
|
declare const ScopeSkills = "skills";
|
|
1364
1417
|
declare const ScopeAccount = "account";
|
|
1418
|
+
/** 远程控制能力 (分组 scope, 自包含展开到 3 个子 scope). 高风险, 不进 allScopes(). */
|
|
1419
|
+
declare const ScopeRemoteControl = "remote_control";
|
|
1420
|
+
/** 创建 / 取消 / stream AgentRun. */
|
|
1421
|
+
declare const ScopeRemoteControlAgentRun = "remote_control:agent-run";
|
|
1422
|
+
/** 远程会话 lifecycle 控制 (cancel / interrupt / kill). */
|
|
1423
|
+
declare const ScopeRemoteControlSessionControl = "remote_control:session-control";
|
|
1424
|
+
/** 代表用户提交远控权限审批响应 (allow / deny / timeout). */
|
|
1425
|
+
declare const ScopeRemoteControlPermissionResponse = "remote_control:permission-response";
|
|
1365
1426
|
/** @deprecated 旧细粒度 scope, 保留向后兼容, 新代码请用分组 scope */
|
|
1366
1427
|
declare const ScopeModels = "models";
|
|
1367
1428
|
/** @deprecated */
|
|
@@ -1390,6 +1451,11 @@ declare function modelScopes(): string[];
|
|
|
1390
1451
|
declare function commerceScopes(): string[];
|
|
1391
1452
|
/** 技能/工具 scope */
|
|
1392
1453
|
declare function skillScopes(): string[];
|
|
1454
|
+
/**
|
|
1455
|
+
* 远程控制 scope (推荐). 仅返回分组 ScopeRemoteControl, 服务端 ScopeExpansion 会展开
|
|
1456
|
+
* 为 3 个子 scope. 调用方需显式申请, allScopes() 不包含本项 (避免桌面登录自动获权).
|
|
1457
|
+
*/
|
|
1458
|
+
declare function remoteControlScopes(): string[];
|
|
1393
1459
|
|
|
1394
1460
|
interface OpenAIChatResponse {
|
|
1395
1461
|
id: string;
|
|
@@ -1900,7 +1966,139 @@ declare module '@acosmi/sdk-ts' {
|
|
|
1900
1966
|
}
|
|
1901
1967
|
}
|
|
1902
1968
|
|
|
1969
|
+
type AdapterKind = 'remote_io' | 'app_server_tcp_ws' | 'bridge_ccr' | 'app_server_uds' | 'stdio_stream_json' | 'tauri_managed_app_server';
|
|
1970
|
+
type RunnerKind = 'cloud' | 'desktop' | 'local_embedded';
|
|
1971
|
+
interface WorkspacePolicy {
|
|
1972
|
+
readOnly?: boolean;
|
|
1973
|
+
allowedPaths?: string[];
|
|
1974
|
+
deniedPaths?: string[];
|
|
1975
|
+
maxBytes?: number;
|
|
1976
|
+
}
|
|
1977
|
+
interface PermissionPolicy {
|
|
1978
|
+
shellAllowed?: boolean;
|
|
1979
|
+
shellDenyList?: string[];
|
|
1980
|
+
networkAllowed?: boolean;
|
|
1981
|
+
writeAllowed?: boolean;
|
|
1982
|
+
approvalTimeoutMs?: number;
|
|
1983
|
+
requiredActors?: string[];
|
|
1984
|
+
}
|
|
1985
|
+
interface RemoteSessionPlacement {
|
|
1986
|
+
tenantId: string;
|
|
1987
|
+
userId: string;
|
|
1988
|
+
appId: string;
|
|
1989
|
+
runId: string;
|
|
1990
|
+
runner: RunnerKind;
|
|
1991
|
+
adapter: AdapterKind;
|
|
1992
|
+
ttlMs?: number;
|
|
1993
|
+
workspace?: WorkspacePolicy;
|
|
1994
|
+
permission?: PermissionPolicy;
|
|
1995
|
+
}
|
|
1996
|
+
interface RemoteSessionRef {
|
|
1997
|
+
sessionId: string;
|
|
1998
|
+
runId: string;
|
|
1999
|
+
tenantId: string;
|
|
2000
|
+
userId: string;
|
|
2001
|
+
adapter: AdapterKind;
|
|
2002
|
+
createdAt?: string;
|
|
2003
|
+
expiresAt?: string;
|
|
2004
|
+
}
|
|
2005
|
+
type RemoteControlEventType = 'text_delta' | 'reasoning_delta' | 'tool_call' | 'tool_result' | 'permission_request' | 'permission_result' | 'usage' | 'settle' | 'status' | 'error' | 'done';
|
|
2006
|
+
interface RemoteControlTextDelta {
|
|
2007
|
+
type: 'text_delta';
|
|
2008
|
+
index: number;
|
|
2009
|
+
text: string;
|
|
2010
|
+
}
|
|
2011
|
+
interface RemoteControlReasoningDelta {
|
|
2012
|
+
type: 'reasoning_delta';
|
|
2013
|
+
index: number;
|
|
2014
|
+
text: string;
|
|
2015
|
+
}
|
|
2016
|
+
interface RemoteControlToolCall {
|
|
2017
|
+
type: 'tool_call';
|
|
2018
|
+
toolCallId: string;
|
|
2019
|
+
name: string;
|
|
2020
|
+
input?: unknown;
|
|
2021
|
+
source?: string;
|
|
2022
|
+
}
|
|
2023
|
+
interface RemoteControlToolResult {
|
|
2024
|
+
type: 'tool_result';
|
|
2025
|
+
toolCallId: string;
|
|
2026
|
+
ok: boolean;
|
|
2027
|
+
output?: unknown;
|
|
2028
|
+
error?: string;
|
|
2029
|
+
}
|
|
2030
|
+
interface RemoteControlPermissionRequest {
|
|
2031
|
+
type: 'permission_request';
|
|
2032
|
+
requestId: string;
|
|
2033
|
+
kind: string;
|
|
2034
|
+
payload?: unknown;
|
|
2035
|
+
deadlineMs?: number;
|
|
2036
|
+
}
|
|
2037
|
+
interface RemoteControlPermissionResult {
|
|
2038
|
+
type: 'permission_result';
|
|
2039
|
+
requestId: string;
|
|
2040
|
+
decision: 'allow' | 'deny' | string;
|
|
2041
|
+
actor?: string;
|
|
2042
|
+
decidedAt?: string;
|
|
2043
|
+
}
|
|
2044
|
+
interface RemoteControlUsage {
|
|
2045
|
+
type: 'usage';
|
|
2046
|
+
inputTokens?: number;
|
|
2047
|
+
outputTokens?: number;
|
|
2048
|
+
cacheRead?: number;
|
|
2049
|
+
cacheCreate?: number;
|
|
2050
|
+
exact?: boolean;
|
|
2051
|
+
}
|
|
2052
|
+
interface RemoteControlSettle {
|
|
2053
|
+
type: 'settle';
|
|
2054
|
+
status: string;
|
|
2055
|
+
billed?: boolean;
|
|
2056
|
+
}
|
|
2057
|
+
interface RemoteControlStatus {
|
|
2058
|
+
type: 'status';
|
|
2059
|
+
phase: 'created' | 'connecting' | 'connected' | 'running' | 'cancelling' | 'terminating' | string;
|
|
2060
|
+
message?: string;
|
|
2061
|
+
}
|
|
2062
|
+
interface RemoteControlError {
|
|
2063
|
+
type: 'error';
|
|
2064
|
+
code: string;
|
|
2065
|
+
message: string;
|
|
2066
|
+
retryable?: boolean;
|
|
2067
|
+
kind?: string;
|
|
2068
|
+
}
|
|
2069
|
+
interface RemoteControlDone {
|
|
2070
|
+
type: 'done';
|
|
2071
|
+
reason: string;
|
|
2072
|
+
runId: string;
|
|
2073
|
+
finalStatus: string;
|
|
2074
|
+
}
|
|
2075
|
+
type RemoteControlEvent = RemoteControlTextDelta | RemoteControlReasoningDelta | RemoteControlToolCall | RemoteControlToolResult | RemoteControlPermissionRequest | RemoteControlPermissionResult | RemoteControlUsage | RemoteControlSettle | RemoteControlStatus | RemoteControlError | RemoteControlDone;
|
|
2076
|
+
/**
|
|
2077
|
+
* 把后端 SSE/JSON wire payload 翻译成强类型 RemoteControlEvent。
|
|
2078
|
+
*
|
|
2079
|
+
* - wire 字段 snake_case (text_delta / tool_call_id / permission_request ...);
|
|
2080
|
+
* - TS API 字段 camelCase (toolCallId / requestId ...);
|
|
2081
|
+
* - 未知 type / 缺失关键字段返回 null, 调用方应当忽略并打 warn;
|
|
2082
|
+
* - 不抛异常: 一律返回 null。
|
|
2083
|
+
*/
|
|
2084
|
+
declare function parseRemoteControlEvent(raw: unknown): RemoteControlEvent | null;
|
|
2085
|
+
/**
|
|
2086
|
+
* isTerminalRemoteEvent — 仅 `done` 与 `settle` 终结一个 stream。
|
|
2087
|
+
*
|
|
2088
|
+
* 注意契约 §4 关于 error:
|
|
2089
|
+
* - 终结性错误进入 `done`;
|
|
2090
|
+
* - 非终结 error 不结束 stream;
|
|
2091
|
+
* 因此 `error` 本身不算 terminal, `done` 才是。
|
|
2092
|
+
*/
|
|
2093
|
+
declare function isTerminalRemoteEvent(ev: RemoteControlEvent): boolean;
|
|
2094
|
+
|
|
1903
2095
|
type AgentRunStatus = 'queued' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
2096
|
+
/**
|
|
2097
|
+
* Remote-control runtime selector (Phase 3 / contract §3).
|
|
2098
|
+
* - 'standard' existing chat/workflow path (default; backward compatible)
|
|
2099
|
+
* - 'crabcode_remote' CrabCode remote-control session; requires runner + adapter
|
|
2100
|
+
*/
|
|
2101
|
+
type AgentRunRuntime = 'standard' | 'crabcode_remote';
|
|
1904
2102
|
interface AgentRunLocalContextPolicy {
|
|
1905
2103
|
enabled?: boolean;
|
|
1906
2104
|
readonly?: boolean;
|
|
@@ -1923,6 +2121,22 @@ interface AgentRunCreateRequest {
|
|
|
1923
2121
|
metadata?: Record<string, string>;
|
|
1924
2122
|
localContextPolicy?: AgentRunLocalContextPolicy;
|
|
1925
2123
|
artifactPolicy?: AgentRunArtifactPolicy;
|
|
2124
|
+
runtime?: AgentRunRuntime;
|
|
2125
|
+
runner?: RunnerKind;
|
|
2126
|
+
adapter?: AdapterKind;
|
|
2127
|
+
permissionPolicy?: PermissionPolicy;
|
|
2128
|
+
workspacePolicy?: WorkspacePolicy;
|
|
2129
|
+
}
|
|
2130
|
+
/**
|
|
2131
|
+
* Narrow type for `agentRuns.createRemoteRun(req)`:
|
|
2132
|
+
* - runtime is fixed to `'crabcode_remote'`;
|
|
2133
|
+
* - runner + adapter are required;
|
|
2134
|
+
* - inherits everything else from AgentRunCreateRequest.
|
|
2135
|
+
*/
|
|
2136
|
+
interface AgentRunRemoteCreateRequest extends AgentRunCreateRequest {
|
|
2137
|
+
runtime: 'crabcode_remote';
|
|
2138
|
+
runner: RunnerKind;
|
|
2139
|
+
adapter: AdapterKind;
|
|
1926
2140
|
}
|
|
1927
2141
|
interface AgentRun {
|
|
1928
2142
|
runId: string;
|
|
@@ -2090,6 +2304,34 @@ declare class AgentRunsClient {
|
|
|
2090
2304
|
get(runId: string, signal?: AbortSignal): Promise<AgentRun>;
|
|
2091
2305
|
stream(runId: string, opts?: AgentRunStreamOptions, signal?: AbortSignal): AsyncIterable<AgentRunStreamEvent>;
|
|
2092
2306
|
cancel(runId: string, signal?: AbortSignal): Promise<AgentRun>;
|
|
2307
|
+
/**
|
|
2308
|
+
* Create a CrabCode remote-control agent run (contract §3, ADR-2 + ADR-5).
|
|
2309
|
+
*
|
|
2310
|
+
* Equivalent to `create()` with `runtime: 'crabcode_remote'` and the required
|
|
2311
|
+
* `runner` + `adapter` fields set. Per-session policies (permission/workspace)
|
|
2312
|
+
* are forwarded to the gateway, which is the only side allowed to enforce
|
|
2313
|
+
* them (contract §6). The SDK never enforces remote permissions client-side.
|
|
2314
|
+
*
|
|
2315
|
+
* The corresponding stream uses `streamRemoteControl(runId)`, NOT `stream()`,
|
|
2316
|
+
* because the event union is different (contract §4).
|
|
2317
|
+
*/
|
|
2318
|
+
createRemoteRun(req: AgentRunRemoteCreateRequest, signal?: AbortSignal): Promise<AgentRunCreateResponse>;
|
|
2319
|
+
/**
|
|
2320
|
+
* Stream remote-control events for a CrabCode remote run (contract §4).
|
|
2321
|
+
*
|
|
2322
|
+
* Yields the canonical 11-event union: text_delta / reasoning_delta /
|
|
2323
|
+
* tool_call / tool_result / permission_request / permission_result /
|
|
2324
|
+
* usage / settle / status / error / done.
|
|
2325
|
+
*
|
|
2326
|
+
* Iteration ends naturally when a terminal event (`done` or `settle`) is
|
|
2327
|
+
* observed. Per contract §4, `error` alone is non-terminal — terminal errors
|
|
2328
|
+
* are carried by `done.reason` / `done.final_status`.
|
|
2329
|
+
*
|
|
2330
|
+
* Unknown event types and malformed frames are silently skipped (warn-only),
|
|
2331
|
+
* matching `parseRemoteControlEvent`'s null-return contract.
|
|
2332
|
+
*/
|
|
2333
|
+
streamRemoteControl(runId: string, signal?: AbortSignal): AsyncIterable<RemoteControlEvent>;
|
|
2334
|
+
private streamRemoteControlGen;
|
|
2093
2335
|
listArtifacts(runId: string, signal?: AbortSignal): Promise<AgentRunArtifact[]>;
|
|
2094
2336
|
downloadArtifact(runId: string, artifactId: string, signal?: AbortSignal): Promise<AgentRunDownload>;
|
|
2095
2337
|
submitLocalToolResult(runId: string, result: AgentRunLocalToolResult, signal?: AbortSignal): Promise<AgentRun>;
|
|
@@ -3456,6 +3698,11 @@ declare module '@acosmi/sdk-ts' {
|
|
|
3456
3698
|
listPlans(audience?: SubscriptionAudience, signal?: AbortSignal): Promise<SubscriptionPlan[]>;
|
|
3457
3699
|
/** 列出当前用户已激活订阅 (跨档位; 通常 1 条 active) */
|
|
3458
3700
|
listUserSubscriptions(signal?: AbortSignal): Promise<UserSubscription[]>;
|
|
3701
|
+
/**
|
|
3702
|
+
* 按 planCode 精确取单个可售订阅计划 (V41 起 planCode 在 active 内唯一)。
|
|
3703
|
+
* 复用 listPlans 客户端过滤, 未命中返回 null。减少 C 端按字段手筛 (deep-review §12.3)。
|
|
3704
|
+
*/
|
|
3705
|
+
getPlanByCode(planCode: string, signal?: AbortSignal): Promise<SubscriptionPlan | null>;
|
|
3459
3706
|
}
|
|
3460
3707
|
}
|
|
3461
3708
|
|
|
@@ -4135,4 +4382,201 @@ declare module '@acosmi/sdk-ts' {
|
|
|
4135
4382
|
}
|
|
4136
4383
|
}
|
|
4137
4384
|
|
|
4138
|
-
|
|
4385
|
+
type Platform = 'feishu' | 'wecom' | 'dingtalk' | 'slack' | 'teams' | 'telegram' | 'whatsapp';
|
|
4386
|
+
type Region = 'cn' | 'intl';
|
|
4387
|
+
type IntegrationStatus = 'pending' | 'active' | 'suspended' | 'revoked';
|
|
4388
|
+
/**
|
|
4389
|
+
* CredentialRef — chat-bridge 凭证公开引用 (`cred_<22 char base32>`).
|
|
4390
|
+
*
|
|
4391
|
+
* branded type 防止 plaintext secret 字符串被误传到需要 CredentialRef 的位置。
|
|
4392
|
+
* SDK 调用方应仅持有 CredentialRef, 永不持 plaintext。
|
|
4393
|
+
*/
|
|
4394
|
+
type CredentialRef = string & {
|
|
4395
|
+
readonly __brand: 'CredentialRef';
|
|
4396
|
+
};
|
|
4397
|
+
/**
|
|
4398
|
+
* ChannelAttachment — 入站附件 / 出站文件附件.
|
|
4399
|
+
*
|
|
4400
|
+
* 安全约束 (ADR-8):
|
|
4401
|
+
* - `url` 必须由 bridge runtime 解析过 (Acosmi 内部存储 URL); 严禁是平台原始签名 URL。
|
|
4402
|
+
* - `contentType` 是标准 MIME; `kind` 是 bridge 内部分类 (image/file/audio/video/link/...)。
|
|
4403
|
+
*/
|
|
4404
|
+
interface ChannelAttachment {
|
|
4405
|
+
kind: string;
|
|
4406
|
+
url: string;
|
|
4407
|
+
size?: number;
|
|
4408
|
+
contentType?: string;
|
|
4409
|
+
}
|
|
4410
|
+
/**
|
|
4411
|
+
* ChannelCardAction — 出站交互卡片按钮 / 自由输入.
|
|
4412
|
+
*
|
|
4413
|
+
* `kind`: 'approve' | 'reject' | 'cancel' | 'free_text' | 其他 bridge 自定义。
|
|
4414
|
+
* `id` 是 bridge 侧稳定 action id, 用于把用户点击映射回原 requestId 幂等键。
|
|
4415
|
+
*/
|
|
4416
|
+
interface ChannelCardAction {
|
|
4417
|
+
kind: string;
|
|
4418
|
+
id: string;
|
|
4419
|
+
label: string;
|
|
4420
|
+
}
|
|
4421
|
+
/**
|
|
4422
|
+
* ChannelCard — 出站交互卡片 (permission / tool_status / done / error).
|
|
4423
|
+
*/
|
|
4424
|
+
interface ChannelCard {
|
|
4425
|
+
kind: string;
|
|
4426
|
+
title: string;
|
|
4427
|
+
body: string;
|
|
4428
|
+
actions?: ChannelCardAction[];
|
|
4429
|
+
}
|
|
4430
|
+
/**
|
|
4431
|
+
* ChannelInboundEvent — bridge runtime 视角的入站平台消息.
|
|
4432
|
+
*
|
|
4433
|
+
* 安全约束:
|
|
4434
|
+
* - `threadHash` / `senderHash` 是 SHA256(平台原始 ID), 不允许直接是平台 ID;
|
|
4435
|
+
* - `metadata` 仅含非敏感字段 (例: locale, message_kind), 严禁含 plaintext secret;
|
|
4436
|
+
* - `messageId` 是平台原生 message id, 仅用于平台侧 ack / dedup, 不进 AgentRun transcript。
|
|
4437
|
+
*/
|
|
4438
|
+
interface ChannelInboundEvent {
|
|
4439
|
+
platform: Platform;
|
|
4440
|
+
threadHash: string;
|
|
4441
|
+
senderHash?: string;
|
|
4442
|
+
content: string;
|
|
4443
|
+
attachments?: ChannelAttachment[];
|
|
4444
|
+
messageId?: string;
|
|
4445
|
+
receivedAt?: string;
|
|
4446
|
+
metadata?: Record<string, string>;
|
|
4447
|
+
}
|
|
4448
|
+
/**
|
|
4449
|
+
* ChannelOutboundEvent — bridge runtime 出站平台消息 / 卡片.
|
|
4450
|
+
*
|
|
4451
|
+
* Metadata 仅含非敏感投递参数 (例: card_locale), 严禁含 plaintext secret。
|
|
4452
|
+
*/
|
|
4453
|
+
interface ChannelOutboundEvent {
|
|
4454
|
+
threadHash: string;
|
|
4455
|
+
content?: string;
|
|
4456
|
+
cards?: ChannelCard[];
|
|
4457
|
+
metadata?: Record<string, string>;
|
|
4458
|
+
}
|
|
4459
|
+
/**
|
|
4460
|
+
* BridgeThreadRef — bridge runtime 内部 thread 引用 (Acosmi 三元组).
|
|
4461
|
+
*
|
|
4462
|
+
* 永不携带 platform secret / 原始平台 ID。
|
|
4463
|
+
*/
|
|
4464
|
+
interface BridgeThreadRef {
|
|
4465
|
+
threadId: string;
|
|
4466
|
+
runId?: string;
|
|
4467
|
+
remoteSessionId?: string;
|
|
4468
|
+
tenantId: string;
|
|
4469
|
+
userId: string;
|
|
4470
|
+
appId: string;
|
|
4471
|
+
}
|
|
4472
|
+
/**
|
|
4473
|
+
* ChatIntegration — 平台安装记录的 SDK 只读视图.
|
|
4474
|
+
*
|
|
4475
|
+
* 注意: `configJson` 仅含非敏感配置 (rate limit / feature toggles); 严禁含 secret。
|
|
4476
|
+
* Phase 7B handler 落地后, SDK admin 子客户端会按此型号 GET。
|
|
4477
|
+
*/
|
|
4478
|
+
interface ChatIntegration {
|
|
4479
|
+
id: string;
|
|
4480
|
+
tenantId: string;
|
|
4481
|
+
appId: string;
|
|
4482
|
+
platform: Platform;
|
|
4483
|
+
region: Region;
|
|
4484
|
+
workspaceIdHash?: string;
|
|
4485
|
+
botIdHash?: string;
|
|
4486
|
+
status: IntegrationStatus;
|
|
4487
|
+
configJson?: string;
|
|
4488
|
+
installedByUserId?: string;
|
|
4489
|
+
lastUsedAt?: string;
|
|
4490
|
+
createdAt?: string;
|
|
4491
|
+
updatedAt?: string;
|
|
4492
|
+
}
|
|
4493
|
+
/**
|
|
4494
|
+
* ChatCredentialPublic — 凭证的 SDK 只读视图 (绝不含 ciphertext / plaintext).
|
|
4495
|
+
*
|
|
4496
|
+
* 仅暴露公开字段: `credentialRef` / `fingerprint` / `keyId` / `version` / `status`。
|
|
4497
|
+
*/
|
|
4498
|
+
interface ChatCredentialPublic {
|
|
4499
|
+
credentialRef: CredentialRef;
|
|
4500
|
+
integrationId: string;
|
|
4501
|
+
platform: Platform;
|
|
4502
|
+
region: Region;
|
|
4503
|
+
secretKind: string;
|
|
4504
|
+
fingerprint: string;
|
|
4505
|
+
keyId: string;
|
|
4506
|
+
version: number;
|
|
4507
|
+
status: 'active' | 'rotating' | 'revoked' | string;
|
|
4508
|
+
lastUsedAt?: string;
|
|
4509
|
+
rotatedAt?: string;
|
|
4510
|
+
createdAt?: string;
|
|
4511
|
+
updatedAt?: string;
|
|
4512
|
+
}
|
|
4513
|
+
/**
|
|
4514
|
+
* ChatThread — 平台 thread 到 Acosmi session 的映射 (SDK 只读视图).
|
|
4515
|
+
*
|
|
4516
|
+
* 永不携带原始 platform thread / sender ID; 仅含 SHA256 hash。
|
|
4517
|
+
*/
|
|
4518
|
+
interface ChatThread {
|
|
4519
|
+
id: string;
|
|
4520
|
+
tenantId: string;
|
|
4521
|
+
integrationId: string;
|
|
4522
|
+
platformThreadHash: string;
|
|
4523
|
+
platform: Platform;
|
|
4524
|
+
userId: string;
|
|
4525
|
+
appId: string;
|
|
4526
|
+
sessionId?: string;
|
|
4527
|
+
lastRunId?: string;
|
|
4528
|
+
senderHash?: string;
|
|
4529
|
+
lastInboundAt?: string;
|
|
4530
|
+
lastOutboundAt?: string;
|
|
4531
|
+
}
|
|
4532
|
+
/**
|
|
4533
|
+
* ChatBridgeSession — 一次 bridge runtime 会话 (SDK 只读视图).
|
|
4534
|
+
*/
|
|
4535
|
+
interface ChatBridgeSession {
|
|
4536
|
+
id: string;
|
|
4537
|
+
tenantId: string;
|
|
4538
|
+
threadId: string;
|
|
4539
|
+
integrationId: string;
|
|
4540
|
+
runId?: string;
|
|
4541
|
+
remoteSessionId?: string;
|
|
4542
|
+
status: 'created' | 'routing' | 'active' | 'paused' | 'closed' | 'errored' | string;
|
|
4543
|
+
adapter?: string;
|
|
4544
|
+
lastFrameAt?: string;
|
|
4545
|
+
closedAt?: string;
|
|
4546
|
+
disconnectReason?: string;
|
|
4547
|
+
createdAt?: string;
|
|
4548
|
+
updatedAt?: string;
|
|
4549
|
+
}
|
|
4550
|
+
declare const ALL_PLATFORMS: readonly Platform[];
|
|
4551
|
+
declare const ALL_REGIONS: readonly Region[];
|
|
4552
|
+
declare const ALL_INTEGRATION_STATUS: readonly IntegrationStatus[];
|
|
4553
|
+
/**
|
|
4554
|
+
* isPlatform — runtime type guard for {@link Platform}.
|
|
4555
|
+
*
|
|
4556
|
+
* 用途: SDK 解析 wire payload 时校验未知字段; 不直接抛异常, 调用方决策。
|
|
4557
|
+
*/
|
|
4558
|
+
declare function isPlatform(v: unknown): v is Platform;
|
|
4559
|
+
/**
|
|
4560
|
+
* isRegion — runtime type guard for {@link Region}.
|
|
4561
|
+
*/
|
|
4562
|
+
declare function isRegion(v: unknown): v is Region;
|
|
4563
|
+
/**
|
|
4564
|
+
* isIntegrationStatus — runtime type guard for {@link IntegrationStatus}.
|
|
4565
|
+
*/
|
|
4566
|
+
declare function isIntegrationStatus(v: unknown): v is IntegrationStatus;
|
|
4567
|
+
/**
|
|
4568
|
+
* isChannelInboundEvent — 极简 type guard, 用于 wire payload 入口校验.
|
|
4569
|
+
*
|
|
4570
|
+
* 仅校验必填字段 (platform/threadHash/content); 其他字段交给调用方按需校验。
|
|
4571
|
+
* 不抛异常: 失败返回 false。
|
|
4572
|
+
*/
|
|
4573
|
+
declare function isChannelInboundEvent(v: unknown): v is ChannelInboundEvent;
|
|
4574
|
+
/**
|
|
4575
|
+
* 把任意字符串安全 brand 成 {@link CredentialRef}; 不做合法性校验.
|
|
4576
|
+
*
|
|
4577
|
+
* Phase 7B SDK 客户端 wire 解析时使用 — 服务端返回的 `credential_ref` 字段一律走它。
|
|
4578
|
+
* 调用方自行判断格式 (例: 是否 `cred_` 前缀)。
|
|
4579
|
+
*/
|
|
4580
|
+
declare function asCredentialRef(s: string): CredentialRef;
|
|
4581
|
+
|
|
4582
|
+
export { ALL_INTEGRATION_STATUS, ALL_PLATFORMS, ALL_REGIONS, type APIResponse, type AdapterKind, 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 AgentRunRemoteCreateRequest, type AgentRunRunOptions, type AgentRunRuntime, type AgentRunSettlement, type AgentRunStatus, AgentRunStreamError, type AgentRunStreamEvent, type AgentRunStreamOptions, type AgentRunUsage, type AgentRunWithLocalToolsOptions, AgentRunsClient, AnthropicResponse, type ApiClientRef, type ApproveSealApprovalQuery, type AssignSeatRequest, type Audience, AudienceEnum, type AuthorizeResult, type BalanceDetail, type BillingMode, BillingModeEnum, type BillingPreflightResult, type BlockMeta, type BookConsultationRequest, type BridgeThreadRef, type BrowserRefreshMode, type BugReportResult, type BugView, BusinessError, type CancelSealApprovalQuery, type CaseLead, type CaseMatter, type CertificationStatus, type ChannelAttachment, type ChannelCard, type ChannelCardAction, type ChannelInboundEvent, type ChannelOutboundEvent, type ChatBridgeSession, type ChatCredentialPublic, type ChatIntegration, ChatRequest, ChatResponse, type ChatThread, Client, type ClientRegistration, type ComplianceAssetType, type ComplianceBenefitType, type ComplianceBillingDisplayStatus, type ComplianceCapability, ComplianceClient, type ComplianceClientErrorCode, type ComplianceDigestSource, type ComplianceEnvelopeStatus, type ComplianceErrorInfo, type ComplianceErrorKey, type ComplianceHashAlgorithm, CompliancePollError, type CompliancePollOptions, type CompliancePrivacyLevel, type ComplianceProviderRequestStatus, type ComplianceProviderStatus, type ComplianceQuoteResponse, type ComplianceReport, type ComplianceScope, type ComplianceSealApprovalStatus, type ComplianceSku, type ComplianceTimestampVerificationStatus, type ComplianceWriteOptions, type Config, type ConsumeRecord, type ConsumeRecordPage, type ContractTemplateField, type ContractTemplateFieldType, type ContractTemplatePageItem, type ContractTemplateResp, type ContractTemplateStatus, type ContractTemplateVersion, type CorporateTransfer, type CreateContractTemplateRequest, type CreateEvidenceAssetRequest, type CreateH5SigningUrlRequest, type CreateReportRequest, type CreateSigningEnvelopeRequest, type CreateWebAuthorizationRequestOptions, type CredentialRef, DEFAULT_GATEWAY_BASE_URL, DefaultRetryPolicy, type DeviceRegistration, type EnterpriseKycMyStatusView, type EnterpriseMember, type EnterpriseSummary, type EntitlementBalance, type EntitlementItem, type EnvelopeContractItem, 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 EvidenceAssetPageItem, type EvidencePackage, type EvidencePackagePageItem, type FeatureGateState, type FeatureGateStatus, FileTokenStore, type FilterStatus, FilterStatusAdminBypass, FilterStatusDisabledByFlag, FilterStatusFallbackMissingUser, FilterStatusFallbackNoBuckets, FilterStatusFallbackTkdistError, FilterStatusFallbackTkdistSkew, FilterStatusInternalBypass, FilterStatusOK, FilterStatusUnknown, type GateQuota, type GenerateSkillRequest, type GenerateSkillResult, HTTPError, type IdempotencyKey, IdempotencyKeyHeader, InMemoryTokenStore, type InitiateCorporateTransferInput, type InitiateCorporateTransferResult, InputModality, type IntegrationStatus, type InviteMemberRequest, type Invoice, type IssueTimestampRequest, type LawyerCredentialMyView, type LawyerSummary, type LegalConsultation, type LegalServiceOrder, type LegalServiceSku, type LegalSkuCode, type ListContractTemplatesRequest, type ListEvidenceAssetsRequest, type ListEvidencePackagesRequest, type ListOperationsRequest, type ListReportsRequest, type ListSealApprovalsRequest, type ListSealUsesRequest, type ListSigningEnvelopesRequest, type ListTimestampsRequest, 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, OAuthTokenEndpointError, type OpenAIChatChoice, type OpenAIChatMessage, type OpenAIChatResponse, type OpenAIFunctionCall, type OpenAIStreamChoice, type OpenAIStreamChunk, type OpenAIStreamDelta, type OpenAIStreamToolCall, type OpenAIToolCall, type OpenAIUsage, type OperationDetail, type OperationId, type OperationPageItem, type OperationSource, type OperationStatus, type OptimizeSkillRequest, type OptimizeSkillResult, type Order, type OrderStatus, OrderTerminalError, type OrgConsumeReport, type OrgSeat, type OrgSubscription, type PageRequest, type PageResult, type PayPayload, type PermissionPolicy, type Platform, type PricingConfig, type PrincipalRef, type Product, type ProductFamily, ProductFamilyEnum, ProviderAdapter, type ProviderRequestStatus, type ProviderRequestStatusView, type PublicEvidenceVerifyResult, type PublicModelSummary, QuotaSummary, RETRY_ADVICE_REASONS, RateLimitError, type RefundPolicy, type RefundRecord, type Region, type RegionScope, RegionScopeEnum, type RegisterWebOAuthClientOptions, type RejectSealApprovalQuery, type RemoteControlDone, type RemoteControlError, type RemoteControlEvent, type RemoteControlEventType, type RemoteControlPermissionRequest, type RemoteControlPermissionResult, type RemoteControlReasoningDelta, type RemoteControlSettle, type RemoteControlStatus, type RemoteControlTextDelta, type RemoteControlToolCall, type RemoteControlToolResult, type RemoteControlUsage, type RemoteSessionPlacement, type RemoteSessionRef, type ReportDownload, type ReportPageItem, type RequestInvoiceInput, type RequestRefundInput, type RetryAdvice, type RetryAdviceReason, type RetryPolicy, type RetryRequestInfo, type RolloverPolicy, type RunnerKind, ScopeAI, ScopeAccount, ScopeComplianceContractSigningRead, ScopeComplianceContractSigningWrite, ScopeComplianceContractTemplateRead, ScopeComplianceContractTemplateWrite, ScopeComplianceEvidenceRead, ScopeComplianceEvidenceWrite, ScopeComplianceReportsPublish, ScopeComplianceReportsRead, ScopeComplianceReportsWrite, ScopeComplianceSealApprovalApprove, ScopeComplianceSealApprovalRequest, ScopeComplianceSealManage, ScopeComplianceSealUseExecute, ScopeComplianceTimestampIssue, ScopeComplianceTimestampVerify, ScopeEntitlements, ScopeModels, ScopeModelsChat, ScopeProfile, ScopeRemoteControl, ScopeRemoteControlAgentRun, ScopeRemoteControlPermissionResponse, ScopeRemoteControlSessionControl, ScopeSkillStore, ScopeSkills, ScopeTokenPackages, ScopeTools, ScopeToolsExecute, ScopeWallet, ScopeWalletReadonly, type SealApproval, type SealApprovalPageItem, type SealUsePageItem, type ServerMetadata, type SignEnvelopeRequest, type SigningEnvelope, type SigningEnvelopePageItem, type SkillBrowseListResponse, type SkillBrowseResponse, type SkillStoreItem, type SkillStoreListItem, type SkillStoreQuery, type SkillSummary, type SortDirection, SourcesEvent, type StepUpStatus, StreamError, StreamEvent, StreamSettlement, type SubmitCaseLeadRequest, type SubmitSealApprovalRequest, type SubscriptionAudience, type SubscriptionPlan, type TenantRef, type TimestampPageItem, type TimestampToken, type TimestampVerifyResult, type TokenPackage, type TokenResponse, type TokenSet, type TokenStore, type ToolListResponse, type ToolProvider, type ToolView, type Transaction, type TsaProvider, type TsaStats, type UpdateContractTemplateRequest, type UploadContractTemplatePdfRequest, type UserSubscription, type VerifyStatus, type VerifyTimestampRequest, type VoidEnvelopeRequest, type WSConfig, type WSEvent, type WalletStats, type WebAuthorizationCallbackParams, type WebAuthorizationPending, type WebAuthorizationRequest, type WorkspacePolicy, type YudaoPageResult, allScopes, apiResponseBusinessError, apiResponseGetMessage, asCredentialRef, authorize, buildBetas, classifyComplianceError, commerceScopes, completeWebAuthorizationRequest, complianceErrorToRetryAdvice, complianceScopes, computeBackoff, createWebAuthorizationRequest, defaultRetryable, defaultSafeToRetry, discover, discoverWebOAuthMetadata, discoverWithProfile, effectivePolicy, exchangeCode, extractAnthropicBlockMeta, fileLockDefaults, findDesktopVisualUnderstandingModel, findFirstModelByInputModality, generateState, isBillingConfirmable, isChannelInboundEvent, isComplianceBusinessError, isComplianceTerminalError, isIntegrationStatus, isInvalidGrantError, isPlatform, isRegion, isSSECommentLine, isSSLError, isTerminalRemoteEvent, maxEndUserIdLength, modelScopes, modelSupportsImageInput, modelSupportsInputModality, newFileTokenStore, newTokenSet, normalizeGatewayBaseURL, parseNotificationEvent, parseRemoteControlEvent, refreshToken, register, registerWebOAuthClient, remoteControlScopes, retryReasonForComplianceKey, retryReasonForOAuthError, revokeToken, skillScopes, tokenSetIsExpired, uniqueMerge, validateEndUserId };
|