mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 13:38:31 +00:00
refactor(open-sse): extract safeParseJSON util, dedup tryParseJSON (B5)
Consolidate two tryParseJSON variants into helpers/jsonUtil.js with explicit fallback param. Preserve exact per-call semantics: openai-to-claude passthrough (fallback=str), geminiHelper null. geminiHelper keeps tryParseJSON re-export. No behavior change; gate: no regression. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import { register } from "../index.js";
|
||||
import { FORMATS } from "../formats.js";
|
||||
import { CLAUDE_SYSTEM_PROMPT } from "../../config/appConstants.js";
|
||||
import { adjustMaxTokens } from "../helpers/maxTokensHelper.js";
|
||||
import { safeParseJSON } from "../helpers/jsonUtil.js";
|
||||
|
||||
// Empty prefix matches real Claude Code behavior (no tool name prefix).
|
||||
// Previously "proxy_" was used but this is a detectable fingerprint difference.
|
||||
@@ -281,7 +282,7 @@ function getContentBlocksFromMessage(msg, toolNameMap = new Map()) {
|
||||
type: "tool_use",
|
||||
id: tc.id,
|
||||
name: toolName,
|
||||
input: tryParseJSON(tc.function.arguments)
|
||||
input: safeParseJSON(tc.function.arguments, tc.function.arguments)
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -332,16 +333,6 @@ function extractTextContent(content) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// Try parse JSON
|
||||
function tryParseJSON(str) {
|
||||
if (typeof str !== "string") return str;
|
||||
try {
|
||||
return JSON.parse(str);
|
||||
} catch {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
// OpenAI -> Claude format for Antigravity (without system prompt modifications)
|
||||
function openaiToClaudeRequestForAntigravity(model, body, stream) {
|
||||
const result = openaiToClaudeRequest(model, body, stream);
|
||||
|
||||
Reference in New Issue
Block a user