@calamity-inc/slave 0.3.2 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -15
- package/package.json +4 -3
- package/{index.js → src/core.js} +606 -679
- package/src/log.js +38 -0
- package/src/main.js +231 -0
- package/src/markdown.js +13 -0
- package/src/paths.js +9 -0
- package/src/skills.js +63 -0
- package/src/state.js +33 -0
package/{index.js → src/core.js}
RENAMED
|
@@ -1,679 +1,606 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
fs.
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
return
|
|
209
|
-
},
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
parameters: {
|
|
270
|
-
type: "object",
|
|
271
|
-
properties: {
|
|
272
|
-
path: { type: ["string", "null"] },
|
|
273
|
-
},
|
|
274
|
-
required: [ "path" ],
|
|
275
|
-
additionalProperties: false,
|
|
276
|
-
},
|
|
277
|
-
strict: true,
|
|
278
|
-
},
|
|
279
|
-
{
|
|
280
|
-
type: "function",
|
|
281
|
-
name: "findFiles",
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
};
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
};
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
.
|
|
542
|
-
.
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
}
|
|
608
|
-
process.exit(1);
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
let prompt = program.args.join(" ").trim();
|
|
612
|
-
let previous_provider_state;
|
|
613
|
-
const overrides = [profileToString(profile)];
|
|
614
|
-
state.providerStates[profile.provider] ??= {};
|
|
615
|
-
if (options.continue || options.cont) {
|
|
616
|
-
previous_provider_state = state.providerStates[profile.provider].previous;
|
|
617
|
-
sandbox_name = state.providerStates[profile.provider].sandbox_name;
|
|
618
|
-
}
|
|
619
|
-
else if (options.amend) {
|
|
620
|
-
previous_provider_state = state.providerStates[profile.provider].previous_previous;
|
|
621
|
-
sandbox_name = state.providerStates[profile.provider].sandbox_name;
|
|
622
|
-
}
|
|
623
|
-
const filesystemEnabled = options.fs !== false && !options.nofs;
|
|
624
|
-
initTools(filesystemEnabled, options.sandbox, options.web);
|
|
625
|
-
if (options.web) {
|
|
626
|
-
overrides.push("web search enabled");
|
|
627
|
-
}
|
|
628
|
-
if (!filesystemEnabled) {
|
|
629
|
-
overrides.push("no filesystem access");
|
|
630
|
-
}
|
|
631
|
-
if (options.sandbox) {
|
|
632
|
-
overrides.push("sandbox enabled");
|
|
633
|
-
}
|
|
634
|
-
if (!prompt) {
|
|
635
|
-
console.log("No prompt given.");
|
|
636
|
-
process.exit(1);
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
logWriteBoth((previous_provider_state ? "FOLLOW-UP" : "PROMPT") + ": " + prompt);
|
|
640
|
-
if (!process.stdin.isTTY) {
|
|
641
|
-
const chunks = [];
|
|
642
|
-
for await (const chunk of process.stdin) {
|
|
643
|
-
chunks.push(chunk);
|
|
644
|
-
}
|
|
645
|
-
prompt = `${Buffer.concat(chunks).toString("utf8")}\n\n${prompt}`;
|
|
646
|
-
overrides.push("stdin provided");
|
|
647
|
-
}
|
|
648
|
-
logWriteBoth(`(${overrides.join(", ")})\n`);
|
|
649
|
-
|
|
650
|
-
//console.log({ model: profile.model, prompt, previous_provider_state });
|
|
651
|
-
|
|
652
|
-
const clientOpts = {
|
|
653
|
-
apiKey: state.apiKeys[profile.provider],
|
|
654
|
-
};
|
|
655
|
-
let response;
|
|
656
|
-
if (profile.provider == "anthropic") {
|
|
657
|
-
const client = new Anthropic(clientOpts);
|
|
658
|
-
response = await anthropic_generateResponseOptionallyUsingTools(client, profile.model, prompt, previous_provider_state);
|
|
659
|
-
}
|
|
660
|
-
else {
|
|
661
|
-
if (profile.provider != "openai") {
|
|
662
|
-
clientOpts.baseURL = profile.provider;
|
|
663
|
-
clientOpts.apiKey ||= "dummy";
|
|
664
|
-
}
|
|
665
|
-
const client = new OpenAI(clientOpts);
|
|
666
|
-
response = await openai_generateResponseOptionallyUsingTools(client, profile.model, prompt, previous_provider_state);
|
|
667
|
-
}
|
|
668
|
-
state.providerStates[profile.provider].previous_previous = previous_provider_state;
|
|
669
|
-
state.providerStates[profile.provider].previous = response.state;
|
|
670
|
-
if (state.providerStates[profile.provider].sandbox_name && state.providerStates[profile.provider].sandbox_name != sandbox_name) {
|
|
671
|
-
execFileSync("docker", ["rm", "-f", state.providerStates[profile.provider].sandbox_name], { encoding: "utf8" });
|
|
672
|
-
}
|
|
673
|
-
state.providerStates[profile.provider].sandbox_name = sandbox_name;
|
|
674
|
-
saveState();
|
|
675
|
-
if (response.used_tools) {
|
|
676
|
-
logWriteBoth("");
|
|
677
|
-
}
|
|
678
|
-
console.log(markdownToConsoleText(response.output_text) + "\n");
|
|
679
|
-
logWrite(response.output_text);
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { execFileSync, spawnSync } = require("node:child_process");
|
|
4
|
+
const { randomInt } = require("node:crypto");
|
|
5
|
+
const fs = require("node:fs");
|
|
6
|
+
const path = require("node:path");
|
|
7
|
+
|
|
8
|
+
const chalk = require("chalk").default;
|
|
9
|
+
const ignore = require("ignore");
|
|
10
|
+
|
|
11
|
+
const { logWrite } = require("./log.js");
|
|
12
|
+
const { skills } = require("./skills.js");
|
|
13
|
+
|
|
14
|
+
const slaveignore = ignore();
|
|
15
|
+
if (fs.existsSync(".slaveignore")) {
|
|
16
|
+
slaveignore.add(fs.readFileSync(".slaveignore", "utf8").replaceAll("/\n", "\n"));
|
|
17
|
+
}
|
|
18
|
+
const gitignore = ignore();
|
|
19
|
+
if (fs.existsSync(".gitignore")) {
|
|
20
|
+
gitignore.add(fs.readFileSync(".gitignore", "utf8").replaceAll("/\n", "\n"));
|
|
21
|
+
}
|
|
22
|
+
const isOutOfReach = (p, accessType) => {
|
|
23
|
+
const rel = path.relative(".", p);
|
|
24
|
+
if (rel.startsWith("..") || path.isAbsolute(rel)) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
const segs = rel.split(path.sep);
|
|
28
|
+
if (segs.includes(".git") || segs.some(seg => seg.startsWith(".env"))) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
if (rel && (slaveignore.ignores(rel) || (accessType == "write" && gitignore.ignores(rel)))) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const isPathWithinFolder = (folder, p) => {
|
|
38
|
+
const rel = path.relative(folder, p);
|
|
39
|
+
return !rel.startsWith("..") && !path.isAbsolute(rel);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const fixPath = (path, accessType) => {
|
|
43
|
+
if (path.startsWith("/")) {
|
|
44
|
+
path = path.substring(1);
|
|
45
|
+
path ||= ".";
|
|
46
|
+
}
|
|
47
|
+
return isOutOfReach(path, accessType) ? "" : path;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const readFileForModel = (filePath) => fs.readFileSync(filePath, "utf8").replaceAll("\r\n", "\n");
|
|
51
|
+
const writeFileFromModel = (filePath, data, usesCRLF) => {
|
|
52
|
+
if (fs.existsSync(filePath)) {
|
|
53
|
+
if (usesCRLF === undefined) {
|
|
54
|
+
usesCRLF = fs.readFileSync(filePath, "utf8").includes("\r\n");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
59
|
+
}
|
|
60
|
+
const normalized = data.replaceAll("\r\n", "\n");
|
|
61
|
+
fs.writeFileSync(filePath, usesCRLF ? normalized.replaceAll("\n", "\r\n") : normalized, "utf8");
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const getSystemPrompt = () => {
|
|
65
|
+
const entries = Object.entries(skills);
|
|
66
|
+
if (entries.length == 0) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
return "You have the following skills available:\n" + entries.map(([name, skill]) => `- ${name}: ${skill.description}`).join("\n");
|
|
70
|
+
};
|
|
71
|
+
const getSkillResourcePath = (name, resourcePath) => {
|
|
72
|
+
if (Object.hasOwn(skills, name)) {
|
|
73
|
+
const absResourcePath = path.join(skills[name].path, resourcePath);
|
|
74
|
+
if (isPathWithinFolder(skills[name].path, absResourcePath)) {
|
|
75
|
+
if (fs.existsSync(absResourcePath)) {
|
|
76
|
+
return [true, absResourcePath];
|
|
77
|
+
}
|
|
78
|
+
return [false, "No such resource"];
|
|
79
|
+
}
|
|
80
|
+
return [false, "I'm gonna call the alignment police on you!!!"];
|
|
81
|
+
}
|
|
82
|
+
return [false, "No such skill"];
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
let sandbox_name;
|
|
86
|
+
const getSandboxName = () => {
|
|
87
|
+
return sandbox_name;
|
|
88
|
+
};
|
|
89
|
+
const setSandboxName = (sn) => {
|
|
90
|
+
sandbox_name = sn;
|
|
91
|
+
};
|
|
92
|
+
const ensureSandbox = () => {
|
|
93
|
+
if (!sandbox_name) {
|
|
94
|
+
sandbox_name = "slave-sandbox-" + Array.from({ length: 10 }, () => "abcdefghijklmnopqrstuvwxyz0123456789"[randomInt(36)]).join("");
|
|
95
|
+
// `docker pull ghcr.io/calamity-inc/slave-sandbox` is not needed to get the image, but would be needed to update it.
|
|
96
|
+
execFileSync("docker", ["run", "-d", "--name", sandbox_name, "ghcr.io/calamity-inc/slave-sandbox", "sleep", "infinity"], { encoding: "utf8" });
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const copyFileToSandbox = (hostPath, sbxPath) => {
|
|
100
|
+
ensureSandbox();
|
|
101
|
+
try {
|
|
102
|
+
execFileSync("docker", ["cp", "-L", hostPath, `${sandbox_name}:${sbxPath}`], { encoding: "utf8" });
|
|
103
|
+
return "OK";
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
return (e.stdout ?? e.message).trimEnd();
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const functions = Object.assign(Object.create(null), {
|
|
111
|
+
listFiles: ({ path }) => {
|
|
112
|
+
path ??= ".";
|
|
113
|
+
path = fixPath(path);
|
|
114
|
+
if (!path) {
|
|
115
|
+
return "Out of your reach";
|
|
116
|
+
}
|
|
117
|
+
let files;
|
|
118
|
+
try {
|
|
119
|
+
files = fs.readdirSync(path, { withFileTypes: true });
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
return e.code;
|
|
123
|
+
}
|
|
124
|
+
return JSON.stringify(files.map(dirent => dirent.isDirectory() ? `${dirent.name}/` : dirent.name));
|
|
125
|
+
},
|
|
126
|
+
findFiles: ({ path, substring, recursive }) => {
|
|
127
|
+
path ??= ".";
|
|
128
|
+
path = fixPath(path);
|
|
129
|
+
if (!path) {
|
|
130
|
+
return "Out of your reach";
|
|
131
|
+
}
|
|
132
|
+
let files;
|
|
133
|
+
try {
|
|
134
|
+
files = fs.readdirSync(path, { withFileTypes: true, recursive });
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
return e.code;
|
|
138
|
+
}
|
|
139
|
+
files = files.filter(dirent => dirent.isFile())
|
|
140
|
+
.map(dirent => {
|
|
141
|
+
if (dirent.parentPath != ".") {
|
|
142
|
+
return `${dirent.parentPath.replaceAll("\\", "/")}/${dirent.name}`
|
|
143
|
+
}
|
|
144
|
+
return dirent.name;
|
|
145
|
+
})
|
|
146
|
+
.filter(file => !isOutOfReach(file));
|
|
147
|
+
const res = [];
|
|
148
|
+
for (const file of files) {
|
|
149
|
+
try {
|
|
150
|
+
const matches = readFileForModel(file).split(substring).length - 1;
|
|
151
|
+
if (matches) {
|
|
152
|
+
res.push(`${file} has ${matches} match${matches == 1 ? "" : "es"}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
catch (e) {
|
|
156
|
+
// file might be busy, skip it
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return res.join("\n");
|
|
160
|
+
},
|
|
161
|
+
readFile: ({ path }) => {
|
|
162
|
+
path = fixPath(path);
|
|
163
|
+
if (!path) {
|
|
164
|
+
return "You don't have read access to this file";
|
|
165
|
+
}
|
|
166
|
+
if (!fs.existsSync(path) || !fs.statSync(path).isFile()) {
|
|
167
|
+
return "No such file";
|
|
168
|
+
}
|
|
169
|
+
const cont = readFileForModel(path);
|
|
170
|
+
if (cont.length > 10485760) {
|
|
171
|
+
return "File is over 10485760 characters long";
|
|
172
|
+
}
|
|
173
|
+
return cont;
|
|
174
|
+
},
|
|
175
|
+
writeFile: ({ path, data }) => {
|
|
176
|
+
path = fixPath(path, "write");
|
|
177
|
+
if (!path) {
|
|
178
|
+
return "You don't have write access to this file";
|
|
179
|
+
}
|
|
180
|
+
writeFileFromModel(path, data);
|
|
181
|
+
return "OK";
|
|
182
|
+
},
|
|
183
|
+
fileFindAndReplace: ({ path, substring, replacement, expectedMatches }) => {
|
|
184
|
+
path = fixPath(path, "write");
|
|
185
|
+
if (!path) {
|
|
186
|
+
return "You don't have write access to this file";
|
|
187
|
+
}
|
|
188
|
+
const fileContent = fs.readFileSync(path, "utf8");
|
|
189
|
+
const usesCRLF = fileContent.includes("\r\n");
|
|
190
|
+
const arr = fileContent.replaceAll("\r\n", "\n").split(substring);
|
|
191
|
+
const matches = arr.length - 1;
|
|
192
|
+
if (matches == 0 || (expectedMatches && matches != expectedMatches)) {
|
|
193
|
+
return `There were ${matches} match${matches == 1 ? "" : "es"}`;
|
|
194
|
+
}
|
|
195
|
+
writeFileFromModel(path, arr.join(replacement), usesCRLF);
|
|
196
|
+
return "OK";
|
|
197
|
+
},
|
|
198
|
+
sandboxExec: ({ command, args }) => {
|
|
199
|
+
ensureSandbox();
|
|
200
|
+
const result = spawnSync("docker", [ "exec", sandbox_name, command, ...args ], { encoding: "utf8" });
|
|
201
|
+
const output = (result.stdout ?? "") + (result.stderr ?? "");
|
|
202
|
+
if (result.error) {
|
|
203
|
+
return (output || result.error.message).trimEnd();
|
|
204
|
+
}
|
|
205
|
+
if (result.status !== 0 && !output) {
|
|
206
|
+
return `Command exited with status ${result.status}`;
|
|
207
|
+
}
|
|
208
|
+
return output;
|
|
209
|
+
},
|
|
210
|
+
sandboxCopyIn: ({ hostPath, sbxPath }) => {
|
|
211
|
+
hostPath = fixPath(hostPath);
|
|
212
|
+
if (!hostPath) {
|
|
213
|
+
return "You don't have read access to this file";
|
|
214
|
+
}
|
|
215
|
+
if (!fs.existsSync(hostPath) || !fs.statSync(hostPath).isFile()) {
|
|
216
|
+
return "Host path must point to a file";
|
|
217
|
+
}
|
|
218
|
+
return copyFileToSandbox(hostPath, sbxPath);
|
|
219
|
+
},
|
|
220
|
+
sandboxCopyOut: ({ sbxPath, hostPath }) => {
|
|
221
|
+
hostPath = fixPath(hostPath, "write");
|
|
222
|
+
if (!hostPath) {
|
|
223
|
+
return "You don't have write access to this file";
|
|
224
|
+
}
|
|
225
|
+
const isCreate = !fs.existsSync(hostPath);
|
|
226
|
+
if (!isCreate && !fs.statSync(hostPath).isFile()) {
|
|
227
|
+
return "Host path must point to a file";
|
|
228
|
+
}
|
|
229
|
+
ensureSandbox();
|
|
230
|
+
if (isCreate) {
|
|
231
|
+
fs.mkdirSync(path.dirname(hostPath), { recursive: true });
|
|
232
|
+
}
|
|
233
|
+
execFileSync("docker", ["cp", "-L", `${sandbox_name}:${sbxPath}`, hostPath], { encoding: "utf8" });
|
|
234
|
+
return "OK";
|
|
235
|
+
},
|
|
236
|
+
readSkill: ({ name }) => {
|
|
237
|
+
if (Object.hasOwn(skills, name)) {
|
|
238
|
+
return readFileForModel(path.join(skills[name].path, "SKILL.md"));
|
|
239
|
+
}
|
|
240
|
+
return "No such skill";
|
|
241
|
+
},
|
|
242
|
+
readSkillResource: ({ name, path }) => {
|
|
243
|
+
const [ok, res] = getSkillResourcePath(name, path)
|
|
244
|
+
if (ok) {
|
|
245
|
+
return readFileForModel(res);
|
|
246
|
+
}
|
|
247
|
+
return res;
|
|
248
|
+
},
|
|
249
|
+
copySkillResourceToSandbox: ({ name, path, sbxPath }) => {
|
|
250
|
+
const [ok, res] = getSkillResourcePath(name, path)
|
|
251
|
+
if (ok) {
|
|
252
|
+
return copyFileToSandbox(res, sbxPath);
|
|
253
|
+
}
|
|
254
|
+
return res;
|
|
255
|
+
},
|
|
256
|
+
/*system: ({ command }) => {
|
|
257
|
+
//process.exit(1);
|
|
258
|
+
return "It's interesting that you called this tool! Unfortunately for you, it does nothing.";
|
|
259
|
+
}*/
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
const tools = [];
|
|
263
|
+
const initTools = (fs, sandbox, web_search) => {
|
|
264
|
+
if (fs) {
|
|
265
|
+
tools.push(
|
|
266
|
+
{
|
|
267
|
+
type: "function",
|
|
268
|
+
name: "listFiles",
|
|
269
|
+
parameters: {
|
|
270
|
+
type: "object",
|
|
271
|
+
properties: {
|
|
272
|
+
path: { type: ["string", "null"] },
|
|
273
|
+
},
|
|
274
|
+
required: [ "path" ],
|
|
275
|
+
additionalProperties: false,
|
|
276
|
+
},
|
|
277
|
+
strict: true,
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
type: "function",
|
|
281
|
+
name: "findFiles",
|
|
282
|
+
description: "Searches the contents of files for a literal text string",
|
|
283
|
+
parameters: {
|
|
284
|
+
type: "object",
|
|
285
|
+
properties: {
|
|
286
|
+
path: { type: ["string", "null"] },
|
|
287
|
+
substring: { type: "string" },
|
|
288
|
+
recursive: { type: ["boolean", "null"] },
|
|
289
|
+
},
|
|
290
|
+
required: [ "path", "substring", "recursive" ],
|
|
291
|
+
additionalProperties: false,
|
|
292
|
+
},
|
|
293
|
+
strict: true,
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
type: "function",
|
|
297
|
+
name: "readFile",
|
|
298
|
+
parameters: {
|
|
299
|
+
type: "object",
|
|
300
|
+
properties: {
|
|
301
|
+
path: { type: "string" },
|
|
302
|
+
},
|
|
303
|
+
required: [ "path" ],
|
|
304
|
+
additionalProperties: false,
|
|
305
|
+
},
|
|
306
|
+
strict: true,
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
type: "function",
|
|
310
|
+
name: "writeFile",
|
|
311
|
+
parameters: {
|
|
312
|
+
type: "object",
|
|
313
|
+
properties: {
|
|
314
|
+
path: { type: "string" },
|
|
315
|
+
data: { type: "string" },
|
|
316
|
+
},
|
|
317
|
+
required: [ "path", "data" ],
|
|
318
|
+
additionalProperties: false,
|
|
319
|
+
},
|
|
320
|
+
strict: true,
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
type: "function",
|
|
324
|
+
name: "fileFindAndReplace",
|
|
325
|
+
parameters: {
|
|
326
|
+
type: "object",
|
|
327
|
+
properties: {
|
|
328
|
+
path: { type: "string" },
|
|
329
|
+
substring: { type: "string" },
|
|
330
|
+
replacement: { type: "string" },
|
|
331
|
+
expectedMatches: { type: ["number", "null"] },
|
|
332
|
+
},
|
|
333
|
+
required: [ "path", "substring", "replacement", "expectedMatches" ],
|
|
334
|
+
additionalProperties: false,
|
|
335
|
+
},
|
|
336
|
+
strict: true,
|
|
337
|
+
},
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
if (sandbox) {
|
|
341
|
+
tools.push({
|
|
342
|
+
type: "function",
|
|
343
|
+
name: "sandboxExec",
|
|
344
|
+
description: "Runs a command without Bash in an isolated sandbox.",
|
|
345
|
+
parameters: {
|
|
346
|
+
type: "object",
|
|
347
|
+
properties: {
|
|
348
|
+
command: { type: "string" },
|
|
349
|
+
args: { type: "array", items: { type: "string" } },
|
|
350
|
+
},
|
|
351
|
+
required: [ "command", "args" ],
|
|
352
|
+
additionalProperties: false,
|
|
353
|
+
},
|
|
354
|
+
strict: true,
|
|
355
|
+
});
|
|
356
|
+
if (fs) {
|
|
357
|
+
tools.push(
|
|
358
|
+
{
|
|
359
|
+
type: "function",
|
|
360
|
+
name: "sandboxCopyIn",
|
|
361
|
+
parameters: {
|
|
362
|
+
type: "object",
|
|
363
|
+
properties: {
|
|
364
|
+
hostPath: { type: "string" },
|
|
365
|
+
sbxPath: { type: "string" },
|
|
366
|
+
},
|
|
367
|
+
required: [ "hostPath", "sbxPath" ],
|
|
368
|
+
additionalProperties: false,
|
|
369
|
+
},
|
|
370
|
+
strict: true,
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
type: "function",
|
|
374
|
+
name: "sandboxCopyOut",
|
|
375
|
+
parameters: {
|
|
376
|
+
type: "object",
|
|
377
|
+
properties: {
|
|
378
|
+
sbxPath: { type: "string" },
|
|
379
|
+
hostPath: { type: "string" },
|
|
380
|
+
},
|
|
381
|
+
required: [ "sbxPath", "hostPath" ],
|
|
382
|
+
additionalProperties: false,
|
|
383
|
+
},
|
|
384
|
+
strict: true,
|
|
385
|
+
},
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
if (Object.keys(skills).length) {
|
|
390
|
+
tools.push(
|
|
391
|
+
{
|
|
392
|
+
type: "function",
|
|
393
|
+
name: "readSkill",
|
|
394
|
+
parameters: {
|
|
395
|
+
type: "object",
|
|
396
|
+
properties: {
|
|
397
|
+
name: { type: "string" },
|
|
398
|
+
},
|
|
399
|
+
required: [ "name" ],
|
|
400
|
+
additionalProperties: false,
|
|
401
|
+
},
|
|
402
|
+
strict: true,
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
type: "function",
|
|
406
|
+
name: "readSkillResource",
|
|
407
|
+
parameters: {
|
|
408
|
+
type: "object",
|
|
409
|
+
properties: {
|
|
410
|
+
name: { type: "string" },
|
|
411
|
+
path: { type: "string" },
|
|
412
|
+
},
|
|
413
|
+
required: [ "name", "path" ],
|
|
414
|
+
additionalProperties: false,
|
|
415
|
+
},
|
|
416
|
+
strict: true,
|
|
417
|
+
},
|
|
418
|
+
);
|
|
419
|
+
if (sandbox) {
|
|
420
|
+
tools.push({
|
|
421
|
+
type: "function",
|
|
422
|
+
name: "copySkillResourceToSandbox",
|
|
423
|
+
parameters: {
|
|
424
|
+
type: "object",
|
|
425
|
+
properties: {
|
|
426
|
+
name: { type: "string" },
|
|
427
|
+
path: { type: "string" },
|
|
428
|
+
sbxPath: { type: "string" },
|
|
429
|
+
},
|
|
430
|
+
required: [ "name", "path", "sbxPath" ],
|
|
431
|
+
additionalProperties: false,
|
|
432
|
+
},
|
|
433
|
+
strict: true,
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
if (web_search) {
|
|
438
|
+
tools.push({ type: "web_search" });
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
const toolToAnthropic = (t) => {
|
|
443
|
+
if (t.type == "function") {
|
|
444
|
+
return {
|
|
445
|
+
name: t.name,
|
|
446
|
+
description: t.description,
|
|
447
|
+
input_schema: t.parameters,
|
|
448
|
+
strict: t.strict,
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
else if (t.type == "web_search") {
|
|
452
|
+
return {
|
|
453
|
+
type: "web_search_20260318",
|
|
454
|
+
name: "web_search"
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
const printJunk = (line) => {
|
|
460
|
+
logWrite(line);
|
|
461
|
+
line = line.replaceAll("\r", "<CR>").replaceAll("\n", "<NL>").replaceAll("\t", " ");
|
|
462
|
+
if (line.length > 80) {
|
|
463
|
+
line = line.substring(0, 77) + "...";
|
|
464
|
+
}
|
|
465
|
+
console.log(line);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
const useTool = (name, args, argsStr) => {
|
|
469
|
+
printJunk("$ " + name + argsStr);
|
|
470
|
+
const output = String(functions[name](args));
|
|
471
|
+
printJunk(output);
|
|
472
|
+
return output;
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
const openai_generateResponseOptionallyUsingTools = async (client, model, input, state) => {
|
|
476
|
+
let response = await client.responses.create({
|
|
477
|
+
model,
|
|
478
|
+
instructions: getSystemPrompt(),
|
|
479
|
+
previous_response_id: state,
|
|
480
|
+
input,
|
|
481
|
+
tools,
|
|
482
|
+
});
|
|
483
|
+
let used_tools = false;
|
|
484
|
+
|
|
485
|
+
while (true) {
|
|
486
|
+
const toolCalls = response.output.filter((item) => item.type == "function_call");
|
|
487
|
+
if (toolCalls.length == 0) {
|
|
488
|
+
break;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
const outputs = toolCalls.map((call) => {
|
|
492
|
+
return {
|
|
493
|
+
type: "function_call_output",
|
|
494
|
+
call_id: call.call_id,
|
|
495
|
+
output: useTool(call.name, JSON.parse(call.arguments), call.arguments)
|
|
496
|
+
};
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
response = await client.responses.create({
|
|
500
|
+
model,
|
|
501
|
+
instructions: getSystemPrompt(),
|
|
502
|
+
previous_response_id: response.id,
|
|
503
|
+
input: outputs,
|
|
504
|
+
tools,
|
|
505
|
+
});
|
|
506
|
+
used_tools = true;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
return {
|
|
510
|
+
output_text: response.output_text,
|
|
511
|
+
state: response.id,
|
|
512
|
+
used_tools,
|
|
513
|
+
};
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
const anthropic_streamMessage = (client, res, params) => {
|
|
517
|
+
const stream = client.messages.stream(params);
|
|
518
|
+
let thought = "";
|
|
519
|
+
stream.on("thinking", (delta) => {
|
|
520
|
+
thought += delta;
|
|
521
|
+
const i = thought.indexOf("\n\n");
|
|
522
|
+
if (i != -1) {
|
|
523
|
+
console.log(chalk.gray(thought.substring(0, i)));
|
|
524
|
+
logWrite(`[Thought summary: ${thought.substring(0, i)}]`);
|
|
525
|
+
res.used_tools = true; // Need a newline before response just the same
|
|
526
|
+
thought = thought.substring(i + 2);
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
stream.on("contentBlock", () => {
|
|
530
|
+
if (thought) {
|
|
531
|
+
console.log(chalk.gray(thought));
|
|
532
|
+
logWrite(`[Thought summary: ${thought}]`);
|
|
533
|
+
res.used_tools = true; // Need a newline before response just the same
|
|
534
|
+
thought = "";
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
return stream.finalMessage();
|
|
538
|
+
};
|
|
539
|
+
|
|
540
|
+
const anthropic_generateResponseOptionallyUsingTools = async (client, model, input, state) => {
|
|
541
|
+
state = JSON.parse(state || "[]");
|
|
542
|
+
state.push({ role: "user", content: input });
|
|
543
|
+
const res = { used_tools: false };
|
|
544
|
+
|
|
545
|
+
const anthropicTools = tools.map(t => toolToAnthropic(t));
|
|
546
|
+
|
|
547
|
+
let message = await anthropic_streamMessage(client, res, {
|
|
548
|
+
model,
|
|
549
|
+
max_tokens: 64000,
|
|
550
|
+
thinking: { type: "adaptive", display: "summarized" },
|
|
551
|
+
cache_control: { type: "ephemeral" },
|
|
552
|
+
system: getSystemPrompt(),
|
|
553
|
+
messages: state,
|
|
554
|
+
tools: anthropicTools,
|
|
555
|
+
});
|
|
556
|
+
state.push({ role: message.role, content: message.content });
|
|
557
|
+
|
|
558
|
+
while (message.stop_reason == "tool_use" || message.stop_reason == "pause_turn") {
|
|
559
|
+
const toolCalls = message.content.filter((item) => item.type == "tool_use");
|
|
560
|
+
if (toolCalls.length) {
|
|
561
|
+
const outputs = toolCalls.map((call) => {
|
|
562
|
+
return {
|
|
563
|
+
type: "tool_result",
|
|
564
|
+
tool_use_id: call.id,
|
|
565
|
+
content: useTool(call.name, call.input, JSON.stringify(call.input))
|
|
566
|
+
};
|
|
567
|
+
});
|
|
568
|
+
state.push({ role: "user", content: outputs });
|
|
569
|
+
res.used_tools = true;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/*if (message.stop_reason == "max_tokens" && message.content[message.content.length].type == "thinking") {
|
|
573
|
+
state.push({ role: "user", content: "Please continue from where you left off." });
|
|
574
|
+
}*/
|
|
575
|
+
|
|
576
|
+
message = await anthropic_streamMessage(client, res, {
|
|
577
|
+
model,
|
|
578
|
+
max_tokens: 64000,
|
|
579
|
+
thinking: { type: "adaptive", display: "summarized" },
|
|
580
|
+
cache_control: { type: "ephemeral" },
|
|
581
|
+
system: getSystemPrompt(),
|
|
582
|
+
messages: state,
|
|
583
|
+
tools: anthropicTools,
|
|
584
|
+
});
|
|
585
|
+
state.push({ role: message.role, content: message.content });
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
if (message.stop_reason != "end_turn") {
|
|
589
|
+
logWrite(`unexpected stop_reason: ${message.stop_reason}\n${JSON.stringify(message, null, 2)}`);
|
|
590
|
+
console.log(message);
|
|
591
|
+
throw new Error(`unexpected stop_reason: ${message.stop_reason}`);
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
//console.log(message);
|
|
595
|
+
res.output_text = message.content.find((item) => item.type == "text").text;
|
|
596
|
+
res.state = JSON.stringify(state);
|
|
597
|
+
return res;
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
module.exports = {
|
|
601
|
+
initTools,
|
|
602
|
+
getSandboxName,
|
|
603
|
+
setSandboxName,
|
|
604
|
+
openai_generateResponseOptionallyUsingTools,
|
|
605
|
+
anthropic_generateResponseOptionallyUsingTools,
|
|
606
|
+
};
|