@mastra/core
Version:
69 lines • 4.34 kB
TypeScript
import type { KnowledgePage, KnowledgeProvenance, KnowledgeReadScope, KnowledgeStorage } from '../storage/domains/knowledge/index.js';
import type { KnowledgeAccessGrant } from './access.js';
import type { CompiledKnowledgeScopes, KnowledgeRole, KnowledgeScopeDeclarations } from './declarations.js';
/** Why a run can or can't reach a scope or page. See {@link Knowledge.explainAccess}. @experimental */
export interface KnowledgeAccessExplanation {
/** The run's strongest role on the target's scope; null when it can't read it. */
role: KnowledgeRole | null;
/** Every rule that gives one of the run's principals a role there. */
reasons: KnowledgeAccessGrant[];
/** The resolved page and its home scope address, for page targets that exist. */
page?: {
id: string;
scope: string;
};
/** `missing`: no such page. `hidden`: the page exists but the run can't read its scope. `no-rule`: a scope no rule gives the run. */
reason?: 'missing' | 'hidden' | 'no-rule';
}
/** How long the store's scope declarations are reused before {@link KnowledgeScopeRuntime.resolve} reads them again. */
export declare const KNOWLEDGE_STORE_DECLARATIONS_TTL_MS = 30000;
/** Declaration-backed access and lazy scope creation shared by the Knowledge lifecycle and tools. @internal */
export declare class KnowledgeScopeRuntime {
#private;
private readonly getStorage;
private readonly warn;
constructor(declarations: KnowledgeScopeDeclarations, getStorage: () => Promise<KnowledgeStorage>, warn: (message: string) => void);
/** The declarations as last resolved: the config's, plus the store's from the latest {@link resolve}. */
get compiled(): CompiledKnowledgeScopes;
/**
* Reads the store's scope declarations and merges them under the config's: a key the config
* declares keeps the config's declaration. Called once at the start of every call. The store's
* answer is reused for {@link KNOWLEDGE_STORE_DECLARATIONS_TTL_MS}, so a declaration the store adds
* or changes applies within that window, and right away after {@link invalidate}. A store
* declaration that doesn't compile next to the others is skipped with a warning. Recompiles only
* when the store's answer changes.
*/
resolve(): Promise<CompiledKnowledgeScopes>;
/** Makes the next {@link resolve} read the store's declarations again. */
invalidate(): void;
validatePrincipals(principals: readonly string[]): void;
/**
* Fails when stored scope pages carry declaration keys neither the config nor the store declares: a
* renamed or removed key would otherwise silently cut those scopes off from prefix and `belongsTo`
* reach. Checked once per set of resolved declarations; only a pass is remembered, so a store error
* is retried next time.
*/
checkDeclarations(): Promise<void>;
/** Re-keys stored scopes from declaration `from` to `to`. See {@link Knowledge.renameScopeDeclaration}. */
renameScopeDeclaration(from: string, to: string): Promise<number>;
readScopeFor(principals: readonly string[]): Promise<Exclude<KnowledgeReadScope, 'all'>>;
roleOn(principals: readonly string[], scope: KnowledgePage): Promise<KnowledgeRole | null>;
explainAccess(runScopes: readonly string[], target: {
scope: string;
} | {
page: string;
}): Promise<KnowledgeAccessExplanation>;
/**
* The `<scope>#<key path>` of a page its scope's declaration lists in `pages`, or undefined for an
* ordinary page. Template pages belong to config: tools can't move them or merge them away.
*/
templatePageRef(page: KnowledgePage): Promise<string | undefined>;
materializeScope(address: string, principals: readonly string[], provenance: KnowledgeProvenance): Promise<KnowledgePage>;
/**
* {@link materializeScope} for each address in turn (a write-run start's principals), reading
* scopes from one lookup. `#materialize` skips the store call for a scope that exists, needs no new
* `belongsTo` link, has its child scopes and declares no template pages; warnings fire as before.
*/
materializeScopes(addresses: readonly string[], principals: readonly string[], provenance: KnowledgeProvenance): Promise<void>;
}
//# sourceMappingURL=scope-runtime.d.ts.map