@mastra/core
Version:
54 lines • 2.29 kB
TypeScript
import type { KnowledgeStorage } from '../storage/domains/knowledge/base.js';
/**
* One committed write to a Knowledge store. Events carry ids only: a listener serving people (a UI
* stream) must re-read the page under the viewer's read scope and drop what they can't read.
* `scopeId` is the page's scope after the write; `fromScopeId` (move, and merge for the page merged
* away) is its scope before. For notes and pins, read the page by `pageId`. Creating a scope emits one
* `scope:create` for the scope itself, not for its child scopes or template pages, and template pages
* added later to an existing scope emit nothing: re-list the scope on `scope:create`.
* `dangerouslyReset()` emits nothing.
* @experimental
*/
export type KnowledgeChangeEvent = {
knowledgeId: string;
at: Date;
} & ({
kind: 'scope';
op: 'create';
pageId: string;
scopeId: string;
} | {
kind: 'page';
op: 'create' | 'update' | 'move' | 'merge' | 'delete';
pageId: string;
scopeId: string;
/** For `move` and `merge`: the moved or merged-away page's scope before the write. */
fromScopeId?: string;
/** For `merge`: the page merged away (now deleted); `pageId` is the target. */
sourceId?: string;
} | {
kind: 'note';
op: 'add' | 'restamp' | 'remove' | 'restore';
pageId: string;
noteId: string;
} | {
kind: 'pin';
op: 'add' | 'remove';
pageId: string;
});
/** @experimental */
export type KnowledgeChangeListener = (event: KnowledgeChangeEvent) => void;
type Change = {
[K in KnowledgeChangeEvent['kind']]: Omit<Extract<KnowledgeChangeEvent, {
kind: K;
}>, 'knowledgeId' | 'at'>;
}[KnowledgeChangeEvent['kind']];
/**
* Wraps `storage` so each page-store write in {@link WRITES} calls `emit` after it resolves. Every
* other member passes through, bound to the real store so adapters' private fields keep working.
* Nothing extra happens while `listening()` is false. Describing or emitting an event never fails a
* write that committed: errors go to `onError`.
*/
export declare function emitKnowledgeChanges(storage: KnowledgeStorage, emit: (change: Change) => void, listening: () => boolean, onError: (error: unknown) => void): KnowledgeStorage;
export {};
//# sourceMappingURL=changes.d.ts.map