|
1 | | -import { getLoggedInClient } from "./supabaseContext"; |
| 1 | +import { getLoggedInClient, getSupabaseContext } from "./supabaseContext"; |
2 | 2 | import { Result } from "./types"; |
3 | 3 | import normalizePageTitle from "roamjs-components/queries/normalizePageTitle"; |
4 | 4 | import findDiscourseNode from "./findDiscourseNode"; |
5 | 5 | import { nextApiRoot } from "@repo/utils/execContext"; |
6 | 6 | import { DiscourseNode } from "./getDiscourseNodes"; |
7 | 7 | import getExtensionAPI from "roamjs-components/util/extensionApiContext"; |
| 8 | +import { getAllNodes } from "@repo/database/lib/queries"; |
8 | 9 |
|
9 | 10 | type ApiEmbeddingResponse = { |
10 | 11 | data: Array<{ |
@@ -455,26 +456,30 @@ export const performHydeSearch = async ({ |
455 | 456 | ); |
456 | 457 |
|
457 | 458 | if (useAllPagesForSuggestions) { |
458 | | - // TODO: Use Supabase to get all pages |
459 | | - candidateNodesForHyde = (await getAllPageByUidAsync()) |
460 | | - .map(([pageName, pageUid]) => { |
461 | | - if (!pageUid || pageUid === blockUid) return null; |
462 | | - const node = findDiscourseNode(pageUid); |
463 | | - if ( |
464 | | - !node || |
465 | | - node.backedBy === "default" || |
466 | | - !validTypes.includes(node.type) || |
467 | | - existingUids.has(pageUid) |
468 | | - ) { |
469 | | - return null; |
470 | | - } |
| 459 | + const context = await getSupabaseContext(); |
| 460 | + if (!context) return []; |
| 461 | + const supabase = await getLoggedInClient(); |
| 462 | + const spaceId = context.spaceId; |
| 463 | + if (!supabase) return []; |
| 464 | + |
| 465 | + candidateNodesForHyde = ( |
| 466 | + await getAllNodes({ |
| 467 | + supabase, |
| 468 | + spaceId, |
| 469 | + fields: { content: ["source_local_id", "text"] }, |
| 470 | + ofTypes: validTypes, |
| 471 | + pagination: { limit: 10000 }, |
| 472 | + }) |
| 473 | + ) |
| 474 | + .map((c) => { |
| 475 | + const node = findDiscourseNode(c.Content?.source_local_id || ""); |
471 | 476 | return { |
472 | | - uid: pageUid, |
473 | | - text: pageName, |
474 | | - type: node.type, |
475 | | - } as SuggestedNode; |
| 477 | + uid: c.Content?.source_local_id || "", |
| 478 | + text: c.Content?.text || "", |
| 479 | + type: node ? node.type : "", |
| 480 | + }; |
476 | 481 | }) |
477 | | - .filter((n): n is SuggestedNode => n !== null); |
| 482 | + .filter((n) => n.uid && n.text && n.type); |
478 | 483 | } else { |
479 | 484 | const referenced: { uid: string; text: string }[] = []; |
480 | 485 | if (shouldGrabFromReferencedPages) { |
|
0 commit comments