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

Function parseChatHistory

apps/sim/hooks/queries/mothership-chats.ts:154–179  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

152}
153
154function parseChatHistory(value: unknown): MothershipChatHistory {
155 const responseContext = 'Invalid chat response'
156 const chatContext = `${responseContext}: chat`
157
158 assertValid(isRecordLike(value), `${responseContext}: body must be an object`)
159 assertValid(isRecordLike(value.chat), `${chatContext} must be an object`)
160
161 const chat = value.chat
162
163 assertValid(typeof chat.id === 'string', `${chatContext}.id must be a string`)
164 assertValid(isNullableString(chat.title), `${chatContext}.title must be a string or null`)
165 assertValid(Array.isArray(chat.messages), `${chatContext}.messages must be an array`)
166 assertValid(
167 isNullableString(chat.activeStreamId),
168 `${chatContext}.activeStreamId must be a string or null`
169 )
170
171 return {
172 id: chat.id,
173 title: chat.title,
174 messages: normalizeMessages(chat.messages),
175 activeStreamId: chat.activeStreamId,
176 resources: parseResources(chat.resources, `${chatContext}.resources`),
177 streamSnapshot: parseStrictStreamSnapshot(chat.streamSnapshot, `${chatContext}.streamSnapshot`),
178 }
179}
180
181function parseChatResourcesResponse(value: unknown): { resources: MothershipResource[] } {
182 assertValid(isRecordLike(value), 'Invalid chat resources response: body must be an object')

Callers 1

Calls 6

isRecordLikeFunction · 0.90
assertValidFunction · 0.85
isNullableStringFunction · 0.85
normalizeMessagesFunction · 0.85
parseResourcesFunction · 0.85

Tested by

no test coverage detected