@ai-sdk/anthropic
Advanced tools
Comparing version 0.0.34 to 0.0.35
@@ -125,20 +125,21 @@ "use strict"; | ||
case "assistant": { | ||
if (block.messages.length > 1) { | ||
throw new import_provider.UnsupportedFunctionalityError({ | ||
functionality: "Multiple assistant messages in block" | ||
}); | ||
} | ||
const { content } = block.messages[0]; | ||
messages.push({ | ||
role: "assistant", | ||
content: content.map((part, j) => { | ||
const anthropicContent = []; | ||
for (const { content } of block.messages) { | ||
for (let j = 0; j < content.length; j++) { | ||
const part = content[j]; | ||
switch (part.type) { | ||
case "text": { | ||
if (i === blocks.length - 1 && j === block.messages.length - 1) { | ||
return { type: "text", text: part.text.trim() }; | ||
} | ||
return { type: "text", text: part.text }; | ||
anthropicContent.push({ | ||
type: "text", | ||
text: ( | ||
// trim the last text part if it's the last message in the block | ||
// because Anthropic does not allow trailing whitespace | ||
// in pre-filled assistant responses | ||
i === blocks.length - 1 && j === block.messages.length - 1 ? part.text.trim() : part.text | ||
) | ||
}); | ||
break; | ||
} | ||
case "tool-call": { | ||
return { | ||
anthropicContent.push({ | ||
type: "tool_use", | ||
@@ -148,7 +149,9 @@ id: part.toolCallId, | ||
input: part.args | ||
}; | ||
}); | ||
break; | ||
} | ||
} | ||
}) | ||
}); | ||
} | ||
} | ||
messages.push({ role: "assistant", content: anthropicContent }); | ||
break; | ||
@@ -155,0 +158,0 @@ } |
@@ -125,20 +125,21 @@ "use strict"; | ||
case "assistant": { | ||
if (block.messages.length > 1) { | ||
throw new import_provider.UnsupportedFunctionalityError({ | ||
functionality: "Multiple assistant messages in block" | ||
}); | ||
} | ||
const { content } = block.messages[0]; | ||
messages.push({ | ||
role: "assistant", | ||
content: content.map((part, j) => { | ||
const anthropicContent = []; | ||
for (const { content } of block.messages) { | ||
for (let j = 0; j < content.length; j++) { | ||
const part = content[j]; | ||
switch (part.type) { | ||
case "text": { | ||
if (i === blocks.length - 1 && j === block.messages.length - 1) { | ||
return { type: "text", text: part.text.trim() }; | ||
} | ||
return { type: "text", text: part.text }; | ||
anthropicContent.push({ | ||
type: "text", | ||
text: ( | ||
// trim the last text part if it's the last message in the block | ||
// because Anthropic does not allow trailing whitespace | ||
// in pre-filled assistant responses | ||
i === blocks.length - 1 && j === block.messages.length - 1 ? part.text.trim() : part.text | ||
) | ||
}); | ||
break; | ||
} | ||
case "tool-call": { | ||
return { | ||
anthropicContent.push({ | ||
type: "tool_use", | ||
@@ -148,7 +149,9 @@ id: part.toolCallId, | ||
input: part.args | ||
}; | ||
}); | ||
break; | ||
} | ||
} | ||
}) | ||
}); | ||
} | ||
} | ||
messages.push({ role: "assistant", content: anthropicContent }); | ||
break; | ||
@@ -155,0 +158,0 @@ } |
{ | ||
"name": "@ai-sdk/anthropic", | ||
"version": "0.0.34", | ||
"version": "0.0.35", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
160953
2177