@yitom/acp-client 0.1.14 → 0.1.16

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/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const ACP_CLIENT_VERSION = "0.1.14";
1
+ export declare const ACP_CLIENT_VERSION = "0.1.16";
@@ -1,6 +1,6 @@
1
1
  # 新增 Agent 运行时适配器指南 (Adding an Agent)
2
2
 
3
- `@inkdown/acp` 采用插件化适配器(Adapter Pattern)架构。如果你想接入一个新的 Agent 运行时,**只需要在一个地方新增适配器文件并注册**,所有调用该 SDK 的项目(CLI、Electron、Tauri、Web 等)即可全局自动支持该 Agent!
3
+ `@yitom/acp-client` 采用插件化适配器(Adapter Pattern)架构。如果你想接入一个新的 Agent 运行时,**只需要在一个地方新增适配器文件并注册**,所有调用该 SDK 的项目(CLI、Electron、Tauri、Web 等)即可全局自动支持该 Agent!
4
4
 
5
5
  ---
6
6
 
@@ -1,6 +1,6 @@
1
1
  # 完整 API 参考文档 (API Reference)
2
2
 
3
- 本文档详细列出 `@inkdown/acp` 导出的所有核心类、方法与类型定义。
3
+ 本文档详细列出 `@yitom/acp-client` 导出的所有核心类、方法与类型定义。
4
4
 
5
5
  ---
6
6
 
@@ -20,10 +20,16 @@ const client = new AcpClient(options: AcpClientOptions)
20
20
  | :--- | :--- | :---: | :--- |
21
21
  | `workspaceRoot` | `string` | **是** | Agent 工作区根目录(绝对路径) |
22
22
  | `runtime` | `string \| AcpRuntimeInfo` | 否 | 运行时标识(如 `'codex-acp'`、`'cursor-cli'`、`'claude'`、`'deepseek'` 等),默认 `'codex-acp'` |
23
- | `clientInfo` | `{ name: string; version?: string }` | 否 | 客户端身份声明,默认 `{ name: 'inkdown', version: '0.1.0' }` |
23
+ | `clientInfo` | `{ name: string; version?: string }` | 否 | 客户端身份声明,默认 `{ name: 'acp-client', version: ACP_CLIENT_VERSION }` |
24
24
  | `dataDir` | `string` | 否 | 本地凭据与配置持久化目录,缺省自动使用操作系统标准应用数据目录 |
25
- | `proxy` | `Partial<AcpProxySettings>` | 否 | 代理配置 `{ enabled?: boolean; host?: string; port?: number }` |
25
+ | `proxy` | `Partial<AcpProxySettings>` | 否 | 代理配置 `{ enabled?: boolean; host?: string; port?: number }`(与持久化配置合并并作用于子进程环境) |
26
26
  | `env` | `NodeJS.ProcessEnv` | 否 | 注入给子进程的额外环境变量 |
27
+ | `requestTimeoutMs` | `number` | 否 | 控制面 RPC(`initialize` / `session/new` / `setConfigOption` 等)超时(毫秒,默认 `120_000`) |
28
+ | `promptIdleTimeoutMs` | `number` | 否 | `session/prompt` 原生静默超时(毫秒,收到事件/FS/终端活动自动重置,等待人工审批期间暂停;默认 `300_000`,`0` 禁用) |
29
+ | `promptMaxDurationMs` | `number` | 否 | `session/prompt` 硬性最大总时长上限(毫秒,默认 `0` 表示不限制总时长) |
30
+ | `quotaCacheTtlMs` | `number` | 否 | 配额缓存有效期(毫秒,默认 `30_000`) |
31
+ | `maxReadBytes` | `number` | 否 | `fs/read_text_file` 单次最大读取字节上限(默认 `2MB`) |
32
+ | `terminalOutputByteLimit` | `number` | 否 | 内置终端输出缓冲区上限(字节,默认 `1MB`) |
27
33
  | `resources` | `{ directory: string }` | 否 | 应用资源目录(单目录接口):含 `AGENTS.md` 与 `skills/<name>/SKILL.md`。提供即走原生资源准备(读取/合并/注入/报告),缺席保持旧行为 |
28
34
  | `callbacks` | `AcpClientCallbacks` | 否 | 事件与审批回调钩子(详见下文) |
29
35
 
@@ -60,6 +66,12 @@ ACP 没有“工具呈现方式”的标准字段。支持的 Agent 在 `initial
60
66
  - **能力优先**:`supportsCodeMode(agentCapabilities)` 只读声明;没有声明就没有 code mode,不按运行时 id 猜测。
61
67
  - **不支持就忽略**:未声明的运行时不会收到该 `_meta`,也不会看到“勾了却没生效”的开关;想新增支持,按 `docs/adding-an-agent.md` 的“声明 code mode”一节接入。
62
68
 
69
+ #### `authenticate(methodId: string): Promise<Result<void, AppError>>`
70
+
71
+ 对当前连接调用 ACP `authenticate`,`methodId` 来自 `connect().value.init.authMethods`。由宿主呈现登录选项并在用户选择后调用。若 `createSession` 或 `promptSession` 返回 `UNAUTHORIZED`,完成认证后重试原请求。Sidecar 对应 `client/authenticate`,参数为 `{ methodId }`。
72
+
73
+ Antigravity CLI 使用运行时 `antigravity-cli`。终端登录可执行 `agy acp --login`,随后重新连接以使用 CLI 保存的凭据。
74
+
63
75
  #### `disconnect(reason?: string): Promise<void>`
64
76
  断开当前连接,释放 Stdio 管道并安全杀死后台进程(清理进程树,避免孤儿进程)。
65
77
 
@@ -79,8 +91,8 @@ ACP 没有“工具呈现方式”的标准字段。支持的 Agent 在 `initial
79
91
 
80
92
  ### 方法
81
93
 
82
- #### `prompt(text: string, options?: { timeoutMs?: number }): Promise<Result<unknown, AppError>>`
83
- 向当前会话发送提示词或用户输入。
94
+ #### `prompt(text: string, options?: AcpPromptOptions): Promise<Result<unknown, AppError>>`
95
+ 向当前会话发送提示词或用户输入。默认启用基于活动的静默超时(`idleTimeoutMs` 默认 `300_000`,持续收到 `session/update`、FS 读写、终端输出会自动重置,等待用户审批期间暂停;仅超静默上限返回 `ACP_TIMEOUT`)。若显式传入旧参数 `timeoutMs`(且未传 `idleTimeoutMs`),仍按硬性总时长上限兼容执行。
84
96
 
85
97
  #### `setConfigOption(configId: string, value: string | boolean): Promise<Result<unknown, AppError>>`
86
98
  动态修改会话配置项(如切换底层模型 `model`、模式 `mode` 等)。
@@ -98,8 +110,9 @@ export interface AcpClientCallbacks {
98
110
  sessionId?: string
99
111
  toolCall?: { id?: string; title?: string; kind?: string }
100
112
  params: Record<string, unknown>
113
+ signal: AbortSignal
101
114
  }) => Promise<{ outcome: 'selected'; optionId: string } | { outcome: 'cancelled' }>
102
- // 允许放行统一用 pickAllowOptionId(params) 挑 Agent 给定的允许项(协议层无 'approved')
115
+ // 展示 params.options,返回用户选择的 optionId。signal 中止时关闭审批界面。
103
116
 
104
117
  /** 会话状态与内容流式更新 */
105
118
  onSessionUpdate?: (params: Record<string, unknown>) => void
@@ -125,7 +138,7 @@ export interface AcpClientCallbacks {
125
138
  - `getAcpRuntimeAdapter(runtimeId: string): AcpRuntimeAdapter`
126
139
  获取指定运行时的适配器对象。
127
140
  - `BUILTIN_ACP_RUNTIMES: readonly AcpRuntimeInfo[]`
128
- 获取当前内置支持的所有 8 大 Agent 运行时配置元数据列表。
141
+ 获取当前内置支持的所有 Agent 运行时配置元数据列表。
129
142
 
130
143
  ---
131
144
 
@@ -1,6 +1,6 @@
1
1
  # 快速入门指南 (Getting Started)
2
2
 
3
- 本指南介绍如何在不同的技术栈与应用宿主中快速集成 `@inkdown/acp`。
3
+ 本指南介绍如何在不同的技术栈与应用宿主中快速集成 `@yitom/acp-client`。
4
4
 
5
5
  ---
6
6
 
@@ -9,9 +9,9 @@
9
9
  在目标项目中安装本包:
10
10
 
11
11
  ```bash
12
- bun add @inkdown/acp
12
+ bun add @yitom/acp-client
13
13
  # 或
14
- npm install @inkdown/acp
14
+ npm install @yitom/acp-client
15
15
  ```
16
16
 
17
17
  > **环境要求**:Node.js 18+ 或 Bun 1.0+。
@@ -25,7 +25,7 @@ npm install @inkdown/acp
25
25
  ```typescript
26
26
  import readline from 'node:readline/promises'
27
27
  import { stdin, stdout } from 'node:process'
28
- import { AcpClient, pickAllowOptionId } from '@yitom/acp-client'
28
+ import { AcpClient } from '@yitom/acp-client'
29
29
 
30
30
  async function runCli() {
31
31
  const rl = readline.createInterface({ input: stdin, output: stdout })
@@ -41,15 +41,13 @@ async function runCli() {
41
41
  onStatusChange: (status, detail) => {
42
42
  console.log(`[连接状态] ${status} ${detail ? `(${detail})` : ''}`)
43
43
  },
44
- // 敏感权限交互式审批(协议层只有 selected/cancelled,用 pickAllowOptionId 挑允许项)
45
- onPermissionRequest: async ({ toolCall, params }) => {
46
- const answer = await rl.question(
47
- `\n[权限确认] Agent 请求执行工具 "${toolCall?.title || '未知'}",是否允许?(y/N): `
48
- )
49
- if (answer.trim().toLowerCase() !== 'y') return { outcome: 'cancelled' as const }
50
- const optionId = pickAllowOptionId(params as Record<string, unknown>)
51
- return optionId
52
- ? { outcome: 'selected' as const, optionId }
44
+ onPermissionRequest: async ({ toolCall, params, signal }) => {
45
+ const options = (params.options ?? []) as Array<{ name: string; optionId: string }>
46
+ const choices = options.map((option, index) => `${index + 1}. ${option.name}`).join('\n')
47
+ const answer = await rl.question(`\n${toolCall?.title ?? '工具审批'}\n${choices}\n选择序号,回车取消:`, { signal })
48
+ const selected = options[Number(answer.trim()) - 1]
49
+ return selected
50
+ ? { outcome: 'selected' as const, optionId: selected.optionId }
53
51
  : { outcome: 'cancelled' as const }
54
52
  },
55
53
  // 实时流式响应
@@ -76,7 +74,7 @@ async function runCli() {
76
74
  rl.close()
77
75
  return
78
76
  }
79
- const session = sessionRes.data
77
+ const session = sessionRes.value
80
78
 
81
79
  // 3. 循环问答
82
80
  while (true) {
@@ -101,7 +99,7 @@ runCli().catch(console.error)
101
99
 
102
100
  ```typescript
103
101
  import { WebSocketServer } from 'ws'
104
- import { AcpClient } from '@inkdown/acp'
102
+ import { AcpClient } from '@yitom/acp-client'
105
103
 
106
104
  const wss = new WebSocketServer({ port: 8080 })
107
105
 
@@ -122,7 +120,7 @@ wss.on('connection', async (ws) => {
122
120
  })
123
121
 
124
122
  await client.connect()
125
- const session = (await client.createSession()).data
123
+ const session = (await client.createSession()).value
126
124
 
127
125
  ws.on('message', async (message) => {
128
126
  const { prompt } = JSON.parse(message.toString())
@@ -143,7 +141,7 @@ wss.on('connection', async (ws) => {
143
141
 
144
142
  ```typescript
145
143
  import { BrowserWindow } from 'electron'
146
- import { AcpClient } from '@inkdown/acp'
144
+ import { AcpClient } from '@yitom/acp-client'
147
145
 
148
146
  export function setupAcpClient(mainWindow: BrowserWindow, workspaceRoot: string) {
149
147
  const client = new AcpClient({
@@ -1,6 +1,6 @@
1
1
  # Tauri 集成与 Sidecar 模式实战指南
2
2
 
3
- 本指南面向希望在 **Tauri** 桌面应用中复用 `@inkdown/acp` 的开发者。
3
+ 本指南面向希望在 **Tauri** 桌面应用中复用 `@yitom/acp-client` 的开发者。
4
4
 
5
5
  ---
6
6
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  Tauri 的前端 WebView 运行在受限的浏览器沙盒中,无法直接调用 `node:child_process` 拉起后台 Agent 子进程。
10
10
 
11
- 要在 Tauri 中复用本 SDK,**无需将整套协议和 8 大 Agent 适配器用 Rust 重写一遍**。Tauri 官方提供了非常成熟的 **Sidecar(伴生进程)** 机制:
11
+ 要在 Tauri 中复用本 SDK,**无需将整套协议和内置 Agent 适配器用 Rust 重写一遍**。Tauri 官方提供了非常成熟的 **Sidecar(伴生进程)** 机制:
12
12
 
13
13
  ```
14
14
  ┌────────────────────────────────────────────────────────┐
@@ -22,7 +22,7 @@ Tauri 的前端 WebView 运行在受限的浏览器沙盒中,无法直接调
22
22
  │ ▼ ▼ │
23
23
  │ ┌──────────────────────────────────────────────────┐ │
24
24
  │ │ ACP Sidecar 引擎 (纯独立二进制可执行文件) │ │
25
- │ │ 由 @inkdown/acp 编译而成,负责所有 Agent 交互 │ │
25
+ │ │ 由 @yitom/acp-client 编译而成,负责所有 Agent 交互 │ │
26
26
  │ └──────────────────────────────────────────────────┘ │
27
27
  └────────────────────────────────────────────────────────┘
28
28
  ```
@@ -101,7 +101,7 @@ fn start_acp_sidecar(app_handle: tauri::AppHandle) {
101
101
 
102
102
  | 考量因素 | Sidecar 模式(推荐) | 纯 Rust 重写模式 |
103
103
  | :--- | :--- | :--- |
104
- | **代码复用率** | **100% 共用**:Electron、CLI、Tauri 维护同一份 Agent 适配逻辑 | 0%:需用 Rust 把 8 大 Agent 适配器完全重写一遍 |
104
+ | **代码复用率** | **100% 共用**:Electron、CLI、Tauri 维护同一份 Agent 适配逻辑 | 0%:需用 Rust 把内置 Agent 适配器完全重写一遍 |
105
105
  | **生态跟进** | **极快**:依赖官方 `@agentclientprotocol/sdk`,上游一更新立即生效 | **滞后**:Rust 生态目前缺少官方实时维护的 ACP 客户端库 |
106
106
  | **内存与启动** | 启动毫秒级,常驻内存约 30~50MB | 启动纳秒级,常驻内存约 5~15MB |
107
107
  | **适用建议** | **适合 95% 的应用**,用极低维护成本换取跨平台、跨项目通用性 | 仅适合极致追求超小包体积与极低内存的单体纯 Rust 项目 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yitom/acp-client",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "description": "Headless ACP (Agent Client Protocol) SDK for connecting to Codex, Claude, Cursor, DeepSeek and more",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -38,10 +38,10 @@
38
38
  "test:mcp": "vitest run src/client/mcp-session-recovery.test.ts src/client/acp-client-mcp.test.ts"
39
39
  },
40
40
  "dependencies": {
41
- "@agentclientprotocol/sdk": "^1.0.0"
41
+ "@agentclientprotocol/sdk": "^2.9.1"
42
42
  },
43
43
  "devDependencies": {
44
- "@types/node": "^26.6.3",
44
+ "@types/node": "^26.6.6",
45
45
  "typescript": "^7.0.2",
46
46
  "vitest": "^4.1.11"
47
47
  },