(payload: ExportChatDocxPayload)
| 76 | } |
| 77 | |
| 78 | export async function exportChatDocx(payload: ExportChatDocxPayload): Promise<{ |
| 79 | blob: Blob; |
| 80 | filename: string; |
| 81 | }> { |
| 82 | const response = await fetch(buildApiUrl("/api/chat/export/docx"), { |
| 83 | method: "POST", |
| 84 | credentials: "include", |
| 85 | headers: { |
| 86 | "Content-Type": "application/json", |
| 87 | }, |
| 88 | body: JSON.stringify({ |
| 89 | text: payload.text, |
| 90 | question: payload.question ?? "", |
| 91 | sources: payload.sources ?? [], |
| 92 | }), |
| 93 | }); |
| 94 | if (!response.ok) { |
| 95 | let message = response.statusText || "Export docx failed"; |
| 96 | try { |
| 97 | const json = (await response.json()) as { error?: string }; |
| 98 | message = json.error ?? message; |
| 99 | } catch { |
| 100 | // no-op |
| 101 | } |
| 102 | throw new Error(message); |
| 103 | } |
| 104 | const blob = await response.blob(); |
| 105 | return { |
| 106 | blob, |
| 107 | filename: parseFilename(response.headers.get("Content-Disposition")), |
| 108 | }; |
| 109 | } |
no test coverage detected