zidane 1.5.2 → 1.6.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 +18 -14
- package/dist/agent-DVvuhEN-.d.ts +671 -0
- package/dist/{chunk-PRNQ7DXE.js → chunk-3K5D27BF.js} +20 -59
- package/dist/chunk-7V33E7LT.js +32 -0
- package/dist/chunk-CFLC2I7D.js +8 -0
- package/dist/{chunk-XMFQK35S.js → chunk-VRAZJES3.js} +178 -271
- package/dist/{chunk-ZH2KFHLB.js → chunk-XT7QBZ47.js} +6 -6
- package/dist/{chunk-26LIQARN.js → chunk-YTZOORAP.js} +1 -10
- package/dist/harnesses.d.ts +2 -6
- package/dist/harnesses.js +4 -6
- package/dist/index.d.ts +21 -30
- package/dist/index.js +17 -21
- package/dist/mcp.d.ts +2 -6
- package/dist/mcp.js +1 -4
- package/dist/providers.d.ts +4 -82
- package/dist/providers.js +24 -1
- package/dist/sandbox-C08DQPTu.d.ts +28 -0
- package/dist/session.d.ts +4 -193
- package/dist/session.js +1 -2
- package/dist/skills.d.ts +2 -2
- package/dist/skills.js +2 -3
- package/dist/{spawn-MUlKj85h.d.ts → spawn-DJZZ9ZWw.d.ts} +1 -2
- package/dist/tools.d.ts +5 -18
- package/dist/tools.js +3 -6
- package/dist/{types-D8fzooXc.d.ts → types-CyRzBgm0.d.ts} +1 -1
- package/dist/types.d.ts +7 -0
- package/dist/types.js +0 -0
- package/dist/validation-CwSuvOKf.d.ts +11 -0
- package/package.json +12 -1
- package/dist/agent-DZDheE1c.d.ts +0 -271
- package/dist/chunk-PNKVD2UK.js +0 -26
- package/dist/chunk-QPYZR2QM.js +0 -21
- package/dist/types-CskNDruh.d.ts +0 -110
|
@@ -1,110 +1,87 @@
|
|
|
1
1
|
import {
|
|
2
|
-
connectMcpServers
|
|
3
|
-
|
|
4
|
-
} from "./chunk-26LIQARN.js";
|
|
2
|
+
connectMcpServers
|
|
3
|
+
} from "./chunk-YTZOORAP.js";
|
|
5
4
|
import {
|
|
6
5
|
buildCatalog,
|
|
7
|
-
init_catalog,
|
|
8
|
-
init_interpolate,
|
|
9
|
-
init_resolve,
|
|
10
6
|
interpolateShellCommands,
|
|
11
7
|
mergeSkillsConfig,
|
|
12
8
|
resolveSkills
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import {
|
|
15
|
-
__esm,
|
|
16
|
-
__export,
|
|
17
|
-
__toCommonJS
|
|
18
|
-
} from "./chunk-PNKVD2UK.js";
|
|
9
|
+
} from "./chunk-3K5D27BF.js";
|
|
19
10
|
|
|
20
11
|
// src/tools/list-files.ts
|
|
21
|
-
var listFiles
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
input_schema: {
|
|
30
|
-
type: "object",
|
|
31
|
-
properties: {
|
|
32
|
-
path: { type: "string", description: 'Relative directory path (default: ".")' }
|
|
33
|
-
},
|
|
34
|
-
required: []
|
|
35
|
-
}
|
|
12
|
+
var listFiles = {
|
|
13
|
+
spec: {
|
|
14
|
+
name: "list_files",
|
|
15
|
+
description: "List files and directories at the given path (relative to project root).",
|
|
16
|
+
input_schema: {
|
|
17
|
+
type: "object",
|
|
18
|
+
properties: {
|
|
19
|
+
path: { type: "string", description: 'Relative directory path (default: ".")' }
|
|
36
20
|
},
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
21
|
+
required: []
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
async execute({ path }, ctx) {
|
|
25
|
+
try {
|
|
26
|
+
const entries = await ctx.execution.listFiles(ctx.handle, path || ".");
|
|
27
|
+
return entries.join("\n") || "(empty directory)";
|
|
28
|
+
} catch {
|
|
29
|
+
return `Directory not found: ${path}`;
|
|
30
|
+
}
|
|
46
31
|
}
|
|
47
|
-
}
|
|
32
|
+
};
|
|
48
33
|
|
|
49
34
|
// src/tools/read-file.ts
|
|
50
|
-
var readFile
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
input_schema: {
|
|
59
|
-
type: "object",
|
|
60
|
-
properties: {
|
|
61
|
-
path: { type: "string", description: "Relative file path" }
|
|
62
|
-
},
|
|
63
|
-
required: ["path"]
|
|
64
|
-
}
|
|
35
|
+
var readFile = {
|
|
36
|
+
spec: {
|
|
37
|
+
name: "read_file",
|
|
38
|
+
description: "Read the contents of a file at the given path (relative to project root).",
|
|
39
|
+
input_schema: {
|
|
40
|
+
type: "object",
|
|
41
|
+
properties: {
|
|
42
|
+
path: { type: "string", description: "Relative file path" }
|
|
65
43
|
},
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
44
|
+
required: ["path"]
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
async execute({ path }, ctx) {
|
|
48
|
+
try {
|
|
49
|
+
return await ctx.execution.readFile(ctx.handle, path);
|
|
50
|
+
} catch {
|
|
51
|
+
return `File not found: ${path}`;
|
|
52
|
+
}
|
|
74
53
|
}
|
|
75
|
-
}
|
|
54
|
+
};
|
|
76
55
|
|
|
77
56
|
// src/tools/shell.ts
|
|
78
|
-
var shell
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
"
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
description: "
|
|
86
|
-
input_schema: {
|
|
87
|
-
type: "object",
|
|
88
|
-
properties: {
|
|
89
|
-
command: { type: "string", description: "The shell command to run" }
|
|
90
|
-
},
|
|
91
|
-
required: ["command"]
|
|
92
|
-
}
|
|
57
|
+
var shell = {
|
|
58
|
+
spec: {
|
|
59
|
+
name: "shell",
|
|
60
|
+
description: "Execute a shell command and return stdout+stderr. Runs in the project root.",
|
|
61
|
+
input_schema: {
|
|
62
|
+
type: "object",
|
|
63
|
+
properties: {
|
|
64
|
+
command: { type: "string", description: "The shell command to run" }
|
|
93
65
|
},
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
66
|
+
required: ["command"]
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
async execute({ command }, ctx) {
|
|
70
|
+
const result = await ctx.execution.exec(ctx.handle, command);
|
|
71
|
+
if (result.exitCode === 0) {
|
|
72
|
+
return result.stdout || "(no output)";
|
|
73
|
+
}
|
|
74
|
+
return `Exit code ${result.exitCode}
|
|
100
75
|
${result.stdout}
|
|
101
76
|
${result.stderr}`.trim();
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
77
|
}
|
|
105
|
-
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// src/agent.ts
|
|
81
|
+
import { createHooks } from "hookable";
|
|
106
82
|
|
|
107
83
|
// src/contexts/docker.ts
|
|
84
|
+
var SINGLE_QUOTE_RE = /'/g;
|
|
108
85
|
function createDockerContext(config) {
|
|
109
86
|
let counter = 0;
|
|
110
87
|
const containers = /* @__PURE__ */ new Map();
|
|
@@ -231,19 +208,13 @@ function createDockerContext(config) {
|
|
|
231
208
|
};
|
|
232
209
|
return ctx;
|
|
233
210
|
}
|
|
234
|
-
var SINGLE_QUOTE_RE;
|
|
235
|
-
var init_docker = __esm({
|
|
236
|
-
"src/contexts/docker.ts"() {
|
|
237
|
-
"use strict";
|
|
238
|
-
SINGLE_QUOTE_RE = /'/g;
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
211
|
|
|
242
212
|
// src/contexts/process.ts
|
|
243
213
|
import { exec as execCb } from "child_process";
|
|
244
214
|
import { mkdir, readdir, readFile as readFile2, writeFile } from "fs/promises";
|
|
245
215
|
import { dirname, resolve } from "path";
|
|
246
216
|
import { promisify } from "util";
|
|
217
|
+
var execAsync = promisify(execCb);
|
|
247
218
|
function createProcessContext(config) {
|
|
248
219
|
let counter = 0;
|
|
249
220
|
const handles = /* @__PURE__ */ new Map();
|
|
@@ -299,13 +270,6 @@ function createProcessContext(config) {
|
|
|
299
270
|
}
|
|
300
271
|
};
|
|
301
272
|
}
|
|
302
|
-
var execAsync;
|
|
303
|
-
var init_process = __esm({
|
|
304
|
-
"src/contexts/process.ts"() {
|
|
305
|
-
"use strict";
|
|
306
|
-
execAsync = promisify(execCb);
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
273
|
|
|
310
274
|
// src/contexts/sandbox.ts
|
|
311
275
|
function createSandboxContext(provider) {
|
|
@@ -351,67 +315,6 @@ function createSandboxContext(provider) {
|
|
|
351
315
|
}
|
|
352
316
|
};
|
|
353
317
|
}
|
|
354
|
-
var init_sandbox = __esm({
|
|
355
|
-
"src/contexts/sandbox.ts"() {
|
|
356
|
-
"use strict";
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
// src/contexts/index.ts
|
|
361
|
-
var init_contexts = __esm({
|
|
362
|
-
"src/contexts/index.ts"() {
|
|
363
|
-
"use strict";
|
|
364
|
-
init_docker();
|
|
365
|
-
init_process();
|
|
366
|
-
init_sandbox();
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
// src/harnesses/basic.ts
|
|
371
|
-
function getSpawn() {
|
|
372
|
-
if (!_spawn) {
|
|
373
|
-
_spawn = (init_spawn(), __toCommonJS(spawn_exports)).spawn;
|
|
374
|
-
}
|
|
375
|
-
return _spawn;
|
|
376
|
-
}
|
|
377
|
-
var basicTools, _spawn, spawnProxy, basic_default;
|
|
378
|
-
var init_basic = __esm({
|
|
379
|
-
"src/harnesses/basic.ts"() {
|
|
380
|
-
"use strict";
|
|
381
|
-
init_harnesses();
|
|
382
|
-
init_tools();
|
|
383
|
-
basicTools = { shell, readFile, writeFile: writeFile2, listFiles };
|
|
384
|
-
spawnProxy = {
|
|
385
|
-
get spec() {
|
|
386
|
-
return getSpawn().spec;
|
|
387
|
-
},
|
|
388
|
-
execute(input, ctx) {
|
|
389
|
-
return getSpawn().execute(input, ctx);
|
|
390
|
-
}
|
|
391
|
-
};
|
|
392
|
-
basic_default = defineHarness({
|
|
393
|
-
name: "basic",
|
|
394
|
-
system: "You are a helpful assistant with access to shell, file reading, file writing, directory listing, and sub-agent spawning tools. Use them to accomplish tasks in the project directory.",
|
|
395
|
-
tools: { ...basicTools, spawn: spawnProxy }
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
// src/harnesses/index.ts
|
|
401
|
-
function defineHarness(config) {
|
|
402
|
-
return config;
|
|
403
|
-
}
|
|
404
|
-
var noTools;
|
|
405
|
-
var init_harnesses = __esm({
|
|
406
|
-
"src/harnesses/index.ts"() {
|
|
407
|
-
init_basic();
|
|
408
|
-
noTools = defineHarness({
|
|
409
|
-
name: "none",
|
|
410
|
-
system: "You are a helpful assistant.",
|
|
411
|
-
tools: {}
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
});
|
|
415
318
|
|
|
416
319
|
// src/tools/validation.ts
|
|
417
320
|
function validateToolArgs(input, schema) {
|
|
@@ -423,11 +326,6 @@ function validateToolArgs(input, schema) {
|
|
|
423
326
|
}
|
|
424
327
|
return { valid: true };
|
|
425
328
|
}
|
|
426
|
-
var init_validation = __esm({
|
|
427
|
-
"src/tools/validation.ts"() {
|
|
428
|
-
"use strict";
|
|
429
|
-
}
|
|
430
|
-
});
|
|
431
329
|
|
|
432
330
|
// src/loop.ts
|
|
433
331
|
function turnsToMessages(turns) {
|
|
@@ -448,6 +346,7 @@ async function runLoop(ctx) {
|
|
|
448
346
|
totalIn += result.usage.input;
|
|
449
347
|
totalOut += result.usage.output;
|
|
450
348
|
turnUsages.push(result.usage);
|
|
349
|
+
await ctx.hooks.callHook("usage", { turn, turnId: result.turnId, usage: result.usage, totalIn, totalOut });
|
|
451
350
|
if (ctx.signal.aborted) {
|
|
452
351
|
await ctx.hooks.callHook("agent:abort", {});
|
|
453
352
|
break;
|
|
@@ -458,6 +357,7 @@ async function runLoop(ctx) {
|
|
|
458
357
|
const steerUserMsg = ctx.provider.userMessage(steerMsg);
|
|
459
358
|
ctx.turns.push({
|
|
460
359
|
id: await ctx.generateTurnId(),
|
|
360
|
+
runId: ctx.runId,
|
|
461
361
|
role: steerUserMsg.role,
|
|
462
362
|
content: steerUserMsg.content,
|
|
463
363
|
createdAt: Date.now()
|
|
@@ -471,13 +371,14 @@ async function runLoop(ctx) {
|
|
|
471
371
|
const followUpMsg = ctx.provider.userMessage(followUp);
|
|
472
372
|
ctx.turns.push({
|
|
473
373
|
id: await ctx.generateTurnId(),
|
|
374
|
+
runId: ctx.runId,
|
|
474
375
|
role: followUpMsg.role,
|
|
475
376
|
content: followUpMsg.content,
|
|
476
377
|
createdAt: Date.now()
|
|
477
378
|
});
|
|
478
379
|
continue;
|
|
479
380
|
}
|
|
480
|
-
const stats2 = { totalIn, totalOut, turns: turn + 1, elapsed: Date.now() - startTime, turnUsage: turnUsages };
|
|
381
|
+
const stats2 = { totalIn, totalOut, turns: turn + 1, elapsed: Date.now() - startTime, turnUsage: turnUsages, output: result.output };
|
|
481
382
|
await ctx.hooks.callHook("agent:done", stats2);
|
|
482
383
|
return stats2;
|
|
483
384
|
}
|
|
@@ -515,40 +416,87 @@ async function executeTurn(ctx, turn) {
|
|
|
515
416
|
}
|
|
516
417
|
);
|
|
517
418
|
} catch (err) {
|
|
518
|
-
|
|
419
|
+
const errorTurn = {
|
|
420
|
+
id: turnId,
|
|
421
|
+
runId: ctx.runId,
|
|
422
|
+
role: "assistant",
|
|
423
|
+
content: currentText ? [{ type: "text", text: currentText }] : [],
|
|
424
|
+
usage: { input: 0, output: 0 },
|
|
425
|
+
createdAt: Date.now()
|
|
426
|
+
};
|
|
427
|
+
ctx.turns.push(errorTurn);
|
|
428
|
+
await ctx.hooks.callHook("turn:after", { turn, turnId, usage: errorTurn.usage, message: errorTurn });
|
|
519
429
|
throw err;
|
|
520
430
|
}
|
|
521
431
|
if (currentText) {
|
|
522
432
|
await ctx.hooks.callHook("stream:end", { text: currentText, turnId, blockIndex });
|
|
523
433
|
blockIndex++;
|
|
524
434
|
}
|
|
525
|
-
|
|
526
|
-
if (result.done) {
|
|
527
|
-
ctx.turns.push({
|
|
528
|
-
id: turnId,
|
|
529
|
-
role: "assistant",
|
|
530
|
-
content: result.assistantMessage?.content ?? [{ type: "text", text: currentText }],
|
|
531
|
-
usage: result.usage,
|
|
532
|
-
createdAt: Date.now()
|
|
533
|
-
});
|
|
534
|
-
return { ended: true, usage: result.usage };
|
|
535
|
-
}
|
|
536
|
-
ctx.turns.push({
|
|
435
|
+
const assistantTurn = {
|
|
537
436
|
id: turnId,
|
|
437
|
+
runId: ctx.runId,
|
|
538
438
|
role: "assistant",
|
|
539
|
-
content: result.assistantMessage.content,
|
|
439
|
+
content: result.done ? result.assistantMessage?.content ?? [{ type: "text", text: currentText }] : result.assistantMessage.content,
|
|
540
440
|
usage: result.usage,
|
|
541
441
|
createdAt: Date.now()
|
|
542
|
-
}
|
|
442
|
+
};
|
|
443
|
+
ctx.turns.push(assistantTurn);
|
|
444
|
+
await ctx.hooks.callHook("turn:after", { turn, turnId, usage: result.usage, message: assistantTurn });
|
|
445
|
+
if (result.done) {
|
|
446
|
+
if (ctx.schema && !ctx.signal.aborted) {
|
|
447
|
+
const outputSpec = {
|
|
448
|
+
name: "__output__",
|
|
449
|
+
description: "Return the final structured output matching the required schema.",
|
|
450
|
+
input_schema: ctx.schema
|
|
451
|
+
};
|
|
452
|
+
const schemaResult = await ctx.provider.stream(
|
|
453
|
+
{
|
|
454
|
+
model: ctx.model,
|
|
455
|
+
system: ctx.system,
|
|
456
|
+
tools: ctx.provider.formatTools([outputSpec]),
|
|
457
|
+
messages: turnsToMessages(ctx.turns),
|
|
458
|
+
maxTokens: ctx.maxTokens ?? 16384,
|
|
459
|
+
signal: ctx.signal,
|
|
460
|
+
toolChoice: { type: "tool", name: "__output__" }
|
|
461
|
+
},
|
|
462
|
+
{ onText: () => {
|
|
463
|
+
} }
|
|
464
|
+
);
|
|
465
|
+
const output = schemaResult.toolCalls.find((tc) => tc.name === "__output__")?.input;
|
|
466
|
+
if (output) {
|
|
467
|
+
await ctx.hooks.callHook("output", { output, schema: ctx.schema });
|
|
468
|
+
}
|
|
469
|
+
const schemaTurn = {
|
|
470
|
+
id: await ctx.generateTurnId(),
|
|
471
|
+
runId: ctx.runId,
|
|
472
|
+
role: "assistant",
|
|
473
|
+
content: schemaResult.assistantMessage.content,
|
|
474
|
+
usage: schemaResult.usage,
|
|
475
|
+
createdAt: Date.now()
|
|
476
|
+
};
|
|
477
|
+
ctx.turns.push(schemaTurn);
|
|
478
|
+
return {
|
|
479
|
+
ended: true,
|
|
480
|
+
turnId,
|
|
481
|
+
usage: {
|
|
482
|
+
input: result.usage.input + schemaResult.usage.input,
|
|
483
|
+
output: result.usage.output + schemaResult.usage.output
|
|
484
|
+
},
|
|
485
|
+
output
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
return { ended: true, turnId, usage: result.usage };
|
|
489
|
+
}
|
|
543
490
|
const toolResults = ctx.toolExecution === "parallel" ? await executeToolsParallel(ctx, result.toolCalls) : await executeToolsSequential(ctx, result.toolCalls);
|
|
544
491
|
const toolResultMsg = ctx.provider.toolResultsMessage(toolResults);
|
|
545
492
|
ctx.turns.push({
|
|
546
493
|
id: await ctx.generateTurnId(),
|
|
494
|
+
runId: ctx.runId,
|
|
547
495
|
role: toolResultMsg.role,
|
|
548
496
|
content: toolResultMsg.content,
|
|
549
497
|
createdAt: Date.now()
|
|
550
498
|
});
|
|
551
|
-
return { ended: false, usage: result.usage };
|
|
499
|
+
return { ended: false, turnId, usage: result.usage };
|
|
552
500
|
}
|
|
553
501
|
async function executeSingleTool(ctx, call) {
|
|
554
502
|
const toolDef = ctx.tools[call.name];
|
|
@@ -605,6 +553,7 @@ async function executeToolsSequential(ctx, toolCalls) {
|
|
|
605
553
|
const toolResultMsg = ctx.provider.toolResultsMessage(results);
|
|
606
554
|
ctx.turns.push({
|
|
607
555
|
id: await ctx.generateTurnId(),
|
|
556
|
+
runId: ctx.runId,
|
|
608
557
|
role: toolResultMsg.role,
|
|
609
558
|
content: toolResultMsg.content,
|
|
610
559
|
createdAt: Date.now()
|
|
@@ -612,6 +561,7 @@ async function executeToolsSequential(ctx, toolCalls) {
|
|
|
612
561
|
const steerUserMsg = ctx.provider.userMessage(steerMsg);
|
|
613
562
|
ctx.turns.push({
|
|
614
563
|
id: await ctx.generateTurnId(),
|
|
564
|
+
runId: ctx.runId,
|
|
615
565
|
role: steerUserMsg.role,
|
|
616
566
|
content: steerUserMsg.content,
|
|
617
567
|
createdAt: Date.now()
|
|
@@ -628,16 +578,19 @@ async function executeToolsParallel(ctx, toolCalls) {
|
|
|
628
578
|
const settled = await Promise.all(executions);
|
|
629
579
|
return settled.map((s) => s.result);
|
|
630
580
|
}
|
|
631
|
-
var init_loop = __esm({
|
|
632
|
-
"src/loop.ts"() {
|
|
633
|
-
"use strict";
|
|
634
|
-
init_validation();
|
|
635
|
-
}
|
|
636
|
-
});
|
|
637
581
|
|
|
638
582
|
// src/agent.ts
|
|
639
|
-
|
|
640
|
-
function
|
|
583
|
+
var noTools = { name: "none", system: "You are a helpful assistant.", tools: {} };
|
|
584
|
+
function resolveBehavior(harnessBehavior, agentBehavior, runBehavior) {
|
|
585
|
+
return {
|
|
586
|
+
toolExecution: runBehavior?.toolExecution ?? agentBehavior?.toolExecution ?? harnessBehavior?.toolExecution ?? "sequential",
|
|
587
|
+
maxTurns: runBehavior?.maxTurns ?? agentBehavior?.maxTurns ?? harnessBehavior?.maxTurns,
|
|
588
|
+
maxTokens: runBehavior?.maxTokens ?? agentBehavior?.maxTokens ?? harnessBehavior?.maxTokens,
|
|
589
|
+
thinkingBudget: runBehavior?.thinkingBudget ?? agentBehavior?.thinkingBudget ?? harnessBehavior?.thinkingBudget,
|
|
590
|
+
schema: runBehavior?.schema ?? agentBehavior?.schema ?? harnessBehavior?.schema
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
function createAgent({ harness: harnessOption, provider, behavior: agentBehavior, execution, mcpServers, session, skills: agentSkills, _mcpConnector }) {
|
|
641
594
|
const hooks = createHooks();
|
|
642
595
|
const harness = harnessOption ?? noTools;
|
|
643
596
|
const executionContext = execution ?? createProcessContext();
|
|
@@ -729,18 +682,16 @@ function createAgent({ harness: harnessOption, provider, toolExecution = "sequen
|
|
|
729
682
|
}
|
|
730
683
|
const thinking = options.thinking ?? "off";
|
|
731
684
|
const model = options.model ?? provider.meta.defaultModel;
|
|
732
|
-
const maxTurns =
|
|
733
|
-
const maxTokens = options.maxTokens ?? agentMaxTokens;
|
|
734
|
-
const thinkingBudget = options.thinkingBudget ?? agentThinkingBudget;
|
|
685
|
+
const { toolExecution, maxTurns, maxTokens, thinkingBudget, schema } = resolveBehavior(harness.behavior, agentBehavior, options.behavior);
|
|
735
686
|
let system = options.system || harness.system || "You are a helpful assistant.";
|
|
736
687
|
if (skillsCatalog) {
|
|
737
688
|
system = `${system}
|
|
738
689
|
|
|
739
690
|
${skillsCatalog}`;
|
|
740
691
|
}
|
|
741
|
-
const
|
|
692
|
+
const baseTools = options.tools !== void 0 ? options.tools : mcpConnection ? { ...harness.tools, ...mcpConnection.tools } : harness.tools;
|
|
742
693
|
const tools = {};
|
|
743
|
-
for (const tool of Object.values(
|
|
694
|
+
for (const tool of Object.values(baseTools)) {
|
|
744
695
|
tools[tool.spec.name] = tool;
|
|
745
696
|
}
|
|
746
697
|
const toolSpecs = Object.values(tools).map(
|
|
@@ -750,17 +701,19 @@ ${skillsCatalog}`;
|
|
|
750
701
|
input_schema: t.spec.input_schema
|
|
751
702
|
})
|
|
752
703
|
);
|
|
753
|
-
const formattedTools =
|
|
704
|
+
const formattedTools = toolSpecs.length > 0 ? provider.formatTools(toolSpecs) : [];
|
|
754
705
|
const turns = [];
|
|
755
706
|
const isResume = session && session.turns.length > 0 && session.runs.length > 0;
|
|
756
707
|
if (isResume) {
|
|
757
708
|
turns.push(...session.turns);
|
|
758
709
|
}
|
|
710
|
+
const runTurnStart = turns.length;
|
|
759
711
|
if (options.system) {
|
|
760
712
|
await hooks.callHook("system:before", { system: options.system });
|
|
761
713
|
const systemUserMsg = provider.userMessage(options.system);
|
|
762
714
|
turns.push({
|
|
763
715
|
id: crypto.randomUUID(),
|
|
716
|
+
runId,
|
|
764
717
|
role: systemUserMsg.role,
|
|
765
718
|
content: systemUserMsg.content,
|
|
766
719
|
createdAt: Date.now()
|
|
@@ -768,6 +721,7 @@ ${skillsCatalog}`;
|
|
|
768
721
|
const systemAckMsg = provider.assistantMessage("Understood. I will proceed with these instructions above the rest of my system prompt.");
|
|
769
722
|
turns.push({
|
|
770
723
|
id: crypto.randomUUID(),
|
|
724
|
+
runId,
|
|
771
725
|
role: systemAckMsg.role,
|
|
772
726
|
content: systemAckMsg.content,
|
|
773
727
|
createdAt: Date.now()
|
|
@@ -776,6 +730,7 @@ ${skillsCatalog}`;
|
|
|
776
730
|
const promptMsg = provider.userMessage(options.prompt, options.images);
|
|
777
731
|
turns.push({
|
|
778
732
|
id: crypto.randomUUID(),
|
|
733
|
+
runId,
|
|
779
734
|
role: promptMsg.role,
|
|
780
735
|
content: promptMsg.content,
|
|
781
736
|
createdAt: Date.now()
|
|
@@ -808,10 +763,12 @@ ${skillsCatalog}`;
|
|
|
808
763
|
steeringQueue,
|
|
809
764
|
followUpQueue,
|
|
810
765
|
turns,
|
|
766
|
+
runId,
|
|
811
767
|
generateTurnId: () => session?.generateTurnId() ?? crypto.randomUUID(),
|
|
812
768
|
maxTurns,
|
|
813
769
|
maxTokens,
|
|
814
|
-
thinkingBudget
|
|
770
|
+
thinkingBudget,
|
|
771
|
+
schema
|
|
815
772
|
});
|
|
816
773
|
const finalStats = {
|
|
817
774
|
...stats,
|
|
@@ -824,7 +781,7 @@ ${skillsCatalog}`;
|
|
|
824
781
|
if (run2)
|
|
825
782
|
await session.updateRun(run2);
|
|
826
783
|
await session.updateStatus("idle");
|
|
827
|
-
await hooks.callHook("session:end", { sessionId: session.id, runId, status: "aborted" });
|
|
784
|
+
await hooks.callHook("session:end", { sessionId: session.id, runId, status: "aborted", turnRange: [runTurnStart, turns.length - 1] });
|
|
828
785
|
}
|
|
829
786
|
await hooks.callHook("agent:done", finalStats);
|
|
830
787
|
return finalStats;
|
|
@@ -849,7 +806,7 @@ ${skillsCatalog}`;
|
|
|
849
806
|
if (run2)
|
|
850
807
|
await session.updateRun(run2);
|
|
851
808
|
await session.updateStatus("completed");
|
|
852
|
-
await hooks.callHook("session:end", { sessionId: session.id, runId, status: "completed" });
|
|
809
|
+
await hooks.callHook("session:end", { sessionId: session.id, runId, status: "completed", turnRange: [runTurnStart, turns.length - 1] });
|
|
853
810
|
}
|
|
854
811
|
await hooks.callHook("agent:done", finalStats);
|
|
855
812
|
return finalStats;
|
|
@@ -861,7 +818,7 @@ ${skillsCatalog}`;
|
|
|
861
818
|
if (run2)
|
|
862
819
|
await session.updateRun(run2);
|
|
863
820
|
await session.updateStatus("idle");
|
|
864
|
-
await hooks.callHook("session:end", { sessionId: session.id, runId, status: "aborted" });
|
|
821
|
+
await hooks.callHook("session:end", { sessionId: session.id, runId, status: "aborted", turnRange: [runTurnStart, turns.length - 1] });
|
|
865
822
|
}
|
|
866
823
|
const stats = { totalIn: 0, totalOut: 0, turns: 0, elapsed: 0 };
|
|
867
824
|
await hooks.callHook("agent:done", stats);
|
|
@@ -873,7 +830,7 @@ ${skillsCatalog}`;
|
|
|
873
830
|
if (run2)
|
|
874
831
|
await session.updateRun(run2);
|
|
875
832
|
await session.updateStatus("error");
|
|
876
|
-
await hooks.callHook("session:end", { sessionId: session.id, runId, status: "error" });
|
|
833
|
+
await hooks.callHook("session:end", { sessionId: session.id, runId, status: "error", turnRange: [runTurnStart, turns.length - 1] });
|
|
877
834
|
}
|
|
878
835
|
throw err;
|
|
879
836
|
} finally {
|
|
@@ -954,25 +911,8 @@ ${skillsCatalog}`;
|
|
|
954
911
|
meta: provider.meta
|
|
955
912
|
};
|
|
956
913
|
}
|
|
957
|
-
var init_agent = __esm({
|
|
958
|
-
"src/agent.ts"() {
|
|
959
|
-
"use strict";
|
|
960
|
-
init_contexts();
|
|
961
|
-
init_harnesses();
|
|
962
|
-
init_loop();
|
|
963
|
-
init_mcp();
|
|
964
|
-
init_catalog();
|
|
965
|
-
init_interpolate();
|
|
966
|
-
init_resolve();
|
|
967
|
-
}
|
|
968
|
-
});
|
|
969
914
|
|
|
970
915
|
// src/tools/spawn.ts
|
|
971
|
-
var spawn_exports = {};
|
|
972
|
-
__export(spawn_exports, {
|
|
973
|
-
createSpawnTool: () => createSpawnTool,
|
|
974
|
-
spawn: () => spawn
|
|
975
|
-
});
|
|
976
916
|
function extractText(message) {
|
|
977
917
|
if (!message || typeof message !== "object")
|
|
978
918
|
return "";
|
|
@@ -1073,71 +1013,38 @@ function createSpawnTool(options = {}) {
|
|
|
1073
1013
|
}
|
|
1074
1014
|
};
|
|
1075
1015
|
}
|
|
1076
|
-
var spawn;
|
|
1077
|
-
var init_spawn = __esm({
|
|
1078
|
-
"src/tools/spawn.ts"() {
|
|
1079
|
-
"use strict";
|
|
1080
|
-
init_agent();
|
|
1081
|
-
spawn = createSpawnTool();
|
|
1082
|
-
}
|
|
1083
|
-
});
|
|
1016
|
+
var spawn = createSpawnTool();
|
|
1084
1017
|
|
|
1085
1018
|
// src/tools/write-file.ts
|
|
1086
|
-
var writeFile2
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
"
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
type: "object",
|
|
1096
|
-
properties: {
|
|
1097
|
-
path: { type: "string", description: "Relative file path" },
|
|
1098
|
-
content: { type: "string", description: "File content to write" }
|
|
1099
|
-
},
|
|
1100
|
-
required: ["path", "content"]
|
|
1101
|
-
}
|
|
1019
|
+
var writeFile2 = {
|
|
1020
|
+
spec: {
|
|
1021
|
+
name: "write_file",
|
|
1022
|
+
description: "Write content to a file. Creates parent directories if needed.",
|
|
1023
|
+
input_schema: {
|
|
1024
|
+
type: "object",
|
|
1025
|
+
properties: {
|
|
1026
|
+
path: { type: "string", description: "Relative file path" },
|
|
1027
|
+
content: { type: "string", description: "File content to write" }
|
|
1102
1028
|
},
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
});
|
|
1110
|
-
|
|
1111
|
-
// src/tools/index.ts
|
|
1112
|
-
var init_tools = __esm({
|
|
1113
|
-
"src/tools/index.ts"() {
|
|
1114
|
-
init_list_files();
|
|
1115
|
-
init_read_file();
|
|
1116
|
-
init_shell();
|
|
1117
|
-
init_spawn();
|
|
1118
|
-
init_validation();
|
|
1119
|
-
init_write_file();
|
|
1029
|
+
required: ["path", "content"]
|
|
1030
|
+
}
|
|
1031
|
+
},
|
|
1032
|
+
async execute({ path, content }, ctx) {
|
|
1033
|
+
await ctx.execution.writeFile(ctx.handle, path, content);
|
|
1034
|
+
return `Wrote ${content.length} bytes to ${path}`;
|
|
1120
1035
|
}
|
|
1121
|
-
}
|
|
1036
|
+
};
|
|
1122
1037
|
|
|
1123
1038
|
export {
|
|
1124
1039
|
createDockerContext,
|
|
1125
1040
|
createProcessContext,
|
|
1126
1041
|
createSandboxContext,
|
|
1127
|
-
|
|
1042
|
+
validateToolArgs,
|
|
1043
|
+
createAgent,
|
|
1128
1044
|
listFiles,
|
|
1129
1045
|
readFile,
|
|
1130
1046
|
shell,
|
|
1131
1047
|
createSpawnTool,
|
|
1132
1048
|
spawn,
|
|
1133
|
-
|
|
1134
|
-
writeFile2 as writeFile,
|
|
1135
|
-
init_tools,
|
|
1136
|
-
basicTools,
|
|
1137
|
-
basic_default,
|
|
1138
|
-
defineHarness,
|
|
1139
|
-
noTools,
|
|
1140
|
-
init_harnesses,
|
|
1141
|
-
createAgent,
|
|
1142
|
-
init_agent
|
|
1049
|
+
writeFile2 as writeFile
|
|
1143
1050
|
};
|