@isartech/chat
Version:
A reusable native webcomponent that can be initiated with parameters such as an endpoint url and styles in any environment based on web technologies.
1,449 lines (1,272 loc) • 43.9 kB
TypeScript
import { AzureOptions } from 'speech-to-element/dist/types/options';
import { Commands } from 'speech-to-element/dist/types/options';
import { EventName } from '@lit/react';
import * as React_2 from 'react';
import { ReactWebComponent } from '@lit/react';
import { TextColor } from 'speech-to-element/dist/types/options';
import { Translations } from 'speech-to-element/dist/types/options';
import { WebSpeechOptions } from 'speech-to-element/dist/types/options';
declare interface APIKey {
key?: string;
validateKeyProperty?: boolean;
}
declare interface AssemblyAI {
audio?: true;
}
declare type AssignNever<T, K> = K & {
[B in Exclude<keyof T, keyof K>]?: never;
};
declare type AssistantFunctionHandler = (functionsDetails: FunctionsDetails) => AssistantFunctionHandlerResponse;
declare type AssistantFunctionHandlerResponse = string[] | Promise<string>[];
declare type AttributeTypeConverter = (value: string) => unknown;
declare type AudioFormat = 'mp3' | '4a' | 'webm' | 'mp4' | 'mpga' | 'wav' | 'mpeg' | 'm4a';
declare interface AudioRecordingFiles {
format?: AudioFormat;
acceptedFormats?: string;
maxNumberOfFiles?: number;
maxDurationSeconds?: number;
}
declare interface Avatar {
src?: string;
styles?: AvatarStyles;
}
declare type Avatars = true | CustomAvatars;
declare interface AvatarStyles {
container?: CustomStyle;
avatar?: CustomStyle;
position?: 'left' | 'right';
}
declare interface Azure {
textToSpeech?: AzureRegion & AzureTextToSpeechConfig;
speechToText?: AzureRegion & AzureSpeechToTextConfig;
summarization?: AzureEndpoint & AzureSummarizationConfig;
translation?: Partial<AzureRegion> & AzureTranslationConfig;
}
declare interface AzureEndpoint {
endpoint: string;
}
declare interface AzureRegion {
region: string;
}
declare interface AzureSpeechToTextConfig {
lang?: string;
}
declare interface AzureSummarizationConfig {
language?: string;
}
declare interface AzureTextToSpeechConfig {
lang?: string;
name?: string;
gender?: string;
outputFormat?: string;
}
declare interface AzureTranslationConfig {
language?: string;
}
declare type BuildUniqueInterfaces<CompleteInterface, Interfaces> = Interfaces extends object ? AssignNever<CompleteInterface, Interfaces> : never;
declare interface Button {
styles?: ButtonStyles;
position?: ButtonPosition;
}
declare interface ButtonInnerStyles {
styles?: StatefulStyles;
content?: string;
}
declare type ButtonPosition = 'inside-left' | 'inside-right' | 'outside-left' | 'outside-right' | 'dropup-menu';
declare interface ButtonStyles {
container?: StatefulStyles;
svg?: ButtonInnerStyles;
text?: ButtonInnerStyles;
}
declare interface CameraDimensions {
width?: number;
height?: number;
}
declare interface CameraFiles {
maxNumberOfFiles?: number;
acceptedFormats?: string;
format?: PhotoFormat;
dimensions?: CameraDimensions;
}
declare type CameraFilesServiceConfig = {
connect?: Connect;
files?: CameraFiles;
button?: Button;
modalContainerStyle?: CustomStyle;
};
export declare type CartAction = {
type: "PRODUCT_INCREMENT";
payload: IsarTechProduct.Product;
} | {
type: "PRODUCT_DECREMENT";
payload: IsarTechProduct.Product;
} | {
type: "PRODUCT_INCREMENT_BULK";
payload: IsarTechProduct.Product;
} | {
type: "PRODUCT_DECREMENT_BULK";
payload: IsarTechProduct.Product;
};
export declare const CartApiContext: React_2.Context<{
incrementWithHook: (product: IsarTechProduct.Product) => Promise<boolean>;
decrementWithHook: (product: IsarTechProduct.Product) => Promise<boolean>;
incrementBulkWithHook: (product: IsarTechProduct.Product) => Promise<boolean>;
decrementBulkWithHook: (product: IsarTechProduct.Product) => Promise<boolean>;
}>;
export declare const CartContext: React_2.Context<{
cart: Map<string, IsarTechProduct.Product>;
}>;
export declare const CartDispatch: React_2.Context<React_2.Dispatch<CartAction>>;
export declare type CartEventHandlers = {
onProductIncrement: (ev: CustomEvent<IsarTechProduct.Product>) => void | Promise<void>;
onProductDecrement: (ev: CustomEvent<IsarTechProduct.Product>) => void | Promise<void>;
onProductIncrementBulk: (ev: CustomEvent<IsarTechProduct.Product>) => void | Promise<void>;
onProductDecrementBulk: (ev: CustomEvent<IsarTechProduct.Product>) => void | Promise<void>;
};
export declare const cartReducer: (state: {
cart: Map<string, IsarTechProduct.Product>;
}, action: CartAction) => {
cart: Map<string, IsarTechProduct.Product>;
};
declare type ChatFunctionHandler = (functionsDetails: FunctionsDetails) => ChatFunctionHandlerResponse | Promise<ChatFunctionHandlerResponse>;
declare type ChatFunctionHandlerResponse = InterfacesUnion<{
response: string;
}[] | {
text: string;
}>;
declare interface Cohere {
chat?: true | CohereChatConfig;
textGeneration?: true | CohereGenerateConfig;
summarization?: true | CohereSummarizationConfig;
}
declare interface CohereChatConfig {
model?: string;
temperature?: number;
prompt_truncation?: 'AUTO' | 'OFF';
connectors?: {
id: string;
}[];
documents?: {
title: string;
snippet: string;
}[];
}
declare interface CohereGenerateConfig {
model?: string;
max_tokens?: number;
truncate?: 'NONE' | 'START' | 'END';
temperature?: number;
k?: number;
p?: number;
end_sequences?: string[];
stop_sequences?: string[];
frequency_penalty?: number;
presence_penalty?: number;
logit_bias?: GenericObject<string | number>;
preset?: string;
}
declare interface CohereSummarizationConfig {
model?: string;
length?: 'auto' | 'short' | 'medium' | 'long';
format?: 'auto' | 'paragraph' | 'bullets';
extractiveness?: 'auto' | 'low' | 'medium' | 'high';
temperature?: number;
additional_command?: string;
}
declare interface CompletionsHandlers {
onFinish: () => void;
}
declare interface Connect {
url?: string;
method?: string;
headers?: GenericObject<string>;
credentials?: 'same-origin' | 'include' | 'omit';
additionalBodyProps?: GenericObject<any>;
stream?: Stream;
websocket?: boolean | string | string[];
handler?: Handler;
}
declare type CustomAvatars = {
default?: Avatar;
user?: Avatar;
ai?: Avatar;
} & {
[name: string]: Avatar;
};
declare type CustomErrors = string[];
declare type CustomNames = {
default?: Name;
ai?: Name;
user?: Name;
} & {
[name: string]: Name;
};
declare type CustomStyle = Partial<CSSStyleDeclaration>;
declare class DeepChat extends InternalHTML {
connect?: Connect;
directConnection?: DirectConnection;
webModel?: WebModel;
requestBodyLimits?: RequestBodyLimits;
requestInterceptor?: RequestInterceptor;
responseInterceptor?: ResponseInterceptor;
validateInput?: ValidateInput;
loadHistory?: LoadHistory;
chatStyle?: CustomStyle;
attachmentContainerStyle?: CustomStyle;
dropupStyles?: DropupStyles;
inputAreaStyle?: CustomStyle;
textInput?: TextInput;
submitButtonStyles?: SubmitButtonStyles;
auxiliaryStyle?: string;
history?: MessageContent[];
introMessage?: IntroMessage | IntroMessage[];
avatars?: Avatars;
names?: Names;
displayLoadingBubble?: boolean;
errorMessages?: ErrorMessages;
messageStyles?: MessageStyles;
textToSpeech?: boolean | TextToSpeechConfig;
speechToText?: boolean | SpeechToTextConfig;
images?: boolean | FilesServiceConfig;
gifs?: boolean | FilesServiceConfig;
camera?: boolean | CameraFilesServiceConfig;
audio?: boolean | FilesServiceConfig;
microphone?: boolean | MicrophoneFilesServiceConfig;
mixedFiles?: boolean | FilesServiceConfig;
dragAndDrop?: boolean | CustomStyle;
introPanelStyle?: CustomStyle;
htmlClassUtilities?: HTMLClassUtilities;
getMessages: () => MessageContent[];
submitUserMessage: (content: UserContent) => void;
addMessage: (message: Response_2, isUpdate?: boolean) => void;
focusInput: () => void;
refreshMessages: () => void;
clearMessages: (isReset?: boolean) => void;
scrollToBottom: () => void;
disableSubmitButton: DisableSubmitButton;
setPlaceholderText: (text: string) => void;
onMessage?: OnMessage;
onClearMessages?: () => void;
onComponentRender?: (ref: DeepChat) => void;
onError?: OnError;
demo?: Demo;
_hasBeenRendered: boolean;
_auxiliaryStyleApplied: boolean;
_activeService?: ServiceIO;
_childElement?: HTMLElement;
_validationHandler?: ValidationHandler;
_insertKeyViewStyles?: InsertKeyViewStyles;
constructor();
private readonly _elementRef;
private changeToChatView;
onRender(): void;
disconnectedCallback(): void;
}
declare type Demo = true | {
response?: DemoResponse;
displayErrors?: DemoErrors;
displayLoadingBubble?: boolean;
displayFileAttachmentContainer?: boolean;
};
declare type DemoErrors = {
[key in keyof ErrorMessageOverrides]?: boolean;
};
declare type DemoResponse = Response_2 | ((message: MessageContent) => Response_2);
declare interface DirectConnection {
openAI?: OpenAI & APIKey;
huggingFace?: HuggingFace & APIKey;
mistral?: Mistral & APIKey;
stabilityAI?: StabilityAI & APIKey;
cohere?: Cohere & APIKey;
azure?: Azure & APIKey;
assemblyAI?: AssemblyAI & APIKey;
}
declare type DisableSubmitButton = (isDisabled?: boolean) => void;
declare class DropDown extends HTMLElement {
private suggestions;
private activeSuggestionIndex;
private targetEl;
private suggestionsContainer;
private elementRef;
private closeButtonRef;
private hasRendered;
private currentPrompt;
constructor();
connectedCallback(): void;
setTargetElement(target: HTMLElement): void;
disconnectedCallback(): void;
render(): void;
/**
* Opens the suggestions list with options (optionally filtered).
* @param {Array<string>} suggestionsList
*/
populateSuggestions(prompt: string, suggestionsList: string[]): void;
/**
* Clears any highlighted suggestion from the list.
*/
clearHighlights(): void;
/**
* Highlights the suggestion at the given index.
* @param {number} index
*/
highlightItem(index: number): void;
hideSuggestions(): void;
showSuggestions(): void;
handleCloseClick(e: Event): void;
handleDocumentClick(e: MouseEvent): void;
handleInput(e: Event): void;
handleFocus(e: Event): void;
handleSuggestionClick(e: Event): void;
}
declare interface DropupMenuStyles {
container?: CustomStyle;
item?: StatefulStyles;
iconContainer?: CustomStyle;
text?: CustomStyle;
}
declare interface DropupStyles {
button?: Button;
menu?: DropupMenuStyles;
}
declare interface ErrorMessageOverrides {
default?: string;
service?: string;
speechToText?: string;
}
declare interface ErrorMessages {
displayServiceErrorMessages?: boolean;
overrides?: ErrorMessageOverrides;
}
declare type ErrorResp = string | string[] | Error | Response_2;
export declare type EventMap = {
changeQuantity: EventName<CustomEvent<IsarTechProduct.Product>>;
changeBulkQuantity: EventName<CustomEvent<IsarTechProduct.Product>>;
onProductIncrement: EventName<CustomEvent<IsarTechProduct.Product>>;
onProductDecrement: EventName<CustomEvent<IsarTechProduct.Product>>;
onProductIncrementBulk: EventName<CustomEvent<IsarTechProduct.Product>>;
onProductDecrementBulk: EventName<CustomEvent<IsarTechProduct.Product>>;
};
declare type EventToFunction = {
[K in keyof GlobalEventHandlersEventMap]?: (event: Partial<GlobalEventHandlersEventMap[K]>) => void;
} & {
[eventName: string]: (event: CustomEvent) => void;
};
declare type FetchFunc = (body: any) => Promise<Response>;
declare type FILE_TYPES = 'images' | 'gifs' | 'audio' | 'mixedFiles';
declare interface FileAttachments {
maxNumberOfFiles?: number;
acceptedFormats?: string;
infoModal?: InfoModal;
}
declare type FileServiceIO = FilesServiceConfig & {
infoModalTextMarkUp?: string;
};
declare type FilesServiceConfig = {
connect?: Connect;
files?: FileAttachments;
button?: Button;
};
declare type FileToolTypes = 'code_interpreter' | 'file_search' | 'images';
declare type FunctionsDetails = {
name: string;
arguments: string;
}[];
declare type GenericObject<T = string> = {
[key: string]: T;
};
declare type Handler = (body: any, signals: Signals) => void;
declare type HistoryMessage = MessageContent | false;
declare type HTMLClassUtilities = {
[className: string]: HTMLClassUtility;
};
declare interface HTMLClassUtility {
events?: EventToFunction;
styles?: StatefulStyles;
}
declare type HuggingFace = {
conversation?: true | (HuggingFaceModel & HuggingFaceConversationConfig);
textGeneration?: true | (HuggingFaceModel & HuggingFaceTextGenerationConfig);
summarization?: true | (HuggingFaceModel & HuggingFaceSummarizationConfig);
translation?: true | (HuggingFaceModel & HuggingFaceTranslationConfig);
fillMask?: true | (HuggingFaceModel & HuggingFaceFillMaskConfig);
questionAnswer?: HuggingFaceModel & HuggingFaceQuestionAnswerConfig;
audioSpeechRecognition?: true | HuggingFaceModel;
audioClassification?: true | HuggingFaceModel;
imageClassification?: true | HuggingFaceModel;
};
declare interface HuggingFaceConversationConfig {
parameters?: {
min_length?: number;
max_length?: number;
top_k?: number;
top_p?: number;
temperature?: number;
repetition_penalty?: number;
};
options?: {
use_cache?: boolean;
};
}
declare interface HuggingFaceFillMaskConfig {
options?: {
use_cache?: boolean;
};
}
declare interface HuggingFaceModel {
model?: string;
}
declare interface HuggingFaceQuestionAnswerConfig {
context: string;
}
declare interface HuggingFaceSummarizationConfig {
parameters?: {
min_length?: number;
max_length?: number;
top_k?: number;
top_p?: number;
temperature?: number;
repetition_penalty?: number;
};
options?: {
use_cache?: boolean;
};
}
declare interface HuggingFaceTextGenerationConfig {
parameters?: {
top_k?: number;
top_p?: number;
temperature?: number;
repetition_penalty?: number;
max_new_tokens?: number;
do_sample?: boolean;
};
options?: {
use_cache?: boolean;
};
}
declare interface HuggingFaceTranslationConfig {
options?: {
use_cache?: boolean;
};
}
declare interface InfoModal {
textMarkDown: string;
openModalOnce?: boolean;
containerStyle?: CustomStyle;
}
declare interface InsertKeyViewStyles {
displayCautionText?: boolean;
}
declare type InterfacesUnion<Interfaces> = BuildUniqueInterfaces<UnionToIntersection<Interfaces>, Interfaces>;
declare class InternalHTML extends HTMLElement {
_waitingToRender_: boolean;
_propUpdated_: boolean;
static _attributes_: GenericObject<AttributeTypeConverter>;
static _attributeToProperty_: GenericObject<string>;
static get observedAttributes(): string[];
constructor();
private constructPropertyAccessors;
attributeChangedCallback(attributeName: string, oldValue: string, newValue: string): void;
onRender(): void;
}
declare type IntroMessage = InterfacesUnion<{
text: string;
} | {
html: string;
}>;
declare class IntroPanel {
readonly _elementRef?: HTMLElement;
private _isDisplayed;
constructor(childElement?: HTMLElement, introPanelMarkUp?: string, introPanelStyle?: CustomStyle);
private static createIntroPanel;
private createIntroPanelWithChild;
private createInternalIntroPanel;
hide(): void;
display(): void;
}
declare class IsarTechChat extends DeepChat {
static get observedAttributes(): string[];
url: string;
userId: string;
language: LanguageCode;
isartechId: string;
isartechKey: string;
countryId: number | string;
country: string;
tenantId: number | string;
tenant: string;
districtId: string | number;
district: string;
marketId: number | string;
market: string;
disableCredits: boolean;
enableHeader: boolean;
enableLanguage: boolean;
useSessionHistory: boolean;
themeColor: string | null;
mobileBreakpoint: number;
isMobile: boolean;
private messages;
private sessionId;
private _cart;
protected elementRef: ShadowRoot;
asideRef: HTMLDivElement | undefined;
private containerRef;
private introPanelContainerRef;
messagesRef: HTMLElement | null;
scrollTopRef: ScrollToTop | null;
scrollAsideRef: ScrollToTop | null;
dropdownRef: DropDown | null;
suggestionsAbortController: AbortController | null;
suggestionsTimeout: NodeJS.Timeout | string | number | undefined | null;
private introMetadata;
private mutationObserver;
inflightSuggestion: boolean;
private lastInflightWordCount;
private initialized;
private postRender;
private resizeObserver;
private lastWidth;
private isDev;
private createCarousel;
private attributesSimple;
private tdLinkHandlers;
constructor();
setColorTheme(hexColor: string): void;
registerTdHandlers(): void;
clearChat(isReset?: boolean): Promise<void>;
get cart(): Map<string, IsarTechProduct_2.Attributes> | null | undefined;
set cart(newCart: Map<string, IsarTechProduct_2.Attributes> | null | undefined);
setCart(cart: Map<string, IsarTechProduct_2.Attributes>): void;
setCartNative(cart: [string, IsarTechProduct_2.Attributes][]): void;
updateQuantity(product: IsarTechProduct_2.Product): void;
handleCartChange(cart: [string, IsarTechProduct_2.Attributes][]): void;
clearCart(): void;
getCart(): IsarTechProduct_2.Product[];
private setBackendUrl;
disconnectedCallback(): void;
handleScrollToHash(ev: Event): void;
handleMessagesScroll(): void;
handleAsideScroll(): void;
connectedCallback(): void;
private createSuggestions;
private createObservers;
private _renderStoreLocation;
private getIntro;
private renderGroupedIntroPanel;
private createDesktopIntroOverlay;
private createMobileIntroPanel;
private handleIntroSubmission;
attributeChangedCallback(name: string, oldValue: string | number, newValue: string | number): void;
private inputHandler;
private handleResize;
private handleRender;
private setupScroll;
private initChat;
private createAside;
private _setHeader;
private _newConversation;
private _setNewConversationAction;
private _setLanguageToggle;
private _shortCuts;
private setServiceHeaders;
toggleLanguage(): Promise<void>;
private setDocLanguage;
private setMessageStyles;
private addQuantityChangeListener;
private sendMessage;
}
declare const IsartechChatReact: ReactWebComponent<IsarTechChat, EventMap>;
export { IsartechChatReact }
export default IsartechChatReact;
declare namespace IsarTechProduct {
const EVENT_CHANGE_QUANTITY: "change-quantity";
const EVENT_CHANGE_QUANTITY_BULK: "change-quantity-bulk";
const EVENT_PRODUCT_CLICK: "product-click";
const EVENT_INCREMENT: "product-increment";
const EVENT_DECREMENT: "product-decrement";
const EVENT_INCREMENT_BULK: "product-increment-bulk";
const EVENT_DECREMENT_BULK: "product-decrement-bulk";
const ELEMENT_TAG: "it-product";
type Product = Attributes & {
name: string;
};
interface Attributes {
name: string;
quantity: number;
bulkQuantity: number;
itemId: string;
messageId: string;
slug: string;
in_stock: boolean;
brand: string;
price: string;
query: string;
description?: string;
category?: string;
points?: string;
priceUnit?: string;
displayUnit?: string;
bundleUnit?: string;
weight?: string;
weightUnit?: string;
origin?: string;
imgURL?: string;
weighted?: boolean;
weightIncrement?: number;
maxWeightPerOrder?: number;
minWeightPerOrder?: number;
defaultWeightCount?: number;
source?: string;
score?: number;
original_price?: number | string;
preferred_cuts?: PreferredCuts;
discount_type?: string;
condition_value?: string;
currency?: string;
benefit_value?: string;
bulk_step?: number;
}
interface CutPattern {
id: number;
image: string;
default: boolean;
name_ar: string;
name_en: string;
}
interface PreferredCuts {
name: string;
cut_type: string;
cut_patterns: CutPattern[];
important_text_ar: string;
important_text_en: string;
}
interface ProductEvent extends Event {
detail: Attributes;
}
interface ProductEventMap {
CHANGE_QUANTITY: ProductEvent;
PRODUCT_CLICK: ProductEvent;
}
{};
}
declare namespace IsarTechProduct_2 {
const EVENT_CHANGE_QUANTITY: "change-quantity";
const EVENT_CHANGE_QUANTITY_BULK: "change-quantity-bulk";
const EVENT_PRODUCT_CLICK: "product-click";
const EVENT_INCREMENT: "product-increment";
const EVENT_DECREMENT: "product-decrement";
const EVENT_INCREMENT_BULK: "product-increment-bulk";
const EVENT_DECREMENT_BULK: "product-decrement-bulk";
const ELEMENT_TAG: "it-product";
type Product = Attributes & {
name: string;
};
interface Attributes {
name: string;
quantity: number;
bulkQuantity: number;
itemId: string;
messageId: string;
slug: string;
in_stock: boolean;
brand: string;
price: string;
query: string;
description?: string;
category?: string;
points?: string;
priceUnit?: string;
displayUnit?: string;
bundleUnit?: string;
weight?: string;
weightUnit?: string;
origin?: string;
imgURL?: string;
weighted?: boolean;
weightIncrement?: number;
maxWeightPerOrder?: number;
minWeightPerOrder?: number;
defaultWeightCount?: number;
source?: string;
score?: number;
original_price?: number | string;
preferred_cuts?: PreferredCuts;
discount_type?: string;
condition_value?: string;
currency?: string;
benefit_value?: string;
bulk_step?: number;
}
interface CutPattern {
id: number;
image: string;
default: boolean;
name_ar: string;
name_en: string;
}
interface PreferredCuts {
name: string;
cut_type: string;
cut_patterns: CutPattern[];
important_text_ar: string;
important_text_en: string;
}
interface ProductEvent extends Event {
detail: Attributes;
}
interface ProductEventMap {
CHANGE_QUANTITY: ProductEvent;
PRODUCT_CLICK: ProductEvent;
}
{};
}
export declare const IsartechProvider: React_2.FC<IsartechProviderProps>;
export declare interface IsartechProviderProps {
children: React_2.ReactNode;
initialState?: {
cart: Map<string, IsarTechProduct.Product>;
};
onBeforeIncrement?: (product: IsarTechProduct.Product) => Promise<IsarTechProduct.Product>;
onBeforeDecrement?: (product: IsarTechProduct.Product) => Promise<IsarTechProduct.Product>;
onBeforeIncrementBulk?: (product: IsarTechProduct.Product) => Promise<IsarTechProduct.Product>;
onBeforeDecrementBulk?: (product: IsarTechProduct.Product) => Promise<IsarTechProduct.Product>;
onError?: (error: Error, operation: 'increment' | 'decrement' | 'incrementBulk' | 'decrementBulk', product: IsarTechProduct.Product) => void;
}
declare interface IWebsocketHandler {
isOpen: boolean;
newUserMessage: {
listener: (text: string) => void;
};
}
declare interface KeyVerificationHandlers {
onSuccess: () => void;
onFail: (message: string) => void;
onLoad: () => void;
}
declare type LanguageCode = "en" | "ar" | "de";
declare type LoadHistory = (index: number) => HistoryMessage[] | Promise<HistoryMessage[]>;
declare interface LoadingHistoryStyles {
full?: LoadingStyles;
small?: LoadingStyles;
}
declare interface LoadingMessageStyles {
message?: LoadingStyles;
history?: LoadingHistoryStyles;
}
declare interface LoadingStyles {
styles?: MessageElementsStyles;
html?: string;
}
declare type MessageContent = {
role?: string;
text?: string;
files?: MessageFile[];
html?: string;
_sessionId?: string;
};
declare type MessageContentI = PropsRequired<MessageContent, 'role'>;
declare interface MessageElements {
outerContainer: HTMLElement;
innerContainer: HTMLElement;
bubbleElement: HTMLElement;
}
declare interface MessageElementsStyles {
outerContainer?: CustomStyle;
innerContainer?: CustomStyle;
bubble?: CustomStyle;
media?: CustomStyle;
}
declare type MessageFile = {
src?: string;
name?: string;
type?: MessageFileType;
ref?: File;
};
declare type MessageFiles = MessageFile[];
declare type MessageFileType = 'image' | 'audio' | 'any';
declare type MessageRoleStyles = {
shared?: MessageElementsStyles;
user?: MessageElementsStyles;
ai?: MessageElementsStyles;
} & {
[role: string]: MessageElementsStyles;
};
declare class Messages_2 extends MessagesBase {
private readonly _errorMessageOverrides?;
private readonly _onClearMessages?;
private readonly _onError?;
private readonly _displayLoadingMessage?;
private readonly _permittedErrorPrefixes?;
private readonly _displayServiceErrorMessages?;
private _introMessage?;
customDemoResponse?: DemoResponse;
constructor(deepChat: DeepChat, serviceIO: ServiceIO, panel?: HTMLElement);
private static getDisplayLoadingMessage;
private prepareDemo;
private addSetupMessageIfNeeded;
private addIntroductoryMessages;
private addIntroductoryMessage;
removeIntroductoryMessage(): void;
addAnyMessage(message: ResponseI, isHistory?: boolean, isTop?: boolean): void | MessageContentI;
addNewMessage(data: ResponseI, isHistory?: boolean, isTop?: boolean): MessageContentI;
private isValidMessageContent;
private updateStateOnMessage;
private removeMessageOnError;
addNewErrorMessage(type: keyof Omit<ErrorMessageOverrides, 'default'>, message?: ErrorResp, isTop?: boolean): void;
private static checkPermittedErrorPrefixes;
private static extractErrorMessages;
private getPermittedMessage;
removeError(): void;
private addDefaultLoadingMessage;
addLoadingMessage(): void;
private populateIntroPanel;
addMultipleFiles(filesData: {
file: File;
type: MessageFileType;
}[]): Promise<MessageFile[]>;
private static isActiveElement;
private clearMessages;
}
declare class MessagesBase {
messageElementRefs: MessageElements[];
textToSpeech?: ProcessedTextToSpeechConfig;
submitUserMessage?: (content: UserContent) => void;
readonly elementRef: HTMLElement;
readonly messageStyles?: MessageStyles;
readonly messages: MessageContentI[];
readonly htmlClassUtilities: HTMLClassUtilities;
textElementsToText: [MessageElements, string][];
protected _introPanel?: IntroPanel;
protected readonly _avatars?: Avatars;
protected readonly _names?: Names;
private _remarkable;
private readonly _onMessage?;
constructor(deepChat: DeepChat);
private static createContainerElement;
addNewTextMessage(text: string, role: string, overwrite?: Overwrite, isTop?: boolean): MessageElements;
private overwriteText;
protected createAndAppendNewMessageElement(text: string, role: string): MessageElements;
private createAndPrependNewMessageElement;
createMessageElementsOnOrientation(text: string, role: string, isTop: boolean): MessageElements;
createNewMessageElement(text: string, role: string, isTop?: boolean): MessageElements;
private revealRoleElementsIfTempRemoved;
protected static isTemporaryElement(elements: MessageElements): boolean;
createMessageElements(text: string, role: string, isTop?: boolean): MessageElements;
protected static createBaseElements(): MessageElements;
private addInnerContainerElements;
applyCustomStyles(elements: MessageElements | undefined, role: string, media: boolean, otherStyles?: MessageRoleStyles | MessageElementsStyles): void;
static createMessageContent(content: Response_2): MessageContentI;
removeMessage(messageElements: MessageElements): void;
removeLastMessage(): void;
isLastMessageError(): boolean | undefined;
static isLoadingMessage(elements?: MessageElements): boolean | undefined;
sendClientUpdate(message: MessageContentI, isHistory?: boolean): void;
renderText(bubbleElement: HTMLElement, text: string): void;
protected refreshTextMessages(): void;
}
declare interface MessageStyles {
default?: MessageRoleStyles;
image?: MessageRoleStyles;
audio?: MessageRoleStyles;
file?: MessageRoleStyles;
html?: MessageRoleStyles;
intro?: MessageElementsStyles;
error?: MessageElementsStyles;
loading?: LoadingMessageStyles;
}
declare type MicrophoneFilesServiceConfig = {
connect?: Connect;
files?: AudioRecordingFiles;
button?: MicrophoneStyles;
};
declare interface MicrophoneStyles {
default?: ButtonStyles;
active?: ButtonStyles;
unsupported?: ButtonStyles;
position?: ButtonPosition;
}
declare type Mistral = {
model?: string;
systemPrompt?: string;
};
declare interface Name {
text?: string;
style?: CustomStyle;
position?: 'left' | 'right';
}
declare type Names = true | CustomNames;
declare type OnError = (error: string) => void;
declare type OnMessage = (body: {
message: MessageContent;
isHistory: boolean;
}) => void;
declare interface OpenAI {
chat?: true | OpenAIChat;
assistant?: true | OpenAIAssistant;
images?: true | OpenAIImagesDalle2 | OpenAIImagesDalle3;
textToSpeech?: true | OpenAITextToSpeech;
speechToText?: true | OpenAISpeechToText;
}
declare interface OpenAIAssistant {
assistant_id?: string;
thread_id?: string;
load_thread_history?: boolean;
new_assistant?: OpenAINewAssistant;
files_tool_type?: FileToolTypes | ((fileNames: string[]) => FileToolTypes);
function_handler?: AssistantFunctionHandler;
}
declare type OpenAIChat = {
system_prompt?: string;
model?: string;
max_tokens?: number;
temperature?: number;
top_p?: number;
} & OpenAIChatFunctions;
declare interface OpenAIChatFunctions {
tools?: {
type: 'function' | 'object';
function: {
name: string;
description?: string;
parameters: object;
};
}[];
tool_choice?: 'auto' | {
type: 'function';
function: {
name: string;
};
};
function_handler?: ChatFunctionHandler;
}
declare interface OpenAIImagesDalle2 {
model?: 'dall-e-2';
n?: number;
size?: '256x256' | '512x512' | '1024x1024';
response_format?: 'url' | 'b64_json';
user?: string;
}
declare interface OpenAIImagesDalle3 {
model: 'dall-e-3';
quality?: string;
size?: '1024x1024' | '1792x1024' | '1024x1792';
style?: 'vivid' | 'natural';
response_format?: 'url' | 'b64_json';
user?: string;
}
declare interface OpenAINewAssistant {
model?: string;
name?: string;
description?: string;
instructions?: string;
tools?: {
type: 'code_interpreter' | 'file_search' | 'function';
function?: {
name: string;
description?: string;
parameters?: object;
};
}[];
tool_resources?: {
code_interpreter?: {
file_ids: string[];
};
file_search?: {
vector_store_ids?: string[];
vector_stores: {
file_ids: string[];
};
};
};
}
declare type OpenAISpeechToText = {
model?: string;
temperature?: number;
language?: string;
type?: 'transcription' | 'translation';
};
declare type OpenAITextToSpeech = {
model?: string;
voice?: string;
speed?: number;
};
declare interface Overwrite {
status?: boolean;
}
declare type PhotoFormat = 'png' | 'jpeg';
declare interface Placeholder {
text?: string;
style?: CustomStyle;
}
declare type PollResult = Promise<InterfacesUnion<Response_2 | {
timeoutMS: number;
}>>;
declare type ProcessedTextToSpeechConfig = {
lang?: string;
pitch?: number;
rate?: number;
voice?: SpeechSynthesisVoice;
volume?: number;
};
export declare type Product = IsarTechProduct.Product;
declare type PropsRequired<T, K extends keyof T> = T & {
[P in K]-?: T[P];
};
declare interface RequestBodyLimits {
maxMessages?: number;
totalMessagesMaxCharLength?: number;
}
declare interface RequestContents {
text?: string;
files?: File[];
}
declare interface RequestDetails {
body: any;
headers?: GenericObject<string>;
}
declare type RequestInterceptor = (details: RequestDetails) => ResponseDetails | Promise<ResponseDetails>;
declare interface Response_2 {
text?: string;
files?: MessageFiles;
html?: string;
error?: string;
role?: string;
overwrite?: boolean;
_sessionId?: string;
}
declare type ResponseDetails = RequestDetails | {
error: string;
};
declare type ResponseI = Response_2 & {
sendUpdate?: boolean;
ignoreText?: boolean;
};
declare type ResponseInterceptor = (response: any) => Response_2 | Promise<Response_2>;
declare class ScrollToTop extends HTMLElement {
private elementRef;
private buttonRef;
private clickHandler;
scrollTargetRef: HTMLElement;
bottomMarker: HTMLElement;
size: string;
private hasRendered;
private viewportHeight;
constructor(target: HTMLElement);
connectedCallback(): void;
disconnectedCallback(): void;
render(): void;
moveTobottom(): void;
setupEventListeners(): void;
onResize(): void;
toggleDirection(): void;
handleClick(): void;
}
declare type ServiceFileTypes = {
[key in FILE_TYPES]?: FileServiceIO;
};
declare interface ServiceIO {
key?: string;
validateKeyProperty: boolean;
insertKeyPlaceholderText?: string;
keyHelpUrl?: string;
url?: string;
websocket?: WebSocket | 'pending' | IWebsocketHandler;
completionsHandlers: CompletionsHandlers;
streamHandlers: StreamHandlers;
isTextInputDisabled?: boolean;
textInputPlaceholderText?: string;
fileTypes: ServiceFileTypes;
camera?: CameraFilesServiceConfig;
recordAudio?: MicrophoneFilesServiceConfig;
connectSettings: Connect;
introPanelMarkUp?: string;
permittedErrorPrefixes?: CustomErrors;
canSendMessage: (text?: string, files?: File[], isProgrammatic?: boolean) => boolean;
verifyKey(key: string, keyVerificationHandlers: KeyVerificationHandlers): void;
callAPI(requestContents: RequestContents, messages: Messages_2): Promise<void>;
extractResultData?(result: object, fetch?: FetchFunc, previousBody?: object): Promise<InterfacesUnion<Response_2 | {
makingAnotherRequest: true;
}>>;
extractPollResultData?(result: object): PollResult;
demo?: Demo;
stream?: Stream;
deepChat: DeepChat;
isDirectConnection(): boolean;
isWebModel(): boolean;
isSubmitProgrammaticallyDisabled?: boolean;
sessionId?: string;
fetchHistory?: () => Promise<Response_2[]> | Response_2[];
asyncCallInProgress?: boolean;
}
export declare const setCart: () => React_2.Dispatch<CartAction>;
declare interface Signals {
onResponse: (response: Response_2) => void;
onOpen: () => void;
onClose: () => void;
stopClicked: {
listener: () => void;
};
newUserMessage: {
listener: (body: any) => void;
};
}
declare interface SpeechEvents {
onStart?: () => void;
onStop?: () => void;
onResult?: (text: string, isFinal: boolean) => void;
onPreResult?: (text: string, isFinal: boolean) => void;
onCommandModeTrigger?: (isStart: boolean) => void;
onPauseTrigger?: (isStart: boolean) => void;
}
declare type SpeechToTextConfig = {
webSpeech?: true | WebSpeechOptions;
azure?: AzureOptions;
displayInterimResults?: boolean;
textColor?: TextColor;
translations?: Translations;
commands?: Commands & {
submit?: string;
};
stopAfterSubmit?: false;
submitAfterSilence?: SubmitAfterSilence;
button?: {
commandMode?: ButtonStyles;
} & MicrophoneStyles;
events?: SpeechEvents;
};
declare interface StabilityAI {
textToImage?: true | StabilityAITextToImage;
imageToImage?: true | StabilityAIImageToImage;
imageToImageMasking?: true | StabilityAIImageToImageMasking;
imageToImageUpscale?: true | StabilityAIImageToImageUpscale;
}
declare interface StabilityAICommon {
engine_id?: string;
weight?: number;
cfg_scale?: number;
clip_guidance_preset?: 'FAST_BLUE' | 'FAST_GREEN' | 'NONE' | 'SIMPLE' | 'SLOW' | 'SLOWER' | 'SLOWEST';
samples?: number;
seed?: number;
steps?: number;
style_preset?: '3d-model' | 'analog-film' | 'anime' | 'cinematic' | 'comic-book' | 'digital-art' | 'enhance' | 'fantasy-art' | 'isometric' | 'line-art' | 'low-poly' | 'modeling-compound' | 'neon-punk' | 'origami' | 'photographic' | 'pixel-art' | 'tile-texture';
sampler?: 'DDIM' | 'DDPM' | 'K_DPMPP_2M' | 'K_DPMPP_2S_ANCESTRAL' | 'K_DPM_2' | 'K_DPM_2_ANCESTRAL' | 'K_EULER' | 'K_EULER_ANCESTRAL' | 'K_HEUN' | 'K_LMS';
}
declare type StabilityAIImageToImage = {
init_image_mode?: 'image_strength' | 'step_schedule_*';
image_strength?: number;
step_schedule_start: number;
step_schedule_end: number;
} & StabilityAICommon;
declare type StabilityAIImageToImageMasking = {
mask_source?: 'MASK_IMAGE_WHITE' | 'MASK_IMAGE_BLACK' | 'INIT_IMAGE_ALPHA';
} & StabilityAICommon;
declare interface StabilityAIImageToImageUpscale {
engine_id?: string;
height?: number;
width?: number;
}
declare type StabilityAITextToImage = {
height?: number;
width?: number;
} & StabilityAICommon;
declare interface StatefulStyles {
default?: CustomStyle;
hover?: CustomStyle;
click?: CustomStyle;
}
declare type Stream = boolean | StreamSimulation;
declare interface StreamHandlers {
onOpen: () => void;
onClose: () => void;
abortStream: AbortController;
stopClicked: Signals['stopClicked'];
simulationInterim?: number;
}
declare interface StreamSimulation {
simulation?: boolean | number | string;
}
declare type SubmitAfterSilence = true | number;
declare interface SubmitButtonStyles {
submit?: ButtonStyles;
loading?: ButtonStyles;
stop?: ButtonStyles;
disabled?: ButtonStyles;
position?: 'inside-left' | 'inside-right' | 'outside-left' | 'outside-right';
alwaysEnabled?: boolean;
}
declare interface TextInput {
styles?: TextInputStyles;
characterLimit?: number;
placeholder?: Placeholder;
disabled?: boolean;
}
declare interface TextInputStyles {
text?: CustomStyle;
container?: CustomStyle;
focus?: CustomStyle;
}
declare interface TextToSpeechConfig {
lang?: string;
pitch?: number;
rate?: number;
voiceName?: string;
volume?: number;
}
declare type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
export declare const useCart: () => {
cart: Map<string, IsarTechProduct.Product>;
};
export declare const useCartApi: () => {
incrementWithHook: (product: IsarTechProduct.Product) => Promise<boolean>;
decrementWithHook: (product: IsarTechProduct.Product) => Promise<boolean>;
incrementBulkWithHook: (product: IsarTechProduct.Product) => Promise<boolean>;
decrementBulkWithHook: (product: IsarTechProduct.Product) => Promise<boolean>;
};
export declare const useCartEventHandlers: () => CartEventHandlers;
declare type UserContent = {
text?: string;
files?: File[] | FileList;
};
declare type UserContentI = {
text?: string;
files?: {
file: File;
type: MessageFileType;
}[];
};
declare type ValidateInput = (text?: string, files?: File[]) => boolean;
declare type ValidationHandler = (programmatic?: UserContentI) => Promise<boolean | null>;
declare type WebModel = boolean | WebModelConfig;
declare interface WebModelConfig {
model?: WebModelName;
instruction?: string;
urls?: WebModelUrls;
load?: WebModelLoad;
introMessage?: WebModelIntro;
worker?: Worker;
}
declare interface WebModelIntro {
displayed?: boolean;
initialHtml?: string;
downloadClass?: string;
uploadClass?: string;
fileInputClass?: string;
afterLoadHtml?: string;
exportFilesClass?: string;
removeAfterLoad?: boolean;
removeAfterMessage?: boolean;
autoScroll?: boolean;
}
declare interface WebModelLoad {
onInit?: boolean;
onMessage?: boolean;
clearCache?: boolean;
skipCache?: boolean;
}
declare type WebModelName = 'Llama-2-7b-chat-hf-q4f32_1' | 'Llama-2-7b-chat-hf-q4f16_1' | 'Llama-2-7b-chat-hf-q4f16_1-1k' | 'Llama-2-13b-chat-hf-q4f16_1' | 'Llama-2-70b-chat-hf-q4f16_1' | 'RedPajama-INCITE-Chat-3B-v1-q4f16_1' | 'RedPajama-INCITE-Chat-3B-v1-q4f32_1' | 'RedPajama-INCITE-Chat-3B-v1-q4f16_1-1k' | 'RedPajama-INCITE-Chat-3B-v1-q4f32_1-1k' | 'WizardMath-7B-V1.1-q4f16_1' | 'Mistral-7B-Instruct-v0.2-q4f16_1' | 'OpenHermes-2.5-Mistral-7B-q4f16_1' | 'NeuralHermes-2.5-Mistral-7B-q4f16_1' | 'TinyLlama-1.1B-Chat-v0.4-q0f16' | 'TinyLlama-1.1B-Chat-v0.4-q0f32' | 'TinyLlama-1.1B-Chat-v0.4-q4f16_1-1k' | 'TinyLlama-1.1B-Chat-v0.4-q4f32_1-1k';
declare interface WebModelUrls {
model?: string;
wasm?: string;
}
export { }