Open History to see the last commit
1import * as Context from "effect/Context";
2import * as Effect from "effect/Effect";
3import * as Stdio from "effect/Stdio";
4import * as Layer from "effect/Layer";
5import * as Schema from "effect/Schema";
6import * as Scope from "effect/Scope";
7import * as Stream from "effect/Stream";
8import * as RpcClient from "effect/unstable/rpc/RpcClient";
9import * as RpcServer from "effect/unstable/rpc/RpcServer";
10import * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner";
11
12import * as AcpError from "./errors.ts";
13import * as AcpProtocol from "./protocol.ts";
14import * as AcpRpcs from "./rpc.ts";
15import * as AcpSchema from "./_generated/schema.gen.ts";
16import { AGENT_METHODS, CLIENT_METHODS } from "./_generated/meta.gen.ts";
17import {
18 callRpc,
19 decodeExtNotificationRegistration,
20 decodeExtRequestRegistration,
21 runHandler,
22} from "./_internal/shared.ts";
23import { makeChildStdio, makeTerminationError } from "./_internal/stdio.ts";
24
25export interface AcpClientOptions {
26 readonly logIncoming?: boolean;
27 readonly logOutgoing?: boolean;
28 readonly logger?: (event: AcpProtocol.AcpProtocolLogEvent) => Effect.Effect<void, never>;
29}
30
31type AcpClientRaw = {
32 readonly notifications: Stream.Stream<AcpProtocol.AcpIncomingNotification>;
33 readonly request: (method: string, payload: unknown) => Effect.Effect<unknown, AcpError.AcpError>;
34 readonly notify: (method: string, payload: unknown) => Effect.Effect<void, AcpError.AcpError>;
35};
36
37export class AcpClient extends Context.Service<
38 AcpClient,
39 {
40 readonly raw: AcpClientRaw;
41 readonly agent: {
42 /**
43 * Initializes the ACP session and negotiates capabilities.
44 * @see https://agentclientprotocol.com/protocol/schema#initialize
45 */
46 readonly initialize: (
47 payload: AcpSchema.InitializeRequest,
48 ) => Effect.Effect<AcpSchema.InitializeResponse, AcpError.AcpError>;
49 /**
50 * Performs ACP authentication when the agent requires it.
51 * @see https://agentclientprotocol.com/protocol/schema#authenticate
52 */
53 readonly authenticate: (
54 payload: AcpSchema.AuthenticateRequest,
55 ) => Effect.Effect<AcpSchema.AuthenticateResponse, AcpError.AcpError>;
56 /**
57 * Logs out the current ACP identity.
58 * @see https://agentclientprotocol.com/protocol/schema#logout
59 */
60 readonly logout: (
61 payload: AcpSchema.LogoutRequest,
62 ) => Effect.Effect<AcpSchema.LogoutResponse, AcpError.AcpError>;
63 /**
64 * Starts a new ACP session.
65 * @see https://agentclientprotocol.com/protocol/schema#session/new
66 */
67 readonly createSession: (
68 payload: AcpSchema.NewSessionRequest,
69 ) => Effect.Effect<AcpSchema.NewSessionResponse, AcpError.AcpError>;
70 /**
71 * Loads a previously saved ACP session.
72 * @see https://agentclientprotocol.com/protocol/schema#session/load
73 */
74 readonly loadSession: (
75 payload: AcpSchema.LoadSessionRequest,
76 ) => Effect.Effect<AcpSchema.LoadSessionResponse, AcpError.AcpError>;
77 /**
78 * Lists available ACP sessions.
79 * @see https://agentclientprotocol.com/protocol/schema#session/list
80 */
81 readonly listSessions: (
82 payload: AcpSchema.ListSessionsRequest,
83 ) => Effect.Effect<AcpSchema.ListSessionsResponse, AcpError.AcpError>;
84 /**
85 * Forks an ACP session.
86 * @see https://agentclientprotocol.com/protocol/schema#session/fork
87 */
88 readonly forkSession: (
89 payload: AcpSchema.ForkSessionRequest,
90 ) => Effect.Effect<AcpSchema.ForkSessionResponse, AcpError.AcpError>;
91 /**
92 * Resumes an ACP session.
93 * @see https://agentclientprotocol.com/protocol/schema#session/resume
94 */
95 readonly resumeSession: (
96 payload: AcpSchema.ResumeSessionRequest,
97 ) => Effect.Effect<AcpSchema.ResumeSessionResponse, AcpError.AcpError>;
98 /**
99 * Closes an ACP session.
100 * @see https://agentclientprotocol.com/protocol/schema#session/close
101 */
102 readonly closeSession: (
103 payload: AcpSchema.CloseSessionRequest,
104 ) => Effect.Effect<AcpSchema.CloseSessionResponse, AcpError.AcpError>;
105 /**
106 * Selects the active model for a session.
107 * @see https://agentclientprotocol.com/protocol/schema#session/set_model
108 */
109 readonly setSessionModel: (
110 payload: AcpSchema.SetSessionModelRequest,
111 ) => Effect.Effect<AcpSchema.SetSessionModelResponse, AcpError.AcpError>;
112 /**
113 * Updates a session configuration option.
114 * @see https://agentclientprotocol.com/protocol/schema#session/set_config_option
115 */
116 readonly setSessionConfigOption: (
117 payload: AcpSchema.SetSessionConfigOptionRequest,
118 ) => Effect.Effect<AcpSchema.SetSessionConfigOptionResponse, AcpError.AcpError>;
119 /**
120 * Sends a prompt turn to the agent.
121 * @see https://agentclientprotocol.com/protocol/schema#session/prompt
122 */
123 readonly prompt: (
124 payload: AcpSchema.PromptRequest,
125 ) => Effect.Effect<AcpSchema.PromptResponse, AcpError.AcpError>;
126 /**
127 * Sends a real ACP `session/cancel` notification.
128 * @see https://agentclientprotocol.com/protocol/schema#session/cancel
129 */
130 readonly cancel: (
131 payload: AcpSchema.CancelNotification,
132 ) => Effect.Effect<void, AcpError.AcpError>;
133 };
134 /**
135 * Registers a handler for `session/request_permission`.
136 * @see https://agentclientprotocol.com/protocol/schema#session/request_permission
137 */
138 readonly handleRequestPermission: (
139 handler: (
140 request: AcpSchema.RequestPermissionRequest,
141 ) => Effect.Effect<AcpSchema.RequestPermissionResponse, AcpError.AcpError>,
142 ) => Effect.Effect<void>;
143 /**
144 * Registers a handler for `session/elicitation`.
145 * @see https://agentclientprotocol.com/protocol/schema#session/elicitation
146 */
147 readonly handleElicitation: (
148 handler: (
149 request: AcpSchema.ElicitationRequest,
150 ) => Effect.Effect<AcpSchema.ElicitationResponse, AcpError.AcpError>,
151 ) => Effect.Effect<void>;
152 /**
153 * Registers a handler for `fs/read_text_file`.
154 * @see https://agentclientprotocol.com/protocol/schema#fs/read_text_file
155 */
156 readonly handleReadTextFile: (
157 handler: (
158 request: AcpSchema.ReadTextFileRequest,
159 ) => Effect.Effect<AcpSchema.ReadTextFileResponse, AcpError.AcpError>,
160 ) => Effect.Effect<void>;
161 /**
162 * Registers a handler for `fs/write_text_file`.
163 * @see https://agentclientprotocol.com/protocol/schema#fs/write_text_file
164 */
165 readonly handleWriteTextFile: (
166 handler: (
167 request: AcpSchema.WriteTextFileRequest,
168 ) => Effect.Effect<AcpSchema.WriteTextFileResponse | void, AcpError.AcpError>,
169 ) => Effect.Effect<void>;
170 /**
171 * Registers a handler for `terminal/create`.
172 * @see https://agentclientprotocol.com/protocol/schema#terminal/create
173 */
174 readonly handleCreateTerminal: (
175 handler: (
176 request: AcpSchema.CreateTerminalRequest,
177 ) => Effect.Effect<AcpSchema.CreateTerminalResponse, AcpError.AcpError>,
178 ) => Effect.Effect<void>;
179 /**
180 * Registers a handler for `terminal/output`.
181 * @see https://agentclientprotocol.com/protocol/schema#terminal/output
182 */
183 readonly handleTerminalOutput: (
184 handler: (
185 request: AcpSchema.TerminalOutputRequest,
186 ) => Effect.Effect<AcpSchema.TerminalOutputResponse, AcpError.AcpError>,
187 ) => Effect.Effect<void>;
188 /**
189 * Registers a handler for `terminal/wait_for_exit`.
190 * @see https://agentclientprotocol.com/protocol/schema#terminal/wait_for_exit
191 */
192 readonly handleTerminalWaitForExit: (
193 handler: (
194 request: AcpSchema.WaitForTerminalExitRequest,
195 ) => Effect.Effect<AcpSchema.WaitForTerminalExitResponse, AcpError.AcpError>,
196 ) => Effect.Effect<void>;
197 /**
198 * Registers a handler for `terminal/kill`.
199 * @see https://agentclientprotocol.com/protocol/schema#terminal/kill
200 */
201 readonly handleTerminalKill: (
202 handler: (
203 request: AcpSchema.KillTerminalRequest,
204 ) => Effect.Effect<AcpSchema.KillTerminalResponse | void, AcpError.AcpError>,
205 ) => Effect.Effect<void>;
206 /**
207 * Registers a handler for `terminal/release`.
208 * @see https://agentclientprotocol.com/protocol/schema#terminal/release
209 */
210 readonly handleTerminalRelease: (
211 handler: (
212 request: AcpSchema.ReleaseTerminalRequest,
213 ) => Effect.Effect<AcpSchema.ReleaseTerminalResponse | void, AcpError.AcpError>,
214 ) => Effect.Effect<void>;
215 /**
216 * Registers a handler for `session/update`.
217 * @see https://agentclientprotocol.com/protocol/schema#session/update
218 */
219 readonly handleSessionUpdate: (
220 handler: (
221 notification: AcpSchema.SessionNotification,
222 ) => Effect.Effect<void, AcpError.AcpError>,
223 ) => Effect.Effect<void>;
224 /**
225 * Registers a handler for `session/elicitation/complete`.
226 * @see https://agentclientprotocol.com/protocol/schema#session/elicitation/complete
227 */
228 readonly handleElicitationComplete: (
229 handler: (
230 notification: AcpSchema.ElicitationCompleteNotification,
231 ) => Effect.Effect<void, AcpError.AcpError>,
232 ) => Effect.Effect<void>;
233 /**
234 * Registers a fallback extension request handler.
235 * @see https://agentclientprotocol.com/protocol/extensibility
236 */
237 readonly handleUnknownExtRequest: (
238 handler: (method: string, params: unknown) => Effect.Effect<unknown, AcpError.AcpError>,
239 ) => Effect.Effect<void>;
240 /**
241 * Registers a fallback extension notification handler.
242 * @see https://agentclientprotocol.com/protocol/extensibility
243 */
244 readonly handleUnknownExtNotification: (
245 handler: (method: string, params: unknown) => Effect.Effect<void, AcpError.AcpError>,
246 ) => Effect.Effect<void>;
247 /**
248 * Registers a typed extension request handler.
249 * @see https://agentclientprotocol.com/protocol/extensibility
250 */
251 readonly handleExtRequest: <A, I>(
252 method: string,
253 payload: Schema.Codec<A, I>,
254 handler: (payload: A) => Effect.Effect<unknown, AcpError.AcpError>,
255 ) => Effect.Effect<void>;
256 /**
257 * Registers a typed extension notification handler.
258 * @see https://agentclientprotocol.com/protocol/extensibility
259 */
260 readonly handleExtNotification: <A, I>(
261 method: string,
262 payload: Schema.Codec<A, I>,
263 handler: (payload: A) => Effect.Effect<void, AcpError.AcpError>,
264 ) => Effect.Effect<void>;
265 }
266>()("effect-acp/client/AcpClient") {}
267
268interface AcpCoreRequestHandlers {
269 requestPermission?: (
270 request: AcpSchema.RequestPermissionRequest,
271 ) => Effect.Effect<AcpSchema.RequestPermissionResponse, AcpError.AcpError>;
272 elicitation?: (
273 request: AcpSchema.ElicitationRequest,
274 ) => Effect.Effect<AcpSchema.ElicitationResponse, AcpError.AcpError>;
275 readTextFile?: (
276 request: AcpSchema.ReadTextFileRequest,
277 ) => Effect.Effect<AcpSchema.ReadTextFileResponse, AcpError.AcpError>;
278 writeTextFile?: (
279 request: AcpSchema.WriteTextFileRequest,
280 ) => Effect.Effect<AcpSchema.WriteTextFileResponse | void, AcpError.AcpError>;
281 createTerminal?: (
282 request: AcpSchema.CreateTerminalRequest,
283 ) => Effect.Effect<AcpSchema.CreateTerminalResponse, AcpError.AcpError>;
284 terminalOutput?: (
285 request: AcpSchema.TerminalOutputRequest,
286 ) => Effect.Effect<AcpSchema.TerminalOutputResponse, AcpError.AcpError>;
287 terminalWaitForExit?: (
288 request: AcpSchema.WaitForTerminalExitRequest,
289 ) => Effect.Effect<AcpSchema.WaitForTerminalExitResponse, AcpError.AcpError>;
290 terminalKill?: (
291 request: AcpSchema.KillTerminalRequest,
292 ) => Effect.Effect<AcpSchema.KillTerminalResponse | void, AcpError.AcpError>;
293 terminalRelease?: (
294 request: AcpSchema.ReleaseTerminalRequest,
295 ) => Effect.Effect<AcpSchema.ReleaseTerminalResponse | void, AcpError.AcpError>;
296}
297
298interface AcpNotificationHandlers {
299 readonly sessionUpdate: BufferedNotificationHandler<AcpSchema.SessionNotification>;
300 readonly elicitationComplete: BufferedNotificationHandler<AcpSchema.ElicitationCompleteNotification>;
301}
302
303interface BufferedNotificationHandler<A> {
304 readonly handlers: Array<(notification: A) => Effect.Effect<void, AcpError.AcpError>>;
305 readonly pending: Array<A>;
306}
307
308export const make = Effect.fn("effect-acp/AcpClient.make")(function* (
309 stdio: Stdio.Stdio,
310 options: AcpClientOptions = {},
311 terminationError?: Effect.Effect<AcpError.AcpError>,
312): Effect.fn.Return<AcpClient["Service"], never, Scope.Scope> {
313 const coreHandlers: AcpCoreRequestHandlers = {};
314 const notificationHandlers: AcpNotificationHandlers = {
315 sessionUpdate: { handlers: [], pending: [] },
316 elicitationComplete: { handlers: [], pending: [] },
317 };
318 const extRequestHandlers = new Map<
319 string,
320 (params: unknown) => Effect.Effect<unknown, AcpError.AcpError>
321 >();
322 const extNotificationHandlers = new Map<
323 string,
324 (params: unknown) => Effect.Effect<void, AcpError.AcpError>
325 >();
326 let unknownExtRequestHandler:
327 | ((method: string, params: unknown) => Effect.Effect<unknown, AcpError.AcpError>)
328 | undefined;
329 let unknownExtNotificationHandler:
330 | ((method: string, params: unknown) => Effect.Effect<void, AcpError.AcpError>)
331 | undefined;
332
333 const runNotificationHandlers = <A>(
334 registration: BufferedNotificationHandler<A>,
335 notification: A,
336 ) =>
337 Effect.forEach(
338 registration.handlers,
339 (handler) => handler(notification).pipe(Effect.catch(() => Effect.void)),
340 { discard: true },
341 );
342
343 const flushBufferedNotifications = <A>(registration: BufferedNotificationHandler<A>) =>
344 Effect.suspend(() => {
345 if (registration.handlers.length === 0 || registration.pending.length === 0) {
346 return Effect.void;
347 }
348 const pending = registration.pending.splice(0, registration.pending.length);
349 return Effect.forEach(
350 pending,
351 (notification) => runNotificationHandlers(registration, notification),
352 {
353 discard: true,
354 },
355 );
356 });
357
358 const dispatchNotification = (notification: AcpProtocol.AcpIncomingNotification) => {
359 switch (notification._tag) {
360 case "SessionUpdate": {
361 if (notificationHandlers.sessionUpdate.handlers.length === 0) {
362 notificationHandlers.sessionUpdate.pending.push(notification.params);
363 return Effect.void;
364 }
365 return runNotificationHandlers(notificationHandlers.sessionUpdate, notification.params);
366 }
367 case "ElicitationComplete": {
368 if (notificationHandlers.elicitationComplete.handlers.length === 0) {
369 notificationHandlers.elicitationComplete.pending.push(notification.params);
370 return Effect.void;
371 }
372 return runNotificationHandlers(
373 notificationHandlers.elicitationComplete,
374 notification.params,
375 );
376 }
377 case "ExtNotification": {
378 const handler = extNotificationHandlers.get(notification.method);
379 if (handler) {
380 return handler(notification.params);
381 }
382 return unknownExtNotificationHandler
383 ? unknownExtNotificationHandler(notification.method, notification.params)
384 : Effect.void;
385 }
386 }
387 };
388
389 const dispatchExtRequest = (method: string, params: unknown) => {
390 const handler = extRequestHandlers.get(method);
391 if (handler) {
392 return handler(params);
393 }
394 return unknownExtRequestHandler
395 ? unknownExtRequestHandler(method, params)
396 : Effect.fail(AcpError.AcpRequestError.methodNotFound(method));
397 };
398
399 const transport = yield* AcpProtocol.makeAcpPatchedProtocol({
400 stdio: stdio,
401 ...(terminationError ? { terminationError } : {}),
402 serverRequestMethods: new Set(AcpRpcs.ClientRpcs.requests.keys()),
403 ...(options.logIncoming !== undefined ? { logIncoming: options.logIncoming } : {}),
404 ...(options.logOutgoing !== undefined ? { logOutgoing: options.logOutgoing } : {}),
405 ...(options.logger ? { logger: options.logger } : {}),
406 onNotification: dispatchNotification,
407 onExtRequest: dispatchExtRequest,
408 });
409
410 const clientHandlerLayer = AcpRpcs.ClientRpcs.toLayer(
411 AcpRpcs.ClientRpcs.of({
412 [CLIENT_METHODS.session_request_permission]: (payload) =>
413 runHandler(
414 coreHandlers.requestPermission,
415 payload,
416 CLIENT_METHODS.session_request_permission,
417 ),
418 [CLIENT_METHODS.session_elicitation]: (payload) =>
419 runHandler(coreHandlers.elicitation, payload, CLIENT_METHODS.session_elicitation),
420 [CLIENT_METHODS.fs_read_text_file]: (payload) =>
421 runHandler(coreHandlers.readTextFile, payload, CLIENT_METHODS.fs_read_text_file),
422 [CLIENT_METHODS.fs_write_text_file]: (payload) =>
423 runHandler(coreHandlers.writeTextFile, payload, CLIENT_METHODS.fs_write_text_file).pipe(
424 Effect.map((result) => result ?? {}),
425 ),
426 [CLIENT_METHODS.terminal_create]: (payload) =>
427 runHandler(coreHandlers.createTerminal, payload, CLIENT_METHODS.terminal_create),
428 [CLIENT_METHODS.terminal_output]: (payload) =>
429 runHandler(coreHandlers.terminalOutput, payload, CLIENT_METHODS.terminal_output),
430 [CLIENT_METHODS.terminal_wait_for_exit]: (payload) =>
431 runHandler(
432 coreHandlers.terminalWaitForExit,
433 payload,
434 CLIENT_METHODS.terminal_wait_for_exit,
435 ),
436 [CLIENT_METHODS.terminal_kill]: (payload) =>
437 runHandler(coreHandlers.terminalKill, payload, CLIENT_METHODS.terminal_kill).pipe(
438 Effect.map((result) => result ?? {}),
439 ),
440 [CLIENT_METHODS.terminal_release]: (payload) =>
441 runHandler(coreHandlers.terminalRelease, payload, CLIENT_METHODS.terminal_release).pipe(
442 Effect.map((result) => result ?? {}),
443 ),
444 }),
445 );
446
447 yield* RpcServer.make(AcpRpcs.ClientRpcs).pipe(
448 Effect.provideService(RpcServer.Protocol, transport.serverProtocol),
449 Effect.provide(clientHandlerLayer),
450 Effect.forkScoped,
451 );
452
453 let nextRpcRequestId = 1n << 32n;
454 const rpc = yield* RpcClient.make(AcpRpcs.AgentRpcs, {
455 generateRequestId: () => nextRpcRequestId++ as never,
456 }).pipe(Effect.provideService(RpcClient.Protocol, transport.clientProtocol));
457
458 return AcpClient.of({
459 raw: {
460 notifications: transport.incoming,
461 request: transport.request,
462 notify: transport.notify,
463 },
464 agent: {
465 initialize: (payload) =>
466 callRpc(AGENT_METHODS.initialize, rpc[AGENT_METHODS.initialize](payload)),
467 authenticate: (payload) =>
468 callRpc(AGENT_METHODS.authenticate, rpc[AGENT_METHODS.authenticate](payload)),
469 logout: (payload) => callRpc(AGENT_METHODS.logout, rpc[AGENT_METHODS.logout](payload)),
470 createSession: (payload) =>
471 callRpc(AGENT_METHODS.session_new, rpc[AGENT_METHODS.session_new](payload)),
472 loadSession: (payload) =>
473 callRpc(AGENT_METHODS.session_load, rpc[AGENT_METHODS.session_load](payload)),
474 listSessions: (payload) =>
475 callRpc(AGENT_METHODS.session_list, rpc[AGENT_METHODS.session_list](payload)),
476 forkSession: (payload) =>
477 callRpc(AGENT_METHODS.session_fork, rpc[AGENT_METHODS.session_fork](payload)),
478 resumeSession: (payload) =>
479 callRpc(AGENT_METHODS.session_resume, rpc[AGENT_METHODS.session_resume](payload)),
480 closeSession: (payload) =>
481 callRpc(AGENT_METHODS.session_close, rpc[AGENT_METHODS.session_close](payload)),
482 setSessionModel: (payload) =>
483 callRpc(AGENT_METHODS.session_set_model, rpc[AGENT_METHODS.session_set_model](payload)),
484 setSessionConfigOption: (payload) =>
485 callRpc(
486 AGENT_METHODS.session_set_config_option,
487 rpc[AGENT_METHODS.session_set_config_option](payload),
488 ),
489 prompt: (payload) =>
490 callRpc(AGENT_METHODS.session_prompt, rpc[AGENT_METHODS.session_prompt](payload)),
491 cancel: (payload) => transport.notify(AGENT_METHODS.session_cancel, payload),
492 },
493 handleRequestPermission: (handler) =>
494 Effect.suspend(() => {
495 coreHandlers.requestPermission = handler;
496 return Effect.void;
497 }),
498 handleElicitation: (handler) =>
499 Effect.suspend(() => {
500 coreHandlers.elicitation = handler;
501 return Effect.void;
502 }),
503 handleReadTextFile: (handler) =>
504 Effect.suspend(() => {
505 coreHandlers.readTextFile = handler;
506 return Effect.void;
507 }),
508 handleWriteTextFile: (handler) =>
509 Effect.suspend(() => {
510 coreHandlers.writeTextFile = handler;
511 return Effect.void;
512 }),
513 handleCreateTerminal: (handler) =>
514 Effect.suspend(() => {
515 coreHandlers.createTerminal = handler;
516 return Effect.void;
517 }),
518 handleTerminalOutput: (handler) =>
519 Effect.suspend(() => {
520 coreHandlers.terminalOutput = handler;
521 return Effect.void;
522 }),
523 handleTerminalWaitForExit: (handler) =>
524 Effect.suspend(() => {
525 coreHandlers.terminalWaitForExit = handler;
526 return Effect.void;
527 }),
528 handleTerminalKill: (handler) =>
529 Effect.suspend(() => {
530 coreHandlers.terminalKill = handler;
531 return Effect.void;
532 }),
533 handleTerminalRelease: (handler) =>
534 Effect.suspend(() => {
535 coreHandlers.terminalRelease = handler;
536 return Effect.void;
537 }),
538 handleSessionUpdate: (handler) =>
539 Effect.suspend(() => {
540 notificationHandlers.sessionUpdate.handlers.push(handler);
541 return flushBufferedNotifications(notificationHandlers.sessionUpdate);
542 }),
543 handleElicitationComplete: (handler) =>
544 Effect.suspend(() => {
545 notificationHandlers.elicitationComplete.handlers.push(handler);
546 return flushBufferedNotifications(notificationHandlers.elicitationComplete);
547 }),
548 handleUnknownExtRequest: (handler) =>
549 Effect.suspend(() => {
550 unknownExtRequestHandler = handler;
551 return Effect.void;
552 }),
553 handleUnknownExtNotification: (handler) =>
554 Effect.suspend(() => {
555 unknownExtNotificationHandler = handler;
556 return Effect.void;
557 }),
558 handleExtRequest: (method, payload, handler) =>
559 Effect.suspend(() => {
560 extRequestHandlers.set(method, decodeExtRequestRegistration(method, payload, handler));
561 return Effect.void;
562 }),
563 handleExtNotification: (method, payload, handler) =>
564 Effect.suspend(() => {
565 extNotificationHandlers.set(
566 method,
567 decodeExtNotificationRegistration(method, payload, handler),
568 );
569 return Effect.void;
570 }),
571 });
572});
573
574export const layer = (stdio: Stdio.Stdio, options: AcpClientOptions = {}): Layer.Layer<AcpClient> =>
575 Layer.effect(AcpClient, make(stdio, options));
576
577export const layerChildProcess = (
578 handle: ChildProcessSpawner.ChildProcessHandle,
579 options: AcpClientOptions = {},
580): Layer.Layer<AcpClient> => {
581 const stdio = makeChildStdio(handle);
582 const terminationError = makeTerminationError(handle);
583 return Layer.effect(AcpClient, make(stdio, options, terminationError));
584};