Refactor
This commit is contained in:
@@ -4,7 +4,6 @@ import { CLAUDE_SYSTEM_PROMPT } from "../../config/appConstants.js";
|
||||
import { adjustMaxTokens } from "../formats/maxTokens.js";
|
||||
import { safeParseJSON } from "../concerns/json.js";
|
||||
import { parseDataUri } from "../concerns/image.js";
|
||||
import { effortToBudget } from "../concerns/thinking.js";
|
||||
import { extractTextContent } from "../formats/gemini.js";
|
||||
import { ROLE, OPENAI_BLOCK, CLAUDE_BLOCK } from "../schema/index.js";
|
||||
|
||||
@@ -175,25 +174,7 @@ Respond ONLY with the JSON object, no other text.`);
|
||||
result.tool_choice = convertOpenAIToolChoice(body.tool_choice);
|
||||
}
|
||||
|
||||
// Thinking configuration
|
||||
if (body.thinking) {
|
||||
result.thinking = {
|
||||
type: body.thinking.type || "enabled",
|
||||
...(body.thinking.budget_tokens && { budget_tokens: body.thinking.budget_tokens }),
|
||||
...(body.thinking.max_tokens && { max_tokens: body.thinking.max_tokens })
|
||||
};
|
||||
}
|
||||
|
||||
// Map OpenAI reasoning_effort → Claude thinking.budget_tokens
|
||||
// When client sends reasoning_effort (OpenAI format) but no explicit thinking block,
|
||||
// translate to Claude's native format.
|
||||
if (body.reasoning_effort && !result.thinking) {
|
||||
const budget = effortToBudget(body.reasoning_effort);
|
||||
if (budget) {
|
||||
result.thinking = { type: "enabled", budget_tokens: budget };
|
||||
}
|
||||
// budget === 0 (none) or undefined (unknown) → no thinking
|
||||
}
|
||||
// Thinking is normalized centrally by applyThinking (thinkingUnified.js) after translation.
|
||||
|
||||
// Attach toolNameMap to result for response translation
|
||||
if (toolNameMap.size > 0) {
|
||||
@@ -245,6 +226,16 @@ function getContentBlocksFromMessage(msg, toolNameMap = new Map()) {
|
||||
}
|
||||
} else if (part.type === OPENAI_BLOCK.IMAGE && part.source) {
|
||||
blocks.push({ type: CLAUDE_BLOCK.IMAGE, source: part.source });
|
||||
} else if (part.type === OPENAI_BLOCK.FILE && part.file) {
|
||||
// OpenAI file block -> Claude document (PDF only; Claude rejects other mimes).
|
||||
const fileData = part.file.file_data;
|
||||
const parsed = parseDataUri(fileData);
|
||||
if (parsed && parsed.mimeType === "application/pdf") {
|
||||
blocks.push({
|
||||
type: CLAUDE_BLOCK.DOCUMENT,
|
||||
source: { type: "base64", media_type: parsed.mimeType, data: parsed.base64 }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ import { FORMATS } from "../formats.js";
|
||||
import { DEFAULT_THINKING_AG_SIGNATURE, DEFAULT_THINKING_GEMINI_CLI_SIGNATURE } from "../../config/defaultThinkingSignature.js";
|
||||
import { ANTIGRAVITY_DEFAULT_SYSTEM } from "../../config/appConstants.js";
|
||||
import { openaiToClaudeRequestForAntigravity } from "./openai-to-claude.js";
|
||||
import { effortToThinkingLevel } from "../concerns/thinking.js";
|
||||
|
||||
function generateUUID() {
|
||||
return crypto.randomUUID();
|
||||
}
|
||||
@@ -230,23 +228,7 @@ export function openaiToGeminiRequest(model, body, stream) {
|
||||
// OpenAI -> Gemini CLI (Cloud Code Assist)
|
||||
export function openaiToGeminiCLIRequest(model, body, stream) {
|
||||
const gemini = openaiToGeminiBase(model, body, stream, DEFAULT_THINKING_GEMINI_CLI_SIGNATURE);
|
||||
const isClaude = model.toLowerCase().includes("claude");
|
||||
|
||||
// Map reasoning effort → thinkingConfig.thinkingLevel (gemini-3 enum: minimal|low|medium|high)
|
||||
// Gemini 3 cannot fully disable thinking; "none"/"off" map to "minimal" (closest to no-thinking)
|
||||
// Accept both OpenAI chat (reasoning_effort) and Responses (reasoning.effort) shapes
|
||||
const reasoningEffort = body.reasoning_effort ?? body.reasoning?.effort;
|
||||
if (reasoningEffort) {
|
||||
const level = effortToThinkingLevel(reasoningEffort);
|
||||
gemini.generationConfig.thinkingConfig = { thinkingLevel: level, includeThoughts: level !== "minimal" };
|
||||
}
|
||||
|
||||
// Claude-format thinking: disabled → minimal, enabled → high
|
||||
if (body.thinking?.type === "disabled") {
|
||||
gemini.generationConfig.thinkingConfig = { thinkingLevel: "minimal", includeThoughts: false };
|
||||
} else if (body.thinking?.type === "enabled") {
|
||||
gemini.generationConfig.thinkingConfig = { thinkingLevel: "high", includeThoughts: true };
|
||||
}
|
||||
// Thinking is normalized centrally by applyThinking (thinkingUnified.js) after translation.
|
||||
|
||||
// Clean schema for tools
|
||||
if (gemini.tools?.[0]?.functionDeclarations) {
|
||||
|
||||
Reference in New Issue
Block a user