@mastra/core
Version:
181 lines • 8.52 kB
TypeScript
import type { KnowledgeNote, KnowledgePage, KnowledgePageActivityEvent, KnowledgePageLinkCounts, KnowledgePageLinkEdge, KnowledgePageSearchHit, KnowledgePageStore, KnowledgePin, KnowledgeReadScope } from '../storage/index.js';
import type { KnowledgeRole } from './declarations.js';
/**
* Read-only views over the schema-4 page store for browsing UIs (Mastra Studio, Factory).
*
* Every reader takes the caller's `read` scope and passes it to each store call, so a page or note the
* caller can't read behaves like a missing id. `'all'` is for host surfaces behind their own auth.
* Scope pages are structure the store lists without a read filter; these readers only return the
* scope pages `read` allows, and hoist readable scopes found below an unreadable one so a bound
* viewer still reaches them. These functions never write.
*
* @experimental Knowledge APIs are experimental and may change without notice.
*/
/** Most scope pages one tree or ancestor walk looks at before it stops and reports truncation. */
export declare const MAX_KNOWLEDGE_EXPLORER_SCOPE_SCAN = 1000;
/** A page in one tree level, with how many readable children sit directly under it. */
export type KnowledgeTreePage = KnowledgePage & {
/**
* Readable child pages, plus readable child scopes for a scope. Left out when the store can't count
* (an adapter older than `countChildPages`), so a UI can tell "none" from 'unknown'.
*/
childCount?: number;
/**
* Set when the child-scope walk for this page hit {@link MAX_KNOWLEDGE_EXPLORER_SCOPE_SCAN}, so
* `childCount` is a lower bound: show it as "at least" (e.g. `1000+`), not as the exact number.
*/
childCountCapped?: true;
};
export interface KnowledgeTreeChildren {
/** Readable child scopes (all of them, on the first page only), then readable child pages in order. */
pages: KnowledgeTreePage[];
/** Cursor for more child pages; child scopes are never paged. */
nextCursor?: string;
/** True when the scope walk hit {@link MAX_KNOWLEDGE_EXPLORER_SCOPE_SCAN}. */
truncated: boolean;
}
/**
* One level of the page tree. `parentId: null` lists the root scopes `read` reaches. Child scopes come
* first (they're structure), then the parent's ordinary child pages, paged with `cursor`/`limit`.
*/
export declare function listKnowledgeTreeChildren(store: KnowledgePageStore, input: {
parentId: string | null;
read: KnowledgeReadScope;
cursor?: string;
limit?: number;
}): Promise<KnowledgeTreeChildren>;
export declare const DEFAULT_KNOWLEDGE_PAGE_NOTE_LIMIT = 50;
export interface KnowledgePageView {
page: KnowledgePage;
/** Readable ancestors, root first. */
ancestors: KnowledgePage[];
notes: KnowledgeNote[];
notesNextCursor?: string;
pin: KnowledgePin | null;
/** Readable pages the notes mention or are stamped to, for names and links. Unreadable ids are left out. */
related: KnowledgePage[];
/** Readable notes on other pages that mention this page (first page). */
mentionedBy: KnowledgeNote[];
}
/** One page with its notes, pin and the pages they reference. Null when `read` can't see the page. */
export declare function readKnowledgePage(store: KnowledgePageStore, input: {
pageId: string;
read: KnowledgeReadScope;
noteCursor?: string;
noteLimit?: number;
}): Promise<KnowledgePageView | null>;
export interface KnowledgePageGraphLimits {
/** Most pages walked from the root. */
maxPages: number;
/** Most notes read across the graph when collecting mentions; each page's notes are read in full until then. */
maxNotes: number;
/** Most mentioned pages outside the walk added as endpoints. */
maxOutsidePages: number;
}
export declare const DEFAULT_KNOWLEDGE_PAGE_GRAPH_LIMITS: KnowledgePageGraphLimits;
export interface KnowledgePageGraphEdge {
source: string;
target: string;
kind: 'parent' | 'mention';
/** Mention edges: how many readable notes on `source` mention `target`. */
count?: number;
}
export interface KnowledgePageGraph {
/** Pages in the walk, then readable mentioned pages outside it. */
pages: KnowledgePage[];
/** Ids of `pages` that are outside the walk (mention endpoints only). */
outsideIds: string[];
edges: KnowledgePageGraphEdge[];
/** Page ids that have pins. */
pinnedIds: string[];
/** True when a limit stopped the walk or the endpoint list. */
truncated: boolean;
}
/**
* A bounded graph: pages breadth-first under `rootId` (or every root scope `read` reaches), parent
* edges between them, and mention edges from their readable notes. A hidden note never contributes
* an edge, so the graph shows only links the caller could read.
*/
export declare function readKnowledgePageGraph(store: KnowledgePageStore, input: {
read: KnowledgeReadScope;
rootId?: string | null;
limits?: Partial<KnowledgePageGraphLimits>;
}): Promise<KnowledgePageGraph | null>;
export declare const DEFAULT_KNOWLEDGE_PAGE_SEARCH_LIMIT = 20;
/** Pages (name, synopsis, body) and notes matching `query` that `read` allows, optionally within scopes. */
export declare function searchKnowledgeExplorerPages(store: KnowledgePageStore, input: {
query: string;
read: KnowledgeReadScope;
scopeIds?: string[];
limit?: number;
}): Promise<KnowledgePageSearchHit[]>;
export declare const DEFAULT_KNOWLEDGE_PAGE_ACTIVITY_LIMIT = 25;
/** Activity newest first, filtered by what `read` can see now. */
export declare function readKnowledgePageActivity(store: KnowledgePageStore, input: {
read: KnowledgeReadScope;
scopeId?: string;
pageId?: string;
cursor?: string;
limit?: number;
}): Promise<{
events: KnowledgePageActivityEvent[];
nextCursor?: string;
}>;
/** An access grant drawn between scopes in a browsing graph. @experimental */
export interface KnowledgeGraphScopeGrant {
/** The principal scope address, e.g. `role:acme:support`. */
principal: string;
/** Its scope page id, when it has one; absent for a declared principal nothing was written to yet. */
principalId?: string;
/** The granted scope's page id. */
target: string;
role: KnowledgeRole;
}
/**
* The declared grants onto the scope pages in `pages`, for drawing who can reach what. `grantsFor` is
* `knowledge.scopeGrants`. A principal is kept only when `read` can read its scope page; with `'all'`,
* a declared principal with no scope page yet comes back without `principalId`.
*/
export declare function readKnowledgeScopeGrants(store: KnowledgePageStore, input: {
pages: readonly KnowledgePage[];
read: KnowledgeReadScope;
grantsFor: (scope: {
address: string;
parentAddress?: string | null;
}) => Array<{
principal: string;
role: KnowledgeRole;
}>;
}): Promise<KnowledgeGraphScopeGrant[]>;
/** Most pages one {@link readKnowledgePageLinkCounts} call counts. */
export declare const MAX_KNOWLEDGE_LINK_COUNT_PAGES = 200;
/** Most links one {@link readKnowledgePageLinks} call returns. */
export declare const MAX_KNOWLEDGE_EXPLORER_PAGE_LINKS = 200;
/**
* How many distinct other pages link to each page (`in`) and are linked from it (`out`), by body `[[ref]]`
* or note mention, counted by the store over every page it holds rather than only the ones a UI has
* loaded. Pages `read` can't reach count as zero, the same as pages that don't exist. Returns `null`
* when the store has no link index.
*/
export declare function readKnowledgePageLinkCounts(store: KnowledgePageStore, input: {
pageIds: string[];
read: KnowledgeReadScope;
}): Promise<Record<string, KnowledgePageLinkCounts> | null>;
/** One page's links, with the pages at their other ends so a UI can name and place them. */
export interface KnowledgePageLinks {
edges: KnowledgePageLinkEdge[];
/** The pages at the other end of `edges` that `read` can reach. */
pages: KnowledgePage[];
/** True when the page has more links than {@link MAX_KNOWLEDGE_EXPLORER_PAGE_LINKS}. */
truncated: boolean;
}
/**
* The links into and out of one readable page, by body `[[ref]]` or note mention. A page `read` can't
* reach has none. Returns `null` when the store has no link index.
*/
export declare function readKnowledgePageLinks(store: KnowledgePageStore, input: {
pageId: string;
read: KnowledgeReadScope;
direction?: 'in' | 'out' | 'both';
}): Promise<KnowledgePageLinks | null>;
//# sourceMappingURL=explorer-pages.d.ts.map