@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/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,23 @@ All notable changes to `@acosmi/sdk-ts` will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.1.0] - 2026-05-28 — 远程控制 CrabCode 多接入面
|
|
9
|
+
|
|
10
|
+
Additive minor。公开类型 / 方法签名零移除、零改名。契约见 `docs/audit/sdk-remote-control-contract-2026-05-27.md`。
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **Acosmi Gateway URL 公共契约**:`serverURL` / `baseURL` / `baseUrl` 三别名 + `normalizeGatewayBaseURL()`(仅接受 `http`/`https`,拒绝 `ws`/`wss` 及空 host,规整尾斜杠)。详见 README §"Acosmi Gateway URL 公共契约"。
|
|
15
|
+
- **远程控制(CrabCode remote-control)**,`agentRuns` 命名空间下、事件协议独立于旧 `stream`:
|
|
16
|
+
- `agentRuns.createRemoteRun(req, signal?)` — `req.runtime` 固定 `'crabcode_remote'`,`runner` + `adapter` 必填。
|
|
17
|
+
- `agentRuns.streamRemoteControl(runId, signal?)` — 无 options 参数;`error` 恒非终结、`done`/`settle` 终结、从不抛异常。
|
|
18
|
+
- 11 事件 `RemoteControlEvent` union + helper `parseRemoteControlEvent(raw)`(wire→强类型,未知 type 返回 `null`)/ `isTerminalRemoteEvent(ev)`。
|
|
19
|
+
- 枚举:`AdapterKind`(6)/ `RunnerKind`(3)/ `PermissionPolicy` / `WorkspacePolicy`。
|
|
20
|
+
- 专用 scope `remote_control`(+ 3 子 scope):`remoteControlScopes()` / `ScopeRemoteControl`,**不进 `allScopes()`**,绝不复用 `models:chat` / `ai`。
|
|
21
|
+
- wire 约定按平面分(契约 §12):远控平面 = snake_case + 时长整数毫秒(`approval_timeout_ms`);唯一序列化出口 `RemoteSessionEvent.ToWire()`,跨语言金标 fixtures 护栏(`test/remote-control-wire-golden.test.ts` ⇄ 后端 `wire_golden.json`)。
|
|
22
|
+
- **`chatbridge` 第三方聊天平台桥接类型骨架**(types-only,无 `client.chatBridge.*` 方法,Phase 7B 后端落地):导出类型 + 守卫 `isPlatform` / `isRegion` / `isIntegrationStatus` / `isChannelInboundEvent` / `asCredentialRef`。资源视图平面 = camelCase;secret 只入上游 vault,公共面仅见 `CredentialRef` + fingerprint + 脱敏 metadata(契约 §16)。
|
|
23
|
+
- `subscription.getPlanByCode(planCode, signal?)` — 按 `planCode` 精确取单个可售订阅计划(复用 `listPlans` 客户端过滤,未命中返回 `null`;deep-review §12.3)。
|
|
24
|
+
|
|
8
25
|
## [2.0.1] - 2026-05-25 — Packaging fix
|
|
9
26
|
|
|
10
27
|
### Fixed
|
package/README.md
CHANGED
|
@@ -6,11 +6,34 @@
|
|
|
6
6
|
|
|
7
7
|
## 状态
|
|
8
8
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
9
|
+
- **主实现 / 事实标准**:本 TS SDK 现为 Acosmi SDK 的主力实现。Go SDK [acosmi-sdk-go](https://github.com/acosmi/acosmi-sdk-go) 已暂停维护,待 TS 稳定后再从 TS 反向翻译补齐。
|
|
10
|
+
- **当前 npm 版本:`2.1.0`**(远程控制 CrabCode 多接入面,2026-05-28)。
|
|
11
|
+
- **`v2.1.0`(已发布)**:远程控制 CrabCode 多接入面 —— `serverURL`/`baseURL` Gateway URL 公共契约(见下方小节)、`agentRuns.createRemoteRun` / `agentRuns.streamRemoteControl` + 11 事件 union(见 §Agent Runs → 远程控制)、`chatbridge` 第三方聊天平台桥接类型(types-only 骨架,见 §Chat Bridge)、专用 `remote_control` scope(不进 `allScopes()`)。契约见 `docs/audit/sdk-remote-control-contract-2026-05-27.md`。
|
|
12
|
+
- **v2.0.0 BREAKING(Phase 3 复核 + 全量根治,2026-05-25)摘要**:
|
|
13
|
+
- SDK 同步主仓 9 commit 闭环 20 P0(RBAC 表达式统一 / PII 真落盘加密链 / K7 视频 webhook 幂等 / K8 OCR SSRF / K9 KYC main flow / admin 写端点错误码契约)。
|
|
14
|
+
- 新增 `casehall.getMyLawyerCredentialStatus()` + `enterprise.getMyEnterpriseKycStatus()` 律师 / 企业 OWNER 自查端点(纯增量)。
|
|
15
|
+
- `finance/types.ts` P2-016 PII Javadoc 升级(含 `keyVersion` v1/v2 payload 协议 + 4 角色 × 3 PII 级矩阵)。
|
|
16
|
+
- 新建 `docs/pii-role-matrix.md`(4 角色:`platform_admin` / `s2s` / `lawyer` / `consumer`)。
|
|
17
|
+
- admin 写端点错误码改 HTTP 状态码语义(`200+{ok:false}` → `403/404/501`),上游契约整流。
|
|
18
|
+
- **升级路径详见下方 "v2.0.0 升级指引"**。
|
|
19
|
+
- **v1.x 历史链**:1.9.0 finance / 1.8.1 enterprise / 1.8.0 casehall / 1.7.0 csign+pricing+products+subscription / 1.6.0 endUserId+11min 保活 / 1.5.x 跨域共享 DTO + Compliance S1-S6 rollup / 1.4.x 浏览器 Web OAuth / 1.3.x compliance SDK / 1.2.x InputModality / 1.1.x agentRuns / 1.0.x 包发布修复。详见 [CHANGELOG](./CHANGELOG.md)。
|
|
20
|
+
- **测试**:发布前需通过 `typecheck` / `lint` / `vitest` / `build` / `test:pack`(packed-tarball consumer smoke)。
|
|
21
|
+
- **API 参考文档**:`npm run docs`(TypeDoc)生成到 `docs/api/`。
|
|
22
|
+
- **包链接**:[npm](https://www.npmjs.com/package/@acosmi/sdk-ts) · [GitHub Releases](https://github.com/acosmi/sdk-ts/releases)。
|
|
23
|
+
|
|
24
|
+
### v2.0.0 升级指引
|
|
25
|
+
|
|
26
|
+
v2.0.0 标 BREAKING,但 **TS SDK 公开类型与方法签名零移除、零改名**;BREAKING 范围在网关后端,集成方按以下清单核对:
|
|
27
|
+
|
|
28
|
+
| 受影响场景 | 集成方动作 | 关联 |
|
|
29
|
+
|------------|----------|------|
|
|
30
|
+
| 持有 `ROLE_ADMIN` 角色(不是 `platform_admin`)想读 PII L3 字段(如发票税号、律师执照号) | **必须 review** — 网关 `SensitiveSerializer` 不再把 `ROLE_ADMIN` 当 `platform_admin` 别名 fail-OPEN,统一收敛为 4 角色严格白名单。仍需 PII L3 read 的角色须重新申请 `platform_admin` | `docs/pii-role-matrix.md` |
|
|
31
|
+
| 持有 admin 写端点 (`/admin/**/...`) 旧契约 — 期望 `200+{ok:false,code:xxx}` 业务错误码 | **必须改** — 改读 HTTP 状态码:`403` 鉴权不足 / `404` 资源不存在 / `501` `NOT_CONFIGURED_CODE` 网关未配置 provider;body 不再保证带业务码 | 主仓 `K10AdminController` |
|
|
32
|
+
| 用 `client.casehall.*` / `client.enterprise.*` 调律师 / 企业 OWNER 资质相关接口 | **零改动** — 新增 `getMyLawyerCredentialStatus()` / `getMyEnterpriseKycStatus()` 是纯增量,不影响既有方法 | `src/casehall/client.ts`、`src/enterprise/client.ts` |
|
|
33
|
+
| 读 `Invoice.taxNumber` / `Invoice.bankAccount` 等 PII 字段 | **零代码改动** — 字段名 / wire-format 不变,仅 Javadoc 标注从"脱敏"升级为"keyVersion v1/v2 真加密 + AAD field binding",运行时 transparent | `src/finance/types.ts` |
|
|
34
|
+
| 集成 v1.x 时按"`ROLE_ADMIN` 自动当 `platform_admin`"测试用例 | **必须改** — 删掉别名假设;测试角色显式写 `platform_admin` / `s2s` / `lawyer` / `consumer` 之一 | `docs/pii-role-matrix.md` §角色映射表 |
|
|
35
|
+
|
|
36
|
+
> v2.0.0 → v2.0.1 是纯 packaging fix(`package.json.files` 数组补 2 个 docs),无源码改动;从 v2.0.0 升 v2.0.1 不需要任何 review。
|
|
14
37
|
|
|
15
38
|
## 安装
|
|
16
39
|
|
|
@@ -23,7 +46,7 @@ npm install @acosmi/sdk-ts
|
|
|
23
46
|
```ts
|
|
24
47
|
import { Client, allScopes } from '@acosmi/sdk-ts';
|
|
25
48
|
|
|
26
|
-
const client = new Client({
|
|
49
|
+
const client = new Client({ baseURL: process.env.ACOSMI_BASE_URL! });
|
|
27
50
|
await client.login('My App', allScopes());
|
|
28
51
|
|
|
29
52
|
const resp = await client.chat('claude-opus-4-7', {
|
|
@@ -34,6 +57,45 @@ const resp = await client.chat('claude-opus-4-7', {
|
|
|
34
57
|
console.log(resp.content);
|
|
35
58
|
```
|
|
36
59
|
|
|
60
|
+
### Acosmi Gateway URL — `serverURL` / `baseURL` 公共契约 (v2.1+)
|
|
61
|
+
|
|
62
|
+
`Client` 配置中 `serverURL` / `baseURL` / `baseUrl` 三字段同语义、互为 alias,归一化后必须相等;任传其一即可,多写时 normalize 后冲突会立刻抛错。
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
// 推荐拼写
|
|
66
|
+
const client = new Client({ baseURL: 'https://acosmi.com' });
|
|
67
|
+
|
|
68
|
+
// 与历史 serverURL 完全等价
|
|
69
|
+
const same = new Client({ serverURL: 'https://acosmi.com' });
|
|
70
|
+
|
|
71
|
+
// 多写一致 OK; 不一致抛错
|
|
72
|
+
new Client({ serverURL: 'https://a.example', baseURL: 'https://b.example' });
|
|
73
|
+
// → Error: Acosmi Gateway URL conflict: …
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**红线 (Phase 0 契约 §1-§2)** — Acosmi Gateway URL 是 `@acosmi/sdk-ts` 调 Acosmi nexus-v4 API 的根:
|
|
77
|
+
|
|
78
|
+
- 只接受 `http:` / `https:`;`ws:` / `wss:` 是 CrabCode `--sdk-url` RemoteIO 会话通道,**不是** SDK gateway URL,传入立刻抛错。
|
|
79
|
+
- agent-runs / managed-models / notifications WS / compliance 都从同一个 normalized base 派生;SDK 内部 `apiURL()` 自动追加 `/api/v4`,不会重复拼。
|
|
80
|
+
- 不推荐 runtime mutate `client.serverURL`;多 base 用 per-instance Client cache(例如 `Map<normalizedGatewayURL, Promise<Client>>`)。
|
|
81
|
+
- `complianceBaseURL` 是独立第二根地址,不被 `baseURL` alias 覆盖。
|
|
82
|
+
|
|
83
|
+
公共 helper:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { Client, normalizeGatewayBaseURL, DEFAULT_GATEWAY_BASE_URL } from '@acosmi/sdk-ts';
|
|
87
|
+
|
|
88
|
+
normalizeGatewayBaseURL('https://gw.example/api/v4/'); // → 'https://gw.example/api/v4'
|
|
89
|
+
normalizeGatewayBaseURL('wss://session.example'); // → throw: only allows http/https
|
|
90
|
+
DEFAULT_GATEWAY_BASE_URL; // → 'https://acosmi.com'
|
|
91
|
+
|
|
92
|
+
const c = new Client({ baseURL: 'https://gw.example' });
|
|
93
|
+
c.getBaseURL(); // → 'https://gw.example' (= c.getServerURL())
|
|
94
|
+
c.apiURL('/agent-runs'); // → 'https://gw.example/api/v4/agent-runs'
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
详见 `docs/audit/sdk-remote-control-contract-2026-05-27.md`。
|
|
98
|
+
|
|
37
99
|
### 用户隔离 (v1.6.0+)
|
|
38
100
|
|
|
39
101
|
`ChatRequest.endUserId` — 业务侧终端用户的稳定标识, **跨 provider 通用语义**, 不绑死 DeepSeek。SDK 自动按 wire-format 注入: OpenAI 顶层 `user_id` / Anthropic `metadata.user_id`; 网关侧校验并派生后送达上游, 命中三项隔离能力 (内容安全 / KV-cache / 调度)。
|
|
@@ -179,6 +241,75 @@ await client.agentRuns.cancel(run.runId); // safe to call from UI cancel buttons
|
|
|
179
241
|
| `error` | 失败事件(`throwOnError:true` 默认会转 `AgentRunStreamError` 抛出) | `error.code`、`error.message`、`error.stage`、`error.retryable` |
|
|
180
242
|
| `done` | 流终止 | `runId`、`status` |
|
|
181
243
|
|
|
244
|
+
### 远程控制 — CrabCode remote-control(v2.1.0)
|
|
245
|
+
|
|
246
|
+
远程控制是 Agent Run 的一个独立 runtime(`runtime: 'crabcode_remote'`),用于把 CrabCode 子进程的会话/工具/权限循环经服务端适配成 C 端可消费的事件流。它**不复用** `agentRuns.stream` 的旧事件 union,事件协议另成一套(契约 §4 的 11 事件)。
|
|
247
|
+
|
|
248
|
+
```ts
|
|
249
|
+
import { Client, remoteControlScopes } from '@acosmi/sdk-ts';
|
|
250
|
+
|
|
251
|
+
const client = new Client({ baseURL: process.env.ACOSMI_BASE_URL! });
|
|
252
|
+
// 远控是高风险 scope,不在 allScopes() 内,必须显式申请
|
|
253
|
+
await client.login('CrabCode Remote', remoteControlScopes());
|
|
254
|
+
|
|
255
|
+
const run = await client.agentRuns.createRemoteRun({
|
|
256
|
+
appId: 'crabcode',
|
|
257
|
+
input: '重构这个函数并跑测试',
|
|
258
|
+
runtime: 'crabcode_remote', // 固定值
|
|
259
|
+
runner: 'cloud', // 'cloud' | 'desktop' | 'local_embedded'
|
|
260
|
+
adapter: 'remote_io', // 6 选 1,见下表
|
|
261
|
+
permissionPolicy: { shellAllowed: true, shellDenyList: ['rm', 'shutdown'], approvalTimeoutMs: 30_000 },
|
|
262
|
+
workspacePolicy: { readOnly: false, deniedPaths: ['/etc', '/root'] },
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
for await (const ev of client.agentRuns.streamRemoteControl(run.runId)) {
|
|
266
|
+
switch (ev.type) {
|
|
267
|
+
case 'text_delta': process.stdout.write(ev.text); break;
|
|
268
|
+
case 'permission_request': /* 渲染审批卡片,回写 permission_result */ break;
|
|
269
|
+
case 'settle': console.log('billed', ev.billed); break;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
await client.agentRuns.cancel(run.runId); // UI 中止走服务端 cancel control frame,不是 fetch abort
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
要点:
|
|
277
|
+
|
|
278
|
+
- **scope 隔离**:远控用专用 `remote_control` scope(服务端展开为 `remote_control:{agent-run,session-control,permission-response}` 三子项);**绝不复用** `models:chat`/`ai`,且 `allScopes()` 不含它——桌面登录不会自动获得远控权限。用 `remoteControlScopes()` 或显式 `[...allScopes(), ScopeRemoteControl]`。
|
|
279
|
+
- **adapter / runner**(`AdapterKind` / `RunnerKind`,契约 §3 placement 矩阵):
|
|
280
|
+
|
|
281
|
+
| adapter | 适用 |
|
|
282
|
+
| --- | --- |
|
|
283
|
+
| `remote_io` | 单次纯会话流(CrabCode `--sdk-url` ws/wss) |
|
|
284
|
+
| `app_server_tcp_ws` | Desktop 已登录、本机 AppServer loopback RPC |
|
|
285
|
+
| `bridge_ccr` | 云端/托管 runner,session pool + heartbeat |
|
|
286
|
+
| `app_server_uds` / `stdio_stream_json` | 同机父子进程内嵌 |
|
|
287
|
+
| `tauri_managed_app_server` | Tauri native 托管 lifecycle |
|
|
288
|
+
|
|
289
|
+
- **wire 约定(契约 §12-§14,按平面分)**:远控属 **snake_case 平面**——`permissionPolicy`/`workspacePolicy` 等 SDK camelCase 入参由 SDK 翻译为 snake_case wire(`shell_allowed`/`approval_timeout_ms`/`denied_paths`…);时长一律**整数毫秒**(`approvalTimeoutMs`,禁 `time.Duration` 上 wire)。事件帧为**扁平信封**(`type`+`seq`+字段同级,snake_case),SDK 用 `parseRemoteControlEvent(raw)` 翻译为强类型 `RemoteControlEvent`。
|
|
290
|
+
- **11 事件 union**(`RemoteControlEvent`,契约 §4):`text_delta` / `reasoning_delta` / `tool_call` / `tool_result` / `permission_request` / `permission_result` / `usage` / `settle` / `status` / `error` / `done`。`error` **恒为非终结**(终结性错误由 `done.reason`/`done.finalStatus` 承载),`done` / `settle` 才终结流——故 `streamRemoteControl` 不接受 options、从不抛异常;用 `isTerminalRemoteEvent(ev)` 判终结。
|
|
291
|
+
- **辅助导出**:`parseRemoteControlEvent` / `isTerminalRemoteEvent` / `AdapterKind` / `RunnerKind` / `RemoteControlEvent` / `RemoteSessionPlacement` / `PermissionPolicy` / `WorkspacePolicy`(`src/agent-runs/remote-control.ts`)。
|
|
292
|
+
|
|
293
|
+
## Chat Bridge(第三方聊天平台桥接,v2.1.0 · types-only 骨架,无 client 方法,Phase 7B 后端落地)
|
|
294
|
+
|
|
295
|
+
`chatbridge` 从根入口导出第三方聊天平台(飞书/企微/钉钉/Slack/Teams/Telegram/WhatsApp)接入 Acosmi 远控的**稳定类型契约**。Phase 7 仅交付类型骨架:**SDK 暂无 `client.chatBridge.*` 方法**,平台 webhook/凭证/桥接 handler 是 Phase 7B 后端工作;平台 SDK 依赖留在独立 adapter 包,不进主包。
|
|
296
|
+
|
|
297
|
+
```ts
|
|
298
|
+
import {
|
|
299
|
+
isPlatform, isRegion, isChannelInboundEvent, asCredentialRef,
|
|
300
|
+
type Platform, type ChatCredentialPublic, type ChannelInboundEvent,
|
|
301
|
+
} from '@acosmi/sdk-ts';
|
|
302
|
+
|
|
303
|
+
isPlatform('feishu'); // → true(7 平台枚举运行时守卫)
|
|
304
|
+
asCredentialRef('cred_abc...'); // → branded CredentialRef(防 plaintext 误传)
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
边界(契约 §6 + §16):
|
|
308
|
+
|
|
309
|
+
- 平台 secret(bot token / signing key / AES key)**只入上游 credential vault**;SDK 公共面只见 `CredentialRef`(`cred_<base32>`)+ `fingerprint` + 脱敏 metadata,**永不**出现 ciphertext / plaintext(`ChatCredentialPublic` 编译期即无密文字段)。
|
|
310
|
+
- **wire 平面**:chatbridge 资源视图走 nexus-v4 model-direct 序列化,字段为 **camelCase**(与 remote-control 的 snake_case 平面不同,详见契约 §12)。
|
|
311
|
+
- 平台原始 thread / sender / workspace ID 一律 SHA256 hash 后入库(`threadHash`/`senderHash`)。
|
|
312
|
+
|
|
182
313
|
## 认证
|
|
183
314
|
|
|
184
315
|
### 浏览器内 / 自动 OAuth(推荐)
|
|
@@ -247,6 +378,8 @@ const client = new Client({ serverURL: process.env.ACOSMI_SERVER_URL!, store: ne
|
|
|
247
378
|
| **Client 构造** | `new Client(cfg)`(同步),`Client.create(cfg)`(async;预加载已有 TokenStore) |
|
|
248
379
|
| **Chat** | `chat`, `chatStream`, `chatStreamWithUsage`, `chatMessages`, `chatMessagesStream`, `buildChatRequest` |
|
|
249
380
|
| **Agent Runs** | `agentRuns.create`, `agentRuns.stream`, `agentRuns.run`, `agentRuns.cancel`, `agentRuns.get`, `agentRuns.listArtifacts`, `agentRuns.downloadArtifact`, `agentRuns.submitLocalToolResult`, `agentRuns.runWithLocalTools` |
|
|
381
|
+
| **Agent Runs — 远程控制**(v2.1) | `agentRuns.createRemoteRun`, `agentRuns.streamRemoteControl`;helper:`parseRemoteControlEvent`, `isTerminalRemoteEvent`;scope:`remoteControlScopes()` / `ScopeRemoteControl`(不进 `allScopes()`) |
|
|
382
|
+
| **Chat Bridge**(v2.1 · types-only) | 无 client 方法(Phase 7B 后端落地);导出类型守卫 `isPlatform`, `isRegion`, `isIntegrationStatus`, `isChannelInboundEvent`, `asCredentialRef` |
|
|
250
383
|
| **Auth — 内置 Loopback OAuth** | `login`, `loginWithHandler`, `logout`, `ensureToken`, `forceRefresh`, `isAuthorized`, `getTokenSet` |
|
|
251
384
|
| **Auth — 手动 OAuth 原语** | `discover`, `discoverWithProfile`, `register`, `authorize`, `exchangeCode`, `refreshToken`, `revokeToken`, `generateState` |
|
|
252
385
|
| **Auth — 浏览器 Web OAuth (v1.4.0+)** | `discoverWebOAuthMetadata`, `registerWebOAuthClient`, `createWebAuthorizationRequest`, `completeWebAuthorizationRequest` |
|
|
@@ -260,7 +393,17 @@ const client = new Client({ serverURL: process.env.ACOSMI_SERVER_URL!, store: ne
|
|
|
260
393
|
| **Notifications — WebSocket** | `connect`, `disconnect`, `isConnected` (实时推送订阅;浏览器走原生 WebSocket,Node 18-21 需自装 `ws`,Node 22+ 用原生) |
|
|
261
394
|
| **Bug Report** | `submitBugReport`, `getBugReport` |
|
|
262
395
|
| **Web Search** | `newWebSearchTool` (factory) |
|
|
263
|
-
| **
|
|
396
|
+
| **Subscription**(v1.7.0+) | `listPlans`, `listUserSubscriptions` |
|
|
397
|
+
| **Pricing**(v1.7.0+) | `getPricingConfig`, `quoteCompliance` |
|
|
398
|
+
| **Products**(v1.7.0+) | `getProductBySlug`, `listProductsByFamily`, `listComplianceSkus`, `listPublicModels` |
|
|
399
|
+
| **Casehall — 法律案件**(v1.8.0+) | `listLawyers`, `getLawyer`, `submitCaseLead`, `listMyCaseLeads`, `getMyCases`, `bookConsultation`, `listMyConsultations`, `listMyLegalOrders`, `listLegalSKUs`, `getMyLawyerCredentialStatus`(v2.0.0+) |
|
|
400
|
+
| **Enterprise — 企业席位**(v1.8.1+) | `listMyEnterprises`, `getEnterprise`, `inviteMember`, `listEnterpriseMembers`, `listOrgSubscriptions`, `listSeats`, `assignSeat`, `revokeSeat`, `getOrgConsumeReport`, `getMyEnterpriseKycStatus`(v2.0.0+) |
|
|
401
|
+
| **Finance — 财务**(v1.9.0+) | `listMyInvoices`, `requestInvoice`, `listMyRefunds`, `requestRefund`, `listMyCorporateTransfers`, `initiateCorporateTransfer`, `uploadCorporateTransferProof` |
|
|
402
|
+
| **Compliance — 证据 / 章戳 / 公开验真** | `compliance.createEvidenceAsset`, `compliance.getEvidenceAsset`, `compliance.verifyEvidencePublic`(匿名公开验真,v1.3.2+), `compliance.issueTimestamp`, `compliance.issueTimestampForAsset`, `compliance.getTimestamp`, `compliance.verifyTimestamp`, `compliance.waitForTimestampVerified`, `compliance.buildEvidencePackage` |
|
|
403
|
+
| **Compliance — 报告** | `compliance.createReport`(写,带 `Idempotency-Key`), `compliance.getReport`, `compliance.publishReport`(step-up + 写), `compliance.downloadReport` |
|
|
404
|
+
| **Compliance — 签署 envelope** | `compliance.createSigningEnvelope`(写), `compliance.getSigningEnvelope`, `compliance.signEnvelope`(step-up + gate + 写), `compliance.createH5SigningUrl`(step-up + gate + 写), `compliance.syncSigningEnvelopeStatus`(写) |
|
|
405
|
+
| **Compliance — 用印审批** | `compliance.submitSealApproval`(写), `compliance.approveSealApproval`(step-up + 写), `compliance.rejectSealApproval`(写), `compliance.cancelSealApproval`(写), `compliance.listPendingSealApprovals`, `compliance.getSealApproval` |
|
|
406
|
+
| **Compliance — Provider Request** | `compliance.getProviderRequest`, `compliance.waitForProviderRequestTerminal`, `compliance.classifyError` |
|
|
264
407
|
| **Compliance — 分页列表** | `compliance.listEvidenceAssets`, `compliance.listTimestamps`, `compliance.listEvidencePackages`, `compliance.listReports`, `compliance.listSigningEnvelopes`, `compliance.listSealApprovals`, `compliance.listSealUses`(均返回 `PageResult<T>`) |
|
|
265
408
|
| **Compliance — 能力与操作投影** | `compliance.getCapabilities`, `compliance.getFeatureGate`, `compliance.listOperations`, `compliance.getOperation` |
|
|
266
409
|
| **Compliance — TSA 只读视图** | `compliance.listTsaProviders`, `compliance.getTsaStats` |
|
|
@@ -537,68 +680,103 @@ PII / 合同原文 / storage bucket+key / subject snapshot / provider raw / TSA
|
|
|
537
680
|
|
|
538
681
|
### 完整 API 列表
|
|
539
682
|
|
|
683
|
+
标注约定:
|
|
684
|
+
- `// 写` — POST / PUT / DELETE 写操作,**必传 `Idempotency-Key`**(即第二参数 `options?: ComplianceWriteOptions` 的 `idempotencyKey` 字段);写操作不自动 retry,401 不 refresh + replay
|
|
685
|
+
- `// step-up` — 需 OAuth token 升级等级;失败抛 `BusinessError` 含 code `1031000013`,调用方按 `classifyComplianceError` 分支引导用户重新 introspection
|
|
686
|
+
- `// gate` — 受 capability gate 控制,未闭合时 fail-closed;先用 `getCapabilities` / `getFeatureGate` 探测
|
|
687
|
+
- `// 分页` — 走 `GET .../page` 返回 `PageResult<T>`(`{ total, list }`)
|
|
688
|
+
- 无标注 — GET 读路径,单次 401 refresh 重试
|
|
689
|
+
|
|
690
|
+
#### 证据资产(evidence)
|
|
691
|
+
|
|
540
692
|
```ts
|
|
541
|
-
client.compliance.createEvidenceAsset(req, options?)
|
|
693
|
+
client.compliance.createEvidenceAsset(req, options?) // 写
|
|
542
694
|
client.compliance.getEvidenceAsset(id, signal?)
|
|
543
|
-
client.compliance.verifyEvidencePublic(req, signal?)
|
|
544
|
-
client.compliance.listEvidenceAssets(req?, signal?)
|
|
545
|
-
client.compliance.listEvidencePackages(req?, signal?)
|
|
695
|
+
client.compliance.verifyEvidencePublic(req, signal?) // 匿名公开验真(未 login 不抛 not-authorized)
|
|
696
|
+
client.compliance.listEvidenceAssets(req?, signal?) // 分页
|
|
697
|
+
client.compliance.listEvidencePackages(req?, signal?) // 分页
|
|
698
|
+
client.compliance.buildEvidencePackage(assetId, timestampTokenId?, options?) // 写
|
|
699
|
+
```
|
|
700
|
+
|
|
701
|
+
#### 时间章(timestamp)
|
|
546
702
|
|
|
547
|
-
|
|
548
|
-
client.compliance.
|
|
703
|
+
```ts
|
|
704
|
+
client.compliance.issueTimestamp(req, options?) // 写
|
|
705
|
+
client.compliance.issueTimestampForAsset(assetId, options?) // 写
|
|
549
706
|
client.compliance.getTimestamp(id, signal?)
|
|
550
|
-
client.compliance.verifyTimestamp(req, options?)
|
|
707
|
+
client.compliance.verifyTimestamp(req, options?) // 写(远端 verify 落审计)
|
|
551
708
|
client.compliance.waitForTimestampVerified(id, opts?)
|
|
552
|
-
client.compliance.listTimestamps(req?, signal?)
|
|
709
|
+
client.compliance.listTimestamps(req?, signal?) // 分页
|
|
710
|
+
client.compliance.listTsaProviders(signal?) // TSA provider 只读列表
|
|
711
|
+
client.compliance.getTsaStats(signal?) // 时间章统计只读视图
|
|
712
|
+
```
|
|
553
713
|
|
|
554
|
-
|
|
714
|
+
#### 出证报告(report)
|
|
555
715
|
|
|
556
|
-
|
|
716
|
+
```ts
|
|
717
|
+
client.compliance.createReport(req, options?) // 写,需 compliance:reports:write
|
|
557
718
|
client.compliance.getReport(id, signal?)
|
|
558
|
-
client.compliance.publishReport(id, options?)
|
|
559
|
-
client.compliance.downloadReport(id, signal?)
|
|
560
|
-
client.compliance.listReports(req?, signal?)
|
|
719
|
+
client.compliance.publishReport(id, options?) // 写 + step-up
|
|
720
|
+
client.compliance.downloadReport(id, signal?) // 离线复核 hash 视图
|
|
721
|
+
client.compliance.listReports(req?, signal?) // 分页
|
|
722
|
+
```
|
|
561
723
|
|
|
562
|
-
|
|
724
|
+
#### 签署 envelope
|
|
725
|
+
|
|
726
|
+
```ts
|
|
727
|
+
client.compliance.createSigningEnvelope(req, options?) // 写
|
|
563
728
|
client.compliance.getSigningEnvelope(envelopeId, signal?)
|
|
564
|
-
client.compliance.signEnvelope(envelopeId, req, options?)
|
|
565
|
-
client.compliance.createH5SigningUrl(envelopeId, req, options?)
|
|
566
|
-
client.compliance.syncSigningEnvelopeStatus(envelopeId, options?)
|
|
567
|
-
client.compliance.listSigningEnvelopes(req?, signal?)
|
|
568
|
-
client.compliance.listEnvelopeContracts(envelopeId, signal?)
|
|
569
|
-
client.compliance.listEnvelopeProviderRequests(envelopeId, signal?)
|
|
570
|
-
client.compliance.voidEnvelope(envelopeId, req, options?)
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
729
|
+
client.compliance.signEnvelope(envelopeId, req, options?) // 写 + step-up + gate
|
|
730
|
+
client.compliance.createH5SigningUrl(envelopeId, req, options?) // 写 + step-up + gate
|
|
731
|
+
client.compliance.syncSigningEnvelopeStatus(envelopeId, options?) // 写
|
|
732
|
+
client.compliance.listSigningEnvelopes(req?, signal?) // 分页
|
|
733
|
+
client.compliance.listEnvelopeContracts(envelopeId, signal?) // 合同列表(数组,非 PageResult)
|
|
734
|
+
client.compliance.listEnvelopeProviderRequests(envelopeId, signal?) // provider 请求列表(数组,非 PageResult)
|
|
735
|
+
client.compliance.voidEnvelope(envelopeId, req, options?) // 写
|
|
736
|
+
```
|
|
737
|
+
|
|
738
|
+
#### 用印审批(seal approval / seal use)
|
|
739
|
+
|
|
740
|
+
```ts
|
|
741
|
+
client.compliance.submitSealApproval(req, options?) // 写
|
|
742
|
+
client.compliance.approveSealApproval(id, query, options?) // 写 + step-up
|
|
743
|
+
client.compliance.rejectSealApproval(id, query, options?) // 写
|
|
744
|
+
client.compliance.cancelSealApproval(id, query, options?) // 写
|
|
576
745
|
client.compliance.listPendingSealApprovals(signal?)
|
|
577
746
|
client.compliance.getSealApproval(id, signal?)
|
|
578
|
-
client.compliance.listSealApprovals(req?, signal?)
|
|
579
|
-
client.compliance.listSealUses(req?, signal?)
|
|
747
|
+
client.compliance.listSealApprovals(req?, signal?) // 分页
|
|
748
|
+
client.compliance.listSealUses(req?, signal?) // 分页(用印执行)
|
|
749
|
+
```
|
|
750
|
+
|
|
751
|
+
#### Provider request 状态轮询
|
|
580
752
|
|
|
753
|
+
```ts
|
|
581
754
|
client.compliance.getProviderRequest(id, signal?)
|
|
582
755
|
client.compliance.waitForProviderRequestTerminal(id, opts?)
|
|
756
|
+
```
|
|
757
|
+
|
|
758
|
+
#### 能力闸门 / 操作投影
|
|
759
|
+
|
|
760
|
+
```ts
|
|
761
|
+
client.compliance.getCapabilities(signal?) // 能力闸门列表(拿不到必须 fail-closed)
|
|
762
|
+
client.compliance.getFeatureGate(action, signal?) // 单动作能力(便捷,一次网络请求)
|
|
763
|
+
client.compliance.listOperations(req?, signal?) // 分页(操作投影)
|
|
764
|
+
client.compliance.getOperation(id, signal?)
|
|
765
|
+
client.compliance.classifyError(err) // BusinessError → ComplianceErrorInfo | null(同顶层 classifyComplianceError,便于 catch 块链式调用)
|
|
766
|
+
```
|
|
583
767
|
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
client.compliance.
|
|
588
|
-
client.compliance.
|
|
589
|
-
|
|
590
|
-
client.compliance.
|
|
591
|
-
client.compliance.
|
|
592
|
-
|
|
593
|
-
client.compliance.
|
|
594
|
-
client.compliance.
|
|
595
|
-
client.compliance.
|
|
596
|
-
client.compliance.getContractTemplate(id, signal?) // 模板详情
|
|
597
|
-
client.compliance.listContractTemplates(req?, signal?) // 模板分页 → PageResult
|
|
598
|
-
client.compliance.uploadContractTemplatePdf(id, req, options?) // 上传 PDF(base64)
|
|
599
|
-
client.compliance.publishContractTemplate(id, options?) // DRAFT → PUBLISHED
|
|
600
|
-
client.compliance.archiveContractTemplate(id, options?) // PUBLISHED → ARCHIVED
|
|
601
|
-
client.compliance.listContractTemplateVersions(id, signal?) // 版本快照列表(数组)
|
|
768
|
+
#### 合同模板(contract template,v1.5.0 S5)
|
|
769
|
+
|
|
770
|
+
```ts
|
|
771
|
+
client.compliance.createContractTemplate(req, options?) // 写,DRAFT
|
|
772
|
+
client.compliance.updateContractTemplate(id, req, options?) // 写(仅 DRAFT)
|
|
773
|
+
client.compliance.deleteContractTemplate(id, options?) // 写(仅 DRAFT)
|
|
774
|
+
client.compliance.getContractTemplate(id, signal?) // 模板详情
|
|
775
|
+
client.compliance.listContractTemplates(req?, signal?) // 分页
|
|
776
|
+
client.compliance.uploadContractTemplatePdf(id, req, options?) // 写(上传 PDF base64)
|
|
777
|
+
client.compliance.publishContractTemplate(id, options?) // 写,DRAFT → PUBLISHED
|
|
778
|
+
client.compliance.archiveContractTemplate(id, options?) // 写,PUBLISHED → ARCHIVED
|
|
779
|
+
client.compliance.listContractTemplateVersions(id, signal?) // 版本快照列表(数组)
|
|
602
780
|
```
|
|
603
781
|
|
|
604
782
|
> 6 个 `list*` 分页方法(compliance gateway S1)均走 `GET .../page`,返回
|
|
@@ -683,7 +861,15 @@ npm run docs # 经 TypeDoc 生成 API 参考到 docs/api/
|
|
|
683
861
|
|
|
684
862
|
| 版本 | 状态 | 概要 |
|
|
685
863
|
| --- | --- | --- |
|
|
686
|
-
| 1.
|
|
864
|
+
| 2.1.0 | **当前稳定版(npm latest)** | **远程控制 CrabCode 多接入面(2026-05-28)**。`serverURL`/`baseURL`/`baseUrl` Gateway URL 公共契约 + `normalizeGatewayBaseURL`(仅 http/https,拒 ws/wss);`agentRuns.createRemoteRun` / `streamRemoteControl` + 11 事件 `RemoteControlEvent` union + `parseRemoteControlEvent` / `isTerminalRemoteEvent`;`AdapterKind`(6) / `RunnerKind`(3) / `PermissionPolicy` / `WorkspacePolicy`;专用 `remote_control` scope(不进 `allScopes()`,`remoteControlScopes()`);`chatbridge` 第三方聊天平台类型骨架(types-only,无 client 方法,Phase 7B 后端落地);`subscription.getPlanByCode`。wire 约定按平面分(远控 snake_case + 毫秒整数 / chatbridge camelCase,契约 §12-§14)。公开类型 / 方法签名零移除、零改名(additive minor)。 |
|
|
865
|
+
| 2.0.1 | 稳定版 | **Packaging fix — 纯发布元数据,无源码改动**。`package.json.files` 数组补 `docs/pii-role-matrix.md` + `docs/开发与发布手册.md` 两项,让 v2.0.0 引入的 PII 角色矩阵与开发手册随 npm tarball 一并下发。从 v2.0.0 升级到 v2.0.1 无需任何 review。 |
|
|
866
|
+
| 2.0.0 | **BREAKING** | **Phase 3 复核 + 全量根治(2026-05-25)**。主仓 9 commit 闭环 20 P0(RBAC 表达式统一 / PII 真落盘加密链 / K7 视频 webhook 幂等 / K8 OCR SSRF / K9 KYC main flow / admin 写端点错误码契约)。**SDK 同步**:新增 `casehall.getMyLawyerCredentialStatus()` + `enterprise.getMyEnterpriseKycStatus()` 律师/企业 OWNER 自查端点;`finance/types.ts` P2-016 PII Javadoc 升级(含 `keyVersion` v1/v2 payload 协议);新建 `docs/pii-role-matrix.md`(4 角色 × 3 PII 级矩阵);admin 写端点错误码改 HTTP 状态码语义(`200+{ok:false}` → `403/404/501`)。**升级指引详见 §"v2.0.0 升级指引"**。SDK 公开类型 / 方法签名零移除、零改名;BREAKING 范围在网关后端契约。 |
|
|
867
|
+
| 1.9.0 | 稳定版 | **finance 域落地(商品化总规划 P7)**。新增 `client.finance.*`:`listMyInvoices` / `requestInvoice` / `listMyRefunds` / `requestRefund` / `listMyCorporateTransfers` / `initiateCorporateTransfer` / `uploadCorporateTransferProof`(决策 14/15 + R12)。发票 / 退款 / 对公转账三条业务线全量接入;金额一律用 string(json.Number 端口,避免 JS 浮点损失)。 |
|
|
868
|
+
| 1.8.1 | 稳定版 | **enterprise 企业席位域落地(商品化总规划 P6a)**。新增 `client.enterprise.*`:`listMyEnterprises` / `getEnterprise` / `inviteMember` / `listEnterpriseMembers` / `listOrgSubscriptions` / `listSeats` / `assignSeat` / `revokeSeat` / `getOrgConsumeReport`。OWNER/ADMIN 权限下席位月度变更 ≤ 3 次(超出返 41xxx 业务码);订阅 + 席位 + 用量报表三视图齐备。 |
|
|
869
|
+
| 1.8.0 | 稳定版 | **casehall 法律案件咨询域落地(商品化总规划 P5 方案 B)**。新增 `client.casehall.*`:`listLawyers` / `getLawyer` / `submitCaseLead` / `listMyCaseLeads` / `getMyCases` / `bookConsultation` / `listMyConsultations` / `listMyLegalOrders` / `listLegalSKUs`。律师库公开端点(VERIFIED + ACTIVE,PII L3 已脱敏)+ 案件线索 + 咨询 + 5 LEGAL_SERVICE SKU;admin 板块 9 模块不在 SDK 边界。 |
|
|
870
|
+
| 1.7.0 | 稳定版 | **subscription + pricing + products 三域落地(商品化总规划 P1-P4)**。`subscription`:`listPlans` / `listUserSubscriptions`(订阅档位 + 用户订阅)。`pricing`:`getPricingConfig` / `quoteCompliance`(公开业务参数 + csign 合规 SKU 报价)。`products`:`getProductBySlug` / `listProductsByFamily` / `listComplianceSkus` / `listPublicModels`(商品中心 productFamily / audience / billingMode 索引)。 |
|
|
871
|
+
| 1.6.0 | 稳定版 | `ChatRequest.endUserId` 业务侧终端用户稳定标识,跨 provider 通用语义;SDK 自动按 wire-format 注入(OpenAI 顶层 `user_id` / Anthropic `metadata.user_id`);不传时网关从认证身份 HMAC-SHA256 自动派生 32 字符 id。`validateEndUserId(s)` helper 校验 PII / 长度 / 字符集。SSE keep-alive + 11 分钟超时调优;网关侧命中三项隔离能力(内容安全 / KV-cache / 调度)。 |
|
|
872
|
+
| 1.5.1 | 历史稳定版 | **Docs / examples / 源码注释全量复核与修订 — 无 API 变化**。修补 8 项漂移与遗漏:README API 总览补 25+ 漏列方法(Chat 内部方法、Auth 浏览器 Web OAuth 4 原语、Skills/Notifications/Entitlements/Packages 全量、WS `connect/disconnect/isConnected`);重写 §"手动 OAuth" 段对齐 `auth.ts` 真实签名;§"双格式红线" + 三个 chat 示例 `maxTokens` → snake_case `max_tokens`;错误表补 `ModelNotFoundError`;§Agent Runs 补 13 类 stream event 完整表;新增 §`sanitize` 命名空间小节;`docs/compliance.md` 6 处 `Since v1.6/.../1.10` 统一为 `v1.5.0 (originally planned as ...)`;手册 §7 scope 数 12 → 15 + 新增 S1-S6 rollup 段;`examples/compliance-evidence-timestamp.ts` 补 `ScopeComplianceReportsWrite`(v1.3.2 漂移生产 401 隐患);`examples/auth-oauth-flow.ts` + `examples/core-chat.ts` 注释对齐当前契约;`src/index.ts` + `src/browser.ts` + `src/auth/auth.ts` 注释从 Go-port 语义改为"TS 主实现 + Web OAuth 替代品"。`typecheck` / `lint` / `vitest`(214) / `build` / `test:pack` 全绿。 |
|
|
687
873
|
| 1.5.0 | 稳定版 | 沉淀 `src/shared/` 跨域共享 DTO(`PageRequest`/`PageResult` 别名、`OperationId`/`OperationStatus`/`IdempotencyKeyHeader`、`RetryAdvice` 叠加层、`PrincipalRef`/`TenantRef`、`FeatureGateStatus`/`StepUpStatus`/`BillingPreflightResult`)。**同时全量 rollup compliance gateway S1-S6** 能力(原 1.6.0-1.11.0 roadmap,见 [CHANGELOG.md](./CHANGELOG.md)):S1 6 个分页列表、S2 capabilities + operations 投影、S3 TSA 只读视图、S4 envelope 收尾 + void、S5 合同模板全生命周期 + 2 新 scope(`compliance:contract_template:{read,write}`)、S6 用印执行分页(`listSealUses`)。当前 compliance scope 总数 **15** 个(`complianceScopes()` 返回)。纯增量;8 个平台控制面占位命名空间仍待后端契约就绪后落地。 |
|
|
688
874
|
| 1.4.2 | 稳定版 | `src/` 从扁平 36 文件按业务域重组为 per-domain 目录;公共导出符号集合、`exports`、`dist/` 路径一字未变(纯内部重组)。新增 TypeDoc API 文档。 |
|
|
689
875
|
| 1.4.1 | 稳定版 | 新增 `Config.browserRefreshMode` / `refreshProxyURL`——浏览器 Web OAuth token 刷新策略(规避 issuer CORS 403)。 |
|