Spaces:
Runtime error
Runtime error
Download frontend/src/hooks/reportSuggestions.ts from firebird-technologies/NoteStack-Test: direct link, hf CLI and curl.
- Browser
- Download file 1.14 kB
-
https://huggingface.co/spaces/firebird-technologies/NoteStack-Test/resolve/main/frontend/src/hooks/reportSuggestions.ts
- Command line
-
hf download hf://spaces/firebird-technologies/NoteStack-Test/frontend/src/hooks/reportSuggestions.ts
-
curl -L -o reportSuggestions.ts https://huggingface.co/spaces/firebird-technologies/NoteStack-Test/resolve/main/frontend/src/hooks/reportSuggestions.ts
1.14 kB
| import { reportsApi } from "../api/endpoints"; | |
| import type { ReportTemplate } from "../api/types"; | |
| /** The suggested report templates for some sources. The server keeps them (prepared as soon as ideas are extracted), so a repeat is | |
| * instant; this also shares one request between the notebook page asking early and the dialog asking when it opens. */ | |
| const asked = new Map<string, Promise<ReportTemplate[]>>(); | |
| export function suggestTemplates(body: Record<string, unknown>): Promise<ReportTemplate[]> { | |
| const key = JSON.stringify(body); | |
| let found = asked.get(key); | |
| if (!found) { | |
| found = reportsApi.suggest(body).then((r) => r.templates).catch((e) => { | |
| asked.delete(key); // a failure is tried again next time | |
| throw e; | |
| }); | |
| asked.set(key, found); | |
| } | |
| return found; | |
| } | |
| /** Ask for a notebook's templates ahead of time, for the posts the Create report dialog starts with ticked, so they are ready when it opens. */ | |
| export function prefetchSuggestions(notebookId: string, postIds: string[]) { | |
| if (postIds.length) suggestTemplates({ document_ids: postIds, notebook_id: notebookId }).catch(() => undefined); | |
| } | |