@juspay/neurolink
Version:
The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002
26 lines (25 loc) • 959 B
JavaScript
/**
* Strips base64 image/PDF payloads from Anthropic messages before they go on a
* trace attribute — one screenshot would otherwise be megabytes on a span.
* Other block types pass through; the serializer still applies its length cap.
*/
export function sanitizeAnthropicMessagesForTrace(messages) {
return messages.map((message) => {
if (typeof message.content === "string") {
return { role: message.role, content: message.content };
}
return {
role: message.role,
content: message.content.map((block) => {
if (block.type === "image" || block.type === "document") {
return {
type: block.type,
media_type: block.source.media_type,
base64_chars: block.source.data.length,
};
}
return block;
}),
};
});
}