Skip to content

Commit e1802f3

Browse files
authored
Merge pull request #3195 from Kilo-Org/christiaan/browser-crash
Prevent webview crash when browser tool is used with native tool calling enabled
2 parents 673aada + 93371d0 commit e1802f3

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

.changeset/shaggy-hotels-remain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"kilo-code": patch
3+
---
4+
5+
Fixed crash when browser tool is used with native tool calling enabled

packages/types/src/kilocode/native-function-calling.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const nativeFunctionCallingProviders = [
1717
"deepinfra",
1818
"xai",
1919
"zai",
20+
"human-relay",
2021
] satisfies ProviderName[] as ProviderName[]
2122

2223
const modelsDefaultingToNativeFunctionCalls = ["anthropic/claude-haiku-4.5"]

src/core/tools/browserActionTool.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,32 @@ import {
88
} from "../../shared/ExtensionMessage"
99
import { formatResponse } from "../prompts/responses"
1010

11+
function toStringlyTyped_kilocode(value: string | number[] | object | null | undefined): string | undefined {
12+
if (typeof value === "string") {
13+
console.debug("toStringlyTyped: returning string as-is", value)
14+
return value
15+
}
16+
if (Array.isArray(value)) {
17+
console.debug(
18+
"toStringlyTyped: model returned an array, this is not allowed by either the XML or JSON tool.",
19+
value,
20+
)
21+
return value.join(",")
22+
}
23+
if (value && typeof value === "object") {
24+
if ("x" in value && "y" in value) {
25+
console.debug("toStringlyTyped: x,y object", value)
26+
return `${value.x},${value.y}`
27+
}
28+
if ("width" in value && "height" in value) {
29+
console.debug("toStringlyTyped: width,height object", value)
30+
return `${value.width},${value.height}`
31+
}
32+
}
33+
console.debug("toStringlyTyped: returning undefined", value)
34+
return undefined
35+
}
36+
1137
export async function browserActionTool(
1238
cline: Task,
1339
block: ToolUse,
@@ -18,9 +44,9 @@ export async function browserActionTool(
1844
) {
1945
const action: BrowserAction | undefined = block.params.action as BrowserAction
2046
const url: string | undefined = block.params.url
21-
const coordinate: string | undefined = block.params.coordinate
47+
const coordinate: string | undefined = toStringlyTyped_kilocode(block.params.coordinate)
2248
const text: string | undefined = block.params.text
23-
const size: string | undefined = block.params.size
49+
const size: string | undefined = toStringlyTyped_kilocode(block.params.size)
2450

2551
if (!action || !browserActions.includes(action)) {
2652
// checking for action to ensure it is complete and valid

0 commit comments

Comments
 (0)