@assistant-ui/react
Version:
TypeScript/React library for AI Chat
111 lines • 4.65 kB
TypeScript
import { ThreadRuntime } from "../runtime/ThreadRuntime";
import { ModelContext } from "../../model-context";
/**
* Hook to access the ThreadRuntime from the current context.
*
* The ThreadRuntime provides access to thread-level state and actions,
* including message management, thread state, and composer functionality.
*
* @param options Configuration options
* @param options.optional Whether the hook should return null if no context is found
* @returns The ThreadRuntime instance, or null if optional is true and no context exists
*
* @example
* ```tsx
* function MyComponent() {
* const runtime = useThreadRuntime();
*
* const handleSendMessage = (text: string) => {
* runtime.append({ role: "user", content: [{ type: "text", text }] });
* };
*
* return <button onClick={() => handleSendMessage("Hello!")}>Send</button>;
* }
* ```
*/
export declare function useThreadRuntime(options?: {
optional?: false | undefined;
}): ThreadRuntime;
export declare function useThreadRuntime(options?: {
optional?: boolean | undefined;
}): ThreadRuntime | null;
/**
* Hook to access the current thread state.
*
* This hook provides reactive access to the thread's state, including messages,
* running status, capabilities, and other thread-level properties.
*
* @param selector Optional selector function to pick specific state properties
* @returns The selected thread state or the entire thread state if no selector provided
*
* @example
* ```tsx
* function ThreadStatus() {
* const isRunning = useThread((state) => state.isRunning);
* const messageCount = useThread((state) => state.messages.length);
*
* return <div>Running: {isRunning}, Messages: {messageCount}</div>;
* }
* ```
*/
export declare const useThread: {
(): import("../runtime").ThreadState;
<TSelected>(selector: (state: import("../runtime").ThreadState) => TSelected): TSelected;
<TSelected>(selector: ((state: import("../runtime").ThreadState) => TSelected) | undefined): import("../runtime").ThreadState | TSelected;
(options: {
optional?: false | undefined;
}): import("../runtime").ThreadState;
(options: {
optional?: boolean | undefined;
}): import("../runtime").ThreadState | null;
<TSelected>(options: {
optional?: false | undefined;
selector: (state: import("../runtime").ThreadState) => TSelected;
}): TSelected;
<TSelected>(options: {
optional?: false | undefined;
selector: ((state: import("../runtime").ThreadState) => TSelected) | undefined;
}): import("../runtime").ThreadState | TSelected;
<TSelected>(options: {
optional?: boolean | undefined;
selector: (state: import("../runtime").ThreadState) => TSelected;
}): TSelected | null;
<TSelected>(options: {
optional?: boolean | undefined;
selector: ((state: import("../runtime").ThreadState) => TSelected) | undefined;
}): import("../runtime").ThreadState | TSelected | null;
};
export declare const useThreadComposer: {
(): import("../runtime").ThreadComposerState;
<TSelected>(selector: (state: import("../runtime").ThreadComposerState) => TSelected): TSelected;
<TSelected>(selector: ((state: import("../runtime").ThreadComposerState) => TSelected) | undefined): import("../runtime").ThreadComposerState | TSelected;
(options: {
optional?: false | undefined;
}): import("../runtime").ThreadComposerState;
(options: {
optional?: boolean | undefined;
}): import("../runtime").ThreadComposerState | null;
<TSelected>(options: {
optional?: false | undefined;
selector: (state: import("../runtime").ThreadComposerState) => TSelected;
}): TSelected;
<TSelected>(options: {
optional?: false | undefined;
selector: ((state: import("../runtime").ThreadComposerState) => TSelected) | undefined;
}): import("../runtime").ThreadComposerState | TSelected;
<TSelected>(options: {
optional?: boolean | undefined;
selector: (state: import("../runtime").ThreadComposerState) => TSelected;
}): TSelected | null;
<TSelected>(options: {
optional?: boolean | undefined;
selector: ((state: import("../runtime").ThreadComposerState) => TSelected) | undefined;
}): import("../runtime").ThreadComposerState | TSelected | null;
};
export declare function useThreadModelContext(options?: {
optional?: false | undefined;
}): ModelContext;
export declare function useThreadModelContext(options?: {
optional?: boolean | undefined;
}): ModelContext | null;
//# sourceMappingURL=ThreadContext.d.ts.map