@polka-codes/runner 0.8.14 → 0.8.16
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 +71 -68
- 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.16";
|
|
32752
32752
|
|
|
32753
32753
|
// src/runner.ts
|
|
32754
32754
|
import { execSync } from "node:child_process";
|
|
@@ -36155,8 +36155,32 @@ Anthropic.Beta = Beta;
|
|
|
36155
36155
|
// ../core/src/AiService/ModelInfo.ts
|
|
36156
36156
|
var anthropicDefaultModelId = "claude-3-7-sonnet-20250219";
|
|
36157
36157
|
var anthropicModels = {
|
|
36158
|
+
"claude-opus-4-20250514": {
|
|
36159
|
+
maxTokens: 32000,
|
|
36160
|
+
contextWindow: 200000,
|
|
36161
|
+
supportsImages: true,
|
|
36162
|
+
supportsComputerUse: true,
|
|
36163
|
+
supportsPromptCache: true,
|
|
36164
|
+
inputPrice: 15,
|
|
36165
|
+
outputPrice: 75,
|
|
36166
|
+
cacheWritesPrice: 18.75,
|
|
36167
|
+
cacheReadsPrice: 1.5,
|
|
36168
|
+
reasoning: true
|
|
36169
|
+
},
|
|
36170
|
+
"claude-sonnet-4-20250514": {
|
|
36171
|
+
maxTokens: 64000,
|
|
36172
|
+
contextWindow: 200000,
|
|
36173
|
+
supportsImages: true,
|
|
36174
|
+
supportsComputerUse: true,
|
|
36175
|
+
supportsPromptCache: true,
|
|
36176
|
+
inputPrice: 3,
|
|
36177
|
+
outputPrice: 15,
|
|
36178
|
+
cacheWritesPrice: 3.75,
|
|
36179
|
+
cacheReadsPrice: 0.3,
|
|
36180
|
+
reasoning: true
|
|
36181
|
+
},
|
|
36158
36182
|
"claude-3-7-sonnet-20250219": {
|
|
36159
|
-
maxTokens:
|
|
36183
|
+
maxTokens: 64000,
|
|
36160
36184
|
contextWindow: 200000,
|
|
36161
36185
|
supportsImages: true,
|
|
36162
36186
|
supportsComputerUse: true,
|
|
@@ -36277,6 +36301,7 @@ class AnthropicService extends AiServiceBase {
|
|
|
36277
36301
|
temperature = undefined;
|
|
36278
36302
|
}
|
|
36279
36303
|
switch (modelId) {
|
|
36304
|
+
case "claude-sonnet-4-20250514":
|
|
36280
36305
|
case "claude-3-7-sonnet-20250219":
|
|
36281
36306
|
case "claude-3-5-sonnet-20241022":
|
|
36282
36307
|
case "claude-3-5-haiku-20241022":
|
|
@@ -41809,70 +41834,31 @@ class OpenRouterService extends AiServiceBase {
|
|
|
41809
41834
|
...convertToOpenAiMessages(messages)
|
|
41810
41835
|
];
|
|
41811
41836
|
const cacheControl = this.#options.enableCache ? { type: "ephemeral" } : undefined;
|
|
41812
|
-
|
|
41813
|
-
|
|
41814
|
-
|
|
41815
|
-
|
|
41816
|
-
|
|
41817
|
-
|
|
41818
|
-
|
|
41819
|
-
|
|
41820
|
-
|
|
41821
|
-
|
|
41822
|
-
|
|
41823
|
-
|
|
41824
|
-
|
|
41825
|
-
|
|
41826
|
-
|
|
41827
|
-
|
|
41828
|
-
|
|
41829
|
-
|
|
41830
|
-
|
|
41831
|
-
|
|
41832
|
-
|
|
41833
|
-
{
|
|
41834
|
-
type: "text",
|
|
41835
|
-
text: systemPrompt,
|
|
41836
|
-
cache_control: cacheControl
|
|
41837
|
-
}
|
|
41838
|
-
]
|
|
41839
|
-
};
|
|
41840
|
-
const lastTwoUserMessages = openAiMessages.filter((msg) => msg.role === "user").slice(-2);
|
|
41841
|
-
for (const msg of lastTwoUserMessages) {
|
|
41842
|
-
if (typeof msg.content === "string") {
|
|
41843
|
-
msg.content = [{ type: "text", text: msg.content }];
|
|
41844
|
-
}
|
|
41845
|
-
if (Array.isArray(msg.content)) {
|
|
41846
|
-
let lastTextPart = msg.content.filter((part) => part.type === "text").pop();
|
|
41847
|
-
if (!lastTextPart) {
|
|
41848
|
-
lastTextPart = { type: "text", text: "..." };
|
|
41849
|
-
msg.content.push(lastTextPart);
|
|
41850
|
-
}
|
|
41851
|
-
lastTextPart.cache_control = cacheControl;
|
|
41837
|
+
if (this.model.id.startsWith("anthropic/claude")) {
|
|
41838
|
+
openAiMessages[0] = {
|
|
41839
|
+
role: "system",
|
|
41840
|
+
content: [
|
|
41841
|
+
{
|
|
41842
|
+
type: "text",
|
|
41843
|
+
text: systemPrompt,
|
|
41844
|
+
cache_control: cacheControl
|
|
41845
|
+
}
|
|
41846
|
+
]
|
|
41847
|
+
};
|
|
41848
|
+
const lastTwoUserMessages = openAiMessages.filter((msg) => msg.role === "user").slice(-2);
|
|
41849
|
+
for (const msg of lastTwoUserMessages) {
|
|
41850
|
+
if (typeof msg.content === "string") {
|
|
41851
|
+
msg.content = [{ type: "text", text: msg.content }];
|
|
41852
|
+
}
|
|
41853
|
+
if (Array.isArray(msg.content)) {
|
|
41854
|
+
let lastTextPart = msg.content.filter((part) => part.type === "text").pop();
|
|
41855
|
+
if (!lastTextPart) {
|
|
41856
|
+
lastTextPart = { type: "text", text: "..." };
|
|
41857
|
+
msg.content.push(lastTextPart);
|
|
41852
41858
|
}
|
|
41859
|
+
lastTextPart.cache_control = cacheControl;
|
|
41853
41860
|
}
|
|
41854
|
-
break;
|
|
41855
41861
|
}
|
|
41856
|
-
default:
|
|
41857
|
-
break;
|
|
41858
|
-
}
|
|
41859
|
-
let maxTokens;
|
|
41860
|
-
switch (this.model.id) {
|
|
41861
|
-
case "anthropic/claude-3.7-sonnet:thinking":
|
|
41862
|
-
case "anthropic/claude-3.7-sonnet":
|
|
41863
|
-
case "anthropic/claude-3.7-sonnet:beta":
|
|
41864
|
-
case "anthropic/claude-3-7-sonnet":
|
|
41865
|
-
case "anthropic/claude-3-7-sonnet:beta":
|
|
41866
|
-
case "anthropic/claude-3.5-sonnet":
|
|
41867
|
-
case "anthropic/claude-3.5-sonnet:beta":
|
|
41868
|
-
case "anthropic/claude-3.5-sonnet-20240620":
|
|
41869
|
-
case "anthropic/claude-3.5-sonnet-20240620:beta":
|
|
41870
|
-
case "anthropic/claude-3-5-haiku":
|
|
41871
|
-
case "anthropic/claude-3-5-haiku:beta":
|
|
41872
|
-
case "anthropic/claude-3-5-haiku-20241022":
|
|
41873
|
-
case "anthropic/claude-3-5-haiku-20241022:beta":
|
|
41874
|
-
maxTokens = 8192;
|
|
41875
|
-
break;
|
|
41876
41862
|
}
|
|
41877
41863
|
let reasoning = {};
|
|
41878
41864
|
switch (this.model.id) {
|
|
@@ -41880,7 +41866,9 @@ class OpenRouterService extends AiServiceBase {
|
|
|
41880
41866
|
case "anthropic/claude-3.7-sonnet:beta":
|
|
41881
41867
|
case "anthropic/claude-3.7-sonnet:thinking":
|
|
41882
41868
|
case "anthropic/claude-3-7-sonnet":
|
|
41883
|
-
case "anthropic/claude-3-7-sonnet:beta":
|
|
41869
|
+
case "anthropic/claude-3-7-sonnet:beta":
|
|
41870
|
+
case "anthropic/claude-opus-4":
|
|
41871
|
+
case "anthropic/claude-sonnet-4": {
|
|
41884
41872
|
const budget_tokens = this.#options.parameters.thinkingBudgetTokens || 0;
|
|
41885
41873
|
if (budget_tokens > 0) {
|
|
41886
41874
|
reasoning = { max_tokens: budget_tokens };
|
|
@@ -41894,7 +41882,6 @@ class OpenRouterService extends AiServiceBase {
|
|
|
41894
41882
|
}
|
|
41895
41883
|
const stream = await this.#client.chat.completions.create({
|
|
41896
41884
|
model: this.model.id,
|
|
41897
|
-
max_completion_tokens: maxTokens,
|
|
41898
41885
|
messages: openAiMessages,
|
|
41899
41886
|
temperature: 0,
|
|
41900
41887
|
stream: true,
|
|
@@ -58671,12 +58658,21 @@ class Runner {
|
|
|
58671
58658
|
if (resp.type === "Reply" /* Reply */) {
|
|
58672
58659
|
return responsePrompts.toolResults(request.tool, resp.message);
|
|
58673
58660
|
}
|
|
58674
|
-
return
|
|
58661
|
+
return {
|
|
58662
|
+
type: "error",
|
|
58663
|
+
message: responsePrompts.errorInvokeTool(request.tool, `Unexpected tool response: ${JSON.stringify(resp)}`)
|
|
58664
|
+
};
|
|
58675
58665
|
}
|
|
58676
|
-
return
|
|
58666
|
+
return {
|
|
58667
|
+
type: "error",
|
|
58668
|
+
message: responsePrompts.errorInvokeTool(request.tool, "Tool not available")
|
|
58669
|
+
};
|
|
58677
58670
|
} catch (toolError) {
|
|
58678
58671
|
console.error(`Error executing tool ${request.tool}:`, toolError);
|
|
58679
|
-
return
|
|
58672
|
+
return {
|
|
58673
|
+
type: "error",
|
|
58674
|
+
message: responsePrompts.errorInvokeTool(request.tool, toolError)
|
|
58675
|
+
};
|
|
58680
58676
|
}
|
|
58681
58677
|
};
|
|
58682
58678
|
const respMsg = await fn();
|
|
@@ -58693,6 +58689,13 @@ class Runner {
|
|
|
58693
58689
|
index: request.index
|
|
58694
58690
|
});
|
|
58695
58691
|
return;
|
|
58692
|
+
} else if (respMsg.type === "error") {
|
|
58693
|
+
responses.push({
|
|
58694
|
+
index: request.index,
|
|
58695
|
+
tool: request.tool,
|
|
58696
|
+
response: respMsg.message
|
|
58697
|
+
});
|
|
58698
|
+
break;
|
|
58696
58699
|
}
|
|
58697
58700
|
}
|
|
58698
58701
|
this.wsManager.sendMessage({
|