@polka-codes/core 0.9.19 → 0.9.21
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 +138 -66
- package/dist/index.d.ts +3 -0
- package/dist/index.js +525 -236
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ __export(allTools_exports, {
|
|
|
14
14
|
fetchUrl: () => fetchUrl_default,
|
|
15
15
|
handOver: () => handOver_default,
|
|
16
16
|
listFiles: () => listFiles_default,
|
|
17
|
+
readBinaryFile: () => readBinaryFile_default,
|
|
17
18
|
readFile: () => readFile_default,
|
|
18
19
|
removeFile: () => removeFile_default,
|
|
19
20
|
renameFile: () => renameFile_default,
|
|
@@ -101,14 +102,20 @@ var handler = async (provider, args) => {
|
|
|
101
102
|
if (!provider.askFollowupQuestion) {
|
|
102
103
|
return {
|
|
103
104
|
type: "Error" /* Error */,
|
|
104
|
-
message:
|
|
105
|
+
message: {
|
|
106
|
+
type: "error-text",
|
|
107
|
+
value: "Not possible to ask followup question."
|
|
108
|
+
}
|
|
105
109
|
};
|
|
106
110
|
}
|
|
107
111
|
const { questions } = toolInfo.parameters.parse(args);
|
|
108
112
|
if (questions.length === 0) {
|
|
109
113
|
return {
|
|
110
114
|
type: "Invalid" /* Invalid */,
|
|
111
|
-
message:
|
|
115
|
+
message: {
|
|
116
|
+
type: "error-text",
|
|
117
|
+
value: "No questions provided"
|
|
118
|
+
}
|
|
112
119
|
};
|
|
113
120
|
}
|
|
114
121
|
const answers = [];
|
|
@@ -121,7 +128,10 @@ ${answer}
|
|
|
121
128
|
}
|
|
122
129
|
return {
|
|
123
130
|
type: "Reply" /* Reply */,
|
|
124
|
-
message:
|
|
131
|
+
message: {
|
|
132
|
+
type: "text",
|
|
133
|
+
value: answers.join("\n")
|
|
134
|
+
}
|
|
125
135
|
};
|
|
126
136
|
};
|
|
127
137
|
var isAvailable = (provider) => {
|
|
@@ -159,7 +169,10 @@ var handler2 = async (provider, args) => {
|
|
|
159
169
|
if (!parsed.success) {
|
|
160
170
|
return {
|
|
161
171
|
type: "Invalid" /* Invalid */,
|
|
162
|
-
message:
|
|
172
|
+
message: {
|
|
173
|
+
type: "error-text",
|
|
174
|
+
value: `Invalid arguments for attempt_completion: ${parsed.error.message}`
|
|
175
|
+
}
|
|
163
176
|
};
|
|
164
177
|
}
|
|
165
178
|
const { result } = parsed.data;
|
|
@@ -172,7 +185,10 @@ var handler2 = async (provider, args) => {
|
|
|
172
185
|
}
|
|
173
186
|
return {
|
|
174
187
|
type: "Reply" /* Reply */,
|
|
175
|
-
message:
|
|
188
|
+
message: {
|
|
189
|
+
type: "text",
|
|
190
|
+
value: `<user_message>${moreMessage}</user_message>`
|
|
191
|
+
}
|
|
176
192
|
};
|
|
177
193
|
};
|
|
178
194
|
var isAvailable2 = (_provider) => {
|
|
@@ -218,7 +234,10 @@ var handler3 = async (_provider, args) => {
|
|
|
218
234
|
if (!parsed.success) {
|
|
219
235
|
return {
|
|
220
236
|
type: "Invalid" /* Invalid */,
|
|
221
|
-
message:
|
|
237
|
+
message: {
|
|
238
|
+
type: "error-text",
|
|
239
|
+
value: `Invalid arguments for delegate: ${parsed.error.message}`
|
|
240
|
+
}
|
|
222
241
|
};
|
|
223
242
|
}
|
|
224
243
|
const { agentName, task, context, files } = parsed.data;
|
|
@@ -273,7 +292,10 @@ var handler4 = async (provider, args) => {
|
|
|
273
292
|
if (!provider.executeCommand) {
|
|
274
293
|
return {
|
|
275
294
|
type: "Error" /* Error */,
|
|
276
|
-
message:
|
|
295
|
+
message: {
|
|
296
|
+
type: "error-text",
|
|
297
|
+
value: "Not possible to execute command. Abort."
|
|
298
|
+
}
|
|
277
299
|
};
|
|
278
300
|
}
|
|
279
301
|
const { command, requiresApproval } = toolInfo4.parameters.parse(args);
|
|
@@ -291,17 +313,26 @@ ${result.stderr}
|
|
|
291
313
|
if (result.exitCode === 0) {
|
|
292
314
|
return {
|
|
293
315
|
type: "Reply" /* Reply */,
|
|
294
|
-
message
|
|
316
|
+
message: {
|
|
317
|
+
type: "text",
|
|
318
|
+
value: message
|
|
319
|
+
}
|
|
295
320
|
};
|
|
296
321
|
}
|
|
297
322
|
return {
|
|
298
323
|
type: "Error" /* Error */,
|
|
299
|
-
message
|
|
324
|
+
message: {
|
|
325
|
+
type: "error-text",
|
|
326
|
+
value: message
|
|
327
|
+
}
|
|
300
328
|
};
|
|
301
329
|
} catch (error) {
|
|
302
330
|
return {
|
|
303
331
|
type: "Error" /* Error */,
|
|
304
|
-
message:
|
|
332
|
+
message: {
|
|
333
|
+
type: "error-text",
|
|
334
|
+
value: error instanceof Error ? error.message : String(error)
|
|
335
|
+
}
|
|
305
336
|
};
|
|
306
337
|
}
|
|
307
338
|
};
|
|
@@ -353,14 +384,20 @@ var handler5 = async (provider, args) => {
|
|
|
353
384
|
if (!provider.fetchUrl) {
|
|
354
385
|
return {
|
|
355
386
|
type: "Error" /* Error */,
|
|
356
|
-
message:
|
|
387
|
+
message: {
|
|
388
|
+
type: "error-text",
|
|
389
|
+
value: "Not possible to fetch url."
|
|
390
|
+
}
|
|
357
391
|
};
|
|
358
392
|
}
|
|
359
393
|
const { url: urls } = toolInfo5.parameters.parse(args);
|
|
360
394
|
if (urls.length === 0) {
|
|
361
395
|
return {
|
|
362
396
|
type: "Error" /* Error */,
|
|
363
|
-
message:
|
|
397
|
+
message: {
|
|
398
|
+
type: "error-text",
|
|
399
|
+
value: "No URLs provided. Please provide at least one URL to fetch."
|
|
400
|
+
}
|
|
364
401
|
};
|
|
365
402
|
}
|
|
366
403
|
const results = [];
|
|
@@ -376,7 +413,10 @@ var handler5 = async (provider, args) => {
|
|
|
376
413
|
const resolvedResults = await Promise.all(results);
|
|
377
414
|
return {
|
|
378
415
|
type: "Reply" /* Reply */,
|
|
379
|
-
message:
|
|
416
|
+
message: {
|
|
417
|
+
type: "text",
|
|
418
|
+
value: resolvedResults.join("\n")
|
|
419
|
+
}
|
|
380
420
|
};
|
|
381
421
|
};
|
|
382
422
|
var isAvailable5 = (provider) => {
|
|
@@ -422,7 +462,10 @@ var handler6 = async (_provider, args) => {
|
|
|
422
462
|
if (!parsed.success) {
|
|
423
463
|
return {
|
|
424
464
|
type: "Invalid" /* Invalid */,
|
|
425
|
-
message:
|
|
465
|
+
message: {
|
|
466
|
+
type: "error-text",
|
|
467
|
+
value: `Invalid arguments for hand_over: ${parsed.error.message}`
|
|
468
|
+
}
|
|
426
469
|
};
|
|
427
470
|
}
|
|
428
471
|
const { agentName, task, context, files } = parsed.data;
|
|
@@ -484,18 +527,24 @@ var handler7 = async (provider, args) => {
|
|
|
484
527
|
if (!provider.listFiles) {
|
|
485
528
|
return {
|
|
486
529
|
type: "Error" /* Error */,
|
|
487
|
-
message:
|
|
530
|
+
message: {
|
|
531
|
+
type: "error-text",
|
|
532
|
+
value: "Not possible to list files."
|
|
533
|
+
}
|
|
488
534
|
};
|
|
489
535
|
}
|
|
490
536
|
const { path, maxCount, recursive, includeIgnored } = toolInfo7.parameters.parse(args);
|
|
491
537
|
const [files, limitReached] = await provider.listFiles(path, recursive, maxCount, includeIgnored);
|
|
492
538
|
return {
|
|
493
539
|
type: "Reply" /* Reply */,
|
|
494
|
-
message:
|
|
540
|
+
message: {
|
|
541
|
+
type: "text",
|
|
542
|
+
value: `<list_files_path>${path}</list_files_path>
|
|
495
543
|
<list_files_files>
|
|
496
544
|
${files.join("\n")}
|
|
497
545
|
</list_files_files>
|
|
498
546
|
<list_files_truncated>${limitReached}</list_files_truncated>`
|
|
547
|
+
}
|
|
499
548
|
};
|
|
500
549
|
};
|
|
501
550
|
var isAvailable7 = (provider) => {
|
|
@@ -507,25 +556,82 @@ var listFiles_default = {
|
|
|
507
556
|
isAvailable: isAvailable7
|
|
508
557
|
};
|
|
509
558
|
|
|
510
|
-
// src/tools/
|
|
559
|
+
// src/tools/readBinaryFile.ts
|
|
511
560
|
import { z as z8 } from "zod";
|
|
512
561
|
var toolInfo8 = {
|
|
562
|
+
name: "read_binary_file",
|
|
563
|
+
description: "Read a binary file from a URL or local path. Use file:// prefix to access local files. This can be used to access non-text files such as PDFs or images.",
|
|
564
|
+
parameters: z8.object({
|
|
565
|
+
url: z8.string().describe("The URL or local path of the file to read.")
|
|
566
|
+
}),
|
|
567
|
+
permissionLevel: 1 /* Read */
|
|
568
|
+
};
|
|
569
|
+
var handler8 = async (provider, args) => {
|
|
570
|
+
if (!provider.readBinaryFile) {
|
|
571
|
+
return {
|
|
572
|
+
type: "Error" /* Error */,
|
|
573
|
+
message: {
|
|
574
|
+
type: "error-text",
|
|
575
|
+
value: "Not possible to fetch files. Abort."
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
const { url } = toolInfo8.parameters.parse(args);
|
|
580
|
+
try {
|
|
581
|
+
const filePart = await provider.readBinaryFile(url);
|
|
582
|
+
return {
|
|
583
|
+
type: "Reply" /* Reply */,
|
|
584
|
+
message: {
|
|
585
|
+
type: "content",
|
|
586
|
+
value: [
|
|
587
|
+
{
|
|
588
|
+
type: "media",
|
|
589
|
+
url,
|
|
590
|
+
base64Data: filePart.base64Data,
|
|
591
|
+
mediaType: filePart.mediaType
|
|
592
|
+
}
|
|
593
|
+
]
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
} catch (error) {
|
|
597
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
598
|
+
return {
|
|
599
|
+
type: "Error" /* Error */,
|
|
600
|
+
message: {
|
|
601
|
+
type: "error-text",
|
|
602
|
+
value: `Error fetching file from ${url}: ${errorMessage}`
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
var isAvailable8 = (provider) => {
|
|
608
|
+
return typeof provider.readBinaryFile === "function";
|
|
609
|
+
};
|
|
610
|
+
var readBinaryFile_default = {
|
|
611
|
+
...toolInfo8,
|
|
612
|
+
handler: handler8,
|
|
613
|
+
isAvailable: isAvailable8
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
// src/tools/readFile.ts
|
|
617
|
+
import { z as z9 } from "zod";
|
|
618
|
+
var toolInfo9 = {
|
|
513
619
|
name: "read_file",
|
|
514
620
|
description: "Request to read the contents of one or multiple files at the specified paths. Use comma separated paths to read multiple files. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. May not be suitable for other types of binary files, as it returns the raw content as a string. Try to list all the potential files are relevent to the task, and then use this tool to read all the relevant files.",
|
|
515
|
-
parameters:
|
|
516
|
-
path:
|
|
621
|
+
parameters: z9.object({
|
|
622
|
+
path: z9.preprocess((val) => {
|
|
517
623
|
if (!val) return [];
|
|
518
624
|
const values = Array.isArray(val) ? val : [val];
|
|
519
625
|
return values.flatMap((i) => typeof i === "string" ? i.split(",") : []).filter((s) => s.length > 0);
|
|
520
|
-
},
|
|
521
|
-
includeIgnored:
|
|
626
|
+
}, z9.array(z9.string())).describe("The path of the file to read").meta({ usageValue: "Comma separated paths here" }),
|
|
627
|
+
includeIgnored: z9.preprocess((val) => {
|
|
522
628
|
if (typeof val === "string") {
|
|
523
629
|
const lower = val.toLowerCase();
|
|
524
630
|
if (lower === "false") return false;
|
|
525
631
|
if (lower === "true") return true;
|
|
526
632
|
}
|
|
527
633
|
return val;
|
|
528
|
-
},
|
|
634
|
+
}, z9.boolean().optional().default(false)).describe("Whether to include ignored files. Use true to include files ignored by .gitignore.").meta({ usageValue: "true or false (optional)" })
|
|
529
635
|
}).meta({
|
|
530
636
|
examples: [
|
|
531
637
|
{
|
|
@@ -544,14 +650,17 @@ var toolInfo8 = {
|
|
|
544
650
|
}),
|
|
545
651
|
permissionLevel: 1 /* Read */
|
|
546
652
|
};
|
|
547
|
-
var
|
|
653
|
+
var handler9 = async (provider, args) => {
|
|
548
654
|
if (!provider.readFile) {
|
|
549
655
|
return {
|
|
550
656
|
type: "Error" /* Error */,
|
|
551
|
-
message:
|
|
657
|
+
message: {
|
|
658
|
+
type: "error-text",
|
|
659
|
+
value: "Not possible to read file."
|
|
660
|
+
}
|
|
552
661
|
};
|
|
553
662
|
}
|
|
554
|
-
const { path: paths, includeIgnored } =
|
|
663
|
+
const { path: paths, includeIgnored } = toolInfo9.parameters.parse(args);
|
|
555
664
|
const resp = [];
|
|
556
665
|
for (const path of paths) {
|
|
557
666
|
const fileContent = await provider.readFile(path, includeIgnored);
|
|
@@ -568,25 +677,28 @@ var handler8 = async (provider, args) => {
|
|
|
568
677
|
}
|
|
569
678
|
return {
|
|
570
679
|
type: "Reply" /* Reply */,
|
|
571
|
-
message:
|
|
680
|
+
message: {
|
|
681
|
+
type: "text",
|
|
682
|
+
value: resp.join("\n")
|
|
683
|
+
}
|
|
572
684
|
};
|
|
573
685
|
};
|
|
574
|
-
var
|
|
686
|
+
var isAvailable9 = (provider) => {
|
|
575
687
|
return !!provider.readFile;
|
|
576
688
|
};
|
|
577
689
|
var readFile_default = {
|
|
578
|
-
...
|
|
579
|
-
handler:
|
|
580
|
-
isAvailable:
|
|
690
|
+
...toolInfo9,
|
|
691
|
+
handler: handler9,
|
|
692
|
+
isAvailable: isAvailable9
|
|
581
693
|
};
|
|
582
694
|
|
|
583
695
|
// src/tools/removeFile.ts
|
|
584
|
-
import { z as
|
|
585
|
-
var
|
|
696
|
+
import { z as z10 } from "zod";
|
|
697
|
+
var toolInfo10 = {
|
|
586
698
|
name: "remove_file",
|
|
587
699
|
description: "Request to remove a file at the specified path.",
|
|
588
|
-
parameters:
|
|
589
|
-
path:
|
|
700
|
+
parameters: z10.object({
|
|
701
|
+
path: z10.string().describe("The path of the file to remove").meta({ usageValue: "File path here" })
|
|
590
702
|
}).meta({
|
|
591
703
|
examples: [
|
|
592
704
|
{
|
|
@@ -599,44 +711,53 @@ var toolInfo9 = {
|
|
|
599
711
|
}),
|
|
600
712
|
permissionLevel: 2 /* Write */
|
|
601
713
|
};
|
|
602
|
-
var
|
|
714
|
+
var handler10 = async (provider, args) => {
|
|
603
715
|
if (!provider.removeFile) {
|
|
604
716
|
return {
|
|
605
717
|
type: "Error" /* Error */,
|
|
606
|
-
message:
|
|
718
|
+
message: {
|
|
719
|
+
type: "error-text",
|
|
720
|
+
value: "Not possible to remove file."
|
|
721
|
+
}
|
|
607
722
|
};
|
|
608
723
|
}
|
|
609
|
-
const parsed =
|
|
724
|
+
const parsed = toolInfo10.parameters.safeParse(args);
|
|
610
725
|
if (!parsed.success) {
|
|
611
726
|
return {
|
|
612
727
|
type: "Invalid" /* Invalid */,
|
|
613
|
-
message:
|
|
728
|
+
message: {
|
|
729
|
+
type: "error-text",
|
|
730
|
+
value: `Invalid arguments for remove_file: ${parsed.error.message}`
|
|
731
|
+
}
|
|
614
732
|
};
|
|
615
733
|
}
|
|
616
734
|
const { path } = parsed.data;
|
|
617
735
|
await provider.removeFile(path);
|
|
618
736
|
return {
|
|
619
737
|
type: "Reply" /* Reply */,
|
|
620
|
-
message:
|
|
738
|
+
message: {
|
|
739
|
+
type: "text",
|
|
740
|
+
value: `<remove_file_path>${path}</remove_file_path><status>Success</status>`
|
|
741
|
+
}
|
|
621
742
|
};
|
|
622
743
|
};
|
|
623
|
-
var
|
|
744
|
+
var isAvailable10 = (provider) => {
|
|
624
745
|
return !!provider.removeFile;
|
|
625
746
|
};
|
|
626
747
|
var removeFile_default = {
|
|
627
|
-
...
|
|
628
|
-
handler:
|
|
629
|
-
isAvailable:
|
|
748
|
+
...toolInfo10,
|
|
749
|
+
handler: handler10,
|
|
750
|
+
isAvailable: isAvailable10
|
|
630
751
|
};
|
|
631
752
|
|
|
632
753
|
// src/tools/renameFile.ts
|
|
633
|
-
import { z as
|
|
634
|
-
var
|
|
754
|
+
import { z as z11 } from "zod";
|
|
755
|
+
var toolInfo11 = {
|
|
635
756
|
name: "rename_file",
|
|
636
757
|
description: "Request to rename a file from source path to target path.",
|
|
637
|
-
parameters:
|
|
638
|
-
source_path:
|
|
639
|
-
target_path:
|
|
758
|
+
parameters: z11.object({
|
|
759
|
+
source_path: z11.string().describe("The current path of the file").meta({ usageValue: "Source file path here" }),
|
|
760
|
+
target_path: z11.string().describe("The new path for the file").meta({ usageValue: "Target file path here" })
|
|
640
761
|
}).meta({
|
|
641
762
|
examples: [
|
|
642
763
|
{
|
|
@@ -650,31 +771,37 @@ var toolInfo10 = {
|
|
|
650
771
|
}),
|
|
651
772
|
permissionLevel: 2 /* Write */
|
|
652
773
|
};
|
|
653
|
-
var
|
|
774
|
+
var handler11 = async (provider, args) => {
|
|
654
775
|
if (!provider.renameFile) {
|
|
655
776
|
return {
|
|
656
777
|
type: "Error" /* Error */,
|
|
657
|
-
message:
|
|
778
|
+
message: {
|
|
779
|
+
type: "error-text",
|
|
780
|
+
value: "Not possible to rename file."
|
|
781
|
+
}
|
|
658
782
|
};
|
|
659
783
|
}
|
|
660
|
-
const { source_path, target_path } =
|
|
784
|
+
const { source_path, target_path } = toolInfo11.parameters.parse(args);
|
|
661
785
|
await provider.renameFile(source_path, target_path);
|
|
662
786
|
return {
|
|
663
787
|
type: "Reply" /* Reply */,
|
|
664
|
-
message:
|
|
788
|
+
message: {
|
|
789
|
+
type: "text",
|
|
790
|
+
value: `<rename_file_path>${target_path}</rename_file_path><status>Success</status>`
|
|
791
|
+
}
|
|
665
792
|
};
|
|
666
793
|
};
|
|
667
|
-
var
|
|
794
|
+
var isAvailable11 = (provider) => {
|
|
668
795
|
return !!provider.renameFile;
|
|
669
796
|
};
|
|
670
797
|
var renameFile_default = {
|
|
671
|
-
...
|
|
672
|
-
handler:
|
|
673
|
-
isAvailable:
|
|
798
|
+
...toolInfo11,
|
|
799
|
+
handler: handler11,
|
|
800
|
+
isAvailable: isAvailable11
|
|
674
801
|
};
|
|
675
802
|
|
|
676
803
|
// src/tools/replaceInFile.ts
|
|
677
|
-
import { z as
|
|
804
|
+
import { z as z12 } from "zod";
|
|
678
805
|
|
|
679
806
|
// src/tools/utils/replaceInFile.ts
|
|
680
807
|
var replaceInFile = (fileContent, diff) => {
|
|
@@ -751,12 +878,12 @@ var replaceInFile = (fileContent, diff) => {
|
|
|
751
878
|
};
|
|
752
879
|
|
|
753
880
|
// src/tools/replaceInFile.ts
|
|
754
|
-
var
|
|
881
|
+
var toolInfo12 = {
|
|
755
882
|
name: "replace_in_file",
|
|
756
883
|
description: "Request to replace sections of content in an existing file using SEARCH/REPLACE blocks that define exact changes to specific parts of the file. This tool should be used when you need to make targeted changes to specific parts of a file.",
|
|
757
|
-
parameters:
|
|
758
|
-
path:
|
|
759
|
-
diff:
|
|
884
|
+
parameters: z12.object({
|
|
885
|
+
path: z12.string().describe("The path of the file to modify").meta({ usageValue: "File path here" }),
|
|
886
|
+
diff: z12.string().describe(
|
|
760
887
|
`One or more SEARCH/REPLACE blocks following this exact format:
|
|
761
888
|
\`\`\`
|
|
762
889
|
<<<<<<< SEARCH
|
|
@@ -864,18 +991,24 @@ function oldFeature() {
|
|
|
864
991
|
}),
|
|
865
992
|
permissionLevel: 2 /* Write */
|
|
866
993
|
};
|
|
867
|
-
var
|
|
994
|
+
var handler12 = async (provider, args) => {
|
|
868
995
|
if (!provider.readFile || !provider.writeFile) {
|
|
869
996
|
return {
|
|
870
997
|
type: "Error" /* Error */,
|
|
871
|
-
message:
|
|
998
|
+
message: {
|
|
999
|
+
type: "error-text",
|
|
1000
|
+
value: "Not possible to replace in file."
|
|
1001
|
+
}
|
|
872
1002
|
};
|
|
873
1003
|
}
|
|
874
|
-
const parsed =
|
|
1004
|
+
const parsed = toolInfo12.parameters.safeParse(args);
|
|
875
1005
|
if (!parsed.success) {
|
|
876
1006
|
return {
|
|
877
1007
|
type: "Invalid" /* Invalid */,
|
|
878
|
-
message:
|
|
1008
|
+
message: {
|
|
1009
|
+
type: "error-text",
|
|
1010
|
+
value: `Invalid arguments for replace_in_file: ${parsed.error.message}`
|
|
1011
|
+
}
|
|
879
1012
|
};
|
|
880
1013
|
}
|
|
881
1014
|
const { path, diff } = parsed.data;
|
|
@@ -884,60 +1017,75 @@ var handler11 = async (provider, args) => {
|
|
|
884
1017
|
if (fileContent == null) {
|
|
885
1018
|
return {
|
|
886
1019
|
type: "Error" /* Error */,
|
|
887
|
-
message:
|
|
1020
|
+
message: {
|
|
1021
|
+
type: "error-text",
|
|
1022
|
+
value: `<replace_in_file_result path="${path}" status="failed" message="File not found" />`
|
|
1023
|
+
}
|
|
888
1024
|
};
|
|
889
1025
|
}
|
|
890
1026
|
const result = replaceInFile(fileContent, diff);
|
|
891
1027
|
if (result.status === "no_diff_applied") {
|
|
892
1028
|
return {
|
|
893
1029
|
type: "Error" /* Error */,
|
|
894
|
-
message:
|
|
1030
|
+
message: {
|
|
1031
|
+
type: "error-text",
|
|
1032
|
+
value: `<replace_in_file_result path="${path}" status="failed" message="Unable to apply changes">
|
|
895
1033
|
<file_content path="${path}">${fileContent}</file_content>
|
|
896
1034
|
</replace_in_file_result>`
|
|
1035
|
+
}
|
|
897
1036
|
};
|
|
898
1037
|
}
|
|
899
1038
|
await provider.writeFile(path, result.content);
|
|
900
1039
|
if (result.status === "some_diff_applied") {
|
|
901
1040
|
return {
|
|
902
1041
|
type: "Reply" /* Reply */,
|
|
903
|
-
message:
|
|
1042
|
+
message: {
|
|
1043
|
+
type: "text",
|
|
1044
|
+
value: `<replace_in_file_result path="${path}" status="some_diff_applied" applied_count="${result.appliedCount}" total_count="${result.totalCount}">
|
|
904
1045
|
<file_content path="${path}">${result.content}</file_content>
|
|
905
1046
|
</replace_in_file_result>`
|
|
1047
|
+
}
|
|
906
1048
|
};
|
|
907
1049
|
}
|
|
908
1050
|
return {
|
|
909
1051
|
type: "Reply" /* Reply */,
|
|
910
|
-
message:
|
|
1052
|
+
message: {
|
|
1053
|
+
type: "text",
|
|
1054
|
+
value: `<replace_in_file_result path="${path}" status="all_diff_applied" />`
|
|
1055
|
+
}
|
|
911
1056
|
};
|
|
912
1057
|
} catch (error) {
|
|
913
1058
|
return {
|
|
914
1059
|
type: "Invalid" /* Invalid */,
|
|
915
|
-
message:
|
|
1060
|
+
message: {
|
|
1061
|
+
type: "error-text",
|
|
1062
|
+
value: `Invalid arguments for replace_in_file: ${error}`
|
|
1063
|
+
}
|
|
916
1064
|
};
|
|
917
1065
|
}
|
|
918
1066
|
};
|
|
919
|
-
var
|
|
1067
|
+
var isAvailable12 = (provider) => {
|
|
920
1068
|
return !!provider.readFile && !!provider.writeFile;
|
|
921
1069
|
};
|
|
922
1070
|
var replaceInFile_default = {
|
|
923
|
-
...
|
|
924
|
-
handler:
|
|
925
|
-
isAvailable:
|
|
1071
|
+
...toolInfo12,
|
|
1072
|
+
handler: handler12,
|
|
1073
|
+
isAvailable: isAvailable12
|
|
926
1074
|
};
|
|
927
1075
|
|
|
928
1076
|
// src/tools/searchFiles.ts
|
|
929
|
-
import { z as
|
|
930
|
-
var
|
|
1077
|
+
import { z as z13 } from "zod";
|
|
1078
|
+
var toolInfo13 = {
|
|
931
1079
|
name: "search_files",
|
|
932
1080
|
description: "Request to perform a regex search across files in a specified directory, outputting context-rich results that include surrounding lines. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.",
|
|
933
|
-
parameters:
|
|
934
|
-
path:
|
|
1081
|
+
parameters: z13.object({
|
|
1082
|
+
path: z13.string().describe(
|
|
935
1083
|
"The path of the directory to search in (relative to the current working directory). This directory will be recursively searched."
|
|
936
1084
|
).meta({ usageValue: "Directory path here" }),
|
|
937
|
-
regex:
|
|
1085
|
+
regex: z13.string().describe("The regular expression pattern to search for. Uses Rust regex syntax.").meta({
|
|
938
1086
|
usageValue: "Your regex pattern here"
|
|
939
1087
|
}),
|
|
940
|
-
filePattern:
|
|
1088
|
+
filePattern: z13.string().optional().describe(
|
|
941
1089
|
'Comma-separated glob pattern to filter files (e.g., "*.ts" for TypeScript files or "*.ts,*.js" for both TypeScript and JavaScript files). If not provided, it will search all files (*).'
|
|
942
1090
|
).meta({
|
|
943
1091
|
usageValue: "file pattern here (optional)"
|
|
@@ -956,18 +1104,24 @@ var toolInfo12 = {
|
|
|
956
1104
|
}),
|
|
957
1105
|
permissionLevel: 1 /* Read */
|
|
958
1106
|
};
|
|
959
|
-
var
|
|
1107
|
+
var handler13 = async (provider, args) => {
|
|
960
1108
|
if (!provider.searchFiles) {
|
|
961
1109
|
return {
|
|
962
1110
|
type: "Error" /* Error */,
|
|
963
|
-
message:
|
|
1111
|
+
message: {
|
|
1112
|
+
type: "error-text",
|
|
1113
|
+
value: "Not possible to search files."
|
|
1114
|
+
}
|
|
964
1115
|
};
|
|
965
1116
|
}
|
|
966
|
-
const parsed =
|
|
1117
|
+
const parsed = toolInfo13.parameters.safeParse(args);
|
|
967
1118
|
if (!parsed.success) {
|
|
968
1119
|
return {
|
|
969
1120
|
type: "Invalid" /* Invalid */,
|
|
970
|
-
message:
|
|
1121
|
+
message: {
|
|
1122
|
+
type: "error-text",
|
|
1123
|
+
value: `Invalid arguments for search_files: ${parsed.error.message}`
|
|
1124
|
+
}
|
|
971
1125
|
};
|
|
972
1126
|
}
|
|
973
1127
|
const { path, regex, filePattern } = parsed.data;
|
|
@@ -975,38 +1129,44 @@ var handler12 = async (provider, args) => {
|
|
|
975
1129
|
const files = await provider.searchFiles(path, regex, filePattern ?? "*");
|
|
976
1130
|
return {
|
|
977
1131
|
type: "Reply" /* Reply */,
|
|
978
|
-
message:
|
|
1132
|
+
message: {
|
|
1133
|
+
type: "text",
|
|
1134
|
+
value: `<search_files_path>${path}</search_files_path>
|
|
979
1135
|
<search_files_regex>${regex}</search_files_regex>
|
|
980
1136
|
<search_files_file_pattern>${filePattern}</search_files_file_pattern>
|
|
981
1137
|
<search_files_files>
|
|
982
1138
|
${files.join("\n")}
|
|
983
1139
|
</search_files_files>
|
|
984
1140
|
`
|
|
1141
|
+
}
|
|
985
1142
|
};
|
|
986
1143
|
} catch (error) {
|
|
987
1144
|
return {
|
|
988
1145
|
type: "Error" /* Error */,
|
|
989
|
-
message:
|
|
1146
|
+
message: {
|
|
1147
|
+
type: "error-text",
|
|
1148
|
+
value: `Error searching files: ${error}`
|
|
1149
|
+
}
|
|
990
1150
|
};
|
|
991
1151
|
}
|
|
992
1152
|
};
|
|
993
|
-
var
|
|
1153
|
+
var isAvailable13 = (provider) => {
|
|
994
1154
|
return !!provider.searchFiles;
|
|
995
1155
|
};
|
|
996
1156
|
var searchFiles_default = {
|
|
997
|
-
...
|
|
998
|
-
handler:
|
|
999
|
-
isAvailable:
|
|
1157
|
+
...toolInfo13,
|
|
1158
|
+
handler: handler13,
|
|
1159
|
+
isAvailable: isAvailable13
|
|
1000
1160
|
};
|
|
1001
1161
|
|
|
1002
1162
|
// src/tools/writeToFile.ts
|
|
1003
|
-
import { z as
|
|
1004
|
-
var
|
|
1163
|
+
import { z as z14 } from "zod";
|
|
1164
|
+
var toolInfo14 = {
|
|
1005
1165
|
name: "write_to_file",
|
|
1006
1166
|
description: "Request to write content to a file at the specified path. If the file exists, it will be overwritten with the provided content. If the file doesn't exist, it will be created. This tool will automatically create any directories needed to write the file. Ensure that the output content does not include incorrect escaped character patterns such as `<`, `>`, or `&`. Also ensure there is no unwanted CDATA tags in the content.",
|
|
1007
|
-
parameters:
|
|
1008
|
-
path:
|
|
1009
|
-
content:
|
|
1167
|
+
parameters: z14.object({
|
|
1168
|
+
path: z14.string().describe("The path of the file to write to").meta({ usageValue: "File path here" }),
|
|
1169
|
+
content: z14.string().describe(
|
|
1010
1170
|
"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."
|
|
1011
1171
|
).meta({ usageValue: "Your file content here" })
|
|
1012
1172
|
}).meta({
|
|
@@ -1033,18 +1193,24 @@ export default App;
|
|
|
1033
1193
|
}),
|
|
1034
1194
|
permissionLevel: 2 /* Write */
|
|
1035
1195
|
};
|
|
1036
|
-
var
|
|
1196
|
+
var handler14 = async (provider, args) => {
|
|
1037
1197
|
if (!provider.writeFile) {
|
|
1038
1198
|
return {
|
|
1039
1199
|
type: "Error" /* Error */,
|
|
1040
|
-
message:
|
|
1200
|
+
message: {
|
|
1201
|
+
type: "error-text",
|
|
1202
|
+
value: "Not possible to write file."
|
|
1203
|
+
}
|
|
1041
1204
|
};
|
|
1042
1205
|
}
|
|
1043
|
-
const parsed =
|
|
1206
|
+
const parsed = toolInfo14.parameters.safeParse(args);
|
|
1044
1207
|
if (!parsed.success) {
|
|
1045
1208
|
return {
|
|
1046
1209
|
type: "Invalid" /* Invalid */,
|
|
1047
|
-
message:
|
|
1210
|
+
message: {
|
|
1211
|
+
type: "error-text",
|
|
1212
|
+
value: `Invalid arguments for write_to_file: ${parsed.error.message}`
|
|
1213
|
+
}
|
|
1048
1214
|
};
|
|
1049
1215
|
}
|
|
1050
1216
|
let { path, content } = parsed.data;
|
|
@@ -1053,16 +1219,19 @@ var handler13 = async (provider, args) => {
|
|
|
1053
1219
|
await provider.writeFile(path, content);
|
|
1054
1220
|
return {
|
|
1055
1221
|
type: "Reply" /* Reply */,
|
|
1056
|
-
message:
|
|
1222
|
+
message: {
|
|
1223
|
+
type: "text",
|
|
1224
|
+
value: `<write_to_file_path>${path}</write_to_file_path><status>Success</status>`
|
|
1225
|
+
}
|
|
1057
1226
|
};
|
|
1058
1227
|
};
|
|
1059
|
-
var
|
|
1228
|
+
var isAvailable14 = (provider) => {
|
|
1060
1229
|
return !!provider.writeFile;
|
|
1061
1230
|
};
|
|
1062
1231
|
var writeToFile_default = {
|
|
1063
|
-
...
|
|
1064
|
-
handler:
|
|
1065
|
-
isAvailable:
|
|
1232
|
+
...toolInfo14,
|
|
1233
|
+
handler: handler14,
|
|
1234
|
+
isAvailable: isAvailable14
|
|
1066
1235
|
};
|
|
1067
1236
|
|
|
1068
1237
|
// src/tools/provider.ts
|
|
@@ -1271,7 +1440,7 @@ import { camelCase } from "lodash";
|
|
|
1271
1440
|
import { toJSONSchema } from "zod";
|
|
1272
1441
|
|
|
1273
1442
|
// src/tool-v1-compat.ts
|
|
1274
|
-
import { z as
|
|
1443
|
+
import { z as z15 } from "zod";
|
|
1275
1444
|
function zodSchemaToParameters(schema) {
|
|
1276
1445
|
const parameters = [];
|
|
1277
1446
|
const { shape } = schema;
|
|
@@ -1288,12 +1457,12 @@ function zodSchemaToParameters(schema) {
|
|
|
1288
1457
|
if (usageValue) {
|
|
1289
1458
|
param.usageValue = usageValue;
|
|
1290
1459
|
}
|
|
1291
|
-
if (def instanceof
|
|
1460
|
+
if (def instanceof z15.ZodObject) {
|
|
1292
1461
|
param.children = zodSchemaToParameters(def);
|
|
1293
|
-
} else if (def instanceof
|
|
1462
|
+
} else if (def instanceof z15.ZodArray) {
|
|
1294
1463
|
param.allowMultiple = true;
|
|
1295
1464
|
const element = def.element;
|
|
1296
|
-
if (element instanceof
|
|
1465
|
+
if (element instanceof z15.ZodObject) {
|
|
1297
1466
|
param.children = zodSchemaToParameters(element);
|
|
1298
1467
|
}
|
|
1299
1468
|
}
|
|
@@ -1660,25 +1829,64 @@ Avoid unnecessary escape characters or special characters.
|
|
|
1660
1829
|
requireUseToolNative: `Error: No tool use detected. You MUST use a tool before proceeding.
|
|
1661
1830
|
`,
|
|
1662
1831
|
toolResults: (tool, result) => {
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1832
|
+
switch (result.type) {
|
|
1833
|
+
case "text":
|
|
1834
|
+
return [
|
|
1835
|
+
{
|
|
1836
|
+
type: "text",
|
|
1837
|
+
text: `<tool_response name=${tool}>${result.value}</tool_response>`
|
|
1838
|
+
}
|
|
1839
|
+
];
|
|
1840
|
+
case "error-text":
|
|
1841
|
+
return [
|
|
1842
|
+
{
|
|
1843
|
+
type: "text",
|
|
1844
|
+
text: `<tool_response_error name=${tool}>${result.value}</tool_response_error>`
|
|
1845
|
+
}
|
|
1846
|
+
];
|
|
1847
|
+
case "json":
|
|
1848
|
+
return [
|
|
1849
|
+
{
|
|
1850
|
+
type: "text",
|
|
1851
|
+
text: `<tool_response_json name=${tool}>${JSON.stringify(result.value)}</tool_response_json>`
|
|
1852
|
+
}
|
|
1853
|
+
];
|
|
1854
|
+
case "error-json":
|
|
1855
|
+
return [
|
|
1856
|
+
{
|
|
1857
|
+
type: "text",
|
|
1858
|
+
text: `<tool_response_error_json name=${tool}>${JSON.stringify(result.value)}</tool_response_error_json>`
|
|
1859
|
+
}
|
|
1860
|
+
];
|
|
1861
|
+
case "content":
|
|
1862
|
+
return [
|
|
1863
|
+
{
|
|
1864
|
+
type: "text",
|
|
1865
|
+
text: `<tool_response name=${tool}>`
|
|
1866
|
+
},
|
|
1867
|
+
...result.value.map((part) => {
|
|
1868
|
+
if (part.type === "text") {
|
|
1869
|
+
return part;
|
|
1870
|
+
}
|
|
1871
|
+
if (part.mediaType.startsWith("image/")) {
|
|
1872
|
+
return {
|
|
1873
|
+
type: "image",
|
|
1874
|
+
mediaType: part.mediaType,
|
|
1875
|
+
image: part.data
|
|
1876
|
+
};
|
|
1877
|
+
}
|
|
1878
|
+
return {
|
|
1879
|
+
type: "file",
|
|
1880
|
+
mediaType: part.mediaType,
|
|
1881
|
+
data: part.data
|
|
1882
|
+
};
|
|
1883
|
+
}),
|
|
1884
|
+
{
|
|
1885
|
+
type: "text",
|
|
1886
|
+
text: "</tool_response>"
|
|
1887
|
+
}
|
|
1888
|
+
];
|
|
1670
1889
|
}
|
|
1671
|
-
return [
|
|
1672
|
-
{
|
|
1673
|
-
type: "text",
|
|
1674
|
-
text: `<tool_response name=${tool}>`
|
|
1675
|
-
},
|
|
1676
|
-
...result,
|
|
1677
|
-
{
|
|
1678
|
-
type: "text",
|
|
1679
|
-
text: "</tool_response>"
|
|
1680
|
-
}
|
|
1681
|
-
];
|
|
1682
1890
|
},
|
|
1683
1891
|
commandResult: (command, exitCode, stdout, stderr) => `<command>${command}</command>
|
|
1684
1892
|
<command_exit_code>${exitCode}</command_exit_code>
|
|
@@ -1794,19 +2002,23 @@ ${instance.prompt}`;
|
|
|
1794
2002
|
if (this.#messages.length === 0) {
|
|
1795
2003
|
this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
|
|
1796
2004
|
}
|
|
1797
|
-
return await this.#request(
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
2005
|
+
return await this.#request([
|
|
2006
|
+
{
|
|
2007
|
+
role: "user",
|
|
2008
|
+
content: prompt6
|
|
2009
|
+
}
|
|
2010
|
+
]);
|
|
1801
2011
|
}
|
|
1802
2012
|
async handleStepResponse(response) {
|
|
1803
2013
|
return this.#handleResponse(response);
|
|
1804
2014
|
}
|
|
1805
2015
|
async #processLoop(userMessage) {
|
|
1806
|
-
let nextRequest =
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
2016
|
+
let nextRequest = [
|
|
2017
|
+
{
|
|
2018
|
+
role: "user",
|
|
2019
|
+
content: userMessage
|
|
2020
|
+
}
|
|
2021
|
+
];
|
|
1810
2022
|
while (true) {
|
|
1811
2023
|
if (this.#aborted) {
|
|
1812
2024
|
return { type: "Aborted" };
|
|
@@ -1835,7 +2047,7 @@ ${instance.prompt}`;
|
|
|
1835
2047
|
throw new Error("userMessage is missing");
|
|
1836
2048
|
}
|
|
1837
2049
|
await this.#callback({ kind: "StartRequest" /* StartRequest */, agent: this, userMessage });
|
|
1838
|
-
this.#messages.push(userMessage);
|
|
2050
|
+
this.#messages.push(...userMessage);
|
|
1839
2051
|
for (const instance of this.#policies) {
|
|
1840
2052
|
if (instance.onBeforeRequest) {
|
|
1841
2053
|
await instance.onBeforeRequest(this);
|
|
@@ -2004,6 +2216,25 @@ Retrying request ${i + 2} of ${retryCount}`);
|
|
|
2004
2216
|
}
|
|
2005
2217
|
async #handleResponse(response) {
|
|
2006
2218
|
const toolResponses = [];
|
|
2219
|
+
const medias = [];
|
|
2220
|
+
const processResponse = (resp) => {
|
|
2221
|
+
if (resp.type === "content") {
|
|
2222
|
+
return {
|
|
2223
|
+
type: "content",
|
|
2224
|
+
value: resp.value.map((part) => {
|
|
2225
|
+
if (part.type === "media") {
|
|
2226
|
+
medias.push(part);
|
|
2227
|
+
return {
|
|
2228
|
+
type: "text",
|
|
2229
|
+
text: `<media url="${part.url}" media-type="${part.mediaType}" />`
|
|
2230
|
+
};
|
|
2231
|
+
}
|
|
2232
|
+
return part;
|
|
2233
|
+
})
|
|
2234
|
+
};
|
|
2235
|
+
}
|
|
2236
|
+
return resp;
|
|
2237
|
+
};
|
|
2007
2238
|
let hasPause = false;
|
|
2008
2239
|
outer: for (const content of response) {
|
|
2009
2240
|
switch (content.type) {
|
|
@@ -2015,7 +2246,7 @@ Retrying request ${i + 2} of ${retryCount}`);
|
|
|
2015
2246
|
switch (toolResp.type) {
|
|
2016
2247
|
case "Reply" /* Reply */: {
|
|
2017
2248
|
await this.#callback({ kind: "ToolReply" /* ToolReply */, agent: this, tool: content.name, content: toolResp.message });
|
|
2018
|
-
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message, id: content.id });
|
|
2249
|
+
toolResponses.push({ type: "response", tool: content.name, response: processResponse(toolResp.message), id: content.id });
|
|
2019
2250
|
break;
|
|
2020
2251
|
}
|
|
2021
2252
|
case "Exit" /* Exit */:
|
|
@@ -2025,12 +2256,12 @@ Retrying request ${i + 2} of ${retryCount}`);
|
|
|
2025
2256
|
return { type: "exit", reason: toolResp };
|
|
2026
2257
|
case "Invalid" /* Invalid */: {
|
|
2027
2258
|
await this.#callback({ kind: "ToolInvalid" /* ToolInvalid */, agent: this, tool: content.name, content: toolResp.message });
|
|
2028
|
-
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message, id: content.id });
|
|
2259
|
+
toolResponses.push({ type: "response", tool: content.name, response: processResponse(toolResp.message), id: content.id });
|
|
2029
2260
|
break outer;
|
|
2030
2261
|
}
|
|
2031
2262
|
case "Error" /* Error */: {
|
|
2032
2263
|
await this.#callback({ kind: "ToolError" /* ToolError */, agent: this, tool: content.name, content: toolResp.message });
|
|
2033
|
-
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message, id: content.id });
|
|
2264
|
+
toolResponses.push({ type: "response", tool: content.name, response: processResponse(toolResp.message), id: content.id });
|
|
2034
2265
|
break outer;
|
|
2035
2266
|
}
|
|
2036
2267
|
case "Interrupted" /* Interrupted */:
|
|
@@ -2082,57 +2313,87 @@ Retrying request ${i + 2} of ${retryCount}`);
|
|
|
2082
2313
|
if (toolResponses.length === 0) {
|
|
2083
2314
|
return {
|
|
2084
2315
|
type: "reply",
|
|
2085
|
-
message:
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2316
|
+
message: [
|
|
2317
|
+
{
|
|
2318
|
+
role: "user",
|
|
2319
|
+
content: responsePrompts.requireUseToolNative
|
|
2320
|
+
}
|
|
2321
|
+
]
|
|
2089
2322
|
};
|
|
2090
2323
|
}
|
|
2324
|
+
const mediaUserMessage = medias.length > 0 ? [
|
|
2325
|
+
{
|
|
2326
|
+
role: "user",
|
|
2327
|
+
content: medias.map((m) => {
|
|
2328
|
+
if (m.mediaType.startsWith("image/")) {
|
|
2329
|
+
return {
|
|
2330
|
+
type: "image",
|
|
2331
|
+
image: m.base64Data,
|
|
2332
|
+
mediaType: m.mediaType
|
|
2333
|
+
};
|
|
2334
|
+
}
|
|
2335
|
+
return {
|
|
2336
|
+
type: "file",
|
|
2337
|
+
data: m.base64Data,
|
|
2338
|
+
mediaType: m.mediaType,
|
|
2339
|
+
filename: m.url.split("/").pop()
|
|
2340
|
+
};
|
|
2341
|
+
})
|
|
2342
|
+
}
|
|
2343
|
+
] : [];
|
|
2091
2344
|
if (this.config.toolFormat === "native") {
|
|
2092
2345
|
const toolResults = toolResponses.filter((resp) => resp.type === "response").map(
|
|
2093
2346
|
(resp) => ({
|
|
2094
2347
|
type: "tool-result",
|
|
2095
2348
|
toolCallId: resp.id,
|
|
2096
2349
|
toolName: resp.tool,
|
|
2097
|
-
output:
|
|
2098
|
-
type: "text",
|
|
2099
|
-
value: resp.response
|
|
2100
|
-
}
|
|
2350
|
+
output: resp.response
|
|
2101
2351
|
})
|
|
2102
2352
|
);
|
|
2103
2353
|
return {
|
|
2104
2354
|
type: "reply",
|
|
2105
|
-
message:
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2355
|
+
message: [
|
|
2356
|
+
{
|
|
2357
|
+
role: "tool",
|
|
2358
|
+
content: toolResults
|
|
2359
|
+
},
|
|
2360
|
+
...mediaUserMessage
|
|
2361
|
+
]
|
|
2109
2362
|
};
|
|
2110
2363
|
}
|
|
2111
2364
|
if (toolResponses.length === 0) {
|
|
2112
2365
|
return {
|
|
2113
2366
|
type: "reply",
|
|
2114
|
-
message:
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2367
|
+
message: [
|
|
2368
|
+
{
|
|
2369
|
+
role: "user",
|
|
2370
|
+
content: responsePrompts.requireUseTool
|
|
2371
|
+
}
|
|
2372
|
+
]
|
|
2118
2373
|
};
|
|
2119
2374
|
}
|
|
2120
2375
|
const finalResp = toolResponses.filter((resp) => resp.type === "response").flatMap(({ tool, response: response2 }) => responsePrompts.toolResults(tool, response2));
|
|
2121
2376
|
return {
|
|
2122
2377
|
type: "reply",
|
|
2123
|
-
message:
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2378
|
+
message: [
|
|
2379
|
+
{
|
|
2380
|
+
role: "user",
|
|
2381
|
+
content: finalResp
|
|
2382
|
+
},
|
|
2383
|
+
...mediaUserMessage
|
|
2384
|
+
]
|
|
2127
2385
|
};
|
|
2128
2386
|
}
|
|
2129
2387
|
async #invokeTool(name, args) {
|
|
2130
2388
|
try {
|
|
2131
|
-
const
|
|
2132
|
-
if (!
|
|
2389
|
+
const handler16 = this.handlers[name]?.handler;
|
|
2390
|
+
if (!handler16) {
|
|
2133
2391
|
return {
|
|
2134
2392
|
type: "Error" /* Error */,
|
|
2135
|
-
message:
|
|
2393
|
+
message: {
|
|
2394
|
+
type: "error-text",
|
|
2395
|
+
value: responsePrompts.errorInvokeTool(name, "Tool not found")
|
|
2396
|
+
},
|
|
2136
2397
|
canRetry: false
|
|
2137
2398
|
};
|
|
2138
2399
|
}
|
|
@@ -2148,11 +2409,14 @@ Retrying request ${i + 2} of ${retryCount}`);
|
|
|
2148
2409
|
if (resp) {
|
|
2149
2410
|
return resp;
|
|
2150
2411
|
}
|
|
2151
|
-
return await
|
|
2412
|
+
return await handler16(this.config.provider, args);
|
|
2152
2413
|
} catch (error) {
|
|
2153
2414
|
return {
|
|
2154
2415
|
type: "Error" /* Error */,
|
|
2155
|
-
message:
|
|
2416
|
+
message: {
|
|
2417
|
+
type: "error-text",
|
|
2418
|
+
value: responsePrompts.errorInvokeTool(name, error)
|
|
2419
|
+
},
|
|
2156
2420
|
canRetry: false
|
|
2157
2421
|
};
|
|
2158
2422
|
}
|
|
@@ -2480,7 +2744,10 @@ var CodeFixerAgent = class extends AgentBase {
|
|
|
2480
2744
|
if (exitCode !== 0) {
|
|
2481
2745
|
return {
|
|
2482
2746
|
type: "Reply" /* Reply */,
|
|
2483
|
-
message:
|
|
2747
|
+
message: {
|
|
2748
|
+
type: "error-text",
|
|
2749
|
+
value: responsePrompts.commandResult(checkCommand, exitCode, stdout, stderr)
|
|
2750
|
+
}
|
|
2484
2751
|
};
|
|
2485
2752
|
}
|
|
2486
2753
|
} catch (error) {
|
|
@@ -2495,7 +2762,10 @@ var CodeFixerAgent = class extends AgentBase {
|
|
|
2495
2762
|
if (exitCode !== 0) {
|
|
2496
2763
|
return {
|
|
2497
2764
|
type: "Reply" /* Reply */,
|
|
2498
|
-
message:
|
|
2765
|
+
message: {
|
|
2766
|
+
type: "error-text",
|
|
2767
|
+
value: responsePrompts.commandResult(testCommand, exitCode, stdout, stderr)
|
|
2768
|
+
}
|
|
2499
2769
|
};
|
|
2500
2770
|
}
|
|
2501
2771
|
} catch (error) {
|
|
@@ -2680,7 +2950,10 @@ var CoderAgent = class extends AgentBase {
|
|
|
2680
2950
|
if (exitCode !== 0 && shouldReplyWithError) {
|
|
2681
2951
|
return {
|
|
2682
2952
|
type: "Reply" /* Reply */,
|
|
2683
|
-
message:
|
|
2953
|
+
message: {
|
|
2954
|
+
type: "error-text",
|
|
2955
|
+
value: responsePrompts.commandResult(command, exitCode, stdout, stderr)
|
|
2956
|
+
}
|
|
2684
2957
|
};
|
|
2685
2958
|
}
|
|
2686
2959
|
} catch (error) {
|
|
@@ -2797,73 +3070,73 @@ var MultiAgent = class {
|
|
|
2797
3070
|
};
|
|
2798
3071
|
|
|
2799
3072
|
// src/config.ts
|
|
2800
|
-
import { z as
|
|
2801
|
-
var toolFormatSchema =
|
|
2802
|
-
var providerModelSchema =
|
|
2803
|
-
provider:
|
|
2804
|
-
model:
|
|
2805
|
-
parameters:
|
|
3073
|
+
import { z as z16 } from "zod";
|
|
3074
|
+
var toolFormatSchema = z16.enum(["native", "polka-codes"]).optional();
|
|
3075
|
+
var providerModelSchema = z16.object({
|
|
3076
|
+
provider: z16.string().optional(),
|
|
3077
|
+
model: z16.string().optional(),
|
|
3078
|
+
parameters: z16.record(z16.string(), z16.any()).optional(),
|
|
2806
3079
|
toolFormat: toolFormatSchema
|
|
2807
3080
|
});
|
|
2808
3081
|
var agentSchema = providerModelSchema.extend({
|
|
2809
|
-
initialContext:
|
|
2810
|
-
maxFileCount:
|
|
2811
|
-
excludes:
|
|
3082
|
+
initialContext: z16.object({
|
|
3083
|
+
maxFileCount: z16.number().int().positive().optional(),
|
|
3084
|
+
excludes: z16.array(z16.string()).optional()
|
|
2812
3085
|
}).optional(),
|
|
2813
|
-
retryCount:
|
|
2814
|
-
requestTimeoutSeconds:
|
|
3086
|
+
retryCount: z16.number().int().min(0).optional(),
|
|
3087
|
+
requestTimeoutSeconds: z16.number().int().positive().optional()
|
|
2815
3088
|
});
|
|
2816
|
-
var configSchema =
|
|
2817
|
-
agent:
|
|
2818
|
-
prices:
|
|
2819
|
-
|
|
3089
|
+
var configSchema = z16.object({
|
|
3090
|
+
agent: z16.string().optional(),
|
|
3091
|
+
prices: z16.record(
|
|
3092
|
+
z16.string(),
|
|
2820
3093
|
// provider
|
|
2821
|
-
|
|
2822
|
-
|
|
3094
|
+
z16.record(
|
|
3095
|
+
z16.string(),
|
|
2823
3096
|
// model
|
|
2824
|
-
|
|
2825
|
-
inputPrice:
|
|
2826
|
-
outputPrice:
|
|
2827
|
-
cacheWritesPrice:
|
|
2828
|
-
cacheReadsPrice:
|
|
3097
|
+
z16.object({
|
|
3098
|
+
inputPrice: z16.number().optional(),
|
|
3099
|
+
outputPrice: z16.number().optional(),
|
|
3100
|
+
cacheWritesPrice: z16.number().optional(),
|
|
3101
|
+
cacheReadsPrice: z16.number().optional()
|
|
2829
3102
|
})
|
|
2830
3103
|
)
|
|
2831
3104
|
).optional(),
|
|
2832
|
-
providers:
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
apiKey:
|
|
2836
|
-
defaultModel:
|
|
2837
|
-
defaultParameters:
|
|
2838
|
-
location:
|
|
2839
|
-
project:
|
|
2840
|
-
keyFile:
|
|
3105
|
+
providers: z16.record(
|
|
3106
|
+
z16.string(),
|
|
3107
|
+
z16.object({
|
|
3108
|
+
apiKey: z16.string().optional(),
|
|
3109
|
+
defaultModel: z16.string().optional(),
|
|
3110
|
+
defaultParameters: z16.record(z16.string(), z16.any()).optional(),
|
|
3111
|
+
location: z16.string().optional(),
|
|
3112
|
+
project: z16.string().optional(),
|
|
3113
|
+
keyFile: z16.string().optional()
|
|
2841
3114
|
})
|
|
2842
3115
|
).optional(),
|
|
2843
|
-
defaultProvider:
|
|
2844
|
-
defaultModel:
|
|
2845
|
-
defaultParameters:
|
|
3116
|
+
defaultProvider: z16.string().optional(),
|
|
3117
|
+
defaultModel: z16.string().optional(),
|
|
3118
|
+
defaultParameters: z16.record(z16.string(), z16.any()).optional(),
|
|
2846
3119
|
toolFormat: toolFormatSchema,
|
|
2847
|
-
maxMessageCount:
|
|
2848
|
-
budget:
|
|
2849
|
-
retryCount:
|
|
2850
|
-
requestTimeoutSeconds:
|
|
2851
|
-
scripts:
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
command:
|
|
2856
|
-
description:
|
|
3120
|
+
maxMessageCount: z16.number().int().positive().optional(),
|
|
3121
|
+
budget: z16.number().positive().optional(),
|
|
3122
|
+
retryCount: z16.number().int().min(0).optional(),
|
|
3123
|
+
requestTimeoutSeconds: z16.number().int().positive().optional(),
|
|
3124
|
+
scripts: z16.record(
|
|
3125
|
+
z16.string(),
|
|
3126
|
+
z16.string().or(
|
|
3127
|
+
z16.object({
|
|
3128
|
+
command: z16.string(),
|
|
3129
|
+
description: z16.string()
|
|
2857
3130
|
})
|
|
2858
3131
|
)
|
|
2859
3132
|
).optional(),
|
|
2860
|
-
agents:
|
|
2861
|
-
commands:
|
|
3133
|
+
agents: z16.record(z16.string(), agentSchema).optional(),
|
|
3134
|
+
commands: z16.object({
|
|
2862
3135
|
default: providerModelSchema.optional()
|
|
2863
3136
|
}).catchall(providerModelSchema).optional(),
|
|
2864
|
-
rules:
|
|
2865
|
-
excludeFiles:
|
|
2866
|
-
policies:
|
|
3137
|
+
rules: z16.array(z16.string()).optional().or(z16.string()).optional(),
|
|
3138
|
+
excludeFiles: z16.array(z16.string()).optional(),
|
|
3139
|
+
policies: z16.array(z16.string()).optional()
|
|
2867
3140
|
}).strict();
|
|
2868
3141
|
var Policies = /* @__PURE__ */ ((Policies2) => {
|
|
2869
3142
|
Policies2["TruncateContext"] = "truncatecontext";
|
|
@@ -3362,7 +3635,7 @@ var generateProjectConfig_default = {
|
|
|
3362
3635
|
};
|
|
3363
3636
|
|
|
3364
3637
|
// src/AiTool/tools/gitDiff.ts
|
|
3365
|
-
import { z as
|
|
3638
|
+
import { z as z17 } from "zod";
|
|
3366
3639
|
|
|
3367
3640
|
// src/AiTool/tools/utils/diffLineNumbers.ts
|
|
3368
3641
|
function parseHunkHeader(header) {
|
|
@@ -3420,40 +3693,43 @@ function annotateDiffWithLineNumbers(diff) {
|
|
|
3420
3693
|
}
|
|
3421
3694
|
|
|
3422
3695
|
// src/AiTool/tools/gitDiff.ts
|
|
3423
|
-
var
|
|
3696
|
+
var toolInfo15 = {
|
|
3424
3697
|
name: "git_diff",
|
|
3425
3698
|
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.",
|
|
3426
|
-
parameters:
|
|
3427
|
-
staged:
|
|
3699
|
+
parameters: z17.object({
|
|
3700
|
+
staged: z17.preprocess((val) => {
|
|
3428
3701
|
if (typeof val === "string") {
|
|
3429
3702
|
const lower = val.toLowerCase();
|
|
3430
3703
|
if (lower === "false") return false;
|
|
3431
3704
|
if (lower === "true") return true;
|
|
3432
3705
|
}
|
|
3433
3706
|
return val;
|
|
3434
|
-
},
|
|
3435
|
-
commitRange:
|
|
3436
|
-
file:
|
|
3437
|
-
contextLines:
|
|
3438
|
-
includeLineNumbers:
|
|
3707
|
+
}, z17.boolean().optional().default(false)).describe("Get staged changes instead of unstaged changes."),
|
|
3708
|
+
commitRange: z17.string().optional().describe('The commit range to get the diff for (e.g., "main...HEAD").'),
|
|
3709
|
+
file: z17.string().optional().describe("Get the diff for a specific file."),
|
|
3710
|
+
contextLines: z17.coerce.number().optional().default(5).describe("Number of context lines to include around changes."),
|
|
3711
|
+
includeLineNumbers: z17.preprocess((val) => {
|
|
3439
3712
|
if (typeof val === "string") {
|
|
3440
3713
|
const lower = val.toLowerCase();
|
|
3441
3714
|
if (lower === "false") return false;
|
|
3442
3715
|
if (lower === "true") return true;
|
|
3443
3716
|
}
|
|
3444
3717
|
return val;
|
|
3445
|
-
},
|
|
3718
|
+
}, z17.boolean().optional().default(false)).describe("Annotate the diff with line numbers for additions and deletions.")
|
|
3446
3719
|
}),
|
|
3447
3720
|
permissionLevel: 1 /* Read */
|
|
3448
3721
|
};
|
|
3449
|
-
var
|
|
3722
|
+
var handler15 = async (provider, args) => {
|
|
3450
3723
|
if (!provider.executeCommand) {
|
|
3451
3724
|
return {
|
|
3452
3725
|
type: "Error" /* Error */,
|
|
3453
|
-
message:
|
|
3726
|
+
message: {
|
|
3727
|
+
type: "error-text",
|
|
3728
|
+
value: "Not possible to execute command. Abort."
|
|
3729
|
+
}
|
|
3454
3730
|
};
|
|
3455
3731
|
}
|
|
3456
|
-
const { staged, file, commitRange, contextLines, includeLineNumbers } =
|
|
3732
|
+
const { staged, file, commitRange, contextLines, includeLineNumbers } = toolInfo15.parameters.parse(args);
|
|
3457
3733
|
const commandParts = ["git", "diff", "--no-color", `-U${contextLines}`];
|
|
3458
3734
|
if (staged) {
|
|
3459
3735
|
commandParts.push("--staged");
|
|
@@ -3471,7 +3747,10 @@ var handler14 = async (provider, args) => {
|
|
|
3471
3747
|
if (!result.stdout.trim()) {
|
|
3472
3748
|
return {
|
|
3473
3749
|
type: "Reply" /* Reply */,
|
|
3474
|
-
message:
|
|
3750
|
+
message: {
|
|
3751
|
+
type: "text",
|
|
3752
|
+
value: "No diff found."
|
|
3753
|
+
}
|
|
3475
3754
|
};
|
|
3476
3755
|
}
|
|
3477
3756
|
let diffOutput = result.stdout;
|
|
@@ -3480,30 +3759,39 @@ var handler14 = async (provider, args) => {
|
|
|
3480
3759
|
}
|
|
3481
3760
|
return {
|
|
3482
3761
|
type: "Reply" /* Reply */,
|
|
3483
|
-
message:
|
|
3762
|
+
message: {
|
|
3763
|
+
type: "text",
|
|
3764
|
+
value: `<diff file="${file ?? "all"}">
|
|
3484
3765
|
${diffOutput}
|
|
3485
3766
|
</diff>`
|
|
3767
|
+
}
|
|
3486
3768
|
};
|
|
3487
3769
|
}
|
|
3488
3770
|
return {
|
|
3489
3771
|
type: "Error" /* Error */,
|
|
3490
|
-
message:
|
|
3772
|
+
message: {
|
|
3773
|
+
type: "error-text",
|
|
3774
|
+
value: `\`${command}\` exited with code ${result.exitCode}:
|
|
3491
3775
|
${result.stderr}`
|
|
3776
|
+
}
|
|
3492
3777
|
};
|
|
3493
3778
|
} catch (error) {
|
|
3494
3779
|
return {
|
|
3495
3780
|
type: "Error" /* Error */,
|
|
3496
|
-
message:
|
|
3781
|
+
message: {
|
|
3782
|
+
type: "error-text",
|
|
3783
|
+
value: error instanceof Error ? error.message : String(error)
|
|
3784
|
+
}
|
|
3497
3785
|
};
|
|
3498
3786
|
}
|
|
3499
3787
|
};
|
|
3500
|
-
var
|
|
3788
|
+
var isAvailable15 = (provider) => {
|
|
3501
3789
|
return !!provider.executeCommand;
|
|
3502
3790
|
};
|
|
3503
3791
|
var gitDiff_default = {
|
|
3504
|
-
...
|
|
3505
|
-
handler:
|
|
3506
|
-
isAvailable:
|
|
3792
|
+
...toolInfo15,
|
|
3793
|
+
handler: handler15,
|
|
3794
|
+
isAvailable: isAvailable15
|
|
3507
3795
|
};
|
|
3508
3796
|
|
|
3509
3797
|
// src/AiTool/reviewDiff.ts
|
|
@@ -3734,6 +4022,7 @@ export {
|
|
|
3734
4022
|
makeMultiAgentTool,
|
|
3735
4023
|
makeTool,
|
|
3736
4024
|
parseAssistantMessage,
|
|
4025
|
+
readBinaryFile_default as readBinaryFile,
|
|
3737
4026
|
readFile_default as readFile,
|
|
3738
4027
|
removeFile_default as removeFile,
|
|
3739
4028
|
renameFile_default as renameFile,
|