@polka-codes/core 0.9.2 → 0.9.4
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/_tsup-dts-rollup.d.ts +179 -689
- package/dist/index.d.ts +3 -0
- package/dist/index.js +630 -410
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -55,35 +55,27 @@ var toolInfo = {
|
|
|
55
55
|
description: "Call this when vital details are missing. Pose each follow-up as one direct, unambiguous question. If it speeds the reply, add up to five short, mutually-exclusive answer options. Group any related questions in the same call to avoid a back-and-forth chain.",
|
|
56
56
|
parameters: z.object({
|
|
57
57
|
questions: z.array(questionObject).describe("One or more follow-up questions you need answered before you can continue.").meta({ usageValue: "questions here" })
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
name: "questions",
|
|
65
|
-
value: { prompt: "What is the target deployment environment?" }
|
|
58
|
+
}).meta({
|
|
59
|
+
examples: [
|
|
60
|
+
{
|
|
61
|
+
description: "Single clarifying question (no options)",
|
|
62
|
+
input: {
|
|
63
|
+
questions: { prompt: "What is the target deployment environment?" }
|
|
66
64
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
{
|
|
73
|
-
name: "questions",
|
|
74
|
-
value: {
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
description: "Single question with multiple-choice options",
|
|
68
|
+
input: {
|
|
69
|
+
questions: {
|
|
75
70
|
prompt: "Which frontend framework are you using?",
|
|
76
71
|
options: ["React", "Angular", "Vue", "Svelte"]
|
|
77
72
|
}
|
|
78
73
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
{
|
|
85
|
-
name: "questions",
|
|
86
|
-
value: [
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
description: "Two related questions in one call",
|
|
77
|
+
input: {
|
|
78
|
+
questions: [
|
|
87
79
|
{ prompt: "What type of application are you building?" },
|
|
88
80
|
{
|
|
89
81
|
prompt: "Preferred programming language?",
|
|
@@ -91,21 +83,18 @@ var toolInfo = {
|
|
|
91
83
|
}
|
|
92
84
|
]
|
|
93
85
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
{
|
|
100
|
-
name: "questions",
|
|
101
|
-
value: {
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
description: "Binary (yes/no) confirmation",
|
|
89
|
+
input: {
|
|
90
|
+
questions: {
|
|
102
91
|
prompt: "Is it acceptable to refactor existing tests to improve performance?",
|
|
103
92
|
options: ["Yes", "No"]
|
|
104
93
|
}
|
|
105
94
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
}),
|
|
109
98
|
permissionLevel: 0 /* None */
|
|
110
99
|
};
|
|
111
100
|
var handler = async (provider, args) => {
|
|
@@ -124,9 +113,9 @@ var handler = async (provider, args) => {
|
|
|
124
113
|
}
|
|
125
114
|
const answers = [];
|
|
126
115
|
for (const question of questions) {
|
|
127
|
-
const { prompt:
|
|
128
|
-
const answer = await provider.askFollowupQuestion(
|
|
129
|
-
answers.push(`<ask_followup_question_answer question="${
|
|
116
|
+
const { prompt: prompt6, options } = question;
|
|
117
|
+
const answer = await provider.askFollowupQuestion(prompt6, options);
|
|
118
|
+
answers.push(`<ask_followup_question_answer question="${prompt6}">
|
|
130
119
|
${answer}
|
|
131
120
|
</ask_followup_question_answer>`);
|
|
132
121
|
}
|
|
@@ -153,18 +142,16 @@ var toolInfo2 = {
|
|
|
153
142
|
result: z2.string().describe(
|
|
154
143
|
"The result of the task. Formulate this result in a way that is final and does not require further input from the user. Don't end your result with questions or offers for further assistance."
|
|
155
144
|
).meta({ usageValue: "Your final result description here" })
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
name: "result",
|
|
163
|
-
value: "Your final result description here"
|
|
145
|
+
}).meta({
|
|
146
|
+
examples: [
|
|
147
|
+
{
|
|
148
|
+
description: "Request to present the result of the task",
|
|
149
|
+
input: {
|
|
150
|
+
result: "Your final result description here"
|
|
164
151
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
152
|
+
}
|
|
153
|
+
]
|
|
154
|
+
}),
|
|
168
155
|
permissionLevel: 0 /* None */
|
|
169
156
|
};
|
|
170
157
|
var handler2 = async (provider, args) => {
|
|
@@ -211,30 +198,19 @@ var toolInfo3 = {
|
|
|
211
198
|
const values = Array.isArray(val) ? val : [val];
|
|
212
199
|
return values.flatMap((i) => typeof i === "string" ? i.split(",") : []).filter((s) => s.length > 0);
|
|
213
200
|
}, z3.array(z3.string())).optional().describe("The files relevant to the task. Comma separated paths").meta({ usageValue: "Relevant files" })
|
|
214
|
-
})
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
{
|
|
224
|
-
name: "task",
|
|
225
|
-
value: "Analyze the authentication implementation"
|
|
226
|
-
},
|
|
227
|
-
{
|
|
228
|
-
name: "context",
|
|
229
|
-
value: "Need to understand the security implications of the current auth system"
|
|
230
|
-
},
|
|
231
|
-
{
|
|
232
|
-
name: "files",
|
|
233
|
-
value: "src/auth/login.ts,src/auth/types.ts"
|
|
201
|
+
}).meta({
|
|
202
|
+
examples: [
|
|
203
|
+
{
|
|
204
|
+
description: "Delegate a code analysis task to the analyzer agent",
|
|
205
|
+
input: {
|
|
206
|
+
agentName: "analyzer",
|
|
207
|
+
task: "Analyze the authentication implementation",
|
|
208
|
+
context: "Need to understand the security implications of the current auth system",
|
|
209
|
+
files: "src/auth/login.ts,src/auth/types.ts"
|
|
234
210
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
211
|
+
}
|
|
212
|
+
]
|
|
213
|
+
}),
|
|
238
214
|
permissionLevel: 0 /* None */
|
|
239
215
|
};
|
|
240
216
|
var handler3 = async (_provider, args) => {
|
|
@@ -280,16 +256,17 @@ var toolInfo4 = {
|
|
|
280
256
|
}, z4.boolean().optional().default(false)).describe(
|
|
281
257
|
"Set to `true` for commands that install/uninstall software, modify or delete files, change system settings, perform network operations, or have other side effects. Use `false` for safe, read-only, or purely local development actions (e.g., listing files, make a build, running tests)."
|
|
282
258
|
).meta({ usageValue: "true | false" })
|
|
259
|
+
}).meta({
|
|
260
|
+
examples: [
|
|
261
|
+
{
|
|
262
|
+
description: "Make a build",
|
|
263
|
+
input: {
|
|
264
|
+
command: "npm run build",
|
|
265
|
+
requiresApproval: "false"
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
]
|
|
283
269
|
}),
|
|
284
|
-
examples: [
|
|
285
|
-
{
|
|
286
|
-
description: "Make a build",
|
|
287
|
-
parameters: [
|
|
288
|
-
{ name: "command", value: "npm run build" },
|
|
289
|
-
{ name: "requiresApproval", value: "false" }
|
|
290
|
-
]
|
|
291
|
-
}
|
|
292
|
-
],
|
|
293
270
|
permissionLevel: 3 /* Arbitrary */
|
|
294
271
|
};
|
|
295
272
|
var handler4 = async (provider, args) => {
|
|
@@ -348,36 +325,28 @@ var toolInfo5 = {
|
|
|
348
325
|
const values = Array.isArray(val) ? val : [val];
|
|
349
326
|
return values.flatMap((i) => typeof i === "string" ? i.split(",") : []).filter((s) => s.length > 0);
|
|
350
327
|
}, z5.array(z5.string())).describe("One or more URLs to fetch, separated by commas if multiple.").meta({ usageValue: "url" })
|
|
351
|
-
})
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
name: "url",
|
|
358
|
-
value: "https://example.com"
|
|
328
|
+
}).meta({
|
|
329
|
+
examples: [
|
|
330
|
+
{
|
|
331
|
+
description: "Fetch a single webpage",
|
|
332
|
+
input: {
|
|
333
|
+
url: "https://example.com"
|
|
359
334
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
{
|
|
366
|
-
name: "url",
|
|
367
|
-
value: "https://example.com,https://developer.mozilla.org/en-US/docs/Web/HTTP"
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
description: "Fetch multiple webpages",
|
|
338
|
+
input: {
|
|
339
|
+
url: "https://example.com,https://developer.mozilla.org/en-US/docs/Web/HTTP"
|
|
368
340
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
{
|
|
375
|
-
name: "url",
|
|
376
|
-
value: "https://raw.githubusercontent.com/user/repo/main/README.md"
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
description: "Fetch a raw file from GitHub",
|
|
344
|
+
input: {
|
|
345
|
+
url: "https://raw.githubusercontent.com/user/repo/main/README.md"
|
|
377
346
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
347
|
+
}
|
|
348
|
+
]
|
|
349
|
+
}),
|
|
381
350
|
permissionLevel: 1 /* Read */
|
|
382
351
|
};
|
|
383
352
|
var handler5 = async (provider, args) => {
|
|
@@ -433,30 +402,19 @@ var toolInfo6 = {
|
|
|
433
402
|
const values = Array.isArray(val) ? val : [val];
|
|
434
403
|
return values.flatMap((i) => typeof i === "string" ? i.split(",") : []).filter((s) => s.length > 0);
|
|
435
404
|
}, z6.array(z6.string())).optional().describe("The files relevant to the task. Comma separated paths").meta({ usageValue: "Relevant files" })
|
|
436
|
-
})
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
{
|
|
446
|
-
name: "task",
|
|
447
|
-
value: "Implement the login feature"
|
|
448
|
-
},
|
|
449
|
-
{
|
|
450
|
-
name: "context",
|
|
451
|
-
value: "We need a secure login system with email and password"
|
|
452
|
-
},
|
|
453
|
-
{
|
|
454
|
-
name: "files",
|
|
455
|
-
value: "src/auth/login.ts,src/auth/types.ts"
|
|
405
|
+
}).meta({
|
|
406
|
+
examples: [
|
|
407
|
+
{
|
|
408
|
+
description: "Hand over a coding task to the coder agent",
|
|
409
|
+
input: {
|
|
410
|
+
agentName: "coder",
|
|
411
|
+
task: "Implement the login feature",
|
|
412
|
+
context: "We need a secure login system with email and password",
|
|
413
|
+
files: "src/auth/login.ts,src/auth/types.ts"
|
|
456
414
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
415
|
+
}
|
|
416
|
+
]
|
|
417
|
+
}),
|
|
460
418
|
permissionLevel: 0 /* None */
|
|
461
419
|
};
|
|
462
420
|
var handler6 = async (_provider, args) => {
|
|
@@ -501,22 +459,17 @@ var toolInfo7 = {
|
|
|
501
459
|
}
|
|
502
460
|
return val;
|
|
503
461
|
}, z7.boolean().optional().default(true)).describe("Whether to list files recursively. Use true for recursive listing, false or omit for top-level only.").meta({ usageValue: "true or false (optional)" })
|
|
504
|
-
})
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
value: "src"
|
|
512
|
-
},
|
|
513
|
-
{
|
|
514
|
-
name: "maxCount",
|
|
515
|
-
value: "100"
|
|
462
|
+
}).meta({
|
|
463
|
+
examples: [
|
|
464
|
+
{
|
|
465
|
+
description: "Request to list files",
|
|
466
|
+
input: {
|
|
467
|
+
path: "src",
|
|
468
|
+
maxCount: "100"
|
|
516
469
|
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
470
|
+
}
|
|
471
|
+
]
|
|
472
|
+
}),
|
|
520
473
|
permissionLevel: 1 /* Read */
|
|
521
474
|
};
|
|
522
475
|
var handler7 = async (provider, args) => {
|
|
@@ -557,27 +510,22 @@ var toolInfo8 = {
|
|
|
557
510
|
const values = Array.isArray(val) ? val : [val];
|
|
558
511
|
return values.flatMap((i) => typeof i === "string" ? i.split(",") : []).filter((s) => s.length > 0);
|
|
559
512
|
}, z8.array(z8.string())).describe("The path of the file to read").meta({ usageValue: "Comma separated paths here" })
|
|
560
|
-
})
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
name: "path",
|
|
567
|
-
value: "src/main.js"
|
|
513
|
+
}).meta({
|
|
514
|
+
examples: [
|
|
515
|
+
{
|
|
516
|
+
description: "Request to read the contents of a file",
|
|
517
|
+
input: {
|
|
518
|
+
path: "src/main.js"
|
|
568
519
|
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
{
|
|
575
|
-
name: "path",
|
|
576
|
-
value: "src/main.js,src/index.js"
|
|
520
|
+
},
|
|
521
|
+
{
|
|
522
|
+
description: "Request to read multiple files",
|
|
523
|
+
input: {
|
|
524
|
+
path: "src/main.js,src/index.js"
|
|
577
525
|
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
526
|
+
}
|
|
527
|
+
]
|
|
528
|
+
}),
|
|
581
529
|
permissionLevel: 1 /* Read */
|
|
582
530
|
};
|
|
583
531
|
var handler8 = async (provider, args) => {
|
|
@@ -623,18 +571,16 @@ var toolInfo9 = {
|
|
|
623
571
|
description: "Request to remove a file at the specified path.",
|
|
624
572
|
parameters: z9.object({
|
|
625
573
|
path: z9.string().describe("The path of the file to remove").meta({ usageValue: "File path here" })
|
|
626
|
-
})
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
name: "path",
|
|
633
|
-
value: "src/main.js"
|
|
574
|
+
}).meta({
|
|
575
|
+
examples: [
|
|
576
|
+
{
|
|
577
|
+
description: "Request to remove a file",
|
|
578
|
+
input: {
|
|
579
|
+
path: "src/main.js"
|
|
634
580
|
}
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
581
|
+
}
|
|
582
|
+
]
|
|
583
|
+
}),
|
|
638
584
|
permissionLevel: 2 /* Write */
|
|
639
585
|
};
|
|
640
586
|
var handler9 = async (provider, args) => {
|
|
@@ -675,22 +621,17 @@ var toolInfo10 = {
|
|
|
675
621
|
parameters: z10.object({
|
|
676
622
|
source_path: z10.string().describe("The current path of the file").meta({ usageValue: "Source file path here" }),
|
|
677
623
|
target_path: z10.string().describe("The new path for the file").meta({ usageValue: "Target file path here" })
|
|
678
|
-
})
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
value: "src/old-name.js"
|
|
686
|
-
},
|
|
687
|
-
{
|
|
688
|
-
name: "target_path",
|
|
689
|
-
value: "src/new-name.js"
|
|
624
|
+
}).meta({
|
|
625
|
+
examples: [
|
|
626
|
+
{
|
|
627
|
+
description: "Request to rename a file",
|
|
628
|
+
input: {
|
|
629
|
+
source_path: "src/old-name.js",
|
|
630
|
+
target_path: "src/new-name.js"
|
|
690
631
|
}
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
632
|
+
}
|
|
633
|
+
]
|
|
634
|
+
}),
|
|
694
635
|
permissionLevel: 2 /* Write */
|
|
695
636
|
};
|
|
696
637
|
var handler10 = async (provider, args) => {
|
|
@@ -825,18 +766,13 @@ Critical rules:
|
|
|
825
766
|
* To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
|
|
826
767
|
* To delete code: Use empty REPLACE section`
|
|
827
768
|
).meta({ usageValue: "Search and replace blocks here" })
|
|
828
|
-
})
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
value: "src/main.js"
|
|
836
|
-
},
|
|
837
|
-
{
|
|
838
|
-
name: "diff",
|
|
839
|
-
value: `<<<<<<< SEARCH
|
|
769
|
+
}).meta({
|
|
770
|
+
examples: [
|
|
771
|
+
{
|
|
772
|
+
description: "Request to replace sections of content in a file",
|
|
773
|
+
input: {
|
|
774
|
+
path: "src/main.js",
|
|
775
|
+
diff: `<<<<<<< SEARCH
|
|
840
776
|
import React from 'react';
|
|
841
777
|
=======
|
|
842
778
|
import React, { useState } from 'react';
|
|
@@ -864,35 +800,23 @@ return (
|
|
|
864
800
|
<div>
|
|
865
801
|
>>>>>>> REPLACE`
|
|
866
802
|
}
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
name: "path",
|
|
874
|
-
value: "src/config.js"
|
|
875
|
-
},
|
|
876
|
-
{
|
|
877
|
-
name: "diff",
|
|
878
|
-
value: `<<<<<<< SEARCH
|
|
803
|
+
},
|
|
804
|
+
{
|
|
805
|
+
description: "Request to perform a simple, single-line replacement",
|
|
806
|
+
input: {
|
|
807
|
+
path: "src/config.js",
|
|
808
|
+
diff: `<<<<<<< SEARCH
|
|
879
809
|
const API_URL = 'https://api.example.com';
|
|
880
810
|
=======
|
|
881
811
|
const API_URL = 'https://api.staging.example.com';
|
|
882
812
|
>>>>>>> REPLACE`
|
|
883
813
|
}
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
name: "path",
|
|
891
|
-
value: "src/utils.js"
|
|
892
|
-
},
|
|
893
|
-
{
|
|
894
|
-
name: "diff",
|
|
895
|
-
value: `<<<<<<< SEARCH
|
|
814
|
+
},
|
|
815
|
+
{
|
|
816
|
+
description: "Request to add a new function to a file",
|
|
817
|
+
input: {
|
|
818
|
+
path: "src/utils.js",
|
|
819
|
+
diff: `<<<<<<< SEARCH
|
|
896
820
|
function helperA() {
|
|
897
821
|
// ...
|
|
898
822
|
}
|
|
@@ -906,18 +830,12 @@ function newHelper() {
|
|
|
906
830
|
}
|
|
907
831
|
>>>>>>> REPLACE`
|
|
908
832
|
}
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
name: "path",
|
|
916
|
-
value: "src/app.js"
|
|
917
|
-
},
|
|
918
|
-
{
|
|
919
|
-
name: "diff",
|
|
920
|
-
value: `<<<<<<< SEARCH
|
|
833
|
+
},
|
|
834
|
+
{
|
|
835
|
+
description: "Request to delete a block of code from a file",
|
|
836
|
+
input: {
|
|
837
|
+
path: "src/app.js",
|
|
838
|
+
diff: `<<<<<<< SEARCH
|
|
921
839
|
function oldFeature() {
|
|
922
840
|
// This is no longer needed
|
|
923
841
|
}
|
|
@@ -925,9 +843,9 @@ function oldFeature() {
|
|
|
925
843
|
=======
|
|
926
844
|
>>>>>>> REPLACE`
|
|
927
845
|
}
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
846
|
+
}
|
|
847
|
+
]
|
|
848
|
+
}),
|
|
931
849
|
permissionLevel: 2 /* Write */
|
|
932
850
|
};
|
|
933
851
|
var handler11 = async (provider, args) => {
|
|
@@ -1001,26 +919,18 @@ var toolInfo12 = {
|
|
|
1001
919
|
).meta({
|
|
1002
920
|
usageValue: "file pattern here (optional)"
|
|
1003
921
|
})
|
|
1004
|
-
})
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
},
|
|
1013
|
-
{
|
|
1014
|
-
name: "regex",
|
|
1015
|
-
value: "^components/"
|
|
1016
|
-
},
|
|
1017
|
-
{
|
|
1018
|
-
name: "filePattern",
|
|
1019
|
-
value: "*.ts,*.tsx"
|
|
922
|
+
}).meta({
|
|
923
|
+
examples: [
|
|
924
|
+
{
|
|
925
|
+
description: "Request to perform a regex search across files",
|
|
926
|
+
input: {
|
|
927
|
+
path: "src",
|
|
928
|
+
regex: "^components/",
|
|
929
|
+
filePattern: "*.ts,*.tsx"
|
|
1020
930
|
}
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
931
|
+
}
|
|
932
|
+
]
|
|
933
|
+
}),
|
|
1024
934
|
permissionLevel: 1 /* Read */
|
|
1025
935
|
};
|
|
1026
936
|
var handler12 = async (provider, args) => {
|
|
@@ -1069,18 +979,13 @@ var toolInfo13 = {
|
|
|
1069
979
|
content: z13.string().describe(
|
|
1070
980
|
"The content to write to the file. ALWAYS provide the COMPLETE intended content of the file, without any truncation or omissions. You MUST include ALL parts of the file, even if they haven't been modified."
|
|
1071
981
|
).meta({ usageValue: "Your file content here" })
|
|
1072
|
-
})
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
value: "src/main.js"
|
|
1080
|
-
},
|
|
1081
|
-
{
|
|
1082
|
-
name: "content",
|
|
1083
|
-
value: `import React from 'react';
|
|
982
|
+
}).meta({
|
|
983
|
+
examples: [
|
|
984
|
+
{
|
|
985
|
+
description: "Request to write content to a file",
|
|
986
|
+
input: {
|
|
987
|
+
path: "src/main.js",
|
|
988
|
+
content: `import React from 'react';
|
|
1084
989
|
|
|
1085
990
|
function App() {
|
|
1086
991
|
return (
|
|
@@ -1093,9 +998,9 @@ function App() {
|
|
|
1093
998
|
export default App;
|
|
1094
999
|
`
|
|
1095
1000
|
}
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1001
|
+
}
|
|
1002
|
+
]
|
|
1003
|
+
}),
|
|
1099
1004
|
permissionLevel: 2 /* Write */
|
|
1100
1005
|
};
|
|
1101
1006
|
var handler13 = async (provider, args) => {
|
|
@@ -1186,46 +1091,6 @@ var getAvailableTools = ({
|
|
|
1186
1091
|
return tools;
|
|
1187
1092
|
};
|
|
1188
1093
|
|
|
1189
|
-
// src/tool-v1-compat.ts
|
|
1190
|
-
import { z as z14 } from "zod";
|
|
1191
|
-
function zodSchemaToParameters(schema) {
|
|
1192
|
-
const parameters = [];
|
|
1193
|
-
const { shape } = schema;
|
|
1194
|
-
for (const name in shape) {
|
|
1195
|
-
const def = shape[name];
|
|
1196
|
-
const isOptional = def.safeParse(void 0).success;
|
|
1197
|
-
const description = def.description || "";
|
|
1198
|
-
const param = {
|
|
1199
|
-
name,
|
|
1200
|
-
description,
|
|
1201
|
-
required: !isOptional
|
|
1202
|
-
};
|
|
1203
|
-
const usageValue = def.meta()?.usageValue;
|
|
1204
|
-
if (usageValue) {
|
|
1205
|
-
param.usageValue = usageValue;
|
|
1206
|
-
}
|
|
1207
|
-
if (def instanceof z14.ZodObject) {
|
|
1208
|
-
param.children = zodSchemaToParameters(def);
|
|
1209
|
-
} else if (def instanceof z14.ZodArray) {
|
|
1210
|
-
param.allowMultiple = true;
|
|
1211
|
-
const element = def.element;
|
|
1212
|
-
if (element instanceof z14.ZodObject) {
|
|
1213
|
-
param.children = zodSchemaToParameters(element);
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
parameters.push(param);
|
|
1217
|
-
}
|
|
1218
|
-
return parameters;
|
|
1219
|
-
}
|
|
1220
|
-
function toToolInfoV1(tool) {
|
|
1221
|
-
const { parameters: zodSchema, ...rest } = tool;
|
|
1222
|
-
const v1Parameters = zodSchemaToParameters(zodSchema);
|
|
1223
|
-
return {
|
|
1224
|
-
...rest,
|
|
1225
|
-
parameters: v1Parameters
|
|
1226
|
-
};
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
1094
|
// src/UsageMeter.ts
|
|
1230
1095
|
var UsageMeter = class {
|
|
1231
1096
|
#totals = { input: 0, output: 0, cachedRead: 0, cost: 0 };
|
|
@@ -1371,7 +1236,54 @@ var UsageMeter = class {
|
|
|
1371
1236
|
};
|
|
1372
1237
|
|
|
1373
1238
|
// src/Agent/AgentBase.ts
|
|
1374
|
-
import { streamText } from "ai";
|
|
1239
|
+
import { jsonSchema, streamText } from "ai";
|
|
1240
|
+
import { camelCase } from "lodash";
|
|
1241
|
+
import { toJSONSchema } from "zod";
|
|
1242
|
+
|
|
1243
|
+
// src/tool-v1-compat.ts
|
|
1244
|
+
import { z as z14 } from "zod";
|
|
1245
|
+
function zodSchemaToParameters(schema) {
|
|
1246
|
+
const parameters = [];
|
|
1247
|
+
const { shape } = schema;
|
|
1248
|
+
for (const name in shape) {
|
|
1249
|
+
const def = shape[name];
|
|
1250
|
+
const isOptional = def.safeParse(void 0).success;
|
|
1251
|
+
const description = def.description || "";
|
|
1252
|
+
const param = {
|
|
1253
|
+
name,
|
|
1254
|
+
description,
|
|
1255
|
+
required: !isOptional
|
|
1256
|
+
};
|
|
1257
|
+
const usageValue = def.meta()?.usageValue;
|
|
1258
|
+
if (usageValue) {
|
|
1259
|
+
param.usageValue = usageValue;
|
|
1260
|
+
}
|
|
1261
|
+
if (def instanceof z14.ZodObject) {
|
|
1262
|
+
param.children = zodSchemaToParameters(def);
|
|
1263
|
+
} else if (def instanceof z14.ZodArray) {
|
|
1264
|
+
param.allowMultiple = true;
|
|
1265
|
+
const element = def.element;
|
|
1266
|
+
if (element instanceof z14.ZodObject) {
|
|
1267
|
+
param.children = zodSchemaToParameters(element);
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
parameters.push(param);
|
|
1271
|
+
}
|
|
1272
|
+
return parameters;
|
|
1273
|
+
}
|
|
1274
|
+
function toToolInfoV1(tool) {
|
|
1275
|
+
const { parameters: zodSchema, ...rest } = tool;
|
|
1276
|
+
const v1Parameters = zodSchemaToParameters(zodSchema);
|
|
1277
|
+
const examples = zodSchema.meta()?.examples;
|
|
1278
|
+
const v1Tool = {
|
|
1279
|
+
...rest,
|
|
1280
|
+
parameters: v1Parameters
|
|
1281
|
+
};
|
|
1282
|
+
if (examples) {
|
|
1283
|
+
v1Tool.examples = examples;
|
|
1284
|
+
}
|
|
1285
|
+
return v1Tool;
|
|
1286
|
+
}
|
|
1375
1287
|
|
|
1376
1288
|
// src/Agent/parseAssistantMessage.ts
|
|
1377
1289
|
function parseNestedParameters(content, parameterPrefix, childrenParams) {
|
|
@@ -1543,7 +1455,7 @@ var toolInfoExamplesPrompt = (tool, example, toolNamePrefix, parameterPrefix) =>
|
|
|
1543
1455
|
## Example: ${example.description}
|
|
1544
1456
|
|
|
1545
1457
|
<${toolNamePrefix}${tool.name}>
|
|
1546
|
-
${example.
|
|
1458
|
+
${Object.entries(example.input).map(([name, value]) => renderParameterValue(name, value, parameterPrefix)).join("\n")}
|
|
1547
1459
|
</${toolNamePrefix}${tool.name}>
|
|
1548
1460
|
`;
|
|
1549
1461
|
var toolUsePrompt = (tools, toolNamePrefix) => {
|
|
@@ -1551,6 +1463,7 @@ var toolUsePrompt = (tools, toolNamePrefix) => {
|
|
|
1551
1463
|
return "";
|
|
1552
1464
|
}
|
|
1553
1465
|
const parameterPrefix = `${toolNamePrefix}parameter_`;
|
|
1466
|
+
const v1Tools = tools.map(toToolInfoV1);
|
|
1554
1467
|
return `
|
|
1555
1468
|
====
|
|
1556
1469
|
|
|
@@ -1609,10 +1522,10 @@ Always adhere to this format, ensuring every opening tag has a matching closing
|
|
|
1609
1522
|
NEVER surround tool use with triple backticks (\`\`\`).
|
|
1610
1523
|
|
|
1611
1524
|
# Tools
|
|
1612
|
-
${
|
|
1525
|
+
${v1Tools.map((tool) => toolInfoPrompt(tool, toolNamePrefix, parameterPrefix)).join("\n")}
|
|
1613
1526
|
|
|
1614
1527
|
# Tool Use Examples
|
|
1615
|
-
${
|
|
1528
|
+
${v1Tools.map((tool) => {
|
|
1616
1529
|
let promp = "";
|
|
1617
1530
|
for (const example of tool.examples ?? []) {
|
|
1618
1531
|
promp += toolInfoExamplesPrompt(tool, example, toolNamePrefix, parameterPrefix);
|
|
@@ -1703,6 +1616,8 @@ e.g. <tool_tool_name>tool_name</tool_tool_name>
|
|
|
1703
1616
|
Ensure the opening and closing tags are correctly nested and closed, and that you are using the correct tool name.
|
|
1704
1617
|
Avoid unnecessary text or symbols before or after the tool use.
|
|
1705
1618
|
Avoid unnecessary escape characters or special characters.
|
|
1619
|
+
`,
|
|
1620
|
+
requireUseToolNative: `Error: No tool use detected. You MUST use a tool before proceeding.
|
|
1706
1621
|
`,
|
|
1707
1622
|
toolResults: (tool, result) => {
|
|
1708
1623
|
if (typeof result === "string") {
|
|
@@ -1760,6 +1675,7 @@ var AgentBase = class {
|
|
|
1760
1675
|
config;
|
|
1761
1676
|
handlers;
|
|
1762
1677
|
#policies;
|
|
1678
|
+
#toolSet;
|
|
1763
1679
|
#messages = [];
|
|
1764
1680
|
#aborted = false;
|
|
1765
1681
|
#abortController;
|
|
@@ -1797,6 +1713,20 @@ ${instance.prompt}`;
|
|
|
1797
1713
|
role: "system",
|
|
1798
1714
|
content: this.config.systemPrompt
|
|
1799
1715
|
});
|
|
1716
|
+
if (this.config.toolFormat === "native") {
|
|
1717
|
+
const tools = {};
|
|
1718
|
+
for (const tool of Object.values(this.handlers)) {
|
|
1719
|
+
const toolName = camelCase(tool.name);
|
|
1720
|
+
tools[toolName] = {
|
|
1721
|
+
description: tool.description,
|
|
1722
|
+
inputSchema: jsonSchema(toJSONSchema(tool.parameters))
|
|
1723
|
+
};
|
|
1724
|
+
this.handlers[toolName] = tool;
|
|
1725
|
+
}
|
|
1726
|
+
this.#toolSet = tools;
|
|
1727
|
+
} else {
|
|
1728
|
+
this.#toolSet = {};
|
|
1729
|
+
}
|
|
1800
1730
|
}
|
|
1801
1731
|
abort() {
|
|
1802
1732
|
this.#aborted = true;
|
|
@@ -1816,21 +1746,27 @@ ${instance.prompt}`;
|
|
|
1816
1746
|
async #callback(event) {
|
|
1817
1747
|
await this.config.callback?.(event);
|
|
1818
1748
|
}
|
|
1819
|
-
async start(
|
|
1749
|
+
async start(prompt6) {
|
|
1820
1750
|
this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
|
|
1821
|
-
return await this.#processLoop(
|
|
1751
|
+
return await this.#processLoop(prompt6);
|
|
1822
1752
|
}
|
|
1823
|
-
async step(
|
|
1753
|
+
async step(prompt6) {
|
|
1824
1754
|
if (this.#messages.length === 0) {
|
|
1825
1755
|
this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
|
|
1826
1756
|
}
|
|
1827
|
-
return await this.#request(
|
|
1757
|
+
return await this.#request({
|
|
1758
|
+
role: "user",
|
|
1759
|
+
content: prompt6
|
|
1760
|
+
});
|
|
1828
1761
|
}
|
|
1829
1762
|
async handleStepResponse(response) {
|
|
1830
1763
|
return this.#handleResponse(response);
|
|
1831
1764
|
}
|
|
1832
1765
|
async #processLoop(userMessage) {
|
|
1833
|
-
let nextRequest =
|
|
1766
|
+
let nextRequest = {
|
|
1767
|
+
role: "user",
|
|
1768
|
+
content: userMessage
|
|
1769
|
+
};
|
|
1834
1770
|
while (true) {
|
|
1835
1771
|
if (this.#aborted) {
|
|
1836
1772
|
return { type: "Aborted" };
|
|
@@ -1859,10 +1795,7 @@ ${instance.prompt}`;
|
|
|
1859
1795
|
throw new Error("userMessage is missing");
|
|
1860
1796
|
}
|
|
1861
1797
|
await this.#callback({ kind: "StartRequest" /* StartRequest */, agent: this, userMessage });
|
|
1862
|
-
this.#messages.push(
|
|
1863
|
-
role: "user",
|
|
1864
|
-
content: userMessage
|
|
1865
|
-
});
|
|
1798
|
+
this.#messages.push(userMessage);
|
|
1866
1799
|
for (const instance of this.#policies) {
|
|
1867
1800
|
if (instance.onBeforeRequest) {
|
|
1868
1801
|
await instance.onBeforeRequest(this);
|
|
@@ -1874,96 +1807,133 @@ ${instance.prompt}`;
|
|
|
1874
1807
|
messages = await instance.prepareMessages(this, messages);
|
|
1875
1808
|
}
|
|
1876
1809
|
}
|
|
1877
|
-
let currentAssistantMessage = "";
|
|
1878
1810
|
const retryCount = this.config.retryCount ?? 5;
|
|
1879
|
-
const requestTimeoutSeconds = this.config.requestTimeoutSeconds ??
|
|
1811
|
+
const requestTimeoutSeconds = this.config.requestTimeoutSeconds ?? 90;
|
|
1812
|
+
let respMessages = [];
|
|
1880
1813
|
for (let i = 0; i < retryCount; i++) {
|
|
1881
|
-
|
|
1814
|
+
if (this.#aborted) {
|
|
1815
|
+
break;
|
|
1816
|
+
}
|
|
1817
|
+
respMessages = [];
|
|
1882
1818
|
let timeout;
|
|
1819
|
+
let requestAbortController;
|
|
1820
|
+
requestAbortController = new AbortController();
|
|
1821
|
+
this.#abortController = requestAbortController;
|
|
1883
1822
|
const resetTimeout = () => {
|
|
1884
1823
|
if (timeout) {
|
|
1885
1824
|
clearTimeout(timeout);
|
|
1886
1825
|
}
|
|
1887
|
-
if (requestTimeoutSeconds > 0) {
|
|
1826
|
+
if (requestTimeoutSeconds > 0 && requestAbortController) {
|
|
1888
1827
|
timeout = setTimeout(() => {
|
|
1889
|
-
console.debug(
|
|
1890
|
-
|
|
1828
|
+
console.debug(
|
|
1829
|
+
`Request timeout after ${requestTimeoutSeconds} seconds. Canceling current request attempt ${i + 1}/${retryCount}.`
|
|
1830
|
+
);
|
|
1831
|
+
requestAbortController?.abort();
|
|
1891
1832
|
}, requestTimeoutSeconds * 1e3);
|
|
1892
1833
|
}
|
|
1893
1834
|
};
|
|
1894
|
-
this.#abortController = new AbortController();
|
|
1895
|
-
const providerOptions = {};
|
|
1896
|
-
const thinkingBudgetTokens = this.config.parameters?.thinkingBudgetTokens;
|
|
1897
|
-
const enableThinking = thinkingBudgetTokens > 0;
|
|
1898
|
-
if (enableThinking) {
|
|
1899
|
-
providerOptions.anthropic = {
|
|
1900
|
-
thinking: { type: "enabled", budgetTokens: thinkingBudgetTokens }
|
|
1901
|
-
};
|
|
1902
|
-
providerOptions.openrouter = {
|
|
1903
|
-
reasoning: {
|
|
1904
|
-
max_tokens: thinkingBudgetTokens
|
|
1905
|
-
}
|
|
1906
|
-
};
|
|
1907
|
-
providerOptions.google = {
|
|
1908
|
-
thinkingConfig: {
|
|
1909
|
-
includeThoughts: true,
|
|
1910
|
-
thinkingBudget: thinkingBudgetTokens
|
|
1911
|
-
}
|
|
1912
|
-
};
|
|
1913
|
-
}
|
|
1914
1835
|
try {
|
|
1915
|
-
|
|
1836
|
+
resetTimeout();
|
|
1837
|
+
const streamTextOptions = {
|
|
1916
1838
|
model: this.ai,
|
|
1917
1839
|
messages,
|
|
1918
|
-
providerOptions,
|
|
1840
|
+
providerOptions: this.config.parameters?.providerOptions,
|
|
1919
1841
|
onChunk: async ({ chunk }) => {
|
|
1920
1842
|
resetTimeout();
|
|
1921
1843
|
switch (chunk.type) {
|
|
1922
1844
|
case "text":
|
|
1923
|
-
currentAssistantMessage += chunk.text;
|
|
1924
1845
|
await this.#callback({ kind: "Text" /* Text */, agent: this, newText: chunk.text });
|
|
1925
1846
|
break;
|
|
1926
1847
|
case "reasoning":
|
|
1927
1848
|
await this.#callback({ kind: "Reasoning" /* Reasoning */, agent: this, newText: chunk.text });
|
|
1928
1849
|
break;
|
|
1850
|
+
case "tool-call":
|
|
1851
|
+
break;
|
|
1929
1852
|
}
|
|
1930
1853
|
},
|
|
1931
1854
|
onFinish: this.config.usageMeter.onFinishHandler(this.ai),
|
|
1932
1855
|
onError: async (error) => {
|
|
1933
1856
|
console.error("Error in stream:", error);
|
|
1934
1857
|
},
|
|
1935
|
-
abortSignal:
|
|
1858
|
+
abortSignal: requestAbortController.signal
|
|
1859
|
+
};
|
|
1860
|
+
if (this.config.toolFormat === "native") {
|
|
1861
|
+
streamTextOptions.tools = this.#toolSet;
|
|
1862
|
+
}
|
|
1863
|
+
const stream = streamText(streamTextOptions);
|
|
1864
|
+
await stream.consumeStream({
|
|
1865
|
+
onError: (error) => {
|
|
1866
|
+
console.error("Error in stream:", error);
|
|
1867
|
+
}
|
|
1936
1868
|
});
|
|
1937
|
-
await stream.
|
|
1869
|
+
const resp = await stream.response;
|
|
1870
|
+
respMessages = resp.messages;
|
|
1871
|
+
if (timeout) {
|
|
1872
|
+
clearTimeout(timeout);
|
|
1873
|
+
timeout = void 0;
|
|
1874
|
+
}
|
|
1938
1875
|
} catch (error) {
|
|
1939
1876
|
if (error instanceof Error && error.name === "AbortError") {
|
|
1940
|
-
|
|
1877
|
+
if (this.#aborted) {
|
|
1878
|
+
break;
|
|
1879
|
+
}
|
|
1880
|
+
console.debug(`Request attempt ${i + 1} timed out, will retry`);
|
|
1881
|
+
} else {
|
|
1882
|
+
console.error("Error in stream:", error);
|
|
1941
1883
|
}
|
|
1942
|
-
console.error("Error in stream:", error);
|
|
1943
1884
|
} finally {
|
|
1944
1885
|
if (timeout) {
|
|
1945
1886
|
clearTimeout(timeout);
|
|
1946
1887
|
}
|
|
1947
1888
|
}
|
|
1948
|
-
if (
|
|
1889
|
+
if (respMessages.length > 0) {
|
|
1949
1890
|
break;
|
|
1950
1891
|
}
|
|
1951
1892
|
if (this.#aborted) {
|
|
1952
1893
|
break;
|
|
1953
1894
|
}
|
|
1954
|
-
|
|
1895
|
+
if (i < retryCount - 1) {
|
|
1896
|
+
console.debug(`Retrying request ${i + 2} of ${retryCount}`);
|
|
1897
|
+
}
|
|
1955
1898
|
}
|
|
1956
|
-
if (
|
|
1899
|
+
if (respMessages.length === 0) {
|
|
1957
1900
|
if (this.#aborted) {
|
|
1958
1901
|
return [];
|
|
1959
1902
|
}
|
|
1960
|
-
throw new Error("No assistant message received");
|
|
1903
|
+
throw new Error("No assistant message received after all retry attempts");
|
|
1904
|
+
}
|
|
1905
|
+
this.#messages.push(...respMessages);
|
|
1906
|
+
if (this.config.toolFormat === "native") {
|
|
1907
|
+
return respMessages.flatMap((msg) => {
|
|
1908
|
+
if (msg.role === "assistant") {
|
|
1909
|
+
const content = msg.content;
|
|
1910
|
+
if (typeof content === "string") {
|
|
1911
|
+
return [{ type: "text", content }];
|
|
1912
|
+
}
|
|
1913
|
+
return content.flatMap((part) => {
|
|
1914
|
+
if (part.type === "text" || part.type === "reasoning") {
|
|
1915
|
+
return [{ type: "text", content: part.text }];
|
|
1916
|
+
}
|
|
1917
|
+
if (part.type === "tool-call") {
|
|
1918
|
+
return [{ type: "tool_use", id: part.toolCallId, name: part.toolName, params: part.input }];
|
|
1919
|
+
}
|
|
1920
|
+
return [];
|
|
1921
|
+
});
|
|
1922
|
+
}
|
|
1923
|
+
return [];
|
|
1924
|
+
});
|
|
1961
1925
|
}
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1926
|
+
const currentAssistantMessage = respMessages.map((msg) => {
|
|
1927
|
+
if (typeof msg.content === "string") {
|
|
1928
|
+
return msg.content;
|
|
1929
|
+
}
|
|
1930
|
+
return msg.content.map((part) => {
|
|
1931
|
+
if (part.type === "text") {
|
|
1932
|
+
return part.text;
|
|
1933
|
+
}
|
|
1934
|
+
return "";
|
|
1935
|
+
});
|
|
1936
|
+
}).join("\n");
|
|
1967
1937
|
const ret = parseAssistantMessage(currentAssistantMessage, this.config.tools.map(toToolInfoV1), this.config.toolNamePrefix);
|
|
1968
1938
|
await this.#callback({ kind: "EndRequest" /* EndRequest */, agent: this, message: currentAssistantMessage });
|
|
1969
1939
|
return ret;
|
|
@@ -1976,12 +1946,12 @@ ${instance.prompt}`;
|
|
|
1976
1946
|
case "text":
|
|
1977
1947
|
break;
|
|
1978
1948
|
case "tool_use": {
|
|
1979
|
-
await this.#callback({ kind: "ToolUse" /* ToolUse */, agent: this, tool: content.name });
|
|
1949
|
+
await this.#callback({ kind: "ToolUse" /* ToolUse */, agent: this, tool: content.name, content: content.params });
|
|
1980
1950
|
const toolResp = await this.#invokeTool(content.name, content.params);
|
|
1981
1951
|
switch (toolResp.type) {
|
|
1982
1952
|
case "Reply" /* Reply */: {
|
|
1983
|
-
await this.#callback({ kind: "ToolReply" /* ToolReply */, agent: this, tool: content.name });
|
|
1984
|
-
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message });
|
|
1953
|
+
await this.#callback({ kind: "ToolReply" /* ToolReply */, agent: this, tool: content.name, content: toolResp.message });
|
|
1954
|
+
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message, id: content.id });
|
|
1985
1955
|
break;
|
|
1986
1956
|
}
|
|
1987
1957
|
case "Exit" /* Exit */:
|
|
@@ -1990,17 +1960,17 @@ ${instance.prompt}`;
|
|
|
1990
1960
|
}
|
|
1991
1961
|
return { type: "exit", reason: toolResp };
|
|
1992
1962
|
case "Invalid" /* Invalid */: {
|
|
1993
|
-
await this.#callback({ kind: "ToolInvalid" /* ToolInvalid */, agent: this, tool: content.name });
|
|
1994
|
-
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message });
|
|
1963
|
+
await this.#callback({ kind: "ToolInvalid" /* ToolInvalid */, agent: this, tool: content.name, content: toolResp.message });
|
|
1964
|
+
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message, id: content.id });
|
|
1995
1965
|
break outer;
|
|
1996
1966
|
}
|
|
1997
1967
|
case "Error" /* Error */: {
|
|
1998
|
-
await this.#callback({ kind: "ToolError" /* ToolError */, agent: this, tool: content.name });
|
|
1999
|
-
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message });
|
|
1968
|
+
await this.#callback({ kind: "ToolError" /* ToolError */, agent: this, tool: content.name, content: toolResp.message });
|
|
1969
|
+
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message, id: content.id });
|
|
2000
1970
|
break outer;
|
|
2001
1971
|
}
|
|
2002
1972
|
case "Interrupted" /* Interrupted */:
|
|
2003
|
-
await this.#callback({ kind: "ToolInterrupted" /* ToolInterrupted */, agent: this, tool: content.name });
|
|
1973
|
+
await this.#callback({ kind: "ToolInterrupted" /* ToolInterrupted */, agent: this, tool: content.name, content: toolResp.message });
|
|
2004
1974
|
return { type: "exit", reason: toolResp };
|
|
2005
1975
|
case "HandOver" /* HandOver */: {
|
|
2006
1976
|
if (toolResponses.length > 0) {
|
|
@@ -2034,7 +2004,7 @@ ${instance.prompt}`;
|
|
|
2034
2004
|
}
|
|
2035
2005
|
case "Pause" /* Pause */: {
|
|
2036
2006
|
await this.#callback({ kind: "ToolPause" /* ToolPause */, agent: this, tool: content.name, object: toolResp.object });
|
|
2037
|
-
toolResponses.push({ type: "pause", tool: content.name, object: toolResp.object });
|
|
2007
|
+
toolResponses.push({ type: "pause", tool: content.name, object: toolResp.object, id: content.id });
|
|
2038
2008
|
hasPause = true;
|
|
2039
2009
|
}
|
|
2040
2010
|
}
|
|
@@ -2046,15 +2016,56 @@ ${instance.prompt}`;
|
|
|
2046
2016
|
return { type: "exit", reason: { type: "Pause", responses: toolResponses } };
|
|
2047
2017
|
}
|
|
2048
2018
|
if (toolResponses.length === 0) {
|
|
2049
|
-
return {
|
|
2019
|
+
return {
|
|
2020
|
+
type: "reply",
|
|
2021
|
+
message: {
|
|
2022
|
+
role: "user",
|
|
2023
|
+
content: responsePrompts.requireUseToolNative
|
|
2024
|
+
}
|
|
2025
|
+
};
|
|
2026
|
+
}
|
|
2027
|
+
if (this.config.toolFormat === "native") {
|
|
2028
|
+
const toolResults = toolResponses.filter((resp) => resp.type === "response").map(
|
|
2029
|
+
(resp) => ({
|
|
2030
|
+
type: "tool-result",
|
|
2031
|
+
toolCallId: resp.id,
|
|
2032
|
+
toolName: resp.tool,
|
|
2033
|
+
output: {
|
|
2034
|
+
type: "text",
|
|
2035
|
+
value: resp.response
|
|
2036
|
+
}
|
|
2037
|
+
})
|
|
2038
|
+
);
|
|
2039
|
+
return {
|
|
2040
|
+
type: "reply",
|
|
2041
|
+
message: {
|
|
2042
|
+
role: "tool",
|
|
2043
|
+
content: toolResults
|
|
2044
|
+
}
|
|
2045
|
+
};
|
|
2046
|
+
}
|
|
2047
|
+
if (toolResponses.length === 0) {
|
|
2048
|
+
return {
|
|
2049
|
+
type: "reply",
|
|
2050
|
+
message: {
|
|
2051
|
+
role: "user",
|
|
2052
|
+
content: responsePrompts.requireUseTool
|
|
2053
|
+
}
|
|
2054
|
+
};
|
|
2050
2055
|
}
|
|
2051
2056
|
const finalResp = toolResponses.filter((resp) => resp.type === "response").flatMap(({ tool, response: response2 }) => responsePrompts.toolResults(tool, response2));
|
|
2052
|
-
return {
|
|
2057
|
+
return {
|
|
2058
|
+
type: "reply",
|
|
2059
|
+
message: {
|
|
2060
|
+
role: "user",
|
|
2061
|
+
content: finalResp
|
|
2062
|
+
}
|
|
2063
|
+
};
|
|
2053
2064
|
}
|
|
2054
2065
|
async #invokeTool(name, args) {
|
|
2055
2066
|
try {
|
|
2056
|
-
const
|
|
2057
|
-
if (!
|
|
2067
|
+
const handler15 = this.handlers[name]?.handler;
|
|
2068
|
+
if (!handler15) {
|
|
2058
2069
|
return {
|
|
2059
2070
|
type: "Error" /* Error */,
|
|
2060
2071
|
message: responsePrompts.errorInvokeTool(name, "Tool not found"),
|
|
@@ -2073,7 +2084,7 @@ ${instance.prompt}`;
|
|
|
2073
2084
|
if (resp) {
|
|
2074
2085
|
return resp;
|
|
2075
2086
|
}
|
|
2076
|
-
return await
|
|
2087
|
+
return await handler15(this.config.provider, args);
|
|
2077
2088
|
} catch (error) {
|
|
2078
2089
|
return {
|
|
2079
2090
|
type: "Error" /* Error */,
|
|
@@ -2130,12 +2141,12 @@ var AnalyzerAgent = class extends AgentBase {
|
|
|
2130
2141
|
permissionLevel: 1 /* Read */,
|
|
2131
2142
|
interactive: true
|
|
2132
2143
|
});
|
|
2133
|
-
const toolNamePrefix = "tool_";
|
|
2144
|
+
const toolNamePrefix = options.toolFormat === "native" ? "" : "tool_";
|
|
2134
2145
|
const systemPrompt = fullSystemPrompt(
|
|
2135
2146
|
{
|
|
2136
2147
|
os: options.os
|
|
2137
2148
|
},
|
|
2138
|
-
tools
|
|
2149
|
+
tools,
|
|
2139
2150
|
toolNamePrefix,
|
|
2140
2151
|
options.customInstructions ?? [],
|
|
2141
2152
|
options.scripts ?? {},
|
|
@@ -2226,12 +2237,12 @@ var ArchitectAgent = class extends AgentBase {
|
|
|
2226
2237
|
permissionLevel: 1 /* Read */,
|
|
2227
2238
|
interactive: true
|
|
2228
2239
|
});
|
|
2229
|
-
const toolNamePrefix = "tool_";
|
|
2240
|
+
const toolNamePrefix = options.toolFormat === "native" ? "" : "tool_";
|
|
2230
2241
|
const systemPrompt = fullSystemPrompt2(
|
|
2231
2242
|
{
|
|
2232
2243
|
os: options.os
|
|
2233
2244
|
},
|
|
2234
|
-
tools
|
|
2245
|
+
tools,
|
|
2235
2246
|
toolNamePrefix,
|
|
2236
2247
|
options.customInstructions ?? [],
|
|
2237
2248
|
options.scripts ?? {},
|
|
@@ -2355,12 +2366,12 @@ var CodeFixerAgent = class extends AgentBase {
|
|
|
2355
2366
|
permissionLevel: 3 /* Arbitrary */,
|
|
2356
2367
|
interactive: true
|
|
2357
2368
|
});
|
|
2358
|
-
const toolNamePrefix = "tool_";
|
|
2369
|
+
const toolNamePrefix = options.toolFormat === "native" ? "" : "tool_";
|
|
2359
2370
|
const systemPrompt = fullSystemPrompt3(
|
|
2360
2371
|
{
|
|
2361
2372
|
os: options.os
|
|
2362
2373
|
},
|
|
2363
|
-
tools
|
|
2374
|
+
tools,
|
|
2364
2375
|
toolNamePrefix,
|
|
2365
2376
|
options.customInstructions ?? [],
|
|
2366
2377
|
options.scripts ?? {},
|
|
@@ -2561,12 +2572,12 @@ var CoderAgent = class extends AgentBase {
|
|
|
2561
2572
|
permissionLevel: 3 /* Arbitrary */,
|
|
2562
2573
|
interactive: true
|
|
2563
2574
|
});
|
|
2564
|
-
const toolNamePrefix = "tool_";
|
|
2575
|
+
const toolNamePrefix = options.toolFormat === "native" ? "" : "tool_";
|
|
2565
2576
|
const systemPrompt = fullSystemPrompt4(
|
|
2566
2577
|
{
|
|
2567
2578
|
os: options.os
|
|
2568
2579
|
},
|
|
2569
|
-
tools
|
|
2580
|
+
tools,
|
|
2570
2581
|
toolNamePrefix,
|
|
2571
2582
|
options.customInstructions ?? [],
|
|
2572
2583
|
options.scripts ?? {},
|
|
@@ -2658,24 +2669,24 @@ var MultiAgent = class {
|
|
|
2658
2669
|
switch (exitReason.type) {
|
|
2659
2670
|
case "HandOver" /* HandOver */: {
|
|
2660
2671
|
this.#agents.pop();
|
|
2661
|
-
const
|
|
2672
|
+
const prompt6 = await this.#config.getPrompt?.(
|
|
2662
2673
|
exitReason.agentName,
|
|
2663
2674
|
exitReason.task,
|
|
2664
2675
|
exitReason.context,
|
|
2665
2676
|
exitReason.files,
|
|
2666
2677
|
this.#originalTask
|
|
2667
2678
|
) ?? exitReason.task;
|
|
2668
|
-
return await this.#startTask(exitReason.agentName,
|
|
2679
|
+
return await this.#startTask(exitReason.agentName, prompt6);
|
|
2669
2680
|
}
|
|
2670
2681
|
case "Delegate" /* Delegate */: {
|
|
2671
|
-
const
|
|
2682
|
+
const prompt6 = await this.#config.getPrompt?.(
|
|
2672
2683
|
exitReason.agentName,
|
|
2673
2684
|
exitReason.task,
|
|
2674
2685
|
exitReason.context,
|
|
2675
2686
|
exitReason.files,
|
|
2676
2687
|
this.#originalTask
|
|
2677
2688
|
) ?? exitReason.task;
|
|
2678
|
-
const delegateResult = await this.#startTask(exitReason.agentName,
|
|
2689
|
+
const delegateResult = await this.#startTask(exitReason.agentName, prompt6);
|
|
2679
2690
|
switch (delegateResult.type) {
|
|
2680
2691
|
case "HandOver" /* HandOver */:
|
|
2681
2692
|
case "Delegate" /* Delegate */:
|
|
@@ -3014,23 +3025,23 @@ var prompt = `You are an AiTool designed to assist users in creating new project
|
|
|
3014
3025
|
- Create a .gitattributes file with appropriate configurations:
|
|
3015
3026
|
- Mark lock files as generated and exclude them from diffs
|
|
3016
3027
|
- Example for different package managers:
|
|
3017
|
-
|
|
3028
|
+
|
|
3018
3029
|
# For Bun
|
|
3019
3030
|
bun.lock linguist-generated=true
|
|
3020
3031
|
bun.lock -diff
|
|
3021
|
-
|
|
3032
|
+
|
|
3022
3033
|
# For npm
|
|
3023
3034
|
package-lock.json linguist-generated=true
|
|
3024
3035
|
package-lock.json -diff
|
|
3025
|
-
|
|
3036
|
+
|
|
3026
3037
|
# For Yarn
|
|
3027
3038
|
yarn.lock linguist-generated=true
|
|
3028
3039
|
yarn.lock -diff
|
|
3029
|
-
|
|
3040
|
+
|
|
3030
3041
|
# For pnpm
|
|
3031
3042
|
pnpm-lock.yaml linguist-generated=true
|
|
3032
3043
|
pnpm-lock.yaml -diff
|
|
3033
|
-
|
|
3044
|
+
|
|
3034
3045
|
- Include other common configurations as needed based on project type
|
|
3035
3046
|
|
|
3036
3047
|
6. **Handover to Coder Agent:**
|
|
@@ -3286,6 +3297,199 @@ var generateProjectConfig_default = {
|
|
|
3286
3297
|
agent: "analyzer"
|
|
3287
3298
|
};
|
|
3288
3299
|
|
|
3300
|
+
// src/AiTool/tools/gitDiff.ts
|
|
3301
|
+
import { z as z16 } from "zod";
|
|
3302
|
+
var toolInfo14 = {
|
|
3303
|
+
name: "git_diff",
|
|
3304
|
+
description: "Get the git diff for the current repository. Can be used to get staged changes, unstaged changes, or changes between commits. By default, it returns unstaged changes.",
|
|
3305
|
+
parameters: z16.object({
|
|
3306
|
+
staged: z16.preprocess((val) => {
|
|
3307
|
+
if (typeof val === "string") {
|
|
3308
|
+
const lower = val.toLowerCase();
|
|
3309
|
+
if (lower === "false") return false;
|
|
3310
|
+
if (lower === "true") return true;
|
|
3311
|
+
}
|
|
3312
|
+
return val;
|
|
3313
|
+
}, z16.boolean().optional().default(false)).describe("Get staged changes instead of unstaged changes."),
|
|
3314
|
+
commitRange: z16.string().optional().describe('The commit range to get the diff for (e.g., "main...HEAD").'),
|
|
3315
|
+
file: z16.string().optional().describe("Get the diff for a specific file.")
|
|
3316
|
+
}),
|
|
3317
|
+
permissionLevel: 1 /* Read */
|
|
3318
|
+
};
|
|
3319
|
+
var handler14 = async (provider, args) => {
|
|
3320
|
+
if (!provider.executeCommand) {
|
|
3321
|
+
return {
|
|
3322
|
+
type: "Error" /* Error */,
|
|
3323
|
+
message: "Not possible to execute command. Abort."
|
|
3324
|
+
};
|
|
3325
|
+
}
|
|
3326
|
+
const { staged, file, commitRange } = toolInfo14.parameters.parse(args);
|
|
3327
|
+
const commandParts = ["git", "diff", "--no-color"];
|
|
3328
|
+
if (staged) {
|
|
3329
|
+
commandParts.push("--staged");
|
|
3330
|
+
}
|
|
3331
|
+
if (commitRange) {
|
|
3332
|
+
commandParts.push(commitRange);
|
|
3333
|
+
}
|
|
3334
|
+
if (file) {
|
|
3335
|
+
commandParts.push("--", file);
|
|
3336
|
+
}
|
|
3337
|
+
const command = commandParts.join(" ");
|
|
3338
|
+
try {
|
|
3339
|
+
const result = await provider.executeCommand(command, false);
|
|
3340
|
+
if (result.exitCode === 0) {
|
|
3341
|
+
if (!result.stdout.trim()) {
|
|
3342
|
+
return {
|
|
3343
|
+
type: "Reply" /* Reply */,
|
|
3344
|
+
message: "No diff found."
|
|
3345
|
+
};
|
|
3346
|
+
}
|
|
3347
|
+
return {
|
|
3348
|
+
type: "Reply" /* Reply */,
|
|
3349
|
+
message: `<diff file="${file ?? "all"}">
|
|
3350
|
+
${result.stdout}
|
|
3351
|
+
</diff>`
|
|
3352
|
+
};
|
|
3353
|
+
}
|
|
3354
|
+
return {
|
|
3355
|
+
type: "Error" /* Error */,
|
|
3356
|
+
message: `\`${command}\` exited with code ${result.exitCode}:
|
|
3357
|
+
${result.stderr}`
|
|
3358
|
+
};
|
|
3359
|
+
} catch (error) {
|
|
3360
|
+
return {
|
|
3361
|
+
type: "Error" /* Error */,
|
|
3362
|
+
message: error instanceof Error ? error.message : String(error)
|
|
3363
|
+
};
|
|
3364
|
+
}
|
|
3365
|
+
};
|
|
3366
|
+
var isAvailable14 = (provider) => {
|
|
3367
|
+
return !!provider.executeCommand;
|
|
3368
|
+
};
|
|
3369
|
+
var gitDiff_default = {
|
|
3370
|
+
...toolInfo14,
|
|
3371
|
+
handler: handler14,
|
|
3372
|
+
isAvailable: isAvailable14
|
|
3373
|
+
};
|
|
3374
|
+
|
|
3375
|
+
// src/AiTool/reviewDiff.ts
|
|
3376
|
+
var prompt5 = `
|
|
3377
|
+
# Code Review Prompt
|
|
3378
|
+
|
|
3379
|
+
You are a senior software engineer reviewing code changes.
|
|
3380
|
+
|
|
3381
|
+
## Critical Instructions
|
|
3382
|
+
**ONLY review the actual changes shown in the diff.** Do not comment on existing code that wasn't modified.
|
|
3383
|
+
|
|
3384
|
+
## Viewing Changes
|
|
3385
|
+
- **Use git_diff** to inspect the actual code changes for each relevant file.
|
|
3386
|
+
- **Pull request**: use the provided commit range for the git_diff tool.
|
|
3387
|
+
- **Local changes**: diff staged or unstaged files using the git_diff tool.
|
|
3388
|
+
- If a pull request is present you may receive:
|
|
3389
|
+
- <pr_title>
|
|
3390
|
+
- <pr_description>
|
|
3391
|
+
- <commit_messages>
|
|
3392
|
+
- A <review_instructions> tag tells you the focus of the review.
|
|
3393
|
+
- File status information is provided in <file_status> - use this to understand which files were modified, added, deleted, or renamed.
|
|
3394
|
+
|
|
3395
|
+
## Review Guidelines
|
|
3396
|
+
Focus exclusively on the changed lines (+ additions, - deletions, modified lines):
|
|
3397
|
+
- **Specific issues**: Point to exact problems in the changed code with line references
|
|
3398
|
+
- **Actionable fixes**: Provide concrete solutions, not vague suggestions
|
|
3399
|
+
- **Clear reasoning**: Explain why each issue matters and how to fix it
|
|
3400
|
+
- **Avoid generic advice**: No generic suggestions like "add more tests", "improve documentation", or "follow best practices" unless directly related to a specific problem in the diff
|
|
3401
|
+
|
|
3402
|
+
## What NOT to review
|
|
3403
|
+
- Existing unchanged code
|
|
3404
|
+
- Overall project structure or architecture (unless directly impacted by changes)
|
|
3405
|
+
- Generic best practices unrelated to the specific changes
|
|
3406
|
+
- Missing features or functionality not part of this diff
|
|
3407
|
+
|
|
3408
|
+
## Output Format
|
|
3409
|
+
Do **not** include praise or positive feedback. Ignore generated files such as lock files.
|
|
3410
|
+
Only include reviews for actual issues found in the changed code.
|
|
3411
|
+
|
|
3412
|
+
Return your review as a JSON object inside a \`\`\`json block, wrapped like:
|
|
3413
|
+
<tool_attempt_completion>
|
|
3414
|
+
<tool_parameter_result>
|
|
3415
|
+
\`\`\`json
|
|
3416
|
+
{
|
|
3417
|
+
"overview": "Summary of specific issues found in the diff changes, or 'No issues found' if the changes look good.",
|
|
3418
|
+
"specificReviews": [
|
|
3419
|
+
{
|
|
3420
|
+
"file": "path/filename.ext",
|
|
3421
|
+
"lines": "N or N-M",
|
|
3422
|
+
"review": "Specific issue with the changed code and exact actionable fix."
|
|
3423
|
+
}
|
|
3424
|
+
]
|
|
3425
|
+
}
|
|
3426
|
+
\`\`\`
|
|
3427
|
+
</tool_parameter_result>
|
|
3428
|
+
</tool_attempt_completion>
|
|
3429
|
+
`;
|
|
3430
|
+
var reviewDiff_default = {
|
|
3431
|
+
name: "reviewDiff",
|
|
3432
|
+
description: "Reviews a git diff",
|
|
3433
|
+
prompt: prompt5,
|
|
3434
|
+
formatInput: (params) => {
|
|
3435
|
+
const parts = [];
|
|
3436
|
+
if (params.pullRequestTitle) {
|
|
3437
|
+
parts.push(`<pr_title>
|
|
3438
|
+
${params.pullRequestTitle}
|
|
3439
|
+
</pr_title>`);
|
|
3440
|
+
}
|
|
3441
|
+
if (params.pullRequestDescription) {
|
|
3442
|
+
parts.push(`<pr_description>
|
|
3443
|
+
${params.pullRequestDescription}
|
|
3444
|
+
</pr_description>`);
|
|
3445
|
+
}
|
|
3446
|
+
if (params.commitMessages) {
|
|
3447
|
+
parts.push(`<commit_messages>
|
|
3448
|
+
${params.commitMessages}
|
|
3449
|
+
</commit_messages>`);
|
|
3450
|
+
}
|
|
3451
|
+
if (params.changedFiles && params.changedFiles.length > 0) {
|
|
3452
|
+
const fileList = params.changedFiles.map((file) => `${file.status}: ${file.path}`).join("\n");
|
|
3453
|
+
parts.push(`<file_status>
|
|
3454
|
+
${fileList}
|
|
3455
|
+
</file_status>`);
|
|
3456
|
+
}
|
|
3457
|
+
let instructions = "";
|
|
3458
|
+
if (params.commitRange) {
|
|
3459
|
+
instructions = `Review the pull request. Use the git_diff tool with commit range '${params.commitRange}' to inspect the actual code changes. File status information is already provided above.`;
|
|
3460
|
+
} else if (params.staged) {
|
|
3461
|
+
instructions = "Review the staged changes. Use the git_diff tool with staged: true to inspect the actual code changes. File status information is already provided above.";
|
|
3462
|
+
} else {
|
|
3463
|
+
instructions = "Review the unstaged changes. Use the git_diff tool to inspect the actual code changes. File status information is already provided above.";
|
|
3464
|
+
}
|
|
3465
|
+
parts.push(`<review_instructions>
|
|
3466
|
+
${instructions}
|
|
3467
|
+
</review_instructions>`);
|
|
3468
|
+
return parts.join("\n");
|
|
3469
|
+
},
|
|
3470
|
+
parseOutput: (output) => {
|
|
3471
|
+
const jsonBlockRegex = /```json\n([\s\S]*?)\n```/;
|
|
3472
|
+
const match = output.match(jsonBlockRegex);
|
|
3473
|
+
const content = match ? match[1] : output;
|
|
3474
|
+
try {
|
|
3475
|
+
return JSON.parse(content);
|
|
3476
|
+
} catch (error) {
|
|
3477
|
+
console.error("Error parsing JSON output:", error);
|
|
3478
|
+
return {
|
|
3479
|
+
overview: `Could not parse review output. Raw output:
|
|
3480
|
+
${output}`,
|
|
3481
|
+
specificReviews: []
|
|
3482
|
+
};
|
|
3483
|
+
}
|
|
3484
|
+
},
|
|
3485
|
+
agent: (options) => {
|
|
3486
|
+
return new AnalyzerAgent({
|
|
3487
|
+
...options,
|
|
3488
|
+
additionalTools: [gitDiff_default]
|
|
3489
|
+
});
|
|
3490
|
+
}
|
|
3491
|
+
};
|
|
3492
|
+
|
|
3289
3493
|
// src/AiTool/index.ts
|
|
3290
3494
|
var executeTool = async (definition, ai, params, usageMeter) => {
|
|
3291
3495
|
const resp = await generateText({
|
|
@@ -3301,10 +3505,7 @@ var executeTool = async (definition, ai, params, usageMeter) => {
|
|
|
3301
3505
|
usageMeter.addUsage(ai, resp);
|
|
3302
3506
|
return definition.parseOutput(resp.text);
|
|
3303
3507
|
};
|
|
3304
|
-
var
|
|
3305
|
-
if (!definition.agent) {
|
|
3306
|
-
throw new Error("Agent not specified");
|
|
3307
|
-
}
|
|
3508
|
+
var executeMultiAgentTool = async (definition, agent, params) => {
|
|
3308
3509
|
const exitReason = await agent.startTask({
|
|
3309
3510
|
agentName: definition.agent,
|
|
3310
3511
|
task: definition.prompt,
|
|
@@ -3315,20 +3516,36 @@ var executeAgentTool = async (definition, agent, params) => {
|
|
|
3315
3516
|
}
|
|
3316
3517
|
throw new Error(`Tool execution failed: ${exitReason.type}`);
|
|
3317
3518
|
};
|
|
3519
|
+
var executeAgentTool = async (definition, options, params) => {
|
|
3520
|
+
const agent = definition.agent(options);
|
|
3521
|
+
const exitReason = await agent.start(`${definition.prompt}
|
|
3522
|
+
|
|
3523
|
+
${definition.formatInput(params)}`);
|
|
3524
|
+
if (exitReason.type === "Exit" /* Exit */) {
|
|
3525
|
+
return definition.parseOutput(exitReason.message);
|
|
3526
|
+
}
|
|
3527
|
+
throw new Error(`Tool execution failed: ${exitReason.type}`);
|
|
3528
|
+
};
|
|
3318
3529
|
var makeTool = (definition) => {
|
|
3319
3530
|
return async (ai, params, usageMeter) => {
|
|
3320
3531
|
return executeTool(definition, ai, params, usageMeter);
|
|
3321
3532
|
};
|
|
3322
3533
|
};
|
|
3323
|
-
var
|
|
3534
|
+
var makeMultiAgentTool = (definition) => {
|
|
3324
3535
|
return async (agent, params) => {
|
|
3325
|
-
return
|
|
3536
|
+
return executeMultiAgentTool(definition, agent, params);
|
|
3537
|
+
};
|
|
3538
|
+
};
|
|
3539
|
+
var makeAgentTool = (definition) => {
|
|
3540
|
+
return async (options, params) => {
|
|
3541
|
+
return executeAgentTool(definition, options, params);
|
|
3326
3542
|
};
|
|
3327
3543
|
};
|
|
3328
3544
|
var generateGitCommitMessage = makeTool(generateGitCommitMessage_default);
|
|
3329
3545
|
var generateGithubPullRequestDetails = makeTool(generateGithubPullRequestDetails_default);
|
|
3330
|
-
var
|
|
3331
|
-
var
|
|
3546
|
+
var reviewDiff = makeAgentTool(reviewDiff_default);
|
|
3547
|
+
var generateProjectConfig = makeMultiAgentTool(generateProjectConfig_default);
|
|
3548
|
+
var createNewProject = makeMultiAgentTool(createNewProject_default);
|
|
3332
3549
|
export {
|
|
3333
3550
|
AgentBase,
|
|
3334
3551
|
AnalyzerAgent,
|
|
@@ -3361,6 +3578,7 @@ export {
|
|
|
3361
3578
|
delegate_default as delegate,
|
|
3362
3579
|
executeAgentTool,
|
|
3363
3580
|
executeCommand_default as executeCommand,
|
|
3581
|
+
executeMultiAgentTool,
|
|
3364
3582
|
executeTool,
|
|
3365
3583
|
fetchUrl_default as fetchUrl,
|
|
3366
3584
|
generateGitCommitMessage,
|
|
@@ -3370,6 +3588,7 @@ export {
|
|
|
3370
3588
|
handOver_default as handOver,
|
|
3371
3589
|
listFiles_default as listFiles,
|
|
3372
3590
|
makeAgentTool,
|
|
3591
|
+
makeMultiAgentTool,
|
|
3373
3592
|
makeTool,
|
|
3374
3593
|
parseAssistantMessage,
|
|
3375
3594
|
readFile_default as readFile,
|
|
@@ -3378,6 +3597,7 @@ export {
|
|
|
3378
3597
|
replaceInFile_default as replaceInFile,
|
|
3379
3598
|
replaceInFile as replaceInFileHelper,
|
|
3380
3599
|
responsePrompts,
|
|
3600
|
+
reviewDiff,
|
|
3381
3601
|
searchFiles_default as searchFiles,
|
|
3382
3602
|
systemInformation,
|
|
3383
3603
|
toolUsePrompt,
|