@agentrq/acp-gateway 0.2.32 → 0.2.34

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
@@ -37,7 +37,7 @@ npm install -g @agentrq/acp-gateway
37
37
 
38
38
  ## Current Version
39
39
 
40
- `0.2.32`
40
+ `0.2.34`
41
41
 
42
42
  ## Usage
43
43
 
@@ -140,6 +140,13 @@ describe("AgentRQACPClient", () => {
140
140
  "mcp__agentrq-workspace__loadMemory",
141
141
  "mcp.agentrq-workspace.deleteMemory",
142
142
  "reply (agentrq-workspace MCP Server)",
143
+ "mcp__agentrq-workspace__task",
144
+ "mcp__agentrq-workspace__memory",
145
+ "mcp__agentrq-workspace__skills",
146
+ "mcp__agentrq-workspace__workspace",
147
+ "mcp__agentrq-workspace__siteTools",
148
+ "mcp__agentrq-workspace__pano",
149
+ "mcp__agentrq-workspace__help",
143
150
  ])("auto-allows %s", async (title) => {
144
151
  const { bridge, client: c } = clientFor("agentrq-workspace");
145
152
  const response = await c.requestPermission(ask(title));
@@ -2126,5 +2133,214 @@ describe("AgentRQACPClient", () => {
2126
2133
  consoleSpy.mockRestore();
2127
2134
  });
2128
2135
  });
2136
+ describe("dispose and resource management", () => {
2137
+ it("removes verdict and reconnected listeners from mcpBridge on dispose", () => {
2138
+ const bridge = Object.assign(new EventEmitter(), {
2139
+ getSessionId: vi.fn().mockReturnValue("test-session"),
2140
+ sendNotification: vi.fn().mockResolvedValue(undefined),
2141
+ callTool: vi.fn(),
2142
+ });
2143
+ expect(bridge.listenerCount("verdict")).toBe(0);
2144
+ expect(bridge.listenerCount("reconnected")).toBe(0);
2145
+ const client = new AgentRQACPClient(bridge);
2146
+ expect(bridge.listenerCount("verdict")).toBe(1);
2147
+ expect(bridge.listenerCount("reconnected")).toBe(1);
2148
+ client.dispose();
2149
+ expect(bridge.listenerCount("verdict")).toBe(0);
2150
+ expect(bridge.listenerCount("reconnected")).toBe(0);
2151
+ });
2152
+ it("cancels pending permissions and aborts pending elicitations on dispose", async () => {
2153
+ const bridge = Object.assign(new EventEmitter(), {
2154
+ getSessionId: vi.fn().mockReturnValue("test-session"),
2155
+ sendNotification: vi.fn().mockResolvedValue(undefined),
2156
+ callTool: vi.fn(),
2157
+ });
2158
+ let promptSignal;
2159
+ const client = new AgentRQACPClient(bridge, () => undefined, {
2160
+ promptUrlElicitation: ({ signal }) => {
2161
+ promptSignal = signal;
2162
+ return new Promise(() => { });
2163
+ },
2164
+ });
2165
+ const permPromise = client.requestPermission({
2166
+ sessionId: "sess-1",
2167
+ toolCall: { toolCallId: "call-1" },
2168
+ options: [
2169
+ { optionId: "allow", name: "Allow", kind: "allow" },
2170
+ { optionId: "reject", name: "Reject", kind: "reject" },
2171
+ ],
2172
+ });
2173
+ void client.createElicitation({
2174
+ mode: "url",
2175
+ url: "https://example.com/login",
2176
+ elicitationId: "elicit-1",
2177
+ message: "Sign in",
2178
+ });
2179
+ await vi.waitFor(() => {
2180
+ expect(client.pendingPermissionCount).toBe(1);
2181
+ expect(promptSignal).toBeDefined();
2182
+ });
2183
+ expect(promptSignal?.aborted).toBe(false);
2184
+ client.dispose();
2185
+ expect(client.pendingPermissionCount).toBe(0);
2186
+ expect(promptSignal?.aborted).toBe(true);
2187
+ const result = await permPromise;
2188
+ expect(result.outcome).toEqual({ outcome: "cancelled" });
2189
+ });
2190
+ it("bounds replyBuffers to prevent unbounded memory growth", async () => {
2191
+ const bridge = Object.assign(new EventEmitter(), {
2192
+ getSessionId: vi.fn().mockReturnValue("test-session"),
2193
+ sendNotification: vi.fn().mockResolvedValue(undefined),
2194
+ callTool: vi.fn(),
2195
+ });
2196
+ const client = new AgentRQACPClient(bridge, (sid) => "task-" + sid);
2197
+ for (let i = 0; i < 300; i++) {
2198
+ await client.sessionUpdate({
2199
+ sessionId: "sess-" + i,
2200
+ update: {
2201
+ sessionUpdate: "agent_message_chunk",
2202
+ content: { type: "text", text: "hello from " + i },
2203
+ },
2204
+ });
2205
+ }
2206
+ // sess-0 should have been evicted by BoundedMap(256)
2207
+ await client.flushReply("sess-0");
2208
+ expect(bridge.callTool).not.toHaveBeenCalledWith("reply", expect.objectContaining({ chatId: "task-sess-0" }));
2209
+ // sess-299 should still be present
2210
+ await client.flushReply("sess-299");
2211
+ expect(bridge.callTool).toHaveBeenCalledWith("reply", expect.objectContaining({
2212
+ chatId: "task-sess-299",
2213
+ text: "hello from 299",
2214
+ }));
2215
+ });
2216
+ });
2217
+ describe("the single task tool", () => {
2218
+ const TASK_SERVER = new Set(["task", "pano", "getWorkspace"]);
2219
+ beforeEach(() => {
2220
+ mcpBridge.getAdvertisedTools = vi.fn().mockReturnValue(TASK_SERVER);
2221
+ });
2222
+ function okResult(text = "ok") {
2223
+ return { isError: false, content: [{ type: "text", text }] };
2224
+ }
2225
+ it("forwards the agent's reply through task", async () => {
2226
+ mcpBridge.callTool.mockResolvedValue(okResult());
2227
+ const c = new AgentRQACPClient(mcpBridge, () => "task-123");
2228
+ vi.spyOn(process.stdout, "write").mockImplementation(() => true);
2229
+ await c.sessionUpdate({ sessionId: "sess-1", update: { sessionUpdate: "agent_message_chunk", content: { type: "text", text: "Hello" } } });
2230
+ await c.flushReply("sess-1");
2231
+ expect(mcpBridge.callTool).toHaveBeenCalledWith("task", {
2232
+ action: "reply",
2233
+ payload: { taskId: "task-123", text: "Hello" },
2234
+ });
2235
+ });
2236
+ it("reports a stop reason through task", async () => {
2237
+ mcpBridge.callTool.mockResolvedValue(okResult());
2238
+ const c = new AgentRQACPClient(mcpBridge, () => "task-1");
2239
+ await c.reportStopReason("sess-1", "refusal");
2240
+ expect(mcpBridge.callTool).toHaveBeenCalledWith("task", {
2241
+ action: "reply",
2242
+ payload: { taskId: "task-1", text: expect.any(String) },
2243
+ });
2244
+ });
2245
+ it("creates, starts and asks through task when an elicitation has no task", async () => {
2246
+ mcpBridge.callTool.mockImplementation(async (_name, args) => {
2247
+ if (args.action === "create")
2248
+ return okResult("task created with id=T-new");
2249
+ if (args.action === "elicit")
2250
+ return okResult(JSON.stringify({ action: "decline" }));
2251
+ return okResult();
2252
+ });
2253
+ const params = {
2254
+ mode: "form",
2255
+ message: "Name?",
2256
+ requestedSchema: { type: "object", properties: { name: { type: "string" } } },
2257
+ };
2258
+ const response = await client.createElicitation(params);
2259
+ expect(mcpBridge.callTool.mock.calls).toEqual([
2260
+ ["task", { action: "create", payload: { title: "Name?", body: "Name?", assignee: "human" } }],
2261
+ ["task", { action: "updateStatus", payload: { taskId: "T-new", status: "ongoing" } }],
2262
+ ["task", {
2263
+ action: "elicit",
2264
+ payload: { taskId: "T-new", message: "Name?", mode: "form", requestedSchema: params.requestedSchema },
2265
+ }],
2266
+ ]);
2267
+ expect(response).toEqual({ action: "decline" });
2268
+ });
2269
+ it.each([
2270
+ ["task (agentrq-0an2BXTfpGj MCP Server)", { action: "reply", payload: { taskId: "task-123", text: "Hello world" } }],
2271
+ ["mcp__agentrq-workspace__task", { action: "reply", payload: { taskId: "task-123", text: "Hello world" } }],
2272
+ ["task (agentrq-0an2BXTfpGj MCP Server)", { action: "reply", taskId: "task-123", text: "Hello world" }],
2273
+ ["mcp__agentrq-workspace__reply", { chatId: "task-123", text: "Hello world" }],
2274
+ ["agentrq-workspace_task", { action: "reply", payload: { taskId: "task-123", text: "Hello world" } }],
2275
+ ])("does not repeat a reply the agent already sent as %s %j", async (title, rawInput) => {
2276
+ mcpBridge.callTool.mockResolvedValue(okResult());
2277
+ const c = new AgentRQACPClient(mcpBridge, () => "task-123");
2278
+ mcpBridge.getAdvertisedTools.mockReturnValue(new Set([...TASK_SERVER, "reply"]));
2279
+ vi.spyOn(process.stdout, "write").mockImplementation(() => true);
2280
+ await c.sessionUpdate({ sessionId: "sess-1", update: { sessionUpdate: "agent_message_chunk", content: { type: "text", text: "Hello world" } } });
2281
+ await c.sessionUpdate({
2282
+ sessionId: "sess-1",
2283
+ update: { sessionUpdate: "tool_call", title, status: "completed", toolCallId: "tc-1", rawInput },
2284
+ });
2285
+ await c.flushReply("sess-1");
2286
+ expect(mcpBridge.callTool).not.toHaveBeenCalled();
2287
+ });
2288
+ it.each([
2289
+ ["another action", { action: "get", payload: { taskId: "task-123" } }],
2290
+ ["no task id", { action: "reply", payload: { text: "Hello world" } }],
2291
+ ["a payload that is not an object", { action: "reply", payload: "Hello world" }],
2292
+ ["no input", undefined],
2293
+ ])("still replies when the agent's task call has %s", async (_case, rawInput) => {
2294
+ mcpBridge.callTool.mockResolvedValue(okResult());
2295
+ const c = new AgentRQACPClient(mcpBridge, () => "task-123");
2296
+ vi.spyOn(process.stdout, "write").mockImplementation(() => true);
2297
+ await c.sessionUpdate({ sessionId: "sess-1", update: { sessionUpdate: "agent_message_chunk", content: { type: "text", text: "Hello world" } } });
2298
+ await c.sessionUpdate({
2299
+ sessionId: "sess-1",
2300
+ update: { sessionUpdate: "tool_call", title: "mcp__agentrq-workspace__task", status: "completed", toolCallId: "tc-1", rawInput },
2301
+ });
2302
+ await c.flushReply("sess-1");
2303
+ expect(mcpBridge.callTool).toHaveBeenCalledWith("task", {
2304
+ action: "reply",
2305
+ payload: { taskId: "task-123", text: "Hello world" },
2306
+ });
2307
+ });
2308
+ it.each([
2309
+ ["mcp__agentrq-workspace__task", { action: "reply", payload: { taskId: "task-123" } }],
2310
+ ["mcp__agentrq-workspace__reply", { chatId: "task-123" }],
2311
+ ])("treats a %s reply with no text as empty, not as the agent's text", async (title, rawInput) => {
2312
+ mcpBridge.getAdvertisedTools.mockReturnValue(new Set([...TASK_SERVER, "reply"]));
2313
+ mcpBridge.callTool.mockResolvedValue(okResult());
2314
+ const c = new AgentRQACPClient(mcpBridge, () => "task-123");
2315
+ vi.spyOn(process.stdout, "write").mockImplementation(() => true);
2316
+ await c.sessionUpdate({ sessionId: "sess-1", update: { sessionUpdate: "agent_message_chunk", content: { type: "text", text: "Hello world" } } });
2317
+ await c.sessionUpdate({
2318
+ sessionId: "sess-1",
2319
+ update: { sessionUpdate: "tool_call", title, status: "completed", toolCallId: "tc-1", rawInput },
2320
+ });
2321
+ await c.flushReply("sess-1");
2322
+ expect(mcpBridge.callTool).toHaveBeenCalledTimes(1);
2323
+ });
2324
+ it("recognises task as the workspace's own when tools/list failed", async () => {
2325
+ mcpBridge.getAdvertisedTools.mockReturnValue(undefined);
2326
+ mcpBridge.callTool.mockResolvedValue(okResult());
2327
+ const c = new AgentRQACPClient(mcpBridge, () => "task-123");
2328
+ vi.spyOn(process.stdout, "write").mockImplementation(() => true);
2329
+ await c.sessionUpdate({ sessionId: "sess-1", update: { sessionUpdate: "agent_message_chunk", content: { type: "text", text: "Hi" } } });
2330
+ await c.sessionUpdate({
2331
+ sessionId: "sess-1",
2332
+ update: {
2333
+ sessionUpdate: "tool_call",
2334
+ title: "mcp__agentrq-workspace__task",
2335
+ status: "completed",
2336
+ toolCallId: "tc-1",
2337
+ rawInput: { action: "reply", payload: { taskId: "task-123", text: "Hi" } },
2338
+ },
2339
+ });
2340
+ await c.flushReply("sess-1");
2341
+ // Were task not on the known list, the call would go unrecognised and the reply repeat.
2342
+ expect(mcpBridge.callTool).not.toHaveBeenCalled();
2343
+ });
2344
+ });
2129
2345
  });
2130
2346
  //# sourceMappingURL=acpClient.test.js.map