@polka-codes/core 0.5.0 → 0.5.2
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/index.js +457 -259
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2865,62 +2865,11 @@ Anthropic.Models = Models2;
|
|
|
2865
2865
|
Anthropic.ModelInfosPage = ModelInfosPage;
|
|
2866
2866
|
Anthropic.Beta = Beta;
|
|
2867
2867
|
|
|
2868
|
-
// src/AiService/UsageMeter.ts
|
|
2869
|
-
class UsageMeter {
|
|
2870
|
-
#usage = {
|
|
2871
|
-
inputTokens: 0,
|
|
2872
|
-
outputTokens: 0,
|
|
2873
|
-
cacheWriteTokens: 0,
|
|
2874
|
-
cacheReadTokens: 0,
|
|
2875
|
-
totalCost: 0
|
|
2876
|
-
};
|
|
2877
|
-
#messageCount = 0;
|
|
2878
|
-
maxCost;
|
|
2879
|
-
maxMessageCount;
|
|
2880
|
-
constructor(options = {}) {
|
|
2881
|
-
this.maxCost = options.maxCost || 1000;
|
|
2882
|
-
this.maxMessageCount = options.maxMessageCount || 1000;
|
|
2883
|
-
}
|
|
2884
|
-
addUsage(usage, model) {
|
|
2885
|
-
this.#usage.inputTokens += usage.inputTokens ?? 0;
|
|
2886
|
-
this.#usage.outputTokens += usage.outputTokens ?? 0;
|
|
2887
|
-
this.#usage.cacheWriteTokens += usage.cacheWriteTokens ?? 0;
|
|
2888
|
-
this.#usage.cacheReadTokens += usage.cacheReadTokens ?? 0;
|
|
2889
|
-
if (!usage.totalCost && model) {
|
|
2890
|
-
usage.totalCost = ((model.inputPrice ?? 0) * (usage.inputTokens ?? 0) + (model.outputPrice ?? 0) * (usage.outputTokens ?? 0) + (model.cacheWritesPrice ?? 0) * (usage.cacheWriteTokens ?? 0) + (model.cacheReadsPrice ?? 0) * (usage.cacheReadTokens ?? 0)) / 1e6;
|
|
2891
|
-
}
|
|
2892
|
-
this.#usage.totalCost += usage.totalCost ?? 0;
|
|
2893
|
-
}
|
|
2894
|
-
incrementMessageCount(count = 1) {
|
|
2895
|
-
this.#messageCount += count;
|
|
2896
|
-
}
|
|
2897
|
-
isLimitExceeded() {
|
|
2898
|
-
const messageCount = this.#messageCount >= this.maxMessageCount;
|
|
2899
|
-
const cost = this.#usage.totalCost >= this.maxCost;
|
|
2900
|
-
return {
|
|
2901
|
-
messageCount,
|
|
2902
|
-
cost,
|
|
2903
|
-
result: messageCount || cost
|
|
2904
|
-
};
|
|
2905
|
-
}
|
|
2906
|
-
get usage() {
|
|
2907
|
-
return { ...this.#usage };
|
|
2908
|
-
}
|
|
2909
|
-
printUsage() {
|
|
2910
|
-
console.log("Usages:");
|
|
2911
|
-
console.log(`Input tokens: ${this.#usage.inputTokens}`);
|
|
2912
|
-
console.log(`Output tokens: ${this.#usage.outputTokens}`);
|
|
2913
|
-
console.log(`Cache read tokens: ${this.#usage.cacheReadTokens}`);
|
|
2914
|
-
console.log(`Cache write tokens: ${this.#usage.cacheWriteTokens}`);
|
|
2915
|
-
console.log(`Total cost: ${this.#usage.totalCost}`);
|
|
2916
|
-
}
|
|
2917
|
-
}
|
|
2918
|
-
|
|
2919
2868
|
// src/AiService/AiServiceBase.ts
|
|
2920
2869
|
class AiServiceBase {
|
|
2921
2870
|
usageMeter;
|
|
2922
2871
|
constructor(usageMeter) {
|
|
2923
|
-
this.usageMeter = usageMeter
|
|
2872
|
+
this.usageMeter = usageMeter;
|
|
2924
2873
|
}
|
|
2925
2874
|
async* send(systemPrompt, messages) {
|
|
2926
2875
|
this.usageMeter.incrementMessageCount();
|
|
@@ -8156,6 +8105,61 @@ class OpenRouterService extends AiServiceBase {
|
|
|
8156
8105
|
}
|
|
8157
8106
|
}
|
|
8158
8107
|
|
|
8108
|
+
// src/AiService/UsageMeter.ts
|
|
8109
|
+
class UsageMeter {
|
|
8110
|
+
#usage = {
|
|
8111
|
+
inputTokens: 0,
|
|
8112
|
+
outputTokens: 0,
|
|
8113
|
+
cacheWriteTokens: 0,
|
|
8114
|
+
cacheReadTokens: 0,
|
|
8115
|
+
totalCost: 0
|
|
8116
|
+
};
|
|
8117
|
+
#messageCount = 0;
|
|
8118
|
+
maxCost;
|
|
8119
|
+
maxMessageCount;
|
|
8120
|
+
constructor(options = {}) {
|
|
8121
|
+
this.maxCost = options.maxCost || 1000;
|
|
8122
|
+
this.maxMessageCount = options.maxMessageCount || 1000;
|
|
8123
|
+
}
|
|
8124
|
+
addUsage(usage, model) {
|
|
8125
|
+
this.#usage.inputTokens += usage.inputTokens ?? 0;
|
|
8126
|
+
this.#usage.outputTokens += usage.outputTokens ?? 0;
|
|
8127
|
+
this.#usage.cacheWriteTokens += usage.cacheWriteTokens ?? 0;
|
|
8128
|
+
this.#usage.cacheReadTokens += usage.cacheReadTokens ?? 0;
|
|
8129
|
+
if (!usage.totalCost && model) {
|
|
8130
|
+
usage.totalCost = ((model.inputPrice ?? 0) * (usage.inputTokens ?? 0) + (model.outputPrice ?? 0) * (usage.outputTokens ?? 0) + (model.cacheWritesPrice ?? 0) * (usage.cacheWriteTokens ?? 0) + (model.cacheReadsPrice ?? 0) * (usage.cacheReadTokens ?? 0)) / 1e6;
|
|
8131
|
+
}
|
|
8132
|
+
this.#usage.totalCost += usage.totalCost ?? 0;
|
|
8133
|
+
}
|
|
8134
|
+
incrementMessageCount(count = 1) {
|
|
8135
|
+
this.#messageCount += count;
|
|
8136
|
+
}
|
|
8137
|
+
isLimitExceeded() {
|
|
8138
|
+
const messageCount = this.#messageCount >= this.maxMessageCount;
|
|
8139
|
+
const cost = this.#usage.totalCost >= this.maxCost;
|
|
8140
|
+
return {
|
|
8141
|
+
messageCount,
|
|
8142
|
+
cost,
|
|
8143
|
+
result: messageCount || cost
|
|
8144
|
+
};
|
|
8145
|
+
}
|
|
8146
|
+
get usage() {
|
|
8147
|
+
return { ...this.#usage };
|
|
8148
|
+
}
|
|
8149
|
+
printUsage() {
|
|
8150
|
+
const { inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens } = this.#usage;
|
|
8151
|
+
const allTokensZero = inputTokens === 0 && outputTokens === 0 && cacheReadTokens === 0 && cacheWriteTokens === 0;
|
|
8152
|
+
console.log("Usages:");
|
|
8153
|
+
if (!allTokensZero) {
|
|
8154
|
+
console.log(`Input tokens: ${this.#usage.inputTokens}`);
|
|
8155
|
+
console.log(`Output tokens: ${this.#usage.outputTokens}`);
|
|
8156
|
+
console.log(`Cache read tokens: ${this.#usage.cacheReadTokens}`);
|
|
8157
|
+
console.log(`Cache write tokens: ${this.#usage.cacheWriteTokens}`);
|
|
8158
|
+
}
|
|
8159
|
+
console.log(`Total cost: ${this.#usage.totalCost}`);
|
|
8160
|
+
}
|
|
8161
|
+
}
|
|
8162
|
+
|
|
8159
8163
|
// src/AiService/index.ts
|
|
8160
8164
|
var AiServiceProvider;
|
|
8161
8165
|
((AiServiceProvider2) => {
|
|
@@ -8182,20 +8186,6 @@ var createService = (provider, options) => {
|
|
|
8182
8186
|
return new OpenRouterService(options);
|
|
8183
8187
|
}
|
|
8184
8188
|
};
|
|
8185
|
-
// src/tool.ts
|
|
8186
|
-
var ToolResponseType;
|
|
8187
|
-
((ToolResponseType2) => {
|
|
8188
|
-
ToolResponseType2["Reply"] = "Reply";
|
|
8189
|
-
ToolResponseType2["Exit"] = "Exit";
|
|
8190
|
-
ToolResponseType2["Invalid"] = "Invalid";
|
|
8191
|
-
ToolResponseType2["Error"] = "Error";
|
|
8192
|
-
ToolResponseType2["Interrupted"] = "Interrupted";
|
|
8193
|
-
ToolResponseType2["HandOver"] = "HandOver";
|
|
8194
|
-
})(ToolResponseType ||= {});
|
|
8195
|
-
var getAvailableTools = (provider, allTools) => {
|
|
8196
|
-
return allTools.filter((tool) => tool.isAvailable(provider));
|
|
8197
|
-
};
|
|
8198
|
-
|
|
8199
8189
|
// src/tools/provider.ts
|
|
8200
8190
|
class MockProvider {
|
|
8201
8191
|
async readFile(path) {
|
|
@@ -8242,6 +8232,7 @@ __export(exports_allTools, {
|
|
|
8242
8232
|
listCodeDefinitionNames: () => listCodeDefinitionNames_default,
|
|
8243
8233
|
handOver: () => handOver_default,
|
|
8244
8234
|
executeCommand: () => executeCommand_default,
|
|
8235
|
+
delegate: () => delegate_default,
|
|
8245
8236
|
attemptCompletion: () => attemptCompletion_default,
|
|
8246
8237
|
askFollowupQuestion: () => askFollowupQuestion_default
|
|
8247
8238
|
});
|
|
@@ -8466,8 +8457,83 @@ var attemptCompletion_default = {
|
|
|
8466
8457
|
handler: handler2,
|
|
8467
8458
|
isAvailable: isAvailable2
|
|
8468
8459
|
};
|
|
8469
|
-
// src/tools/
|
|
8460
|
+
// src/tools/delegate.ts
|
|
8470
8461
|
var toolInfo3 = {
|
|
8462
|
+
name: "delegate",
|
|
8463
|
+
description: "Temporarily delegate a task to another agent and receive the result back",
|
|
8464
|
+
parameters: [
|
|
8465
|
+
{
|
|
8466
|
+
name: "agent_name",
|
|
8467
|
+
description: "The name of the agent to delegate the task to",
|
|
8468
|
+
required: true,
|
|
8469
|
+
usageValue: "Name of the target agent"
|
|
8470
|
+
},
|
|
8471
|
+
{
|
|
8472
|
+
name: "task",
|
|
8473
|
+
description: "The task to be completed by the target agent",
|
|
8474
|
+
required: true,
|
|
8475
|
+
usageValue: "Task description"
|
|
8476
|
+
},
|
|
8477
|
+
{
|
|
8478
|
+
name: "context",
|
|
8479
|
+
description: "The context information for the task",
|
|
8480
|
+
required: true,
|
|
8481
|
+
usageValue: "Context information"
|
|
8482
|
+
},
|
|
8483
|
+
{
|
|
8484
|
+
name: "files",
|
|
8485
|
+
description: "The files relevant to the task. Comma separated paths",
|
|
8486
|
+
required: false,
|
|
8487
|
+
usageValue: "Relevant files"
|
|
8488
|
+
}
|
|
8489
|
+
],
|
|
8490
|
+
examples: [
|
|
8491
|
+
{
|
|
8492
|
+
description: "Delegate a code analysis task to the analyzer agent",
|
|
8493
|
+
parameters: [
|
|
8494
|
+
{
|
|
8495
|
+
name: "agent_name",
|
|
8496
|
+
value: "analyzer"
|
|
8497
|
+
},
|
|
8498
|
+
{
|
|
8499
|
+
name: "task",
|
|
8500
|
+
value: "Analyze the authentication implementation"
|
|
8501
|
+
},
|
|
8502
|
+
{
|
|
8503
|
+
name: "context",
|
|
8504
|
+
value: "Need to understand the security implications of the current auth system"
|
|
8505
|
+
},
|
|
8506
|
+
{
|
|
8507
|
+
name: "files",
|
|
8508
|
+
value: "src/auth/login.ts,src/auth/types.ts"
|
|
8509
|
+
}
|
|
8510
|
+
]
|
|
8511
|
+
}
|
|
8512
|
+
]
|
|
8513
|
+
};
|
|
8514
|
+
var handler3 = async (_provider, args) => {
|
|
8515
|
+
const agentName = getString(args, "agent_name");
|
|
8516
|
+
const task = getString(args, "task");
|
|
8517
|
+
const context = getString(args, "context", undefined);
|
|
8518
|
+
const files = getStringArray(args, "files", []);
|
|
8519
|
+
return {
|
|
8520
|
+
type: "Delegate" /* Delegate */,
|
|
8521
|
+
agentName,
|
|
8522
|
+
task,
|
|
8523
|
+
context,
|
|
8524
|
+
files
|
|
8525
|
+
};
|
|
8526
|
+
};
|
|
8527
|
+
var isAvailable3 = (_provider) => {
|
|
8528
|
+
return true;
|
|
8529
|
+
};
|
|
8530
|
+
var delegate_default = {
|
|
8531
|
+
...toolInfo3,
|
|
8532
|
+
handler: handler3,
|
|
8533
|
+
isAvailable: isAvailable3
|
|
8534
|
+
};
|
|
8535
|
+
// src/tools/executeCommand.ts
|
|
8536
|
+
var toolInfo4 = {
|
|
8471
8537
|
name: "execute_command",
|
|
8472
8538
|
description: `Request to execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task. You must tailor your command to the user's system and provide a clear explanation of what the command does. Prefer to execute complex CLI commands over creating executable scripts, as they are more flexible and easier to run. Commands will also be executed in the project root directory regardless of executed commands in previous tool uses.`,
|
|
8473
8539
|
parameters: [
|
|
@@ -8500,7 +8566,7 @@ var toolInfo3 = {
|
|
|
8500
8566
|
}
|
|
8501
8567
|
]
|
|
8502
8568
|
};
|
|
8503
|
-
var
|
|
8569
|
+
var handler4 = async (provider, args) => {
|
|
8504
8570
|
if (!provider.executeCommand) {
|
|
8505
8571
|
return {
|
|
8506
8572
|
type: "Error" /* Error */,
|
|
@@ -8529,16 +8595,16 @@ ${result.stderr}
|
|
|
8529
8595
|
message
|
|
8530
8596
|
};
|
|
8531
8597
|
};
|
|
8532
|
-
var
|
|
8598
|
+
var isAvailable4 = (provider) => {
|
|
8533
8599
|
return !!provider.executeCommand;
|
|
8534
8600
|
};
|
|
8535
8601
|
var executeCommand_default = {
|
|
8536
|
-
...
|
|
8537
|
-
handler:
|
|
8538
|
-
isAvailable:
|
|
8602
|
+
...toolInfo4,
|
|
8603
|
+
handler: handler4,
|
|
8604
|
+
isAvailable: isAvailable4
|
|
8539
8605
|
};
|
|
8540
8606
|
// src/tools/listCodeDefinitionNames.ts
|
|
8541
|
-
var
|
|
8607
|
+
var toolInfo5 = {
|
|
8542
8608
|
name: "list_code_definition_names",
|
|
8543
8609
|
description: "Request to list definition names (classes, functions, methods, etc.) used in a file. This tool provides insights into the codebase structure and important constructs, encapsulating high-level concepts and relationships that are crucial for understanding the overall architecture.",
|
|
8544
8610
|
parameters: [
|
|
@@ -8550,7 +8616,7 @@ var toolInfo4 = {
|
|
|
8550
8616
|
}
|
|
8551
8617
|
]
|
|
8552
8618
|
};
|
|
8553
|
-
var
|
|
8619
|
+
var handler5 = async (provider, args) => {
|
|
8554
8620
|
if (!provider.listCodeDefinitionNames) {
|
|
8555
8621
|
return {
|
|
8556
8622
|
type: "Error" /* Error */,
|
|
@@ -8568,16 +8634,16 @@ ${files.join(`
|
|
|
8568
8634
|
</list_code_definition_names_files>`
|
|
8569
8635
|
};
|
|
8570
8636
|
};
|
|
8571
|
-
var
|
|
8637
|
+
var isAvailable5 = (provider) => {
|
|
8572
8638
|
return !!provider.listCodeDefinitionNames;
|
|
8573
8639
|
};
|
|
8574
8640
|
var listCodeDefinitionNames_default = {
|
|
8575
|
-
...
|
|
8576
|
-
handler:
|
|
8577
|
-
isAvailable:
|
|
8641
|
+
...toolInfo5,
|
|
8642
|
+
handler: handler5,
|
|
8643
|
+
isAvailable: isAvailable5
|
|
8578
8644
|
};
|
|
8579
8645
|
// src/tools/listFiles.ts
|
|
8580
|
-
var
|
|
8646
|
+
var toolInfo6 = {
|
|
8581
8647
|
name: "list_files",
|
|
8582
8648
|
description: "Request to list files and directories within the specified directory. If recursive is true, it will list all files and directories recursively. If recursive is false or not provided, it will only list the top-level contents. Do not use this tool to confirm the existence of files you may have created, as the user will let you know if the files were created successfully or not.",
|
|
8583
8649
|
parameters: [
|
|
@@ -8616,7 +8682,7 @@ var toolInfo5 = {
|
|
|
8616
8682
|
}
|
|
8617
8683
|
]
|
|
8618
8684
|
};
|
|
8619
|
-
var
|
|
8685
|
+
var handler6 = async (provider, args) => {
|
|
8620
8686
|
if (!provider.listFiles) {
|
|
8621
8687
|
return {
|
|
8622
8688
|
type: "Error" /* Error */,
|
|
@@ -8637,16 +8703,16 @@ ${files.join(`
|
|
|
8637
8703
|
<list_files_truncated>${limitReached}</list_files_truncated>`
|
|
8638
8704
|
};
|
|
8639
8705
|
};
|
|
8640
|
-
var
|
|
8706
|
+
var isAvailable6 = (provider) => {
|
|
8641
8707
|
return !!provider.listFiles;
|
|
8642
8708
|
};
|
|
8643
8709
|
var listFiles_default = {
|
|
8644
|
-
...
|
|
8645
|
-
handler:
|
|
8646
|
-
isAvailable:
|
|
8710
|
+
...toolInfo6,
|
|
8711
|
+
handler: handler6,
|
|
8712
|
+
isAvailable: isAvailable6
|
|
8647
8713
|
};
|
|
8648
8714
|
// src/tools/readFile.ts
|
|
8649
|
-
var
|
|
8715
|
+
var toolInfo7 = {
|
|
8650
8716
|
name: "read_file",
|
|
8651
8717
|
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.",
|
|
8652
8718
|
parameters: [
|
|
@@ -8678,7 +8744,7 @@ var toolInfo6 = {
|
|
|
8678
8744
|
}
|
|
8679
8745
|
]
|
|
8680
8746
|
};
|
|
8681
|
-
var
|
|
8747
|
+
var handler7 = async (provider, args) => {
|
|
8682
8748
|
if (!provider.readFile) {
|
|
8683
8749
|
return {
|
|
8684
8750
|
type: "Error" /* Error */,
|
|
@@ -8702,16 +8768,16 @@ var handler6 = async (provider, args) => {
|
|
|
8702
8768
|
`)
|
|
8703
8769
|
};
|
|
8704
8770
|
};
|
|
8705
|
-
var
|
|
8771
|
+
var isAvailable7 = (provider) => {
|
|
8706
8772
|
return !!provider.readFile;
|
|
8707
8773
|
};
|
|
8708
8774
|
var readFile_default = {
|
|
8709
|
-
...
|
|
8710
|
-
handler:
|
|
8711
|
-
isAvailable:
|
|
8775
|
+
...toolInfo7,
|
|
8776
|
+
handler: handler7,
|
|
8777
|
+
isAvailable: isAvailable7
|
|
8712
8778
|
};
|
|
8713
8779
|
// src/tools/replaceInFile.ts
|
|
8714
|
-
var
|
|
8780
|
+
var toolInfo8 = {
|
|
8715
8781
|
name: "replace_in_file",
|
|
8716
8782
|
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.",
|
|
8717
8783
|
parameters: [
|
|
@@ -8795,7 +8861,7 @@ return (
|
|
|
8795
8861
|
}
|
|
8796
8862
|
]
|
|
8797
8863
|
};
|
|
8798
|
-
var
|
|
8864
|
+
var handler8 = async (provider, args) => {
|
|
8799
8865
|
if (!provider.readFile || !provider.writeFile) {
|
|
8800
8866
|
return {
|
|
8801
8867
|
type: "Error" /* Error */,
|
|
@@ -8812,16 +8878,16 @@ var handler7 = async (provider, args) => {
|
|
|
8812
8878
|
message: `<replace_in_file_path>${path}</replace_in_file_path>`
|
|
8813
8879
|
};
|
|
8814
8880
|
};
|
|
8815
|
-
var
|
|
8881
|
+
var isAvailable8 = (provider) => {
|
|
8816
8882
|
return !!provider.readFile && !!provider.writeFile;
|
|
8817
8883
|
};
|
|
8818
8884
|
var replaceInFile_default = {
|
|
8819
|
-
...
|
|
8820
|
-
handler:
|
|
8821
|
-
isAvailable:
|
|
8885
|
+
...toolInfo8,
|
|
8886
|
+
handler: handler8,
|
|
8887
|
+
isAvailable: isAvailable8
|
|
8822
8888
|
};
|
|
8823
8889
|
// src/tools/searchFiles.ts
|
|
8824
|
-
var
|
|
8890
|
+
var toolInfo9 = {
|
|
8825
8891
|
name: "search_files",
|
|
8826
8892
|
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.",
|
|
8827
8893
|
parameters: [
|
|
@@ -8864,7 +8930,7 @@ var toolInfo8 = {
|
|
|
8864
8930
|
}
|
|
8865
8931
|
]
|
|
8866
8932
|
};
|
|
8867
|
-
var
|
|
8933
|
+
var handler9 = async (provider, args) => {
|
|
8868
8934
|
if (!provider.searchFiles) {
|
|
8869
8935
|
return {
|
|
8870
8936
|
type: "Error" /* Error */,
|
|
@@ -8887,16 +8953,16 @@ ${files.join(`
|
|
|
8887
8953
|
`
|
|
8888
8954
|
};
|
|
8889
8955
|
};
|
|
8890
|
-
var
|
|
8956
|
+
var isAvailable9 = (provider) => {
|
|
8891
8957
|
return !!provider.searchFiles;
|
|
8892
8958
|
};
|
|
8893
8959
|
var searchFiles_default = {
|
|
8894
|
-
...
|
|
8895
|
-
handler:
|
|
8896
|
-
isAvailable:
|
|
8960
|
+
...toolInfo9,
|
|
8961
|
+
handler: handler9,
|
|
8962
|
+
isAvailable: isAvailable9
|
|
8897
8963
|
};
|
|
8898
8964
|
// src/tools/writeToFile.ts
|
|
8899
|
-
var
|
|
8965
|
+
var toolInfo10 = {
|
|
8900
8966
|
name: "write_to_file",
|
|
8901
8967
|
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.",
|
|
8902
8968
|
parameters: [
|
|
@@ -8940,7 +9006,7 @@ export default App;
|
|
|
8940
9006
|
}
|
|
8941
9007
|
]
|
|
8942
9008
|
};
|
|
8943
|
-
var
|
|
9009
|
+
var handler10 = async (provider, args) => {
|
|
8944
9010
|
if (!provider.writeFile) {
|
|
8945
9011
|
return {
|
|
8946
9012
|
type: "Error" /* Error */,
|
|
@@ -8955,16 +9021,16 @@ var handler9 = async (provider, args) => {
|
|
|
8955
9021
|
message: `<write_to_file_path>${path}</write_to_file_path><status>Success</status>`
|
|
8956
9022
|
};
|
|
8957
9023
|
};
|
|
8958
|
-
var
|
|
9024
|
+
var isAvailable10 = (provider) => {
|
|
8959
9025
|
return !!provider.writeFile;
|
|
8960
9026
|
};
|
|
8961
9027
|
var writeToFile_default = {
|
|
8962
|
-
...
|
|
8963
|
-
handler:
|
|
8964
|
-
isAvailable:
|
|
9028
|
+
...toolInfo10,
|
|
9029
|
+
handler: handler10,
|
|
9030
|
+
isAvailable: isAvailable10
|
|
8965
9031
|
};
|
|
8966
9032
|
// src/tools/handOver.ts
|
|
8967
|
-
var
|
|
9033
|
+
var toolInfo11 = {
|
|
8968
9034
|
name: "hand_over",
|
|
8969
9035
|
description: "Hand over the current task to another agent to complete",
|
|
8970
9036
|
parameters: [
|
|
@@ -8988,7 +9054,7 @@ var toolInfo10 = {
|
|
|
8988
9054
|
},
|
|
8989
9055
|
{
|
|
8990
9056
|
name: "files",
|
|
8991
|
-
description: "The files relevant to the task",
|
|
9057
|
+
description: "The files relevant to the task. Comma separated paths",
|
|
8992
9058
|
required: false,
|
|
8993
9059
|
usageValue: "Relevant files"
|
|
8994
9060
|
}
|
|
@@ -9017,7 +9083,7 @@ var toolInfo10 = {
|
|
|
9017
9083
|
}
|
|
9018
9084
|
]
|
|
9019
9085
|
};
|
|
9020
|
-
var
|
|
9086
|
+
var handler11 = async (_provider, args) => {
|
|
9021
9087
|
const agentName = getString(args, "agent_name");
|
|
9022
9088
|
const task = getString(args, "task");
|
|
9023
9089
|
const context = getString(args, "context", undefined);
|
|
@@ -9030,16 +9096,16 @@ var handler10 = async (_provider, args) => {
|
|
|
9030
9096
|
files
|
|
9031
9097
|
};
|
|
9032
9098
|
};
|
|
9033
|
-
var
|
|
9099
|
+
var isAvailable11 = (_provider) => {
|
|
9034
9100
|
return true;
|
|
9035
9101
|
};
|
|
9036
9102
|
var handOver_default = {
|
|
9037
|
-
...
|
|
9038
|
-
handler:
|
|
9039
|
-
isAvailable:
|
|
9103
|
+
...toolInfo11,
|
|
9104
|
+
handler: handler11,
|
|
9105
|
+
isAvailable: isAvailable11
|
|
9040
9106
|
};
|
|
9041
9107
|
// src/tools/removeFile.ts
|
|
9042
|
-
var
|
|
9108
|
+
var toolInfo12 = {
|
|
9043
9109
|
name: "remove_file",
|
|
9044
9110
|
description: "Request to remove a file at the specified path.",
|
|
9045
9111
|
parameters: [
|
|
@@ -9062,7 +9128,7 @@ var toolInfo11 = {
|
|
|
9062
9128
|
}
|
|
9063
9129
|
]
|
|
9064
9130
|
};
|
|
9065
|
-
var
|
|
9131
|
+
var handler12 = async (provider, args) => {
|
|
9066
9132
|
if (!provider.removeFile) {
|
|
9067
9133
|
return {
|
|
9068
9134
|
type: "Error" /* Error */,
|
|
@@ -9076,16 +9142,16 @@ var handler11 = async (provider, args) => {
|
|
|
9076
9142
|
message: `<remove_file_path>${path}</remove_file_path><status>Success</status>`
|
|
9077
9143
|
};
|
|
9078
9144
|
};
|
|
9079
|
-
var
|
|
9145
|
+
var isAvailable12 = (provider) => {
|
|
9080
9146
|
return !!provider.removeFile;
|
|
9081
9147
|
};
|
|
9082
9148
|
var removeFile_default = {
|
|
9083
|
-
...
|
|
9084
|
-
handler:
|
|
9085
|
-
isAvailable:
|
|
9149
|
+
...toolInfo12,
|
|
9150
|
+
handler: handler12,
|
|
9151
|
+
isAvailable: isAvailable12
|
|
9086
9152
|
};
|
|
9087
9153
|
// src/tools/renameFile.ts
|
|
9088
|
-
var
|
|
9154
|
+
var toolInfo13 = {
|
|
9089
9155
|
name: "rename_file",
|
|
9090
9156
|
description: "Request to rename a file from source path to target path.",
|
|
9091
9157
|
parameters: [
|
|
@@ -9118,7 +9184,7 @@ var toolInfo12 = {
|
|
|
9118
9184
|
}
|
|
9119
9185
|
]
|
|
9120
9186
|
};
|
|
9121
|
-
var
|
|
9187
|
+
var handler13 = async (provider, args) => {
|
|
9122
9188
|
if (!provider.renameFile) {
|
|
9123
9189
|
return {
|
|
9124
9190
|
type: "Error" /* Error */,
|
|
@@ -9133,14 +9199,42 @@ var handler12 = async (provider, args) => {
|
|
|
9133
9199
|
message: `<rename_file_path>${targetPath}</rename_file_path><status>Success</status>`
|
|
9134
9200
|
};
|
|
9135
9201
|
};
|
|
9136
|
-
var
|
|
9202
|
+
var isAvailable13 = (provider) => {
|
|
9137
9203
|
return !!provider.renameFile;
|
|
9138
9204
|
};
|
|
9139
9205
|
var renameFile_default = {
|
|
9140
|
-
...
|
|
9141
|
-
handler:
|
|
9142
|
-
isAvailable:
|
|
9206
|
+
...toolInfo13,
|
|
9207
|
+
handler: handler13,
|
|
9208
|
+
isAvailable: isAvailable13
|
|
9209
|
+
};
|
|
9210
|
+
// src/tool.ts
|
|
9211
|
+
var ToolResponseType;
|
|
9212
|
+
((ToolResponseType2) => {
|
|
9213
|
+
ToolResponseType2["Reply"] = "Reply";
|
|
9214
|
+
ToolResponseType2["Exit"] = "Exit";
|
|
9215
|
+
ToolResponseType2["Invalid"] = "Invalid";
|
|
9216
|
+
ToolResponseType2["Error"] = "Error";
|
|
9217
|
+
ToolResponseType2["Interrupted"] = "Interrupted";
|
|
9218
|
+
ToolResponseType2["HandOver"] = "HandOver";
|
|
9219
|
+
ToolResponseType2["Delegate"] = "Delegate";
|
|
9220
|
+
})(ToolResponseType ||= {});
|
|
9221
|
+
var getAvailableTools = (provider2, allTools2, hasAgent) => {
|
|
9222
|
+
const tools = [];
|
|
9223
|
+
for (const tool of allTools2) {
|
|
9224
|
+
if (!hasAgent) {
|
|
9225
|
+
switch (tool.name) {
|
|
9226
|
+
case handOver_default.name:
|
|
9227
|
+
case delegate_default.name:
|
|
9228
|
+
continue;
|
|
9229
|
+
}
|
|
9230
|
+
}
|
|
9231
|
+
if (tool.isAvailable(provider2)) {
|
|
9232
|
+
tools.push(tool);
|
|
9233
|
+
}
|
|
9234
|
+
}
|
|
9235
|
+
return tools;
|
|
9143
9236
|
};
|
|
9237
|
+
|
|
9144
9238
|
// src/Agent/parseAssistantMessage.ts
|
|
9145
9239
|
function parseAssistantMessage(assistantMessage, tools, toolNamePrefix) {
|
|
9146
9240
|
const parameterPrefix = `${toolNamePrefix}parameter_`;
|
|
@@ -9272,17 +9366,21 @@ ${tools.map((tool) => {
|
|
|
9272
9366
|
}).join("")}
|
|
9273
9367
|
# Tool Use Guidelines
|
|
9274
9368
|
|
|
9275
|
-
1. **
|
|
9276
|
-
|
|
9277
|
-
|
|
9278
|
-
|
|
9279
|
-
|
|
9280
|
-
|
|
9281
|
-
|
|
9282
|
-
|
|
9283
|
-
|
|
9284
|
-
|
|
9285
|
-
|
|
9369
|
+
1. **Thinking Tags**: Use \`<thinking>\` tags to clearly outline your thought process *before* using any tools. This includes:
|
|
9370
|
+
* Assessing the current situation and available information.
|
|
9371
|
+
* Defining specific goals and a plan to achieve them.
|
|
9372
|
+
* Justifying the selection of a particular tool.
|
|
9373
|
+
* Explaining how you intend to use the tool and what you expect to achieve.
|
|
9374
|
+
2. **Tool Selection**: Choose one tool at a time per message based on the task and its description. Do not assume a tool’s outcome without explicit confirmation.
|
|
9375
|
+
3. **Formatting**: Formulate tool use only in the specified XML format for each tool.
|
|
9376
|
+
4. **User Response**: Wait for the user’s response after each tool use. Do not proceed until you have their confirmation. The user’s response may include:
|
|
9377
|
+
* Tool success or failure details
|
|
9378
|
+
* Linter errors
|
|
9379
|
+
* Terminal output or other relevant feedback
|
|
9380
|
+
5. **Conciseness**: Never repeat or quote the entire tool command in your final user-facing message. Summarize outcomes clearly and avoid echoing commands verbatim.
|
|
9381
|
+
6. **Brevity**: Respond concisely and move the conversation forward. Do not re-issue the same command or re-trigger tool use without necessity.
|
|
9382
|
+
7. **Iteration**: Follow these steps iteratively, confirming success and addressing issues as you go.
|
|
9383
|
+
8. **Error Handling**: If a tool returns an error, analyze the error message and adjust your approach accordingly. Consider alternative tools or strategies to achieve the desired outcome.
|
|
9286
9384
|
|
|
9287
9385
|
By adhering to these guidelines:
|
|
9288
9386
|
- You maintain clarity without accidentally re-invoking tools.
|
|
@@ -9408,6 +9506,7 @@ var TaskEventKind;
|
|
|
9408
9506
|
TaskEventKind2["ToolError"] = "ToolError";
|
|
9409
9507
|
TaskEventKind2["ToolInterrupted"] = "ToolInterrupted";
|
|
9410
9508
|
TaskEventKind2["ToolHandOver"] = "ToolHandOver";
|
|
9509
|
+
TaskEventKind2["ToolDelegate"] = "ToolDelegate";
|
|
9411
9510
|
TaskEventKind2["UsageExceeded"] = "UsageExceeded";
|
|
9412
9511
|
TaskEventKind2["EndTask"] = "EndTask";
|
|
9413
9512
|
})(TaskEventKind ||= {});
|
|
@@ -9416,9 +9515,10 @@ class AgentBase {
|
|
|
9416
9515
|
ai;
|
|
9417
9516
|
config;
|
|
9418
9517
|
handlers;
|
|
9518
|
+
messages = [];
|
|
9419
9519
|
constructor(name, ai, config) {
|
|
9420
9520
|
this.ai = ai;
|
|
9421
|
-
if (config.agents &&
|
|
9521
|
+
if (config.agents && config.agents.length > 0) {
|
|
9422
9522
|
const agents = agentsPrompt(config.agents, name);
|
|
9423
9523
|
config.systemPrompt += `
|
|
9424
9524
|
${agents}`;
|
|
@@ -9430,89 +9530,80 @@ ${agents}`;
|
|
|
9430
9530
|
}
|
|
9431
9531
|
this.handlers = handlers;
|
|
9432
9532
|
}
|
|
9433
|
-
async
|
|
9434
|
-
|
|
9435
|
-
|
|
9436
|
-
|
|
9437
|
-
}
|
|
9438
|
-
}) {
|
|
9439
|
-
const taskInfo = {
|
|
9440
|
-
messages: [],
|
|
9441
|
-
inputTokens: 0,
|
|
9442
|
-
outputTokens: 0,
|
|
9443
|
-
cacheWriteTokens: 0,
|
|
9444
|
-
cacheReadTokens: 0,
|
|
9445
|
-
totalCost: 0
|
|
9446
|
-
};
|
|
9533
|
+
async#callback(event) {
|
|
9534
|
+
await this.config.callback?.(event);
|
|
9535
|
+
}
|
|
9536
|
+
async startTask({ task, context }) {
|
|
9447
9537
|
let text = `<task>${task}</task>`;
|
|
9448
9538
|
if (context) {
|
|
9449
9539
|
text += `
|
|
9450
9540
|
<context>${context}</context>`;
|
|
9451
9541
|
}
|
|
9452
|
-
callback({ kind: "StartTask" /* StartTask */,
|
|
9453
|
-
return await this.#processLoop(text
|
|
9542
|
+
this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
|
|
9543
|
+
return await this.#processLoop(text);
|
|
9454
9544
|
}
|
|
9455
|
-
async#processLoop(userMessage
|
|
9545
|
+
async#processLoop(userMessage) {
|
|
9456
9546
|
let nextRequest = userMessage;
|
|
9457
|
-
while (
|
|
9547
|
+
while (true) {
|
|
9458
9548
|
if (this.ai.usageMeter.isLimitExceeded().result) {
|
|
9459
|
-
callback({ kind: "UsageExceeded" /* UsageExceeded */,
|
|
9460
|
-
return
|
|
9549
|
+
this.#callback({ kind: "UsageExceeded" /* UsageExceeded */, agent: this });
|
|
9550
|
+
return { type: "UsageExceeded" };
|
|
9461
9551
|
}
|
|
9462
|
-
const response = await this.#request(
|
|
9463
|
-
const
|
|
9464
|
-
if (
|
|
9465
|
-
callback({ kind: "EndTask" /* EndTask */,
|
|
9466
|
-
return
|
|
9552
|
+
const response = await this.#request(nextRequest);
|
|
9553
|
+
const resp = await this.#handleResponse(response);
|
|
9554
|
+
if ("exit" in resp) {
|
|
9555
|
+
this.#callback({ kind: "EndTask" /* EndTask */, agent: this, exitReason: resp.exit });
|
|
9556
|
+
return resp.exit;
|
|
9467
9557
|
}
|
|
9468
|
-
nextRequest =
|
|
9558
|
+
nextRequest = resp.replay;
|
|
9469
9559
|
}
|
|
9470
|
-
callback({ kind: "EndTask" /* EndTask */, info: taskInfo });
|
|
9471
|
-
return [{ type: "Exit" /* Exit */, message: "Task completed successfully" }, taskInfo];
|
|
9472
9560
|
}
|
|
9473
|
-
async continueTask(userMessage
|
|
9474
|
-
|
|
9475
|
-
return await this.#processLoop(userMessage, taskInfo, callback);
|
|
9561
|
+
async continueTask(userMessage) {
|
|
9562
|
+
return await this.#processLoop(userMessage);
|
|
9476
9563
|
}
|
|
9477
|
-
async#request(
|
|
9478
|
-
await callback({ kind: "StartRequest" /* StartRequest */,
|
|
9479
|
-
|
|
9564
|
+
async#request(userMessage) {
|
|
9565
|
+
await this.#callback({ kind: "StartRequest" /* StartRequest */, agent: this, userMessage });
|
|
9566
|
+
this.messages.push({
|
|
9480
9567
|
role: "user",
|
|
9481
9568
|
content: userMessage
|
|
9482
9569
|
});
|
|
9483
|
-
const stream = this.ai.send(this.config.systemPrompt, info.messages);
|
|
9484
9570
|
let currentAssistantMessage = "";
|
|
9485
|
-
|
|
9486
|
-
|
|
9487
|
-
|
|
9488
|
-
|
|
9489
|
-
|
|
9490
|
-
|
|
9491
|
-
|
|
9492
|
-
|
|
9493
|
-
|
|
9494
|
-
|
|
9495
|
-
|
|
9496
|
-
|
|
9497
|
-
|
|
9498
|
-
|
|
9499
|
-
|
|
9500
|
-
|
|
9501
|
-
|
|
9571
|
+
const retryCount = 3;
|
|
9572
|
+
for (let i = 0;i < retryCount; i++) {
|
|
9573
|
+
let gotAnything = false;
|
|
9574
|
+
currentAssistantMessage = "";
|
|
9575
|
+
const stream = this.ai.send(this.config.systemPrompt, this.messages);
|
|
9576
|
+
for await (const chunk of stream) {
|
|
9577
|
+
gotAnything = true;
|
|
9578
|
+
switch (chunk.type) {
|
|
9579
|
+
case "usage":
|
|
9580
|
+
await this.#callback({ kind: "Usage" /* Usage */, agent: this });
|
|
9581
|
+
break;
|
|
9582
|
+
case "text":
|
|
9583
|
+
currentAssistantMessage += chunk.text;
|
|
9584
|
+
await this.#callback({ kind: "Text" /* Text */, agent: this, newText: chunk.text });
|
|
9585
|
+
break;
|
|
9586
|
+
case "reasoning":
|
|
9587
|
+
await this.#callback({ kind: "Reasoning" /* Reasoning */, agent: this, newText: chunk.text });
|
|
9588
|
+
break;
|
|
9589
|
+
}
|
|
9590
|
+
}
|
|
9591
|
+
if (currentAssistantMessage) {
|
|
9592
|
+
break;
|
|
9593
|
+
}
|
|
9594
|
+
if (gotAnything) {
|
|
9595
|
+
throw new Error("No assistant message received");
|
|
9502
9596
|
}
|
|
9503
9597
|
}
|
|
9504
|
-
|
|
9505
|
-
throw new Error("No assistant message received");
|
|
9506
|
-
}
|
|
9507
|
-
info.messages.push({
|
|
9598
|
+
this.messages.push({
|
|
9508
9599
|
role: "assistant",
|
|
9509
9600
|
content: currentAssistantMessage
|
|
9510
9601
|
});
|
|
9511
9602
|
const ret = parseAssistantMessage(currentAssistantMessage, this.config.tools, this.config.toolNamePrefix);
|
|
9512
|
-
await callback({ kind: "EndRequest" /* EndRequest */,
|
|
9603
|
+
await this.#callback({ kind: "EndRequest" /* EndRequest */, agent: this });
|
|
9513
9604
|
return ret;
|
|
9514
9605
|
}
|
|
9515
|
-
async#handleResponse(
|
|
9606
|
+
async#handleResponse(response) {
|
|
9516
9607
|
const toolReponses = [];
|
|
9517
9608
|
outer:
|
|
9518
9609
|
for (const content of response) {
|
|
@@ -9520,54 +9611,65 @@ ${agents}`;
|
|
|
9520
9611
|
case "text":
|
|
9521
9612
|
break;
|
|
9522
9613
|
case "tool_use": {
|
|
9523
|
-
await callback({ kind: "ToolUse" /* ToolUse */,
|
|
9614
|
+
await this.#callback({ kind: "ToolUse" /* ToolUse */, agent: this, tool: content.name });
|
|
9524
9615
|
const toolResp = await this.#invokeTool(content.name, content.params);
|
|
9525
9616
|
switch (toolResp.type) {
|
|
9526
9617
|
case "Reply" /* Reply */:
|
|
9527
|
-
await callback({ kind: "ToolReply" /* ToolReply */,
|
|
9618
|
+
await this.#callback({ kind: "ToolReply" /* ToolReply */, agent: this, tool: content.name });
|
|
9528
9619
|
toolReponses.push({ tool: content.name, response: toolResp.message });
|
|
9529
9620
|
break;
|
|
9530
9621
|
case "Exit" /* Exit */:
|
|
9531
|
-
return
|
|
9622
|
+
return { exit: toolResp };
|
|
9532
9623
|
case "Invalid" /* Invalid */:
|
|
9533
|
-
await callback({ kind: "ToolInvalid" /* ToolInvalid */,
|
|
9624
|
+
await this.#callback({ kind: "ToolInvalid" /* ToolInvalid */, agent: this, tool: content.name });
|
|
9534
9625
|
toolReponses.push({ tool: content.name, response: toolResp.message });
|
|
9535
9626
|
break outer;
|
|
9536
9627
|
case "Error" /* Error */:
|
|
9537
|
-
await callback({ kind: "ToolError" /* ToolError */,
|
|
9628
|
+
await this.#callback({ kind: "ToolError" /* ToolError */, agent: this, tool: content.name });
|
|
9538
9629
|
toolReponses.push({ tool: content.name, response: toolResp.message });
|
|
9539
9630
|
break outer;
|
|
9540
9631
|
case "Interrupted" /* Interrupted */:
|
|
9541
|
-
await callback({ kind: "ToolInterrupted" /* ToolInterrupted */,
|
|
9542
|
-
return
|
|
9632
|
+
await this.#callback({ kind: "ToolInterrupted" /* ToolInterrupted */, agent: this, tool: content.name });
|
|
9633
|
+
return { exit: toolResp };
|
|
9543
9634
|
case "HandOver" /* HandOver */:
|
|
9544
|
-
await callback({
|
|
9635
|
+
await this.#callback({
|
|
9545
9636
|
kind: "ToolHandOver" /* ToolHandOver */,
|
|
9546
|
-
|
|
9637
|
+
agent: this,
|
|
9638
|
+
tool: content.name,
|
|
9639
|
+
agentName: toolResp.agentName,
|
|
9640
|
+
task: toolResp.task,
|
|
9641
|
+
context: toolResp.context,
|
|
9642
|
+
files: toolResp.files
|
|
9643
|
+
});
|
|
9644
|
+
return { exit: toolResp };
|
|
9645
|
+
case "Delegate" /* Delegate */:
|
|
9646
|
+
await this.#callback({
|
|
9647
|
+
kind: "ToolDelegate" /* ToolDelegate */,
|
|
9648
|
+
agent: this,
|
|
9547
9649
|
tool: content.name,
|
|
9548
9650
|
agentName: toolResp.agentName,
|
|
9549
9651
|
task: toolResp.task,
|
|
9550
9652
|
context: toolResp.context,
|
|
9551
9653
|
files: toolResp.files
|
|
9552
9654
|
});
|
|
9553
|
-
return
|
|
9655
|
+
return { exit: toolResp };
|
|
9554
9656
|
}
|
|
9555
9657
|
break;
|
|
9556
9658
|
}
|
|
9557
9659
|
}
|
|
9558
9660
|
}
|
|
9559
9661
|
if (toolReponses.length === 0 && !this.config.interactive) {
|
|
9560
|
-
return
|
|
9662
|
+
return { replay: responsePrompts.requireUseTool };
|
|
9561
9663
|
}
|
|
9562
9664
|
const finalResp = toolReponses.map(({ tool, response: response2 }) => responsePrompts.toolResults(tool, response2)).join(`
|
|
9563
9665
|
|
|
9564
9666
|
`);
|
|
9565
|
-
return
|
|
9667
|
+
return { replay: finalResp };
|
|
9566
9668
|
}
|
|
9567
9669
|
async#invokeTool(name, args) {
|
|
9568
9670
|
try {
|
|
9569
|
-
const
|
|
9570
|
-
if (!
|
|
9671
|
+
const handler14 = this.handlers[name]?.handler;
|
|
9672
|
+
if (!handler14) {
|
|
9571
9673
|
return {
|
|
9572
9674
|
type: "Error" /* Error */,
|
|
9573
9675
|
message: responsePrompts.errorInvokeTool(name, "Tool not found"),
|
|
@@ -9578,7 +9680,7 @@ ${agents}`;
|
|
|
9578
9680
|
if (resp) {
|
|
9579
9681
|
return resp;
|
|
9580
9682
|
}
|
|
9581
|
-
return await
|
|
9683
|
+
return await handler14(this.config.provider, args);
|
|
9582
9684
|
} catch (error) {
|
|
9583
9685
|
return {
|
|
9584
9686
|
type: "Error" /* Error */,
|
|
@@ -9633,12 +9735,13 @@ class AnalyzerAgent extends AgentBase {
|
|
|
9633
9735
|
askFollowupQuestion_default,
|
|
9634
9736
|
attemptCompletion_default,
|
|
9635
9737
|
handOver_default,
|
|
9738
|
+
delegate_default,
|
|
9636
9739
|
listCodeDefinitionNames_default,
|
|
9637
9740
|
listFiles_default,
|
|
9638
9741
|
readFile_default,
|
|
9639
9742
|
searchFiles_default
|
|
9640
9743
|
];
|
|
9641
|
-
const tools = getAvailableTools(options.provider, agentTools);
|
|
9744
|
+
const tools = getAvailableTools(options.provider, agentTools, (options.agents?.length ?? 0) > 0);
|
|
9642
9745
|
const toolNamePrefix = "tool_";
|
|
9643
9746
|
const systemPrompt = fullSystemPrompt({
|
|
9644
9747
|
os: options.os
|
|
@@ -9650,7 +9753,8 @@ class AnalyzerAgent extends AgentBase {
|
|
|
9650
9753
|
provider: options.provider,
|
|
9651
9754
|
interactive: options.interactive,
|
|
9652
9755
|
agents: options.agents,
|
|
9653
|
-
scripts: options.scripts
|
|
9756
|
+
scripts: options.scripts,
|
|
9757
|
+
callback: options.callback
|
|
9654
9758
|
});
|
|
9655
9759
|
}
|
|
9656
9760
|
onBeforeInvokeTool() {
|
|
@@ -9679,7 +9783,7 @@ You are the **Architect** agent, responsible for:
|
|
|
9679
9783
|
3. **File Reading** – Use the provided tools to gather information from these files.
|
|
9680
9784
|
4. **Implementation Plan** – Draft a concise plan detailing steps, resources, and dependencies.
|
|
9681
9785
|
5. **Review & Improve** – Evaluate and refine the plan.
|
|
9682
|
-
6. **Handover** – Provide the final plan, context, and files to the **Coder** agent.
|
|
9786
|
+
6. **Handover/Delegate** – Provide the final plan, context, and files to the **Coder** agent.
|
|
9683
9787
|
|
|
9684
9788
|
> **Note**: The **Architect** agent must not make any direct modifications. Your role is limited to creating the implementation plan and handing it over to the **Coder** agent, who will perform any actual changes.
|
|
9685
9789
|
|
|
@@ -9712,7 +9816,7 @@ You are the **Architect** agent, responsible for:
|
|
|
9712
9816
|
- Check the plan for consistency, clarity, and feasibility.
|
|
9713
9817
|
- Make adjustments or refinements to ensure accuracy and efficiency.
|
|
9714
9818
|
|
|
9715
|
-
6. **Handover**
|
|
9819
|
+
6. **Handover/Delegate**
|
|
9716
9820
|
- Deliver the final implementation plan, context, and relevant files to the **Coder** agent.
|
|
9717
9821
|
- Provide any additional instructions or clarifications needed for successful implementation.
|
|
9718
9822
|
${toolUsePrompt(tools, toolNamePrefix)}
|
|
@@ -9731,12 +9835,13 @@ class ArchitectAgent extends AgentBase {
|
|
|
9731
9835
|
askFollowupQuestion_default,
|
|
9732
9836
|
attemptCompletion_default,
|
|
9733
9837
|
handOver_default,
|
|
9838
|
+
delegate_default,
|
|
9734
9839
|
listCodeDefinitionNames_default,
|
|
9735
9840
|
listFiles_default,
|
|
9736
9841
|
readFile_default,
|
|
9737
9842
|
searchFiles_default
|
|
9738
9843
|
];
|
|
9739
|
-
const tools = getAvailableTools(options.provider, agentTools);
|
|
9844
|
+
const tools = getAvailableTools(options.provider, agentTools, (options.agents?.length ?? 0) > 0);
|
|
9740
9845
|
const toolNamePrefix = "tool_";
|
|
9741
9846
|
const systemPrompt = fullSystemPrompt2({
|
|
9742
9847
|
os: options.os
|
|
@@ -9748,7 +9853,8 @@ class ArchitectAgent extends AgentBase {
|
|
|
9748
9853
|
provider: options.provider,
|
|
9749
9854
|
interactive: options.interactive,
|
|
9750
9855
|
agents: options.agents,
|
|
9751
|
-
scripts: options.scripts
|
|
9856
|
+
scripts: options.scripts,
|
|
9857
|
+
callback: options.callback
|
|
9752
9858
|
});
|
|
9753
9859
|
}
|
|
9754
9860
|
onBeforeInvokeTool() {
|
|
@@ -9883,7 +9989,7 @@ ${interactiveMode(interactive)}
|
|
|
9883
9989
|
class CoderAgent extends AgentBase {
|
|
9884
9990
|
constructor(options) {
|
|
9885
9991
|
const combinedTools = [...options.additionalTools ?? [], ...Object.values(exports_allTools)];
|
|
9886
|
-
const tools = getAvailableTools(options.provider, combinedTools);
|
|
9992
|
+
const tools = getAvailableTools(options.provider, combinedTools, (options.agents?.length ?? 0) > 0);
|
|
9887
9993
|
const toolNamePrefix = "tool_";
|
|
9888
9994
|
const systemPrompt = fullSystemPrompt3({
|
|
9889
9995
|
os: options.os
|
|
@@ -9895,7 +10001,8 @@ class CoderAgent extends AgentBase {
|
|
|
9895
10001
|
provider: options.provider,
|
|
9896
10002
|
interactive: options.interactive,
|
|
9897
10003
|
agents: options.agents,
|
|
9898
|
-
scripts: options.scripts
|
|
10004
|
+
scripts: options.scripts,
|
|
10005
|
+
callback: options.callback
|
|
9899
10006
|
});
|
|
9900
10007
|
}
|
|
9901
10008
|
async onBeforeInvokeTool(name, args) {
|
|
@@ -9956,48 +10063,140 @@ var coderAgentInfo = {
|
|
|
9956
10063
|
// src/Agent/MultiAgent.ts
|
|
9957
10064
|
class MultiAgent {
|
|
9958
10065
|
#config;
|
|
9959
|
-
#
|
|
10066
|
+
#agents = [];
|
|
9960
10067
|
constructor(config) {
|
|
9961
10068
|
this.#config = config;
|
|
9962
10069
|
}
|
|
9963
|
-
|
|
9964
|
-
|
|
10070
|
+
async#handleTaskResult(exitReason) {
|
|
10071
|
+
switch (exitReason.type) {
|
|
10072
|
+
case "HandOver" /* HandOver */: {
|
|
10073
|
+
this.#agents.pop();
|
|
10074
|
+
const newContext = await this.#config.getContext?.(exitReason.agentName, exitReason.context, exitReason.files);
|
|
10075
|
+
return await this.#startTask(exitReason.agentName, exitReason.task, newContext);
|
|
10076
|
+
}
|
|
10077
|
+
case "Delegate" /* Delegate */: {
|
|
10078
|
+
const newContext = await this.#config.getContext?.(exitReason.agentName, exitReason.context, exitReason.files);
|
|
10079
|
+
const delegateResult = await this.#startTask(exitReason.agentName, exitReason.task, newContext);
|
|
10080
|
+
switch (delegateResult.type) {
|
|
10081
|
+
case "HandOver" /* HandOver */:
|
|
10082
|
+
case "Delegate" /* Delegate */:
|
|
10083
|
+
console.warn("Unexpected exit reason", delegateResult);
|
|
10084
|
+
break;
|
|
10085
|
+
case "Interrupted" /* Interrupted */:
|
|
10086
|
+
return delegateResult;
|
|
10087
|
+
case "Exit" /* Exit */:
|
|
10088
|
+
return this.continueTask(delegateResult.message);
|
|
10089
|
+
}
|
|
10090
|
+
return delegateResult;
|
|
10091
|
+
}
|
|
10092
|
+
case "Interrupted" /* Interrupted */:
|
|
10093
|
+
case "Exit" /* Exit */:
|
|
10094
|
+
this.#agents.pop();
|
|
10095
|
+
return exitReason;
|
|
10096
|
+
default:
|
|
10097
|
+
return exitReason;
|
|
10098
|
+
}
|
|
9965
10099
|
}
|
|
9966
|
-
async#startTask(agentName, task, context
|
|
9967
|
-
|
|
9968
|
-
|
|
10100
|
+
async#startTask(agentName, task, context) {
|
|
10101
|
+
const newAgent = await this.#config.createAgent(agentName);
|
|
10102
|
+
this.#agents.push(newAgent);
|
|
10103
|
+
const exitReason = await newAgent.startTask({
|
|
9969
10104
|
task,
|
|
9970
|
-
context
|
|
9971
|
-
callback
|
|
10105
|
+
context
|
|
9972
10106
|
});
|
|
9973
|
-
|
|
9974
|
-
return [exitReason, info];
|
|
9975
|
-
}
|
|
9976
|
-
if (exitReason.type === "HandOver") {
|
|
9977
|
-
const context2 = await this.#config.getContext?.(agentName, exitReason.context, exitReason.files);
|
|
9978
|
-
return await this.#startTask(exitReason.agentName, exitReason.task, context2, callback);
|
|
9979
|
-
}
|
|
9980
|
-
return [exitReason, info];
|
|
10107
|
+
return await this.#handleTaskResult(exitReason);
|
|
9981
10108
|
}
|
|
9982
10109
|
async startTask(options) {
|
|
9983
|
-
if (this.#
|
|
10110
|
+
if (this.#agents.length > 0) {
|
|
9984
10111
|
throw new Error("An active agent already exists");
|
|
9985
10112
|
}
|
|
9986
|
-
return this.#startTask(options.agentName, options.task, options.context
|
|
10113
|
+
return this.#startTask(options.agentName, options.task, options.context);
|
|
9987
10114
|
}
|
|
9988
|
-
async continueTask(userMessage
|
|
9989
|
-
|
|
9990
|
-
if (!this.#activeAgent) {
|
|
10115
|
+
async continueTask(userMessage) {
|
|
10116
|
+
if (!this.#agents.length) {
|
|
9991
10117
|
throw new Error("No active agent");
|
|
9992
10118
|
}
|
|
9993
|
-
|
|
10119
|
+
const exitReason = await this.#agents[this.#agents.length - 1].continueTask(userMessage);
|
|
10120
|
+
return await this.#handleTaskResult(exitReason);
|
|
9994
10121
|
}
|
|
9995
10122
|
}
|
|
9996
10123
|
|
|
9997
10124
|
// src/Agent/index.ts
|
|
9998
10125
|
var allAgents = [architectAgentInfo, coderAgentInfo, analyzerAgentInfo];
|
|
10126
|
+
// src/AiTool/createNewProject.ts
|
|
10127
|
+
var prompt = `You are an AiTool designed to assist users in creating new projects. Follow these guidelines:
|
|
10128
|
+
|
|
10129
|
+
1. **Gather Information:**
|
|
10130
|
+
- Begin by asking the user for essential project details, including:
|
|
10131
|
+
- Project type (e.g., web, mobile, desktop, etc.)
|
|
10132
|
+
- Desired programming languages
|
|
10133
|
+
- Preferred frameworks or libraries
|
|
10134
|
+
- Build tools and package manager preferences
|
|
10135
|
+
- Testing frameworks and patterns
|
|
10136
|
+
- Code style and linting preferences
|
|
10137
|
+
- Any additional specifications or requirements
|
|
10138
|
+
|
|
10139
|
+
2. **Clarification & Confirmation:**
|
|
10140
|
+
- Do not make any decisions or assumptions on behalf of the user.
|
|
10141
|
+
- Ask clarifying questions if any detail is ambiguous.
|
|
10142
|
+
- Confirm each piece of information with the user before proceeding to the next step.
|
|
10143
|
+
|
|
10144
|
+
3. **Avoid Redundancy:**
|
|
10145
|
+
- Do not repeat questions or details that have already been confirmed.
|
|
10146
|
+
- Keep interactions concise and focused on gathering complete and accurate details.
|
|
10147
|
+
|
|
10148
|
+
4. **Generate Configuration:**
|
|
10149
|
+
- Based on the collected information, generate a .polkacodes.yml configuration file that includes:
|
|
10150
|
+
- scripts section with common development commands (test, format, check, etc.)
|
|
10151
|
+
- rules section reflecting project conventions and tools
|
|
10152
|
+
- excludeFiles section for sensitive and generated files
|
|
10153
|
+
- Example structure:
|
|
10154
|
+
\`\`\`yaml
|
|
10155
|
+
scripts:
|
|
10156
|
+
test:
|
|
10157
|
+
command: "[test-command]"
|
|
10158
|
+
description: "Run tests"
|
|
10159
|
+
format:
|
|
10160
|
+
command: "[format-command]"
|
|
10161
|
+
description: "Format code"
|
|
10162
|
+
check:
|
|
10163
|
+
command: "[check-command]"
|
|
10164
|
+
description: "Check code"
|
|
10165
|
+
|
|
10166
|
+
rules:
|
|
10167
|
+
- "[package-manager-rule]"
|
|
10168
|
+
- "[testing-framework-rule]"
|
|
10169
|
+
- "[code-style-rule]"
|
|
10170
|
+
- "[other-rule]"
|
|
10171
|
+
|
|
10172
|
+
excludeFiles:
|
|
10173
|
+
- ".env"
|
|
10174
|
+
- ".env.*"
|
|
10175
|
+
\`\`\`
|
|
10176
|
+
|
|
10177
|
+
5. **Handover to Coder Agent:**
|
|
10178
|
+
- Once all required information is collected and validated by the user, compile:
|
|
10179
|
+
1. The final project specifications
|
|
10180
|
+
2. The .polkacodes.yml configuration content
|
|
10181
|
+
- Clearly hand over these details to the coder agent, instructing them to:
|
|
10182
|
+
1. Create the new project based on the confirmed specifications
|
|
10183
|
+
2. Include the .polkacodes.yml file in the project root
|
|
10184
|
+
3. Ensure all specified tools and configurations are properly set up`;
|
|
10185
|
+
var createNewProject_default = {
|
|
10186
|
+
name: "createNewProject",
|
|
10187
|
+
description: "Creates a new project",
|
|
10188
|
+
prompt,
|
|
10189
|
+
formatInput: (params) => {
|
|
10190
|
+
return `<project_name>${params}</project_name>`;
|
|
10191
|
+
},
|
|
10192
|
+
parseOutput: (output) => {
|
|
10193
|
+
return output.trim();
|
|
10194
|
+
},
|
|
10195
|
+
agent: "architect"
|
|
10196
|
+
};
|
|
10197
|
+
|
|
9999
10198
|
// src/AiTool/generateGitCommitMessage.ts
|
|
10000
|
-
var
|
|
10199
|
+
var prompt2 = `
|
|
10001
10200
|
You are an advanced assistant specialized in creating concise and accurate Git commit messages. When you receive:
|
|
10002
10201
|
- A Git diff inside the <tool_input> tag.
|
|
10003
10202
|
- Additional user-supplied context inside the <tool_input_context> tag (if any).
|
|
@@ -10032,7 +10231,7 @@ Follow the same structure for any new input. Never repeat questions; focus on ge
|
|
|
10032
10231
|
var generateGitCommitMessage_default = {
|
|
10033
10232
|
name: "generateGitCommitMessage",
|
|
10034
10233
|
description: "Generates git commit messages from git diff output",
|
|
10035
|
-
prompt,
|
|
10234
|
+
prompt: prompt2,
|
|
10036
10235
|
formatInput: (params) => {
|
|
10037
10236
|
let ret = `<tool_input>
|
|
10038
10237
|
${params.diff}
|
|
@@ -10057,7 +10256,7 @@ ${output}`);
|
|
|
10057
10256
|
};
|
|
10058
10257
|
|
|
10059
10258
|
// src/AiTool/generateGithubPullRequestDetails.ts
|
|
10060
|
-
var
|
|
10259
|
+
var prompt3 = `
|
|
10061
10260
|
# Generate Github Pull Request Details
|
|
10062
10261
|
|
|
10063
10262
|
You are given:
|
|
@@ -10141,7 +10340,7 @@ Use the above format whenever you receive <tool_input> that may include a branch
|
|
|
10141
10340
|
var generateGithubPullRequestDetails_default = {
|
|
10142
10341
|
name: "generateGithubPullRequestDetails",
|
|
10143
10342
|
description: "Generates a GitHub pull request title and description from git commits",
|
|
10144
|
-
prompt:
|
|
10343
|
+
prompt: prompt3,
|
|
10145
10344
|
formatInput: (params) => {
|
|
10146
10345
|
return `<tool_input>
|
|
10147
10346
|
<tool_input_branch_name>${params.branchName}</tool_input_branch_name>${params.context ? `
|
|
@@ -10174,7 +10373,7 @@ ${output}`);
|
|
|
10174
10373
|
};
|
|
10175
10374
|
|
|
10176
10375
|
// src/AiTool/generateProjectConfig.ts
|
|
10177
|
-
var
|
|
10376
|
+
var prompt4 = `You are an analyzer agent responsible for examining project files and generating appropriate polkacodes configuration. Your task is to:
|
|
10178
10377
|
|
|
10179
10378
|
1. Read and analyze the provided files using tool_read_file to understand:
|
|
10180
10379
|
- Build tools and package manager (e.g., bun, npm)
|
|
@@ -10241,12 +10440,9 @@ The configuration should accurately reflect the project's structure, tools, and
|
|
|
10241
10440
|
var generateProjectConfig_default = {
|
|
10242
10441
|
name: "generateProjectConfig",
|
|
10243
10442
|
description: "Analyzes project files to generate polkacodes config sections",
|
|
10244
|
-
prompt:
|
|
10245
|
-
formatInput: (
|
|
10246
|
-
return
|
|
10247
|
-
${params.join(`
|
|
10248
|
-
`)}
|
|
10249
|
-
</tool_input>`;
|
|
10443
|
+
prompt: prompt4,
|
|
10444
|
+
formatInput: () => {
|
|
10445
|
+
return "";
|
|
10250
10446
|
},
|
|
10251
10447
|
parseOutput: (output) => {
|
|
10252
10448
|
return output.trim();
|
|
@@ -10264,15 +10460,14 @@ var executeTool = async (definition, ai, params) => {
|
|
|
10264
10460
|
usage
|
|
10265
10461
|
};
|
|
10266
10462
|
};
|
|
10267
|
-
var executeAgentTool = async (definition, agent, params
|
|
10463
|
+
var executeAgentTool = async (definition, agent, params) => {
|
|
10268
10464
|
if (!definition.agent) {
|
|
10269
10465
|
throw new Error("Agent not specified");
|
|
10270
10466
|
}
|
|
10271
|
-
const
|
|
10467
|
+
const exitReason = await agent.startTask({
|
|
10272
10468
|
agentName: definition.agent,
|
|
10273
10469
|
task: definition.prompt,
|
|
10274
|
-
context: definition.formatInput(params)
|
|
10275
|
-
callback
|
|
10470
|
+
context: definition.formatInput(params)
|
|
10276
10471
|
});
|
|
10277
10472
|
if (exitReason.type === "Exit" /* Exit */) {
|
|
10278
10473
|
return definition.parseOutput(exitReason.message);
|
|
@@ -10285,13 +10480,14 @@ var makeTool = (definition) => {
|
|
|
10285
10480
|
};
|
|
10286
10481
|
};
|
|
10287
10482
|
var makeAgentTool = (definition) => {
|
|
10288
|
-
return async (agent, params
|
|
10289
|
-
return executeAgentTool(definition, agent, params
|
|
10483
|
+
return async (agent, params) => {
|
|
10484
|
+
return executeAgentTool(definition, agent, params);
|
|
10290
10485
|
};
|
|
10291
10486
|
};
|
|
10292
10487
|
var generateGitCommitMessage = makeTool(generateGitCommitMessage_default);
|
|
10293
10488
|
var generateGithubPullRequestDetails = makeTool(generateGithubPullRequestDetails_default);
|
|
10294
10489
|
var generateProjectConfig = makeAgentTool(generateProjectConfig_default);
|
|
10490
|
+
var createNewProject = makeAgentTool(createNewProject_default);
|
|
10295
10491
|
export {
|
|
10296
10492
|
writeToFile_default as writeToFile,
|
|
10297
10493
|
searchFiles_default as searchFiles,
|
|
@@ -10312,10 +10508,12 @@ export {
|
|
|
10312
10508
|
executeTool,
|
|
10313
10509
|
executeCommand_default as executeCommand,
|
|
10314
10510
|
executeAgentTool,
|
|
10511
|
+
delegate_default as delegate,
|
|
10315
10512
|
defaultModels,
|
|
10316
10513
|
deepSeekModels,
|
|
10317
10514
|
deepSeekDefaultModelId,
|
|
10318
10515
|
createService,
|
|
10516
|
+
createNewProject,
|
|
10319
10517
|
coderAgentInfo,
|
|
10320
10518
|
attemptCompletion_default as attemptCompletion,
|
|
10321
10519
|
askFollowupQuestion_default as askFollowupQuestion,
|