acp-factory 0.0.1

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.
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Session - High-level interface for interacting with an agent session
3
+ */
4
+ import type * as acp from "@agentclientprotocol/sdk";
5
+ import type { PromptContent, ExtendedSessionUpdate } from "./types.js";
6
+ import type { ACPClientHandler } from "./client-handler.js";
7
+ /**
8
+ * Represents an active session with an agent
9
+ */
10
+ export declare class Session {
11
+ readonly id: string;
12
+ readonly modes: string[];
13
+ readonly models: string[];
14
+ private readonly connection;
15
+ private readonly clientHandler;
16
+ constructor(id: string, connection: acp.ClientSideConnection, clientHandler: ACPClientHandler, modes?: string[], models?: string[]);
17
+ /**
18
+ * Send a prompt and stream responses
19
+ *
20
+ * In interactive permission mode, this may yield PermissionRequestUpdate objects
21
+ * that require a response via respondToPermission() before the prompt can continue.
22
+ */
23
+ prompt(content: PromptContent): AsyncIterable<ExtendedSessionUpdate>;
24
+ /**
25
+ * Cancel the current prompt
26
+ */
27
+ cancel(): Promise<void>;
28
+ /**
29
+ * Interrupt the current prompt and start a new one with additional context.
30
+ *
31
+ * This cancels any in-progress prompt and immediately starts a new prompt.
32
+ * The agent will restart its work but retains the conversation history.
33
+ *
34
+ * Use this when you need to redirect or add context to the agent's work.
35
+ *
36
+ * @param content - The new prompt content (can reference or build upon previous context)
37
+ * @returns AsyncIterable of session updates for the new prompt
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * // Original prompt running
42
+ * for await (const update of session.prompt("Analyze the codebase")) {
43
+ * handleUpdate(update);
44
+ * if (userWantsToRedirect) {
45
+ * // Interrupt and redirect
46
+ * for await (const update of session.interruptWith("Focus only on the /src directory")) {
47
+ * handleUpdate(update);
48
+ * }
49
+ * break;
50
+ * }
51
+ * }
52
+ * ```
53
+ */
54
+ interruptWith(content: PromptContent): AsyncIterable<ExtendedSessionUpdate>;
55
+ /**
56
+ * Add context to the agent while it's working (without interrupting).
57
+ *
58
+ * NOTE: This feature requires agent support for mid-execution messaging.
59
+ * Currently, claude-code-acp does not support this. When called, this method
60
+ * will throw an error. Use `interruptWith()` as an alternative.
61
+ *
62
+ * In the future, when agent adapters support the `_session/addContext` extension,
63
+ * this method will push context to the agent without cancelling current work.
64
+ *
65
+ * @param content - Additional context to send to the agent
66
+ * @throws Error - Always throws until agent support is available
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * // Future usage (not yet supported):
71
+ * for await (const update of session.prompt("Analyze the codebase")) {
72
+ * handleUpdate(update);
73
+ * if (userHasAdditionalContext) {
74
+ * // Add context without interrupting (future)
75
+ * await session.addContext("Also check the test coverage");
76
+ * }
77
+ * }
78
+ * ```
79
+ */
80
+ addContext(_content: PromptContent): Promise<void>;
81
+ /**
82
+ * Set the session mode
83
+ */
84
+ setMode(mode: string): Promise<void>;
85
+ /**
86
+ * Fork this session to create a new independent session
87
+ *
88
+ * The forked session inherits the conversation history, allowing
89
+ * operations like generating summaries without affecting this session.
90
+ *
91
+ * Note: This creates a new Session object - the original session
92
+ * remains active and can continue independently.
93
+ *
94
+ * @experimental This relies on the unstable session/fork ACP capability
95
+ */
96
+ fork(): Promise<Session>;
97
+ /**
98
+ * Respond to a permission request (for interactive permission mode)
99
+ *
100
+ * When using permissionMode: "interactive", permission requests are emitted
101
+ * as session updates with sessionUpdate: "permission_request". Call this method
102
+ * with the requestId and your chosen optionId to allow the prompt to continue.
103
+ *
104
+ * @param requestId - The requestId from the PermissionRequestUpdate
105
+ * @param optionId - The optionId of the selected permission option
106
+ */
107
+ respondToPermission(requestId: string, optionId: string): void;
108
+ /**
109
+ * Cancel a permission request (for interactive permission mode)
110
+ *
111
+ * This will cancel the permission request, which typically aborts the tool call.
112
+ *
113
+ * @param requestId - The requestId from the PermissionRequestUpdate
114
+ */
115
+ cancelPermission(requestId: string): void;
116
+ /**
117
+ * Check if there are any pending permission requests for this session
118
+ */
119
+ hasPendingPermissions(): boolean;
120
+ /**
121
+ * Get all pending permission request IDs for this session
122
+ */
123
+ getPendingPermissionIds(): string[];
124
+ }
125
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,KAAK,GAAG,MAAM,0BAA0B,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D;;GAEG;AACH,qBAAa,OAAO;IAClB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAE1B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA2B;IACtD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAmB;gBAG/C,EAAE,EAAE,MAAM,EACV,UAAU,EAAE,GAAG,CAAC,oBAAoB,EACpC,aAAa,EAAE,gBAAgB,EAC/B,KAAK,GAAE,MAAM,EAAO,EACpB,MAAM,GAAE,MAAM,EAAO;IASvB;;;;;OAKG;IACI,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,aAAa,CAAC,qBAAqB,CAAC;IAqD3E;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAM7B;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACI,aAAa,CAAC,OAAO,EAAE,aAAa,GAAG,aAAa,CAAC,qBAAqB,CAAC;IAWlF;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACG,UAAU,CAAC,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBxD;;OAEG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU1C;;;;;;;;;;OAUG;IACG,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAkB9B;;;;;;;;;OASG;IACH,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAI9D;;;;;;OAMG;IACH,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAIzC;;OAEG;IACH,qBAAqB,IAAI,OAAO;IAIhC;;OAEG;IACH,uBAAuB,IAAI,MAAM,EAAE;CAGpC"}
@@ -0,0 +1,221 @@
1
+ /**
2
+ * Session - High-level interface for interacting with an agent session
3
+ */
4
+ /**
5
+ * Represents an active session with an agent
6
+ */
7
+ export class Session {
8
+ id;
9
+ modes;
10
+ models;
11
+ connection;
12
+ clientHandler;
13
+ constructor(id, connection, clientHandler, modes = [], models = []) {
14
+ this.id = id;
15
+ this.connection = connection;
16
+ this.clientHandler = clientHandler;
17
+ this.modes = modes;
18
+ this.models = models;
19
+ }
20
+ /**
21
+ * Send a prompt and stream responses
22
+ *
23
+ * In interactive permission mode, this may yield PermissionRequestUpdate objects
24
+ * that require a response via respondToPermission() before the prompt can continue.
25
+ */
26
+ async *prompt(content) {
27
+ // Convert string to ContentBlock array
28
+ const promptBlocks = typeof content === "string"
29
+ ? [{ type: "text", text: content }]
30
+ : content;
31
+ // Get the session stream for updates
32
+ const stream = this.clientHandler.getSessionStream(this.id);
33
+ // Start the prompt (non-blocking, returns when complete)
34
+ const promptPromise = this.connection.prompt({
35
+ sessionId: this.id,
36
+ prompt: promptBlocks,
37
+ });
38
+ // Yield updates as they arrive
39
+ // We need to race between getting updates and the prompt completing
40
+ const updateIterator = stream[Symbol.asyncIterator]();
41
+ try {
42
+ while (true) {
43
+ // Check if prompt has completed
44
+ const raceResult = await Promise.race([
45
+ promptPromise.then((result) => ({ type: "done", result })),
46
+ updateIterator.next().then((update) => ({ type: "update", update })),
47
+ ]);
48
+ if (raceResult.type === "done") {
49
+ // Prompt completed, drain remaining updates
50
+ this.clientHandler.endSessionStream(this.id);
51
+ // Yield any remaining queued updates
52
+ let remaining = await updateIterator.next();
53
+ while (!remaining.done) {
54
+ yield remaining.value;
55
+ remaining = await updateIterator.next();
56
+ }
57
+ break;
58
+ }
59
+ else {
60
+ // Got an update
61
+ if (raceResult.update.done) {
62
+ break;
63
+ }
64
+ yield raceResult.update.value;
65
+ }
66
+ }
67
+ }
68
+ finally {
69
+ // Ensure stream is ended
70
+ this.clientHandler.endSessionStream(this.id);
71
+ }
72
+ }
73
+ /**
74
+ * Cancel the current prompt
75
+ */
76
+ async cancel() {
77
+ await this.connection.cancel({
78
+ sessionId: this.id,
79
+ });
80
+ }
81
+ /**
82
+ * Interrupt the current prompt and start a new one with additional context.
83
+ *
84
+ * This cancels any in-progress prompt and immediately starts a new prompt.
85
+ * The agent will restart its work but retains the conversation history.
86
+ *
87
+ * Use this when you need to redirect or add context to the agent's work.
88
+ *
89
+ * @param content - The new prompt content (can reference or build upon previous context)
90
+ * @returns AsyncIterable of session updates for the new prompt
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * // Original prompt running
95
+ * for await (const update of session.prompt("Analyze the codebase")) {
96
+ * handleUpdate(update);
97
+ * if (userWantsToRedirect) {
98
+ * // Interrupt and redirect
99
+ * for await (const update of session.interruptWith("Focus only on the /src directory")) {
100
+ * handleUpdate(update);
101
+ * }
102
+ * break;
103
+ * }
104
+ * }
105
+ * ```
106
+ */
107
+ async *interruptWith(content) {
108
+ // Cancel any in-progress prompt
109
+ await this.cancel();
110
+ // Small delay to allow cancellation to propagate
111
+ await new Promise((resolve) => setTimeout(resolve, 50));
112
+ // Start new prompt and yield its updates
113
+ yield* this.prompt(content);
114
+ }
115
+ /**
116
+ * Add context to the agent while it's working (without interrupting).
117
+ *
118
+ * NOTE: This feature requires agent support for mid-execution messaging.
119
+ * Currently, claude-code-acp does not support this. When called, this method
120
+ * will throw an error. Use `interruptWith()` as an alternative.
121
+ *
122
+ * In the future, when agent adapters support the `_session/addContext` extension,
123
+ * this method will push context to the agent without cancelling current work.
124
+ *
125
+ * @param content - Additional context to send to the agent
126
+ * @throws Error - Always throws until agent support is available
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * // Future usage (not yet supported):
131
+ * for await (const update of session.prompt("Analyze the codebase")) {
132
+ * handleUpdate(update);
133
+ * if (userHasAdditionalContext) {
134
+ * // Add context without interrupting (future)
135
+ * await session.addContext("Also check the test coverage");
136
+ * }
137
+ * }
138
+ * ```
139
+ */
140
+ async addContext(_content) {
141
+ // TODO: When claude-code-acp supports _session/addContext extension,
142
+ // implement this using:
143
+ // await this.connection.extMethod("session/addContext", {
144
+ // sessionId: this.id,
145
+ // content: typeof _content === "string"
146
+ // ? [{ type: "text", text: _content }]
147
+ // : _content,
148
+ // });
149
+ throw new Error("addContext() is not yet supported. The agent adapter must implement the " +
150
+ "'_session/addContext' extension method. Use interruptWith() as an alternative, " +
151
+ "which cancels the current prompt and starts a new one.");
152
+ }
153
+ /**
154
+ * Set the session mode
155
+ */
156
+ async setMode(mode) {
157
+ if (!this.connection.setSessionMode) {
158
+ throw new Error("Agent does not support setting session mode");
159
+ }
160
+ await this.connection.setSessionMode({
161
+ sessionId: this.id,
162
+ modeId: mode,
163
+ });
164
+ }
165
+ /**
166
+ * Fork this session to create a new independent session
167
+ *
168
+ * The forked session inherits the conversation history, allowing
169
+ * operations like generating summaries without affecting this session.
170
+ *
171
+ * Note: This creates a new Session object - the original session
172
+ * remains active and can continue independently.
173
+ *
174
+ * @experimental This relies on the unstable session/fork ACP capability
175
+ */
176
+ async fork() {
177
+ if (!this.connection.forkSession) {
178
+ throw new Error("Agent does not support forking sessions");
179
+ }
180
+ const result = await this.connection.forkSession({
181
+ sessionId: this.id,
182
+ });
183
+ return new Session(result.sessionId, this.connection, this.clientHandler, result.modes?.availableModes?.map((m) => m.id) ?? [], result.models?.availableModels?.map((m) => m.modelId) ?? []);
184
+ }
185
+ /**
186
+ * Respond to a permission request (for interactive permission mode)
187
+ *
188
+ * When using permissionMode: "interactive", permission requests are emitted
189
+ * as session updates with sessionUpdate: "permission_request". Call this method
190
+ * with the requestId and your chosen optionId to allow the prompt to continue.
191
+ *
192
+ * @param requestId - The requestId from the PermissionRequestUpdate
193
+ * @param optionId - The optionId of the selected permission option
194
+ */
195
+ respondToPermission(requestId, optionId) {
196
+ this.clientHandler.respondToPermission(requestId, optionId);
197
+ }
198
+ /**
199
+ * Cancel a permission request (for interactive permission mode)
200
+ *
201
+ * This will cancel the permission request, which typically aborts the tool call.
202
+ *
203
+ * @param requestId - The requestId from the PermissionRequestUpdate
204
+ */
205
+ cancelPermission(requestId) {
206
+ this.clientHandler.cancelPermission(requestId);
207
+ }
208
+ /**
209
+ * Check if there are any pending permission requests for this session
210
+ */
211
+ hasPendingPermissions() {
212
+ return this.clientHandler.getPendingPermissionIds(this.id).length > 0;
213
+ }
214
+ /**
215
+ * Get all pending permission request IDs for this session
216
+ */
217
+ getPendingPermissionIds() {
218
+ return this.clientHandler.getPendingPermissionIds(this.id);
219
+ }
220
+ }
221
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH;;GAEG;AACH,MAAM,OAAO,OAAO;IACT,EAAE,CAAS;IACX,KAAK,CAAW;IAChB,MAAM,CAAW;IAET,UAAU,CAA2B;IACrC,aAAa,CAAmB;IAEjD,YACE,EAAU,EACV,UAAoC,EACpC,aAA+B,EAC/B,QAAkB,EAAE,EACpB,SAAmB,EAAE;QAErB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,CAAC,MAAM,CAAC,OAAsB;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,qBAAqB;QACnB,OAAO,IAAI,CAAC,aAAa,CAAC,uBAAuB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IACxE,CAAC;IAED;;OAEG;IACH,uBAAuB;QACrB,OAAO,IAAI,CAAC,aAAa,CAAC,uBAAuB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC7D,CAAC;CACF"}
@@ -0,0 +1,154 @@
1
+ /**
2
+ * Type definitions for acp-factory
3
+ */
4
+ import type * as acp from "@agentclientprotocol/sdk";
5
+ export type {
6
+ /** Updates streamed during prompt processing */
7
+ SessionUpdate,
8
+ /** Content blocks in prompts and responses */
9
+ ContentBlock,
10
+ /** Text content block */
11
+ TextContent,
12
+ /** Image content block */
13
+ ImageContent,
14
+ /** Resource link content block */
15
+ ResourceLink,
16
+ /** Agent capabilities advertised during initialization */
17
+ AgentCapabilities,
18
+ /** Reason why prompt processing stopped */
19
+ StopReason, } from "@agentclientprotocol/sdk";
20
+ export type {
21
+ /** A tool call initiated by the agent */
22
+ ToolCall,
23
+ /** Update to a tool call's status or content */
24
+ ToolCallUpdate,
25
+ /** Status of a tool call */
26
+ ToolCallStatus,
27
+ /** Content returned by a tool */
28
+ ToolCallContent,
29
+ /** Location affected by a tool call */
30
+ ToolCallLocation, } from "@agentclientprotocol/sdk";
31
+ export type {
32
+ /** Request for user permission */
33
+ RequestPermissionRequest,
34
+ /** Response to permission request */
35
+ RequestPermissionResponse,
36
+ /** A permission option presented to the user */
37
+ PermissionOption, } from "@agentclientprotocol/sdk";
38
+ export type {
39
+ /** Request to create a terminal */
40
+ CreateTerminalRequest,
41
+ /** Response with terminal ID */
42
+ CreateTerminalResponse,
43
+ /** Request for terminal output */
44
+ TerminalOutputRequest,
45
+ /** Response with terminal output */
46
+ TerminalOutputResponse, } from "@agentclientprotocol/sdk";
47
+ export type {
48
+ /** MCP server configuration (stdio, HTTP, or SSE) */
49
+ McpServer,
50
+ /** MCP server over stdio */
51
+ McpServerStdio,
52
+ /** MCP server over HTTP */
53
+ McpServerHttp,
54
+ /** MCP server over SSE */
55
+ McpServerSse, } from "@agentclientprotocol/sdk";
56
+ export type {
57
+ /** Response when creating a new session */
58
+ NewSessionResponse,
59
+ /** Response after prompt processing completes */
60
+ PromptResponse,
61
+ /** Request to initialize the connection */
62
+ InitializeRequest,
63
+ /** Response to initialization */
64
+ InitializeResponse,
65
+ /** Request to fork an existing session (UNSTABLE) */
66
+ ForkSessionRequest,
67
+ /** Response from forking a session (UNSTABLE) */
68
+ ForkSessionResponse, } from "@agentclientprotocol/sdk";
69
+ /**
70
+ * Configuration for spawning an agent
71
+ */
72
+ export interface AgentConfig {
73
+ /** Command to execute (e.g., "npx") */
74
+ command: string;
75
+ /** Arguments for the command (e.g., ["claude-code-acp"]) */
76
+ args: string[];
77
+ /** Environment variables to set */
78
+ env?: Record<string, string>;
79
+ }
80
+ /**
81
+ * Permission handling mode
82
+ * - "auto-approve": Automatically approve all permission requests
83
+ * - "auto-deny": Automatically deny all permission requests
84
+ * - "callback": Use the onPermissionRequest callback handler
85
+ * - "interactive": Emit permission requests as session updates for UI handling
86
+ */
87
+ export type PermissionMode = "auto-approve" | "auto-deny" | "callback" | "interactive";
88
+ /**
89
+ * A permission request emitted as a session update (for interactive mode)
90
+ */
91
+ export interface PermissionRequestUpdate {
92
+ sessionUpdate: "permission_request";
93
+ /** Unique ID for this permission request (use to respond) */
94
+ requestId: string;
95
+ /** Session this request belongs to */
96
+ sessionId: string;
97
+ /** The tool call that triggered this permission request */
98
+ toolCall: {
99
+ toolCallId: string;
100
+ title: string;
101
+ status: string;
102
+ rawInput?: unknown;
103
+ };
104
+ /** Available options for the user to choose from */
105
+ options: acp.PermissionOption[];
106
+ }
107
+ /**
108
+ * Extended session update type that includes permission requests
109
+ */
110
+ export type ExtendedSessionUpdate = acp.SessionUpdate | PermissionRequestUpdate;
111
+ /**
112
+ * Handlers for client-side operations
113
+ */
114
+ export interface ClientHandlers {
115
+ /** Handle permission requests from the agent */
116
+ onPermissionRequest?: (request: acp.RequestPermissionRequest) => Promise<acp.RequestPermissionResponse>;
117
+ /** Handle file read requests */
118
+ onFileRead?: (path: string) => Promise<string>;
119
+ /** Handle file write requests */
120
+ onFileWrite?: (path: string, content: string) => Promise<void>;
121
+ /** Handle terminal creation requests */
122
+ onTerminalCreate?: (params: acp.CreateTerminalRequest) => Promise<acp.CreateTerminalResponse>;
123
+ /** Handle terminal output requests */
124
+ onTerminalOutput?: (terminalId: string) => Promise<string>;
125
+ /** Handle terminal kill requests */
126
+ onTerminalKill?: (terminalId: string) => Promise<void>;
127
+ /** Handle terminal release requests */
128
+ onTerminalRelease?: (terminalId: string) => Promise<void>;
129
+ /** Handle terminal wait for exit requests */
130
+ onTerminalWaitForExit?: (terminalId: string) => Promise<number>;
131
+ }
132
+ /**
133
+ * Options for spawning an agent
134
+ */
135
+ export interface SpawnOptions extends ClientHandlers {
136
+ /** Environment variables to merge with agent config */
137
+ env?: Record<string, string>;
138
+ /** Permission handling mode (default: "auto-approve") */
139
+ permissionMode?: PermissionMode;
140
+ }
141
+ /**
142
+ * Options for creating a session
143
+ */
144
+ export interface SessionOptions {
145
+ /** MCP servers to connect */
146
+ mcpServers?: acp.McpServer[];
147
+ /** Initial mode for the session */
148
+ mode?: string;
149
+ }
150
+ /**
151
+ * Content that can be sent as a prompt
152
+ */
153
+ export type PromptContent = string | acp.ContentBlock[];
154
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,KAAK,GAAG,MAAM,0BAA0B,CAAC;AAOrD,YAAY;AACV,gDAAgD;AAChD,aAAa;AACb,8CAA8C;AAC9C,YAAY;AACZ,yBAAyB;AACzB,WAAW;AACX,0BAA0B;AAC1B,YAAY;AACZ,kCAAkC;AAClC,YAAY;AACZ,0DAA0D;AAC1D,iBAAiB;AACjB,2C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CAAC,CAAC;IAE1D,6CAA6C;IAC7C,qBAAqB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CACjE;AAED;;GAEG;AACH,MAAM,WAAW,YAAa,SAAQ,cAAc;IAClD,uDAAuD;IACvD,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,yDAAyD;IACzD,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,6BAA6B;IAC7B,UAAU,CAAC,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC;IAC7B,mCAAmC;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Type definitions for acp-factory
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "acp-factory",
3
+ "version": "0.0.1",
4
+ "description": "A library for spawning and managing agents through the Agent Client Protocol (ACP)",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist/",
16
+ "README.md",
17
+ "LICENSE",
18
+ "CHANGELOG.md"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsc",
22
+ "dev": "tsc --watch",
23
+ "test": "vitest",
24
+ "test:run": "vitest run",
25
+ "lint": "eslint src --ext .ts",
26
+ "lint:fix": "eslint src --ext .ts --fix",
27
+ "clean": "rm -rf dist",
28
+ "prebuild": "npm run clean",
29
+ "pretest:run": "npm run build",
30
+ "prepublishOnly": "npm run test:run && npm run build",
31
+ "version": "npm run build",
32
+ "postversion": "git push && git push --tags",
33
+ "release:patch": "npm version patch",
34
+ "release:minor": "npm version minor",
35
+ "release:major": "npm version major",
36
+ "publish:dry": "npm publish --dry-run",
37
+ "publish:npm": "npm publish --access public"
38
+ },
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/sudocode-ai/acp-factory.git"
42
+ },
43
+ "bugs": {
44
+ "url": "https://github.com/sudocode-ai/acp-factory/issues"
45
+ },
46
+ "homepage": "https://github.com/sudocode-ai/acp-factory#readme",
47
+ "keywords": [
48
+ "acp",
49
+ "agent",
50
+ "agent-client-protocol",
51
+ "claude",
52
+ "claude-code",
53
+ "ai",
54
+ "llm",
55
+ "typescript",
56
+ "sdk"
57
+ ],
58
+ "author": "Sudocode AI",
59
+ "license": "MIT",
60
+ "engines": {
61
+ "node": ">=18.0.0"
62
+ },
63
+ "dependencies": {
64
+ "@agentclientprotocol/sdk": "^0.10.0"
65
+ },
66
+ "devDependencies": {
67
+ "@types/node": "^22.0.0",
68
+ "typescript": "^5.7.0",
69
+ "vitest": "^2.0.0"
70
+ }
71
+ }