@polka-codes/core 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.
@@ -210,8 +210,32 @@ export { AnthropicModelId }
210
210
  export { AnthropicModelId as AnthropicModelId_alias_1 }
211
211
 
212
212
  declare const anthropicModels: {
213
+ readonly 'claude-opus-4-20250514': {
214
+ readonly maxTokens: 32000;
215
+ readonly contextWindow: 200000;
216
+ readonly supportsImages: true;
217
+ readonly supportsComputerUse: true;
218
+ readonly supportsPromptCache: true;
219
+ readonly inputPrice: 15;
220
+ readonly outputPrice: 75;
221
+ readonly cacheWritesPrice: 18.75;
222
+ readonly cacheReadsPrice: 1.5;
223
+ readonly reasoning: true;
224
+ };
225
+ readonly 'claude-sonnet-4-20250514': {
226
+ readonly maxTokens: 64000;
227
+ readonly contextWindow: 200000;
228
+ readonly supportsImages: true;
229
+ readonly supportsComputerUse: true;
230
+ readonly supportsPromptCache: true;
231
+ readonly inputPrice: 3;
232
+ readonly outputPrice: 15;
233
+ readonly cacheWritesPrice: 3.75;
234
+ readonly cacheReadsPrice: 0.3;
235
+ readonly reasoning: true;
236
+ };
213
237
  readonly 'claude-3-7-sonnet-20250219': {
214
- readonly maxTokens: 8192;
238
+ readonly maxTokens: 64000;
215
239
  readonly contextWindow: 200000;
216
240
  readonly supportsImages: true;
217
241
  readonly supportsComputerUse: true;
@@ -1089,32 +1113,32 @@ declare const _default_14: {
1089
1113
  readonly usageValue: "File path here";
1090
1114
  }, {
1091
1115
  readonly name: "operations";
1092
- readonly description: "Edit operation with before_text, after_text, new_text, and optional line range hints";
1116
+ readonly description: "Edit operation with start_anchor, end_anchor, new_text, and optional line range hints";
1093
1117
  readonly required: true;
1094
1118
  readonly allowMultiple: true;
1095
1119
  readonly children: [{
1096
- readonly name: "before_text";
1120
+ readonly name: "start_anchor";
1097
1121
  readonly description: "Text to find as the start anchor (use <<<START_OF_FILE>>> for file start)";
1098
1122
  readonly required: false;
1099
1123
  readonly usageValue: "Text before the edit location";
1100
1124
  }, {
1101
- readonly name: "after_text";
1125
+ readonly name: "end_anchor";
1102
1126
  readonly description: "Text to find as the end anchor (use <<<END_OF_FILE>>> for file end)";
1103
1127
  readonly required: false;
1104
1128
  readonly usageValue: "Text after the edit location";
1105
1129
  }, {
1106
1130
  readonly name: "new_text";
1107
- readonly description: "Text to replace the content between before_text and after_text";
1131
+ readonly description: "Text to replace the content between start_anchor and end_anchor";
1108
1132
  readonly required: true;
1109
1133
  readonly usageValue: "New text content";
1110
1134
  }, {
1111
- readonly name: "before_text_line_start";
1112
- readonly description: "Optional line number hint for before_text location (1-based)";
1135
+ readonly name: "start_anchor_line_start";
1136
+ readonly description: "Optional line number hint for start_anchor location (1-based)";
1113
1137
  readonly required: false;
1114
1138
  readonly usageValue: "10";
1115
1139
  }, {
1116
- readonly name: "after_text_line_start";
1117
- readonly description: "Optional line number hint for after_text location (1-based)";
1140
+ readonly name: "end_anchor_line_start";
1141
+ readonly description: "Optional line number hint for end_anchor location (1-based)";
1118
1142
  readonly required: false;
1119
1143
  readonly usageValue: "20";
1120
1144
  }];
@@ -1128,8 +1152,8 @@ declare const _default_14: {
1128
1152
  }, {
1129
1153
  readonly name: "operations";
1130
1154
  readonly value: {
1131
- readonly before_text: "function oldFunction() {";
1132
- readonly after_text: "}";
1155
+ readonly start_anchor: "function oldFunction() {";
1156
+ readonly end_anchor: "}";
1133
1157
  readonly new_text: "\n return \"new implementation\";\n";
1134
1158
  };
1135
1159
  }];
@@ -1141,8 +1165,8 @@ declare const _default_14: {
1141
1165
  }, {
1142
1166
  readonly name: "operations";
1143
1167
  readonly value: {
1144
- readonly before_text: "<<<START_OF_FILE>>>";
1145
- readonly after_text: "export";
1168
+ readonly start_anchor: "<<<START_OF_FILE>>>";
1169
+ readonly end_anchor: "export";
1146
1170
  readonly new_text: "// File header comment\n";
1147
1171
  };
1148
1172
  }];
@@ -1154,12 +1178,12 @@ declare const _default_14: {
1154
1178
  }, {
1155
1179
  readonly name: "operations";
1156
1180
  readonly value: [{
1157
- readonly before_text: "import React";
1158
- readonly after_text: "from \"react\"";
1181
+ readonly start_anchor: "import React";
1182
+ readonly end_anchor: "from \"react\"";
1159
1183
  readonly new_text: ", { useState }";
1160
1184
  }, {
1161
- readonly before_text: "function Component() {";
1162
- readonly after_text: "return (";
1185
+ readonly start_anchor: "function Component() {";
1186
+ readonly end_anchor: "return (";
1163
1187
  readonly new_text: "\n const [state, setState] = useState(false);\n ";
1164
1188
  }];
1165
1189
  }];
@@ -1176,32 +1200,32 @@ declare const _default_14: {
1176
1200
  readonly usageValue: "File path here";
1177
1201
  }, {
1178
1202
  readonly name: "operations";
1179
- readonly description: "Edit operation with before_text, after_text, new_text, and optional line range hints";
1203
+ readonly description: "Edit operation with start_anchor, end_anchor, new_text, and optional line range hints";
1180
1204
  readonly required: true;
1181
1205
  readonly allowMultiple: true;
1182
1206
  readonly children: [{
1183
- readonly name: "before_text";
1207
+ readonly name: "start_anchor";
1184
1208
  readonly description: "Text to find as the start anchor (use <<<START_OF_FILE>>> for file start)";
1185
1209
  readonly required: false;
1186
1210
  readonly usageValue: "Text before the edit location";
1187
1211
  }, {
1188
- readonly name: "after_text";
1212
+ readonly name: "end_anchor";
1189
1213
  readonly description: "Text to find as the end anchor (use <<<END_OF_FILE>>> for file end)";
1190
1214
  readonly required: false;
1191
1215
  readonly usageValue: "Text after the edit location";
1192
1216
  }, {
1193
1217
  readonly name: "new_text";
1194
- readonly description: "Text to replace the content between before_text and after_text";
1218
+ readonly description: "Text to replace the content between start_anchor and end_anchor";
1195
1219
  readonly required: true;
1196
1220
  readonly usageValue: "New text content";
1197
1221
  }, {
1198
- readonly name: "before_text_line_start";
1199
- readonly description: "Optional line number hint for before_text location (1-based)";
1222
+ readonly name: "start_anchor_line_start";
1223
+ readonly description: "Optional line number hint for start_anchor location (1-based)";
1200
1224
  readonly required: false;
1201
1225
  readonly usageValue: "10";
1202
1226
  }, {
1203
- readonly name: "after_text_line_start";
1204
- readonly description: "Optional line number hint for after_text location (1-based)";
1227
+ readonly name: "end_anchor_line_start";
1228
+ readonly description: "Optional line number hint for end_anchor location (1-based)";
1205
1229
  readonly required: false;
1206
1230
  readonly usageValue: "20";
1207
1231
  }];
@@ -1215,8 +1239,8 @@ declare const _default_14: {
1215
1239
  }, {
1216
1240
  readonly name: "operations";
1217
1241
  readonly value: {
1218
- readonly before_text: "function oldFunction() {";
1219
- readonly after_text: "}";
1242
+ readonly start_anchor: "function oldFunction() {";
1243
+ readonly end_anchor: "}";
1220
1244
  readonly new_text: "\n return \"new implementation\";\n";
1221
1245
  };
1222
1246
  }];
@@ -1228,8 +1252,8 @@ declare const _default_14: {
1228
1252
  }, {
1229
1253
  readonly name: "operations";
1230
1254
  readonly value: {
1231
- readonly before_text: "<<<START_OF_FILE>>>";
1232
- readonly after_text: "export";
1255
+ readonly start_anchor: "<<<START_OF_FILE>>>";
1256
+ readonly end_anchor: "export";
1233
1257
  readonly new_text: "// File header comment\n";
1234
1258
  };
1235
1259
  }];
@@ -1241,12 +1265,12 @@ declare const _default_14: {
1241
1265
  }, {
1242
1266
  readonly name: "operations";
1243
1267
  readonly value: [{
1244
- readonly before_text: "import React";
1245
- readonly after_text: "from \"react\"";
1268
+ readonly start_anchor: "import React";
1269
+ readonly end_anchor: "from \"react\"";
1246
1270
  readonly new_text: ", { useState }";
1247
1271
  }, {
1248
- readonly before_text: "function Component() {";
1249
- readonly after_text: "return (";
1272
+ readonly start_anchor: "function Component() {";
1273
+ readonly end_anchor: "return (";
1250
1274
  readonly new_text: "\n const [state, setState] = useState(false);\n ";
1251
1275
  }];
1252
1276
  }];
@@ -1972,11 +1996,11 @@ export { editFile_2 as editFile_alias_4 }
1972
1996
  export declare const editingFilesPrompt: (toolNamePrefix: string) => string;
1973
1997
 
1974
1998
  declare interface EditOperation {
1975
- before_text?: string;
1976
- after_text?: string;
1999
+ start_anchor?: string;
2000
+ end_anchor?: string;
1977
2001
  new_text: string;
1978
- before_text_line_start?: number;
1979
- after_text_line_start?: number;
2002
+ start_anchor_line_start?: number;
2003
+ end_anchor_line_start?: number;
1980
2004
  }
1981
2005
  export { EditOperation }
1982
2006
  export { EditOperation as EditOperation_alias_1 }
@@ -2406,8 +2430,32 @@ export { ModelInfo as ModelInfo_alias_2 }
2406
2430
 
2407
2431
  declare const modelInfos: {
2408
2432
  anthropic: {
2433
+ readonly 'claude-opus-4-20250514': {
2434
+ readonly maxTokens: 32000;
2435
+ readonly contextWindow: 200000;
2436
+ readonly supportsImages: true;
2437
+ readonly supportsComputerUse: true;
2438
+ readonly supportsPromptCache: true;
2439
+ readonly inputPrice: 15;
2440
+ readonly outputPrice: 75;
2441
+ readonly cacheWritesPrice: 18.75;
2442
+ readonly cacheReadsPrice: 1.5;
2443
+ readonly reasoning: true;
2444
+ };
2445
+ readonly 'claude-sonnet-4-20250514': {
2446
+ readonly maxTokens: 64000;
2447
+ readonly contextWindow: 200000;
2448
+ readonly supportsImages: true;
2449
+ readonly supportsComputerUse: true;
2450
+ readonly supportsPromptCache: true;
2451
+ readonly inputPrice: 3;
2452
+ readonly outputPrice: 15;
2453
+ readonly cacheWritesPrice: 3.75;
2454
+ readonly cacheReadsPrice: 0.3;
2455
+ readonly reasoning: true;
2456
+ };
2409
2457
  readonly 'claude-3-7-sonnet-20250219': {
2410
- readonly maxTokens: 8192;
2458
+ readonly maxTokens: 64000;
2411
2459
  readonly contextWindow: 200000;
2412
2460
  readonly supportsImages: true;
2413
2461
  readonly supportsComputerUse: true;
@@ -3158,32 +3206,32 @@ export declare const toolInfo_alias_3: {
3158
3206
  readonly usageValue: "File path here";
3159
3207
  }, {
3160
3208
  readonly name: "operations";
3161
- readonly description: "Edit operation with before_text, after_text, new_text, and optional line range hints";
3209
+ readonly description: "Edit operation with start_anchor, end_anchor, new_text, and optional line range hints";
3162
3210
  readonly required: true;
3163
3211
  readonly allowMultiple: true;
3164
3212
  readonly children: [{
3165
- readonly name: "before_text";
3213
+ readonly name: "start_anchor";
3166
3214
  readonly description: "Text to find as the start anchor (use <<<START_OF_FILE>>> for file start)";
3167
3215
  readonly required: false;
3168
3216
  readonly usageValue: "Text before the edit location";
3169
3217
  }, {
3170
- readonly name: "after_text";
3218
+ readonly name: "end_anchor";
3171
3219
  readonly description: "Text to find as the end anchor (use <<<END_OF_FILE>>> for file end)";
3172
3220
  readonly required: false;
3173
3221
  readonly usageValue: "Text after the edit location";
3174
3222
  }, {
3175
3223
  readonly name: "new_text";
3176
- readonly description: "Text to replace the content between before_text and after_text";
3224
+ readonly description: "Text to replace the content between start_anchor and end_anchor";
3177
3225
  readonly required: true;
3178
3226
  readonly usageValue: "New text content";
3179
3227
  }, {
3180
- readonly name: "before_text_line_start";
3181
- readonly description: "Optional line number hint for before_text location (1-based)";
3228
+ readonly name: "start_anchor_line_start";
3229
+ readonly description: "Optional line number hint for start_anchor location (1-based)";
3182
3230
  readonly required: false;
3183
3231
  readonly usageValue: "10";
3184
3232
  }, {
3185
- readonly name: "after_text_line_start";
3186
- readonly description: "Optional line number hint for after_text location (1-based)";
3233
+ readonly name: "end_anchor_line_start";
3234
+ readonly description: "Optional line number hint for end_anchor location (1-based)";
3187
3235
  readonly required: false;
3188
3236
  readonly usageValue: "20";
3189
3237
  }];
@@ -3197,8 +3245,8 @@ export declare const toolInfo_alias_3: {
3197
3245
  }, {
3198
3246
  readonly name: "operations";
3199
3247
  readonly value: {
3200
- readonly before_text: "function oldFunction() {";
3201
- readonly after_text: "}";
3248
+ readonly start_anchor: "function oldFunction() {";
3249
+ readonly end_anchor: "}";
3202
3250
  readonly new_text: "\n return \"new implementation\";\n";
3203
3251
  };
3204
3252
  }];
@@ -3210,8 +3258,8 @@ export declare const toolInfo_alias_3: {
3210
3258
  }, {
3211
3259
  readonly name: "operations";
3212
3260
  readonly value: {
3213
- readonly before_text: "<<<START_OF_FILE>>>";
3214
- readonly after_text: "export";
3261
+ readonly start_anchor: "<<<START_OF_FILE>>>";
3262
+ readonly end_anchor: "export";
3215
3263
  readonly new_text: "// File header comment\n";
3216
3264
  };
3217
3265
  }];
@@ -3223,12 +3271,12 @@ export declare const toolInfo_alias_3: {
3223
3271
  }, {
3224
3272
  readonly name: "operations";
3225
3273
  readonly value: [{
3226
- readonly before_text: "import React";
3227
- readonly after_text: "from \"react\"";
3274
+ readonly start_anchor: "import React";
3275
+ readonly end_anchor: "from \"react\"";
3228
3276
  readonly new_text: ", { useState }";
3229
3277
  }, {
3230
- readonly before_text: "function Component() {";
3231
- readonly after_text: "return (";
3278
+ readonly start_anchor: "function Component() {";
3279
+ readonly end_anchor: "return (";
3232
3280
  readonly new_text: "\n const [state, setState] = useState(false);\n ";
3233
3281
  }];
3234
3282
  }];
package/dist/index.js CHANGED
@@ -69,8 +69,32 @@ import { Anthropic } from "@anthropic-ai/sdk";
69
69
  // src/AiService/ModelInfo.ts
70
70
  var anthropicDefaultModelId = "claude-3-7-sonnet-20250219";
71
71
  var anthropicModels = {
72
+ "claude-opus-4-20250514": {
73
+ maxTokens: 32e3,
74
+ contextWindow: 2e5,
75
+ supportsImages: true,
76
+ supportsComputerUse: true,
77
+ supportsPromptCache: true,
78
+ inputPrice: 15,
79
+ outputPrice: 75,
80
+ cacheWritesPrice: 18.75,
81
+ cacheReadsPrice: 1.5,
82
+ reasoning: true
83
+ },
84
+ "claude-sonnet-4-20250514": {
85
+ maxTokens: 64e3,
86
+ contextWindow: 2e5,
87
+ supportsImages: true,
88
+ supportsComputerUse: true,
89
+ supportsPromptCache: true,
90
+ inputPrice: 3,
91
+ outputPrice: 15,
92
+ cacheWritesPrice: 3.75,
93
+ cacheReadsPrice: 0.3,
94
+ reasoning: true
95
+ },
72
96
  "claude-3-7-sonnet-20250219": {
73
- maxTokens: 8192,
97
+ maxTokens: 64e3,
74
98
  contextWindow: 2e5,
75
99
  supportsImages: true,
76
100
  supportsComputerUse: true,
@@ -198,6 +222,7 @@ var AnthropicService = class extends AiServiceBase {
198
222
  }
199
223
  switch (modelId) {
200
224
  // 'latest' alias does not support cache_control
225
+ case "claude-sonnet-4-20250514":
201
226
  case "claude-3-7-sonnet-20250219":
202
227
  case "claude-3-5-sonnet-20241022":
203
228
  case "claude-3-5-haiku-20241022":
@@ -590,71 +615,32 @@ var OpenRouterService = class extends AiServiceBase {
590
615
  ...convertToOpenAiMessages(messages)
591
616
  ];
592
617
  const cacheControl = this.#options.enableCache ? { type: "ephemeral" } : void 0;
593
- switch (this.model.id) {
594
- case "anthropic/claude-3.7-sonnet:thinking":
595
- case "anthropic/claude-3.7-sonnet":
596
- case "anthropic/claude-3.7-sonnet:beta":
597
- case "anthropic/claude-3-7-sonnet":
598
- case "anthropic/claude-3-7-sonnet:beta":
599
- case "anthropic/claude-3.5-sonnet":
600
- case "anthropic/claude-3.5-sonnet:beta":
601
- case "anthropic/claude-3.5-sonnet-20240620":
602
- case "anthropic/claude-3.5-sonnet-20240620:beta":
603
- case "anthropic/claude-3-5-haiku":
604
- case "anthropic/claude-3-5-haiku:beta":
605
- case "anthropic/claude-3-5-haiku-20241022":
606
- case "anthropic/claude-3-5-haiku-20241022:beta":
607
- case "anthropic/claude-3-haiku":
608
- case "anthropic/claude-3-haiku:beta":
609
- case "anthropic/claude-3-opus":
610
- case "anthropic/claude-3-opus:beta": {
611
- openAiMessages[0] = {
612
- role: "system",
613
- content: [
614
- {
615
- type: "text",
616
- text: systemPrompt,
617
- // @ts-ignore-next-line
618
- cache_control: cacheControl
619
- }
620
- ]
621
- };
622
- const lastTwoUserMessages = openAiMessages.filter((msg) => msg.role === "user").slice(-2);
623
- for (const msg of lastTwoUserMessages) {
624
- if (typeof msg.content === "string") {
625
- msg.content = [{ type: "text", text: msg.content }];
618
+ if (this.model.id.startsWith("anthropic/claude")) {
619
+ openAiMessages[0] = {
620
+ role: "system",
621
+ content: [
622
+ {
623
+ type: "text",
624
+ text: systemPrompt,
625
+ // @ts-ignore-next-line
626
+ cache_control: cacheControl
626
627
  }
627
- if (Array.isArray(msg.content)) {
628
- let lastTextPart = msg.content.filter((part) => part.type === "text").pop();
629
- if (!lastTextPart) {
630
- lastTextPart = { type: "text", text: "..." };
631
- msg.content.push(lastTextPart);
632
- }
633
- lastTextPart.cache_control = cacheControl;
628
+ ]
629
+ };
630
+ const lastTwoUserMessages = openAiMessages.filter((msg) => msg.role === "user").slice(-2);
631
+ for (const msg of lastTwoUserMessages) {
632
+ if (typeof msg.content === "string") {
633
+ msg.content = [{ type: "text", text: msg.content }];
634
+ }
635
+ if (Array.isArray(msg.content)) {
636
+ let lastTextPart = msg.content.filter((part) => part.type === "text").pop();
637
+ if (!lastTextPart) {
638
+ lastTextPart = { type: "text", text: "..." };
639
+ msg.content.push(lastTextPart);
634
640
  }
641
+ lastTextPart.cache_control = cacheControl;
635
642
  }
636
- break;
637
643
  }
638
- default:
639
- break;
640
- }
641
- let maxTokens;
642
- switch (this.model.id) {
643
- case "anthropic/claude-3.7-sonnet:thinking":
644
- case "anthropic/claude-3.7-sonnet":
645
- case "anthropic/claude-3.7-sonnet:beta":
646
- case "anthropic/claude-3-7-sonnet":
647
- case "anthropic/claude-3-7-sonnet:beta":
648
- case "anthropic/claude-3.5-sonnet":
649
- case "anthropic/claude-3.5-sonnet:beta":
650
- case "anthropic/claude-3.5-sonnet-20240620":
651
- case "anthropic/claude-3.5-sonnet-20240620:beta":
652
- case "anthropic/claude-3-5-haiku":
653
- case "anthropic/claude-3-5-haiku:beta":
654
- case "anthropic/claude-3-5-haiku-20241022":
655
- case "anthropic/claude-3-5-haiku-20241022:beta":
656
- maxTokens = 8192;
657
- break;
658
644
  }
659
645
  let reasoning = {};
660
646
  switch (this.model.id) {
@@ -662,7 +648,9 @@ var OpenRouterService = class extends AiServiceBase {
662
648
  case "anthropic/claude-3.7-sonnet:beta":
663
649
  case "anthropic/claude-3.7-sonnet:thinking":
664
650
  case "anthropic/claude-3-7-sonnet":
665
- case "anthropic/claude-3-7-sonnet:beta": {
651
+ case "anthropic/claude-3-7-sonnet:beta":
652
+ case "anthropic/claude-opus-4":
653
+ case "anthropic/claude-sonnet-4": {
666
654
  const budget_tokens = this.#options.parameters.thinkingBudgetTokens || 0;
667
655
  if (budget_tokens > 0) {
668
656
  reasoning = { max_tokens: budget_tokens };
@@ -676,7 +664,6 @@ var OpenRouterService = class extends AiServiceBase {
676
664
  }
677
665
  const stream = await this.#client.chat.completions.create({
678
666
  model: this.model.id,
679
- max_completion_tokens: maxTokens,
680
667
  messages: openAiMessages,
681
668
  temperature: 0,
682
669
  stream: true,
@@ -942,41 +929,41 @@ var editFile = async (fileContent, operations) => {
942
929
  return updatedContent;
943
930
  };
944
931
  async function applyEditOperation(fileContent, operation, originalLines) {
945
- const { before_text, after_text, new_text, before_text_line_start, after_text_line_start } = operation;
946
- if (before_text === START_OF_FILE && after_text === END_OF_FILE) {
932
+ const { start_anchor, end_anchor, new_text, start_anchor_line_start, end_anchor_line_start } = operation;
933
+ if (start_anchor === START_OF_FILE && end_anchor === END_OF_FILE) {
947
934
  return new_text;
948
935
  }
949
- if (before_text === START_OF_FILE) {
950
- if (!after_text) {
936
+ if (start_anchor === START_OF_FILE) {
937
+ if (!end_anchor) {
951
938
  return new_text + fileContent;
952
939
  }
953
- const afterIndex = findTextWithHint(fileContent, after_text, after_text_line_start, originalLines);
940
+ const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines);
954
941
  return new_text + fileContent.slice(afterIndex);
955
942
  }
956
- if (after_text === END_OF_FILE) {
957
- if (!before_text) {
943
+ if (end_anchor === END_OF_FILE) {
944
+ if (!start_anchor) {
958
945
  return fileContent + new_text;
959
946
  }
960
- const beforeIndex = findTextWithHint(fileContent, before_text, before_text_line_start, originalLines);
961
- const beforeEndIndex = beforeIndex + before_text.length;
947
+ const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
948
+ const beforeEndIndex = beforeIndex + start_anchor.length;
962
949
  return fileContent.slice(0, beforeEndIndex) + new_text;
963
950
  }
964
- if (before_text && after_text) {
965
- const beforeIndex = findTextWithHint(fileContent, before_text, before_text_line_start, originalLines);
966
- const beforeEndIndex = beforeIndex + before_text.length;
967
- const afterIndex = findTextWithHint(fileContent, after_text, after_text_line_start, originalLines, beforeEndIndex);
951
+ if (start_anchor && end_anchor) {
952
+ const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
953
+ const beforeEndIndex = beforeIndex + start_anchor.length;
954
+ const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines, beforeEndIndex);
968
955
  return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(afterIndex);
969
956
  }
970
- if (before_text) {
971
- const beforeIndex = findTextWithHint(fileContent, before_text, before_text_line_start, originalLines);
972
- const beforeEndIndex = beforeIndex + before_text.length;
957
+ if (start_anchor) {
958
+ const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
959
+ const beforeEndIndex = beforeIndex + start_anchor.length;
973
960
  return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(beforeEndIndex);
974
961
  }
975
- if (after_text) {
976
- const afterIndex = findTextWithHint(fileContent, after_text, after_text_line_start, originalLines);
962
+ if (end_anchor) {
963
+ const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines);
977
964
  return fileContent.slice(0, afterIndex) + new_text + fileContent.slice(afterIndex);
978
965
  }
979
- throw new Error("Either before_text or after_text must be specified");
966
+ throw new Error("Either start_anchor or end_anchor must be specified");
980
967
  }
981
968
  function findTextWithHint(content, searchText, lineHint, originalLines, startIndex = 0) {
982
969
  if (lineHint && lineHint > 0 && lineHint <= originalLines.length) {
@@ -2207,37 +2194,37 @@ var toolInfo13 = {
2207
2194
  },
2208
2195
  {
2209
2196
  name: "operations",
2210
- description: "Edit operation with before_text, after_text, new_text, and optional line range hints",
2197
+ description: "Edit operation with start_anchor, end_anchor, new_text, and optional line range hints",
2211
2198
  required: true,
2212
2199
  allowMultiple: true,
2213
2200
  children: [
2214
2201
  {
2215
- name: "before_text",
2202
+ name: "start_anchor",
2216
2203
  description: `Text to find as the start anchor (use ${START_OF_FILE} for file start)`,
2217
2204
  required: false,
2218
2205
  usageValue: "Text before the edit location"
2219
2206
  },
2220
2207
  {
2221
- name: "after_text",
2208
+ name: "end_anchor",
2222
2209
  description: `Text to find as the end anchor (use ${END_OF_FILE} for file end)`,
2223
2210
  required: false,
2224
2211
  usageValue: "Text after the edit location"
2225
2212
  },
2226
2213
  {
2227
2214
  name: "new_text",
2228
- description: "Text to replace the content between before_text and after_text",
2215
+ description: "Text to replace the content between start_anchor and end_anchor",
2229
2216
  required: true,
2230
2217
  usageValue: "New text content"
2231
2218
  },
2232
2219
  {
2233
- name: "before_text_line_start",
2234
- description: "Optional line number hint for before_text location (1-based)",
2220
+ name: "start_anchor_line_start",
2221
+ description: "Optional line number hint for start_anchor location (1-based)",
2235
2222
  required: false,
2236
2223
  usageValue: "10"
2237
2224
  },
2238
2225
  {
2239
- name: "after_text_line_start",
2240
- description: "Optional line number hint for after_text location (1-based)",
2226
+ name: "end_anchor_line_start",
2227
+ description: "Optional line number hint for end_anchor location (1-based)",
2241
2228
  required: false,
2242
2229
  usageValue: "20"
2243
2230
  }
@@ -2256,8 +2243,8 @@ var toolInfo13 = {
2256
2243
  {
2257
2244
  name: "operations",
2258
2245
  value: {
2259
- before_text: "function oldFunction() {",
2260
- after_text: "}",
2246
+ start_anchor: "function oldFunction() {",
2247
+ end_anchor: "}",
2261
2248
  new_text: '\n return "new implementation";\n'
2262
2249
  }
2263
2250
  }
@@ -2273,8 +2260,8 @@ var toolInfo13 = {
2273
2260
  {
2274
2261
  name: "operations",
2275
2262
  value: {
2276
- before_text: START_OF_FILE,
2277
- after_text: "export",
2263
+ start_anchor: START_OF_FILE,
2264
+ end_anchor: "export",
2278
2265
  new_text: "// File header comment\n"
2279
2266
  }
2280
2267
  }
@@ -2291,13 +2278,13 @@ var toolInfo13 = {
2291
2278
  name: "operations",
2292
2279
  value: [
2293
2280
  {
2294
- before_text: "import React",
2295
- after_text: 'from "react"',
2281
+ start_anchor: "import React",
2282
+ end_anchor: 'from "react"',
2296
2283
  new_text: ", { useState }"
2297
2284
  },
2298
2285
  {
2299
- before_text: "function Component() {",
2300
- after_text: "return (",
2286
+ start_anchor: "function Component() {",
2287
+ end_anchor: "return (",
2301
2288
  new_text: "\n const [state, setState] = useState(false);\n "
2302
2289
  }
2303
2290
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/core",
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",