@agentrq/acp-gateway 0.2.26 → 0.2.28
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 +2 -2
- package/dist/__tests__/index.test.js +67 -7
- package/dist/__tests__/index.test.js.map +1 -1
- package/dist/index.js +58 -13
- package/dist/index.js.map +1 -1
- package/dist/mcpClient.js +1 -1
- package/package.json +1 -1
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.
|
|
40
|
+
`0.2.28`
|
|
41
41
|
|
|
42
42
|
## Usage
|
|
43
43
|
|
|
@@ -173,7 +173,7 @@ Credentials are never stored by the gateway; the agent keeps its own, exactly as
|
|
|
173
173
|
|
|
174
174
|
`acp-gateway` searches for `.mcp.json` starting in the current working directory and up to 3 parent directories.
|
|
175
175
|
|
|
176
|
-
`--list-models`, `--agent-info` and `--list-auth-methods` only ask the agent about itself, so they do not need a workspace: they skip the search and run without a `.mcp.json`. They still read a config named with `--mcp-json`.
|
|
176
|
+
`--list-models`, `--agent-info` and `--list-auth-methods` only ask the agent about itself, so they do not need a workspace: they skip the search and run without a `.mcp.json`. They still read a config named with `--mcp-json`, but `--list-models` never connects to the workspace: it runs the agent in an empty temporary directory, so the agent does not pick up the workspace's `.mcp.json` and get taken for the workspace's agent.
|
|
177
177
|
|
|
178
178
|
`--mcp-json <path>` names a config directly, wherever it lives and whatever it is called. It is read *as well as* whatever the search finds, with the named file winning any name collision — so a gateway started from somewhere other than its workspace still connects to the right one.
|
|
179
179
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
2
|
import { setVerbose } from "../log.js";
|
|
3
|
-
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { existsSync, mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { tmpdir } from "node:os";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { EventEmitter } from "node:events";
|
|
7
7
|
import * as acp from "@agentclientprotocol/sdk";
|
|
8
|
-
import { createAcpSessionSwitcher, fetchNextTask, startPendingTask, drainPendingTasks, createSelfFillingTaskQueue, MAX_SKIPPED_FETCHES, IDLE_TASK_POLL_INTERVAL_MS, freeSlots, resetPendingTaskDrain, mapMcpServers, TaskQueue, createTaskQueue, resetConcurrencyReports, getOrCreateSession, openIdleSession, resetIdleSession, activeSessions, AuthenticationFailed, IDLE_SESSION_KEY, loginCommandFor, authConfig, modelConfig, createSessionWithAuth, isInteractiveTerminal, openAgentConnection, agentExitFailed, showAgentStderr, shouldPrintBanner, parseGatewayArgs, assertAgentRunnable, helpText, isRunnable, resolveOnPath, spawnTarget, needsShell, escapeCmdCommand, quoteForCmd, spawnArgsFor, terminateAgentProcess, printHelp, resolveAgentCommand, runListAgents, pickHumanApprovalMode, enforceHumanApprovalMode, handleAgentModeChange, runAgentCommand, loadWorkspace, createDetachedBridge, WORKSPACE_OPTIONAL_COMMANDS, findActiveSession, handleTaskCancellation, handleSetModel, handleSetConcurrency, runTurnForTask, resetTaskTurns, registerConcurrencyListeners, reportConcurrency, applyModelSelection, cancelledTaskSeq, markTaskCancelled, isTaskCancelled, nextTaskSeq, supportsCloseSession, closeSession, closeAllSessions, setupSignalHandlers, } from "../index.js";
|
|
9
|
-
import { sendModelsNotification } from "../acpClient.js";
|
|
8
|
+
import { createAcpSessionSwitcher, fetchNextTask, startPendingTask, drainPendingTasks, createSelfFillingTaskQueue, MAX_SKIPPED_FETCHES, IDLE_TASK_POLL_INTERVAL_MS, freeSlots, resetPendingTaskDrain, mapMcpServers, TaskQueue, createTaskQueue, resetConcurrencyReports, getOrCreateSession, openIdleSession, resetIdleSession, activeSessions, AuthenticationFailed, IDLE_SESSION_KEY, loginCommandFor, authConfig, modelConfig, createSessionWithAuth, isInteractiveTerminal, openAgentConnection, agentExitFailed, showAgentStderr, shouldPrintBanner, parseGatewayArgs, assertAgentRunnable, helpText, isRunnable, resolveOnPath, spawnTarget, needsShell, escapeCmdCommand, quoteForCmd, spawnArgsFor, terminateAgentProcess, printHelp, resolveAgentCommand, runListAgents, pickHumanApprovalMode, enforceHumanApprovalMode, handleAgentModeChange, runAgentCommand, loadWorkspace, createDetachedBridge, makeIsolatedDir, WORKSPACE_OPTIONAL_COMMANDS, findActiveSession, handleTaskCancellation, handleSetModel, handleSetConcurrency, runTurnForTask, resetTaskTurns, registerConcurrencyListeners, reportConcurrency, applyModelSelection, cancelledTaskSeq, markTaskCancelled, isTaskCancelled, nextTaskSeq, supportsCloseSession, closeSession, closeAllSessions, setupSignalHandlers, } from "../index.js";
|
|
9
|
+
import { AgentRQACPClient, sendModelsNotification } from "../acpClient.js";
|
|
10
10
|
import { AUTH_REQUIRED_CODE } from "../auth.js";
|
|
11
11
|
/**
|
|
12
12
|
* A stand-in for the workspace bridge.
|
|
@@ -2678,12 +2678,19 @@ describe("index", () => {
|
|
|
2678
2678
|
writeFileSync(join(dir, ".mcp.json"), "{ not json");
|
|
2679
2679
|
expect(loadWorkspace("list-models", undefined, dir).configs).toEqual([]);
|
|
2680
2680
|
});
|
|
2681
|
-
it("should still use a config named with --mcp-json", () => {
|
|
2681
|
+
it.each(["agent-info", "list-auth-methods"])("should still use a config named with --mcp-json for --%s", (command) => {
|
|
2682
2682
|
const file = writeMcpJson(emptyWorkspaceDir(), "servers.json");
|
|
2683
|
-
const workspace = loadWorkspace(
|
|
2683
|
+
const workspace = loadWorkspace(command, file, emptyWorkspaceDir());
|
|
2684
2684
|
expect(workspace.agentrqConfig.name).toBe("agentrq-ws");
|
|
2685
2685
|
expect(workspace.mcpBridge.getServerName()).toBe("agentrq-ws");
|
|
2686
2686
|
});
|
|
2687
|
+
it("should never connect --list-models to the workspace, even one named with --mcp-json", async () => {
|
|
2688
|
+
const file = writeMcpJson(emptyWorkspaceDir(), "servers.json");
|
|
2689
|
+
const workspace = loadWorkspace("list-models", file, emptyWorkspaceDir());
|
|
2690
|
+
expect(workspace.agentrqConfig.name).toBe("agentrq-ws");
|
|
2691
|
+
expect(workspace.mcpBridge.getServerName()).toBeUndefined();
|
|
2692
|
+
await expect(workspace.mcpBridge.callTool("elicit", {})).rejects.toThrow("No agentrq workspace is configured");
|
|
2693
|
+
});
|
|
2687
2694
|
it("should still report a --mcp-json path that is wrong", () => {
|
|
2688
2695
|
expect(() => loadWorkspace("list-models", "/nowhere/servers.json", emptyWorkspaceDir())).toThrow();
|
|
2689
2696
|
});
|
|
@@ -2698,16 +2705,40 @@ describe("index", () => {
|
|
|
2698
2705
|
expect(workspace.mcpBridge.getServerName()).toBe("agentrq-ws");
|
|
2699
2706
|
});
|
|
2700
2707
|
});
|
|
2708
|
+
describe("makeIsolatedDir", () => {
|
|
2709
|
+
it("should make an empty directory and remove it again", () => {
|
|
2710
|
+
const isolated = makeIsolatedDir();
|
|
2711
|
+
expect(existsSync(isolated.dir)).toBe(true);
|
|
2712
|
+
expect(isolated.dir.startsWith(tmpdir())).toBe(true);
|
|
2713
|
+
isolated.remove();
|
|
2714
|
+
expect(existsSync(isolated.dir)).toBe(false);
|
|
2715
|
+
// Removing twice, or after something else did, is harmless.
|
|
2716
|
+
expect(() => isolated.remove()).not.toThrow();
|
|
2717
|
+
});
|
|
2718
|
+
});
|
|
2701
2719
|
describe("createDetachedBridge", () => {
|
|
2702
|
-
it("should fail
|
|
2720
|
+
it("should fail tool calls, drop notifications, and close quietly", async () => {
|
|
2703
2721
|
const bridge = createDetachedBridge();
|
|
2704
2722
|
await expect(bridge.callTool("elicit", {})).rejects.toThrow("No agentrq workspace is configured");
|
|
2705
|
-
await expect(bridge.sendNotification("notifications/x", {})).
|
|
2723
|
+
await expect(bridge.sendNotification("notifications/x", {})).resolves.toBeUndefined();
|
|
2706
2724
|
expect(bridge.getSessionId()).toBeUndefined();
|
|
2707
2725
|
expect(bridge.getServerName()).toBeUndefined();
|
|
2708
2726
|
expect(bridge.getAdvertisedTools()).toBeUndefined();
|
|
2709
2727
|
await expect(bridge.close()).resolves.toBeUndefined();
|
|
2710
2728
|
});
|
|
2729
|
+
it("should not print an error when the agent shares its slash commands", async () => {
|
|
2730
|
+
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => { });
|
|
2731
|
+
const client = new AgentRQACPClient(createDetachedBridge());
|
|
2732
|
+
await client.sessionUpdate({
|
|
2733
|
+
sessionId: "s1",
|
|
2734
|
+
update: {
|
|
2735
|
+
sessionUpdate: "available_commands_update",
|
|
2736
|
+
availableCommands: [{ name: "init", description: "d" }],
|
|
2737
|
+
},
|
|
2738
|
+
});
|
|
2739
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
2740
|
+
errorSpy.mockRestore();
|
|
2741
|
+
});
|
|
2711
2742
|
});
|
|
2712
2743
|
describe("runAgentCommand", () => {
|
|
2713
2744
|
const agentrqConfig = { env: {} };
|
|
@@ -2739,6 +2770,35 @@ describe("index", () => {
|
|
|
2739
2770
|
expect(printed).toContain("--logout");
|
|
2740
2771
|
expect(spawnedAgents[0].kill).toHaveBeenCalled();
|
|
2741
2772
|
});
|
|
2773
|
+
it("should run --list-models in an empty directory of its own, and remove it after", async () => {
|
|
2774
|
+
// Run from the workspace's own directory, the agent would find the
|
|
2775
|
+
// workspace's .mcp.json there and connect to it as though it were the
|
|
2776
|
+
// workspace's agent.
|
|
2777
|
+
const { spawn } = await import("node:child_process");
|
|
2778
|
+
const newSession = vi.fn().mockResolvedValue({ sessionId: "m-sess", configOptions: [] });
|
|
2779
|
+
mockConnection({ newSession });
|
|
2780
|
+
await runAgentCommand("list-models", ["gemini", "--acp"], agentrqConfig, fakeBridge());
|
|
2781
|
+
const sessionCwd = newSession.mock.calls[0][0].cwd;
|
|
2782
|
+
expect(sessionCwd).not.toBe(process.cwd());
|
|
2783
|
+
expect(sessionCwd.startsWith(tmpdir())).toBe(true);
|
|
2784
|
+
expect(newSession.mock.calls[0][0].mcpServers).toEqual([]);
|
|
2785
|
+
expect(vi.mocked(spawn)).toHaveBeenLastCalledWith("gemini", ["--acp"], expect.objectContaining({ cwd: sessionCwd }));
|
|
2786
|
+
expect(existsSync(sessionCwd)).toBe(false);
|
|
2787
|
+
});
|
|
2788
|
+
it("should remove the --list-models directory when the agent fails to start", async () => {
|
|
2789
|
+
const { spawn } = await import("node:child_process");
|
|
2790
|
+
mockConnection({ initialize: vi.fn().mockRejectedValue(new Error("boom")) });
|
|
2791
|
+
await expect(runAgentCommand("list-models", ["gemini", "--acp"], agentrqConfig, fakeBridge())).rejects.toThrow();
|
|
2792
|
+
const cwd = vi.mocked(spawn).mock.calls.at(-1)[2].cwd;
|
|
2793
|
+
expect(cwd.startsWith(tmpdir())).toBe(true);
|
|
2794
|
+
expect(existsSync(cwd)).toBe(false);
|
|
2795
|
+
});
|
|
2796
|
+
it("should leave the other commands running where the gateway runs", async () => {
|
|
2797
|
+
const { spawn } = await import("node:child_process");
|
|
2798
|
+
mockConnection({});
|
|
2799
|
+
await runAgentCommand("agent-info", ["gemini", "--acp"], agentrqConfig, fakeBridge());
|
|
2800
|
+
expect(vi.mocked(spawn).mock.calls.at(-1)[2]).not.toHaveProperty("cwd");
|
|
2801
|
+
});
|
|
2742
2802
|
it("should list models from configOptions and cleanly close session", async () => {
|
|
2743
2803
|
mockConnection({
|
|
2744
2804
|
newSession: vi.fn().mockResolvedValue({
|