UNPKG

@mastra/core

Version:
54 lines • 2.64 kB
/** * One-hop Knowledge access: from the scopes a caller holds (its principals) to the scopes it can read * and the role it has on a given scope. A held scope reaches every scope whose declared rules name * it; scopes reached that way never act as principals themselves, so access never chains. * * @experimental Knowledge APIs are experimental and may change without notice. */ import type { KnowledgeReadScope } from '../storage/domains/knowledge/pages.js'; import type { CompiledKnowledgeScopes, KnowledgeRole } from './declarations.js'; /** Looks up materialized scope pages by address, e.g. `storage.getScopesByAddress`. */ export type KnowledgeScopeLookup = (addresses: string[]) => Promise<Array<{ id: string; address?: string; }>>; /** * The scopes a caller holding `principals` can read: every scope a declared rule gives one of them a * role on. Undeclared principals add nothing, and no principals read nothing (never `'all'`). * `lookupScopes` resolves `belongsTo` parents to page ids; parents not materialized yet reach nothing. * * @experimental */ export declare function knowledgeReadScopeFor(compiled: CompiledKnowledgeScopes, principals: readonly string[], lookupScopes: KnowledgeScopeLookup): Promise<Exclude<KnowledgeReadScope, 'all'>>; /** One rule giving a held principal a role on a scope. @experimental */ export interface KnowledgeAccessGrant { /** The held principal the rule names (the scope itself for `self`). */ principal: string; role: KnowledgeRole; /** The declaration key, or the concrete address whose own rules gave it. */ rule: string; /** How the rule binds: the scope itself, its params, or its `belongsTo` parent. */ via: 'self' | 'rule' | 'belongsTo'; } /** * Every rule that gives one of `principals` (or, with `'any'`, any principal) a role on one scope. * `parentAddress` is the address of the scope page's tree parent, needed for rules that bind through * `belongsTo`. * * @experimental */ export declare function knowledgeAccessGrants(compiled: CompiledKnowledgeScopes, principals: readonly string[] | 'any', scope: { address: string; parentAddress?: string | null; }): KnowledgeAccessGrant[]; /** * The strongest role `principals` give on one scope, or null. `parentAddress` is the address of the * scope page's tree parent, needed for rules that bind through `belongsTo`. * * @experimental */ export declare function knowledgeRoleOn(compiled: CompiledKnowledgeScopes, principals: readonly string[], scope: { address: string; parentAddress?: string | null; }): KnowledgeRole | null; //# sourceMappingURL=access.d.ts.map