@polka-codes/runner 0.8.15 → 0.8.17

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.
Files changed (2) hide show
  1. package/dist/index.js +87 -100
  2. 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.15";
32751
+ var version = "0.8.17";
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: 8192,
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
- switch (this.model.id) {
41813
- case "anthropic/claude-3.7-sonnet:thinking":
41814
- case "anthropic/claude-3.7-sonnet":
41815
- case "anthropic/claude-3.7-sonnet:beta":
41816
- case "anthropic/claude-3-7-sonnet":
41817
- case "anthropic/claude-3-7-sonnet:beta":
41818
- case "anthropic/claude-3.5-sonnet":
41819
- case "anthropic/claude-3.5-sonnet:beta":
41820
- case "anthropic/claude-3.5-sonnet-20240620":
41821
- case "anthropic/claude-3.5-sonnet-20240620:beta":
41822
- case "anthropic/claude-3-5-haiku":
41823
- case "anthropic/claude-3-5-haiku:beta":
41824
- case "anthropic/claude-3-5-haiku-20241022":
41825
- case "anthropic/claude-3-5-haiku-20241022:beta":
41826
- case "anthropic/claude-3-haiku":
41827
- case "anthropic/claude-3-haiku:beta":
41828
- case "anthropic/claude-3-opus":
41829
- case "anthropic/claude-3-opus:beta": {
41830
- openAiMessages[0] = {
41831
- role: "system",
41832
- content: [
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,
@@ -42078,41 +42065,41 @@ var editFile = async (fileContent, operations) => {
42078
42065
  return updatedContent;
42079
42066
  };
42080
42067
  async function applyEditOperation(fileContent, operation, originalLines) {
42081
- const { before_text, after_text, new_text, before_text_line_start, after_text_line_start } = operation;
42082
- if (before_text === START_OF_FILE && after_text === END_OF_FILE) {
42068
+ const { start_anchor, end_anchor, new_text, start_anchor_line_start, end_anchor_line_start } = operation;
42069
+ if (start_anchor === START_OF_FILE && end_anchor === END_OF_FILE) {
42083
42070
  return new_text;
42084
42071
  }
42085
- if (before_text === START_OF_FILE) {
42086
- if (!after_text) {
42072
+ if (start_anchor === START_OF_FILE) {
42073
+ if (!end_anchor) {
42087
42074
  return new_text + fileContent;
42088
42075
  }
42089
- const afterIndex = findTextWithHint(fileContent, after_text, after_text_line_start, originalLines);
42076
+ const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines);
42090
42077
  return new_text + fileContent.slice(afterIndex);
42091
42078
  }
42092
- if (after_text === END_OF_FILE) {
42093
- if (!before_text) {
42079
+ if (end_anchor === END_OF_FILE) {
42080
+ if (!start_anchor) {
42094
42081
  return fileContent + new_text;
42095
42082
  }
42096
- const beforeIndex = findTextWithHint(fileContent, before_text, before_text_line_start, originalLines);
42097
- const beforeEndIndex = beforeIndex + before_text.length;
42083
+ const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
42084
+ const beforeEndIndex = beforeIndex + start_anchor.length;
42098
42085
  return fileContent.slice(0, beforeEndIndex) + new_text;
42099
42086
  }
42100
- if (before_text && after_text) {
42101
- const beforeIndex = findTextWithHint(fileContent, before_text, before_text_line_start, originalLines);
42102
- const beforeEndIndex = beforeIndex + before_text.length;
42103
- const afterIndex = findTextWithHint(fileContent, after_text, after_text_line_start, originalLines, beforeEndIndex);
42087
+ if (start_anchor && end_anchor) {
42088
+ const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
42089
+ const beforeEndIndex = beforeIndex + start_anchor.length;
42090
+ const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines, beforeEndIndex);
42104
42091
  return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(afterIndex);
42105
42092
  }
42106
- if (before_text) {
42107
- const beforeIndex = findTextWithHint(fileContent, before_text, before_text_line_start, originalLines);
42108
- const beforeEndIndex = beforeIndex + before_text.length;
42093
+ if (start_anchor) {
42094
+ const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
42095
+ const beforeEndIndex = beforeIndex + start_anchor.length;
42109
42096
  return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(beforeEndIndex);
42110
42097
  }
42111
- if (after_text) {
42112
- const afterIndex = findTextWithHint(fileContent, after_text, after_text_line_start, originalLines);
42098
+ if (end_anchor) {
42099
+ const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines);
42113
42100
  return fileContent.slice(0, afterIndex) + new_text + fileContent.slice(afterIndex);
42114
42101
  }
42115
- throw new Error("Either before_text or after_text must be specified");
42102
+ throw new Error("Either start_anchor or end_anchor must be specified");
42116
42103
  }
42117
42104
  function findTextWithHint(content, searchText, lineHint, originalLines, startIndex = 0) {
42118
42105
  if (lineHint && lineHint > 0 && lineHint <= originalLines.length) {
@@ -43333,37 +43320,37 @@ var toolInfo13 = {
43333
43320
  },
43334
43321
  {
43335
43322
  name: "operations",
43336
- description: "Edit operation with before_text, after_text, new_text, and optional line range hints",
43323
+ description: "Edit operation with start_anchor, end_anchor, new_text, and optional line range hints",
43337
43324
  required: true,
43338
43325
  allowMultiple: true,
43339
43326
  children: [
43340
43327
  {
43341
- name: "before_text",
43328
+ name: "start_anchor",
43342
43329
  description: `Text to find as the start anchor (use ${START_OF_FILE} for file start)`,
43343
43330
  required: false,
43344
43331
  usageValue: "Text before the edit location"
43345
43332
  },
43346
43333
  {
43347
- name: "after_text",
43334
+ name: "end_anchor",
43348
43335
  description: `Text to find as the end anchor (use ${END_OF_FILE} for file end)`,
43349
43336
  required: false,
43350
43337
  usageValue: "Text after the edit location"
43351
43338
  },
43352
43339
  {
43353
43340
  name: "new_text",
43354
- description: "Text to replace the content between before_text and after_text",
43341
+ description: "Text to replace the content between start_anchor and end_anchor",
43355
43342
  required: true,
43356
43343
  usageValue: "New text content"
43357
43344
  },
43358
43345
  {
43359
- name: "before_text_line_start",
43360
- description: "Optional line number hint for before_text location (1-based)",
43346
+ name: "start_anchor_line_start",
43347
+ description: "Optional line number hint for start_anchor location (1-based)",
43361
43348
  required: false,
43362
43349
  usageValue: "10"
43363
43350
  },
43364
43351
  {
43365
- name: "after_text_line_start",
43366
- description: "Optional line number hint for after_text location (1-based)",
43352
+ name: "end_anchor_line_start",
43353
+ description: "Optional line number hint for end_anchor location (1-based)",
43367
43354
  required: false,
43368
43355
  usageValue: "20"
43369
43356
  }
@@ -43382,8 +43369,8 @@ var toolInfo13 = {
43382
43369
  {
43383
43370
  name: "operations",
43384
43371
  value: {
43385
- before_text: "function oldFunction() {",
43386
- after_text: "}",
43372
+ start_anchor: "function oldFunction() {",
43373
+ end_anchor: "}",
43387
43374
  new_text: `
43388
43375
  return "new implementation";
43389
43376
  `
@@ -43401,8 +43388,8 @@ var toolInfo13 = {
43401
43388
  {
43402
43389
  name: "operations",
43403
43390
  value: {
43404
- before_text: START_OF_FILE,
43405
- after_text: "export",
43391
+ start_anchor: START_OF_FILE,
43392
+ end_anchor: "export",
43406
43393
  new_text: `// File header comment
43407
43394
  `
43408
43395
  }
@@ -43420,13 +43407,13 @@ var toolInfo13 = {
43420
43407
  name: "operations",
43421
43408
  value: [
43422
43409
  {
43423
- before_text: "import React",
43424
- after_text: 'from "react"',
43410
+ start_anchor: "import React",
43411
+ end_anchor: 'from "react"',
43425
43412
  new_text: ", { useState }"
43426
43413
  },
43427
43414
  {
43428
- before_text: "function Component() {",
43429
- after_text: "return (",
43415
+ start_anchor: "function Component() {",
43416
+ end_anchor: "return (",
43430
43417
  new_text: `
43431
43418
  const [state, setState] = useState(false);
43432
43419
  `
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/runner",
3
- "version": "0.8.15",
3
+ "version": "0.8.17",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",