@acosmi/sdk-ts 2.6.0 → 2.7.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 +20 -0
- package/README.md +74 -11
- package/dist/browser/index.mjs +307 -2
- package/dist/browser/index.mjs.map +1 -1
- package/dist/index.mjs +307 -2
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +310 -1
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +228 -3
- package/dist/node/index.d.ts +228 -3
- package/dist/node/index.mjs +307 -2
- 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 +6 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,26 @@ 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.7.0] - 2026-06-11 — 远控管理面补齐 + BYOK 密钥客户端 + Chat Bridge CRUD(Phase 7B)
|
|
9
|
+
|
|
10
|
+
补齐远控核心交互之外的全部管理面(此前下游 CrabCode 只能裸 fetch),新增 BYO 模型密钥客户端,落地 chat-bridge integration/credential 管理面 CRUD——云端控制台与下游调用的是同一组端点同一份租户隔离数据,天然互通。全部方法逐字段对齐 nexus-v4 handler 真实 wire 形状(契约 §12/§14/§18 附录 A)。
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **`agentRuns.list(opts?)`** — 调用者自己的 run 列表(`GET /agent-runs`,Phase 5C 控制台):`runtime`/`status` 过滤 + `page`/`pageSize` 分页,信封 `{records,total,page,pageSize}`;run view 新增 `runtime`/`runner`/`adapter` 字段(标准 run 缺省),永不含 session token/policy/messages。
|
|
15
|
+
- **`agentRuns.submitPermissionResult(runId, {requestId, decision, reason?})`** — 远控审批决策回写(`POST /:runId/permission-results`);decision 仅 `approved`|`rejected`(契约 §14),409 = 会话不可用。
|
|
16
|
+
- **`agentRuns.submitUserMessage(runId, {content, requestId?})`** — 会话中途追加用户消息(`POST /:runId/messages`,≤64KB,role 服务端硬编码 user);返回服务端最终幂等键。
|
|
17
|
+
- **`agentRuns.revealRemoteToken(runId)`** — desktop launcher 一次性 session token(`POST /:runId/remote-token`,Phase 5B;仅 runner=desktop);响应含 `workspace`(契约 §18.3 r4)。token 永不落浏览器存储。
|
|
18
|
+
- **`AgentRunCreateRequest.byokCredentialRef`** — BYO 密钥引用上 wire(`byok_credential_ref`,仅远控 + cloud runner)。
|
|
19
|
+
- **`client.crabcodeByok`(`CrabCodeByokClient`)** — BYO 模型密钥管理面(契约 §18.2,`/crabcode/byok-credentials`,`remote_control` scope):`list`/`create`/`rotate`/`revoke`;明文一次性提交,响应恒 masked(ref+fingerprint)。新类型 `ByokProvider`/`ByokCredential`/`ByokCreateRequest`。
|
|
20
|
+
- **`client.chatBridge`(`ChatBridgeClient`,Phase 7B)** — 第三方聊天平台集成/凭证管理面 CRUD:`createIntegration`/`listIntegrations`/`getIntegration`/`updateIntegrationStatus` + `storeCredential`/`listCredentials`/`rotateCredential`/`revokeCredential`。请求体 snake_case(SDK 转换)、响应 camelCase(契约 §12 平面分化);scope 三档 `chat_bridge:read`/`:write`/`:rotate`。新类型 `CreateIntegrationRequest`/`StoreCredentialRequest`。
|
|
21
|
+
- **metadata 约定键常量** — `AGENT_RUN_META_TITLE`/`AGENT_RUN_META_WORKSPACE`(契约 §18.3 r4:title 列表标题 / workspace 期望项目目录)。
|
|
22
|
+
- **远控管理面类型** — `RemotePermissionDecision`/`RemotePermissionResultRequest`/`RemoteUserMessageRequest`/`RemoteUserMessageAck`/`RemoteSessionTokenGrant`/`AgentRunListOptions`/`AgentRunListResult`。
|
|
23
|
+
|
|
24
|
+
### Deprecated
|
|
25
|
+
|
|
26
|
+
- **`ChatIntegration.configJson`** — 服务端从不返回该字段(model `json:"-"`,防 secret 误入后整体不外发),读取恒 `undefined`;写入走 `createIntegration({ configJson })`。
|
|
27
|
+
|
|
8
28
|
## [2.6.0] - 2026-06-04 — 会员订阅查询 + 后端契约类型修正 + WS 一次性 ticket 鉴权
|
|
9
29
|
|
|
10
30
|
新增会员订阅查询能力 + chat_bridge scope,并修正一批此前与后端不符(运行时即为 `undefined`)的计费/订单/钱包/余额/通知类型形状。**破坏性 = 类型修正**:被修正的类型字段名 / 类型发生变化,但它们此前本就拿不到正确运行时值,对真正生效的调用代码无功能回退。
|
package/README.md
CHANGED
|
@@ -332,14 +332,50 @@ const run = await client.agentRuns.createRemoteRun({
|
|
|
332
332
|
for await (const ev of client.agentRuns.streamRemoteControl(run.runId)) {
|
|
333
333
|
switch (ev.type) {
|
|
334
334
|
case 'text_delta': process.stdout.write(ev.text); break;
|
|
335
|
-
case 'permission_request':
|
|
335
|
+
case 'permission_request': // 渲染审批卡片后回写决策 (仅 approved|rejected, 契约 §14)
|
|
336
|
+
await client.agentRuns.submitPermissionResult(run.runId, {
|
|
337
|
+
requestId: ev.requestId, decision: 'approved',
|
|
338
|
+
});
|
|
339
|
+
break;
|
|
336
340
|
case 'settle': console.log('billed', ev.billed); break;
|
|
337
341
|
}
|
|
338
342
|
}
|
|
339
343
|
|
|
344
|
+
// 会话中途追加用户消息 (role 服务端硬编码 user, ≤64KB)
|
|
345
|
+
await client.agentRuns.submitUserMessage(run.runId, { content: '继续, 用方案B' });
|
|
346
|
+
|
|
340
347
|
await client.agentRuns.cancel(run.runId); // UI 中止走服务端 cancel control frame,不是 fetch abort
|
|
341
348
|
```
|
|
342
349
|
|
|
350
|
+
#### 远控管理面(v2.7.0)
|
|
351
|
+
|
|
352
|
+
| 方法 | 端点 | 说明 |
|
|
353
|
+
| --- | --- | --- |
|
|
354
|
+
| `agentRuns.list(opts?)` | `GET /agent-runs` | 调用者自己的 run 列表(新→旧);`{ runtime: 'crabcode_remote' }` 过滤远控 run,分页 `{records,total,page,pageSize}`。view 只含元数据,永不含 session token / policy / messages(契约 §6) |
|
|
355
|
+
| `agentRuns.submitPermissionResult(runId, {requestId, decision, reason?})` | `POST /:runId/permission-results` | 回写 `permission_request` 决策;仅 `approved` \| `rejected`(`timeout`/`cancelled` 由服务端产生)。409 = 远控会话已不可用 |
|
|
356
|
+
| `agentRuns.submitUserMessage(runId, {content, requestId?})` | `POST /:runId/messages` | 会话中途追加用户消息;role 服务端硬编码 `user`(契约 §6 #5 防注入),返回服务端最终幂等键 |
|
|
357
|
+
| `agentRuns.revealRemoteToken(runId)` | `POST /:runId/remote-token` | **仅 desktop runner / desktop launcher 用**:一次性 session token(重复调用 409)。token 永不落浏览器存储,native 层接收后只注入 CrabCode 子进程 env;响应含 `workspace`(用户声明的项目目录,契约 §18.3 r4) |
|
|
358
|
+
|
|
359
|
+
**metadata 约定键(契约 §18.3 r4)**:`metadata.title`(列表显示标题,缺省服务端从 input 首行派生)、`metadata.workspace`(期望项目目录,经 `revealRemoteToken().workspace` 下发给桌面端采纳)。常量 `AGENT_RUN_META_TITLE` / `AGENT_RUN_META_WORKSPACE`。服务端上限 ≤32 条 / 键 ≤64B / 值 ≤2KB。
|
|
360
|
+
|
|
361
|
+
#### BYOK — 用户自有模型密钥(v2.7.0,契约 §18.2)
|
|
362
|
+
|
|
363
|
+
`client.crabcodeByok` 管理 BYO 模型密钥(守卫 `remote_control` scope);创建后把 `credentialRef` 传给 `createRemoteRun({ byokCredentialRef })`(仅 `runner: 'cloud'`)。明文一次性提交、服务端加密落库后即弃,所有读取只回 masked 视图(ref + fingerprint)——解密只发生在网关 cloud runner 启动时的子进程 env 注入点。
|
|
364
|
+
|
|
365
|
+
```ts
|
|
366
|
+
const cred = await client.crabcodeByok.create({
|
|
367
|
+
provider: 'deepseek', // anthropic|openai|deepseek|dashscope|zhipu|volcengine|custom
|
|
368
|
+
plaintext: process.env.MY_KEY!, // 一次性提交; SDK/服务端永不回传
|
|
369
|
+
name: '我的 DeepSeek 钥匙',
|
|
370
|
+
});
|
|
371
|
+
await client.agentRuns.createRemoteRun({
|
|
372
|
+
appId: '', input: '…', runtime: 'crabcode_remote', runner: 'cloud', adapter: 'remote_io',
|
|
373
|
+
byokCredentialRef: cred.credentialRef,
|
|
374
|
+
});
|
|
375
|
+
await client.crabcodeByok.rotate(cred.credentialRef, 'sk-new'); // ref 不变, fingerprint 更新
|
|
376
|
+
await client.crabcodeByok.revoke(cred.credentialRef); // 软吊销 + 抹密文, 幂等
|
|
377
|
+
```
|
|
378
|
+
|
|
343
379
|
要点:
|
|
344
380
|
|
|
345
381
|
- **scope 隔离**:远控用专用 `remote_control` scope(服务端展开为 `remote_control:{agent-run,session-control,permission-response}` 三子项);**绝不复用** `models:chat`/`ai`,且 `allScopes()` 不含它——桌面登录不会自动获得远控权限。用 `remoteControlScopes()` 或显式 `[...allScopes(), ScopeRemoteControl]`。
|
|
@@ -357,25 +393,52 @@ await client.agentRuns.cancel(run.runId); // UI 中止走服务端 cancel contro
|
|
|
357
393
|
- **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)` 判终结。
|
|
358
394
|
- **辅助导出**:`parseRemoteControlEvent` / `isTerminalRemoteEvent` / `AdapterKind` / `RunnerKind` / `RemoteControlEvent` / `RemoteSessionPlacement` / `PermissionPolicy` / `WorkspacePolicy`(`src/agent-runs/remote-control.ts`)。
|
|
359
395
|
|
|
360
|
-
## Chat Bridge(第三方聊天平台桥接,v2.
|
|
396
|
+
## Chat Bridge(第三方聊天平台桥接,v2.7.0 · Phase 7B 管理面 CRUD 落地)
|
|
361
397
|
|
|
362
|
-
`
|
|
398
|
+
`client.chatBridge` 提供第三方聊天平台(飞书/企微/钉钉/Slack/Teams/Telegram/WhatsApp)集成与凭证的管理面 CRUD。**云端控制台与下游(CrabCode 等)调的是同一组端点、同一份按租户隔离的数据**——任一端创建/修改,另一端即时可见,无需同步机制。平台 webhook adapter(验签/收发消息)是 Phase 8 后端工作,SDK 不承载。
|
|
363
399
|
|
|
364
400
|
```ts
|
|
365
|
-
import {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
401
|
+
import { Client, chatBridgeScopes } from '@acosmi/sdk-ts';
|
|
402
|
+
|
|
403
|
+
const client = new Client({ baseURL: process.env.ACOSMI_BASE_URL! });
|
|
404
|
+
// chat_bridge 是高风险 scope, 不在 allScopes() 内, 必须显式申请
|
|
405
|
+
await client.login('CrabCode 平台接入', chatBridgeScopes());
|
|
369
406
|
|
|
407
|
+
// 1. 创建集成 (chat_bridge:write); 平台原始 ID 服务端只存 SHA256 hash
|
|
408
|
+
const integ = await client.chatBridge.createIntegration({
|
|
409
|
+
appId: 'crabcode', platform: 'feishu', region: 'cn',
|
|
410
|
+
workspaceId: 'ou_xxx', botId: 'cli_xxx',
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
// 2. 存凭证 (明文一次性提交; 响应恒为 masked 视图, 永不回明文/密文)
|
|
414
|
+
const cred = await client.chatBridge.storeCredential(integ.id, {
|
|
415
|
+
secretKind: 'app_secret', plaintext: process.env.FEISHU_SECRET!,
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
// 3. 激活
|
|
419
|
+
await client.chatBridge.updateIntegrationStatus(integ.id, 'active');
|
|
420
|
+
|
|
421
|
+
// 查询 (chat_bridge:read) / 轮换与吊销 (chat_bridge:rotate, 高风险独立 scope)
|
|
422
|
+
await client.chatBridge.listIntegrations('crabcode');
|
|
423
|
+
await client.chatBridge.listCredentials(integ.id);
|
|
424
|
+
await client.chatBridge.rotateCredential(integ.id, 'app_secret', 'new-secret');
|
|
425
|
+
await client.chatBridge.revokeCredential(cred.credentialRef);
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
类型守卫与 branded ref 仍从根入口导出:
|
|
429
|
+
|
|
430
|
+
```ts
|
|
431
|
+
import { isPlatform, asCredentialRef, type Platform } from '@acosmi/sdk-ts';
|
|
370
432
|
isPlatform('feishu'); // → true(7 平台枚举运行时守卫)
|
|
371
433
|
asCredentialRef('cred_abc...'); // → branded CredentialRef(防 plaintext 误传)
|
|
372
434
|
```
|
|
373
435
|
|
|
374
|
-
边界(契约 §6 + §16):
|
|
436
|
+
边界(契约 §6 + §12 + §16):
|
|
375
437
|
|
|
376
|
-
- 平台 secret(bot token / signing key / AES key
|
|
377
|
-
- **wire
|
|
378
|
-
- 平台原始 thread / sender / workspace ID 一律 SHA256 hash 后入库(`threadHash`/`senderHash`)。
|
|
438
|
+
- 平台 secret(bot token / signing key / AES key)**只在 `storeCredential`/`rotateCredential` 请求体出现一次**,服务端加密落库后即弃;SDK 公共面只见 `CredentialRef`(`cred_<base32>`)+ `fingerprint` + 脱敏 metadata,**永不**出现 ciphertext / plaintext(`ChatCredentialPublic` 编译期即无密文字段)。
|
|
439
|
+
- **wire 平面**:请求体为 snake_case(SDK 自动转换),响应资源视图走 nexus-v4 model-direct 序列化为 **camelCase**(与 remote-control 的 snake_case 平面不同,详见契约 §12)。`ChatIntegration.configJson` 服务端从不返回(`json:"-"`),写入走 `createIntegration({ configJson })`。
|
|
440
|
+
- 平台原始 thread / sender / workspace ID 一律 SHA256 hash 后入库(`threadHash`/`senderHash`/`workspaceIdHash`)。
|
|
441
|
+
- scope 三档最小授权:`chat_bridge:read`(查询)/ `chat_bridge:write`(创建集成/存凭证)/ `chat_bridge:rotate`(轮换/吊销,高风险);分组 scope `chat_bridge` 自包含三子项。跨租户引用服务端一律 404。
|
|
379
442
|
|
|
380
443
|
## 认证
|
|
381
444
|
|
package/dist/browser/index.mjs
CHANGED
|
@@ -4763,6 +4763,8 @@ async function sleepWithSignal2(ms, signal) {
|
|
|
4763
4763
|
}
|
|
4764
4764
|
|
|
4765
4765
|
// src/agent-runs/types.ts
|
|
4766
|
+
var AGENT_RUN_META_TITLE = "title";
|
|
4767
|
+
var AGENT_RUN_META_WORKSPACE = "workspace";
|
|
4766
4768
|
var AgentRunStreamError = class extends Error {
|
|
4767
4769
|
event;
|
|
4768
4770
|
code;
|
|
@@ -4938,6 +4940,33 @@ var AgentRunsClient = class {
|
|
|
4938
4940
|
);
|
|
4939
4941
|
return fromWireCreateResponse(resp);
|
|
4940
4942
|
}
|
|
4943
|
+
/**
|
|
4944
|
+
* List the caller's own agent runs, newest first (GET /agent-runs, Phase 5C
|
|
4945
|
+
* console). Returns view metadata only — never session tokens, policies or
|
|
4946
|
+
* messages (contract §6). Filter remote-control runs with
|
|
4947
|
+
* `{ runtime: 'crabcode_remote' }`.
|
|
4948
|
+
*/
|
|
4949
|
+
async list(opts = {}, signal) {
|
|
4950
|
+
const params = new URLSearchParams();
|
|
4951
|
+
if (opts.runtime) params.set("runtime", opts.runtime);
|
|
4952
|
+
if (opts.status) params.set("status", opts.status);
|
|
4953
|
+
if (opts.page != null) params.set("page", String(opts.page));
|
|
4954
|
+
if (opts.pageSize != null) params.set("page_size", String(opts.pageSize));
|
|
4955
|
+
const qs = params.toString();
|
|
4956
|
+
const resp = await this.requestAPI(
|
|
4957
|
+
"GET",
|
|
4958
|
+
`/agent-runs${qs ? `?${qs}` : ""}`,
|
|
4959
|
+
null,
|
|
4960
|
+
signal,
|
|
4961
|
+
{ retryOn401: true }
|
|
4962
|
+
);
|
|
4963
|
+
return {
|
|
4964
|
+
records: (resp.records ?? []).map(fromWireRun),
|
|
4965
|
+
total: typeof resp.total === "number" ? resp.total : 0,
|
|
4966
|
+
page: typeof resp.page === "number" ? resp.page : 1,
|
|
4967
|
+
pageSize: typeof resp.pageSize === "number" ? resp.pageSize : 20
|
|
4968
|
+
};
|
|
4969
|
+
}
|
|
4941
4970
|
get(runId, signal) {
|
|
4942
4971
|
return this.requestAPI(
|
|
4943
4972
|
"GET",
|
|
@@ -4999,6 +5028,73 @@ var AgentRunsClient = class {
|
|
|
4999
5028
|
[Symbol.asyncIterator]: () => this.streamRemoteControlGen(runId, signal)
|
|
5000
5029
|
};
|
|
5001
5030
|
}
|
|
5031
|
+
/**
|
|
5032
|
+
* Submit a permission decision for a pending `permission_request` event
|
|
5033
|
+
* (POST /agent-runs/:runId/permission-results, contract §4/§9/§14).
|
|
5034
|
+
*
|
|
5035
|
+
* Only `approved` | `rejected` may be submitted by clients — `timeout` /
|
|
5036
|
+
* `cancelled` are produced server-side. Requires an OAuth token with the
|
|
5037
|
+
* explicit `remote_control` scope (or a web JWT). 409 means the remote
|
|
5038
|
+
* session is gone (e.g. already terminated).
|
|
5039
|
+
*/
|
|
5040
|
+
async submitPermissionResult(runId, result, signal) {
|
|
5041
|
+
await this.requestAPI(
|
|
5042
|
+
"POST",
|
|
5043
|
+
`/agent-runs/${encodeURIComponent(runId)}/permission-results`,
|
|
5044
|
+
{
|
|
5045
|
+
request_id: result.requestId,
|
|
5046
|
+
decision: result.decision,
|
|
5047
|
+
reason: result.reason
|
|
5048
|
+
},
|
|
5049
|
+
signal,
|
|
5050
|
+
{ retryOn401: false }
|
|
5051
|
+
);
|
|
5052
|
+
}
|
|
5053
|
+
/**
|
|
5054
|
+
* Append a mid-session user message to a remote run
|
|
5055
|
+
* (POST /agent-runs/:runId/messages, Phase 5C). The message role is
|
|
5056
|
+
* hard-coded to 'user' server-side (contract §6 #5 prompt-injection
|
|
5057
|
+
* defence); content is limited to 64KB. Requires the explicit
|
|
5058
|
+
* `remote_control` scope (or a web JWT).
|
|
5059
|
+
*/
|
|
5060
|
+
async submitUserMessage(runId, message, signal) {
|
|
5061
|
+
const resp = await this.requestAPI(
|
|
5062
|
+
"POST",
|
|
5063
|
+
`/agent-runs/${encodeURIComponent(runId)}/messages`,
|
|
5064
|
+
{ request_id: message.requestId, content: message.content },
|
|
5065
|
+
signal,
|
|
5066
|
+
{ retryOn401: false }
|
|
5067
|
+
);
|
|
5068
|
+
return {
|
|
5069
|
+
ok: resp?.ok === true,
|
|
5070
|
+
requestId: resp?.request_id ?? message.requestId ?? ""
|
|
5071
|
+
};
|
|
5072
|
+
}
|
|
5073
|
+
/**
|
|
5074
|
+
* Reveal the one-shot remote session token for a desktop-runner run
|
|
5075
|
+
* (POST /agent-runs/:runId/remote-token, Phase 5B; contract §18.1).
|
|
5076
|
+
*
|
|
5077
|
+
* Desktop launcher only: the token is single-consumption (a second call
|
|
5078
|
+
* returns 409) and must never touch browser storage — receive it in the
|
|
5079
|
+
* native layer and inject it into the CrabCode child-process env only
|
|
5080
|
+
* (contract §6). Cloud / local_embedded runners never expose tokens over
|
|
5081
|
+
* HTTP (403). Requires the explicit `remote_control` scope.
|
|
5082
|
+
*/
|
|
5083
|
+
async revealRemoteToken(runId, signal) {
|
|
5084
|
+
const resp = await this.requestAPI(
|
|
5085
|
+
"POST",
|
|
5086
|
+
`/agent-runs/${encodeURIComponent(runId)}/remote-token`,
|
|
5087
|
+
{},
|
|
5088
|
+
signal,
|
|
5089
|
+
{ retryOn401: false }
|
|
5090
|
+
);
|
|
5091
|
+
return {
|
|
5092
|
+
accessToken: resp?.access_token ?? "",
|
|
5093
|
+
sessionUrl: resp?.session_url ?? "",
|
|
5094
|
+
tenantId: resp?.tenant_id ?? "",
|
|
5095
|
+
workspace: resp?.workspace || void 0
|
|
5096
|
+
};
|
|
5097
|
+
}
|
|
5002
5098
|
async *streamRemoteControlGen(runId, signal) {
|
|
5003
5099
|
const resp = await this.requestRaw(
|
|
5004
5100
|
"GET",
|
|
@@ -5249,6 +5345,7 @@ function toWireCreateRequest(req) {
|
|
|
5249
5345
|
adapter: req.adapter,
|
|
5250
5346
|
permission_policy: req.permissionPolicy ? toWirePermissionPolicy(req.permissionPolicy) : void 0,
|
|
5251
5347
|
workspace_policy: req.workspacePolicy ? toWireWorkspacePolicy(req.workspacePolicy) : void 0,
|
|
5348
|
+
byok_credential_ref: req.byokCredentialRef,
|
|
5252
5349
|
artifact_policy: req.artifactPolicy ? {
|
|
5253
5350
|
enabled: req.artifactPolicy.enabled,
|
|
5254
5351
|
max_files: req.artifactPolicy.maxFiles
|
|
@@ -5281,7 +5378,10 @@ function fromWireRun(resp) {
|
|
|
5281
5378
|
startedAt: resp.started_at,
|
|
5282
5379
|
completedAt: resp.completed_at,
|
|
5283
5380
|
error: normalizeError(resp.error),
|
|
5284
|
-
metadata: resp.metadata
|
|
5381
|
+
metadata: resp.metadata,
|
|
5382
|
+
runtime: resp.runtime,
|
|
5383
|
+
runner: resp.runner,
|
|
5384
|
+
adapter: resp.adapter
|
|
5285
5385
|
};
|
|
5286
5386
|
}
|
|
5287
5387
|
function fromWireArtifact(resp) {
|
|
@@ -5539,6 +5639,87 @@ function errorMessage(e) {
|
|
|
5539
5639
|
return e instanceof Error ? e.message : String(e);
|
|
5540
5640
|
}
|
|
5541
5641
|
|
|
5642
|
+
// src/agent-runs/byok.ts
|
|
5643
|
+
function fromWireByok(v) {
|
|
5644
|
+
return {
|
|
5645
|
+
credentialRef: v.credential_ref ?? "",
|
|
5646
|
+
provider: v.provider ?? "",
|
|
5647
|
+
name: v.name || void 0,
|
|
5648
|
+
baseUrl: v.base_url || void 0,
|
|
5649
|
+
fingerprint: v.fingerprint || void 0,
|
|
5650
|
+
status: v.status ?? "",
|
|
5651
|
+
createdAt: v.created_at || void 0,
|
|
5652
|
+
lastUsedAt: v.last_used_at || void 0
|
|
5653
|
+
};
|
|
5654
|
+
}
|
|
5655
|
+
var byokByClient = /* @__PURE__ */ new WeakMap();
|
|
5656
|
+
Object.defineProperty(Client.prototype, "crabcodeByok", {
|
|
5657
|
+
configurable: true,
|
|
5658
|
+
enumerable: false,
|
|
5659
|
+
get() {
|
|
5660
|
+
let existing = byokByClient.get(this);
|
|
5661
|
+
if (!existing) {
|
|
5662
|
+
existing = new CrabCodeByokClient(this);
|
|
5663
|
+
byokByClient.set(this, existing);
|
|
5664
|
+
}
|
|
5665
|
+
return existing;
|
|
5666
|
+
}
|
|
5667
|
+
});
|
|
5668
|
+
var CrabCodeByokClient = class {
|
|
5669
|
+
constructor(client) {
|
|
5670
|
+
this.client = client;
|
|
5671
|
+
}
|
|
5672
|
+
client;
|
|
5673
|
+
/** 列出调用者自己的密钥 (masked; 新→旧, 服务端上限 100 条)。 */
|
|
5674
|
+
async list(signal) {
|
|
5675
|
+
const resp = await this.client.doJSON(
|
|
5676
|
+
"GET",
|
|
5677
|
+
"/crabcode/byok-credentials",
|
|
5678
|
+
null,
|
|
5679
|
+
signal
|
|
5680
|
+
);
|
|
5681
|
+
return (resp.data?.items ?? []).map(fromWireByok);
|
|
5682
|
+
}
|
|
5683
|
+
/**
|
|
5684
|
+
* 创建密钥 — 明文一次性提交, 返回 masked 视图。
|
|
5685
|
+
* 单用户上限 20 把; provider='custom' 必须带 https:// baseUrl。
|
|
5686
|
+
*/
|
|
5687
|
+
async create(req, signal) {
|
|
5688
|
+
const resp = await this.client.doJSON(
|
|
5689
|
+
"POST",
|
|
5690
|
+
"/crabcode/byok-credentials",
|
|
5691
|
+
{
|
|
5692
|
+
provider: req.provider,
|
|
5693
|
+
name: req.name,
|
|
5694
|
+
base_url: req.baseUrl,
|
|
5695
|
+
plaintext: req.plaintext
|
|
5696
|
+
},
|
|
5697
|
+
signal
|
|
5698
|
+
);
|
|
5699
|
+
return fromWireByok(resp.data ?? {});
|
|
5700
|
+
}
|
|
5701
|
+
/** 轮换密钥明文 — credentialRef 不变, fingerprint 更新。已吊销的密钥不可轮换 (400)。 */
|
|
5702
|
+
async rotate(credentialRef, newPlaintext, signal) {
|
|
5703
|
+
const resp = await this.client.doJSON(
|
|
5704
|
+
"POST",
|
|
5705
|
+
`/crabcode/byok-credentials/${encodeURIComponent(credentialRef)}/rotate`,
|
|
5706
|
+
{ new_plaintext: newPlaintext },
|
|
5707
|
+
signal
|
|
5708
|
+
);
|
|
5709
|
+
return fromWireByok(resp.data ?? {});
|
|
5710
|
+
}
|
|
5711
|
+
/** 吊销密钥 (软状态 + 服务端抹密文, 不可恢复; 幂等 — 重复吊销返回当前视图)。 */
|
|
5712
|
+
async revoke(credentialRef, signal) {
|
|
5713
|
+
const resp = await this.client.doJSON(
|
|
5714
|
+
"POST",
|
|
5715
|
+
`/crabcode/byok-credentials/${encodeURIComponent(credentialRef)}/revoke`,
|
|
5716
|
+
{},
|
|
5717
|
+
signal
|
|
5718
|
+
);
|
|
5719
|
+
return fromWireByok(resp.data ?? {});
|
|
5720
|
+
}
|
|
5721
|
+
};
|
|
5722
|
+
|
|
5542
5723
|
// src/compliance/scopes.ts
|
|
5543
5724
|
var ScopeComplianceEvidenceRead = "compliance:evidence:read";
|
|
5544
5725
|
var ScopeComplianceEvidenceWrite = "compliance:evidence:write";
|
|
@@ -7192,6 +7373,130 @@ function asCredentialRef(s) {
|
|
|
7192
7373
|
return s;
|
|
7193
7374
|
}
|
|
7194
7375
|
|
|
7195
|
-
|
|
7376
|
+
// src/chatbridge/client.ts
|
|
7377
|
+
var chatBridgeByClient = /* @__PURE__ */ new WeakMap();
|
|
7378
|
+
Object.defineProperty(Client.prototype, "chatBridge", {
|
|
7379
|
+
configurable: true,
|
|
7380
|
+
enumerable: false,
|
|
7381
|
+
get() {
|
|
7382
|
+
let existing = chatBridgeByClient.get(this);
|
|
7383
|
+
if (!existing) {
|
|
7384
|
+
existing = new ChatBridgeClient(this);
|
|
7385
|
+
chatBridgeByClient.set(this, existing);
|
|
7386
|
+
}
|
|
7387
|
+
return existing;
|
|
7388
|
+
}
|
|
7389
|
+
});
|
|
7390
|
+
var ChatBridgeClient = class {
|
|
7391
|
+
constructor(client) {
|
|
7392
|
+
this.client = client;
|
|
7393
|
+
}
|
|
7394
|
+
client;
|
|
7395
|
+
// ---------------------------------------------------------------------------
|
|
7396
|
+
// Integration 管理面
|
|
7397
|
+
// ---------------------------------------------------------------------------
|
|
7398
|
+
/** 创建平台集成 (chat_bridge:write)。云端控制台与下游 (CrabCode) 调的是同一端点/同一份数据。 */
|
|
7399
|
+
async createIntegration(req, signal) {
|
|
7400
|
+
const resp = await this.client.doJSON(
|
|
7401
|
+
"POST",
|
|
7402
|
+
"/chat-bridge/integrations",
|
|
7403
|
+
{
|
|
7404
|
+
app_id: req.appId,
|
|
7405
|
+
platform: req.platform,
|
|
7406
|
+
region: req.region,
|
|
7407
|
+
workspace_id: req.workspaceId,
|
|
7408
|
+
bot_id: req.botId,
|
|
7409
|
+
config_json: req.configJson
|
|
7410
|
+
},
|
|
7411
|
+
signal
|
|
7412
|
+
);
|
|
7413
|
+
return resp.data;
|
|
7414
|
+
}
|
|
7415
|
+
/** 列出本租户集成 (chat_bridge:read; masked 视图)。可按 appId 过滤。 */
|
|
7416
|
+
async listIntegrations(appId, signal) {
|
|
7417
|
+
const qs = appId ? `?app_id=${encodeURIComponent(appId)}` : "";
|
|
7418
|
+
const resp = await this.client.doJSON(
|
|
7419
|
+
"GET",
|
|
7420
|
+
`/chat-bridge/integrations${qs}`,
|
|
7421
|
+
null,
|
|
7422
|
+
signal
|
|
7423
|
+
);
|
|
7424
|
+
return resp.data?.items ?? [];
|
|
7425
|
+
}
|
|
7426
|
+
/** 取单个集成 (chat_bridge:read)。不存在/跨租户一律 404。 */
|
|
7427
|
+
async getIntegration(id, signal) {
|
|
7428
|
+
const resp = await this.client.doJSON(
|
|
7429
|
+
"GET",
|
|
7430
|
+
`/chat-bridge/integrations/${encodeURIComponent(id)}`,
|
|
7431
|
+
null,
|
|
7432
|
+
signal
|
|
7433
|
+
);
|
|
7434
|
+
return resp.data;
|
|
7435
|
+
}
|
|
7436
|
+
/** 更新集成状态 (chat_bridge:write): pending | active | suspended | revoked。 */
|
|
7437
|
+
async updateIntegrationStatus(id, status, signal) {
|
|
7438
|
+
await this.client.doJSON(
|
|
7439
|
+
"PATCH",
|
|
7440
|
+
`/chat-bridge/integrations/${encodeURIComponent(id)}/status`,
|
|
7441
|
+
{ status },
|
|
7442
|
+
signal
|
|
7443
|
+
);
|
|
7444
|
+
}
|
|
7445
|
+
// ---------------------------------------------------------------------------
|
|
7446
|
+
// Credential 管理面 (vault)
|
|
7447
|
+
// ---------------------------------------------------------------------------
|
|
7448
|
+
/** 存凭证 (chat_bridge:write) — 明文一次性提交, 返回 masked 记录 (ref+fingerprint)。 */
|
|
7449
|
+
async storeCredential(integrationId, req, signal) {
|
|
7450
|
+
const resp = await this.client.doJSON(
|
|
7451
|
+
"POST",
|
|
7452
|
+
`/chat-bridge/integrations/${encodeURIComponent(integrationId)}/credentials`,
|
|
7453
|
+
{
|
|
7454
|
+
secret_kind: req.secretKind,
|
|
7455
|
+
plaintext: req.plaintext,
|
|
7456
|
+
region: req.region,
|
|
7457
|
+
platform: req.platform
|
|
7458
|
+
},
|
|
7459
|
+
signal
|
|
7460
|
+
);
|
|
7461
|
+
return brandCredential(resp.data);
|
|
7462
|
+
}
|
|
7463
|
+
/** 列出集成的凭证 (chat_bridge:read; masked, 永不含明文/密文)。 */
|
|
7464
|
+
async listCredentials(integrationId, signal) {
|
|
7465
|
+
const resp = await this.client.doJSON(
|
|
7466
|
+
"GET",
|
|
7467
|
+
`/chat-bridge/integrations/${encodeURIComponent(integrationId)}/credentials`,
|
|
7468
|
+
null,
|
|
7469
|
+
signal
|
|
7470
|
+
);
|
|
7471
|
+
return (resp.data?.items ?? []).map(brandCredential);
|
|
7472
|
+
}
|
|
7473
|
+
/** 轮换凭证 (chat_bridge:rotate, 高风险) — ref 不变, fingerprint 更新。 */
|
|
7474
|
+
async rotateCredential(integrationId, secretKind, newPlaintext, signal) {
|
|
7475
|
+
const resp = await this.client.doJSON(
|
|
7476
|
+
"POST",
|
|
7477
|
+
`/chat-bridge/integrations/${encodeURIComponent(integrationId)}/credentials/rotate`,
|
|
7478
|
+
{ secret_kind: secretKind, new_plaintext: newPlaintext },
|
|
7479
|
+
signal
|
|
7480
|
+
);
|
|
7481
|
+
return brandCredential(resp.data);
|
|
7482
|
+
}
|
|
7483
|
+
/** 吊销凭证 (chat_bridge:rotate) — 软吊销 + 服务端抹密文。 */
|
|
7484
|
+
async revokeCredential(credentialRef, signal) {
|
|
7485
|
+
await this.client.doJSON(
|
|
7486
|
+
"POST",
|
|
7487
|
+
`/chat-bridge/credentials/${encodeURIComponent(credentialRef)}/revoke`,
|
|
7488
|
+
{},
|
|
7489
|
+
signal
|
|
7490
|
+
);
|
|
7491
|
+
}
|
|
7492
|
+
};
|
|
7493
|
+
function brandCredential(c) {
|
|
7494
|
+
if (c && typeof c.credentialRef === "string") {
|
|
7495
|
+
return { ...c, credentialRef: asCredentialRef(c.credentialRef) };
|
|
7496
|
+
}
|
|
7497
|
+
return c;
|
|
7498
|
+
}
|
|
7499
|
+
|
|
7500
|
+
export { AGENT_RUN_META_TITLE, AGENT_RUN_META_WORKSPACE, ALL_INTEGRATION_STATUS, ALL_PLATFORMS, ALL_REGIONS, AgentRunStreamError, AgentRunsClient, AnthropicAdapter, AudienceEnum, BillingModeEnum, BucketClassCommercial, BucketClassGeneric, BusinessError, ChatBridgeClient, Client, ComplianceClient, CompliancePollError, CrabCodeByokClient, DEFAULT_API_TIMEOUT_MS, DEFAULT_GATEWAY_BASE_URL, LocalStorageTokenStore as DefaultBrowserTokenStore, DefaultRetryPolicy, 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, FileTokenStore, FilterStatusAdminBypass, FilterStatusDisabledByFlag, FilterStatusFallbackMissingUser, FilterStatusFallbackNoBuckets, FilterStatusFallbackTkdistError, FilterStatusFallbackTkdistSkew, FilterStatusInternalBypass, FilterStatusOK, FilterStatusUnknown, HTTPError, IdempotencyKeyHeader, InMemoryTokenStore, LocalStorageTokenStore, ModelNotFoundError, NetworkError, OAuthTokenEndpointError, OpenAIAdapter, OrderTerminalError, ProductFamilyEnum, ProviderFormat, RETRY_ADVICE_REASONS, RateLimitError, RegionScopeEnum, ScopeAI, ScopeAccount, ScopeChatBridge, ScopeChatBridgeRead, ScopeChatBridgeRotate, ScopeChatBridgeWrite, 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, ServerToolTypeWebSearch, StreamError, ThinkingHigh, ThinkingHighMinMaxTokens, ThinkingMax, ThinkingMaxFallbackMaxTokens, ThinkingOff, allScopes, anthropicResponseTextContent, anthropicResponseThinkingContent, anthropicResponseToolUseBlocks, apiResponseBusinessError, apiResponseGetMessage, asCredentialRef, authorize, bucketInfoIsCommercial, bucketRowIsCommercial, buildBetas, chatBridgeScopes, classifyComplianceError, commerceScopes, completeWebAuthorizationRequest, complianceErrorToRetryAdvice, complianceScopes, computeBackoff, createWebAuthorizationRequest, defaultRetryable, defaultSafeToRetry, discover, discoverWebOAuthMetadata, discoverWithProfile, effectivePolicy, exchangeCode, extractAnthropicBlockMeta, fileLockDefaults, findDesktopVisualUnderstandingModel, findFirstModelByInputModality, generateState, getAdapter, getAdapterForModel, isBillingConfirmable, isChannelInboundEvent, isComplianceBusinessError, isComplianceTerminalError, isIntegrationStatus, isInvalidGrantError, isPlatform, isRegion, isSSECommentLine, isSSLError, isTerminalRemoteEvent, isValidTokenSet, maxEndUserIdLength, modelScopes, modelSupportsImageInput, modelSupportsInputModality, newFileTokenStore, newThinkingConfig, newTokenSet, newWebSearchTool, normalizeGatewayBaseURL, normalizeOverrideBaseURL, parseNotificationEvent, parseRemoteControlEvent, parseSettlement, parseSourcesEvent, refreshToken, register, registerWebOAuthClient, remoteControlScopes, retryReasonForComplianceKey, retryReasonForOAuthError, revokeToken, sanitize_exports as sanitize, skillScopes, tokenSetIsExpired, uniqueMerge, validateEndUserId };
|
|
7196
7501
|
//# sourceMappingURL=index.mjs.map
|
|
7197
7502
|
//# sourceMappingURL=index.mjs.map
|