clanka 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AgentExecutor.d.ts +135 -62
- package/dist/AgentExecutor.d.ts.map +1 -1
- package/dist/AgentExecutor.js +130 -1
- package/dist/AgentExecutor.js.map +1 -1
- package/package.json +1 -1
- package/src/AgentExecutor.ts +195 -0
package/dist/AgentExecutor.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
-
import { Effect, FileSystem, Layer, Option, Path, ServiceMap, Stream } from "effect";
|
|
4
|
+
import { Effect, FileSystem, Layer, Option, Path, Schema, Scope, ServiceMap, Stream } from "effect";
|
|
5
5
|
import { Tool, Toolkit } from "effect/unstable/ai";
|
|
6
|
+
import { Rpc, RpcClient, RpcGroup, RpcServer } from "effect/unstable/rpc";
|
|
6
7
|
import { CurrentDirectory, SubagentExecutor, TaskCompleter } from "./AgentTools.ts";
|
|
7
8
|
import { ToolkitRenderer } from "./ToolkitRenderer.ts";
|
|
8
9
|
import type { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner";
|
|
@@ -39,120 +40,133 @@ export declare const makeLocal: <Toolkit extends Toolkit.Any = never>(options: {
|
|
|
39
40
|
}): Stream.Stream<string>;
|
|
40
41
|
}, never, Tool.HandlersFor<{
|
|
41
42
|
readonly readFile: Tool.Tool<"readFile", {
|
|
42
|
-
readonly parameters:
|
|
43
|
-
readonly path:
|
|
44
|
-
readonly startLine:
|
|
45
|
-
readonly endLine:
|
|
43
|
+
readonly parameters: Schema.Struct<{
|
|
44
|
+
readonly path: Schema.String;
|
|
45
|
+
readonly startLine: Schema.optional<Schema.Number>;
|
|
46
|
+
readonly endLine: Schema.optional<Schema.Number>;
|
|
46
47
|
}>;
|
|
47
|
-
readonly success:
|
|
48
|
-
readonly failure:
|
|
48
|
+
readonly success: Schema.NullOr<Schema.String>;
|
|
49
|
+
readonly failure: Schema.Never;
|
|
49
50
|
readonly failureMode: "error";
|
|
50
51
|
}, CurrentDirectory>;
|
|
51
52
|
readonly writeFile: Tool.Tool<"writeFile", {
|
|
52
|
-
readonly parameters:
|
|
53
|
-
readonly path:
|
|
54
|
-
readonly content:
|
|
53
|
+
readonly parameters: Schema.Struct<{
|
|
54
|
+
readonly path: Schema.String;
|
|
55
|
+
readonly content: Schema.String;
|
|
55
56
|
}>;
|
|
56
|
-
readonly success:
|
|
57
|
-
readonly failure:
|
|
57
|
+
readonly success: Schema.Void;
|
|
58
|
+
readonly failure: Schema.Never;
|
|
58
59
|
readonly failureMode: "error";
|
|
59
60
|
}, CurrentDirectory>;
|
|
60
61
|
readonly applyPatch: Tool.Tool<"applyPatch", {
|
|
61
|
-
readonly parameters:
|
|
62
|
-
readonly success:
|
|
63
|
-
readonly failure:
|
|
62
|
+
readonly parameters: Schema.String;
|
|
63
|
+
readonly success: Schema.String;
|
|
64
|
+
readonly failure: Schema.Never;
|
|
64
65
|
readonly failureMode: "error";
|
|
65
66
|
}, CurrentDirectory>;
|
|
66
67
|
readonly removeFile: Tool.Tool<"removeFile", {
|
|
67
|
-
readonly parameters:
|
|
68
|
-
readonly success:
|
|
69
|
-
readonly failure:
|
|
68
|
+
readonly parameters: Schema.String;
|
|
69
|
+
readonly success: Schema.Void;
|
|
70
|
+
readonly failure: Schema.Never;
|
|
70
71
|
readonly failureMode: "error";
|
|
71
72
|
}, CurrentDirectory>;
|
|
72
73
|
readonly renameFile: Tool.Tool<"renameFile", {
|
|
73
|
-
readonly parameters:
|
|
74
|
-
readonly from:
|
|
75
|
-
readonly to:
|
|
74
|
+
readonly parameters: Schema.Struct<{
|
|
75
|
+
readonly from: Schema.String;
|
|
76
|
+
readonly to: Schema.String;
|
|
76
77
|
}>;
|
|
77
|
-
readonly success:
|
|
78
|
-
readonly failure:
|
|
78
|
+
readonly success: Schema.Void;
|
|
79
|
+
readonly failure: Schema.Never;
|
|
79
80
|
readonly failureMode: "error";
|
|
80
81
|
}, CurrentDirectory>;
|
|
81
82
|
readonly mkdir: Tool.Tool<"mkdir", {
|
|
82
|
-
readonly parameters:
|
|
83
|
-
readonly success:
|
|
84
|
-
readonly failure:
|
|
83
|
+
readonly parameters: Schema.String;
|
|
84
|
+
readonly success: Schema.Void;
|
|
85
|
+
readonly failure: Schema.Never;
|
|
85
86
|
readonly failureMode: "error";
|
|
86
87
|
}, CurrentDirectory>;
|
|
87
88
|
readonly ls: Tool.Tool<"ls", {
|
|
88
|
-
readonly parameters:
|
|
89
|
-
readonly success:
|
|
90
|
-
readonly failure:
|
|
89
|
+
readonly parameters: Schema.String;
|
|
90
|
+
readonly success: Schema.$Array<Schema.String>;
|
|
91
|
+
readonly failure: Schema.Never;
|
|
91
92
|
readonly failureMode: "error";
|
|
92
93
|
}, CurrentDirectory>;
|
|
93
94
|
readonly rg: Tool.Tool<"rg", {
|
|
94
|
-
readonly parameters:
|
|
95
|
-
readonly pattern:
|
|
96
|
-
readonly glob:
|
|
97
|
-
readonly noIgnore:
|
|
98
|
-
readonly maxLines:
|
|
95
|
+
readonly parameters: Schema.Struct<{
|
|
96
|
+
readonly pattern: Schema.String;
|
|
97
|
+
readonly glob: Schema.optional<Schema.String>;
|
|
98
|
+
readonly noIgnore: Schema.optional<Schema.Boolean>;
|
|
99
|
+
readonly maxLines: Schema.optional<Schema.Finite>;
|
|
99
100
|
}>;
|
|
100
|
-
readonly success:
|
|
101
|
-
readonly failure:
|
|
101
|
+
readonly success: Schema.String;
|
|
102
|
+
readonly failure: Schema.Never;
|
|
102
103
|
readonly failureMode: "error";
|
|
103
104
|
}, CurrentDirectory>;
|
|
104
105
|
readonly glob: Tool.Tool<"glob", {
|
|
105
|
-
readonly parameters:
|
|
106
|
-
readonly success:
|
|
107
|
-
readonly failure:
|
|
106
|
+
readonly parameters: Schema.String;
|
|
107
|
+
readonly success: Schema.$Array<Schema.String>;
|
|
108
|
+
readonly failure: Schema.Never;
|
|
108
109
|
readonly failureMode: "error";
|
|
109
110
|
}, CurrentDirectory>;
|
|
110
111
|
readonly bash: Tool.Tool<"bash", {
|
|
111
|
-
readonly parameters:
|
|
112
|
-
readonly success:
|
|
113
|
-
readonly failure:
|
|
112
|
+
readonly parameters: Schema.String;
|
|
113
|
+
readonly success: Schema.String;
|
|
114
|
+
readonly failure: Schema.Never;
|
|
114
115
|
readonly failureMode: "error";
|
|
115
116
|
}, CurrentDirectory>;
|
|
116
117
|
readonly gh: Tool.Tool<"gh", {
|
|
117
|
-
readonly parameters:
|
|
118
|
-
readonly success:
|
|
119
|
-
readonly failure:
|
|
118
|
+
readonly parameters: Schema.$Array<Schema.String>;
|
|
119
|
+
readonly success: Schema.String;
|
|
120
|
+
readonly failure: Schema.Never;
|
|
120
121
|
readonly failureMode: "error";
|
|
121
122
|
}, CurrentDirectory>;
|
|
122
123
|
readonly delegate: Tool.Tool<"delegate", {
|
|
123
|
-
readonly parameters:
|
|
124
|
-
readonly success:
|
|
125
|
-
readonly failure:
|
|
124
|
+
readonly parameters: Schema.String;
|
|
125
|
+
readonly success: Schema.String;
|
|
126
|
+
readonly failure: Schema.Never;
|
|
126
127
|
readonly failureMode: "error";
|
|
127
128
|
}, SubagentExecutor>;
|
|
128
129
|
readonly webSearch: Tool.Tool<"webSearch", {
|
|
129
|
-
readonly parameters:
|
|
130
|
-
readonly query:
|
|
131
|
-
readonly numResults:
|
|
130
|
+
readonly parameters: Schema.Struct<{
|
|
131
|
+
readonly query: Schema.String;
|
|
132
|
+
readonly numResults: Schema.optional<Schema.Number>;
|
|
132
133
|
}>;
|
|
133
|
-
readonly success:
|
|
134
|
-
readonly failure:
|
|
134
|
+
readonly success: Schema.String;
|
|
135
|
+
readonly failure: Schema.Never;
|
|
135
136
|
readonly failureMode: "error";
|
|
136
137
|
}, never>;
|
|
137
138
|
readonly fetchMarkdown: Tool.Tool<"fetchMarkdown", {
|
|
138
|
-
readonly parameters:
|
|
139
|
-
readonly success:
|
|
140
|
-
readonly failure:
|
|
139
|
+
readonly parameters: Schema.String;
|
|
140
|
+
readonly success: Schema.String;
|
|
141
|
+
readonly failure: Schema.Never;
|
|
141
142
|
readonly failureMode: "error";
|
|
142
143
|
}, never>;
|
|
143
144
|
readonly sleep: Tool.Tool<"sleep", {
|
|
144
|
-
readonly parameters:
|
|
145
|
-
readonly success:
|
|
146
|
-
readonly failure:
|
|
145
|
+
readonly parameters: Schema.Finite;
|
|
146
|
+
readonly success: Schema.Void;
|
|
147
|
+
readonly failure: Schema.Never;
|
|
147
148
|
readonly failureMode: "error";
|
|
148
149
|
}, never>;
|
|
149
150
|
readonly taskComplete: Tool.Tool<"taskComplete", {
|
|
150
|
-
readonly parameters:
|
|
151
|
-
readonly success:
|
|
152
|
-
readonly failure:
|
|
151
|
+
readonly parameters: Schema.String;
|
|
152
|
+
readonly success: Schema.Void;
|
|
153
|
+
readonly failure: Schema.Never;
|
|
153
154
|
readonly failureMode: "error";
|
|
154
155
|
}, TaskCompleter>;
|
|
155
156
|
}> | FileSystem.FileSystem | Path.Path | ToolkitRenderer | Exclude<Toolkit extends Toolkit.Toolkit<infer T extends Record<string, Tool.Any>> ? Tool.HandlersFor<T> | Tool.HandlerServices<T[keyof T]> : never, CurrentDirectory | TaskCompleter | SubagentExecutor>>;
|
|
157
|
+
/**
|
|
158
|
+
* @since 1.0.0
|
|
159
|
+
* @category Constructors
|
|
160
|
+
*/
|
|
161
|
+
export declare const makeRpc: Effect.Effect<{
|
|
162
|
+
readonly toolsDts: Effect.Effect<string>;
|
|
163
|
+
readonly agentsMd: Effect.Effect<Option.Option<string>>;
|
|
164
|
+
execute(options: {
|
|
165
|
+
readonly script: string;
|
|
166
|
+
readonly onTaskComplete: (summary: string) => Effect.Effect<void>;
|
|
167
|
+
readonly onSubagent: (message: string) => Effect.Effect<string>;
|
|
168
|
+
}): Stream.Stream<string>;
|
|
169
|
+
}, never, Scope.Scope | RpcClient.Protocol>;
|
|
156
170
|
/**
|
|
157
171
|
* @since 1.0.0
|
|
158
172
|
* @category Layers
|
|
@@ -161,5 +175,64 @@ export declare const layerLocal: <Toolkit extends Toolkit.Any = never>(options:
|
|
|
161
175
|
readonly directory: string;
|
|
162
176
|
readonly tools?: Toolkit | undefined;
|
|
163
177
|
}) => Layer.Layer<AgentExecutor, never, FileSystem.FileSystem | Path.Path | ChildProcessSpawner | HttpClient | Exclude<Toolkit extends Toolkit.Toolkit<infer T> ? Tool.HandlersFor<T> | Tool.HandlerServices<T[keyof T]> : never, CurrentDirectory | SubagentExecutor | TaskCompleter>>;
|
|
178
|
+
/**
|
|
179
|
+
* Create an AgentExecutor that communicates with a remote RpcServer serving the
|
|
180
|
+
* AgentExecutor protocol.
|
|
181
|
+
*
|
|
182
|
+
* @since 1.0.0
|
|
183
|
+
* @category Layers
|
|
184
|
+
*/
|
|
185
|
+
export declare const layerRpc: Layer.Layer<AgentExecutor, never, RpcClient.Protocol>;
|
|
186
|
+
/**
|
|
187
|
+
* Create a RpcServer that serves the AgentExecutor rpc protocol.
|
|
188
|
+
*
|
|
189
|
+
* This can be used to run the AgentExecutor in a remote location.
|
|
190
|
+
*
|
|
191
|
+
* @since 1.0.0
|
|
192
|
+
* @category Layers
|
|
193
|
+
*/
|
|
194
|
+
export declare const layerRpcServer: <Toolkit extends Toolkit.Any = never>(options: {
|
|
195
|
+
readonly directory: string;
|
|
196
|
+
readonly tools?: Toolkit | undefined;
|
|
197
|
+
}) => Layer.Layer<never, never, RpcServer.Protocol | FileSystem.FileSystem | HttpClient | Path.Path | ChildProcessSpawner | Exclude<Toolkit extends Toolkit.Toolkit<infer T> ? Tool.HandlersFor<T> | Tool.HandlerServices<T[keyof T]> : never, CurrentDirectory | SubagentExecutor | TaskCompleter>>;
|
|
198
|
+
/**
|
|
199
|
+
* @since 1.0.0
|
|
200
|
+
* @category Rpcs
|
|
201
|
+
*/
|
|
202
|
+
export declare const ExecuteOutput: Schema.TaggedUnion<{
|
|
203
|
+
readonly Text: Schema.TaggedStruct<"Text", {
|
|
204
|
+
readonly text: Schema.String;
|
|
205
|
+
}>;
|
|
206
|
+
readonly TaskComplete: Schema.TaggedStruct<"TaskComplete", {
|
|
207
|
+
readonly summary: Schema.String;
|
|
208
|
+
}>;
|
|
209
|
+
readonly Subagent: Schema.TaggedStruct<"Subagent", {
|
|
210
|
+
readonly id: Schema.Finite;
|
|
211
|
+
readonly prompt: Schema.String;
|
|
212
|
+
}>;
|
|
213
|
+
}>;
|
|
214
|
+
declare const Rpcs_base: RpcGroup.RpcGroup<Rpc.Rpc<"toolsDts", Schema.Void, Schema.String, Schema.Never, never, never> | Rpc.Rpc<"agentsMd", Schema.Void, Schema.Option<Schema.String>, Schema.Never, never, never> | Rpc.Rpc<"subagentOutput", Schema.Struct<{
|
|
215
|
+
id: Schema.Finite;
|
|
216
|
+
output: Schema.String;
|
|
217
|
+
}>, Schema.Void, Schema.Never, never, never> | Rpc.Rpc<"execute", Schema.Struct<{
|
|
218
|
+
readonly script: Schema.String;
|
|
219
|
+
}>, import("effect/unstable/rpc/RpcSchema").Stream<Schema.TaggedUnion<{
|
|
220
|
+
readonly Text: Schema.TaggedStruct<"Text", {
|
|
221
|
+
readonly text: Schema.String;
|
|
222
|
+
}>;
|
|
223
|
+
readonly TaskComplete: Schema.TaggedStruct<"TaskComplete", {
|
|
224
|
+
readonly summary: Schema.String;
|
|
225
|
+
}>;
|
|
226
|
+
readonly Subagent: Schema.TaggedStruct<"Subagent", {
|
|
227
|
+
readonly id: Schema.Finite;
|
|
228
|
+
readonly prompt: Schema.String;
|
|
229
|
+
}>;
|
|
230
|
+
}>, Schema.Never>, Schema.Never, never, never>>;
|
|
231
|
+
/**
|
|
232
|
+
* @since 1.0.0
|
|
233
|
+
* @category Rpcs
|
|
234
|
+
*/
|
|
235
|
+
export declare class Rpcs extends Rpcs_base {
|
|
236
|
+
}
|
|
164
237
|
export {};
|
|
165
238
|
//# sourceMappingURL=AgentExecutor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentExecutor.d.ts","sourceRoot":"","sources":["../src/AgentExecutor.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAGL,MAAM,EAGN,UAAU,EACV,KAAK,EACL,MAAM,EACN,IAAI,EAIJ,UAAU,EACV,MAAM,EACP,MAAM,QAAQ,CAAA;AACf,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"AgentExecutor.d.ts","sourceRoot":"","sources":["../src/AgentExecutor.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAGL,MAAM,EAGN,UAAU,EACV,KAAK,EACL,MAAM,EACN,IAAI,EAIJ,MAAM,EACN,KAAK,EACL,UAAU,EACV,MAAM,EACP,MAAM,QAAQ,CAAA;AACf,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAIzE,OAAO,EAGL,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACd,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAA;AACtF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;;uBAS1C,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;uBACrB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;qBACtC;QACf,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;QACvB,QAAQ,CAAC,cAAc,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QACjE,QAAQ,CAAC,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,K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pC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GACtD,KAAK,EACT,gBAAgB,GAAG,gBAAgB,GAAG,aAAa,CACpD,CA4EF,CAAA;AAEH;;;GAGG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;EAIxB,CAAA;;;;;;;;;;;;;;;;;;AAEF;;;GAGG;AACH,qBAAa,IAAK,SAAQ,SAoBzB;CAAG"}
|
package/dist/AgentExecutor.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
-
import { Cause, Console, Effect, Exit, Fiber, FileSystem, Layer, Option, Path, pipe, Queue, Scope, ServiceMap, Stream, } from "effect";
|
|
4
|
+
import { Cause, Console, Effect, Exit, Fiber, FileSystem, Layer, Option, Path, pipe, Queue, Result, Schema, Scope, ServiceMap, Stream, } from "effect";
|
|
5
5
|
import { Tool, Toolkit } from "effect/unstable/ai";
|
|
6
|
+
import { Rpc, RpcClient, RpcGroup, RpcServer } from "effect/unstable/rpc";
|
|
6
7
|
import * as NodeConsole from "node:console";
|
|
7
8
|
import * as NodeVm from "node:vm";
|
|
8
9
|
import { Writable } from "node:stream";
|
|
@@ -90,11 +91,139 @@ ${opts.script}
|
|
|
90
91
|
execute,
|
|
91
92
|
});
|
|
92
93
|
});
|
|
94
|
+
/**
|
|
95
|
+
* @since 1.0.0
|
|
96
|
+
* @category Constructors
|
|
97
|
+
*/
|
|
98
|
+
export const makeRpc = Effect.gen(function* () {
|
|
99
|
+
const client = yield* RpcClient.make(Rpcs, {
|
|
100
|
+
spanPrefix: "AgentExecutorClient",
|
|
101
|
+
});
|
|
102
|
+
return AgentExecutor.of({
|
|
103
|
+
toolsDts: Effect.orDie(client.toolsDts()),
|
|
104
|
+
agentsMd: Effect.orDie(client.agentsMd()),
|
|
105
|
+
execute: (opts) => Scope.Scope.useSync((scope) => client.execute({ script: opts.script }).pipe(Stream.tap((part) => {
|
|
106
|
+
switch (part._tag) {
|
|
107
|
+
case "Text": {
|
|
108
|
+
return Effect.void;
|
|
109
|
+
}
|
|
110
|
+
case "TaskComplete": {
|
|
111
|
+
return opts.onTaskComplete(part.summary);
|
|
112
|
+
}
|
|
113
|
+
case "Subagent": {
|
|
114
|
+
const id = part.id;
|
|
115
|
+
return pipe(opts.onSubagent(part.prompt), Effect.flatMap((output) => client.subagentOutput({ id, output })), Effect.forkIn(scope));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}), Stream.orDie, Stream.filterMap((part) => part._tag === "Text" ? Result.succeed(part.text) : Result.failVoid))).pipe(Stream.unwrap),
|
|
119
|
+
});
|
|
120
|
+
});
|
|
93
121
|
/**
|
|
94
122
|
* @since 1.0.0
|
|
95
123
|
* @category Layers
|
|
96
124
|
*/
|
|
97
125
|
export const layerLocal = (options) => Layer.effect(AgentExecutor, makeLocal(options)).pipe(Layer.provide([AgentToolHandlers, ToolkitRenderer.layer]));
|
|
126
|
+
/**
|
|
127
|
+
* Create an AgentExecutor that communicates with a remote RpcServer serving the
|
|
128
|
+
* AgentExecutor protocol.
|
|
129
|
+
*
|
|
130
|
+
* @since 1.0.0
|
|
131
|
+
* @category Layers
|
|
132
|
+
*/
|
|
133
|
+
export const layerRpc = Layer.effect(AgentExecutor, makeRpc);
|
|
134
|
+
/**
|
|
135
|
+
* Create a RpcServer that serves the AgentExecutor rpc protocol.
|
|
136
|
+
*
|
|
137
|
+
* This can be used to run the AgentExecutor in a remote location.
|
|
138
|
+
*
|
|
139
|
+
* @since 1.0.0
|
|
140
|
+
* @category Layers
|
|
141
|
+
*/
|
|
142
|
+
export const layerRpcServer = (options) => RpcServer.layer(Rpcs, {
|
|
143
|
+
spanPrefix: "AgentExecutorServer",
|
|
144
|
+
disableFatalDefects: true,
|
|
145
|
+
}).pipe(Layer.provide(Rpcs.toLayer(Effect.gen(function* () {
|
|
146
|
+
const local = yield* makeLocal(options);
|
|
147
|
+
const subagentResumes = new Map();
|
|
148
|
+
return Rpcs.of({
|
|
149
|
+
agentsMd: () => local.agentsMd,
|
|
150
|
+
toolsDts: () => local.toolsDts,
|
|
151
|
+
subagentOutput: ({ id, output }) => {
|
|
152
|
+
const resume = subagentResumes.get(id);
|
|
153
|
+
if (resume) {
|
|
154
|
+
resume(Effect.succeed(output));
|
|
155
|
+
subagentResumes.delete(id);
|
|
156
|
+
}
|
|
157
|
+
return Effect.void;
|
|
158
|
+
},
|
|
159
|
+
execute: Effect.fnUntraced(function* ({ script }) {
|
|
160
|
+
const queue = yield* Queue.unbounded();
|
|
161
|
+
let subagentId = 0;
|
|
162
|
+
yield* pipe(local.execute({
|
|
163
|
+
script,
|
|
164
|
+
onTaskComplete(summary) {
|
|
165
|
+
return Queue.offer(queue, {
|
|
166
|
+
_tag: "TaskComplete",
|
|
167
|
+
summary,
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
onSubagent(prompt) {
|
|
171
|
+
const id = subagentId++;
|
|
172
|
+
return Effect.callback((resume) => {
|
|
173
|
+
subagentResumes.set(id, resume);
|
|
174
|
+
Queue.offerUnsafe(queue, {
|
|
175
|
+
_tag: "Subagent",
|
|
176
|
+
id,
|
|
177
|
+
prompt,
|
|
178
|
+
});
|
|
179
|
+
return Effect.sync(() => {
|
|
180
|
+
subagentResumes.delete(id);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
},
|
|
184
|
+
}), Stream.runForEachArray((parts) => {
|
|
185
|
+
for (const part of parts) {
|
|
186
|
+
Queue.offerUnsafe(queue, {
|
|
187
|
+
_tag: "Text",
|
|
188
|
+
text: part,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
return Effect.void;
|
|
192
|
+
}), Effect.forkScoped);
|
|
193
|
+
return queue;
|
|
194
|
+
}),
|
|
195
|
+
});
|
|
196
|
+
}))), Layer.provide([AgentToolHandlers, ToolkitRenderer.layer]));
|
|
197
|
+
/**
|
|
198
|
+
* @since 1.0.0
|
|
199
|
+
* @category Rpcs
|
|
200
|
+
*/
|
|
201
|
+
export const ExecuteOutput = Schema.TaggedUnion({
|
|
202
|
+
Text: { text: Schema.String },
|
|
203
|
+
TaskComplete: { summary: Schema.String },
|
|
204
|
+
Subagent: { id: Schema.Finite, prompt: Schema.String },
|
|
205
|
+
});
|
|
206
|
+
/**
|
|
207
|
+
* @since 1.0.0
|
|
208
|
+
* @category Rpcs
|
|
209
|
+
*/
|
|
210
|
+
export class Rpcs extends RpcGroup.make(Rpc.make("toolsDts", {
|
|
211
|
+
success: Schema.String,
|
|
212
|
+
}), Rpc.make("agentsMd", {
|
|
213
|
+
success: Schema.Option(Schema.String),
|
|
214
|
+
}), Rpc.make("subagentOutput", {
|
|
215
|
+
payload: {
|
|
216
|
+
id: Schema.Finite,
|
|
217
|
+
output: Schema.String,
|
|
218
|
+
},
|
|
219
|
+
}), Rpc.make("execute", {
|
|
220
|
+
payload: Schema.Struct({
|
|
221
|
+
script: Schema.String,
|
|
222
|
+
}),
|
|
223
|
+
success: ExecuteOutput,
|
|
224
|
+
stream: true,
|
|
225
|
+
})) {
|
|
226
|
+
}
|
|
98
227
|
const defaultMain = () => Promise.resolve();
|
|
99
228
|
const makeConsole = Effect.fn(function* (queue) {
|
|
100
229
|
const writable = new QueueWriteStream(queue);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentExecutor.js","sourceRoot":"","sources":["../src/AgentExecutor.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,KAAK,EACL,OAAO,EACP,MAAM,EACN,IAAI,EACJ,KAAK,EACL,UAAU,EACV,KAAK,EACL,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,KAAK,EACL,UAAU,EACV,MAAM,GACP,MAAM,QAAQ,CAAA;AACf,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,KAAK,WA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AAI;CACb,CAAC,CACH;CAAG;AAYJ,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,CAAA;AAE3C,MAAM,WAAW,GAAG,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,EACrC,KAAsC;IAEtC,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC,KAAK,CAAC,CAAA;IAC5C,MAAM,UAAU,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IACpD,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE;QAC9B,QAAQ,CAAC,GAAG,EAAE,CAAA;QACd,OAAO,MAAM,CAAC,IAAI,CAAA;IACpB,CAAC,CAAC,CAAA;IACF,OAAO,UAAU,CAAA;AACnB,CAAC,CAAC,CAAA;AAEF,MAAM,gBAAiB,SAAQ,QAAQ;IAC5B,KAAK,CAAmC;IACjD,YAAY,KAAwC;QAClD,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IACD,MAAM;IACJ,sDAAsD;IACtD,KAAU,EACV,SAAyB,EACzB,QAAwC;QAExC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAA;QAC/C,QAAQ,EAAE,CAAA;IACZ,CAAC;CACF"}
|
package/package.json
CHANGED
package/src/AgentExecutor.ts
CHANGED
|
@@ -13,11 +13,14 @@ import {
|
|
|
13
13
|
Path,
|
|
14
14
|
pipe,
|
|
15
15
|
Queue,
|
|
16
|
+
Result,
|
|
17
|
+
Schema,
|
|
16
18
|
Scope,
|
|
17
19
|
ServiceMap,
|
|
18
20
|
Stream,
|
|
19
21
|
} from "effect"
|
|
20
22
|
import { Tool, Toolkit } from "effect/unstable/ai"
|
|
23
|
+
import { Rpc, RpcClient, RpcGroup, RpcServer } from "effect/unstable/rpc"
|
|
21
24
|
import * as NodeConsole from "node:console"
|
|
22
25
|
import * as NodeVm from "node:vm"
|
|
23
26
|
import { Writable } from "node:stream"
|
|
@@ -178,6 +181,50 @@ ${opts.script}
|
|
|
178
181
|
})
|
|
179
182
|
})
|
|
180
183
|
|
|
184
|
+
/**
|
|
185
|
+
* @since 1.0.0
|
|
186
|
+
* @category Constructors
|
|
187
|
+
*/
|
|
188
|
+
export const makeRpc = Effect.gen(function* () {
|
|
189
|
+
const client = yield* RpcClient.make(Rpcs, {
|
|
190
|
+
spanPrefix: "AgentExecutorClient",
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
return AgentExecutor.of({
|
|
194
|
+
toolsDts: Effect.orDie(client.toolsDts()),
|
|
195
|
+
agentsMd: Effect.orDie(client.agentsMd()),
|
|
196
|
+
execute: (opts) =>
|
|
197
|
+
Scope.Scope.useSync((scope) =>
|
|
198
|
+
client.execute({ script: opts.script }).pipe(
|
|
199
|
+
Stream.tap((part) => {
|
|
200
|
+
switch (part._tag) {
|
|
201
|
+
case "Text": {
|
|
202
|
+
return Effect.void
|
|
203
|
+
}
|
|
204
|
+
case "TaskComplete": {
|
|
205
|
+
return opts.onTaskComplete(part.summary)
|
|
206
|
+
}
|
|
207
|
+
case "Subagent": {
|
|
208
|
+
const id = part.id
|
|
209
|
+
return pipe(
|
|
210
|
+
opts.onSubagent(part.prompt),
|
|
211
|
+
Effect.flatMap((output) =>
|
|
212
|
+
client.subagentOutput({ id, output }),
|
|
213
|
+
),
|
|
214
|
+
Effect.forkIn(scope),
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}),
|
|
219
|
+
Stream.orDie,
|
|
220
|
+
Stream.filterMap((part) =>
|
|
221
|
+
part._tag === "Text" ? Result.succeed(part.text) : Result.failVoid,
|
|
222
|
+
),
|
|
223
|
+
),
|
|
224
|
+
).pipe(Stream.unwrap),
|
|
225
|
+
})
|
|
226
|
+
})
|
|
227
|
+
|
|
181
228
|
/**
|
|
182
229
|
* @since 1.0.0
|
|
183
230
|
* @category Layers
|
|
@@ -203,6 +250,154 @@ export const layerLocal = <Toolkit extends Toolkit.Any = never>(options: {
|
|
|
203
250
|
Layer.provide([AgentToolHandlers, ToolkitRenderer.layer]),
|
|
204
251
|
)
|
|
205
252
|
|
|
253
|
+
/**
|
|
254
|
+
* Create an AgentExecutor that communicates with a remote RpcServer serving the
|
|
255
|
+
* AgentExecutor protocol.
|
|
256
|
+
*
|
|
257
|
+
* @since 1.0.0
|
|
258
|
+
* @category Layers
|
|
259
|
+
*/
|
|
260
|
+
export const layerRpc: Layer.Layer<AgentExecutor, never, RpcClient.Protocol> =
|
|
261
|
+
Layer.effect(AgentExecutor, makeRpc)
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Create a RpcServer that serves the AgentExecutor rpc protocol.
|
|
265
|
+
*
|
|
266
|
+
* This can be used to run the AgentExecutor in a remote location.
|
|
267
|
+
*
|
|
268
|
+
* @since 1.0.0
|
|
269
|
+
* @category Layers
|
|
270
|
+
*/
|
|
271
|
+
export const layerRpcServer = <Toolkit extends Toolkit.Any = never>(options: {
|
|
272
|
+
readonly directory: string
|
|
273
|
+
readonly tools?: Toolkit | undefined
|
|
274
|
+
}): Layer.Layer<
|
|
275
|
+
never,
|
|
276
|
+
never,
|
|
277
|
+
| RpcServer.Protocol
|
|
278
|
+
| FileSystem.FileSystem
|
|
279
|
+
| HttpClient
|
|
280
|
+
| Path.Path
|
|
281
|
+
| ChildProcessSpawner
|
|
282
|
+
| Exclude<
|
|
283
|
+
Toolkit extends Toolkit.Toolkit<infer T>
|
|
284
|
+
? Tool.HandlersFor<T> | Tool.HandlerServices<T[keyof T]>
|
|
285
|
+
: never,
|
|
286
|
+
CurrentDirectory | SubagentExecutor | TaskCompleter
|
|
287
|
+
>
|
|
288
|
+
> =>
|
|
289
|
+
RpcServer.layer(Rpcs, {
|
|
290
|
+
spanPrefix: "AgentExecutorServer",
|
|
291
|
+
disableFatalDefects: true,
|
|
292
|
+
}).pipe(
|
|
293
|
+
Layer.provide(
|
|
294
|
+
Rpcs.toLayer(
|
|
295
|
+
Effect.gen(function* () {
|
|
296
|
+
const local = yield* makeLocal(options)
|
|
297
|
+
const subagentResumes = new Map<
|
|
298
|
+
number,
|
|
299
|
+
(effect: Effect.Effect<string>) => void
|
|
300
|
+
>()
|
|
301
|
+
|
|
302
|
+
return Rpcs.of({
|
|
303
|
+
agentsMd: () => local.agentsMd,
|
|
304
|
+
toolsDts: () => local.toolsDts,
|
|
305
|
+
subagentOutput: ({ id, output }) => {
|
|
306
|
+
const resume = subagentResumes.get(id)
|
|
307
|
+
if (resume) {
|
|
308
|
+
resume(Effect.succeed(output))
|
|
309
|
+
subagentResumes.delete(id)
|
|
310
|
+
}
|
|
311
|
+
return Effect.void
|
|
312
|
+
},
|
|
313
|
+
execute: Effect.fnUntraced(function* ({ script }) {
|
|
314
|
+
const queue = yield* Queue.unbounded<
|
|
315
|
+
typeof ExecuteOutput.Type,
|
|
316
|
+
Cause.Done
|
|
317
|
+
>()
|
|
318
|
+
let subagentId = 0
|
|
319
|
+
|
|
320
|
+
yield* pipe(
|
|
321
|
+
local.execute({
|
|
322
|
+
script,
|
|
323
|
+
onTaskComplete(summary) {
|
|
324
|
+
return Queue.offer(queue, {
|
|
325
|
+
_tag: "TaskComplete",
|
|
326
|
+
summary,
|
|
327
|
+
})
|
|
328
|
+
},
|
|
329
|
+
onSubagent(prompt) {
|
|
330
|
+
const id = subagentId++
|
|
331
|
+
return Effect.callback((resume) => {
|
|
332
|
+
subagentResumes.set(id, resume)
|
|
333
|
+
Queue.offerUnsafe(queue, {
|
|
334
|
+
_tag: "Subagent",
|
|
335
|
+
id,
|
|
336
|
+
prompt,
|
|
337
|
+
})
|
|
338
|
+
return Effect.sync(() => {
|
|
339
|
+
subagentResumes.delete(id)
|
|
340
|
+
})
|
|
341
|
+
})
|
|
342
|
+
},
|
|
343
|
+
}),
|
|
344
|
+
Stream.runForEachArray((parts) => {
|
|
345
|
+
for (const part of parts) {
|
|
346
|
+
Queue.offerUnsafe(queue, {
|
|
347
|
+
_tag: "Text",
|
|
348
|
+
text: part,
|
|
349
|
+
})
|
|
350
|
+
}
|
|
351
|
+
return Effect.void
|
|
352
|
+
}),
|
|
353
|
+
Effect.forkScoped,
|
|
354
|
+
)
|
|
355
|
+
|
|
356
|
+
return queue
|
|
357
|
+
}),
|
|
358
|
+
})
|
|
359
|
+
}),
|
|
360
|
+
),
|
|
361
|
+
),
|
|
362
|
+
Layer.provide([AgentToolHandlers, ToolkitRenderer.layer]),
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* @since 1.0.0
|
|
367
|
+
* @category Rpcs
|
|
368
|
+
*/
|
|
369
|
+
export const ExecuteOutput = Schema.TaggedUnion({
|
|
370
|
+
Text: { text: Schema.String },
|
|
371
|
+
TaskComplete: { summary: Schema.String },
|
|
372
|
+
Subagent: { id: Schema.Finite, prompt: Schema.String },
|
|
373
|
+
})
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* @since 1.0.0
|
|
377
|
+
* @category Rpcs
|
|
378
|
+
*/
|
|
379
|
+
export class Rpcs extends RpcGroup.make(
|
|
380
|
+
Rpc.make("toolsDts", {
|
|
381
|
+
success: Schema.String,
|
|
382
|
+
}),
|
|
383
|
+
Rpc.make("agentsMd", {
|
|
384
|
+
success: Schema.Option(Schema.String),
|
|
385
|
+
}),
|
|
386
|
+
Rpc.make("subagentOutput", {
|
|
387
|
+
payload: {
|
|
388
|
+
id: Schema.Finite,
|
|
389
|
+
output: Schema.String,
|
|
390
|
+
},
|
|
391
|
+
}),
|
|
392
|
+
Rpc.make("execute", {
|
|
393
|
+
payload: Schema.Struct({
|
|
394
|
+
script: Schema.String,
|
|
395
|
+
}),
|
|
396
|
+
success: ExecuteOutput,
|
|
397
|
+
stream: true,
|
|
398
|
+
}),
|
|
399
|
+
) {}
|
|
400
|
+
|
|
206
401
|
// ------------------------------------------
|
|
207
402
|
// Internal
|
|
208
403
|
// -------------------------------------------
|