Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions lib/messages/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { loadPrompt } from "../prompts"
import {
extractParameterKey,
buildToolIdList,
createSyntheticAssistantMessageWithToolPart,
createSyntheticAssistantMessage,
isIgnoredUserMessage,
} from "./utils"
import { getFilePathFromParameters, isProtectedFilePath } from "../protected-file-patterns"
Expand Down Expand Up @@ -149,7 +149,5 @@ export const insertPruneToolContext = (

const userInfo = lastUserMessage.info as UserMessage
const variant = state.variant ?? userInfo.variant
messages.push(
createSyntheticAssistantMessageWithToolPart(lastUserMessage, prunableToolsContent, variant),
)
messages.push(createSyntheticAssistantMessage(lastUserMessage, prunableToolsContent, variant))
}
24 changes: 6 additions & 18 deletions lib/messages/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const isGeminiModel = (modelID: string): boolean => {
return lowerModelID.includes("gemini")
}

export const createSyntheticAssistantMessageWithToolPart = (
export const createSyntheticAssistantMessage = (
baseMessage: WithParts,
content: string,
variant?: string,
Expand All @@ -39,24 +39,11 @@ export const createSyntheticAssistantMessageWithToolPart = (
...(variant !== undefined && { variant }),
}

// For Gemini models, inject as text to avoid thought signature requirements
// Gemini 3+ has strict validation requiring thoughtSignature on functionCall parts
if (isGeminiModel(userInfo.model.modelID)) {
return {
info: baseInfo,
parts: [
{
id: SYNTHETIC_PART_ID,
sessionID: userInfo.sessionID,
messageID: SYNTHETIC_MESSAGE_ID,
type: "text",
text: content,
},
],
}
}
// For Gemini models, add thoughtSignature bypass to avoid validation errors
const toolPartMetadata = isGeminiModel(userInfo.model.modelID)
? { google: { thoughtSignature: "skip_thought_signature_validator" } }
: undefined

// For other models, use tool part for cleaner context
return {
info: baseInfo,
parts: [
Expand All @@ -75,6 +62,7 @@ export const createSyntheticAssistantMessageWithToolPart = (
metadata: {},
time: { start: now, end: now },
},
...(toolPartMetadata && { metadata: toolPartMetadata }),
},
],
}
Expand Down