import { Accessor } from "solid-js"; import { AIDevtoolsDisplayOptions, BoundInterrupts, ChatClientOptions, ChatClientState, ChatInterruptState, ChatRequestBody, ChatResumeState, ClientContextOptionFromTools, ConnectionStatus, DistributedOmit, InferredClientContext, MultimodalContent, QueueConfig, QueueOption, QueueStrategy, QueuedMessage, ResolvableChatInterrupt, SendMessageOptions, UIMessage, WhenBusy } from "@tanstack/ai-client"; import { AnyClientTool as AnyClientTool$1, InferSchemaType, InterruptDefinition, ModelMessage, RunAgentResumeItem, SchemaInput } from "@tanstack/ai"; //#region src/types.d.ts /** * Recursive partial — every property and every nested array element is optional. * Used to type the in-flight `partial` accessor while a structured-output * stream is still arriving. */ type DeepPartial = T extends ReadonlyArray ? Array> : T extends object ? { [K in keyof T]?: DeepPartial } : T; /** * Options for the useChat hook. * * This extends ChatClientOptions but omits the state change callbacks that are * managed internally by Solid signals: * - `onMessagesChange` - Managed by Solid signal (exposed as `messages`) * - `onLoadingChange` - Managed by Solid signal (exposed as `isLoading`) * - `onErrorChange` - Managed by Solid signal (exposed as `error`) * - `onStatusChange` - Managed by Solid signal (exposed as `status`) * * All other callbacks (onResponse, onChunk, onFinish, onError) are * passed through to the underlying ChatClient and can be used for side effects. * * When `outputSchema` is supplied, the hook returns typed `partial` and `final` * accessors. The schema is used purely for type inference; server-side * validation still runs against the schema passed to `chat({ outputSchema })` * on the server route. * * Note: Connection and body changes will recreate the ChatClient instance. * To update these options, remount the component or use a key prop. */ type UseChatOptions = any, TSchema extends SchemaInput | undefined = undefined, TContext = InferredClientContext, TInterrupts extends ReadonlyArray> = readonly []> = DistributedOmit, 'onMessagesChange' | 'onLoadingChange' | 'onErrorChange' | 'onStatusChange' | 'onSubscriptionChange' | 'onConnectionStatusChange' | 'onSessionGeneratingChange' | 'onQueueChange' | 'onResumeStateChange' | 'onRunIdChange' | 'context' | 'devtools'> & { /** Display options for TanStack AI Devtools. */ devtools?: AIDevtoolsDisplayOptions; live?: boolean; /** * Standard-schema-compatible schema (Zod, Valibot, ArkType, or plain JSON * Schema). Used to infer the shape of `partial` and `final`. */ outputSchema?: TSchema; } & ClientContextOptionFromTools; /** * Discriminated return shape: when `outputSchema` is supplied, the hook adds * typed `partial` / `final` accessors; otherwise the return is unchanged. */ type UseChatReturn = any, TSchema extends SchemaInput | undefined = undefined, TInterrupts extends ReadonlyArray> = readonly []> = BaseUseChatReturn : unknown, TInterrupts> & (TSchema extends SchemaInput ? { /** * Live progressively-parsed structured output. Derived from the * latest assistant message's structured-output part. */ partial: Accessor>>; /** * Final, schema-validated structured output. `null` until the latest * assistant turn's structured-output part transitions to `complete`. */ final: Accessor | null>; } : Record); interface BaseUseChatReturn = any, TData = unknown, TInterrupts extends ReadonlyArray> = readonly []> { /** * Current messages in the conversation. When `outputSchema` is supplied, * `messages()[i].parts.find(p => p.type === 'structured-output')` is typed * by the schema — `data: T`, `partial: DeepPartial`. */ messages: Accessor>>; /** * Pending messages queued while the client is busy (streaming, claiming a * send, or draining). Separate from `messages` until they drain. */ queue: Accessor>; /** * Cancel a queued message before it drains. No-op if already sent. */ cancelQueued: (id: string) => void; /** * Send a message and get a response. * Can be a simple string or multimodal content with images, audio, etc. * By default, sends while busy are queued until the run settles successfully * (`queue: 'drop'` restores the old drop-while-busy behavior). * Pass `{ whenBusy }` to override the policy for a single send, or * `{ body }` to merge per-call JSON into this request's `forwardedProps`. */ sendMessage: (content: string | MultimodalContent, options?: SendMessageOptions) => Promise; /** * Append a message to the conversation */ append: (message: ModelMessage | UIMessage) => Promise; /** * Add the result of a client-side tool execution */ addToolResult: (result: { toolCallId: string; tool: string; output: any; state?: 'output-available' | 'output-error'; errorText?: string; }) => Promise; /** * Respond to a tool approval request */ addToolApprovalResponse: (response: { id: string; approved: boolean; }) => Promise; /** * The id of the run this client has in flight — one it started or rejoined — * or `null` when there is none (including while a run sits paused on an * interrupt, waiting on approval). * * A run is one turn of the conversation, so this changes from turn to turn. A * whole tool loop stays inside one run, while resuming after an interrupt * continues the turn under a new id — so one user message can produce several * run ids. Use it to talk to your own server about that run (cancel it, poll * it, correlate a log line). */ runId: Accessor; interrupts: Accessor>; /** @deprecated Use `interrupts`. */ pendingInterrupts: Accessor>; interruptErrors: Accessor['interruptErrors']>; resuming: Accessor; resolveInterrupts: { (approved: boolean): void; (resolver: (interrupt: ResolvableChatInterrupt) => undefined): void; }; cancelInterrupts: () => void; retryInterrupts: () => void; resumeInterruptsUnsafe: (resume: Array, state?: ChatResumeState) => Promise; /** @deprecated Use bound interrupt methods or `resumeInterruptsUnsafe`. */ resumeInterrupts: (resume: Array, state?: ChatResumeState) => Promise; /** * Reload the last assistant message */ reload: () => Promise; /** * Stop the current response generation */ stop: () => void; /** * Whether a response is currently being generated */ isLoading: Accessor; /** * True when the last hydrate or older-page response said more messages exist. */ hasOlderMessages: Accessor; /** * Fetch the next older window and put it in front of the painted messages. */ loadOlderMessages: () => Promise; /** * Current error, if any */ error: Accessor; /** * Set messages manually */ setMessages: (messages: Array>) => void; /** * Clear all messages */ clear: () => void; /** * Current generation status */ status: Accessor; /** * Whether the subscription loop is currently active */ isSubscribed: Accessor; /** * Current connection lifecycle status */ connectionStatus: Accessor; /** * Whether the shared session is actively generating. * Derived from stream run events (RUN_STARTED / RUN_FINISHED / RUN_ERROR). * Unlike `isLoading` (request-local), this reflects shared generation * activity visible to all subscribers (e.g. across tabs/devices). */ sessionGenerating: Accessor; } //#endregion export { type ChatRequestBody, DeepPartial, type QueueConfig, type QueueOption, type QueueStrategy, type QueuedMessage, type SendMessageOptions, type UIMessage, UseChatOptions, UseChatReturn, type WhenBusy }; //# sourceMappingURL=types.d.ts.map