mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 12:22:14 +03:00
Integrated into release/v3.8.2
This commit is contained in:
committed by
GitHub
parent
ae73b90280
commit
caefdfa971
@@ -1,4 +1,8 @@
|
||||
import { FORMATS } from "../translator/formats.ts";
|
||||
import {
|
||||
buildGeminiThoughtSignatureKey,
|
||||
storeGeminiThoughtSignature,
|
||||
} from "../services/geminiThoughtSignatureStore.ts";
|
||||
|
||||
type JsonRecord = Record<string, unknown>;
|
||||
|
||||
@@ -278,6 +282,7 @@ export function translateNonStreamingResponse(
|
||||
const contentParts: JsonRecord[] = [];
|
||||
const toolCalls: JsonRecord[] = [];
|
||||
let reasoningContent = "";
|
||||
let pendingThoughtSignature = "";
|
||||
|
||||
if (Array.isArray(content.parts)) {
|
||||
for (const part of content.parts) {
|
||||
@@ -287,6 +292,15 @@ export function translateNonStreamingResponse(
|
||||
continue;
|
||||
}
|
||||
|
||||
// Capture thoughtSignature from thinking parts (Gemini thinking models)
|
||||
// so it can be stored alongside any subsequent functionCall part.
|
||||
const partThoughtSig = toString(
|
||||
partObj.thoughtSignature ?? partObj.thought_signature
|
||||
);
|
||||
if (partThoughtSig) {
|
||||
pendingThoughtSignature = partThoughtSig;
|
||||
}
|
||||
|
||||
if (typeof partObj.text === "string") {
|
||||
textContent += partObj.text;
|
||||
contentParts.push({ type: "text", text: partObj.text });
|
||||
@@ -309,11 +323,23 @@ export function translateNonStreamingResponse(
|
||||
const rawName = toString(fn.name);
|
||||
const restoredName = toolNameMap?.get(rawName) ?? rawName;
|
||||
const nativeId = toString(fn.id);
|
||||
const toolCallId =
|
||||
nativeId.length > 0
|
||||
? nativeId
|
||||
: `call_${toString(restoredName, "unknown")}_${Date.now()}_${toolCalls.length}`;
|
||||
|
||||
// Persist the thought signature so openai-to-gemini can
|
||||
// resolve it on the next turn. Use the part-level field
|
||||
// (part.thoughtSignature) and fall back to any signature
|
||||
// captured from an earlier thinking-only part.
|
||||
const sig = partThoughtSig || pendingThoughtSignature;
|
||||
if (sig) {
|
||||
const sigKey = buildGeminiThoughtSignatureKey(null, toolCallId);
|
||||
storeGeminiThoughtSignature(sigKey, sig);
|
||||
}
|
||||
|
||||
toolCalls.push({
|
||||
id:
|
||||
nativeId.length > 0
|
||||
? nativeId
|
||||
: `call_${toString(restoredName, "unknown")}_${Date.now()}_${toolCalls.length}`,
|
||||
id: toolCallId,
|
||||
type: "function",
|
||||
function: {
|
||||
name: restoredName,
|
||||
|
||||
Reference in New Issue
Block a user