UNPKG

@mastra/core

Version:
53 lines • 3.47 kB
import type { KnowledgePage, KnowledgeStorage } from '../storage/domains/knowledge/index.js'; /** The `[[ref]]`s in a markdown body outside code, trimmed, with how many times each appears. */ export declare function knowledgeBodyLinkRefs(body: string | undefined): Map<string, number>; /** * Resolves body `[[ref]]`s the way `run.page(ref)` does (id, `scope#key/key` path, scope address, * unique name), but over the whole store: the index must not depend on who wrote the body, and reads * gate every link by the reader's scopes. A name resolves to the one live page with that name in the * source page's home scope, else to the one in the whole store; an ambiguous name stays unresolved. * Ids and scope addresses are looked up in one batch per call, and answers are kept for the * resolver's life, so pages re-synced together share their lookups. */ declare class BodyLinkResolver { #private; /** Refs looked up in the store so far (answers reused from earlier calls don't count). */ looked: number; constructor(storage: KnowledgeStorage); resolve(refs: string[], homeScopeId: string): Promise<Map<string, string | null>>; } /** Rewrites a page's body-link rows from its current body; a deleted page keeps none. */ export declare function syncKnowledgePageBodyLinks(storage: KnowledgeStorage, page: KnowledgePage, resolver?: BodyLinkResolver): Promise<void>; /** The page and its live ordinary descendants, at most {@link MAX_KNOWLEDGE_MOVE_PAGES} + 1. */ export declare function knowledgeSubtree(storage: KnowledgeStorage, root: KnowledgePage): Promise<KnowledgePage[]>; /** * Most linking pages one write re-resolves. Past it, or once a write has looked up * {@link MAX_KNOWLEDGE_PAGE_BODY_LINKS} refs, the rest keep their links as they were until they are * next written or `knowledge.reindexLinks()` runs; the write reports how many it left. */ export declare const MAX_KNOWLEDGE_LINK_REFRESH_SOURCES = 100; /** * Most same-named pages a write checks for links its page made ambiguous or took over: one under the * store's page list limit, so a full page means there may be more. Past it, links to the rest keep * their targets until `knowledge.reindexLinks()` runs; the write reports it. */ export declare const MAX_KNOWLEDGE_LINK_REFRESH_NAMESAKES: number; /** * Re-resolves the pages whose body links one of `pages` or names a ref one of them answers to now, * after they were created, renamed, moved, merged or deleted, in page id order up to * {@link MAX_KNOWLEDGE_LINK_REFRESH_SOURCES}. With `withDescendants`, the pages' subtrees count too * (their paths changed with them). Throws after the update when it left linking pages out, so the * caller's {@link updateKnowledgeLinks} reports it. */ export declare function refreshKnowledgeLinksTo(storage: KnowledgeStorage, pages: KnowledgePage[], options?: { withDescendants?: boolean; }): Promise<void>; /** * Runs a link-index update after a write that already landed. A store without the link index skips * it silently; any other failure is reported, not thrown, since the write itself succeeded. */ export declare function updateKnowledgeLinks(warn: ((message: string) => void) | undefined, work: () => Promise<void>): Promise<void>; /** Rebuilds every page's body links from its body. Returns how many pages were indexed. */ export declare function reindexKnowledgeLinks(storage: KnowledgeStorage): Promise<number>; export {}; //# sourceMappingURL=links.d.ts.map