Serializes and parses chat message content and legacy tool calls for AI SDKs. Use this to normalize data between different AI model interfaces and chat message formats.
// Source: https://github.com/ThinkInAIXYZ/deepchat | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
import type { ChatMessage } from '@shared/types/core/chat-message'
import { generateId } from 'ai'
import { jsonrepair } from 'jsonrepair'
export interface ParsedLegacyToolCall {
id: string
type: 'function'
function: {
name: string
arguments: string
}
}
export function serializeChatMessageContent(content: ChatMessage['content']): string {
if (content == null) {
return ''
}
if (typeof content === 'string') {
return content
}
return content
.map((part) => {
if (part.type === 'text') {
return part.text
}
if (part.type
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key