fix(ai): normalize tool call ids and handoff tests fixes #821

This commit is contained in:
Mario Zechner 2026-01-19 00:10:49 +01:00
parent 298af5c1c2
commit 2c7c23b865
19 changed files with 570 additions and 1376 deletions

View file

@ -59,10 +59,10 @@ function resolveThoughtSignature(isSameProviderAndModel: boolean, signature: str
}
/**
* Claude models via Google APIs require explicit tool call IDs in function calls/responses.
* Models via Google APIs that require explicit tool call IDs in function calls/responses.
*/
export function requiresToolCallId(modelId: string): boolean {
return modelId.startsWith("claude-");
return modelId.startsWith("claude-") || modelId.startsWith("gpt-oss-");
}
/**
@ -70,7 +70,12 @@ export function requiresToolCallId(modelId: string): boolean {
*/
export function convertMessages<T extends GoogleApiType>(model: Model<T>, context: Context): Content[] {
const contents: Content[] = [];
const transformedMessages = transformMessages(context.messages, model);
const normalizeToolCallId = (id: string): string => {
if (!requiresToolCallId(model.id)) return id;
return id.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 64);
};
const transformedMessages = transformMessages(context.messages, model, normalizeToolCallId);
for (const msg of transformedMessages) {
if (msg.role === "user") {