UNPKG

@iyio/convo-lang

Version:

A conversational language.

125 lines (124 loc) 5.27 kB
import { ReadonlySubject } from "@iyio/common"; import { Observable } from "rxjs"; import { Conversation, ConversationOptions } from "./Conversation"; import { ConvoComponentRenderer, ConvoDataStore, ConvoEditorMode, ConvoMessageRenderResult, ConvoMessageRenderer, ConvoPromptMedia } from "./convo-lang-ui-types"; import { FlatConvoMessage } from "./convo-types"; export type ConversationUiCtrlTask = 'completing' | 'loading' | 'clearing' | 'disposed'; export interface InitConversationUiCtrlConvoOptions { appendTemplate: boolean; } export interface ConversationUiCtrlOptions { id?: string; /** * If true and an id is given the conversation will be auto loaded. */ autoLoad?: boolean; template?: string; convo?: Conversation; convoOptions?: ConversationOptions; initConvo?: (convo: Conversation) => void; autoSave?: boolean; store?: null | 'localStorage' | ConvoDataStore; removeDanglingUserMessages?: boolean; enableSlashCommand?: boolean; } export declare class ConversationUiCtrl { readonly id: string; readonly autoSave: boolean; private readonly store; private readonly convoOptions?; private readonly initConvoCallback?; private readonly _lastCompletion; get lastCompletionSubject(): ReadonlySubject<string | null>; get lastCompletion(): string | null; private readonly tasks; private readonly _currentTask; get currentTaskSubject(): ReadonlySubject<ConversationUiCtrlTask | null>; get currentTask(): ConversationUiCtrlTask | null; private readonly _template; get templateSubject(): ReadonlySubject<string | undefined>; get template(): string | undefined; set template(value: string | undefined); private readonly _removeDanglingUserMessages; get removeDanglingUserMessagesSubject(): ReadonlySubject<boolean>; get removeDanglingUserMessages(): boolean; set removeDanglingUserMessages(value: boolean); private readonly _convo; get convoSubject(): ReadonlySubject<Conversation | null>; get convo(): Conversation | null; private readonly _showSource; get showSourceSubject(): ReadonlySubject<boolean>; /** * If true the source convo-lang syntax should be displayed to the user */ get showSource(): boolean; set showSource(value: boolean); private readonly _editorMode; get editorModeSubject(): ReadonlySubject<ConvoEditorMode>; get editorMode(): ConvoEditorMode; set editorMode(value: ConvoEditorMode); private readonly _showSystemMessages; get showSystemMessagesSubject(): ReadonlySubject<boolean>; /** * If true the system messages should be displayed to the user */ get showSystemMessages(): boolean; set showSystemMessages(value: boolean); private readonly _showFunctions; get showFunctionsSubject(): ReadonlySubject<boolean>; /** * If true function calls should be displayed to the user */ get showFunctions(): boolean; set showFunctions(value: boolean); private readonly _enabledSlashCommands; get enabledSlashCommandsSubject(): ReadonlySubject<boolean>; /** * If messages appended to the conversation using the appendUiMessage will be checked for messages * starting with a forward slash and be interpreted as a command. */ get enabledSlashCommands(): boolean; set enabledSlashCommands(value: boolean); private readonly _theme; get themeSubject(): ReadonlySubject<Record<string, any>>; get theme(): Record<string, any>; set theme(value: Record<string, any>); private readonly _mediaQueue; get mediaQueueSubject(): ReadonlySubject<readonly (ConvoPromptMedia)[]>; get mediaQueue(): readonly (ConvoPromptMedia)[]; private readonly _collapsed; get collapsedSubject(): ReadonlySubject<boolean>; /** * Often used to indicate if the conversation is display in a collapsed state */ get collapsed(): boolean; set collapsed(value: boolean); private readonly _onClear; get onClear(): Observable<void>; readonly componentRenderers: Record<string, ConvoComponentRenderer>; constructor({ id, autoLoad, convo, initConvo, convoOptions, template, autoSave, removeDanglingUserMessages, store, enableSlashCommand, }?: ConversationUiCtrlOptions); private _isDisposed; get isDisposed(): boolean; dispose(): void; protected initConvo(convo: Conversation, options: InitConversationUiCtrlConvoOptions): void; private createConvo; loadAsync(): Promise<boolean>; clear(): boolean; private pushTask; private popTask; private convoTaskCount; private convoTaskSub; private setConvo; replace(convo: string): boolean; replaceAndCompleteAsync(convo: string): Promise<boolean>; isSlashCommand(message: string): boolean; appendUiMessageAsync(message: string): Promise<boolean | 'command'>; queueMedia(media: string | ConvoPromptMedia): void; dequeueMedia(media: string | ConvoPromptMedia): boolean; private isAutoSaving; private autoSaveRequested; private queueAutoSave; private _autoSaveAsync; renderMessage(message: FlatConvoMessage, index: number): ConvoMessageRenderResult; readonly messageRenderers: ConvoMessageRenderer[]; }