1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[63185],{71058:function(e,t,n){Promise.resolve().then(n.t.bind(n,88003,23)),Promise.resolve().then(n.t.bind(n,14929,23)),Promise.resolve().then(n.t.bind(n,37613,23)),Promise.resolve().then(n.bind(n,69064)),Promise.resolve().then(n.bind(n,14438)),Promise.resolve().then(n.t.bind(n,2778,23)),Promise.resolve().then(n.bind(n,3855))},3855:function(e,t,n){"use strict";n.d(t,{Providers:function(){return x}});var s=n(57437),r=n(21623),o=n(29827),a=n(3204),i=n(78298),l=n(2265),c=n(84881),d=n(46034),u=n(25041),m=n(69064);let g=(0,l.createContext)({lastError:null,isOffline:!1,clearError:()=>{},reportError:()=>{}});function p(e){let{children:t}=e,[n,r]=(0,l.useState)(null),[o,a]=(0,l.useState)(!1),[i,c]=(0,l.useState)(!1),[d,p]=(0,l.useState)(!1),[x,v]=(0,l.useState)(null),f=(0,l.useCallback)(()=>{r(null),c(!1),p(!1),v(null)},[]),b=(0,l.useCallback)(e=>{r(e),e.isCreditError()?c(!0):e.is(u.jK.PLAN_LIMIT_EXCEEDED)?p(!0):e.isRateLimitError()&&v(e)},[]);return(0,l.useEffect)(()=>{let e=e=>{r(e.detail),c(!0)},t=e=>{r(e.detail),p(!0)},n=e=>{v(e.detail);let t=e.detail.retryAfter||60;m.toast.error("Too many requests. Please wait ".concat(t," seconds."),{id:"rate-limit",duration:1e3*t})},s=e=>{r(e.detail),a(!0)},o=()=>{a(!1)},i=e=>{r(e.detail),m.toast.error("Your account has been suspended. Please contact support at [email protected]",{id:"account-banned",duration:1e4})},l=e=>{r(e.detail),m.toast.error("Your session has expired. Please log in again.",{id:"auth-expired",duration:4e3})};return window.addEventListener("insufficient-credits",e),window.addEventListener("plan-limit-exceeded",t),window.addEventListener("rate-limited",n),window.addEventListener("network-error",s),window.addEventListener("network-recovered",o),window.addEventListener("account-banned",i),window.addEventListener("auth-expired",l),()=>{window.removeEventListener("insufficient-credits",e),window.removeEventListener("plan-limit-exceeded",t),window.removeEventListener("rate-limited",n),window.removeEventListener("network-error",s),window.removeEventListener("network-recovered",o),window.removeEventListener("account-banned",i),window.removeEventListener("auth-expired",l)}},[]),(0,l.useEffect)(()=>{let e=()=>{a(!1),m.toast.success("You are back online!",{id:"online-status"})},t=()=>{a(!0),m.toast.error("You are offline. Please check your connection.",{id:"online-status",duration:1/0})};return"undefined"==typeof navigator||navigator.onLine||a(!0),window.addEventListener("online",e),window.addEventListener("offline",t),()=>{window.removeEventListener("online",e),window.removeEventListener("offline",t)}},[]),(0,l.useEffect)(()=>{if(null==x?void 0:x.retryAfter){let e=setTimeout(()=>{v(null)},1e3*x.retryAfter);return()=>clearTimeout(e)}},[x]),(0,s.jsxs)(g.Provider,{value:{lastError:n,isOffline:o,clearError:f,reportError:b},children:[o&&(0,s.jsx)("div",{className:"fixed top-0 left-0 right-0 z-50 bg-yellow-500 text-yellow-900 text-center py-2 px-4 text-sm font-medium",children:(0,s.jsxs)("div",{className:"flex items-center justify-center gap-2",children:[(0,s.jsx)("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M18.364 5.636a9 9 0 010 12.728m0 0l-2.829-2.829m2.829 2.829L21 21M15.536 8.464a5 5 0 010 7.072m0 0l-2.829-2.829m-4.243 2.829a4.978 4.978 0 01-1.414-2.83m-1.414 5.658a9 9 0 01-2.167-9.238m7.824 2.167a1 1 0 111.414 1.414m-1.414-1.414L3 3m8.293 8.293l1.414 1.414"})}),(0,s.jsx)("span",{children:"You are offline. Some features may not work."}),(0,s.jsx)("button",{onClick:()=>a(!1),className:"ml-2 p-1 hover:bg-yellow-600 rounded transition-colors","aria-label":"Dismiss",children:(0,s.jsx)("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})}),x&&(0,s.jsx)("div",{className:"fixed bottom-4 right-4 z-50 bg-orange-100 border border-orange-300 rounded-lg p-4 shadow-lg max-w-sm",children:(0,s.jsxs)("div",{className:"flex items-start gap-3",children:[(0,s.jsx)("svg",{className:"w-5 h-5 text-orange-500 mt-0.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm font-medium text-orange-800",children:"Rate limit reached"}),(0,s.jsxs)("p",{className:"text-sm text-orange-700",children:["Please wait ",x.retryAfter||60," seconds before trying again."]})]})]})}),t,i&&n&&(0,s.jsx)(w,{isOpen:i,onClose:()=>c(!1),error:n}),d&&n&&(0,s.jsx)(h,{isOpen:d,onClose:()=>p(!1),error:n})]})}function w(e){let{isOpen:t,onClose:n,error:r}=e;return t?(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50",children:(0,s.jsxs)("div",{className:"bg-white rounded-lg shadow-xl max-w-md w-full p-6",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3 mb-4",children:[(0,s.jsx)("div",{className:"flex-shrink-0 w-10 h-10 rounded-full bg-red-100 flex items-center justify-center",children:(0,s.jsx)("svg",{className:"w-6 h-6 text-red-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),(0,s.jsx)("h2",{className:"text-lg font-semibold text-gray-900",children:"Insufficient Credits"})]}),(0,s.jsx)("p",{className:"text-gray-600 mb-4",children:r.getUserMessage()}),void 0!==r.availableCredits&&(0,s.jsxs)("div",{className:"bg-gray-50 rounded-lg p-4 mb-4",children:[(0,s.jsxs)("div",{className:"flex justify-between text-sm",children:[(0,s.jsx)("span",{className:"text-gray-500",children:"Available credits:"}),(0,s.jsx)("span",{className:"font-medium text-gray-900",children:r.availableCredits})]}),void 0!==r.requiredCredits&&(0,s.jsxs)("div",{className:"flex justify-between text-sm mt-1",children:[(0,s.jsx)("span",{className:"text-gray-500",children:"Required credits:"}),(0,s.jsx)("span",{className:"font-medium text-red-600",children:r.requiredCredits})]})]}),(0,s.jsxs)("div",{className:"flex gap-3",children:[(0,s.jsx)("button",{onClick:n,className:"flex-1 px-4 py-2 text-sm font-medium text-gray-700 bg-gray-100 rounded-lg hover:bg-gray-200 transition-colors",children:"Cancel"}),(0,s.jsx)("a",{href:r.upgradeUrl||"/dashboard/billing",className:"flex-1 px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700 transition-colors text-center",children:"Buy Credits"})]})]})}):null}function h(e){let{isOpen:t,onClose:n,error:r}=e;return t?(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50",children:(0,s.jsxs)("div",{className:"bg-white rounded-lg shadow-xl max-w-md w-full p-6",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3 mb-4",children:[(0,s.jsx)("div",{className:"flex-shrink-0 w-10 h-10 rounded-full bg-orange-100 flex items-center justify-center",children:(0,s.jsx)("svg",{className:"w-6 h-6 text-orange-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})})}),(0,s.jsx)("h2",{className:"text-lg font-semibold text-gray-900",children:"Plan Limit Reached"})]}),(0,s.jsx)("p",{className:"text-gray-600 mb-4",children:r.getUserMessage()}),r.plan&&(0,s.jsxs)("div",{className:"bg-gray-50 rounded-lg p-4 mb-4",children:[(0,s.jsxs)("div",{className:"flex justify-between text-sm",children:[(0,s.jsx)("span",{className:"text-gray-500",children:"Current plan:"}),(0,s.jsx)("span",{className:"font-medium text-gray-900",children:r.plan})]}),void 0!==r.limit&&(0,s.jsxs)("div",{className:"flex justify-between text-sm mt-1",children:[(0,s.jsx)("span",{className:"text-gray-500",children:"Plan limit:"}),(0,s.jsx)("span",{className:"font-medium text-gray-900",children:r.limit})]})]}),(0,s.jsxs)("div",{className:"flex gap-3",children:[(0,s.jsx)("button",{onClick:n,className:"flex-1 px-4 py-2 text-sm font-medium text-gray-700 bg-gray-100 rounded-lg hover:bg-gray-200 transition-colors",children:"Cancel"}),(0,s.jsx)("a",{href:r.upgradeUrl||"/dashboard/billing",className:"flex-1 px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700 transition-colors text-center",children:"Upgrade Plan"})]})]})}):null}function x(e){let{children:t}=e,[n]=(0,l.useState)(()=>new r.S({defaultOptions:{queries:{staleTime:3e4,gcTime:3e5,retry:1,refetchOnWindowFocus:!1,refetchOnReconnect:!0}}}));return(0,s.jsxs)(o.aH,{client:n,children:[(0,s.jsx)(i.f,{attribute:"class",defaultTheme:"light",forcedTheme:"light",disableTransitionOnChange:!0,children:(0,s.jsx)(c.H,{children:(0,s.jsx)(d.w,{children:(0,s.jsx)(p,{children:t})})})}),(0,s.jsx)(a.t,{initialIsOpen:!1})]})}},46034:function(e,t,n){"use strict";n.d(t,{s:function(){return d},w:function(){return c}});var s=n(57437),r=n(2265),o=n(84881),a=n(40257);let i=(0,r.createContext)(void 0),l=a.env.NEXT_PUBLIC_WEBSOCKET_URL||"";function c(e){let{children:t}=e,{user:n,token:a}=(0,o.a)(),[c,d]=(0,r.useState)(null),[u,m]=(0,r.useState)(!1),[g,p]=(0,r.useState)(null),[w,h]=(0,r.useState)([]),[x,v]=(0,r.useState)([]),[f,b]=(0,r.useState)([]),k=(0,r.useRef)(0),_=(0,r.useRef)(null),y=(0,r.useRef)(null),j=(0,r.useRef)(!1),E=(0,r.useRef)(null),C=null==n?void 0:n.workspace_id,N=(0,r.useCallback)(()=>
1{if(!a||!n){console.log("[WebSocket] No token or user, skipping connection");return}if(j.current){console.log("[WebSocket] Already connecting, skipping");return}if(c&&c.readyState===WebSocket.OPEN&&E.current===a){console.log("[WebSocket] Already connected with same token, skipping");return}j.current=!0,E.current=a;let e=new URL("/api/ws",(l||"".concat("https:"===window.location.protocol?"wss:":"ws:","//").concat(window.location.host)).replace("http","ws"));e.searchParams.set("token",a),C&&e.searchParams.set("workspace_id",C),console.log("[WebSocket] Connecting to:",e.toString().replace(a,"***"));let t=new WebSocket(e.toString());t.onopen=()=>{console.log("[WebSocket] Connected"),m(!0),k.current=0,j.current=!1,_.current=setInterval(()=>{t.readyState===WebSocket.OPEN&&t.send(JSON.stringify({type:"ping"}))},25e3)},t.onmessage=e=>{try{let t=JSON.parse(e.data);S(t)}catch(e){console.error("[WebSocket] Error parsing message:",e)}},t.onclose=e=>{console.log("[WebSocket] Disconnected:",e.code,e.reason),m(!1),d(null),j.current=!1,_.current&&(clearInterval(_.current),_.current=null),1e3!==e.code&&k.current<5&&(k.current++,console.log("[WebSocket] Reconnecting (attempt ".concat(k.current,"/").concat(5,")...")),y.current=setTimeout(N,3e3))},t.onerror=e=>{console.error("[WebSocket] Error:",e),j.current=!1},d(t)},[a,n,C]),S=(0,r.useCallback)(e=>{switch(e.type){case"connection":console.log("[WebSocket] Connection confirmed:",e.status);break;case"pong":break;case"chat":let t={id:e.message_id||Date.now().toString(),room_id:e.conversation_id||g||"",user_id:e.sender_id,username:e.sender_name||"Unknown",message:e.content,timestamp:e.timestamp,type:e.is_ai?"ai":"text"};h(e=>[...e,t]);break;case"typing":e.is_typing?v(t=>t.find(t=>t.user_id===e.user_id)?t:[...t,{user_id:e.user_id,username:e.username||"Someone"}]):v(t=>t.filter(t=>t.user_id!==e.user_id));break;case"presence":"online"===e.status?b(t=>t.find(t=>t.user_id===e.user_id)?t.map(t=>t.user_id===e.user_id?{...t,status:e.status,current_room:e.current_room||null}:t):[...t,{user_id:e.user_id,username:e.username||"Unknown",status:e.status,current_room:e.current_room||null}]):"offline"===e.status&&b(t=>t.filter(t=>t.user_id!==e.user_id));break;case"new_message":console.log("[WebSocket] New message received:",e),window.dispatchEvent(new CustomEvent("ws:new_message",{detail:e}));break;case"conversation_update":console.log("[WebSocket] Conversation updated:",e),window.dispatchEvent(new CustomEvent("ws:conversation_update",{detail:e}));break;case"lead_update":console.log("[WebSocket] Lead updated:",e),window.dispatchEvent(new CustomEvent("ws:lead_update",{detail:e}));break;case"notification":console.log("[WebSocket] Notification received:",e),window.dispatchEvent(new CustomEvent("ws:notification",{detail:e}));break;case"agent_response":console.log("[WebSocket] Agent response:",e),window.dispatchEvent(new CustomEvent("ws:agent_response",{detail:e}));break;case"call_status_update":console.log("[WebSocket] Call status update:",e),window.dispatchEvent(new CustomEvent("ws:call_status_update",{detail:e}));break;case"messages_read":console.log("[WebSocket] Messages read:",e),window.dispatchEvent(new CustomEvent("ws:messages_read",{detail:e}));break;case"typing_indicator":console.log("[WebSocket] Typing indicator:",e),window.dispatchEvent(new CustomEvent("ws:typing_indicator",{detail:e}));break;case"agent_alert":console.log("[WebSocket] Agent alert:",e),window.dispatchEvent(new CustomEvent("ws:agent_alert",{detail:e}));break;case"dashboard_event":var n;"agent_alert"===e.event_type?(console.log("[WebSocket] Dashboard agent alert:",e),window.dispatchEvent(new CustomEvent("ws:agent_alert",{detail:e.data}))):"lead_updated"===e.event_type&&(null===(n=e.data)||void 0===n?void 0:n.ai_first_call_status)?(console.log("[WebSocket] Lead AI call status update:",e),window.dispatchEvent(new CustomEvent("ws:call_status_update",{detail:{type:"call_status_update",lead_id:e.data.lead_id,status:e.data.ai_first_call_status,call_type:"ai_call",...e.data}}))):window.dispatchEvent(new CustomEvent("ws:dashboard_event",{detail:e}));break;case"error":console.error("[WebSocket] Server error:",e.error);break;default:console.log("[WebSocket] Unknown message type:",e.type,e)}},[g]),L=null==n?void 0:n.id;(0,r.useEffect)(()=>(L&&a&&N(),()=>{_.current&&clearInterval(_.current),y.current&&clearTimeout(y.current)}),[L,a,N]),(0,r.useEffect)(()=>()=>{c&&c.close(1e3,"Component unmounting")},[c]);let W=(0,r.useCallback)(e=>{c&&c.readyState===WebSocket.OPEN?c.send(JSON.stringify(e)):console.warn("[WebSocket] Cannot send message, not connected")},[c]),P=(0,r.useCallback)(e=>{p(e),W({type:"presence",status:"online",current_room:e}),console.log("[WebSocket] Joined room:",e)},[W]),O=(0,r.useCallback)(e=>{g===e&&(p(null),W({type:"presence",status:"online",current_room:null}),console.log("[WebSocket] Left room:",e))},[g,W]),T=(0,r.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"text";if(!g){console.warn("[WebSocket] No room joined, cannot send message");return}W({type:"chat",content:e,message_type:t,workspace_id:C,conversation_id:g})},[g,C,W]),R=(0,r.useCallback)((e,t,n)=>{W({type:"chat",content:e,conversation_id:t,recipient_id:n,workspace_id:C})},[C,W]),A=(0,r.useCallback)(e=>{W({type:"typing",is_typing:!0,conversation_id:e||g,workspace_id:C})},[g,C,W]),M=(0,r.useCallback)(e=>{W({type:"typing",is_typing:!1,conversation_id:e||g,workspace_id:C})},[g,C,W]);return(0,s.jsx)(i.Provider,{value:{socket:c,connected:u,currentRoom:g,messages:w,typingUsers:x,onlineUsers:f,joinRoom:P,leaveRoom:O,sendMessage:T,sendChatMessage:R,startTyping:A,stopTyping:M,sendCustomMessage:W},children:t})}function d(){let e=(0,r.useContext)(i);if(void 0===e)throw Error("useSocket must be used within a SocketProvider");return e}},2778:function(){}},function(e){e.O(0,[52469,82461,83464,69064,14438,19226,88003,91779,71837,84881,92971,52117,1744],function(){return e(e.s=71058)}),_N_E=e.O()}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.