@polka-codes/cli-shared 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.
- package/dist/index.js +86 -99
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -30889,8 +30889,32 @@ Anthropic.Beta = Beta;
|
|
|
30889
30889
|
// ../core/src/AiService/ModelInfo.ts
|
|
30890
30890
|
var anthropicDefaultModelId = "claude-3-7-sonnet-20250219";
|
|
30891
30891
|
var anthropicModels = {
|
|
30892
|
+
"claude-opus-4-20250514": {
|
|
30893
|
+
maxTokens: 32000,
|
|
30894
|
+
contextWindow: 200000,
|
|
30895
|
+
supportsImages: true,
|
|
30896
|
+
supportsComputerUse: true,
|
|
30897
|
+
supportsPromptCache: true,
|
|
30898
|
+
inputPrice: 15,
|
|
30899
|
+
outputPrice: 75,
|
|
30900
|
+
cacheWritesPrice: 18.75,
|
|
30901
|
+
cacheReadsPrice: 1.5,
|
|
30902
|
+
reasoning: true
|
|
30903
|
+
},
|
|
30904
|
+
"claude-sonnet-4-20250514": {
|
|
30905
|
+
maxTokens: 64000,
|
|
30906
|
+
contextWindow: 200000,
|
|
30907
|
+
supportsImages: true,
|
|
30908
|
+
supportsComputerUse: true,
|
|
30909
|
+
supportsPromptCache: true,
|
|
30910
|
+
inputPrice: 3,
|
|
30911
|
+
outputPrice: 15,
|
|
30912
|
+
cacheWritesPrice: 3.75,
|
|
30913
|
+
cacheReadsPrice: 0.3,
|
|
30914
|
+
reasoning: true
|
|
30915
|
+
},
|
|
30892
30916
|
"claude-3-7-sonnet-20250219": {
|
|
30893
|
-
maxTokens:
|
|
30917
|
+
maxTokens: 64000,
|
|
30894
30918
|
contextWindow: 200000,
|
|
30895
30919
|
supportsImages: true,
|
|
30896
30920
|
supportsComputerUse: true,
|
|
@@ -31011,6 +31035,7 @@ class AnthropicService extends AiServiceBase {
|
|
|
31011
31035
|
temperature = undefined;
|
|
31012
31036
|
}
|
|
31013
31037
|
switch (modelId) {
|
|
31038
|
+
case "claude-sonnet-4-20250514":
|
|
31014
31039
|
case "claude-3-7-sonnet-20250219":
|
|
31015
31040
|
case "claude-3-5-sonnet-20241022":
|
|
31016
31041
|
case "claude-3-5-haiku-20241022":
|
|
@@ -36543,70 +36568,31 @@ class OpenRouterService extends AiServiceBase {
|
|
|
36543
36568
|
...convertToOpenAiMessages(messages)
|
|
36544
36569
|
];
|
|
36545
36570
|
const cacheControl = this.#options.enableCache ? { type: "ephemeral" } : undefined;
|
|
36546
|
-
|
|
36547
|
-
|
|
36548
|
-
|
|
36549
|
-
|
|
36550
|
-
|
|
36551
|
-
|
|
36552
|
-
|
|
36553
|
-
|
|
36554
|
-
|
|
36555
|
-
|
|
36556
|
-
|
|
36557
|
-
|
|
36558
|
-
|
|
36559
|
-
|
|
36560
|
-
|
|
36561
|
-
|
|
36562
|
-
|
|
36563
|
-
|
|
36564
|
-
|
|
36565
|
-
|
|
36566
|
-
|
|
36567
|
-
{
|
|
36568
|
-
type: "text",
|
|
36569
|
-
text: systemPrompt,
|
|
36570
|
-
cache_control: cacheControl
|
|
36571
|
-
}
|
|
36572
|
-
]
|
|
36573
|
-
};
|
|
36574
|
-
const lastTwoUserMessages = openAiMessages.filter((msg) => msg.role === "user").slice(-2);
|
|
36575
|
-
for (const msg of lastTwoUserMessages) {
|
|
36576
|
-
if (typeof msg.content === "string") {
|
|
36577
|
-
msg.content = [{ type: "text", text: msg.content }];
|
|
36578
|
-
}
|
|
36579
|
-
if (Array.isArray(msg.content)) {
|
|
36580
|
-
let lastTextPart = msg.content.filter((part) => part.type === "text").pop();
|
|
36581
|
-
if (!lastTextPart) {
|
|
36582
|
-
lastTextPart = { type: "text", text: "..." };
|
|
36583
|
-
msg.content.push(lastTextPart);
|
|
36584
|
-
}
|
|
36585
|
-
lastTextPart.cache_control = cacheControl;
|
|
36571
|
+
if (this.model.id.startsWith("anthropic/claude")) {
|
|
36572
|
+
openAiMessages[0] = {
|
|
36573
|
+
role: "system",
|
|
36574
|
+
content: [
|
|
36575
|
+
{
|
|
36576
|
+
type: "text",
|
|
36577
|
+
text: systemPrompt,
|
|
36578
|
+
cache_control: cacheControl
|
|
36579
|
+
}
|
|
36580
|
+
]
|
|
36581
|
+
};
|
|
36582
|
+
const lastTwoUserMessages = openAiMessages.filter((msg) => msg.role === "user").slice(-2);
|
|
36583
|
+
for (const msg of lastTwoUserMessages) {
|
|
36584
|
+
if (typeof msg.content === "string") {
|
|
36585
|
+
msg.content = [{ type: "text", text: msg.content }];
|
|
36586
|
+
}
|
|
36587
|
+
if (Array.isArray(msg.content)) {
|
|
36588
|
+
let lastTextPart = msg.content.filter((part) => part.type === "text").pop();
|
|
36589
|
+
if (!lastTextPart) {
|
|
36590
|
+
lastTextPart = { type: "text", text: "..." };
|
|
36591
|
+
msg.content.push(lastTextPart);
|
|
36586
36592
|
}
|
|
36593
|
+
lastTextPart.cache_control = cacheControl;
|
|
36587
36594
|
}
|
|
36588
|
-
break;
|
|
36589
36595
|
}
|
|
36590
|
-
default:
|
|
36591
|
-
break;
|
|
36592
|
-
}
|
|
36593
|
-
let maxTokens;
|
|
36594
|
-
switch (this.model.id) {
|
|
36595
|
-
case "anthropic/claude-3.7-sonnet:thinking":
|
|
36596
|
-
case "anthropic/claude-3.7-sonnet":
|
|
36597
|
-
case "anthropic/claude-3.7-sonnet:beta":
|
|
36598
|
-
case "anthropic/claude-3-7-sonnet":
|
|
36599
|
-
case "anthropic/claude-3-7-sonnet:beta":
|
|
36600
|
-
case "anthropic/claude-3.5-sonnet":
|
|
36601
|
-
case "anthropic/claude-3.5-sonnet:beta":
|
|
36602
|
-
case "anthropic/claude-3.5-sonnet-20240620":
|
|
36603
|
-
case "anthropic/claude-3.5-sonnet-20240620:beta":
|
|
36604
|
-
case "anthropic/claude-3-5-haiku":
|
|
36605
|
-
case "anthropic/claude-3-5-haiku:beta":
|
|
36606
|
-
case "anthropic/claude-3-5-haiku-20241022":
|
|
36607
|
-
case "anthropic/claude-3-5-haiku-20241022:beta":
|
|
36608
|
-
maxTokens = 8192;
|
|
36609
|
-
break;
|
|
36610
36596
|
}
|
|
36611
36597
|
let reasoning = {};
|
|
36612
36598
|
switch (this.model.id) {
|
|
@@ -36614,7 +36600,9 @@ class OpenRouterService extends AiServiceBase {
|
|
|
36614
36600
|
case "anthropic/claude-3.7-sonnet:beta":
|
|
36615
36601
|
case "anthropic/claude-3.7-sonnet:thinking":
|
|
36616
36602
|
case "anthropic/claude-3-7-sonnet":
|
|
36617
|
-
case "anthropic/claude-3-7-sonnet:beta":
|
|
36603
|
+
case "anthropic/claude-3-7-sonnet:beta":
|
|
36604
|
+
case "anthropic/claude-opus-4":
|
|
36605
|
+
case "anthropic/claude-sonnet-4": {
|
|
36618
36606
|
const budget_tokens = this.#options.parameters.thinkingBudgetTokens || 0;
|
|
36619
36607
|
if (budget_tokens > 0) {
|
|
36620
36608
|
reasoning = { max_tokens: budget_tokens };
|
|
@@ -36628,7 +36616,6 @@ class OpenRouterService extends AiServiceBase {
|
|
|
36628
36616
|
}
|
|
36629
36617
|
const stream = await this.#client.chat.completions.create({
|
|
36630
36618
|
model: this.model.id,
|
|
36631
|
-
max_completion_tokens: maxTokens,
|
|
36632
36619
|
messages: openAiMessages,
|
|
36633
36620
|
temperature: 0,
|
|
36634
36621
|
stream: true,
|
|
@@ -36812,41 +36799,41 @@ var editFile = async (fileContent, operations) => {
|
|
|
36812
36799
|
return updatedContent;
|
|
36813
36800
|
};
|
|
36814
36801
|
async function applyEditOperation(fileContent, operation, originalLines) {
|
|
36815
|
-
const {
|
|
36816
|
-
if (
|
|
36802
|
+
const { start_anchor, end_anchor, new_text, start_anchor_line_start, end_anchor_line_start } = operation;
|
|
36803
|
+
if (start_anchor === START_OF_FILE && end_anchor === END_OF_FILE) {
|
|
36817
36804
|
return new_text;
|
|
36818
36805
|
}
|
|
36819
|
-
if (
|
|
36820
|
-
if (!
|
|
36806
|
+
if (start_anchor === START_OF_FILE) {
|
|
36807
|
+
if (!end_anchor) {
|
|
36821
36808
|
return new_text + fileContent;
|
|
36822
36809
|
}
|
|
36823
|
-
const afterIndex = findTextWithHint(fileContent,
|
|
36810
|
+
const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines);
|
|
36824
36811
|
return new_text + fileContent.slice(afterIndex);
|
|
36825
36812
|
}
|
|
36826
|
-
if (
|
|
36827
|
-
if (!
|
|
36813
|
+
if (end_anchor === END_OF_FILE) {
|
|
36814
|
+
if (!start_anchor) {
|
|
36828
36815
|
return fileContent + new_text;
|
|
36829
36816
|
}
|
|
36830
|
-
const beforeIndex = findTextWithHint(fileContent,
|
|
36831
|
-
const beforeEndIndex = beforeIndex +
|
|
36817
|
+
const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
|
|
36818
|
+
const beforeEndIndex = beforeIndex + start_anchor.length;
|
|
36832
36819
|
return fileContent.slice(0, beforeEndIndex) + new_text;
|
|
36833
36820
|
}
|
|
36834
|
-
if (
|
|
36835
|
-
const beforeIndex = findTextWithHint(fileContent,
|
|
36836
|
-
const beforeEndIndex = beforeIndex +
|
|
36837
|
-
const afterIndex = findTextWithHint(fileContent,
|
|
36821
|
+
if (start_anchor && end_anchor) {
|
|
36822
|
+
const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
|
|
36823
|
+
const beforeEndIndex = beforeIndex + start_anchor.length;
|
|
36824
|
+
const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines, beforeEndIndex);
|
|
36838
36825
|
return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(afterIndex);
|
|
36839
36826
|
}
|
|
36840
|
-
if (
|
|
36841
|
-
const beforeIndex = findTextWithHint(fileContent,
|
|
36842
|
-
const beforeEndIndex = beforeIndex +
|
|
36827
|
+
if (start_anchor) {
|
|
36828
|
+
const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
|
|
36829
|
+
const beforeEndIndex = beforeIndex + start_anchor.length;
|
|
36843
36830
|
return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(beforeEndIndex);
|
|
36844
36831
|
}
|
|
36845
|
-
if (
|
|
36846
|
-
const afterIndex = findTextWithHint(fileContent,
|
|
36832
|
+
if (end_anchor) {
|
|
36833
|
+
const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines);
|
|
36847
36834
|
return fileContent.slice(0, afterIndex) + new_text + fileContent.slice(afterIndex);
|
|
36848
36835
|
}
|
|
36849
|
-
throw new Error("Either
|
|
36836
|
+
throw new Error("Either start_anchor or end_anchor must be specified");
|
|
36850
36837
|
}
|
|
36851
36838
|
function findTextWithHint(content, searchText, lineHint, originalLines, startIndex = 0) {
|
|
36852
36839
|
if (lineHint && lineHint > 0 && lineHint <= originalLines.length) {
|
|
@@ -38067,37 +38054,37 @@ var toolInfo13 = {
|
|
|
38067
38054
|
},
|
|
38068
38055
|
{
|
|
38069
38056
|
name: "operations",
|
|
38070
|
-
description: "Edit operation with
|
|
38057
|
+
description: "Edit operation with start_anchor, end_anchor, new_text, and optional line range hints",
|
|
38071
38058
|
required: true,
|
|
38072
38059
|
allowMultiple: true,
|
|
38073
38060
|
children: [
|
|
38074
38061
|
{
|
|
38075
|
-
name: "
|
|
38062
|
+
name: "start_anchor",
|
|
38076
38063
|
description: `Text to find as the start anchor (use ${START_OF_FILE} for file start)`,
|
|
38077
38064
|
required: false,
|
|
38078
38065
|
usageValue: "Text before the edit location"
|
|
38079
38066
|
},
|
|
38080
38067
|
{
|
|
38081
|
-
name: "
|
|
38068
|
+
name: "end_anchor",
|
|
38082
38069
|
description: `Text to find as the end anchor (use ${END_OF_FILE} for file end)`,
|
|
38083
38070
|
required: false,
|
|
38084
38071
|
usageValue: "Text after the edit location"
|
|
38085
38072
|
},
|
|
38086
38073
|
{
|
|
38087
38074
|
name: "new_text",
|
|
38088
|
-
description: "Text to replace the content between
|
|
38075
|
+
description: "Text to replace the content between start_anchor and end_anchor",
|
|
38089
38076
|
required: true,
|
|
38090
38077
|
usageValue: "New text content"
|
|
38091
38078
|
},
|
|
38092
38079
|
{
|
|
38093
|
-
name: "
|
|
38094
|
-
description: "Optional line number hint for
|
|
38080
|
+
name: "start_anchor_line_start",
|
|
38081
|
+
description: "Optional line number hint for start_anchor location (1-based)",
|
|
38095
38082
|
required: false,
|
|
38096
38083
|
usageValue: "10"
|
|
38097
38084
|
},
|
|
38098
38085
|
{
|
|
38099
|
-
name: "
|
|
38100
|
-
description: "Optional line number hint for
|
|
38086
|
+
name: "end_anchor_line_start",
|
|
38087
|
+
description: "Optional line number hint for end_anchor location (1-based)",
|
|
38101
38088
|
required: false,
|
|
38102
38089
|
usageValue: "20"
|
|
38103
38090
|
}
|
|
@@ -38116,8 +38103,8 @@ var toolInfo13 = {
|
|
|
38116
38103
|
{
|
|
38117
38104
|
name: "operations",
|
|
38118
38105
|
value: {
|
|
38119
|
-
|
|
38120
|
-
|
|
38106
|
+
start_anchor: "function oldFunction() {",
|
|
38107
|
+
end_anchor: "}",
|
|
38121
38108
|
new_text: `
|
|
38122
38109
|
return "new implementation";
|
|
38123
38110
|
`
|
|
@@ -38135,8 +38122,8 @@ var toolInfo13 = {
|
|
|
38135
38122
|
{
|
|
38136
38123
|
name: "operations",
|
|
38137
38124
|
value: {
|
|
38138
|
-
|
|
38139
|
-
|
|
38125
|
+
start_anchor: START_OF_FILE,
|
|
38126
|
+
end_anchor: "export",
|
|
38140
38127
|
new_text: `// File header comment
|
|
38141
38128
|
`
|
|
38142
38129
|
}
|
|
@@ -38154,13 +38141,13 @@ var toolInfo13 = {
|
|
|
38154
38141
|
name: "operations",
|
|
38155
38142
|
value: [
|
|
38156
38143
|
{
|
|
38157
|
-
|
|
38158
|
-
|
|
38144
|
+
start_anchor: "import React",
|
|
38145
|
+
end_anchor: 'from "react"',
|
|
38159
38146
|
new_text: ", { useState }"
|
|
38160
38147
|
},
|
|
38161
38148
|
{
|
|
38162
|
-
|
|
38163
|
-
|
|
38149
|
+
start_anchor: "function Component() {",
|
|
38150
|
+
end_anchor: "return (",
|
|
38164
38151
|
new_text: `
|
|
38165
38152
|
const [state, setState] = useState(false);
|
|
38166
38153
|
`
|