@polka-codes/runner 0.7.23 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +80 -35
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -25790,7 +25790,7 @@ var {
|
|
|
25790
25790
|
Help
|
|
25791
25791
|
} = import__.default;
|
|
25792
25792
|
// package.json
|
|
25793
|
-
var version = "0.
|
|
25793
|
+
var version = "0.8.0";
|
|
25794
25794
|
|
|
25795
25795
|
// src/runner.ts
|
|
25796
25796
|
import { execSync } from "node:child_process";
|
|
@@ -36359,11 +36359,10 @@ class AgentBase {
|
|
|
36359
36359
|
ai;
|
|
36360
36360
|
config;
|
|
36361
36361
|
handlers;
|
|
36362
|
-
#messages;
|
|
36362
|
+
#messages = [];
|
|
36363
36363
|
#originalTask;
|
|
36364
|
-
constructor(name2, ai, config
|
|
36364
|
+
constructor(name2, ai, config) {
|
|
36365
36365
|
this.ai = ai;
|
|
36366
|
-
this.#messages = messages;
|
|
36367
36366
|
if (config.agents && config.agents.length > 0) {
|
|
36368
36367
|
const agents = agentsPrompt(config.agents, name2);
|
|
36369
36368
|
config.systemPrompt += `
|
|
@@ -36380,7 +36379,7 @@ ${agents}`;
|
|
|
36380
36379
|
return this.#messages;
|
|
36381
36380
|
}
|
|
36382
36381
|
setMessages(messages) {
|
|
36383
|
-
this.#messages = messages;
|
|
36382
|
+
this.#messages = [...messages];
|
|
36384
36383
|
}
|
|
36385
36384
|
async#callback(event) {
|
|
36386
36385
|
await this.config.callback?.(event);
|
|
@@ -36390,19 +36389,13 @@ ${agents}`;
|
|
|
36390
36389
|
this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
|
|
36391
36390
|
return await this.#processLoop(prompt);
|
|
36392
36391
|
}
|
|
36393
|
-
async step(
|
|
36394
|
-
if (messages) {
|
|
36395
|
-
this.#messages = messages;
|
|
36396
|
-
}
|
|
36392
|
+
async step(prompt) {
|
|
36397
36393
|
if (this.#messages.length === 0) {
|
|
36398
36394
|
this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
|
|
36399
36395
|
}
|
|
36400
|
-
return await this.#request(
|
|
36396
|
+
return await this.#request(prompt);
|
|
36401
36397
|
}
|
|
36402
|
-
async handleStepResponse(response
|
|
36403
|
-
if (messages) {
|
|
36404
|
-
this.#messages = messages;
|
|
36405
|
-
}
|
|
36398
|
+
async handleStepResponse(response) {
|
|
36406
36399
|
return this.#handleResponse(response);
|
|
36407
36400
|
}
|
|
36408
36401
|
async#processLoop(userMessage) {
|
|
@@ -54542,6 +54535,11 @@ var wsOutgoingMessageSchema = z3.discriminatedUnion("type", [
|
|
|
54542
54535
|
response: z3.string()
|
|
54543
54536
|
}))
|
|
54544
54537
|
}),
|
|
54538
|
+
z3.object({
|
|
54539
|
+
type: z3.literal("pending_tools_response_completed"),
|
|
54540
|
+
step: z3.number(),
|
|
54541
|
+
index: z3.number()
|
|
54542
|
+
}),
|
|
54545
54543
|
z3.object({
|
|
54546
54544
|
type: z3.literal("file"),
|
|
54547
54545
|
path: z3.string(),
|
|
@@ -54749,29 +54747,71 @@ class Runner {
|
|
|
54749
54747
|
console.log(`Received tool requests for step ${message.step}:`, message.requests.map((r2) => r2.tool));
|
|
54750
54748
|
const responses = [];
|
|
54751
54749
|
for (const request of message.requests) {
|
|
54752
|
-
|
|
54753
|
-
|
|
54754
|
-
|
|
54755
|
-
|
|
54756
|
-
|
|
54757
|
-
|
|
54758
|
-
|
|
54759
|
-
|
|
54760
|
-
|
|
54761
|
-
|
|
54750
|
+
const fn = async () => {
|
|
54751
|
+
try {
|
|
54752
|
+
console.log(`Executing tool: ${request.tool} with params:`, request.params);
|
|
54753
|
+
if (request.params.overridenAgent === "coder" && this.provider.executeCommand) {
|
|
54754
|
+
const { format, check, test } = request.params;
|
|
54755
|
+
if (format) {
|
|
54756
|
+
try {
|
|
54757
|
+
await this.provider.executeCommand(format, false);
|
|
54758
|
+
} catch (error) {
|
|
54759
|
+
console.warn(`Failed to format code using command: ${format}`, error);
|
|
54760
|
+
}
|
|
54761
|
+
}
|
|
54762
|
+
if (check) {
|
|
54763
|
+
try {
|
|
54764
|
+
const { exitCode, stdout, stderr } = await this.provider.executeCommand(check, false);
|
|
54765
|
+
if (exitCode !== 0) {
|
|
54766
|
+
return responsePrompts.commandResult(check, exitCode, stdout, stderr);
|
|
54767
|
+
}
|
|
54768
|
+
} catch (error) {
|
|
54769
|
+
console.warn(`Failed to check code using command: ${check}`, error);
|
|
54770
|
+
}
|
|
54771
|
+
}
|
|
54772
|
+
if (test) {
|
|
54773
|
+
try {
|
|
54774
|
+
const { exitCode, stdout, stderr } = await this.provider.executeCommand(test, false);
|
|
54775
|
+
if (exitCode !== 0) {
|
|
54776
|
+
return responsePrompts.commandResult(test, exitCode, stdout, stderr);
|
|
54777
|
+
}
|
|
54778
|
+
} catch (error) {
|
|
54779
|
+
console.warn(`Failed to test code using command: ${test}`, error);
|
|
54780
|
+
}
|
|
54781
|
+
}
|
|
54782
|
+
return {
|
|
54783
|
+
type: "exit"
|
|
54784
|
+
};
|
|
54762
54785
|
}
|
|
54763
|
-
|
|
54764
|
-
|
|
54786
|
+
const tool2 = this.availableTools[request.tool];
|
|
54787
|
+
if (tool2) {
|
|
54788
|
+
const resp = await tool2.handler(this.provider, request.params);
|
|
54789
|
+
if (resp.type === "Reply" /* Reply */) {
|
|
54790
|
+
return responsePrompts.toolResults(request.tool, resp.message);
|
|
54791
|
+
}
|
|
54792
|
+
return responsePrompts.errorInvokeTool(request.tool, `Unexpected tool response: ${JSON.stringify(resp)}`);
|
|
54793
|
+
}
|
|
54794
|
+
return responsePrompts.errorInvokeTool(request.tool, "Tool not available");
|
|
54795
|
+
} catch (toolError) {
|
|
54796
|
+
console.error(`Error executing tool ${request.tool}:`, toolError);
|
|
54797
|
+
return responsePrompts.errorInvokeTool(request.tool, toolError);
|
|
54765
54798
|
}
|
|
54766
|
-
}
|
|
54767
|
-
|
|
54768
|
-
|
|
54799
|
+
};
|
|
54800
|
+
const respMsg = await fn();
|
|
54801
|
+
if (typeof respMsg === "string") {
|
|
54802
|
+
responses.push({
|
|
54803
|
+
index: request.index,
|
|
54804
|
+
tool: request.tool,
|
|
54805
|
+
response: respMsg
|
|
54806
|
+
});
|
|
54807
|
+
} else if (respMsg.type === "exit") {
|
|
54808
|
+
this.wsManager.sendMessage({
|
|
54809
|
+
type: "pending_tools_response_completed",
|
|
54810
|
+
step: message.step,
|
|
54811
|
+
index: request.index
|
|
54812
|
+
});
|
|
54813
|
+
return;
|
|
54769
54814
|
}
|
|
54770
|
-
responses.push({
|
|
54771
|
-
index: request.index,
|
|
54772
|
-
tool: request.tool,
|
|
54773
|
-
response: respMsg
|
|
54774
|
-
});
|
|
54775
54815
|
}
|
|
54776
54816
|
this.wsManager.sendMessage({
|
|
54777
54817
|
type: "pending_tools_response",
|
|
@@ -54827,7 +54867,7 @@ class Runner {
|
|
|
54827
54867
|
if (statusCode.startsWith("R")) {
|
|
54828
54868
|
const parts2 = path4.split(" -> ");
|
|
54829
54869
|
if (parts2.length === 2) {
|
|
54830
|
-
const [
|
|
54870
|
+
const [oldPath, newPath] = parts2;
|
|
54831
54871
|
changes.push({
|
|
54832
54872
|
status: "renamed",
|
|
54833
54873
|
path: newPath,
|
|
@@ -54860,6 +54900,11 @@ class Runner {
|
|
|
54860
54900
|
console.log(`Sent content for file: ${path4}`);
|
|
54861
54901
|
} else {
|
|
54862
54902
|
console.error(`File not found: ${path4}`);
|
|
54903
|
+
this.wsManager.sendMessage({
|
|
54904
|
+
type: "error",
|
|
54905
|
+
message: "File not found",
|
|
54906
|
+
details: path4
|
|
54907
|
+
});
|
|
54863
54908
|
}
|
|
54864
54909
|
} catch (error) {
|
|
54865
54910
|
console.error(`Error reading file ${path4}:`, error);
|