@mastra/core
Version:
53 lines • 2.52 kB
TypeScript
/**
* PinnedStateProcessor
*
* Projects the Knowledge pin set onto the agent state-signal lane. Delivery
* follows the lane's contract: when no snapshot is in the visible context
* (state never emitted, or observational memory evicted it) emit a full
* snapshot; otherwise emit a small delta carrying only this turn's changes;
* when nothing changed and the base snapshot is still visible, emit nothing so
* the cached prompt prefix stays stable.
*
* Each entry is a pinned page keyed by its page id, rendered from the page's
* current body, so a delta can say exactly which pin appeared, changed or left.
* An edited page arrives as a `change` of the same id with its new text.
*/
import type { ComputeStateSignalArgs, ComputeStateSignalResult, Processor, ProcessInputArgs, ProcessInputResult } from '../processors/index.js';
import { PINNED_KNOWLEDGE_STATE_ID } from './pinned.js';
import type { PinEntry } from './pinned.js';
import type { KnowledgeRunContext } from './run.js';
export type { PinEntry } from './pinned.js';
export type PinDeltaOp = {
op: 'add';
pin: PinEntry;
} | {
op: 'change';
pin: PinEntry;
} | {
op: 'remove';
id: string;
name?: string;
scope?: string;
};
export declare function stablePinsCacheKey(pins: PinEntry[]): string;
export declare function applyPinOps(pins: PinEntry[], ops: PinDeltaOp[]): PinEntry[];
export declare function effectivePriorPins(args: ComputeStateSignalArgs): PinEntry[];
export declare function diffPins(prior: PinEntry[], current: PinEntry[]): PinDeltaOp[];
export interface PinnedStateProcessorDeps {
/** A key identifying the run's principals, for the per-turn memo. Throws when the run has no Knowledge view. */
principalsKey(context: KnowledgeRunContext): string;
/** The pins the run receives. */
readPins(context: KnowledgeRunContext): Promise<PinEntry[]>;
}
/** Request-context key memoizing a turn's pin read; pin writes clear it so the next step reads fresh. */
export declare const PINNED_READ_MEMO_KEY = "__knowledgePinnedRead";
export declare class PinnedStateProcessor implements Processor<typeof PINNED_KNOWLEDGE_STATE_ID> {
private readonly deps;
readonly id = "knowledge";
readonly stateId = "knowledge";
constructor(deps: PinnedStateProcessorDeps);
processInput(args: ProcessInputArgs): ProcessInputResult;
private readPins;
computeStateSignal(args: ComputeStateSignalArgs): Promise<ComputeStateSignalResult>;
}
//# sourceMappingURL=pinned-state-processor.d.ts.map