/** * Build worklist of links for prompt mode. */ import { App, TFile } from "obsidian"; import type { EdgeVocabulary } from "../vocab/types"; import { extractWikilinks } from "./sectionParser"; import { extractExistingMappings } from "./mappingExtractor"; export interface LinkWorkItem { link: string; // Wikilink basename targetType: string | null; // Note type from metadataCache/frontmatter currentType: string | null; // Existing edge type mapping, if any } export interface SectionWorklist { sectionHeading: string | null; items: LinkWorkItem[]; } /** * Build worklist for a section. */ export async function buildSectionWorklist( app: App, sectionContent: string, sectionHeading: string | null, wrapperCalloutType: string, wrapperTitle: string ): Promise { // Extract all wikilinks (deduplicated) const links = extractWikilinks(sectionContent); // Extract existing mappings const mappingState = extractExistingMappings( sectionContent, wrapperCalloutType, wrapperTitle ); // Build worklist items const items: LinkWorkItem[] = []; for (const link of links) { // Get target file const targetFile = app.metadataCache.getFirstLinkpathDest(link, ""); // Get target type from frontmatter let targetType: string | null = null; if (targetFile) { const cache = app.metadataCache.getFileCache(targetFile); if (cache?.frontmatter) { targetType = cache.frontmatter.type || cache.frontmatter.noteType || null; if (targetType && typeof targetType !== "string") { targetType = String(targetType); } } } // Get current mapping const currentType = mappingState.existingMappings.get(link) || null; items.push({ link, targetType, currentType, }); } return { sectionHeading, items, }; } /** * Get source type from current file. */ export function getSourceType(app: App, file: TFile): string | null { const cache = app.metadataCache.getFileCache(file); if (cache?.frontmatter) { const type = cache.frontmatter.type || cache.frontmatter.noteType || null; if (type && typeof type === "string") { return type; } } return null; }