(value: unknown)
| 152 | } |
| 153 | |
| 154 | function 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 | |
| 181 | function parseChatResourcesResponse(value: unknown): { resources: MothershipResource[] } { |
| 182 | assertValid(isRecordLike(value), 'Invalid chat resources response: body must be an object') |
no test coverage detected