Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

client.ts

585 lines22.8 KB

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