import { SupervisorInput } from "../contracts/supervisor/supervisor-input.type.mjs"; import { TurnSnapshot } from "../contracts/result/orchestrator-result.type.mjs"; import { RecalledMemory } from "../contracts/memory/memory-item.type.mjs"; import { MemoryContract } from "../contracts/memory/memory.contract.mjs"; import { OrchestratorMemoryConfig, OrchestratorMemoryScope } from "../contracts/orchestrator/orchestrator-config.type.mjs"; //#region ../ai/src/orchestrator/memory.d.ts /** * Memory wiring resolved once per turn from `OrchestratorConfig.memory` * (memory core M2). Normalizes the two accepted config shapes — a bare * {@link MemoryContract} or the richer {@link OrchestratorMemoryConfig} — * into a single flat record the lifecycle phase reads, so `runTurn` never * branches on which form the dev supplied. */ type ResolvedOrchestratorMemory = { /** The store recalled-from before dispatch and remembered-into after. */store: MemoryContract; /** Recall count cap; `0` disables recall (write-only memory). */ k?: number; /** Semantic-similarity floor for recall. */ threshold?: number; /** Single-tier recall restriction. */ tier?: ResolvedTier; /** Whether a clean turn writes its outcome back. Default `true`. */ remember: boolean; /** Tier the remembered outcome lands in. Omit for the memory's `defaultTier`. */ rememberTier?: ResolvedTier; /** * Isolation boundary for recall + write-back. Default `"session"` — * the turn's `sessionId` keys every read and write, so one session * cannot recall another's memories out of the shared store. */ scope: OrchestratorMemoryScope; /** Context-bag key the recalled memories are injected under. */ injectKey: string; }; type ResolvedTier = NonNullable["tier"]; /** * Normalize `OrchestratorConfig.memory` into {@link ResolvedOrchestratorMemory}, * or `undefined` when no memory is configured. Centralizes the * bare-store-vs-config distinction so the engine context carries one * shape and the lifecycle phase stays branch-free. */ declare function resolveOrchestratorMemory(memory: MemoryContract | OrchestratorMemoryConfig | undefined): ResolvedOrchestratorMemory | undefined; /** * Resolve the isolation key a turn reads and writes memories under * (4.15.0 — security fix for cross-session recall). * * The memory store is resolved once per orchestrator instance and reused * by every session, so this — not the store — is what keeps one session's * remembered turns out of another's recall. It is derived from the * execute-time `sessionId` by the engine and handed to every tier as an * exact-match filter; the model, the tool payload, and the per-call * `context` bag have no say in it. * * `"shared"` resolves to `undefined`, i.e. the store's unscoped pool — * the explicit opt-in back to pre-4.15.0 cross-session behavior, which * also keeps memories written before this release readable. */ declare function memoryScopeFor(memory: ResolvedOrchestratorMemory, sessionId: string): string | undefined; /** * The default `"session"` scope key: the session id under a reserved * prefix, so a custom `scope` callback returning a bare tenant id can * never accidentally collide with a session-scoped pool. */ declare function sessionMemoryScope(sessionId: string): string; /** * Coerce a turn's {@link SupervisorInput} (string or structured object) * into the natural-language query the memory store recalls / embeds * against. Strings pass through; objects are JSON-serialized — the same * coercion the supervisor applies when forwarding an object input to a * child agent without an explicit `input(ctx)` override. */ declare function memoryQueryFromInput(input: SupervisorInput): string; /** * Recall the memories relevant to a turn's input (memory core M2 — the * pre-dispatch half). Returns the scored {@link RecalledMemory}[] the * lifecycle injects into the turn's `context` bag under * `memory.injectKey`. Returns an empty array — never throws on "no hits" * — and short-circuits when `k === 0` (recall disabled / write-only * memory) so a write-only config never round-trips the embedder. * * The recall is confined to the calling session's scope (see * {@link memoryScopeFor}) — `sessionId` is required, not optional, so a * new call site cannot silently recall across every session. */ declare function recallForTurn(memory: ResolvedOrchestratorMemory, input: SupervisorInput, sessionId: string): Promise; /** * Merge the recalled memories into a fresh per-turn context bag under * `memory.injectKey` (memory core M2 — the injection half). Never * mutates the caller's `context` object — returns a new bag (or the * original when there is nothing to inject) so the request-scoped input * stays immutable, and the supervisor's intake (which freezes a * shallow copy) sees the recalled set on every `ctx.context[injectKey]`. * * A pre-existing value at `injectKey` is preserved when recall produced * nothing, and overwritten with the recalled set otherwise — the * orchestrator owns that key once memory is configured. */ declare function injectMemories(context: Record | undefined, memory: ResolvedOrchestratorMemory, recalled: RecalledMemory[]): Record | undefined; /** * Remember a settled turn's outcome (memory core M2 — the post-dispatch * half). Called only after a clean turn (cancelled / failed turns revert * and never remember — §17). No-ops when `remember` is `false` * (read-only memory) or when the produced text is empty. * * The remembered text is the turn input followed by the model's textual * outcome when one is available, so a later `recall` keyed on a similar * input surfaces both the prior question and its answer. * * The write is tagged with the calling session's scope (see * {@link memoryScopeFor}) so only that session recalls it later — * turn text routinely contains one user's private content. */ declare function rememberTurnOutcome(memory: ResolvedOrchestratorMemory, input: SupervisorInput, outcomeText: string | undefined, sessionId: string): Promise; /** * Derive a turn's textual outcome for remembering (memory core M2). * Prefers the validated `result.data` (an `output` schema reshaped it); * otherwise stringifies the dispatched intents' branch outputs from the * turn snapshot, joined newline-wise so a multi-branch fan-out * contributes every output. Returns `undefined` when the turn produced * no usable text — the caller then remembers the input alone. */ declare function outcomeTextFromTurn(data: unknown, turnSnapshot: TurnSnapshot): string | undefined; //#endregion export { ResolvedOrchestratorMemory, injectMemories, memoryQueryFromInput, memoryScopeFor, outcomeTextFromTurn, recallForTurn, rememberTurnOutcome, resolveOrchestratorMemory, sessionMemoryScope }; //# sourceMappingURL=memory.d.mts.map