-
Notifications
You must be signed in to change notification settings - Fork 0
Add BrowserOS tool-calling mode to prevent environment-refusal responses #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -38,6 +38,7 @@ export interface CodexOptions { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| signal?: AbortSignal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tools?: any[]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tool_choice?: any; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| browseros_mode?: boolean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export interface ParsedToolCall { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -74,27 +75,77 @@ export type CodexStreamEvent = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export function parseToolCalls(text: string): ParsedToolCall[] { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const calls: ParsedToolCall[] = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const regex = /<tool_call>([\s\S]*?)<\/tool_call>/g; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let match; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const seen = new Set<string>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let callIndex = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while ((match = regex.exec(text)) !== null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const pushCall = (raw: any) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const name = raw?.name || raw?.toolName || raw?.function?.name || ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const argsRaw = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raw?.arguments ?? raw?.input ?? raw?.parameters ?? raw?.function?.arguments; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!name) return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const args = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| typeof argsRaw === "string" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? argsRaw | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : JSON.stringify(argsRaw ?? {}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+82
to
+89
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const name = raw?.name || raw?.toolName || raw?.function?.name || ""; | |
| const argsRaw = | |
| raw?.arguments ?? raw?.input ?? raw?.parameters ?? raw?.function?.arguments; | |
| if (!name) return; | |
| const args = | |
| typeof argsRaw === "string" | |
| ? argsRaw | |
| : JSON.stringify(argsRaw ?? {}); | |
| if (!raw || typeof raw !== "object") return; | |
| // Support only canonical tool-call shapes: | |
| // 1) { function: { name, arguments } } | |
| // 2) { name, arguments } | |
| let name: string | undefined; | |
| let argsRaw: any; | |
| if (raw.function && typeof raw.function === "object") { | |
| name = typeof raw.function.name === "string" ? raw.function.name : undefined; | |
| argsRaw = raw.function.arguments; | |
| } else { | |
| name = typeof raw.name === "string" ? raw.name : undefined; | |
| argsRaw = raw.arguments; | |
| } | |
| // Require both a valid name and explicit arguments to treat this as a tool call. | |
| if (!name || argsRaw === undefined) return; | |
| const args = | |
| typeof argsRaw === "string" ? argsRaw : JSON.stringify(argsRaw); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warning logs a preview of the assistant output (
accumulatedText) when tools are provided but no tool calls are parsed. That content may include sensitive user data or secrets and will end up in server logs. Consider gating this behind a debug flag and/or redacting content (e.g., log only length / hash / truncated-with-redaction) to reduce accidental data exposure.