@polka-codes/runner 0.8.24 → 0.8.25
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 +87 -22
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -32748,7 +32748,7 @@ var {
|
|
|
32748
32748
|
Help
|
|
32749
32749
|
} = import__.default;
|
|
32750
32750
|
// package.json
|
|
32751
|
-
var version = "0.8.
|
|
32751
|
+
var version = "0.8.25";
|
|
32752
32752
|
|
|
32753
32753
|
// src/runner.ts
|
|
32754
32754
|
import { execSync } from "node:child_process";
|
|
@@ -32763,14 +32763,19 @@ import { join as join2 } from "node:path";
|
|
|
32763
32763
|
class AiServiceBase {
|
|
32764
32764
|
usageMeter;
|
|
32765
32765
|
options;
|
|
32766
|
+
#abortController;
|
|
32766
32767
|
constructor(options) {
|
|
32767
32768
|
this.options = options;
|
|
32768
32769
|
this.usageMeter = options.usageMeter;
|
|
32769
32770
|
}
|
|
32771
|
+
abort() {
|
|
32772
|
+
this.#abortController?.abort();
|
|
32773
|
+
}
|
|
32770
32774
|
async* send(systemPrompt, messages) {
|
|
32771
32775
|
this.usageMeter.checkLimit();
|
|
32772
32776
|
this.usageMeter.incrementMessageCount();
|
|
32773
|
-
|
|
32777
|
+
this.#abortController = new AbortController;
|
|
32778
|
+
const stream = this.sendImpl(systemPrompt, messages, this.#abortController.signal);
|
|
32774
32779
|
for await (const chunk of stream) {
|
|
32775
32780
|
switch (chunk.type) {
|
|
32776
32781
|
case "usage":
|
|
@@ -32783,7 +32788,8 @@ class AiServiceBase {
|
|
|
32783
32788
|
async request(systemPrompt, messages) {
|
|
32784
32789
|
this.usageMeter.checkLimit();
|
|
32785
32790
|
this.usageMeter.incrementMessageCount();
|
|
32786
|
-
|
|
32791
|
+
this.#abortController = new AbortController;
|
|
32792
|
+
const stream = this.sendImpl(systemPrompt, messages, this.#abortController.signal);
|
|
32787
32793
|
const usage = {
|
|
32788
32794
|
inputTokens: 0,
|
|
32789
32795
|
outputTokens: 0,
|
|
@@ -36288,7 +36294,7 @@ class AnthropicService extends AiServiceBase {
|
|
|
36288
36294
|
info: anthropicModels[id] ?? anthropicModels[anthropicDefaultModelId]
|
|
36289
36295
|
};
|
|
36290
36296
|
}
|
|
36291
|
-
async* sendImpl(systemPrompt, messages) {
|
|
36297
|
+
async* sendImpl(systemPrompt, messages, signal) {
|
|
36292
36298
|
let stream;
|
|
36293
36299
|
const modelId = this.model.id;
|
|
36294
36300
|
const cacheControl = this.#options.enableCache ? { type: "ephemeral" } : undefined;
|
|
@@ -36346,7 +36352,7 @@ class AnthropicService extends AiServiceBase {
|
|
|
36346
36352
|
return message;
|
|
36347
36353
|
}),
|
|
36348
36354
|
stream: true
|
|
36349
|
-
});
|
|
36355
|
+
}, { signal });
|
|
36350
36356
|
break;
|
|
36351
36357
|
}
|
|
36352
36358
|
default: {
|
|
@@ -36357,7 +36363,7 @@ class AnthropicService extends AiServiceBase {
|
|
|
36357
36363
|
system: [{ text: systemPrompt, type: "text" }],
|
|
36358
36364
|
messages,
|
|
36359
36365
|
stream: true
|
|
36360
|
-
});
|
|
36366
|
+
}, { signal });
|
|
36361
36367
|
break;
|
|
36362
36368
|
}
|
|
36363
36369
|
}
|
|
@@ -41715,7 +41721,7 @@ class DeepSeekService extends AiServiceBase {
|
|
|
41715
41721
|
info: deepSeekModels[id] ?? deepSeekModels[deepSeekDefaultModelId]
|
|
41716
41722
|
};
|
|
41717
41723
|
}
|
|
41718
|
-
async* sendImpl(systemPrompt, messages) {
|
|
41724
|
+
async* sendImpl(systemPrompt, messages, signal) {
|
|
41719
41725
|
const openAiMessages = [
|
|
41720
41726
|
{ role: "system", content: systemPrompt },
|
|
41721
41727
|
...convertToOpenAiMessages(messages)
|
|
@@ -41727,7 +41733,7 @@ class DeepSeekService extends AiServiceBase {
|
|
|
41727
41733
|
temperature: 0,
|
|
41728
41734
|
stream: true,
|
|
41729
41735
|
stream_options: { include_usage: true }
|
|
41730
|
-
});
|
|
41736
|
+
}, { signal });
|
|
41731
41737
|
for await (const chunk of stream) {
|
|
41732
41738
|
const delta = chunk.choices[0]?.delta;
|
|
41733
41739
|
if (delta?.reasoning_content) {
|
|
@@ -41771,7 +41777,7 @@ class OllamaService extends AiServiceBase {
|
|
|
41771
41777
|
info: openAiModelInfoSaneDefaults
|
|
41772
41778
|
};
|
|
41773
41779
|
}
|
|
41774
|
-
async* sendImpl(systemPrompt, messages) {
|
|
41780
|
+
async* sendImpl(systemPrompt, messages, signal) {
|
|
41775
41781
|
const openAiMessages = [
|
|
41776
41782
|
{ role: "system", content: systemPrompt },
|
|
41777
41783
|
...convertToOpenAiMessages(messages)
|
|
@@ -41781,7 +41787,7 @@ class OllamaService extends AiServiceBase {
|
|
|
41781
41787
|
messages: openAiMessages,
|
|
41782
41788
|
temperature: 0,
|
|
41783
41789
|
stream: true
|
|
41784
|
-
});
|
|
41790
|
+
}, { signal });
|
|
41785
41791
|
for await (const chunk of stream) {
|
|
41786
41792
|
const delta = chunk.choices[0]?.delta;
|
|
41787
41793
|
if (delta?.content) {
|
|
@@ -41828,7 +41834,7 @@ class OpenRouterService extends AiServiceBase {
|
|
|
41828
41834
|
this.#modelProviderInfo = data.data;
|
|
41829
41835
|
});
|
|
41830
41836
|
}
|
|
41831
|
-
async* sendImpl(systemPrompt, messages) {
|
|
41837
|
+
async* sendImpl(systemPrompt, messages, signal) {
|
|
41832
41838
|
const openAiMessages = [
|
|
41833
41839
|
{ role: "system", content: systemPrompt },
|
|
41834
41840
|
...convertToOpenAiMessages(messages)
|
|
@@ -41888,7 +41894,7 @@ class OpenRouterService extends AiServiceBase {
|
|
|
41888
41894
|
transforms: shouldApplyMiddleOutTransform ? ["middle-out"] : undefined,
|
|
41889
41895
|
include_reasoning: true,
|
|
41890
41896
|
...reasoning
|
|
41891
|
-
});
|
|
41897
|
+
}, { signal });
|
|
41892
41898
|
let genId;
|
|
41893
41899
|
for await (const chunk of stream) {
|
|
41894
41900
|
if ("error" in chunk) {
|
|
@@ -42142,7 +42148,7 @@ var getArray = (args, name, defaultValue) => {
|
|
|
42142
42148
|
return [ret];
|
|
42143
42149
|
};
|
|
42144
42150
|
// ../core/src/tools/utils/replaceInFile.ts
|
|
42145
|
-
var replaceInFile =
|
|
42151
|
+
var replaceInFile = (fileContent, diff) => {
|
|
42146
42152
|
const blockPattern = /<<<<<+ SEARCH>?\s*\r?\n([\s\S]*?)\r?\n=======[ \t]*\r?\n([\s\S]*?)\r?\n?>>>>>+ REPLACE/g;
|
|
42147
42153
|
const blocks = [];
|
|
42148
42154
|
for (let match = blockPattern.exec(diff);match !== null; match = blockPattern.exec(diff)) {
|
|
@@ -42187,14 +42193,32 @@ var replaceInFile = async (fileContent, diff) => {
|
|
|
42187
42193
|
const startPos = endPos - strippedSearch.length;
|
|
42188
42194
|
return content.slice(0, startPos) + replace + content.slice(endPos);
|
|
42189
42195
|
}
|
|
42190
|
-
|
|
42191
|
-
${search}`);
|
|
42196
|
+
return null;
|
|
42192
42197
|
};
|
|
42193
42198
|
let updatedFile = fileContent;
|
|
42199
|
+
let appliedCount = 0;
|
|
42200
|
+
const totalCount = blocks.length;
|
|
42194
42201
|
for (const { search, replace } of blocks) {
|
|
42195
|
-
|
|
42202
|
+
const result = findAndReplace(updatedFile, search, replace);
|
|
42203
|
+
if (result !== null) {
|
|
42204
|
+
updatedFile = result;
|
|
42205
|
+
appliedCount++;
|
|
42206
|
+
}
|
|
42196
42207
|
}
|
|
42197
|
-
|
|
42208
|
+
let status;
|
|
42209
|
+
if (appliedCount === 0) {
|
|
42210
|
+
status = "no_diff_applied";
|
|
42211
|
+
} else if (appliedCount < totalCount) {
|
|
42212
|
+
status = "some_diff_applied";
|
|
42213
|
+
} else {
|
|
42214
|
+
status = "all_diff_applied";
|
|
42215
|
+
}
|
|
42216
|
+
return {
|
|
42217
|
+
content: updatedFile,
|
|
42218
|
+
status,
|
|
42219
|
+
appliedCount,
|
|
42220
|
+
totalCount
|
|
42221
|
+
};
|
|
42198
42222
|
};
|
|
42199
42223
|
// ../core/src/tools/askFollowupQuestion.ts
|
|
42200
42224
|
var toolInfo = {
|
|
@@ -42889,14 +42913,26 @@ var handler8 = async (provider, args) => {
|
|
|
42889
42913
|
if (fileContent == null) {
|
|
42890
42914
|
return {
|
|
42891
42915
|
type: "Error" /* Error */,
|
|
42892
|
-
message: `<
|
|
42916
|
+
message: `<replace_in_file_result path="${path}" status="failed" message="File not found" />`
|
|
42917
|
+
};
|
|
42918
|
+
}
|
|
42919
|
+
const result = replaceInFile(fileContent, diff);
|
|
42920
|
+
if (result.status === "no_diff_applied") {
|
|
42921
|
+
return {
|
|
42922
|
+
type: "Error" /* Error */,
|
|
42923
|
+
message: `<replace_in_file_result path="${path}" status="failed" message="Unable to apply changes" />`
|
|
42924
|
+
};
|
|
42925
|
+
}
|
|
42926
|
+
await provider.writeFile(path, result.content);
|
|
42927
|
+
if (result.status === "some_diff_applied") {
|
|
42928
|
+
return {
|
|
42929
|
+
type: "Reply" /* Reply */,
|
|
42930
|
+
message: `<replace_in_file_result path="${path}" status="some_diff_applied" applied_count="${result.appliedCount}" total_count="${result.totalCount}" />`
|
|
42893
42931
|
};
|
|
42894
42932
|
}
|
|
42895
|
-
const result = await replaceInFile(fileContent, diff);
|
|
42896
|
-
await provider.writeFile(path, result);
|
|
42897
42933
|
return {
|
|
42898
42934
|
type: "Reply" /* Reply */,
|
|
42899
|
-
message: `<
|
|
42935
|
+
message: `<replace_in_file_result path="${path}" status="all_diff_applied" />`
|
|
42900
42936
|
};
|
|
42901
42937
|
};
|
|
42902
42938
|
var isAvailable8 = (provider) => {
|
|
@@ -43938,6 +43974,7 @@ class AgentBase {
|
|
|
43938
43974
|
handlers;
|
|
43939
43975
|
#messages = [];
|
|
43940
43976
|
#policies;
|
|
43977
|
+
#aborted = false;
|
|
43941
43978
|
constructor(name, ai, config) {
|
|
43942
43979
|
this.ai = ai;
|
|
43943
43980
|
if (config.agents && config.agents.length > 0) {
|
|
@@ -43969,6 +44006,10 @@ ${instance.prompt}`;
|
|
|
43969
44006
|
this.config = config;
|
|
43970
44007
|
this.#policies = policies;
|
|
43971
44008
|
}
|
|
44009
|
+
abort() {
|
|
44010
|
+
this.#aborted = true;
|
|
44011
|
+
this.ai.abort();
|
|
44012
|
+
}
|
|
43972
44013
|
get parameters() {
|
|
43973
44014
|
return this.ai.options.parameters;
|
|
43974
44015
|
}
|
|
@@ -43997,11 +44038,17 @@ ${instance.prompt}`;
|
|
|
43997
44038
|
async#processLoop(userMessage) {
|
|
43998
44039
|
let nextRequest = userMessage;
|
|
43999
44040
|
while (true) {
|
|
44041
|
+
if (this.#aborted) {
|
|
44042
|
+
return { type: "Aborted" };
|
|
44043
|
+
}
|
|
44000
44044
|
if (this.ai.usageMeter.isLimitExceeded().result) {
|
|
44001
44045
|
this.#callback({ kind: "UsageExceeded" /* UsageExceeded */, agent: this });
|
|
44002
44046
|
return { type: "UsageExceeded" };
|
|
44003
44047
|
}
|
|
44004
44048
|
const response = await this.#request(nextRequest);
|
|
44049
|
+
if (this.#aborted) {
|
|
44050
|
+
return { type: "Aborted" };
|
|
44051
|
+
}
|
|
44005
44052
|
const resp = await this.#handleResponse(response);
|
|
44006
44053
|
if (resp.type === "exit") {
|
|
44007
44054
|
this.#callback({ kind: "EndTask" /* EndTask */, agent: this, exitReason: resp.reason });
|
|
@@ -44048,14 +44095,23 @@ ${instance.prompt}`;
|
|
|
44048
44095
|
}
|
|
44049
44096
|
}
|
|
44050
44097
|
} catch (error) {
|
|
44098
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
44099
|
+
break;
|
|
44100
|
+
}
|
|
44051
44101
|
console.error("Error in stream:", error);
|
|
44052
44102
|
}
|
|
44053
44103
|
if (currentAssistantMessage) {
|
|
44054
44104
|
break;
|
|
44055
44105
|
}
|
|
44106
|
+
if (this.#aborted) {
|
|
44107
|
+
break;
|
|
44108
|
+
}
|
|
44056
44109
|
console.debug(`Retrying request ${i2 + 1} of ${retryCount}`);
|
|
44057
44110
|
}
|
|
44058
44111
|
if (!currentAssistantMessage) {
|
|
44112
|
+
if (this.#aborted) {
|
|
44113
|
+
return [];
|
|
44114
|
+
}
|
|
44059
44115
|
throw new Error("No assistant message received");
|
|
44060
44116
|
}
|
|
44061
44117
|
this.#messages.push({
|
|
@@ -44376,6 +44432,7 @@ class MultiAgent {
|
|
|
44376
44432
|
case "Delegate" /* Delegate */:
|
|
44377
44433
|
console.warn("Unexpected exit reason", delegateResult);
|
|
44378
44434
|
break;
|
|
44435
|
+
case "Aborted":
|
|
44379
44436
|
case "Interrupted" /* Interrupted */:
|
|
44380
44437
|
return delegateResult;
|
|
44381
44438
|
case "Exit" /* Exit */:
|
|
@@ -44383,6 +44440,7 @@ class MultiAgent {
|
|
|
44383
44440
|
}
|
|
44384
44441
|
return delegateResult;
|
|
44385
44442
|
}
|
|
44443
|
+
case "Aborted":
|
|
44386
44444
|
case "Interrupted" /* Interrupted */:
|
|
44387
44445
|
case "Exit" /* Exit */:
|
|
44388
44446
|
this.#agents.pop();
|
|
@@ -44415,6 +44473,11 @@ class MultiAgent {
|
|
|
44415
44473
|
get hasActiveAgent() {
|
|
44416
44474
|
return this.#agents.length > 0;
|
|
44417
44475
|
}
|
|
44476
|
+
abort() {
|
|
44477
|
+
if (this.hasActiveAgent) {
|
|
44478
|
+
this.#agents[this.#agents.length - 1].abort();
|
|
44479
|
+
}
|
|
44480
|
+
}
|
|
44418
44481
|
}
|
|
44419
44482
|
// ../core/node_modules/zod/lib/index.mjs
|
|
44420
44483
|
var util;
|
|
@@ -54363,6 +54426,8 @@ var getProvider = (agentName, config2, options = {}) => {
|
|
|
54363
54426
|
}
|
|
54364
54427
|
return provider2;
|
|
54365
54428
|
};
|
|
54429
|
+
// ../cli-shared/src/utils/eventHandler.ts
|
|
54430
|
+
var toolCallStats = new Map;
|
|
54366
54431
|
// ../../node_modules/ws/wrapper.mjs
|
|
54367
54432
|
var import_stream = __toESM(require_stream(), 1);
|
|
54368
54433
|
var import_receiver = __toESM(require_receiver(), 1);
|
|
@@ -58807,7 +58872,7 @@ class Runner {
|
|
|
58807
58872
|
path,
|
|
58808
58873
|
content
|
|
58809
58874
|
});
|
|
58810
|
-
console.log(`Sent content for file: ${path}`);
|
|
58875
|
+
console.log(`Sent content for file: ${path}, size: ${content.length}`);
|
|
58811
58876
|
} else {
|
|
58812
58877
|
console.error(`Path is not a file or directory: ${path}`);
|
|
58813
58878
|
}
|