MCPcopy
hub / github.com/tashfeenahmed/freellmapi / contentToString

Function contentToString

server/src/lib/content.ts:14–34  ·  view source on GitHub ↗
(content: unknown)

Source from the content-addressed store, hash-verified

12export type ContentBlock = ContentTextBlock | { type: string; [key: string]: unknown };
13
14export function contentToString(content: unknown): string {
15 if (typeof content === 'string') return content;
16 if (content == null) return '';
17 if (Array.isArray(content)) {
18 return content
19 .map((b) => {
20 if (typeof b === 'string') return b;
21 const block = b as { type?: string; text?: unknown };
22 // OpenAI blocks carry type:'text'; Gemini-lineage agents (Qwen Code,
23 // AionUI) send part-style `{ text }` with no type at all — accept any
24 // block whose `text` is a string and whose type doesn't say it's
25 // something else. (#200)
26 if (typeof block?.text === 'string' && (block.type === 'text' || block.type === undefined)) {
27 return block.text;
28 }
29 return '';
30 })
31 .join('');
32 }
33 return '';
34}
35
36export function flattenMessageContent(messages: ChatMessage[]): ChatMessage[] {
37 return messages.map((m) => ({

Callers 12

userContentToPartsFunction · 0.85
toGeminiContentsFunction · 0.85
normalizeMessagesMethod · 0.85
getSessionKeyFunction · 0.85
proxy.tsFile · 0.85
responses.tsFile · 0.85
flattenMessageContentFunction · 0.85
normalizeOutboundContentFunction · 0.85
runModelCallFunction · 0.85
trimContentFunction · 0.85
content.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected