@docgenlab.com/chat-widget 0.2.4 → 0.4.2

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.
@@ -1,9 +1,9 @@
1
- (function(k,_){typeof exports=="object"&&typeof module!="undefined"?_(exports,require("react-dom/client"),require("react")):typeof define=="function"&&define.amd?define(["exports","react-dom/client","react"],_):(k=typeof globalThis!="undefined"?globalThis:k||self,_(k.DocGenLab={},k.ReactDOM,k.React))})(this,function(k,_,o){"use strict";function ye(t){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const l in t)if(l!=="default"){const a=Object.getOwnPropertyDescriptor(t,l);Object.defineProperty(s,l,a.get?a:{enumerable:!0,get:()=>t[l]})}}return s.default=t,Object.freeze(s)}const e=ye(o),$="/api/v1/public/kb",J="dgl-visitor-id";function Y(){const t=globalThis.crypto;return t&&typeof t.randomUUID=="function"?t.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,s=>{const l=Math.random()*16|0;return(s==="x"?l:l&3|8).toString(16)})}function be(){try{let t=localStorage.getItem(J);return t||(t=Y(),localStorage.setItem(J,t)),t}catch(t){return Y()}}class Ee{constructor(s){this.agentKey=s.agentKey,this.baseUrl=s.apiBaseUrl.replace(/\/+$/,""),this.visitorId=s.endUserId?`user:${s.endUserId}`:be(),this.endUserHash=s.endUserHash}headers(s){const l={"X-DocGenLab-Key":this.agentKey,"X-DocGenLab-Visitor-Id":this.visitorId,...s||{}};return this.endUserHash&&(l["X-DocGenLab-User-Hash"]=this.endUserHash),l}async getAgent(){const s=await fetch(`${this.baseUrl}${$}/agent`,{method:"GET",headers:this.headers()});if(!s.ok)throw new Error(`getAgent failed: ${s.status}`);return s.json()}async uploadImage(s){const l=new FormData;l.append("file",s);const a=await fetch(`${this.baseUrl}${$}/chat-image`,{method:"POST",headers:this.headers(),body:l});if(!a.ok){let c=`${a.status} ${a.statusText}`;try{const i=await a.json();c=(i==null?void 0:i.detail)||c}catch(i){}throw new Error(c)}return(await a.json()).image_path}async fetchImage(s){const l=`${this.baseUrl}${$}/chat-image?path=${encodeURIComponent(s)}&key=${encodeURIComponent(this.agentKey)}`,a=await fetch(l,{method:"GET",headers:{"X-DocGenLab-Visitor-Id":this.visitorId}});if(!a.ok)throw new Error(`fetchImage failed: ${a.status}`);const n=await a.blob();return URL.createObjectURL(n)}async fetchSourceFrame(s,l){const a=`${this.baseUrl}${$}/sources/${encodeURIComponent(s)}/frame?path=${encodeURIComponent(l)}&key=${encodeURIComponent(this.agentKey)}`,n=await fetch(a,{method:"GET",headers:{"X-DocGenLab-Visitor-Id":this.visitorId}});if(!n.ok)throw new Error(`fetchSourceFrame failed: ${n.status}`);const c=await n.blob();return URL.createObjectURL(c)}streamChat(s,l){const a=new AbortController;return(async()=>{try{const n=await fetch(`${this.baseUrl}${$}/chat`,{method:"POST",signal:a.signal,headers:this.headers({"Content-Type":"application/json",Accept:"text/event-stream"}),body:JSON.stringify(s)});if(!n.ok||!n.body){let u=`${n.status} ${n.statusText}`;try{const p=await n.json();u=(p==null?void 0:p.detail)||u}catch(p){}l({type:"error",error:u});return}const c=n.body.getReader(),i=new TextDecoder;let r="";for(;;){const{value:u,done:p}=await c.read();if(p)break;r+=i.decode(u,{stream:!0});let I;for(;(I=r.indexOf(`
1
+ (function(I,P){typeof exports=="object"&&typeof module!="undefined"?P(exports,require("react-dom/client"),require("react")):typeof define=="function"&&define.amd?define(["exports","react-dom/client","react"],P):(I=typeof globalThis!="undefined"?globalThis:I||self,P(I.DocGenLab={},I.ReactDOM,I.React))})(this,function(I,P,d){"use strict";function Ue(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const l=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(n,r,l.get?l:{enumerable:!0,get:()=>t[r]})}}return n.default=t,Object.freeze(n)}const e=Ue(d),$="/api/v1/public/kb",re="dgl-visitor-id";function ie(){const t=globalThis.crypto;return t&&typeof t.randomUUID=="function"?t.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,n=>{const r=Math.random()*16|0;return(n==="x"?r:r&3|8).toString(16)})}function Se(){try{let t=localStorage.getItem(re);return t||(t=ie(),localStorage.setItem(re,t)),t}catch(t){return ie()}}class Ce{constructor(n){this.agentKey=n.agentKey,this.baseUrl=n.apiBaseUrl.replace(/\/+$/,""),this.visitorId=n.endUserId?`user:${n.endUserId}`:Se(),this.endUserHash=n.endUserHash}headers(n){const r={"X-DocGenLab-Key":this.agentKey,"X-DocGenLab-Visitor-Id":this.visitorId,...n||{}};return this.endUserHash&&(r["X-DocGenLab-User-Hash"]=this.endUserHash),r}async getAgent(){const n=await fetch(`${this.baseUrl}${$}/agent`,{method:"GET",headers:this.headers()});if(!n.ok)throw new Error(`getAgent failed: ${n.status}`);return n.json()}async getConversation(n){const r=`${this.baseUrl}${$}/conversations/${encodeURIComponent(n)}`,l=await fetch(r,{headers:this.headers()});if(!l.ok)throw new Error(`getConversation failed: ${l.status}`);return l.json()}async getTicketCardState(n){const r=`${this.baseUrl}${$}/conversations/${encodeURIComponent(n)}/ticket-card`,l=await fetch(r,{headers:this.headers()});if(!l.ok)throw new Error(`getTicketCardState failed: ${l.status}`);return l.json()}async uploadImage(n){const r=new FormData;r.append("file",n);const l=await fetch(`${this.baseUrl}${$}/chat-image`,{method:"POST",headers:this.headers(),body:r});if(!l.ok){let o=`${l.status} ${l.statusText}`;try{const s=await l.json();o=(s==null?void 0:s.detail)||o}catch(s){}throw new Error(o)}return(await l.json()).image_path}async fetchImage(n){const r=`${this.baseUrl}${$}/chat-image?path=${encodeURIComponent(n)}&key=${encodeURIComponent(this.agentKey)}`,l=await fetch(r,{method:"GET",headers:{"X-DocGenLab-Visitor-Id":this.visitorId}});if(!l.ok)throw new Error(`fetchImage failed: ${l.status}`);const a=await l.blob();return URL.createObjectURL(a)}async raiseTicket(n,r){const l=`${this.baseUrl}${$}/conversations/${encodeURIComponent(n)}/raise-ticket`,a=await fetch(l,{method:"POST",headers:{"Content-Type":"application/json","X-DocGenLab-Key":this.agentKey,"X-DocGenLab-Visitor-Id":this.visitorId,...this.endUserHash?{"X-DocGenLab-User-Hash":this.endUserHash}:{}},body:JSON.stringify(r)});if(!a.ok){let o=`raiseTicket failed: ${a.status}`;try{o=(await a.json()).detail||o}catch(s){}throw new Error(o)}return a.json()}async listTickets(n){const r=n?`?conversation_id=${encodeURIComponent(n)}`:"",l=`${this.baseUrl}${$}/tickets${r}`,a=await fetch(l,{headers:{"X-DocGenLab-Key":this.agentKey,"X-DocGenLab-Visitor-Id":this.visitorId}});if(!a.ok)throw new Error(`listTickets failed: ${a.status}`);return a.json()}async getTicket(n,r=!1){const l=`${this.baseUrl}${$}/tickets/${encodeURIComponent(n)}${r?"?refresh=1":""}`,a=await fetch(l,{headers:{"X-DocGenLab-Key":this.agentKey,"X-DocGenLab-Visitor-Id":this.visitorId}});if(!a.ok)throw new Error(`getTicket failed: ${a.status}`);return a.json()}async fetchSourceFrame(n,r){const l=`${this.baseUrl}${$}/sources/${encodeURIComponent(n)}/frame?path=${encodeURIComponent(r)}&key=${encodeURIComponent(this.agentKey)}`,a=await fetch(l,{method:"GET",headers:{"X-DocGenLab-Visitor-Id":this.visitorId}});if(!a.ok)throw new Error(`fetchSourceFrame failed: ${a.status}`);const o=await a.blob();return URL.createObjectURL(o)}streamChat(n,r){const l=new AbortController;return(async()=>{try{const a=await fetch(`${this.baseUrl}${$}/chat`,{method:"POST",signal:l.signal,headers:this.headers({"Content-Type":"application/json",Accept:"text/event-stream"}),body:JSON.stringify(n)});if(!a.ok||!a.body){let m=`${a.status} ${a.statusText}`;try{const h=await a.json();m=(h==null?void 0:h.detail)||m}catch(h){}r({type:"error",error:m});return}const o=a.body.getReader(),s=new TextDecoder;let i="";for(;;){const{value:m,done:h}=await o.read();if(h)break;i+=s.decode(m,{stream:!0});let w;for(;(w=i.indexOf(`
2
2
 
3
- `))!==-1;){const b=r.slice(0,I);r=r.slice(I+2);const h=b.trim();if(h.startsWith("data:"))try{const O=JSON.parse(h.slice(5).trim());l(O)}catch(O){}}}}catch(n){(n==null?void 0:n.name)!=="AbortError"&&l({type:"error",error:(n==null?void 0:n.message)||String(n)})}})(),()=>a.abort()}}const x={apiBaseUrl:"https://api.docgenlab.com",position:"bottom-right",primary:"#4F46E5",primaryText:"#FFFFFF",radius:"14px",fontFamily:'system-ui, -apple-system, "Segoe UI", Roboto, sans-serif',greeting:"How can I help you today?",greetingSub:"Ask anything about your uploaded documents. I'll only answer from what's in the knowledge base."};function A(t){var ie,oe,ce,de,me,ue,ge,he;const s=t.apiBaseUrl||x.apiBaseUrl,l=t.enableImageUpload!==!1,a=o.useRef(null),n=`${t.agentKey}::${t.endUserId||""}::${t.endUserHash||""}`,c=o.useRef("");(!a.current||c.current!==n)&&(a.current=new Ee({agentKey:t.agentKey,apiBaseUrl:s,endUserId:t.endUserId,endUserHash:t.endUserHash}),c.current=n);const i=a.current,[r,u]=o.useState(null),[p,I]=o.useState(null),b=(r==null?void 0:r.widget_config)||{},h={position:t.position||b.position||x.position,primary:((ie=t.theme)==null?void 0:ie.primary)||b.primary_color||x.primary,primaryText:((oe=t.theme)==null?void 0:oe.primaryText)||b.primary_text_color||x.primaryText,radius:((ce=t.theme)==null?void 0:ce.radius)||b.radius||x.radius,fontFamily:((de=t.theme)==null?void 0:de.fontFamily)||x.fontFamily,greeting:t.greeting||b.greeting||x.greeting,agentName:t.agentName||b.agent_name||(r==null?void 0:r.name)||"Assistant",agentAvatarUrl:t.agentAvatarUrl||b.agent_avatar_url||void 0,launcherAvatarUrl:b.launcher_avatar_url||void 0,hideBranding:(ue=(me=t.hideBranding)!=null?me:b.hide_branding)!=null?ue:!1,openOnLoad:(he=(ge=t.openOnLoad)!=null?ge:b.open_on_load)!=null?he:!1},O={"--dgl-primary":h.primary,"--dgl-primary-text":h.primaryText,"--dgl-radius":h.radius,"--dgl-font":h.fontFamily},[F,ne]=o.useState(h.openOnLoad),[T,Be]=o.useState(!1),[j,L]=o.useState([]),[D,H]=o.useState(""),[S,B]=o.useState(!1),[P,R]=o.useState(null),[ae,V]=o.useState(null),[w,z]=o.useState(null),[K,X]=o.useState(!1),re=o.useRef(null),q=o.useRef(null),W=o.useRef(""),M=o.useRef(null);o.useEffect(()=>{!F||r||i.getAgent().then(d=>{var m;u(d),(m=t.onReady)==null||m.call(t,d)}).catch(d=>{var m;I(d.message),(m=t.onError)==null||m.call(t,d.message)})},[F,r,i,t]),o.useEffect(()=>{const d=`dgl-chat:${t.agentKey}`,m=localStorage.getItem(d);m&&R(m)},[t.agentKey]),o.useEffect(()=>{P&&localStorage.setItem(`dgl-chat:${t.agentKey}`,P)},[P,t.agentKey]),o.useEffect(()=>{M.current&&(M.current.scrollTop=M.current.scrollHeight)},[j]);const le=o.useCallback(()=>{w&&URL.revokeObjectURL(w),V(null),z(null)},[w]),se=o.useCallback(d=>{if(!d.type.startsWith("image/"))return;const m=10*1024*1024;d.size>m||(w&&URL.revokeObjectURL(w),V(d),z(URL.createObjectURL(d)))},[w]),Pe=async d=>{var fe;if(d.preventDefault(),!D.trim()||S||K)return;const m=D.trim();let E,N;if(ae){try{X(!0),E=await i.uploadImage(ae)}catch(g){(fe=t.onError)==null||fe.call(t,(g==null?void 0:g.message)||"Image upload failed"),X(!1);return}X(!1),N=w||void 0}H(""),W.current="",L(g=>[...g,{role:"user",content:m,imagePath:E,imagePreviewUrl:N},{role:"assistant",content:"",streaming:!0}]),B(!0),V(null),z(null),q.current=i.streamChat({message:m,conversation_id:P||void 0,image_path:E},g=>{var pe;if(g.type==="conversation")R(g.conversation_id);else if(g.type==="token"){W.current+=g.content;const y=W.current;L(f=>f.map((v,We)=>We===f.length-1&&v.role==="assistant"?{...v,content:y}:v))}else g.type==="citations"?L(y=>y.map((f,v)=>v===y.length-1&&f.role==="assistant"?{...f,citations:g.citations}:f)):g.type==="refused"?(W.current=g.content,L(y=>y.map((f,v)=>v===y.length-1&&f.role==="assistant"?{...f,content:g.content,refused:!0}:f))):g.type==="done"?(L(y=>y.map((f,v)=>v===y.length-1&&f.role==="assistant"?{...f,streaming:!1,id:g.message_id,cacheHit:g.cache_hit}:f)),B(!1)):g.type==="error"&&(L(y=>y.map((f,v)=>v===y.length-1&&f.role==="assistant"?{...f,content:`Error: ${g.error}`,streaming:!1,refused:!0}:f)),B(!1),(pe=t.onError)==null||pe.call(t,g.error))})},Ke=()=>{q.current&&q.current(),L([]),R(null),B(!1),localStorage.removeItem(`dgl-chat:${t.agentKey}`),le()};return e.createElement("div",{className:`dgl-root dgl-pos-${h.position}`,style:O},F&&e.createElement("div",{className:`dgl-panel ${T?"dgl-panel-expanded":""}`},e.createElement("div",{className:"dgl-header"},e.createElement("div",{className:"dgl-header-info"},h.agentAvatarUrl?e.createElement("img",{src:h.agentAvatarUrl,alt:"",className:"dgl-avatar"}):e.createElement("div",{className:"dgl-avatar dgl-avatar-fallback dgl-avatar-fallback-light"},h.agentName.slice(0,1).toUpperCase()),e.createElement("div",{className:"dgl-header-text"},e.createElement("div",{className:"dgl-title"},h.agentName),(r==null?void 0:r.org_name)&&e.createElement("div",{className:"dgl-subtitle"},r.org_name))),e.createElement("div",{className:"dgl-header-actions"},e.createElement("button",{type:"button",onClick:Ke,className:"dgl-icon-btn",title:"New chat","aria-label":"New chat"},Fe()),e.createElement("button",{type:"button",onClick:()=>Be(d=>!d),className:"dgl-icon-btn dgl-hide-on-mobile",title:T?"Restore size":"Expand view","aria-label":T?"Restore size":"Expand view"},T?De():je()),e.createElement("button",{type:"button",onClick:()=>ne(!1),className:"dgl-icon-btn",title:"Close","aria-label":"Close"},G()))),e.createElement("div",{className:"dgl-messages",ref:M},j.length===0&&!p&&e.createElement("div",{className:"dgl-empty"},e.createElement("div",{className:"dgl-empty-icon"},Z()),e.createElement("div",{className:"dgl-empty-text"},h.greeting),e.createElement("div",{className:"dgl-empty-sub"},(r==null?void 0:r.description)||x.greetingSub)),p&&e.createElement("div",{className:"dgl-error"},"Couldn't load the assistant: ",p),j.map((d,m)=>e.createElement(ve,{key:m,message:d,client:i,isLast:m===j.length-1,agentAvatarUrl:h.agentAvatarUrl,onPickFollowup:E=>{H(E)}}))),e.createElement("form",{className:"dgl-composer",onSubmit:Pe},w&&e.createElement("div",{className:"dgl-staged-image"},e.createElement("img",{src:w,alt:"attachment"}),e.createElement("button",{type:"button",onClick:le,className:"dgl-staged-remove","aria-label":"Remove image"},G())),e.createElement("div",{className:"dgl-composer-row"},l&&e.createElement(e.Fragment,null,e.createElement("button",{type:"button",className:"dgl-icon-btn",onClick:()=>{var d;return(d=re.current)==null?void 0:d.click()},disabled:S||K,title:"Attach image","aria-label":"Attach image"},Oe()),e.createElement("input",{ref:re,type:"file",accept:"image/png,image/jpeg,image/webp,image/gif",style:{display:"none"},onChange:d=>{var E;const m=(E=d.target.files)==null?void 0:E[0];m&&se(m),d.target&&(d.target.value="")}})),e.createElement("input",{className:"dgl-input",value:D,onChange:d=>H(d.target.value),placeholder:S?"Thinking…":w?"Describe what to know about this image…":"Type your question…",disabled:S,onPaste:d=>{var E;if(!l)return;const m=Array.from(((E=d.clipboardData)==null?void 0:E.items)||[]).find(N=>N.kind==="file"&&N.type.startsWith("image/"));if(m){const N=m.getAsFile();N&&(d.preventDefault(),se(N))}}}),e.createElement("button",{type:"submit",className:"dgl-send-btn",disabled:!D.trim()||S||K,"aria-label":"Send"},S||K?Te():Ae())),!h.hideBranding&&e.createElement("div",{className:"dgl-branding"},"Powered by ",e.createElement("a",{href:"https://docgenlab.com",target:"_blank",rel:"noopener noreferrer"},"DocGenLab")))),e.createElement("button",{type:"button",className:"dgl-launcher",onClick:()=>ne(d=>!d),"aria-label":F?"Close chat":"Open chat"},F?$e():h.launcherAvatarUrl?e.createElement("img",{src:h.launcherAvatarUrl,alt:"",className:"dgl-launcher-avatar"}):_e()))}function ve({message:t,client:s,isLast:l,agentAvatarUrl:a,onPickFollowup:n}){var r;if(t.role==="user")return e.createElement("div",{className:"dgl-msg dgl-msg-user"},e.createElement("div",{className:"dgl-bubble dgl-bubble-user"},(t.imagePath||t.imagePreviewUrl)&&e.createElement(we,{client:s,imagePath:t.imagePath,previewUrl:t.imagePreviewUrl}),t.content));const c=Ie(t.content),i=t.streaming?[]:Ce(t.content);return e.createElement("div",{className:"dgl-msg dgl-msg-assistant"},a?e.createElement("img",{src:a,className:"dgl-avatar",alt:""}):e.createElement("div",{className:"dgl-avatar dgl-avatar-fallback"},Z()),e.createElement("div",{className:"dgl-msg-body"},t.refused?e.createElement("div",{className:"dgl-refused"},c):e.createElement("div",{className:"dgl-assistant-text"},t.streaming&&!c?e.createElement(Se,null):e.createElement(e.Fragment,null,Le(c),t.streaming&&e.createElement("span",{className:"dgl-typing-cursor"},"▍"))),!t.streaming&&!!((r=t.citations)!=null&&r.length)&&e.createElement(xe,{citations:t.citations,client:s}),i.length>0&&e.createElement(ke,{suggestions:i,onPick:n})))}function ke({suggestions:t,onPick:s}){return e.createElement("div",{className:"dgl-followups"},e.createElement("div",{className:"dgl-followups-label"},"Continue exploring"),e.createElement("div",{className:"dgl-followups-list"},t.map((l,a)=>e.createElement("button",{key:a,type:"button",className:"dgl-followup-chip",onClick:()=>s(l)},l))))}function we({client:t,imagePath:s,previewUrl:l}){const[a,n]=o.useState(l||null),[c,i]=o.useState(!1);return o.useEffect(()=>{if(l||!s)return;let r=null;return t.fetchImage(s).then(u=>{r=u,n(u)}).catch(()=>n(null)),()=>{r&&URL.revokeObjectURL(r)}},[t,s,l]),o.useEffect(()=>{if(!c)return;const r=p=>{p.key==="Escape"&&i(!1)};window.addEventListener("keydown",r);const u=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{window.removeEventListener("keydown",r),document.body.style.overflow=u}},[c]),a?e.createElement(e.Fragment,null,e.createElement("button",{type:"button",onClick:()=>i(!0),className:"dgl-user-image-btn","aria-label":"View image"},e.createElement("img",{src:a,className:"dgl-user-image",alt:"attached"})),c&&e.createElement("div",{className:"dgl-lightbox",role:"dialog","aria-modal":"true",onClick:()=>i(!1)},e.createElement("button",{type:"button",className:"dgl-lightbox-close",onClick:r=>{r.stopPropagation(),i(!1)},"aria-label":"Close image"},G()),e.createElement("img",{src:a,className:"dgl-lightbox-img",alt:"attached",onClick:r=>r.stopPropagation()}))):null}function xe({citations:t,client:s}){const l={};for(const r of t){const u=l[r.source_id];(!u||r.score>u.score)&&(l[r.source_id]=r)}const a=Object.values(l).sort((r,u)=>u.score-r.score).slice(0,3),n=Object.keys(l).length-a.length;if(!a.length)return null;const[c,i]=o.useState(null);return e.createElement("div",{className:"dgl-citations"},a.map(r=>e.createElement(Ne,{key:r.chunk_id,citation:r,client:s,isOpen:c===r.chunk_id,onToggle:()=>i(c===r.chunk_id?null:r.chunk_id)})),n>0&&e.createElement("span",{className:"dgl-citation-more"},"+",n," more"))}function Ne({citation:t,client:s,isOpen:l,onToggle:a}){const n=t,c=!!n.frame_path,i=n.heading?`${n.heading}${n.subheading?" › "+n.subheading:""}`:null,r=n.start_seconds!=null?`${Math.floor(n.start_seconds/60)}:${String(n.start_seconds%60).padStart(2,"0")}`:null;return e.createElement("span",{className:"dgl-citation-wrap"},e.createElement("button",{type:"button",className:`dgl-citation ${l?"dgl-citation-open":""}`,onClick:a,title:n.snippet||""},c&&e.createElement("span",{className:"dgl-citation-icon"},"▶"),n.source_name,r&&e.createElement("span",{className:"dgl-citation-stamp"}," · ",r),n.page&&e.createElement("span",{className:"dgl-citation-stamp"}," · p",n.page)),l&&e.createElement("div",{className:"dgl-citation-popover"},n.frame_path&&e.createElement(Ue,{client:s,sourceId:n.source_id,framePath:n.frame_path}),i&&e.createElement("div",{className:"dgl-citation-breadcrumb"},i),n.snippet&&e.createElement("div",{className:"dgl-citation-snippet"},n.snippet)))}function Ue({client:t,sourceId:s,framePath:l}){const[a,n]=o.useState(null);return o.useEffect(()=>{let c=null;return t.fetchSourceFrame(s,l).then(i=>{c=i,n(i)}).catch(()=>n(null)),()=>{c&&URL.revokeObjectURL(c)}},[t,s,l]),a?e.createElement("a",{href:a,target:"_blank",rel:"noopener noreferrer",className:"dgl-citation-frame-link"},e.createElement("img",{src:a,alt:"",className:"dgl-citation-frame"})):e.createElement("div",{className:"dgl-citation-frame-loading"})}function Ce(t){const s=t.match(/<followups>([\s\S]*?)<\/followups>/i);return s?s[1].split(`
4
- `).map(l=>l.trim()).map(l=>l.replace(/^[-*•\d.)\s"']+|["']$/g,"").trim()).filter(l=>l.length>=4&&l.length<=120).slice(0,3):[]}function Ie(t){return t.replace(/\n*<followups>[\s\S]*?(<\/followups>|$)/gi,"").replace(/\s*\[\s*Section:[^\]]*\]?/gi,"").replace(/\s*\[\s*doc:[^\]]*\]?/gi,"").replace(/\s*\[\s*(?:document|doc|source|ref|reference)[^\]]*\]?/gi,"").replace(/\s*\[\s*(?:p\.?\s*)?\d+(?:\s*[,–-]\s*\d+)*\s*\]/gi,"").replace(/[,;]?\s*doc:\s*[0-9a-fA-F][0-9a-fA-F-]{6,}\]?/gi,"").replace(/[,;]\s*(?:\d+|doc:?\s*[0-9a-fA-F-]+)\s*\]?/gi,"").replace(/([\w%])\s*\]/g,"$1").replace(/\s+([,.;:!?])/g,"$1").replace(/[ \t]+/g," ").replace(/\n{3,}/g,`
3
+ `))!==-1;){const y=i.slice(0,w);i=i.slice(w+2);const b=y.trim();if(b.startsWith("data:"))try{const C=JSON.parse(b.slice(5).trim());r(C)}catch(C){}}}}catch(a){(a==null?void 0:a.name)!=="AbortError"&&r({type:"error",error:(a==null?void 0:a.message)||String(a)})}})(),()=>l.abort()}}const O={apiBaseUrl:"https://api.docgenlab.com",position:"bottom-right",primary:"#4F46E5",primaryText:"#FFFFFF",radius:"14px",fontFamily:'system-ui, -apple-system, "Segoe UI", Roboto, sans-serif',greeting:"How can I help you today?",greetingSub:"Ask anything about your uploaded documents. I'll only answer from what's in the knowledge base."};function G(t){var ke,Ee,ye,ve,Ne,we,xe,_e;const n=t.apiBaseUrl||O.apiBaseUrl,r=t.enableImageUpload!==!1,l=d.useRef(null),a=`${t.agentKey}::${t.endUserId||""}::${t.endUserHash||""}`,o=d.useRef("");(!l.current||o.current!==a)&&(l.current=new Ce({agentKey:t.agentKey,apiBaseUrl:n,endUserId:t.endUserId,endUserHash:t.endUserHash}),o.current=a);const s=l.current,[i,m]=d.useState(null),[h,w]=d.useState(null),y=(i==null?void 0:i.widget_config)||{},b={position:t.position||y.position||O.position,primary:((ke=t.theme)==null?void 0:ke.primary)||y.primary_color||O.primary,primaryText:((Ee=t.theme)==null?void 0:Ee.primaryText)||y.primary_text_color||O.primaryText,radius:((ye=t.theme)==null?void 0:ye.radius)||y.radius||O.radius,fontFamily:((ve=t.theme)==null?void 0:ve.fontFamily)||O.fontFamily,greeting:t.greeting||y.greeting||O.greeting,agentName:t.agentName||y.agent_name||(i==null?void 0:i.name)||"Assistant",agentAvatarUrl:t.agentAvatarUrl||y.agent_avatar_url||void 0,launcherAvatarUrl:y.launcher_avatar_url||void 0,hideBranding:(we=(Ne=t.hideBranding)!=null?Ne:y.hide_branding)!=null?we:!1,openOnLoad:(_e=(xe=t.openOnLoad)!=null?xe:y.open_on_load)!=null?_e:!1},C={"--dgl-primary":b.primary,"--dgl-primary-text":b.primaryText,"--dgl-radius":b.radius,"--dgl-font":b.fontFamily},[_,F]=d.useState(b.openOnLoad),[S,K]=d.useState(!1),[E,L]=d.useState([]),[X,J]=d.useState(""),[M,V]=d.useState(!1),[W,Q]=d.useState(null),[ge,Z]=d.useState(null),[T,ee]=d.useState(null),[Y,te]=d.useState(!1),fe=d.useRef(null),ae=d.useRef(null),q=d.useRef(""),z=d.useRef(null),[ne,le]=d.useState([]),[Ze,he]=d.useState(!1);d.useEffect(()=>{!_||i||s.getAgent().then(u=>{var k;m(u),(k=t.onReady)==null||k.call(t,u)}).catch(u=>{var k;w(u.message),(k=t.onError)==null||k.call(t,u.message)})},[_,i,s,t]),d.useEffect(()=>{if(!_||t.disableTicketing)return;let u=!1;return s.listTickets().then(k=>{u||le(k)}).catch(()=>{}),()=>{u=!0}},[_,s,t.disableTicketing]),d.useEffect(()=>{if(!_)return;const u=`dgl-chat:${t.agentKey}`,k=localStorage.getItem(u);if(!k)return;let x=!1;return(async()=>{try{const[v,p]=await Promise.all([s.getConversation(k),s.getTicketCardState(k).catch(()=>null)]);if(x)return;const c=[];for(const U of v.messages||[])U.role==="user"?c.push({id:U.id,role:"user",content:U.content||"",imagePath:U.image_path||void 0}):U.role==="assistant"&&c.push({id:U.id,role:"assistant",content:U.content||"",citations:U.retrieved_chunks||void 0});if(p&&p.kind&&c.length){let U=-1;for(let g=c.length-1;g>=0;g--)if(c[g].role==="assistant"){U=g;break}if(U>=0){const g=c[U];p.kind==="offer"&&p.conversation_id&&p.connector_type&&p.connector_name?g.ticketOffer={conversationId:p.conversation_id,connectorType:p.connector_type,connectorName:p.connector_name}:p.kind==="existing"&&p.ticket_id&&p.status?g.ticketExisting={ticketId:p.ticket_id,externalNumber:p.external_ticket_number||null,externalUrl:p.external_url||null,status:p.status}:p.kind==="created"&&p.ticket_id&&(g.ticketCreated={id:p.ticket_id,externalNumber:p.external_ticket_number||null,externalUrl:p.external_url||null})}}Q(k),L(c)}catch(v){localStorage.removeItem(u)}})(),()=>{x=!0}},[t.agentKey,s,_]),d.useEffect(()=>{W&&localStorage.setItem(`dgl-chat:${t.agentKey}`,W)},[W,t.agentKey]),d.useEffect(()=>{z.current&&(z.current.scrollTop=z.current.scrollHeight)},[E]);const pe=d.useCallback(()=>{T&&URL.revokeObjectURL(T),Z(null),ee(null)},[T]),be=d.useCallback(u=>{if(!u.type.startsWith("image/"))return;const k=10*1024*1024;u.size>k||(T&&URL.revokeObjectURL(T),Z(u),ee(URL.createObjectURL(u)))},[T]),et=async u=>{var p;if(u.preventDefault(),!X.trim()||M||Y)return;const k=X.trim();let x,v;if(ge){try{te(!0),x=await s.uploadImage(ge)}catch(c){(p=t.onError)==null||p.call(t,(c==null?void 0:c.message)||"Image upload failed"),te(!1);return}te(!1),v=T||void 0}J(""),q.current="",L(c=>[...c,{role:"user",content:k,imagePath:x,imagePreviewUrl:v},{role:"assistant",content:"",streaming:!0}]),V(!0),Z(null),ee(null),ae.current=s.streamChat({message:k,conversation_id:W||void 0,image_path:x},c=>{var U;if(c.type==="conversation")Q(c.conversation_id);else if(c.type==="token"){q.current+=c.content;const g=q.current;L(f=>f.map((N,at)=>at===f.length-1&&N.role==="assistant"?{...N,content:g}:N))}else if(c.type==="citations")L(g=>g.map((f,N)=>N===g.length-1&&f.role==="assistant"?{...f,citations:c.citations}:f));else if(c.type==="refused")q.current=c.content,L(g=>g.map((f,N)=>N===g.length-1&&f.role==="assistant"?{...f,content:c.content,refused:!0}:f));else if(c.type==="ticket_offer"){if(t.disableTicketing)return;L(g=>g.map((f,N)=>N===g.length-1&&f.role==="assistant"?{...f,ticketOffer:{conversationId:c.conversation_id,connectorType:c.connector_type,connectorName:c.connector_name}}:f))}else if(c.type==="ticket_existing"){if(t.disableTicketing)return;L(g=>g.map((f,N)=>N===g.length-1&&f.role==="assistant"?{...f,ticketExisting:{ticketId:c.ticket_id,externalNumber:c.external_ticket_number,externalUrl:c.external_url,status:c.status}}:f))}else c.type==="ticket_status_card"?L(g=>g.map((f,N)=>N===g.length-1&&f.role==="assistant"?{...f,ticketStatus:{ticketId:c.ticket_id,externalNumber:c.external_number,externalUrl:c.external_url,status:c.status,title:c.title,priority:c.priority,lastUpdate:c.last_update,assignedTo:c.assigned_to,createdAt:c.created_at}}:f)):c.type==="done"?(L(g=>g.map((f,N)=>N===g.length-1&&f.role==="assistant"?{...f,streaming:!1,id:c.message_id,cacheHit:c.cache_hit}:f)),V(!1)):c.type==="error"&&(L(g=>g.map((f,N)=>N===g.length-1&&f.role==="assistant"?{...f,content:`Error: ${c.error}`,streaming:!1,refused:!0}:f)),V(!1),(U=t.onError)==null||U.call(t,c.error))})},tt=()=>{ae.current&&ae.current(),L([]),Q(null),V(!1),localStorage.removeItem(`dgl-chat:${t.agentKey}`),pe()};return e.createElement("div",{className:`dgl-root dgl-pos-${b.position}`,style:C},_&&e.createElement("div",{className:`dgl-panel ${S?"dgl-panel-expanded":""}`},e.createElement("div",{className:"dgl-header"},e.createElement("div",{className:"dgl-header-info"},b.agentAvatarUrl?e.createElement("img",{src:b.agentAvatarUrl,alt:"",className:"dgl-avatar"}):e.createElement("div",{className:"dgl-avatar dgl-avatar-fallback dgl-avatar-fallback-light"},b.agentName.slice(0,1).toUpperCase()),e.createElement("div",{className:"dgl-header-text"},e.createElement("div",{className:"dgl-title"},b.agentName),(i==null?void 0:i.org_name)&&e.createElement("div",{className:"dgl-subtitle"},i.org_name))),e.createElement("div",{className:"dgl-header-actions"},!t.disableTicketing&&ne.length>0&&e.createElement("button",{type:"button",onClick:()=>he(!0),className:"dgl-tix-btn",title:"Your tickets","aria-label":"Your tickets"},D(),e.createElement("span",null,"Tickets"),e.createElement("span",{className:"dgl-tix-btn-badge"},ne.length)),e.createElement("button",{type:"button",onClick:tt,className:"dgl-icon-btn",title:"New chat","aria-label":"New chat"},Ve()),e.createElement("button",{type:"button",onClick:()=>K(u=>!u),className:"dgl-icon-btn dgl-hide-on-mobile",title:S?"Restore size":"Expand view","aria-label":S?"Restore size":"Expand view"},S?Je():ze()),e.createElement("button",{type:"button",onClick:()=>F(!1),className:"dgl-icon-btn",title:"Close","aria-label":"Close"},H()))),Ze&&e.createElement(Ge,{tickets:ne,onClose:()=>he(!1),onRefresh:async()=>{try{const u=await s.listTickets();le(u)}catch(u){}}}),e.createElement("div",{className:"dgl-messages",ref:z},E.length===0&&!h&&e.createElement("div",{className:"dgl-empty"},e.createElement("div",{className:"dgl-empty-icon"},de()),e.createElement("div",{className:"dgl-empty-text"},b.greeting),e.createElement("div",{className:"dgl-empty-sub"},(i==null?void 0:i.description)||O.greetingSub)),h&&e.createElement("div",{className:"dgl-error"},"Couldn't load the assistant: ",h),E.map((u,k)=>e.createElement(Le,{key:k,message:u,client:s,isLast:k===E.length-1,agentAvatarUrl:b.agentAvatarUrl,onPickFollowup:x=>{J(x)},defaultEmail:t.endUserEmail,defaultPhone:t.endUserPhone,conversationId:W||void 0,onTicketCreated:(x,v)=>{L(p=>p.map(c=>c===x?{...c,ticketOffer:void 0,ticketExisting:void 0,ticketCreated:{id:v.id,externalNumber:v.external_ticket_number,externalUrl:v.external_url}}:c)),le(p=>[v,...p.filter(c=>c.id!==v.id)])}}))),e.createElement("form",{className:"dgl-composer",onSubmit:et},T&&e.createElement("div",{className:"dgl-staged-image"},e.createElement("img",{src:T,alt:"attachment"}),e.createElement("button",{type:"button",onClick:pe,className:"dgl-staged-remove","aria-label":"Remove image"},H())),e.createElement("div",{className:"dgl-composer-row"},r&&e.createElement(e.Fragment,null,e.createElement("button",{type:"button",className:"dgl-icon-btn",onClick:()=>{var u;return(u=fe.current)==null?void 0:u.click()},disabled:M||Y,title:"Attach image","aria-label":"Attach image"},qe()),e.createElement("input",{ref:fe,type:"file",accept:"image/png,image/jpeg,image/webp,image/gif",style:{display:"none"},onChange:u=>{var x;const k=(x=u.target.files)==null?void 0:x[0];k&&be(k),u.target&&(u.target.value="")}})),e.createElement("input",{className:"dgl-input",value:X,onChange:u=>J(u.target.value),placeholder:M?"Thinking…":T?"Describe what to know about this image…":"Type your question…",disabled:M,onPaste:u=>{var x;if(!r)return;const k=Array.from(((x=u.clipboardData)==null?void 0:x.items)||[]).find(v=>v.kind==="file"&&v.type.startsWith("image/"));if(k){const v=k.getAsFile();v&&(u.preventDefault(),be(v))}}}),e.createElement("button",{type:"submit",className:"dgl-send-btn",disabled:!X.trim()||M||Y,"aria-label":"Send"},M||Y?R():Ye())),!b.hideBranding&&e.createElement("div",{className:"dgl-branding"},"Powered by ",e.createElement("a",{href:"https://docgenlab.com",target:"_blank",rel:"noopener noreferrer"},"DocGenLab")))),e.createElement("button",{type:"button",className:"dgl-launcher",onClick:()=>F(u=>!u),"aria-label":_?"Close chat":"Open chat"},_?Xe():b.launcherAvatarUrl?e.createElement("img",{src:b.launcherAvatarUrl,alt:"",className:"dgl-launcher-avatar"}):Re()))}function Le({message:t,client:n,isLast:r,agentAvatarUrl:l,onPickFollowup:a,defaultEmail:o,defaultPhone:s,conversationId:i,onTicketCreated:m}){var y;if(t.role==="user")return e.createElement("div",{className:"dgl-msg dgl-msg-user"},e.createElement("div",{className:"dgl-bubble dgl-bubble-user"},(t.imagePath||t.imagePreviewUrl)&&e.createElement($e,{client:n,imagePath:t.imagePath,previewUrl:t.imagePreviewUrl}),t.content));const h=je(t.content),w=t.streaming?[]:Be(t.content);return e.createElement("div",{className:"dgl-msg dgl-msg-assistant"},l?e.createElement("img",{src:l,className:"dgl-avatar",alt:""}):e.createElement("div",{className:"dgl-avatar dgl-avatar-fallback"},de()),e.createElement("div",{className:"dgl-msg-body"},t.refused?e.createElement("div",{className:"dgl-refused"},h):t.ticketStatus?e.createElement(We,{ticket:t.ticketStatus}):e.createElement("div",{className:"dgl-assistant-text"},t.streaming&&!h?e.createElement(De,null):e.createElement(e.Fragment,null,Ae(h),t.streaming&&e.createElement("span",{className:"dgl-typing-cursor"},"▍"))),!t.streaming&&!t.refused&&!!((y=t.citations)!=null&&y.length)&&!t.ticketStatus&&e.createElement(Te,{citations:t.citations,client:n}),!t.streaming&&!t.ticketStatus&&t.ticketCreated?e.createElement(Pe,{created:t.ticketCreated}):!t.streaming&&!t.ticketStatus&&t.ticketExisting?e.createElement(Ke,{existing:t.ticketExisting,client:n,conversationId:i,defaultEmail:o,defaultPhone:s,onNewTicketRaised:b=>m==null?void 0:m(t,b)}):!t.streaming&&!t.ticketStatus&&t.ticketOffer?e.createElement(Me,{client:n,offer:t.ticketOffer,defaultEmail:o,defaultPhone:s,onCreated:b=>m==null?void 0:m(t,b)}):null,w.length>0&&e.createElement(Ie,{suggestions:w,onPick:a})))}function Ie({suggestions:t,onPick:n}){return e.createElement("div",{className:"dgl-followups"},e.createElement("div",{className:"dgl-followups-label"},"Continue exploring"),e.createElement("div",{className:"dgl-followups-list"},t.map((r,l)=>e.createElement("button",{key:l,type:"button",className:"dgl-followup-chip",onClick:()=>n(r)},r))))}function $e({client:t,imagePath:n,previewUrl:r}){const[l,a]=d.useState(r||null),[o,s]=d.useState(!1);return d.useEffect(()=>{if(r||!n)return;let i=null;return t.fetchImage(n).then(m=>{i=m,a(m)}).catch(()=>a(null)),()=>{i&&URL.revokeObjectURL(i)}},[t,n,r]),d.useEffect(()=>{if(!o)return;const i=h=>{h.key==="Escape"&&s(!1)};window.addEventListener("keydown",i);const m=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{window.removeEventListener("keydown",i),document.body.style.overflow=m}},[o]),l?e.createElement(e.Fragment,null,e.createElement("button",{type:"button",onClick:()=>s(!0),className:"dgl-user-image-btn","aria-label":"View image"},e.createElement("img",{src:l,className:"dgl-user-image",alt:"attached"})),o&&e.createElement("div",{className:"dgl-lightbox",role:"dialog","aria-modal":"true",onClick:()=>s(!1)},e.createElement("button",{type:"button",className:"dgl-lightbox-close",onClick:i=>{i.stopPropagation(),s(!1)},"aria-label":"Close image"},H()),e.createElement("img",{src:l,className:"dgl-lightbox-img",alt:"attached",onClick:i=>i.stopPropagation()}))):null}function Te({citations:t,client:n}){const r={};for(const i of t){const m=r[i.source_id];(!m||i.score>m.score)&&(r[i.source_id]=i)}const l=Object.values(r).sort((i,m)=>m.score-i.score).slice(0,3),a=Object.keys(r).length-l.length;if(!l.length)return null;const[o,s]=d.useState(null);return e.createElement("div",{className:"dgl-citations"},l.map(i=>e.createElement(Oe,{key:i.chunk_id,citation:i,client:n,isOpen:o===i.chunk_id,onToggle:()=>s(o===i.chunk_id?null:i.chunk_id)})),a>0&&e.createElement("span",{className:"dgl-citation-more"},"+",a," more"))}function Oe({citation:t,client:n,isOpen:r,onToggle:l}){const a=t,o=!!a.frame_path,s=a.heading?`${a.heading}${a.subheading?" › "+a.subheading:""}`:null,i=a.start_seconds!=null?`${Math.floor(a.start_seconds/60)}:${String(a.start_seconds%60).padStart(2,"0")}`:null;return e.createElement("span",{className:"dgl-citation-wrap"},e.createElement("button",{type:"button",className:`dgl-citation ${r?"dgl-citation-open":""}`,onClick:l,title:a.snippet||""},o&&e.createElement("span",{className:"dgl-citation-icon"},"▶"),a.source_name,i&&e.createElement("span",{className:"dgl-citation-stamp"}," · ",i),a.page&&e.createElement("span",{className:"dgl-citation-stamp"}," · p",a.page)),r&&e.createElement("div",{className:"dgl-citation-popover"},a.frame_path&&e.createElement(Fe,{client:n,sourceId:a.source_id,framePath:a.frame_path}),s&&e.createElement("div",{className:"dgl-citation-breadcrumb"},s),a.snippet&&e.createElement("div",{className:"dgl-citation-snippet"},a.snippet)))}function Fe({client:t,sourceId:n,framePath:r}){const[l,a]=d.useState(null);return d.useEffect(()=>{let o=null;return t.fetchSourceFrame(n,r).then(s=>{o=s,a(s)}).catch(()=>a(null)),()=>{o&&URL.revokeObjectURL(o)}},[t,n,r]),l?e.createElement("a",{href:l,target:"_blank",rel:"noopener noreferrer",className:"dgl-citation-frame-link"},e.createElement("img",{src:l,alt:"",className:"dgl-citation-frame"})):e.createElement("div",{className:"dgl-citation-frame-loading"})}function Be(t){const n=t.match(/<followups>([\s\S]*?)<\/followups>/i);return n?n[1].split(`
4
+ `).map(r=>r.trim()).map(r=>r.replace(/^[-*•\d.)\s"']+|["']$/g,"").trim()).filter(r=>r.length>=4&&r.length<=120).slice(0,3):[]}function je(t){const n=/\s*I\s+(don'?t|do not)\s+have\s+(?:specific|enough|that|the|any)?\s*information\s+on\s+(?:this|that)[^.]*?\.(?:\s*Please\s+(?:contact|reach\s*out\s+to)\s+(?:your\s+)?(?:support|admin)[^.]*?\.)?/gi,r=/\n*<followups>[\s\S]*?(<\/followups>|$)/gi,l=t.replace(r,""),a=l.replace(n,"").trim();return(l.trim().length>0&&a.length<20?t:t.replace(n,"")).replace(/\n*<followups>[\s\S]*?(<\/followups>|$)/gi,"").replace(/\s*\[\s*Section:[^\]]*\]?/gi,"").replace(/\s*\[\s*doc:[^\]]*\]?/gi,"").replace(/\s*\[\s*(?:document|doc|source|ref|reference)[^\]]*\]?/gi,"").replace(/\s*\[\s*(?:p\.?\s*)?\d+(?:\s*[,–-]\s*\d+)*\s*\]/gi,"").replace(/[,;]?\s*doc:\s*[0-9a-fA-F][0-9a-fA-F-]{6,}\]?/gi,"").replace(/[,;]\s*(?:\d+|doc:?\s*[0-9a-fA-F-]+)\s*\]?/gi,"").replace(/([\w%])\s*\]/g,"$1").replace(/\s+([,.;:!?])/g,"$1").replace(/[ \t]+/g," ").replace(/\n{3,}/g,`
5
5
 
6
- `).trim()}function Le(t){return t.split(/\n{2,}/).map((l,a)=>{const n=l.split(`
7
- `);if(n.every(i=>/^(\s*)([-*]|\d+\.)\s/.test(i))&&n.length>0){const i=/^\d+\./.test(n[0].trim()),r=n.map(p=>p.replace(/^\s*(?:[-*]|\d+\.)\s+/,"")),u=i?"ol":"ul";return e.createElement(u,{key:a,className:`dgl-md-list ${i?"dgl-md-ol":"dgl-md-ul"}`},r.map((p,I)=>e.createElement("li",{key:I},Q(p))))}return e.createElement("p",{key:a,className:"dgl-md-p"},l.split(`
8
- `).map((i,r,u)=>e.createElement(e.Fragment,{key:r},Q(i),r<u.length-1&&e.createElement("br",null))))})}function Q(t){const s=/(`[^`]+`|\*\*[^*\n]+\*\*|\*[^*\n]+\*|\[[^\]]+\]\([^)]+\))/g;return t.split(s).map((a,n)=>{if(!a)return null;if(a.startsWith("`")&&a.endsWith("`"))return e.createElement("code",{key:n,className:"dgl-md-code"},a.slice(1,-1));if(a.startsWith("**")&&a.endsWith("**"))return e.createElement("strong",{key:n},a.slice(2,-2));if(a.startsWith("*")&&a.endsWith("*")&&a.length>2)return e.createElement("em",{key:n},a.slice(1,-1));const c=a.match(/^\[([^\]]+)\]\(([^)]+)\)$/);return c?e.createElement("a",{key:n,href:c[2],target:"_blank",rel:"noopener noreferrer",className:"dgl-md-link"},c[1]):e.createElement(e.Fragment,{key:n},a)})}function Se(){return e.createElement("span",{className:"dgl-thinking"},e.createElement("span",{className:"dgl-thinking-dot"}),e.createElement("span",{className:"dgl-thinking-dot"}),e.createElement("span",{className:"dgl-thinking-dot"}))}function _e(){return e.createElement("svg",{viewBox:"0 0 24 24",width:"22",height:"22",fill:"currentColor"},e.createElement("path",{d:"M4 4h16a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H8l-4 4V6a2 2 0 0 1 2-2z"}))}function $e(){return e.createElement("svg",{viewBox:"0 0 24 24",width:"22",height:"22",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round"},e.createElement("polyline",{points:"6 9 12 15 18 9"}))}function G(){return e.createElement("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},e.createElement("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.createElement("line",{x1:"6",y1:"6",x2:"18",y2:"18"}))}function Fe(){return e.createElement("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},e.createElement("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.createElement("line",{x1:"5",y1:"12",x2:"19",y2:"12"}))}function Ae(){return e.createElement("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"currentColor"},e.createElement("path",{d:"M2 21l21-9L2 3v7l15 2-15 2z"}))}function Oe(){return e.createElement("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},e.createElement("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.createElement("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),e.createElement("polyline",{points:"21 15 16 10 5 21"}))}function Te(){return e.createElement("svg",{viewBox:"0 0 24 24",width:"16",height:"16",className:"dgl-spin",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round"},e.createElement("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"}))}function je(){return e.createElement("svg",{viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},e.createElement("polyline",{points:"15 3 21 3 21 9"}),e.createElement("polyline",{points:"9 21 3 21 3 15"}),e.createElement("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),e.createElement("line",{x1:"3",y1:"21",x2:"10",y2:"14"}))}function De(){return e.createElement("svg",{viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},e.createElement("polyline",{points:"4 14 10 14 10 20"}),e.createElement("polyline",{points:"20 10 14 10 14 4"}),e.createElement("line",{x1:"14",y1:"10",x2:"21",y2:"3"}),e.createElement("line",{x1:"3",y1:"21",x2:"10",y2:"14"}))}function Z(){return e.createElement("svg",{viewBox:"0 0 24 24",width:"14",height:"14",fill:"currentColor"},e.createElement("path",{d:"M12 2l2.39 6.95L21 11l-6.61 2.05L12 20l-2.39-6.95L3 11l6.61-2.05L12 2z"}))}let U=null,C=null;function ee(t){if(typeof document=="undefined")throw new Error("DocGenLab.init() requires a browser environment.");if(U){U.render(o.createElement(A,t));return}C=document.createElement("div"),C.id="docgenlab-chat-widget-root",document.body.appendChild(C),U=_.createRoot(C),U.render(o.createElement(A,t))}function te(){U&&(U.unmount(),U=null),C&&(C.remove(),C=null)}typeof window!="undefined"&&(window.DocGenLab={init:ee,destroy:te,DocGenLabChat:A}),k.DocGenLabChat=A,k.destroy=te,k.init=ee,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
6
+ `).trim()}function Ae(t){return t.split(/\n{2,}/).map((r,l)=>{const a=r.split(`
7
+ `);if(a.every(s=>/^(\s*)([-*]|\d+\.)\s/.test(s))&&a.length>0){const s=/^\d+\./.test(a[0].trim()),i=a.map(h=>h.replace(/^\s*(?:[-*]|\d+\.)\s+/,"")),m=s?"ol":"ul";return e.createElement(m,{key:l,className:`dgl-md-list ${s?"dgl-md-ol":"dgl-md-ul"}`},i.map((h,w)=>e.createElement("li",{key:w},se(h))))}return e.createElement("p",{key:l,className:"dgl-md-p"},r.split(`
8
+ `).map((s,i,m)=>e.createElement(e.Fragment,{key:i},se(s),i<m.length-1&&e.createElement("br",null))))})}function se(t){const n=/(`[^`]+`|\*\*[^*\n]+\*\*|\*[^*\n]+\*|\[[^\]]+\]\([^)]+\))/g;return t.split(n).map((l,a)=>{if(!l)return null;if(l.startsWith("`")&&l.endsWith("`"))return e.createElement("code",{key:a,className:"dgl-md-code"},l.slice(1,-1));if(l.startsWith("**")&&l.endsWith("**"))return e.createElement("strong",{key:a},l.slice(2,-2));if(l.startsWith("*")&&l.endsWith("*")&&l.length>2)return e.createElement("em",{key:a},l.slice(1,-1));const o=l.match(/^\[([^\]]+)\]\(([^)]+)\)$/);return o?e.createElement("a",{key:a,href:o[2],target:"_blank",rel:"noopener noreferrer",className:"dgl-md-link"},o[1]):e.createElement(e.Fragment,{key:a},l)})}function De(){return e.createElement("span",{className:"dgl-thinking"},e.createElement("span",{className:"dgl-thinking-dot"}),e.createElement("span",{className:"dgl-thinking-dot"}),e.createElement("span",{className:"dgl-thinking-dot"}))}const B={open:{label:"Open",stripe:"linear-gradient(90deg,#3b82f6,#6366f1)",iconBg:"#3b82f6",pillBg:"#dbeafe",pillFg:"#1e40af"},in_progress:{label:"In progress",stripe:"linear-gradient(90deg,#8b5cf6,#d946ef)",iconBg:"#8b5cf6",pillBg:"#ede9fe",pillFg:"#5b21b6"},on_hold:{label:"On hold",stripe:"linear-gradient(90deg,#f59e0b,#f97316)",iconBg:"#f59e0b",pillBg:"#fef3c7",pillFg:"#92400e"},resolved:{label:"Resolved",stripe:"linear-gradient(90deg,#10b981,#14b8a6)",iconBg:"#10b981",pillBg:"#d1fae5",pillFg:"#065f46"},closed:{label:"Closed",stripe:"linear-gradient(90deg,#94a3b8,#64748b)",iconBg:"#64748b",pillBg:"#f1f5f9",pillFg:"#334155"},cancelled:{label:"Cancelled",stripe:"linear-gradient(90deg,#ef4444,#f43f5e)",iconBg:"#ef4444",pillBg:"#fee2e2",pillFg:"#991b1b"}},ce={low:{bg:"#f1f5f9",fg:"#475569"},medium:{bg:"#dbeafe",fg:"#1e40af"},high:{bg:"#fef3c7",fg:"#92400e"},urgent:{bg:"#fee2e2",fg:"#991b1b"}};function oe(t){if(!t)return"—";const n=new Date(t),r=Date.now()-n.getTime();if(Number.isNaN(r))return t;const l=Math.floor(r/6e4);if(l<1)return"just now";if(l<60)return`${l}m ago`;const a=Math.floor(l/60);if(a<24)return`${a}h ago`;const o=Math.floor(a/24);return o<7?`${o}d ago`:n.toLocaleDateString()}function Me({client:t,offer:n,defaultEmail:r,defaultPhone:l,onCreated:a}){const[o,s]=d.useState(r||""),[i,m]=d.useState(l||""),[h,w]=d.useState(!r),[y,b]=d.useState("medium"),[C,_]=d.useState(!1),[F,S]=d.useState(null),K=async()=>{if(!o.trim()){S("Email is required so the team can follow up.");return}_(!0),S(null);try{const E=await t.raiseTicket(n.conversationId,{consent:!0,end_user_email:o.trim(),end_user_phone:i.trim()||void 0,priority:y});a(E)}catch(E){S((E==null?void 0:E.message)||"Could not create ticket. Try again.")}finally{_(!1)}};return e.createElement("div",{className:"dgl-ticket-card"},e.createElement("div",{className:"dgl-ticket-card-stripe",style:{background:"linear-gradient(90deg,#6366f1,#8b5cf6)"}}),e.createElement("div",{className:"dgl-ticket-card-body"},e.createElement("div",{className:"dgl-ticket-card-head"},e.createElement("div",{className:"dgl-ticket-card-icon",style:{background:"linear-gradient(135deg,#6366f1,#8b5cf6,#ec4899)"}},D()),e.createElement("div",{className:"dgl-ticket-card-titles"},e.createElement("div",{className:"dgl-ticket-card-eyebrow"},"Support escalation"),e.createElement("div",{className:"dgl-ticket-card-title"},"Need a human to look at this?"))),e.createElement("div",{className:"dgl-ticket-card-desc"},"We'll summarise this chat and raise a ticket. Our team will follow up on the email below."),e.createElement("div",{className:"dgl-ticket-form-grid"},e.createElement("div",null,e.createElement("div",{className:"dgl-ticket-field-label"},"Reply to"),h?e.createElement("input",{type:"email",className:"dgl-ticket-input",value:o,onChange:E=>s(E.target.value),onBlur:()=>o&&w(!1),placeholder:"you@example.com",autoFocus:!0}):e.createElement("button",{type:"button",className:"dgl-ticket-email-link",onClick:()=>w(!0),title:"Click to change"},o||"Set email"," ",e.createElement("span",{className:"dgl-ticket-email-change"},"(change)"))),e.createElement("div",null,e.createElement("div",{className:"dgl-ticket-field-label"},"Priority"),e.createElement("select",{className:"dgl-ticket-input",value:y,onChange:E=>b(E.target.value)},e.createElement("option",{value:"low"},"Low"),e.createElement("option",{value:"medium"},"Medium"),e.createElement("option",{value:"high"},"High"),e.createElement("option",{value:"urgent"},"Urgent")))),F&&e.createElement("div",{className:"dgl-ticket-error"},F),e.createElement("div",{className:"dgl-ticket-card-footer"},e.createElement("span",{className:"dgl-ticket-hint"},"The bot writes the title + description from this chat."),e.createElement("button",{type:"button",className:"dgl-ticket-submit",onClick:K,disabled:C||!o.trim()},C?R():D(),e.createElement("span",null,C?"Submitting…":"Submit ticket")))))}function Pe({created:t}){const n=B.open;return e.createElement("div",{className:"dgl-ticket-card"},e.createElement("div",{className:"dgl-ticket-card-stripe",style:{background:"linear-gradient(90deg,#10b981,#14b8a6)"}}),e.createElement("div",{className:"dgl-ticket-card-body"},e.createElement("div",{className:"dgl-ticket-card-head"},e.createElement("div",{className:"dgl-ticket-card-icon",style:{background:"linear-gradient(135deg,#10b981,#14b8a6)"}},He()),e.createElement("div",{className:"dgl-ticket-card-titles"},e.createElement("div",{className:"dgl-ticket-card-eyebrow",style:{color:"#059669"}},"Ticket created"),e.createElement("div",{className:"dgl-ticket-card-title"},"#",t.externalNumber||t.id.slice(0,8))),t.externalUrl&&e.createElement("a",{className:"dgl-ticket-open-btn",href:t.externalUrl,target:"_blank",rel:"noopener noreferrer"},"Open")),e.createElement("div",{className:"dgl-ticket-pills"},e.createElement("span",{className:"dgl-ticket-pill",style:{background:n.pillBg,color:n.pillFg}},e.createElement("span",{className:"dgl-ticket-pill-dot",style:{background:n.iconBg}})," Open")),e.createElement("div",{className:"dgl-ticket-card-desc"},"Support team has been notified — they'll follow up directly on your email.")))}function Ke({existing:t,client:n,conversationId:r,defaultEmail:l,defaultPhone:a,onNewTicketRaised:o}){const s=B[t.status]||B.open,[i,m]=d.useState(!1),[h,w]=d.useState(l||""),[y,b]=d.useState("medium"),[C,_]=d.useState(!1),[F,S]=d.useState(null),K=async()=>{if(!h.trim()){S("Email is required so the team can follow up.");return}if(!r){S("Conversation not available yet.");return}_(!0),S(null);try{const E=await n.raiseTicket(r,{consent:!0,end_user_email:h.trim(),end_user_phone:a||void 0,priority:y,force_new:!0});o==null||o(E)}catch(E){S((E==null?void 0:E.message)||"Could not create ticket. Try again.")}finally{_(!1)}};return e.createElement("div",{className:"dgl-ticket-card"},e.createElement("div",{className:"dgl-ticket-card-stripe",style:{background:s.stripe}}),e.createElement("div",{className:"dgl-ticket-card-body"},e.createElement("div",{className:"dgl-ticket-card-head"},e.createElement("div",{className:"dgl-ticket-card-icon",style:{background:s.iconBg}},D()),e.createElement("div",{className:"dgl-ticket-card-titles"},e.createElement("div",{className:"dgl-ticket-card-eyebrow"},"We're already on it"),e.createElement("div",{className:"dgl-ticket-card-title"},"#",t.externalNumber||t.ticketId.slice(0,8))),t.externalUrl&&e.createElement("a",{className:"dgl-ticket-open-btn",href:t.externalUrl,target:"_blank",rel:"noopener noreferrer"},"Open")),e.createElement("div",{className:"dgl-ticket-pills"},e.createElement("span",{className:"dgl-ticket-pill",style:{background:s.pillBg,color:s.pillFg}},e.createElement("span",{className:"dgl-ticket-pill-dot",style:{background:s.iconBg}})," ",s.label)),e.createElement("div",{className:"dgl-ticket-card-desc"},"A ticket has already been raised for this conversation. Our team will follow up — no need to file another."),i?e.createElement("div",{className:"dgl-ticket-diff-form"},e.createElement("div",{className:"dgl-ticket-field-label",style:{marginTop:4}},"File a separate ticket for a new issue"),e.createElement("div",{className:"dgl-ticket-form-grid"},e.createElement("div",null,e.createElement("div",{className:"dgl-ticket-field-label"},"Reply to"),e.createElement("input",{type:"email",className:"dgl-ticket-input",value:h,onChange:E=>w(E.target.value),placeholder:"you@example.com"})),e.createElement("div",null,e.createElement("div",{className:"dgl-ticket-field-label"},"Priority"),e.createElement("select",{className:"dgl-ticket-input",value:y,onChange:E=>b(E.target.value)},e.createElement("option",{value:"low"},"Low"),e.createElement("option",{value:"medium"},"Medium"),e.createElement("option",{value:"high"},"High"),e.createElement("option",{value:"urgent"},"Urgent")))),F&&e.createElement("div",{className:"dgl-ticket-error"},F),e.createElement("div",{className:"dgl-ticket-card-footer"},e.createElement("button",{type:"button",className:"dgl-ticket-diff-cancel",onClick:()=>m(!1)},"Cancel"),e.createElement("button",{type:"button",className:"dgl-ticket-submit",onClick:K,disabled:C||!h.trim()},C?R():D(),e.createElement("span",null,C?"Submitting…":"Submit new ticket")))):e.createElement("button",{type:"button",className:"dgl-ticket-diff-link",onClick:()=>m(!0)},"Different issue? Raise new ticket →")))}function We({ticket:t}){const n=B[t.status]||B.open,r=ce[(t.priority||"medium").toLowerCase()]||ce.medium;return e.createElement("div",{className:"dgl-ticket-card"},e.createElement("div",{className:"dgl-ticket-card-stripe",style:{background:n.stripe}}),e.createElement("div",{className:"dgl-ticket-card-body"},e.createElement("div",{className:"dgl-ticket-card-head"},e.createElement("div",{className:"dgl-ticket-card-icon",style:{background:n.iconBg}},D()),e.createElement("div",{className:"dgl-ticket-card-titles"},e.createElement("div",{className:"dgl-ticket-card-eyebrow"},"Support ticket"),e.createElement("div",{className:"dgl-ticket-card-title"},"#",t.externalNumber||t.ticketId.slice(0,8))),t.externalUrl&&e.createElement("a",{className:"dgl-ticket-open-btn",href:t.externalUrl,target:"_blank",rel:"noopener noreferrer"},"Open")),e.createElement("div",{className:"dgl-ticket-pills"},e.createElement("span",{className:"dgl-ticket-pill",style:{background:n.pillBg,color:n.pillFg}},e.createElement("span",{className:"dgl-ticket-pill-dot",style:{background:n.iconBg}})," ",n.label),e.createElement("span",{className:"dgl-ticket-pill",style:{background:r.bg,color:r.fg}},t.priority||"medium"," priority")),t.title&&e.createElement("div",{className:"dgl-ticket-card-body-title"},t.title),e.createElement("div",{className:"dgl-ticket-meta-grid"},e.createElement("div",null,e.createElement("div",{className:"dgl-ticket-meta-label"},"Last update"),e.createElement("div",{className:"dgl-ticket-meta-value"},oe(t.lastUpdate))),e.createElement("div",null,e.createElement("div",{className:"dgl-ticket-meta-label"},"Assigned to"),e.createElement("div",{className:"dgl-ticket-meta-value"},t.assignedTo||"Unassigned")))))}function Ge({tickets:t,onClose:n,onRefresh:r}){const[l,a]=d.useState(!1);d.useEffect(()=>{const i=m=>{m.key==="Escape"&&n()};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[n]);const o=async()=>{a(!0);try{await r()}finally{a(!1)}},s=[...t].sort((i,m)=>{const h=i.created_at?new Date(i.created_at).getTime():0;return(m.created_at?new Date(m.created_at).getTime():0)-h});return e.createElement("div",{className:"dgl-tix-modal-backdrop",onClick:n},e.createElement("div",{className:"dgl-tix-modal",onClick:i=>i.stopPropagation()},e.createElement("div",{className:"dgl-tix-modal-header"},e.createElement("div",null,e.createElement("div",{className:"dgl-tix-modal-title"},"Your tickets"),e.createElement("div",{className:"dgl-tix-modal-sub"},t.length===0?"No tickets yet":`${t.length} ticket${t.length===1?"":"s"} on this assistant`)),e.createElement("div",{style:{display:"flex",gap:4}},e.createElement("button",{type:"button",onClick:o,className:"dgl-icon-btn",title:"Refresh","aria-label":"Refresh tickets",disabled:l,style:{color:"#475569"}},l?R():Qe()),e.createElement("button",{type:"button",onClick:n,className:"dgl-icon-btn",title:"Close","aria-label":"Close",style:{color:"#475569"}},H()))),e.createElement("div",{className:"dgl-tix-modal-list"},s.length===0?e.createElement("div",{className:"dgl-tix-empty"},"You haven't raised any support tickets here yet. They'll show up here once you do."):s.map(i=>{const m=B[i.status]||B.open;return e.createElement("div",{key:i.id,className:"dgl-tix-row"},e.createElement("div",{className:"dgl-tix-row-head"},e.createElement("span",{className:"dgl-tix-row-num"},"#",i.external_ticket_number||i.id.slice(0,8)),e.createElement("span",{className:"dgl-ticket-pill",style:{background:m.pillBg,color:m.pillFg}},e.createElement("span",{className:"dgl-ticket-pill-dot",style:{background:m.iconBg}}),m.label),i.external_url&&e.createElement("a",{href:i.external_url,target:"_blank",rel:"noopener noreferrer",className:"dgl-ticket-open-btn",style:{marginLeft:"auto"}},"Open")),i.title&&e.createElement("div",{className:"dgl-tix-row-title"},i.title),e.createElement("div",{className:"dgl-tix-row-meta"},i.priority||"medium"," priority · raised ",oe(i.created_at)))}))))}function D(){return e.createElement("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},e.createElement("circle",{cx:"12",cy:"12",r:"10"}),e.createElement("circle",{cx:"12",cy:"12",r:"4"}),e.createElement("path",{d:"M4.93 4.93l4.24 4.24M14.83 14.83l4.24 4.24M14.83 9.17l4.24-4.24M14.83 9.17l3.53-3.53M4.93 19.07l4.24-4.24"}))}function He(){return e.createElement("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"white",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round"},e.createElement("path",{d:"M20 6L9 17l-5-5"}))}function Re(){return e.createElement("svg",{viewBox:"0 0 24 24",width:"22",height:"22",fill:"currentColor"},e.createElement("path",{d:"M4 4h16a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H8l-4 4V6a2 2 0 0 1 2-2z"}))}function Xe(){return e.createElement("svg",{viewBox:"0 0 24 24",width:"22",height:"22",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round"},e.createElement("polyline",{points:"6 9 12 15 18 9"}))}function H(){return e.createElement("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},e.createElement("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.createElement("line",{x1:"6",y1:"6",x2:"18",y2:"18"}))}function Ve(){return e.createElement("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},e.createElement("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.createElement("line",{x1:"5",y1:"12",x2:"19",y2:"12"}))}function Ye(){return e.createElement("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"currentColor"},e.createElement("path",{d:"M2 21l21-9L2 3v7l15 2-15 2z"}))}function qe(){return e.createElement("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},e.createElement("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.createElement("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),e.createElement("polyline",{points:"21 15 16 10 5 21"}))}function R(){return e.createElement("svg",{viewBox:"0 0 24 24",width:"16",height:"16",className:"dgl-spin",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round"},e.createElement("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"}))}function ze(){return e.createElement("svg",{viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},e.createElement("polyline",{points:"15 3 21 3 21 9"}),e.createElement("polyline",{points:"9 21 3 21 3 15"}),e.createElement("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),e.createElement("line",{x1:"3",y1:"21",x2:"10",y2:"14"}))}function Je(){return e.createElement("svg",{viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},e.createElement("polyline",{points:"4 14 10 14 10 20"}),e.createElement("polyline",{points:"20 10 14 10 14 4"}),e.createElement("line",{x1:"14",y1:"10",x2:"21",y2:"3"}),e.createElement("line",{x1:"3",y1:"21",x2:"10",y2:"14"}))}function Qe(){return e.createElement("svg",{viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},e.createElement("polyline",{points:"23 4 23 10 17 10"}),e.createElement("polyline",{points:"1 20 1 14 7 14"}),e.createElement("path",{d:"M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"}))}function de(){return e.createElement("svg",{viewBox:"0 0 24 24",width:"14",height:"14",fill:"currentColor"},e.createElement("path",{d:"M12 2l2.39 6.95L21 11l-6.61 2.05L12 20l-2.39-6.95L3 11l6.61-2.05L12 2z"}))}let j=null,A=null;function me(t){if(typeof document=="undefined")throw new Error("DocGenLab.init() requires a browser environment.");if(j){j.render(d.createElement(G,t));return}A=document.createElement("div"),A.id="docgenlab-chat-widget-root",document.body.appendChild(A),j=P.createRoot(A),j.render(d.createElement(G,t))}function ue(){j&&(j.unmount(),j=null),A&&(A.remove(),A=null)}typeof window!="undefined"&&(window.DocGenLab={init:me,destroy:ue,DocGenLabChat:G}),I.DocGenLabChat=G,I.destroy=ue,I.init=me,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})});
9
9
  //# sourceMappingURL=index.umd.cjs.map