( output: unknown )
| 84 | } |
| 85 | |
| 86 | export function parseCitationsFromToolOutput( |
| 87 | output: unknown |
| 88 | ): CitationsPayload | null { |
| 89 | const texts = extractTextItems(output) |
| 90 | for (const text of texts) { |
| 91 | const parsed = tryParseJson(text) |
| 92 | if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) { |
| 93 | const rag = fromRagPayload(parsed as Record<string, unknown>) |
| 94 | if (rag) return rag |
| 95 | } |
| 96 | if (parsed !== null) { |
| 97 | const web = fromWebPayload(parsed) |
| 98 | if (web) return web |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | if (output && typeof output === 'object' && !Array.isArray(output)) { |
| 103 | const rag = fromRagPayload(output as Record<string, unknown>) |
| 104 | if (rag) return rag |
| 105 | } |
| 106 | const web = fromWebPayload(output) |
| 107 | if (web) return web |
| 108 | |
| 109 | return null |
| 110 | } |
no test coverage detected