(message)
| 18 | } |
| 19 | |
| 20 | function toAnthropicAssistantContent(message) { |
| 21 | const content = []; |
| 22 | |
| 23 | if (message.content) { |
| 24 | content.push({ type: "text", text: message.content }); |
| 25 | } |
| 26 | |
| 27 | for (const toolCall of message.tool_calls ?? []) { |
| 28 | content.push({ |
| 29 | type: "tool_use", |
| 30 | id: toolCall.id, |
| 31 | name: toolCall.function.name, |
| 32 | input: parseArguments(toolCall.function.arguments), |
| 33 | }); |
| 34 | } |
| 35 | |
| 36 | if (content.length === 0) { |
| 37 | return ""; |
| 38 | } |
| 39 | |
| 40 | return content.length === 1 && content[0].type === "text" ? content[0].text : content; |
| 41 | } |
| 42 | |
| 43 | function toAnthropicUserContent(message) { |
| 44 | return typeof message.content === "string" ? message.content : JSON.stringify(message.content ?? ""); |
no test coverage detected