@assistant-ui/react
Version:
TypeScript/React library for AI Chat
138 lines • 4.91 kB
TypeScript
import { ComposerRuntime } from "../runtime/ComposerRuntime";
/**
* @deprecated Use `useAssistantApi()` with `api.composer()` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
*
* Hook to access the ComposerRuntime from the current context.
*
* The ComposerRuntime provides access to composer state and actions for message
* composition, including text input, attachments, and sending functionality.
* This hook automatically resolves to either the message's edit composer or
* the thread's main composer depending on the context.
*
* @param options Configuration options
* @param options.optional Whether the hook should return null if no context is found
* @returns The ComposerRuntime instance, or null if optional is true and no context exists
*
* @example
* ```tsx
* // Before:
* function ComposerActions() {
* const runtime = useComposerRuntime();
* const handleSend = () => {
* if (runtime.getState().canSend) {
* runtime.send();
* }
* };
* const handleCancel = () => {
* if (runtime.getState().canCancel) {
* runtime.cancel();
* }
* };
* return (
* <div>
* <button onClick={handleSend}>Send</button>
* <button onClick={handleCancel}>Cancel</button>
* </div>
* );
* }
*
* // After:
* function ComposerActions() {
* const api = useAssistantApi();
* const canSend = useAssistantState(({ composer }) => composer.canSend);
* const canCancel = useAssistantState(({ composer }) => composer.canCancel);
* const handleSend = () => {
* if (canSend) {
* api.composer().send();
* }
* };
* const handleCancel = () => {
* if (canCancel) {
* api.composer().cancel();
* }
* };
* return (
* <div>
* <button onClick={handleSend}>Send</button>
* <button onClick={handleCancel}>Cancel</button>
* </div>
* );
* }
* ```
*/
export declare function useComposerRuntime(options?: {
optional?: false | undefined;
}): ComposerRuntime;
export declare function useComposerRuntime(options?: {
optional?: boolean | undefined;
}): ComposerRuntime | null;
/**
* @deprecated Use `useAssistantState(({ composer }) => composer)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
*
* Hook to access the current composer state.
*
* This hook provides reactive access to the composer's state, including text content,
* attachments, editing status, and send/cancel capabilities.
*
* @param selector Optional selector function to pick specific state properties
* @returns The selected composer state or the entire composer state if no selector provided
*
* @example
* ```tsx
* // Before:
* function ComposerStatus() {
* const text = useComposer((state) => state.text);
* const canSend = useComposer((state) => state.canSend);
* const attachmentCount = useComposer((state) => state.attachments.length);
* return (
* <div>
* Text: {text.length} chars,
* Attachments: {attachmentCount},
* Can send: {canSend}
* </div>
* );
* }
*
* // After:
* function ComposerStatus() {
* const text = useAssistantState(({ composer }) => composer.text);
* const canSend = useAssistantState(({ composer }) => composer.canSend);
* const attachmentCount = useAssistantState(({ composer }) => composer.attachments.length);
* return (
* <div>
* Text: {text.length} chars,
* Attachments: {attachmentCount},
* Can send: {canSend}
* </div>
* );
* }
* ```
*/
export declare const useComposer: {
(): import("../runtime").ComposerState;
<TSelected>(selector: (state: import("../runtime").ComposerState) => TSelected): TSelected;
<TSelected>(selector: ((state: import("../runtime").ComposerState) => TSelected) | undefined): import("../runtime").ComposerState | TSelected;
(options: {
optional?: false | undefined;
}): import("../runtime").ComposerState;
(options: {
optional?: boolean | undefined;
}): import("../runtime").ComposerState | null;
<TSelected>(options: {
optional?: false | undefined;
selector: (state: import("../runtime").ComposerState) => TSelected;
}): TSelected;
<TSelected>(options: {
optional?: false | undefined;
selector: ((state: import("../runtime").ComposerState) => TSelected) | undefined;
}): import("../runtime").ComposerState | TSelected;
<TSelected>(options: {
optional?: boolean | undefined;
selector: (state: import("../runtime").ComposerState) => TSelected;
}): TSelected | null;
<TSelected>(options: {
optional?: boolean | undefined;
selector: ((state: import("../runtime").ComposerState) => TSelected) | undefined;
}): import("../runtime").ComposerState | TSelected | null;
};
//# sourceMappingURL=ComposerContext.d.ts.map