import * as react_jsx_runtime from 'react/jsx-runtime'; import { ReactNode } from 'react'; import { C as ConnectOptions, a as CallToolAsTaskOptions, T as TaskHandle, b as ToolCallResult, R as RequestFileOptions, F as FileResult, A as App, M as ModelContext, c as Theme, d as ToolResultData } from '../types-BxPfGHKO.js'; import { McpUiHostContext } from '@modelcontextprotocol/ext-apps'; import { Task, ResourceListChangedNotification } from '@modelcontextprotocol/sdk/types.js'; interface AppProviderProps extends ConnectOptions { children: ReactNode; } /** * Connect on mount and provide the {@link App} to everything below. * * Renders nothing until the handshake completes, so no hook below can observe * a half-connected app and no tool call can be fired into a host that has not * answered `ui/initialize` yet. */ declare function AppProvider({ children, ...options }: AppProviderProps): react_jsx_runtime.JSX.Element | null; /** The connected app. Throws outside an ``. */ declare function useApp(): App; /** * The current theme, re-rendering only when it actually moves. * * `App` filters `host-context-changed` notifications through a theme equality * check, so a context update that leaves the derived theme untouched (a * workspace switch, say) does not re-render every themed component. */ declare function useTheme(): Theme; /** * The full ext-apps host context — spec fields (`theme`, `styles`, * `displayMode`, `toolInfo`) plus whatever the host publishes alongside. * Re-renders on every `host-context-changed`. * * Prefer `useTheme()` when only theming matters: it filters no-op fires. * Reach for this one for host extensions, e.g. on NimbleBrain: * * ```tsx * const { workspace } = useHostContext<{ workspace?: { id: string } }>(); * ``` */ declare function useHostContext(): T; /** * The latest tool result pushed by the host, or `null` before one arrives. A * host that mounts the app without a tool call never sends one, so `null` is a * state to render, not only a loading state. */ declare function useToolResult(): ToolResultData | null; /** The arguments the host is calling the bound tool with, or `null` until it sends them. */ declare function useToolInput(): Record | null; /** Report this app's frame size to the host. Every host accepts it; the spec has no capability for it. */ declare function useResize(): (width?: number, height?: number) => void; interface UseCallToolResult { call: (args?: Record) => Promise>; isPending: boolean; error: Error | null; data: TOutput | null; } /** * Call one tool, with pending/error/data state for the latest call. * * Where the host did not declare `serverTools`, `call` rejects with * `HostCapabilityError` without sending, and `error` holds it. */ declare function useCallTool(toolName: string): UseCallToolResult; /** * Run `callback` when the app's own MCP server announces that its data changed. * * A server sends `notifications/resources/list_changed` from the write that * changed its data, and an MCP Apps host forwards it to that server's views * (host capability `serverResources.listChanged`). The callback receives the * notification's params as the spec defines them, or `{}` when the host sends * none. They name no server and no tool: the notification only ever comes from * this app's own server, and a change need not come from a tool call at all. * * Where the host did not declare `serverResources.listChanged`, the callback * never runs. Nothing fails: the app shows what it last loaded until the user * or the app reloads it. */ declare function useDataSync(callback: (params: NonNullable) => void): void; /** * Push what the user is looking at to the agent (ext-apps * `ui/update-model-context`), debounced so a selection the user drags through * costs one frame rather than thirty. * * **Declarative** — pushes when `deps` change: * ```tsx * useModelContext(() => ({ * state: { board: selectedBoard }, * summary: `Viewing "${selectedBoard?.name}"`, * }), [selectedBoard]); * ``` * * **Imperative** — returns a push function: * ```tsx * const push = useModelContext(); * push({ board: selectedBoard }, "Viewing board X"); * ``` * * The debounce lives here rather than on `app.updateModelContext`, which * sends immediately: the rapid-change problem is a React one, and the plain * method should do what it says. * * A no-op where the host did not declare `updateModelContext`. */ declare function useModelContext(): (state: Record, summary?: string) => void; declare function useModelContext(factory: () => ModelContext, deps: unknown[]): void; /** * Send a user message into the agent conversation. A no-op where the host did * not declare `message`; check `app.hostCapabilities.message` to decide whether * to offer the control at all. */ declare function useSendMessage(): (text: string, context?: { action?: string; entity?: string; }) => void; /** Trigger a host-side action. A no-op where the host did not declare `ai.nimblebrain/action`. */ declare function useAction(): (name: string, params?: Record) => void; interface UseFileUploadResult { pickFile: (options?: RequestFileOptions) => Promise; pickFiles: (options?: RequestFileOptions) => Promise; isPending: boolean; } /** * The host's native file picker, with a pending flag. Both functions reject * with `HostCapabilityError` where the host did not declare * `ai.nimblebrain/request-file`; `hostSupports(app, "requestFile")` says so up * front. */ declare function useFileUpload(): UseFileUploadResult; interface UseCallToolAsTaskResult { /** * Start (or re-start) a task-augmented tool call. Returns the * resolved `TaskHandle` so callers can `await fire(...)` if they * want to know when the server has accepted the task, but reading * `task`/`result`/`error` from the hook is usually enough. * * Re-firing while a previous task is still in flight detaches this * hook from the prior handle (stops polling, unsubscribes) but does * NOT cancel the server-side task — the task keeps running and its * result may still be fetched elsewhere (e.g. on page revisit). */ fire(args?: TInput, options?: CallToolAsTaskOptions): Promise>; /** Latest `Task` state, or `null` before `fire()` has been called. */ task: Task | null; /** Populated once `handle.result()` resolves non-error. */ result: ToolCallResult | null; /** Populated on rejection or when `result.isError === true`. */ error: Error | null; /** `true` while the task is non-terminal (`working` / `input_required`). */ isWorking: boolean; /** `true` when `task.status ∈ {completed, failed, cancelled}`. */ isTerminal: boolean; /** * Cancel the active task via `tasks/cancel`. No-op when no task is * active. Swallowed errors surface via `error`. */ cancel(): Promise; } /** * React wrapper around `callToolAsTask(app, …)`. * * Handles the full MCP 2025-11-25 task lifecycle: * * 1. `fire(args, options?)` sends the task-augmented `tools/call` and * stores the returned `TaskHandle` in a ref. * 2. Subscribes to `handle.onStatus` — updates `task` whenever the * host emits `notifications/tasks/status` (OPTIONAL per spec). * 3. Starts a polling fallback: if no status notification arrives * within `pollInterval × 1.5` (defaulting to ~7.5s), calls * `handle.refresh()` for canonical state. Stops on terminal. * 4. Awaits `handle.result()` in the background — resolves to either * `result` (success / `isError: false`) or `error` (network reject * OR `result.isError === true`). * * Where the host did not declare the tasks capability, `fire` rejects with * `HostCapabilityError` and `error` holds it; `app.supportsTasks` says so up * front. * * Cleanup (unmount or re-fire) unsubscribes from status events and * clears the poll timer, but does NOT cancel the server-side task — * the caller may remount and recover state by firing again, and tasks * outlive iframe teardown until TTL elapses. */ declare function useCallToolAsTask, TOutput = unknown>(toolName: string): UseCallToolAsTaskResult; export { AppProvider, type AppProviderProps, type UseCallToolAsTaskResult, type UseCallToolResult, type UseFileUploadResult, useAction, useApp, useCallTool, useCallToolAsTask, useDataSync, useFileUpload, useHostContext, useModelContext, useResize, useSendMessage, useTheme, useToolInput, useToolResult };