import type { MemoryConsumptionFile, MemoryConsumptionResult, MemoryGenerationGateInput, MemoryGenerationGateResult, MemoryGenerationResult, MemoryRoot } from '../protocol/memory.js'; export type { EffectiveMemoryConfig, MemoryConsumptionFile, MemoryConsumptionResult, MemoryGenerationGateInput, MemoryGenerationGateResult, MemoryGenerationResult, MemoryGenerationFailedFile, MemoryMode, MemoryRoot, MemoryRootAccess, SerializableMemoryConfig, SerializableMemoryConsumptionOptions, SerializableMemoryGenerationOptions, } from '../protocol/memory.js'; /** Product-side decision invoked before TurnComplete memory generation starts. */ export type MemoryShouldGenerate = (input: MemoryGenerationGateInput, options: { signal: AbortSignal; }) => Promise; export type MemoryGenerationOptions = { /** Enables automatic and active memory generation. Defaults to true. */ enabled?: boolean; /** Memory directories available to the main agent and background memory agent. CLI defaults are used when omitted. */ roots?: MemoryRoot[]; /** Generation instructions. The CLI-owned default prompt is used when omitted. */ prompt?: string; /** Controls generation started from the real CLI TurnComplete event. */ turnComplete?: { /** Defaults to true when generation is enabled. */ enabled?: boolean; /** Product-side gate called before the background memory agent starts. Omit to use only CLI built-in guards. */ shouldGenerate?: MemoryShouldGenerate; /** Maximum time allowed for shouldGenerate. The CLI default is 10 seconds. */ timeoutMs?: number; /** Whether callback errors/timeouts produce a skipped or failed generation result. Defaults to "skip". */ onGateError?: 'skip' | 'report_failed'; }; /** Called for every completed generation attempt, including saved, partial, no-change, skipped, and failed outcomes. */ onResult?: (result: MemoryGenerationResult) => void | Promise; }; export type MemoryConsumptionOptions = { /** Enables memory consumption. Defaults to true. */ enabled?: boolean; /** Explicit files to inject in array order. They replace CLI native auto-memory; static instructions remain. CLI native auto-memory is used when omitted. */ files?: MemoryConsumptionFile[]; /** Shared token budget for all explicit files. Omit for no explicit SDK budget. */ maxTokens?: number; /** Behavior when explicit file content exceeds maxTokens. Defaults to "truncate". */ overflow?: 'truncate' | 'fail_query'; /** Read-failure behavior. Only required files fail the query in "fail_query" mode. Defaults to "best_effort". */ failureMode?: 'best_effort' | 'fail_query'; /** Receives per-file load status after initialization and explicit refreshes. */ onResult?: (result: MemoryConsumptionResult) => void | Promise; }; export type MemoryOptions = { /** An empty object disables SDK memory, equivalent to omitting options.memory. */ mode?: never; projectScope?: never; userScope?: never; generation?: never; consumption?: never; } | { /** Uses CLI-native generation and consumption; only scope switches and result callbacks are configurable. */ mode: 'native'; /** Enables or disables the CLI PROJECT scope for this Query. Defaults to `true`. */ projectScope?: boolean; /** Enables or disables the CLI USER scope for this Query. Defaults to `true`. */ userScope?: boolean; generation?: Pick; consumption?: Pick; } | { /** Applies supplied overrides and inherits omitted behavior from the CLI. */ mode: 'custom'; /** Enables or disables the CLI PROJECT scope for inherited native behavior. Defaults to `true`. */ projectScope?: boolean; /** Enables or disables the CLI USER scope for inherited native behavior. Defaults to `true`. */ userScope?: boolean; /** Memory generation overrides. Omit to use CLI generation defaults. */ generation?: MemoryGenerationOptions; /** Memory consumption overrides. Omit to use CLI consumption defaults. */ consumption?: MemoryConsumptionOptions; }; export type MemoryRuntimeCallbacks = { shouldGenerateCallbacks: ReadonlyMap; onGenerationResult?: MemoryGenerationOptions['onResult']; onConsumptionResult?: MemoryConsumptionOptions['onResult']; };