thinkwell 0.1.0
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 +30 -0
- package/dist/agent.d.ts +188 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +298 -0
- package/dist/agent.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/patchwork.d.ts +55 -0
- package/dist/patchwork.d.ts.map +1 -0
- package/dist/patchwork.js +64 -0
- package/dist/patchwork.js.map +1 -0
- package/dist/schema.d.ts +35 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +38 -0
- package/dist/schema.js.map +1 -0
- package/dist/session.d.ts +78 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +65 -0
- package/dist/session.js.map +1 -0
- package/dist/think-builder.d.ts +150 -0
- package/dist/think-builder.d.ts.map +1 -0
- package/dist/think-builder.js +322 -0
- package/dist/think-builder.js.map +1 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<p>
|
|
2
|
+
<img src="assets/logo.jpg" alt="Thinkwell Logo" width="200">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
A TypeScript library for easy scripting of AI agents. Thinkwell provides a fluent API for blending deterministic code with LLM-powered reasoning.
|
|
6
|
+
|
|
7
|
+
## Quick Start
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { Agent, schemaOf } from "thinkwell";
|
|
11
|
+
|
|
12
|
+
const agent = await Agent.connect("npx -y @zed-industries/claude-code-acp");
|
|
13
|
+
|
|
14
|
+
const result = await agent
|
|
15
|
+
.think(schemaOf<{ greeting: string }>({
|
|
16
|
+
type: "object",
|
|
17
|
+
properties: { greeting: { type: "string" } },
|
|
18
|
+
required: ["greeting"]
|
|
19
|
+
}))
|
|
20
|
+
.text("Say hello!")
|
|
21
|
+
.run();
|
|
22
|
+
|
|
23
|
+
console.log(result.greeting);
|
|
24
|
+
|
|
25
|
+
agent.close();
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
# License
|
|
29
|
+
|
|
30
|
+
MIT
|
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { type ChildProcess } from "node:child_process";
|
|
2
|
+
import { ClientSideConnection } from "@agentclientprotocol/sdk";
|
|
3
|
+
import { McpOverAcpHandler, type SchemaProvider, type SessionUpdate } from "@thinkwell/acp";
|
|
4
|
+
import { ThinkBuilder } from "./think-builder.js";
|
|
5
|
+
import { Session } from "./session.js";
|
|
6
|
+
/**
|
|
7
|
+
* Options for connecting to an agent
|
|
8
|
+
*/
|
|
9
|
+
export interface ConnectOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Path to the conductor binary.
|
|
12
|
+
* If not specified, uses SACP_CONDUCTOR_PATH env var or searches PATH.
|
|
13
|
+
*/
|
|
14
|
+
conductorPath?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Environment variables for the agent process
|
|
17
|
+
*/
|
|
18
|
+
env?: Record<string, string>;
|
|
19
|
+
/**
|
|
20
|
+
* Connection timeout in milliseconds
|
|
21
|
+
*/
|
|
22
|
+
timeout?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Options for creating a session
|
|
26
|
+
*/
|
|
27
|
+
export interface SessionOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Working directory for the session
|
|
30
|
+
*/
|
|
31
|
+
cwd?: string;
|
|
32
|
+
/**
|
|
33
|
+
* System prompt for the session
|
|
34
|
+
*/
|
|
35
|
+
systemPrompt?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Interface for handling session updates
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export interface SessionHandler {
|
|
42
|
+
pushUpdate(update: SessionUpdate): void;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Internal connection state shared between Agent and Session
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
export interface AgentConnection {
|
|
49
|
+
process: ChildProcess;
|
|
50
|
+
connection: ClientSideConnection;
|
|
51
|
+
mcpHandler: McpOverAcpHandler;
|
|
52
|
+
sessionHandlers: Map<string, SessionHandler>;
|
|
53
|
+
initialized: boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The main entry point for Patchwork.
|
|
57
|
+
*
|
|
58
|
+
* Agent represents a connection to an AI agent (like Claude Code) and provides
|
|
59
|
+
* a fluent API for blending deterministic code with LLM-powered reasoning.
|
|
60
|
+
*
|
|
61
|
+
* @example Simple usage with ephemeral sessions
|
|
62
|
+
* ```typescript
|
|
63
|
+
* import { Agent, schemaOf } from "@anthropic/patchwork";
|
|
64
|
+
*
|
|
65
|
+
* const agent = await Agent.connect("npx -y @zed-industries/claude-code-acp");
|
|
66
|
+
*
|
|
67
|
+
* const summary = await agent
|
|
68
|
+
* .think(schemaOf<{ title: string; points: string[] }>({
|
|
69
|
+
* type: "object",
|
|
70
|
+
* properties: {
|
|
71
|
+
* title: { type: "string" },
|
|
72
|
+
* points: { type: "array", items: { type: "string" } }
|
|
73
|
+
* },
|
|
74
|
+
* required: ["title", "points"]
|
|
75
|
+
* }))
|
|
76
|
+
* .text("Summarize this document:")
|
|
77
|
+
* .quote(document)
|
|
78
|
+
* .run();
|
|
79
|
+
*
|
|
80
|
+
* agent.close();
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @example Multi-turn conversation with explicit session
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const agent = await Agent.connect("npx -y @zed-industries/claude-code-acp");
|
|
86
|
+
* const session = await agent.createSession({ cwd: "/my/project" });
|
|
87
|
+
*
|
|
88
|
+
* const analysis = await session
|
|
89
|
+
* .think(AnalysisSchema)
|
|
90
|
+
* .text("Analyze this codebase")
|
|
91
|
+
* .run();
|
|
92
|
+
*
|
|
93
|
+
* // Same session - agent remembers context
|
|
94
|
+
* const fixes = await session
|
|
95
|
+
* .think(FixesSchema)
|
|
96
|
+
* .text("Suggest fixes for the top issues")
|
|
97
|
+
* .run();
|
|
98
|
+
*
|
|
99
|
+
* session.close();
|
|
100
|
+
* agent.close();
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare class Agent {
|
|
104
|
+
private readonly _conn;
|
|
105
|
+
private constructor();
|
|
106
|
+
/**
|
|
107
|
+
* Connect to an agent.
|
|
108
|
+
*
|
|
109
|
+
* @param command - The command to spawn the agent process (e.g., "npx -y @zed-industries/claude-code-acp")
|
|
110
|
+
* @param options - Connection options
|
|
111
|
+
* @returns A connected Agent instance
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const agent = await Agent.connect("npx -y @zed-industries/claude-code-acp");
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
static connect(command: string, options?: ConnectOptions): Promise<Agent>;
|
|
119
|
+
/**
|
|
120
|
+
* Create a new think builder for constructing a prompt with tools.
|
|
121
|
+
*
|
|
122
|
+
* Each call to `think()` creates an ephemeral session that is automatically
|
|
123
|
+
* closed when the prompt completes. For multi-turn conversations, use
|
|
124
|
+
* `createSession()` instead.
|
|
125
|
+
*
|
|
126
|
+
* @param schema - A SchemaProvider that defines the expected output structure
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const result = await agent
|
|
131
|
+
* .think(schemaOf<{ answer: string }>({
|
|
132
|
+
* type: "object",
|
|
133
|
+
* properties: { answer: { type: "string" } },
|
|
134
|
+
* required: ["answer"]
|
|
135
|
+
* }))
|
|
136
|
+
* .text("What is 2 + 2?")
|
|
137
|
+
* .run();
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
think<Output>(schema: SchemaProvider<Output>): ThinkBuilder<Output>;
|
|
141
|
+
/**
|
|
142
|
+
* Create a new think builder without a schema.
|
|
143
|
+
*
|
|
144
|
+
* @deprecated Use `think(schemaOf<T>(schema))` instead to provide a typed schema.
|
|
145
|
+
*/
|
|
146
|
+
think<Output>(): ThinkBuilder<Output>;
|
|
147
|
+
/**
|
|
148
|
+
* Create a new session for multi-turn conversations.
|
|
149
|
+
*
|
|
150
|
+
* Sessions maintain conversation context across multiple `think()` calls,
|
|
151
|
+
* allowing the agent to remember previous interactions.
|
|
152
|
+
*
|
|
153
|
+
* @param options - Session configuration options
|
|
154
|
+
* @returns A Session instance
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* const session = await agent.createSession({ cwd: "/my/project" });
|
|
159
|
+
*
|
|
160
|
+
* // First turn
|
|
161
|
+
* const result1 = await session.think(Schema1).text("...").run();
|
|
162
|
+
*
|
|
163
|
+
* // Second turn - agent remembers context
|
|
164
|
+
* const result2 = await session.think(Schema2).text("...").run();
|
|
165
|
+
*
|
|
166
|
+
* session.close();
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
createSession(options?: SessionOptions): Promise<Session>;
|
|
170
|
+
/**
|
|
171
|
+
* Close the connection to the agent.
|
|
172
|
+
*
|
|
173
|
+
* This terminates the conductor process. Any active sessions will be
|
|
174
|
+
* invalidated.
|
|
175
|
+
*/
|
|
176
|
+
close(): void;
|
|
177
|
+
/**
|
|
178
|
+
* Get the internal connection for use by ThinkBuilder
|
|
179
|
+
* @internal
|
|
180
|
+
*/
|
|
181
|
+
get _connection(): AgentConnection;
|
|
182
|
+
/**
|
|
183
|
+
* Initialize the connection (negotiate protocol version)
|
|
184
|
+
* @internal
|
|
185
|
+
*/
|
|
186
|
+
_initialize(): Promise<void>;
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,YA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;;;;;;;;;;;;;;;;;OAoBG;IACH,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC,MAAM,CAAC;IAEnE;;;;OAIG;IACH,KAAK,CAAC,MAAM,KAAK,YAAY,CAAC,MAAM,CAAC;IAMrC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACG,aAAa,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC;IAY/D;;;;;OAKG;IACH,KAAK,IAAI,IAAI;IAIb;;;OAGG;IACH,IAAI,WAAW,IAAI,eAAe,CAEjC;IAED;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;CAUnC"}
|
package/dist/agent.js
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { ClientSideConnection, ndJsonStream, } from "@agentclientprotocol/sdk";
|
|
3
|
+
import { McpOverAcpHandler, } from "@thinkwell/acp";
|
|
4
|
+
import { ThinkBuilder } from "./think-builder.js";
|
|
5
|
+
import { Session } from "./session.js";
|
|
6
|
+
/**
|
|
7
|
+
* The main entry point for Patchwork.
|
|
8
|
+
*
|
|
9
|
+
* Agent represents a connection to an AI agent (like Claude Code) and provides
|
|
10
|
+
* a fluent API for blending deterministic code with LLM-powered reasoning.
|
|
11
|
+
*
|
|
12
|
+
* @example Simple usage with ephemeral sessions
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { Agent, schemaOf } from "@anthropic/patchwork";
|
|
15
|
+
*
|
|
16
|
+
* const agent = await Agent.connect("npx -y @zed-industries/claude-code-acp");
|
|
17
|
+
*
|
|
18
|
+
* const summary = await agent
|
|
19
|
+
* .think(schemaOf<{ title: string; points: string[] }>({
|
|
20
|
+
* type: "object",
|
|
21
|
+
* properties: {
|
|
22
|
+
* title: { type: "string" },
|
|
23
|
+
* points: { type: "array", items: { type: "string" } }
|
|
24
|
+
* },
|
|
25
|
+
* required: ["title", "points"]
|
|
26
|
+
* }))
|
|
27
|
+
* .text("Summarize this document:")
|
|
28
|
+
* .quote(document)
|
|
29
|
+
* .run();
|
|
30
|
+
*
|
|
31
|
+
* agent.close();
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @example Multi-turn conversation with explicit session
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const agent = await Agent.connect("npx -y @zed-industries/claude-code-acp");
|
|
37
|
+
* const session = await agent.createSession({ cwd: "/my/project" });
|
|
38
|
+
*
|
|
39
|
+
* const analysis = await session
|
|
40
|
+
* .think(AnalysisSchema)
|
|
41
|
+
* .text("Analyze this codebase")
|
|
42
|
+
* .run();
|
|
43
|
+
*
|
|
44
|
+
* // Same session - agent remembers context
|
|
45
|
+
* const fixes = await session
|
|
46
|
+
* .think(FixesSchema)
|
|
47
|
+
* .text("Suggest fixes for the top issues")
|
|
48
|
+
* .run();
|
|
49
|
+
*
|
|
50
|
+
* session.close();
|
|
51
|
+
* agent.close();
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export class Agent {
|
|
55
|
+
_conn;
|
|
56
|
+
constructor(conn) {
|
|
57
|
+
this._conn = conn;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Connect to an agent.
|
|
61
|
+
*
|
|
62
|
+
* @param command - The command to spawn the agent process (e.g., "npx -y @zed-industries/claude-code-acp")
|
|
63
|
+
* @param options - Connection options
|
|
64
|
+
* @returns A connected Agent instance
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const agent = await Agent.connect("npx -y @zed-industries/claude-code-acp");
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
static async connect(command, options) {
|
|
72
|
+
const conductorPath = findConductor(options?.conductorPath);
|
|
73
|
+
const conductorArgs = ["agent", command];
|
|
74
|
+
const childProcess = spawn(conductorPath, conductorArgs, {
|
|
75
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
76
|
+
env: options?.env ? { ...process.env, ...options.env } : process.env,
|
|
77
|
+
});
|
|
78
|
+
if (!childProcess.stdout || !childProcess.stdin) {
|
|
79
|
+
throw new Error("Conductor process must have stdio");
|
|
80
|
+
}
|
|
81
|
+
// Log stderr for debugging
|
|
82
|
+
childProcess.stderr?.on("data", (data) => {
|
|
83
|
+
console.error("[conductor stderr]", data.toString());
|
|
84
|
+
});
|
|
85
|
+
// Convert Node streams to Web streams for the SDK
|
|
86
|
+
const { readable, writable } = nodeToWebStreams(childProcess.stdout, childProcess.stdin);
|
|
87
|
+
// Create the ndjson stream
|
|
88
|
+
const stream = ndJsonStream(writable, readable);
|
|
89
|
+
// Create the MCP handler
|
|
90
|
+
const mcpHandler = new McpOverAcpHandler();
|
|
91
|
+
// Build the connection state
|
|
92
|
+
const conn = {
|
|
93
|
+
process: childProcess,
|
|
94
|
+
connection: null, // Set below after creating the client
|
|
95
|
+
mcpHandler,
|
|
96
|
+
sessionHandlers: new Map(),
|
|
97
|
+
initialized: false,
|
|
98
|
+
};
|
|
99
|
+
// Create the ACP client connection
|
|
100
|
+
const clientConnection = new ClientSideConnection((_agent) => createClient(conn, mcpHandler), stream);
|
|
101
|
+
conn.connection = clientConnection;
|
|
102
|
+
return new Agent(conn);
|
|
103
|
+
}
|
|
104
|
+
think(schema) {
|
|
105
|
+
return new ThinkBuilder(this._conn, schema);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Create a new session for multi-turn conversations.
|
|
109
|
+
*
|
|
110
|
+
* Sessions maintain conversation context across multiple `think()` calls,
|
|
111
|
+
* allowing the agent to remember previous interactions.
|
|
112
|
+
*
|
|
113
|
+
* @param options - Session configuration options
|
|
114
|
+
* @returns A Session instance
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const session = await agent.createSession({ cwd: "/my/project" });
|
|
119
|
+
*
|
|
120
|
+
* // First turn
|
|
121
|
+
* const result1 = await session.think(Schema1).text("...").run();
|
|
122
|
+
*
|
|
123
|
+
* // Second turn - agent remembers context
|
|
124
|
+
* const result2 = await session.think(Schema2).text("...").run();
|
|
125
|
+
*
|
|
126
|
+
* session.close();
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
async createSession(options) {
|
|
130
|
+
await this._initialize();
|
|
131
|
+
const request = {
|
|
132
|
+
cwd: options?.cwd ?? process.cwd(),
|
|
133
|
+
mcpServers: [],
|
|
134
|
+
};
|
|
135
|
+
const response = await this._conn.connection.newSession(request);
|
|
136
|
+
return new Session(this._conn, response.sessionId, options);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Close the connection to the agent.
|
|
140
|
+
*
|
|
141
|
+
* This terminates the conductor process. Any active sessions will be
|
|
142
|
+
* invalidated.
|
|
143
|
+
*/
|
|
144
|
+
close() {
|
|
145
|
+
this._conn.process.kill();
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get the internal connection for use by ThinkBuilder
|
|
149
|
+
* @internal
|
|
150
|
+
*/
|
|
151
|
+
get _connection() {
|
|
152
|
+
return this._conn;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Initialize the connection (negotiate protocol version)
|
|
156
|
+
* @internal
|
|
157
|
+
*/
|
|
158
|
+
async _initialize() {
|
|
159
|
+
if (this._conn.initialized)
|
|
160
|
+
return;
|
|
161
|
+
await this._conn.connection.initialize({
|
|
162
|
+
protocolVersion: 1,
|
|
163
|
+
clientCapabilities: {},
|
|
164
|
+
});
|
|
165
|
+
this._conn.initialized = true;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Find the conductor binary
|
|
170
|
+
*/
|
|
171
|
+
function findConductor(explicitPath) {
|
|
172
|
+
// 1. Use explicit path if provided
|
|
173
|
+
if (explicitPath) {
|
|
174
|
+
return explicitPath;
|
|
175
|
+
}
|
|
176
|
+
// 2. Check environment variable
|
|
177
|
+
const envPath = process.env.SACP_CONDUCTOR_PATH;
|
|
178
|
+
if (envPath) {
|
|
179
|
+
return envPath;
|
|
180
|
+
}
|
|
181
|
+
// 3. Assume it's in PATH
|
|
182
|
+
return "sacp-conductor";
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Convert Node.js streams to Web Streams for the ACP SDK
|
|
186
|
+
*/
|
|
187
|
+
function nodeToWebStreams(stdout, stdin) {
|
|
188
|
+
const readable = new ReadableStream({
|
|
189
|
+
start(controller) {
|
|
190
|
+
stdout.on("data", (chunk) => {
|
|
191
|
+
controller.enqueue(new Uint8Array(chunk));
|
|
192
|
+
});
|
|
193
|
+
stdout.on("end", () => {
|
|
194
|
+
controller.close();
|
|
195
|
+
});
|
|
196
|
+
stdout.on("error", (err) => {
|
|
197
|
+
controller.error(err);
|
|
198
|
+
});
|
|
199
|
+
},
|
|
200
|
+
cancel() {
|
|
201
|
+
stdout.destroy();
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
const writable = new WritableStream({
|
|
205
|
+
write(chunk) {
|
|
206
|
+
return new Promise((resolve, reject) => {
|
|
207
|
+
stdin.write(Buffer.from(chunk), (err) => {
|
|
208
|
+
if (err)
|
|
209
|
+
reject(err);
|
|
210
|
+
else
|
|
211
|
+
resolve();
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
},
|
|
215
|
+
close() {
|
|
216
|
+
return new Promise((resolve) => {
|
|
217
|
+
stdin.end(() => resolve());
|
|
218
|
+
});
|
|
219
|
+
},
|
|
220
|
+
abort(reason) {
|
|
221
|
+
stdin.destroy(reason instanceof Error ? reason : new Error(String(reason)));
|
|
222
|
+
},
|
|
223
|
+
});
|
|
224
|
+
return { readable, writable };
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Create a Client implementation that handles incoming agent requests
|
|
228
|
+
*/
|
|
229
|
+
function createClient(conn, mcpHandler) {
|
|
230
|
+
return {
|
|
231
|
+
sessionUpdate(notification) {
|
|
232
|
+
const { sessionId } = notification;
|
|
233
|
+
const handler = conn.sessionHandlers.get(sessionId);
|
|
234
|
+
if (!handler) {
|
|
235
|
+
console.error(`No handler for session: ${sessionId}`);
|
|
236
|
+
return Promise.resolve();
|
|
237
|
+
}
|
|
238
|
+
const update = convertNotification(notification);
|
|
239
|
+
if (update) {
|
|
240
|
+
handler.pushUpdate(update);
|
|
241
|
+
}
|
|
242
|
+
return Promise.resolve();
|
|
243
|
+
},
|
|
244
|
+
requestPermission(request) {
|
|
245
|
+
const firstOption = request.options[0];
|
|
246
|
+
return Promise.resolve({
|
|
247
|
+
outcome: {
|
|
248
|
+
outcome: "selected",
|
|
249
|
+
optionId: firstOption?.optionId ?? "approve",
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
},
|
|
253
|
+
async extMethod(method, params) {
|
|
254
|
+
if (mcpHandler.isMcpRequest(method)) {
|
|
255
|
+
const result = await mcpHandler.routeRequest(method, params);
|
|
256
|
+
return result ?? {};
|
|
257
|
+
}
|
|
258
|
+
throw new Error(`Unknown extension method: ${method}`);
|
|
259
|
+
},
|
|
260
|
+
async extNotification(method, params) {
|
|
261
|
+
if (mcpHandler.isMcpRequest(method)) {
|
|
262
|
+
await mcpHandler.routeRequest(method, params);
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Convert ACP notification to SessionUpdate
|
|
269
|
+
*/
|
|
270
|
+
function convertNotification(notification) {
|
|
271
|
+
const { update } = notification;
|
|
272
|
+
switch (update.sessionUpdate) {
|
|
273
|
+
case "agent_message_chunk":
|
|
274
|
+
case "user_message_chunk":
|
|
275
|
+
case "agent_thought_chunk": {
|
|
276
|
+
const content = update.content;
|
|
277
|
+
if (content.type === "text") {
|
|
278
|
+
return { type: "text", content: content.text };
|
|
279
|
+
}
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
case "tool_call": {
|
|
283
|
+
return {
|
|
284
|
+
type: "tool_use",
|
|
285
|
+
id: update.toolCallId,
|
|
286
|
+
name: update.title,
|
|
287
|
+
input: update.rawInput ?? {},
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
case "plan":
|
|
291
|
+
case "tool_call_update":
|
|
292
|
+
case "available_commands_update":
|
|
293
|
+
case "current_mode_update":
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EACL,oBAAoB,EACpB,YAAY,GAUb,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,iBAAiB,GAGlB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AA0DvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,OAAO,KAAK;IACC,KAAK,CAAkB;IAExC,YAAoB,IAAqB;QACvC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAe,EAAE,OAAwB;QAC5D,MAAM,aAAa,GAAG,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;QAC5D,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAEzC,MAAM,YAAY,GAAG,KAAK,CAAC,aAAa,EAAE,aAAa,EAAE;YACvD,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;YAC/B,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG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I,CAAC;AACd,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Agent } from "./agent.js";
|
|
2
|
+
export type { ConnectOptions, SessionOptions } from "./agent.js";
|
|
3
|
+
export { Session } from "./session.js";
|
|
4
|
+
export { ThinkBuilder } from "./think-builder.js";
|
|
5
|
+
export { schemaOf } from "./schema.js";
|
|
6
|
+
export type { JsonSchema, SchemaProvider, JsonValue, JsonObject } from "@thinkwell/acp";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,gBAAgB;AAChB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,iBAAiB;AACjB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Agent } from "./agent.js";
|
|
2
|
+
import type { SchemaProvider } from "@thinkwell/acp";
|
|
3
|
+
import { ThinkBuilder } from "./think-builder.js";
|
|
4
|
+
/**
|
|
5
|
+
* Main entry point for creating patchwork instances.
|
|
6
|
+
*
|
|
7
|
+
* @deprecated Use Agent instead. This class will be removed in the next major version.
|
|
8
|
+
*
|
|
9
|
+
* Patchwork provides a fluent API for blending deterministic code
|
|
10
|
+
* with LLM-powered reasoning.
|
|
11
|
+
*/
|
|
12
|
+
export declare class Patchwork {
|
|
13
|
+
private readonly _agent;
|
|
14
|
+
/** @internal */
|
|
15
|
+
constructor(agent: Agent);
|
|
16
|
+
/**
|
|
17
|
+
* Create a new think builder for constructing a prompt with tools.
|
|
18
|
+
*
|
|
19
|
+
* @param schema - A SchemaProvider that defines the expected output structure
|
|
20
|
+
*
|
|
21
|
+
* @deprecated Use Agent.think() instead.
|
|
22
|
+
*/
|
|
23
|
+
think<Output>(schema: SchemaProvider<Output>): ThinkBuilder<Output>;
|
|
24
|
+
/**
|
|
25
|
+
* Create a new think builder without a schema.
|
|
26
|
+
*
|
|
27
|
+
* @deprecated Use `think(schemaOf<T>(schema))` instead to provide a typed schema.
|
|
28
|
+
*/
|
|
29
|
+
think<Output>(): ThinkBuilder<Output>;
|
|
30
|
+
/**
|
|
31
|
+
* Close the connection to the conductor
|
|
32
|
+
*
|
|
33
|
+
* @deprecated Use Agent.close() instead.
|
|
34
|
+
*/
|
|
35
|
+
close(): void;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Connect to an agent via the conductor.
|
|
39
|
+
*
|
|
40
|
+
* @deprecated Use Agent.connect() instead. This function will be removed in the next major version.
|
|
41
|
+
*
|
|
42
|
+
* @param conductorCommand - The command to spawn the conductor process
|
|
43
|
+
* @returns A Patchwork instance connected to the conductor
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* // Old API (deprecated):
|
|
48
|
+
* const patchwork = await connect(["sacp-conductor", "agent", "npx ..."]);
|
|
49
|
+
*
|
|
50
|
+
* // New API:
|
|
51
|
+
* const agent = await Agent.connect("npx ...");
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function connect(conductorCommand: string[]): Promise<Patchwork>;
|
|
55
|
+
//# sourceMappingURL=patchwork.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patchwork.d.ts","sourceRoot":"","sources":["../src/patchwork.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;;;;;GAOG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAE/B,gBAAgB;gBACJ,KAAK,EAAE,KAAK;IAIxB;;;;;;OAMG;IACH,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC,MAAM,CAAC;IAEnE;;;;OAIG;IACH,KAAK,CAAC,MAAM,KAAK,YAAY,CAAC,MAAM,CAAC;IAMrC;;;;OAIG;IACH,KAAK,IAAI,IAAI;CAGd;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,OAAO,CAAC,gBAAgB,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAkB5E"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Agent } from "./agent.js";
|
|
2
|
+
/**
|
|
3
|
+
* Main entry point for creating patchwork instances.
|
|
4
|
+
*
|
|
5
|
+
* @deprecated Use Agent instead. This class will be removed in the next major version.
|
|
6
|
+
*
|
|
7
|
+
* Patchwork provides a fluent API for blending deterministic code
|
|
8
|
+
* with LLM-powered reasoning.
|
|
9
|
+
*/
|
|
10
|
+
export class Patchwork {
|
|
11
|
+
_agent;
|
|
12
|
+
/** @internal */
|
|
13
|
+
constructor(agent) {
|
|
14
|
+
this._agent = agent;
|
|
15
|
+
}
|
|
16
|
+
think(schema) {
|
|
17
|
+
return this._agent.think(schema);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Close the connection to the conductor
|
|
21
|
+
*
|
|
22
|
+
* @deprecated Use Agent.close() instead.
|
|
23
|
+
*/
|
|
24
|
+
close() {
|
|
25
|
+
this._agent.close();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Connect to an agent via the conductor.
|
|
30
|
+
*
|
|
31
|
+
* @deprecated Use Agent.connect() instead. This function will be removed in the next major version.
|
|
32
|
+
*
|
|
33
|
+
* @param conductorCommand - The command to spawn the conductor process
|
|
34
|
+
* @returns A Patchwork instance connected to the conductor
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* // Old API (deprecated):
|
|
39
|
+
* const patchwork = await connect(["sacp-conductor", "agent", "npx ..."]);
|
|
40
|
+
*
|
|
41
|
+
* // New API:
|
|
42
|
+
* const agent = await Agent.connect("npx ...");
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export async function connect(conductorCommand) {
|
|
46
|
+
// Extract the agent command from the conductor command
|
|
47
|
+
// Old format: ["sacp-conductor", "agent", "npx -y @zed-industries/claude-code-acp"]
|
|
48
|
+
// New format: just the agent command string
|
|
49
|
+
const agentIndex = conductorCommand.indexOf("agent");
|
|
50
|
+
let agentCommand;
|
|
51
|
+
if (agentIndex !== -1 && conductorCommand.length > agentIndex + 1) {
|
|
52
|
+
agentCommand = conductorCommand[agentIndex + 1];
|
|
53
|
+
}
|
|
54
|
+
else if (conductorCommand.length > 0) {
|
|
55
|
+
// Fallback: join remaining args as the command
|
|
56
|
+
agentCommand = conductorCommand.slice(1).join(" ");
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
throw new Error("Invalid conductor command format");
|
|
60
|
+
}
|
|
61
|
+
const agent = await Agent.connect(agentCommand);
|
|
62
|
+
return new Patchwork(agent);
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=patchwork.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patchwork.js","sourceRoot":"","sources":["../src/patchwork.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAInC;;;;;;;GAOG;AACH,MAAM,OAAO,SAAS;IACH,MAAM,CAAQ;IAE/B,gBAAgB;IAChB,YAAY,KAAY;QACtB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAkBD,KAAK,CAAS,MAA+B;QAC3C,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAO,CAAC,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACH,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,gBAA0B;IACtD,uDAAuD;IACvD,oFAAoF;IACpF,4CAA4C;IAC5C,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACrD,IAAI,YAAoB,CAAC;IAEzB,IAAI,UAAU,KAAK,CAAC,CAAC,IAAI,gBAAgB,CAAC,MAAM,GAAG,UAAU,GAAG,CAAC,EAAE,CAAC;QAClE,YAAY,GAAG,gBAAgB,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;IAClD,CAAC;SAAM,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvC,+CAA+C;QAC/C,YAAY,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrD,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;IAED,MAAM,KAAK,G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