(message: unknown)
| 1 | import type { WithParts } from "../state" |
| 2 | |
| 3 | export function isMessageWithInfo(message: unknown): message is WithParts { |
| 4 | if (!message || typeof message !== "object") { |
| 5 | return false |
| 6 | } |
| 7 | |
| 8 | const info = (message as any).info |
| 9 | const parts = (message as any).parts |
| 10 | if (!info || typeof info !== "object") { |
| 11 | return false |
| 12 | } |
| 13 | |
| 14 | return ( |
| 15 | typeof info.id === "string" && |
| 16 | info.id.length > 0 && |
| 17 | typeof info.sessionID === "string" && |
| 18 | info.sessionID.length > 0 && |
| 19 | (info.role === "user" || info.role === "assistant") && |
| 20 | info.time && |
| 21 | typeof info.time === "object" && |
| 22 | typeof info.time.created === "number" && |
| 23 | Array.isArray(parts) |
| 24 | ) |
| 25 | } |
| 26 | |
| 27 | export function filterMessages(messages: unknown): WithParts[] { |
| 28 | if (!Array.isArray(messages)) { |
no outgoing calls
no test coverage detected