// get_source(T3.7)— 指回原文:給一個節點名,回它所有 triplet 的來源指標。 // 鐵律:走 base API、零 SQL。圖在插件層組裝。 // 用途:圖遍歷找到一筆知識後,回跳產生它的 canonical MD(source.uri + anchor)。 import type { KbdbClient } from '../lib/kbdb-client'; import { getNodeEdges } from './graph-nodes'; export type SourceRef = { uri: string | null; // 來源穩定識別(github:owner/repo@path) anchor: string | null; // 檔內定位(heading slug / block id) block_id: string | null; // 向後相容:Logseq block id content_hash: string | null; // 該批快照 hash edge: { subject: string; predicate: string; object: string }; }; /** 給節點名,回觸及它的(active)triplet 的來源指標清單,去重同 uri+anchor。 */ export async function getSource(client: KbdbClient, node: string): Promise { const edges = await getNodeEdges(client, node); // 已 active-only(經 queryTriplets) const seen = new Set(); const refs: SourceRef[] = []; for (const t of edges) { const key = `${t.source_uri ?? ''}#${t.source_anchor ?? ''}`; if (seen.has(key)) continue; seen.add(key); refs.push({ uri: t.source_uri, anchor: t.source_anchor, block_id: t.source_block_id, content_hash: t.content_hash, edge: { subject: t.subject, predicate: t.predicate, object: t.object }, }); } return refs; }