@actant/acp 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/dist/index.d.ts +281 -0
- package/dist/index.js +1089 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { SessionNotification, RequestPermissionRequest, RequestPermissionResponse, ReadTextFileRequest, ReadTextFileResponse, WriteTextFileRequest, WriteTextFileResponse, CreateTerminalRequest, CreateTerminalResponse, TerminalOutputRequest, TerminalOutputResponse, WaitForTerminalExitRequest, WaitForTerminalExitResponse, KillTerminalCommandRequest, KillTerminalCommandResponse, ReleaseTerminalRequest, ReleaseTerminalResponse, InitializeResponse, ClientSideConnection, NewSessionResponse, ContentBlock, ClientCapabilities } from '@agentclientprotocol/sdk';
|
|
2
|
+
export { ContentBlock, SessionNotification } from '@agentclientprotocol/sdk';
|
|
3
|
+
import { PermissionsConfig } from '@actant/shared';
|
|
4
|
+
import { Socket } from 'node:net';
|
|
5
|
+
import { PermissionPolicyEnforcer, AgentCommunicator, RunPromptOptions, PromptResult, StreamChunk } from '@actant/core';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Pluggable handler for every Client callback the Agent can invoke.
|
|
9
|
+
* Implementations decide whether to handle locally or forward to IDE.
|
|
10
|
+
*/
|
|
11
|
+
interface ClientCallbackHandler {
|
|
12
|
+
requestPermission(params: RequestPermissionRequest): Promise<RequestPermissionResponse>;
|
|
13
|
+
sessionUpdate(params: SessionNotification): Promise<void>;
|
|
14
|
+
readTextFile(params: ReadTextFileRequest): Promise<ReadTextFileResponse>;
|
|
15
|
+
writeTextFile(params: WriteTextFileRequest): Promise<WriteTextFileResponse>;
|
|
16
|
+
createTerminal?(params: CreateTerminalRequest): Promise<CreateTerminalResponse>;
|
|
17
|
+
terminalOutput?(params: TerminalOutputRequest): Promise<TerminalOutputResponse>;
|
|
18
|
+
waitForTerminalExit?(params: WaitForTerminalExitRequest): Promise<WaitForTerminalExitResponse>;
|
|
19
|
+
killTerminal?(params: KillTerminalCommandRequest): Promise<KillTerminalCommandResponse>;
|
|
20
|
+
releaseTerminal?(params: ReleaseTerminalRequest): Promise<ReleaseTerminalResponse>;
|
|
21
|
+
}
|
|
22
|
+
interface AcpConnectionOptions {
|
|
23
|
+
/** Auto-approve all tool permission requests (fallback when no permissionPolicy). */
|
|
24
|
+
autoApprove?: boolean;
|
|
25
|
+
/** Permission policy for the ACP Client allowlist (Layer 2 enforcement). */
|
|
26
|
+
permissionPolicy?: PermissionsConfig;
|
|
27
|
+
/** Instance name for audit logging. */
|
|
28
|
+
instanceName?: string;
|
|
29
|
+
/** Global session update listener. */
|
|
30
|
+
onSessionUpdate?: (notification: SessionNotification) => void;
|
|
31
|
+
/** Env vars to pass to the agent subprocess. */
|
|
32
|
+
env?: Record<string, string>;
|
|
33
|
+
/**
|
|
34
|
+
* Override the default local Client callbacks.
|
|
35
|
+
* When provided, AcpConnection delegates ALL Client requests to this handler
|
|
36
|
+
* instead of using the built-in local implementation.
|
|
37
|
+
* Used by AcpGateway to route callbacks to IDE or local depending on lease state.
|
|
38
|
+
*/
|
|
39
|
+
callbackHandler?: ClientCallbackHandler;
|
|
40
|
+
}
|
|
41
|
+
interface AcpSessionInfo {
|
|
42
|
+
sessionId: string;
|
|
43
|
+
modes?: NewSessionResponse["modes"];
|
|
44
|
+
configOptions?: NewSessionResponse["configOptions"];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Wraps a ClientSideConnection + child process lifecycle.
|
|
48
|
+
* Manages spawn → initialize → session/new → prompt → cancel → close.
|
|
49
|
+
*
|
|
50
|
+
* Implements ALL ACP Client callbacks:
|
|
51
|
+
* - requestPermission (auto-approve or delegate)
|
|
52
|
+
* - sessionUpdate
|
|
53
|
+
* - fs/read_text_file (with line/limit)
|
|
54
|
+
* - fs/write_text_file
|
|
55
|
+
* - terminal/* (create, output, wait_for_exit, kill, release)
|
|
56
|
+
*/
|
|
57
|
+
declare class AcpConnection {
|
|
58
|
+
private child;
|
|
59
|
+
private conn;
|
|
60
|
+
private initResponse;
|
|
61
|
+
private sessions;
|
|
62
|
+
private updateListeners;
|
|
63
|
+
private readonly options;
|
|
64
|
+
private readonly terminalManager;
|
|
65
|
+
private enforcer;
|
|
66
|
+
private auditLogger;
|
|
67
|
+
constructor(options?: AcpConnectionOptions);
|
|
68
|
+
/** Update the permission policy at runtime (hot-reload). */
|
|
69
|
+
updatePermissionPolicy(config: PermissionsConfig): void;
|
|
70
|
+
get isConnected(): boolean;
|
|
71
|
+
get agentCapabilities(): InitializeResponse | null;
|
|
72
|
+
get rawConnection(): ClientSideConnection | null;
|
|
73
|
+
spawn(command: string, args: string[], cwd: string): Promise<void>;
|
|
74
|
+
initialize(): Promise<InitializeResponse>;
|
|
75
|
+
newSession(cwd: string, mcpServers?: NewSessionResponse["modes"] extends unknown ? unknown[] : never[]): Promise<AcpSessionInfo>;
|
|
76
|
+
loadSession(sessionId: string, cwd: string): Promise<void>;
|
|
77
|
+
setSessionMode(sessionId: string, modeId: string): Promise<void>;
|
|
78
|
+
setSessionConfigOption(sessionId: string, configId: string, value: string): Promise<unknown>;
|
|
79
|
+
authenticate(methodId: string): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Send a prompt with arbitrary content blocks.
|
|
82
|
+
* For text-only convenience, use the string overload.
|
|
83
|
+
*/
|
|
84
|
+
prompt(sessionId: string, content: string | ContentBlock[]): Promise<{
|
|
85
|
+
stopReason: string;
|
|
86
|
+
text: string;
|
|
87
|
+
}>;
|
|
88
|
+
/**
|
|
89
|
+
* Stream prompt — yields every SessionNotification as it arrives.
|
|
90
|
+
*/
|
|
91
|
+
streamPrompt(sessionId: string, content: string | ContentBlock[]): AsyncIterable<SessionNotification>;
|
|
92
|
+
cancel(sessionId: string): Promise<void>;
|
|
93
|
+
getSession(sessionId: string): AcpSessionInfo | undefined;
|
|
94
|
+
listSessions(): string[];
|
|
95
|
+
close(): Promise<void>;
|
|
96
|
+
private buildClient;
|
|
97
|
+
private localRequestPermission;
|
|
98
|
+
private localSessionUpdate;
|
|
99
|
+
private localReadTextFile;
|
|
100
|
+
private localWriteTextFile;
|
|
101
|
+
addUpdateListener(sessionId: string, listener: (n: SessionNotification) => void): void;
|
|
102
|
+
removeUpdateListener(sessionId: string, listener: (n: SessionNotification) => void): void;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Upstream (IDE) handler interface.
|
|
107
|
+
* When a lease is active, agent callbacks are forwarded to the IDE
|
|
108
|
+
* through this interface, which wraps the AgentSideConnection facing the IDE.
|
|
109
|
+
*/
|
|
110
|
+
interface UpstreamHandler {
|
|
111
|
+
requestPermission(params: RequestPermissionRequest): Promise<RequestPermissionResponse>;
|
|
112
|
+
sessionUpdate(params: SessionNotification): Promise<void>;
|
|
113
|
+
readTextFile(params: ReadTextFileRequest): Promise<ReadTextFileResponse>;
|
|
114
|
+
writeTextFile(params: WriteTextFileRequest): Promise<WriteTextFileResponse>;
|
|
115
|
+
createTerminal(params: CreateTerminalRequest): Promise<CreateTerminalResponse>;
|
|
116
|
+
terminalOutput(params: TerminalOutputRequest): Promise<TerminalOutputResponse>;
|
|
117
|
+
waitForTerminalExit(params: WaitForTerminalExitRequest): Promise<WaitForTerminalExitResponse>;
|
|
118
|
+
killTerminal(params: KillTerminalCommandRequest): Promise<KillTerminalCommandResponse>;
|
|
119
|
+
releaseTerminal(params: ReleaseTerminalRequest): Promise<ReleaseTerminalResponse>;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Routes Client callbacks from the Agent to either:
|
|
123
|
+
* (A) the IDE (upstream) — when a lease is active and IDE supports the capability
|
|
124
|
+
* (B) local handlers (impersonation) — when no lease or IDE lacks the capability
|
|
125
|
+
*
|
|
126
|
+
* The Agent always sees full capabilities; the router handles fallback transparently.
|
|
127
|
+
*/
|
|
128
|
+
declare class ClientCallbackRouter implements ClientCallbackHandler {
|
|
129
|
+
private readonly local;
|
|
130
|
+
private upstream;
|
|
131
|
+
private ideCapabilities;
|
|
132
|
+
private enforcer;
|
|
133
|
+
constructor(local: ClientCallbackHandler);
|
|
134
|
+
/** Attach a PermissionPolicyEnforcer for pre-filtering in lease mode. */
|
|
135
|
+
setEnforcer(enforcer: PermissionPolicyEnforcer | null): void;
|
|
136
|
+
/**
|
|
137
|
+
* Activate lease-forwarding mode.
|
|
138
|
+
* Callbacks will be routed to the IDE for supported capabilities.
|
|
139
|
+
*/
|
|
140
|
+
attachUpstream(handler: UpstreamHandler, capabilities: ClientCapabilities): void;
|
|
141
|
+
/**
|
|
142
|
+
* Deactivate lease-forwarding. All callbacks revert to local handlers.
|
|
143
|
+
*/
|
|
144
|
+
detachUpstream(): void;
|
|
145
|
+
get isLeaseActive(): boolean;
|
|
146
|
+
requestPermission(params: RequestPermissionRequest): Promise<RequestPermissionResponse>;
|
|
147
|
+
sessionUpdate(params: SessionNotification): Promise<void>;
|
|
148
|
+
readTextFile(params: ReadTextFileRequest): Promise<ReadTextFileResponse>;
|
|
149
|
+
writeTextFile(params: WriteTextFileRequest): Promise<WriteTextFileResponse>;
|
|
150
|
+
createTerminal(params: CreateTerminalRequest): Promise<CreateTerminalResponse>;
|
|
151
|
+
terminalOutput(params: TerminalOutputRequest): Promise<TerminalOutputResponse>;
|
|
152
|
+
waitForTerminalExit(params: WaitForTerminalExitRequest): Promise<WaitForTerminalExitResponse>;
|
|
153
|
+
killTerminal(params: KillTerminalCommandRequest): Promise<KillTerminalCommandResponse>;
|
|
154
|
+
releaseTerminal(params: ReleaseTerminalRequest): Promise<ReleaseTerminalResponse>;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
interface GatewayOptions {
|
|
158
|
+
/** The downstream AcpConnection (Daemon → Agent). */
|
|
159
|
+
downstream: AcpConnection;
|
|
160
|
+
/** The callback router to attach upstream when IDE connects. */
|
|
161
|
+
callbackRouter: ClientCallbackRouter;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* ACP Gateway — bridges upstream IDE (ACP Client) and downstream Agent (ACP Server).
|
|
165
|
+
*
|
|
166
|
+
* Architecture:
|
|
167
|
+
* IDE ← ACP/socket → AgentSideConnection (upstream)
|
|
168
|
+
* ↕ (bridged)
|
|
169
|
+
* ClientSideConnection (downstream) ← ACP/stdio → Agent
|
|
170
|
+
*
|
|
171
|
+
* The Gateway:
|
|
172
|
+
* - Exposes an Agent interface to the IDE via AgentSideConnection
|
|
173
|
+
* - Forwards IDE requests (prompt, cancel, etc.) to the downstream Agent
|
|
174
|
+
* - Routes Agent callbacks (permissions, fs, terminal) to IDE or local
|
|
175
|
+
* via the ClientCallbackRouter
|
|
176
|
+
*/
|
|
177
|
+
declare class AcpGateway {
|
|
178
|
+
private upstream;
|
|
179
|
+
private readonly downstream;
|
|
180
|
+
private readonly callbackRouter;
|
|
181
|
+
private ideCapabilities;
|
|
182
|
+
/**
|
|
183
|
+
* WORKAROUND for SDK API limitation (see #95):
|
|
184
|
+
* AgentSideConnection exposes flat methods for fs (readTextFile, writeTextFile)
|
|
185
|
+
* but wraps terminal ops behind TerminalHandle. Ideally the Gateway should be
|
|
186
|
+
* stateless — the IDE (Client) manages its own terminal state keyed by terminalId.
|
|
187
|
+
* We maintain this map only because the SDK doesn't expose flat terminalOutput(),
|
|
188
|
+
* waitForTerminalExit(), killTerminal(), releaseTerminal() on AgentSideConnection.
|
|
189
|
+
* Remove this once the SDK adds flat terminal methods.
|
|
190
|
+
*/
|
|
191
|
+
private terminalHandles;
|
|
192
|
+
constructor(options: GatewayOptions);
|
|
193
|
+
get isUpstreamConnected(): boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Accept an IDE connection on a Unix/named-pipe socket.
|
|
196
|
+
* Creates an AgentSideConnection that bridges to the downstream Agent.
|
|
197
|
+
*/
|
|
198
|
+
acceptSocket(socket: Socket): void;
|
|
199
|
+
/**
|
|
200
|
+
* Disconnect the upstream IDE.
|
|
201
|
+
*/
|
|
202
|
+
disconnectUpstream(): void;
|
|
203
|
+
private buildAgentHandler;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
interface ConnectOptions {
|
|
207
|
+
command: string;
|
|
208
|
+
args: string[];
|
|
209
|
+
cwd: string;
|
|
210
|
+
connectionOptions?: AcpConnectionOptions;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Manages a pool of ACP connections keyed by agent instance name.
|
|
214
|
+
* Handles spawn → initialize → session lifecycle for each agent.
|
|
215
|
+
* Supports Gateway mode for Session Lease (IDE ↔ Gateway ↔ Agent).
|
|
216
|
+
*/
|
|
217
|
+
declare class AcpConnectionManager {
|
|
218
|
+
private connections;
|
|
219
|
+
private primarySessions;
|
|
220
|
+
private routers;
|
|
221
|
+
private gateways;
|
|
222
|
+
private enforcers;
|
|
223
|
+
/**
|
|
224
|
+
* Spawn an ACP agent process, initialize, and create a default session.
|
|
225
|
+
* Uses ClientCallbackRouter so Gateway can later attach an IDE upstream.
|
|
226
|
+
* When connectionOptions.permissionPolicy is set, creates a PermissionPolicyEnforcer
|
|
227
|
+
* for Layer 2 ACP Client allowlist enforcement.
|
|
228
|
+
*/
|
|
229
|
+
connect(name: string, options: ConnectOptions): Promise<AcpSessionInfo>;
|
|
230
|
+
/**
|
|
231
|
+
* Accept an IDE connection on the Gateway for a named agent.
|
|
232
|
+
* The IDE socket carries ACP protocol messages.
|
|
233
|
+
*/
|
|
234
|
+
acceptLeaseSocket(name: string, socket: Socket): void;
|
|
235
|
+
/**
|
|
236
|
+
* Disconnect IDE from the Gateway.
|
|
237
|
+
*/
|
|
238
|
+
disconnectLease(name: string): void;
|
|
239
|
+
getConnection(name: string): AcpConnection | undefined;
|
|
240
|
+
getGateway(name: string): AcpGateway | undefined;
|
|
241
|
+
getRouter(name: string): ClientCallbackRouter | undefined;
|
|
242
|
+
getPrimarySessionId(name: string): string | undefined;
|
|
243
|
+
has(name: string): boolean;
|
|
244
|
+
disconnect(name: string): Promise<void>;
|
|
245
|
+
disposeAll(): Promise<void>;
|
|
246
|
+
/**
|
|
247
|
+
* Update the permission policy for a named connection at runtime.
|
|
248
|
+
* Propagates to both the AcpConnection and the local handler enforcer.
|
|
249
|
+
*/
|
|
250
|
+
updatePermissionPolicy(name: string, config: PermissionsConfig): void;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Bridges an AcpConnection to the AgentCommunicator interface.
|
|
255
|
+
* Used by AgentManager to send prompts through ACP sessions.
|
|
256
|
+
*/
|
|
257
|
+
declare class AcpCommunicator implements AgentCommunicator {
|
|
258
|
+
private readonly connection;
|
|
259
|
+
private readonly sessionId;
|
|
260
|
+
constructor(connection: AcpConnection, sessionId: string);
|
|
261
|
+
runPrompt(_workspaceDir: string, prompt: string, _options?: RunPromptOptions): Promise<PromptResult>;
|
|
262
|
+
streamPrompt(_workspaceDir: string, prompt: string, _options?: RunPromptOptions): AsyncIterable<StreamChunk>;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Manages local terminal processes for ACP Client terminal/* callbacks.
|
|
267
|
+
* Each terminal is a child process with captured stdout/stderr output.
|
|
268
|
+
*/
|
|
269
|
+
declare class LocalTerminalManager {
|
|
270
|
+
private terminals;
|
|
271
|
+
private counter;
|
|
272
|
+
createTerminal(params: CreateTerminalRequest): Promise<CreateTerminalResponse>;
|
|
273
|
+
terminalOutput(params: TerminalOutputRequest): Promise<TerminalOutputResponse>;
|
|
274
|
+
waitForExit(params: WaitForTerminalExitRequest): Promise<WaitForTerminalExitResponse>;
|
|
275
|
+
killTerminal(params: KillTerminalCommandRequest): Promise<KillTerminalCommandResponse>;
|
|
276
|
+
releaseTerminal(params: ReleaseTerminalRequest): Promise<ReleaseTerminalResponse>;
|
|
277
|
+
disposeAll(): void;
|
|
278
|
+
private getTerminal;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export { AcpCommunicator, AcpConnection, AcpConnectionManager, type AcpConnectionOptions, AcpGateway, type AcpSessionInfo, type ClientCallbackHandler, ClientCallbackRouter, type ConnectOptions, type GatewayOptions, LocalTerminalManager, type UpstreamHandler };
|