@liuyuzhao/ai-chat
Version:
A Vue 3 AI chat component with TypeScript support for Web, H5, and UniApp
7 lines (6 loc) • 35.3 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue"),require("marked"),require("dompurify")):"function"==typeof define&&define.amd?define(["exports","vue","marked","dompurify"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).AiChat={},e.Vue,e.marked,e.DOMPurify)}(this,function(e,t,n,o){"use strict";var r=Object.defineProperty,a=Object.defineProperties,s=Object.getOwnPropertyDescriptors,l=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,c=Object.prototype.propertyIsEnumerable,d=(e,t,n)=>t in e?r(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,u=(e,t)=>{for(var n in t||(t={}))i.call(t,n)&&d(e,n,t[n]);if(l)for(var n of l(t))c.call(t,n)&&d(e,n,t[n]);return e},h=(e,t,n)=>new Promise((o,r)=>{var a=e=>{try{l(n.next(e))}catch(t){r(t)}},s=e=>{try{l(n.throw(e))}catch(t){r(t)}},l=e=>e.done?o(e.value):Promise.resolve(e.value).then(a,s);l((n=n.apply(e,t)).next())});function p(e,t){for(var n=0;n<t.length;n++){const o=t[n];if("string"!=typeof o&&!Array.isArray(o))for(const t in o)if("default"!==t&&!(t in e)){const n=Object.getOwnPropertyDescriptor(o,t);n&&Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>o[t]})}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}class f{constructor(e){var t,n;d(this,"symbol"!=typeof(t="config")?t+"":t,n),this.config=e}connect(e,t,n,o,r,a){return h(this,null,function*(){try{const s=new URLSearchParams,l=`${e[e.length-1][0].content}`;s.append("prompt",l),t&&s.append("sessionId",t),n.requestParams&&Object.entries(n.requestParams).forEach(([e,t])=>{s.append(e,String(t))}),s.has("lawyerName")||s.append("lawyerName",n.lawyerName||""),n.lawyerAllowedPort&&s.append("lawyerAllowedPort",n.lawyerAllowedPort||""),s.has("knowledgeCode")||s.append("knowledgeCode",n.knowledgeCode||""),s.has("hotIssues")||s.append("hotIssues",n.hotIssues||"");const i=`${n.apiUrl}/chat?${s.toString()}`;return yield this.connectWeb(i,n.headers,o,r,a)}catch(s){return r(new Error(`Failed to establish connection: ${s}`)),{close:()=>{}}}})}connectWeb(e,t,n,o,r){return h(this,null,function*(){const{EventSourcePolyfill:a}=yield Promise.resolve().then(()=>W),s=new a(e,u({withCredentials:!1},t&&{headers:t}));return s.addEventListener("message",e=>{try{n(e.data)}catch(t){o(new Error(`Message parsing error: ${t}`))}}),s.addEventListener("error",e=>{o(new Error("Connection error occurred")),s.close()}),s.addEventListener("end",()=>{s.close(),null==r||r()}),s})}connectUniapp(e,t,n,o,r){const a=uni.request({url:e,method:"GET",header:t||{},responseType:"text",enableChunked:!0,success:e=>{try{n(e.data),null==r||r()}catch(t){o(new Error(`Message parsing error: ${t}`))}},fail:e=>{o(new Error("Connection error occurred"))}});return{close:()=>a.abort()}}}let A="";function g(e){const n=t.ref([]),o=t.ref(""),r=t.ref(!1),l=t.ref(null),i=t.ref(null),c=t.ref(null),d=t.ref(null),p=t.ref([]),g=t.ref(!1),v=new f(e),y=(...t)=>h(null,[...t],function*(t=[]){g.value=!0;try{const n=new URLSearchParams;t.length>0&&n.append("excludeIds",t.join(","));const o=`${e.apiUrl}/hot-issues`,r=yield fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:t.length>0?JSON.stringify(t):"[]"});if(r.ok){const e=yield r.json();p.value=e.data||[]}else console.error("获取热点问题失败:",r.statusText),p.value=[]}catch(n){console.error("获取热点问题出错:",n),p.value=[]}finally{g.value=!1}});t.onMounted(()=>{y()});let w="",E=!1,C="",m=new Map,b=new Map;const B=()=>h(null,null,function*(){if(!o.value.trim()||r.value)return;const t={role:"user",content:o.value};n.value.push([t,{role:"assistant",content:""}]),o.value="",r.value=!0,A="",w="",E=!1,C="",m.clear();const h=u({},e);var p,f;d.value&&(h.requestParams=(p=u({},e.requestParams),f={hotIssues:d.value},a(p,s(f))),d.value=null);try{const e=yield v.connect(n.value,i.value,h,e=>{var t,a;A+=e;let s=A;for(;s.length>0;)try{let e=0,l=!1,d=!1,u=-1;for(let t=0;t<s.length;t++){const n=s[t];if(d)d=!1;else if("\\"!==n)if('"'!==n){if(!l)if("{"===n)e++;else if("}"===n&&(e--,0===e)){u=t+1;break}}else l=!l;else d=!0}if(u>0){const e=s.substring(0,u),l=JSON.parse(e);let d=l.choices[0].delta.content;if("[DONE]"===d)return r.value=!1,c.value=null,A="",w="",void m.clear();if(i.value=null!=(t=l.id)?t:"",d){const e=null!=(a=l.id)?a:"";C!==e&&(w="",E=!1,C=e,m.clear(),b.clear());const t=()=>"json_"+Date.now()+"_"+Math.random().toString(36).substr(2,9),r=e=>`<div id="${e}" class="button-group" style="margin: 10px 0; display: flex; flex-wrap: wrap; gap: 8px; min-height: 40px; border: 1px dashed #ccc; padding: 8px; border-radius: 4px;"><span class="loading-text" style="color: #666; font-size: 12px;">正在加载按钮...</span></div>`,s=e=>`<div id="${e}" style="margin: 10px 0;"><table class="json-table" style="border-collapse: collapse; width: 100%; border: 1px solid #ddd;"><thead><tr><th style="border: 1px solid #ddd; padding: 12px; background: #f5f5f5;">正在加载表格...</th></tr></thead><tbody></tbody></table></div>`,i=(e,t)=>{let n="";if(Array.isArray(t)){if(0===t.length)return;const e=Object.keys(t[0]);n='<table class="json-table" style="border-collapse: collapse; width: 100%; border: 1px solid #ddd;">',n+="<thead><tr>",e.forEach(e=>{n+=`<th style="border: 1px solid #ddd; padding: 12px; background: #f5f5f5; font-weight: bold; text-align: left;">${e}</th>`}),n+="</tr></thead>",n+="<tbody>",t.forEach((t,o)=>{n+=`<tr style="background-color: ${o%2==0?"#ffffff":"#f9f9f9"};">`,e.forEach(e=>{n+=`<td style="border: 1px solid #ddd; padding: 12px;">${t[e]||""}</td>`}),n+="</tr>"}),n+="</tbody></table>"}else t.headers&&t.rows&&(n='<table class="json-table" style="border-collapse: collapse; width: 100%; border: 1px solid #ddd;">',n+="<thead><tr>",t.headers.forEach(e=>{n+=`<th style="border: 1px solid #ddd; padding: 12px; background: #f5f5f5; font-weight: bold; text-align: left;">${e}</th>`}),n+="</tr></thead>",n+="<tbody>",t.rows.forEach((e,t)=>{n+=`<tr style="background-color: ${t%2==0?"#ffffff":"#f9f9f9"};">`,e.forEach(e=>{n+=`<td style="border: 1px solid #ddd; padding: 12px;">${e}</td>`}),n+="</tr>"}),n+="</tbody></table>");setTimeout(()=>{const t=document.getElementById(e);t&&(t.innerHTML=n)},0)},c=(e,t)=>{const n=document.getElementById(e);if(!n)return;const r=n.querySelectorAll("button").length;if(0===r){const e=n.querySelector(".loading-text");e&&e.remove()}t.slice(r).forEach((e,t)=>{e&&e.trim()&&setTimeout(()=>{const t=document.createElement("button");t.className="msgButton",t.textContent=e.trim(),t.onclick=()=>{o.value=e.trim(),B()},t.style.opacity="0",t.style.transform="translateY(10px)",t.style.transition="all 0.3s ease",n.appendChild(t),setTimeout(()=>{t.style.opacity="1",t.style.transform="translateY(0)"},10)},150*t)})},u=e=>{const t=[];try{const n=e.match(new RegExp('"data"\\s*:\\s*\\[(.*?)\\]',"s"));if(n){const e=n[1].match(/"([^"]+)"/g);e&&e.forEach(e=>{const n=e.replace(/"/g,"").trim();n&&t.push(n)})}}catch(n){console.log("解析部分按钮数据失败:",n)}return t};w+=d;if(w.includes("begin")){const e=[...w.matchAll(/begin/g)],o=[...w.matchAll(/end/g)];if(e.length>o.length){const o=e.length-m.size;for(let e=0;e<o;e++){const e=t(),o=/begin([\s\S]*?)$/,a=w.match(o);if(a){const t=a[1].trim();let o="";if(t.includes('"type"')&&t.includes('"button"')){o=r(e),m.set(e,"button"),b.set(e,[]);n.value[n.value.length-1][1].content+=o,setTimeout(()=>{const n=u(t);n.length>0&&(b.set(e,n),c(e,n))},100)}else if(t.includes('"type"')&&t.includes('"table"')){o=s(e),m.set(e,"table");n.value[n.value.length-1][1].content+=o}}}}m.forEach((e,t)=>{if("button"===e){const e=/begin([\s\S]*?)(?:end|$)/,n=w.match(e);if(n){const e=n[1].trim(),o=u(e),r=b.get(t)||[];o.length>r.length&&(b.set(t,o),c(t,o))}}});const a=/begin([\s\S]*?)end/g,l=[...w.matchAll(a)];if(l.forEach((e,t)=>{const n=e[1].trim();try{const e=JSON.parse(n);if(e.type&&e.data){const n=Array.from(m.keys())[t];if(n){switch(e.type){case"button":const t=Array.isArray(e.data)?e.data:[],o=b.get(n)||[];t.length>o.length&&(b.set(n,t),c(n,t)),setTimeout(()=>{const e=document.getElementById(n);e&&(e.style.border="none")},150*t.length+200);break;case"table":i(n,e.data);break;default:console.warn("未知的JSON类型:",e.type)}m.delete(n),b.delete(n)}}}catch(o){console.log("JSON解析失败:",o)}}),l.length>0){let e=w;if(l.forEach(t=>{e=e.replace(t[0],"")}),e.trim()&&!e.includes("begin")){n.value[n.value.length-1][1].content+=e}w=e.includes("begin")?e:""}}else{n.value[n.value.length-1][1].content+=d,w=""}}}s=s.substring(u),A=s}catch(l){break}},e=>{l.value=e,r.value=!1,c.value=null,A="",w="",m.clear()});c.value=e}catch(g){l.value=g instanceof Error?g:new Error("连接失败"),r.value=!1,c.value=null}});return{messages:n,input:o,loading:r,error:l,sendMessage:B,stopGeneration:()=>{if(c.value&&"function"==typeof c.value.close){try{c.value.close()}catch(e){console.warn("关闭连接时出错:",e)}c.value=null,r.value=!1,n.value[n.value.length-1][1].stopMessage=!0,A="",w="",m.clear()}},hotQuestions:p,hotQuestionsLoading:g,refreshHotIssues:()=>{const e=p.value.map(e=>e.id);y(e)},selectHotIssue:e=>{d.value=e.id,o.value=e.question,B()}}}const v={class:"ai-chat-container"},y={key:0,class:"chat-header"},w={class:"ai-avatar"},E=["src"],C={class:"welcome-message"},m={key:1,class:"hot-questions"},b={class:"section-title"},B=["disabled"],S={class:"questions-list"},k=["onClick"],x={key:0,class:"empty-questions"},T={class:"message-content user"},D=["innerHTML"],Q={class:"message-content assistant"},I={class:"message-label"},L={key:0,class:"assistant-loading"},O={key:1,class:"assistant-stop"},R=["innerHTML"],N={key:3,class:"tag-container"},P=["onClick"],F={class:"chat-input"},U={class:"input-container"},V=["disabled"],G=["disabled"],M=((e,t)=>{const n=e.__vccOpts||e;for(const[o,r]of t)n[o]=r;return n})(t.defineComponent({__name:"AiChat",props:{config:{}},setup(e){const r=e,{messages:a,input:s,loading:l,sendMessage:i,stopGeneration:c,hotQuestions:d,hotQuestionsLoading:u,refreshHotIssues:h,selectHotIssue:p}=g(r.config),f=t.ref(["查看预约记录","查看被监管人","系统问题"]),A=()=>{setTimeout(()=>{window.scrollTo({top:document.documentElement.scrollHeight,behavior:"smooth"})},100)};t.watch(()=>a.value.length,()=>{A()}),t.watch(()=>a.value.length>0?a.value[a.value.length-1][1].content:"",()=>{A()}),t.watch(l,e=>{e&&A()}),t.watch(()=>r.config.knowledgeCode,()=>{a.value=[],s.value=""});const M=e=>e?function(e){if(!e)return"";let t=e;if(t!==e)return o.sanitize(t,{ALLOWED_TAGS:["div","span","p","br","strong","em","code","pre","h1","h2","h3","h4","h5","h6","ul","ol","li","a","button","table","thead","tbody","tr","th","td"],ALLOWED_ATTR:["href","class","onclick","data-*","id","colspan","rowspan"]});const r=e.includes("<button"),a=e.includes("<table")||e.includes("<tr")||e.includes("<td")||e.includes("<th");if(r||a){const t=e.replace(/\n/g,"\n");return o.sanitize(t,{ALLOWED_TAGS:["p","br","strong","em","code","pre","blockquote","h1","h2","h3","h4","h5","h6","ul","ol","li","a","button","div","span","table","thead","tbody","tfoot","tr","th","td","caption"],ALLOWED_ATTR:["href","class","onclick","data-*","id","target","title","alt","src","width","height","colspan","rowspan","scope","style"]})}const s=e.includes("**")||e.includes("*")||e.includes("`")||e.includes("#")||e.includes("[")||e.includes("\n- ")||e.includes("\n1. ")||e.includes("|");let l=e;return l=s?n.marked.parse(e):e.replace(/\n/g,"<br>"),o.sanitize(l,{ALLOWED_TAGS:["p","br","strong","em","code","pre","blockquote","h1","h2","h3","h4","h5","h6","ul","ol","li","a","button","div","span","table","thead","tbody","tfoot","tr","th","td","caption"],ALLOWED_ATTR:["href","class","onclick","data-*","id","target","title","alt","src","width","height","colspan","rowspan","scope","style"]})}(e):"",j=e=>{"lsyy"===r.config.knowledgeCode?(s.value=`请提供关于 ${e} 的详细信息`,i()):s.value=`${a.value[a.value.length-1][0].content}${a.value[a.value.length-1][0].content.includes(":")?`-${e}`:`:${e}`}`};return"undefined"!=typeof window&&(window.selectPerson=j),(e,n)=>(t.openBlock(),t.createElementBlock("div",v,["lsyy"===e.config.knowledgeCode?(t.openBlock(),t.createElementBlock("div",y,[t.createElementVNode("div",w,[t.createElementVNode("img",{width:"100%",mode:"widthFix",src:t.unref("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAAAXNSR0IArs4c6QAAFSBJREFUeF7tXW2S1LgStJtrQTD8ZLkLxJ4A5gQv2Lss/GSI5Vq0X8jdbjw97bY+skpVUvLnvY2RJVWqMqtUstXjwH/uEfjv+/8eLkYcDw/jYXz7wqhp+tMmxuJxfFo3m47Tz8t/H45Pb97//ezvMV2yjT0ERntT4oy2EJiJfk3wVGKj4T0LxUUgKA5ohEX7owCIwpvf+RLVx+HV57mX2kRPNWUcnxZRePPh05fUx9leBwEKgA7Ou6M8i+7eyL5r3anBNA2P8/9hlhCJmHwzCoA8xpsjBNLPEb5Rwu9BuwgCM4Q9pOT+TgGQw/Zmz72TfgtuioGyI56HowAo4E7Sp4FMMUjDq6Q1BaAEvTvPkvQYYCkGGBy3eqEAAPG9FPLG4VS55z8oAkEMWC+AQjpQAAB4MtoDQEzogkKQANZOUwpAAZYkfgF4gEe5PSgHkQKQgSGJnwGa8CPMCvIApgAk4Pbfv1+/jNzfJyCm35RCkIY5BSACL0b8CJCMNaEQxC0IBeAOTiR+nBNZbUUR2F8ZCsAGRr++//Oj11d0993GVwsKwfZ6UQCusOE+3xe5U2ZLIXiJFgXgjAnT/RQq+W5LIfizfhSAYRiY7v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EIBqIF6xpgmRYCf2maspK1HKAC21mNzNha3Aq//+kT/ceI/W9PkAjpaQEv3A/BCTUeOc2eqFABn61g9E+Bruc485v50KQBOl7NGNsB79Zw6CzOA9hZusUhFCBj1m3UgZgCNLG0QgmDKeBjfFv1aD8/yG/GIODP+Dz5iatEYxhQWAAAAAElFTkSuQmCC"),alt:"AI头像"},null,8,E)]),t.createElementVNode("div",C," 你好,"+t.toDisplayString(e.config.lawyerName)+"律师,我是智能客服,请问您有什么需要帮助? ",1)])):t.createCommentVNode("",!0),"lsyy"===e.config.knowledgeCode?(t.openBlock(),t.createElementBlock("div",m,[t.createElementVNode("div",b,[n[5]||(n[5]=t.createElementVNode("span",null,"热门问题",-1)),t.createElementVNode("button",{class:"refresh-btn",onClick:n[0]||(n[0]=(...e)=>t.unref(h)&&t.unref(h)(...e)),disabled:t.unref(u)},t.toDisplayString(t.unref(u)?"加载中...":"换一换"),9,B)]),t.createElementVNode("div",S,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(d),(e,n)=>(t.openBlock(),t.createElementBlock("div",{class:"question-item",key:e.id,onClick:n=>t.unref(p)(e)},t.toDisplayString(n+1)+". "+t.toDisplayString(e.question),9,k))),128)),0!==t.unref(d).length||t.unref(u)?t.createCommentVNode("",!0):(t.openBlock(),t.createElementBlock("div",x," 暂无热门问题 "))])])):t.createCommentVNode("",!0),t.unref(a).length>0?(t.openBlock(),t.createElementBlock("div",{key:2,class:t.normalizeClass(["chat-messages",{tag:f.value.length>0}])},[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(a),(e,o)=>(t.openBlock(),t.createElementBlock("div",{class:"message-item",key:o},[t.createElementVNode("div",T,[n[6]||(n[6]=t.createElementVNode("div",{class:"message-label"},"问:",-1)),t.createElementVNode("div",{class:"user-message-text",innerHTML:M(e[0].content)},null,8,D)]),t.createElementVNode("div",Q,[t.createElementVNode("div",I,[n[7]||(n[7]=t.createTextVNode(" 答: ",-1)),t.unref(l)&&o===t.unref(a).length-1?(t.openBlock(),t.createElementBlock("span",L)):t.createCommentVNode("",!0),e[1].stopMessage?(t.openBlock(),t.createElementBlock("span",O,"此问题用户停止咨询")):t.createCommentVNode("",!0)]),t.createElementVNode("div",{class:"message-text",innerHTML:M(e[1].content)},null,8,R)])]))),128))],2)):t.createCommentVNode("",!0),"lsyy"===e.config.knowledgeCode?(t.openBlock(),t.createElementBlock("div",N,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(f.value,(e,n)=>(t.openBlock(),t.createElementBlock("button",{class:"tag-btn",onClick:t=>{return n=e,s.value=n,i(),void A();var n},key:n},t.toDisplayString(e),9,P))),128))])):t.createCommentVNode("",!0),t.createElementVNode("div",F,[t.createElementVNode("div",U,[t.withDirectives(t.createElementVNode("input",{"onUpdate:modelValue":n[1]||(n[1]=e=>t.isRef(s)?s.value=e:null),onKeyup:n[2]||(n[2]=t.withKeys((...e)=>t.unref(i)&&t.unref(i)(...e),["enter"])),placeholder:"请输入想要咨询的问题",disabled:t.unref(l),class:"message-input"},null,40,V),[[t.vModelText,t.unref(s)]]),t.unref(l)?t.createCommentVNode("",!0):(t.openBlock(),t.createElementBlock("button",{key:0,onClick:n[3]||(n[3]=(...e)=>t.unref(i)&&t.unref(i)(...e)),disabled:!t.unref(s).trim(),class:"send-button"},n[8]||(n[8]=[t.createElementVNode("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none"},[t.createElementVNode("path",{d:"M2 21L23 12L2 3V10L17 12L2 14V21Z",fill:"currentColor"})],-1)]),8,G)),t.unref(l)?(t.openBlock(),t.createElementBlock("button",{key:1,onClick:n[4]||(n[4]=(...e)=>t.unref(c)&&t.unref(c)(...e)),class:"stop-button"},n[9]||(n[9]=[t.createElementVNode("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none"},[t.createElementVNode("rect",{x:"6",y:"6",width:"12",height:"12",fill:"currentColor"})],-1)]))):t.createCommentVNode("",!0)])])]))}}),[["__scopeId","data-v-1eb006ae"]]);var j,H,J,K={exports:{}};
/** @license
* eventsource.js
* Available under MIT License (MIT)
* https://github.com/Yaffle/EventSource/
*/const W=p({__proto__:null},[(j||(j=1,H=K,J=K.exports,function(e){var t=e.setTimeout,n=e.clearTimeout,o=e.XMLHttpRequest,r=e.XDomainRequest,a=e.ActiveXObject,s=e.EventSource,l=e.document,i=e.Promise,c=e.fetch,d=e.Response,u=e.TextDecoder,h=e.TextEncoder,p=e.AbortController;if("undefined"==typeof window||void 0===l||"readyState"in l||null!=l.body||(l.readyState="loading",window.addEventListener("load",function(e){l.readyState="complete"},!1)),null==o&&null!=a&&(o=function(){return new a("Microsoft.XMLHTTP")}),null==Object.create&&(Object.create=function(e){function t(){}return t.prototype=e,new t}),Date.now||(Date.now=function(){return(new Date).getTime()}),null==p){var f=c;c=function(e,t){var n=t.signal;return f(e,{headers:t.headers,credentials:t.credentials,cache:t.cache}).then(function(e){var t=e.body.getReader();return n._reader=t,n._aborted&&n._reader.cancel(),{status:e.status,statusText:e.statusText,headers:e.headers,body:{getReader:function(){return t}}}})},p=function(){this.signal={_reader:null,_aborted:!1},this.abort=function(){null!=this.signal._reader&&this.signal._reader.cancel(),this.signal._aborted=!0}}}function A(){this.bitsNeeded=0,this.codePoint=0}A.prototype.decode=function(e){function t(e,t,n){if(1===n)return e>=128>>t&&e<<t<=2047;if(2===n)return e>=2048>>t&&e<<t<=55295||e>=57344>>t&&e<<t<=65535;if(3===n)return e>=65536>>t&&e<<t<=1114111;throw new Error}function n(e,t){if(6===e)return t>>6>15?3:t>31?2:1;if(12===e)return t>15?3:2;if(18===e)return 3;throw new Error}for(var o=65533,r="",a=this.bitsNeeded,s=this.codePoint,l=0;l<e.length;l+=1){var i=e[l];0!==a&&(i<128||i>191||!t(s<<6|63&i,a-6,n(a,s)))&&(a=0,s=o,r+=String.fromCharCode(s)),0===a?(i>=0&&i<=127?(a=0,s=i):i>=192&&i<=223?(a=6,s=31&i):i>=224&&i<=239?(a=12,s=15&i):i>=240&&i<=247?(a=18,s=7&i):(a=0,s=o),0===a||t(s,a,n(a,s))||(a=0,s=o)):(a-=6,s=s<<6|63&i),0===a&&(s<=65535?r+=String.fromCharCode(s):(r+=String.fromCharCode(55296+(s-65535-1>>10)),r+=String.fromCharCode(56320+(s-65535-1&1023))))}return this.bitsNeeded=a,this.codePoint=s,r},null!=u&&null!=h&&function(){try{return"test"===(new u).decode((new h).encode("test"),{stream:!0})}catch(e){console.debug("TextDecoder does not support streaming option. Using polyfill instead: "+e)}return!1}()||(u=A);var g=function(){};function v(e){this.withCredentials=!1,this.readyState=0,this.status=0,this.statusText="",this.responseText="",this.onprogress=g,this.onload=g,this.onerror=g,this.onreadystatechange=g,this._contentType="",this._xhr=e,this._sendTimeout=0,this._abort=g}function y(e){return e.replace(/[A-Z]/g,function(e){return String.fromCharCode(e.charCodeAt(0)+32)})}function w(e){for(var t=Object.create(null),n=e.split("\r\n"),o=0;o<n.length;o+=1){var r=n[o].split(": "),a=r.shift(),s=r.join(": ");t[y(a)]=s}this._map=t}function E(){}function C(e){this._headers=e}function m(){}function b(){this._listeners=Object.create(null)}function B(e){t(function(){throw e},0)}function S(e){this.type=e,this.target=void 0}function k(e,t){S.call(this,e),this.data=t.data,this.lastEventId=t.lastEventId}function x(e,t){S.call(this,e),this.status=t.status,this.statusText=t.statusText,this.headers=t.headers}function T(e,t){S.call(this,e),this.error=t.error}v.prototype.open=function(e,r){this._abort(!0);var a=this,s=this._xhr,l=1,i=0;this._abort=function(e){0!==a._sendTimeout&&(n(a._sendTimeout),a._sendTimeout=0),1!==l&&2!==l&&3!==l||(l=4,s.onload=g,s.onerror=g,s.onabort=g,s.onprogress=g,s.onreadystatechange=g,s.abort(),0!==i&&(n(i),i=0),e||(a.readyState=4,a.onabort(null),a.onreadystatechange())),l=0};var c=function(){if(1===l){var e=0,t="",n=void 0;if("contentType"in s)e=200,t="OK",n=s.contentType;else try{e=s.status,t=s.statusText,n=s.getResponseHeader("Content-Type")}catch(o){e=0,t="",n=void 0}0!==e&&(l=2,a.readyState=2,a.status=e,a.statusText=t,a._contentType=n,a.onreadystatechange())}},d=function(){if(c(),2===l||3===l){l=3;var e="";try{e=s.responseText}catch(t){}a.readyState=3,a.responseText=e,a.onprogress()}},u=function(e,t){if(null!=t&&null!=t.preventDefault||(t={preventDefault:g}),d(),1===l||2===l||3===l){if(l=4,0!==i&&(n(i),i=0),a.readyState=4,"load"===e)a.onload(t);else if("error"===e)a.onerror(t);else{if("abort"!==e)throw new TypeError;a.onabort(t)}a.onreadystatechange()}},h=function(){i=t(function(){h()},500),3===s.readyState&&d()};"onload"in s&&(s.onload=function(e){u("load",e)}),"onerror"in s&&(s.onerror=function(e){u("error",e)}),"onabort"in s&&(s.onabort=function(e){u("abort",e)}),"onprogress"in s&&(s.onprogress=d),"onreadystatechange"in s&&(s.onreadystatechange=function(e){!function(e){null!=s&&(4===s.readyState?"onload"in s&&"onerror"in s&&"onabort"in s||u(""===s.responseText?"error":"load",e):3===s.readyState?"onprogress"in s||d():2===s.readyState&&c())}(e)}),!("contentType"in s)&&"ontimeout"in o.prototype||(r+=(-1===r.indexOf("?")?"?":"&")+"padding=true"),s.open(e,r,!0),"readyState"in s&&(i=t(function(){h()},0))},v.prototype.abort=function(){this._abort(!1)},v.prototype.getResponseHeader=function(e){return this._contentType},v.prototype.setRequestHeader=function(e,t){var n=this._xhr;"setRequestHeader"in n&&n.setRequestHeader(e,t)},v.prototype.getAllResponseHeaders=function(){return null!=this._xhr.getAllResponseHeaders&&this._xhr.getAllResponseHeaders()||""},v.prototype.send=function(){if("ontimeout"in o.prototype&&("sendAsBinary"in o.prototype||"mozAnon"in o.prototype)||null==l||null==l.readyState||"complete"===l.readyState){var e=this._xhr;"withCredentials"in e&&(e.withCredentials=this.withCredentials);try{e.send(void 0)}catch(r){throw r}}else{var n=this;n._sendTimeout=t(function(){n._sendTimeout=0,n.send()},4)}},w.prototype.get=function(e){return this._map[y(e)]},null!=o&&null==o.HEADERS_RECEIVED&&(o.HEADERS_RECEIVED=2),E.prototype.open=function(e,t,n,r,a,s,l){e.open("GET",a);var i=0;for(var c in e.onprogress=function(){var t=e.responseText.slice(i);i+=t.length,n(t)},e.onerror=function(e){e.preventDefault(),r(new Error("NetworkError"))},e.onload=function(){r(null)},e.onabort=function(){r(null)},e.onreadystatechange=function(){if(e.readyState===o.HEADERS_RECEIVED){var n=e.status,r=e.statusText,a=e.getResponseHeader("Content-Type"),s=e.getAllResponseHeaders();t(n,r,a,new w(s))}},e.withCredentials=s,l)Object.prototype.hasOwnProperty.call(l,c)&&e.setRequestHeader(c,l[c]);return e.send(),e},C.prototype.get=function(e){return this._headers.get(e)},m.prototype.open=function(e,t,n,o,r,a,s){var l=null,d=new p,h=d.signal,f=new u;return c(r,{headers:s,credentials:a?"include":"same-origin",signal:h,cache:"no-store"}).then(function(e){return l=e.body.getReader(),t(e.status,e.statusText,e.headers.get("Content-Type"),new C(e.headers)),new i(function(e,t){var o=function(){l.read().then(function(t){if(t.done)e(void 0);else{var r=f.decode(t.value,{stream:!0});n(r),o()}}).catch(function(e){t(e)})};o()})}).catch(function(e){return"AbortError"===e.name?void 0:e}).then(function(e){o(e)}),{abort:function(){null!=l&&l.cancel(),d.abort()}}},b.prototype.dispatchEvent=function(e){e.target=this;var t=this._listeners[e.type];if(null!=t)for(var n=t.length,o=0;o<n;o+=1){var r=t[o];try{"function"==typeof r.handleEvent?r.handleEvent(e):r.call(this,e)}catch(a){B(a)}}},b.prototype.addEventListener=function(e,t){e=String(e);var n=this._listeners,o=n[e];null==o&&(o=[],n[e]=o);for(var r=!1,a=0;a<o.length;a+=1)o[a]===t&&(r=!0);r||o.push(t)},b.prototype.removeEventListener=function(e,t){e=String(e);var n=this._listeners,o=n[e];if(null!=o){for(var r=[],a=0;a<o.length;a+=1)o[a]!==t&&r.push(o[a]);0===r.length?delete n[e]:n[e]=r}},k.prototype=Object.create(S.prototype),x.prototype=Object.create(S.prototype),T.prototype=Object.create(S.prototype);var D=-1,Q=-1,I=/^text\/event\-stream(;.*)?$/i,L=function(e,t){var n=null==e?t:parseInt(e,10);return n!=n&&(n=t),O(n)},O=function(e){return Math.min(Math.max(e,1e3),18e6)},R=function(e,t,n){try{"function"==typeof t&&t.call(e,n)}catch(o){B(o)}};function N(e,a){b.call(this),a=a||{},this.onopen=void 0,this.onmessage=void 0,this.onerror=void 0,this.url=void 0,this.readyState=void 0,this.withCredentials=void 0,this.headers=void 0,this._close=void 0,function(e,a,s){a=String(a);var l=Boolean(s.withCredentials),i=s.lastEventIdQueryParameterName||"lastEventId",c=O(1e3),d=L(s.heartbeatTimeout,45e3),u="",h=c,p=!1,f=0,A=s.headers||{},g=s.Transport,y=P&&null==g?void 0:new v(null!=g?new g:null!=o&&"withCredentials"in o.prototype||null==r?new o:new r),w=null!=g&&"string"!=typeof g?new g:null==y?new m:new E,C=void 0,b=0,B=D,S="",N="",F="",U="",V=0,G=0,M=0,j=function(t,n,o,r){if(0===B)if(200===t&&null!=o&&I.test(o)){B=1,p=Date.now(),h=c,e.readyState=1;var a=new x("open",{status:t,statusText:n,headers:r});e.dispatchEvent(a),R(e,e.onopen,a)}else{var s="";200!==t?(n&&(n=n.replace(/\s+/g," ")),s="EventSource's response has a status "+t+" "+n+" that is not 200. Aborting the connection."):s="EventSource's response has a Content-Type specifying an unsupported type: "+(null==o?"-":o.replace(/\s+/g," "))+". Aborting the connection.",K(),a=new x("error",{status:t,statusText:n,headers:r}),e.dispatchEvent(a),R(e,e.onerror,a),console.error(s)}},H=function(o){if(1===B){for(var r=-1,a=0;a<o.length;a+=1)(i=o.charCodeAt(a))!=="\n".charCodeAt(0)&&i!=="\r".charCodeAt(0)||(r=a);var s=(-1!==r?U:"")+o.slice(0,r+1);U=(-1===r?U:"")+o.slice(r+1),""!==o&&(p=Date.now(),f+=o.length);for(var l=0;l<s.length;l+=1){var i=s.charCodeAt(l);if(V===Q&&i==="\n".charCodeAt(0))V=0;else if(V===Q&&(V=0),i==="\r".charCodeAt(0)||i==="\n".charCodeAt(0)){if(0!==V){1===V&&(M=l+1);var A=s.slice(G,M-1),g=s.slice(M+(M<l&&s.charCodeAt(M)===" ".charCodeAt(0)?1:0),l);"data"===A?(S+="\n",S+=g):"id"===A?N=g:"event"===A?F=g:"retry"===A?(c=L(g,c),h=c):"heartbeatTimeout"===A&&(d=L(g,d),0!==b&&(n(b),b=t(function(){W()},d)))}if(0===V){if(""!==S){u=N,""===F&&(F="message");var v=new k(F,{data:S.slice(1),lastEventId:N});if(e.dispatchEvent(v),"open"===F?R(e,e.onopen,v):"message"===F?R(e,e.onmessage,v):"error"===F&&R(e,e.onerror,v),2===B)return}S="",F=""}V=i==="\r".charCodeAt(0)?Q:0}else 0===V&&(G=l,V=1),1===V?i===":".charCodeAt(0)&&(M=l+1,V=2):2===V&&(V=3)}}},J=function(o){if(1===B||0===B){B=D,0!==b&&(n(b),b=0),b=t(function(){W()},h),h=O(Math.min(16*c,2*h)),e.readyState=0;var r=new T("error",{error:o});e.dispatchEvent(r),R(e,e.onerror,r),null!=o&&console.error(o)}},K=function(){B=2,null!=C&&(C.abort(),C=void 0),0!==b&&(n(b),b=0),e.readyState=2},W=function(){if(b=0,B===D){p=!1,f=0,b=t(function(){W()},d),B=0,S="",F="",N=u,U="",G=0,M=0,V=0;var n=a;if("data:"!==a.slice(0,5)&&"blob:"!==a.slice(0,5)&&""!==u){var o=a.indexOf("?");n=-1===o?a:a.slice(0,o+1)+a.slice(o+1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g,function(e,t){return t===i?"":e}),n+=(-1===a.indexOf("?")?"?":"&")+i+"="+encodeURIComponent(u)}var r=e.withCredentials,s={Accept:"text/event-stream"},l=e.headers;if(null!=l)for(var c in l)Object.prototype.hasOwnProperty.call(l,c)&&(s[c]=l[c]);try{C=w.open(y,j,H,J,n,r,s)}catch(A){throw K(),A}}else if(p||null==C){var h=Math.max((p||Date.now())+d-Date.now(),1);p=!1,b=t(function(){W()},h)}else J(new Error("No activity within "+d+" milliseconds. "+(0===B?"No response received.":f+" chars received.")+" Reconnecting.")),null!=C&&(C.abort(),C=void 0)};e.url=a,e.readyState=0,e.withCredentials=l,e.headers=A,e._close=K,W()}(this,e,a)}var P=null!=c&&null!=d&&"body"in d.prototype;N.prototype=Object.create(b.prototype),N.prototype.CONNECTING=0,N.prototype.OPEN=1,N.prototype.CLOSED=2,N.prototype.close=function(){this._close()},N.CONNECTING=0,N.OPEN=1,N.CLOSED=2,N.prototype.withCredentials=void 0;var F,U,V=s;null==o||null!=s&&"withCredentials"in s.prototype||(V=N),(F=J).EventSourcePolyfill=N,F.NativeEventSource=s,void 0!==(U=void(F.EventSource=V))&&(H.exports=U)}("undefined"==typeof globalThis?"undefined"!=typeof window?window:"undefined"!=typeof self?self:K.exports:globalThis)),K.exports)]);e.AIService=f,e.AiChat=M,e.default=M,e.useAiChat=g,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});