MCPcopy Index your code
hub / github.com/simstudioai/sim / serializeTaskChat

Function serializeTaskChat

apps/sim/lib/copilot/vfs/serializers.ts:916–950  ·  view source on GitHub ↗
(rawMessages: unknown[])

Source from the content-addressed store, hash-verified

914}
915
916export function serializeTaskChat(rawMessages: unknown[]): string {
917 const filtered: { role: string; content: string }[] = []
918
919 for (const msg of rawMessages) {
920 if (!msg || typeof msg !== 'object') continue
921 const m = msg as Record<string, unknown>
922 const role = m.role as string | undefined
923 if (role !== 'user' && role !== 'assistant') continue
924
925 let content = ''
926 if (role === 'assistant' && Array.isArray(m.contentBlocks)) {
927 const textParts: string[] = []
928 for (const block of m.contentBlocks) {
929 if (
930 block &&
931 typeof block === 'object' &&
932 (block as any).type === 'text' &&
933 (block as any).content
934 ) {
935 textParts.push((block as any).content)
936 }
937 }
938 content = textParts.join('')
939 }
940
941 if (!content && typeof m.content === 'string') {
942 content = m.content
943 }
944
945 if (!content) continue
946 filtered.push({ role, content })
947 }
948
949 return JSON.stringify(filtered, null, 2)
950}

Callers 1

materializeTasksMethod · 0.90

Calls 2

joinMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected