@yitom/acp-client 0.1.14 → 0.1.15

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.15";
@@ -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
 
@@ -60,6 +60,12 @@ ACP 没有“工具呈现方式”的标准字段。支持的 Agent 在 `initial
60
60
  - **能力优先**:`supportsCodeMode(agentCapabilities)` 只读声明;没有声明就没有 code mode,不按运行时 id 猜测。
61
61
  - **不支持就忽略**:未声明的运行时不会收到该 `_meta`,也不会看到“勾了却没生效”的开关;想新增支持,按 `docs/adding-an-agent.md` 的“声明 code mode”一节接入。
62
62
 
63
+ #### `authenticate(methodId: string): Promise<Result<void, AppError>>`
64
+
65
+ 对当前连接调用 ACP `authenticate`,`methodId` 来自 `connect().value.init.authMethods`。由宿主呈现登录选项并在用户选择后调用。若 `createSession` 或 `promptSession` 返回 `UNAUTHORIZED`,完成认证后重试原请求。Sidecar 对应 `client/authenticate`,参数为 `{ methodId }`。
66
+
67
+ Antigravity CLI 使用运行时 `antigravity-cli`。终端登录可执行 `agy acp --login`,随后重新连接以使用 CLI 保存的凭据。
68
+
63
69
  #### `disconnect(reason?: string): Promise<void>`
64
70
  断开当前连接,释放 Stdio 管道并安全杀死后台进程(清理进程树,避免孤儿进程)。
65
71
 
@@ -98,8 +104,9 @@ export interface AcpClientCallbacks {
98
104
  sessionId?: string
99
105
  toolCall?: { id?: string; title?: string; kind?: string }
100
106
  params: Record<string, unknown>
107
+ signal: AbortSignal
101
108
  }) => Promise<{ outcome: 'selected'; optionId: string } | { outcome: 'cancelled' }>
102
- // 允许放行统一用 pickAllowOptionId(params) 挑 Agent 给定的允许项(协议层无 'approved')
109
+ // 展示 params.options,返回用户选择的 optionId。signal 中止时关闭审批界面。
103
110
 
104
111
  /** 会话状态与内容流式更新 */
105
112
  onSessionUpdate?: (params: Record<string, unknown>) => void
@@ -125,7 +132,7 @@ export interface AcpClientCallbacks {
125
132
  - `getAcpRuntimeAdapter(runtimeId: string): AcpRuntimeAdapter`
126
133
  获取指定运行时的适配器对象。
127
134
  - `BUILTIN_ACP_RUNTIMES: readonly AcpRuntimeInfo[]`
128
- 获取当前内置支持的所有 8 大 Agent 运行时配置元数据列表。
135
+ 获取当前内置支持的所有 Agent 运行时配置元数据列表。
129
136
 
130
137
  ---
131
138
 
@@ -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.15",
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
  },