@yitom/acp-client 0.1.0 → 0.1.2

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)
@@ -51,6 +51,10 @@ export declare class AcpSessionHandle {
51
51
  /** 向当前会话发送 Prompt / 消息交互 */
52
52
  prompt(promptText: string, options?: {
53
53
  timeoutMs?: number;
54
+ images?: Array<{
55
+ mimeType: string;
56
+ data: string;
57
+ }>;
54
58
  }): Promise<Result<unknown, AppError>>;
55
59
  /** 修改会话配置项(如模型 ID、模式等) */
56
60
  setConfigOption(configId: string, value: string | boolean): Promise<Result<unknown, AppError>>;
@@ -69,6 +73,7 @@ export declare class AcpClient {
69
73
  private readonly workspaceRoot;
70
74
  private readonly clientInfo;
71
75
  private readonly dataDir;
76
+ private readonly extraEnv;
72
77
  private readonly callbacks;
73
78
  private readonly terminals;
74
79
  private processHandle;
@@ -81,6 +86,7 @@ export declare class AcpClient {
81
86
  get isConnected(): boolean;
82
87
  /** 获取底层当前 Agent 的 RPC 客户端句柄 */
83
88
  get agent(): import("@agentclientprotocol/sdk").ClientContext | null;
89
+ get initializeResponse(): InitializeResponse | null;
84
90
  /**
85
91
  * 启动并连接 Agent:
86
92
  * 1. 预检判停(如缺少 API Key、未安装 CLI);
@@ -101,6 +107,10 @@ export declare class AcpClient {
101
107
  /** 向指定会话发送消息 */
102
108
  promptSession(sessionId: string, promptText: string, options?: {
103
109
  timeoutMs?: number;
110
+ images?: Array<{
111
+ mimeType: string;
112
+ data: string;
113
+ }>;
104
114
  }): Promise<Result<unknown, AppError>>;
105
115
  /** 动态更新会话配置项(如模型 ID) */
106
116
  setSessionConfigOption(sessionId: string, configId: string, value: string | boolean): Promise<Result<unknown, AppError>>;
package/dist/index.cjs CHANGED
@@ -2156,6 +2156,7 @@ class AcpClient {
2156
2156
  workspaceRoot;
2157
2157
  clientInfo;
2158
2158
  dataDir;
2159
+ extraEnv;
2159
2160
  callbacks;
2160
2161
  terminals = new AcpTerminalManager;
2161
2162
  processHandle = null;
@@ -2167,9 +2168,10 @@ class AcpClient {
2167
2168
  this.workspaceRoot = options.workspaceRoot;
2168
2169
  this.clientInfo = {
2169
2170
  name: options.clientInfo?.name ?? "inkdown",
2170
- version: options.clientInfo?.version ?? "0.1.0"
2171
+ version: options.clientInfo?.version ?? "0.1.1"
2171
2172
  };
2172
2173
  this.dataDir = options.dataDir ?? getDefaultAgentDataDir();
2174
+ this.extraEnv = options.env ?? {};
2173
2175
  this.callbacks = options.callbacks ?? {};
2174
2176
  const runtimeId = typeof options.runtime === "string" ? options.runtime : options.runtime?.id ?? DEFAULT_ACP_RUNTIME_ID;
2175
2177
  this.adapter = getAcpRuntimeAdapter(runtimeId);
@@ -2192,6 +2194,9 @@ class AcpClient {
2192
2194
  get agent() {
2193
2195
  return this.sdkConnection?.agent ?? null;
2194
2196
  }
2197
+ get initializeResponse() {
2198
+ return this.initResponse;
2199
+ }
2195
2200
  async connect() {
2196
2201
  try {
2197
2202
  this.setStatus("connecting");
@@ -2213,7 +2218,11 @@ class AcpClient {
2213
2218
  }
2214
2219
  const storedProxy = await readAcpProxySettings(this.dataDir);
2215
2220
  const proxyEnv = buildAcpProxySpawnEnv(storedProxy);
2216
- const spawnEnv = this.adapter.getSpawnEnv?.(storedProxy) ?? proxyEnv;
2221
+ const baseEnv = this.adapter.getSpawnEnv?.(storedProxy) ?? proxyEnv;
2222
+ const spawnEnv = {
2223
+ ...baseEnv,
2224
+ env: { ...baseEnv.env ?? {}, ...this.extraEnv ?? {} }
2225
+ };
2217
2226
  await this.adapter.beforeSpawn?.();
2218
2227
  const processHandle = spawnAcpProcess({
2219
2228
  runtime: effectiveRuntime,
@@ -2315,9 +2324,15 @@ class AcpClient {
2315
2324
  return err({ code: "ACP_NOT_CONNECTED", message: "尚未连接到 Agent 服务端" });
2316
2325
  }
2317
2326
  try {
2327
+ const prompt = [{ type: "text", text: promptText }];
2328
+ for (const image of options?.images ?? []) {
2329
+ if (!image?.data || !image?.mimeType)
2330
+ continue;
2331
+ prompt.push({ type: "image", mimeType: image.mimeType, data: image.data });
2332
+ }
2318
2333
  const response = await sdkRequest(this.sdkConnection.agent, import_sdk4.methods.agent.session.prompt, {
2319
2334
  sessionId,
2320
- prompt: [{ type: "text", text: promptText }]
2335
+ prompt
2321
2336
  }, options?.timeoutMs);
2322
2337
  return ok(response);
2323
2338
  } catch (e) {
package/dist/index.js CHANGED
@@ -1996,6 +1996,7 @@ class AcpClient {
1996
1996
  workspaceRoot;
1997
1997
  clientInfo;
1998
1998
  dataDir;
1999
+ extraEnv;
1999
2000
  callbacks;
2000
2001
  terminals = new AcpTerminalManager;
2001
2002
  processHandle = null;
@@ -2007,9 +2008,10 @@ class AcpClient {
2007
2008
  this.workspaceRoot = options.workspaceRoot;
2008
2009
  this.clientInfo = {
2009
2010
  name: options.clientInfo?.name ?? "inkdown",
2010
- version: options.clientInfo?.version ?? "0.1.0"
2011
+ version: options.clientInfo?.version ?? "0.1.1"
2011
2012
  };
2012
2013
  this.dataDir = options.dataDir ?? getDefaultAgentDataDir();
2014
+ this.extraEnv = options.env ?? {};
2013
2015
  this.callbacks = options.callbacks ?? {};
2014
2016
  const runtimeId = typeof options.runtime === "string" ? options.runtime : options.runtime?.id ?? DEFAULT_ACP_RUNTIME_ID;
2015
2017
  this.adapter = getAcpRuntimeAdapter(runtimeId);
@@ -2032,6 +2034,9 @@ class AcpClient {
2032
2034
  get agent() {
2033
2035
  return this.sdkConnection?.agent ?? null;
2034
2036
  }
2037
+ get initializeResponse() {
2038
+ return this.initResponse;
2039
+ }
2035
2040
  async connect() {
2036
2041
  try {
2037
2042
  this.setStatus("connecting");
@@ -2053,7 +2058,11 @@ class AcpClient {
2053
2058
  }
2054
2059
  const storedProxy = await readAcpProxySettings(this.dataDir);
2055
2060
  const proxyEnv = buildAcpProxySpawnEnv(storedProxy);
2056
- const spawnEnv = this.adapter.getSpawnEnv?.(storedProxy) ?? proxyEnv;
2061
+ const baseEnv = this.adapter.getSpawnEnv?.(storedProxy) ?? proxyEnv;
2062
+ const spawnEnv = {
2063
+ ...baseEnv,
2064
+ env: { ...baseEnv.env ?? {}, ...this.extraEnv ?? {} }
2065
+ };
2057
2066
  await this.adapter.beforeSpawn?.();
2058
2067
  const processHandle = spawnAcpProcess({
2059
2068
  runtime: effectiveRuntime,
@@ -2155,9 +2164,15 @@ class AcpClient {
2155
2164
  return err({ code: "ACP_NOT_CONNECTED", message: "尚未连接到 Agent 服务端" });
2156
2165
  }
2157
2166
  try {
2167
+ const prompt = [{ type: "text", text: promptText }];
2168
+ for (const image of options?.images ?? []) {
2169
+ if (!image?.data || !image?.mimeType)
2170
+ continue;
2171
+ prompt.push({ type: "image", mimeType: image.mimeType, data: image.data });
2172
+ }
2158
2173
  const response = await sdkRequest(this.sdkConnection.agent, methods2.agent.session.prompt, {
2159
2174
  sessionId,
2160
- prompt: [{ type: "text", text: promptText }]
2175
+ prompt
2161
2176
  }, options?.timeoutMs);
2162
2177
  return ok(response);
2163
2178
  } catch (e) {
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};