@assistant-ui/react
Version:
React components for AI chat.
222 lines • 9.22 kB
TypeScript
import { Attachment, PendingAttachment } from "../types/AttachmentTypes";
import { ComposerRuntimeCore, ThreadComposerRuntimeCore } from "../runtimes/core/ComposerRuntimeCore";
import { Unsubscribe } from "../types";
import { SubscribableWithState } from "./subscribable/Subscribable";
import { AttachmentRuntime, EditComposerAttachmentRuntimeImpl, ThreadComposerAttachmentRuntimeImpl } from "./AttachmentRuntime";
import { ComposerRuntimePath } from "./RuntimePathTypes";
import { MessageRole } from "../types/AssistantTypes";
export type ThreadComposerRuntimeCoreBinding = SubscribableWithState<ThreadComposerRuntimeCore | undefined, ComposerRuntimePath & {
composerSource: "thread";
}>;
export type EditComposerRuntimeCoreBinding = SubscribableWithState<ComposerRuntimeCore | undefined, ComposerRuntimePath & {
composerSource: "edit";
}>;
export type ComposerRuntimeCoreBinding = SubscribableWithState<ComposerRuntimeCore | undefined, ComposerRuntimePath>;
type LegacyEditComposerState = Readonly<{
type: "edit";
/** @deprecated Use `text` instead. This will be removed in 0.6.0. */
value: string;
/** @deprecated Use `useComposerRuntime().setText()` instead. This will be removed in 0.6.0. */
setValue: (value: string) => void;
text: string;
/**
* @deprecated Use `useComposerRuntime().setText()` instead. This will be removed in 0.6.0.
*/
setText: (value: string) => void;
canCancel: boolean;
isEditing: boolean;
isEmpty: boolean;
/**
* @deprecated Use useComposerRuntime().beginEdit() instead. This will be removed in 0.6.0.
*/
edit: () => void;
/**
* @deprecated Use `useComposerRuntime().send()` instead. This will be removed in 0.6.0.
*/
send: () => void;
/**
* @deprecated Use `useComposerRuntime().cancel()` instead. This will be removed in 0.6.0.
*/
cancel: () => void;
}>;
type LegacyThreadComposerState = Readonly<{
type: "thread";
/** @deprecated Use `text` instead. This will be removed in 0.6.0. */
value: string;
/** @deprecated Use `useComposerRuntime().setText` instead. This will be removed in 0.6.0. */
setValue: (value: string) => void;
attachments: readonly Attachment[];
/** @deprecated Use `useComposerRuntime().addAttachment` instead. This will be removed in 0.6.0. */
addAttachment: (file: File) => Promise<void>;
/** @deprecated Use `useComposerRuntime().removeAttachment` instead. This will be removed in 0.6.0. */
removeAttachment: (attachmentId: string) => Promise<void>;
text: string;
/** @deprecated Use `useComposerRuntime().setText` instead. This will be removed in 0.6.0. */
setText: (value: string) => void;
/** @deprecated Use `useComposerRuntime().reset` instead. This will be removed in 0.6.0. */
reset: () => void;
canCancel: boolean;
isEditing: boolean;
isEmpty: boolean;
/**
* @deprecated Use `useComposerRuntime().send` instead. This will be removed in 0.6.0.
**/
send: () => void;
/** @deprecated Use `useComposerRuntime().cancel` instead. This will be removed in 0.6.0. */
cancel: () => void;
}>;
type BaseComposerState = {
text: string;
role: MessageRole;
attachments: readonly Attachment[];
canCancel: boolean;
isEditing: boolean;
isEmpty: boolean;
};
export type ThreadComposerState = LegacyThreadComposerState & BaseComposerState & {
type: "thread";
attachments: readonly PendingAttachment[];
};
export type EditComposerState = LegacyEditComposerState & BaseComposerState & {
type: "edit";
};
export type ComposerState = ThreadComposerState | EditComposerState;
export type ComposerRuntime = {
path: ComposerRuntimePath;
readonly type: "edit" | "thread";
getState(): ComposerState;
/** @deprecated Use `getState().isEditing` instead. This will be removed in 0.6.0. */
readonly isEditing: boolean;
/** @deprecated Use `getState().isEmpty` instead. This will be removed in 0.6.0. */
readonly isEmpty: boolean;
/** @deprecated Use `getState().canCancel` instead. This will be removed in 0.6.0. */
readonly canCancel: boolean;
/** @deprecated Use `getState().text` instead. This will be removed in 0.6.0. */
readonly text: string;
/** @deprecated Use `getState().attachments` instead. This will be removed in 0.6.0. */
readonly attachments: readonly Attachment[];
/** @deprecated Use `getState().text` instead. This will be removed in 0.6.0. */
readonly value: string;
setText(text: string): void;
setValue(text: string): void;
getAttachmentAccept(): string;
addAttachment(file: File): Promise<void>;
/** @deprecated Use `getAttachmentById(id).removeAttachment()` instead. This will be removed in 0.6.0. */
removeAttachment(attachmentId: string): Promise<void>;
/** @deprecated This method will be removed in 0.6.0. Submit feedback if you need this functionality. */
reset(): void;
send(): void;
cancel(): void;
subscribe(callback: () => void): Unsubscribe;
getAttachmentByIndex(idx: number): AttachmentRuntime;
};
export declare abstract class ComposerRuntimeImpl implements ComposerRuntimeCore, ComposerRuntime {
protected _core: ComposerRuntimeCoreBinding;
get path(): ComposerRuntimePath;
abstract get type(): "edit" | "thread";
constructor(_core: ComposerRuntimeCoreBinding);
/**
* @deprecated Use `getState().isEditing` instead. This will be removed in 0.6.0.
*/
get isEditing(): boolean;
/**
* @deprecated Use `getState().isEmpty` instead. This will be removed in 0.6.0.
*/
get isEmpty(): boolean;
/**
* @deprecated Use `getState().canCancel` instead. This will be removed in 0.6.0.
*/
get canCancel(): boolean;
/**
* @deprecated Use `getState().text` instead. This will be removed in 0.6.0.
*/
get text(): string;
/**
* @deprecated Use `getState().role` instead. This will be removed in 0.6.0.
*/
get role(): MessageRole;
/**
* @deprecated Use `getState().attachments` instead. This will be removed in 0.6.0.
*/
get attachments(): readonly Attachment[] | (readonly Attachment[] & readonly PendingAttachment[]);
/**
* @deprecated Use `getState().text` instead. This will be removed in 0.6.0.
*/
get value(): string;
abstract getState(): ComposerState;
setText(text: string): void;
setValue(text: string): void;
addAttachment(file: File): Promise<void>;
/**
* @deprecated Use `getAttachmentById(id).removeAttachment()` instead. This will be removed in 0.6.0.
*/
removeAttachment(attachmentId: string): Promise<void>;
/**
* @deprecated This method will be removed in 0.6.0. Submit feedback if you need this functionality.
*/
reset(): void;
send(): void;
cancel(): void;
setRole(role: MessageRole): void;
subscribe(callback: () => void): Unsubscribe;
getAttachmentAccept(): string;
abstract getAttachmentByIndex(idx: number): AttachmentRuntime;
}
export type ThreadComposerRuntime = Omit<ComposerRuntime, "getState" | "getAttachmentByIndex"> & {
readonly path: ComposerRuntimePath & {
composerSource: "thread";
};
readonly type: "thread";
getState(): ThreadComposerState;
/**
* @deprecated Use `getState().attachments` instead. This will be removed in 0.6.0.
*/
attachments: readonly PendingAttachment[];
getAttachmentByIndex(idx: number): AttachmentRuntime & {
source: "thread-composer";
};
};
export declare class ThreadComposerRuntimeImpl extends ComposerRuntimeImpl implements ThreadComposerRuntime, ThreadComposerState {
get path(): ComposerRuntimePath & {
composerSource: "thread";
};
get type(): "thread";
private _getState;
constructor(core: ThreadComposerRuntimeCoreBinding);
get attachments(): readonly Attachment[] & readonly PendingAttachment[];
getState(): ThreadComposerState;
getAttachmentByIndex(idx: number): ThreadComposerAttachmentRuntimeImpl;
}
export type EditComposerRuntime = Omit<ComposerRuntime, "getState" | "getAttachmentByIndex"> & {
readonly path: ComposerRuntimePath & {
composerSource: "edit";
};
readonly type: "edit";
getState(): EditComposerState;
beginEdit(): void;
/**
* @deprecated Use `beginEdit()` instead. This will be removed in 0.6.0.
*/
edit(): void;
getAttachmentByIndex(idx: number): AttachmentRuntime & {
source: "edit-composer";
};
};
export declare class EditComposerRuntimeImpl extends ComposerRuntimeImpl implements EditComposerRuntime, EditComposerState {
private _beginEdit;
get path(): ComposerRuntimePath & {
composerSource: "edit";
};
get type(): "edit";
private _getState;
constructor(core: EditComposerRuntimeCoreBinding, _beginEdit: () => void);
getState(): EditComposerState;
beginEdit(): void;
/**
* @deprecated Use `beginEdit()` instead. This will be removed in 0.6.0.
*/
edit(): void;
getAttachmentByIndex(idx: number): EditComposerAttachmentRuntimeImpl;
}
export {};
//# sourceMappingURL=ComposerRuntime.d.ts.map