@theonexai/chartsconnect-chat-widget 1.0.18
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 +270 -0
- package/dist/ChatWidget-Bs0XV_7i.js +1356 -0
- package/dist/ChatWidget-Bs0XV_7i.js.map +1 -0
- package/dist/ChatWidget-PcqRrOmi.cjs +2 -0
- package/dist/ChatWidget-PcqRrOmi.cjs.map +1 -0
- package/dist/adapters/vue/index.d.ts +7 -0
- package/dist/adapters/vue/index.d.ts.map +1 -0
- package/dist/adapters/vue/useChatMode.d.ts +21 -0
- package/dist/adapters/vue/useChatMode.d.ts.map +1 -0
- package/dist/components/ChatWidget.d.ts +39 -0
- package/dist/components/ChatWidget.d.ts.map +1 -0
- package/dist/composables/useChatWidget.d.ts +35 -0
- package/dist/composables/useChatWidget.d.ts.map +1 -0
- package/dist/core/stateManager.d.ts +136 -0
- package/dist/core/stateManager.d.ts.map +1 -0
- package/dist/core/types.d.ts +64 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/entry/next.d.ts +9 -0
- package/dist/entry/next.d.ts.map +1 -0
- package/dist/entry/nuxt.d.ts +12 -0
- package/dist/entry/nuxt.d.ts.map +1 -0
- package/dist/entry/react.d.ts +10 -0
- package/dist/entry/react.d.ts.map +1 -0
- package/dist/entry/vanilla.d.ts +33 -0
- package/dist/entry/vanilla.d.ts.map +1 -0
- package/dist/entry/vite.d.ts +11 -0
- package/dist/entry/vite.d.ts.map +1 -0
- package/dist/entry/vue.d.ts +12 -0
- package/dist/entry/vue.d.ts.map +1 -0
- package/dist/hooks/useChatMode.d.ts +17 -0
- package/dist/hooks/useChatMode.d.ts.map +1 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +1383 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/nuxt.cjs.js +2 -0
- package/dist/nuxt.cjs.js.map +1 -0
- package/dist/nuxt.esm.js +9 -0
- package/dist/nuxt.esm.js.map +1 -0
- package/dist/sanitize-C8MB41vY.cjs +4 -0
- package/dist/sanitize-C8MB41vY.cjs.map +1 -0
- package/dist/sanitize-Cm1kskSD.js +1842 -0
- package/dist/sanitize-Cm1kskSD.js.map +1 -0
- package/dist/services/chatService.d.ts +144 -0
- package/dist/services/chatService.d.ts.map +1 -0
- package/dist/services/dialogflowBackendService.d.ts +36 -0
- package/dist/services/dialogflowBackendService.d.ts.map +1 -0
- package/dist/services/dialogflowClient.d.ts +36 -0
- package/dist/services/dialogflowClient.d.ts.map +1 -0
- package/dist/services/sessionManager.d.ts +13 -0
- package/dist/services/sessionManager.d.ts.map +1 -0
- package/dist/styles.css +1 -0
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/dialogflowHandler.d.ts +31 -0
- package/dist/utils/dialogflowHandler.d.ts.map +1 -0
- package/dist/utils/frameworkDetector.d.ts +17 -0
- package/dist/utils/frameworkDetector.d.ts.map +1 -0
- package/dist/utils/sanitize.d.ts +25 -0
- package/dist/utils/sanitize.d.ts.map +1 -0
- package/dist/utils/ssr.d.ts +35 -0
- package/dist/utils/ssr.d.ts.map +1 -0
- package/dist/vue.cjs.js +2 -0
- package/dist/vue.cjs.js.map +1 -0
- package/dist/vue.esm.js +9 -0
- package/dist/vue.esm.js.map +1 -0
- package/package.json +114 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChatWidget.d.ts","sourceRoot":"","sources":["../../src/composables/useChatWidget.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAA+C,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5E,MAAM,WAAW,mBAAmB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@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State Manager - Framework Agnostic
|
|
3
|
+
* Manages widget state independently of framework
|
|
4
|
+
*/
|
|
5
|
+
import type { WidgetState, WidgetConfig } from './types';
|
|
6
|
+
export declare class WidgetStateManager {
|
|
7
|
+
private state;
|
|
8
|
+
private config;
|
|
9
|
+
private listeners;
|
|
10
|
+
private chatMode;
|
|
11
|
+
private chatId;
|
|
12
|
+
private supportSessionId;
|
|
13
|
+
private chatService;
|
|
14
|
+
private collectingUserInfo;
|
|
15
|
+
private userInfoStep;
|
|
16
|
+
private collectedUserName;
|
|
17
|
+
private collectedUserEmail;
|
|
18
|
+
private collectedUserMobile;
|
|
19
|
+
private wsConnected;
|
|
20
|
+
private agentTyping;
|
|
21
|
+
private currentAgent;
|
|
22
|
+
private isConnectingToAgent;
|
|
23
|
+
private agentAccepted;
|
|
24
|
+
private chatResolved;
|
|
25
|
+
private historyLoaded;
|
|
26
|
+
private typingTimeout;
|
|
27
|
+
private agentTypingTimeout;
|
|
28
|
+
constructor(config: WidgetConfig);
|
|
29
|
+
/**
|
|
30
|
+
* Subscribe to state changes
|
|
31
|
+
*/
|
|
32
|
+
subscribe(listener: (state: WidgetState) => void): () => void;
|
|
33
|
+
/**
|
|
34
|
+
* Get current state
|
|
35
|
+
*/
|
|
36
|
+
getState(): WidgetState;
|
|
37
|
+
/**
|
|
38
|
+
* Update state and notify listeners
|
|
39
|
+
*/
|
|
40
|
+
private setState;
|
|
41
|
+
/**
|
|
42
|
+
* Update configuration
|
|
43
|
+
*/
|
|
44
|
+
updateConfig(config: Partial<WidgetConfig>): void;
|
|
45
|
+
/**
|
|
46
|
+
* Open chat
|
|
47
|
+
*/
|
|
48
|
+
openChat(): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Close chat
|
|
51
|
+
*/
|
|
52
|
+
closeChat(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Close welcome popup
|
|
55
|
+
*/
|
|
56
|
+
closeWelcomePopup(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Toggle chat
|
|
59
|
+
*/
|
|
60
|
+
toggleChat(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Set input value
|
|
63
|
+
*/
|
|
64
|
+
setInputValue(value: string): void;
|
|
65
|
+
/**
|
|
66
|
+
* Clear error
|
|
67
|
+
*/
|
|
68
|
+
clearError(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Send message
|
|
71
|
+
*/
|
|
72
|
+
sendMessage(text: string, skipUserMessage?: boolean): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Send message to Dialogflow
|
|
75
|
+
*/
|
|
76
|
+
private sendAIMessage;
|
|
77
|
+
/**
|
|
78
|
+
* Send message to human support
|
|
79
|
+
*/
|
|
80
|
+
private sendHumanMessage;
|
|
81
|
+
/**
|
|
82
|
+
* Switch to human mode
|
|
83
|
+
*/
|
|
84
|
+
switchToHumanMode(): void;
|
|
85
|
+
/**
|
|
86
|
+
* Switch to AI mode
|
|
87
|
+
*/
|
|
88
|
+
switchToBotMode(): void;
|
|
89
|
+
/**
|
|
90
|
+
* Initialize welcome popup
|
|
91
|
+
*/
|
|
92
|
+
initializeWelcomePopup(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Start user info collection for handoff
|
|
95
|
+
*/
|
|
96
|
+
private startUserInfoCollection;
|
|
97
|
+
/**
|
|
98
|
+
* Handle user info collection
|
|
99
|
+
*/
|
|
100
|
+
private handleUserInfoCollection;
|
|
101
|
+
/**
|
|
102
|
+
* Handle handoff from Dialogflow to human support
|
|
103
|
+
*/
|
|
104
|
+
handleHandoff(customerName?: string, customerEmail?: string, customerMobile?: string): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Handle WebSocket messages
|
|
107
|
+
*/
|
|
108
|
+
private handleWebSocketMessage;
|
|
109
|
+
/**
|
|
110
|
+
* Enter resolved state
|
|
111
|
+
*/
|
|
112
|
+
private enterResolvedState;
|
|
113
|
+
/**
|
|
114
|
+
* Load message history
|
|
115
|
+
*/
|
|
116
|
+
loadMessageHistory(preserveExisting?: boolean): Promise<void>;
|
|
117
|
+
/**
|
|
118
|
+
* Get additional state for UI (not in WidgetState but needed by components)
|
|
119
|
+
*/
|
|
120
|
+
getAdditionalState(): {
|
|
121
|
+
wsConnected: boolean;
|
|
122
|
+
agentTyping: boolean;
|
|
123
|
+
currentAgent: {
|
|
124
|
+
name: string;
|
|
125
|
+
id?: string;
|
|
126
|
+
};
|
|
127
|
+
isConnectingToAgent: boolean;
|
|
128
|
+
agentAccepted: boolean;
|
|
129
|
+
chatResolved: boolean;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Cleanup
|
|
133
|
+
*/
|
|
134
|
+
destroy(): void;
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=stateManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stateManager.d.ts","sourceRoot":"","sources":["../../src/core/stateManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAe,MAAM,SAAS,CAAC;AAYtE,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,SAAS,CAAgD;IACjE,OAAO,CAAC,QAAQ,CAAwB;IACxC,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,gBAAgB,CAAuB;IAC/C,OAAO,CAAC,WAAW,CAAqD;IAGxE,OAAO,CAAC,kBAAkB,CAAkB;IAC5C,OAAO,CAAC,YAAY,CAA4C;IAChE,OAAO,CAAC,iBAAiB,CAAc;IACvC,OAAO,CAAC,kBAAkB,CAAc;IACxC,OAAO,CAAC,mBAAmB,CAAc;IAGzC,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,YAAY,CAAoD;IACxE,OAAO,CAAC,m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AEG;IACH,OAAO,CAAC,sBAAsB;IAsI9B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAmG1B;;OAEG;IACG,kBAAkB,CAAC,gBAAgB,GAAE,OAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAqD1E;;OAEG;IACH,kBAAkB;;;;kBA/hCY,MAAM;iBAAO,MAAM;;;;;;IA0iCjD;;OAEG;IACH,OAAO,IAAI,IAAI;CAYhB"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Types - Framework Agnostic
|
|
3
|
+
* These types are used across all framework adapters
|
|
4
|
+
*/
|
|
5
|
+
export interface ChatMessage {
|
|
6
|
+
id: string;
|
|
7
|
+
text: string;
|
|
8
|
+
sender: 'user' | 'bot' | 'agent';
|
|
9
|
+
timestamp: Date;
|
|
10
|
+
richContent?: RichContentArray[];
|
|
11
|
+
}
|
|
12
|
+
export interface RichContent {
|
|
13
|
+
type?: string;
|
|
14
|
+
options?: ChipOption[];
|
|
15
|
+
}
|
|
16
|
+
export type RichContentArray = RichContent | RichContent[];
|
|
17
|
+
export interface ChipOption {
|
|
18
|
+
text: string;
|
|
19
|
+
payload: string;
|
|
20
|
+
}
|
|
21
|
+
export interface WidgetConfig {
|
|
22
|
+
dfProjectId?: string;
|
|
23
|
+
dfLocation?: string;
|
|
24
|
+
dfAgentId?: string;
|
|
25
|
+
languageCode?: string;
|
|
26
|
+
backendBaseUrl?: string;
|
|
27
|
+
backendWsUrl?: string;
|
|
28
|
+
title?: string;
|
|
29
|
+
subtitle?: string;
|
|
30
|
+
welcomeTitle?: string;
|
|
31
|
+
welcomeMessage?: string;
|
|
32
|
+
welcomeCta?: string;
|
|
33
|
+
showWelcomePopup?: boolean;
|
|
34
|
+
welcomePopupDelay?: number;
|
|
35
|
+
fallbackWelcomeMessage?: string;
|
|
36
|
+
inputPlaceholder?: string;
|
|
37
|
+
emptyStateMessage?: string;
|
|
38
|
+
debug?: boolean;
|
|
39
|
+
}
|
|
40
|
+
export interface WidgetState {
|
|
41
|
+
isOpen: boolean;
|
|
42
|
+
showWelcomePopup: boolean;
|
|
43
|
+
messages: ChatMessage[];
|
|
44
|
+
inputValue: string;
|
|
45
|
+
isLoading: boolean;
|
|
46
|
+
error: string | null;
|
|
47
|
+
sessionId: string | null;
|
|
48
|
+
chatMode: 'ai' | 'human';
|
|
49
|
+
}
|
|
50
|
+
export interface WidgetActions {
|
|
51
|
+
openChat: () => void;
|
|
52
|
+
closeChat: () => void;
|
|
53
|
+
sendMessage: (text: string) => Promise<void>;
|
|
54
|
+
toggleChat: () => void;
|
|
55
|
+
setInputValue: (value: string) => void;
|
|
56
|
+
clearError: () => void;
|
|
57
|
+
}
|
|
58
|
+
export interface FrameworkAdapter {
|
|
59
|
+
createComponent: (config: WidgetConfig) => any;
|
|
60
|
+
mount: (element: HTMLElement, component: any, config: WidgetConfig) => void;
|
|
61
|
+
unmount: (element: HTMLElement) => void;
|
|
62
|
+
updateProps: (component: any, config: WidgetConfig) => void;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,OAAO,CAAC;IACjC,SAAS,EAAE,IAAI,CAAC;IAChB,WAAW,CAAC,EAAE,gBAAgB,EAAE,CAAC;CAClC;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC;CACxB;AAED,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,WAAW,EAAE,CAAC;AAE3D,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC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IACvB,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,eAAe,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,GAAG,CAAC;IAC/C,KAAK,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,KAAK,IAAI,CAAC;IAC5E,OAAO,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;IACxC,WAAW,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,KAAK,IAAI,CAAC;CAC7D"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next.js Entry Point
|
|
3
|
+
* Optimized for Next.js with SSR support
|
|
4
|
+
*/
|
|
5
|
+
export { default as ChatWidget } from '../components/ChatWidget';
|
|
6
|
+
export type { ChatWidgetProps } from '../components/ChatWidget';
|
|
7
|
+
export * from '../types';
|
|
8
|
+
export declare const getServerSideProps: () => {};
|
|
9
|
+
//# sourceMappingURL=next.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../../src/entry/next.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACjE,YAAY,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,cAAc,UAAU,CAAC;AAGzB,eAAO,MAAM,kBAAkB,UAG9B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nuxt 3 Entry Point
|
|
3
|
+
* SSR-optimized entry point for Nuxt 3
|
|
4
|
+
*/
|
|
5
|
+
import ChatWidgetComponent from '../components/ChatWidget.vue';
|
|
6
|
+
export default ChatWidgetComponent;
|
|
7
|
+
export { ChatWidgetComponent as ChatWidget };
|
|
8
|
+
export { useChatWidget } from '../composables/useChatWidget';
|
|
9
|
+
export type { UseChatWidgetReturn } from '../composables/useChatWidget';
|
|
10
|
+
export type { WidgetConfig, WidgetState, ChatMessage, RichContent, ChipOption, } from '../core/types';
|
|
11
|
+
export { WidgetStateManager } from '../core/stateManager';
|
|
12
|
+
//# sourceMappingURL=nuxt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nuxt.d.ts","sourceRoot":"","sources":["../../src/entry/nuxt.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,mBAAmB,MAAM,8BAA8B,CAAC;AAG/D,eAAe,mBAAmB,CAAC;AACnC,OAAO,EAAE,mBAAmB,IAAI,UAAU,EAAE,CAAC;AAG7C,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,YAAY,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAGxE,YAAY,EACV,YAAY,EACZ,WAAW,EACX,WAAW,EACX,WAAW,EACX,UAAU,GACX,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Entry Point
|
|
3
|
+
* Explicit React entry point for React and Next.js applications
|
|
4
|
+
*
|
|
5
|
+
* Uses the original full-featured ChatWidget component (not the adapter)
|
|
6
|
+
*/
|
|
7
|
+
export { default as ChatWidget } from '../components/ChatWidget';
|
|
8
|
+
export type { ChatWidgetProps } from '../components/ChatWidget';
|
|
9
|
+
export * from '../types';
|
|
10
|
+
//# sourceMappingURL=react.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/entry/react.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACjE,YAAY,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vanilla JavaScript Entry Point
|
|
3
|
+
* Uses the original ChatWidget.tsx component via ReactDOM
|
|
4
|
+
* Reuses the same component to reduce code duplication
|
|
5
|
+
*/
|
|
6
|
+
import type { ChatWidgetProps } from '../components/ChatWidget';
|
|
7
|
+
import '../styles/chatWidget.css';
|
|
8
|
+
/**
|
|
9
|
+
* Vanilla JS Chat Widget
|
|
10
|
+
* Renders the original React component using ReactDOM
|
|
11
|
+
* This reuses the same component code, reducing duplication
|
|
12
|
+
*/
|
|
13
|
+
export declare class ChatWidget {
|
|
14
|
+
private container;
|
|
15
|
+
private config;
|
|
16
|
+
private root;
|
|
17
|
+
constructor(container: HTMLElement | string, config: ChatWidgetProps);
|
|
18
|
+
private render;
|
|
19
|
+
/**
|
|
20
|
+
* Update configuration
|
|
21
|
+
*/
|
|
22
|
+
updateConfig(config: Partial<ChatWidgetProps>): void;
|
|
23
|
+
/**
|
|
24
|
+
* Destroy the widget
|
|
25
|
+
*/
|
|
26
|
+
destroy(): void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Factory function for easier usage
|
|
30
|
+
*/
|
|
31
|
+
export declare function createChatWidget(container: HTMLElement | string, config: ChatWidgetProps): ChatWidget;
|
|
32
|
+
export default ChatWidget;
|
|
33
|
+
//# sourceMappingURL=vanilla.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vanilla.d.ts","sourceRoot":"","sources":["../../src/entry/vanilla.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,0BAA0B,CAAC;AAElC;;;;GAIG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,IAAI,CAAqB;gBAErB,SAAS,EAAE,WAAW,GAAG,MAAM,EAAE,MAAM,EAAE,eAAe;IAoBpE,OAAO,CAAC,MAAM;IAQd;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,IAAI;IAKpD;;OAEG;IACH,OAAO,IAAI,IAAI;CAMhB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,WAAW,GAAG,MAAM,EAC/B,MAAM,EAAE,eAAe,GACtB,UAAU,CAEZ;AAED,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vite Entry Point
|
|
3
|
+
* Optimized for Vite-based applications
|
|
4
|
+
*
|
|
5
|
+
* Uses the original full-featured ChatWidget component
|
|
6
|
+
* For Vue.js, use @chartsconnect/chat-widget/vue
|
|
7
|
+
*/
|
|
8
|
+
export { default as ChatWidget } from '../components/ChatWidget';
|
|
9
|
+
export type { ChatWidgetProps } from '../components/ChatWidget';
|
|
10
|
+
export * from '../types';
|
|
11
|
+
//# sourceMappingURL=vite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../src/entry/vite.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACjE,YAAY,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue Entry Point
|
|
3
|
+
* Optimized for Vue 3.x applications
|
|
4
|
+
*/
|
|
5
|
+
import ChatWidgetComponent from '../components/ChatWidget.vue';
|
|
6
|
+
export default ChatWidgetComponent;
|
|
7
|
+
export { ChatWidgetComponent as ChatWidget };
|
|
8
|
+
export { useChatWidget } from '../composables/useChatWidget';
|
|
9
|
+
export type { UseChatWidgetReturn } from '../composables/useChatWidget';
|
|
10
|
+
export type { WidgetConfig, WidgetState, ChatMessage, RichContent, ChipOption, } from '../core/types';
|
|
11
|
+
export { WidgetStateManager } from '../core/stateManager';
|
|
12
|
+
//# sourceMappingURL=vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue.d.ts","sourceRoot":"","sources":["../../src/entry/vue.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,mBAAmB,MAAM,8BAA8B,CAAC;AAG/D,eAAe,mBAAmB,CAAC;AACnC,OAAO,EAAE,mBAAmB,IAAI,UAAU,EAAE,CAAC;AAG7C,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,YAAY,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAGxE,YAAY,EACV,YAAY,EACZ,WAAW,EACX,WAAW,EACX,WAAW,EACX,UAAU,GACX,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ChatResponse } from "../services/dialogflowBackendService";
|
|
2
|
+
export type ChatMode = "BOT" | "HUMAN";
|
|
3
|
+
export interface UseChatModeReturn {
|
|
4
|
+
currentMode: ChatMode;
|
|
5
|
+
switchToHumanMode: () => void;
|
|
6
|
+
switchToBotMode: () => void;
|
|
7
|
+
isHandoffTriggered: (dialogflowResponse: ChatResponse) => boolean;
|
|
8
|
+
chatId: string | null;
|
|
9
|
+
sessionId: string | null;
|
|
10
|
+
setChatId: (id: string | null) => void;
|
|
11
|
+
setSessionId: (id: string | null) => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Hook to manage chat mode (BOT or HUMAN)
|
|
15
|
+
*/
|
|
16
|
+
export declare function useChatMode(): UseChatModeReturn;
|
|
17
|
+
//# sourceMappingURL=useChatMode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChatMode.d.ts","sourceRoot":"","sources":["../../src/hooks/useChatMode.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAEzE,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,OAAO,CAAC;AAMvC,MAAM,WAAW,iBAAiB;IAChC,WAAW,EAAE,QAAQ,CAAC;IACtB,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAC9B,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,kBAAkB,EAAE,CAAC,kBAAkB,EAAE,YAAY,KAAK,OAAO,CAAC;IAClE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IACvC,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;CAC3C;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,iBAAiB,CAmF/C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),t=require("react"),n=require("./sanitize-C8MB41vY.cjs"),s=require("react-dom");var a="undefined"!=typeof document?document.currentScript:null;const o="chartsconnectect_chat_mode",r="chartsconnect_chat_id",i="chartsconnect_session_id";function c({title:s="💬 Charts Connect AI Assistant",subtitle:a="We're here to help",welcomeTitle:c="👋 Welcome to Charts Connect",welcomeMessage:l="My name is Charts Connect AI Assistant and I'll guide you.",welcomeCta:d="💬 Click here to start chatting!",showWelcomePopup:u=!0,welcomePopupDelay:m=1500,fallbackWelcomeMessage:h="Hello! I'm Charts Connect AI Assistant. How can I help you today?",inputPlaceholder:g="Type your message...",emptyStateMessage:p="Hi! I'm Charts Connect AI Assistant. How can I help you today?",debug:f=!1,dfProjectId:w,dfLocation:x="us-central1",dfAgentId:y,languageCode:_="en",backendBaseUrl:v,backendWsUrl:S}){const[b,D]=t.useState(!1),[C,j]=t.useState(!1),[N,T]=t.useState([]),[k,I]=t.useState(""),[E,A]=t.useState(!1),[R,O]=t.useState(null),[$,M]=t.useState(!1),[P,U]=t.useState(!1),[L,H]=t.useState(!1),[V,B]=t.useState(!1),[W,F]=t.useState({name:"Agent"}),[q,z]=t.useState(!1),[K,G]=t.useState(!1),[X,Y]=t.useState(!1),[J,Q]=t.useState(!1),[Z,ee]=t.useState(null),[te,ne]=t.useState(""),[se,ae]=t.useState(""),[oe,re]=t.useState(""),ie=t.useRef(""),ce=t.useRef(null),le=t.useRef(null),de=t.useRef(null),ue=t.useRef(!1),me=t.useRef(null),he=()=>v||"undefined"!=typeof process&&process.env?.REACT_APP_BACKEND_BASE_URL,ge=t.useRef(n.createChatService({baseUrl:he(),wsUrl:S||"undefined"!=typeof process&&process.env?.REACT_APP_BACKEND_WS_URL,debug:f})),pe=t.useRef(null),{currentMode:fe,switchToHumanMode:we,switchToBotMode:xe,chatId:ye,sessionId:_e,setChatId:ve,setSessionId:Se}=function(){const[e,n]=t.useState(()=>"HUMAN"===localStorage.getItem(o)?"HUMAN":"BOT"),[s,a]=t.useState(()=>localStorage.getItem(r)),[c,l]=t.useState(()=>localStorage.getItem(i));t.useEffect(()=>{localStorage.setItem(o,e)},[e]);const d=t.useCallback(e=>{a(e),e?localStorage.setItem(r,e):localStorage.removeItem(r)},[]),u=t.useCallback(e=>{l(e),e?localStorage.setItem(i,e):localStorage.removeItem(i)},[]),m=t.useCallback(()=>{n("HUMAN")},[]),h=t.useCallback(()=>{n("BOT")},[]),g=t.useCallback(e=>!1,[]);return{currentMode:e,switchToHumanMode:m,switchToBotMode:h,isHandoffTriggered:g,chatId:s,sessionId:c,setChatId:d,setSessionId:u}}(),be=t.useCallback(e=>{G(!0),U(!1),Q(!1),B(!1),de.current&&(clearTimeout(de.current),de.current=null),ge.current.disconnectWebSocket(),ve(null),Se(null),O(null);const t={id:`resolved-${Date.now()}`,text:"Thank you for contacting us!",sender:"bot",timestamp:new Date};T(e=>[...e,t]),setTimeout(()=>{xe(),G(!1),T([]),z(!1),ee(null),ne(""),ae(""),re(""),ie.current="",me.current&&me.current().catch(console.error)},2e3)},[ve,Se,xe]);t.useCallback(async()=>{if(!X){Y(!0);try{const e=ie.current||te||null,t=se||null,n=oe||null,s=await ge.current.startSupportChat(R||null,e,t,n);we(),ve(s.chat_id),Se(s.session_id),G(!1),I("")}catch(e){T(t=>[...t,{id:`error-new-chat-${Date.now()}`,text:f?`Error: ${e?.message||"Failed to start a new chat."}`:"Sorry, I couldn't start a new chat. Please try again.",sender:"bot",timestamp:new Date}])}finally{Y(!1)}}},[se,oe,te,f,X,R,ve,Se,we]);const De=()=>{if(w&&y)return{dfProjectId:w,dfLocation:x||"us-central1",dfAgentId:y,languageCode:_||"en",backendBaseUrl:he()}};t.useEffect(()=>{if(!u)return;const e=setTimeout(()=>{j(!0)},m);return()=>clearTimeout(e)},[u,m]),t.useEffect(()=>{ce.current?.scrollIntoView({behavior:"smooth"})},[N]);const Ce=t.useCallback(e=>{if(e.to_agent){F({id:e.to_agent_id,name:e.to_agent});const t={id:`system-${Date.now()}`,text:e.from_agent?`Chat has been transferred from ${e.from_agent} to ${e.to_agent}`:`Chat has been transferred to ${e.to_agent}`,sender:"bot",timestamp:new Date};T(e=>[...e,t])}},[f]),je=t.useCallback(e=>{switch(e.type){case"message":if(e.content)if("agent"!==e.sender_type&&e.sender_type)f&&e.sender_type;else{const t={id:e.id||`agent-${Date.now()}`,text:e.content,sender:"agent",timestamp:new Date(e.timestamp||Date.now())};T(e=>new Set(e.map(e=>e.id)).has(t.id)?e:[...e,t]),B(!1),de.current&&(clearTimeout(de.current),de.current=null)}break;case"typing_start":"agent"===e.sender_type&&(B(!0),de.current&&clearTimeout(de.current),de.current=setTimeout(()=>{B(!1)},3e3));break;case"typing_stop":"agent"===e.sender_type&&(B(!1),de.current&&(clearTimeout(de.current),de.current=null));break;case"agent_changed":Ce(e);break;case"chat_info":"active"===e.status?(U(!1),Q(!0)):"resolved"!==e.status&&"ended"!==e.status||be(e.chat_id||null),e.agent_id&&F(t=>({...t,id:e.agent_id}));break;case"agent_accepted":Q(!0),U(!1);const t={id:e.id||`agent-accepted-${e.chat_id||Date.now()}-${Date.now()}`,text:"You can chat now, the agent has accepted your request.",sender:"bot",timestamp:e.timestamp?new Date(e.timestamp):new Date};T(e=>new Set(e.map(e=>e.id)).has(t.id)?e:[...e,t]),e.to_agent&&F({name:e.to_agent,id:e.to_agent_id});break;case"chat_resolved":case"chat_ended":be(e.chat_id||null);break;case"error":const n={id:`error-${Date.now()}`,text:e.error||"An error occurred. Please try again.",sender:"bot",timestamp:new Date};T(e=>[...e,n])}},[f,be,Ce]),Ne=t.useCallback(e=>{4e3===e.code&&be(ye)},[ye,be]),Te=t.useCallback(e=>{H(e),e&&U(!1)},[]);t.useEffect(()=>{if("HUMAN"===fe&&ye&&_e)return ge.current.connectWebSocket(ye,_e,je,Te,Ne),()=>{ge.current.disconnectWebSocket()}},[fe,ye,_e,je,Te,Ne]);const ke=t.useCallback(async(e=!0)=>{if(ye&&_e)try{A(!0);const t=(await ge.current.loadMessageHistory(ye,_e)).map(e=>({id:e.id||`msg-${Date.now()}-${Math.random()}`,text:e.content,sender:"agent"===e.sender_type?"agent":"user",timestamp:new Date(e.timestamp)}));T(e?e=>{const n=new Set(e.map(e=>e.id)),s=t.filter(e=>!n.has(e.id));return[...e,...s].sort((e,t)=>e.timestamp.getTime()-t.timestamp.getTime())}:t)}catch(t){if(f){const e={id:`error-${Date.now()}`,text:`Failed to load chat history: ${t.message}`,sender:"bot",timestamp:new Date};T(t=>[...t,e])}}finally{A(!1)}},[ye,_e,f]);t.useEffect(()=>{if("HUMAN"===fe&&ye&&_e){const e=`${ye}-${_e}`;if(pe.current!==e){pe.current=e;setTimeout(()=>{0===N.length&&ke(!1).catch(console.error)},0)}}else"BOT"===fe&&(pe.current=null)},[fe,ye,_e,ke,N.length]);const Ie=async(e=!1,t=!1)=>{if(R&&!e&&!t)return R;if(ue.current){if(await new Promise(e=>setTimeout(e,100)),R)return R;throw new Error("Session creation in progress. Please try again.")}ue.current=!0;try{M(!0);const e=De();if(!e)throw new Error("Dialogflow configuration is missing. Please provide dfProjectId and dfAgentId.");const s=t&&R?R:null,a=await n.createDialogflowSession(e,s);if(O(a.session_id),a.message){const e={id:`welcome-${Date.now()}`,text:a.message,sender:"bot",timestamp:new Date,richContent:a.richContent};T(t=>0===t.length?[e]:[e,...t])}return a.session_id}catch(s){const e={id:`error-${Date.now()}`,text:f?`Error: ${s.message||"Failed to create session. Please check your Dialogflow configuration."}`:h,sender:"bot",timestamp:new Date};return T(t=>[...t,e]),null}finally{M(!1),ue.current=!1}};me.current=Ie;const Ee=async(e,t,s=!1)=>{if(!e.trim())return;if(q){if("name"===Z){const t=e.trim();ne(t),ie.current=t,ee("email");const n={id:Date.now().toString(),text:t,sender:"user",timestamp:new Date};T(e=>[...e,n]);const s={id:(Date.now()+1).toString(),text:"Thank you! Now please provide your email address:",sender:"bot",timestamp:new Date};return T(e=>[...e,s]),void I("")}if("email"===Z){const t=e.trim();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)){const e={id:(Date.now()+1).toString(),text:"Please provide a valid email address:",sender:"bot",timestamp:new Date};return T(t=>[...t,e]),void I("")}ae(t),ee("mobile");const n={id:Date.now().toString(),text:t,sender:"user",timestamp:new Date};T(e=>[...e,n]);const s={id:(Date.now()+1).toString(),text:"Thank you! Now please provide your mobile number:",sender:"bot",timestamp:new Date};return T(e=>[...e,s]),void I("")}if("mobile"===Z){const t=e.trim();if(!/^[\+]?[(]?[0-9]{1,4}[)]?[-\s\.]?[(]?[0-9]{1,4}[)]?[-\s\.]?[0-9]{1,9}$/.test(t)||t.length<10){const e={id:(Date.now()+1).toString(),text:"Please provide a valid mobile number (e.g., +1234567890):",sender:"bot",timestamp:new Date};return T(t=>[...t,e]),void I("")}re(t);const n={id:Date.now().toString(),text:t,sender:"user",timestamp:new Date};T(e=>[...e,n]);const s=ie.current,a=se;return z(!1),ee(null),ie.current="",await(async(e,t,n)=>{try{U(!0);const a=R,o=await ge.current.ensureChatInitialized(ye,_e,a||null,e||null,t||null,n||null);if(!o||!o.chat_id)throw new Error("Failed to initialize chat session");const r=o.chat_id,i=o.session_id;r!==ye&&(ve(r),Se(i));try{await ge.current.requestHandoff(r,i,"Customer requested human agent",a||null,e||null,t||null,n||null)}catch(s){if(!(s.message?.includes("Invalid chat_id")||s.message?.includes("Chat not found")||s.message?.includes("unauthorized")||s.message?.includes("400")||s.message?.includes("401")||s.message?.includes("404")||s.message?.includes("expired")))throw s;{ve(null),Se(null);const s=await ge.current.startSupportChat(a||null,e||null,t||null,n||null);if(!s||!s.chat_id)throw new Error("Failed to re-initialize chat session");const o=s.chat_id,r=s.session_id;ve(o),Se(r),await ge.current.requestHandoff(o,r,"Customer requested human agent",a||null,e||null,t||null,n||null);const i=`${o}-${r}`;pe.current!==i&&(pe.current=i,await ke(!0))}}we(),G(!1),Q(!1);const c={id:`connecting-${Date.now()}`,text:"Connecting you to a human agent...",sender:"bot",timestamp:new Date};T(e=>[...e,c]);const l=`${r}-${i}`;pe.current=l}catch(a){const e={id:`error-${Date.now()}`,text:f?`Handoff error: ${a.message}`:"Failed to connect to agent. Please try again.",sender:"bot",timestamp:new Date};T(t=>[...t,e]),U(!1)}})(s,a,t),void I("")}}if("HUMAN"===fe){if(!ye||!_e){const e={id:Date.now().toString(),text:"Chat session not initialized. Please try again.",sender:"bot",timestamp:new Date};return void T(t=>[...t,e])}if(!s){const n={id:Date.now().toString(),text:t||e.trim(),sender:"user",timestamp:new Date};T(e=>[...e,n])}ge.current.sendTypingIndicator("typing_stop"),le.current&&(clearTimeout(le.current),le.current=null),I(""),A(!0);try{ge.current.sendMessageViaWebSocket(e.trim())||await ge.current.sendMessageToAgent(ye,_e,e.trim())}catch(o){if(o instanceof n.ChatResolvedError||"ChatResolvedError"===o?.name||"chat_resolved"===o?.message)return void be(ye);if(o.message?.includes("Chat not found")||o.message?.includes("unauthorized")||o.message?.includes("401")||o.message?.includes("404")){ve(null),Se(null);try{const t=await ge.current.startSupportChat(R||null,null,null,null);ve(t.chat_id),Se(t.session_id);try{await ge.current.sendMessageToAgent(t.chat_id,t.session_id,e.trim())}catch(r){if(r instanceof n.ChatResolvedError||"ChatResolvedError"===r?.name||"chat_resolved"===r?.message)return void be(t.chat_id);throw r}return}catch(r){if(r instanceof n.ChatResolvedError||"ChatResolvedError"===r?.name||"chat_resolved"===r?.message)return void be(ye);const e={id:(Date.now()+1).toString(),text:f?`Error: ${r.message||"Failed to send message."}`:"Sorry, I'm having trouble sending your message. Please try again.",sender:"bot",timestamp:new Date};T(t=>[...t,e])}}else{const e={id:(Date.now()+1).toString(),text:f?`Error: ${o.message||"Failed to send message to agent."}`:"Sorry, I'm having trouble sending your message. Please try again.",sender:"bot",timestamp:new Date};T(t=>[...t,e])}}finally{A(!1)}return}let a=R;if(!a)try{if(a=await Ie(),!a){const e={id:Date.now().toString(),text:f?"Failed to create session. Please check the console for details.":"Sorry, I'm having trouble connecting. Please try again.",sender:"bot",timestamp:new Date};return void T(t=>[...t,e])}}catch(o){const e={id:Date.now().toString(),text:f?`Connection Error: ${o.message||"Please check your Dialogflow configuration."}`:"Sorry, I'm having trouble connecting. Please check your configuration.",sender:"bot",timestamp:new Date};return void T(t=>[...t,e])}if(!s){const n={id:Date.now().toString(),text:t||e.trim(),sender:"user",timestamp:new Date};T(e=>[...e,n])}I(""),A(!0);try{const t=De();if(!t)throw new Error("Dialogflow configuration is missing. Please provide dfProjectId and dfAgentId.");const s=await n.sendDialogflowMessage(e.trim(),a,t);if(!0===s.handoff){const e={id:(Date.now()+1).toString(),text:s.response,sender:"bot",timestamp:new Date(s.timestamp||Date.now()),richContent:s.richContent};T(t=>[...t,e]),z(!0),ee("name"),ne(""),ae(""),ie.current="";const t={id:(Date.now()+2).toString(),text:"To connect you with a human agent, I'll need some information. Please provide your name:",sender:"bot",timestamp:new Date};return void T(e=>[...e,t])}const o={id:(Date.now()+1).toString(),text:s.response,sender:"bot",timestamp:new Date(s.timestamp||Date.now()),richContent:s.richContent};T(e=>[...e,o])}catch(o){const e={id:(Date.now()+1).toString(),text:f?`Error: ${o.message||"Failed to send message. Please check your Dialogflow configuration."}`:o.message?.includes("Failed to fetch")||o.message?.includes("CORS")?"Unable to connect to Dialogflow. Please check your configuration and network.":"Sorry, I'm having trouble processing your message. Please try again.",sender:"bot",timestamp:new Date};T(t=>[...t,e])}finally{A(!1)}};t.useEffect(()=>()=>{le.current&&clearTimeout(le.current),de.current&&clearTimeout(de.current)},[]);const Ae=async()=>{D(!0),j(!1),R||await Ie()},Re=e=>e.includes("👤")||e.includes("being connected")||e.includes("live support agent")||e.includes("transfer your conversation")||e.includes("✅")||e.includes("🔄");return t.useEffect(()=>()=>{ge.current.disconnectWebSocket()},[]),e.jsxs(e.Fragment,{children:[C&&!b&&e.jsxs("div",{className:"custom-welcome-popup",onClick:Ae,children:[e.jsxs("div",{className:"custom-welcome-header",children:[e.jsx("div",{className:"custom-welcome-title",children:c}),e.jsx("button",{className:"custom-close-popup",onClick:e=>{e.stopPropagation(),j(!1)},children:"×"})]}),e.jsx("div",{className:"custom-welcome-message",children:l}),e.jsx("div",{className:"custom-welcome-cta",children:d})]}),!b&&e.jsx("button",{className:"custom-chat-toggle-btn",onClick:Ae,"aria-label":"Open chat",children:e.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),b&&e.jsxs("div",{className:"custom-chat-window",children:[e.jsxs("div",{className:"custom-chat-header",children:[e.jsxs("div",{className:"custom-chat-header-content",children:[e.jsx("div",{className:"custom-chat-title",children:s}),e.jsxs("div",{className:"custom-chat-subtitle",children:[a,"HUMAN"===fe&&e.jsxs("span",{className:"custom-mode-indicator",children:[" ","• ",L?"🟢 Connected":"🟡 Connecting..."]})]}),"HUMAN"===fe&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"custom-mode-badge",children:"Human Support Mode"}),e.jsxs("div",{className:"custom-agent-info",children:[e.jsx("span",{className:"custom-agent-label",children:"Agent:"}),e.jsx("span",{className:"custom-agent-name",children:W.name})]})]}),"BOT"===fe&&e.jsx("div",{className:"custom-mode-badge",children:"Bot Mode"})]}),e.jsx("button",{className:"custom-chat-close-btn",onClick:()=>{D(!1),"HUMAN"===fe&&ge.current.disconnectWebSocket()},"aria-label":"Close chat",children:"×"})]}),e.jsxs("div",{className:"custom-chat-messages",children:[$&&0===N.length&&e.jsxs("div",{className:"custom-chat-empty",children:[e.jsxs("div",{className:"custom-typing-indicator",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}),e.jsx("p",{children:"Initializing chat..."})]}),!$&&0===N.length&&e.jsxs("div",{className:"custom-chat-empty",children:[e.jsx("div",{className:"custom-chat-empty-icon",children:"👋"}),e.jsx("p",{children:p})]}),N.map(t=>e.jsxs("div",{className:`custom-message custom-message-${t.sender} ${Re(t.text)?"custom-handoff-message":""}`,children:[e.jsx("div",{className:"custom-message-content "+(Re(t.text)?"custom-handoff-content":""),dangerouslySetInnerHTML:{__html:n.linkifyText(t.text).replace(/\n/g,"<br>")}}),(f&&t.richContent,t.richContent&&Array.isArray(t.richContent)&&t.richContent.length>0?e.jsx("div",{className:"custom-chips-container",children:t.richContent.map((t,n)=>{if(!Array.isArray(t)){const s=t;return s&&"chips"===s.type&&s.options?e.jsx("div",{className:"custom-chips-group",children:s.options.map((t,n)=>e.jsx("button",{className:"custom-chip-button",onClick:()=>{const e={id:Date.now().toString(),text:t.text,sender:"user",timestamp:new Date};T(t=>[...t,e]),Ee(t.text,t.text,!0)},type:"button",children:t.text},n))},n):null}return t.map((t,s)=>t&&"chips"===t.type&&t.options?e.jsx("div",{className:"custom-chips-group",children:t.options.map((t,n)=>e.jsx("button",{className:"custom-chip-button",onClick:()=>{const e={id:Date.now().toString(),text:t.text,sender:"user",timestamp:new Date};T(t=>[...t,e]),Ee(t.text,t.text,!0)},type:"button",children:t.text},n))},`${n}-${s}`):null)})}):null),e.jsx("div",{className:"custom-message-time",children:t.timestamp.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]},t.id)),E&&e.jsx("div",{className:"custom-message custom-message-bot",children:e.jsxs("div",{className:"custom-typing-indicator",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]})}),P&&e.jsxs("div",{className:"custom-message custom-message-bot",children:[e.jsxs("div",{className:"custom-typing-indicator",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}),e.jsx("div",{className:"custom-message-content",children:"Connecting to agent..."})]}),"HUMAN"===fe&&V&&e.jsxs("div",{className:"custom-agent-typing-indicator",children:[e.jsxs("span",{className:"custom-typing-dots",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}),e.jsx("span",{className:"custom-typing-text",children:"Agent is typing..."})]}),e.jsx("div",{ref:ce})]}),e.jsxs("form",{className:"custom-chat-input-form",onSubmit:e=>{e.preventDefault(),Ee(k)},children:[e.jsx("input",{type:"text",className:"custom-chat-input",value:k,onChange:e=>{const t=e.target.value;I(t),"HUMAN"===fe&&L&&(ge.current.sendTypingIndicator("typing_start"),le.current&&clearTimeout(le.current),le.current=setTimeout(()=>{ge.current.sendTypingIndicator("typing_stop"),le.current=null},2e3))},placeholder:g,disabled:E||$||X}),e.jsx("button",{type:"submit",className:"custom-chat-send-btn",disabled:!k.trim()||E||$||X,children:e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),e.jsx("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]})]})]})}function l(){const e="undefined"==typeof window;if("undefined"!=typeof process&&void 0!==process.env){const t=process.env;if(t?.NEXT_RUNTIME)return{name:"next",version:t.NEXT_VERSION,isSSR:e}}if("undefined"!=typeof process&&void 0!==process.env){const t=process.env;if(t?.NUXT||globalThis.__NUXT__)return{name:"nuxt",version:t.NUXT_VERSION,isSSR:e}}if(globalThis.__NUXT__)return{name:"nuxt",version:void 0,isSSR:e};if(void 0!=={url:"undefined"==typeof document?require("url").pathToFileURL(__filename).href:a&&"SCRIPT"===a.tagName.toUpperCase()&&a.src||new URL("index.cjs.js",document.baseURI).href}){const t={url:"undefined"==typeof document?require("url").pathToFileURL(__filename).href:a&&"SCRIPT"===a.tagName.toUpperCase()&&a.src||new URL("index.cjs.js",document.baseURI).href};if(t.env?.DEV)return{name:"vite",version:t.env?.VITE_VERSION,isSSR:e}}return function(){if("undefined"!=typeof window&&(window.React||window.react))return!0;if("undefined"!=typeof document&&window.__REACT_DEVTOOLS_GLOBAL_HOOK__)return!0;return!1}()?{name:"react",version:d(),isSSR:e}:function(){if("undefined"!=typeof window&&(window.Vue||window.vue))return!0;if("undefined"!=typeof window&&window.__VUE_DEVTOOLS_GLOBAL_HOOK__)return!0;return!1}()?{name:"vue",version:u(),isSSR:e}:{name:"vanilla",isSSR:e}}function d(){try{if("undefined"!=typeof window&&window.React?.version)return window.React.version;if("undefined"!=typeof window&&window.__REACT_DEVTOOLS_GLOBAL_HOOK__){const e=window.__REACT_DEVTOOLS_GLOBAL_HOOK__;if(e.renderers&&e.renderers.size>0){return Array.from(e.renderers.values())[0].version}}}catch{}}function u(){try{if("undefined"!=typeof window&&window.Vue?.version)return window.Vue.version;if("undefined"!=typeof window&&window.__VUE_DEVTOOLS_GLOBAL_HOOK__){const e=window.__VUE_DEVTOOLS_GLOBAL_HOOK__;if(e.apps&&e.apps.length>0){return e.apps[0].version}}}catch{}}let m=null;var h,g=s;h=g.createRoot,g.hydrateRoot;class p{constructor(e,t){if(this.root=null,this.config=t,"string"==typeof e){const t=document.querySelector(e);if(!t)throw new Error(`Container element "${e}" not found`);this.container=t}else this.container=e;this.root=h(this.container),this.render()}render(){this.root&&this.root.render(t.createElement(c,this.config))}updateConfig(e){this.config={...this.config,...e},this.render()}destroy(){this.root&&(this.root.unmount(),this.root=null)}}exports.createDialogflowSession=n.createDialogflowSession,exports.sendDialogflowMessage=n.sendDialogflowMessage,exports.ChatWidget=c,exports.ReactChatWidget=c,exports.VanillaChatWidget=p,exports.createChatWidget=function(e,t){return new p(e,t)},exports.default=c,exports.getFramework=function(){return m?{name:m,isSSR:"undefined"==typeof window}:l()},exports.setFramework=function(e){m=e};
|
|
2
|
+
//# sourceMappingURL=index.cjs.js.map
|