@opencx/widget 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +105 -0
- package/dist/basic.cjs +259 -0
- package/dist/basic.cjs.map +1 -0
- package/dist/basic.d.ts +2 -0
- package/dist/basic.js +40507 -0
- package/dist/basic.js.map +1 -0
- package/dist/core/client/api.d.ts +15 -0
- package/dist/core/client/client.d.ts +39 -0
- package/dist/core/client/index.d.ts +1 -0
- package/dist/core/errors/index.d.ts +21 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/managers/chathistory-manager.d.ts +61 -0
- package/dist/core/managers/session-manager.d.ts +35 -0
- package/dist/core/platform/index.d.ts +20 -0
- package/dist/core/transport/http.transport.d.ts +17 -0
- package/dist/core/transport/transport.d.ts +25 -0
- package/dist/core/types/helpers.d.ts +5 -0
- package/dist/core/types/index.d.ts +32 -0
- package/dist/core/types/messages.d.ts +43 -0
- package/dist/core/types/prelude.d.ts +14 -0
- package/dist/core/types/pub-sub.d.ts +94 -0
- package/dist/core/types/schemas.d.ts +489 -0
- package/dist/core/types/transport.d.ts +31 -0
- package/dist/core/utils/genId.d.ts +2 -0
- package/dist/core/utils/genId.test.d.ts +1 -0
- package/dist/core/utils/history-to-widget-messages.d.ts +4 -0
- package/dist/history-to-widget-messages-CP0hKjhv.js +195 -0
- package/dist/history-to-widget-messages-CP0hKjhv.js.map +1 -0
- package/dist/history-to-widget-messages-CdbZolRN.cjs +2 -0
- package/dist/history-to-widget-messages-CdbZolRN.cjs.map +1 -0
- package/dist/index-C11ivBh5.js +2604 -0
- package/dist/index-C11ivBh5.js.map +1 -0
- package/dist/index-DQmRZV3b.cjs +18 -0
- package/dist/index-DQmRZV3b.cjs.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +445 -0
- package/dist/index.js.map +1 -0
- package/dist/react-lib/Root.d.ts +6 -0
- package/dist/react-lib/hooks/handle-socket-messages.d.ts +27 -0
- package/dist/react-lib/hooks/index.d.ts +6 -0
- package/dist/react-lib/hooks/socket.d.ts +11 -0
- package/dist/react-lib/hooks/socketState.d.ts +2 -0
- package/dist/react-lib/hooks/use-sound.d.ts +13 -0
- package/dist/react-lib/hooks/use-sound.test.d.ts +1 -0
- package/dist/react-lib/hooks/use-sync-state.test.d.ts +1 -0
- package/dist/react-lib/hooks/useAbstractChat.d.ts +159 -0
- package/dist/react-lib/hooks/useAxiosInstance.d.ts +121 -0
- package/dist/react-lib/hooks/useBaseClient.d.ts +2 -0
- package/dist/react-lib/hooks/useScrollTo.d.ts +2 -0
- package/dist/react-lib/hooks/useSyncState.d.ts +4 -0
- package/dist/react-lib/hooks/useTimeoutState.d.ts +3 -0
- package/dist/react-lib/hooks/useUploadFiles.d.ts +21 -0
- package/dist/react-lib/hooks/useVote.d.ts +2 -0
- package/dist/react-lib/hooks/useWidgetContentHeight.d.ts +9 -0
- package/dist/react-lib/index.d.ts +10 -0
- package/dist/react-lib/locales/ar.locale.d.ts +2 -0
- package/dist/react-lib/locales/de.locale.d.ts +2 -0
- package/dist/react-lib/locales/en.locale.d.ts +55 -0
- package/dist/react-lib/locales/fr.locale.d.ts +2 -0
- package/dist/react-lib/locales/helper.d.ts +65 -0
- package/dist/react-lib/locales/index.d.ts +3 -0
- package/dist/react-lib/locales/nl.locale.d.ts +2 -0
- package/dist/react-lib/locales/pt.locale.d.ts +2 -0
- package/dist/react-lib/providers/ChatProvider.d.ts +135 -0
- package/dist/react-lib/providers/ClientProvider.d.ts +7 -0
- package/dist/react-lib/providers/ConfigDataProvider.d.ts +62 -0
- package/dist/react-lib/providers/ContactProvider.d.ts +58 -0
- package/dist/react-lib/providers/LocalesProvider.d.ts +11 -0
- package/dist/react-lib/providers/componentRegistry.d.ts +13 -0
- package/dist/react-lib/providers/use-widget-sfx.d.ts +7 -0
- package/dist/react-lib/providers/usePreludeData.d.ts +2 -0
- package/dist/react-lib/types/components.d.ts +10 -0
- package/dist/react-lib/types/index.d.ts +6 -0
- package/dist/react-lib/types/options.d.ts +43 -0
- package/dist/react-lib/utils/create-safe-context.d.ts +1 -0
- package/dist/react-lib/utils/debug.d.ts +2 -0
- package/dist/react-lib/utils/getters.d.ts +24 -0
- package/dist/react-lib/utils/index.d.ts +1 -0
- package/dist/react.cjs +2 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.ts +2 -0
- package/dist/react.js +41 -0
- package/dist/react.js.map +1 -0
- package/dist/src/@components/BotMessage.d.ts +9 -0
- package/dist/src/@components/BotMessageWrapper.d.ts +7 -0
- package/dist/src/@components/ChatEvent.component.d.ts +9 -0
- package/dist/src/@components/Fallback.component.d.ts +8 -0
- package/dist/src/@components/Loading.component.d.ts +2 -0
- package/dist/src/@components/OpenLogoSvg.d.ts +4 -0
- package/dist/src/@components/Text.component.d.ts +3 -0
- package/dist/src/@components/index.d.ts +6 -0
- package/dist/src/@components/markdown.d.ts +3 -0
- package/dist/src/components/MotionDiv.d.ts +18 -0
- package/dist/src/components/RenderFile.d.ts +7 -0
- package/dist/src/components/avatar.d.ts +6 -0
- package/dist/src/components/button.d.ts +11 -0
- package/dist/src/components/dialog.d.ts +276 -0
- package/dist/src/components/dropdown-menu.d.ts +27 -0
- package/dist/src/components/input.d.ts +5 -0
- package/dist/src/components/keyboard.d.ts +7 -0
- package/dist/src/components/popover.d.ts +8 -0
- package/dist/src/components/skeleton.d.ts +3 -0
- package/dist/src/components/switch.d.ts +4 -0
- package/dist/src/components/tooltip.d.ts +10 -0
- package/dist/src/components/userMessage.d.ts +8 -0
- package/dist/src/components/wobble.d.ts +15 -0
- package/dist/src/designs/basic/WidgetPopoverTrigger.d.ts +5 -0
- package/dist/src/designs/basic/index.d.ts +5 -0
- package/dist/src/designs/basic/screens/chat-screen/ChatFooter.d.ts +2 -0
- package/dist/src/designs/basic/screens/chat-screen/ChatHeader.d.ts +2 -0
- package/dist/src/designs/basic/screens/chat-screen/ChatScreen.d.ts +2 -0
- package/dist/src/designs/basic/screens/chat-screen/SessionClosedDialog.d.ts +2 -0
- package/dist/src/designs/basic/screens/root-screen.d.ts +2 -0
- package/dist/src/designs/basic/screens/welcome-screen/WelcomeScreen.d.ts +2 -0
- package/dist/src/designs/constants.d.ts +15 -0
- package/dist/src/hooks/useShouldCollectData.d.ts +3 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/render.d.ts +2 -0
- package/dist/src/utils.d.ts +2 -0
- package/dist/style.css +1 -0
- package/dist-embed/script.js +476 -0
- package/dist-embed/script.js.map +1 -0
- package/package.json +153 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ChatSessionType } from '../types/schemas';
|
|
2
|
+
import { MessageData } from '../types/transport';
|
|
3
|
+
export interface ApiCallerOptions {
|
|
4
|
+
apiUrl: string;
|
|
5
|
+
token: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class ApiCaller {
|
|
8
|
+
private readonly options;
|
|
9
|
+
constructor(options: ApiCallerOptions);
|
|
10
|
+
createSession(): Promise<ChatSessionType>;
|
|
11
|
+
fetchSession(sessionId: string): Promise<ChatSessionType>;
|
|
12
|
+
ping(): Promise<void>;
|
|
13
|
+
getMessages(sessionId?: string): Promise<MessageData[]>;
|
|
14
|
+
sendMessage(message: MessageData): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { CoreOptions } from '../types';
|
|
2
|
+
import { Subscribable } from '../types/pub-sub';
|
|
3
|
+
import { Platform } from '../platform';
|
|
4
|
+
import { MessagingTransport } from '../transport/transport';
|
|
5
|
+
import { MessageType, SendMessageInput } from '../types/messages';
|
|
6
|
+
export declare class ApiClient extends Subscribable {
|
|
7
|
+
private readonly platform;
|
|
8
|
+
private messagingTransport;
|
|
9
|
+
private readonly options;
|
|
10
|
+
private readonly api;
|
|
11
|
+
private readonly session;
|
|
12
|
+
private readonly events;
|
|
13
|
+
private messages;
|
|
14
|
+
private keyboard;
|
|
15
|
+
private pollingInterval?;
|
|
16
|
+
private heartbeatInterval?;
|
|
17
|
+
constructor(options: CoreOptions, platform?: Platform);
|
|
18
|
+
private startMessagePolling;
|
|
19
|
+
private startHeartbeat;
|
|
20
|
+
private appendMessages;
|
|
21
|
+
private handleIncomingMessage;
|
|
22
|
+
private refreshSession;
|
|
23
|
+
private initializeTransport;
|
|
24
|
+
sendMessage({ content, user, ...data }: SendMessageInput): Promise<void>;
|
|
25
|
+
setKeyboard(options: string[] | null): void;
|
|
26
|
+
handleKeyboardOption(option: string): void;
|
|
27
|
+
getMessages(): readonly MessageType[];
|
|
28
|
+
clearChat(): void;
|
|
29
|
+
connect(): Promise<void>;
|
|
30
|
+
disconnect(): Promise<void>;
|
|
31
|
+
setTransport(transport: MessagingTransport): void;
|
|
32
|
+
get state(): {
|
|
33
|
+
connected: boolean;
|
|
34
|
+
session: import('../managers/session-manager').ChatSessionWithStatus | null;
|
|
35
|
+
messages: MessageType[];
|
|
36
|
+
keyboard: string[] | null;
|
|
37
|
+
};
|
|
38
|
+
protected cleanup(): void;
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './client';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare class OpenCopilotError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class ConnectionError extends OpenCopilotError {
|
|
5
|
+
constructor(message?: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class AuthenticationError extends OpenCopilotError {
|
|
8
|
+
constructor(message?: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class SessionError extends OpenCopilotError {
|
|
11
|
+
constructor(message?: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class SessionNotDefinedError extends SessionError {
|
|
14
|
+
constructor(message?: string);
|
|
15
|
+
}
|
|
16
|
+
export declare class TransportError extends OpenCopilotError {
|
|
17
|
+
constructor(message?: string);
|
|
18
|
+
}
|
|
19
|
+
export declare class FileUploadError extends OpenCopilotError {
|
|
20
|
+
constructor(message?: string);
|
|
21
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ChatHistoryMessageType, MessageType, UserMessageType } from '../types';
|
|
2
|
+
import { EventMap, PubSub } from '../types/pub-sub';
|
|
3
|
+
/**
|
|
4
|
+
* Events emitted by the ChatHistoryManager
|
|
5
|
+
*/
|
|
6
|
+
export interface ChatHistoryEvents extends EventMap {
|
|
7
|
+
"history:message:added": MessageType;
|
|
8
|
+
"history:message:updated": MessageType;
|
|
9
|
+
"history:updated": MessageType[];
|
|
10
|
+
"history:cleared": void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Manages chat history and message operations.
|
|
14
|
+
* Uses a strongly typed event system for history-related events.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const history = new ChatHistoryManager();
|
|
19
|
+
*
|
|
20
|
+
* // Subscribe to events
|
|
21
|
+
* history.on('history:message:added', (message) => {
|
|
22
|
+
* console.log('New message:', message);
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // Add messages
|
|
26
|
+
* history.appendUserMessage({
|
|
27
|
+
* id: '123',
|
|
28
|
+
* type: 'FROM_USER',
|
|
29
|
+
* content: 'Hello'
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare class ChatHistoryManager extends PubSub<ChatHistoryEvents> {
|
|
34
|
+
private messages;
|
|
35
|
+
private lastUpdated;
|
|
36
|
+
constructor();
|
|
37
|
+
/**
|
|
38
|
+
* Subscribe to history events
|
|
39
|
+
* @param event Event name to subscribe to
|
|
40
|
+
* @param callback Callback function to handle the event
|
|
41
|
+
* @returns Unsubscribe function
|
|
42
|
+
*/
|
|
43
|
+
on<K extends keyof ChatHistoryEvents>(event: K, callback: (data: ChatHistoryEvents[K]) => void): () => void;
|
|
44
|
+
private handleNewMessage;
|
|
45
|
+
private handleHistoryUpdate;
|
|
46
|
+
private notifyHistoryUpdate;
|
|
47
|
+
addResponseMessage(message: MessageType): void;
|
|
48
|
+
appendUserMessage(message: UserMessageType): void;
|
|
49
|
+
prependHistory(historyMessages: MessageType[]): void;
|
|
50
|
+
setDeliveredAt(clientMessageId: string, deliveredAt: string): void;
|
|
51
|
+
setMessages(messages: MessageType[]): void;
|
|
52
|
+
appendMessages(newMessages: MessageType[]): void;
|
|
53
|
+
reset(): void;
|
|
54
|
+
getMessages(): readonly MessageType[];
|
|
55
|
+
getLastUpdated(): number | null;
|
|
56
|
+
getLastMessageTimestamp(): string | undefined;
|
|
57
|
+
isEmpty(): boolean;
|
|
58
|
+
mapHistoryMessages(historyMessages: ChatHistoryMessageType[]): MessageType[];
|
|
59
|
+
private updateTimestamp;
|
|
60
|
+
protected cleanup(): void;
|
|
61
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { EventMap, PubSub } from '../types/pub-sub';
|
|
2
|
+
import { ChatSessionType } from '../types/schemas';
|
|
3
|
+
import { ApiCaller } from '../client/api';
|
|
4
|
+
export type ChatSessionWithStatus = ChatSessionType & {
|
|
5
|
+
isSessionClosed: boolean;
|
|
6
|
+
isAssignedToAi: boolean;
|
|
7
|
+
isAssignedToHuman: boolean;
|
|
8
|
+
isPendingHuman: boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Events emitted by the SessionManager
|
|
12
|
+
*/
|
|
13
|
+
interface SessionEvents extends EventMap {
|
|
14
|
+
"session:updated": ChatSessionType;
|
|
15
|
+
"session:created": ChatSessionType;
|
|
16
|
+
"session:closed": {
|
|
17
|
+
sessionId: string;
|
|
18
|
+
};
|
|
19
|
+
"session:error": {
|
|
20
|
+
error: Error;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export declare class SessionManager extends PubSub<SessionEvents> {
|
|
24
|
+
#private;
|
|
25
|
+
private readonly httpClient;
|
|
26
|
+
constructor(httpClient: ApiCaller, initialSession?: ChatSessionType);
|
|
27
|
+
get currentSession(): ChatSessionWithStatus | null;
|
|
28
|
+
setSession(session: ChatSessionType): void;
|
|
29
|
+
clearSession: () => void;
|
|
30
|
+
createSession(): Promise<ChatSessionType>;
|
|
31
|
+
getOrCreateSession(): Promise<ChatSessionType>;
|
|
32
|
+
refreshSession(sessionId: string): Promise<ChatSessionType | null>;
|
|
33
|
+
protected cleanup(): void;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface Platform {
|
|
2
|
+
storage?: Storage;
|
|
3
|
+
env: {
|
|
4
|
+
platform: string;
|
|
5
|
+
};
|
|
6
|
+
date: {
|
|
7
|
+
now(): number;
|
|
8
|
+
toISOString(date: number): string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export declare class DefaultPlatform implements Platform {
|
|
12
|
+
env: {
|
|
13
|
+
platform: string;
|
|
14
|
+
};
|
|
15
|
+
date: {
|
|
16
|
+
now: () => number;
|
|
17
|
+
toISOString: (date: number) => string;
|
|
18
|
+
};
|
|
19
|
+
private detectPlatform;
|
|
20
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Platform } from '../platform';
|
|
2
|
+
import { MessageData, TransportOptions } from '../types/transport';
|
|
3
|
+
import { MessagingTransport } from './transport';
|
|
4
|
+
interface HttpTransportOptions extends TransportOptions {
|
|
5
|
+
pollingInterval: number;
|
|
6
|
+
}
|
|
7
|
+
export declare class HttpTransport extends MessagingTransport {
|
|
8
|
+
private readonly httpOptions;
|
|
9
|
+
private readonly platform;
|
|
10
|
+
private pollingInterval?;
|
|
11
|
+
constructor(httpOptions: HttpTransportOptions, platform?: Platform);
|
|
12
|
+
connect(): Promise<void>;
|
|
13
|
+
disconnect(): void;
|
|
14
|
+
sendMessage(message: MessageData): Promise<void>;
|
|
15
|
+
private startPolling;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { MessageData, TransportOptions } from '../types/transport';
|
|
2
|
+
import { PubSub } from '../types/pub-sub';
|
|
3
|
+
export interface TransportEvents extends Record<string, any> {
|
|
4
|
+
"transport:message:received": MessageData;
|
|
5
|
+
"transport:error": {
|
|
6
|
+
error: Error;
|
|
7
|
+
};
|
|
8
|
+
"transport:status": {
|
|
9
|
+
status: "connected" | "disconnected";
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export interface TransportState {
|
|
13
|
+
connected: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare abstract class MessagingTransport extends PubSub<TransportEvents> {
|
|
16
|
+
#private;
|
|
17
|
+
protected readonly options: TransportOptions;
|
|
18
|
+
constructor(options: TransportOptions);
|
|
19
|
+
abstract connect(): Promise<void>;
|
|
20
|
+
abstract disconnect(): void;
|
|
21
|
+
abstract sendMessage(message: MessageData): Promise<void>;
|
|
22
|
+
protected setState(newState: Partial<TransportState>): void;
|
|
23
|
+
isConnected(): boolean;
|
|
24
|
+
getState(): TransportState;
|
|
25
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type PromiseType<P extends Promise<unknown>> = P extends Promise<infer T> ? T : never;
|
|
2
|
+
export type FunctionReturningPromise = (...args: any[]) => Promise<any>;
|
|
3
|
+
export type MakeKeysNotNullable<T, K extends keyof T> = Omit<T, K> & {
|
|
4
|
+
[P in K]-?: NonNullable<T[P]>;
|
|
5
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export * from './messages';
|
|
2
|
+
export * from './schemas';
|
|
3
|
+
export * from './pub-sub';
|
|
4
|
+
export * from './transport';
|
|
5
|
+
export * from './helpers';
|
|
6
|
+
export interface User {
|
|
7
|
+
external_id?: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
email?: string;
|
|
10
|
+
phone?: string;
|
|
11
|
+
customData?: Record<string, string>;
|
|
12
|
+
avatarUrl?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface CoreOptions {
|
|
15
|
+
token: string;
|
|
16
|
+
apiUrl?: string;
|
|
17
|
+
transport?: "socket" | "http";
|
|
18
|
+
socketUrl?: string;
|
|
19
|
+
headers?: Record<string, string>;
|
|
20
|
+
queryParams?: Record<string, string>;
|
|
21
|
+
pathParams?: Record<string, string>;
|
|
22
|
+
debug?: boolean;
|
|
23
|
+
language?: string;
|
|
24
|
+
user?: User;
|
|
25
|
+
bot?: {
|
|
26
|
+
name?: string;
|
|
27
|
+
avatarUrl?: string;
|
|
28
|
+
id?: number | null;
|
|
29
|
+
is_ai?: boolean;
|
|
30
|
+
};
|
|
31
|
+
pollingInterval?: number;
|
|
32
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AgentType, ChatAttachmentType, ChatHistoryMessageType } from './schemas';
|
|
2
|
+
export type UserMessageType = {
|
|
3
|
+
id: string;
|
|
4
|
+
type: "FROM_USER";
|
|
5
|
+
content: string;
|
|
6
|
+
deliveredAt: string | null;
|
|
7
|
+
attachments?: ChatAttachmentType[];
|
|
8
|
+
timestamp?: string;
|
|
9
|
+
user?: {
|
|
10
|
+
name?: string;
|
|
11
|
+
email?: string;
|
|
12
|
+
phone?: string;
|
|
13
|
+
customData?: Record<string, string>;
|
|
14
|
+
avatarUrl?: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export type BotMessageType<TData = unknown> = {
|
|
18
|
+
id: string;
|
|
19
|
+
type: "FROM_BOT";
|
|
20
|
+
component: string;
|
|
21
|
+
data: TData;
|
|
22
|
+
timestamp?: string;
|
|
23
|
+
original?: ChatHistoryMessageType;
|
|
24
|
+
agent?: AgentType;
|
|
25
|
+
attachments?: ChatAttachmentType[];
|
|
26
|
+
};
|
|
27
|
+
export type MessageType = UserMessageType | BotMessageType;
|
|
28
|
+
export interface SendMessageInput {
|
|
29
|
+
content: {
|
|
30
|
+
text: string;
|
|
31
|
+
};
|
|
32
|
+
attachments?: ChatAttachmentType[];
|
|
33
|
+
id?: string;
|
|
34
|
+
language?: string;
|
|
35
|
+
user?: {
|
|
36
|
+
external_id?: string;
|
|
37
|
+
name?: string;
|
|
38
|
+
email?: string;
|
|
39
|
+
phone?: string;
|
|
40
|
+
customData?: Record<string, string>;
|
|
41
|
+
avatarUrl?: string;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface PreludeData {
|
|
2
|
+
initial_questions?: string[];
|
|
3
|
+
organization_name?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface WorkingHours {
|
|
6
|
+
timezone: string;
|
|
7
|
+
weekdays: {
|
|
8
|
+
[key: string]: {
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
start: string;
|
|
11
|
+
end: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base interface for event maps. All event maps must extend this.
|
|
3
|
+
* @example
|
|
4
|
+
* ```typescript
|
|
5
|
+
* interface MyEvents extends EventMap {
|
|
6
|
+
* "my:event": string
|
|
7
|
+
* "my:other:event": { data: number }
|
|
8
|
+
* }
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export interface EventMap {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Event subscriber function type
|
|
16
|
+
*/
|
|
17
|
+
export type Subscriber<T> = (data: T) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Generic PubSub class that can be typed with specific event maps.
|
|
20
|
+
* Each component should create its own instance with its specific events.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* interface MyEvents extends EventMap {
|
|
25
|
+
* "my:event": string
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* const pubSub = new PubSub<MyEvents>();
|
|
29
|
+
*
|
|
30
|
+
* pubSub.subscribe("my:event", (data) => {
|
|
31
|
+
* console.log(data.toUpperCase()); // Type-safe: data is string
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare class PubSub<T extends EventMap> {
|
|
36
|
+
private subscribers;
|
|
37
|
+
/**
|
|
38
|
+
* Subscribe to an event
|
|
39
|
+
* @param event Event name to subscribe to
|
|
40
|
+
* @param callback Function to call when event is published
|
|
41
|
+
* @returns Unsubscribe function
|
|
42
|
+
*/
|
|
43
|
+
subscribe<K extends keyof T>(event: K, callback: Subscriber<T[K]>): () => void;
|
|
44
|
+
/**
|
|
45
|
+
* Publish an event with data
|
|
46
|
+
* @param event Event name to publish
|
|
47
|
+
* @param data Data to send with the event
|
|
48
|
+
*/
|
|
49
|
+
publish<K extends keyof T>(event: K, data: T[K]): void;
|
|
50
|
+
/**
|
|
51
|
+
* Clear all subscriptions
|
|
52
|
+
*/
|
|
53
|
+
clear(): void;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Abstract base class for components that need subscription management.
|
|
57
|
+
* Provides common functionality for managing subscriptions and cleanup.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* class MyComponent extends Subscribable {
|
|
62
|
+
* constructor() {
|
|
63
|
+
* super();
|
|
64
|
+
* // Add unsubscribers
|
|
65
|
+
* this.addUnsubscriber(() => {
|
|
66
|
+
* console.log('Cleanup');
|
|
67
|
+
* });
|
|
68
|
+
* }
|
|
69
|
+
*
|
|
70
|
+
* protected cleanup(): void {
|
|
71
|
+
* // Component-specific cleanup
|
|
72
|
+
* }
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare abstract class Subscribable {
|
|
77
|
+
protected unsubscribers: (() => void)[];
|
|
78
|
+
/**
|
|
79
|
+
* Add an unsubscribe function to be called during cleanup
|
|
80
|
+
*/
|
|
81
|
+
protected addUnsubscriber(unsubscribe: () => void): void;
|
|
82
|
+
/**
|
|
83
|
+
* Dispose of all subscriptions and perform cleanup
|
|
84
|
+
*/
|
|
85
|
+
dispose(): void;
|
|
86
|
+
/**
|
|
87
|
+
* Component-specific cleanup logic
|
|
88
|
+
*/
|
|
89
|
+
protected abstract cleanup(): void;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Helper function to create a strongly typed PubSub instance
|
|
93
|
+
*/
|
|
94
|
+
export declare function createPubSub<T extends EventMap>(): PubSub<T>;
|