import { A as SessionOptions, C as AgentSessionProvider, D as StoredCompaction, E as SessionProvider, O as SessionMessage, S as isSearchProvider, T as SearchResult, _ as R2SkillProvider, b as AgentSearchProvider, f as ContextBlock, g as isWritableProvider, h as WritableContextProvider, k as SessionMessagePart, m as ContextProvider, p as ContextConfig, r as CompactResult, v as SkillProvider, w as SqlProvider, x as SearchProvider, y as isSkillProvider } from "../../../compaction-helpers-CzCq1-fF.js"; import { ToolSet } from "ai"; //#region src/experimental/memory/session/session.d.ts type SessionContextOptions = Omit; declare class Session { private storage; private context; private _agent?; private _broadcaster?; private _sessionId?; private _pending?; private _cachedPrompt?; private _compactionFn?; private _tokenThreshold?; private _ready; constructor(storage: SessionProvider, options?: SessionOptions); /** * Chainable session creation with auto-wired SQLite providers. * Chain methods in any order — providers are resolved lazily on first use. * * @example * ```ts * const session = Session.create(this) * .withContext("soul", { provider: { get: async () => "You are helpful." } }) * .withContext("memory", { description: "Learned facts", maxTokens: 1100 }) * .withCachedPrompt(); * * // Skills from R2 (on-demand loading via load_context tool) * const session = Session.create(this) * .withContext("skills", { * provider: new R2SkillProvider(env.SKILLS_BUCKET, { prefix: "skills/" }) * }) * .withCachedPrompt(); * ``` */ static create(agent: SqlProvider): Session; forSession(sessionId: string): this; withContext(label: string, options?: SessionContextOptions): this; withCachedPrompt(provider?: WritableContextProvider): this; /** * Register a compaction function. Called by `compact()` to compress * message history into a summary overlay. */ onCompaction(fn: (messages: SessionMessage[]) => Promise): this; /** * Auto-compact when estimated token count exceeds the threshold. * Checked after each `appendMessage`. Requires `onCompaction()`. */ compactAfter(tokenThreshold: number): this; private _ensureReady; /** * Reconstruct which skills are loaded by scanning conversation history * for load_context tool results that haven't been unloaded. * Called during init to survive hibernation/eviction. */ private _restoreLoadedSkills; /** * Replace a load_context tool result in conversation history * with a short marker to reclaim context space. */ private _reclaimLoadedSkill; getHistory(leafId?: string | null): SessionMessage[]; getMessage(id: string): SessionMessage | null; getLatestLeaf(): SessionMessage | null; getBranches(messageId: string): SessionMessage[]; getPathLength(leafId?: string | null): number; private _broadcast; private _emitStatus; private _emitError; appendMessage(message: SessionMessage, parentId?: string | null): Promise; updateMessage(message: SessionMessage): void; deleteMessages(messageIds: string[]): void; clearMessages(): void; addCompaction(summary: string, fromMessageId: string, toMessageId: string): StoredCompaction; getCompactions(): StoredCompaction[]; /** * Run the registered compaction function and store the result as an overlay. * Requires `onCompaction()` to be called first. */ compact(): Promise; getContextBlock(label: string): ContextBlock | null; getContextBlocks(): ContextBlock[]; replaceContextBlock(label: string, content: string): Promise; appendContextBlock(label: string, content: string): Promise; /** * Dynamically register a new context block after session initialization. * Used by extensions to contribute context blocks at runtime. * * The block's provider is initialized and loaded immediately. * Call `refreshSystemPrompt()` afterward to include the new block * in the system prompt. * * Note: When called without a provider, auto-wires to SQLite via * AgentContextProvider. Requires the session to have been created * via `Session.create(agent)` (not the direct constructor). */ addContext(label: string, options?: SessionContextOptions): Promise; /** * Remove a dynamically registered context block. * Used during extension unload cleanup. * * Returns true if the block existed and was removed. * Call `refreshSystemPrompt()` afterward to rebuild the prompt * without the removed block. */ removeContext(label: string): boolean; /** * Unload a previously loaded skill, reclaiming context space. * The tool result in conversation history is replaced with a short marker. */ unloadSkill(label: string, key: string): boolean; /** * Get currently loaded skill keys (as "label:key" strings). */ getLoadedSkillKeys(): Set; freezeSystemPrompt(): Promise; refreshSystemPrompt(): Promise; search(query: string, options?: { limit?: number; }): Array<{ id: string; role: string; content: string; createdAt?: string; }>; /** Returns set_context and load_context tools. */ tools(): Promise; } //#endregion //#region src/experimental/memory/session/manager.d.ts interface SessionInfo { id: string; name: string; parent_session_id: string | null; model: string | null; source: string | null; input_tokens: number; output_tokens: number; estimated_cost: number; end_reason: string | null; created_at: string; updated_at: string; } interface SessionManagerOptions {} declare class SessionManager { private agent; private _pending; private _cachedPrompt?; private _compactionFn?; private _tokenThreshold?; private _sessions; private _historyLabel?; private _tableReady; private _ready; constructor(agent: SqlProvider, _options?: SessionManagerOptions); /** * Chainable SessionManager creation with auto-wired context for all sessions. * * @example * ```ts * const manager = SessionManager.create(this) * .withContext("soul", { provider: { get: async () => "You are helpful." } }) * .withContext("memory", { description: "Learned facts", maxTokens: 1100 }) * .withCachedPrompt() * .compactAfter(100_000); * * // Each getSession(id) auto-creates namespaced providers: * // memory key: "memory_" * // prompt key: "_system_prompt_" * const session = manager.getSession("chat-123"); * ``` */ static create(agent: SqlProvider): SessionManager; withContext(label: string, options?: SessionContextOptions): this; withCachedPrompt(provider?: WritableContextProvider): this; /** * Register a compaction function propagated to all sessions. * Called by `Session.compact()` to compress message history. */ onCompaction(fn: (messages: SessionMessage[]) => Promise): this; /** * Auto-compact when estimated token count exceeds the threshold. * Propagated to all sessions. Requires `onCompaction()`. */ compactAfter(tokenThreshold: number): this; /** * Add a searchable context block that searches conversation history * across all sessions managed by this manager. * * The model can use `search_context` to find relevant messages from * any session. The block is readonly (no `set`). * * @example * ```ts * SessionManager.create(this) * .withContext("memory", { maxTokens: 1100 }) * .withSearchableHistory("history") * .withCachedPrompt(); * ``` */ withSearchableHistory(label: string): this; private _ensureReady; private _ensureTable; private _createHistoryProvider; /** Get or create the Session instance for a session ID. */ getSession(sessionId: string): Session; create(name: string, opts?: { parentSessionId?: string; model?: string; source?: string; }): SessionInfo; get(sessionId: string): SessionInfo | null; list(): SessionInfo[]; delete(sessionId: string): void; rename(sessionId: string, name: string): void; append(sessionId: string, message: SessionMessage, parentId?: string): Promise; upsert(sessionId: string, message: SessionMessage, parentId?: string): Promise; appendAll(sessionId: string, messages: SessionMessage[], parentId?: string): Promise; getHistory(sessionId: string, leafId?: string): SessionMessage[]; getMessageCount(sessionId: string): number; clearMessages(sessionId: string): void; deleteMessages(sessionId: string, messageIds: string[]): void; getBranches(sessionId: string, messageId: string): SessionMessage[]; /** * Fork a session at a specific message, creating a new session * with the history up to that point copied over. */ fork(sessionId: string, atMessageId: string, newName: string): Promise; addCompaction(sessionId: string, summary: string, fromId: string, toId: string): StoredCompaction; getCompactions(sessionId: string): StoredCompaction[]; compactAndSplit(sessionId: string, summary: string, newName?: string): Promise; addUsage(sessionId: string, inputTokens: number, outputTokens: number, cost: number): void; search(query: string, options?: { limit?: number; }): { id: string; role: string; content: string; createdAt: string; }[]; tools(): ToolSet; private _touch; } //#endregion //#region src/experimental/memory/session/providers/agent-context.d.ts declare class AgentContextProvider implements WritableContextProvider { private agent; private label; private initialized; constructor(agent: SqlProvider, label?: string); init(label: string): void; private ensureTable; get(): Promise; set(content: string): Promise; } //#endregion export { AgentContextProvider, AgentSearchProvider, AgentSessionProvider, type ContextBlock, type ContextConfig, type ContextProvider, R2SkillProvider, type SearchProvider, type SearchResult, Session, type SessionContextOptions, type SessionInfo, SessionManager, type SessionManagerOptions, type SessionMessage, type SessionMessagePart, type SessionOptions, type SessionProvider, type SkillProvider, type SqlProvider, type StoredCompaction, type WritableContextProvider, isSearchProvider, isSkillProvider, isWritableProvider }; //# sourceMappingURL=index.d.ts.map