@assistant-ui/react
Version:
Typescript/React library for AI Chat
114 lines • 4.72 kB
TypeScript
import { Attachment, PendingAttachment } from "../types/AttachmentTypes";
import { ComposerRuntimeCore, ComposerRuntimeEventType, 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, RunConfig } 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 BaseComposerState = {
readonly canCancel: boolean;
readonly isEditing: boolean;
readonly isEmpty: boolean;
readonly text: string;
readonly role: MessageRole;
readonly attachments: readonly Attachment[];
readonly runConfig: RunConfig;
};
export type ThreadComposerState = BaseComposerState & {
readonly type: "thread";
readonly attachments: readonly PendingAttachment[];
};
export type EditComposerState = BaseComposerState & {
readonly type: "edit";
};
export type ComposerState = ThreadComposerState | EditComposerState;
export type ComposerRuntime = {
readonly path: ComposerRuntimePath;
readonly type: "edit" | "thread";
getState(): ComposerState;
getAttachmentAccept(): string;
addAttachment(file: File): Promise<void>;
setText(text: string): void;
setRole(role: MessageRole): void;
setRunConfig(runConfig: RunConfig): void;
reset(): Promise<void>;
clearAttachments(): Promise<void>;
send(): void;
cancel(): void;
subscribe(callback: () => void): Unsubscribe;
getAttachmentByIndex(idx: number): AttachmentRuntime;
};
export declare abstract class ComposerRuntimeImpl implements ComposerRuntime {
protected _core: ComposerRuntimeCoreBinding;
get path(): ComposerRuntimePath;
abstract get type(): "edit" | "thread";
constructor(_core: ComposerRuntimeCoreBinding);
protected __internal_bindMethods(): void;
abstract getState(): ComposerState;
setText(text: string): void;
setRunConfig(runConfig: RunConfig): void;
addAttachment(file: File): Promise<void>;
reset(): Promise<void>;
clearAttachments(): Promise<void>;
send(): void;
cancel(): void;
setRole(role: MessageRole): void;
subscribe(callback: () => void): Unsubscribe;
private _eventSubscriptionSubjects;
unstable_on(event: ComposerRuntimeEventType, 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;
getAttachmentByIndex(idx: number): AttachmentRuntime & {
source: "thread-composer";
};
};
export declare class ThreadComposerRuntimeImpl extends ComposerRuntimeImpl implements ThreadComposerRuntime {
get path(): ComposerRuntimePath & {
composerSource: "thread";
};
get type(): "thread";
private _getState;
constructor(core: ThreadComposerRuntimeCoreBinding);
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;
getAttachmentByIndex(idx: number): AttachmentRuntime & {
source: "edit-composer";
};
};
export declare class EditComposerRuntimeImpl extends ComposerRuntimeImpl implements EditComposerRuntime {
private _beginEdit;
get path(): ComposerRuntimePath & {
composerSource: "edit";
};
get type(): "edit";
private _getState;
constructor(core: EditComposerRuntimeCoreBinding, _beginEdit: () => void);
__internal_bindMethods(): void;
getState(): EditComposerState;
beginEdit(): void;
getAttachmentByIndex(idx: number): EditComposerAttachmentRuntimeImpl;
}
export {};
//# sourceMappingURL=ComposerRuntime.d.ts.map