vpschatbotwidget 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist-lib/types/chatbot/api/chatbot-api.d.ts +7 -4
  2. package/dist-lib/types/chatbot/api/chatbot-api.test.d.ts +1 -0
  3. package/dist-lib/types/chatbot/api/chatbot-types.d.ts +14 -0
  4. package/dist-lib/types/chatbot/core/AgentReasoning.d.ts +0 -1
  5. package/dist-lib/types/chatbot/core/ChatContext.d.ts +4 -1
  6. package/dist-lib/types/chatbot/core/ChatMarkdown.d.ts +2 -1
  7. package/dist-lib/types/chatbot/core/ChatProvider.d.ts +2 -0
  8. package/dist-lib/types/chatbot/core/grounding.test.d.ts +1 -0
  9. package/dist-lib/types/chatbot/embedded/EmbeddedChatbot.d.ts +1 -0
  10. package/dist-lib/types/chatbot/index.d.ts +1 -1
  11. package/dist-lib/types/chatbot/widget/ChatbotWidget.d.ts +1 -0
  12. package/dist-lib/vps-chatbot.cjs +53 -24
  13. package/dist-lib/vps-chatbot.js +1181 -840
  14. package/package.json +1 -1
  15. package/src/chatbot/api/chatbot-api.test.ts +48 -0
  16. package/src/chatbot/api/chatbot-api.ts +141 -49
  17. package/src/chatbot/api/chatbot-types.ts +16 -0
  18. package/src/chatbot/chatbot.test.tsx +24 -1
  19. package/src/chatbot/core/AgentReasoning.tsx +28 -23
  20. package/src/chatbot/core/ChatContext.tsx +4 -0
  21. package/src/chatbot/core/ChatInput.tsx +14 -1
  22. package/src/chatbot/core/ChatMarkdown.tsx +12 -3
  23. package/src/chatbot/core/ChatMessage.tsx +16 -4
  24. package/src/chatbot/core/ChatProvider.tsx +84 -15
  25. package/src/chatbot/core/ChatTypingIndicator.tsx +2 -7
  26. package/src/chatbot/core/GroundedSources.tsx +4 -6
  27. package/src/chatbot/core/grounding.test.tsx +21 -0
  28. package/src/chatbot/embedded/EmbeddedChatbot.tsx +4 -1
  29. package/src/chatbot/index.ts +2 -0
  30. package/src/chatbot/widget/ChatbotWidget.tsx +4 -1
  31. package/src/index.css +38 -162
@@ -1,6 +1,5 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),v=require("react");var we=typeof document<"u"?document.currentScript:null;function gt(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const u=gt(v),mt={};function se(e){if(e!=null&&e.trim()!=="")return e.trim().replace(/\/+$/,"");const t=(typeof{url:typeof document>"u"?require("url").pathToFileURL(__filename).href:we&&we.tagName.toUpperCase()==="SCRIPT"&&we.src||new URL("vps-chatbot.cjs",document.baseURI).href}<"u"&&mt,"");return String(t).trim().replace(/\/+$/,"")}function pe(e,t){const n=se(e);if(!n)return t;if(n.endsWith("/api")&&t.startsWith("/api/"))return`${n}${t.slice(4)}`;if(n.endsWith("/api")&&t==="/health"){const s=n.slice(0,-4);return s?`${s}/health`:"/health"}const r=t.startsWith("/")?t:`/${t}`;return`${n}${r}`}function bt(e){return e&&typeof e=="object"&&"data"in e&&e.success!==!1?e.data:e}function vt(e,t,n){var l,a,i;const r=e,s=(l=r==null?void 0:r.error)==null?void 0:l.message;return s&&!_t(s)?{code:(a=r==null?void 0:r.error)==null?void 0:a.code,message:s,requestId:(i=r==null?void 0:r.error)==null?void 0:i.request_id}:n>=500?{message:"I couldn't process that request right now."}:n===0?{message:"Something went wrong while connecting. Please try again."}:{message:t}}function _t(e){return/traceback|sql|exception|stack|api[_ ]?key|password/i.test(e)}function He(e){return{chunkId:e.chunk_id,source:e.source,score:e.score,title:e.title,snippet:e.snippet}}function Ve(e){return{toolName:e.tool_name,arguments:e.arguments??{},result:e.result??{}}}function ze(e){return{model:e.model,promptTokens:e.prompt_tokens,completionTokens:e.completion_tokens,totalTokens:e.total_tokens}}function wt(e){const t=e.role==="user"||e.role==="system"?e.role:"assistant";return{id:String(e.id),role:t,content:e.content,createdAt:e.created_at||new Date().toISOString(),status:"complete",usage:e.model?{model:e.model,promptTokens:e.prompt_tokens||0,completionTokens:e.completion_tokens||0,totalTokens:(e.prompt_tokens||0)+(e.completion_tokens||0)}:void 0}}async function yt(e){const t=await e.text();if(!t)return{};try{return JSON.parse(t)}catch{return{}}}function xe(e){const t=se(e);async function n(r,s){let l;const a=pe(t,r);try{l=await fetch(a,{...s,headers:{"Content-Type":"application/json",...(s==null?void 0:s.headers)??{}}})}catch{throw{message:"Something went wrong while connecting. Please try again."}}if(l.status===204)return;const i=await yt(l);if(!l.ok)throw vt(i,"I couldn't process that request right now.",l.status);return bt(i)}return{apiBaseUrl:t,async createSession(){const r=await n("/api/v1/sessions",{method:"POST",body:JSON.stringify({})});return{sessionId:r.session_id,createdAt:r.created_at}},async sendMessage(r,s,l){const a=await n(`/api/v1/sessions/${r}/messages`,{method:"POST",body:JSON.stringify({message:s,...(l==null?void 0:l.roleId)!==void 0?{role_id:l.roleId}:{},...l!=null&&l.client?{client:l.client}:{}})});return{requestId:a.request_id,sessionId:a.session_id,answer:a.answer,sources:(a.sources||[]).map(He),toolCalls:(a.tool_calls||[]).map(Ve),usage:ze(a.usage)}},async sendMessageStream(r,s,l,a){const i=pe(t,`/api/v1/sessions/${r}/messages/stream`);try{const c=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:s,...(l==null?void 0:l.roleId)!==void 0?{role_id:l.roleId}:{},...l!=null&&l.client?{client:l.client}:{}})});if(!c.ok||!c.body)return await this.sendMessage(r,s,l);const f=c.body.getReader(),g=new TextDecoder;let _="",h=null;for(;;){const{done:d,value:p}=await f.read();if(d)break;_+=g.decode(p,{stream:!0});const C=_.split(`
2
-
3
- `);_=C.pop()||"";for(const b of C){const T=b.trim();if(T.startsWith("data:"))try{const k=JSON.parse(T.slice(5).trim());if(k.type==="progress"&&k.stage)a==null||a(k.stage);else if(k.type==="complete")h={requestId:k.request_id,sessionId:k.session_id,answer:k.answer,sources:(k.sources||[]).map(He),toolCalls:(k.tool_calls||[]).map(Ve),usage:ze(k.usage)};else if(k.type==="error")throw new Error(k.message||"An error occurred")}catch(k){if(!(k instanceof Error&&k.message!=="An error occurred"))throw k}}}return h||await this.sendMessage(r,s,l)}catch{return await this.sendMessage(r,s,l)}},async getHistory(r){try{return((await n(`/api/v1/sessions/${r}/messages`)).messages||[]).map(wt)}catch{return[]}},async closeSession(r){try{await n(`/api/v1/sessions/${r}`,{method:"DELETE"})}catch{}},async createTicket(){throw new Error("Ticket creation has been removed.")},async checkHealth(){try{const r=pe(t,"/health");return(await fetch(r)).ok}catch{return!1}}}}const Ct=xe(),kt=[{label:"How do I access my reports?",query:"How do I access my reports in the VPS Customer Portal?"},{label:"Where can I find sample status?",query:"Where can I find my sample status?"},{label:"How do I pre-register a sample?",query:"How do I pre-register a sample in the portal?"},{label:"How do I contact VPS Support?",query:"How can I contact VPS Customer Support?"}],Se=v.createContext(null);function Xe(){const e=v.useContext(Se);if(!e)throw new Error("useChatbot must be used inside ChatProvider.");return e}function _e(){return v.useContext(Se)}const xt=`Hello! I am your **VPS Veritas assistant**.
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),b=require("react");var Te=typeof document<"u"?document.currentScript:null;function _t(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const d=_t(b),wt={};function de(e){if(e!=null&&e.trim()!=="")return e.trim().replace(/\/+$/,"");const t=(typeof{url:typeof document>"u"?require("url").pathToFileURL(__filename).href:Te&&Te.tagName.toUpperCase()==="SCRIPT"&&Te.src||new URL("vps-chatbot.cjs",document.baseURI).href}<"u"&&wt,"");return String(t).trim().replace(/\/+$/,"")}function Ce(e,t){const n=de(e);if(!n)return t;if(n.endsWith("/api")&&t.startsWith("/api/"))return`${n}${t.slice(4)}`;if(n.endsWith("/api")&&t==="/health"){const o=n.slice(0,-4);return o?`${o}/health`:"/health"}const r=t.startsWith("/")?t:`/${t}`;return`${n}${r}`}function Ye(e){return e&&typeof e=="object"&&"data"in e&&e.success!==!1?e.data:e}function Je(e,t,n){var l,a,i;const r=e,o=(l=r==null?void 0:r.error)==null?void 0:l.message;return o&&!yt(o)?{code:(a=r==null?void 0:r.error)==null?void 0:a.code,message:o,requestId:(i=r==null?void 0:r.error)==null?void 0:i.request_id}:n>=500?{message:"I couldn't process that request right now."}:n===0?{message:"Something went wrong while connecting. Please try again."}:{message:t}}function yt(e){return/traceback|sql|exception|stack|api[_ ]?key|password/i.test(e)}function Ae(e){return{chunkId:e.chunk_id,source:e.source,score:e.score,title:e.title,snippet:e.snippet}}function Me(e){return{toolName:e.tool_name,arguments:e.arguments??{},result:e.result??{}}}function Ne(e){return{model:e.model,promptTokens:e.prompt_tokens,completionTokens:e.completion_tokens,totalTokens:e.total_tokens}}function xt(e){const t=e.role==="user"||e.role==="system"?e.role:"assistant";return{id:String(e.id),role:t,content:e.content,createdAt:e.created_at||new Date().toISOString(),status:"complete",usage:e.model?{model:e.model,promptTokens:e.prompt_tokens||0,completionTokens:e.completion_tokens||0,totalTokens:(e.prompt_tokens||0)+(e.completion_tokens||0)}:void 0}}async function Ie(e){const t=await e.text();if(!t)return{};try{return JSON.parse(t)}catch{return{}}}function Le(e){const t=de(e);async function n(r,o){let l;const a=Ce(t,r);try{l=await fetch(a,{...o,headers:{"Content-Type":"application/json",...(o==null?void 0:o.headers)??{}}})}catch{throw{message:"Something went wrong while connecting. Please try again."}}if(l.status===204)return;const i=await Ie(l);if(!l.ok)throw Je(i,"I couldn't process that request right now.",l.status);return Ye(i)}return{apiBaseUrl:t,async listModels(){try{const r=await n("/api/v1/models");return{defaultModelId:r.default_model_id,complexModelId:r.complex_model_id,models:r.models||[]}}catch{return null}},async createSession(r){const o=await n("/api/v1/sessions",{method:"POST",signal:r,body:JSON.stringify({})});return{sessionId:o.session_id,createdAt:o.created_at}},async sendMessage(r,o,l,a){const i=await n(`/api/v1/sessions/${r}/messages`,{method:"POST",signal:a,body:JSON.stringify({message:o,...(l==null?void 0:l.roleId)!==void 0?{role_id:l.roleId}:{},...l!=null&&l.client?{client:l.client}:{},...l!=null&&l.modelId?{model_id:l.modelId}:{}})});return{requestId:i.request_id,sessionId:i.session_id,answer:i.answer,sources:(i.sources||[]).map(Ae),toolCalls:(i.tool_calls||[]).map(Me),usage:Ne(i.usage),durationMs:i.duration_ms}},async sendMessageStream(r,o,l,a,i,u){var g,f;const h=Ce(t,`/api/v1/sessions/${r}/messages/stream`);try{const c=await fetch(h,{method:"POST",signal:u,headers:{"Content-Type":"application/json"},body:JSON.stringify({message:o,...(l==null?void 0:l.roleId)!==void 0?{role_id:l.roleId}:{},...l!=null&&l.client?{client:l.client}:{},...l!=null&&l.modelId?{model_id:l.modelId}:{}})});if(!c.ok){if(c.status===404||c.status===405)return await this.sendMessage(r,o,l,u);const j=await Ie(c);throw Je(j,"I couldn't process that request right now.",c.status)}if(!c.body||(f=(g=c.headers)==null?void 0:g.get("content-type"))!=null&&f.includes("application/json")){const j=Ye(await Ie(c));if(typeof j.answer!="string"||!j.usage)throw{message:"The response stream ended unexpectedly."};return{requestId:j.request_id,sessionId:j.session_id,answer:j.answer,sources:(j.sources||[]).map(Ae),toolCalls:(j.tool_calls||[]).map(Me),usage:Ne(j.usage),durationMs:j.duration_ms}}const p=c.body.getReader(),v=new TextDecoder;let y="";const _={value:null},m=j=>{const B=j.split(/\r?\n/).filter(T=>T.startsWith("data:")).map(T=>T.slice(5).trimStart()).join(`
2
+ `);if(!B)return;let k={};try{const T=JSON.parse(B);if(!T||typeof T!="object")return;k=T}catch{return}if(k.type==="progress"&&typeof k.stage=="string")a==null||a(k.stage);else if(k.type==="token"&&typeof k.text=="string")i==null||i(k.text);else if(k.type==="complete")_.value={requestId:k.request_id||"",sessionId:k.session_id||r,answer:k.answer||"",sources:(k.sources||[]).map(Ae),toolCalls:(k.tool_calls||[]).map(Me),usage:k.usage?Ne(k.usage):{model:"",promptTokens:0,completionTokens:0,totalTokens:0},durationMs:k.duration_ms};else if(k.type==="error")throw{message:k.message||"I couldn't process that request right now.",requestId:k.request_id}};try{for(;!_.value;){const{done:j,value:B}=await p.read();if(j)break;if(y+=v.decode(B,{stream:!0}),y.length>1e6)throw{message:"The response stream was too large."};const k=y.split(/\r?\n\r?\n/);y=k.pop()||"";for(const T of k)if(m(T),_.value)break}y+=v.decode(),!_.value&&y.trim()&&m(y)}finally{await p.cancel().catch(()=>{}),p.releaseLock()}const I=_.value;if(I)return I;throw{message:"The response stream ended before the answer was complete."}}catch(c){throw!(c instanceof Error)&&c&&typeof c=="object"&&"message"in c?c:{message:"Something went wrong while connecting. Please try again."}}},async getHistory(r){try{return((await n(`/api/v1/sessions/${r}/messages`)).messages||[]).map(xt)}catch{return[]}},async closeSession(r){try{await n(`/api/v1/sessions/${r}`,{method:"DELETE"})}catch{}},async createTicket(){throw new Error("Ticket creation has been removed.")},async checkHealth(){try{const r=Ce(t,"/health");return(await fetch(r)).ok}catch{return!1}}}}const kt=Le(),Ct=[{label:"How do I access my reports?",query:"How do I access my reports in the VPS Customer Portal?"},{label:"Where can I find sample status?",query:"Where can I find my sample status?"},{label:"How do I pre-register a sample?",query:"How do I pre-register a sample in the portal?"},{label:"How do I contact VPS Support?",query:"How can I contact VPS Customer Support?"}],Oe=b.createContext(null);function st(){const e=b.useContext(Oe);if(!e)throw new Error("useChatbot must be used inside ChatProvider.");return e}function Ee(){return b.useContext(Oe)}const St=`Hello! I am your **VPS Veritas assistant**.
4
3
 
5
4
  I can help you with:
6
5
  - **Fuel Quality Testing (FQT)** & **Oil Condition Monitoring (OCM)**
@@ -9,97 +8,127 @@ I can help you with:
9
8
  - **FSC & FSQ E-Forms** — paperless fuel system checks and bunker sample pre-registration
10
9
  - **Samplogic** sample logistics, report downloads, and support tickets
11
10
 
12
- Feel free to ask a question or select one of the suggested topics below!`;function Ge(e){return`${e}-${crypto.randomUUID()}`}function St(e){if(e&&typeof e=="object"&&"message"in e){const t=String(e.message);if(t&&!/traceback|sql|exception|stack|api[_ ]?key|password/i.test(t))return t}return"I couldn't process that request right now."}const Te=({children:e,userContext:t={},role:n,roleId:r,client:s,welcomeMessage:l,suggestions:a=kt,disableSuggestions:i=!1,initialMessage:c,apiBaseUrl:f,apiUrl:g,proxyUrl:_,api:h,hideInspectSources:d=!1,showGroundedSources:p=!0})=>{const C=f??g??_,b=v.useMemo(()=>h??xe(C),[h,C]),T=v.useMemo(()=>({...t,...n!==void 0?{role:n}:{},...r!==void 0?{roleId:r}:{},...s!==void 0?{client:s}:{}}),[t,n,r,s]),k=v.useMemo(()=>l===""?null:{id:"welcome-default",role:"assistant",content:l||xt,createdAt:new Date().toISOString(),status:"complete"},[l]),[M,U]=v.useState(null),[B,D]=v.useState(()=>k?[k]:[]),[j,P]=v.useState("idle"),[O,ee]=v.useState(null),Y=v.useRef(null),w=v.useRef(!1),S=v.useCallback(async()=>{if(M)return M;P("connecting");const q=await b.createSession();return U(q.sessionId),q.sessionId},[M,b]),F=v.useCallback(async q=>{Y.current=q;const K={id:Ge("user"),role:"user",content:q,createdAt:new Date().toISOString(),status:"complete"},Q=Ge("asst"),J={id:Q,role:"assistant",content:"",createdAt:new Date().toISOString(),status:"pending",progressText:"Analyzing question & expanding domain terms "};D(E=>[...E,K,J]),P("awaiting"),ee(null);const ne=E=>{D(W=>W.map(Z=>Z.id===Q?{...Z,progressText:E}:Z))};try{const E=await S(),W=b.sendMessageStream?await b.sendMessageStream(E,q,{roleId:T.roleId,client:T.client},Z=>{ne(Z)}):await b.sendMessage(E,q,{roleId:T.roleId,client:T.client});D(Z=>Z.map(G=>G.id===Q?{...G,id:W.requestId||Q,content:W.answer,status:"complete",progressText:void 0,sources:W.sources,toolCalls:W.toolCalls,usage:W.usage}:G)),P("idle")}catch(E){const W=St(E);D(Z=>Z.map(G=>G.id===Q?{...G,content:W,status:"error",progressText:void 0}:G)),ee(W),P("error")}},[S,b,T.client,T.roleId]),R=v.useCallback(async q=>{const K=q.trim();!K||j==="awaiting"||j==="connecting"||await F(K)},[F,j]),A=v.useCallback(async()=>{const q=Y.current;q&&(D(K=>K.filter(Q=>Q.status!=="error")),await F(q))},[F]),I=v.useCallback(async()=>{},[]),N=v.useCallback(()=>{},[]),z=v.useCallback(async()=>{M&&await b.closeSession(M),U(null),D(k?[k]:[]),P("idle"),ee(null),Y.current=null},[M,b,k]);v.useEffect(()=>{!c||w.current||(w.current=!0,R(c))},[c,R]);const te=v.useMemo(()=>({messages:B,status:j,error:O,sessionId:M,pendingTicket:null,ticketBusy:!1,lastTicket:null,suggestions:a,showSuggestions:!i&&(B.length===0||B.length===1&&B[0].id==="welcome-default"),suggestionBadgesEnabled:!i,userContext:T,apiBaseUrl:b.apiBaseUrl,hideInspectSources:d,showGroundedSources:p,sendMessage:R,retryLast:A,confirmTicket:I,cancelTicket:N,resetConversation:z}),[B,j,O,M,a,i,T,b.apiBaseUrl,d,p,R,A,I,N,z]);return o.jsx(Se.Provider,{value:te,children:e})};function ce(){return Xe()}const Tt=({message:e,onRetry:t})=>o.jsxs("div",{className:"chat-error-banner",role:"alert",children:[o.jsx("p",{children:e}),t&&o.jsx("button",{type:"button",onClick:t,className:"chat-error-retry-btn",children:"Try again"})]});/**
11
+ Feel free to ask a question or select one of the suggested topics below!`;function Ke(e){return`${e}-${crypto.randomUUID()}`}function jt(e){if(e&&typeof e=="object"&&"message"in e){const t=String(e.message);if(t&&!/traceback|sql|exception|stack|api[_ ]?key|password/i.test(t))return t}return"I couldn't process that request right now."}const qe=({children:e,userContext:t={},role:n,roleId:r,client:o,welcomeMessage:l,suggestions:a=Ct,disableSuggestions:i=!1,initialMessage:u,apiBaseUrl:h,apiUrl:g,proxyUrl:f,api:c,hideInspectSources:p=!1,showGroundedSources:v=!0,modelId:y="auto"})=>{const _=h??g??f,m=b.useMemo(()=>c??Le(_),[c,_]),I=b.useMemo(()=>({...t,...n!==void 0?{role:n}:{},...r!==void 0?{roleId:r}:{},...o!==void 0?{client:o}:{}}),[t,n,r,o]),j=b.useMemo(()=>l===""?null:{id:"welcome-default",role:"assistant",content:l||St,createdAt:new Date().toISOString(),status:"complete"},[l]),[B,k]=b.useState(null),[T,A]=b.useState(()=>j?[j]:[]),[z,L]=b.useState("idle"),[ne,J]=b.useState(null),x=b.useRef(null),E=b.useRef(!1),M=b.useRef(null),N=b.useRef(!1),[D,O]=b.useState([]),[P,U]=b.useState(y);b.useEffect(()=>U(y),[y]),b.useEffect(()=>{var C;let F=!0;return O([]),(C=m.listModels)==null||C.call(m).then(W=>{F&&O((W==null?void 0:W.models)||[])}).catch(()=>{}),()=>{F=!1}},[m]);const Z=b.useCallback(F=>{!N.current&&(F==="auto"||D.some(C=>C.id===F&&C.configured))&&U(F)},[D]);b.useEffect(()=>()=>{var F;return(F=M.current)==null?void 0:F.abort()},[]);const ae=b.useCallback(async F=>{if(B)return B;L("connecting");const C=await m.createSession(F);if(F.aborted)throw new DOMException("Aborted","AbortError");return k(C.sessionId),C.sessionId},[B,m]),te=b.useCallback(async F=>{if(N.current)return;N.current=!0;const C=new AbortController;M.current=C;let W,ue="";const he=()=>{W!==void 0&&cancelAnimationFrame(W),W=void 0};x.current=F;const oe={id:Ke("user"),role:"user",content:F,createdAt:new Date().toISOString(),status:"complete"},re=Ke("asst"),pe={id:re,role:"assistant",content:"",createdAt:new Date().toISOString(),status:"pending",progressText:"Preparing your answer…"},xe=performance.now();A(Q=>[...Q,oe,pe]),L("awaiting"),J(null);const ke=Q=>{C.signal.aborted||A(G=>G.map(X=>X.id===re?{...X,progressText:Q}:X))};try{const Q=await ae(C.signal),G=m.sendMessageStream?await m.sendMessageStream(Q,F,{roleId:I.roleId,client:I.client,modelId:P},ke,X=>{C.signal.aborted||(ue+=X,W===void 0&&(W=requestAnimationFrame(()=>{W=void 0,C.signal.aborted||A(K=>K.map(fe=>fe.id===re?{...fe,content:ue}:fe))})))},C.signal):await m.sendMessage(Q,F,{roleId:I.roleId,client:I.client,modelId:P},C.signal);if(he(),C.signal.aborted)return;A(X=>X.map(K=>K.id===re?{...K,id:G.requestId||re,content:G.answer,status:"complete",progressText:void 0,sources:G.sources,toolCalls:G.toolCalls,usage:G.usage,durationMs:Math.max(Math.round(performance.now()-xe),G.durationMs??0)}:K)),L("idle")}catch(Q){if(he(),C.signal.aborted)return;const G=jt(Q);A(X=>X.map(K=>K.id===re?{...K,content:G,status:"error",progressText:void 0}:K)),J(G),L("error")}finally{he(),M.current===C&&(M.current=null,N.current=!1)}},[ae,m,I.client,I.roleId,P]),ie=b.useCallback(async F=>{const C=F.trim();!C||z==="awaiting"||z==="connecting"||await te(C)},[te,z]),Y=b.useCallback(async()=>{if(N.current)return;const F=x.current;F&&(A(C=>C.filter(W=>W.status!=="error")),await te(F))},[te]),se=b.useCallback(async()=>{},[]),q=b.useCallback(()=>{},[]),ce=b.useCallback(async()=>{var F;(F=M.current)==null||F.abort(),M.current=null,N.current=!1,k(null),A(j?[j]:[]),L("idle"),J(null),x.current=null,B&&await m.closeSession(B)},[B,m,j]);b.useEffect(()=>{!u||E.current||(E.current=!0,ie(u))},[u,ie]);const ye=b.useMemo(()=>({messages:T,status:z,error:ne,sessionId:B,pendingTicket:null,ticketBusy:!1,lastTicket:null,suggestions:a,showSuggestions:!i&&(T.length===0||T.length===1&&T[0].id==="welcome-default"),suggestionBadgesEnabled:!i,userContext:I,apiBaseUrl:m.apiBaseUrl,hideInspectSources:p,showGroundedSources:v,sendMessage:ie,retryLast:Y,confirmTicket:se,cancelTicket:q,resetConversation:ce,models:D,selectedModelId:P,selectModel:Z}),[T,z,ne,B,a,i,I,m.apiBaseUrl,p,v,ie,Y,se,q,ce,D,P,Z]);return s.jsx(Oe.Provider,{value:ye,children:e})};function ve(){return st()}const Rt=({message:e,onRetry:t})=>s.jsxs("div",{className:"chat-error-banner",role:"alert",children:[s.jsx("p",{children:e}),t&&s.jsx("button",{type:"button",onClick:t,className:"chat-error-retry-btn",children:"Try again"})]});/**
12
+ * @license lucide-react v0.468.0 - ISC
13
+ *
14
+ * This source code is licensed under the ISC license.
15
+ * See the LICENSE file in the root directory of this source tree.
16
+ */const Ft=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),ot=(...e)=>e.filter((t,n,r)=>!!t&&t.trim()!==""&&r.indexOf(t)===n).join(" ").trim();/**
17
+ * @license lucide-react v0.468.0 - ISC
18
+ *
19
+ * This source code is licensed under the ISC license.
20
+ * See the LICENSE file in the root directory of this source tree.
21
+ */var Et={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
22
+ * @license lucide-react v0.468.0 - ISC
23
+ *
24
+ * This source code is licensed under the ISC license.
25
+ * See the LICENSE file in the root directory of this source tree.
26
+ */const Tt=b.forwardRef(({color:e="currentColor",size:t=24,strokeWidth:n=2,absoluteStrokeWidth:r,className:o="",children:l,iconNode:a,...i},u)=>b.createElement("svg",{ref:u,...Et,width:t,height:t,stroke:e,strokeWidth:r?Number(n)*24/Number(t):n,className:ot("lucide",o),...i},[...a.map(([h,g])=>b.createElement(h,g)),...Array.isArray(l)?l:[l]]));/**
27
+ * @license lucide-react v0.468.0 - ISC
28
+ *
29
+ * This source code is licensed under the ISC license.
30
+ * See the LICENSE file in the root directory of this source tree.
31
+ */const $=(e,t)=>{const n=b.forwardRef(({className:r,...o},l)=>b.createElement(Tt,{ref:l,iconNode:t,className:ot(`lucide-${Ft(e)}`,r),...o}));return n.displayName=`${e}`,n};/**
32
+ * @license lucide-react v0.468.0 - ISC
33
+ *
34
+ * This source code is licensed under the ISC license.
35
+ * See the LICENSE file in the root directory of this source tree.
36
+ */const At=$("ArrowDown",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]);/**
37
+ * @license lucide-react v0.468.0 - ISC
38
+ *
39
+ * This source code is licensed under the ISC license.
40
+ * See the LICENSE file in the root directory of this source tree.
41
+ */const Mt=$("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);/**
13
42
  * @license lucide-react v0.468.0 - ISC
14
43
  *
15
44
  * This source code is licensed under the ISC license.
16
45
  * See the LICENSE file in the root directory of this source tree.
17
- */const jt=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),et=(...e)=>e.filter((t,n,r)=>!!t&&t.trim()!==""&&r.indexOf(t)===n).join(" ").trim();/**
46
+ */const Nt=$("ArrowUp",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]);/**
18
47
  * @license lucide-react v0.468.0 - ISC
19
48
  *
20
49
  * This source code is licensed under the ISC license.
21
50
  * See the LICENSE file in the root directory of this source tree.
22
- */var Ft={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
51
+ */const It=$("BookOpen",[["path",{d:"M12 7v14",key:"1akyts"}],["path",{d:"M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z",key:"ruj8y"}]]);/**
23
52
  * @license lucide-react v0.468.0 - ISC
24
53
  *
25
54
  * This source code is licensed under the ISC license.
26
55
  * See the LICENSE file in the root directory of this source tree.
27
- */const Et=v.forwardRef(({color:e="currentColor",size:t=24,strokeWidth:n=2,absoluteStrokeWidth:r,className:s="",children:l,iconNode:a,...i},c)=>v.createElement("svg",{ref:c,...Ft,width:t,height:t,stroke:e,strokeWidth:r?Number(n)*24/Number(t):n,className:et("lucide",s),...i},[...a.map(([f,g])=>v.createElement(f,g)),...Array.isArray(l)?l:[l]]));/**
56
+ */const lt=$("BotMessageSquare",[["path",{d:"M12 6V2H8",key:"1155em"}],["path",{d:"m8 18-4 4V8a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2Z",key:"w2lp3e"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M9 11v2",key:"1ueba0"}],["path",{d:"M15 11v2",key:"i11awn"}],["path",{d:"M20 12h2",key:"1q8mjw"}]]);/**
28
57
  * @license lucide-react v0.468.0 - ISC
29
58
  *
30
59
  * This source code is licensed under the ISC license.
31
60
  * See the LICENSE file in the root directory of this source tree.
32
- */const V=(e,t)=>{const n=v.forwardRef(({className:r,...s},l)=>v.createElement(Et,{ref:l,iconNode:t,className:et(`lucide-${jt(e)}`,r),...s}));return n.displayName=`${e}`,n};/**
61
+ */const Dt=$("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);/**
33
62
  * @license lucide-react v0.468.0 - ISC
34
63
  *
35
64
  * This source code is licensed under the ISC license.
36
65
  * See the LICENSE file in the root directory of this source tree.
37
- */const Rt=V("ArrowDown",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]);/**
66
+ */const Bt=$("ChevronDown",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);/**
38
67
  * @license lucide-react v0.468.0 - ISC
39
68
  *
40
69
  * This source code is licensed under the ISC license.
41
70
  * See the LICENSE file in the root directory of this source tree.
42
- */const At=V("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);/**
71
+ */const Pt=$("ChevronUp",[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]]);/**
43
72
  * @license lucide-react v0.468.0 - ISC
44
73
  *
45
74
  * This source code is licensed under the ISC license.
46
75
  * See the LICENSE file in the root directory of this source tree.
47
- */const Mt=V("ArrowUp",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]);/**
76
+ */const Lt=$("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);/**
48
77
  * @license lucide-react v0.468.0 - ISC
49
78
  *
50
79
  * This source code is licensed under the ISC license.
51
80
  * See the LICENSE file in the root directory of this source tree.
52
- */const tt=V("BotMessageSquare",[["path",{d:"M12 6V2H8",key:"1155em"}],["path",{d:"m8 18-4 4V8a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2Z",key:"w2lp3e"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M9 11v2",key:"1ueba0"}],["path",{d:"M15 11v2",key:"i11awn"}],["path",{d:"M20 12h2",key:"1q8mjw"}]]);/**
81
+ */const Ot=$("ClipboardCheck",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}],["path",{d:"m9 14 2 2 4-4",key:"df797q"}]]);/**
53
82
  * @license lucide-react v0.468.0 - ISC
54
83
  *
55
84
  * This source code is licensed under the ISC license.
56
85
  * See the LICENSE file in the root directory of this source tree.
57
- */const Bt=V("Brain",[["path",{d:"M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z",key:"l5xja"}],["path",{d:"M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z",key:"ep3f8r"}],["path",{d:"M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4",key:"1p4c4q"}],["path",{d:"M17.599 6.5a3 3 0 0 0 .399-1.375",key:"tmeiqw"}],["path",{d:"M6.003 5.125A3 3 0 0 0 6.401 6.5",key:"105sqy"}],["path",{d:"M3.477 10.896a4 4 0 0 1 .585-.396",key:"ql3yin"}],["path",{d:"M19.938 10.5a4 4 0 0 1 .585.396",key:"1qfode"}],["path",{d:"M6 18a4 4 0 0 1-1.967-.516",key:"2e4loj"}],["path",{d:"M19.967 17.484A4 4 0 0 1 18 18",key:"159ez6"}]]);/**
86
+ */const qt=$("ExternalLink",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]]);/**
58
87
  * @license lucide-react v0.468.0 - ISC
59
88
  *
60
89
  * This source code is licensed under the ISC license.
61
90
  * See the LICENSE file in the root directory of this source tree.
62
- */const Dt=V("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);/**
91
+ */const $t=$("FlaskConical",[["path",{d:"M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2",key:"18mbvz"}],["path",{d:"M6.453 15h11.094",key:"3shlmq"}],["path",{d:"M8.5 2h7",key:"csnxdl"}]]);/**
63
92
  * @license lucide-react v0.468.0 - ISC
64
93
  *
65
94
  * This source code is licensed under the ISC license.
66
95
  * See the LICENSE file in the root directory of this source tree.
67
- */const It=V("ClipboardCheck",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}],["path",{d:"m9 14 2 2 4-4",key:"df797q"}]]);/**
96
+ */const zt=$("LoaderCircle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);/**
68
97
  * @license lucide-react v0.468.0 - ISC
69
98
  *
70
99
  * This source code is licensed under the ISC license.
71
100
  * See the LICENSE file in the root directory of this source tree.
72
- */const Nt=V("FlaskConical",[["path",{d:"M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2",key:"18mbvz"}],["path",{d:"M6.453 15h11.094",key:"3shlmq"}],["path",{d:"M8.5 2h7",key:"csnxdl"}]]);/**
101
+ */const at=$("MessageSquare",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}]]);/**
73
102
  * @license lucide-react v0.468.0 - ISC
74
103
  *
75
104
  * This source code is licensed under the ISC license.
76
105
  * See the LICENSE file in the root directory of this source tree.
77
- */const rt=V("MessageSquare",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}]]);/**
106
+ */const Ht=$("Microscope",[["path",{d:"M6 18h8",key:"1borvv"}],["path",{d:"M3 22h18",key:"8prr45"}],["path",{d:"M14 22a7 7 0 1 0 0-14h-1",key:"1jwaiy"}],["path",{d:"M9 14h2",key:"197e7h"}],["path",{d:"M9 12a2 2 0 0 1-2-2V6h6v4a2 2 0 0 1-2 2Z",key:"1bmzmy"}],["path",{d:"M12 6V3a1 1 0 0 0-1-1H9a1 1 0 0 0-1 1v3",key:"1drr47"}]]);/**
78
107
  * @license lucide-react v0.468.0 - ISC
79
108
  *
80
109
  * This source code is licensed under the ISC license.
81
110
  * See the LICENSE file in the root directory of this source tree.
82
- */const Pt=V("Microscope",[["path",{d:"M6 18h8",key:"1borvv"}],["path",{d:"M3 22h18",key:"8prr45"}],["path",{d:"M14 22a7 7 0 1 0 0-14h-1",key:"1jwaiy"}],["path",{d:"M9 14h2",key:"197e7h"}],["path",{d:"M9 12a2 2 0 0 1-2-2V6h6v4a2 2 0 0 1-2 2Z",key:"1bmzmy"}],["path",{d:"M12 6V3a1 1 0 0 0-1-1H9a1 1 0 0 0-1 1v3",key:"1drr47"}]]);/**
111
+ */const Wt=$("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);/**
83
112
  * @license lucide-react v0.468.0 - ISC
84
113
  *
85
114
  * This source code is licensed under the ISC license.
86
115
  * See the LICENSE file in the root directory of this source tree.
87
- */const Lt=V("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);/**
116
+ */const Vt=$("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);/**
88
117
  * @license lucide-react v0.468.0 - ISC
89
118
  *
90
119
  * This source code is licensed under the ISC license.
91
120
  * See the LICENSE file in the root directory of this source tree.
92
- */const Ot=V("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);/**
121
+ */const Gt=$("ShieldCheck",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);/**
93
122
  * @license lucide-react v0.468.0 - ISC
94
123
  *
95
124
  * This source code is licensed under the ISC license.
96
125
  * See the LICENSE file in the root directory of this source tree.
97
- */const qt=V("TestTubeDiagonal",[["path",{d:"M21 7 6.82 21.18a2.83 2.83 0 0 1-3.99-.01a2.83 2.83 0 0 1 0-4L17 3",key:"1ub6xw"}],["path",{d:"m16 2 6 6",key:"1gw87d"}],["path",{d:"M12 16H4",key:"1cjfip"}]]);/**
126
+ */const Ut=$("TestTubeDiagonal",[["path",{d:"M21 7 6.82 21.18a2.83 2.83 0 0 1-3.99-.01a2.83 2.83 0 0 1 0-4L17 3",key:"1ub6xw"}],["path",{d:"m16 2 6 6",key:"1gw87d"}],["path",{d:"M12 16H4",key:"1cjfip"}]]);/**
98
127
  * @license lucide-react v0.468.0 - ISC
99
128
  *
100
129
  * This source code is licensed under the ISC license.
101
130
  * See the LICENSE file in the root directory of this source tree.
102
- */const Wt=V("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),$t={alpha:{label:"Alpha",Icon:Nt,variant:"env-badge--alpha",tooltip:"Alpha build — internal testing only"},beta:{label:"Beta",Icon:qt,variant:"env-badge--beta",tooltip:"Beta build — public pre-release"},gamma:{label:"Gamma",Icon:Pt,variant:"env-badge--gamma",tooltip:"Gamma / Release Candidate"},qa:{label:"QA",Icon:It,variant:"env-badge--qa",tooltip:"Quality Assurance build"}},Ht=({stage:e,pulse:t=!0,className:n=""})=>{if(!e)return null;const{label:r,Icon:s,variant:l,tooltip:a}=$t[e];return o.jsxs("span",{className:`env-badge-inline ${l} ${n}`.trim(),title:a,"aria-label":`${r} build`,role:"status",children:[o.jsx(s,{size:10,className:"env-badge-icon","aria-hidden":"true"}),o.jsx("span",{className:"env-badge-inline-label",children:r})]})},Vt=e=>o.jsx("svg",{width:e.width||"24px",height:e.height||"24px",viewBox:"0 0 24 24",role:"img",xmlns:"http://www.w3.org/2000/svg",fill:e.Color||"currentColor",...e,children:o.jsx("path",{d:"M11.999 0c-2.25 0-4.5.06-6.6.21a5.57 5.57 0 0 0-5.19 5.1c-.24 3.21-.27 6.39-.06 9.6a5.644 5.644 0 0 0 5.7 5.19h3.15v-3.9h-3.15c-.93.03-1.74-.63-1.83-1.56-.18-3-.15-6 .06-9 .06-.84.72-1.47 1.56-1.53 2.04-.15 4.2-.21 6.36-.21s4.32.09 6.36.18c.81.06 1.5.69 1.56 1.53.24 3 .24 6 .06 9-.12.93-.9 1.62-1.83 1.59h-3.15l-6 3.9V24l6-3.9h3.15c2.97.03 5.46-2.25 5.7-5.19.21-3.18.18-6.39-.03-9.57a5.57 5.57 0 0 0-5.19-5.1c-2.13-.18-4.38-.24-6.63-.24zm-5.04 8.76c-.36 0-.66.3-.66.66v2.34c0 .33.18.63.48.78 1.62.78 3.42 1.2 5.22 1.26 1.8-.06 3.6-.48 5.22-1.26.3-.15.48-.45.48-.78V9.42c0-.09-.03-.15-.09-.21a.648.648 0 0 0-.87-.36c-1.5.66-3.12 1.02-4.77 1.05-1.65-.03-3.27-.42-4.77-1.08a.566.566 0 0 0-.24-.06z"})}),zt=({title:e="VPS AI Assistant",subtitle:t="Customer portal support",onClose:n,onReset:r,onBack:s,showMinimize:l=!1,envStage:a,envPulse:i=!0})=>o.jsxs("header",{className:"chat-header",children:[o.jsxs("div",{className:"chat-header-left",children:[s&&o.jsx("button",{type:"button",onClick:s,className:"icon-btn-back","aria-label":"Back",children:o.jsx(At,{size:16})}),o.jsx("div",{className:"avatar-circle","aria-hidden":"true",children:o.jsx(Vt,{width:"16px",height:"16px",color:"white"})}),o.jsxs("div",{children:[o.jsxs("div",{className:"chat-header-title-row",children:[o.jsx("h2",{className:"chat-header-title",children:e}),o.jsx(Ht,{stage:a,pulse:i})]}),o.jsx("p",{className:"chat-header-subtitle",children:t||"Customer portal support"})]})]}),o.jsxs("div",{className:"chat-header-actions",children:[r&&o.jsx("button",{type:"button",onClick:r,className:"icon-btn-action","aria-label":"Start a new conversation",title:"New conversation",children:o.jsx(Ot,{size:15})}),n&&o.jsx("button",{type:"button",onClick:n,className:"icon-btn-action","aria-label":l?"Minimize chat":"Close chat",children:o.jsx(Lt,{size:16})})]})]});function Gt(e,t){const n=v.useRef(e);v.useEffect(()=>{var r;n.current&&!e&&((r=t.current)==null||r.focus()),n.current=e},[e,t])}function Ut(e,t){const n=t.trim().toLowerCase();return n?e.filter(r=>r.label.toLowerCase().includes(n)||r.query.toLowerCase().includes(n)):e}const Yt=({suggestions:e,onSelect:t,disabled:n,variant:r="list"})=>e.length?r==="badge"?o.jsx("ul",{className:"suggestions-badge-list","aria-label":"Suggested questions",children:e.map(s=>o.jsx("li",{className:"suggestion-badge-item",children:o.jsx("button",{type:"button",disabled:n,onClick:()=>t(s),title:s.query,className:"suggestion-badge-btn",children:s.label})},s.query))}):o.jsx("div",{className:"suggestions-list",children:e.map(s=>o.jsx("button",{type:"button",disabled:n,onClick:()=>t(s),className:"suggestion-list-btn",children:s.label},s.query))}):null,Jt=({onSend:e,disabled:t=!1,placeholder:n="Ask something…"})=>{const{suggestions:r,showSuggestions:s,suggestionBadgesEnabled:l}=ce(),[a,i]=v.useState(""),c=v.useRef(null),f=d=>{d&&(d.style.height="auto",d.style.height=`${Math.min(d.scrollHeight,96)}px`)};Gt(t,c),v.useEffect(()=>{f(c.current)},[a]);const g=v.useMemo(()=>{if(!l||t)return[];const d=a.trim();return d?Ut(r,d):s?r:[]},[t,s,l,r,a]),_=d=>{i(d.query);const p=c.current;p==null||p.focus()},h=()=>{const d=a.trim();!d||t||(e(d),i(""),c.current&&(c.current.style.height="auto"))};return o.jsxs("div",{className:"chat-input-wrapper",children:[o.jsx(Yt,{variant:"badge",suggestions:g,onSelect:_,disabled:t}),o.jsx("label",{htmlFor:"vps-chat-input",className:"sr-only",children:"Chat message"}),o.jsxs("div",{className:"chat-input-row",children:[o.jsx("textarea",{id:"vps-chat-input",ref:c,rows:1,value:a,disabled:t,placeholder:n,onChange:d=>{i(d.target.value),f(d.target)},onKeyDown:d=>{d.key==="Enter"&&!d.shiftKey&&(d.preventDefault(),h())},className:"chat-textarea"}),o.jsx("button",{type:"button",onClick:h,disabled:t||!a.trim(),"aria-label":"Send message",className:"chat-send-btn",children:o.jsx(Mt,{size:16})})]}),o.jsxs("p",{className:"chat-input-footer",children:["Powered by ",o.jsx("span",{className:"chat-input-footer-brand",children:"VPS Veritas AI"})]})]})};function Zt({defaultTagName:e,props:t,render:n,state:r={},stateAttributesMapping:s}){let l=Ce(Kt(r,s),t);if(!n)return u.createElement(e,l);if(typeof n=="function")return n(l,r);if(!u.isValidElement(n))return null;let a=n.props,i={...Ce(l,a),ref:ue(l.ref,a.ref)};return u.cloneElement(n,i)}function Ce(...e){let t={};for(let n of e){if(!n)continue;let r=n;for(let s of Object.keys(r)){let l=r[s];if(l===void 0)continue;let a=t[s];s==="className"?t[s]=[a,l].filter(Boolean).join(" "):s==="style"?t[s]={...a,...l}:s==="ref"?t[s]=ue(a,l):Xt(s)&&typeof a=="function"&&typeof l=="function"?t[s]=Qt(l,a):t[s]=l}}return t}function Kt(e,t){var r;let n={};for(let s of Object.keys(e)){let l=e[s],a=(r=t==null?void 0:t[s])==null?void 0:r.call(t,l);if(a){Object.assign(n,a);continue}if(s==="slot"){n["data-slot"]=l;continue}let i=`data-${String(s).replace(/[A-Z]/g,c=>`-${c.toLowerCase()}`)}`;typeof l=="boolean"?n[i]=l?"":void 0:l!=null&&(n[i]=String(l))}return n}function Qt(e,t){return function(n){e(n),n.defaultPrevented||t(n)}}function Xt(e){return/^on[A-Z]/.test(e)}function ue(...e){let t=e.filter(Boolean);if(t.length!==0)return n=>{for(let r of t)typeof r=="function"?r(n):r&&(r.current=n)}}var er=8,tr=64,rr=0,be=.5,nr=180,sr=new Set(["ArrowDown","ArrowUp","End","Home","PageDown","PageUp"," "]),nt={start:!1,end:!1},or=[],ve={currentAnchorId:null,visibleMessageIds:or};function lr({content:e,scrollEdgeThreshold:t,spacer:n,viewport:r}){if(!r||!e)return nt;let s=je({content:e,spacer:n,viewport:r});return{start:r.scrollTop>t,end:s-r.scrollTop-r.clientHeight>t}}function ar({content:e,scrollMargin:t,scrollPreviousItemPeek:n,spacer:r,viewport:s,visibleMessageIds:l}){if(!e||!s)return ve;let a=s.getBoundingClientRect(),i=a.top+t+n,c=typeof IntersectionObserver>"u",f=[],g=null;for(let _ of ie(e,r)){let h=_.dataset.messageId;if(!h)continue;let d=_.dataset.scrollAnchor==="true",p=d||c?_.getBoundingClientRect():null;(c&&p?p.bottom>i&&p.top<a.bottom:l.has(h))&&f.push(h),d&&p&&p.top<=i+be&&(g=h)}return f.length===0&&g===null?ve:{currentAnchorId:g,visibleMessageIds:f}}function ie(e,t){return Array.from(e.children).filter(n=>n instanceof HTMLElement&&n!==t)}function ir(e,t){for(let n=t;n<e.length;n++){let r=e[n];if((r==null?void 0:r.dataset.scrollAnchor)==="true")return r}return null}function cr(e,t){for(let n of e)if(n.dataset.scrollAnchor==="true"&&!t.has(n))return n;return null}function ur(e,t){var r;let n=0;for(let s=t;s<e.length;s++)if(((r=e[s])==null?void 0:r.dataset.scrollAnchor)==="true"&&(n+=1,n>1))return!0;return!1}function dr(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if((n==null?void 0:n.dataset.scrollAnchor)==="true")return n}return null}function hr({content:e,spacer:t,viewport:n}){let r=n.getBoundingClientRect();for(let s of ie(e,t)){if(!s.dataset.messageId)continue;let l=s.getBoundingClientRect();if(l.bottom>r.top&&l.top<r.bottom)return s}return null}function fr({align:e,element:t,scrollMargin:n,spacer:r,viewport:s}){let l=st(t,s),a=t.getBoundingClientRect().height,i=mr(r);if(e==="center"){let c=Math.max(0,s.clientHeight-i.start-i.end);return l-i.start-(c-a)/2-n}if(e==="end")return l-s.clientHeight+a+i.end+n;if(e==="nearest"){let c=l+a,f=s.scrollTop+i.start,g=s.scrollTop+s.clientHeight-i.end;return l>=f&&c<=g?s.scrollTop:l<f?l-i.start-n:c-s.clientHeight+i.end+n}return l-i.start-n}function st(e,t){let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();return n.top-r.top+t.scrollTop}function ge(e,t){return e.getBoundingClientRect().top-t.getBoundingClientRect().top}function pr({content:e,scrollTop:t,spacer:n,viewport:r}){let s=je({content:e,spacer:n,viewport:r});return t+r.clientHeight-s}function je({content:e,spacer:t,viewport:n}){let r=ie(e,t),s=ot(e),l=n.getBoundingClientRect(),a=n.scrollTop,i=s.start+s.end;for(let c of r){let f=c.getBoundingClientRect();i=Math.max(i,f.bottom-l.top+a+s.end)}return i}function gr(e){return Math.max(0,e.scrollHeight-e.clientHeight)}function ot(e){let t=window.getComputedStyle(e);return{end:ke(t.paddingBlockEnd||t.paddingBottom),start:ke(t.paddingBlockStart||t.paddingTop)}}function mr(e){let t=e==null?void 0:e.parentElement;return t?ot(t):{end:0,start:0}}function br(e){if(!e)return 0;let t=window.getComputedStyle(e),n=t.rowGap==="normal"?t.gap:t.rowGap;return ke(n)}function ke(e){if(!e)return 0;let t=Number.parseFloat(e);return Number.isFinite(t)?t:0}function lt(e,t){let n=e,r=new Set;return{getSnapshot:()=>n,hasListeners:()=>r.size>0,setSnapshot:s=>{t(n,s)||(n=s,r.forEach(l=>l()))},subscribe:(s,l,a)=>{let i=r.size===0;return r.add(s),i&&(l==null||l()),()=>{r.delete(s),r.size===0&&(a==null||a())}}}}function Ue(e,t){return lt(e,t)}function vr(){return lt(ve,wr)}function _r(e,t){return e.start===t.start&&e.end===t.end}function wr(e,t){return e.currentAnchorId!==t.currentAnchorId||e.visibleMessageIds.length!==t.visibleMessageIds.length?!1:e.visibleMessageIds.every((n,r)=>n===t.visibleMessageIds[r])}function yr({autoScroll:e,defaultScrollPosition:t,scrollEdgeThreshold:n,scrollMargin:r,scrollPreviousItemPeek:s}){let l=u.useRef(e),a=u.useRef(!1),i=u.useRef(null),c=u.useRef(!1),f=u.useRef(n),g=u.useRef(0),_=u.useRef(null),h=u.useRef(0),d=u.useRef(e?"following-bottom":"free-scrolling"),p=u.useRef(new Map),C=u.useRef(null),b=u.useRef(null),T=u.useRef(null),k=u.useRef(s),M=u.useRef(!0),U=u.useRef(null),B=u.useRef(r),D=u.useRef(null),j=u.useRef(0),P=u.useRef(0),O=u.useRef(null),ee=u.useRef(null),Y=u.useRef(null),w=u.useRef(null),S=u.useRef(null),F=u.useRef(null),R=u.useRef(null),A=u.useRef(null),I=u.useRef(null),N=u.useRef(new Set),z=u.useRef(new WeakSet);return Y.current===null&&(Y.current=Ue(t==="end"||t==="last-anchor",(te,q)=>te===q)),w.current===null&&(w.current=Ue(nt,_r)),I.current===null&&(I.current=vr()),l.current=e,f.current=n,B.current=r,k.current=s,{autoScrollRef:l,autoscrollingRef:a,autoscrollingTimeoutRef:S,streamingTurnRef:T,contentRef:i,defaultScrollPositionAppliedRef:c,firstItemRef:_,itemCountRef:g,lastScrollTopRef:h,messageElementsRef:p,modeRef:d,pendingScrollFrameRef:D,pendingScrollToMessageRef:C,prependRestoreRef:b,preserveScrollOnPrependRef:M,pendingDefaultScrollStore:Y.current,rootRef:U,scrollEdgeThresholdRef:f,scrollMarginRef:B,scrollPreviousItemPeekRef:k,spacerGapRef:j,spacerHeightRef:P,spacerRef:O,stateFrameRef:ee,stateStore:w.current,viewportRef:F,visibilityFrameRef:R,visibilityObserverRef:A,visibilityStore:I.current,visibleMessageIdsRef:N,handledScrollAnchorsRef:z}}function at(e){e.pendingDefaultScrollStore.setSnapshot(!1)}function me(e){e.defaultScrollPositionAppliedRef.current=!0,at(e)}function Cr({refs:e,commitScrollState:t,scheduleStateCommit:n,scheduleVisibilitySync:r}){let{streamingTurnRef:s,autoScrollRef:l,autoscrollingRef:a,autoscrollingTimeoutRef:i,contentRef:c,itemCountRef:f,messageElementsRef:g,modeRef:_,pendingScrollToMessageRef:h,prependRestoreRef:d,scrollMarginRef:p,scrollPreviousItemPeekRef:C,spacerGapRef:b,spacerHeightRef:T,spacerRef:k,viewportRef:M}=e,U=u.useCallback(w=>{i.current!==null&&(window.clearTimeout(i.current),i.current=null),a.current!==w&&(a.current=w,t()),w&&(i.current=window.setTimeout(()=>{i.current=null,a.current=!1,t()},nr))},[t]),B=u.useCallback(w=>{let S=k.current;if(!S)return;let F=Math.max(0,Math.ceil(w));T.current!==F&&(T.current=F,S.hidden=F===0,S.style.height=`${F}px`,S.style.marginTop=F>0?`${-b.current}px`:"")},[]),D=u.useCallback((w,{behavior:S="auto",autoscrolling:F=!1}={})=>{let R=M.current;if(!R)return;let A=Math.max(0,w);if(Math.abs(R.scrollTop-A)<=be){R.scrollTop=A,t();return}F&&U(!0),R.scrollTo({top:A,behavior:S}),n()},[t,n,U]),j=u.useCallback(({behavior:w="auto"}={})=>M.current?(B(0),s.current=null,_.current="free-scrolling",D(0,{behavior:w}),r(),!0):!1,[r,D,B]),P=u.useCallback(({behavior:w="auto"}={})=>{let S=M.current;return S?(B(0),s.current=null,_.current=l.current?"following-bottom":"free-scrolling",D(gr(S),{autoscrolling:!0,behavior:w}),r(),!0):!1},[r,D,B]),O=u.useCallback((w,{align:S="start",behavior:F="auto",scrollMargin:R=p.current}={},{keepPreviousPeek:A=!1}={})=>{let I=c.current,N=M.current;if(!I||!N||!I.contains(w))return!1;let z=fr({align:S,element:w,scrollMargin:A?R+C.current:R,spacer:k.current,viewport:N}),te=pr({content:I,scrollTop:z,spacer:k.current,viewport:N});return B(te),d.current={element:w,viewportTop:ge(w,N)},_.current=A?"anchored-to-message":"settling-jump",s.current=A?w:null,D(z,{behavior:F}),r(),!0},[r,D,B]),ee=u.useCallback(()=>{let w=s.current;return!w||!w.isConnected||_.current!=="anchored-to-message"?!1:O(w,{align:"start"},{keepPreviousPeek:!0})},[O]),Y=u.useCallback((w,S)=>{let F=g.current.get(w);return F?(me(e),O(F,S)?(h.current=null,!0):(h.current={messageId:w,options:S},!0)):f.current===0?(h.current={messageId:w,options:S},me(e),!0):!1},[O]);return{flushPendingScrollToMessage:u.useCallback(()=>{let w=h.current;if(!w)return!1;let S=g.current.get(w.messageId);return!S||!O(S,w.options)?!1:(h.current=null,me(e),!0)},[O]),reanchorToAnchoredMessage:ee,scrollToElement:O,scrollToEnd:P,scrollToMessage:Y,scrollToStart:j}}function Ye(e,t){return u.useCallback(n=>{e.current=n,n&&t()},[e,t])}function kr({autoScroll:e=!1,defaultScrollPosition:t="end",scrollEdgeThreshold:n=er,scrollPreviousItemPeek:r=tr,scrollMargin:s=rr}){let l=yr({autoScroll:e,defaultScrollPosition:t,scrollEdgeThreshold:n,scrollMargin:s,scrollPreviousItemPeek:r}),{streamingTurnRef:a,autoScrollRef:i,autoscrollingRef:c,autoscrollingTimeoutRef:f,contentRef:g,defaultScrollPositionAppliedRef:_,firstItemRef:h,itemCountRef:d,lastScrollTopRef:p,messageElementsRef:C,modeRef:b,pendingScrollFrameRef:T,pendingScrollToMessageRef:k,prependRestoreRef:M,preserveScrollOnPrependRef:U,pendingDefaultScrollStore:B,rootRef:D,scrollEdgeThresholdRef:j,scrollMarginRef:P,scrollPreviousItemPeekRef:O,spacerGapRef:ee,spacerHeightRef:Y,spacerRef:w,stateFrameRef:S,stateStore:F,viewportRef:R,visibilityFrameRef:A,visibilityObserverRef:I,visibilityStore:N,visibleMessageIdsRef:z,handledScrollAnchorsRef:te}=l,q=u.useRef(t);q.current!==t&&(q.current=t,_.current=!1);let K=u.useCallback(m=>{let y=D.current,x=R.current,L=[m.start&&"start",m.end&&"end"].filter(Boolean).join(" "),re=c.current;for(let H of[y,x])H&&(L?H.setAttribute("data-scrollable",L):H.removeAttribute("data-scrollable"),H.toggleAttribute("data-autoscrolling",re))},[]),Q=u.useCallback(m=>{var L;let y=((L=R.current)==null?void 0:L.scrollTop)??0,x=y<p.current-be;p.current=y,i.current&&!m.end&&b.current!=="settling-jump"&&b.current!=="anchored-to-message"?b.current="following-bottom":b.current==="following-bottom"&&m.end&&x&&!c.current&&(b.current="free-scrolling")},[]),J=u.useCallback(()=>{let m=lr({content:g.current,scrollEdgeThreshold:j.current,spacer:w.current,viewport:R.current});Q(m);let y=b.current==="following-bottom"?{...m,end:!1}:m;K(y),F.setSnapshot(y)},[Q,F,K]),ne=u.useCallback(()=>{S.current===null&&(S.current=window.requestAnimationFrame(()=>{S.current=null,J()}))},[J]),E=u.useCallback(()=>{N.hasListeners()&&A.current===null&&(A.current=window.requestAnimationFrame(()=>{A.current=null,N.hasListeners()&&N.setSnapshot(ar({content:g.current,scrollMargin:P.current,scrollPreviousItemPeek:O.current,spacer:w.current,viewport:R.current,visibleMessageIds:z.current}))}))},[N]),{flushPendingScrollToMessage:W,reanchorToAnchoredMessage:Z,scrollToElement:G,scrollToEnd:$,scrollToMessage:Ee,scrollToStart:he}=Cr({refs:l,commitScrollState:J,scheduleStateCommit:ne,scheduleVisibilitySync:E}),Re=u.useCallback(()=>{let m=M.current,y=R.current;if(!m||!y||!m.element.isConnected)return!1;let x=ge(m.element,y)-m.viewportTop;return Math.abs(x)<=be?!1:(y.scrollTop+=x,m.viewportTop=ge(m.element,y),ne(),E(),!0)},[ne,E]),oe=u.useCallback(()=>{let m=g.current,y=R.current;if(!m||!y){M.current=null;return}let x=hr({content:m,spacer:w.current,viewport:y});M.current=x?{element:x,viewportTop:ge(x,y)}:null},[]),Ae=u.useCallback(()=>{T.current===null&&(T.current=window.requestAnimationFrame(()=>{T.current=null,W()&&oe()}))},[oe,W]),fe=u.useCallback(()=>{if(!t||_.current||d.current===0)return!1;let m=!1;if(t==="last-anchor"){let y=g.current,x=R.current,L=y&&x?dr(ie(y,w.current)):null;if(!y||!x||!L)m=$({behavior:"auto"});else{let re=st(L,x);m=je({content:y,spacer:w.current,viewport:x})-re<=x.clientHeight?$({behavior:"auto"}):G(L,{align:"start"},{keepPreviousPeek:!0})}}else m=t==="end"?$({behavior:"auto"}):he({behavior:"auto"});return m?(me(l),!0):!1},[t,G,$,he]),Me=u.useCallback(()=>{let m=g.current;if(!m)return;let y=ie(m,w.current),x=d.current,L=h.current;d.current=y.length,h.current=y[0]??null,(()=>{if(W())return;if(x===0){if(fe()||y.length>0&&i.current&&$({behavior:"auto"}))return;J(),E();return}let re=L?y.indexOf(L):-1;if(U.current&&re>0){Re();return}if(y.length>x){let H=ir(y,x);if(H){if(i.current&&b.current==="following-bottom"&&ur(y,x)){$({behavior:"auto"});return}G(H,{align:"start"},{keepPreviousPeek:!0}),te.current.add(H);return}}if(y.length===x){let H=cr(y,te.current);if(H){G(H,{align:"start"},{keepPreviousPeek:!0}),te.current.add(H);return}}b.current==="following-bottom"&&i.current?$({behavior:"auto"}):(J(),E())})(),oe()},[fe,oe,J,W,Re,E,G,$]),Be=u.useCallback(()=>{if(b.current==="following-bottom"&&i.current){$({behavior:"auto"});return}let m=Y.current;if(Z()){i.current&&m>0&&Y.current===0&&$({behavior:"auto"});return}ne(),E()},[Z,ne,E,$]),De=u.useCallback(()=>{let m=R.current;if(!(!m||!N.hasListeners())){if(typeof IntersectionObserver>"u"){E();return}I.current||(I.current=new IntersectionObserver(y=>{for(let x of y){let L=x.target.dataset.messageId;L&&(x.isIntersecting?z.current.add(L):z.current.delete(L))}E()},{root:m,rootMargin:`${-(P.current+O.current)}px 0px 0px 0px`,threshold:[0,.01,.5,1]})),C.current.forEach(y=>{var x;(x=I.current)==null||x.observe(y)}),E()}},[E,N]),Ie=u.useCallback(()=>{var m;A.current!==null&&(window.cancelAnimationFrame(A.current),A.current=null),(m=I.current)==null||m.disconnect(),I.current=null,z.current.clear(),N.setSnapshot(ve)},[N]),ft=u.useCallback((m,y,x)=>{var L,re,H;if(y){C.current.set(m,y),(L=I.current)==null||L.observe(y),E(),((re=k.current)==null?void 0:re.messageId)===m&&Ae();return}x&&C.current.get(m)===x&&(C.current.delete(m),z.current.delete(m),(H=I.current)==null||H.unobserve(x),E())},[Ae,E]),Ne=u.useCallback(()=>{(b.current==="following-bottom"||b.current==="anchored-to-message"||b.current==="settling-jump")&&(a.current=null,b.current="free-scrolling")},[]),Pe=u.useCallback(()=>K(F.getSnapshot()),[F,K]),Le=Ye(D,Pe),Oe=Ye(R,Pe),qe=u.useCallback(m=>{g.current=m},[]),We=u.useCallback(m=>{w.current=m,ee.current=br((m==null?void 0:m.parentElement)??null)},[]),$e=u.useCallback(()=>{J(),E(),oe()},[oe,J,E]),pt=u.useMemo(()=>({handleContentChange:Me,handleResize:Be,observeVisibility:De,pendingDefaultScrollStore:B,preserveScrollOnPrependRef:U,scrollToEnd:$,scrollToMessage:Ee,scrollToStart:he,setContentElement:qe,setRootElement:Le,setSpacerElement:We,setViewportElement:Oe,stateStore:F,syncAfterScroll:$e,unobserveVisibility:Ie,userScrollIntent:Ne,viewportRef:R,visibilityStore:N}),[Me,Be,De,B,$,Ee,he,qe,Le,We,Oe,F,$e,Ie,Ne,N]);return u.useLayoutEffect(()=>{fe()||d.current===0&&at(l)},[fe]),u.useEffect(()=>()=>{var m;S.current!==null&&(window.cancelAnimationFrame(S.current),S.current=null),A.current!==null&&(window.cancelAnimationFrame(A.current),A.current=null),f.current!==null&&(window.clearTimeout(f.current),f.current=null),T.current!==null&&(window.cancelAnimationFrame(T.current),T.current=null),(m=I.current)==null||m.disconnect(),I.current=null},[]),u.useLayoutEffect(()=>{if(e&&b.current==="following-bottom"&&d.current>0){$({behavior:"auto"});return}J()},[e,J,$]),{context:pt,registerMessage:ft}}function xr(e){let t=u.useRef(e);return t.current=e,t}var it=u.createContext(null),ct=u.createContext(null);function de(){let e=u.useContext(it);if(!e)throw new Error("useMessageScroller must be used within a MessageScroller.");return e}function Sr(){let e=u.useContext(ct);if(!e)throw new Error("MessageScrollerItem must be used within a MessageScroller.");return e}function Tr({autoScroll:e=!1,children:t,defaultScrollPosition:n="end",scrollEdgeThreshold:r,scrollPreviousItemPeek:s,scrollMargin:l}){let{context:a,registerMessage:i}=kr({autoScroll:e,defaultScrollPosition:n,scrollEdgeThreshold:r,scrollPreviousItemPeek:s,scrollMargin:l});return o.jsx(it.Provider,{value:a,children:o.jsx(ct.Provider,{value:i,children:t})})}function ut(){let{pendingDefaultScrollStore:e}=de();return u.useSyncExternalStore(e.subscribe,e.getSnapshot,e.getSnapshot)}function jr({children:e,...t}){let{setRootElement:n}=de(),r=ut();return o.jsx("div",{ref:n,...t,...r?{"data-pending-scroll":""}:null,children:e})}function Fr({"aria-label":e,children:t,onKeyDown:n,onScroll:r,onTouchMove:s,onWheel:l,preserveScrollOnPrepend:a=!0,ref:i,role:c,tabIndex:f,...g}){let{handleResize:_,preserveScrollOnPrependRef:h,setViewportElement:d,syncAfterScroll:p,userScrollIntent:C,viewportRef:b}=de(),T=ut();h.current=a;let k=u.useCallback(j=>{var P;d(j),(P=ue(i))==null||P(j)},[i,d]);function M(j){p(),r==null||r(j)}function U(j){C(),l==null||l(j)}function B(j){C(),s==null||s(j)}function D(j){sr.has(j.key)&&C(),n==null||n(j)}return u.useEffect(()=>{let j=b.current;if(!j||typeof ResizeObserver>"u")return;let P=0,O=new ResizeObserver(()=>{window.cancelAnimationFrame(P),P=window.requestAnimationFrame(_)});return O.observe(j),()=>{window.cancelAnimationFrame(P),O.disconnect()}},[_,b]),o.jsx("div",{ref:k,role:c??"region","aria-label":e??"Messages",tabIndex:f??0,onKeyDown:D,onScroll:M,onTouchMove:B,onWheel:U,...g,...T?{"data-pending-scroll":""}:null,children:t})}function Er({"aria-relevant":e,children:t,ref:n,role:r,spacerClassName:s,...l}){let{handleContentChange:a,handleResize:i,setContentElement:c,setSpacerElement:f}=de(),g=u.useRef(null),_=u.useCallback(h=>{var d;g.current=h,c(h),(d=ue(n))==null||d(h)},[n,c]);return u.useLayoutEffect(()=>{let h=g.current;if(!h||(a(),typeof MutationObserver>"u"))return;let d=new MutationObserver(()=>{a()});return d.observe(h,{childList:!0}),()=>d.disconnect()},[a]),u.useEffect(()=>{let h=g.current;if(!h||typeof ResizeObserver>"u")return;let d=0,p=new ResizeObserver(()=>{window.cancelAnimationFrame(d),d=window.requestAnimationFrame(i)});return p.observe(h),()=>{window.cancelAnimationFrame(d),p.disconnect()}},[i]),o.jsxs("div",{ref:_,role:r??"log","aria-relevant":e??"additions",...l,children:[t,o.jsx("div",{ref:f,"aria-hidden":"true","data-message-scroller-spacer":"",hidden:!0,className:s})]})}function Rr({messageId:e,ref:t,scrollAnchor:n=!1,...r}){let s=Sr(),l=u.useRef(null),a=u.useCallback(i=>{var f;let c=l.current;l.current=i,e&&s(e,i,c),(f=ue(t))==null||f(i)},[e,t,s]);return o.jsx("div",{ref:a,"data-message-id":e,"data-scroll-anchor":n?"true":"false",...r})}function Ar({behavior:e="smooth",children:t,direction:n="end",onClick:r,render:s,tabIndex:l,type:a="button",...i}){let{scrollToEnd:c,scrollToStart:f,stateStore:g}=de(),_=xr(r),h=u.useCallback(b=>g.subscribe(b),[g]),d=u.useCallback(()=>{let b=g.getSnapshot();return n==="start"?b.start:b.end},[n,g]),p=u.useSyncExternalStore(h,d,d),C=u.useCallback(b=>{var T;p&&((T=_.current)==null||T.call(_,b),b.defaultPrevented||(b.currentTarget.blur(),n==="start"?f({behavior:e}):c({behavior:e})))},[e,n,p,_,c,f]);return Zt({defaultTagName:"button",props:Ce({type:a,inert:!p,tabIndex:p?l:-1,children:t??o.jsxs("span",{children:["Scroll to ",n]}),onClick:C},i),render:s,state:{active:p,direction:n},stateAttributesMapping:{active:b=>({"data-active":b?"true":"false"})}})}var le={Provider:Tr,Root:jr,Viewport:Fr,Content:Er,Item:Rr,Button:Ar};function dt(e){var t,n,r="";if(typeof e=="string"||typeof e=="number")r+=e;else if(typeof e=="object")if(Array.isArray(e)){var s=e.length;for(t=0;t<s;t++)e[t]&&(n=dt(e[t]))&&(r&&(r+=" "),r+=n)}else for(n in e)e[n]&&(r&&(r+=" "),r+=n);return r}function Mr(){for(var e,t,n=0,r="",s=arguments.length;n<s;n++)(e=arguments[n])&&(t=dt(e))&&(r&&(r+=" "),r+=t);return r}function ae(...e){return Mr(e)}function Br(e){return o.jsx(le.Provider,{...e})}function Dr({className:e,...t}){return o.jsx(le.Root,{"data-slot":"message-scroller",className:ae("msg-scroller-root",e),...t})}function Ir({className:e,...t}){return o.jsx(le.Viewport,{"data-slot":"message-scroller-viewport",className:ae("msg-scroller-viewport",e),...t})}function Nr({className:e,...t}){return o.jsx(le.Content,{"data-slot":"message-scroller-content",className:ae("msg-scroller-content",e),...t})}function Je({className:e,scrollAnchor:t=!1,...n}){return o.jsx(le.Item,{"data-slot":"message-scroller-item",scrollAnchor:t,className:ae("msg-scroller-item",e),...n})}function Pr({direction:e="end",className:t,children:n,...r}){return o.jsx(le.Button,{"data-slot":"message-scroller-button",direction:e,className:ae("msg-scroller-btn",t),...r,children:n??o.jsxs(o.Fragment,{children:[o.jsx(Rt,{size:16,"aria-hidden":"true",className:e==="start"?"rotate-180":void 0}),o.jsx("span",{className:"sr-only",children:e==="end"?"Jump to latest":"Jump to start"})]})})}const Lr=()=>o.jsxs("div",{className:"chat-empty-row",children:[o.jsx("div",{className:"avatar-circle avatar-circle--mt","aria-hidden":"true",children:o.jsx(tt,{size:15})}),o.jsx("div",{className:"chat-empty-bubble",children:o.jsx("p",{children:"Hello — I am the VPS Veritas assistant. Ask about reports, sample status, registration, or support, or choose a question below the text box."})})]});function X(e){if(!e)return[];const t=/(\[[^\]]+\]\([^)]+\)|\*\*[^*]+\*\*|\*[^*]+\*|`[^`]+`|https?:\/\/[^\s]+)/g;return e.split(t).map((r,s)=>{if(!r)return null;const l=r.match(/^\[([^\]]+)\]\(([^)]+)\)$/);if(l){const a=l[1],i=l[2],c=/^https?:\/\//i.test(i);return o.jsx("a",{href:i,target:c?"_blank":void 0,rel:c?"noopener noreferrer":void 0,className:"md-link",children:a},s)}return r.startsWith("**")&&r.endsWith("**")&&r.length>=4?o.jsx("strong",{children:r.slice(2,-2)},s):r.startsWith("*")&&r.endsWith("*")&&r.length>=2?o.jsx("em",{children:r.slice(1,-1)},s):r.startsWith("`")&&r.endsWith("`")&&r.length>=2?o.jsx("code",{className:"md-code",children:r.slice(1,-1)},s):/^https?:\/\//i.test(r)?o.jsx("a",{href:r,target:"_blank",rel:"noopener noreferrer",className:"md-link",children:r},s):o.jsx(v.Fragment,{children:r},s)})}function Or(e){const t=e.replace(/\r\n/g,`
131
+ */const Yt=$("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),Jt={alpha:{label:"Alpha",Icon:$t,variant:"env-badge--alpha",tooltip:"Alpha build — internal testing only"},beta:{label:"Beta",Icon:Ut,variant:"env-badge--beta",tooltip:"Beta build — public pre-release"},gamma:{label:"Gamma",Icon:Ht,variant:"env-badge--gamma",tooltip:"Gamma / Release Candidate"},qa:{label:"QA",Icon:Ot,variant:"env-badge--qa",tooltip:"Quality Assurance build"}},Kt=({stage:e,pulse:t=!0,className:n=""})=>{if(!e)return null;const{label:r,Icon:o,variant:l,tooltip:a}=Jt[e];return s.jsxs("span",{className:`env-badge-inline ${l} ${n}`.trim(),title:a,"aria-label":`${r} build`,role:"status",children:[s.jsx(o,{size:10,className:"env-badge-icon","aria-hidden":"true"}),s.jsx("span",{className:"env-badge-inline-label",children:r})]})},Qt=e=>s.jsx("svg",{width:e.width||"24px",height:e.height||"24px",viewBox:"0 0 24 24",role:"img",xmlns:"http://www.w3.org/2000/svg",fill:e.Color||"currentColor",...e,children:s.jsx("path",{d:"M11.999 0c-2.25 0-4.5.06-6.6.21a5.57 5.57 0 0 0-5.19 5.1c-.24 3.21-.27 6.39-.06 9.6a5.644 5.644 0 0 0 5.7 5.19h3.15v-3.9h-3.15c-.93.03-1.74-.63-1.83-1.56-.18-3-.15-6 .06-9 .06-.84.72-1.47 1.56-1.53 2.04-.15 4.2-.21 6.36-.21s4.32.09 6.36.18c.81.06 1.5.69 1.56 1.53.24 3 .24 6 .06 9-.12.93-.9 1.62-1.83 1.59h-3.15l-6 3.9V24l6-3.9h3.15c2.97.03 5.46-2.25 5.7-5.19.21-3.18.18-6.39-.03-9.57a5.57 5.57 0 0 0-5.19-5.1c-2.13-.18-4.38-.24-6.63-.24zm-5.04 8.76c-.36 0-.66.3-.66.66v2.34c0 .33.18.63.48.78 1.62.78 3.42 1.2 5.22 1.26 1.8-.06 3.6-.48 5.22-1.26.3-.15.48-.45.48-.78V9.42c0-.09-.03-.15-.09-.21a.648.648 0 0 0-.87-.36c-1.5.66-3.12 1.02-4.77 1.05-1.65-.03-3.27-.42-4.77-1.08a.566.566 0 0 0-.24-.06z"})}),Xt=({title:e="VPS AI Assistant",subtitle:t="Customer portal support",onClose:n,onReset:r,onBack:o,showMinimize:l=!1,envStage:a,envPulse:i=!0})=>s.jsxs("header",{className:"chat-header",children:[s.jsxs("div",{className:"chat-header-left",children:[o&&s.jsx("button",{type:"button",onClick:o,className:"icon-btn-back","aria-label":"Back",children:s.jsx(Mt,{size:16})}),s.jsx("div",{className:"avatar-circle","aria-hidden":"true",children:s.jsx(Qt,{width:"16px",height:"16px",color:"white"})}),s.jsxs("div",{children:[s.jsxs("div",{className:"chat-header-title-row",children:[s.jsx("h2",{className:"chat-header-title",children:e}),s.jsx(Kt,{stage:a,pulse:i})]}),s.jsx("p",{className:"chat-header-subtitle",children:t||"Customer portal support"})]})]}),s.jsxs("div",{className:"chat-header-actions",children:[r&&s.jsx("button",{type:"button",onClick:r,className:"icon-btn-action","aria-label":"Start a new conversation",title:"New conversation",children:s.jsx(Vt,{size:15})}),n&&s.jsx("button",{type:"button",onClick:n,className:"icon-btn-action","aria-label":l?"Minimize chat":"Close chat",children:s.jsx(Wt,{size:16})})]})]});function Zt(e,t){const n=b.useRef(e);b.useEffect(()=>{var r;n.current&&!e&&((r=t.current)==null||r.focus()),n.current=e},[e,t])}function er(e,t){const n=t.trim().toLowerCase();return n?e.filter(r=>r.label.toLowerCase().includes(n)||r.query.toLowerCase().includes(n)):e}const tr=({suggestions:e,onSelect:t,disabled:n,variant:r="list"})=>e.length?r==="badge"?s.jsx("ul",{className:"suggestions-badge-list","aria-label":"Suggested questions",children:e.map(o=>s.jsx("li",{className:"suggestion-badge-item",children:s.jsx("button",{type:"button",disabled:n,onClick:()=>t(o),title:o.query,className:"suggestion-badge-btn",children:o.label})},o.query))}):s.jsx("div",{className:"suggestions-list",children:e.map(o=>s.jsx("button",{type:"button",disabled:n,onClick:()=>t(o),className:"suggestion-list-btn",children:o.label},o.query))}):null,rr=({onSend:e,disabled:t=!1,placeholder:n="Ask something…"})=>{const{suggestions:r,showSuggestions:o,suggestionBadgesEnabled:l,models:a,selectedModelId:i,selectModel:u}=ve(),[h,g]=b.useState(""),f=b.useRef(null),c=b.useId(),p=m=>{m&&(m.style.height="auto",m.style.height=`${Math.min(m.scrollHeight,96)}px`)};Zt(t,f),b.useEffect(()=>{p(f.current)},[h]);const v=b.useMemo(()=>{if(!l||t)return[];const m=h.trim();return m?er(r,m):o?r:[]},[t,o,l,r,h]),y=m=>{g(m.query);const I=f.current;I==null||I.focus()},_=()=>{const m=h.trim();!m||t||(e(m),g(""),f.current&&(f.current.style.height="auto"))};return s.jsxs("div",{className:"chat-input-wrapper",children:[s.jsx(tr,{variant:"badge",suggestions:v,onSelect:y,disabled:t}),s.jsx("label",{htmlFor:"vps-chat-input",className:"sr-only",children:"Chat message"}),s.jsxs("div",{className:"chat-input-row",children:[s.jsx("textarea",{id:"vps-chat-input",ref:f,rows:1,value:h,disabled:t,placeholder:n,onChange:m=>{g(m.target.value),p(m.target)},onKeyDown:m=>{m.key==="Enter"&&!m.shiftKey&&(m.preventDefault(),_())},className:"chat-textarea"}),s.jsx("button",{type:"button",onClick:_,disabled:t||!h.trim(),"aria-label":"Send message",className:"chat-send-btn",children:s.jsx(Nt,{size:16})})]}),a.length>1&&s.jsxs("div",{className:"chat-model-picker",children:[s.jsx("label",{htmlFor:c,children:"AI model"}),s.jsxs("select",{id:c,"aria-label":"AI model",value:i,disabled:t,onChange:m=>u(m.target.value),children:[s.jsx("option",{value:"auto",children:"Automatic"}),a.map(m=>s.jsx("option",{value:m.id,disabled:!m.configured,children:m.label},m.id))]})]}),s.jsxs("p",{className:"chat-input-footer",children:["Powered by ",s.jsx("span",{className:"chat-input-footer-brand",children:"VPS Veritas AI"})]})]})};function nr({defaultTagName:e,props:t,render:n,state:r={},stateAttributesMapping:o}){let l=Be(sr(r,o),t);if(!n)return d.createElement(e,l);if(typeof n=="function")return n(l,r);if(!d.isValidElement(n))return null;let a=n.props,i={...Be(l,a),ref:_e(l.ref,a.ref)};return d.cloneElement(n,i)}function Be(...e){let t={};for(let n of e){if(!n)continue;let r=n;for(let o of Object.keys(r)){let l=r[o];if(l===void 0)continue;let a=t[o];o==="className"?t[o]=[a,l].filter(Boolean).join(" "):o==="style"?t[o]={...a,...l}:o==="ref"?t[o]=_e(a,l):lr(o)&&typeof a=="function"&&typeof l=="function"?t[o]=or(l,a):t[o]=l}}return t}function sr(e,t){var r;let n={};for(let o of Object.keys(e)){let l=e[o],a=(r=t==null?void 0:t[o])==null?void 0:r.call(t,l);if(a){Object.assign(n,a);continue}if(o==="slot"){n["data-slot"]=l;continue}let i=`data-${String(o).replace(/[A-Z]/g,u=>`-${u.toLowerCase()}`)}`;typeof l=="boolean"?n[i]=l?"":void 0:l!=null&&(n[i]=String(l))}return n}function or(e,t){return function(n){e(n),n.defaultPrevented||t(n)}}function lr(e){return/^on[A-Z]/.test(e)}function _e(...e){let t=e.filter(Boolean);if(t.length!==0)return n=>{for(let r of t)typeof r=="function"?r(n):r&&(r.current=n)}}var ar=8,ir=64,cr=0,Re=.5,ur=180,dr=new Set(["ArrowDown","ArrowUp","End","Home","PageDown","PageUp"," "]),it={start:!1,end:!1},hr=[],Fe={currentAnchorId:null,visibleMessageIds:hr};function pr({content:e,scrollEdgeThreshold:t,spacer:n,viewport:r}){if(!r||!e)return it;let o=$e({content:e,spacer:n,viewport:r});return{start:r.scrollTop>t,end:o-r.scrollTop-r.clientHeight>t}}function fr({content:e,scrollMargin:t,scrollPreviousItemPeek:n,spacer:r,viewport:o,visibleMessageIds:l}){if(!e||!o)return Fe;let a=o.getBoundingClientRect(),i=a.top+t+n,u=typeof IntersectionObserver>"u",h=[],g=null;for(let f of be(e,r)){let c=f.dataset.messageId;if(!c)continue;let p=f.dataset.scrollAnchor==="true",v=p||u?f.getBoundingClientRect():null;(u&&v?v.bottom>i&&v.top<a.bottom:l.has(c))&&h.push(c),p&&v&&v.top<=i+Re&&(g=c)}return h.length===0&&g===null?Fe:{currentAnchorId:g,visibleMessageIds:h}}function be(e,t){return Array.from(e.children).filter(n=>n instanceof HTMLElement&&n!==t)}function mr(e,t){for(let n=t;n<e.length;n++){let r=e[n];if((r==null?void 0:r.dataset.scrollAnchor)==="true")return r}return null}function gr(e,t){for(let n of e)if(n.dataset.scrollAnchor==="true"&&!t.has(n))return n;return null}function br(e,t){var r;let n=0;for(let o=t;o<e.length;o++)if(((r=e[o])==null?void 0:r.dataset.scrollAnchor)==="true"&&(n+=1,n>1))return!0;return!1}function vr(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if((n==null?void 0:n.dataset.scrollAnchor)==="true")return n}return null}function _r({content:e,spacer:t,viewport:n}){let r=n.getBoundingClientRect();for(let o of be(e,t)){if(!o.dataset.messageId)continue;let l=o.getBoundingClientRect();if(l.bottom>r.top&&l.top<r.bottom)return o}return null}function wr({align:e,element:t,scrollMargin:n,spacer:r,viewport:o}){let l=ct(t,o),a=t.getBoundingClientRect().height,i=kr(r);if(e==="center"){let u=Math.max(0,o.clientHeight-i.start-i.end);return l-i.start-(u-a)/2-n}if(e==="end")return l-o.clientHeight+a+i.end+n;if(e==="nearest"){let u=l+a,h=o.scrollTop+i.start,g=o.scrollTop+o.clientHeight-i.end;return l>=h&&u<=g?o.scrollTop:l<h?l-i.start-n:u-o.clientHeight+i.end+n}return l-i.start-n}function ct(e,t){let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();return n.top-r.top+t.scrollTop}function Se(e,t){return e.getBoundingClientRect().top-t.getBoundingClientRect().top}function yr({content:e,scrollTop:t,spacer:n,viewport:r}){let o=$e({content:e,spacer:n,viewport:r});return t+r.clientHeight-o}function $e({content:e,spacer:t,viewport:n}){let r=be(e,t),o=ut(e),l=n.getBoundingClientRect(),a=n.scrollTop,i=o.start+o.end;for(let u of r){let h=u.getBoundingClientRect();i=Math.max(i,h.bottom-l.top+a+o.end)}return i}function xr(e){return Math.max(0,e.scrollHeight-e.clientHeight)}function ut(e){let t=window.getComputedStyle(e);return{end:Pe(t.paddingBlockEnd||t.paddingBottom),start:Pe(t.paddingBlockStart||t.paddingTop)}}function kr(e){let t=e==null?void 0:e.parentElement;return t?ut(t):{end:0,start:0}}function Cr(e){if(!e)return 0;let t=window.getComputedStyle(e),n=t.rowGap==="normal"?t.gap:t.rowGap;return Pe(n)}function Pe(e){if(!e)return 0;let t=Number.parseFloat(e);return Number.isFinite(t)?t:0}function dt(e,t){let n=e,r=new Set;return{getSnapshot:()=>n,hasListeners:()=>r.size>0,setSnapshot:o=>{t(n,o)||(n=o,r.forEach(l=>l()))},subscribe:(o,l,a)=>{let i=r.size===0;return r.add(o),i&&(l==null||l()),()=>{r.delete(o),r.size===0&&(a==null||a())}}}}function Qe(e,t){return dt(e,t)}function Sr(){return dt(Fe,Rr)}function jr(e,t){return e.start===t.start&&e.end===t.end}function Rr(e,t){return e.currentAnchorId!==t.currentAnchorId||e.visibleMessageIds.length!==t.visibleMessageIds.length?!1:e.visibleMessageIds.every((n,r)=>n===t.visibleMessageIds[r])}function Fr({autoScroll:e,defaultScrollPosition:t,scrollEdgeThreshold:n,scrollMargin:r,scrollPreviousItemPeek:o}){let l=d.useRef(e),a=d.useRef(!1),i=d.useRef(null),u=d.useRef(!1),h=d.useRef(n),g=d.useRef(0),f=d.useRef(null),c=d.useRef(0),p=d.useRef(e?"following-bottom":"free-scrolling"),v=d.useRef(new Map),y=d.useRef(null),_=d.useRef(null),m=d.useRef(null),I=d.useRef(o),j=d.useRef(!0),B=d.useRef(null),k=d.useRef(r),T=d.useRef(null),A=d.useRef(0),z=d.useRef(0),L=d.useRef(null),ne=d.useRef(null),J=d.useRef(null),x=d.useRef(null),E=d.useRef(null),M=d.useRef(null),N=d.useRef(null),D=d.useRef(null),O=d.useRef(null),P=d.useRef(new Set),U=d.useRef(new WeakSet);return J.current===null&&(J.current=Qe(t==="end"||t==="last-anchor",(Z,ae)=>Z===ae)),x.current===null&&(x.current=Qe(it,jr)),O.current===null&&(O.current=Sr()),l.current=e,h.current=n,k.current=r,I.current=o,{autoScrollRef:l,autoscrollingRef:a,autoscrollingTimeoutRef:E,streamingTurnRef:m,contentRef:i,defaultScrollPositionAppliedRef:u,firstItemRef:f,itemCountRef:g,lastScrollTopRef:c,messageElementsRef:v,modeRef:p,pendingScrollFrameRef:T,pendingScrollToMessageRef:y,prependRestoreRef:_,preserveScrollOnPrependRef:j,pendingDefaultScrollStore:J.current,rootRef:B,scrollEdgeThresholdRef:h,scrollMarginRef:k,scrollPreviousItemPeekRef:I,spacerGapRef:A,spacerHeightRef:z,spacerRef:L,stateFrameRef:ne,stateStore:x.current,viewportRef:M,visibilityFrameRef:N,visibilityObserverRef:D,visibilityStore:O.current,visibleMessageIdsRef:P,handledScrollAnchorsRef:U}}function ht(e){e.pendingDefaultScrollStore.setSnapshot(!1)}function je(e){e.defaultScrollPositionAppliedRef.current=!0,ht(e)}function Er({refs:e,commitScrollState:t,scheduleStateCommit:n,scheduleVisibilitySync:r}){let{streamingTurnRef:o,autoScrollRef:l,autoscrollingRef:a,autoscrollingTimeoutRef:i,contentRef:u,itemCountRef:h,messageElementsRef:g,modeRef:f,pendingScrollToMessageRef:c,prependRestoreRef:p,scrollMarginRef:v,scrollPreviousItemPeekRef:y,spacerGapRef:_,spacerHeightRef:m,spacerRef:I,viewportRef:j}=e,B=d.useCallback(x=>{i.current!==null&&(window.clearTimeout(i.current),i.current=null),a.current!==x&&(a.current=x,t()),x&&(i.current=window.setTimeout(()=>{i.current=null,a.current=!1,t()},ur))},[t]),k=d.useCallback(x=>{let E=I.current;if(!E)return;let M=Math.max(0,Math.ceil(x));m.current!==M&&(m.current=M,E.hidden=M===0,E.style.height=`${M}px`,E.style.marginTop=M>0?`${-_.current}px`:"")},[]),T=d.useCallback((x,{behavior:E="auto",autoscrolling:M=!1}={})=>{let N=j.current;if(!N)return;let D=Math.max(0,x);if(Math.abs(N.scrollTop-D)<=Re){N.scrollTop=D,t();return}M&&B(!0),N.scrollTo({top:D,behavior:E}),n()},[t,n,B]),A=d.useCallback(({behavior:x="auto"}={})=>j.current?(k(0),o.current=null,f.current="free-scrolling",T(0,{behavior:x}),r(),!0):!1,[r,T,k]),z=d.useCallback(({behavior:x="auto"}={})=>{let E=j.current;return E?(k(0),o.current=null,f.current=l.current?"following-bottom":"free-scrolling",T(xr(E),{autoscrolling:!0,behavior:x}),r(),!0):!1},[r,T,k]),L=d.useCallback((x,{align:E="start",behavior:M="auto",scrollMargin:N=v.current}={},{keepPreviousPeek:D=!1}={})=>{let O=u.current,P=j.current;if(!O||!P||!O.contains(x))return!1;let U=wr({align:E,element:x,scrollMargin:D?N+y.current:N,spacer:I.current,viewport:P}),Z=yr({content:O,scrollTop:U,spacer:I.current,viewport:P});return k(Z),p.current={element:x,viewportTop:Se(x,P)},f.current=D?"anchored-to-message":"settling-jump",o.current=D?x:null,T(U,{behavior:M}),r(),!0},[r,T,k]),ne=d.useCallback(()=>{let x=o.current;return!x||!x.isConnected||f.current!=="anchored-to-message"?!1:L(x,{align:"start"},{keepPreviousPeek:!0})},[L]),J=d.useCallback((x,E)=>{let M=g.current.get(x);return M?(je(e),L(M,E)?(c.current=null,!0):(c.current={messageId:x,options:E},!0)):h.current===0?(c.current={messageId:x,options:E},je(e),!0):!1},[L]);return{flushPendingScrollToMessage:d.useCallback(()=>{let x=c.current;if(!x)return!1;let E=g.current.get(x.messageId);return!E||!L(E,x.options)?!1:(c.current=null,je(e),!0)},[L]),reanchorToAnchoredMessage:ne,scrollToElement:L,scrollToEnd:z,scrollToMessage:J,scrollToStart:A}}function Xe(e,t){return d.useCallback(n=>{e.current=n,n&&t()},[e,t])}function Tr({autoScroll:e=!1,defaultScrollPosition:t="end",scrollEdgeThreshold:n=ar,scrollPreviousItemPeek:r=ir,scrollMargin:o=cr}){let l=Fr({autoScroll:e,defaultScrollPosition:t,scrollEdgeThreshold:n,scrollMargin:o,scrollPreviousItemPeek:r}),{streamingTurnRef:a,autoScrollRef:i,autoscrollingRef:u,autoscrollingTimeoutRef:h,contentRef:g,defaultScrollPositionAppliedRef:f,firstItemRef:c,itemCountRef:p,lastScrollTopRef:v,messageElementsRef:y,modeRef:_,pendingScrollFrameRef:m,pendingScrollToMessageRef:I,prependRestoreRef:j,preserveScrollOnPrependRef:B,pendingDefaultScrollStore:k,rootRef:T,scrollEdgeThresholdRef:A,scrollMarginRef:z,scrollPreviousItemPeekRef:L,spacerGapRef:ne,spacerHeightRef:J,spacerRef:x,stateFrameRef:E,stateStore:M,viewportRef:N,visibilityFrameRef:D,visibilityObserverRef:O,visibilityStore:P,visibleMessageIdsRef:U,handledScrollAnchorsRef:Z}=l,ae=d.useRef(t);ae.current!==t&&(ae.current=t,f.current=!1);let te=d.useCallback(w=>{let S=T.current,R=N.current,H=[w.start&&"start",w.end&&"end"].filter(Boolean).join(" "),le=u.current;for(let V of[S,R])V&&(H?V.setAttribute("data-scrollable",H):V.removeAttribute("data-scrollable"),V.toggleAttribute("data-autoscrolling",le))},[]),ie=d.useCallback(w=>{var H;let S=((H=N.current)==null?void 0:H.scrollTop)??0,R=S<v.current-Re;v.current=S,i.current&&!w.end&&_.current!=="settling-jump"&&_.current!=="anchored-to-message"?_.current="following-bottom":_.current==="following-bottom"&&w.end&&R&&!u.current&&(_.current="free-scrolling")},[]),Y=d.useCallback(()=>{let w=pr({content:g.current,scrollEdgeThreshold:A.current,spacer:x.current,viewport:N.current});ie(w);let S=_.current==="following-bottom"?{...w,end:!1}:w;te(S),M.setSnapshot(S)},[ie,M,te]),se=d.useCallback(()=>{E.current===null&&(E.current=window.requestAnimationFrame(()=>{E.current=null,Y()}))},[Y]),q=d.useCallback(()=>{P.hasListeners()&&D.current===null&&(D.current=window.requestAnimationFrame(()=>{D.current=null,P.hasListeners()&&P.setSnapshot(fr({content:g.current,scrollMargin:z.current,scrollPreviousItemPeek:L.current,spacer:x.current,viewport:N.current,visibleMessageIds:U.current}))}))},[P]),{flushPendingScrollToMessage:ce,reanchorToAnchoredMessage:ye,scrollToElement:F,scrollToEnd:C,scrollToMessage:W,scrollToStart:ue}=Er({refs:l,commitScrollState:Y,scheduleStateCommit:se,scheduleVisibilitySync:q}),he=d.useCallback(()=>{let w=j.current,S=N.current;if(!w||!S||!w.element.isConnected)return!1;let R=Se(w.element,S)-w.viewportTop;return Math.abs(R)<=Re?!1:(S.scrollTop+=R,w.viewportTop=Se(w.element,S),se(),q(),!0)},[se,q]),oe=d.useCallback(()=>{let w=g.current,S=N.current;if(!w||!S){j.current=null;return}let R=_r({content:w,spacer:x.current,viewport:S});j.current=R?{element:R,viewportTop:Se(R,S)}:null},[]),re=d.useCallback(()=>{m.current===null&&(m.current=window.requestAnimationFrame(()=>{m.current=null,ce()&&oe()}))},[oe,ce]),pe=d.useCallback(()=>{if(!t||f.current||p.current===0)return!1;let w=!1;if(t==="last-anchor"){let S=g.current,R=N.current,H=S&&R?vr(be(S,x.current)):null;if(!S||!R||!H)w=C({behavior:"auto"});else{let le=ct(H,R);w=$e({content:S,spacer:x.current,viewport:R})-le<=R.clientHeight?C({behavior:"auto"}):F(H,{align:"start"},{keepPreviousPeek:!0})}}else w=t==="end"?C({behavior:"auto"}):ue({behavior:"auto"});return w?(je(l),!0):!1},[t,F,C,ue]),xe=d.useCallback(()=>{let w=g.current;if(!w)return;let S=be(w,x.current),R=p.current,H=c.current;p.current=S.length,c.current=S[0]??null,(()=>{if(ce())return;if(R===0){if(pe()||S.length>0&&i.current&&C({behavior:"auto"}))return;Y(),q();return}let le=H?S.indexOf(H):-1;if(B.current&&le>0){he();return}if(S.length>R){let V=mr(S,R);if(V){if(i.current&&_.current==="following-bottom"&&br(S,R)){C({behavior:"auto"});return}F(V,{align:"start"},{keepPreviousPeek:!0}),Z.current.add(V);return}}if(S.length===R){let V=gr(S,Z.current);if(V){F(V,{align:"start"},{keepPreviousPeek:!0}),Z.current.add(V);return}}_.current==="following-bottom"&&i.current?C({behavior:"auto"}):(Y(),q())})(),oe()},[pe,oe,Y,ce,he,q,F,C]),ke=d.useCallback(()=>{if(_.current==="following-bottom"&&i.current){C({behavior:"auto"});return}let w=J.current;if(ye()){i.current&&w>0&&J.current===0&&C({behavior:"auto"});return}se(),q()},[ye,se,q,C]),Q=d.useCallback(()=>{let w=N.current;if(!(!w||!P.hasListeners())){if(typeof IntersectionObserver>"u"){q();return}O.current||(O.current=new IntersectionObserver(S=>{for(let R of S){let H=R.target.dataset.messageId;H&&(R.isIntersecting?U.current.add(H):U.current.delete(H))}q()},{root:w,rootMargin:`${-(z.current+L.current)}px 0px 0px 0px`,threshold:[0,.01,.5,1]})),y.current.forEach(S=>{var R;(R=O.current)==null||R.observe(S)}),q()}},[q,P]),G=d.useCallback(()=>{var w;D.current!==null&&(window.cancelAnimationFrame(D.current),D.current=null),(w=O.current)==null||w.disconnect(),O.current=null,U.current.clear(),P.setSnapshot(Fe)},[P]),X=d.useCallback((w,S,R)=>{var H,le,V;if(S){y.current.set(w,S),(H=O.current)==null||H.observe(S),q(),((le=I.current)==null?void 0:le.messageId)===w&&re();return}R&&y.current.get(w)===R&&(y.current.delete(w),U.current.delete(w),(V=O.current)==null||V.unobserve(R),q())},[re,q]),K=d.useCallback(()=>{(_.current==="following-bottom"||_.current==="anchored-to-message"||_.current==="settling-jump")&&(a.current=null,_.current="free-scrolling")},[]),fe=d.useCallback(()=>te(M.getSnapshot()),[M,te]),He=Xe(T,fe),We=Xe(N,fe),Ve=d.useCallback(w=>{g.current=w},[]),Ge=d.useCallback(w=>{x.current=w,ne.current=Cr((w==null?void 0:w.parentElement)??null)},[]),Ue=d.useCallback(()=>{Y(),q(),oe()},[oe,Y,q]),vt=d.useMemo(()=>({handleContentChange:xe,handleResize:ke,observeVisibility:Q,pendingDefaultScrollStore:k,preserveScrollOnPrependRef:B,scrollToEnd:C,scrollToMessage:W,scrollToStart:ue,setContentElement:Ve,setRootElement:He,setSpacerElement:Ge,setViewportElement:We,stateStore:M,syncAfterScroll:Ue,unobserveVisibility:G,userScrollIntent:K,viewportRef:N,visibilityStore:P}),[xe,ke,Q,k,C,W,ue,Ve,He,Ge,We,M,Ue,G,K,P]);return d.useLayoutEffect(()=>{pe()||p.current===0&&ht(l)},[pe]),d.useEffect(()=>()=>{var w;E.current!==null&&(window.cancelAnimationFrame(E.current),E.current=null),D.current!==null&&(window.cancelAnimationFrame(D.current),D.current=null),h.current!==null&&(window.clearTimeout(h.current),h.current=null),m.current!==null&&(window.cancelAnimationFrame(m.current),m.current=null),(w=O.current)==null||w.disconnect(),O.current=null},[]),d.useLayoutEffect(()=>{if(e&&_.current==="following-bottom"&&p.current>0){C({behavior:"auto"});return}Y()},[e,Y,C]),{context:vt,registerMessage:X}}function Ar(e){let t=d.useRef(e);return t.current=e,t}var pt=d.createContext(null),ft=d.createContext(null);function we(){let e=d.useContext(pt);if(!e)throw new Error("useMessageScroller must be used within a MessageScroller.");return e}function Mr(){let e=d.useContext(ft);if(!e)throw new Error("MessageScrollerItem must be used within a MessageScroller.");return e}function Nr({autoScroll:e=!1,children:t,defaultScrollPosition:n="end",scrollEdgeThreshold:r,scrollPreviousItemPeek:o,scrollMargin:l}){let{context:a,registerMessage:i}=Tr({autoScroll:e,defaultScrollPosition:n,scrollEdgeThreshold:r,scrollPreviousItemPeek:o,scrollMargin:l});return s.jsx(pt.Provider,{value:a,children:s.jsx(ft.Provider,{value:i,children:t})})}function mt(){let{pendingDefaultScrollStore:e}=we();return d.useSyncExternalStore(e.subscribe,e.getSnapshot,e.getSnapshot)}function Ir({children:e,...t}){let{setRootElement:n}=we(),r=mt();return s.jsx("div",{ref:n,...t,...r?{"data-pending-scroll":""}:null,children:e})}function Dr({"aria-label":e,children:t,onKeyDown:n,onScroll:r,onTouchMove:o,onWheel:l,preserveScrollOnPrepend:a=!0,ref:i,role:u,tabIndex:h,...g}){let{handleResize:f,preserveScrollOnPrependRef:c,setViewportElement:p,syncAfterScroll:v,userScrollIntent:y,viewportRef:_}=we(),m=mt();c.current=a;let I=d.useCallback(A=>{var z;p(A),(z=_e(i))==null||z(A)},[i,p]);function j(A){v(),r==null||r(A)}function B(A){y(),l==null||l(A)}function k(A){y(),o==null||o(A)}function T(A){dr.has(A.key)&&y(),n==null||n(A)}return d.useEffect(()=>{let A=_.current;if(!A||typeof ResizeObserver>"u")return;let z=0,L=new ResizeObserver(()=>{window.cancelAnimationFrame(z),z=window.requestAnimationFrame(f)});return L.observe(A),()=>{window.cancelAnimationFrame(z),L.disconnect()}},[f,_]),s.jsx("div",{ref:I,role:u??"region","aria-label":e??"Messages",tabIndex:h??0,onKeyDown:T,onScroll:j,onTouchMove:k,onWheel:B,...g,...m?{"data-pending-scroll":""}:null,children:t})}function Br({"aria-relevant":e,children:t,ref:n,role:r,spacerClassName:o,...l}){let{handleContentChange:a,handleResize:i,setContentElement:u,setSpacerElement:h}=we(),g=d.useRef(null),f=d.useCallback(c=>{var p;g.current=c,u(c),(p=_e(n))==null||p(c)},[n,u]);return d.useLayoutEffect(()=>{let c=g.current;if(!c||(a(),typeof MutationObserver>"u"))return;let p=new MutationObserver(()=>{a()});return p.observe(c,{childList:!0}),()=>p.disconnect()},[a]),d.useEffect(()=>{let c=g.current;if(!c||typeof ResizeObserver>"u")return;let p=0,v=new ResizeObserver(()=>{window.cancelAnimationFrame(p),p=window.requestAnimationFrame(i)});return v.observe(c),()=>{window.cancelAnimationFrame(p),v.disconnect()}},[i]),s.jsxs("div",{ref:f,role:r??"log","aria-relevant":e??"additions",...l,children:[t,s.jsx("div",{ref:h,"aria-hidden":"true","data-message-scroller-spacer":"",hidden:!0,className:o})]})}function Pr({messageId:e,ref:t,scrollAnchor:n=!1,...r}){let o=Mr(),l=d.useRef(null),a=d.useCallback(i=>{var h;let u=l.current;l.current=i,e&&o(e,i,u),(h=_e(t))==null||h(i)},[e,t,o]);return s.jsx("div",{ref:a,"data-message-id":e,"data-scroll-anchor":n?"true":"false",...r})}function Lr({behavior:e="smooth",children:t,direction:n="end",onClick:r,render:o,tabIndex:l,type:a="button",...i}){let{scrollToEnd:u,scrollToStart:h,stateStore:g}=we(),f=Ar(r),c=d.useCallback(_=>g.subscribe(_),[g]),p=d.useCallback(()=>{let _=g.getSnapshot();return n==="start"?_.start:_.end},[n,g]),v=d.useSyncExternalStore(c,p,p),y=d.useCallback(_=>{var m;v&&((m=f.current)==null||m.call(f,_),_.defaultPrevented||(_.currentTarget.blur(),n==="start"?h({behavior:e}):u({behavior:e})))},[e,n,v,f,u,h]);return nr({defaultTagName:"button",props:Be({type:a,inert:!v,tabIndex:v?l:-1,children:t??s.jsxs("span",{children:["Scroll to ",n]}),onClick:y},i),render:o,state:{active:v,direction:n},stateAttributesMapping:{active:_=>({"data-active":_?"true":"false"})}})}var me={Provider:Nr,Root:Ir,Viewport:Dr,Content:Br,Item:Pr,Button:Lr};function gt(e){var t,n,r="";if(typeof e=="string"||typeof e=="number")r+=e;else if(typeof e=="object")if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(n=gt(e[t]))&&(r&&(r+=" "),r+=n)}else for(n in e)e[n]&&(r&&(r+=" "),r+=n);return r}function Or(){for(var e,t,n=0,r="",o=arguments.length;n<o;n++)(e=arguments[n])&&(t=gt(e))&&(r&&(r+=" "),r+=t);return r}function ge(...e){return Or(e)}function qr(e){return s.jsx(me.Provider,{...e})}function $r({className:e,...t}){return s.jsx(me.Root,{"data-slot":"message-scroller",className:ge("msg-scroller-root",e),...t})}function zr({className:e,...t}){return s.jsx(me.Viewport,{"data-slot":"message-scroller-viewport",className:ge("msg-scroller-viewport",e),...t})}function Hr({className:e,...t}){return s.jsx(me.Content,{"data-slot":"message-scroller-content",className:ge("msg-scroller-content",e),...t})}function Ze({className:e,scrollAnchor:t=!1,...n}){return s.jsx(me.Item,{"data-slot":"message-scroller-item",scrollAnchor:t,className:ge("msg-scroller-item",e),...n})}function Wr({direction:e="end",className:t,children:n,...r}){return s.jsx(me.Button,{"data-slot":"message-scroller-button",direction:e,className:ge("msg-scroller-btn",t),...r,children:n??s.jsxs(s.Fragment,{children:[s.jsx(At,{size:16,"aria-hidden":"true",className:e==="start"?"rotate-180":void 0}),s.jsx("span",{className:"sr-only",children:e==="end"?"Jump to latest":"Jump to start"})]})})}const Vr=()=>s.jsxs("div",{className:"chat-empty-row",children:[s.jsx("div",{className:"avatar-circle avatar-circle--mt","aria-hidden":"true",children:s.jsx(lt,{size:15})}),s.jsx("div",{className:"chat-empty-bubble",children:s.jsx("p",{children:"Hello — I am the VPS Veritas assistant. Ask about reports, sample status, registration, or support, or choose a question below the text box."})})]});function Gr(e){const t=e.trim();if(!/[\u0000-\u001f\u007f]/.test(t)&&/^(https?:\/\/|mailto:|\/(?!\/)|#)/i.test(t))return t}function ee(e){if(!e)return[];const t=/(\[[^\]]+\]\([^)]+\)|\*\*[^*]+\*\*|\*[^*]+\*|`[^`]+`|https?:\/\/[^\s]+)/g;return e.split(t).map((r,o)=>{if(!r)return null;const l=r.match(/^\[([^\]]+)\]\(([^)]+)\)$/);if(l){const a=l[1],i=l[2],u=Gr(i);if(!u)return s.jsx(b.Fragment,{children:a},o);const h=/^https?:\/\//i.test(i);return s.jsx("a",{href:u,target:h?"_blank":void 0,rel:h?"noopener noreferrer":void 0,className:"md-link",children:a},o)}return r.startsWith("**")&&r.endsWith("**")&&r.length>=4?s.jsx("strong",{children:r.slice(2,-2)},o):r.startsWith("*")&&r.endsWith("*")&&r.length>=2?s.jsx("em",{children:r.slice(1,-1)},o):r.startsWith("`")&&r.endsWith("`")&&r.length>=2?s.jsx("code",{className:"md-code",children:r.slice(1,-1)},o):/^https?:\/\//i.test(r)?s.jsx("a",{href:r,target:"_blank",rel:"noopener noreferrer",className:"md-link",children:r},o):s.jsx(b.Fragment,{children:r},o)})}function Ur(e){const t=e.replace(/\r\n/g,`
103
132
  `).split(`
104
- `),n=[];let r=0;for(;r<t.length;){const l=t[r].trim();if(!l){r++;continue}if(l.startsWith("```")){const c=l.slice(3).trim(),f=[];for(r++;r<t.length&&!t[r].trim().startsWith("```");)f.push(t[r]),r++;r<t.length&&t[r].trim().startsWith("```")&&r++,n.push({type:"code",lang:c,code:f.join(`
105
- `)});continue}if(/^(---|___|\*\*\*)$/.test(l)){n.push({type:"hr"}),r++;continue}const a=l.match(/^(#{1,4})\s+(.*)$/);if(a){n.push({type:"h",level:a[1].length,content:a[2]}),r++;continue}if(l.startsWith(">")){const c=[];for(;r<t.length&&t[r].trim().startsWith(">");)c.push(t[r].trim().replace(/^>\s?/,"")),r++;n.push({type:"quote",lines:c});continue}if(/^[-*]\s+/.test(l)){const c=[];for(;r<t.length&&/^[-*]\s+/.test(t[r].trim());)c.push(t[r].trim().replace(/^[-*]\s+/,"")),r++;n.push({type:"ul",items:c});continue}if(/^\d+\.\s+/.test(l)){const c=[];for(;r<t.length&&/^\d+\.\s+/.test(t[r].trim());)c.push(t[r].trim().replace(/^\d+\.\s+/,"")),r++;n.push({type:"ol",items:c});continue}if(l.startsWith("|")&&l.endsWith("|")){const c=[];for(;r<t.length&&t[r].trim().startsWith("|")&&t[r].trim().endsWith("|");)c.push(t[r].trim()),r++;if(c.length>=2){const f=d=>d.slice(1,-1).split("|").map(p=>p.trim()),g=f(c[0]),_=c[1].includes("-")?2:1,h=c.slice(_).map(f);n.push({type:"table",headers:g,rows:h});continue}}const i=[];for(;r<t.length&&t[r].trim()&&!t[r].trim().startsWith("```")&&!/^(#{1,4})\s+/.test(t[r].trim())&&!/^[-*]\s+/.test(t[r].trim())&&!/^\d+\.\s+/.test(t[r].trim())&&!t[r].trim().startsWith(">")&&!/^(---|___|\*\*\*)$/.test(t[r].trim());)i.push(t[r].trim()),r++;i.length>0&&n.push({type:"p",lines:i})}return n}const qr=({text:e})=>{if(!e)return null;const t=Or(e);return o.jsx("div",{className:"md-content",children:t.map((n,r)=>{switch(n.type){case"h":return n.level===1?o.jsx("h2",{className:"md-h1",children:X(n.content)},r):n.level===2?o.jsx("h3",{className:"md-h2",children:X(n.content)},r):n.level===3?o.jsx("h4",{className:"md-h3",children:X(n.content)},r):o.jsx("h5",{className:"md-h4",children:X(n.content)},r);case"ul":return o.jsx("ul",{className:"md-ul",children:n.items.map((s,l)=>o.jsx("li",{className:"md-li",children:X(s)},l))},r);case"ol":return o.jsx("ol",{className:"md-ol",children:n.items.map((s,l)=>o.jsx("li",{className:"md-li",children:X(s)},l))},r);case"code":return o.jsx("pre",{className:"md-pre",children:o.jsx("code",{children:n.code})},r);case"quote":return o.jsx("blockquote",{className:"md-quote",children:n.lines.map((s,l)=>o.jsx("p",{children:X(s)},l))},r);case"hr":return o.jsx("hr",{className:"md-hr"},r);case"table":return o.jsx("div",{className:"md-table-wrap",children:o.jsxs("table",{className:"md-table",children:[o.jsx("thead",{children:o.jsx("tr",{children:n.headers.map((s,l)=>o.jsx("th",{children:X(s)},l))})}),o.jsx("tbody",{children:n.rows.map((s,l)=>o.jsx("tr",{children:s.map((a,i)=>o.jsx("td",{children:X(a)},i))},l))})]})},r);case"p":default:return o.jsx("p",{className:"md-p",children:n.lines.map((s,l)=>o.jsxs(v.Fragment,{children:[X(s),l<n.lines.length-1&&o.jsx("br",{})]},l))},r)}})})},Wr=({className:e,text:t})=>o.jsx("div",{className:ae("typing-indicator-container",e),role:"status","aria-label":"Assistant is preparing a reply",children:o.jsx("div",{className:"typing-progress-pill",children:o.jsx("span",{className:"typing-progress-text",children:t||"Retrieving knowledge & generating answer ..."})})}),$r=({status:e="complete",progressText:t,sourcesCount:n=5,durationMs:r=1800})=>{const s=e==="pending",[l,a]=v.useState(s),[i,c]=v.useState(0);v.useEffect(()=>{if(!s)return;a(!0);const g=Date.now(),_=setInterval(()=>{c(Number(((Date.now()-g)/1e3).toFixed(1)))},100);return()=>clearInterval(_)},[s]),v.useEffect(()=>{s||a(!1)},[s]);const f=s?`${i}s`:`${(r/1e3).toFixed(1)}s`;return o.jsx("div",{className:`agent-reasoning-container${s?" agent-reasoning--active":""}`,children:o.jsx("div",{className:"agent-reasoning-header","aria-expanded":l,children:o.jsxs("div",{className:"agent-reasoning-header-left",children:[o.jsx(Bt,{size:13,className:`agent-reasoning-brain-icon${s?" agent-reasoning-brain--pulse":""}`}),o.jsx("span",{className:"agent-reasoning-title",children:s?`Thinking (${f})...`:`Thought for ${f} `})]})})})};function Hr(e){return e==="create_ticket"?"Support ticket processed":e==="get_customer"?"Account verified":e==="get_ticket"?"Ticket status loaded":"Information retrieved"}function Vr({toolCalls:e}){return e.length?o.jsx("div",{className:"tool-badges",children:e.map((t,n)=>o.jsx("span",{className:"tool-badge",children:Hr(t.toolName)},`${t.toolName}-${n}`))}):null}const zr=({message:e})=>{var c;const t=_e();t==null||t.hideInspectSources,t==null||t.showGroundedSources;const n=e.role==="user",r=e.status==="error",s=e.status==="pending",l=e.id==="welcome-default"||e.id.startsWith("welcome")||e.id==="welcome",a=!!(s||e.sources&&e.sources.length>0||e.toolCalls&&e.toolCalls.length>0||e.usage),i=!n&&!r&&!l&&a;return o.jsxs("div",{className:`msg-row${n?" msg-row--user":""}`,children:[!n&&o.jsx("div",{className:"avatar-circle avatar-circle--mt","aria-hidden":"true",children:o.jsx(tt,{size:15})}),o.jsxs("div",{className:`msg-col${n?" msg-col--user":""}`,children:[o.jsxs("div",{className:n?"msg-bubble msg-bubble--user":r?"msg-bubble msg-bubble--error":"msg-bubble msg-bubble--bot",children:[i&&o.jsx($r,{status:s?"pending":"complete",progressText:e.progressText,sourcesCount:((c=e.sources)==null?void 0:c.length)||5}),s?o.jsx(Wr,{text:e.progressText}):n?o.jsx("p",{className:"msg-user-pre",children:e.content}):o.jsx("div",{className:"msg-content-wrapper",children:o.jsx(qr,{text:e.content})}),e.toolCalls?o.jsx(Vr,{toolCalls:e.toolCalls}):null]}),n&&e.status!=="error"&&o.jsx(Dt,{size:13,className:"msg-tick","aria-hidden":"true"})]})]})},Gr=()=>{const{messages:e,status:t,showSuggestions:n}=ce(),r=t==="awaiting"||t==="connecting";return o.jsx(Br,{autoScroll:!0,defaultScrollPosition:"last-anchor",scrollPreviousItemPeek:64,children:o.jsxs(Dr,{children:[o.jsx(Ir,{"aria-label":"Chat messages",children:o.jsxs(Nr,{"aria-busy":r,children:[e.length===0&&o.jsx(Je,{messageId:"welcome",children:o.jsx(Lr,{})}),e.map(s=>o.jsx(Je,{messageId:s.id,scrollAnchor:s.role==="user",children:o.jsx(zr,{message:s})},s.id))]})}),o.jsx(Pr,{})]})})},Ur=()=>{const{pendingTicket:e,ticketBusy:t,userContext:n,confirmTicket:r,cancelTicket:s}=ce(),l=!n.customerId&&!n.email,[a,i]=v.useState("");return e?o.jsxs("div",{className:"ticket-card",role:"region","aria-label":"Create support ticket",children:[o.jsx("h3",{className:"ticket-card-title",children:"Create support ticket?"}),o.jsx("p",{className:"ticket-card-desc",children:"I can open a support request for you. Nothing is created until you confirm."}),o.jsx("p",{className:"ticket-card-body",children:e.description}),l&&o.jsxs("label",{className:"ticket-id-label",children:["Customer ID or email",o.jsx("input",{value:a,onChange:c=>i(c.target.value),className:"ticket-id-input",placeholder:"CUST-1001 or you@company.com",autoComplete:"email"})]}),o.jsxs("div",{className:"ticket-actions",children:[o.jsx("button",{type:"button",onClick:s,disabled:t,className:"ticket-cancel-btn",children:"Cancel"}),o.jsx("button",{type:"button",onClick:()=>void r(a),disabled:t||l&&!a.trim(),className:"ticket-confirm-btn",children:t?"Creating…":"Create ticket"})]})]}):null},Fe=({className:e,onClose:t,showMinimize:n,title:r,subtitle:s,envStage:l,envPulse:a=!0})=>{const{sendMessage:i,status:c,error:f,resetConversation:g,retryLast:_,pendingTicket:h}=ce(),d=c==="awaiting"||c==="connecting"||!!h;return o.jsxs("section",{className:`chat-panel${e?` ${e}`:""}`,"aria-label":"VPS AI Assistant",children:[o.jsx(zt,{title:r,subtitle:s,onClose:t,onReset:()=>void g(),showMinimize:n,envStage:l,envPulse:a}),o.jsx("div",{className:"chat-panel-body",children:o.jsx(Gr,{})}),f&&c==="error"&&o.jsx(Tt,{message:f,onRetry:()=>void _()}),o.jsx(Ur,{}),o.jsx(Jt,{onSend:p=>void i(p),disabled:d})]})},Yr=({open:e,onClose:t,envStage:n,envPulse:r=!0})=>e?o.jsx("div",{id:"vps-chatbot-widget-panel",className:"widget-panel",children:o.jsx(Fe,{onClose:t,showMinimize:!0,title:"VPS AI Assistant",envStage:n,envPulse:r})}):null,Jr=({open:e,onToggle:t})=>o.jsx("button",{type:"button",onClick:t,"aria-expanded":e,"aria-controls":"vps-chatbot-widget-panel","aria-label":e?"Close assistant":"Open assistant",className:"widget-trigger-btn",children:e?o.jsx(Wt,{size:22}):o.jsx(rt,{size:24})}),Ze=({defaultOpen:e=!1,open:t,onOpenChange:n,envStage:r,envPulse:s=!0})=>{const[l,a]=v.useState(e),i=t??l,c=f=>{n==null||n(f),t===void 0&&a(f)};return o.jsxs(o.Fragment,{children:[o.jsx(Yr,{open:i,onClose:()=>c(!1),envStage:r,envPulse:s}),o.jsx(Jr,{open:i,onToggle:()=>c(!i)})]})},Zr=({apiBaseUrl:e,apiUrl:t,proxyUrl:n,userContext:r,role:s,roleId:l,client:a,welcomeMessage:i,suggestions:c,disableSuggestions:f,initialMessage:g,hideInspectSources:_,showGroundedSources:h,...d})=>{const p=_e(),C=e??t??n;return!!p&&(!C||se(C)===se(p==null?void 0:p.apiBaseUrl))&&!r&&s===void 0&&l===void 0&&a===void 0&&i===void 0&&!c&&f===void 0&&!g&&_===void 0&&h===void 0?o.jsx(Ze,{...d}):o.jsx(Te,{apiBaseUrl:C,userContext:r,role:s,roleId:l,client:a,welcomeMessage:i,suggestions:c,disableSuggestions:f,initialMessage:g,hideInspectSources:_,showGroundedSources:h,children:o.jsx(Ze,{...d})})},Kr=({open:e,onClose:t,subtitle:n,title:r,envStage:s,envPulse:l=!0})=>o.jsxs(o.Fragment,{children:[o.jsx("div",{className:`embedded-overlay ${e?"embedded-overlay--open":"embedded-overlay--closed"}`,hidden:!e,onClick:t,"aria-hidden":"true"}),o.jsx("aside",{id:"vps-embedded-chat-panel",className:`embedded-panel ${e?"embedded-panel--open":"embedded-panel--closed"}`,"aria-hidden":!e,children:e&&o.jsx(Fe,{onClose:t,title:r||"VPS AI Assistant",subtitle:n,envStage:s,envPulse:l})})]}),Qr=5,ye=8,ht="vps-embedded-assistant-top";function Xr(e,t,n){return Math.min(n,Math.max(t,e))}function Ke(e,t){const n=Math.max(ye,window.innerHeight-t-ye);return Xr(e,ye,n)}function en(){try{const e=window.localStorage.getItem(ht);if(!e)return null;const t=Number(e);return Number.isFinite(t)?t:null}catch{return null}}function tn(e){try{window.localStorage.setItem(ht,String(e))}catch{}}const rn=({onOpen:e})=>{const t=v.useRef(null),n=v.useRef({pointerId:null,startY:0,startTop:0,moved:!1}),[r,s]=v.useState(()=>typeof window>"u"?null:en()),l=v.useRef(r),a=v.useRef(!1),[i,c]=v.useState(!1);v.useEffect(()=>{l.current=r},[r]),v.useEffect(()=>{const h=t.current;if(!h)return;const d=()=>{s(p=>{const C=p??Math.round(window.innerHeight/2-h.offsetHeight/2),b=Ke(C,h.offsetHeight);return l.current=b,b})};return d(),window.addEventListener("resize",d),()=>window.removeEventListener("resize",d)},[]);const f=h=>{if(h.button!==0)return;const d=h.currentTarget,p=d.getBoundingClientRect();n.current={pointerId:h.pointerId,startY:h.clientY,startTop:p.top,moved:!1};try{d.setPointerCapture(h.pointerId)}catch{}},g=h=>{if(n.current.pointerId!==h.pointerId)return;const d=h.clientY-n.current.startY;if(!n.current.moved&&Math.abs(d)<Qr)return;n.current.moved=!0,c(!0);const p=Ke(n.current.startTop+d,h.currentTarget.offsetHeight);l.current=p,s(p)},_=h=>{var p,C;if(n.current.pointerId!==h.pointerId)return;try{(C=(p=h.currentTarget).hasPointerCapture)!=null&&C.call(p,h.pointerId)&&h.currentTarget.releasePointerCapture(h.pointerId)}catch{}const d=n.current.moved;n.current.pointerId=null,n.current.moved=!1,c(!1),d&&(a.current=!0,l.current!=null&&tn(l.current))};return o.jsxs("button",{ref:t,type:"button",onPointerDown:f,onPointerMove:g,onPointerUp:_,onPointerCancel:_,onClick:()=>{if(a.current){a.current=!1;return}e()},"aria-expanded":!1,"aria-controls":"vps-embedded-chat-panel","aria-label":"Assistant",className:`embedded-trigger-btn ${i?"embedded-trigger-btn--grabbing":"embedded-trigger-btn--grab"}`,style:{top:r??"50%",transform:r==null?"translateY(-50%)":void 0},children:[o.jsx(rt,{size:16}),"Assistant"]})},Qe=({defaultOpen:e=!1,open:t,onOpenChange:n,showTrigger:r=!0,envStage:s,envPulse:l=!0})=>{const[a,i]=v.useState(e),c=t??a,f=g=>{n==null||n(g),t===void 0&&i(g)};return o.jsxs(o.Fragment,{children:[r&&!c&&o.jsx(rn,{onOpen:()=>f(!0)}),o.jsx(Kr,{open:c,onClose:()=>f(!1),envStage:s,envPulse:l})]})},nn=({apiBaseUrl:e,apiUrl:t,proxyUrl:n,userContext:r,role:s,roleId:l,client:a,welcomeMessage:i,suggestions:c,disableSuggestions:f,initialMessage:g,hideInspectSources:_,showGroundedSources:h,...d})=>{const p=_e(),C=e??t??n;return!!p&&(!C||se(C)===se(p==null?void 0:p.apiBaseUrl))&&!r&&s===void 0&&l===void 0&&a===void 0&&i===void 0&&!c&&f===void 0&&!g&&_===void 0&&h===void 0?o.jsx(Qe,{...d}):o.jsx(Te,{apiBaseUrl:C,userContext:r,role:s,roleId:l,client:a,welcomeMessage:i,suggestions:c,disableSuggestions:f,initialMessage:g,hideInspectSources:_,showGroundedSources:h,children:o.jsx(Qe,{...d})})},sn={Colors:{VPS_White:"#fff",VPS_Dark_Blue:"#1A1A31",VPS_Light_Blue:"#353552",VPS_Light_Grey:"#D1D1D6",VPS_Orange:"#FF4717",Dark_Blue_50:"#F1F5FC",Dark_Blue_100:"#E5EBFA",Dark_Blue_200:"#D1DAF4",Dark_Blue_300:"#B4C2ED",Dark_Blue_400:"#96A2E3",Dark_Blue_500:"#7C84D8",Dark_Blue_600:"#6262C9",Dark_Blue_700:"#5351B1",Dark_Blue_800:"#44448F",Dark_Blue_900:"#3C3D73",Dark_Blue_950:"#1A1A31",Light_Blue_50:"#F4F6FA",Light_Blue_100:"#E6E9F3",Light_Blue_200:"#D3D8EA",Light_Blue_300:"#B4BEDC",Light_Blue_400:"#909DCA",Light_Blue_500:"#7580BC",Light_Blue_600:"#6369AD",Light_Blue_700:"#575A9E",Light_Blue_800:"#4B4B82",Light_Blue_900:"#404168",Light_Blue_950:"#353552",Grey_50:"#F6F6F7",Grey_100:"#EFEFF0",Grey_200:"#E2E1E4",Grey_300:"#D1D1D6",Grey_400:"#B9B9C0",Grey_500:"#A7A6AE",Grey_600:"#93919A",Grey_700:"#7E7D85",Grey_800:"#67666D",Grey_900:"#56555A",Grey_950:"#323234",Orange_50:"#FFF3ED",Orange_100:"#FFE4D4",Orange_200:"#FFC5A8",Orange_300:"#FF9D70",Orange_400:"#FF6837",Orange_500:"#FF4717",Orange_600:"#F02706",Orange_700:"#C71807",Orange_800:"#9E150E",Orange_900:"#7F150F",Orange_950:"#450605",Success_50:"#F1FCF5",Success_100:"#DEFAEA",Success_200:"#BEF4D4",Success_300:"#8BEAB3",Success_400:"#52D689",Success_500:"#2ECC71",Success_600:"#1D9C53",Success_700:"#1B7A43",Success_800:"#1A6139",Success_900:"#175031",Success_950:"#072C18",Warning_50:"#FFFEEA",Warning_100:"#FFF9C5",Warning_200:"#FFF485",Warning_300:"#FFE846",Warning_400:"#FFD81B",Warning_500:"#FFB800",Warning_600:"#E28D00",Warning_700:"#BB6302",Warning_800:"#984C08",Warning_900:"#7C3F0B",Warning_950:"#482000",Error_50:"#FFF1F1",Error_100:"#FFDFDF",Error_200:"#FFC5C5",Error_300:"#FF9D9D",Error_400:"#FF6464",Error_500:"#FF2E2E",Error_600:"#ED1515",Error_700:"#C80D0D",Error_800:"#A50F0F",Error_900:"#881414",Error_950:"#4B0404",Netural_25:"#FDFDFD",Netural_50:"#FAFAFA",Netural_100:"#F5F5F5",Netural_200:"#E9EAEC",Netural_300:"#D6D7DB",Netural_400:"#A4A7AE",Netural_500:"#727681",Netural_600:"#545863",Netural_700:"#424651",Netural_800:"#252B37",Netural_900:"#191D28",Netural_950:"#0A0D12",Tint_Dark_Blue_100:"#1A1A31",Tint_Dark_Blue_90:"#313146",Tint_Dark_Blue_80:"#48485A",Tint_Dark_Blue_70:"#5F5F6F",Tint_Dark_Blue_60:"#767683",Tint_Dark_Blue_50:"#8C8C98",Tint_Dark_Blue_40:"#A3A3AD",Tint_Dark_Blue_30:"#BABAC1",Tint_Dark_Blue_20:"#D1D1D6",Tint_Dark_Blue_10:"#E8E8EA",Tint_Dark_Blue_5:"#F4F4F5",Tint_Light_Blue_100:"#353552",Tint_Light_Blue_90:"#494963",Tint_Light_Blue_80:"#5D5D75",Tint_Light_Blue_70:"#727286",Tint_Light_Blue_60:"#868697",Tint_Light_Blue_50:"#9A9AA8",Tint_Light_Blue_40:"#AEAEBA",Tint_Light_Blue_30:"#C2C2CB",Tint_Light_Blue_20:"#D7D7DC",Tint_Light_Blue_10:"#EBEBEE",Tint_Light_Blue_5:"#F5F5F6",Tint_Grey_100:"#D1D1D6",Tint_Grey_90:"#D6D6DA",Tint_Grey_80:"#DADADE",Tint_Grey_70:"#DFDFE2",Tint_Grey_60:"#E3E3E6",Tint_Grey_50:"#E8E8EB",Tint_Grey_40:"#EDEDEF",Tint_Grey_30:"#F1F1F3",Tint_Grey_20:"#F6F6F7",Tint_Grey_10:"#FAFAFB",Tint_Grey_5:"#FDFDFD",Tint_Solus_100:"#FF4717",Tint_Solus_90:"#FF592E",Tint_Solus_80:"#FF6C45",Tint_Solus_70:"#FF7E5D",Tint_Solus_60:"#FF9174",Tint_Solus_50:"#FFA38B",Tint_Solus_40:"#FFB5A2",Tint_Solus_30:"#FFC8B9",Tint_Solus_20:"#FFDAD1",Tint_Solus_10:"#FFEDE8",Tint_Solus_5:"#FFF6F3",Other_Color:"#00ABC9"},StatusColor:{tested:"#3E4784",received:"#EE46BC",InTransit:"#6938EF",registered:"#1570EF",reported:"#2ECC71",noStatus:"#727681",Action:"#FF2E2E",Caution:"#FFB800",Pass:"#2ECC71",No_Rating:"#FF6837",Received:"#EE46BC",Tested:"#3E4784",Reported:"#2ECC71",No_Status:"#6938EF",Overdue:"#FF2E2E",Duesoon:"#FFB800",Scheduled:"#1570EF",Good:"#2ECC71",NotApplicable:"#353552"}};exports.ChatPanel=Fe;exports.ChatProvider=Te;exports.ChatbotWidget=Zr;exports.ColorPalette=sn;exports.EmbeddedChatbot=nn;exports.buildApiUrl=pe;exports.chatApi=Ct;exports.createChatApi=xe;exports.resolveApiBaseUrl=se;exports.useChatContext=Xe;exports.useChatbot=ce;exports.useOptionalChatContext=_e;
133
+ `),n=[];let r=0;for(;r<t.length;){const l=t[r].trim();if(!l){r++;continue}if(l.startsWith("```")){const u=l.slice(3).trim(),h=[];for(r++;r<t.length&&!t[r].trim().startsWith("```");)h.push(t[r]),r++;r<t.length&&t[r].trim().startsWith("```")&&r++,n.push({type:"code",lang:u,code:h.join(`
134
+ `)});continue}if(/^(---|___|\*\*\*)$/.test(l)){n.push({type:"hr"}),r++;continue}const a=l.match(/^(#{1,4})\s+(.*)$/);if(a){n.push({type:"h",level:a[1].length,content:a[2]}),r++;continue}if(l.startsWith(">")){const u=[];for(;r<t.length&&t[r].trim().startsWith(">");)u.push(t[r].trim().replace(/^>\s?/,"")),r++;n.push({type:"quote",lines:u});continue}if(/^[-*]\s+/.test(l)){const u=[];for(;r<t.length&&/^[-*]\s+/.test(t[r].trim());)u.push(t[r].trim().replace(/^[-*]\s+/,"")),r++;n.push({type:"ul",items:u});continue}if(/^\d+\.\s+/.test(l)){const u=[];for(;r<t.length&&/^\d+\.\s+/.test(t[r].trim());)u.push(t[r].trim().replace(/^\d+\.\s+/,"")),r++;n.push({type:"ol",items:u});continue}if(l.startsWith("|")&&l.endsWith("|")){const u=[];for(;r<t.length&&t[r].trim().startsWith("|")&&t[r].trim().endsWith("|");)u.push(t[r].trim()),r++;if(u.length>=2){const h=p=>p.slice(1,-1).split("|").map(v=>v.trim()),g=h(u[0]),f=u[1].includes("-")?2:1,c=u.slice(f).map(h);n.push({type:"table",headers:g,rows:c});continue}}const i=[];for(;r<t.length&&t[r].trim()&&!t[r].trim().startsWith("```")&&!/^(#{1,4})\s+/.test(t[r].trim())&&!/^[-*]\s+/.test(t[r].trim())&&!/^\d+\.\s+/.test(t[r].trim())&&!t[r].trim().startsWith(">")&&!/^(---|___|\*\*\*)$/.test(t[r].trim());)i.push(t[r].trim()),r++;i.length>0&&n.push({type:"p",lines:i})}return n}const Yr=b.memo(function({text:t}){if(!t)return null;const n=Ur(t);return s.jsx("div",{className:"md-content",children:n.map((r,o)=>{switch(r.type){case"h":return r.level===1?s.jsx("h2",{className:"md-h1",children:ee(r.content)},o):r.level===2?s.jsx("h3",{className:"md-h2",children:ee(r.content)},o):r.level===3?s.jsx("h4",{className:"md-h3",children:ee(r.content)},o):s.jsx("h5",{className:"md-h4",children:ee(r.content)},o);case"ul":return s.jsx("ul",{className:"md-ul",children:r.items.map((l,a)=>s.jsx("li",{className:"md-li",children:ee(l)},a))},o);case"ol":return s.jsx("ol",{className:"md-ol",children:r.items.map((l,a)=>s.jsx("li",{className:"md-li",children:ee(l)},a))},o);case"code":return s.jsx("pre",{className:"md-pre",children:s.jsx("code",{children:r.code})},o);case"quote":return s.jsx("blockquote",{className:"md-quote",children:r.lines.map((l,a)=>s.jsx("p",{children:ee(l)},a))},o);case"hr":return s.jsx("hr",{className:"md-hr"},o);case"table":return s.jsx("div",{className:"md-table-wrap",children:s.jsxs("table",{className:"md-table",children:[s.jsx("thead",{children:s.jsx("tr",{children:r.headers.map((l,a)=>s.jsx("th",{children:ee(l)},a))})}),s.jsx("tbody",{children:r.rows.map((l,a)=>s.jsx("tr",{children:l.map((i,u)=>s.jsx("td",{children:ee(i)},u))},a))})]})},o);case"p":default:return s.jsx("p",{className:"md-p",children:r.lines.map((l,a)=>s.jsxs(b.Fragment,{children:[ee(l),a<r.lines.length-1&&s.jsx("br",{})]},a))},o)}})})}),Jr=({className:e,text:t})=>s.jsxs("div",{className:ge("typing-indicator-container",e),role:"status","aria-label":"Assistant is preparing a reply",children:[s.jsxs("div",{className:"typing-indicator","aria-hidden":"true",children:[s.jsx("span",{className:"typing-dot"}),s.jsx("span",{className:"typing-dot"}),s.jsx("span",{className:"typing-dot"})]}),t&&s.jsx("div",{className:"typing-progress-pill",children:t})]}),Kr=({status:e="complete",progressText:t,durationMs:n})=>{const r=e==="pending",[o,l]=b.useState(0);b.useEffect(()=>{if(!r)return;const i=Date.now(),u=setInterval(()=>{l(Number(((Date.now()-i)/1e3).toFixed(1)))},250);return()=>clearInterval(u)},[r]);const a=r?`${o.toFixed(1)}s`:n===void 0?void 0:`${(n/1e3).toFixed(1)}s`;return s.jsx("div",{className:`agent-reasoning-container${r?" agent-reasoning--active":""}`,children:s.jsx("div",{className:"agent-reasoning-header",role:"status","aria-live":"off",children:s.jsxs("div",{className:"agent-reasoning-header-left",children:[r?s.jsx(zt,{size:13,className:"agent-reasoning-spinner","aria-hidden":"true"}):s.jsx(Lt,{size:13,className:"agent-reasoning-done-icon","aria-hidden":"true"}),s.jsx("span",{className:"agent-reasoning-title",children:r?`${t||"Working…"} · ${a}`:a?`Response generated in ${a}`:"Response generated"})]})})})},Qr={"fuel-defect-reporting":{label:"Fuel Defect Reporting",path:"/dashboard/fuel-Defect-Reporting"},"bunker-master":{label:"Bunker Master",path:"/dashboard/bunker-master"},"fsc-fsq-e-forms":{label:"Pre-Registration & E-Forms",path:"/dashboard/pre-registration"},"pre-registration-ship":{label:"Pre-Registration",path:"/dashboard/pre-registration"},"reports-fuel":{label:"Fuel Reports",path:"/dashboard/reports"},"sample-fuel":{label:"Sample Status",path:"/dashboard/sample-status"}};function Xr(e){const n=(e.split(/[/\\]/).pop()||"").replace(/\.md$/i,"").toLowerCase();for(const[r,o]of Object.entries(Qr))if(n.includes(r))return o;return null}function et(e){return e.title?e.title:(e.source.split(/[/\\]/).pop()||e.source).replace(/\.md$/i,"").replace(/[-_]/g," ").replace(/\b\w/g,n=>n.toUpperCase())}const Zr=({sources:e,hideInspectSources:t=!1,showInspectSources:n=!0,defaultExpanded:r=!1,maxSources:o=5})=>{const l=t||n===!1,[a,i]=b.useState(r&&!l),[u,h]=b.useState(null);if(!e||!e.length)return null;const g=e.slice(0,o);return s.jsxs("div",{className:"grounded-sources-card",children:[s.jsxs("div",{className:"grounded-sources-header",children:[s.jsxs("div",{className:"grounded-sources-badge",children:[s.jsx(Gt,{size:13,className:"grounded-shield-icon"}),s.jsxs("span",{children:[g.length," retrieved VPS sources"]})]}),!l&&s.jsxs("button",{type:"button",className:"grounded-toggle-btn",onClick:()=>i(f=>!f),"aria-expanded":a,children:[s.jsx("span",{children:a?"Hide Details":"Inspect Sources"}),a?s.jsx(Pt,{size:12}):s.jsx(Bt,{size:12})]})]}),s.jsx("div",{className:"grounded-pills-row",children:g.map((f,c)=>{const p=et(f),v=u===c;return s.jsxs("button",{type:"button",className:`grounded-source-pill${v?" grounded-source-pill--selected":""}`,onClick:()=>{l||(i(!0),h(v?null:c))},title:f.source,children:[s.jsx(It,{size:11,className:"grounded-book-icon"}),s.jsxs("span",{className:"grounded-pill-title",children:["[S",c+1,"] ",p]}),s.jsxs("span",{className:"grounded-pill-score",title:"Ranking score, not a probability of correctness",children:["Score ",f.score.toFixed(2)]})]},`${f.chunkId}-${c}`)})}),!l&&a&&s.jsx("div",{className:"grounded-sources-details-list",children:g.map((f,c)=>{const p=et(f),v=Xr(f.source),y=u===c;return s.jsxs("div",{className:`grounded-detail-item${y?" grounded-detail-item--highlighted":""}`,children:[s.jsxs("div",{className:"grounded-detail-top",children:[s.jsxs("div",{className:"grounded-detail-title-group",children:[s.jsxs("span",{className:"grounded-detail-index",children:["[",c+1,"]"]}),s.jsx("span",{className:"grounded-detail-title",children:p})]}),s.jsxs("div",{className:"grounded-detail-meta",children:[s.jsxs("span",{className:"grounded-detail-score",children:["Rank score ",f.score.toFixed(2)]}),v&&s.jsxs("a",{href:v.path,onClick:_=>{_.preventDefault(),window.location.href=v.path},className:"grounded-route-link",title:`Navigate to ${v.label}`,children:[s.jsx("span",{children:v.label}),s.jsx(qt,{size:10})]})]})]}),s.jsx("div",{className:"grounded-detail-path",children:s.jsx("code",{children:f.source})}),f.snippet&&s.jsxs("p",{className:"grounded-detail-snippet",children:['"',f.snippet,'"']})]},`detail-${f.chunkId}-${c}`)})})]})};function en(e){return e==="create_ticket"?"Support ticket processed":e==="get_customer"?"Account verified":e==="get_ticket"?"Ticket status loaded":"Information retrieved"}function tn({toolCalls:e}){return e.length?s.jsx("div",{className:"tool-badges",children:e.map((t,n)=>s.jsx("span",{className:"tool-badge",children:en(t.toolName)},`${t.toolName}-${n}`))}):null}const rn=({message:e})=>{var g;const t=Ee(),n=(t==null?void 0:t.hideInspectSources)??!1,r=(t==null?void 0:t.showGroundedSources)??!0,o=e.role==="user",l=e.status==="error",a=e.status==="pending",i=e.id==="welcome-default"||e.id.startsWith("welcome")||e.id==="welcome",u=!!(a||e.durationMs!==void 0||e.sources&&e.sources.length>0||e.toolCalls&&e.toolCalls.length>0||e.usage),h=!o&&!l&&!i&&u;return s.jsxs("div",{className:`msg-row${o?" msg-row--user":""}`,children:[!o&&s.jsx("div",{className:"avatar-circle avatar-circle--mt","aria-hidden":"true",children:s.jsx(lt,{size:15})}),s.jsxs("div",{className:`msg-col${o?" msg-col--user":""}`,children:[s.jsxs("div",{className:o?"msg-bubble msg-bubble--user":l?"msg-bubble msg-bubble--error":"msg-bubble msg-bubble--bot",children:[h&&s.jsx(Kr,{status:a?"pending":"complete",progressText:e.progressText,durationMs:e.durationMs}),a?e.content?s.jsx("div",{className:"msg-content-wrapper msg-content-wrapper--streaming",children:s.jsx("div",{className:"msg-streaming-text",children:e.content})}):s.jsx(Jr,{}):o?s.jsx("p",{className:"msg-user-pre",children:e.content}):s.jsx("div",{className:"msg-content-wrapper",children:s.jsx(Yr,{text:e.content})}),e.toolCalls?s.jsx(tn,{toolCalls:e.toolCalls}):null,!o&&!a&&!l&&r&&((g=e.sources)!=null&&g.length)?s.jsx(Zr,{sources:e.sources,hideInspectSources:n}):null]}),o&&e.status!=="error"&&s.jsx(Dt,{size:13,className:"msg-tick","aria-hidden":"true"})]})]})},nn=()=>{const{messages:e,status:t,showSuggestions:n}=ve(),r=t==="awaiting"||t==="connecting";return s.jsx(qr,{autoScroll:!0,defaultScrollPosition:"last-anchor",scrollPreviousItemPeek:64,children:s.jsxs($r,{children:[s.jsx(zr,{"aria-label":"Chat messages",children:s.jsxs(Hr,{"aria-busy":r,children:[e.length===0&&s.jsx(Ze,{messageId:"welcome",children:s.jsx(Vr,{})}),e.map(o=>s.jsx(Ze,{messageId:o.id,scrollAnchor:o.role==="user",children:s.jsx(rn,{message:o})},o.id))]})}),s.jsx(Wr,{})]})})},sn=()=>{const{pendingTicket:e,ticketBusy:t,userContext:n,confirmTicket:r,cancelTicket:o}=ve(),l=!n.customerId&&!n.email,[a,i]=b.useState("");return e?s.jsxs("div",{className:"ticket-card",role:"region","aria-label":"Create support ticket",children:[s.jsx("h3",{className:"ticket-card-title",children:"Create support ticket?"}),s.jsx("p",{className:"ticket-card-desc",children:"I can open a support request for you. Nothing is created until you confirm."}),s.jsx("p",{className:"ticket-card-body",children:e.description}),l&&s.jsxs("label",{className:"ticket-id-label",children:["Customer ID or email",s.jsx("input",{value:a,onChange:u=>i(u.target.value),className:"ticket-id-input",placeholder:"CUST-1001 or you@company.com",autoComplete:"email"})]}),s.jsxs("div",{className:"ticket-actions",children:[s.jsx("button",{type:"button",onClick:o,disabled:t,className:"ticket-cancel-btn",children:"Cancel"}),s.jsx("button",{type:"button",onClick:()=>void r(a),disabled:t||l&&!a.trim(),className:"ticket-confirm-btn",children:t?"Creating…":"Create ticket"})]})]}):null},ze=({className:e,onClose:t,showMinimize:n,title:r,subtitle:o,envStage:l,envPulse:a=!0})=>{const{sendMessage:i,status:u,error:h,resetConversation:g,retryLast:f,pendingTicket:c}=ve(),p=u==="awaiting"||u==="connecting"||!!c;return s.jsxs("section",{className:`chat-panel${e?` ${e}`:""}`,"aria-label":"VPS AI Assistant",children:[s.jsx(Xt,{title:r,subtitle:o,onClose:t,onReset:()=>void g(),showMinimize:n,envStage:l,envPulse:a}),s.jsx("div",{className:"chat-panel-body",children:s.jsx(nn,{})}),h&&u==="error"&&s.jsx(Rt,{message:h,onRetry:()=>void f()}),s.jsx(sn,{}),s.jsx(rr,{onSend:v=>void i(v),disabled:p})]})},on=({open:e,onClose:t,envStage:n,envPulse:r=!0})=>e?s.jsx("div",{id:"vps-chatbot-widget-panel",className:"widget-panel",children:s.jsx(ze,{onClose:t,showMinimize:!0,title:"VPS AI Assistant",envStage:n,envPulse:r})}):null,ln=({open:e,onToggle:t})=>s.jsx("button",{type:"button",onClick:t,"aria-expanded":e,"aria-controls":"vps-chatbot-widget-panel","aria-label":e?"Close assistant":"Open assistant",className:"widget-trigger-btn",children:e?s.jsx(Yt,{size:22}):s.jsx(at,{size:24})}),tt=({defaultOpen:e=!1,open:t,onOpenChange:n,envStage:r,envPulse:o=!0})=>{const[l,a]=b.useState(e),i=t??l,u=h=>{n==null||n(h),t===void 0&&a(h)};return s.jsxs(s.Fragment,{children:[s.jsx(on,{open:i,onClose:()=>u(!1),envStage:r,envPulse:o}),s.jsx(ln,{open:i,onToggle:()=>u(!i)})]})},an=({apiBaseUrl:e,apiUrl:t,proxyUrl:n,userContext:r,role:o,roleId:l,client:a,welcomeMessage:i,suggestions:u,disableSuggestions:h,initialMessage:g,hideInspectSources:f,showGroundedSources:c,modelId:p,...v})=>{const y=Ee(),_=e??t??n;return!!y&&(!_||de(_)===de(y==null?void 0:y.apiBaseUrl))&&!r&&o===void 0&&l===void 0&&a===void 0&&i===void 0&&!u&&h===void 0&&!g&&f===void 0&&c===void 0&&p===void 0?s.jsx(tt,{...v}):s.jsx(qe,{apiBaseUrl:_,userContext:r,role:o,roleId:l,client:a,welcomeMessage:i,suggestions:u,disableSuggestions:h,initialMessage:g,hideInspectSources:f,showGroundedSources:c,modelId:p,children:s.jsx(tt,{...v})})},cn=({open:e,onClose:t,subtitle:n,title:r,envStage:o,envPulse:l=!0})=>s.jsxs(s.Fragment,{children:[s.jsx("div",{className:`embedded-overlay ${e?"embedded-overlay--open":"embedded-overlay--closed"}`,hidden:!e,onClick:t,"aria-hidden":"true"}),s.jsx("aside",{id:"vps-embedded-chat-panel",className:`embedded-panel ${e?"embedded-panel--open":"embedded-panel--closed"}`,"aria-hidden":!e,children:e&&s.jsx(ze,{onClose:t,title:r||"VPS AI Assistant",subtitle:n,envStage:o,envPulse:l})})]}),un=5,De=8,bt="vps-embedded-assistant-top";function dn(e,t,n){return Math.min(n,Math.max(t,e))}function rt(e,t){const n=Math.max(De,window.innerHeight-t-De);return dn(e,De,n)}function hn(){try{const e=window.localStorage.getItem(bt);if(!e)return null;const t=Number(e);return Number.isFinite(t)?t:null}catch{return null}}function pn(e){try{window.localStorage.setItem(bt,String(e))}catch{}}const fn=({onOpen:e})=>{const t=b.useRef(null),n=b.useRef({pointerId:null,startY:0,startTop:0,moved:!1}),[r,o]=b.useState(()=>typeof window>"u"?null:hn()),l=b.useRef(r),a=b.useRef(!1),[i,u]=b.useState(!1);b.useEffect(()=>{l.current=r},[r]),b.useEffect(()=>{const c=t.current;if(!c)return;const p=()=>{o(v=>{const y=v??Math.round(window.innerHeight/2-c.offsetHeight/2),_=rt(y,c.offsetHeight);return l.current=_,_})};return p(),window.addEventListener("resize",p),()=>window.removeEventListener("resize",p)},[]);const h=c=>{if(c.button!==0)return;const p=c.currentTarget,v=p.getBoundingClientRect();n.current={pointerId:c.pointerId,startY:c.clientY,startTop:v.top,moved:!1};try{p.setPointerCapture(c.pointerId)}catch{}},g=c=>{if(n.current.pointerId!==c.pointerId)return;const p=c.clientY-n.current.startY;if(!n.current.moved&&Math.abs(p)<un)return;n.current.moved=!0,u(!0);const v=rt(n.current.startTop+p,c.currentTarget.offsetHeight);l.current=v,o(v)},f=c=>{var v,y;if(n.current.pointerId!==c.pointerId)return;try{(y=(v=c.currentTarget).hasPointerCapture)!=null&&y.call(v,c.pointerId)&&c.currentTarget.releasePointerCapture(c.pointerId)}catch{}const p=n.current.moved;n.current.pointerId=null,n.current.moved=!1,u(!1),p&&(a.current=!0,l.current!=null&&pn(l.current))};return s.jsxs("button",{ref:t,type:"button",onPointerDown:h,onPointerMove:g,onPointerUp:f,onPointerCancel:f,onClick:()=>{if(a.current){a.current=!1;return}e()},"aria-expanded":!1,"aria-controls":"vps-embedded-chat-panel","aria-label":"Assistant",className:`embedded-trigger-btn ${i?"embedded-trigger-btn--grabbing":"embedded-trigger-btn--grab"}`,style:{top:r??"50%",transform:r==null?"translateY(-50%)":void 0},children:[s.jsx(at,{size:16}),"Assistant"]})},nt=({defaultOpen:e=!1,open:t,onOpenChange:n,showTrigger:r=!0,envStage:o,envPulse:l=!0})=>{const[a,i]=b.useState(e),u=t??a,h=g=>{n==null||n(g),t===void 0&&i(g)};return s.jsxs(s.Fragment,{children:[r&&!u&&s.jsx(fn,{onOpen:()=>h(!0)}),s.jsx(cn,{open:u,onClose:()=>h(!1),envStage:o,envPulse:l})]})},mn=({apiBaseUrl:e,apiUrl:t,proxyUrl:n,userContext:r,role:o,roleId:l,client:a,welcomeMessage:i,suggestions:u,disableSuggestions:h,initialMessage:g,hideInspectSources:f,showGroundedSources:c,modelId:p,...v})=>{const y=Ee(),_=e??t??n;return!!y&&(!_||de(_)===de(y==null?void 0:y.apiBaseUrl))&&!r&&o===void 0&&l===void 0&&a===void 0&&i===void 0&&!u&&h===void 0&&!g&&f===void 0&&c===void 0&&p===void 0?s.jsx(nt,{...v}):s.jsx(qe,{apiBaseUrl:_,userContext:r,role:o,roleId:l,client:a,welcomeMessage:i,suggestions:u,disableSuggestions:h,initialMessage:g,hideInspectSources:f,showGroundedSources:c,modelId:p,children:s.jsx(nt,{...v})})},gn={Colors:{VPS_White:"#fff",VPS_Dark_Blue:"#1A1A31",VPS_Light_Blue:"#353552",VPS_Light_Grey:"#D1D1D6",VPS_Orange:"#FF4717",Dark_Blue_50:"#F1F5FC",Dark_Blue_100:"#E5EBFA",Dark_Blue_200:"#D1DAF4",Dark_Blue_300:"#B4C2ED",Dark_Blue_400:"#96A2E3",Dark_Blue_500:"#7C84D8",Dark_Blue_600:"#6262C9",Dark_Blue_700:"#5351B1",Dark_Blue_800:"#44448F",Dark_Blue_900:"#3C3D73",Dark_Blue_950:"#1A1A31",Light_Blue_50:"#F4F6FA",Light_Blue_100:"#E6E9F3",Light_Blue_200:"#D3D8EA",Light_Blue_300:"#B4BEDC",Light_Blue_400:"#909DCA",Light_Blue_500:"#7580BC",Light_Blue_600:"#6369AD",Light_Blue_700:"#575A9E",Light_Blue_800:"#4B4B82",Light_Blue_900:"#404168",Light_Blue_950:"#353552",Grey_50:"#F6F6F7",Grey_100:"#EFEFF0",Grey_200:"#E2E1E4",Grey_300:"#D1D1D6",Grey_400:"#B9B9C0",Grey_500:"#A7A6AE",Grey_600:"#93919A",Grey_700:"#7E7D85",Grey_800:"#67666D",Grey_900:"#56555A",Grey_950:"#323234",Orange_50:"#FFF3ED",Orange_100:"#FFE4D4",Orange_200:"#FFC5A8",Orange_300:"#FF9D70",Orange_400:"#FF6837",Orange_500:"#FF4717",Orange_600:"#F02706",Orange_700:"#C71807",Orange_800:"#9E150E",Orange_900:"#7F150F",Orange_950:"#450605",Success_50:"#F1FCF5",Success_100:"#DEFAEA",Success_200:"#BEF4D4",Success_300:"#8BEAB3",Success_400:"#52D689",Success_500:"#2ECC71",Success_600:"#1D9C53",Success_700:"#1B7A43",Success_800:"#1A6139",Success_900:"#175031",Success_950:"#072C18",Warning_50:"#FFFEEA",Warning_100:"#FFF9C5",Warning_200:"#FFF485",Warning_300:"#FFE846",Warning_400:"#FFD81B",Warning_500:"#FFB800",Warning_600:"#E28D00",Warning_700:"#BB6302",Warning_800:"#984C08",Warning_900:"#7C3F0B",Warning_950:"#482000",Error_50:"#FFF1F1",Error_100:"#FFDFDF",Error_200:"#FFC5C5",Error_300:"#FF9D9D",Error_400:"#FF6464",Error_500:"#FF2E2E",Error_600:"#ED1515",Error_700:"#C80D0D",Error_800:"#A50F0F",Error_900:"#881414",Error_950:"#4B0404",Netural_25:"#FDFDFD",Netural_50:"#FAFAFA",Netural_100:"#F5F5F5",Netural_200:"#E9EAEC",Netural_300:"#D6D7DB",Netural_400:"#A4A7AE",Netural_500:"#727681",Netural_600:"#545863",Netural_700:"#424651",Netural_800:"#252B37",Netural_900:"#191D28",Netural_950:"#0A0D12",Tint_Dark_Blue_100:"#1A1A31",Tint_Dark_Blue_90:"#313146",Tint_Dark_Blue_80:"#48485A",Tint_Dark_Blue_70:"#5F5F6F",Tint_Dark_Blue_60:"#767683",Tint_Dark_Blue_50:"#8C8C98",Tint_Dark_Blue_40:"#A3A3AD",Tint_Dark_Blue_30:"#BABAC1",Tint_Dark_Blue_20:"#D1D1D6",Tint_Dark_Blue_10:"#E8E8EA",Tint_Dark_Blue_5:"#F4F4F5",Tint_Light_Blue_100:"#353552",Tint_Light_Blue_90:"#494963",Tint_Light_Blue_80:"#5D5D75",Tint_Light_Blue_70:"#727286",Tint_Light_Blue_60:"#868697",Tint_Light_Blue_50:"#9A9AA8",Tint_Light_Blue_40:"#AEAEBA",Tint_Light_Blue_30:"#C2C2CB",Tint_Light_Blue_20:"#D7D7DC",Tint_Light_Blue_10:"#EBEBEE",Tint_Light_Blue_5:"#F5F5F6",Tint_Grey_100:"#D1D1D6",Tint_Grey_90:"#D6D6DA",Tint_Grey_80:"#DADADE",Tint_Grey_70:"#DFDFE2",Tint_Grey_60:"#E3E3E6",Tint_Grey_50:"#E8E8EB",Tint_Grey_40:"#EDEDEF",Tint_Grey_30:"#F1F1F3",Tint_Grey_20:"#F6F6F7",Tint_Grey_10:"#FAFAFB",Tint_Grey_5:"#FDFDFD",Tint_Solus_100:"#FF4717",Tint_Solus_90:"#FF592E",Tint_Solus_80:"#FF6C45",Tint_Solus_70:"#FF7E5D",Tint_Solus_60:"#FF9174",Tint_Solus_50:"#FFA38B",Tint_Solus_40:"#FFB5A2",Tint_Solus_30:"#FFC8B9",Tint_Solus_20:"#FFDAD1",Tint_Solus_10:"#FFEDE8",Tint_Solus_5:"#FFF6F3",Other_Color:"#00ABC9"},StatusColor:{tested:"#3E4784",received:"#EE46BC",InTransit:"#6938EF",registered:"#1570EF",reported:"#2ECC71",noStatus:"#727681",Action:"#FF2E2E",Caution:"#FFB800",Pass:"#2ECC71",No_Rating:"#FF6837",Received:"#EE46BC",Tested:"#3E4784",Reported:"#2ECC71",No_Status:"#6938EF",Overdue:"#FF2E2E",Duesoon:"#FFB800",Scheduled:"#1570EF",Good:"#2ECC71",NotApplicable:"#353552"}};exports.ChatPanel=ze;exports.ChatProvider=qe;exports.ChatbotWidget=an;exports.ColorPalette=gn;exports.EmbeddedChatbot=mn;exports.buildApiUrl=Ce;exports.chatApi=kt;exports.createChatApi=Le;exports.resolveApiBaseUrl=de;exports.useChatContext=st;exports.useChatbot=ve;exports.useOptionalChatContext=Ee;