@yitom/acp-client 0.1.0 → 0.1.3

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/README.md CHANGED
@@ -64,9 +64,13 @@ const client = new AcpClient({
64
64
  onStatusChange: (status, detail) => {
65
65
  console.log(`[Status] -> ${status}`, detail ?? '')
66
66
  },
67
- onPermissionRequest: async ({ toolCall }) => {
67
+ onPermissionRequest: async ({ toolCall, params }) => {
68
68
  console.log(`Agent 请求调用工具:`, toolCall)
69
- return { outcome: 'approved' } // 交互式批准或自动放行
69
+ // 交互式批准(y)或自动放行:协议层只有 selected/cancelled,
70
+ // 允许项用 pickAllowOptionId 从 Agent 给的 options 里挑(无 'approved')。
71
+ return pickAllowOptionId(params)
72
+ ? { outcome: 'selected' as const, optionId: pickAllowOptionId(params)! }
73
+ : { outcome: 'cancelled' as const }
70
74
  },
71
75
  onSessionUpdate: (event) => {
72
76
  console.log(`[Stream Event]:`, event)
@@ -95,6 +99,20 @@ await client.disconnect()
95
99
 
96
100
  ---
97
101
 
102
+ ## ⌨️ 斜杠命令(available_commands_update)
103
+
104
+ Agent 推送的 `available_commands_update` 会原样经 `onSessionUpdate` 透传,同时按会话缓存最新列表(含 `name` / `description` / `input.hint`),
105
+ 即使宿主还没拿到 sessionId 也不会丢:
106
+
107
+ ```ts
108
+ const handle = (await client.createSession()).value
109
+ const cmds = handle.availableCommands ?? (await client.waitForAvailableCommands(handle.sessionId, 500))
110
+ // 调用命令 = 普通文本 prompt(ACP 规范)
111
+ await handle.prompt(formatCommandPrompt('review', 'main')) // "/review main"
112
+ ```
113
+
114
+ Sidecar:`session/open` 结果带 `availableCommands`(若已收到),并新增 `session/commands` 查询方法。
115
+
98
116
  ## 📦 打包构建
99
117
 
100
118
  在本包根目录一键构建生成 `dist`(ESM / CJS / `.d.ts`):
@@ -1,3 +1,4 @@
1
+ import { type AcpAvailableCommand } from '../session/available-commands';
1
2
  import { type InitializeResponse } from '@agentclientprotocol/sdk';
2
3
  import type { AcpConnectionStatus, AcpPermissionOutcome, AcpProxySettings, AcpRuntimeInfo, AcpSessionRestoreMethod, AppError, InkdownVirtualResource } from "../contracts";
3
4
  import { type Result } from "../contracts";
@@ -51,7 +52,13 @@ export declare class AcpSessionHandle {
51
52
  /** 向当前会话发送 Prompt / 消息交互 */
52
53
  prompt(promptText: string, options?: {
53
54
  timeoutMs?: number;
55
+ images?: Array<{
56
+ mimeType: string;
57
+ data: string;
58
+ }>;
54
59
  }): Promise<Result<unknown, AppError>>;
60
+ /** Agent 通过 available_commands_update 提供的斜杠命令(调用 = prompt 发送 `/name args` 文本) */
61
+ get availableCommands(): AcpAvailableCommand[] | undefined;
55
62
  /** 修改会话配置项(如模型 ID、模式等) */
56
63
  setConfigOption(configId: string, value: string | boolean): Promise<Result<unknown, AppError>>;
57
64
  }
@@ -64,11 +71,13 @@ export declare class AcpSessionHandle {
64
71
  */
65
72
  export declare class AcpClient {
66
73
  private status;
74
+ private readonly commandsCache;
67
75
  private runtimeInfo;
68
76
  private adapter;
69
77
  private readonly workspaceRoot;
70
78
  private readonly clientInfo;
71
79
  private readonly dataDir;
80
+ private readonly extraEnv;
72
81
  private readonly callbacks;
73
82
  private readonly terminals;
74
83
  private processHandle;
@@ -81,6 +90,7 @@ export declare class AcpClient {
81
90
  get isConnected(): boolean;
82
91
  /** 获取底层当前 Agent 的 RPC 客户端句柄 */
83
92
  get agent(): import("@agentclientprotocol/sdk").ClientContext | null;
93
+ get initializeResponse(): InitializeResponse | null;
84
94
  /**
85
95
  * 启动并连接 Agent:
86
96
  * 1. 预检判停(如缺少 API Key、未安装 CLI);
@@ -93,6 +103,10 @@ export declare class AcpClient {
93
103
  status: AcpConnectionStatus;
94
104
  init: InitializeResponse;
95
105
  }, AppError>>;
106
+ /** 最近一次 available_commands_update 的命令列表(未收到过则为 undefined) */
107
+ getAvailableCommands(sessionId: string): AcpAvailableCommand[] | undefined;
108
+ /** 等待某会话的命令列表(已缓存则立即返回;超时返回 undefined) */
109
+ waitForAvailableCommands(sessionId: string, timeoutMs?: number): Promise<AcpAvailableCommand[] | undefined>;
96
110
  /** 创建或恢复会话 */
97
111
  createSession(options?: {
98
112
  resumeSessionId?: string | null;
@@ -101,6 +115,10 @@ export declare class AcpClient {
101
115
  /** 向指定会话发送消息 */
102
116
  promptSession(sessionId: string, promptText: string, options?: {
103
117
  timeoutMs?: number;
118
+ images?: Array<{
119
+ mimeType: string;
120
+ data: string;
121
+ }>;
104
122
  }): Promise<Result<unknown, AppError>>;
105
123
  /** 动态更新会话配置项(如模型 ID) */
106
124
  setSessionConfigOption(sessionId: string, configId: string, value: string | boolean): Promise<Result<unknown, AppError>>;
package/dist/index.cjs CHANGED
@@ -46,6 +46,7 @@ __export(exports_src, {
46
46
  AcpClient: () => AcpClient,
47
47
  AcpSessionHandle: () => AcpSessionHandle,
48
48
  AcpTerminalManager: () => AcpTerminalManager,
49
+ AvailableCommandsCache: () => AvailableCommandsCache,
49
50
  BUILTIN_ACP_RUNTIMES: () => BUILTIN_ACP_RUNTIMES,
50
51
  CLAUDE_ACP_NPM_PACKAGE: () => CLAUDE_ACP_NPM_PACKAGE,
51
52
  CODEX_ACP_NPM_PACKAGE: () => CODEX_ACP_NPM_PACKAGE,
@@ -85,8 +86,10 @@ __export(exports_src, {
85
86
  disposeAllAcpProcesses: () => disposeAllAcpProcesses,
86
87
  emptyAcpAuthPreflight: () => emptyAcpAuthPreflight,
87
88
  err: () => err,
89
+ extractAvailableCommands: () => extractAvailableCommands,
88
90
  findBuiltinAcpRuntime: () => findBuiltinAcpRuntime,
89
91
  findModelConfigOption: () => findModelConfigOption,
92
+ formatCommandPrompt: () => formatCommandPrompt,
90
93
  geminiAdapter: () => geminiAdapter,
91
94
  getAcpEarlyExitStderrDetail: () => getAcpEarlyExitStderrDetail,
92
95
  getAcpProviderCodexHome: () => getAcpProviderCodexHome,
@@ -313,6 +316,94 @@ var BUILTIN_ACP_RUNTIMES = [
313
316
  function findBuiltinAcpRuntime(id) {
314
317
  return BUILTIN_ACP_RUNTIMES.find((item) => item.id === id);
315
318
  }
319
+ // src/session/available-commands.ts
320
+ function normalizeCommand(raw) {
321
+ if (!raw || typeof raw !== "object")
322
+ return null;
323
+ const r = raw;
324
+ if (typeof r.name !== "string" || !r.name.trim())
325
+ return null;
326
+ const out = {
327
+ name: r.name.trim(),
328
+ description: typeof r.description === "string" ? r.description : ""
329
+ };
330
+ const input = r.input;
331
+ if (input && typeof input === "object" && typeof input.hint === "string") {
332
+ out.input = { hint: input.hint };
333
+ }
334
+ if (r._meta && typeof r._meta === "object")
335
+ out._meta = r._meta;
336
+ return out;
337
+ }
338
+ function extractAvailableCommands(params) {
339
+ if (!params || typeof params !== "object")
340
+ return null;
341
+ const p = params;
342
+ if (typeof p.sessionId !== "string" || !p.update)
343
+ return null;
344
+ if (p.update.sessionUpdate !== "available_commands_update")
345
+ return null;
346
+ const list = Array.isArray(p.update.availableCommands) ? p.update.availableCommands : [];
347
+ const commands = list.map(normalizeCommand).filter((c) => c !== null);
348
+ return { sessionId: p.sessionId, commands };
349
+ }
350
+ function formatCommandPrompt(name, args) {
351
+ const n = name.replace(/^\//, "");
352
+ const a = (args ?? "").trim();
353
+ return a ? `/${n} ${a}` : `/${n}`;
354
+ }
355
+
356
+ class AvailableCommandsCache {
357
+ bySession = new Map;
358
+ waiters = new Map;
359
+ observe(params) {
360
+ const hit = extractAvailableCommands(params);
361
+ if (!hit)
362
+ return false;
363
+ this.bySession.set(hit.sessionId, hit.commands);
364
+ const ws = this.waiters.get(hit.sessionId);
365
+ if (ws) {
366
+ this.waiters.delete(hit.sessionId);
367
+ for (const w of ws)
368
+ w(hit.commands);
369
+ }
370
+ return true;
371
+ }
372
+ get(sessionId) {
373
+ return this.bySession.get(sessionId);
374
+ }
375
+ wait(sessionId, timeoutMs = 150) {
376
+ const cur = this.bySession.get(sessionId);
377
+ if (cur || timeoutMs <= 0)
378
+ return Promise.resolve(cur);
379
+ return new Promise((resolve) => {
380
+ const done = (c) => {
381
+ clearTimeout(timer);
382
+ const list = this.waiters.get(sessionId);
383
+ if (list) {
384
+ const i = list.indexOf(fn);
385
+ if (i >= 0)
386
+ list.splice(i, 1);
387
+ if (list.length === 0)
388
+ this.waiters.delete(sessionId);
389
+ }
390
+ resolve(c);
391
+ };
392
+ const fn = (c) => done(c);
393
+ const timer = setTimeout(() => done(undefined), timeoutMs);
394
+ const list = this.waiters.get(sessionId) ?? [];
395
+ list.push(fn);
396
+ this.waiters.set(sessionId, list);
397
+ });
398
+ }
399
+ delete(sessionId) {
400
+ this.bySession.delete(sessionId);
401
+ }
402
+ clear() {
403
+ this.bySession.clear();
404
+ }
405
+ }
406
+
316
407
  // src/client/acp-client.ts
317
408
  var import_sdk4 = require("@agentclientprotocol/sdk");
318
409
 
@@ -2144,6 +2235,9 @@ class AcpSessionHandle {
2144
2235
  async prompt(promptText, options) {
2145
2236
  return this.client.promptSession(this.sessionId, promptText, options);
2146
2237
  }
2238
+ get availableCommands() {
2239
+ return this.client.getAvailableCommands(this.sessionId);
2240
+ }
2147
2241
  async setConfigOption(configId, value) {
2148
2242
  return this.client.setSessionConfigOption(this.sessionId, configId, value);
2149
2243
  }
@@ -2151,11 +2245,13 @@ class AcpSessionHandle {
2151
2245
 
2152
2246
  class AcpClient {
2153
2247
  status = "disconnected";
2248
+ commandsCache = new AvailableCommandsCache;
2154
2249
  runtimeInfo;
2155
2250
  adapter;
2156
2251
  workspaceRoot;
2157
2252
  clientInfo;
2158
2253
  dataDir;
2254
+ extraEnv;
2159
2255
  callbacks;
2160
2256
  terminals = new AcpTerminalManager;
2161
2257
  processHandle = null;
@@ -2167,9 +2263,10 @@ class AcpClient {
2167
2263
  this.workspaceRoot = options.workspaceRoot;
2168
2264
  this.clientInfo = {
2169
2265
  name: options.clientInfo?.name ?? "inkdown",
2170
- version: options.clientInfo?.version ?? "0.1.0"
2266
+ version: options.clientInfo?.version ?? "0.1.1"
2171
2267
  };
2172
2268
  this.dataDir = options.dataDir ?? getDefaultAgentDataDir();
2269
+ this.extraEnv = options.env ?? {};
2173
2270
  this.callbacks = options.callbacks ?? {};
2174
2271
  const runtimeId = typeof options.runtime === "string" ? options.runtime : options.runtime?.id ?? DEFAULT_ACP_RUNTIME_ID;
2175
2272
  this.adapter = getAcpRuntimeAdapter(runtimeId);
@@ -2192,6 +2289,9 @@ class AcpClient {
2192
2289
  get agent() {
2193
2290
  return this.sdkConnection?.agent ?? null;
2194
2291
  }
2292
+ get initializeResponse() {
2293
+ return this.initResponse;
2294
+ }
2195
2295
  async connect() {
2196
2296
  try {
2197
2297
  this.setStatus("connecting");
@@ -2213,7 +2313,11 @@ class AcpClient {
2213
2313
  }
2214
2314
  const storedProxy = await readAcpProxySettings(this.dataDir);
2215
2315
  const proxyEnv = buildAcpProxySpawnEnv(storedProxy);
2216
- const spawnEnv = this.adapter.getSpawnEnv?.(storedProxy) ?? proxyEnv;
2316
+ const baseEnv = this.adapter.getSpawnEnv?.(storedProxy) ?? proxyEnv;
2317
+ const spawnEnv = {
2318
+ ...baseEnv,
2319
+ env: { ...baseEnv.env ?? {}, ...this.extraEnv ?? {} }
2320
+ };
2217
2321
  await this.adapter.beforeSpawn?.();
2218
2322
  const processHandle = spawnAcpProcess({
2219
2323
  runtime: effectiveRuntime,
@@ -2251,6 +2355,7 @@ class AcpClient {
2251
2355
  return { outcome: "cancelled" };
2252
2356
  },
2253
2357
  onSessionUpdate: (params) => {
2358
+ this.commandsCache.observe(params);
2254
2359
  this.callbacks.onSessionUpdate?.(params);
2255
2360
  }
2256
2361
  };
@@ -2281,6 +2386,12 @@ class AcpClient {
2281
2386
  return err({ code: "ACP_PROTOCOL_ERROR", message });
2282
2387
  }
2283
2388
  }
2389
+ getAvailableCommands(sessionId) {
2390
+ return this.commandsCache.get(sessionId);
2391
+ }
2392
+ waitForAvailableCommands(sessionId, timeoutMs = 150) {
2393
+ return this.commandsCache.wait(sessionId, timeoutMs);
2394
+ }
2284
2395
  async createSession(options) {
2285
2396
  if (!this.sdkConnection?.agent) {
2286
2397
  return err({ code: "ACP_NOT_CONNECTED", message: "尚未连接到 Agent 服务端" });
@@ -2315,9 +2426,15 @@ class AcpClient {
2315
2426
  return err({ code: "ACP_NOT_CONNECTED", message: "尚未连接到 Agent 服务端" });
2316
2427
  }
2317
2428
  try {
2429
+ const prompt = [{ type: "text", text: promptText }];
2430
+ for (const image of options?.images ?? []) {
2431
+ if (!image?.data || !image?.mimeType)
2432
+ continue;
2433
+ prompt.push({ type: "image", mimeType: image.mimeType, data: image.data });
2434
+ }
2318
2435
  const response = await sdkRequest(this.sdkConnection.agent, import_sdk4.methods.agent.session.prompt, {
2319
2436
  sessionId,
2320
- prompt: [{ type: "text", text: promptText }]
2437
+ prompt
2321
2438
  }, options?.timeoutMs);
2322
2439
  return ok(response);
2323
2440
  } catch (e) {
package/dist/index.d.ts CHANGED
@@ -28,6 +28,7 @@ export * from "./auth/connect-auth-gate";
28
28
  export * from "./session/agent-registry";
29
29
  export * from "./session/config-options";
30
30
  export * from "./session/session-capabilities";
31
+ export * from "./session/available-commands";
31
32
  export * from "./mcp/inkdown-mcp-tools";
32
33
  export * from "./mcp/inkdown-mcp-toc-tools";
33
34
  export * from "./mcp/inkdown-mcp-rpc";
package/dist/index.js CHANGED
@@ -148,6 +148,94 @@ var BUILTIN_ACP_RUNTIMES = [
148
148
  function findBuiltinAcpRuntime(id) {
149
149
  return BUILTIN_ACP_RUNTIMES.find((item) => item.id === id);
150
150
  }
151
+ // src/session/available-commands.ts
152
+ function normalizeCommand(raw) {
153
+ if (!raw || typeof raw !== "object")
154
+ return null;
155
+ const r = raw;
156
+ if (typeof r.name !== "string" || !r.name.trim())
157
+ return null;
158
+ const out = {
159
+ name: r.name.trim(),
160
+ description: typeof r.description === "string" ? r.description : ""
161
+ };
162
+ const input = r.input;
163
+ if (input && typeof input === "object" && typeof input.hint === "string") {
164
+ out.input = { hint: input.hint };
165
+ }
166
+ if (r._meta && typeof r._meta === "object")
167
+ out._meta = r._meta;
168
+ return out;
169
+ }
170
+ function extractAvailableCommands(params) {
171
+ if (!params || typeof params !== "object")
172
+ return null;
173
+ const p = params;
174
+ if (typeof p.sessionId !== "string" || !p.update)
175
+ return null;
176
+ if (p.update.sessionUpdate !== "available_commands_update")
177
+ return null;
178
+ const list = Array.isArray(p.update.availableCommands) ? p.update.availableCommands : [];
179
+ const commands = list.map(normalizeCommand).filter((c) => c !== null);
180
+ return { sessionId: p.sessionId, commands };
181
+ }
182
+ function formatCommandPrompt(name, args) {
183
+ const n = name.replace(/^\//, "");
184
+ const a = (args ?? "").trim();
185
+ return a ? `/${n} ${a}` : `/${n}`;
186
+ }
187
+
188
+ class AvailableCommandsCache {
189
+ bySession = new Map;
190
+ waiters = new Map;
191
+ observe(params) {
192
+ const hit = extractAvailableCommands(params);
193
+ if (!hit)
194
+ return false;
195
+ this.bySession.set(hit.sessionId, hit.commands);
196
+ const ws = this.waiters.get(hit.sessionId);
197
+ if (ws) {
198
+ this.waiters.delete(hit.sessionId);
199
+ for (const w of ws)
200
+ w(hit.commands);
201
+ }
202
+ return true;
203
+ }
204
+ get(sessionId) {
205
+ return this.bySession.get(sessionId);
206
+ }
207
+ wait(sessionId, timeoutMs = 150) {
208
+ const cur = this.bySession.get(sessionId);
209
+ if (cur || timeoutMs <= 0)
210
+ return Promise.resolve(cur);
211
+ return new Promise((resolve) => {
212
+ const done = (c) => {
213
+ clearTimeout(timer);
214
+ const list = this.waiters.get(sessionId);
215
+ if (list) {
216
+ const i = list.indexOf(fn);
217
+ if (i >= 0)
218
+ list.splice(i, 1);
219
+ if (list.length === 0)
220
+ this.waiters.delete(sessionId);
221
+ }
222
+ resolve(c);
223
+ };
224
+ const fn = (c) => done(c);
225
+ const timer = setTimeout(() => done(undefined), timeoutMs);
226
+ const list = this.waiters.get(sessionId) ?? [];
227
+ list.push(fn);
228
+ this.waiters.set(sessionId, list);
229
+ });
230
+ }
231
+ delete(sessionId) {
232
+ this.bySession.delete(sessionId);
233
+ }
234
+ clear() {
235
+ this.bySession.clear();
236
+ }
237
+ }
238
+
151
239
  // src/client/acp-client.ts
152
240
  import {
153
241
  methods as methods2
@@ -1984,6 +2072,9 @@ class AcpSessionHandle {
1984
2072
  async prompt(promptText, options) {
1985
2073
  return this.client.promptSession(this.sessionId, promptText, options);
1986
2074
  }
2075
+ get availableCommands() {
2076
+ return this.client.getAvailableCommands(this.sessionId);
2077
+ }
1987
2078
  async setConfigOption(configId, value) {
1988
2079
  return this.client.setSessionConfigOption(this.sessionId, configId, value);
1989
2080
  }
@@ -1991,11 +2082,13 @@ class AcpSessionHandle {
1991
2082
 
1992
2083
  class AcpClient {
1993
2084
  status = "disconnected";
2085
+ commandsCache = new AvailableCommandsCache;
1994
2086
  runtimeInfo;
1995
2087
  adapter;
1996
2088
  workspaceRoot;
1997
2089
  clientInfo;
1998
2090
  dataDir;
2091
+ extraEnv;
1999
2092
  callbacks;
2000
2093
  terminals = new AcpTerminalManager;
2001
2094
  processHandle = null;
@@ -2007,9 +2100,10 @@ class AcpClient {
2007
2100
  this.workspaceRoot = options.workspaceRoot;
2008
2101
  this.clientInfo = {
2009
2102
  name: options.clientInfo?.name ?? "inkdown",
2010
- version: options.clientInfo?.version ?? "0.1.0"
2103
+ version: options.clientInfo?.version ?? "0.1.1"
2011
2104
  };
2012
2105
  this.dataDir = options.dataDir ?? getDefaultAgentDataDir();
2106
+ this.extraEnv = options.env ?? {};
2013
2107
  this.callbacks = options.callbacks ?? {};
2014
2108
  const runtimeId = typeof options.runtime === "string" ? options.runtime : options.runtime?.id ?? DEFAULT_ACP_RUNTIME_ID;
2015
2109
  this.adapter = getAcpRuntimeAdapter(runtimeId);
@@ -2032,6 +2126,9 @@ class AcpClient {
2032
2126
  get agent() {
2033
2127
  return this.sdkConnection?.agent ?? null;
2034
2128
  }
2129
+ get initializeResponse() {
2130
+ return this.initResponse;
2131
+ }
2035
2132
  async connect() {
2036
2133
  try {
2037
2134
  this.setStatus("connecting");
@@ -2053,7 +2150,11 @@ class AcpClient {
2053
2150
  }
2054
2151
  const storedProxy = await readAcpProxySettings(this.dataDir);
2055
2152
  const proxyEnv = buildAcpProxySpawnEnv(storedProxy);
2056
- const spawnEnv = this.adapter.getSpawnEnv?.(storedProxy) ?? proxyEnv;
2153
+ const baseEnv = this.adapter.getSpawnEnv?.(storedProxy) ?? proxyEnv;
2154
+ const spawnEnv = {
2155
+ ...baseEnv,
2156
+ env: { ...baseEnv.env ?? {}, ...this.extraEnv ?? {} }
2157
+ };
2057
2158
  await this.adapter.beforeSpawn?.();
2058
2159
  const processHandle = spawnAcpProcess({
2059
2160
  runtime: effectiveRuntime,
@@ -2091,6 +2192,7 @@ class AcpClient {
2091
2192
  return { outcome: "cancelled" };
2092
2193
  },
2093
2194
  onSessionUpdate: (params) => {
2195
+ this.commandsCache.observe(params);
2094
2196
  this.callbacks.onSessionUpdate?.(params);
2095
2197
  }
2096
2198
  };
@@ -2121,6 +2223,12 @@ class AcpClient {
2121
2223
  return err({ code: "ACP_PROTOCOL_ERROR", message });
2122
2224
  }
2123
2225
  }
2226
+ getAvailableCommands(sessionId) {
2227
+ return this.commandsCache.get(sessionId);
2228
+ }
2229
+ waitForAvailableCommands(sessionId, timeoutMs = 150) {
2230
+ return this.commandsCache.wait(sessionId, timeoutMs);
2231
+ }
2124
2232
  async createSession(options) {
2125
2233
  if (!this.sdkConnection?.agent) {
2126
2234
  return err({ code: "ACP_NOT_CONNECTED", message: "尚未连接到 Agent 服务端" });
@@ -2155,9 +2263,15 @@ class AcpClient {
2155
2263
  return err({ code: "ACP_NOT_CONNECTED", message: "尚未连接到 Agent 服务端" });
2156
2264
  }
2157
2265
  try {
2266
+ const prompt = [{ type: "text", text: promptText }];
2267
+ for (const image of options?.images ?? []) {
2268
+ if (!image?.data || !image?.mimeType)
2269
+ continue;
2270
+ prompt.push({ type: "image", mimeType: image.mimeType, data: image.data });
2271
+ }
2158
2272
  const response = await sdkRequest(this.sdkConnection.agent, methods2.agent.session.prompt, {
2159
2273
  sessionId,
2160
- prompt: [{ type: "text", text: promptText }]
2274
+ prompt
2161
2275
  }, options?.timeoutMs);
2162
2276
  return ok(response);
2163
2277
  } catch (e) {
@@ -3125,6 +3239,7 @@ export {
3125
3239
  AcpClient,
3126
3240
  AcpSessionHandle,
3127
3241
  AcpTerminalManager,
3242
+ AvailableCommandsCache,
3128
3243
  BUILTIN_ACP_RUNTIMES,
3129
3244
  CLAUDE_ACP_NPM_PACKAGE,
3130
3245
  CODEX_ACP_NPM_PACKAGE,
@@ -3164,8 +3279,10 @@ export {
3164
3279
  disposeAllAcpProcesses,
3165
3280
  emptyAcpAuthPreflight,
3166
3281
  err,
3282
+ extractAvailableCommands,
3167
3283
  findBuiltinAcpRuntime,
3168
3284
  findModelConfigOption,
3285
+ formatCommandPrompt,
3169
3286
  geminiAdapter,
3170
3287
  getAcpEarlyExitStderrDetail,
3171
3288
  getAcpProviderCodexHome,
@@ -0,0 +1,43 @@
1
+ /**
2
+ * ACP `available_commands_update` handling.
3
+ *
4
+ * Agents typically push their slash commands right after session/new|load|resume
5
+ * returns — i.e. before a host has learned the sessionId or wired a listener.
6
+ * Raw notifications are still forwarded untouched via `onSessionUpdate`; this
7
+ * cache additionally keeps the latest list per session so hosts can read it
8
+ * at any time (`AcpClient.getAvailableCommands`, `AcpSessionHandle.availableCommands`,
9
+ * sidecar `session/open` result + `session/commands`).
10
+ *
11
+ * Invoking a command is plain prompt text (`/name args`) per the ACP spec.
12
+ */
13
+ export interface AcpAvailableCommandInput {
14
+ /** Placeholder shown while the user types the argument. */
15
+ hint: string;
16
+ }
17
+ export interface AcpAvailableCommand {
18
+ name: string;
19
+ description: string;
20
+ input?: AcpAvailableCommandInput | null;
21
+ _meta?: Record<string, unknown>;
22
+ }
23
+ /**
24
+ * Extract `{ sessionId, commands }` from a session/update params object
25
+ * (`{ sessionId, update: { sessionUpdate: 'available_commands_update', availableCommands } }`).
26
+ */
27
+ export declare function extractAvailableCommands(params: unknown): {
28
+ sessionId: string;
29
+ commands: AcpAvailableCommand[];
30
+ } | null;
31
+ /** Build the prompt text for a command invocation (ACP: plain text `/name args`). */
32
+ export declare function formatCommandPrompt(name: string, args?: string): string;
33
+ export declare class AvailableCommandsCache {
34
+ private bySession;
35
+ private waiters;
36
+ /** Feed every session/update params object; returns true if it was a commands update. */
37
+ observe(params: unknown): boolean;
38
+ get(sessionId: string): AcpAvailableCommand[] | undefined;
39
+ /** Resolve with the cached list, or wait up to `timeoutMs` for one (undefined on timeout). */
40
+ wait(sessionId: string, timeoutMs?: number): Promise<AcpAvailableCommand[] | undefined>;
41
+ delete(sessionId: string): void;
42
+ clear(): void;
43
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};