import type { App } from "@modelcontextprotocol/ext-apps"; import type { ModelContextBlock } from "../types/model-context.js"; import type { ContentBlock } from "@modelcontextprotocol/server"; import { type ContextOperationResult, type ContextPayload, type ContextSnapshot } from "./model-context.js"; /** Model-visible state owned by one mounted view runtime. */ type ViewState = Record; interface ModelContextNode { id: string; parentId: string | null; content: string; } /** Narrow runtime surface used by the shared state/context flush pump. */ interface ModelContextStoreHost { /** Connect once, or return the cached in-flight / settled connection promise. */ connect(): Promise; } /** Reset the missing-capability warn-once flag between tests. */ export declare function _resetModelContextUnsupportedWarnedForTesting(): void; /** * Per-runtime view-state document, model-context tree, and async flush pump. * * `useViewState` and `ModelContext` mutate this single owner. Each delivery * contains the complete merged snapshot because `ui/update-model-context` has * overwrite semantics. * * @internal */ export declare class ModelContextStore { #private; /** Create a store backed by the owning view runtime's connection boundary. */ constructor(host: ModelContextStoreHost); /** Reserve native delivery synchronously, without network or listener effects. */ readonly activateAttachments: () => void; /** Stable external-store subscription used by `useViewState`. */ readonly subscribeViewState: (listener: () => void) => (() => void); /** Current canonical view state, excluding the reserved UI-context field. */ readonly getViewStateSnapshot: () => ViewState | null; /** * Initialize view state from a hook default when ChatGPT restored no state. * The first hook default wins; later conflicting defaults warn in development. */ initializeViewState(defaultState: ViewState): void; /** Resolve and apply a `useState`-style update synchronously. */ updateViewState(updater: (previous: ViewState | null) => ViewState): void; /** Register or replace a model-context node and schedule a merged flush. */ setNode(node: ModelContextNode): void; /** Remove a model-context node and schedule a merged flush. */ removeNode(id: string): void; /** Remove every model-context node. */ clear(): void; /** Invalidate the store and ignore late in-flight completions. */ dispose(): void; /** Serialize registered context nodes into an indented markdown list. */ buildDescriptionString(): string; /** Build one full replacement from all contribution namespaces. */ buildModelContextParams(state?: ViewState | null, description?: string, includeBackground?: boolean): ContextPayload; /** Initialize attachment mode behind the runtime's shared connection barrier. */ readonly prepare: () => Promise; /** Queue an ergonomic attachment intent, then validate before committing it. */ readonly add: (key: string, input: ModelContextBlock) => Promise; /** Queue removal of one key; attachment-hook lifetime does not own that key. */ readonly remove: (key: string) => Promise; /** Clear selected and preparing attachments, preserving background. */ readonly clearSelection: () => Promise; /** Consume only the model-context field of raw runtime host notifications. */ receiveHostContext(params: Record): void; /** Subscribe to shared selection and delivery status. */ readonly subscribe: (listener: () => void) => (() => void); /** Cached snapshot suitable for useSyncExternalStore. */ readonly getSnapshot: () => ContextSnapshot; /** Upsert one native attachment; callers normalize and negotiate before entry. */ readonly addAttachment: (key: string, block: ContentBlock) => Promise; /** Remove one attachment without changing state or description contributions. */ readonly removeAttachment: (key: string) => Promise; /** Clear the explicit attachment namespace only. */ readonly clearAttachments: () => Promise; /** Explicitly retry the current desired state, never a saved failed payload. */ readonly retry: () => Promise; /** Clear state between tests without disposing the owning runtime. */ resetForTesting(): void; /** Internal serialized tree for tests. */ getDescriptionForTesting(): string; } export {};