@blockspark/chat-widget 1.0.19 → 1.0.21

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.
@@ -0,0 +1,2 @@
1
+ "use strict";const e=require("vue"),t=require("./sanitize-BYa4jHJ0.cjs");class s{constructor(e){if(this.listeners=new Set,this.chatMode="ai",this.chatId=null,this.supportSessionId=null,this.chatService=null,this.wsConnected=!1,this.agentTyping=!1,this.currentAgent={name:"Agent"},this.isConnectingToAgent=!1,this.agentAccepted=!1,this.chatResolved=!1,this.historyLoaded=null,this.typingTimeout=null,this.agentTypingTimeout=null,this.config=e,this.state={isOpen:!1,showWelcomePopup:!1,messages:[],inputValue:"",isLoading:!1,error:null,sessionId:null,chatMode:"ai"},this.chatService=t.createChatService({baseUrl:this.config.backendBaseUrl||"http://localhost:8012",wsUrl:this.config.backendWsUrl||"ws://localhost:8012",debug:this.config.debug||!1}),"undefined"!=typeof window&&window.localStorage){const e=localStorage.getItem("chartsconnectect_chat_mode");this.chatMode="HUMAN"===e?"human":"ai",this.state.chatMode=this.chatMode,this.chatId=localStorage.getItem("chartsconnect_chat_id"),this.supportSessionId=localStorage.getItem("chartsconnect_session_id")}}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}getState(){return{...this.state}}setState(e){this.state={...this.state,...e},this.listeners.forEach(e=>e(this.getState()))}updateConfig(e){this.config={...this.config,...e}}async openChat(){if(this.setState({isOpen:!0}),this.state.showWelcomePopup&&this.setState({showWelcomePopup:!1}),"ai"===this.state.chatMode&&!this.state.sessionId&&this.config.dfProjectId&&this.config.dfAgentId)try{this.setState({isLoading:!0});const e={dfProjectId:this.config.dfProjectId,dfLocation:this.config.dfLocation||"us-central1",dfAgentId:this.config.dfAgentId,languageCode:this.config.languageCode||"en",backendBaseUrl:this.config.backendBaseUrl||"http://localhost:8012"},s=await t.createDialogflowSession(e);if(this.setState({sessionId:s.session_id,isLoading:!1}),s.message){const e={id:`welcome-${Date.now()}`,text:s.message,sender:"bot",timestamp:new Date,richContent:s.richContent};this.setState({messages:[e]})}}catch(e){this.setState({isLoading:!1,error:e.message||"Failed to initialize chat"});const t={id:`fallback-${Date.now()}`,text:this.config.fallbackWelcomeMessage||"Hello! How can I help you today?",sender:"bot",timestamp:new Date};this.setState({messages:[t]})}}closeChat(){this.setState({isOpen:!1})}closeWelcomePopup(){this.setState({showWelcomePopup:!1})}toggleChat(){const e=!this.state.isOpen;this.setState({isOpen:e}),e&&this.state.showWelcomePopup&&this.setState({showWelcomePopup:!1})}setInputValue(e){this.setState({inputValue:e})}clearError(){this.setState({error:null})}async sendMessage(e,s=!1){if(e.trim()&&!this.state.isLoading){if(s)this.setState({inputValue:"",isLoading:!0,error:null});else{const t={id:`user-${Date.now()}`,text:e.trim(),sender:"user",timestamp:new Date};this.setState({messages:[...this.state.messages,t],inputValue:"",isLoading:!0,error:null})}try{"human"===this.state.chatMode?await this.sendHumanMessage(e):await this.sendAIMessage(e)}catch(a){if(a instanceof t.ChatResolvedError||"ChatResolvedError"===a?.name||"chat_resolved"===a?.message)return void this.enterResolvedState(this.chatId);const e={id:`error-${Date.now()}`,text:this.config.debug?`Error: ${a.message||"Failed to send message"}`:a.message?.includes("CORS")||a.message?.includes("Failed to fetch")?"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};this.setState({messages:[...this.state.messages,e],error:a.message||"Failed to send message",isLoading:!1})}}}async sendAIMessage(e){if(!this.config.dfProjectId||!this.config.dfAgentId)throw new Error("Dialogflow configuration is missing");const s={dfProjectId:this.config.dfProjectId,dfLocation:this.config.dfLocation||"us-central1",dfAgentId:this.config.dfAgentId,languageCode:this.config.languageCode||"en",backendBaseUrl:this.config.backendBaseUrl||"http://localhost:8012"};if(!this.state.sessionId){const e=await t.createDialogflowSession(s);this.setState({sessionId:e.session_id})}this.config.debug;const a=await t.sendDialogflowMessage(e,this.state.sessionId,s);if(this.config.debug,!0===a.handoff){const e={id:`bot-${Date.now()}`,text:a.response||this.config.fallbackWelcomeMessage||"No response",sender:"bot",timestamp:new Date,richContent:a.richContent};return this.setState({messages:[...this.state.messages,e],isLoading:!1}),void(await this.handleHandoff())}const n={id:`bot-${Date.now()}`,text:a.response||this.config.fallbackWelcomeMessage||"No response",sender:"bot",timestamp:new Date,richContent:a.richContent};this.setState({messages:[...this.state.messages,n],isLoading:!1})}async sendHumanMessage(e){if(!this.chatId||!this.supportSessionId){const e={id:`error-${Date.now()}`,text:"Chat session not initialized. Please try again.",sender:"bot",timestamp:new Date};return void this.setState({messages:[...this.state.messages,e],isLoading:!1})}if(!this.chatService)throw new Error("Chat service not initialized");this.chatService.sendTypingIndicator("typing_stop"),this.typingTimeout&&(clearTimeout(this.typingTimeout),this.typingTimeout=null);try{this.chatService.sendMessageViaWebSocket(e.trim())||await this.chatService.sendMessageToAgent(this.chatId,this.supportSessionId,e.trim()),this.setState({isLoading:!1})}catch(s){if(s instanceof t.ChatResolvedError||"ChatResolvedError"===s?.name||"chat_resolved"===s?.message)return void this.enterResolvedState(this.chatId);if(!(s.message?.includes("Chat not found")||s.message?.includes("unauthorized")||s.message?.includes("401")||s.message?.includes("404")))throw s;this.config.debug,this.chatId=null,this.supportSessionId=null,"undefined"!=typeof window&&window.localStorage&&(localStorage.removeItem("chartsconnect_chat_id"),localStorage.removeItem("chartsconnect_session_id"));try{const t=await this.chatService.startSupportChat(this.state.sessionId||null);return this.chatId=t.chat_id,this.supportSessionId=t.session_id,"undefined"!=typeof window&&window.localStorage&&(localStorage.setItem("chartsconnect_chat_id",this.chatId),localStorage.setItem("chartsconnect_session_id",this.supportSessionId)),this.chatId&&this.supportSessionId&&await this.chatService.sendMessageToAgent(this.chatId,this.supportSessionId,e.trim()),void this.setState({isLoading:!1})}catch(a){if(a instanceof t.ChatResolvedError||"chat_resolved"===a?.message)return void this.enterResolvedState(this.chatId);throw a}}}switchToHumanMode(){this.chatMode="human",this.setState({chatMode:"human"}),"undefined"!=typeof window&&window.localStorage&&localStorage.setItem("chartsconnect_chat_mode","HUMAN")}switchToBotMode(){this.chatMode="ai",this.setState({chatMode:"ai"}),"undefined"!=typeof window&&window.localStorage&&localStorage.setItem("chartsconnect_chat_mode","BOT")}initializeWelcomePopup(){if(!1!==this.config.showWelcomePopup){const e=this.config.welcomePopupDelay||1500;setTimeout(()=>{this.state.isOpen||this.setState({showWelcomePopup:!0})},e)}}async handleHandoff(){if(!this.chatService)throw new Error("Chat service not initialized");try{this.isConnectingToAgent=!0;const t=this.state.sessionId,s=await this.chatService.ensureChatInitialized(this.chatId,this.supportSessionId,t||null);if(!s||!s.chat_id)throw new Error("Failed to initialize chat session");const a=s.chat_id,n=s.session_id;a!==this.chatId&&(this.chatId=a,this.supportSessionId=n,"undefined"!=typeof window&&window.localStorage&&(localStorage.setItem("chartsconnect_chat_id",this.chatId),localStorage.setItem("chartsconnect_session_id",this.supportSessionId)),this.config.debug);try{await this.chatService.requestHandoff(a,n,"Customer requested human agent",t||null),this.config.debug}catch(e){if(!(e.message?.includes("Invalid chat_id")||e.message?.includes("Chat not found")||e.message?.includes("unauthorized")||e.message?.includes("400")||e.message?.includes("401")||e.message?.includes("404")||e.message?.includes("expired")))throw e;{this.config.debug,this.chatId=null,this.supportSessionId=null,"undefined"!=typeof window&&window.localStorage&&(localStorage.removeItem("chartsconnect_chat_id"),localStorage.removeItem("chartsconnect_session_id"));const e=await this.chatService.startSupportChat(t||null);if(!e||!e.chat_id)throw new Error("Failed to re-initialize chat session");this.chatId=e.chat_id,this.supportSessionId=e.session_id,"undefined"!=typeof window&&window.localStorage&&(localStorage.setItem("chartsconnect_chat_id",this.chatId),localStorage.setItem("chartsconnect_session_id",this.supportSessionId)),await this.chatService.requestHandoff(this.chatId,this.supportSessionId,"Customer requested human agent",t||null),this.config.debug}}this.switchToHumanMode(),this.chatResolved=!1,this.agentAccepted=!1;const o={id:`connecting-${Date.now()}`,text:"Connecting you to a human agent...",sender:"bot",timestamp:new Date};this.setState({messages:[...this.state.messages,o]}),a&&n&&this.chatService.connectWebSocket(a,n,e=>{this.handleWebSocketMessage(e)},e=>{this.wsConnected=e}),this.isConnectingToAgent=!1}catch(t){const e={id:`error-${Date.now()}`,text:this.config.debug?`Handoff error: ${t.message}`:"Failed to connect to agent. Please try again.",sender:"bot",timestamp:new Date};this.setState({messages:[...this.state.messages,e]}),this.isConnectingToAgent=!1}}handleWebSocketMessage(e){switch(e.type){case"message":if(e.content&&("agent"===e.sender_type||!e.sender_type)){const t={id:e.id||`agent-${Date.now()}`,text:e.content,sender:"agent",timestamp:new Date(e.timestamp||Date.now())};new Set(this.state.messages.map(e=>e.id)).has(t.id)||this.setState({messages:[...this.state.messages,t]}),this.agentTyping=!1,this.agentTypingTimeout&&(clearTimeout(this.agentTypingTimeout),this.agentTypingTimeout=null)}break;case"typing_start":"agent"===e.sender_type&&(this.agentTyping=!0,this.agentTypingTimeout&&clearTimeout(this.agentTypingTimeout),this.agentTypingTimeout=setTimeout(()=>{this.agentTyping=!1},3e3));break;case"typing_stop":"agent"===e.sender_type&&(this.agentTyping=!1,this.agentTypingTimeout&&(clearTimeout(this.agentTypingTimeout),this.agentTypingTimeout=null));break;case"agent_changed":if(e.to_agent){this.currentAgent={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};this.setState({messages:[...this.state.messages,t]})}break;case"agent_accepted":this.agentAccepted=!0,this.isConnectingToAgent=!1;const t={id:e.id||`agent-accepted-${Date.now()}`,text:"You can chat now, the agent has accepted your request.",sender:"bot",timestamp:e.timestamp?new Date(e.timestamp):new Date};new Set(this.state.messages.map(e=>e.id)).has(t.id)||this.setState({messages:[...this.state.messages,t]}),e.to_agent&&(this.currentAgent={name:e.to_agent,id:e.to_agent_id});break;case"chat_resolved":case"chat_ended":this.enterResolvedState(e.chat_id||null);break;case"chat_info":"active"===e.status?(this.isConnectingToAgent=!1,this.agentAccepted=!0):"resolved"!==e.status&&"ended"!==e.status||this.enterResolvedState(e.chat_id||null),e.agent_id&&(this.currentAgent={...this.currentAgent,id:e.agent_id});break;case"error":const s={id:`error-${Date.now()}`,text:e.error||"An error occurred. Please try again.",sender:"bot",timestamp:new Date};this.setState({messages:[...this.state.messages,s]})}}enterResolvedState(e){this.chatResolved=!0,this.isConnectingToAgent=!1,this.agentAccepted=!1,this.agentTyping=!1,this.agentTypingTimeout&&(clearTimeout(this.agentTypingTimeout),this.agentTypingTimeout=null),this.chatService&&this.chatService.disconnectWebSocket(),this.chatId=null,this.supportSessionId=null,"undefined"!=typeof window&&window.localStorage&&(localStorage.removeItem("chartsconnect_chat_id"),localStorage.removeItem("chartsconnect_session_id"));const s={id:`resolved-${Date.now()}`,text:"Thank you for contacting us!",sender:"bot",timestamp:new Date};this.setState({messages:[...this.state.messages,s]}),setTimeout(async()=>{if(this.switchToBotMode(),this.chatResolved=!1,this.setState({messages:[],sessionId:null}),this.config.dfProjectId&&this.config.dfAgentId&&this.state.isOpen)try{this.setState({isLoading:!0});const e={dfProjectId:this.config.dfProjectId,dfLocation:this.config.dfLocation||"us-central1",dfAgentId:this.config.dfAgentId,languageCode:this.config.languageCode||"en",backendBaseUrl:this.config.backendBaseUrl||"http://localhost:8012"},s=await t.createDialogflowSession(e);if(this.setState({sessionId:s.session_id,isLoading:!1}),s.message){const e={id:`welcome-${Date.now()}`,text:s.message,sender:"bot",timestamp:new Date,richContent:s.richContent};this.setState({messages:[e]})}}catch(e){this.setState({isLoading:!1,error:e.message||"Failed to initialize chat"});const t={id:`fallback-${Date.now()}`,text:this.config.fallbackWelcomeMessage||"Hello! How can I help you today?",sender:"bot",timestamp:new Date};this.setState({messages:[t]})}},2e3)}async loadMessageHistory(e=!1){if(this.chatService&&this.chatId&&this.supportSessionId)try{if(this.chatId&&this.supportSessionId){const t=(await this.chatService.loadMessageHistory(this.chatId,this.supportSessionId)).map(e=>({id:e.id||`history-${Date.now()}-${Math.random()}`,text:e.content,sender:"agent"===e.sender_type?"agent":"user",timestamp:new Date(e.timestamp)}));if(e){const e=new Set(this.state.messages.map(e=>e.id)),s=t.filter(t=>!e.has(t.id)),a=[...this.state.messages,...s].sort((e,t)=>e.timestamp.getTime()-t.timestamp.getTime());this.setState({messages:a})}else this.setState({messages:t})}}catch(t){if(this.config.debug){const e={id:`error-${Date.now()}`,text:`Failed to load chat history: ${t.message}`,sender:"bot",timestamp:new Date};this.setState({messages:[...this.state.messages,e]})}}}getAdditionalState(){return{wsConnected:this.wsConnected,agentTyping:this.agentTyping,currentAgent:this.currentAgent,isConnectingToAgent:this.isConnectingToAgent,agentAccepted:this.agentAccepted,chatResolved:this.chatResolved}}destroy(){this.typingTimeout&&clearTimeout(this.typingTimeout),this.agentTypingTimeout&&clearTimeout(this.agentTypingTimeout),this.chatService&&this.chatService.disconnectWebSocket(),this.listeners.clear()}}function a(t){const a=new s(t),n=e.ref(a.getState()),o=e.ref(!1),i=e.ref(!1),c=e.ref({name:"Agent"}),r=e.ref(!1),l=a.subscribe(e=>{n.value={...e};const t=a.getAdditionalState();o.value=t.wsConnected,i.value=t.agentTyping,c.value=t.currentAgent,r.value=t.isConnectingToAgent}),d=e.computed(()=>n.value.isOpen),h=e.computed(()=>n.value.messages),g=e.computed(()=>n.value.isLoading),m=e.computed(()=>n.value.error),u=e.computed(()=>n.value.chatMode);return e.onUnmounted(()=>{l(),a.destroy()}),e.watch(()=>t,e=>{a.updateConfig(e)},{deep:!0}),{state:n,isOpen:d,messages:h,isLoading:g,error:m,chatMode:u,wsConnected:o,agentTyping:i,currentAgent:c,isConnectingToAgent:r,openChat:async()=>{await a.openChat()},closeChat:()=>{a.closeChat()},sendMessage:async e=>{await a.sendMessage(e)},toggleChat:async()=>{await a.toggleChat()},setInputValue:e=>{a.setInputValue(e)},clearError:()=>{a.clearError()},manager:a}}const n={class:"custom-welcome-header"},o={class:"custom-welcome-title"},i={class:"custom-welcome-message"},c={class:"custom-welcome-cta"},r={key:2,class:"custom-chat-window"},l={class:"custom-chat-header"},d={class:"custom-chat-header-content"},h={class:"custom-chat-title"},g={class:"custom-chat-subtitle"},m={key:0,class:"custom-mode-indicator"},u={key:0,class:"custom-mode-badge"},p={key:1,class:"custom-agent-info"},f={class:"custom-agent-name"},w={key:2,class:"custom-mode-badge"},y={key:0,class:"custom-chat-empty"},S={key:1,class:"custom-chat-empty"},v=["innerHTML"],k={key:0,class:"custom-chips-container"},C={key:0,class:"custom-chips-group"},I=["onClick"],b={key:0,class:"custom-chips-group"},E=["onClick"],T={class:"custom-message-time"},_={key:2,class:"custom-message custom-message-bot"},V={key:3,class:"custom-message custom-message-bot"},B={key:4,class:"custom-agent-typing-indicator"},A=["value","placeholder","disabled"],N=["disabled"],M=((e,t)=>{const s=e.__vccOpts||e;for(const[a,n]of t)s[a]=n;return s})(e.defineComponent({inheritAttrs:!1,__name:"ChatWidget",props:{dfProjectId:{},dfLocation:{},dfAgentId:{},languageCode:{},backendBaseUrl:{},backendWsUrl:{},title:{default:"💬 Charts Connect AI Assistant"},subtitle:{default:"We're here to help"},welcomeTitle:{default:"👋 Welcome to Charts Connect"},welcomeMessage:{default:"My name is Charts Connect AI Assistant and I'll guide you."},welcomeCta:{default:"💬 Click here to start chatting!"},showWelcomePopup:{type:Boolean,default:!0},welcomePopupDelay:{default:1500},fallbackWelcomeMessage:{default:"Hello! I'm Charts Connect AI Assistant. How can I help you today?"},inputPlaceholder:{default:"Type your message..."},emptyStateMessage:{default:"Hi! I'm Charts Connect AI Assistant. How can I help you today?"},debug:{type:Boolean,default:!1}},setup(s){const M=s,{state:D,isOpen:L,messages:x,isLoading:P,error:W,chatMode:$,wsConnected:H,agentTyping:O,currentAgent:R,isConnectingToAgent:z,openChat:F,closeChat:U,sendMessage:j,toggleChat:q,setInputValue:Y,clearError:G,manager:J}=a(M),K=e.ref(null),Q=e.ref(null),X=e.computed(()=>M),Z=e.computed(()=>D.value.isLoading&&0===D.value.messages.length&&!D.value.sessionId),ee=e.computed(()=>!1),te=z;e.watch(()=>x.value.length,()=>{e.nextTick(()=>{K.value?.scrollIntoView({behavior:"smooth"})})});const se=async()=>{D.value.isOpen||(D.value.isOpen=!0,D.value.showWelcomePopup=!1),await F()},ae=()=>{U()},ne=()=>{J.closeWelcomePopup()},oe=e=>{const t=e.target;Y(t.value)},ie=async e=>{e.preventDefault(),D.value.inputValue.trim()&&await j(D.value.inputValue)},ce=async(e,t)=>{const s=e||t||"";await j(s)},re=e=>e.includes("👤")||e.includes("being connected")||e.includes("live support agent")||e.includes("transfer your conversation");return e.onMounted(()=>{X.value.showWelcomePopup&&"undefined"!=typeof window&&J.initializeWelcomePopup()}),(s,a)=>(e.openBlock(),e.createElementBlock("div",e.mergeProps({class:"custom-chat-widget"},s.$attrs),[e.unref(D).showWelcomePopup&&!e.unref(D).isOpen?(e.openBlock(),e.createElementBlock("div",{key:0,class:"custom-welcome-popup",onClick:se},[e.createElementVNode("div",n,[e.createElementVNode("div",o,e.toDisplayString(X.value.welcomeTitle),1),e.createElementVNode("button",{class:"custom-close-popup",onClick:e.withModifiers(ne,["stop"]),"aria-label":"Close welcome popup"}," × ")]),e.createElementVNode("div",i,e.toDisplayString(X.value.welcomeMessage),1),e.createElementVNode("div",c,e.toDisplayString(X.value.welcomeCta),1)])):e.createCommentVNode("",!0),e.unref(D).isOpen?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("button",{key:1,class:"custom-chat-toggle-btn",onClick:se,"aria-label":"Open chat"},[...a[0]||(a[0]=[e.createElementVNode("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[e.createElementVNode("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})],-1)])])),e.unref(D).isOpen?(e.openBlock(),e.createElementBlock("div",r,[e.createElementVNode("div",l,[e.createElementVNode("div",d,[e.createElementVNode("div",h,e.toDisplayString(X.value.title),1),e.createElementVNode("div",g,[e.createTextVNode(e.toDisplayString(X.value.subtitle)+" ",1),"human"===e.unref(D).chatMode?(e.openBlock(),e.createElementBlock("span",m," • "+e.toDisplayString(e.unref(H)?"🟢 Connected":"🟡 Connecting..."),1)):e.createCommentVNode("",!0)]),"human"===e.unref(D).chatMode?(e.openBlock(),e.createElementBlock("div",u," Human Support Mode ")):e.createCommentVNode("",!0),"human"===e.unref(D).chatMode?(e.openBlock(),e.createElementBlock("div",p,[a[1]||(a[1]=e.createElementVNode("span",{class:"custom-agent-label"},"Agent:",-1)),e.createElementVNode("span",f,e.toDisplayString(e.unref(R).name),1)])):e.createCommentVNode("",!0),"ai"===e.unref(D).chatMode?(e.openBlock(),e.createElementBlock("div",w," Bot Mode ")):e.createCommentVNode("",!0)]),e.createElementVNode("button",{class:"custom-chat-close-btn",onClick:ae,"aria-label":"Close chat"}," × ")]),e.createElementVNode("div",{class:"custom-chat-messages",ref_key:"messagesContainer",ref:Q},[Z.value&&0===e.unref(D).messages.length?(e.openBlock(),e.createElementBlock("div",y,[...a[2]||(a[2]=[e.createElementVNode("div",{class:"custom-typing-indicator"},[e.createElementVNode("span"),e.createElementVNode("span"),e.createElementVNode("span")],-1),e.createElementVNode("p",null,"Initializing chat...",-1)])])):Z.value||0!==e.unref(D).messages.length?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",S,[a[3]||(a[3]=e.createElementVNode("div",{class:"custom-chat-empty-icon"},"👋",-1)),e.createElementVNode("p",null,e.toDisplayString(X.value.emptyStateMessage),1)])),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(D).messages,s=>{return e.openBlock(),e.createElementBlock("div",{key:s.id,class:e.normalizeClass(["custom-message",`custom-message-${s.sender}`,{"custom-handoff-message":re(s.text)}])},[e.createElementVNode("div",{class:e.normalizeClass(["custom-message-content",{"custom-handoff-content":re(s.text)}]),innerHTML:e.unref(t.safeLinkifyText)(s.text).replace(/\n/g,"<br>")},null,10,v),s.richContent&&Array.isArray(s.richContent)&&s.richContent.length>0?(e.openBlock(),e.createElementBlock("div",k,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.richContent,(t,s)=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:s},[Array.isArray(t)?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:1},e.renderList(t,(t,a)=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:`${s}-${a}`},["chips"===t.type&&t.options?(e.openBlock(),e.createElementBlock("div",b,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.options,(t,s)=>(e.openBlock(),e.createElementBlock("button",{key:s,class:"custom-chip-button",type:"button",onClick:e=>ce(t.text,t.payload)},e.toDisplayString(t.text),9,E))),128))])):e.createCommentVNode("",!0)],64))),128)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},["chips"===t.type&&t.options?(e.openBlock(),e.createElementBlock("div",C,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.options,(t,s)=>(e.openBlock(),e.createElementBlock("button",{key:s,class:"custom-chip-button",type:"button",onClick:e=>ce(t.text,t.payload)},e.toDisplayString(t.text),9,I))),128))])):e.createCommentVNode("",!0)],64))],64))),128))])):e.createCommentVNode("",!0),e.createElementVNode("div",T,e.toDisplayString((a=s.timestamp,a.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}))),1)],2);var a}),128)),e.unref(D).isLoading?(e.openBlock(),e.createElementBlock("div",_,[...a[4]||(a[4]=[e.createElementVNode("div",{class:"custom-typing-indicator"},[e.createElementVNode("span"),e.createElementVNode("span"),e.createElementVNode("span")],-1)])])):e.createCommentVNode("",!0),e.unref(te)?(e.openBlock(),e.createElementBlock("div",V,[...a[5]||(a[5]=[e.createElementVNode("div",{class:"custom-typing-indicator"},[e.createElementVNode("span"),e.createElementVNode("span"),e.createElementVNode("span")],-1),e.createElementVNode("div",{class:"custom-message-content"}," Connecting to agent... ",-1)])])):e.createCommentVNode("",!0),"human"===e.unref(D).chatMode&&e.unref(O)?(e.openBlock(),e.createElementBlock("div",B,[...a[6]||(a[6]=[e.createElementVNode("span",{class:"custom-typing-dots"},[e.createElementVNode("span"),e.createElementVNode("span"),e.createElementVNode("span")],-1),e.createElementVNode("span",{class:"custom-typing-text"},"Agent is typing...",-1)])])):e.createCommentVNode("",!0),e.createElementVNode("div",{ref_key:"messagesEndRef",ref:K},null,512)],512),e.createElementVNode("form",{class:"custom-chat-input-form",onSubmit:e.withModifiers(ie,["prevent"])},[e.createElementVNode("input",{type:"text",class:"custom-chat-input",value:e.unref(D).inputValue,onInput:oe,placeholder:X.value.inputPlaceholder,disabled:e.unref(D).isLoading||Z.value||ee.value},null,40,A),e.createElementVNode("button",{type:"submit",class:"custom-chat-send-btn",disabled:!e.unref(D).inputValue.trim()||e.unref(D).isLoading||Z.value||ee.value},[...a[7]||(a[7]=[e.createElementVNode("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[e.createElementVNode("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),e.createElementVNode("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})],-1)])],8,N)],32)])):e.createCommentVNode("",!0)],16))}}),[["__scopeId","data-v-11671761"]]);exports.ChatWidgetComponent=M,exports.WidgetStateManager=s,exports.useChatWidget=a;
2
+ //# sourceMappingURL=ChatWidget-DoVcxHqA.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatWidget-DoVcxHqA.cjs","sources":["../src/core/stateManager.ts","../src/composables/useChatWidget.ts","../src/components/ChatWidget.vue"],"sourcesContent":["/**\n * State Manager - Framework Agnostic\n * Manages widget state independently of framework\n */\n\nimport type { WidgetState, WidgetConfig, ChatMessage } from './types';\nimport {\n createDialogflowSession,\n sendDialogflowMessage,\n type DialogflowBackendConfig,\n} from '../services/dialogflowBackendService';\nimport { \n createChatService, \n ChatResolvedError,\n type WebSocketMessage\n} from '../services/chatService';\n\nexport class WidgetStateManager {\n private state: WidgetState;\n private config: WidgetConfig;\n private listeners: Set<(state: WidgetState) => void> = new Set();\n private chatMode: 'ai' | 'human' = 'ai';\n private chatId: string | null = null;\n private supportSessionId: string | null = null;\n private chatService: ReturnType<typeof createChatService> | null = null;\n \n // Additional state for human support\n private wsConnected: boolean = false;\n private agentTyping: boolean = false;\n private currentAgent: { name: string; id?: string } = { name: 'Agent' };\n private isConnectingToAgent: boolean = false;\n private agentAccepted: boolean = false;\n private chatResolved: boolean = false;\n private historyLoaded: string | null = null;\n \n // Typing timeout refs (stored as class properties since we can't use refs)\n private typingTimeout: NodeJS.Timeout | null = null;\n private agentTypingTimeout: NodeJS.Timeout | null = null;\n\n constructor(config: WidgetConfig) {\n this.config = config;\n this.state = {\n isOpen: false,\n showWelcomePopup: false,\n messages: [],\n inputValue: '',\n isLoading: false,\n error: null,\n sessionId: null,\n chatMode: 'ai',\n };\n \n // Initialize ChatService\n this.chatService = createChatService({\n baseUrl: this.config.backendBaseUrl || 'http://localhost:8012',\n wsUrl: this.config.backendWsUrl || 'ws://localhost:8012',\n debug: this.config.debug || false,\n });\n \n // Load chat mode and chat IDs from localStorage if available\n if (typeof window !== 'undefined' && window.localStorage) {\n const savedMode = localStorage.getItem('chartsconnectect_chat_mode');\n this.chatMode = savedMode === 'HUMAN' ? 'human' : 'ai';\n this.state.chatMode = this.chatMode;\n \n this.chatId = localStorage.getItem('chartsconnect_chat_id');\n this.supportSessionId = localStorage.getItem('chartsconnect_session_id');\n }\n }\n\n /**\n * Subscribe to state changes\n */\n subscribe(listener: (state: WidgetState) => void): () => void {\n this.listeners.add(listener);\n return () => {\n this.listeners.delete(listener);\n };\n }\n\n /**\n * Get current state\n */\n getState(): WidgetState {\n return { ...this.state };\n }\n\n /**\n * Update state and notify listeners\n */\n private setState(updates: Partial<WidgetState>): void {\n this.state = { ...this.state, ...updates };\n this.listeners.forEach(listener => listener(this.getState()));\n }\n\n /**\n * Update configuration\n */\n updateConfig(config: Partial<WidgetConfig>): void {\n this.config = { ...this.config, ...config };\n }\n\n /**\n * Open chat\n */\n async openChat(): Promise<void> {\n this.setState({ isOpen: true });\n if (this.state.showWelcomePopup) {\n this.setState({ showWelcomePopup: false });\n }\n \n // Initialize Dialogflow session when chat opens (if in AI mode and no session exists)\n if (this.state.chatMode === 'ai' && !this.state.sessionId && this.config.dfProjectId && this.config.dfAgentId) {\n try {\n this.setState({ isLoading: true });\n const dialogflowConfig: DialogflowBackendConfig = {\n dfProjectId: this.config.dfProjectId,\n dfLocation: this.config.dfLocation || 'us-central1',\n dfAgentId: this.config.dfAgentId,\n languageCode: this.config.languageCode || 'en',\n backendBaseUrl: this.config.backendBaseUrl || 'http://localhost:8012',\n };\n \n const session = await createDialogflowSession(dialogflowConfig);\n this.setState({ \n sessionId: session.session_id,\n isLoading: false,\n });\n \n // Add welcome message from Dialogflow if available\n if (session.message) {\n const welcomeMessage: ChatMessage = {\n id: `welcome-${Date.now()}`,\n text: session.message,\n sender: 'bot',\n timestamp: new Date(),\n richContent: session.richContent,\n };\n this.setState({\n messages: [welcomeMessage],\n });\n }\n } catch (error: any) {\n console.error('Error initializing Dialogflow session:', error);\n this.setState({ \n isLoading: false,\n error: error.message || 'Failed to initialize chat',\n });\n \n // Show fallback welcome message\n const fallbackMessage: ChatMessage = {\n id: `fallback-${Date.now()}`,\n text: this.config.fallbackWelcomeMessage || 'Hello! How can I help you today?',\n sender: 'bot',\n timestamp: new Date(),\n };\n this.setState({\n messages: [fallbackMessage],\n });\n }\n }\n }\n\n /**\n * Close chat\n */\n closeChat(): void {\n this.setState({ isOpen: false });\n }\n\n /**\n * Close welcome popup\n */\n closeWelcomePopup(): void {\n this.setState({ showWelcomePopup: false });\n }\n\n /**\n * Toggle chat\n */\n toggleChat(): void {\n const willBeOpen = !this.state.isOpen;\n this.setState({ isOpen: willBeOpen });\n if (willBeOpen && this.state.showWelcomePopup) {\n this.setState({ showWelcomePopup: false });\n }\n }\n\n /**\n * Set input value\n */\n setInputValue(value: string): void {\n this.setState({ inputValue: value });\n }\n\n /**\n * Clear error\n */\n clearError(): void {\n this.setState({ error: null });\n }\n\n /**\n * Send message\n */\n async sendMessage(text: string, skipUserMessage: boolean = false): Promise<void> {\n if (!text.trim() || this.state.isLoading) {\n return;\n }\n\n // Add user message unless skipped (e.g., when chip button already added it)\n if (!skipUserMessage) {\n const userMessage: ChatMessage = {\n id: `user-${Date.now()}`,\n text: text.trim(),\n sender: 'user',\n timestamp: new Date(),\n };\n\n this.setState({\n messages: [...this.state.messages, userMessage],\n inputValue: '',\n isLoading: true,\n error: null,\n });\n } else {\n this.setState({\n inputValue: '',\n isLoading: true,\n error: null,\n });\n }\n\n try {\n if (this.state.chatMode === 'human') {\n // Human support mode\n await this.sendHumanMessage(text);\n } else {\n // AI mode (Dialogflow)\n await this.sendAIMessage(text);\n }\n } catch (error: any) {\n console.error('Error sending message:', error);\n \n // chat_resolved is a normal terminal condition, not an error\n if (error instanceof ChatResolvedError || error?.name === 'ChatResolvedError' || error?.message === 'chat_resolved') {\n this.enterResolvedState(this.chatId);\n return;\n }\n \n // Add error message to chat\n const errorMessage: ChatMessage = {\n id: `error-${Date.now()}`,\n text: this.config.debug \n ? `Error: ${error.message || 'Failed to send message'}`\n : error.message?.includes('CORS') || error.message?.includes('Failed to fetch')\n ? 'Unable to connect to Dialogflow. Please check your configuration and network.'\n : 'Sorry, I\\'m having trouble processing your message. Please try again.',\n sender: 'bot',\n timestamp: new Date(),\n };\n \n this.setState({\n messages: [...this.state.messages, errorMessage],\n error: error.message || 'Failed to send message',\n isLoading: false,\n });\n }\n }\n\n /**\n * Send message to Dialogflow\n */\n private async sendAIMessage(text: string): Promise<void> {\n if (!this.config.dfProjectId || !this.config.dfAgentId) {\n throw new Error('Dialogflow configuration is missing');\n }\n\n const dialogflowConfig: DialogflowBackendConfig = {\n dfProjectId: this.config.dfProjectId!,\n dfLocation: this.config.dfLocation || 'us-central1',\n dfAgentId: this.config.dfAgentId!,\n languageCode: this.config.languageCode || 'en',\n backendBaseUrl: this.config.backendBaseUrl || 'http://localhost:8012',\n };\n\n // Create session if needed\n if (!this.state.sessionId) {\n const session = await createDialogflowSession(dialogflowConfig);\n this.setState({ sessionId: session.session_id });\n }\n\n // Send message (correct parameter order: message, sessionId, config)\n if (this.config.debug) {\n console.log('Sending message to Dialogflow:', {\n message: text,\n sessionId: this.state.sessionId,\n hasConfig: !!dialogflowConfig,\n });\n }\n \n const response = await sendDialogflowMessage(\n text,\n this.state.sessionId!,\n dialogflowConfig\n );\n\n if (this.config.debug) {\n console.log('Dialogflow response:', {\n response: response.response,\n hasRichContent: !!response.richContent,\n richContent: response.richContent,\n });\n }\n\n // Check for handoff\n if (response.handoff === true) {\n // Add bot response first\n const botMessage: ChatMessage = {\n id: `bot-${Date.now()}`,\n text: response.response || this.config.fallbackWelcomeMessage || 'No response',\n sender: 'bot',\n timestamp: new Date(),\n richContent: response.richContent,\n };\n this.setState({\n messages: [...this.state.messages, botMessage],\n isLoading: false,\n });\n \n // Proceed directly with handoff — user details collected by Dialogflow via webhook\n await this.handleHandoff();\n return;\n }\n \n const botMessage: ChatMessage = {\n id: `bot-${Date.now()}`,\n text: response.response || this.config.fallbackWelcomeMessage || 'No response',\n sender: 'bot',\n timestamp: new Date(),\n richContent: response.richContent,\n };\n\n this.setState({\n messages: [...this.state.messages, botMessage],\n isLoading: false,\n });\n }\n\n /**\n * Send message to human support\n */\n private async sendHumanMessage(text: string): Promise<void> {\n if (!this.chatId || !this.supportSessionId) {\n const errorMessage: ChatMessage = {\n id: `error-${Date.now()}`,\n text: 'Chat session not initialized. Please try again.',\n sender: 'bot',\n timestamp: new Date(),\n };\n this.setState({\n messages: [...this.state.messages, errorMessage],\n isLoading: false,\n });\n return;\n }\n\n if (!this.chatService) {\n throw new Error('Chat service not initialized');\n }\n\n // Send typing_stop before sending message\n this.chatService.sendTypingIndicator('typing_stop');\n if (this.typingTimeout) {\n clearTimeout(this.typingTimeout);\n this.typingTimeout = null;\n }\n\n try {\n // Try WebSocket first, fallback to REST API\n const sentViaWs = this.chatService.sendMessageViaWebSocket(text.trim());\n \n if (!sentViaWs) {\n // Fallback to REST API\n await this.chatService.sendMessageToAgent(this.chatId, this.supportSessionId, text.trim());\n }\n \n this.setState({ isLoading: false });\n } catch (error: any) {\n // chat_resolved is a normal terminal condition, not an error\n if (error instanceof ChatResolvedError || error?.name === 'ChatResolvedError' || error?.message === 'chat_resolved') {\n this.enterResolvedState(this.chatId);\n return;\n }\n\n // Handle 401/404 - clear chat_id and reinitialize\n if (error.message?.includes('Chat not found') ||\n error.message?.includes('unauthorized') ||\n error.message?.includes('401') ||\n error.message?.includes('404')) {\n if (this.config.debug) {\n console.log('⚠️ Chat expired. Re-initializing...');\n }\n \n // Clear chat_id\n this.chatId = null;\n this.supportSessionId = null;\n if (typeof window !== 'undefined' && window.localStorage) {\n localStorage.removeItem('chartsconnect_chat_id');\n localStorage.removeItem('chartsconnect_session_id');\n }\n \n // Try to reinitialize chat\n try {\n const newSession = await this.chatService.startSupportChat(\n this.state.sessionId || null\n );\n this.chatId = newSession.chat_id;\n this.supportSessionId = newSession.session_id;\n if (typeof window !== 'undefined' && window.localStorage) {\n localStorage.setItem('chartsconnect_chat_id', this.chatId);\n localStorage.setItem('chartsconnect_session_id', this.supportSessionId);\n }\n \n // Retry sending message\n if (this.chatId && this.supportSessionId) {\n await this.chatService.sendMessageToAgent(\n this.chatId,\n this.supportSessionId,\n text.trim()\n );\n }\n this.setState({ isLoading: false });\n return;\n } catch (retryError: any) {\n if (retryError instanceof ChatResolvedError || retryError?.message === 'chat_resolved') {\n this.enterResolvedState(this.chatId);\n return;\n }\n throw retryError;\n }\n } else {\n throw error;\n }\n }\n }\n\n /**\n * Switch to human mode\n */\n switchToHumanMode(): void {\n this.chatMode = 'human';\n this.setState({ chatMode: 'human' });\n if (typeof window !== 'undefined' && window.localStorage) {\n localStorage.setItem('chartsconnect_chat_mode', 'HUMAN');\n }\n }\n\n /**\n * Switch to AI mode\n */\n switchToBotMode(): void {\n this.chatMode = 'ai';\n this.setState({ chatMode: 'ai' });\n if (typeof window !== 'undefined' && window.localStorage) {\n localStorage.setItem('chartsconnect_chat_mode', 'BOT');\n }\n }\n\n /**\n * Initialize welcome popup\n */\n initializeWelcomePopup(): void {\n if (this.config.showWelcomePopup !== false) {\n const delay = this.config.welcomePopupDelay || 1500;\n setTimeout(() => {\n if (!this.state.isOpen) {\n this.setState({ showWelcomePopup: true });\n }\n }, delay);\n }\n }\n\n /**\n * Handle handoff from Dialogflow to human support\n */\n async handleHandoff(): Promise<void> {\n if (!this.chatService) {\n throw new Error('Chat service not initialized');\n }\n\n try {\n this.isConnectingToAgent = true;\n \n // Get Dialogflow session ID if available\n const dialogflowSessionId = this.state.sessionId;\n \n // STEP 1: Ensure chat is initialized\n const session = await this.chatService.ensureChatInitialized(\n this.chatId,\n this.supportSessionId,\n dialogflowSessionId || null\n );\n \n if (!session || !session.chat_id) {\n throw new Error('Failed to initialize chat session');\n }\n \n const currentChatId = session.chat_id;\n const currentSupportSessionId = session.session_id;\n \n // Update state if chat was newly initialized\n if (currentChatId !== this.chatId) {\n this.chatId = currentChatId;\n this.supportSessionId = currentSupportSessionId;\n if (typeof window !== 'undefined' && window.localStorage) {\n localStorage.setItem('chartsconnect_chat_id', this.chatId);\n localStorage.setItem('chartsconnect_session_id', this.supportSessionId);\n }\n if (this.config.debug) {\n console.log('✅ Chat initialized:', { chatId: currentChatId, sessionId: currentSupportSessionId });\n }\n }\n\n // STEP 2: Request handoff\n try {\n await this.chatService.requestHandoff(\n currentChatId,\n currentSupportSessionId,\n 'Customer requested human agent',\n dialogflowSessionId || null\n );\n \n if (this.config.debug) {\n console.log('✅ Handoff requested successfully');\n }\n } catch (handoffError: any) {\n // Handle 401/404 or \"chat not found\" - clear chat_id and retry\n if (handoffError.message?.includes('Invalid chat_id') || \n handoffError.message?.includes('Chat not found') ||\n handoffError.message?.includes('unauthorized') ||\n handoffError.message?.includes('400') ||\n handoffError.message?.includes('401') ||\n handoffError.message?.includes('404') ||\n handoffError.message?.includes('expired')) {\n if (this.config.debug) {\n console.log('⚠️ Chat expired or not found. Re-initializing chat...');\n }\n \n // Clear old chat_id\n this.chatId = null;\n this.supportSessionId = null;\n if (typeof window !== 'undefined' && window.localStorage) {\n localStorage.removeItem('chartsconnect_chat_id');\n localStorage.removeItem('chartsconnect_session_id');\n }\n \n // Create new chat session\n const newSession = await this.chatService.startSupportChat(\n dialogflowSessionId || null\n );\n \n if (!newSession || !newSession.chat_id) {\n throw new Error('Failed to re-initialize chat session');\n }\n \n this.chatId = newSession.chat_id;\n this.supportSessionId = newSession.session_id;\n if (typeof window !== 'undefined' && window.localStorage) {\n localStorage.setItem('chartsconnect_chat_id', this.chatId);\n localStorage.setItem('chartsconnect_session_id', this.supportSessionId);\n }\n \n // Retry handoff with new chat_id\n await this.chatService.requestHandoff(\n this.chatId,\n this.supportSessionId,\n 'Customer requested human agent',\n dialogflowSessionId || null\n );\n \n if (this.config.debug) {\n console.log('✅ Handoff requested successfully after retry');\n }\n } else {\n throw handoffError;\n }\n }\n\n // Switch to human mode\n this.switchToHumanMode();\n this.chatResolved = false;\n this.agentAccepted = false;\n\n // Add connecting message\n const connectingMessage: ChatMessage = {\n id: `connecting-${Date.now()}`,\n text: 'Connecting you to a human agent...',\n sender: 'bot',\n timestamp: new Date(),\n };\n this.setState({\n messages: [...this.state.messages, connectingMessage],\n });\n\n // Connect WebSocket with handlers\n if (currentChatId && currentSupportSessionId) {\n this.chatService.connectWebSocket(\n currentChatId,\n currentSupportSessionId,\n (message: WebSocketMessage) => {\n this.handleWebSocketMessage(message);\n },\n (connected: boolean) => {\n this.wsConnected = connected;\n }\n );\n }\n \n this.isConnectingToAgent = false;\n } catch (error: any) {\n console.error('Error handling handoff:', error);\n const errorMessage: ChatMessage = {\n id: `error-${Date.now()}`,\n text: this.config.debug\n ? `Handoff error: ${error.message}`\n : 'Failed to connect to agent. Please try again.',\n sender: 'bot',\n timestamp: new Date(),\n };\n this.setState({\n messages: [...this.state.messages, errorMessage],\n });\n this.isConnectingToAgent = false;\n }\n }\n\n /**\n * Handle WebSocket messages\n */\n private handleWebSocketMessage(message: WebSocketMessage): void {\n switch (message.type) {\n case 'message':\n if (message.content) {\n // Only display messages from agent\n if (message.sender_type === 'agent' || !message.sender_type) {\n const agentMessage: ChatMessage = {\n id: message.id || `agent-${Date.now()}`,\n text: message.content,\n sender: 'agent',\n timestamp: new Date(message.timestamp || Date.now()),\n };\n \n // Avoid duplicate messages\n const existingIds = new Set(this.state.messages.map(m => m.id));\n if (!existingIds.has(agentMessage.id)) {\n this.setState({\n messages: [...this.state.messages, agentMessage],\n });\n }\n \n // Hide typing indicator when message received\n this.agentTyping = false;\n if (this.agentTypingTimeout) {\n clearTimeout(this.agentTypingTimeout);\n this.agentTypingTimeout = null;\n }\n }\n }\n break;\n\n case 'typing_start':\n if (message.sender_type === 'agent') {\n this.agentTyping = true;\n // Auto-hide after 3 seconds if no message received\n if (this.agentTypingTimeout) {\n clearTimeout(this.agentTypingTimeout);\n }\n this.agentTypingTimeout = setTimeout(() => {\n this.agentTyping = false;\n }, 3000);\n }\n break;\n\n case 'typing_stop':\n if (message.sender_type === 'agent') {\n this.agentTyping = false;\n if (this.agentTypingTimeout) {\n clearTimeout(this.agentTypingTimeout);\n this.agentTypingTimeout = null;\n }\n }\n break;\n\n case 'agent_changed':\n if (message.to_agent) {\n this.currentAgent = {\n id: message.to_agent_id,\n name: message.to_agent,\n };\n\n // Add system message to chat\n const systemMessage: ChatMessage = {\n id: `system-${Date.now()}`,\n text: message.from_agent\n ? `Chat has been transferred from ${message.from_agent} to ${message.to_agent}`\n : `Chat has been transferred to ${message.to_agent}`,\n sender: 'bot',\n timestamp: new Date(),\n };\n this.setState({\n messages: [...this.state.messages, systemMessage],\n });\n }\n break;\n\n case 'agent_accepted':\n this.agentAccepted = true;\n this.isConnectingToAgent = false;\n const acceptedMessage: ChatMessage = {\n id: message.id || `agent-accepted-${Date.now()}`,\n text: 'You can chat now, the agent has accepted your request.',\n sender: 'bot',\n timestamp: message.timestamp ? new Date(message.timestamp) : new Date(),\n };\n const existingIds = new Set(this.state.messages.map(m => m.id));\n if (!existingIds.has(acceptedMessage.id)) {\n this.setState({\n messages: [...this.state.messages, acceptedMessage],\n });\n }\n if (message.to_agent) {\n this.currentAgent = {\n name: message.to_agent,\n id: message.to_agent_id,\n };\n }\n break;\n\n case 'chat_resolved':\n case 'chat_ended':\n this.enterResolvedState(message.chat_id || null);\n break;\n\n case 'chat_info':\n if (message.status === 'active') {\n this.isConnectingToAgent = false;\n this.agentAccepted = true;\n } else if (message.status === 'resolved' || message.status === 'ended') {\n this.enterResolvedState(message.chat_id || null);\n }\n if (message.agent_id) {\n this.currentAgent = {\n ...this.currentAgent,\n id: message.agent_id,\n };\n }\n break;\n\n case 'error':\n console.error('WebSocket error:', message.error);\n const errorMessage: ChatMessage = {\n id: `error-${Date.now()}`,\n text: message.error || 'An error occurred. Please try again.',\n sender: 'bot',\n timestamp: new Date(),\n };\n this.setState({\n messages: [...this.state.messages, errorMessage],\n });\n break;\n }\n }\n\n /**\n * Enter resolved state\n */\n private enterResolvedState(resolvedChatId?: string | null): void {\n this.chatResolved = true;\n this.isConnectingToAgent = false;\n this.agentAccepted = false;\n this.agentTyping = false;\n if (this.agentTypingTimeout) {\n clearTimeout(this.agentTypingTimeout);\n this.agentTypingTimeout = null;\n }\n\n // Stop WS + prevent any reuse of the old chat_id\n if (this.chatService) {\n this.chatService.disconnectWebSocket();\n }\n this.chatId = null;\n this.supportSessionId = null;\n if (typeof window !== 'undefined' && window.localStorage) {\n localStorage.removeItem('chartsconnect_chat_id');\n localStorage.removeItem('chartsconnect_session_id');\n }\n \n // Add thank you message before reset\n const thankYouMessage: ChatMessage = {\n id: `resolved-${Date.now()}`,\n text: 'Thank you for contacting us!',\n sender: 'bot',\n timestamp: new Date(),\n };\n this.setState({\n messages: [...this.state.messages, thankYouMessage],\n });\n \n // Automatically reset to BOT mode after showing thank you message\n setTimeout(async () => {\n this.switchToBotMode();\n this.chatResolved = false;\n this.setState({\n messages: [],\n sessionId: null, // Clear session ID to force recreation\n });\n // Recreate Dialogflow session to start fresh\n if (this.config.dfProjectId && this.config.dfAgentId && this.state.isOpen) {\n try {\n this.setState({ isLoading: true });\n const dialogflowConfig: DialogflowBackendConfig = {\n dfProjectId: this.config.dfProjectId,\n dfLocation: this.config.dfLocation || 'us-central1',\n dfAgentId: this.config.dfAgentId,\n languageCode: this.config.languageCode || 'en',\n backendBaseUrl: this.config.backendBaseUrl || 'http://localhost:8012',\n };\n \n const session = await createDialogflowSession(dialogflowConfig);\n this.setState({ \n sessionId: session.session_id,\n isLoading: false,\n });\n \n // Add welcome message from Dialogflow if available\n if (session.message) {\n const welcomeMessage: ChatMessage = {\n id: `welcome-${Date.now()}`,\n text: session.message,\n sender: 'bot',\n timestamp: new Date(),\n richContent: session.richContent,\n };\n this.setState({\n messages: [welcomeMessage],\n });\n }\n } catch (error: any) {\n console.error('Error recreating Dialogflow session after handoff:', error);\n this.setState({ \n isLoading: false,\n error: error.message || 'Failed to initialize chat',\n });\n \n // Show fallback welcome message\n const fallbackMessage: ChatMessage = {\n id: `fallback-${Date.now()}`,\n text: this.config.fallbackWelcomeMessage || 'Hello! How can I help you today?',\n sender: 'bot',\n timestamp: new Date(),\n };\n this.setState({\n messages: [fallbackMessage],\n });\n }\n }\n }, 2000);\n }\n\n /**\n * Load message history\n */\n async loadMessageHistory(preserveExisting: boolean = false): Promise<void> {\n if (!this.chatService || !this.chatId || !this.supportSessionId) {\n return;\n }\n\n try {\n if (this.chatId && this.supportSessionId) {\n const history = await this.chatService.loadMessageHistory(this.chatId, this.supportSessionId);\n \n const historyMessages: ChatMessage[] = history.map((msg: any) => ({\n id: msg.id || `history-${Date.now()}-${Math.random()}`,\n text: msg.content,\n sender: msg.sender_type === 'agent' ? 'agent' : 'user',\n timestamp: new Date(msg.timestamp),\n }));\n\n if (preserveExisting) {\n // Merge with existing messages, avoiding duplicates\n const existingIds = new Set(this.state.messages.map(m => m.id));\n const newMessages = historyMessages.filter(m => !existingIds.has(m.id));\n \n // Combine existing messages with new history messages\n // Sort by timestamp to maintain chronological order\n const combined = [...this.state.messages, ...newMessages].sort((a, b) => \n a.timestamp.getTime() - b.timestamp.getTime()\n );\n \n this.setState({\n messages: combined,\n });\n } else {\n // Replace all messages\n this.setState({\n messages: historyMessages,\n });\n }\n }\n } catch (error: any) {\n console.error('Error loading message history:', error);\n if (this.config.debug) {\n const errorMessage: ChatMessage = {\n id: `error-${Date.now()}`,\n text: `Failed to load chat history: ${error.message}`,\n sender: 'bot',\n timestamp: new Date(),\n };\n this.setState({\n messages: [...this.state.messages, errorMessage],\n });\n }\n }\n }\n\n /**\n * Get additional state for UI (not in WidgetState but needed by components)\n */\n getAdditionalState() {\n return {\n wsConnected: this.wsConnected,\n agentTyping: this.agentTyping,\n currentAgent: this.currentAgent,\n isConnectingToAgent: this.isConnectingToAgent,\n agentAccepted: this.agentAccepted,\n chatResolved: this.chatResolved,\n };\n }\n\n /**\n * Cleanup\n */\n destroy(): void {\n if (this.typingTimeout) {\n clearTimeout(this.typingTimeout);\n }\n if (this.agentTypingTimeout) {\n clearTimeout(this.agentTypingTimeout);\n }\n if (this.chatService) {\n this.chatService.disconnectWebSocket();\n }\n this.listeners.clear();\n }\n}\n","/**\n * useChatWidget Composable\n * Headless mode for Vue 3 - use logic without UI\n */\n\nimport { ref, computed, onUnmounted, watch, readonly, type Ref } from 'vue';\nimport { WidgetStateManager } from '../core/stateManager';\nimport type { WidgetConfig, WidgetState, ChatMessage } from '../core/types';\n\nexport interface UseChatWidgetReturn {\n // State\n state: Readonly<Ref<WidgetState>>;\n isOpen: Readonly<Ref<boolean>>;\n messages: Readonly<Ref<ChatMessage[]>>;\n isLoading: Readonly<Ref<boolean>>;\n error: Readonly<Ref<string | null>>;\n chatMode: Readonly<Ref<'ai' | 'human'>>;\n\n // Additional state\n wsConnected: Readonly<Ref<boolean>>;\n agentTyping: Readonly<Ref<boolean>>;\n currentAgent: Readonly<Ref<{ name: string; id?: string }>>;\n isConnectingToAgent: Readonly<Ref<boolean>>;\n\n // Actions\n openChat: () => Promise<void>;\n closeChat: () => void;\n sendMessage: (text: string) => Promise<void>;\n toggleChat: () => Promise<void>;\n setInputValue: (value: string) => void;\n clearError: () => void;\n\n // Manager instance (for advanced usage)\n manager: WidgetStateManager;\n}\n\n/**\n * Headless chat widget composable\n * Use this for custom UI implementations\n */\nexport function useChatWidget(config: WidgetConfig): UseChatWidgetReturn {\n // Create state manager\n const manager = new WidgetStateManager(config);\n\n // Reactive state\n const state = ref<WidgetState>(manager.getState());\n const wsConnected = ref(false);\n const agentTyping = ref(false);\n const currentAgent = ref<{ name: string; id?: string }>({ name: 'Agent' });\n const isConnectingToAgent = ref(false);\n\n // Subscribe to state changes\n const unsubscribe = manager.subscribe((newState) => {\n state.value = { ...newState };\n \n // Update additional state\n const additional = manager.getAdditionalState();\n wsConnected.value = additional.wsConnected;\n agentTyping.value = additional.agentTyping;\n currentAgent.value = additional.currentAgent;\n isConnectingToAgent.value = additional.isConnectingToAgent;\n });\n\n // Computed properties\n const isOpen = computed(() => state.value.isOpen);\n const messages = computed(() => state.value.messages);\n const isLoading = computed(() => state.value.isLoading);\n const error = computed(() => state.value.error);\n const chatMode = computed(() => state.value.chatMode);\n\n // Actions\n const openChat = async () => {\n await manager.openChat();\n };\n\n const closeChat = () => {\n manager.closeChat();\n };\n\n const sendMessage = async (text: string) => {\n await manager.sendMessage(text);\n };\n\n const toggleChat = async () => {\n await manager.toggleChat();\n };\n\n const setInputValue = (value: string) => {\n manager.setInputValue(value);\n };\n\n const clearError = () => {\n manager.clearError();\n };\n\n // Cleanup on unmount\n onUnmounted(() => {\n unsubscribe();\n manager.destroy();\n });\n\n // Watch config changes\n watch(\n () => config,\n (newConfig) => {\n manager.updateConfig(newConfig);\n },\n { deep: true }\n );\n\n return {\n state: state as Readonly<Ref<WidgetState>>,\n isOpen: isOpen as Readonly<Ref<boolean>>,\n messages: messages as Readonly<Ref<ChatMessage[]>>,\n isLoading: isLoading as Readonly<Ref<boolean>>,\n error: error as Readonly<Ref<string | null>>,\n chatMode: chatMode as Readonly<Ref<'ai' | 'human'>>,\n wsConnected: wsConnected as Readonly<Ref<boolean>>,\n agentTyping: agentTyping as Readonly<Ref<boolean>>,\n currentAgent: currentAgent as Readonly<Ref<{ name: string; id?: string }>>,\n isConnectingToAgent: isConnectingToAgent as Readonly<Ref<boolean>>,\n openChat,\n closeChat,\n sendMessage,\n toggleChat,\n setInputValue,\n clearError,\n manager,\n };\n}\n","<template>\n <div class=\"custom-chat-widget\" v-bind=\"$attrs\">\n <!-- Welcome Popup -->\n <div\n v-if=\"state.showWelcomePopup && !state.isOpen\"\n class=\"custom-welcome-popup\"\n @click=\"handleOpenChat\"\n >\n <div class=\"custom-welcome-header\">\n <div class=\"custom-welcome-title\">{{ config.welcomeTitle }}</div>\n <button\n class=\"custom-close-popup\"\n @click.stop=\"handleCloseWelcomePopup\"\n aria-label=\"Close welcome popup\"\n >\n ×\n </button>\n </div>\n <div class=\"custom-welcome-message\">{{ config.welcomeMessage }}</div>\n <div class=\"custom-welcome-cta\">{{ config.welcomeCta }}</div>\n </div>\n\n <!-- Chat Toggle Button -->\n <button\n v-if=\"!state.isOpen\"\n class=\"custom-chat-toggle-btn\"\n @click=\"handleOpenChat\"\n aria-label=\"Open chat\"\n >\n <svg\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n >\n <path d=\"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z\"></path>\n </svg>\n </button>\n\n <!-- Chat Window -->\n <div v-if=\"state.isOpen\" class=\"custom-chat-window\">\n <div class=\"custom-chat-header\">\n <div class=\"custom-chat-header-content\">\n <div class=\"custom-chat-title\">{{ config.title }}</div>\n <div class=\"custom-chat-subtitle\">\n {{ config.subtitle }}\n <span v-if=\"state.chatMode === 'human'\" class=\"custom-mode-indicator\">\n • {{ wsConnected ? '🟢 Connected' : '🟡 Connecting...' }}\n </span>\n </div>\n <div v-if=\"state.chatMode === 'human'\" class=\"custom-mode-badge\">\n Human Support Mode\n </div>\n <div v-if=\"state.chatMode === 'human'\" class=\"custom-agent-info\">\n <span class=\"custom-agent-label\">Agent:</span>\n <span class=\"custom-agent-name\">{{ currentAgent.name }}</span>\n </div>\n <div v-if=\"state.chatMode === 'ai'\" class=\"custom-mode-badge\">\n Bot Mode\n </div>\n </div>\n <button\n class=\"custom-chat-close-btn\"\n @click=\"handleCloseChat\"\n aria-label=\"Close chat\"\n >\n ×\n </button>\n </div>\n\n <div class=\"custom-chat-messages\" ref=\"messagesContainer\">\n <!-- Empty State -->\n <div v-if=\"isInitializing && state.messages.length === 0\" class=\"custom-chat-empty\">\n <div class=\"custom-typing-indicator\">\n <span></span>\n <span></span>\n <span></span>\n </div>\n <p>Initializing chat...</p>\n </div>\n <div v-else-if=\"!isInitializing && state.messages.length === 0\" class=\"custom-chat-empty\">\n <div class=\"custom-chat-empty-icon\">👋</div>\n <p>{{ config.emptyStateMessage }}</p>\n </div>\n\n <!-- Messages -->\n <div\n v-for=\"message in state.messages\"\n :key=\"message.id\"\n :class=\"[\n 'custom-message', \n `custom-message-${message.sender}`,\n { 'custom-handoff-message': isHandoffMessage(message.text) }\n ]\"\n >\n <div \n class=\"custom-message-content\"\n :class=\"{ 'custom-handoff-content': isHandoffMessage(message.text) }\"\n v-html=\"safeLinkifyText(message.text).replace(/\\n/g, '<br>')\"\n ></div>\n \n <!-- Rich Content (Chips) -->\n <div\n v-if=\"message.richContent && Array.isArray(message.richContent) && message.richContent.length > 0\"\n class=\"custom-chips-container\"\n >\n <template v-for=\"(contentGroup, groupIndex) in message.richContent\" :key=\"groupIndex\">\n <template v-if=\"!Array.isArray(contentGroup)\">\n <div\n v-if=\"contentGroup.type === 'chips' && contentGroup.options\"\n class=\"custom-chips-group\"\n >\n <button\n v-for=\"(chip, chipIndex) in contentGroup.options\"\n :key=\"chipIndex\"\n class=\"custom-chip-button\"\n type=\"button\"\n @click=\"handleChipClick(chip.text, chip.payload)\"\n >\n {{ chip.text }}\n </button>\n </div>\n </template>\n <template v-else>\n <template\n v-for=\"(content, contentIndex) in contentGroup\"\n :key=\"`${groupIndex}-${contentIndex}`\"\n >\n <div\n v-if=\"content.type === 'chips' && content.options\"\n class=\"custom-chips-group\"\n >\n <button\n v-for=\"(chip, chipIndex) in content.options\"\n :key=\"chipIndex\"\n class=\"custom-chip-button\"\n type=\"button\"\n @click=\"handleChipClick(chip.text, chip.payload)\"\n >\n {{ chip.text }}\n </button>\n </div>\n </template>\n </template>\n </template>\n </div>\n\n <div class=\"custom-message-time\">\n {{ formatTime(message.timestamp) }}\n </div>\n </div>\n\n <!-- Loading Indicator -->\n <div v-if=\"state.isLoading\" class=\"custom-message custom-message-bot\">\n <div class=\"custom-typing-indicator\">\n <span></span>\n <span></span>\n <span></span>\n </div>\n </div>\n\n <!-- Connecting to Agent Indicator -->\n <div v-if=\"isConnectingToAgent\" class=\"custom-message custom-message-bot\">\n <div class=\"custom-typing-indicator\">\n <span></span>\n <span></span>\n <span></span>\n </div>\n <div class=\"custom-message-content\">\n Connecting to agent...\n </div>\n </div>\n\n <!-- Agent Typing Indicator -->\n <div v-if=\"state.chatMode === 'human' && agentTyping\" class=\"custom-agent-typing-indicator\">\n <span class=\"custom-typing-dots\">\n <span></span>\n <span></span>\n <span></span>\n </span>\n <span class=\"custom-typing-text\">Agent is typing...</span>\n </div>\n\n <div ref=\"messagesEndRef\"></div>\n </div>\n\n <!-- Input Form -->\n <form class=\"custom-chat-input-form\" @submit.prevent=\"handleSubmit\">\n <input\n type=\"text\"\n class=\"custom-chat-input\"\n :value=\"state.inputValue\"\n @input=\"handleInput\"\n :placeholder=\"config.inputPlaceholder\"\n :disabled=\"state.isLoading || isInitializing || isStartingNewChat\"\n />\n <button\n type=\"submit\"\n class=\"custom-chat-send-btn\"\n :disabled=\"!state.inputValue.trim() || state.isLoading || isInitializing || isStartingNewChat\"\n >\n <svg\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n >\n <line x1=\"22\" y1=\"2\" x2=\"11\" y2=\"13\"></line>\n <polygon points=\"22 2 15 22 11 13 2 9 22 2\"></polygon>\n </svg>\n </button>\n </form>\n </div>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { ref, computed, onMounted, nextTick, watch } from 'vue';\nimport { useChatWidget } from '../composables/useChatWidget';\nimport { safeLinkifyText } from '../utils/sanitize';\nimport type { WidgetConfig } from '../core/types';\n\n// Handle attributes properly to avoid Vue warnings\n// For Vue 3.3+, defineOptions is available as a compiler macro\n// @ts-ignore - defineOptions is a compiler macro\ndefineOptions({\n inheritAttrs: false, // We handle attrs manually via v-bind=\"$attrs\"\n});\n\n// Props\nconst props = withDefaults(defineProps<WidgetConfig>(), {\n title: '💬 Charts Connect AI Assistant',\n subtitle: \"We're here to help\",\n welcomeTitle: '👋 Welcome to Charts Connect',\n welcomeMessage: \"My name is Charts Connect AI Assistant and I'll guide you.\",\n welcomeCta: '💬 Click here to start chatting!',\n showWelcomePopup: true,\n welcomePopupDelay: 1500,\n fallbackWelcomeMessage: \"Hello! I'm Charts Connect AI Assistant. How can I help you today?\",\n inputPlaceholder: 'Type your message...',\n emptyStateMessage: \"Hi! I'm Charts Connect AI Assistant. How can I help you today?\",\n debug: false,\n});\n\n// Use headless composable\nconst {\n state,\n isOpen,\n messages,\n isLoading,\n error,\n chatMode,\n wsConnected,\n agentTyping,\n currentAgent,\n isConnectingToAgent: isConnectingToAgentFromComposable,\n openChat,\n closeChat,\n sendMessage,\n toggleChat,\n setInputValue,\n clearError,\n manager,\n} = useChatWidget(props);\n\n// Refs\nconst messagesEndRef = ref<HTMLDivElement | null>(null);\nconst messagesContainer = ref<HTMLDivElement | null>(null);\n\n// Computed config (for reactivity)\nconst config = computed(() => props);\n\n// Computed state for initialization and connection (matching React component)\nconst isInitializing = computed(() => {\n return state.value.isLoading && state.value.messages.length === 0 && !state.value.sessionId;\n});\n\nconst isStartingNewChat = computed(() => {\n // This would be tracked in manager if needed, for now return false\n return false;\n});\n\n// Use isConnectingToAgent from composable (already computed in manager)\nconst isConnectingToAgent = isConnectingToAgentFromComposable;\n\n// Auto-scroll to bottom when messages change\nwatch(\n () => messages.value.length,\n () => {\n nextTick(() => {\n messagesEndRef.value?.scrollIntoView({ behavior: 'smooth' });\n });\n }\n);\n\n// Handlers\nconst handleOpenChat = async () => {\n // Ensure immediate UI response\n if (!state.value.isOpen) {\n state.value.isOpen = true;\n state.value.showWelcomePopup = false;\n }\n await openChat();\n};\n\nconst handleCloseChat = () => {\n closeChat();\n};\n\nconst handleCloseWelcomePopup = () => {\n manager.closeWelcomePopup();\n};\n\nconst handleInput = (event: Event) => {\n const target = event.target as HTMLInputElement;\n setInputValue(target.value);\n};\n\nconst handleSubmit = async (event: Event) => {\n event.preventDefault();\n if (state.value.inputValue.trim()) {\n await sendMessage(state.value.inputValue);\n }\n};\n\nconst handleChipClick = async (chipText: string, payload?: string) => {\n const messageToSend = chipText || payload || '';\n await sendMessage(messageToSend);\n};\n\n// Utility functions\nconst formatTime = (date: Date): string => {\n return date.toLocaleTimeString([], {\n hour: '2-digit',\n minute: '2-digit',\n });\n};\n\n// Check if message is a handoff message\nconst isHandoffMessage = (text: string): boolean => {\n return text.includes('👤') || \n text.includes('being connected') || \n text.includes('live support agent') ||\n text.includes('transfer your conversation');\n};\n\n// Initialize welcome popup on mount (SSR-safe)\nonMounted(() => {\n if (config.value.showWelcomePopup && typeof window !== 'undefined') {\n manager.initializeWelcomePopup();\n }\n});\n</script>\n\n<style scoped>\n/* Styles are imported separately by users */\n/* This ensures SSR compatibility */\n</style>\n"],"names":["WidgetStateManager","constructor","config","this","listeners","Set","chatMode","chatId","supportSessionId","chatService","wsConnected","agentTyping","currentAgent","name","isConnectingToAgent","agentAccepted","chatResolved","historyLoaded","typingTimeout","agentTypingTimeout","state","isOpen","showWelcomePopup","messages","inputValue","isLoading","error","sessionId","createChatService","baseUrl","backendBaseUrl","wsUrl","backendWsUrl","debug","window","localStorage","savedMode","getItem","subscribe","listener","add","delete","getState","setState","updates","forEach","updateConfig","openChat","dfProjectId","dfAgentId","dialogflowConfig","dfLocation","languageCode","session","createDialogflowSession","session_id","message","welcomeMessage","id","Date","now","text","sender","timestamp","richContent","fallbackMessage","fallbackWelcomeMessage","closeChat","closeWelcomePopup","toggleChat","willBeOpen","setInputValue","value","clearError","sendMessage","skipUserMessage","trim","userMessage","sendHumanMessage","sendAIMessage","ChatResolvedError","enterResolvedState","errorMessage","includes","Error","response","sendDialogflowMessage","handoff","botMessage","handleHandoff","sendTypingIndicator","clearTimeout","sendMessageViaWebSocket","sendMessageToAgent","removeItem","newSession","startSupportChat","chat_id","setItem","retryError","switchToHumanMode","switchToBotMode","initializeWelcomePopup","delay","welcomePopupDelay","setTimeout","dialogflowSessionId","ensureChatInitialized","currentChatId","currentSupportSessionId","requestHandoff","handoffError","connectingMessage","connectWebSocket","handleWebSocketMessage","connected","type","content","sender_type","agentMessage","map","m","has","to_agent","to_agent_id","systemMessage","from_agent","acceptedMessage","status","agent_id","resolvedChatId","disconnectWebSocket","thankYouMessage","async","loadMessageHistory","preserveExisting","historyMessages","msg","Math","random","existingIds","newMessages","filter","combined","sort","a","b","getTime","getAdditionalState","destroy","clear","useChatWidget","manager","ref","unsubscribe","newState","additional","computed","onUnmounted","watch","newConfig","deep","props","__props","isConnectingToAgentFromComposable","messagesEndRef","messagesContainer","isInitializing","length","isStartingNewChat","nextTick","scrollIntoView","behavior","handleOpenChat","handleCloseChat","handleCloseWelcomePopup","handleInput","event","target","handleSubmit","preventDefault","handleChipClick","chipText","payload","messageToSend","isHandoffMessage","onMounted","_openBlock","_createElementBlock","_mergeProps","class","$attrs","_unref","onClick","_createElementVNode","_hoisted_1","_hoisted_2","_toDisplayString","welcomeTitle","_hoisted_3","_hoisted_4","welcomeCta","width","height","viewBox","fill","stroke","d","_hoisted_5","_hoisted_6","_hoisted_7","_hoisted_8","title","_hoisted_9","subtitle","_hoisted_10","_hoisted_11","_hoisted_12","_cache","_hoisted_13","_hoisted_14","_hoisted_15","_hoisted_16","emptyStateMessage","_Fragment","_renderList","key","_normalizeClass","innerHTML","safeLinkifyText","replace","Array","isArray","_hoisted_18","contentGroup","groupIndex","contentIndex","options","_hoisted_21","chip","chipIndex","$event","_hoisted_22","_hoisted_19","_hoisted_20","_hoisted_23","date","toLocaleTimeString","hour","minute","_hoisted_24","_hoisted_25","_hoisted_26","onSubmit","onInput","placeholder","inputPlaceholder","disabled","x1","y1","x2","y2","points"],"mappings":"yEAiBO,MAAMA,EAsBX,WAAAC,CAAYC,GAqBV,GAxCFC,KAAQC,cAAmDC,IAC3DF,KAAQG,SAA2B,KACnCH,KAAQI,OAAwB,KAChCJ,KAAQK,iBAAkC,KAC1CL,KAAQM,YAA2D,KAGnEN,KAAQO,aAAuB,EAC/BP,KAAQQ,aAAuB,EAC/BR,KAAQS,aAA8C,CAAEC,KAAM,SAC9DV,KAAQW,qBAA+B,EACvCX,KAAQY,eAAyB,EACjCZ,KAAQa,cAAwB,EAChCb,KAAQc,cAA+B,KAGvCd,KAAQe,cAAuC,KAC/Cf,KAAQgB,mBAA4C,KAGlDhB,KAAKD,OAASA,EACdC,KAAKiB,MAAQ,CACXC,QAAQ,EACRC,kBAAkB,EAClBC,SAAU,GACVC,WAAY,GACZC,WAAW,EACXC,MAAO,KACPC,UAAW,KACXrB,SAAU,MAIZH,KAAKM,YAAcmB,oBAAkB,CACnCC,QAAS1B,KAAKD,OAAO4B,gBAAkB,wBACvCC,MAAO5B,KAAKD,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A0B+D,yBAAgB1E,GAAY,CAAA,cAChEe,EAAAA,mBAOE,QAAA,CANA9E,KAAK,OACL0E,MAAM,oBACLtH,MAAOwH,EAAAA,MAAA5K,GAAMI,WACbsO,QAAO9E,GACP+E,YAAa7P,EAAAsE,MAAOwL,iBACpBC,SAAUjE,EAAAA,MAAA5K,GAAMK,WAAa8I,EAAA/F,OAAkBiG,GAAAjG,kBAElD0H,EAAAA,mBAkBS,SAAA,CAjBP9E,KAAK,SACL0E,MAAM,uBACLmE,UAAWjE,EAAAA,MAAA5K,GAAMI,WAAWoD,QAAUoH,EAAAA,MAAA5K,GAAMK,WAAa8I,EAAA/F,OAAkBiG,GAAAjG,wBAE5E0H,EAAAA,mBAYM,MAAA,CAXJQ,MAAM,KACNC,OAAO,KACPC,QAAQ,YACRC,KAAK,OACLC,OAAO,eACP,eAAa,IACb,iBAAe,QACf,kBAAgB,UAEhBZ,EAAAA,mBAA4C,OAAA,CAAtCgE,GAAG,KAAKC,GAAG,IAAIC,GAAG,KAAKC,GAAG,OAChCnE,EAAAA,mBAAsD,UAAA,CAA7CoE,OAAO"}
@@ -1,5 +1,5 @@
1
1
  import { ref, computed, onUnmounted, watch, defineComponent, nextTick, onMounted, openBlock, createElementBlock, mergeProps, unref, createElementVNode, toDisplayString, withModifiers, createCommentVNode, createTextVNode, Fragment, renderList, normalizeClass } from "vue";
2
- import { c as createChatService, a as createDialogflowSession, C as ChatResolvedError, s as sendDialogflowMessage, b as safeLinkifyText } from "./sanitize-Cm1kskSD.js";
2
+ import { c as createChatService, a as createDialogflowSession, C as ChatResolvedError, s as sendDialogflowMessage, b as safeLinkifyText } from "./sanitize-Q7JIm8H8.js";
3
3
  class WidgetStateManager {
4
4
  constructor(config) {
5
5
  this.listeners = /* @__PURE__ */ new Set();
@@ -7,11 +7,6 @@ class WidgetStateManager {
7
7
  this.chatId = null;
8
8
  this.supportSessionId = null;
9
9
  this.chatService = null;
10
- this.collectingUserInfo = false;
11
- this.userInfoStep = null;
12
- this.collectedUserName = "";
13
- this.collectedUserEmail = "";
14
- this.collectedUserMobile = "";
15
10
  this.wsConnected = false;
16
11
  this.agentTyping = false;
17
12
  this.currentAgent = { name: "Agent" };
@@ -167,22 +162,6 @@ class WidgetStateManager {
167
162
  if (!text.trim() || this.state.isLoading) {
168
163
  return;
169
164
  }
170
- if (this.collectingUserInfo) {
171
- const userMessage = {
172
- id: `user-${Date.now()}`,
173
- text: text.trim(),
174
- sender: "user",
175
- timestamp: /* @__PURE__ */ new Date()
176
- };
177
- this.setState({
178
- messages: [...this.state.messages, userMessage],
179
- inputValue: "",
180
- isLoading: false,
181
- error: null
182
- });
183
- await this.handleUserInfoCollection(text);
184
- return;
185
- }
186
165
  if (!skipUserMessage) {
187
166
  const userMessage = {
188
167
  id: `user-${Date.now()}`,
@@ -277,7 +256,7 @@ class WidgetStateManager {
277
256
  messages: [...this.state.messages, botMessage2],
278
257
  isLoading: false
279
258
  });
280
- this.startUserInfoCollection();
259
+ await this.handleHandoff();
281
260
  return;
282
261
  }
283
262
  const botMessage = {
@@ -340,10 +319,7 @@ class WidgetStateManager {
340
319
  }
341
320
  try {
342
321
  const newSession = await this.chatService.startSupportChat(
343
- this.state.sessionId || null,
344
- null,
345
- null,
346
- null
322
+ this.state.sessionId || null
347
323
  );
348
324
  this.chatId = newSession.chat_id;
349
325
  this.supportSessionId = newSession.session_id;
@@ -405,100 +381,10 @@ class WidgetStateManager {
405
381
  }, delay);
406
382
  }
407
383
  }
408
- /**
409
- * Start user info collection for handoff
410
- */
411
- startUserInfoCollection() {
412
- this.collectingUserInfo = true;
413
- this.userInfoStep = "name";
414
- this.collectedUserName = "";
415
- this.collectedUserEmail = "";
416
- this.collectedUserMobile = "";
417
- const namePrompt = {
418
- id: `prompt-${Date.now()}`,
419
- text: "To connect you with a human agent, I'll need some information. Please provide your name:",
420
- sender: "bot",
421
- timestamp: /* @__PURE__ */ new Date()
422
- };
423
- this.setState({
424
- messages: [...this.state.messages, namePrompt]
425
- });
426
- }
427
- /**
428
- * Handle user info collection
429
- */
430
- async handleUserInfoCollection(text) {
431
- if (this.userInfoStep === "name") {
432
- const name = text.trim();
433
- this.collectedUserName = name;
434
- this.userInfoStep = "email";
435
- const emailPrompt = {
436
- id: `prompt-${Date.now()}`,
437
- text: "Thank you! Now please provide your email address:",
438
- sender: "bot",
439
- timestamp: /* @__PURE__ */ new Date()
440
- };
441
- this.setState({
442
- messages: [...this.state.messages, emailPrompt],
443
- inputValue: ""
444
- });
445
- return;
446
- } else if (this.userInfoStep === "email") {
447
- const email = text.trim();
448
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
449
- if (!emailRegex.test(email)) {
450
- const invalidEmailMessage = {
451
- id: `prompt-${Date.now()}`,
452
- text: "Please provide a valid email address:",
453
- sender: "bot",
454
- timestamp: /* @__PURE__ */ new Date()
455
- };
456
- this.setState({
457
- messages: [...this.state.messages, invalidEmailMessage],
458
- inputValue: ""
459
- });
460
- return;
461
- }
462
- this.collectedUserEmail = email;
463
- this.userInfoStep = "mobile";
464
- const mobilePrompt = {
465
- id: `prompt-${Date.now()}`,
466
- text: "Thank you! Now please provide your mobile number:",
467
- sender: "bot",
468
- timestamp: /* @__PURE__ */ new Date()
469
- };
470
- this.setState({
471
- messages: [...this.state.messages, mobilePrompt],
472
- inputValue: ""
473
- });
474
- return;
475
- } else if (this.userInfoStep === "mobile") {
476
- const mobile = text.trim();
477
- const mobileRegex = /^[\+]?[(]?[0-9]{1,4}[)]?[-\s\.]?[(]?[0-9]{1,4}[)]?[-\s\.]?[0-9]{1,9}$/;
478
- if (!mobileRegex.test(mobile) || mobile.length < 10) {
479
- const invalidMobileMessage = {
480
- id: `prompt-${Date.now()}`,
481
- text: "Please provide a valid mobile number (e.g., +1234567890):",
482
- sender: "bot",
483
- timestamp: /* @__PURE__ */ new Date()
484
- };
485
- this.setState({
486
- messages: [...this.state.messages, invalidMobileMessage],
487
- inputValue: ""
488
- });
489
- return;
490
- }
491
- this.collectedUserMobile = mobile;
492
- this.collectingUserInfo = false;
493
- this.userInfoStep = null;
494
- await this.handleHandoff(this.collectedUserName, this.collectedUserEmail, mobile);
495
- this.setState({ inputValue: "" });
496
- }
497
- }
498
384
  /**
499
385
  * Handle handoff from Dialogflow to human support
500
386
  */
501
- async handleHandoff(customerName, customerEmail, customerMobile) {
387
+ async handleHandoff() {
502
388
  if (!this.chatService) {
503
389
  throw new Error("Chat service not initialized");
504
390
  }
@@ -508,10 +394,7 @@ class WidgetStateManager {
508
394
  const session = await this.chatService.ensureChatInitialized(
509
395
  this.chatId,
510
396
  this.supportSessionId,
511
- dialogflowSessionId || null,
512
- customerName || null,
513
- customerEmail || null,
514
- customerMobile || null
397
+ dialogflowSessionId || null
515
398
  );
516
399
  if (!session || !session.chat_id) {
517
400
  throw new Error("Failed to initialize chat session");
@@ -534,10 +417,7 @@ class WidgetStateManager {
534
417
  currentChatId,
535
418
  currentSupportSessionId,
536
419
  "Customer requested human agent",
537
- dialogflowSessionId || null,
538
- customerName || null,
539
- customerEmail || null,
540
- customerMobile || null
420
+ dialogflowSessionId || null
541
421
  );
542
422
  if (this.config.debug) {
543
423
  console.log("✅ Handoff requested successfully");
@@ -554,10 +434,7 @@ class WidgetStateManager {
554
434
  localStorage.removeItem("chartsconnect_session_id");
555
435
  }
556
436
  const newSession = await this.chatService.startSupportChat(
557
- dialogflowSessionId || null,
558
- customerName || null,
559
- customerEmail || null,
560
- customerMobile || null
437
+ dialogflowSessionId || null
561
438
  );
562
439
  if (!newSession || !newSession.chat_id) {
563
440
  throw new Error("Failed to re-initialize chat session");
@@ -572,10 +449,7 @@ class WidgetStateManager {
572
449
  this.chatId,
573
450
  this.supportSessionId,
574
451
  "Customer requested human agent",
575
- dialogflowSessionId || null,
576
- customerName || null,
577
- customerEmail || null,
578
- customerMobile || null
452
+ dialogflowSessionId || null
579
453
  );
580
454
  if (this.config.debug) {
581
455
  console.log("✅ Handoff requested successfully after retry");
@@ -780,11 +654,6 @@ class WidgetStateManager {
780
654
  sessionId: null
781
655
  // Clear session ID to force recreation
782
656
  });
783
- this.collectingUserInfo = false;
784
- this.userInfoStep = null;
785
- this.collectedUserName = "";
786
- this.collectedUserEmail = "";
787
- this.collectedUserMobile = "";
788
657
  if (this.config.dfProjectId && this.config.dfAgentId && this.state.isOpen) {
789
658
  try {
790
659
  this.setState({ isLoading: true });
@@ -1353,4 +1222,4 @@ export {
1353
1222
  WidgetStateManager as W,
1354
1223
  useChatWidget as u
1355
1224
  };
1356
- //# sourceMappingURL=ChatWidget-Bs0XV_7i.js.map
1225
+ //# sourceMappingURL=ChatWidget-fbaJU7v-.js.map