clanka 0.21.0 → 0.22.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.
- package/dist/Acp.test.js +19 -7
- package/dist/Acp.test.js.map +1 -1
- package/dist/Agent.d.ts +4 -4
- package/dist/Agent.d.ts.map +1 -1
- package/dist/Agent.js +140 -99
- package/dist/Agent.js.map +1 -1
- package/dist/Agent.test.js +5 -4
- package/dist/Agent.test.js.map +1 -1
- package/dist/AgentBashJobs.test.js +47 -32
- package/dist/AgentBashJobs.test.js.map +1 -1
- package/dist/AgentCallerConfig.test.js +26 -7
- package/dist/AgentCallerConfig.test.js.map +1 -1
- package/dist/AgentExecutor.d.ts +71 -41
- package/dist/AgentExecutor.d.ts.map +1 -1
- package/dist/AgentExecutor.js +86 -79
- package/dist/AgentExecutor.js.map +1 -1
- package/dist/AgentExecutor.test.js +108 -83
- package/dist/AgentExecutor.test.js.map +1 -1
- package/dist/AgentExecutorImage.test.js +2 -2
- package/dist/AgentExecutorImage.test.js.map +1 -1
- package/dist/AgentImage.test.js +3 -2
- package/dist/AgentImage.test.js.map +1 -1
- package/dist/AgentSubagents.test.js +218 -29
- package/dist/AgentSubagents.test.js.map +1 -1
- package/dist/AgentTools.d.ts +318 -290
- package/dist/AgentTools.d.ts.map +1 -1
- package/dist/AgentTools.js +225 -199
- package/dist/AgentTools.js.map +1 -1
- package/dist/AgentTools.test.js +2 -2
- package/dist/AgentTools.test.js.map +1 -1
- package/dist/AgentToolsReadFile.test.js +8 -2
- package/dist/AgentToolsReadFile.test.js.map +1 -1
- package/dist/bin/cli.mjs +309 -289
- package/dist/bin/cli.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Acp.test.ts +31 -10
- package/src/Agent.test.ts +5 -4
- package/src/Agent.ts +175 -140
- package/src/AgentBashJobs.test.ts +70 -38
- package/src/AgentCallerConfig.test.ts +39 -7
- package/src/AgentExecutor.test.ts +132 -91
- package/src/AgentExecutor.ts +120 -105
- package/src/AgentExecutorImage.test.ts +2 -2
- package/src/AgentImage.test.ts +4 -3
- package/src/AgentSubagents.test.ts +825 -562
- package/src/AgentTools.test.ts +2 -2
- package/src/AgentTools.ts +345 -288
- package/src/AgentToolsReadFile.test.ts +14 -3
package/dist/AgentExecutor.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AgentTaskExecutor, type AgentTasks, AgentTools, AgentToolsWithSearch, CurrentDirectory, DirectoryChanger, type ExcludableTool, ImageAttacher, type ImageAttachment, Task, TaskCompleter, type TaskHandle } from "./AgentTools.ts";
|
|
2
2
|
import { ToolkitRenderer } from "./ToolkitRenderer.ts";
|
|
3
3
|
import * as AgentSkills from "./AgentSkills.ts";
|
|
4
4
|
import type * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
|
|
@@ -76,20 +76,26 @@ export interface ExecuteOptions {
|
|
|
76
76
|
* yet, for example while sub-agents are still running.
|
|
77
77
|
*/
|
|
78
78
|
readonly onTaskComplete: (summary: string) => Effect.Effect<void, string>;
|
|
79
|
+
/**
|
|
80
|
+
* The agent running the script. Background bash tasks are scoped to it,
|
|
81
|
+
* like the sub-agents in `agentTasks`: the task functions only see tasks
|
|
82
|
+
* started under the same id. Scripts without one share their tasks.
|
|
83
|
+
*/
|
|
84
|
+
readonly agentId?: string | undefined;
|
|
79
85
|
/**
|
|
80
86
|
* The sub-agents of the agent running the script.
|
|
81
87
|
*/
|
|
82
|
-
readonly
|
|
88
|
+
readonly agentTasks: ExecuteAgentTasks;
|
|
83
89
|
/**
|
|
84
90
|
* Receives every image `readFile` attached while the script ran.
|
|
85
91
|
*/
|
|
86
92
|
readonly onImage: (image: ImageAttachment) => Effect.Effect<void>;
|
|
87
93
|
/**
|
|
88
|
-
* Receives every background `bash`
|
|
89
|
-
* command moved to the background at its timeout. The
|
|
94
|
+
* Receives every background `bash` task the script starts, including a
|
|
95
|
+
* command moved to the background at its timeout. The task can outlive the
|
|
90
96
|
* script, so `await` and `claim` stay usable after it ends.
|
|
91
97
|
*/
|
|
92
|
-
readonly
|
|
98
|
+
readonly onTask?: ((task: TaskHandle) => Effect.Effect<void>) | undefined;
|
|
93
99
|
/**
|
|
94
100
|
* Functions added to the script sandbox whose handlers run on the loop
|
|
95
101
|
* side, next to the Agent.
|
|
@@ -105,12 +111,13 @@ export interface ExecuteOptions {
|
|
|
105
111
|
* @since 1.0.0
|
|
106
112
|
* @category Models
|
|
107
113
|
*/
|
|
108
|
-
export interface
|
|
114
|
+
export interface ExecuteAgentTasks extends Omit<AgentTasks, "delegate"> {
|
|
109
115
|
readonly delegate: (options: {
|
|
116
|
+
readonly id: string;
|
|
110
117
|
readonly prompt: string;
|
|
111
118
|
readonly background: boolean;
|
|
112
119
|
readonly environment: EnvironmentUpdate;
|
|
113
|
-
}) => Effect.Effect<
|
|
120
|
+
}) => Effect.Effect<Task>;
|
|
114
121
|
}
|
|
115
122
|
declare const ExecutionEnvironment_base: Schema.Class<ExecutionEnvironment, Schema.Struct<{
|
|
116
123
|
readonly cwd: Schema.String;
|
|
@@ -181,12 +188,12 @@ declare const Capabilities_base: Schema.Class<Capabilities, Schema.Struct<{
|
|
|
181
188
|
*/
|
|
182
189
|
readonly skills: Schema.withConstructorDefault<Schema.withDecodingDefaultKey<Schema.$Array<typeof AgentSkills.Skill>, never>>;
|
|
183
190
|
/**
|
|
184
|
-
* Whether the executor hands background `bash`
|
|
185
|
-
* `ExecuteOptions.
|
|
186
|
-
* and executor servers from before
|
|
187
|
-
* model is told to poll with `
|
|
191
|
+
* Whether the executor hands background `bash` tasks to
|
|
192
|
+
* `ExecuteOptions.onTask`, so the agent can push their results. Executors
|
|
193
|
+
* and executor servers from before task pushes leave it out, and then the
|
|
194
|
+
* model is told to poll with `taskOutput`.
|
|
188
195
|
*/
|
|
189
|
-
readonly
|
|
196
|
+
readonly taskPushes: Schema.withConstructorDefault<Schema.withDecodingDefaultKey<Schema.Boolean, never>>;
|
|
190
197
|
}>, {}>;
|
|
191
198
|
/**
|
|
192
199
|
* @since 1.0.0
|
|
@@ -239,12 +246,12 @@ export interface LocalOptions<Toolkit extends Toolkit.Any = never> {
|
|
|
239
246
|
readonly limits?: Limits | undefined;
|
|
240
247
|
/**
|
|
241
248
|
* Built-in tools to leave out of the sandbox and the type declarations.
|
|
242
|
-
* Leaving out `delegate` also leaves out
|
|
243
|
-
*
|
|
249
|
+
* Leaving out `delegate` also leaves out `messageAgent`, and leaving out
|
|
250
|
+
* both `delegate` and `bash` leaves out the task functions.
|
|
244
251
|
*/
|
|
245
252
|
readonly excludeTools?: ReadonlyArray<ExcludableTool> | undefined;
|
|
246
253
|
}
|
|
247
|
-
type LocalServices<Toolkit> = ToolkitRenderer | FileSystem.FileSystem | Path.Path | Tool.HandlersFor<typeof AgentToolsWithSearch.tools> | Exclude<Toolkit extends Toolkit.Toolkit<infer T> ? Tool.HandlersFor<T> | Tool.HandlerServices<T[keyof T]> : never, CurrentDirectory | DirectoryChanger |
|
|
254
|
+
type LocalServices<Toolkit> = ToolkitRenderer | FileSystem.FileSystem | Path.Path | Tool.HandlersFor<typeof AgentToolsWithSearch.tools> | Exclude<Toolkit extends Toolkit.Toolkit<infer T> ? Tool.HandlersFor<T> | Tool.HandlerServices<T[keyof T]> : never, CurrentDirectory | DirectoryChanger | AgentTaskExecutor | TaskCompleter | ImageAttacher>;
|
|
248
255
|
/**
|
|
249
256
|
* @since 1.0.0
|
|
250
257
|
* @category Constructors
|
|
@@ -287,7 +294,7 @@ export declare const makeRpc: Effect.Effect<{
|
|
|
287
294
|
* @since 1.0.0
|
|
288
295
|
* @category Layers
|
|
289
296
|
*/
|
|
290
|
-
export declare const layerLocal: <Toolkit extends Toolkit.Any = never>(options: LocalOptions<Toolkit>) => Layer.Layer<AgentExecutor, never, FileSystem.FileSystem | Path.Path | ChildProcessSpawner.ChildProcessSpawner | HttpClient.HttpClient | Exclude<Toolkit extends Toolkit.Toolkit<infer T> ? Tool.HandlersFor<T> | Tool.HandlerServices<T[keyof T]> : never, CurrentDirectory | DirectoryChanger |
|
|
297
|
+
export declare const layerLocal: <Toolkit extends Toolkit.Any = never>(options: LocalOptions<Toolkit>) => Layer.Layer<AgentExecutor, never, FileSystem.FileSystem | Path.Path | ChildProcessSpawner.ChildProcessSpawner | HttpClient.HttpClient | Exclude<Toolkit extends Toolkit.Toolkit<infer T> ? Tool.HandlersFor<T> | Tool.HandlerServices<T[keyof T]> : never, CurrentDirectory | DirectoryChanger | AgentTaskExecutor | TaskCompleter | ImageAttacher>>;
|
|
291
298
|
/**
|
|
292
299
|
* Create an AgentExecutor that communicates with a remote RpcServer serving the
|
|
293
300
|
* AgentExecutor protocol.
|
|
@@ -304,13 +311,14 @@ export declare const layerRpc: Layer.Layer<AgentExecutor, never, RpcClient.Proto
|
|
|
304
311
|
* @since 1.0.0
|
|
305
312
|
* @category Layers
|
|
306
313
|
*/
|
|
307
|
-
export declare const layerRpcServer: <Toolkit extends Toolkit.Any = never>(options: LocalOptions<Toolkit>) => Layer.Layer<never, never, RpcServer.Protocol | FileSystem.FileSystem | HttpClient.HttpClient | Path.Path | ChildProcessSpawner.ChildProcessSpawner | Exclude<Toolkit extends Toolkit.Toolkit<infer T> ? Tool.HandlersFor<T> | Tool.HandlerServices<T[keyof T]> : never, CurrentDirectory | DirectoryChanger |
|
|
314
|
+
export declare const layerRpcServer: <Toolkit extends Toolkit.Any = never>(options: LocalOptions<Toolkit>) => Layer.Layer<never, never, RpcServer.Protocol | FileSystem.FileSystem | HttpClient.HttpClient | Path.Path | ChildProcessSpawner.ChildProcessSpawner | Exclude<Toolkit extends Toolkit.Toolkit<infer T> ? Tool.HandlersFor<T> | Tool.HandlerServices<T[keyof T]> : never, CurrentDirectory | DirectoryChanger | AgentTaskExecutor | TaskCompleter | ImageAttacher>>;
|
|
308
315
|
/**
|
|
309
316
|
* @since 1.0.0
|
|
310
317
|
* @category Rpcs
|
|
311
318
|
*/
|
|
312
319
|
export declare const AgentRequest: Schema.TaggedUnion<{
|
|
313
320
|
readonly Delegate: Schema.TaggedStruct<"Delegate", {
|
|
321
|
+
readonly id: Schema.String;
|
|
314
322
|
readonly prompt: Schema.String;
|
|
315
323
|
readonly background: Schema.Boolean;
|
|
316
324
|
readonly environment: typeof EnvironmentUpdate;
|
|
@@ -318,7 +326,7 @@ export declare const AgentRequest: Schema.TaggedUnion<{
|
|
|
318
326
|
readonly EnvironmentChanged: Schema.TaggedStruct<"EnvironmentChanged", {
|
|
319
327
|
readonly environment: typeof ExecutionEnvironment;
|
|
320
328
|
}>;
|
|
321
|
-
readonly
|
|
329
|
+
readonly ListTasks: Schema.TaggedStruct<"ListTasks", {}>;
|
|
322
330
|
readonly LoopTool: Schema.TaggedStruct<"LoopTool", {
|
|
323
331
|
readonly name: Schema.String;
|
|
324
332
|
readonly params: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
@@ -327,14 +335,18 @@ export declare const AgentRequest: Schema.TaggedUnion<{
|
|
|
327
335
|
readonly id: Schema.String;
|
|
328
336
|
readonly message: Schema.String;
|
|
329
337
|
}>;
|
|
330
|
-
readonly
|
|
338
|
+
readonly StopTask: Schema.TaggedStruct<"StopTask", {
|
|
331
339
|
readonly id: Schema.String;
|
|
332
340
|
}>;
|
|
333
341
|
readonly TaskComplete: Schema.TaggedStruct<"TaskComplete", {
|
|
334
342
|
readonly summary: Schema.String;
|
|
335
343
|
}>;
|
|
336
|
-
readonly
|
|
337
|
-
readonly
|
|
344
|
+
readonly TaskOutput: Schema.TaggedStruct<"TaskOutput", {
|
|
345
|
+
readonly id: Schema.String;
|
|
346
|
+
}>;
|
|
347
|
+
readonly WaitTasks: Schema.TaggedStruct<"WaitTasks", {
|
|
348
|
+
readonly ids: Schema.$Array<Schema.String>;
|
|
349
|
+
readonly timeoutMs: Schema.Finite;
|
|
338
350
|
}>;
|
|
339
351
|
}>;
|
|
340
352
|
/**
|
|
@@ -365,13 +377,11 @@ export declare const ExecuteOutput: Schema.TaggedUnion<{
|
|
|
365
377
|
readonly mediaType: Schema.Literals<readonly ["image/png", "image/jpeg", "image/gif", "image/webp"]>;
|
|
366
378
|
readonly data: Schema.Uint8Array;
|
|
367
379
|
}>;
|
|
368
|
-
readonly Job: Schema.TaggedStruct<"Job", {
|
|
369
|
-
readonly id: Schema.String;
|
|
370
|
-
}>;
|
|
371
380
|
readonly Request: Schema.TaggedStruct<"Request", {
|
|
372
381
|
readonly id: Schema.Finite;
|
|
373
382
|
readonly request: Schema.TaggedUnion<{
|
|
374
383
|
readonly Delegate: Schema.TaggedStruct<"Delegate", {
|
|
384
|
+
readonly id: Schema.String;
|
|
375
385
|
readonly prompt: Schema.String;
|
|
376
386
|
readonly background: Schema.Boolean;
|
|
377
387
|
readonly environment: typeof EnvironmentUpdate;
|
|
@@ -379,7 +389,7 @@ export declare const ExecuteOutput: Schema.TaggedUnion<{
|
|
|
379
389
|
readonly EnvironmentChanged: Schema.TaggedStruct<"EnvironmentChanged", {
|
|
380
390
|
readonly environment: typeof ExecutionEnvironment;
|
|
381
391
|
}>;
|
|
382
|
-
readonly
|
|
392
|
+
readonly ListTasks: Schema.TaggedStruct<"ListTasks", {}>;
|
|
383
393
|
readonly LoopTool: Schema.TaggedStruct<"LoopTool", {
|
|
384
394
|
readonly name: Schema.String;
|
|
385
395
|
readonly params: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
@@ -388,29 +398,39 @@ export declare const ExecuteOutput: Schema.TaggedUnion<{
|
|
|
388
398
|
readonly id: Schema.String;
|
|
389
399
|
readonly message: Schema.String;
|
|
390
400
|
}>;
|
|
391
|
-
readonly
|
|
401
|
+
readonly StopTask: Schema.TaggedStruct<"StopTask", {
|
|
392
402
|
readonly id: Schema.String;
|
|
393
403
|
}>;
|
|
394
404
|
readonly TaskComplete: Schema.TaggedStruct<"TaskComplete", {
|
|
395
405
|
readonly summary: Schema.String;
|
|
396
406
|
}>;
|
|
397
|
-
readonly
|
|
398
|
-
readonly
|
|
407
|
+
readonly TaskOutput: Schema.TaggedStruct<"TaskOutput", {
|
|
408
|
+
readonly id: Schema.String;
|
|
409
|
+
}>;
|
|
410
|
+
readonly WaitTasks: Schema.TaggedStruct<"WaitTasks", {
|
|
411
|
+
readonly ids: Schema.$Array<Schema.String>;
|
|
412
|
+
readonly timeoutMs: Schema.Finite;
|
|
399
413
|
}>;
|
|
400
414
|
}>;
|
|
401
415
|
}>;
|
|
416
|
+
readonly Task: Schema.TaggedStruct<"Task", {
|
|
417
|
+
readonly id: Schema.String;
|
|
418
|
+
readonly kind: Schema.Literals<readonly ["bash", "agent"]>;
|
|
419
|
+
}>;
|
|
402
420
|
readonly Text: Schema.TaggedStruct<"Text", {
|
|
403
421
|
readonly text: Schema.String;
|
|
404
422
|
}>;
|
|
405
423
|
}>;
|
|
406
|
-
declare const Rpcs_base: RpcGroup.RpcGroup<Rpc.Rpc<"
|
|
424
|
+
declare const Rpcs_base: RpcGroup.RpcGroup<Rpc.Rpc<"awaitTask", Schema.Struct<{
|
|
407
425
|
id: Schema.String;
|
|
408
426
|
}>, Schema.Struct<{
|
|
409
427
|
readonly id: Schema.String;
|
|
428
|
+
readonly kind: Schema.Literals<readonly ["bash", "agent"]>;
|
|
410
429
|
readonly status: Schema.Literals<readonly ["running", "completed", "failed", "stopped"]>;
|
|
411
|
-
readonly
|
|
430
|
+
readonly description: Schema.String;
|
|
412
431
|
readonly output: Schema.String;
|
|
413
|
-
|
|
432
|
+
readonly exitCode: Schema.optional<Schema.Number>;
|
|
433
|
+
}>, Schema.String, never, never> | Rpc.Rpc<"capabilities", Schema.Void, typeof Capabilities, Schema.Never, never, never> | Rpc.Rpc<"claimTask", Schema.Struct<{
|
|
414
434
|
id: Schema.String;
|
|
415
435
|
}>, Schema.Boolean, Schema.String, never, never> | Rpc.Rpc<"execute", Schema.Struct<{
|
|
416
436
|
readonly script: Schema.String;
|
|
@@ -420,10 +440,14 @@ declare const Rpcs_base: RpcGroup.RpcGroup<Rpc.Rpc<"awaitJob", Schema.Struct<{
|
|
|
420
440
|
*/
|
|
421
441
|
readonly loopTools: Schema.withDecodingDefaultKey<Schema.$Array<Schema.String>, never>;
|
|
422
442
|
/**
|
|
423
|
-
*
|
|
424
|
-
|
|
443
|
+
* The agent running the script, which owns the tasks it starts.
|
|
444
|
+
*/
|
|
445
|
+
readonly agentId: Schema.optionalKey<Schema.String>;
|
|
446
|
+
/**
|
|
447
|
+
* Send a `Task` part for each background bash task the script starts.
|
|
448
|
+
* Older clients leave it out, as they cannot decode those parts.
|
|
425
449
|
*/
|
|
426
|
-
readonly
|
|
450
|
+
readonly watchTasks: Schema.optionalKey<Schema.Boolean>;
|
|
427
451
|
}>, import("effect/rpc/RpcSchema").Stream<Schema.TaggedUnion<{
|
|
428
452
|
readonly Environment: Schema.TaggedStruct<"Environment", {
|
|
429
453
|
readonly environment: typeof ExecutionEnvironment;
|
|
@@ -433,13 +457,11 @@ declare const Rpcs_base: RpcGroup.RpcGroup<Rpc.Rpc<"awaitJob", Schema.Struct<{
|
|
|
433
457
|
readonly mediaType: Schema.Literals<readonly ["image/png", "image/jpeg", "image/gif", "image/webp"]>;
|
|
434
458
|
readonly data: Schema.Uint8Array;
|
|
435
459
|
}>;
|
|
436
|
-
readonly Job: Schema.TaggedStruct<"Job", {
|
|
437
|
-
readonly id: Schema.String;
|
|
438
|
-
}>;
|
|
439
460
|
readonly Request: Schema.TaggedStruct<"Request", {
|
|
440
461
|
readonly id: Schema.Finite;
|
|
441
462
|
readonly request: Schema.TaggedUnion<{
|
|
442
463
|
readonly Delegate: Schema.TaggedStruct<"Delegate", {
|
|
464
|
+
readonly id: Schema.String;
|
|
443
465
|
readonly prompt: Schema.String;
|
|
444
466
|
readonly background: Schema.Boolean;
|
|
445
467
|
readonly environment: typeof EnvironmentUpdate;
|
|
@@ -447,7 +469,7 @@ declare const Rpcs_base: RpcGroup.RpcGroup<Rpc.Rpc<"awaitJob", Schema.Struct<{
|
|
|
447
469
|
readonly EnvironmentChanged: Schema.TaggedStruct<"EnvironmentChanged", {
|
|
448
470
|
readonly environment: typeof ExecutionEnvironment;
|
|
449
471
|
}>;
|
|
450
|
-
readonly
|
|
472
|
+
readonly ListTasks: Schema.TaggedStruct<"ListTasks", {}>;
|
|
451
473
|
readonly LoopTool: Schema.TaggedStruct<"LoopTool", {
|
|
452
474
|
readonly name: Schema.String;
|
|
453
475
|
readonly params: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
@@ -456,17 +478,25 @@ declare const Rpcs_base: RpcGroup.RpcGroup<Rpc.Rpc<"awaitJob", Schema.Struct<{
|
|
|
456
478
|
readonly id: Schema.String;
|
|
457
479
|
readonly message: Schema.String;
|
|
458
480
|
}>;
|
|
459
|
-
readonly
|
|
481
|
+
readonly StopTask: Schema.TaggedStruct<"StopTask", {
|
|
460
482
|
readonly id: Schema.String;
|
|
461
483
|
}>;
|
|
462
484
|
readonly TaskComplete: Schema.TaggedStruct<"TaskComplete", {
|
|
463
485
|
readonly summary: Schema.String;
|
|
464
486
|
}>;
|
|
465
|
-
readonly
|
|
466
|
-
readonly
|
|
487
|
+
readonly TaskOutput: Schema.TaggedStruct<"TaskOutput", {
|
|
488
|
+
readonly id: Schema.String;
|
|
489
|
+
}>;
|
|
490
|
+
readonly WaitTasks: Schema.TaggedStruct<"WaitTasks", {
|
|
491
|
+
readonly ids: Schema.$Array<Schema.String>;
|
|
492
|
+
readonly timeoutMs: Schema.Finite;
|
|
467
493
|
}>;
|
|
468
494
|
}>;
|
|
469
495
|
}>;
|
|
496
|
+
readonly Task: Schema.TaggedStruct<"Task", {
|
|
497
|
+
readonly id: Schema.String;
|
|
498
|
+
readonly kind: Schema.Literals<readonly ["bash", "agent"]>;
|
|
499
|
+
}>;
|
|
470
500
|
readonly Text: Schema.TaggedStruct<"Text", {
|
|
471
501
|
readonly text: Schema.String;
|
|
472
502
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentExecutor.d.ts","sourceRoot":"","sources":["../src/AgentEx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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA/BT;;;GAGG;AACH,qBAAa,IAAK,SAAQ,SA8DzB;CAAG"}
|
package/dist/AgentExecutor.js
CHANGED
|
@@ -6,7 +6,7 @@ import * as NodeOs from "node:os";
|
|
|
6
6
|
import * as NodeVm from "node:vm";
|
|
7
7
|
import { Writable } from "node:stream";
|
|
8
8
|
import { Worker } from "node:worker_threads";
|
|
9
|
-
import {
|
|
9
|
+
import { AgentTaskExecutor, agentTasksUnavailable, AgentToolHandlers, AgentTools, AgentToolsWithSearch, CommandLimits, CurrentDirectory, defaultBashTimeout, DirectoryChanger, ImageAttacher, makeBashTool, Task, TaskCompleter, TaskKind, TaskOwner, TaskWatcher, } from "./AgentTools.js";
|
|
10
10
|
import * as Image from "./Image.js";
|
|
11
11
|
import { ToolkitRenderer } from "./ToolkitRenderer.js";
|
|
12
12
|
import * as AgentEnvironment from "./AgentEnvironment.js";
|
|
@@ -107,12 +107,12 @@ export class Capabilities extends Schema.Class("Capabilities")({
|
|
|
107
107
|
*/
|
|
108
108
|
skills: Schema.Array(AgentSkills.Skill).pipe(Schema.withDecodingDefaultKey(Effect.succeed([])), Schema.withConstructorDefault(Effect.succeed([]))),
|
|
109
109
|
/**
|
|
110
|
-
* Whether the executor hands background `bash`
|
|
111
|
-
* `ExecuteOptions.
|
|
112
|
-
* and executor servers from before
|
|
113
|
-
* model is told to poll with `
|
|
110
|
+
* Whether the executor hands background `bash` tasks to
|
|
111
|
+
* `ExecuteOptions.onTask`, so the agent can push their results. Executors
|
|
112
|
+
* and executor servers from before task pushes leave it out, and then the
|
|
113
|
+
* model is told to poll with `taskOutput`.
|
|
114
114
|
*/
|
|
115
|
-
|
|
115
|
+
taskPushes: Schema.Boolean.pipe(Schema.withDecodingDefaultKey(Effect.succeed(false)), Schema.withConstructorDefault(Effect.succeed(false))),
|
|
116
116
|
}) {
|
|
117
117
|
}
|
|
118
118
|
/**
|
|
@@ -222,12 +222,12 @@ const makeLocalWith = Effect.fnUntraced(function* (options) {
|
|
|
222
222
|
currentDirectory = target;
|
|
223
223
|
return onChange ? onChange(currentEnvironment()) : Effect.void;
|
|
224
224
|
}));
|
|
225
|
-
const taskServices = Context.empty().pipe(Context.add(TaskCompleter, opts.onTaskComplete), Context.add(DirectoryChanger, changeDirectory), Context.add(
|
|
226
|
-
...opts.
|
|
225
|
+
const taskServices = Context.empty().pipe(Context.add(TaskCompleter, opts.onTaskComplete), Context.add(DirectoryChanger, changeDirectory), Context.add(AgentTaskExecutor, {
|
|
226
|
+
...opts.agentTasks,
|
|
227
227
|
// A new agent has only the system prompt, so it gets everything that
|
|
228
228
|
// applies to the directory.
|
|
229
|
-
delegate: (options) => renderEnvironment(currentEnvironment(), { reset: true }).pipe(Effect.flatMap((environment) => opts.
|
|
230
|
-
}), Context.add(ImageAttacher, opts.onImage), Context.add(
|
|
229
|
+
delegate: (options) => renderEnvironment(currentEnvironment(), { reset: true }).pipe(Effect.flatMap((environment) => opts.agentTasks.delegate({ ...options, environment }))),
|
|
230
|
+
}), Context.add(ImageAttacher, opts.onImage), Context.add(TaskWatcher, opts.onTask ?? (() => Effect.void)), Context.add(TaskOwner, opts.agentId), Context.add(CommandLimits, commandLimits), Context.add(Console.Console, console), Context.add(References.CurrentLogAnnotations, {}), Option.isSome(search)
|
|
231
231
|
? Context.add(SemanticSearch, search.value)
|
|
232
232
|
: identity);
|
|
233
233
|
// The script runs in its own worker thread, so a script that is busy in
|
|
@@ -334,7 +334,7 @@ const makeLocalWith = Effect.fnUntraced(function* (options) {
|
|
|
334
334
|
}),
|
|
335
335
|
tools: Object.keys(tools.tools),
|
|
336
336
|
skills,
|
|
337
|
-
|
|
337
|
+
taskPushes: true,
|
|
338
338
|
});
|
|
339
339
|
}),
|
|
340
340
|
execute: (opts) => execute(opts),
|
|
@@ -349,7 +349,7 @@ const makeLocalWith = Effect.fnUntraced(function* (options) {
|
|
|
349
349
|
return Effect.die(new Error(`Unknown tool: ${opts.tool}`));
|
|
350
350
|
}
|
|
351
351
|
const cwd = (opts.environment ?? startupEnvironment).cwd;
|
|
352
|
-
const taskServices = handler.context.pipe(Context.add(TaskCompleter, () => Effect.void), Context.add(CurrentDirectory, cwd), Context.add(DirectoryChanger, (directory) => resolveDirectory(cwd, directory)), Context.add(
|
|
352
|
+
const taskServices = handler.context.pipe(Context.add(TaskCompleter, () => Effect.void), Context.add(CurrentDirectory, cwd), Context.add(DirectoryChanger, (directory) => resolveDirectory(cwd, directory)), Context.add(AgentTaskExecutor, agentTasksUnavailable),
|
|
353
353
|
// Direct tool calls have no model turn to attach images to.
|
|
354
354
|
Context.add(ImageAttacher, () => Effect.void), Context.add(CommandLimits, commandLimits), Context.add(References.CurrentLogAnnotations, {}), Option.isSome(search)
|
|
355
355
|
? Context.add(SemanticSearch, search.value)
|
|
@@ -379,7 +379,8 @@ export const makeRpc = Effect.gen(function* () {
|
|
|
379
379
|
script: opts.script,
|
|
380
380
|
environment: opts.environment,
|
|
381
381
|
loopTools: Object.keys(opts.loopTools ?? {}),
|
|
382
|
-
...(opts.
|
|
382
|
+
...(opts.agentId === undefined ? {} : { agentId: opts.agentId }),
|
|
383
|
+
...(opts.onTask === undefined ? {} : { watchTasks: true }),
|
|
383
384
|
})
|
|
384
385
|
.pipe(Stream.tap((part) => {
|
|
385
386
|
switch (part._tag) {
|
|
@@ -404,14 +405,15 @@ export const makeRpc = Effect.gen(function* () {
|
|
|
404
405
|
latest = part.environment;
|
|
405
406
|
return Effect.void;
|
|
406
407
|
}
|
|
407
|
-
case "
|
|
408
|
-
if (opts.
|
|
408
|
+
case "Task": {
|
|
409
|
+
if (opts.onTask === undefined)
|
|
409
410
|
return Effect.void;
|
|
410
411
|
const id = part.id;
|
|
411
|
-
return opts.
|
|
412
|
+
return opts.onTask({
|
|
412
413
|
id,
|
|
413
|
-
|
|
414
|
-
|
|
414
|
+
kind: part.kind,
|
|
415
|
+
await: Effect.orDie(client.awaitTask({ id })),
|
|
416
|
+
claim: Effect.orDie(client.claimTask({ id })),
|
|
415
417
|
});
|
|
416
418
|
}
|
|
417
419
|
}
|
|
@@ -459,20 +461,20 @@ export const layerRpcServer = (options) => RpcServer.layer(Rpcs, {
|
|
|
459
461
|
const local = yield* withBuiltInHandlers(makeLocalWith(options));
|
|
460
462
|
const requestResumes = new Map();
|
|
461
463
|
let requestId = 0;
|
|
462
|
-
// Background
|
|
463
|
-
// `
|
|
464
|
-
const
|
|
465
|
-
const
|
|
466
|
-
const
|
|
467
|
-
return
|
|
468
|
-
? Effect.fail(`No
|
|
469
|
-
: Effect.succeed(
|
|
464
|
+
// Background bash tasks started by any script, for `awaitTask` and
|
|
465
|
+
// `claimTask`.
|
|
466
|
+
const tasks = new Map();
|
|
467
|
+
const findTask = (id) => Effect.suspend(() => {
|
|
468
|
+
const task = tasks.get(id);
|
|
469
|
+
return task === undefined
|
|
470
|
+
? Effect.fail(`No task with id "${id}"`)
|
|
471
|
+
: Effect.succeed(task);
|
|
470
472
|
});
|
|
471
473
|
return Rpcs.of({
|
|
472
474
|
capabilities: () => local.executor.capabilities,
|
|
473
475
|
renderEnvironment: ({ environment, reset }) => local.renderEnvironment(environment, { reset }),
|
|
474
|
-
|
|
475
|
-
|
|
476
|
+
awaitTask: ({ id }) => Effect.flatMap(findTask(id), (task) => task.await),
|
|
477
|
+
claimTask: ({ id }) => Effect.flatMap(findTask(id), (task) => task.claim),
|
|
476
478
|
respond: ({ id, response }) => {
|
|
477
479
|
const resume = requestResumes.get(id);
|
|
478
480
|
if (resume) {
|
|
@@ -483,7 +485,7 @@ export const layerRpcServer = (options) => RpcServer.layer(Rpcs, {
|
|
|
483
485
|
}
|
|
484
486
|
return Effect.void;
|
|
485
487
|
},
|
|
486
|
-
execute: Effect.fnUntraced(function* ({ script, environment, loopTools,
|
|
488
|
+
execute: Effect.fnUntraced(function* ({ script, environment, loopTools, agentId, watchTasks, }) {
|
|
487
489
|
const queue = yield* Queue.unbounded();
|
|
488
490
|
// Sends a request to the client and waits for its response.
|
|
489
491
|
// IDs come from a server-wide counter, so concurrent and nested
|
|
@@ -502,22 +504,25 @@ export const layerRpcServer = (options) => RpcServer.layer(Rpcs, {
|
|
|
502
504
|
environment,
|
|
503
505
|
onEnvironment: (environment) => Queue.offer(queue, { _tag: "Environment", environment }),
|
|
504
506
|
onTaskComplete: (summary) => request({ _tag: "TaskComplete", summary }),
|
|
505
|
-
|
|
507
|
+
agentId,
|
|
508
|
+
agentTasks: {
|
|
506
509
|
delegate: (options) => Effect.orDie(request({
|
|
507
510
|
_tag: "Delegate",
|
|
508
511
|
...options,
|
|
509
512
|
})),
|
|
510
|
-
|
|
511
|
-
|
|
513
|
+
taskOutput: (id) => request({ _tag: "TaskOutput", id }),
|
|
514
|
+
waitTasks: (ids, { timeoutMs }) => request({
|
|
515
|
+
_tag: "WaitTasks",
|
|
512
516
|
ids,
|
|
517
|
+
timeoutMs,
|
|
513
518
|
}),
|
|
514
519
|
messageAgent: (options) => request({
|
|
515
520
|
_tag: "MessageAgent",
|
|
516
521
|
...options,
|
|
517
522
|
}),
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
_tag: "
|
|
523
|
+
stopTask: (id) => request({ _tag: "StopTask", id }),
|
|
524
|
+
listTasks: Effect.orDie(request({
|
|
525
|
+
_tag: "ListTasks",
|
|
521
526
|
})),
|
|
522
527
|
},
|
|
523
528
|
onImage(image) {
|
|
@@ -528,14 +533,15 @@ export const layerRpcServer = (options) => RpcServer.layer(Rpcs, {
|
|
|
528
533
|
data: image.data,
|
|
529
534
|
});
|
|
530
535
|
},
|
|
531
|
-
// Older clients cannot decode a `
|
|
532
|
-
...(
|
|
536
|
+
// Older clients cannot decode a `Task` part.
|
|
537
|
+
...(watchTasks === true
|
|
533
538
|
? {
|
|
534
|
-
|
|
535
|
-
|
|
539
|
+
onTask: (task) => {
|
|
540
|
+
tasks.set(task.id, task);
|
|
536
541
|
return Queue.offer(queue, {
|
|
537
|
-
_tag: "
|
|
538
|
-
id:
|
|
542
|
+
_tag: "Task",
|
|
543
|
+
id: task.id,
|
|
544
|
+
kind: task.kind,
|
|
539
545
|
});
|
|
540
546
|
},
|
|
541
547
|
}
|
|
@@ -577,14 +583,16 @@ export const layerRpcServer = (options) => RpcServer.layer(Rpcs, {
|
|
|
577
583
|
export const AgentRequest = Schema.TaggedUnion({
|
|
578
584
|
TaskComplete: { summary: Schema.String },
|
|
579
585
|
Delegate: {
|
|
586
|
+
id: Schema.String,
|
|
580
587
|
prompt: Schema.String,
|
|
581
588
|
background: Schema.Boolean,
|
|
582
589
|
environment: EnvironmentUpdate,
|
|
583
590
|
},
|
|
584
|
-
|
|
591
|
+
TaskOutput: { id: Schema.String },
|
|
592
|
+
WaitTasks: { ids: Schema.Array(Schema.String), timeoutMs: Schema.Finite },
|
|
585
593
|
MessageAgent: { id: Schema.String, message: Schema.String },
|
|
586
|
-
|
|
587
|
-
|
|
594
|
+
StopTask: { id: Schema.String },
|
|
595
|
+
ListTasks: {},
|
|
588
596
|
LoopTool: { name: Schema.String, params: Schema.optional(Schema.Json) },
|
|
589
597
|
/**
|
|
590
598
|
* The script changed its environment. The client records it before it
|
|
@@ -621,11 +629,11 @@ export const ExecuteOutput = Schema.TaggedUnion({
|
|
|
621
629
|
*/
|
|
622
630
|
Environment: { environment: ExecutionEnvironment },
|
|
623
631
|
/**
|
|
624
|
-
* The script started a background `bash`
|
|
625
|
-
* asked with `
|
|
626
|
-
* `
|
|
632
|
+
* The script started a background `bash` task. Only sent when the client
|
|
633
|
+
* asked with `watchTasks`. The client follows it with `awaitTask` and
|
|
634
|
+
* `claimTask`.
|
|
627
635
|
*/
|
|
628
|
-
|
|
636
|
+
Task: { id: Schema.String, kind: TaskKind },
|
|
629
637
|
});
|
|
630
638
|
/**
|
|
631
639
|
* @since 1.0.0
|
|
@@ -647,27 +655,31 @@ export class Rpcs extends RpcGroup.make(Rpc.make("capabilities", {
|
|
|
647
655
|
*/
|
|
648
656
|
loopTools: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
|
|
649
657
|
/**
|
|
650
|
-
*
|
|
651
|
-
* clients leave it out, as they cannot decode those parts.
|
|
658
|
+
* The agent running the script, which owns the tasks it starts.
|
|
652
659
|
*/
|
|
653
|
-
|
|
660
|
+
agentId: Schema.optionalKey(Schema.String),
|
|
661
|
+
/**
|
|
662
|
+
* Send a `Task` part for each background bash task the script starts.
|
|
663
|
+
* Older clients leave it out, as they cannot decode those parts.
|
|
664
|
+
*/
|
|
665
|
+
watchTasks: Schema.optionalKey(Schema.Boolean),
|
|
654
666
|
}),
|
|
655
667
|
success: ExecuteOutput,
|
|
656
668
|
stream: true,
|
|
657
669
|
}),
|
|
658
670
|
/**
|
|
659
|
-
* Waits for a background
|
|
671
|
+
* Waits for a background bash task to end and returns its final state.
|
|
660
672
|
*/
|
|
661
|
-
Rpc.make("
|
|
673
|
+
Rpc.make("awaitTask", {
|
|
662
674
|
payload: { id: Schema.String },
|
|
663
|
-
success:
|
|
675
|
+
success: Task,
|
|
664
676
|
error: Schema.String,
|
|
665
677
|
}),
|
|
666
678
|
/**
|
|
667
|
-
* Marks a background
|
|
668
|
-
* it already was.
|
|
679
|
+
* Marks a background bash task's final state as reported. Returns `false`
|
|
680
|
+
* when it already was.
|
|
669
681
|
*/
|
|
670
|
-
Rpc.make("
|
|
682
|
+
Rpc.make("claimTask", {
|
|
671
683
|
payload: { id: Schema.String },
|
|
672
684
|
success: Schema.Boolean,
|
|
673
685
|
error: Schema.String,
|
|
@@ -736,15 +748,17 @@ const handleRequest = (opts, request) => {
|
|
|
736
748
|
case "TaskComplete":
|
|
737
749
|
return opts.onTaskComplete(request.summary);
|
|
738
750
|
case "Delegate":
|
|
739
|
-
return opts.
|
|
740
|
-
case "
|
|
741
|
-
return opts.
|
|
751
|
+
return opts.agentTasks.delegate(request);
|
|
752
|
+
case "TaskOutput":
|
|
753
|
+
return opts.agentTasks.taskOutput(request.id);
|
|
754
|
+
case "WaitTasks":
|
|
755
|
+
return opts.agentTasks.waitTasks(request.ids, request);
|
|
742
756
|
case "MessageAgent":
|
|
743
|
-
return opts.
|
|
744
|
-
case "
|
|
745
|
-
return opts.
|
|
746
|
-
case "
|
|
747
|
-
return opts.
|
|
757
|
+
return opts.agentTasks.messageAgent(request);
|
|
758
|
+
case "StopTask":
|
|
759
|
+
return opts.agentTasks.stopTask(request.id);
|
|
760
|
+
case "ListTasks":
|
|
761
|
+
return opts.agentTasks.listTasks;
|
|
748
762
|
case "EnvironmentChanged":
|
|
749
763
|
// Recorded by the client before it responds.
|
|
750
764
|
return Effect.void;
|
|
@@ -778,25 +792,18 @@ const errorMessage = (error) => typeof error === "string"
|
|
|
778
792
|
: error instanceof Error
|
|
779
793
|
? error.message
|
|
780
794
|
: String(error);
|
|
781
|
-
// Leaving out `delegate` leaves out
|
|
782
|
-
//
|
|
795
|
+
// Leaving out `delegate` leaves out `messageAgent`. The task functions
|
|
796
|
+
// address both kinds, so they go once neither can be started.
|
|
783
797
|
const excludedToolNames = (excludeTools) => {
|
|
784
798
|
const names = new Set(excludeTools);
|
|
785
799
|
if (names.has("delegate")) {
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
"
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
]) {
|
|
792
|
-
names.add(name);
|
|
800
|
+
names.add("messageAgent");
|
|
801
|
+
if (names.has("bash")) {
|
|
802
|
+
for (const name of ["taskOutput", "waitTasks", "stopTask", "listTasks"]) {
|
|
803
|
+
names.add(name);
|
|
804
|
+
}
|
|
793
805
|
}
|
|
794
806
|
}
|
|
795
|
-
if (names.has("bash")) {
|
|
796
|
-
names.add("jobOutput");
|
|
797
|
-
names.add("waitJob");
|
|
798
|
-
names.add("stopJob");
|
|
799
|
-
}
|
|
800
807
|
return names;
|
|
801
808
|
};
|
|
802
809
|
const wrapScript = (script) => `async function main() {
|