import * as _$react from "react"; import { FC } from "react"; import { StoreApi } from "zustand"; import * as _$react_jsx_runtime0 from "react/jsx-runtime"; import { AGUIEvent, AGUIEvent as AGUIEvent$1, ActivityMessage, AssistantMessage, BinaryInputContent, DeveloperMessage, EventType, FunctionCall, InputContent, Message, ReasoningMessage, SystemMessage, TextInputContent, ToolCall, ToolMessage, UserMessage } from "@ag-ui/core"; //#region src/hooks/useActiveArtifact.d.ts /** * Return type for {@link useActiveArtifact}. * * @category Hooks */ type UseActiveArtifactReturn = { /** Whether any artifact is currently active (panel is open). */isArtifactActive: boolean; /** The ID of the currently active artifact, or `null` if none. */ activeArtifactId: string | null; /** Closes whichever artifact is currently active. No-op if none is active. */ closeArtifact: () => void; }; /** * Returns global artifact activation state — whether *any* artifact is open, * and a close action that dismisses it. * * Use this in layout components that react to artifact presence (resizing panels, * showing overlays) without needing to know *which* artifact is active. * For per-artifact state and actions, use {@link useArtifact} instead. * * Must be called within a ``. * * @category Hooks * @returns {@link UseActiveArtifactReturn} */ declare function useActiveArtifact(): UseActiveArtifactReturn; //#endregion //#region src/hooks/useArtifact.d.ts /** * Return type for {@link useArtifact}. * * @category Hooks */ type UseArtifactReturn = { /** Whether this artifact is the currently active (visible) one. */isActive: boolean; /** Activates this artifact. */ open: () => void; /** Deactivates this artifact. */ close: () => void; /** Toggles this artifact: opens if closed, closes if open. */ toggle: () => void; }; /** * Binds a component to a specific artifact by ID, providing activation state * and actions (open, close, toggle). * * Multiple `useArtifact` hooks with different IDs can coexist — * only one artifact is active at a time. * * Must be called within a ``. * * @category Hooks * @param artifactId - Unique identifier for the artifact * @returns {@link UseArtifactReturn} * * @example * ```tsx * function PreviewButton({ id }: { id: string }) { * const { isActive, toggle } = useArtifact(id); * return ( * * ); * } * ``` */ declare function useArtifact(artifactId: string): UseArtifactReturn; //#endregion //#region src/hooks/useArtifactPortalTarget.d.ts /** * Provides access to the artifact portal target DOM node. * * This hook serves two roles: * - **Registering a portal target:** Call `setNode` from a ref callback to * designate a DOM element as the render target for artifact content. * Only one target should be registered at a time. * - **Reading the portal target:** Read `node` to get the current target * element for use with `createPortal()`. * * Must be called within a ``. * * @category Hooks * @returns `{ setNode, node }` — setter for registration, getter for portal rendering * * @example * ```tsx * // Registering a portal target * function MyPortalTarget() { * const { setNode } = useArtifactPortalTarget(); * return
; * } * * // Building a custom artifact panel * function MyArtifactPanel({ artifactId, children }) { * const { isActive } = useArtifact(artifactId); * const { node } = useArtifactPortalTarget(); * if (!isActive || !node) return null; * return createPortal(
{children}
, node); * } * ``` */ declare function useArtifactPortalTarget(): { setNode: (node: HTMLElement | null) => void; node: HTMLElement | null; }; //#endregion //#region src/types/messageFormat.d.ts /** * Converts messages between AG-UI format (used internally) and the * format your backend / storage layer expects. * * Both methods operate on **arrays** so that formats where a single * AG-UI message maps to multiple backend items (e.g. OpenAI Responses * API) work seamlessly alongside 1-to-1 formats (e.g. Completions). * * @example * // Identity (default) — no conversion * const identity: MessageFormat = { * toApi: (messages) => messages, * fromApi: (data) => data as Message[], * }; */ interface MessageFormat { /** Convert AG-UI messages to the format your backend expects (outbound). */ toApi(messages: Message[]): unknown; /** Convert messages from your backend/storage format to AG-UI (inbound). */ fromApi(data: unknown): Message[]; } /** * Default identity message format — no conversion. * Messages are sent and received as-is in AG-UI format. */ declare const identityMessageFormat: MessageFormat; //#endregion //#region src/types/stream.d.ts interface StreamProtocolAdapter { parse(response: Response): AsyncIterable; } //#endregion //#region src/hooks/useMessage.d.ts /** * @category Contexts */ declare const MessageContext: _$react.Context<{ message: Message; } | null>; /** * @category Hooks * @returns The current message. See {@link Message} for more information. */ declare const useMessage: () => { message: Message; }; /** * @category Components */ declare const MessageProvider: ({ message, children }: { message: Message; children: React.ReactNode; }) => _$react_jsx_runtime0.JSX.Element; //#endregion //#region src/store/types.d.ts type CreateMessage = Omit; type Thread = { id: string; title: string; createdAt: string | number; isPending?: boolean; }; type ThreadListState = { threads: Thread[]; isLoadingThreads: boolean; threadListError: Error | null; selectedThreadId: string | null; hasMoreThreads: boolean; }; type ThreadListActions = { loadThreads: () => void; loadMoreThreads: () => void; switchToNewThread: () => void; createThread: (firstMessage: UserMessage) => Promise; selectThread: (threadId: string) => void; updateThread: (thread: Thread) => void; deleteThread: (threadId: string) => void; }; type ThreadState = { messages: Message[]; isRunning: boolean; isLoadingMessages: boolean; threadError: Error | null; }; type ThreadActions = { processMessage: (message: CreateMessage) => Promise; appendMessages: (...messages: Message[]) => void; updateMessage: (message: Message) => void; setMessages: (messages: Message[]) => void; deleteMessage: (messageId: string) => void; cancelMessage: () => void; }; type ChatStore = ThreadListState & ThreadListActions & ThreadState & ThreadActions & { /** @internal */_nextCursor?: any; /** @internal */ _abortController: AbortController | null; }; type ThreadApiConfig = { threadApiUrl: string; fetchThreadList?: never; createThread?: never; deleteThread?: never; updateThread?: never; loadThread?: never; } | { threadApiUrl?: never; fetchThreadList?: (cursor?: any) => Promise<{ threads: Thread[]; nextCursor?: any; }>; createThread?: (firstMessage: UserMessage) => Promise; deleteThread?: (id: string) => Promise; updateThread?: (updated: Thread) => Promise; loadThread?: (threadId: string) => Promise; }; type ChatApiConfig = { apiUrl: string; processMessage?: never; } | { apiUrl?: never; processMessage: (params: { threadId: string; messages: Message[]; abortController: AbortController; }) => Promise; }; type ChatProviderProps = ThreadApiConfig & ChatApiConfig & { streamProtocol?: StreamProtocolAdapter; messageFormat?: MessageFormat; children: React.ReactNode; }; //#endregion //#region src/hooks/useThread.d.ts type ThreadSlice = ThreadState & ThreadActions; type ThreadListSlice = ThreadListState & ThreadListActions; declare function useThread(): ThreadSlice; declare function useThread(selector: (state: ThreadSlice) => T): T; declare function useThreadList(): ThreadListSlice; declare function useThreadList(selector: (state: ThreadListSlice) => T): T; //#endregion //#region src/store/artifactTypes.d.ts /** * Read-only state slice for the artifact system. * * @category Types */ type ArtifactState = { /** The currently displayed artifact, or `null` if the panel is collapsed. */activeArtifactId: string | null; }; /** * Actions for managing artifacts in the store. * * @category Types */ type ArtifactActions = { /** Activates an artifact by ID. */openArtifact: (id: string) => void; /** * Deactivates the artifact if it is the currently active one. * No-op if `id` does not match `activeArtifactId`. */ closeArtifact: (id: string) => void; /** * Resets `activeArtifactId` to `null`. * Called automatically on thread switch. */ resetArtifacts: () => void; }; /** * Internal implementation details — not part of the public API. * * @internal */ type ArtifactInternals = { /** @internal */_artifactPanelNode: HTMLElement | null; /** @internal */ _setArtifactPanelNode: (node: HTMLElement | null) => void; }; /** Combined artifact store type (state + actions + internals). */ type ArtifactStore = ArtifactState & ArtifactActions & ArtifactInternals; //#endregion //#region src/store/ArtifactContext.d.ts /** @internal React context holding the artifact Zustand store. Provided by `ChatProvider`. */ declare const ArtifactContext: _$react.Context | null>; /** * Returns the raw artifact Zustand store for advanced use cases. * * Prefer {@link useArtifact} or {@link useActiveArtifact} for most cases — * this hook is an escape hatch when you need direct store access. * * @category Hooks * @returns The Zustand `StoreApi` instance * @throws Error if called outside a `` */ declare const useArtifactStore: () => StoreApi; //#endregion //#region src/store/ChatProvider.d.ts declare const ChatProvider: FC; //#endregion //#region src/stream/adapters/ag-ui.d.ts declare const agUIAdapter: () => StreamProtocolAdapter; //#endregion //#region src/stream/adapters/langgraph.d.ts /** * Options for the LangGraph adapter. */ interface LangGraphAdapterOptions { /** * Called when a LangGraph interrupt is encountered in an `updates` event. * The interrupt payload is the value of the `__interrupt__` key. */ onInterrupt?: (interrupt: unknown) => void; } /** * Adapter for LangGraph streaming responses. * * LangGraph uses named SSE events (`event: \ndata: \n\n`) * rather than the `data:`-only format used by OpenAI. The adapter handles * the `messages`, `metadata`, `updates`, and `error` event types and maps * them to AG-UI events. * * Usage: * ```tsx * * ``` */ declare const langGraphAdapter: (options?: LangGraphAdapterOptions) => StreamProtocolAdapter; //#endregion //#region src/stream/adapters/openai-completions.d.ts declare const openAIAdapter: () => StreamProtocolAdapter; //#endregion //#region src/stream/adapters/openai-readable-stream.d.ts /** * Adapter for streams produced by the OpenAI SDK's `Stream.toReadableStream()`. * That method emits NDJSON (one JSON object per line, no `data: ` SSE prefix), * which differs from the raw SSE format that `openAIAdapter` expects. */ declare const openAIReadableStreamAdapter: () => StreamProtocolAdapter; //#endregion //#region src/stream/adapters/openai-responses.d.ts declare const openAIResponsesAdapter: () => StreamProtocolAdapter; //#endregion //#region src/stream/formats/langgraph-message-format.d.ts /** * LangChain-style message as returned by the LangGraph thread state API. * Each message carries a `type` discriminator (`"human"`, `"ai"`, `"tool"`, * `"system"`) and uses snake_case field names. */ interface LangChainMessage { id?: string; type: "human" | "ai" | "tool" | "system" | "developer" | (string & {}); content: string | Array<{ type: string; text?: string; }>; name?: string; tool_calls?: Array<{ id: string; name: string; args: Record | string; }>; tool_call_id?: string; } /** * Converts between AG-UI message format and LangGraph's LangChain-style * message format. * * LangGraph uses `type` discriminators (`"human"`, `"ai"`, `"tool"`, * `"system"`) instead of `role`, and tool call arguments are objects * rather than JSON strings. * * AG-UI → LangGraph (toApi): * - Maps `role` to `type` (`"user"` → `"human"`, `"assistant"` → `"ai"`) * - Converts `toolCalls[].function.arguments` from JSON string to object * - Converts `toolCallId` → `tool_call_id` * * LangGraph → AG-UI (fromApi): * - Maps `type` to `role` (`"human"` → `"user"`, `"ai"` → `"assistant"`) * - Converts tool call `args` object to JSON string * - Generates `id` via `crypto.randomUUID()` if not present */ declare const langGraphMessageFormat: MessageFormat; //#endregion //#region src/stream/formats/openai-conversation-message-format.d.ts /** * Converts between AG-UI message format and OpenAI's item-based format, * compatible with both the **Responses API** and **Conversations API**. * * AG-UI → OpenAI (toApi): * - Returns `ResponseInputItem[]` — works for both `responses.create({ input })` * and `conversations.items.create({ items })` * - Flattens assistant messages: text → `EasyInputMessage`, tool calls → `ResponseFunctionToolCall` * * OpenAI → AG-UI (fromApi): * - Accepts `ConversationItem[]` (or `ResponseItem[]`, which is a subset) * - Groups adjacent assistant messages + function_calls into `AssistantMessage` * - Handles Conversations-specific content types (`reasoning_text`, `summary_text`, etc.) */ declare const openAIConversationMessageFormat: MessageFormat; //#endregion //#region src/stream/formats/openai-message-format.d.ts /** * Converts between AG-UI message format and OpenAI **Chat Completions** * message format (`ChatCompletionMessageParam`). * * This is a 1-to-1 mapping — each AG-UI message becomes exactly one * `ChatCompletionMessageParam` and vice versa. * * AG-UI → OpenAI (toApi): * - Strips `id` (OpenAI doesn't use message IDs) * - Converts `toolCalls` → `tool_calls` * - Converts `toolCallId` → `tool_call_id` * - Converts multipart `content` arrays to OpenAI content format * * OpenAI → AG-UI (fromApi): * - Generates `id` via `crypto.randomUUID()` * - Converts `tool_calls` → `toolCalls` * - Converts `tool_call_id` → `toolCallId` */ declare const openAIMessageFormat: MessageFormat; //#endregion //#region src/stream/processStreamedMessage.d.ts /** * @inline */ interface Parameters { response: Response; /** A function that creates a new assistant message in the thread */ createMessage: (message: AssistantMessage) => void; /** A function that updates an existing assistant message in the thread */ updateMessage: (message: AssistantMessage) => void; /** A function that deletes an assistant message from the thread */ deleteMessage: (messageId: string) => void; /** The adapter to use for parsing the stream */ adapter?: StreamProtocolAdapter; } /** * @category Utilities */ declare const processStreamedMessage: ({ response, createMessage, updateMessage, deleteMessage, adapter }: Parameters) => Promise; //#endregion export { type AGUIEvent, type ActivityMessage, type ArtifactActions, ArtifactContext, type ArtifactState, type AssistantMessage, type BinaryInputContent, ChatProvider, type ChatProviderProps, type ChatStore, type CreateMessage, type DeveloperMessage, EventType, type FunctionCall, type InputContent, type LangGraphAdapterOptions, type LangChainMessage as LangGraphMessageFormat, type Message, MessageContext, type MessageFormat, MessageProvider, type ReasoningMessage, type StreamProtocolAdapter, type SystemMessage, type TextInputContent, type Thread, type ThreadActions, type ThreadListActions, type ThreadListState, type ThreadState, type ToolCall, type ToolMessage, type UserMessage, agUIAdapter, identityMessageFormat, langGraphAdapter, langGraphMessageFormat, openAIAdapter, openAIConversationMessageFormat, openAIMessageFormat, openAIReadableStreamAdapter, openAIResponsesAdapter, processStreamedMessage, useActiveArtifact, useArtifact, useArtifactPortalTarget, useArtifactStore, useMessage, useThread, useThreadList }; //# sourceMappingURL=index.d.mts.map