mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-18 19:03:41 +00:00
fix: sanitize bedrock tool call ids (#781)
This commit is contained in:
parent
c45ea27de5
commit
ba8059a502
1 changed files with 8 additions and 3 deletions
|
|
@ -317,6 +317,11 @@ function buildSystemPrompt(
|
||||||
return blocks;
|
return blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sanitizeToolCallId(id: string): string {
|
||||||
|
const sanitized = id.replace(/[^a-zA-Z0-9_-]/g, "_");
|
||||||
|
return sanitized.length > 64 ? sanitized.slice(0, 64) : sanitized;
|
||||||
|
}
|
||||||
|
|
||||||
function convertMessages(context: Context, model: Model<"bedrock-converse-stream">): Message[] {
|
function convertMessages(context: Context, model: Model<"bedrock-converse-stream">): Message[] {
|
||||||
const result: Message[] = [];
|
const result: Message[] = [];
|
||||||
const transformedMessages = transformMessages(context.messages, model);
|
const transformedMessages = transformMessages(context.messages, model);
|
||||||
|
|
@ -359,7 +364,7 @@ function convertMessages(context: Context, model: Model<"bedrock-converse-stream
|
||||||
break;
|
break;
|
||||||
case "toolCall":
|
case "toolCall":
|
||||||
contentBlocks.push({
|
contentBlocks.push({
|
||||||
toolUse: { toolUseId: c.id, name: c.name, input: c.arguments },
|
toolUse: { toolUseId: sanitizeToolCallId(c.id), name: c.name, input: c.arguments },
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "thinking":
|
case "thinking":
|
||||||
|
|
@ -404,7 +409,7 @@ function convertMessages(context: Context, model: Model<"bedrock-converse-stream
|
||||||
// Add current tool result with all content blocks combined
|
// Add current tool result with all content blocks combined
|
||||||
toolResults.push({
|
toolResults.push({
|
||||||
toolResult: {
|
toolResult: {
|
||||||
toolUseId: m.toolCallId,
|
toolUseId: sanitizeToolCallId(m.toolCallId),
|
||||||
content: m.content.map((c) =>
|
content: m.content.map((c) =>
|
||||||
c.type === "image"
|
c.type === "image"
|
||||||
? { image: createImageBlock(c.mimeType, c.data) }
|
? { image: createImageBlock(c.mimeType, c.data) }
|
||||||
|
|
@ -420,7 +425,7 @@ function convertMessages(context: Context, model: Model<"bedrock-converse-stream
|
||||||
const nextMsg = transformedMessages[j] as ToolResultMessage;
|
const nextMsg = transformedMessages[j] as ToolResultMessage;
|
||||||
toolResults.push({
|
toolResults.push({
|
||||||
toolResult: {
|
toolResult: {
|
||||||
toolUseId: nextMsg.toolCallId,
|
toolUseId: sanitizeToolCallId(nextMsg.toolCallId),
|
||||||
content: nextMsg.content.map((c) =>
|
content: nextMsg.content.map((c) =>
|
||||||
c.type === "image"
|
c.type === "image"
|
||||||
? { image: createImageBlock(c.mimeType, c.data) }
|
? { image: createImageBlock(c.mimeType, c.data) }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue