orbitchat 2.8.0 → 2.8.1
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.
- package/dist/assets/{_baseUniq-BPMphbq5-DO5_HCHQ.js → _baseUniq-BPMphbq5-BiznSq9-.js} +1 -1
- package/dist/assets/{api-XcRutblh.js → api-CPJLWxrl.js} +1 -1
- package/dist/assets/{arc-D9rhTKV0-HEIOSimk.js → arc-D9rhTKV0-Dj0KXN17.js} +1 -1
- package/dist/assets/{architectureDiagram-VXUJARFQ-BiqZtsDe-CnT4FtKS.js → architectureDiagram-VXUJARFQ-BiqZtsDe-coVQhEcP.js} +1 -1
- package/dist/assets/{blockDiagram-VD42YOAC-zcRIdFTD-CWkTK5LM.js → blockDiagram-VD42YOAC-zcRIdFTD-BrtL2H_x.js} +1 -1
- package/dist/assets/{c4Diagram-YG6GDRKO-DYXNcDX4-O-nw7plh.js → c4Diagram-YG6GDRKO-DYXNcDX4-DCV5_cMO.js} +1 -1
- package/dist/assets/channel-CUIutAfm-B1Fq6En-.js +1 -0
- package/dist/assets/{chunk-4BX2VUAB-DAh9ktmY-CPh1uj0r.js → chunk-4BX2VUAB-DAh9ktmY-COu2acrd.js} +1 -1
- package/dist/assets/{chunk-55IACEB6-Cza7pcpr-Dt3g8XPZ.js → chunk-55IACEB6-Cza7pcpr-BYg_H-pj.js} +1 -1
- package/dist/assets/{chunk-B4BG7PRW-BTUSpeKy-CjtIH_eO.js → chunk-B4BG7PRW-BTUSpeKy-DJFUm1ej.js} +1 -1
- package/dist/assets/{chunk-DI55MBZ5-DKt4WII7-DmBDPeCL.js → chunk-DI55MBZ5-DKt4WII7-Ck6rw8E1.js} +1 -1
- package/dist/assets/{chunk-FMBD7UC4-DdcCR8w3-Oit_Oj0C.js → chunk-FMBD7UC4-DdcCR8w3-C-08bMxn.js} +1 -1
- package/dist/assets/{chunk-QN33PNHL-v6AkzOl1-KLAZml1W.js → chunk-QN33PNHL-v6AkzOl1-CBUKkb4b.js} +1 -1
- package/dist/assets/{chunk-QZHKN3VN-DVJOrqBZ-GIMCvbeq.js → chunk-QZHKN3VN-DVJOrqBZ-D5HiI4oh.js} +1 -1
- package/dist/assets/{chunk-TZMSLE5B-G2jJHqli-C_qBMUID.js → chunk-TZMSLE5B-G2jJHqli-CEpPlBms.js} +1 -1
- package/dist/assets/{classDiagram-2ON5EDUG-CxmgTanh-CA3Ppuao.js → classDiagram-2ON5EDUG-CxmgTanh-jsILqBHT.js} +1 -1
- package/dist/assets/{classDiagram-v2-WZHVMYZB-CxmgTanh-CA3Ppuao.js → classDiagram-v2-WZHVMYZB-CxmgTanh-jsILqBHT.js} +1 -1
- package/dist/assets/clone-CsNB4mMi-BHOrfYT5.js +1 -0
- package/dist/assets/{cose-bilkent-S5V4N54A-BRr2Y6dg-vCdUVgOY.js → cose-bilkent-S5V4N54A-BRr2Y6dg-BHOEDqnM.js} +1 -1
- package/dist/assets/{dagre-6UL2VRFP-DX8gNHmJ-BYoXuRvj.js → dagre-6UL2VRFP-DX8gNHmJ-CYh5hSEy.js} +1 -1
- package/dist/assets/{diagram-PSM6KHXK-DNX818To-F-_geMhJ.js → diagram-PSM6KHXK-DNX818To-DP7laJPI.js} +1 -1
- package/dist/assets/{diagram-QEK2KX5R-BDO6hKtm-B4RtdGfy.js → diagram-QEK2KX5R-BDO6hKtm-HtTknE56.js} +1 -1
- package/dist/assets/{diagram-S2PKOQOG-IEqaDwzi-B2HWFQ34.js → diagram-S2PKOQOG-IEqaDwzi-DX1MwhnG.js} +1 -1
- package/dist/assets/{erDiagram-Q2GNP2WA-DbLpN8Jp-QZ04AM6K.js → erDiagram-Q2GNP2WA-DbLpN8Jp-Blrgdh0d.js} +1 -1
- package/dist/assets/{flowDiagram-NV44I4VS-pJlHae8Y-CAIm3OCI.js → flowDiagram-NV44I4VS-pJlHae8Y-ZcX989NH.js} +1 -1
- package/dist/assets/{ganttDiagram-JELNMOA3-J0Tkq5TR-DHqa9s8V.js → ganttDiagram-JELNMOA3-J0Tkq5TR-p2P2DGG6.js} +1 -1
- package/dist/assets/{gitGraphDiagram-NY62KEGX-DgYonpsZ-j8MsbrTT.js → gitGraphDiagram-NY62KEGX-DgYonpsZ-DEEHTytg.js} +1 -1
- package/dist/assets/{graph-BpcfrHXY-CHWas41L.js → graph-BpcfrHXY-Gx5COHCO.js} +1 -1
- package/dist/assets/{index-B_3LyfJh.js → index-9ccjMpVY.js} +7 -7
- package/dist/assets/index-D85BTrbv.css +1 -0
- package/dist/assets/{index-DvNpGWs7-B1MZ_xW9.js → index-DvNpGWs7-BlvgI6Oj.js} +1 -1
- package/dist/assets/{infoDiagram-WHAUD3N6-C3JLOAnb-6y-bwNyN.js → infoDiagram-WHAUD3N6-C3JLOAnb-CPXB0Iei.js} +1 -1
- package/dist/assets/{journeyDiagram-XKPGCS4Q-CfjB2Qdf-Cr6xcm9B.js → journeyDiagram-XKPGCS4Q-CfjB2Qdf-Do-Pa_c0.js} +1 -1
- package/dist/assets/{kanban-definition-3W4ZIXB7-CrW8yVmd-CigsAnxH.js → kanban-definition-3W4ZIXB7-CrW8yVmd-SNTX2wCT.js} +1 -1
- package/dist/assets/{layout-bsfAhWjc-CVQ5BnoY.js → layout-bsfAhWjc-CfFDklfA.js} +1 -1
- package/dist/assets/{min-C2aDz5ZK-DS_pl9iJ.js → min-C2aDz5ZK-CNgPDPau.js} +1 -1
- package/dist/assets/{mindmap-definition-VGOIOE7T-Dj37RkY_-gsIYQSNC.js → mindmap-definition-VGOIOE7T-Dj37RkY_-BzuvOjfA.js} +1 -1
- package/dist/assets/{pieDiagram-ADFJNKIX-BiQvDx8I-BT5l2ngl.js → pieDiagram-ADFJNKIX-BiQvDx8I-BAT3faFm.js} +1 -1
- package/dist/assets/{quadrantDiagram-AYHSOK5B-D4b-YFzI-D4aUN4bx.js → quadrantDiagram-AYHSOK5B-D4b-YFzI-ByBf_iEO.js} +1 -1
- package/dist/assets/{requirementDiagram-UZGBJVZJ-km07nlVd-DT-CJzQX.js → requirementDiagram-UZGBJVZJ-km07nlVd-DyCQ9b-2.js} +1 -1
- package/dist/assets/{sankeyDiagram-TZEHDZUN-LfuSRRbf-DinJlA-H.js → sankeyDiagram-TZEHDZUN-LfuSRRbf-B4gBy7rf.js} +1 -1
- package/dist/assets/{sequenceDiagram-WL72ISMW-CQ4J-0_7-BYA8hV94.js → sequenceDiagram-WL72ISMW-CQ4J-0_7-BG0F1yw0.js} +1 -1
- package/dist/assets/{stateDiagram-FKZM4ZOC-JtogJwt6-SGbwMgjL.js → stateDiagram-FKZM4ZOC-JtogJwt6-Ds546Riv.js} +1 -1
- package/dist/assets/{stateDiagram-v2-4FDKWEC3-DuQ7UaeU-DfYMYAyn.js → stateDiagram-v2-4FDKWEC3-DuQ7UaeU-C44zln-C.js} +1 -1
- package/dist/assets/{timeline-definition-IT6M3QCI-Cs3NnF2M-D2VN2LFT.js → timeline-definition-IT6M3QCI-Cs3NnF2M-Dsc7nQem.js} +1 -1
- package/dist/assets/{treemap-KMMF4GRG-CkW25-tn-Bo-KASxu.js → treemap-KMMF4GRG-CkW25-tn-DmpkvHUc.js} +1 -1
- package/dist/assets/{xychartDiagram-PRI3JC2R-JzAaXa5z-DOprIJGo.js → xychartDiagram-PRI3JC2R-JzAaXa5z-DMsk4lld.js} +1 -1
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/dist/assets/channel-CUIutAfm-BvRSnmLW.js +0 -1
- package/dist/assets/clone-CsNB4mMi-BdS88cK4.js +0 -1
- package/dist/assets/index-DrvvX7NL.css +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dagre-6UL2VRFP-DX8gNHmJ-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dagre-6UL2VRFP-DX8gNHmJ-CYh5hSEy.js","assets/graph-BpcfrHXY-Gx5COHCO.js","assets/_baseUniq-BPMphbq5-BiznSq9-.js","assets/layout-bsfAhWjc-CfFDklfA.js","assets/min-C2aDz5ZK-CNgPDPau.js","assets/clone-CsNB4mMi-BHOrfYT5.js","assets/cose-bilkent-S5V4N54A-BRr2Y6dg-BHOEDqnM.js","assets/cytoscape.esm-CjI2IsL8-Da6dFVsf.js","assets/c4Diagram-YG6GDRKO-DYXNcDX4-DCV5_cMO.js","assets/chunk-TZMSLE5B-G2jJHqli-CEpPlBms.js","assets/flowDiagram-NV44I4VS-pJlHae8Y-ZcX989NH.js","assets/chunk-FMBD7UC4-DdcCR8w3-C-08bMxn.js","assets/chunk-55IACEB6-Cza7pcpr-BYg_H-pj.js","assets/chunk-QN33PNHL-v6AkzOl1-CBUKkb4b.js","assets/channel-CUIutAfm-B1Fq6En-.js","assets/erDiagram-Q2GNP2WA-DbLpN8Jp-Blrgdh0d.js","assets/gitGraphDiagram-NY62KEGX-DgYonpsZ-DEEHTytg.js","assets/chunk-4BX2VUAB-DAh9ktmY-COu2acrd.js","assets/chunk-QZHKN3VN-DVJOrqBZ-D5HiI4oh.js","assets/treemap-KMMF4GRG-CkW25-tn-DmpkvHUc.js","assets/infoDiagram-WHAUD3N6-C3JLOAnb-CPXB0Iei.js","assets/pieDiagram-ADFJNKIX-BiQvDx8I-BAT3faFm.js","assets/arc-D9rhTKV0-Dj0KXN17.js","assets/requirementDiagram-UZGBJVZJ-km07nlVd-DyCQ9b-2.js","assets/sequenceDiagram-WL72ISMW-CQ4J-0_7-BG0F1yw0.js","assets/classDiagram-2ON5EDUG-CxmgTanh-jsILqBHT.js","assets/chunk-B4BG7PRW-BTUSpeKy-DJFUm1ej.js","assets/classDiagram-v2-WZHVMYZB-CxmgTanh-jsILqBHT.js","assets/stateDiagram-FKZM4ZOC-JtogJwt6-Ds546Riv.js","assets/chunk-DI55MBZ5-DKt4WII7-Ck6rw8E1.js","assets/stateDiagram-v2-4FDKWEC3-DuQ7UaeU-C44zln-C.js","assets/journeyDiagram-XKPGCS4Q-CfjB2Qdf-Do-Pa_c0.js","assets/timeline-definition-IT6M3QCI-Cs3NnF2M-Dsc7nQem.js","assets/mindmap-definition-VGOIOE7T-Dj37RkY_-BzuvOjfA.js","assets/kanban-definition-3W4ZIXB7-CrW8yVmd-SNTX2wCT.js","assets/diagram-S2PKOQOG-IEqaDwzi-DX1MwhnG.js","assets/diagram-QEK2KX5R-BDO6hKtm-HtTknE56.js","assets/blockDiagram-VD42YOAC-zcRIdFTD-BrtL2H_x.js","assets/architectureDiagram-VXUJARFQ-BiqZtsDe-coVQhEcP.js","assets/diagram-PSM6KHXK-DNX818To-DP7laJPI.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
var rse=Object.defineProperty;var nse=(e,t,r)=>t in e?rse(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var wA=(e,t,r)=>nse(e,typeof t!="symbol"?t+"":t,r);(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const A of document.querySelectorAll('link[rel="modulepreload"]'))n(A);new MutationObserver(A=>{for(const i of A)if(i.type==="childList")for(const a of i.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&n(a)}).observe(document,{childList:!0,subtree:!0});function r(A){const i={};return A.integrity&&(i.integrity=A.integrity),A.referrerPolicy&&(i.referrerPolicy=A.referrerPolicy),A.crossOrigin==="use-credentials"?i.credentials="include":A.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function n(A){if(A.ep)return;A.ep=!0;const i=r(A);fetch(A.href,i)}})();function Ase(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var SV={exports:{}},Gf={},UV={exports:{}},Ct={};/**
|
|
3
3
|
* @license React
|
|
4
4
|
* react.production.min.js
|
|
@@ -827,8 +827,8 @@ Please report this to https://github.com/markedjs/marked.`,e){let n="<p>An error
|
|
|
827
827
|
node : x:${e.x} y:${e.y} w:${e.width} h:${e.height}`);const n=e.x,A=e.y,i=Math.abs(n-r.x),a=e.width/2;let s=r.x<t.x?a-i:a+i;const o=e.height/2,l=Math.abs(t.y-r.y),c=Math.abs(t.x-r.x);if(Math.abs(A-t.y)*a>Math.abs(n-t.x)*o){let u=r.y<t.y?t.y-o-A:A-o-t.y;s=c*u/l;const g={x:r.x<t.x?r.x+s:r.x-c+s,y:r.y<t.y?r.y+l-u:r.y-l+u};return s===0&&(g.x=t.x,g.y=t.y),c===0&&(g.x=t.x),l===0&&(g.y=t.y),ue.debug(`abc89 top/bottom calc, Q ${l}, q ${u}, R ${c}, r ${s}`,g),g}else{r.x<t.x?s=t.x-a-n:s=n-a-t.x;let u=l*s/c,g=r.x<t.x?r.x+c-s:r.x-c+s,d=r.y<t.y?r.y+u:r.y-u;return ue.debug(`sides calc abc89, Q ${l}, q ${u}, R ${c}, r ${s}`,{_x:g,_y:d}),s===0&&(g=t.x,d=t.y),c===0&&(g=t.x),l===0&&(d=t.y),{x:g,y:d}}},"intersection"),kO=F((e,t)=>{ue.warn("abc88 cutPathAtIntersect",e,t);let r=[],n=e[0],A=!1;return e.forEach(i=>{if(ue.info("abc88 checking point",i,t),!zje(t,i)&&!A){const a=Tje(t,n,i);ue.debug("abc88 inside",i,n,a),ue.debug("abc88 intersection",a,t);let s=!1;r.forEach(o=>{s=s||o.x===a.x&&o.y===a.y}),r.some(o=>o.x===a.x&&o.y===a.y)?ue.warn("abc88 no intersect",a,r):r.push(a),A=!0}else ue.warn("abc88 outside",i,n),n=i,A||r.push(i)}),ue.debug("returning points",r),r},"cutPathAtIntersect");function Ute(e){const t=[],r=[];for(let n=1;n<e.length-1;n++){const A=e[n-1],i=e[n],a=e[n+1];(A.x===i.x&&i.y===a.y&&Math.abs(i.x-a.x)>5&&Math.abs(i.y-A.y)>5||A.y===i.y&&i.x===a.x&&Math.abs(i.x-A.x)>5&&Math.abs(i.y-a.y)>5)&&(t.push(i),r.push(n))}return{cornerPoints:t,cornerPointPositions:r}}F(Ute,"extractCornerPoints");var SO=F(function(e,t,r){const n=t.x-e.x,A=t.y-e.y,i=Math.sqrt(n*n+A*A),a=r/i;return{x:t.x-a*n,y:t.y-a*A}},"findAdjacentPoint"),Lje=F(function(e){const{cornerPointPositions:t}=Ute(e),r=[];for(let n=0;n<e.length;n++)if(t.includes(n)){const A=e[n-1],i=e[n+1],a=e[n],s=SO(A,a,5),o=SO(i,a,5),l=o.x-s.x,c=o.y-s.y;r.push(s);const u=Math.sqrt(2)*2;let g={x:a.x,y:a.y};if(Math.abs(i.x-A.x)>10&&Math.abs(i.y-A.y)>=10){ue.debug("Corner point fixing",Math.abs(i.x-A.x),Math.abs(i.y-A.y));const d=5;a.x===s.x?g={x:l<0?s.x-d+u:s.x+d-u,y:c<0?s.y-u:s.y+u}:g={x:l<0?s.x-u:s.x+u,y:c<0?s.y-d+u:s.y+d-u}}else ue.debug("Corner point skipping fixing",Math.abs(i.x-A.x),Math.abs(i.y-A.y));r.push(g,o)}else r.push(e[n]);return r},"fixCorners"),Hje=F((e,t,r)=>{const n=e-t-r,A=2,i=2,a=A+i,s=Math.floor(n/a),o=Array(s).fill(`${A} ${i}`).join(" ");return`0 ${t} ${o} ${r}`},"generateDashArray"),Jje=F(function(e,t,r,n,A,i,a,s=!1){var o;const{handDrawnSeed:l}=Wt();let c=t.points,u=!1;const g=A;var d=i;const B=[];for(const v in t.cssCompiledStyles)u$(v)||B.push(t.cssCompiledStyles[v]);ue.debug("UIO intersect check",t.points,d.x,g.x),d.intersect&&g.intersect&&!s&&(c=c.slice(1,t.points.length-1),c.unshift(g.intersect(c[0])),ue.debug("Last point UIO",t.start,"-->",t.end,c[c.length-1],d,d.intersect(c[c.length-1])),c.push(d.intersect(c[c.length-1])));const h=btoa(JSON.stringify(c));t.toCluster&&(ue.info("to cluster abc88",r.get(t.toCluster)),c=kO(t.points,r.get(t.toCluster).node),u=!0),t.fromCluster&&(ue.debug("from cluster abc88",r.get(t.fromCluster),JSON.stringify(c,null,2)),c=kO(c.reverse(),r.get(t.fromCluster).node).reverse(),u=!0);let f=c.filter(v=>!Number.isNaN(v.y));f=Lje(f);let w=xd;switch(w=Ul,t.curve){case"linear":w=Ul;break;case"basis":w=xd;break;case"cardinal":w=Eq;break;case"bumpX":w=DU;break;case"bumpY":w=kU;break;case"catmullRom":w=yq;break;case"monotoneX":w=jU;break;case"monotoneY":w=zU;break;case"natural":w=TU;break;case"step":w=LU;break;case"stepAfter":w=JU;break;case"stepBefore":w=HU;break;default:w=xd}const{x:p,y:m}=LUe(t),C=xU().x(p).y(m).curve(w);let E;switch(t.thickness){case"normal":E="edge-thickness-normal";break;case"thick":E="edge-thickness-thick";break;case"invisible":E="edge-thickness-invisible";break;default:E="edge-thickness-normal"}switch(t.pattern){case"solid":E+=" edge-pattern-solid";break;case"dotted":E+=" edge-pattern-dotted";break;case"dashed":E+=" edge-pattern-dashed";break;default:E+=" edge-pattern-solid"}let I,Q=t.curve==="rounded"?vte(Gte(f,t),5):C(f);const N=Array.isArray(t.style)?t.style:[t.style];let k=N.find(v=>v==null?void 0:v.startsWith("stroke:")),x=!1;if(t.look==="handDrawn"){const v=Oe.svg(e);Object.assign([],f);const L=v.path(Q,{roughness:.3,seed:l});E+=" transition",I=kt(L).select("path").attr("id",t.id).attr("class"," "+E+(t.classes?" "+t.classes:"")).attr("style",N?N.reduce((R,O)=>R+";"+O,""):"");let J=I.attr("d");I.attr("d",J),e.node().appendChild(I.node())}else{const v=B.join(";"),L=N?N.reduce((G,X)=>G+X+";",""):"";let J="";t.animate&&(J=" edge-animation-fast"),t.animation&&(J=" edge-animation-"+t.animation);const R=(v?v+";"+L+";":L)+";"+(N?N.reduce((G,X)=>G+";"+X,""):"");I=e.append("path").attr("d",Q).attr("id",t.id).attr("class"," "+E+(t.classes?" "+t.classes:"")+(J??"")).attr("style",R),k=(o=R.match(/stroke:([^;]+)/))==null?void 0:o[1],x=t.animate===!0||!!t.animation||v.includes("animation");const O=I.node(),U=typeof O.getTotalLength=="function"?O.getTotalLength():0,K=XJ[t.arrowTypeStart]||0,Ae=XJ[t.arrowTypeEnd]||0;if(t.look==="neo"&&!x){const G=`stroke-dasharray: ${t.pattern==="dotted"||t.pattern==="dashed"?Hje(U,K,Ae):`0 ${K} ${U-K-Ae} ${Ae}`}; stroke-dashoffset: 0;`;I.attr("style",G+I.attr("style"))}}I.attr("data-edge",!0),I.attr("data-et","edge"),I.attr("data-id",t.id),I.attr("data-points",h),t.showPoints&&f.forEach(v=>{e.append("circle").style("stroke","red").style("fill","red").attr("r",1).attr("cx",v.x).attr("cy",v.y)});let D="";(Wt().flowchart.arrowMarkerAbsolute||Wt().state.arrowMarkerAbsolute)&&(D=window.location.protocol+"//"+window.location.host+window.location.pathname+window.location.search,D=D.replace(/\(/g,"\\(").replace(/\)/g,"\\)")),ue.info("arrowTypeStart",t.arrowTypeStart),ue.info("arrowTypeEnd",t.arrowTypeEnd),vje(I,t,D,a,n,k);const z=Math.floor(c.length/2),H=c[z];zi.isLabelCoordinateInPath(H,I.attr("d"))||(u=!0);let T={};return u&&(T.updatedPath=c),T.originalPath=t.points,T},"insertEdge");function vte(e,t){if(e.length<2)return"";let r="";const n=e.length,A=1e-5;for(let i=0;i<n;i++){const a=e[i],s=e[i-1],o=e[i+1];if(i===0)r+=`M${a.x},${a.y}`;else if(i===n-1)r+=`L${a.x},${a.y}`;else{const l=a.x-s.x,c=a.y-s.y,u=o.x-a.x,g=o.y-a.y,d=Math.hypot(l,c),B=Math.hypot(u,g);if(d<A||B<A){r+=`L${a.x},${a.y}`;continue}const h=l/d,f=c/d,w=u/B,p=g/B,m=h*w+f*p,C=Math.max(-1,Math.min(1,m)),E=Math.acos(C);if(E<A||Math.abs(Math.PI-E)<A){r+=`L${a.x},${a.y}`;continue}const I=Math.min(t/Math.sin(E/2),d/2,B/2),Q=a.x-h*I,N=a.y-f*I,k=a.x+w*I,x=a.y+p*I;r+=`L${Q},${N}`,r+=`Q${a.x},${a.y} ${k},${x}`}}return r}F(vte,"generateRoundedPath");function Kx(e,t){if(!e||!t)return{angle:0,deltaX:0,deltaY:0};const r=t.x-e.x,n=t.y-e.y;return{angle:Math.atan2(n,r),deltaX:r,deltaY:n}}F(Kx,"calculateDeltaAndAngle");function Gte(e,t){const r=e.map(A=>({...A}));if(e.length>=2&&Tn[t.arrowTypeStart]){const A=Tn[t.arrowTypeStart],i=e[0],a=e[1],{angle:s}=Kx(i,a),o=A*Math.cos(s),l=A*Math.sin(s);r[0].x=i.x+o,r[0].y=i.y+l}const n=e.length;if(n>=2&&Tn[t.arrowTypeEnd]){const A=Tn[t.arrowTypeEnd],i=e[n-1],a=e[n-2],{angle:s}=Kx(a,i),o=A*Math.cos(s),l=A*Math.sin(s);r[n-1].x=i.x-o,r[n-1].y=i.y-l}return r}F(Gte,"applyMarkerOffsetsToPoints");var Oje=F((e,t,r,n)=>{t.forEach(A=>{aze[A](e,r,n)})},"insertMarkers"),Wje=F((e,t,r)=>{ue.trace("Making markers for ",r),e.append("defs").append("marker").attr("id",r+"_"+t+"-extensionStart").attr("class","marker extension "+t).attr("refX",18).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("path").attr("d","M 1,7 L18,13 V 1 Z"),e.append("defs").append("marker").attr("id",r+"_"+t+"-extensionEnd").attr("class","marker extension "+t).attr("refX",1).attr("refY",7).attr("markerWidth",20).attr("markerHeight",28).attr("orient","auto").append("path").attr("d","M 1,1 V 13 L18,7 Z")},"extension"),Pje=F((e,t,r)=>{e.append("defs").append("marker").attr("id",r+"_"+t+"-compositionStart").attr("class","marker composition "+t).attr("refX",18).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L1,7 L9,1 Z"),e.append("defs").append("marker").attr("id",r+"_"+t+"-compositionEnd").attr("class","marker composition "+t).attr("refX",1).attr("refY",7).attr("markerWidth",20).attr("markerHeight",28).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L1,7 L9,1 Z")},"composition"),Kje=F((e,t,r)=>{e.append("defs").append("marker").attr("id",r+"_"+t+"-aggregationStart").attr("class","marker aggregation "+t).attr("refX",18).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L1,7 L9,1 Z"),e.append("defs").append("marker").attr("id",r+"_"+t+"-aggregationEnd").attr("class","marker aggregation "+t).attr("refX",1).attr("refY",7).attr("markerWidth",20).attr("markerHeight",28).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L1,7 L9,1 Z")},"aggregation"),Vje=F((e,t,r)=>{e.append("defs").append("marker").attr("id",r+"_"+t+"-dependencyStart").attr("class","marker dependency "+t).attr("refX",6).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("path").attr("d","M 5,7 L9,13 L1,7 L9,1 Z"),e.append("defs").append("marker").attr("id",r+"_"+t+"-dependencyEnd").attr("class","marker dependency "+t).attr("refX",13).attr("refY",7).attr("markerWidth",20).attr("markerHeight",28).attr("orient","auto").append("path").attr("d","M 18,7 L9,13 L14,7 L9,1 Z")},"dependency"),Xje=F((e,t,r)=>{e.append("defs").append("marker").attr("id",r+"_"+t+"-lollipopStart").attr("class","marker lollipop "+t).attr("refX",13).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("circle").attr("stroke","black").attr("fill","transparent").attr("cx",7).attr("cy",7).attr("r",6),e.append("defs").append("marker").attr("id",r+"_"+t+"-lollipopEnd").attr("class","marker lollipop "+t).attr("refX",1).attr("refY",7).attr("markerWidth",190).attr("markerHeight",240).attr("orient","auto").append("circle").attr("stroke","black").attr("fill","transparent").attr("cx",7).attr("cy",7).attr("r",6)},"lollipop"),Zje=F((e,t,r)=>{e.append("marker").attr("id",r+"_"+t+"-pointEnd").attr("class","marker "+t).attr("viewBox","0 0 10 10").attr("refX",5).attr("refY",5).attr("markerUnits","userSpaceOnUse").attr("markerWidth",8).attr("markerHeight",8).attr("orient","auto").append("path").attr("d","M 0 0 L 10 5 L 0 10 z").attr("class","arrowMarkerPath").style("stroke-width",1).style("stroke-dasharray","1,0"),e.append("marker").attr("id",r+"_"+t+"-pointStart").attr("class","marker "+t).attr("viewBox","0 0 10 10").attr("refX",4.5).attr("refY",5).attr("markerUnits","userSpaceOnUse").attr("markerWidth",8).attr("markerHeight",8).attr("orient","auto").append("path").attr("d","M 0 5 L 10 10 L 10 0 z").attr("class","arrowMarkerPath").style("stroke-width",1).style("stroke-dasharray","1,0")},"point"),qje=F((e,t,r)=>{e.append("marker").attr("id",r+"_"+t+"-circleEnd").attr("class","marker "+t).attr("viewBox","0 0 10 10").attr("refX",11).attr("refY",5).attr("markerUnits","userSpaceOnUse").attr("markerWidth",11).attr("markerHeight",11).attr("orient","auto").append("circle").attr("cx","5").attr("cy","5").attr("r","5").attr("class","arrowMarkerPath").style("stroke-width",1).style("stroke-dasharray","1,0"),e.append("marker").attr("id",r+"_"+t+"-circleStart").attr("class","marker "+t).attr("viewBox","0 0 10 10").attr("refX",-1).attr("refY",5).attr("markerUnits","userSpaceOnUse").attr("markerWidth",11).attr("markerHeight",11).attr("orient","auto").append("circle").attr("cx","5").attr("cy","5").attr("r","5").attr("class","arrowMarkerPath").style("stroke-width",1).style("stroke-dasharray","1,0")},"circle"),_je=F((e,t,r)=>{e.append("marker").attr("id",r+"_"+t+"-crossEnd").attr("class","marker cross "+t).attr("viewBox","0 0 11 11").attr("refX",12).attr("refY",5.2).attr("markerUnits","userSpaceOnUse").attr("markerWidth",11).attr("markerHeight",11).attr("orient","auto").append("path").attr("d","M 1,1 l 9,9 M 10,1 l -9,9").attr("class","arrowMarkerPath").style("stroke-width",2).style("stroke-dasharray","1,0"),e.append("marker").attr("id",r+"_"+t+"-crossStart").attr("class","marker cross "+t).attr("viewBox","0 0 11 11").attr("refX",-1).attr("refY",5.2).attr("markerUnits","userSpaceOnUse").attr("markerWidth",11).attr("markerHeight",11).attr("orient","auto").append("path").attr("d","M 1,1 l 9,9 M 10,1 l -9,9").attr("class","arrowMarkerPath").style("stroke-width",2).style("stroke-dasharray","1,0")},"cross"),$je=F((e,t,r)=>{e.append("defs").append("marker").attr("id",r+"_"+t+"-barbEnd").attr("refX",19).attr("refY",7).attr("markerWidth",20).attr("markerHeight",14).attr("markerUnits","userSpaceOnUse").attr("orient","auto").append("path").attr("d","M 19,7 L9,13 L14,7 L9,1 Z")},"barb"),eze=F((e,t,r)=>{e.append("defs").append("marker").attr("id",r+"_"+t+"-onlyOneStart").attr("class","marker onlyOne "+t).attr("refX",0).attr("refY",9).attr("markerWidth",18).attr("markerHeight",18).attr("orient","auto").append("path").attr("d","M9,0 L9,18 M15,0 L15,18"),e.append("defs").append("marker").attr("id",r+"_"+t+"-onlyOneEnd").attr("class","marker onlyOne "+t).attr("refX",18).attr("refY",9).attr("markerWidth",18).attr("markerHeight",18).attr("orient","auto").append("path").attr("d","M3,0 L3,18 M9,0 L9,18")},"only_one"),tze=F((e,t,r)=>{const n=e.append("defs").append("marker").attr("id",r+"_"+t+"-zeroOrOneStart").attr("class","marker zeroOrOne "+t).attr("refX",0).attr("refY",9).attr("markerWidth",30).attr("markerHeight",18).attr("orient","auto");n.append("circle").attr("fill","white").attr("cx",21).attr("cy",9).attr("r",6),n.append("path").attr("d","M9,0 L9,18");const A=e.append("defs").append("marker").attr("id",r+"_"+t+"-zeroOrOneEnd").attr("class","marker zeroOrOne "+t).attr("refX",30).attr("refY",9).attr("markerWidth",30).attr("markerHeight",18).attr("orient","auto");A.append("circle").attr("fill","white").attr("cx",9).attr("cy",9).attr("r",6),A.append("path").attr("d","M21,0 L21,18")},"zero_or_one"),rze=F((e,t,r)=>{e.append("defs").append("marker").attr("id",r+"_"+t+"-oneOrMoreStart").attr("class","marker oneOrMore "+t).attr("refX",18).attr("refY",18).attr("markerWidth",45).attr("markerHeight",36).attr("orient","auto").append("path").attr("d","M0,18 Q 18,0 36,18 Q 18,36 0,18 M42,9 L42,27"),e.append("defs").append("marker").attr("id",r+"_"+t+"-oneOrMoreEnd").attr("class","marker oneOrMore "+t).attr("refX",27).attr("refY",18).attr("markerWidth",45).attr("markerHeight",36).attr("orient","auto").append("path").attr("d","M3,9 L3,27 M9,18 Q27,0 45,18 Q27,36 9,18")},"one_or_more"),nze=F((e,t,r)=>{const n=e.append("defs").append("marker").attr("id",r+"_"+t+"-zeroOrMoreStart").attr("class","marker zeroOrMore "+t).attr("refX",18).attr("refY",18).attr("markerWidth",57).attr("markerHeight",36).attr("orient","auto");n.append("circle").attr("fill","white").attr("cx",48).attr("cy",18).attr("r",6),n.append("path").attr("d","M0,18 Q18,0 36,18 Q18,36 0,18");const A=e.append("defs").append("marker").attr("id",r+"_"+t+"-zeroOrMoreEnd").attr("class","marker zeroOrMore "+t).attr("refX",39).attr("refY",18).attr("markerWidth",57).attr("markerHeight",36).attr("orient","auto");A.append("circle").attr("fill","white").attr("cx",9).attr("cy",18).attr("r",6),A.append("path").attr("d","M21,18 Q39,0 57,18 Q39,36 21,18")},"zero_or_more"),Aze=F((e,t,r)=>{e.append("defs").append("marker").attr("id",r+"_"+t+"-requirement_arrowEnd").attr("refX",20).attr("refY",10).attr("markerWidth",20).attr("markerHeight",20).attr("orient","auto").append("path").attr("d",`M0,0
|
|
828
828
|
L20,10
|
|
829
829
|
M20,10
|
|
830
|
-
L0,20`)},"requirement_arrow"),ize=F((e,t,r)=>{const n=e.append("defs").append("marker").attr("id",r+"_"+t+"-requirement_containsStart").attr("refX",0).attr("refY",10).attr("markerWidth",20).attr("markerHeight",20).attr("orient","auto").append("g");n.append("circle").attr("cx",10).attr("cy",10).attr("r",9).attr("fill","none"),n.append("line").attr("x1",1).attr("x2",19).attr("y1",10).attr("y2",10),n.append("line").attr("y1",1).attr("y2",19).attr("x1",10).attr("x2",10)},"requirement_contains"),aze={extension:Wje,composition:Pje,aggregation:Kje,dependency:Vje,lollipop:Xje,point:Zje,circle:qje,cross:_je,barb:$je,only_one:eze,zero_or_one:tze,one_or_more:rze,zero_or_more:nze,requirement_arrow:Aze,requirement_contains:ize},sze=Oje,oze={common:Hu,getConfig:Wn,insertCluster:pje,insertEdge:Jje,insertEdgeLabel:Rje,insertMarkers:sze,insertNode:Ste,interpolateToCurve:r2,labelHelper:tt,log:ue,positionEdgeLabel:jje},wh={},Rte=F(e=>{for(const t of e)wh[t.name]=t},"registerLayoutLoaders"),lze=F(()=>{Rte([{name:"dagre",loader:F(async()=>await Nt(()=>import("./dagre-6UL2VRFP-DX8gNHmJ-BYoXuRvj.js"),__vite__mapDeps([0,1,2,3,4,5])),"loader")},{name:"cose-bilkent",loader:F(async()=>await Nt(()=>import("./cose-bilkent-S5V4N54A-BRr2Y6dg-vCdUVgOY.js"),__vite__mapDeps([6,7])),"loader")}])},"registerDefaultLayoutLoaders");lze();var set=F(async(e,t)=>{if(!(e.layoutAlgorithm in wh))throw new Error(`Unknown layout algorithm: ${e.layoutAlgorithm}`);const r=wh[e.layoutAlgorithm];return(await r.loader()).render(e,t,oze,{algorithm:r.algorithm})},"render"),oet=F((e="",{fallback:t="dagre"}={})=>{if(e in wh)return e;if(t in wh)return ue.warn(`Layout algorithm ${e} is not registered. Using ${t} as fallback.`),t;throw new Error(`Both layout algorithms ${e} and ${t} are not registered.`)},"getRegisteredLayoutAlgorithm"),jte="comm",zte="rule",Tte="decl",cze="@import",uze="@namespace",gze="@keyframes",dze="@layer",Lte=Math.abs,y2=String.fromCharCode;function Hte(e){return e.trim()}function w0(e,t,r){return e.replace(t,r)}function hze(e,t,r){return e.indexOf(t,r)}function Au(e,t){return e.charCodeAt(t)|0}function Fu(e,t,r){return e.slice(t,r)}function ua(e){return e.length}function Bze(e){return e.length}function Fp(e,t){return t.push(e),e}var Zm=1,Yu=1,Jte=0,Ei=0,Vr=0,Vu="";function C2(e,t,r,n,A,i,a,s){return{value:e,root:t,parent:r,type:n,props:A,children:i,line:Zm,column:Yu,length:a,return:"",siblings:s}}function pze(){return Vr}function wze(){return Vr=Ei>0?Au(Vu,--Ei):0,Yu--,Vr===10&&(Yu=1,Zm--),Vr}function Pi(){return Vr=Ei<Jte?Au(Vu,Ei++):0,Yu++,Vr===10&&(Yu=1,Zm++),Vr}function Ao(){return Au(Vu,Ei)}function f0(){return Ei}function qm(e,t){return Fu(Vu,e,t)}function fh(e){switch(e){case 0:case 9:case 10:case 13:case 32:return 5;case 33:case 43:case 44:case 47:case 62:case 64:case 126:case 59:case 123:case 125:return 4;case 58:return 3;case 34:case 39:case 40:case 91:return 2;case 41:case 93:return 1}return 0}function fze(e){return Zm=Yu=1,Jte=ua(Vu=e),Ei=0,[]}function mze(e){return Vu="",e}function lN(e){return Hte(qm(Ei-1,Vx(e===91?e+2:e===40?e+1:e)))}function Eze(e){for(;(Vr=Ao())&&Vr<33;)Pi();return fh(e)>2||fh(Vr)>3?"":" "}function Ize(e,t){for(;--t&&Pi()&&!(Vr<48||Vr>102||Vr>57&&Vr<65||Vr>70&&Vr<97););return qm(e,f0()+(t<6&&Ao()==32&&Pi()==32))}function Vx(e){for(;Pi();)switch(Vr){case e:return Ei;case 34:case 39:e!==34&&e!==39&&Vx(Vr);break;case 40:e===41&&Vx(e);break;case 92:Pi();break}return Ei}function yze(e,t){for(;Pi()&&e+Vr!==57&&!(e+Vr===84&&Ao()===47););return"/*"+qm(t,Ei-1)+"*"+y2(e===47?e:Pi())}function Cze(e){for(;!fh(Ao());)Pi();return qm(e,Ei)}function Qze(e){return mze(m0("",null,null,null,[""],e=fze(e),0,[0],e))}function m0(e,t,r,n,A,i,a,s,o){for(var l=0,c=0,u=a,g=0,d=0,B=0,h=1,f=1,w=1,p=0,m="",C=A,E=i,I=n,Q=m;f;)switch(B=p,p=Pi()){case 40:if(B!=108&&Au(Q,u-1)==58){hze(Q+=w0(lN(p),"&","&\f"),"&\f",Lte(l?s[l-1]:0))!=-1&&(w=-1);break}case 34:case 39:case 91:Q+=lN(p);break;case 9:case 10:case 13:case 32:Q+=Eze(B);break;case 92:Q+=Ize(f0()-1,7);continue;case 47:switch(Ao()){case 42:case 47:Fp(Mze(yze(Pi(),f0()),t,r,o),o),(fh(B||1)==5||fh(Ao()||1)==5)&&ua(Q)&&Fu(Q,-1,void 0)!==" "&&(Q+=" ");break;default:Q+="/"}break;case 123*h:s[l++]=ua(Q)*w;case 125*h:case 59:case 0:switch(p){case 0:case 125:f=0;case 59+c:w==-1&&(Q=w0(Q,/\f/g,"")),d>0&&(ua(Q)-u||h===0&&B===47)&&Fp(d>32?vO(Q+";",n,r,u-1,o):vO(w0(Q," ","")+";",n,r,u-2,o),o);break;case 59:Q+=";";default:if(Fp(I=UO(Q,t,r,l,c,A,s,m,C=[],E=[],u,i),i),p===123)if(c===0)m0(Q,t,I,I,C,i,u,s,E);else{switch(g){case 99:if(Au(Q,3)===110)break;case 108:if(Au(Q,2)===97)break;default:c=0;case 100:case 109:case 115:}c?m0(e,I,I,n&&Fp(UO(e,I,I,0,0,A,s,m,A,C=[],u,E),E),A,E,u,s,n?C:E):m0(Q,I,I,I,[""],E,0,s,E)}}l=c=d=0,h=w=1,m=Q="",u=a;break;case 58:u=1+ua(Q),d=B;default:if(h<1){if(p==123)--h;else if(p==125&&h++==0&&wze()==125)continue}switch(Q+=y2(p),p*h){case 38:w=c>0?1:(Q+="\f",-1);break;case 44:s[l++]=(ua(Q)-1)*w,w=1;break;case 64:Ao()===45&&(Q+=lN(Pi())),g=Ao(),c=u=ua(m=Q+=Cze(f0())),p++;break;case 45:B===45&&ua(Q)==2&&(h=0)}}return i}function UO(e,t,r,n,A,i,a,s,o,l,c,u){for(var g=A-1,d=A===0?i:[""],B=Bze(d),h=0,f=0,w=0;h<n;++h)for(var p=0,m=Fu(e,g+1,g=Lte(f=a[h])),C=e;p<B;++p)(C=Hte(f>0?d[p]+" "+m:w0(m,/&\f/g,d[p])))&&(o[w++]=C);return C2(e,t,r,A===0?zte:s,o,l,c,u)}function Mze(e,t,r,n){return C2(e,t,r,jte,y2(pze()),Fu(e,2,-2),0,n)}function vO(e,t,r,n,A){return C2(e,t,r,Tte,Fu(e,0,n),Fu(e,n+1,-1),n,A)}function Xx(e,t){for(var r="",n=0;n<e.length;n++)r+=t(e[n],n,e,t)||"";return r}function Fze(e,t,r,n){switch(e.type){case dze:if(e.children.length)break;case cze:case uze:case Tte:return e.return=e.return||e.value;case jte:return"";case gze:return e.return=e.value+"{"+Xx(e.children,n)+"}";case zte:if(!ua(e.value=e.props.join(",")))return""}return ua(r=Xx(e.children,n))?e.return=e.value+"{"+r+"}":""}var Yze=B$(Object.keys,Object),Nze=Object.prototype,bze=Nze.hasOwnProperty;function xze(e){if(!Tm(e))return Yze(e);var t=[];for(var r in Object(e))bze.call(e,r)&&r!="constructor"&&t.push(r);return t}var Zx=ic(Da,"DataView"),qx=ic(Da,"Promise"),_x=ic(Da,"Set"),$x=ic(Da,"WeakMap"),GO="[object Map]",Dze="[object Object]",RO="[object Promise]",jO="[object Set]",zO="[object WeakMap]",TO="[object DataView]",kze=Ac(Zx),Sze=Ac(Bh),Uze=Ac(qx),vze=Ac(_x),Gze=Ac($x),qo=Wu;(Zx&&qo(new Zx(new ArrayBuffer(1)))!=TO||Bh&&qo(new Bh)!=GO||qx&&qo(qx.resolve())!=RO||_x&&qo(new _x)!=jO||$x&&qo(new $x)!=zO)&&(qo=function(e){var t=Wu(e),r=t==Dze?e.constructor:void 0,n=r?Ac(r):"";if(n)switch(n){case kze:return TO;case Sze:return GO;case Uze:return RO;case vze:return jO;case Gze:return zO}return t});var Rze="[object Map]",jze="[object Set]",zze=Object.prototype,Tze=zze.hasOwnProperty;function LO(e){if(e==null)return!0;if(Lm(e)&&(Tw(e)||typeof e=="string"||typeof e.splice=="function"||e2(e)||t2(e)||zw(e)))return!e.length;var t=qo(e);if(t==Rze||t==jze)return!e.size;if(Tm(e))return!xze(e).length;for(var r in e)if(Tze.call(e,r))return!1;return!0}var Ote="c4",Lze=F(e=>/^\s*C4Context|C4Container|C4Component|C4Dynamic|C4Deployment/.test(e),"detector"),Hze=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./c4Diagram-YG6GDRKO-DYXNcDX4-O-nw7plh.js");return{diagram:t}},__vite__mapDeps([8,9]));return{id:Ote,diagram:e}},"loader"),Jze={id:Ote,detector:Lze,loader:Hze},Oze=Jze,Wte="flowchart",Wze=F((e,t)=>{var r,n;return((r=t==null?void 0:t.flowchart)==null?void 0:r.defaultRenderer)==="dagre-wrapper"||((n=t==null?void 0:t.flowchart)==null?void 0:n.defaultRenderer)==="elk"?!1:/^\s*graph/.test(e)},"detector"),Pze=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./flowDiagram-NV44I4VS-pJlHae8Y-CAIm3OCI.js");return{diagram:t}},__vite__mapDeps([10,11,12,13,14]));return{id:Wte,diagram:e}},"loader"),Kze={id:Wte,detector:Wze,loader:Pze},Vze=Kze,Pte="flowchart-v2",Xze=F((e,t)=>{var r,n,A;return((r=t==null?void 0:t.flowchart)==null?void 0:r.defaultRenderer)==="dagre-d3"?!1:(((n=t==null?void 0:t.flowchart)==null?void 0:n.defaultRenderer)==="elk"&&(t.layout="elk"),/^\s*graph/.test(e)&&((A=t==null?void 0:t.flowchart)==null?void 0:A.defaultRenderer)==="dagre-wrapper"?!0:/^\s*flowchart/.test(e))},"detector"),Zze=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./flowDiagram-NV44I4VS-pJlHae8Y-CAIm3OCI.js");return{diagram:t}},__vite__mapDeps([10,11,12,13,14]));return{id:Pte,diagram:e}},"loader"),qze={id:Pte,detector:Xze,loader:Zze},_ze=qze,Kte="er",$ze=F(e=>/^\s*erDiagram/.test(e),"detector"),eTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./erDiagram-Q2GNP2WA-DbLpN8Jp-QZ04AM6K.js");return{diagram:t}},__vite__mapDeps([15,12,13,14]));return{id:Kte,diagram:e}},"loader"),tTe={id:Kte,detector:$ze,loader:eTe},rTe=tTe,Vte="gitGraph",nTe=F(e=>/^\s*gitGraph/.test(e),"detector"),ATe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./gitGraphDiagram-NY62KEGX-DgYonpsZ-j8MsbrTT.js");return{diagram:t}},__vite__mapDeps([16,17,18,19,4,2]));return{id:Vte,diagram:e}},"loader"),iTe={id:Vte,detector:nTe,loader:ATe},aTe=iTe,Xte="gantt",sTe=F(e=>/^\s*gantt/.test(e),"detector"),oTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./ganttDiagram-JELNMOA3-J0Tkq5TR-DHqa9s8V.js");return{diagram:t}},[]);return{id:Xte,diagram:e}},"loader"),lTe={id:Xte,detector:sTe,loader:oTe},cTe=lTe,Zte="info",uTe=F(e=>/^\s*info/.test(e),"detector"),gTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./infoDiagram-WHAUD3N6-C3JLOAnb-6y-bwNyN.js");return{diagram:t}},__vite__mapDeps([20,19,4,2]));return{id:Zte,diagram:e}},"loader"),dTe={id:Zte,detector:uTe,loader:gTe},qte="pie",hTe=F(e=>/^\s*pie/.test(e),"detector"),BTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./pieDiagram-ADFJNKIX-BiQvDx8I-BT5l2ngl.js");return{diagram:t}},__vite__mapDeps([21,17,19,4,2,22]));return{id:qte,diagram:e}},"loader"),pTe={id:qte,detector:hTe,loader:BTe},_te="quadrantChart",wTe=F(e=>/^\s*quadrantChart/.test(e),"detector"),fTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./quadrantDiagram-AYHSOK5B-D4b-YFzI-D4aUN4bx.js");return{diagram:t}},[]);return{id:_te,diagram:e}},"loader"),mTe={id:_te,detector:wTe,loader:fTe},ETe=mTe,$te="xychart",ITe=F(e=>/^\s*xychart(-beta)?/.test(e),"detector"),yTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./xychartDiagram-PRI3JC2R-JzAaXa5z-DOprIJGo.js");return{diagram:t}},[]);return{id:$te,diagram:e}},"loader"),CTe={id:$te,detector:ITe,loader:yTe},QTe=CTe,ere="requirement",MTe=F(e=>/^\s*requirement(Diagram)?/.test(e),"detector"),FTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./requirementDiagram-UZGBJVZJ-km07nlVd-DT-CJzQX.js");return{diagram:t}},__vite__mapDeps([23,12,13]));return{id:ere,diagram:e}},"loader"),YTe={id:ere,detector:MTe,loader:FTe},NTe=YTe,tre="sequence",bTe=F(e=>/^\s*sequenceDiagram/.test(e),"detector"),xTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./sequenceDiagram-WL72ISMW-CQ4J-0_7-BYA8hV94.js");return{diagram:t}},__vite__mapDeps([24,9,18]));return{id:tre,diagram:e}},"loader"),DTe={id:tre,detector:bTe,loader:xTe},kTe=DTe,rre="class",STe=F((e,t)=>{var r;return((r=t==null?void 0:t.class)==null?void 0:r.defaultRenderer)==="dagre-wrapper"?!1:/^\s*classDiagram/.test(e)},"detector"),UTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./classDiagram-2ON5EDUG-CxmgTanh-CA3Ppuao.js");return{diagram:t}},__vite__mapDeps([25,26,11,12,13]));return{id:rre,diagram:e}},"loader"),vTe={id:rre,detector:STe,loader:UTe},GTe=vTe,nre="classDiagram",RTe=F((e,t)=>{var r;return/^\s*classDiagram/.test(e)&&((r=t==null?void 0:t.class)==null?void 0:r.defaultRenderer)==="dagre-wrapper"?!0:/^\s*classDiagram-v2/.test(e)},"detector"),jTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./classDiagram-v2-WZHVMYZB-CxmgTanh-CA3Ppuao.js");return{diagram:t}},__vite__mapDeps([27,26,11,12,13]));return{id:nre,diagram:e}},"loader"),zTe={id:nre,detector:RTe,loader:jTe},TTe=zTe,Are="state",LTe=F((e,t)=>{var r;return((r=t==null?void 0:t.state)==null?void 0:r.defaultRenderer)==="dagre-wrapper"?!1:/^\s*stateDiagram/.test(e)},"detector"),HTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./stateDiagram-FKZM4ZOC-JtogJwt6-SGbwMgjL.js");return{diagram:t}},__vite__mapDeps([28,29,12,13,1,2,3,4]));return{id:Are,diagram:e}},"loader"),JTe={id:Are,detector:LTe,loader:HTe},OTe=JTe,ire="stateDiagram",WTe=F((e,t)=>{var r;return!!(/^\s*stateDiagram-v2/.test(e)||/^\s*stateDiagram/.test(e)&&((r=t==null?void 0:t.state)==null?void 0:r.defaultRenderer)==="dagre-wrapper")},"detector"),PTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./stateDiagram-v2-4FDKWEC3-DuQ7UaeU-DfYMYAyn.js");return{diagram:t}},__vite__mapDeps([30,29,12,13]));return{id:ire,diagram:e}},"loader"),KTe={id:ire,detector:WTe,loader:PTe},VTe=KTe,are="journey",XTe=F(e=>/^\s*journey/.test(e),"detector"),ZTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./journeyDiagram-XKPGCS4Q-CfjB2Qdf-Cr6xcm9B.js");return{diagram:t}},__vite__mapDeps([31,9,11,22]));return{id:are,diagram:e}},"loader"),qTe={id:are,detector:XTe,loader:ZTe},_Te=qTe,$Te=F((e,t,r)=>{ue.debug(`rendering svg for syntax error
|
|
831
|
-
`);const n=SSe(t),A=n.append("g");n.attr("viewBox","0 0 2412 512"),eZ(n,100,512,!0),A.append("path").attr("class","error-icon").attr("d","m411.313,123.313c6.25-6.25 6.25-16.375 0-22.625s-16.375-6.25-22.625,0l-32,32-9.375,9.375-20.688-20.688c-12.484-12.5-32.766-12.5-45.25,0l-16,16c-1.261,1.261-2.304,2.648-3.31,4.051-21.739-8.561-45.324-13.426-70.065-13.426-105.867,0-192,86.133-192,192s86.133,192 192,192 192-86.133 192-192c0-24.741-4.864-48.327-13.426-70.065 1.402-1.007 2.79-2.049 4.051-3.31l16-16c12.5-12.492 12.5-32.758 0-45.25l-20.688-20.688 9.375-9.375 32.001-31.999zm-219.313,100.687c-52.938,0-96,43.063-96,96 0,8.836-7.164,16-16,16s-16-7.164-16-16c0-70.578 57.422-128 128-128 8.836,0 16,7.164 16,16s-7.164,16-16,16z"),A.append("path").attr("class","error-icon").attr("d","m459.02,148.98c-6.25-6.25-16.375-6.25-22.625,0s-6.25,16.375 0,22.625l16,16c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688 6.25-6.25 6.25-16.375 0-22.625l-16.001-16z"),A.append("path").attr("class","error-icon").attr("d","m340.395,75.605c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688 6.25-6.25 6.25-16.375 0-22.625l-16-16c-6.25-6.25-16.375-6.25-22.625,0s-6.25,16.375 0,22.625l15.999,16z"),A.append("path").attr("class","error-icon").attr("d","m400,64c8.844,0 16-7.164 16-16v-32c0-8.836-7.156-16-16-16-8.844,0-16,7.164-16,16v32c0,8.836 7.156,16 16,16z"),A.append("path").attr("class","error-icon").attr("d","m496,96.586h-32c-8.844,0-16,7.164-16,16 0,8.836 7.156,16 16,16h32c8.844,0 16-7.164 16-16 0-8.836-7.156-16-16-16z"),A.append("path").attr("class","error-icon").attr("d","m436.98,75.605c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688l32-32c6.25-6.25 6.25-16.375 0-22.625s-16.375-6.25-22.625,0l-32,32c-6.251,6.25-6.251,16.375-0.001,22.625z"),A.append("text").attr("class","error-text").attr("x",1440).attr("y",250).attr("font-size","150px").style("text-anchor","middle").text("Syntax error in text"),A.append("text").attr("class","error-text").attr("x",1250).attr("y",400).attr("font-size","100px").style("text-anchor","middle").text(`mermaid version ${r}`)},"draw"),sre={draw:$Te},eLe=sre,tLe={db:{},renderer:sre,parser:{parse:F(()=>{},"parse")}},rLe=tLe,ore="flowchart-elk",nLe=F((e,t={})=>{var r;return/^\s*flowchart-elk/.test(e)||/^\s*(flowchart|graph)/.test(e)&&((r=t==null?void 0:t.flowchart)==null?void 0:r.defaultRenderer)==="elk"?(t.layout="elk",!0):!1},"detector"),ALe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./flowDiagram-NV44I4VS-pJlHae8Y-
|
|
830
|
+
L0,20`)},"requirement_arrow"),ize=F((e,t,r)=>{const n=e.append("defs").append("marker").attr("id",r+"_"+t+"-requirement_containsStart").attr("refX",0).attr("refY",10).attr("markerWidth",20).attr("markerHeight",20).attr("orient","auto").append("g");n.append("circle").attr("cx",10).attr("cy",10).attr("r",9).attr("fill","none"),n.append("line").attr("x1",1).attr("x2",19).attr("y1",10).attr("y2",10),n.append("line").attr("y1",1).attr("y2",19).attr("x1",10).attr("x2",10)},"requirement_contains"),aze={extension:Wje,composition:Pje,aggregation:Kje,dependency:Vje,lollipop:Xje,point:Zje,circle:qje,cross:_je,barb:$je,only_one:eze,zero_or_one:tze,one_or_more:rze,zero_or_more:nze,requirement_arrow:Aze,requirement_contains:ize},sze=Oje,oze={common:Hu,getConfig:Wn,insertCluster:pje,insertEdge:Jje,insertEdgeLabel:Rje,insertMarkers:sze,insertNode:Ste,interpolateToCurve:r2,labelHelper:tt,log:ue,positionEdgeLabel:jje},wh={},Rte=F(e=>{for(const t of e)wh[t.name]=t},"registerLayoutLoaders"),lze=F(()=>{Rte([{name:"dagre",loader:F(async()=>await Nt(()=>import("./dagre-6UL2VRFP-DX8gNHmJ-CYh5hSEy.js"),__vite__mapDeps([0,1,2,3,4,5])),"loader")},{name:"cose-bilkent",loader:F(async()=>await Nt(()=>import("./cose-bilkent-S5V4N54A-BRr2Y6dg-BHOEDqnM.js"),__vite__mapDeps([6,7])),"loader")}])},"registerDefaultLayoutLoaders");lze();var set=F(async(e,t)=>{if(!(e.layoutAlgorithm in wh))throw new Error(`Unknown layout algorithm: ${e.layoutAlgorithm}`);const r=wh[e.layoutAlgorithm];return(await r.loader()).render(e,t,oze,{algorithm:r.algorithm})},"render"),oet=F((e="",{fallback:t="dagre"}={})=>{if(e in wh)return e;if(t in wh)return ue.warn(`Layout algorithm ${e} is not registered. Using ${t} as fallback.`),t;throw new Error(`Both layout algorithms ${e} and ${t} are not registered.`)},"getRegisteredLayoutAlgorithm"),jte="comm",zte="rule",Tte="decl",cze="@import",uze="@namespace",gze="@keyframes",dze="@layer",Lte=Math.abs,y2=String.fromCharCode;function Hte(e){return e.trim()}function w0(e,t,r){return e.replace(t,r)}function hze(e,t,r){return e.indexOf(t,r)}function Au(e,t){return e.charCodeAt(t)|0}function Fu(e,t,r){return e.slice(t,r)}function ua(e){return e.length}function Bze(e){return e.length}function Fp(e,t){return t.push(e),e}var Zm=1,Yu=1,Jte=0,Ei=0,Vr=0,Vu="";function C2(e,t,r,n,A,i,a,s){return{value:e,root:t,parent:r,type:n,props:A,children:i,line:Zm,column:Yu,length:a,return:"",siblings:s}}function pze(){return Vr}function wze(){return Vr=Ei>0?Au(Vu,--Ei):0,Yu--,Vr===10&&(Yu=1,Zm--),Vr}function Pi(){return Vr=Ei<Jte?Au(Vu,Ei++):0,Yu++,Vr===10&&(Yu=1,Zm++),Vr}function Ao(){return Au(Vu,Ei)}function f0(){return Ei}function qm(e,t){return Fu(Vu,e,t)}function fh(e){switch(e){case 0:case 9:case 10:case 13:case 32:return 5;case 33:case 43:case 44:case 47:case 62:case 64:case 126:case 59:case 123:case 125:return 4;case 58:return 3;case 34:case 39:case 40:case 91:return 2;case 41:case 93:return 1}return 0}function fze(e){return Zm=Yu=1,Jte=ua(Vu=e),Ei=0,[]}function mze(e){return Vu="",e}function lN(e){return Hte(qm(Ei-1,Vx(e===91?e+2:e===40?e+1:e)))}function Eze(e){for(;(Vr=Ao())&&Vr<33;)Pi();return fh(e)>2||fh(Vr)>3?"":" "}function Ize(e,t){for(;--t&&Pi()&&!(Vr<48||Vr>102||Vr>57&&Vr<65||Vr>70&&Vr<97););return qm(e,f0()+(t<6&&Ao()==32&&Pi()==32))}function Vx(e){for(;Pi();)switch(Vr){case e:return Ei;case 34:case 39:e!==34&&e!==39&&Vx(Vr);break;case 40:e===41&&Vx(e);break;case 92:Pi();break}return Ei}function yze(e,t){for(;Pi()&&e+Vr!==57&&!(e+Vr===84&&Ao()===47););return"/*"+qm(t,Ei-1)+"*"+y2(e===47?e:Pi())}function Cze(e){for(;!fh(Ao());)Pi();return qm(e,Ei)}function Qze(e){return mze(m0("",null,null,null,[""],e=fze(e),0,[0],e))}function m0(e,t,r,n,A,i,a,s,o){for(var l=0,c=0,u=a,g=0,d=0,B=0,h=1,f=1,w=1,p=0,m="",C=A,E=i,I=n,Q=m;f;)switch(B=p,p=Pi()){case 40:if(B!=108&&Au(Q,u-1)==58){hze(Q+=w0(lN(p),"&","&\f"),"&\f",Lte(l?s[l-1]:0))!=-1&&(w=-1);break}case 34:case 39:case 91:Q+=lN(p);break;case 9:case 10:case 13:case 32:Q+=Eze(B);break;case 92:Q+=Ize(f0()-1,7);continue;case 47:switch(Ao()){case 42:case 47:Fp(Mze(yze(Pi(),f0()),t,r,o),o),(fh(B||1)==5||fh(Ao()||1)==5)&&ua(Q)&&Fu(Q,-1,void 0)!==" "&&(Q+=" ");break;default:Q+="/"}break;case 123*h:s[l++]=ua(Q)*w;case 125*h:case 59:case 0:switch(p){case 0:case 125:f=0;case 59+c:w==-1&&(Q=w0(Q,/\f/g,"")),d>0&&(ua(Q)-u||h===0&&B===47)&&Fp(d>32?vO(Q+";",n,r,u-1,o):vO(w0(Q," ","")+";",n,r,u-2,o),o);break;case 59:Q+=";";default:if(Fp(I=UO(Q,t,r,l,c,A,s,m,C=[],E=[],u,i),i),p===123)if(c===0)m0(Q,t,I,I,C,i,u,s,E);else{switch(g){case 99:if(Au(Q,3)===110)break;case 108:if(Au(Q,2)===97)break;default:c=0;case 100:case 109:case 115:}c?m0(e,I,I,n&&Fp(UO(e,I,I,0,0,A,s,m,A,C=[],u,E),E),A,E,u,s,n?C:E):m0(Q,I,I,I,[""],E,0,s,E)}}l=c=d=0,h=w=1,m=Q="",u=a;break;case 58:u=1+ua(Q),d=B;default:if(h<1){if(p==123)--h;else if(p==125&&h++==0&&wze()==125)continue}switch(Q+=y2(p),p*h){case 38:w=c>0?1:(Q+="\f",-1);break;case 44:s[l++]=(ua(Q)-1)*w,w=1;break;case 64:Ao()===45&&(Q+=lN(Pi())),g=Ao(),c=u=ua(m=Q+=Cze(f0())),p++;break;case 45:B===45&&ua(Q)==2&&(h=0)}}return i}function UO(e,t,r,n,A,i,a,s,o,l,c,u){for(var g=A-1,d=A===0?i:[""],B=Bze(d),h=0,f=0,w=0;h<n;++h)for(var p=0,m=Fu(e,g+1,g=Lte(f=a[h])),C=e;p<B;++p)(C=Hte(f>0?d[p]+" "+m:w0(m,/&\f/g,d[p])))&&(o[w++]=C);return C2(e,t,r,A===0?zte:s,o,l,c,u)}function Mze(e,t,r,n){return C2(e,t,r,jte,y2(pze()),Fu(e,2,-2),0,n)}function vO(e,t,r,n,A){return C2(e,t,r,Tte,Fu(e,0,n),Fu(e,n+1,-1),n,A)}function Xx(e,t){for(var r="",n=0;n<e.length;n++)r+=t(e[n],n,e,t)||"";return r}function Fze(e,t,r,n){switch(e.type){case dze:if(e.children.length)break;case cze:case uze:case Tte:return e.return=e.return||e.value;case jte:return"";case gze:return e.return=e.value+"{"+Xx(e.children,n)+"}";case zte:if(!ua(e.value=e.props.join(",")))return""}return ua(r=Xx(e.children,n))?e.return=e.value+"{"+r+"}":""}var Yze=B$(Object.keys,Object),Nze=Object.prototype,bze=Nze.hasOwnProperty;function xze(e){if(!Tm(e))return Yze(e);var t=[];for(var r in Object(e))bze.call(e,r)&&r!="constructor"&&t.push(r);return t}var Zx=ic(Da,"DataView"),qx=ic(Da,"Promise"),_x=ic(Da,"Set"),$x=ic(Da,"WeakMap"),GO="[object Map]",Dze="[object Object]",RO="[object Promise]",jO="[object Set]",zO="[object WeakMap]",TO="[object DataView]",kze=Ac(Zx),Sze=Ac(Bh),Uze=Ac(qx),vze=Ac(_x),Gze=Ac($x),qo=Wu;(Zx&&qo(new Zx(new ArrayBuffer(1)))!=TO||Bh&&qo(new Bh)!=GO||qx&&qo(qx.resolve())!=RO||_x&&qo(new _x)!=jO||$x&&qo(new $x)!=zO)&&(qo=function(e){var t=Wu(e),r=t==Dze?e.constructor:void 0,n=r?Ac(r):"";if(n)switch(n){case kze:return TO;case Sze:return GO;case Uze:return RO;case vze:return jO;case Gze:return zO}return t});var Rze="[object Map]",jze="[object Set]",zze=Object.prototype,Tze=zze.hasOwnProperty;function LO(e){if(e==null)return!0;if(Lm(e)&&(Tw(e)||typeof e=="string"||typeof e.splice=="function"||e2(e)||t2(e)||zw(e)))return!e.length;var t=qo(e);if(t==Rze||t==jze)return!e.size;if(Tm(e))return!xze(e).length;for(var r in e)if(Tze.call(e,r))return!1;return!0}var Ote="c4",Lze=F(e=>/^\s*C4Context|C4Container|C4Component|C4Dynamic|C4Deployment/.test(e),"detector"),Hze=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./c4Diagram-YG6GDRKO-DYXNcDX4-DCV5_cMO.js");return{diagram:t}},__vite__mapDeps([8,9]));return{id:Ote,diagram:e}},"loader"),Jze={id:Ote,detector:Lze,loader:Hze},Oze=Jze,Wte="flowchart",Wze=F((e,t)=>{var r,n;return((r=t==null?void 0:t.flowchart)==null?void 0:r.defaultRenderer)==="dagre-wrapper"||((n=t==null?void 0:t.flowchart)==null?void 0:n.defaultRenderer)==="elk"?!1:/^\s*graph/.test(e)},"detector"),Pze=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./flowDiagram-NV44I4VS-pJlHae8Y-ZcX989NH.js");return{diagram:t}},__vite__mapDeps([10,11,12,13,14]));return{id:Wte,diagram:e}},"loader"),Kze={id:Wte,detector:Wze,loader:Pze},Vze=Kze,Pte="flowchart-v2",Xze=F((e,t)=>{var r,n,A;return((r=t==null?void 0:t.flowchart)==null?void 0:r.defaultRenderer)==="dagre-d3"?!1:(((n=t==null?void 0:t.flowchart)==null?void 0:n.defaultRenderer)==="elk"&&(t.layout="elk"),/^\s*graph/.test(e)&&((A=t==null?void 0:t.flowchart)==null?void 0:A.defaultRenderer)==="dagre-wrapper"?!0:/^\s*flowchart/.test(e))},"detector"),Zze=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./flowDiagram-NV44I4VS-pJlHae8Y-ZcX989NH.js");return{diagram:t}},__vite__mapDeps([10,11,12,13,14]));return{id:Pte,diagram:e}},"loader"),qze={id:Pte,detector:Xze,loader:Zze},_ze=qze,Kte="er",$ze=F(e=>/^\s*erDiagram/.test(e),"detector"),eTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./erDiagram-Q2GNP2WA-DbLpN8Jp-Blrgdh0d.js");return{diagram:t}},__vite__mapDeps([15,12,13,14]));return{id:Kte,diagram:e}},"loader"),tTe={id:Kte,detector:$ze,loader:eTe},rTe=tTe,Vte="gitGraph",nTe=F(e=>/^\s*gitGraph/.test(e),"detector"),ATe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./gitGraphDiagram-NY62KEGX-DgYonpsZ-DEEHTytg.js");return{diagram:t}},__vite__mapDeps([16,17,18,19,4,2]));return{id:Vte,diagram:e}},"loader"),iTe={id:Vte,detector:nTe,loader:ATe},aTe=iTe,Xte="gantt",sTe=F(e=>/^\s*gantt/.test(e),"detector"),oTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./ganttDiagram-JELNMOA3-J0Tkq5TR-p2P2DGG6.js");return{diagram:t}},[]);return{id:Xte,diagram:e}},"loader"),lTe={id:Xte,detector:sTe,loader:oTe},cTe=lTe,Zte="info",uTe=F(e=>/^\s*info/.test(e),"detector"),gTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./infoDiagram-WHAUD3N6-C3JLOAnb-CPXB0Iei.js");return{diagram:t}},__vite__mapDeps([20,19,4,2]));return{id:Zte,diagram:e}},"loader"),dTe={id:Zte,detector:uTe,loader:gTe},qte="pie",hTe=F(e=>/^\s*pie/.test(e),"detector"),BTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./pieDiagram-ADFJNKIX-BiQvDx8I-BAT3faFm.js");return{diagram:t}},__vite__mapDeps([21,17,19,4,2,22]));return{id:qte,diagram:e}},"loader"),pTe={id:qte,detector:hTe,loader:BTe},_te="quadrantChart",wTe=F(e=>/^\s*quadrantChart/.test(e),"detector"),fTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./quadrantDiagram-AYHSOK5B-D4b-YFzI-ByBf_iEO.js");return{diagram:t}},[]);return{id:_te,diagram:e}},"loader"),mTe={id:_te,detector:wTe,loader:fTe},ETe=mTe,$te="xychart",ITe=F(e=>/^\s*xychart(-beta)?/.test(e),"detector"),yTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./xychartDiagram-PRI3JC2R-JzAaXa5z-DMsk4lld.js");return{diagram:t}},[]);return{id:$te,diagram:e}},"loader"),CTe={id:$te,detector:ITe,loader:yTe},QTe=CTe,ere="requirement",MTe=F(e=>/^\s*requirement(Diagram)?/.test(e),"detector"),FTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./requirementDiagram-UZGBJVZJ-km07nlVd-DyCQ9b-2.js");return{diagram:t}},__vite__mapDeps([23,12,13]));return{id:ere,diagram:e}},"loader"),YTe={id:ere,detector:MTe,loader:FTe},NTe=YTe,tre="sequence",bTe=F(e=>/^\s*sequenceDiagram/.test(e),"detector"),xTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./sequenceDiagram-WL72ISMW-CQ4J-0_7-BG0F1yw0.js");return{diagram:t}},__vite__mapDeps([24,9,18]));return{id:tre,diagram:e}},"loader"),DTe={id:tre,detector:bTe,loader:xTe},kTe=DTe,rre="class",STe=F((e,t)=>{var r;return((r=t==null?void 0:t.class)==null?void 0:r.defaultRenderer)==="dagre-wrapper"?!1:/^\s*classDiagram/.test(e)},"detector"),UTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./classDiagram-2ON5EDUG-CxmgTanh-jsILqBHT.js");return{diagram:t}},__vite__mapDeps([25,26,11,12,13]));return{id:rre,diagram:e}},"loader"),vTe={id:rre,detector:STe,loader:UTe},GTe=vTe,nre="classDiagram",RTe=F((e,t)=>{var r;return/^\s*classDiagram/.test(e)&&((r=t==null?void 0:t.class)==null?void 0:r.defaultRenderer)==="dagre-wrapper"?!0:/^\s*classDiagram-v2/.test(e)},"detector"),jTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./classDiagram-v2-WZHVMYZB-CxmgTanh-jsILqBHT.js");return{diagram:t}},__vite__mapDeps([27,26,11,12,13]));return{id:nre,diagram:e}},"loader"),zTe={id:nre,detector:RTe,loader:jTe},TTe=zTe,Are="state",LTe=F((e,t)=>{var r;return((r=t==null?void 0:t.state)==null?void 0:r.defaultRenderer)==="dagre-wrapper"?!1:/^\s*stateDiagram/.test(e)},"detector"),HTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./stateDiagram-FKZM4ZOC-JtogJwt6-Ds546Riv.js");return{diagram:t}},__vite__mapDeps([28,29,12,13,1,2,3,4]));return{id:Are,diagram:e}},"loader"),JTe={id:Are,detector:LTe,loader:HTe},OTe=JTe,ire="stateDiagram",WTe=F((e,t)=>{var r;return!!(/^\s*stateDiagram-v2/.test(e)||/^\s*stateDiagram/.test(e)&&((r=t==null?void 0:t.state)==null?void 0:r.defaultRenderer)==="dagre-wrapper")},"detector"),PTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./stateDiagram-v2-4FDKWEC3-DuQ7UaeU-C44zln-C.js");return{diagram:t}},__vite__mapDeps([30,29,12,13]));return{id:ire,diagram:e}},"loader"),KTe={id:ire,detector:WTe,loader:PTe},VTe=KTe,are="journey",XTe=F(e=>/^\s*journey/.test(e),"detector"),ZTe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./journeyDiagram-XKPGCS4Q-CfjB2Qdf-Do-Pa_c0.js");return{diagram:t}},__vite__mapDeps([31,9,11,22]));return{id:are,diagram:e}},"loader"),qTe={id:are,detector:XTe,loader:ZTe},_Te=qTe,$Te=F((e,t,r)=>{ue.debug(`rendering svg for syntax error
|
|
831
|
+
`);const n=SSe(t),A=n.append("g");n.attr("viewBox","0 0 2412 512"),eZ(n,100,512,!0),A.append("path").attr("class","error-icon").attr("d","m411.313,123.313c6.25-6.25 6.25-16.375 0-22.625s-16.375-6.25-22.625,0l-32,32-9.375,9.375-20.688-20.688c-12.484-12.5-32.766-12.5-45.25,0l-16,16c-1.261,1.261-2.304,2.648-3.31,4.051-21.739-8.561-45.324-13.426-70.065-13.426-105.867,0-192,86.133-192,192s86.133,192 192,192 192-86.133 192-192c0-24.741-4.864-48.327-13.426-70.065 1.402-1.007 2.79-2.049 4.051-3.31l16-16c12.5-12.492 12.5-32.758 0-45.25l-20.688-20.688 9.375-9.375 32.001-31.999zm-219.313,100.687c-52.938,0-96,43.063-96,96 0,8.836-7.164,16-16,16s-16-7.164-16-16c0-70.578 57.422-128 128-128 8.836,0 16,7.164 16,16s-7.164,16-16,16z"),A.append("path").attr("class","error-icon").attr("d","m459.02,148.98c-6.25-6.25-16.375-6.25-22.625,0s-6.25,16.375 0,22.625l16,16c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688 6.25-6.25 6.25-16.375 0-22.625l-16.001-16z"),A.append("path").attr("class","error-icon").attr("d","m340.395,75.605c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688 6.25-6.25 6.25-16.375 0-22.625l-16-16c-6.25-6.25-16.375-6.25-22.625,0s-6.25,16.375 0,22.625l15.999,16z"),A.append("path").attr("class","error-icon").attr("d","m400,64c8.844,0 16-7.164 16-16v-32c0-8.836-7.156-16-16-16-8.844,0-16,7.164-16,16v32c0,8.836 7.156,16 16,16z"),A.append("path").attr("class","error-icon").attr("d","m496,96.586h-32c-8.844,0-16,7.164-16,16 0,8.836 7.156,16 16,16h32c8.844,0 16-7.164 16-16 0-8.836-7.156-16-16-16z"),A.append("path").attr("class","error-icon").attr("d","m436.98,75.605c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688l32-32c6.25-6.25 6.25-16.375 0-22.625s-16.375-6.25-22.625,0l-32,32c-6.251,6.25-6.251,16.375-0.001,22.625z"),A.append("text").attr("class","error-text").attr("x",1440).attr("y",250).attr("font-size","150px").style("text-anchor","middle").text("Syntax error in text"),A.append("text").attr("class","error-text").attr("x",1250).attr("y",400).attr("font-size","100px").style("text-anchor","middle").text(`mermaid version ${r}`)},"draw"),sre={draw:$Te},eLe=sre,tLe={db:{},renderer:sre,parser:{parse:F(()=>{},"parse")}},rLe=tLe,ore="flowchart-elk",nLe=F((e,t={})=>{var r;return/^\s*flowchart-elk/.test(e)||/^\s*(flowchart|graph)/.test(e)&&((r=t==null?void 0:t.flowchart)==null?void 0:r.defaultRenderer)==="elk"?(t.layout="elk",!0):!1},"detector"),ALe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./flowDiagram-NV44I4VS-pJlHae8Y-ZcX989NH.js");return{diagram:t}},__vite__mapDeps([10,11,12,13,14]));return{id:ore,diagram:e}},"loader"),iLe={id:ore,detector:nLe,loader:ALe},aLe=iLe,lre="timeline",sLe=F(e=>/^\s*timeline/.test(e),"detector"),oLe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./timeline-definition-IT6M3QCI-Cs3NnF2M-Dsc7nQem.js");return{diagram:t}},__vite__mapDeps([32,22]));return{id:lre,diagram:e}},"loader"),lLe={id:lre,detector:sLe,loader:oLe},cLe=lLe,cre="mindmap",uLe=F(e=>/^\s*mindmap/.test(e),"detector"),gLe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./mindmap-definition-VGOIOE7T-Dj37RkY_-BzuvOjfA.js");return{diagram:t}},__vite__mapDeps([33,12,13]));return{id:cre,diagram:e}},"loader"),dLe={id:cre,detector:uLe,loader:gLe},hLe=dLe,ure="kanban",BLe=F(e=>/^\s*kanban/.test(e),"detector"),pLe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./kanban-definition-3W4ZIXB7-CrW8yVmd-SNTX2wCT.js");return{diagram:t}},__vite__mapDeps([34,11]));return{id:ure,diagram:e}},"loader"),wLe={id:ure,detector:BLe,loader:pLe},fLe=wLe,gre="sankey",mLe=F(e=>/^\s*sankey(-beta)?/.test(e),"detector"),ELe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./sankeyDiagram-TZEHDZUN-LfuSRRbf-B4gBy7rf.js");return{diagram:t}},[]);return{id:gre,diagram:e}},"loader"),ILe={id:gre,detector:mLe,loader:ELe},yLe=ILe,dre="packet",CLe=F(e=>/^\s*packet(-beta)?/.test(e),"detector"),QLe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./diagram-S2PKOQOG-IEqaDwzi-DX1MwhnG.js");return{diagram:t}},__vite__mapDeps([35,17,19,4,2]));return{id:dre,diagram:e}},"loader"),MLe={id:dre,detector:CLe,loader:QLe},hre="radar",FLe=F(e=>/^\s*radar-beta/.test(e),"detector"),YLe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./diagram-QEK2KX5R-BDO6hKtm-HtTknE56.js");return{diagram:t}},__vite__mapDeps([36,17,19,4,2]));return{id:hre,diagram:e}},"loader"),NLe={id:hre,detector:FLe,loader:YLe},Bre="block",bLe=F(e=>/^\s*block(-beta)?/.test(e),"detector"),xLe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./blockDiagram-VD42YOAC-zcRIdFTD-BrtL2H_x.js");return{diagram:t}},__vite__mapDeps([37,11,5,1,2,14]));return{id:Bre,diagram:e}},"loader"),DLe={id:Bre,detector:bLe,loader:xLe},kLe=DLe,pre="architecture",SLe=F(e=>/^\s*architecture/.test(e),"detector"),ULe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./architectureDiagram-VXUJARFQ-BiqZtsDe-coVQhEcP.js");return{diagram:t}},__vite__mapDeps([38,17,19,4,2,7]));return{id:pre,diagram:e}},"loader"),vLe={id:pre,detector:SLe,loader:ULe},GLe=vLe,wre="treemap",RLe=F(e=>/^\s*treemap/.test(e),"detector"),jLe=F(async()=>{const{diagram:e}=await Nt(async()=>{const{diagram:t}=await import("./diagram-PSM6KHXK-DNX818To-DP7laJPI.js");return{diagram:t}},__vite__mapDeps([39,13,17,19,4,2]));return{id:wre,diagram:e}},"loader"),zLe={id:wre,detector:RLe,loader:jLe},HO=!1,_m=F(()=>{HO||(HO=!0,dw("error",rLe,e=>e.toLowerCase().trim()==="error"),dw("---",{db:{clear:F(()=>{},"clear")},styles:{},renderer:{draw:F(()=>{},"draw")},parser:{parse:F(()=>{throw new Error("Diagrams beginning with --- are not valid. If you were trying to use a YAML front-matter, please ensure that you've correctly opened and closed the YAML front-matter with un-indented `---` blocks")},"parse")},init:F(()=>null,"init")},e=>e.toLowerCase().trimStart().startsWith("---")),ex(aLe,hLe,GLe),ex(Oze,fLe,TTe,GTe,rTe,cTe,dTe,pTe,NTe,kTe,_ze,Vze,cLe,aTe,VTe,OTe,_Te,ETe,yLe,MLe,QTe,kLe,NLe,zLe))},"addDiagrams"),TLe=F(async()=>{ue.debug("Loading registered diagrams");const e=(await Promise.allSettled(Object.entries(xl).map(async([t,{detector:r,loader:n}])=>{if(n)try{Ax(t)}catch{try{const{diagram:A,id:i}=await n();dw(i,A,r)}catch(A){throw ue.error(`Failed to load external diagram with key ${t}. Removing from detectors.`),delete xl[t],A}}}))).filter(t=>t.status==="rejected");if(e.length>0){ue.error(`Failed to load ${e.length} external diagrams`);for(const t of e)ue.error(t);throw new Error(`Failed to load ${e.length} external diagrams`)}},"loadRegisteredDiagrams"),LLe="graphics-document document";function fre(e,t){e.attr("role",LLe),t!==""&&e.attr("aria-roledescription",t)}F(fre,"setA11yDiagramInfo");function mre(e,t,r,n){if(e.insert!==void 0){if(r){const A=`chart-desc-${n}`;e.attr("aria-describedby",A),e.insert("desc",":first-child").attr("id",A).text(r)}if(t){const A=`chart-title-${n}`;e.attr("aria-labelledby",A),e.insert("title",":first-child").attr("id",A).text(t)}}}F(mre,"addSVGa11yTitleDescription");var Yp,eD=(Yp=class{constructor(e,t,r,n,A){this.type=e,this.text=t,this.db=r,this.parser=n,this.renderer=A}static async fromText(e,t={}){var r,n;const A=Wn(),i=VS(e,A);e=zGe(e)+`
|
|
832
832
|
`;try{Ax(i)}catch{const c=OFe(i);if(!c)throw new HX(`Diagram ${i} not found.`);const{id:u,diagram:g}=await c();dw(u,g)}const{db:a,parser:s,renderer:o,init:l}=Ax(i);return s.parser&&(s.parser.yy=a),(r=a.clear)==null||r.call(a),l==null||l(A),t.title&&((n=a.setDiagramTitle)==null||n.call(a,t.title)),await s.parse(e),new Yp(i,e,a,s,o)}async render(e,t){await this.renderer.draw(this.text,e,t,this)}getParser(){return this.parser}getType(){return this.type}},F(Yp,"Diagram"),Yp),JO=[],HLe=F(()=>{JO.forEach(e=>{e()}),JO=[]},"attachFunctions"),JLe=F(e=>e.replace(/^\s*%%(?!{)[^\n]+\n?/gm,"").trimStart(),"cleanupComments");function Ere(e){const t=e.match(LX);if(!t)return{text:e,metadata:{}};let r=TUe(t[1],{schema:zUe})??{};r=typeof r=="object"&&!Array.isArray(r)?r:{};const n={};return r.displayMode&&(n.displayMode=r.displayMode.toString()),r.title&&(n.title=r.title.toString()),r.config&&(n.config=r.config),{text:e.slice(t[0].length),metadata:n}}F(Ere,"extractFrontMatter");var OLe=F(e=>e.replace(/\r\n?/g,`
|
|
833
833
|
`).replace(/<(\w+)([^>]*)>/g,(t,r,n)=>"<"+r+n.replace(/="([^"]*)"/g,"='$1'")+">"),"cleanupText"),WLe=F(e=>{const{text:t,metadata:r}=Ere(e),{displayMode:n,title:A,config:i={}}=r;return n&&(i.gantt||(i.gantt={}),i.gantt.displayMode=n),{title:A,config:i,text:t}},"processFrontmatter"),PLe=F(e=>{const t=zi.detectInit(e)??{},r=zi.detectDirective(e,"wrap");return Array.isArray(r)?t.wrap=r.some(({type:n})=>n==="wrap"):(r==null?void 0:r.type)==="wrap"&&(t.wrap=!0),{text:FGe(e),directive:t}},"processDirectives");function Q2(e){const t=OLe(e),r=WLe(t),n=PLe(r.text),A=s2(r.config,n.directive);return e=JLe(n.text),{code:e,title:r.title,config:A}}F(Q2,"preprocessDiagram");function Ire(e){const t=new TextEncoder().encode(e),r=Array.from(t,n=>String.fromCodePoint(n)).join("");return btoa(r)}F(Ire,"toBase64");var KLe=5e4,VLe="graph TB;a[Maximum text size in diagram exceeded];style a fill:#faa",XLe="sandbox",ZLe="loose",qLe="http://www.w3.org/2000/svg",_Le="http://www.w3.org/1999/xlink",$Le="http://www.w3.org/1999/xhtml",e1e="100%",t1e="100%",r1e="border:0;margin:0;",n1e="margin:0",A1e="allow-top-navigation-by-user-activation allow-popups",i1e='The "iframe" tag is not supported by your browser.',a1e=["foreignobject"],s1e=["dominant-baseline"];function M2(e){const t=Q2(e);return uw(),aYe(t.config??{}),t}F(M2,"processAndSetConfigs");async function yre(e,t){_m();try{const{code:r,config:n}=M2(e);return{diagramType:(await Qre(r)).type,config:n}}catch(r){if(t!=null&&t.suppressErrors)return!1;throw r}}F(yre,"parse");var OO=F((e,t,r=[])=>`
|
|
834
834
|
.${e} ${t} { ${r.join(" !important; ")} !important; }`,"cssImportantStyles"),o1e=F((e,t=new Map)=>{var r;let n="";if(e.themeCSS!==void 0&&(n+=`
|
|
@@ -927,7 +927,7 @@ ${e.themeCSS}`),e.fontFamily!==void 0&&(n+=`
|
|
|
927
927
|
from { transform: rotate(0deg); }
|
|
928
928
|
to { transform: rotate(360deg); }
|
|
929
929
|
}
|
|
930
|
-
`})]}),s.title&&$.jsx("h4",{style:{textAlign:"center",marginBottom:s.description?"4px":"12px",marginTop:0,color:T,fontWeight:600,background:"transparent"},children:s.title}),s.description&&$.jsx("p",{style:{textAlign:"center",marginTop:0,marginBottom:"12px",color:R,fontSize:"0.9rem"},children:s.description}),$.jsxs(nOe,{width:"100%",height:p,children:[s.type==="bar"&&$.jsxs(Wqe,{data:s.data,margin:Qe,barCategoryGap:"20%",children:[I&&$.jsx(Fc,{strokeDasharray:"3 3",stroke:H}),$.jsx(Yc,{dataKey:s.xKey||"name",label:ht,...O,...he,tickFormatter:Fe}),$.jsx(oa,{yAxisId:"left",width:80,tickFormatter:pe,...O,children:Oa(x,"left")}),C&&$.jsx(oa,{yAxisId:"right",orientation:"right",width:80,tickFormatter:pe,...O,children:Oa(D,"right")}),$.jsx(Ec,{contentStyle:we,labelStyle:q,itemStyle:be,formatter:Be,labelFormatter:Ke,cursor:ke}),E&&$.jsx($o,{wrapperStyle:er,iconSize:10,iconType:"square"}),Q,m.map(oe=>$.jsx(JD,{name:oe.name,dataKey:oe.key,fill:oe.color,stackId:oe.stackId,yAxisId:oe.yAxisId,radius:[4,4,0,0]},oe.key))]}),s.type==="line"&&$.jsxs(Jqe,{data:s.data,margin:Qe,children:[I&&$.jsx(Fc,{strokeDasharray:"3 3",stroke:H}),$.jsx(Yc,{dataKey:s.xKey||"name",label:ht,...O,...he,tickFormatter:Fe}),$.jsx(oa,{yAxisId:"left",width:80,tickFormatter:pe,...O,children:Oa(x,"left")}),C&&$.jsx(oa,{yAxisId:"right",orientation:"right",width:80,tickFormatter:pe,...O,children:Oa(D,"right")}),$.jsx(Ec,{contentStyle:we,labelStyle:q,itemStyle:be,formatter:Be,labelFormatter:Ke,cursor:ke}),E&&$.jsx($o,{wrapperStyle:er,iconSize:10,iconType:"square"}),Q,m.map(oe=>$.jsx(zD,{name:oe.name,type:"monotone",dataKey:oe.key,stroke:oe.color,yAxisId:oe.yAxisId,strokeWidth:oe.strokeWidth,dot:oe.dot},oe.key))]}),s.type==="area"&&$.jsxs(s_e,{data:s.data,margin:Qe,children:[I&&$.jsx(Fc,{strokeDasharray:"3 3",stroke:H}),$.jsx(Yc,{dataKey:s.xKey||"name",label:ht,...O,...he,tickFormatter:Fe}),$.jsx(oa,{yAxisId:"left",width:80,tickFormatter:pe,...O,children:Oa(x,"left")}),C&&$.jsx(oa,{yAxisId:"right",orientation:"right",width:80,tickFormatter:pe,...O,children:Oa(D,"right")}),$.jsx(Ec,{contentStyle:we,labelStyle:q,itemStyle:be,formatter:Be,labelFormatter:Ke,cursor:ke}),E&&$.jsx($o,{wrapperStyle:er,iconSize:10,iconType:"square"}),Q,m.map(oe=>$.jsx(TD,{name:oe.name,type:"monotone",dataKey:oe.key,stroke:oe.color,yAxisId:oe.yAxisId,fill:oe.color,fillOpacity:oe.opacity,stackId:oe.stackId},oe.key))]}),s.type==="composed"&&$.jsxs(l_e,{data:s.data,margin:Qe,children:[I&&$.jsx(Fc,{strokeDasharray:"3 3",stroke:H}),$.jsx(Yc,{dataKey:s.xKey||"name",label:ht,...O,...he,tickFormatter:Fe}),$.jsx(oa,{yAxisId:"left",width:80,tickFormatter:pe,...O,children:Oa(x,"left")}),C&&$.jsx(oa,{yAxisId:"right",orientation:"right",width:80,tickFormatter:pe,...O,children:Oa(D,"right")}),$.jsx(Ec,{contentStyle:we,labelStyle:q,itemStyle:be,formatter:Be,labelFormatter:Ke,cursor:ke}),E&&$.jsx($o,{wrapperStyle:er,iconSize:10,iconType:"square"}),Q,m.map(oe=>{switch(oe.type){case"line":return $.jsx(zD,{name:oe.name,type:"monotone",dataKey:oe.key,stroke:oe.color,yAxisId:oe.yAxisId,strokeWidth:oe.strokeWidth,dot:oe.dot},oe.key);case"area":return $.jsx(TD,{name:oe.name,type:"monotone",dataKey:oe.key,stroke:oe.color,yAxisId:oe.yAxisId,fill:oe.color,fillOpacity:oe.opacity,stackId:oe.stackId},oe.key);case"scatter":return $.jsx(WD,{name:oe.name,dataKey:oe.key,fill:oe.color,yAxisId:oe.yAxisId},oe.key);default:return $.jsx(JD,{name:oe.name,dataKey:oe.key,fill:oe.color,stackId:oe.stackId,yAxisId:oe.yAxisId,radius:[4,4,0,0]},oe.key)}})]}),s.type==="pie"&&$.jsxs(n_e,{children:[$.jsx(eae,{data:s.data,dataKey:((n=s.dataKeys)==null?void 0:n[0])||"value",nameKey:s.xKey||"name",cx:"50%",cy:"50%",outerRadius:p/3,label:{fill:T},children:s.data.map((oe,rt)=>$.jsx(sg,{fill:w[rt%w.length]},`cell-${rt}`))}),$.jsx(Ec,{contentStyle:we,itemStyle:be,formatter:Be}),E&&$.jsx($o,{wrapperStyle:er,iconSize:10,iconType:"square"})]}),s.type==="scatter"&&$.jsxs(i_e,{margin:Qe,children:[I&&$.jsx(Fc,{strokeDasharray:"3 3",stroke:H}),$.jsx(Yc,{dataKey:s.xKey||"x",label:ht,...O,...he,tickFormatter:Fe}),$.jsx(oa,{dataKey:((A=s.dataKeys)==null?void 0:A[0])||"y",width:80,tickFormatter:pe,...O,children:Oa(x,"left")}),$.jsx(Ec,{contentStyle:we,labelStyle:q,itemStyle:be,formatter:Be,labelFormatter:Ke,cursor:ke}),E&&$.jsx($o,{wrapperStyle:er,iconSize:10,iconType:"square"}),Q,$.jsx(WD,{name:"Data",data:s.data,fill:w[0]})]})]})]})};let Ic=null;const w_e=async()=>{if(typeof window>"u")throw new Error("abcjs requires a browser environment");if(Ic)return Ic;try{const e=await Nt(()=>import("./index-DvNpGWs7-
|
|
930
|
+
`})]}),s.title&&$.jsx("h4",{style:{textAlign:"center",marginBottom:s.description?"4px":"12px",marginTop:0,color:T,fontWeight:600,background:"transparent"},children:s.title}),s.description&&$.jsx("p",{style:{textAlign:"center",marginTop:0,marginBottom:"12px",color:R,fontSize:"0.9rem"},children:s.description}),$.jsxs(nOe,{width:"100%",height:p,children:[s.type==="bar"&&$.jsxs(Wqe,{data:s.data,margin:Qe,barCategoryGap:"20%",children:[I&&$.jsx(Fc,{strokeDasharray:"3 3",stroke:H}),$.jsx(Yc,{dataKey:s.xKey||"name",label:ht,...O,...he,tickFormatter:Fe}),$.jsx(oa,{yAxisId:"left",width:80,tickFormatter:pe,...O,children:Oa(x,"left")}),C&&$.jsx(oa,{yAxisId:"right",orientation:"right",width:80,tickFormatter:pe,...O,children:Oa(D,"right")}),$.jsx(Ec,{contentStyle:we,labelStyle:q,itemStyle:be,formatter:Be,labelFormatter:Ke,cursor:ke}),E&&$.jsx($o,{wrapperStyle:er,iconSize:10,iconType:"square"}),Q,m.map(oe=>$.jsx(JD,{name:oe.name,dataKey:oe.key,fill:oe.color,stackId:oe.stackId,yAxisId:oe.yAxisId,radius:[4,4,0,0]},oe.key))]}),s.type==="line"&&$.jsxs(Jqe,{data:s.data,margin:Qe,children:[I&&$.jsx(Fc,{strokeDasharray:"3 3",stroke:H}),$.jsx(Yc,{dataKey:s.xKey||"name",label:ht,...O,...he,tickFormatter:Fe}),$.jsx(oa,{yAxisId:"left",width:80,tickFormatter:pe,...O,children:Oa(x,"left")}),C&&$.jsx(oa,{yAxisId:"right",orientation:"right",width:80,tickFormatter:pe,...O,children:Oa(D,"right")}),$.jsx(Ec,{contentStyle:we,labelStyle:q,itemStyle:be,formatter:Be,labelFormatter:Ke,cursor:ke}),E&&$.jsx($o,{wrapperStyle:er,iconSize:10,iconType:"square"}),Q,m.map(oe=>$.jsx(zD,{name:oe.name,type:"monotone",dataKey:oe.key,stroke:oe.color,yAxisId:oe.yAxisId,strokeWidth:oe.strokeWidth,dot:oe.dot},oe.key))]}),s.type==="area"&&$.jsxs(s_e,{data:s.data,margin:Qe,children:[I&&$.jsx(Fc,{strokeDasharray:"3 3",stroke:H}),$.jsx(Yc,{dataKey:s.xKey||"name",label:ht,...O,...he,tickFormatter:Fe}),$.jsx(oa,{yAxisId:"left",width:80,tickFormatter:pe,...O,children:Oa(x,"left")}),C&&$.jsx(oa,{yAxisId:"right",orientation:"right",width:80,tickFormatter:pe,...O,children:Oa(D,"right")}),$.jsx(Ec,{contentStyle:we,labelStyle:q,itemStyle:be,formatter:Be,labelFormatter:Ke,cursor:ke}),E&&$.jsx($o,{wrapperStyle:er,iconSize:10,iconType:"square"}),Q,m.map(oe=>$.jsx(TD,{name:oe.name,type:"monotone",dataKey:oe.key,stroke:oe.color,yAxisId:oe.yAxisId,fill:oe.color,fillOpacity:oe.opacity,stackId:oe.stackId},oe.key))]}),s.type==="composed"&&$.jsxs(l_e,{data:s.data,margin:Qe,children:[I&&$.jsx(Fc,{strokeDasharray:"3 3",stroke:H}),$.jsx(Yc,{dataKey:s.xKey||"name",label:ht,...O,...he,tickFormatter:Fe}),$.jsx(oa,{yAxisId:"left",width:80,tickFormatter:pe,...O,children:Oa(x,"left")}),C&&$.jsx(oa,{yAxisId:"right",orientation:"right",width:80,tickFormatter:pe,...O,children:Oa(D,"right")}),$.jsx(Ec,{contentStyle:we,labelStyle:q,itemStyle:be,formatter:Be,labelFormatter:Ke,cursor:ke}),E&&$.jsx($o,{wrapperStyle:er,iconSize:10,iconType:"square"}),Q,m.map(oe=>{switch(oe.type){case"line":return $.jsx(zD,{name:oe.name,type:"monotone",dataKey:oe.key,stroke:oe.color,yAxisId:oe.yAxisId,strokeWidth:oe.strokeWidth,dot:oe.dot},oe.key);case"area":return $.jsx(TD,{name:oe.name,type:"monotone",dataKey:oe.key,stroke:oe.color,yAxisId:oe.yAxisId,fill:oe.color,fillOpacity:oe.opacity,stackId:oe.stackId},oe.key);case"scatter":return $.jsx(WD,{name:oe.name,dataKey:oe.key,fill:oe.color,yAxisId:oe.yAxisId},oe.key);default:return $.jsx(JD,{name:oe.name,dataKey:oe.key,fill:oe.color,stackId:oe.stackId,yAxisId:oe.yAxisId,radius:[4,4,0,0]},oe.key)}})]}),s.type==="pie"&&$.jsxs(n_e,{children:[$.jsx(eae,{data:s.data,dataKey:((n=s.dataKeys)==null?void 0:n[0])||"value",nameKey:s.xKey||"name",cx:"50%",cy:"50%",outerRadius:p/3,label:{fill:T},children:s.data.map((oe,rt)=>$.jsx(sg,{fill:w[rt%w.length]},`cell-${rt}`))}),$.jsx(Ec,{contentStyle:we,itemStyle:be,formatter:Be}),E&&$.jsx($o,{wrapperStyle:er,iconSize:10,iconType:"square"})]}),s.type==="scatter"&&$.jsxs(i_e,{margin:Qe,children:[I&&$.jsx(Fc,{strokeDasharray:"3 3",stroke:H}),$.jsx(Yc,{dataKey:s.xKey||"x",label:ht,...O,...he,tickFormatter:Fe}),$.jsx(oa,{dataKey:((A=s.dataKeys)==null?void 0:A[0])||"y",width:80,tickFormatter:pe,...O,children:Oa(x,"left")}),$.jsx(Ec,{contentStyle:we,labelStyle:q,itemStyle:be,formatter:Be,labelFormatter:Ke,cursor:ke}),E&&$.jsx($o,{wrapperStyle:er,iconSize:10,iconType:"square"}),Q,$.jsx(WD,{name:"Data",data:s.data,fill:w[0]})]})]})]})};let Ic=null;const w_e=async()=>{if(typeof window>"u")throw new Error("abcjs requires a browser environment");if(Ic)return Ic;try{const e=await Nt(()=>import("./index-DvNpGWs7-BlvgI6Oj.js"),[]).then(r=>r.i),t=e.default||e;if(!t)throw new Error("abcjs module is empty");if(typeof t.renderAbc!="function")throw new Error(`renderAbc is not a function. Available methods: ${Object.keys(t).join(", ")}`);return Ic=t,Ic}catch(e){if(typeof window<"u"&&window.ABCJS)return Ic=window.ABCJS,Ic;const t=e instanceof Error?e.message:"Failed to load abcjs";throw new Error(`Failed to load abcjs: ${t}`)}},f_e=e=>{const t=e.trim();return/^[XMTLK]:/m.test(t)||/^X:\d+/m.test(t)},m_e=e=>{const t=e.trim();if(!t.includes("X:")||!/^K:/m.test(t))return!0;const r=t.split(`
|
|
931
931
|
`),n=r[r.length-1].trim();return!!(n.match(/^[A-Z]:?\s*$/)&&n.length<3||n.endsWith("|")&&!n.endsWith("|]")&&!n.endsWith("||")&&n.replace(/\|/g,"").trim().length<2)},E_e=({code:e})=>{const t=y.useRef(null),[r,n]=y.useState(null),[A,i]=y.useState(!0),[a,s]=y.useState(!1),[o,l]=y.useState(!1),[c,u]=y.useState(!1),g=y.useRef(""),d=y.useRef(0),B=y.useRef(null);return y.useEffect(()=>{const h=e.trim();if(!h){i(!1),l(!1),s(!1);return}const f=Date.now(),w=f-d.current,p=e!==g.current;g.current=e,d.current=f;const m=m_e(h),C=p&&w<500&&w>0,E=m||C;if(m){s(!0),i(!0),n(null);return}f_e(e)?(l(!0),n(null),E&&s(!0)):(l(!1),E?(s(!0),n(null)):(n("Unable to detect ABC notation. Expected ABC notation starting with headers like X:, T:, M:, L:, or K:"),i(!1),s(!1)))},[e]),y.useEffect(()=>!o||!e.trim()?void 0:(a&&(B.current&&clearTimeout(B.current),B.current=setTimeout(()=>{s(!1)},400)),(async()=>{try{i(!0);let h=0;const f=10;for(;!t.current&&h<f;)await new Promise(p=>setTimeout(p,50)),h++;if(!t.current)throw new Error("Container element not found after waiting");const w=await w_e();t.current.innerHTML="",w.renderAbc(t.current,e,{responsive:"resize",staffwidth:740,paddingleft:0,paddingright:0,paddingtop:15,paddingbottom:15,scale:1}),n(null),i(!1)}catch(h){const f=h instanceof Error?h.message:"Failed to render ABC notation";n(f),i(!1)}})(),()=>{B.current&&clearTimeout(B.current)}),[e,o,a]),r?$.jsxs("div",{className:"graph-error",children:[$.jsxs("div",{className:"graph-error-header",children:[$.jsx("div",{className:"graph-error-icon",children:"⚠️"}),$.jsxs("div",{className:"graph-error-content",children:[$.jsx("div",{className:"graph-error-title",children:"ABC Notation Rendering Error"}),$.jsx("div",{className:"graph-error-message",children:r})]})]}),$.jsxs("button",{className:"graph-error-toggle",onClick:()=>u(!c),type:"button",children:[c?"Hide":"Show"," Details"]}),c&&$.jsxs("details",{className:"graph-error-details",open:!0,children:[$.jsx("summary",{style:{cursor:"pointer",marginBottom:"8px",fontWeight:500},children:"ABC Notation Code"}),$.jsx("pre",{style:{marginTop:"8px",fontSize:"0.8em",opacity:.8,padding:"8px",background:"rgba(0, 0, 0, 0.05)",borderRadius:"4px",overflow:"auto",maxHeight:"200px"},children:$.jsx("code",{children:e})})]})]}):(A||a)&&!o?$.jsx("div",{className:"graph-container music-container abc-container",children:$.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"30px 20px",color:"var(--md-text-secondary, #6b7280)",minHeight:"120px"},children:[$.jsx("svg",{style:{animation:"spin 1s linear infinite",marginBottom:"10px",width:"28px",height:"28px"},viewBox:"0 0 24 24",fill:"none",children:$.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",strokeDasharray:"32",strokeLinecap:"round"})}),$.jsx("span",{style:{fontWeight:500,fontSize:"14px"},children:a?"Receiving music notation...":"Loading music notation..."}),$.jsx("style",{children:`
|
|
932
932
|
@keyframes spin {
|
|
933
933
|
from { transform: rotate(0deg); }
|
|
@@ -972,9 +972,9 @@ ${cce}`,x_e=()=>{if(typeof document>"u"||document.getElementById(EV))return;cons
|
|
|
972
972
|
{ "name": "REST API", "apiKey": "rest", "apiUrl": "http://localhost:3000" }
|
|
973
973
|
]`;try{const n=JSON.parse(t);if(Array.isArray(n))for(const A of n){const i=e(A);if(i)return i}}catch{}return null}function v_e(){return typeof window<"u"&&k_e(window.ORBIT_CHAT_CONFIG)}function Mt(e,t,r="string"){var o;const n=e==="showGitHubStats"||e==="githubOwner"||e==="githubRepo",A=v_e();if(!n){if(A){const l=(o=window.ORBIT_CHAT_CONFIG)==null?void 0:o[e];return l??t}if(typeof window<"u")switch(e){case"apiUrl":if(window.CHATBOT_API_URL)return window.CHATBOT_API_URL;break;case"defaultKey":if(window.CHATBOT_API_KEY)return window.CHATBOT_API_KEY;break}}const i=S_e[e],s=i?D_e[i]:void 0;if(s!=null&&s!==""){if(r==="boolean")return s==="true";if(r==="number"||r==="numberOrNull"){const l=parseInt(s,10);if(!isNaN(l))return r==="numberOrNull"&&l===0?null:l}else return s}return t}function Wg(e,t){if(e===void 0||e==="")return t===0?null:t;const r=parseInt(e,10);return isNaN(r)||r<0?t===0?null:t:r===0?null:r}function DN(e,t){if(e===void 0||e==="")return t;const r=parseInt(e,10);return isNaN(r)||r<0?t:r}function Vae(e){if(typeof e!="string")return null;const t=e.trim();if(!t)return null;const r=t.toLowerCase();return r==="false"||r==="0"||r==="off"||r==="disabled"?null:t}const Di={apiUrl:Mt("apiUrl",Vl,"string"),defaultKey:Mt("defaultKey","default-key","string"),applicationName:Mt("applicationName","ORBIT Chat","string"),defaultInputPlaceholder:Mt("defaultInputPlaceholder","Message ORBIT...","string"),useLocalApi:Mt("useLocalApi",!1,"boolean"),localApiPath:Mt("localApiPath",void 0,"string"),consoleDebug:Mt("consoleDebug",!1,"boolean"),enableUploadButton:Mt("enableUploadButton",!1,"boolean"),enableAudioOutput:Mt("enableAudioOutput",!1,"boolean"),enableFeedbackButtons:Mt("enableFeedbackButtons",!1,"boolean"),enableConversationThreads:Mt("enableConversationThreads",!0,"boolean"),enableApiMiddleware:Mt("enableApiMiddleware",!1,"boolean"),showGitHubStats:Mt("showGitHubStats",!0,"boolean"),outOfServiceMessage:(()=>{const e=Mt("outOfServiceMessage","","string");return Vae(e)})(),githubOwner:Mt("githubOwner","schmitech","string"),githubRepo:Mt("githubRepo","orbit","string"),maxFilesPerConversation:(()=>{const e=Mt("maxFilesPerConversation","5","string");return DN(e,5)})(),maxFileSizeMB:(()=>{const e=Mt("maxFileSizeMB","50","string");return DN(e,50)})(),maxTotalFiles:(()=>{const e=Mt("maxTotalFiles","100","string");return Wg(e,100)})(),maxConversations:(()=>{const e=Mt("maxConversations","10","string");return Wg(e,10)})(),maxMessagesPerConversation:(()=>{const e=Mt("maxMessagesPerConversation","1000","string");return Wg(e,1e3)})(),maxMessagesPerThread:(()=>{const e=Mt("maxMessagesPerThread","1000","string");return Wg(e,1e3)})(),maxTotalMessages:(()=>{const e=Mt("maxTotalMessages","10000","string");return Wg(e,1e4)})(),maxMessageLength:(()=>{const e=Mt("maxMessageLength","1000","string");return DN(e,1e3)})()};function Hr(){return Mt("apiUrl",Vl,"string")}function ga(e){const t=e==null?void 0:e.trim();return t&&t.length>0?t:Hr()}function wo(){return Mt("defaultKey","default-key","string")}function G_e(){return Mt("applicationName","ORBIT Chat","string")}function Xae(){return Mt("defaultInputPlaceholder","Message ORBIT...","string")}function R_e(){return Mt("useLocalApi",!1,"boolean")}function j_e(){return Mt("localApiPath",void 0,"string")}function z_e(){return Mt("enableUploadButton",!1,"boolean")}function T_e(){return Mt("enableAudioOutput",!1,"boolean")}function L_e(){return Mt("enableFeedbackButtons",!1,"boolean")}function H_e(){return Mt("enableConversationThreads",!0,"boolean")}function lr(){return Mt("enableApiMiddleware",!1,"boolean")}function Pv(){var r;if(!lr())return null;const e=(r=wo())==null?void 0:r.trim();if(e&&e!=="default-key")return e;const t=U_e();return t||(e&&e.length>0?e:null)}function J_e(){return Di.showGitHubStats}function IV(){return Di.githubOwner}function yV(){return Di.githubRepo}function O_e(){const e=Mt("outOfServiceMessage","","string");return Vae(e)}function W_e({audio:e,audioFormat:t="mp3",autoPlay:r=!1,maxSizeMB:n=10}){const A=y.useRef(null),[i,a]=y.useState(!1),[s,o]=y.useState(0),[l,c]=y.useState(0),[u,g]=y.useState(!0),[d,B]=y.useState(null),[h,f]=y.useState(null);y.useEffect(()=>{if(!e)return;let k=null,x=!0;return(async()=>{try{g(!0),B(null),f(null);const H=e.length*3/4/(1024*1024);if(H>n)throw new Error(`Audio file too large (${H.toFixed(1)}MB > ${n}MB limit)`);if(H>2&&(f(`Large audio file (${H.toFixed(1)}MB) - may take time to load`),me("[AudioPlayer] Large audio file detected",{sizeMB:H.toFixed(2)})),!/^[A-Za-z0-9+/=]+$/.test(e.replace(/\s/g,"")))throw new Error("Invalid base64 audio data");const T=atob(e),v=new Uint8Array(T.length);for(let R=0;R<T.length;R++)v[R]=T.charCodeAt(R);const L=t==="mp3"?"audio/mpeg":t==="wav"?"audio/wav":t==="ogg"?"audio/ogg":t==="opus"?"audio/opus":t==="webm"?"audio/webm":`audio/${t}`,J=new Blob([v],{type:L});if(k=URL.createObjectURL(J),!x||!A.current){k&&URL.revokeObjectURL(k);return}A.current.src=k,g(!1),me("[AudioPlayer] Audio loaded successfully",{format:t,mimeType:L,size:J.size}),r&&A.current&&A.current.play().catch(R=>{Uu("[AudioPlayer] Auto-play failed:",R)})}catch{x&&(B("Failed to load audio"),g(!1))}})(),()=>{x=!1,k&&URL.revokeObjectURL(k)}},[e,t,r,n]);const w=()=>{A.current&&o(A.current.duration)},p=()=>{A.current&&c(A.current.currentTime)},m=()=>a(!0),C=()=>a(!1),E=()=>{a(!1),c(0)},I=()=>{A.current&&(i?A.current.pause():A.current.play().catch(k=>{B("Playback failed")}))},Q=k=>{if(!A.current)return;const x=parseFloat(k.target.value);A.current.currentTime=x,c(x)},N=k=>{if(!isFinite(k))return"0:00";const x=Math.floor(k/60),D=Math.floor(k%60);return`${x}:${D.toString().padStart(2,"0")}`};return d?b.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-red-300 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-700 dark:bg-red-900/20 dark:text-red-400",children:[b.jsx(_0,{className:"h-4 w-4"}),b.jsx("span",{children:d})]}):b.jsxs("div",{className:"mt-3 flex flex-col gap-1",children:[h&&b.jsxs("div",{className:"text-xs text-amber-600 dark:text-amber-400 px-1",children:["⚠️ ",h]}),b.jsxs("div",{className:"flex items-center gap-3 rounded-md border border-gray-300 bg-white px-3 py-2 dark:border-[#4a4b54] dark:bg-[#343541]",children:[b.jsx("audio",{ref:A,onLoadedMetadata:w,onTimeUpdate:p,onPlay:m,onPause:C,onEnded:E}),b.jsx("button",{onClick:I,disabled:u,className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-full bg-gray-200 hover:bg-gray-300 disabled:opacity-50 dark:bg-[#4a4b54] dark:hover:bg-[#565869]",title:i?"Pause":"Play",children:u?b.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-gray-400 border-t-transparent"}):i?b.jsx(Kle,{className:"h-4 w-4 text-gray-700 dark:text-[#ececf1]"}):b.jsx(Xle,{className:"h-4 w-4 text-gray-700 dark:text-[#ececf1]"})}),b.jsxs("div",{className:"flex flex-1 items-center gap-2",children:[b.jsx("span",{className:"text-xs text-gray-500 dark:text-[#bfc2cd]",children:N(l)}),b.jsx("input",{type:"range",min:"0",max:s||0,value:l,onChange:Q,disabled:u||!s,className:"flex-1 cursor-pointer accent-gray-600 dark:accent-[#bfc2cd]",style:{background:s?`linear-gradient(to right, rgb(75 85 99) 0%, rgb(75 85 99) ${l/s*100}%, rgb(229 231 235) ${l/s*100}%, rgb(229 231 235) 100%)`:"rgb(229 231 235)"}}),b.jsx("span",{className:"text-xs text-gray-500 dark:text-[#bfc2cd]",children:N(s)})]}),b.jsx(_0,{className:"h-4 w-4 text-gray-500 dark:text-[#bfc2cd]"})]})]})}const P_e=["#","*","`","[","]","(",")","{","}","|","<",">"],Zae=e=>P_e.some(t=>e.includes(t));function qae(e){if(!e||e.length<1e3)return!1;const t=/^[A-Za-z0-9+/=]+$/,r=e.replace(/\s+/g,"");if(r.length>1e4&&t.test(r)){const n=/\b(the|and|for|are|but|not|you|all|can|function|const|let|var|class|return|import|export|async|await|if|else|while|true|false|null|undefined|http|https|www|error|data|response|request|api|json|xml|html|css|js|py|java|cpp|def|print|console|log)\b/i.test(e),A=Zae(e),i=/[.,;:!?'"()-]/.test(e);if(!n&&!A&&!i)return!0}return!!(r.length>5e4&&t.test(r)&&e.replace(/[A-Za-z0-9+/=\s]/g,"").length<10)}function Gd(e){if(!e)return e;if(qae(e))return"";const t=/([A-Za-z0-9+/=]{10000,})/g;return e.replace(t,n=>{const A=n.replace(/\s+/g,"");if(A.length>1e4&&/^[A-Za-z0-9+/=]+$/.test(A)){const i=/\b(function|const|let|var|class|return|import|export|if|else|while|for|true|false|null|def|print)\b/i.test(n),a=Zae(n),s=/[.,;:!?'"()-]/.test(n);if(!i&&!a&&!s)return""}return n})}function _D(e,t=5e4){return!e||e.length<=t?e:qae(e)?"":e.substring(0,t)+`
|
|
974
974
|
|
|
975
|
-
... (content truncated due to length)`}const ot={maxFilesPerConversation:Di.maxFilesPerConversation,maxFileSizeMB:Di.maxFileSizeMB,maxTotalFiles:Di.maxTotalFiles,maxConversations:Di.maxConversations,maxMessagesPerConversation:Di.maxMessagesPerConversation,maxMessagesPerThread:Di.maxMessagesPerThread,maxTotalMessages:Di.maxTotalMessages,maxMessageLength:Di.maxMessageLength},K_e=[];function V_e({message:e,onRegenerate:t,onStartThread:r,onSendThreadMessage:n,threadMessages:A,sessionId:i,isThreadSendDisabled:a}){var xe,Le;const[s,o]=y.useState(!1),[l,c]=y.useState(null),[u,g]=y.useState(""),[d,B]=y.useState(!1),[h,f]=y.useState(!1),w=y.useRef(((xe=e.threadInfo)==null?void 0:xe.thread_id)||null),p=y.useRef(null),m=y.useRef(null),C=y.useRef(""),E=e.role==="assistant",I=A??K_e,Q=I.filter(Fe=>Fe.role==="assistant").length,N=I.filter(Fe=>!(Fe.role==="assistant"&&Fe.isStreaming)).length,k=I.some(Fe=>Fe.isStreaming),x="en-US",D=H_e(),z=ot.maxMessageLength,H=ot.maxMessagesPerThread,T=H!==null&&N>=H,v=T&&H!==null?`This thread reached the ${H} message limit. Start a new conversation for more follow-ups.`:null,{theme:L,isDark:J}=$f(),R=L.mode==="dark"?"dark":L.mode==="light"?"light":"",O=J?"dark":"light",U=y.useMemo(()=>["message-markdown w-full min-w-0","prose prose-slate dark:prose-invert max-w-none",R].filter(Boolean).join(" "),[R]),K=y.useMemo(()=>["message-markdown w-full min-w-0","prose prose-invert max-w-none",R].filter(Boolean).join(" "),[R]),Ae=E?U:K,G=`${U} text-sm leading-6`,X=`${K} text-sm leading-6`;y.useEffect(()=>{var Fe,Ke;!w.current&&((Fe=e.threadInfo)!=null&&Fe.thread_id)&&B(!0),w.current=((Ke=e.threadInfo)==null?void 0:Ke.thread_id)||null},[(Le=e.threadInfo)==null?void 0:Le.thread_id]),y.useEffect(()=>{e.threadInfo||(g(""),B(!1),f(!1))},[e.threadInfo]),y.useEffect(()=>{Q>0&&B(!0)},[Q]),y.useEffect(()=>{if(!d||I.length===0)return;const Fe=I[I.length-1],Ke=(Fe==null?void 0:Fe.content)||"",st=Ke!==C.current;((Fe==null?void 0:Fe.isStreaming)||st)&&requestAnimationFrame(()=>{m.current&&(m.current.scrollTop=m.current.scrollHeight)}),C.current=Ke},[d,I]);const ie=y.useMemo(()=>{const Fe=e.timestamp instanceof Date?e.timestamp:new Date(e.timestamp),Ke=Fe.toLocaleDateString(x,{weekday:"short"}),st=Fe.toLocaleDateString(x,{month:"short"}),Ot=Fe.getDate().toString().padStart(2,"0"),en=Fe.getFullYear(),vr=Fe.toLocaleTimeString(x,{hour:"2-digit",minute:"2-digit",hour12:!0});return`${Ke}, ${st} ${Ot}, ${en} ${vr}`},[e.timestamp,x]),ae=E?"bg-gradient-to-br from-blue-100 to-blue-200 text-blue-900 dark:from-[#1f2a36] dark:to-[#1a2230] dark:text-[#c5d7ff]":"bg-gradient-to-br from-emerald-100 to-emerald-200 text-emerald-900 dark:from-[#0f1f17] dark:to-[#0b1712] dark:text-[#c7f5df]",le=`message-bubble min-w-0 break-words leading-relaxed ${E?"border border-blue-100/80 bg-transparent text-[#0f172a] shadow-[0_15px_35px_-20px_rgba(15,23,42,0.25)] dark:border-[#1f2a36] dark:bg-transparent dark:text-[#e5edff]":"border border-emerald-100 bg-transparent text-[#1c3226] shadow-[0_12px_30px_-18px_rgba(15,52,33,0.25)] dark:border-[#1a2b21] dark:bg-transparent dark:text-[#dffbea]"} rounded-2xl px-4 py-3`,ge=E?"border-blue-100 bg-white/80 dark:border-[#1f2a36] dark:bg-white/5":"border-emerald-100 bg-white/80 dark:border-[#1a2b21] dark:bg-white/5",te=async()=>{try{await navigator.clipboard.writeText(e.content),o(!0),setTimeout(()=>o(!1),2e3)}catch{}},he=Fe=>{c(l===Fe?null:Fe)},we=y.useCallback(Fe=>(Fe instanceof Date?Fe:new Date(Fe)).toLocaleTimeString(x,{hour:"2-digit",minute:"2-digit"}),[x]),q=async()=>{if(!n||!e.threadInfo||T)return;const Fe=u.trim();if(Fe){f(!0);try{await n(e.threadInfo.thread_id,e.id,Fe),g(""),setTimeout(()=>{p.current&&p.current.focus()},100)}catch{setTimeout(()=>{p.current&&p.current.focus()},100)}finally{f(!1)}}},be=Fe=>{Fe.key==="Enter"&&!Fe.shiftKey&&(Fe.preventDefault(),q())},ke=!e.threadInfo||!n||a||k||h||T;y.useEffect(()=>{if(!d||ke)return;const Fe=p.current;if(!Fe)return;const Ke=requestAnimationFrame(()=>{Fe.focus();const st=Fe.value.length;Fe.setSelectionRange(st,st)});return()=>cancelAnimationFrame(Ke)},[d,ke,h]),y.useEffect(()=>{if(p.current){const Ke=p.current;Ke.style.height="auto";const st=Ke.scrollHeight;Ke.style.height=`${Math.min(st,120)}px`,Ke.style.overflowY=st>120?"auto":"hidden"}},[u]);const Be=y.useMemo(()=>e.isStreaming&&(!e.content||e.content==="…")?b.jsx("div",{className:Ae,children:b.jsxs("div",{className:"flex items-center gap-1.5 py-1",children:[b.jsx("span",{className:"inline-block h-2.5 w-2.5 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"0ms"}}),b.jsx("span",{className:"inline-block h-2.5 w-2.5 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"150ms"}}),b.jsx("span",{className:"inline-block h-2.5 w-2.5 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"300ms"}})]})}):b.jsx(Sf,{content:_D(Gd(e.content||"")),className:Ae,syntaxTheme:O}),[Ae,e.content,e.isStreaming,O]),pe=y.useMemo(()=>[...I].sort((Ke,st)=>{const Ot=Ke.timestamp instanceof Date?Ke.timestamp.getTime():new Date(Ke.timestamp).getTime(),en=st.timestamp instanceof Date?st.timestamp.getTime():new Date(st.timestamp).getTime();return Ot-en}).map(Ke=>{const st=Ke.role==="assistant",Ot=st?G:X,en=Ke.isStreaming&&(!Ke.content||Ke.content==="…")?b.jsx("div",{className:Ot,children:b.jsxs("div",{className:"flex items-center gap-1.5 py-1",children:[b.jsx("span",{className:"inline-block h-2 w-2 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"0ms"}}),b.jsx("span",{className:"inline-block h-2 w-2 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"150ms"}}),b.jsx("span",{className:"inline-block h-2 w-2 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"300ms"}})]})}):b.jsx(Sf,{content:_D(Gd(Ke.content||"")),className:Ot,syntaxTheme:O});return b.jsxs("div",{className:"flex items-start gap-3",children:[b.jsx("div",{className:`mt-0.5 flex h-7 w-7 flex-shrink-0 items-center justify-center rounded-full ${st?"bg-blue-100 text-blue-700 dark:bg-[#1f2a36] dark:text-[#c5d7ff]":"bg-emerald-100 text-emerald-700 dark:bg-[#1f2a36] dark:text-[#9ef0d5]"}`,children:st?b.jsx(iR,{className:"h-3.5 w-3.5"}):b.jsx(aR,{className:"h-3.5 w-3.5"})}),b.jsxs("div",{className:"flex-1 min-w-0 rounded-2xl border border-white/70 bg-white/90 px-4 py-3 text-sm shadow-sm dark:border-white/5 dark:bg-white/5 backdrop-blur overflow-hidden",children:[b.jsxs("div",{className:"mb-1 flex items-center justify-between text-[11px] font-semibold uppercase tracking-wide text-blue-900/70 dark:text-[#c5d7ff]",children:[b.jsx("span",{children:st?"Assistant":"You"}),b.jsx("span",{children:we(Ke.timestamp)})]}),b.jsx("div",{className:"thread-markdown-wrapper overflow-x-auto",children:en})]})]},Ke.id)}),[we,O,G,I,X]);return b.jsxs("div",{className:"group flex items-start gap-3 px-1 animate-fadeIn min-w-0 sm:px-0",children:[b.jsx("div",{className:`flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-full self-start -mt-2 ml-1 shadow-sm ring-2 ring-white/50 dark:ring-white/10 sm:-mt-3 sm:ml-2 ${ae}`,children:E?b.jsx(iR,{className:"h-5 w-5"}):b.jsx(aR,{className:"h-5 w-5"})}),b.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[b.jsxs("div",{className:"flex flex-col gap-1.5 mb-1",children:[b.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-gray-700 dark:text-[#ececf1]",children:E?"Assistant":"You"}),b.jsx("span",{className:"text-xs text-gray-500 dark:text-[#bfc2cd]",children:ie})]}),b.jsxs("div",{className:le,children:[Be,e.attachments&&e.attachments.length>0&&b.jsx("div",{className:"mt-3 space-y-2",children:e.attachments.map(Fe=>b.jsxs("div",{className:`flex items-center gap-3 rounded-xl border p-3 ${ge}`,children:[b.jsx(zle,{className:"h-4 w-4 text-gray-500 dark:text-[#bfc2cd]"}),b.jsxs("div",{className:"min-w-0 flex-1",children:[b.jsx("p",{className:"truncate text-sm font-medium text-[#353740] dark:text-[#ececf1]",children:Fe.filename}),b.jsxs("p",{className:"text-xs text-gray-500 dark:text-[#bfc2cd]",children:[(Fe.file_size/1024).toFixed(1)," KB"]})]})]},Fe.file_id))}),e.audio&&E&&!e.isStreaming&&b.jsx(W_e,{audio:e.audio,audioFormat:e.audioFormat,autoPlay:!1})]}),E&&!e.isStreaming&&b.jsxs("div",{className:"flex items-center gap-1 md:gap-2 text-xs text-gray-500 transition-opacity dark:text-[#bfc2cd] sm:opacity-0 sm:group-hover:opacity-100",children:[b.jsxs("button",{onClick:te,className:"inline-flex items-center gap-1 rounded px-2 py-1 hover:bg-gray-200 dark:hover:bg-[#3c3f4a]",title:"Copy message",children:[b.jsx(Gle,{className:"h-4 w-4"}),b.jsx("span",{className:"hidden sm:inline",children:"Copy"})]}),t&&b.jsxs("button",{onClick:()=>t(e.id),className:"inline-flex items-center gap-1 rounded px-2 py-1 hover:bg-gray-200 dark:hover:bg-[#3c3f4a]",title:"Regenerate response",children:[b.jsx(_le,{className:"h-4 w-4"}),b.jsx("span",{className:"hidden sm:inline",children:"Retry"})]}),D&&r&&e.supportsThreading&&!e.threadInfo&&i&&b.jsxs("button",{onClick:()=>r(e.id,i),className:"inline-flex items-center gap-1 rounded px-2 py-1 hover:bg-gray-200 dark:hover:bg-[#3c3f4a]",title:"Start thread for follow-up questions",children:[b.jsx(q0,{className:"h-4 w-4"}),b.jsx("span",{className:"hidden sm:inline",children:"Start Thread"})]}),L_e()&&b.jsxs("div",{className:"flex items-center gap-1",children:[b.jsx("button",{onClick:()=>he("up"),className:`rounded p-1 hover:bg-gray-200 dark:hover:bg-[#3c3f4a] ${l==="up"?"text-[#353740] dark:text-[#ececf1]":""}`,title:"Good response",children:b.jsx(tce,{className:"h-4 w-4"})}),b.jsx("button",{onClick:()=>he("down"),className:`rounded p-1 hover:bg-gray-200 dark:hover:bg-[#3c3f4a] ${l==="down"?"text-[#353740] dark:text-[#ececf1]":""}`,title:"Poor response",children:b.jsx(ece,{className:"h-4 w-4"})})]}),s&&b.jsx("span",{children:"Copied"})]}),D&&e.threadInfo&&b.jsxs("div",{className:"thread-panel mt-4 rounded-xl border border-blue-100/80 bg-blue-50/70 p-3 sm:p-4 text-sm shadow-sm ring-1 ring-blue-100/60 dark:border-[#1f2a36] dark:bg-[#0f1821] dark:ring-[#1f2a36]",children:[b.jsxs("div",{className:"flex items-center justify-between gap-2 text-sm font-semibold text-blue-900 dark:text-[#c5d7ff]",children:[b.jsxs("div",{className:"inline-flex items-center gap-2 uppercase tracking-wide text-xs sm:text-sm",children:[b.jsx(q0,{className:"h-3.5 w-3.5"}),b.jsxs("span",{children:["Thread",Q>0?` (${Q})`:""]})]}),b.jsx("button",{onClick:()=>B(Fe=>!Fe),className:"inline-flex items-center gap-1.5 sm:gap-2 rounded-full border border-blue-200/80 px-2.5 sm:px-3 py-1.5 text-xs uppercase tracking-wide text-blue-900 transition hover:bg-white/70 dark:border-[#233449] dark:text-[#c5d7ff] dark:hover:bg-white/10",children:d?b.jsxs(b.Fragment,{children:[b.jsx("span",{className:"hidden sm:inline",children:"Hide"}),b.jsx(vle,{className:"h-4 w-4 sm:h-3 sm:w-3"})]}):b.jsxs(b.Fragment,{children:[b.jsx("span",{className:"hidden sm:inline",children:"Show"}),b.jsx(X6,{className:"h-4 w-4 sm:h-3 sm:w-3"})]})})]}),d&&b.jsxs(b.Fragment,{children:[b.jsx("div",{ref:m,className:"mt-3 space-y-3 max-h-96 overflow-y-auto scroll-smooth",style:{scrollBehavior:"auto"},children:pe}),v&&b.jsx("div",{className:"mt-3 rounded-md border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-900 dark:border-amber-500/30 dark:bg-[#2f2410] dark:text-amber-100",children:v}),b.jsx("div",{className:"mt-3 rounded-xl border border-white/80 bg-white/95 p-3 shadow-sm dark:border-white/10 dark:bg-white/10",children:b.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-3",children:[b.jsx("textarea",{ref:p,className:"flex-1 w-full sm:w-auto min-w-0 resize-none rounded-lg border border-gray-200 bg-gray-50 px-3 py-2.5 text-base sm:text-sm text-[#353740] placeholder-gray-500 outline-none transition focus:border-gray-400 focus:ring-1 focus:ring-gray-300 disabled:opacity-60 dark:border-[#3c3f4a] dark:bg-[#2d2f39] dark:text-[#ececf1] dark:placeholder-[#8e8ea0] dark:focus:border-[#8e8ea0] dark:focus:ring-[#8e8ea0]",placeholder:Q>0?"Reply in thread...":"Ask a follow-up...",value:u,onChange:Fe=>g(Fe.target.value),onKeyDown:be,disabled:ke,rows:1,maxLength:z,style:{minHeight:"44px",maxHeight:"120px",outline:"none",boxShadow:"none",WebkitAppearance:"none",MozAppearance:"none",appearance:"none"}}),b.jsxs("div",{className:"flex items-center justify-between sm:justify-end gap-2",children:[u.length>0&&b.jsx("div",{className:"text-xs text-gray-500 dark:text-[#bfc2cd] whitespace-nowrap",children:b.jsxs("span",{className:u.length>=z?"text-red-600 font-semibold":"",children:[u.length,"/",z]})}),b.jsx("button",{type:"button",onClick:q,disabled:ke||u.trim().length===0,className:`flex h-11 w-11 sm:h-9 sm:w-9 items-center justify-center rounded-full transition active:scale-95 ${u.trim().length>0&&!ke?"bg-[#10a37f] text-white hover:bg-[#0f8f6f]":"bg-gray-200 text-gray-400 dark:bg-[#2f313a] dark:text-[#6b6f7a]"} disabled:cursor-not-allowed`,title:"Send thread message",children:h?b.jsx(_c,{className:"h-5 w-5 sm:h-4 sm:w-4 animate-spin"}):b.jsx(V6,{className:"h-5 w-5 sm:h-4 sm:w-4"})})]})]})})]})]})]})]})}function X_e(e=800,t=100,r="sine"){try{if(typeof window>"u"){me("[SoundEffects] Window is not available for audio playback");return}const n=window.AudioContext??window.webkitAudioContext;if(!n){me("[SoundEffects] AudioContext not supported in this browser");return}const A=new n,i=A.createOscillator(),a=A.createGain();i.connect(a),a.connect(A.destination),i.frequency.value=e,i.type=r,a.gain.setValueAtTime(.3,A.currentTime),a.gain.exponentialRampToValueAtTime(.01,A.currentTime+t/1e3),i.start(A.currentTime),i.stop(A.currentTime+t/1e3)}catch{}}const Z_e={messageSent:{frequency:600,duration:80,type:"sine"},messageReceived:{frequency:800,duration:100,type:"sine"},success:{frequency:1e3,duration:150,type:"sine"},error:{frequency:400,duration:200,type:"square"},notification:{frequency:700,duration:120,type:"sine"}};function cd(e,t){if(!t)return;const r=Z_e[e];if(r)try{X_e(r.frequency,r.duration,r.type),me(`[SoundEffects] Playing ${e} sound effect`)}catch{}}function q_e({messages:e,onRegenerate:t,onStartThread:r,onSendThreadMessage:n,sessionId:A,isLoading:i}){const a=y.useRef(null),s=y.useRef(null),o=y.useRef(e.length),l=y.useRef(""),c=y.useRef(i),u=y.useRef(!0),{settings:g}=em(),{topLevelMessages:d,threadLookup:B}=y.useMemo(()=>{const w=new Map,p=[];return e.forEach(m=>{if(m.isThreadMessage&&m.parentMessageId){const C=w.get(m.parentMessageId)||[];w.set(m.parentMessageId,[...C,m]);return}p.push(m)}),{topLevelMessages:p,threadLookup:w}},[e]),h=()=>{if(!s.current)return;const{scrollTop:w,scrollHeight:p,clientHeight:m}=s.current,E=p-w-m<200;u.current=E},f=y.useCallback(()=>{requestAnimationFrame(()=>{s.current&&(s.current.scrollTop=s.current.scrollHeight)})},[]);return y.useEffect(()=>{const w=e.length,p=o.current,m=w>p,C=e[e.length-1],E=(C==null?void 0:C.content)||"",I=E!==l.current,Q=(C==null?void 0:C.isStreaming)??!1;m||Q&&I?(f(),u.current=!0):u.current&&I&&f(),o.current=w,l.current=E},[e,f]),y.useEffect(()=>{i&&(f(),u.current=!0)},[i,f]),y.useEffect(()=>{if(c.current&&!i){const w=e[e.length-1];(w==null?void 0:w.role)==="assistant"&&w.content&&cd("messageReceived",g.soundEnabled)}c.current=i},[i,e,g.soundEnabled]),d.length===0?b.jsx("div",{className:"flex-1 flex items-center justify-center px-4 sm:px-6",children:b.jsxs("div",{className:"text-center text-lg text-gray-500 dark:text-[#bfc2cd]",children:[b.jsx("p",{className:"text-xl",children:"Your messages will appear here."}),b.jsx("p",{className:"mt-1 text-lg",children:"Start the conversation by sending a prompt below."})]})}):b.jsx("div",{ref:s,className:"message-list flex-1 overflow-y-auto py-6",onScroll:h,children:b.jsxs("div",{className:"space-y-6 px-3 sm:px-4",children:[d.map(w=>b.jsx(V_e,{message:w,onRegenerate:t,onStartThread:r,onSendThreadMessage:n,threadMessages:B.get(w.id),sessionId:A,isThreadSendDisabled:i},w.id)),b.jsx("div",{ref:a,className:"h-8"})]})})}const __e=2e3;function $_e(e,t){const[r,n]=y.useState(!1),[A,i]=y.useState(null),a=y.useRef(null),s=y.useRef(""),o=y.useRef(!1),l=y.useRef(null),c=y.useCallback(()=>{if(!s.current)return;const w=s.current;s.current="",e(" "+w)},[e]),u=typeof window<"u"&&("webkitSpeechRecognition"in window||"SpeechRecognition"in window),g=y.useCallback(()=>{!t||o.current||(o.current=!0,t())},[t]),d=y.useCallback(()=>{l.current!==null&&(clearTimeout(l.current),l.current=null)},[]),B=y.useCallback(()=>{d(),l.current=setTimeout(()=>{a.current?a.current.stop():g()},__e)},[d,g]),h=y.useCallback(()=>{if(!u){i("Speech recognition is not supported in this browser. Please try Chrome, Edge, or Safari.");return}if(!r)try{o.current=!1;const w=window.SpeechRecognition||window.webkitSpeechRecognition,p=new w;p.continuous=!0,p.interimResults=!0,p.lang=navigator.language||"en-US",p.maxAlternatives=1,p.onstart=()=>{n(!0),i(null),me("Speech recognition started"),B()},p.onresult=m=>{let C="",E="";for(let I=m.resultIndex;I<m.results.length;I++){const Q=m.results[I][0].transcript;m.results[I].isFinal?C+=Q:E+=Q}E&&(s.current=E),C&&(s.current="",e(" "+C)),B()},p.onend=()=>{d(),c(),n(!1),a.current=null,me("Speech recognition ended"),g()},p.onerror=m=>{switch(d(),Uu("Speech recognition error:",m.error),n(!1),a.current=null,s.current="",g(),m.error){case"no-speech":i("No speech detected. Please try again.");break;case"audio-capture":i("Microphone access denied. Please allow microphone access and try again.");break;case"not-allowed":i("Microphone access not allowed. Please enable microphone permissions.");break;case"network":i("Network error occurred. Please check your connection.");break;default:i(`Speech recognition error: ${m.error}`)}},p.start(),a.current=p}catch{i("Failed to start speech recognition. Please try again."),n(!1)}},[u,e,r,c,g,B,d]),f=y.useCallback(()=>{if(a.current){const w=a.current;w.onend=null,w.onerror=null,w.onresult=null,w.onstart=null;try{w.stop()}catch{}a.current=null}d(),c(),n(!1),i(null),g()},[d,c,g]);return{isListening:r,isSupported:u,startListening:h,stopListening:f,error:A}}const e$e="2.8.0",t$e={"@schmitech/chatbot-api":"^2.1.4"},_ae={version:e$e,dependencies:t$e},$ae=_ae.version,CV=_ae.dependencies["@schmitech/chatbot-api"];async function $D(){try{return(await Nt(()=>import("./api-XcRutblh.js"),[])).version||CV}catch{return CV}}async function ese(){const e=await $D();return{appVersion:$ae,apiVersion:e,isLocalApi:!1}}let Wa=null;function Pg(){let e=null,t=null;const r=(A,i,a,s)=>{e=a||null,t=s||null},n=()=>{if(!t)throw new Error("Adapter name is required when middleware is enabled");return{async*streamChat(A,i,a,s,o,l,c,u,g,d,B){var w,p;const h={messages:[{role:"user",content:A}],stream:i!==!1};a&&a.length>0&&(h.file_ids=a),s&&(h.thread_id=s),o&&(h.audio_input=o),l&&(h.audio_format=l),c&&(h.language=c),u!==void 0&&(h.return_audio=u),g&&(h.tts_voice=g),d&&(h.source_language=d),B&&(h.target_language=B);const f=await fetch("/api/v1/chat",{method:"POST",headers:{"Content-Type":"application/json","X-Adapter-Name":t,...e?{"X-Session-ID":e}:{}},body:JSON.stringify(h)});if(!f.ok)throw new Error(`API request failed: ${f.status} ${f.statusText}`);if((w=f.headers.get("content-type"))!=null&&w.includes("text/event-stream")){const m=(p=f.body)==null?void 0:p.getReader(),C=new TextDecoder;let E="";if(!m)throw new Error("Response body is not readable");for(;;){const{done:I,value:Q}=await m.read();if(I)break;E+=C.decode(Q,{stream:!0});const N=E.split(`
|
|
975
|
+
... (content truncated due to length)`}const ot={maxFilesPerConversation:Di.maxFilesPerConversation,maxFileSizeMB:Di.maxFileSizeMB,maxTotalFiles:Di.maxTotalFiles,maxConversations:Di.maxConversations,maxMessagesPerConversation:Di.maxMessagesPerConversation,maxMessagesPerThread:Di.maxMessagesPerThread,maxTotalMessages:Di.maxTotalMessages,maxMessageLength:Di.maxMessageLength},K_e=[];function V_e({message:e,onRegenerate:t,onStartThread:r,onSendThreadMessage:n,threadMessages:A,sessionId:i,isThreadSendDisabled:a}){var xe,Le;const[s,o]=y.useState(!1),[l,c]=y.useState(null),[u,g]=y.useState(""),[d,B]=y.useState(!1),[h,f]=y.useState(!1),w=y.useRef(((xe=e.threadInfo)==null?void 0:xe.thread_id)||null),p=y.useRef(null),m=y.useRef(null),C=y.useRef(""),E=e.role==="assistant",I=A??K_e,Q=I.filter(Fe=>Fe.role==="assistant").length,N=I.filter(Fe=>!(Fe.role==="assistant"&&Fe.isStreaming)).length,k=I.some(Fe=>Fe.isStreaming),x="en-US",D=H_e(),z=ot.maxMessageLength,H=ot.maxMessagesPerThread,T=H!==null&&N>=H,v=T&&H!==null?`This thread reached the ${H} message limit. Start a new conversation for more follow-ups.`:null,{theme:L,isDark:J}=$f(),R=L.mode==="dark"?"dark":L.mode==="light"?"light":"",O=J?"dark":"light",U=y.useMemo(()=>["message-markdown w-full min-w-0","prose prose-slate dark:prose-invert max-w-none",R].filter(Boolean).join(" "),[R]),K=y.useMemo(()=>["message-markdown w-full min-w-0","prose prose-invert max-w-none",R].filter(Boolean).join(" "),[R]),Ae=E?U:K,G=`${U} text-sm leading-6`,X=`${K} text-sm leading-6`;y.useEffect(()=>{var Fe,Ke;!w.current&&((Fe=e.threadInfo)!=null&&Fe.thread_id)&&B(!0),w.current=((Ke=e.threadInfo)==null?void 0:Ke.thread_id)||null},[(Le=e.threadInfo)==null?void 0:Le.thread_id]),y.useEffect(()=>{e.threadInfo||(g(""),B(!1),f(!1))},[e.threadInfo]),y.useEffect(()=>{Q>0&&B(!0)},[Q]),y.useEffect(()=>{if(!d||I.length===0)return;const Fe=I[I.length-1],Ke=(Fe==null?void 0:Fe.content)||"",st=Ke!==C.current;((Fe==null?void 0:Fe.isStreaming)||st)&&requestAnimationFrame(()=>{m.current&&(m.current.scrollTop=m.current.scrollHeight)}),C.current=Ke},[d,I]);const ie=y.useMemo(()=>{const Fe=e.timestamp instanceof Date?e.timestamp:new Date(e.timestamp),Ke=Fe.toLocaleDateString(x,{weekday:"short"}),st=Fe.toLocaleDateString(x,{month:"short"}),Ot=Fe.getDate().toString().padStart(2,"0"),en=Fe.getFullYear(),vr=Fe.toLocaleTimeString(x,{hour:"2-digit",minute:"2-digit",hour12:!0});return`${Ke}, ${st} ${Ot}, ${en} ${vr}`},[e.timestamp,x]),ae=E?"bg-gradient-to-br from-blue-100 to-blue-200 text-blue-900 dark:from-[#1f2a36] dark:to-[#1a2230] dark:text-[#c5d7ff]":"bg-gradient-to-br from-emerald-100 to-emerald-200 text-emerald-900 dark:from-[#0f1f17] dark:to-[#0b1712] dark:text-[#c7f5df]",le=`message-bubble min-w-0 break-words leading-relaxed ${E?"border border-blue-100/80 bg-transparent text-[#0f172a] shadow-[0_15px_35px_-20px_rgba(15,23,42,0.25)] dark:border-[#1f2a36] dark:bg-transparent dark:text-[#e5edff]":"border border-emerald-100 bg-transparent text-[#1c3226] shadow-[0_12px_30px_-18px_rgba(15,52,33,0.25)] dark:border-[#1a2b21] dark:bg-transparent dark:text-[#dffbea]"} rounded-2xl px-4 py-3`,ge=E?"border-blue-100 bg-white/80 dark:border-[#1f2a36] dark:bg-white/5":"border-emerald-100 bg-white/80 dark:border-[#1a2b21] dark:bg-white/5",te=async()=>{try{await navigator.clipboard.writeText(e.content),o(!0),setTimeout(()=>o(!1),2e3)}catch{}},he=Fe=>{c(l===Fe?null:Fe)},we=y.useCallback(Fe=>(Fe instanceof Date?Fe:new Date(Fe)).toLocaleTimeString(x,{hour:"2-digit",minute:"2-digit"}),[x]),q=async()=>{if(!n||!e.threadInfo||T)return;const Fe=u.trim();if(Fe){f(!0);try{await n(e.threadInfo.thread_id,e.id,Fe),g(""),setTimeout(()=>{p.current&&p.current.focus()},100)}catch{setTimeout(()=>{p.current&&p.current.focus()},100)}finally{f(!1)}}},be=Fe=>{Fe.key==="Enter"&&!Fe.shiftKey&&(Fe.preventDefault(),q())},ke=!e.threadInfo||!n||a||k||h||T;y.useEffect(()=>{if(!d||ke)return;const Fe=p.current;if(!Fe)return;const Ke=requestAnimationFrame(()=>{Fe.focus();const st=Fe.value.length;Fe.setSelectionRange(st,st)});return()=>cancelAnimationFrame(Ke)},[d,ke,h]),y.useEffect(()=>{if(p.current){const Ke=p.current;Ke.style.height="auto";const st=Ke.scrollHeight;Ke.style.height=`${Math.min(st,120)}px`,Ke.style.overflowY=st>120?"auto":"hidden"}},[u]);const Be=y.useMemo(()=>e.isStreaming&&(!e.content||e.content==="…")?b.jsx("div",{className:Ae,children:b.jsxs("div",{className:"flex items-center gap-1.5 py-1",children:[b.jsx("span",{className:"inline-block h-2.5 w-2.5 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"0ms"}}),b.jsx("span",{className:"inline-block h-2.5 w-2.5 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"150ms"}}),b.jsx("span",{className:"inline-block h-2.5 w-2.5 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"300ms"}})]})}):b.jsx(Sf,{content:_D(Gd(e.content||"")),className:Ae,syntaxTheme:O}),[Ae,e.content,e.isStreaming,O]),pe=y.useMemo(()=>[...I].sort((Ke,st)=>{const Ot=Ke.timestamp instanceof Date?Ke.timestamp.getTime():new Date(Ke.timestamp).getTime(),en=st.timestamp instanceof Date?st.timestamp.getTime():new Date(st.timestamp).getTime();return Ot-en}).map(Ke=>{const st=Ke.role==="assistant",Ot=st?G:X,en=Ke.isStreaming&&(!Ke.content||Ke.content==="…")?b.jsx("div",{className:Ot,children:b.jsxs("div",{className:"flex items-center gap-1.5 py-1",children:[b.jsx("span",{className:"inline-block h-2 w-2 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"0ms"}}),b.jsx("span",{className:"inline-block h-2 w-2 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"150ms"}}),b.jsx("span",{className:"inline-block h-2 w-2 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"300ms"}})]})}):b.jsx(Sf,{content:_D(Gd(Ke.content||"")),className:Ot,syntaxTheme:O});return b.jsxs("div",{className:"flex items-start gap-3",children:[b.jsx("div",{className:`mt-0.5 flex h-7 w-7 flex-shrink-0 items-center justify-center rounded-full ${st?"bg-blue-100 text-blue-700 dark:bg-[#1f2a36] dark:text-[#c5d7ff]":"bg-emerald-100 text-emerald-700 dark:bg-[#1f2a36] dark:text-[#9ef0d5]"}`,children:st?b.jsx(iR,{className:"h-3.5 w-3.5"}):b.jsx(aR,{className:"h-3.5 w-3.5"})}),b.jsxs("div",{className:"flex-1 min-w-0 rounded-2xl border border-white/70 bg-white/90 px-4 py-3 text-sm shadow-sm dark:border-white/5 dark:bg-white/5 backdrop-blur overflow-hidden",children:[b.jsxs("div",{className:"mb-1 flex items-center justify-between text-[11px] font-semibold uppercase tracking-wide text-blue-900/70 dark:text-[#c5d7ff]",children:[b.jsx("span",{children:st?"Assistant":"You"}),b.jsx("span",{children:we(Ke.timestamp)})]}),b.jsx("div",{className:"thread-markdown-wrapper overflow-x-auto",children:en})]})]},Ke.id)}),[we,O,G,I,X]);return b.jsxs("div",{className:"group flex items-start gap-3 px-1 animate-fadeIn min-w-0 sm:px-0",children:[b.jsx("div",{className:`flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-full self-start -mt-2 ml-1 shadow-sm ring-2 ring-white/50 dark:ring-white/10 sm:-mt-3 sm:ml-2 ${ae}`,children:E?b.jsx(iR,{className:"h-5 w-5"}):b.jsx(aR,{className:"h-5 w-5"})}),b.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[b.jsxs("div",{className:"flex flex-col gap-1.5 mb-1",children:[b.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-gray-700 dark:text-[#ececf1]",children:E?"Assistant":"You"}),b.jsx("span",{className:"text-xs text-gray-500 dark:text-[#bfc2cd]",children:ie})]}),b.jsxs("div",{className:le,children:[Be,e.attachments&&e.attachments.length>0&&b.jsx("div",{className:"mt-3 space-y-2",children:e.attachments.map(Fe=>b.jsxs("div",{className:`flex items-center gap-3 rounded-xl border p-3 ${ge}`,children:[b.jsx(zle,{className:"h-4 w-4 text-gray-500 dark:text-[#bfc2cd]"}),b.jsxs("div",{className:"min-w-0 flex-1",children:[b.jsx("p",{className:"truncate text-sm font-medium text-[#353740] dark:text-[#ececf1]",children:Fe.filename}),b.jsxs("p",{className:"text-xs text-gray-500 dark:text-[#bfc2cd]",children:[(Fe.file_size/1024).toFixed(1)," KB"]})]})]},Fe.file_id))}),e.audio&&E&&!e.isStreaming&&b.jsx(W_e,{audio:e.audio,audioFormat:e.audioFormat,autoPlay:!1})]}),E&&!e.isStreaming&&b.jsxs("div",{className:"flex items-center gap-1 md:gap-2 text-xs text-gray-500 transition-opacity dark:text-[#bfc2cd] sm:opacity-0 sm:group-hover:opacity-100",children:[b.jsxs("button",{onClick:te,className:"inline-flex items-center gap-1 rounded px-2 py-1 hover:bg-gray-200 dark:hover:bg-[#3c3f4a]",title:"Copy message",children:[b.jsx(Gle,{className:"h-4 w-4"}),b.jsx("span",{className:"hidden sm:inline",children:"Copy"})]}),t&&b.jsxs("button",{onClick:()=>t(e.id),className:"inline-flex items-center gap-1 rounded px-2 py-1 hover:bg-gray-200 dark:hover:bg-[#3c3f4a]",title:"Regenerate response",children:[b.jsx(_le,{className:"h-4 w-4"}),b.jsx("span",{className:"hidden sm:inline",children:"Retry"})]}),D&&r&&e.supportsThreading&&!e.threadInfo&&i&&b.jsxs("button",{onClick:()=>r(e.id,i),className:"inline-flex items-center gap-1 rounded px-2 py-1 hover:bg-gray-200 dark:hover:bg-[#3c3f4a]",title:"Start thread for follow-up questions",children:[b.jsx(q0,{className:"h-4 w-4"}),b.jsx("span",{className:"hidden sm:inline",children:"Start Thread"})]}),L_e()&&b.jsxs("div",{className:"flex items-center gap-1",children:[b.jsx("button",{onClick:()=>he("up"),className:`rounded p-1 hover:bg-gray-200 dark:hover:bg-[#3c3f4a] ${l==="up"?"text-[#353740] dark:text-[#ececf1]":""}`,title:"Good response",children:b.jsx(tce,{className:"h-4 w-4"})}),b.jsx("button",{onClick:()=>he("down"),className:`rounded p-1 hover:bg-gray-200 dark:hover:bg-[#3c3f4a] ${l==="down"?"text-[#353740] dark:text-[#ececf1]":""}`,title:"Poor response",children:b.jsx(ece,{className:"h-4 w-4"})})]}),s&&b.jsx("span",{children:"Copied"})]}),D&&e.threadInfo&&b.jsxs("div",{className:"thread-panel mt-4 rounded-xl border border-blue-100/80 bg-blue-50/70 p-3 sm:p-4 text-sm shadow-sm ring-1 ring-blue-100/60 dark:border-[#1f2a36] dark:bg-[#0f1821] dark:ring-[#1f2a36]",children:[b.jsxs("div",{className:"flex items-center justify-between gap-2 text-sm font-semibold text-blue-900 dark:text-[#c5d7ff]",children:[b.jsxs("div",{className:"inline-flex items-center gap-2 uppercase tracking-wide text-xs sm:text-sm",children:[b.jsx(q0,{className:"h-3.5 w-3.5"}),b.jsxs("span",{children:["Thread",Q>0?` (${Q})`:""]})]}),b.jsx("button",{onClick:()=>B(Fe=>!Fe),className:"inline-flex items-center gap-1.5 sm:gap-2 rounded-full border border-blue-200/80 px-2.5 sm:px-3 py-1.5 text-xs uppercase tracking-wide text-blue-900 transition hover:bg-white/70 dark:border-[#233449] dark:text-[#c5d7ff] dark:hover:bg-white/10",children:d?b.jsxs(b.Fragment,{children:[b.jsx("span",{className:"hidden sm:inline",children:"Hide"}),b.jsx(vle,{className:"h-4 w-4 sm:h-3 sm:w-3"})]}):b.jsxs(b.Fragment,{children:[b.jsx("span",{className:"hidden sm:inline",children:"Show"}),b.jsx(X6,{className:"h-4 w-4 sm:h-3 sm:w-3"})]})})]}),d&&b.jsxs(b.Fragment,{children:[b.jsx("div",{ref:m,className:"mt-3 space-y-3 max-h-96 overflow-y-auto scroll-smooth",style:{scrollBehavior:"auto"},children:pe}),v&&b.jsx("div",{className:"mt-3 rounded-md border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-900 dark:border-amber-500/30 dark:bg-[#2f2410] dark:text-amber-100",children:v}),b.jsx("div",{className:"mt-3 rounded-xl border border-white/80 bg-white/95 p-3 shadow-sm dark:border-white/10 dark:bg-white/10",children:b.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-3",children:[b.jsx("textarea",{ref:p,className:"flex-1 w-full sm:w-auto min-w-0 resize-none rounded-lg border border-gray-200 bg-gray-50 px-3 py-2.5 text-base sm:text-sm text-[#353740] placeholder-gray-500 outline-none transition focus:border-gray-400 focus:ring-1 focus:ring-gray-300 disabled:opacity-60 dark:border-[#3c3f4a] dark:bg-[#2d2f39] dark:text-[#ececf1] dark:placeholder-[#8e8ea0] dark:focus:border-[#8e8ea0] dark:focus:ring-[#8e8ea0]",placeholder:Q>0?"Reply in thread...":"Ask a follow-up...",value:u,onChange:Fe=>g(Fe.target.value),onKeyDown:be,disabled:ke,rows:1,maxLength:z,style:{minHeight:"44px",maxHeight:"120px",outline:"none",boxShadow:"none",WebkitAppearance:"none",MozAppearance:"none",appearance:"none"}}),b.jsxs("div",{className:"flex items-center justify-between sm:justify-end gap-2",children:[u.length>0&&b.jsx("div",{className:"text-xs text-gray-500 dark:text-[#bfc2cd] whitespace-nowrap",children:b.jsxs("span",{className:u.length>=z?"text-red-600 font-semibold":"",children:[u.length,"/",z]})}),b.jsx("button",{type:"button",onClick:q,disabled:ke||u.trim().length===0,className:`flex h-11 w-11 sm:h-9 sm:w-9 items-center justify-center rounded-full transition active:scale-95 ${u.trim().length>0&&!ke?"bg-[#10a37f] text-white hover:bg-[#0f8f6f]":"bg-gray-200 text-gray-400 dark:bg-[#2f313a] dark:text-[#6b6f7a]"} disabled:cursor-not-allowed`,title:"Send thread message",children:h?b.jsx(_c,{className:"h-5 w-5 sm:h-4 sm:w-4 animate-spin"}):b.jsx(V6,{className:"h-5 w-5 sm:h-4 sm:w-4"})})]})]})})]})]})]})]})}function X_e(e=800,t=100,r="sine"){try{if(typeof window>"u"){me("[SoundEffects] Window is not available for audio playback");return}const n=window.AudioContext??window.webkitAudioContext;if(!n){me("[SoundEffects] AudioContext not supported in this browser");return}const A=new n,i=A.createOscillator(),a=A.createGain();i.connect(a),a.connect(A.destination),i.frequency.value=e,i.type=r,a.gain.setValueAtTime(.3,A.currentTime),a.gain.exponentialRampToValueAtTime(.01,A.currentTime+t/1e3),i.start(A.currentTime),i.stop(A.currentTime+t/1e3)}catch{}}const Z_e={messageSent:{frequency:600,duration:80,type:"sine"},messageReceived:{frequency:800,duration:100,type:"sine"},success:{frequency:1e3,duration:150,type:"sine"},error:{frequency:400,duration:200,type:"square"},notification:{frequency:700,duration:120,type:"sine"}};function cd(e,t){if(!t)return;const r=Z_e[e];if(r)try{X_e(r.frequency,r.duration,r.type),me(`[SoundEffects] Playing ${e} sound effect`)}catch{}}function q_e({messages:e,onRegenerate:t,onStartThread:r,onSendThreadMessage:n,sessionId:A,isLoading:i}){const a=y.useRef(null),s=y.useRef(null),o=y.useRef(e.length),l=y.useRef(""),c=y.useRef(i),u=y.useRef(!0),{settings:g}=em(),{topLevelMessages:d,threadLookup:B}=y.useMemo(()=>{const w=new Map,p=[];return e.forEach(m=>{if(m.isThreadMessage&&m.parentMessageId){const C=w.get(m.parentMessageId)||[];w.set(m.parentMessageId,[...C,m]);return}p.push(m)}),{topLevelMessages:p,threadLookup:w}},[e]),h=()=>{if(!s.current)return;const{scrollTop:w,scrollHeight:p,clientHeight:m}=s.current,E=p-w-m<200;u.current=E},f=y.useCallback(()=>{requestAnimationFrame(()=>{s.current&&(s.current.scrollTop=s.current.scrollHeight)})},[]);return y.useEffect(()=>{const w=e.length,p=o.current,m=w>p,C=e[e.length-1],E=(C==null?void 0:C.content)||"",I=E!==l.current,Q=(C==null?void 0:C.isStreaming)??!1;m||Q&&I?(f(),u.current=!0):u.current&&I&&f(),o.current=w,l.current=E},[e,f]),y.useEffect(()=>{i&&(f(),u.current=!0)},[i,f]),y.useEffect(()=>{if(c.current&&!i){const w=e[e.length-1];(w==null?void 0:w.role)==="assistant"&&w.content&&cd("messageReceived",g.soundEnabled)}c.current=i},[i,e,g.soundEnabled]),d.length===0?b.jsx("div",{className:"flex-1 flex items-center justify-center px-4 sm:px-6",children:b.jsxs("div",{className:"text-center text-lg text-gray-500 dark:text-[#bfc2cd]",children:[b.jsx("p",{className:"text-xl",children:"Your messages will appear here."}),b.jsx("p",{className:"mt-1 text-lg",children:"Start the conversation by sending a prompt below."})]})}):b.jsx("div",{ref:s,className:"message-list flex-1 overflow-y-auto py-6",onScroll:h,children:b.jsxs("div",{className:"space-y-6 px-3 sm:px-4",children:[d.map(w=>b.jsx(V_e,{message:w,onRegenerate:t,onStartThread:r,onSendThreadMessage:n,threadMessages:B.get(w.id),sessionId:A,isThreadSendDisabled:i},w.id)),b.jsx("div",{ref:a,className:"h-8"})]})})}const __e=2e3;function $_e(e,t){const[r,n]=y.useState(!1),[A,i]=y.useState(null),a=y.useRef(null),s=y.useRef(""),o=y.useRef(!1),l=y.useRef(null),c=y.useCallback(()=>{if(!s.current)return;const w=s.current;s.current="",e(" "+w)},[e]),u=typeof window<"u"&&("webkitSpeechRecognition"in window||"SpeechRecognition"in window),g=y.useCallback(()=>{!t||o.current||(o.current=!0,t())},[t]),d=y.useCallback(()=>{l.current!==null&&(clearTimeout(l.current),l.current=null)},[]),B=y.useCallback(()=>{d(),l.current=setTimeout(()=>{a.current?a.current.stop():g()},__e)},[d,g]),h=y.useCallback(()=>{if(!u){i("Speech recognition is not supported in this browser. Please try Chrome, Edge, or Safari.");return}if(!r)try{o.current=!1;const w=window.SpeechRecognition||window.webkitSpeechRecognition,p=new w;p.continuous=!0,p.interimResults=!0,p.lang=navigator.language||"en-US",p.maxAlternatives=1,p.onstart=()=>{n(!0),i(null),me("Speech recognition started"),B()},p.onresult=m=>{let C="",E="";for(let I=m.resultIndex;I<m.results.length;I++){const Q=m.results[I][0].transcript;m.results[I].isFinal?C+=Q:E+=Q}E&&(s.current=E),C&&(s.current="",e(" "+C)),B()},p.onend=()=>{d(),c(),n(!1),a.current=null,me("Speech recognition ended"),g()},p.onerror=m=>{switch(d(),Uu("Speech recognition error:",m.error),n(!1),a.current=null,s.current="",g(),m.error){case"no-speech":i("No speech detected. Please try again.");break;case"audio-capture":i("Microphone access denied. Please allow microphone access and try again.");break;case"not-allowed":i("Microphone access not allowed. Please enable microphone permissions.");break;case"network":i("Network error occurred. Please check your connection.");break;default:i(`Speech recognition error: ${m.error}`)}},p.start(),a.current=p}catch{i("Failed to start speech recognition. Please try again."),n(!1)}},[u,e,r,c,g,B,d]),f=y.useCallback(()=>{if(a.current){const w=a.current;w.onend=null,w.onerror=null,w.onresult=null,w.onstart=null;try{w.stop()}catch{}a.current=null}d(),c(),n(!1),i(null),g()},[d,c,g]);return{isListening:r,isSupported:u,startListening:h,stopListening:f,error:A}}const e$e="2.8.1",t$e={"@schmitech/chatbot-api":"^2.1.4"},_ae={version:e$e,dependencies:t$e},$ae=_ae.version,CV=_ae.dependencies["@schmitech/chatbot-api"];async function $D(){try{return(await Nt(()=>import("./api-CPJLWxrl.js"),[])).version||CV}catch{return CV}}async function ese(){const e=await $D();return{appVersion:$ae,apiVersion:e,isLocalApi:!1}}let Wa=null;function Pg(){let e=null,t=null;const r=(A,i,a,s)=>{e=a||null,t=s||null},n=()=>{if(!t)throw new Error("Adapter name is required when middleware is enabled");return{async*streamChat(A,i,a,s,o,l,c,u,g,d,B){var w,p;const h={messages:[{role:"user",content:A}],stream:i!==!1};a&&a.length>0&&(h.file_ids=a),s&&(h.thread_id=s),o&&(h.audio_input=o),l&&(h.audio_format=l),c&&(h.language=c),u!==void 0&&(h.return_audio=u),g&&(h.tts_voice=g),d&&(h.source_language=d),B&&(h.target_language=B);const f=await fetch("/api/v1/chat",{method:"POST",headers:{"Content-Type":"application/json","X-Adapter-Name":t,...e?{"X-Session-ID":e}:{}},body:JSON.stringify(h)});if(!f.ok)throw new Error(`API request failed: ${f.status} ${f.statusText}`);if((w=f.headers.get("content-type"))!=null&&w.includes("text/event-stream")){const m=(p=f.body)==null?void 0:p.getReader(),C=new TextDecoder;let E="";if(!m)throw new Error("Response body is not readable");for(;;){const{done:I,value:Q}=await m.read();if(I)break;E+=C.decode(Q,{stream:!0});const N=E.split(`
|
|
976
976
|
`);E=N.pop()||"";for(const k of N)if(k.startsWith("data: "))try{const x=JSON.parse(k.substring(6));yield{text:x.text||x.content||x.message||x.response||"",done:x.done||!1,audio:x.audio,audioFormat:x.audio_format||x.audioFormat,audio_chunk:x.audio_chunk,chunk_index:x.chunk_index,threading:x.threading}}catch{}}if(E.trim()){const I=E.split(`
|
|
977
|
-
`);for(const Q of I)if(Q.startsWith("data: "))try{const N=JSON.parse(Q.substring(6));yield{text:N.text||N.content||N.message||N.response||"",done:N.done||!1,audio:N.audio,audioFormat:N.audio_format||N.audioFormat,audio_chunk:N.audio_chunk,chunk_index:N.chunk_index,threading:N.threading}}catch{}}}else{const m=await f.json();yield{text:m.message||m.response||"",done:!0}}},async createThread(A,i){const a=await fetch("/api/threads",{method:"POST",headers:{"Content-Type":"application/json","X-Adapter-Name":t,"X-Session-ID":i},body:JSON.stringify({message_id:A,session_id:i})});if(!a.ok)throw new Error(`Failed to create thread: ${a.statusText}`);return a.json()},async getThreadInfo(A){const i=await fetch(`/api/threads/${A}`,{headers:{"X-Adapter-Name":t}});if(!i.ok)throw new Error(`Failed to get thread info: ${i.statusText}`);return i.json()},async deleteThread(A){const i=await fetch(`/api/threads/${A}`,{method:"DELETE",headers:{"X-Adapter-Name":t}});if(!i.ok)throw new Error(`Failed to delete thread: ${i.statusText}`);return i.json()},async clearConversationHistory(A){const i=await fetch(`/api/admin/chat-history/${A||e}`,{method:"DELETE",headers:{"X-Adapter-Name":t}});if(!i.ok)throw new Error(`Failed to clear history: ${i.statusText}`);return i.json()},async getConversationHistory(A,i){const a=A||e;if(!a)throw new Error("No session ID available for conversation history");const s=typeof i=="number"&&Number.isFinite(i)&&i>0?`?limit=${Math.floor(i)}`:"",o=await fetch(`/api/admin/chat-history/${a}${s}`,{headers:{"X-Adapter-Name":t}});if(!o.ok)throw new Error(`Failed to load history: ${o.statusText}`);return o.json()},async deleteConversationWithFiles(A,i){const a=A||e,s=i&&i.length>0?`?file_ids=${i.join(",")}`:"",o=await fetch(`/api/admin/conversations/${a}${s}`,{method:"DELETE",headers:{"X-Adapter-Name":t}});if(!o.ok)throw new Error(`Failed to delete conversation: ${o.statusText}`);return o.json()},getSessionId:()=>e,async uploadFile(A){const i=new FormData;i.append("file",A);const a=await fetch("/api/files/upload",{method:"POST",headers:{"X-Adapter-Name":t},body:i});if(!a.ok)throw new Error(`Failed to upload file: ${a.statusText}`);return a.json()},async listFiles(){const A=await fetch("/api/files",{headers:{"X-Adapter-Name":t}});if(!A.ok)throw new Error(`Failed to list files: ${A.statusText}`);const i=await A.json();return Array.isArray(i)?i:i.files||[]},async getFileInfo(A){const i=await fetch(`/api/files/${A}`,{headers:{"X-Adapter-Name":t}});if(!i.ok)throw new Error(`Failed to get file info: ${i.statusText}`);return i.json()},async queryFile(A,i,a){const s=await fetch(`/api/files/${A}/query`,{method:"POST",headers:{"Content-Type":"application/json","X-Adapter-Name":t},body:JSON.stringify({query:i,max_results:a})});if(!s.ok)throw new Error(`Failed to query file: ${s.statusText}`);return s.json()},async deleteFile(A){const i=await fetch(`/api/files/${A}`,{method:"DELETE",headers:{"X-Adapter-Name":t}});if(!i.ok)throw new Error(`Failed to delete file: ${i.statusText}`);return i.json()},async validateApiKey(){const A=await fetch(`/api/admin/api-keys/${t}/status`,{headers:{"X-Adapter-Name":t}});if(!A.ok)throw new Error(`Failed to validate API key: ${A.statusText}`);return A.json()},async getAdapterInfo(){const a=await(async s=>await fetch(s,{headers:{"X-Adapter-Name":t}}))("/api/admin/adapters/info");if(!a.ok){const s=await a.text();throw new Error(`Failed to get adapter info: ${a.status} ${a.statusText} - ${s}`)}return a.json()}}};return{configureApi:r,streamChat:async function*(A,i,a,s,o,l,c,u,g,d,B){yield*n().streamChat(A,i,a,s,o,l,c,u,g,d,B)},ApiClient:class{constructor(i){wA(this,"client");t=i.adapterName||null,e=i.sessionId||null,this.client=n()}async*streamChat(...i){yield*this.client.streamChat(...i)}get createThread(){var i;return(i=this.client.createThread)==null?void 0:i.bind(this.client)}get getThreadInfo(){var i;return(i=this.client.getThreadInfo)==null?void 0:i.bind(this.client)}get deleteThread(){var i;return(i=this.client.deleteThread)==null?void 0:i.bind(this.client)}get clearConversationHistory(){var i;return(i=this.client.clearConversationHistory)==null?void 0:i.bind(this.client)}get getConversationHistory(){var i;return(i=this.client.getConversationHistory)==null?void 0:i.bind(this.client)}get deleteConversationWithFiles(){var i;return(i=this.client.deleteConversationWithFiles)==null?void 0:i.bind(this.client)}get getSessionId(){var i;return(i=this.client.getSessionId)==null?void 0:i.bind(this.client)}get uploadFile(){var i;return(i=this.client.uploadFile)==null?void 0:i.bind(this.client)}get listFiles(){var i;return(i=this.client.listFiles)==null?void 0:i.bind(this.client)}get getFileInfo(){var i;return(i=this.client.getFileInfo)==null?void 0:i.bind(this.client)}get queryFile(){var i;return(i=this.client.queryFile)==null?void 0:i.bind(this.client)}get deleteFile(){var i;return(i=this.client.deleteFile)==null?void 0:i.bind(this.client)}get validateApiKey(){var i;return(i=this.client.validateApiKey)==null?void 0:i.bind(this.client)}get getAdapterInfo(){var i;return(i=this.client.getAdapterInfo)==null?void 0:i.bind(this.client)}}}}async function r$e(e){return e==="@local-node-api/api.mjs"?Nt(()=>import("./api-BHF9IxKN.js"),[]):import(e)}async function n$e(){if(Wa)return Wa;const e=R_e(),t=j_e(),r=lr();try{if(e){let n;t?t.startsWith("/")?n=t.startsWith("/src/")?`.${t.substring(4)}${t.endsWith(".mjs")?"":"/api.mjs"}`:"../../../node-api/dist/api.mjs":t.startsWith("../")||t.startsWith("./")?n=t.endsWith(".mjs")?t:`${t}/api.mjs`:n=`./${t}${t.endsWith(".mjs")?"":"/api.mjs"}`:n="../../../node-api/dist/api.mjs",me(`🔧 Loading local API from: ${n}`);const A=await r$e(n);r?(me("🔐 API Middleware enabled - routing through proxy"),Wa=Pg()):Wa={configureApi:A.configureApi,streamChat:A.streamChat,ApiClient:A.ApiClient},me("✅ Local API loaded successfully")}else{me("📦 Loading npm package API");const n=await Nt(()=>import("./api-XcRutblh.js"),[]),A=async function*(s,o,l,c,u,g,d,B,h,f,w){yield*n.streamChat(s,o,l,c,u,g,d,B,h,f,w)};class i{constructor(o){wA(this,"client");if(r&&o.adapterName){const l=Pg();this.client=new l.ApiClient(o)}else this.client=new n.ApiClient(o)}async*streamChat(o,l,c,u,g,d,B,h,f,w,p){yield*this.client.streamChat(o,l,c,u,g,d,B,h,f,w,p)}get createThread(){var o;return(o=this.client.createThread)==null?void 0:o.bind(this.client)}get getThreadInfo(){var o;return(o=this.client.getThreadInfo)==null?void 0:o.bind(this.client)}get deleteThread(){var o;return(o=this.client.deleteThread)==null?void 0:o.bind(this.client)}get clearConversationHistory(){var o;return(o=this.client.clearConversationHistory)==null?void 0:o.bind(this.client)}get getConversationHistory(){var o;return(o=this.client.getConversationHistory)==null?void 0:o.bind(this.client)}get deleteConversationWithFiles(){var o;return(o=this.client.deleteConversationWithFiles)==null?void 0:o.bind(this.client)}get getSessionId(){var o;return(o=this.client.getSessionId)==null?void 0:o.bind(this.client)}get uploadFile(){var o;return(o=this.client.uploadFile)==null?void 0:o.bind(this.client)}get listFiles(){var o;return(o=this.client.listFiles)==null?void 0:o.bind(this.client)}get getFileInfo(){var o;return(o=this.client.getFileInfo)==null?void 0:o.bind(this.client)}get queryFile(){var o;return(o=this.client.queryFile)==null?void 0:o.bind(this.client)}get deleteFile(){var o;return(o=this.client.deleteFile)==null?void 0:o.bind(this.client)}get validateApiKey(){var o;return(o=this.client.validateApiKey)==null?void 0:o.bind(this.client)}get getAdapterInfo(){var o;return(o=this.client.getAdapterInfo)==null?void 0:o.bind(this.client)}}r?(me("🔐 API Middleware enabled - routing through proxy"),Wa=Pg()):Wa={configureApi:n.configureApi,streamChat:A,ApiClient:i};const a=await $D();me(`✅ NPM package API loaded successfully (v${a})`)}}catch(n){if(e)try{const A=await Nt(()=>import("./api-XcRutblh.js"),[]),i=async function*(o,l,c,u,g,d,B,h,f,w,p){yield*A.streamChat(o,l,c,u,g,d,B,h,f,w,p)};class a{constructor(l){wA(this,"client");if(r&&l.adapterName){const c=Pg();this.client=new c.ApiClient(l)}else this.client=new A.ApiClient(l)}async*streamChat(l,c,u,g,d,B,h,f,w,p,m){yield*this.client.streamChat(l,c,u,g,d,B,h,f,w,p,m)}get createThread(){var l;return(l=this.client.createThread)==null?void 0:l.bind(this.client)}get getThreadInfo(){var l;return(l=this.client.getThreadInfo)==null?void 0:l.bind(this.client)}get deleteThread(){var l;return(l=this.client.deleteThread)==null?void 0:l.bind(this.client)}get clearConversationHistory(){var l;return(l=this.client.clearConversationHistory)==null?void 0:l.bind(this.client)}get getConversationHistory(){var l;return(l=this.client.getConversationHistory)==null?void 0:l.bind(this.client)}get deleteConversationWithFiles(){var l;return(l=this.client.deleteConversationWithFiles)==null?void 0:l.bind(this.client)}get getSessionId(){var l;return(l=this.client.getSessionId)==null?void 0:l.bind(this.client)}get uploadFile(){var l;return(l=this.client.uploadFile)==null?void 0:l.bind(this.client)}get listFiles(){var l;return(l=this.client.listFiles)==null?void 0:l.bind(this.client)}get getFileInfo(){var l;return(l=this.client.getFileInfo)==null?void 0:l.bind(this.client)}get queryFile(){var l;return(l=this.client.queryFile)==null?void 0:l.bind(this.client)}get deleteFile(){var l;return(l=this.client.deleteFile)==null?void 0:l.bind(this.client)}get validateApiKey(){var l;return(l=this.client.validateApiKey)==null?void 0:l.bind(this.client)}get getAdapterInfo(){var l;return(l=this.client.getAdapterInfo)==null?void 0:l.bind(this.client)}}r?(me("🔐 API Middleware enabled - routing through proxy"),Wa=Pg()):Wa={configureApi:A.configureApi,streamChat:i,ApiClient:a};const s=await $D();me(`✅ Fallback to NPM package successful (v${s})`)}catch{throw new Error("Failed to load both local and npm API packages")}else throw n}return Wa}async function nn(){return await n$e()}const Hp=wo(),A$e=()=>{try{if(typeof window>"u"||!window.localStorage)return null;const e=window.localStorage.getItem("chat-api-url");return e&&e===Vl?(window.localStorage.removeItem("chat-api-url"),null):e}catch{return null}},Kg=e=>{const t=e==null?void 0:e.trim();if(t)return t;const r=A$e();return r&&r!==Vl?r:Hr()},Jp=()=>typeof window>"u"?null:window.CHATBOT_API_KEY||null;class kh{static async uploadFile(t,r,n,A,i){try{const a=ot.maxFileSizeMB*1024*1024;if(t.size>a)throw new Error(`File size exceeds maximum limit of ${ot.maxFileSizeMB}MB`);if(!(["application/pdf","text/plain","text/markdown","text/csv","application/json","text/html","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-excel","application/vnd.ms-excel.sheet.macroEnabled.12","text/x-python","text/x-python-script","text/x-java-source","text/x-java","text/x-sql","text/javascript","application/javascript","text/typescript","application/typescript","text/x-c++src","text/x-csrc","text/x-c","text/x-go","text/x-rust","text/x-ruby","text/x-php","text/x-shellscript","text/x-sh","text/yaml","text/x-yaml","text/xml","application/xml","text/css","text/x-scss","text/x-sass","text/x-less","image/png","image/jpeg","image/tiff","audio/wav","audio/mpeg","audio/mp3","audio/mp4","audio/ogg","audio/flac","audio/webm","audio/x-m4a","audio/aac","text/vtt"].includes(t.type)||/\.(pdf|txt|md|csv|json|html|docx|pptx|xlsx|py|java|sql|js|mjs|ts|tsx|cpp|cxx|cc|c|h|hpp|go|rs|rb|php|sh|bash|zsh|yaml|yml|xml|css|scss|sass|less|png|jpe?g|tiff?|wav|mp3|mp4|ogg|flac|webm|m4a|aac|vtt)$/i.test(t.name)||(t.type==="application/x-zip-compressed"||t.type==="application/zip")&&/\.xlsx$/i.test(t.name)))throw new Error(`File type not supported: ${t.type||"unknown"}`);r&&r({filename:t.name,progress:0,status:"uploading"});const l=await nn(),c=Kg(A),u=lr();let g=null,d=null;if(u){if(d=i||(typeof window<"u"?localStorage.getItem("chat-adapter-name"):null),!d)throw new Error("Adapter not configured. Please select an adapter from the dropdown.");me(`🔑 Using adapter: ${d}`)}else{if(g=n||localStorage.getItem("chat-api-key")||Jp()||Hp,!g||g==="your-api-key-here")throw new Error(`API key not configured or invalid. Please:
|
|
977
|
+
`);for(const Q of I)if(Q.startsWith("data: "))try{const N=JSON.parse(Q.substring(6));yield{text:N.text||N.content||N.message||N.response||"",done:N.done||!1,audio:N.audio,audioFormat:N.audio_format||N.audioFormat,audio_chunk:N.audio_chunk,chunk_index:N.chunk_index,threading:N.threading}}catch{}}}else{const m=await f.json();yield{text:m.message||m.response||"",done:!0}}},async createThread(A,i){const a=await fetch("/api/threads",{method:"POST",headers:{"Content-Type":"application/json","X-Adapter-Name":t,"X-Session-ID":i},body:JSON.stringify({message_id:A,session_id:i})});if(!a.ok)throw new Error(`Failed to create thread: ${a.statusText}`);return a.json()},async getThreadInfo(A){const i=await fetch(`/api/threads/${A}`,{headers:{"X-Adapter-Name":t}});if(!i.ok)throw new Error(`Failed to get thread info: ${i.statusText}`);return i.json()},async deleteThread(A){const i=await fetch(`/api/threads/${A}`,{method:"DELETE",headers:{"X-Adapter-Name":t}});if(!i.ok)throw new Error(`Failed to delete thread: ${i.statusText}`);return i.json()},async clearConversationHistory(A){const i=await fetch(`/api/admin/chat-history/${A||e}`,{method:"DELETE",headers:{"X-Adapter-Name":t}});if(!i.ok)throw new Error(`Failed to clear history: ${i.statusText}`);return i.json()},async getConversationHistory(A,i){const a=A||e;if(!a)throw new Error("No session ID available for conversation history");const s=typeof i=="number"&&Number.isFinite(i)&&i>0?`?limit=${Math.floor(i)}`:"",o=await fetch(`/api/admin/chat-history/${a}${s}`,{headers:{"X-Adapter-Name":t}});if(!o.ok)throw new Error(`Failed to load history: ${o.statusText}`);return o.json()},async deleteConversationWithFiles(A,i){const a=A||e,s=i&&i.length>0?`?file_ids=${i.join(",")}`:"",o=await fetch(`/api/admin/conversations/${a}${s}`,{method:"DELETE",headers:{"X-Adapter-Name":t}});if(!o.ok)throw new Error(`Failed to delete conversation: ${o.statusText}`);return o.json()},getSessionId:()=>e,async uploadFile(A){const i=new FormData;i.append("file",A);const a=await fetch("/api/files/upload",{method:"POST",headers:{"X-Adapter-Name":t},body:i});if(!a.ok)throw new Error(`Failed to upload file: ${a.statusText}`);return a.json()},async listFiles(){const A=await fetch("/api/files",{headers:{"X-Adapter-Name":t}});if(!A.ok)throw new Error(`Failed to list files: ${A.statusText}`);const i=await A.json();return Array.isArray(i)?i:i.files||[]},async getFileInfo(A){const i=await fetch(`/api/files/${A}`,{headers:{"X-Adapter-Name":t}});if(!i.ok)throw new Error(`Failed to get file info: ${i.statusText}`);return i.json()},async queryFile(A,i,a){const s=await fetch(`/api/files/${A}/query`,{method:"POST",headers:{"Content-Type":"application/json","X-Adapter-Name":t},body:JSON.stringify({query:i,max_results:a})});if(!s.ok)throw new Error(`Failed to query file: ${s.statusText}`);return s.json()},async deleteFile(A){const i=await fetch(`/api/files/${A}`,{method:"DELETE",headers:{"X-Adapter-Name":t}});if(!i.ok)throw new Error(`Failed to delete file: ${i.statusText}`);return i.json()},async validateApiKey(){const A=await fetch(`/api/admin/api-keys/${t}/status`,{headers:{"X-Adapter-Name":t}});if(!A.ok)throw new Error(`Failed to validate API key: ${A.statusText}`);return A.json()},async getAdapterInfo(){const a=await(async s=>await fetch(s,{headers:{"X-Adapter-Name":t}}))("/api/admin/adapters/info");if(!a.ok){const s=await a.text();throw new Error(`Failed to get adapter info: ${a.status} ${a.statusText} - ${s}`)}return a.json()}}};return{configureApi:r,streamChat:async function*(A,i,a,s,o,l,c,u,g,d,B){yield*n().streamChat(A,i,a,s,o,l,c,u,g,d,B)},ApiClient:class{constructor(i){wA(this,"client");t=i.adapterName||null,e=i.sessionId||null,this.client=n()}async*streamChat(...i){yield*this.client.streamChat(...i)}get createThread(){var i;return(i=this.client.createThread)==null?void 0:i.bind(this.client)}get getThreadInfo(){var i;return(i=this.client.getThreadInfo)==null?void 0:i.bind(this.client)}get deleteThread(){var i;return(i=this.client.deleteThread)==null?void 0:i.bind(this.client)}get clearConversationHistory(){var i;return(i=this.client.clearConversationHistory)==null?void 0:i.bind(this.client)}get getConversationHistory(){var i;return(i=this.client.getConversationHistory)==null?void 0:i.bind(this.client)}get deleteConversationWithFiles(){var i;return(i=this.client.deleteConversationWithFiles)==null?void 0:i.bind(this.client)}get getSessionId(){var i;return(i=this.client.getSessionId)==null?void 0:i.bind(this.client)}get uploadFile(){var i;return(i=this.client.uploadFile)==null?void 0:i.bind(this.client)}get listFiles(){var i;return(i=this.client.listFiles)==null?void 0:i.bind(this.client)}get getFileInfo(){var i;return(i=this.client.getFileInfo)==null?void 0:i.bind(this.client)}get queryFile(){var i;return(i=this.client.queryFile)==null?void 0:i.bind(this.client)}get deleteFile(){var i;return(i=this.client.deleteFile)==null?void 0:i.bind(this.client)}get validateApiKey(){var i;return(i=this.client.validateApiKey)==null?void 0:i.bind(this.client)}get getAdapterInfo(){var i;return(i=this.client.getAdapterInfo)==null?void 0:i.bind(this.client)}}}}async function r$e(e){return e==="@local-node-api/api.mjs"?Nt(()=>import("./api-BHF9IxKN.js"),[]):import(e)}async function n$e(){if(Wa)return Wa;const e=R_e(),t=j_e(),r=lr();try{if(e){let n;t?t.startsWith("/")?n=t.startsWith("/src/")?`.${t.substring(4)}${t.endsWith(".mjs")?"":"/api.mjs"}`:"../../../node-api/dist/api.mjs":t.startsWith("../")||t.startsWith("./")?n=t.endsWith(".mjs")?t:`${t}/api.mjs`:n=`./${t}${t.endsWith(".mjs")?"":"/api.mjs"}`:n="../../../node-api/dist/api.mjs",me(`🔧 Loading local API from: ${n}`);const A=await r$e(n);r?(me("🔐 API Middleware enabled - routing through proxy"),Wa=Pg()):Wa={configureApi:A.configureApi,streamChat:A.streamChat,ApiClient:A.ApiClient},me("✅ Local API loaded successfully")}else{me("📦 Loading npm package API");const n=await Nt(()=>import("./api-CPJLWxrl.js"),[]),A=async function*(s,o,l,c,u,g,d,B,h,f,w){yield*n.streamChat(s,o,l,c,u,g,d,B,h,f,w)};class i{constructor(o){wA(this,"client");if(r&&o.adapterName){const l=Pg();this.client=new l.ApiClient(o)}else this.client=new n.ApiClient(o)}async*streamChat(o,l,c,u,g,d,B,h,f,w,p){yield*this.client.streamChat(o,l,c,u,g,d,B,h,f,w,p)}get createThread(){var o;return(o=this.client.createThread)==null?void 0:o.bind(this.client)}get getThreadInfo(){var o;return(o=this.client.getThreadInfo)==null?void 0:o.bind(this.client)}get deleteThread(){var o;return(o=this.client.deleteThread)==null?void 0:o.bind(this.client)}get clearConversationHistory(){var o;return(o=this.client.clearConversationHistory)==null?void 0:o.bind(this.client)}get getConversationHistory(){var o;return(o=this.client.getConversationHistory)==null?void 0:o.bind(this.client)}get deleteConversationWithFiles(){var o;return(o=this.client.deleteConversationWithFiles)==null?void 0:o.bind(this.client)}get getSessionId(){var o;return(o=this.client.getSessionId)==null?void 0:o.bind(this.client)}get uploadFile(){var o;return(o=this.client.uploadFile)==null?void 0:o.bind(this.client)}get listFiles(){var o;return(o=this.client.listFiles)==null?void 0:o.bind(this.client)}get getFileInfo(){var o;return(o=this.client.getFileInfo)==null?void 0:o.bind(this.client)}get queryFile(){var o;return(o=this.client.queryFile)==null?void 0:o.bind(this.client)}get deleteFile(){var o;return(o=this.client.deleteFile)==null?void 0:o.bind(this.client)}get validateApiKey(){var o;return(o=this.client.validateApiKey)==null?void 0:o.bind(this.client)}get getAdapterInfo(){var o;return(o=this.client.getAdapterInfo)==null?void 0:o.bind(this.client)}}r?(me("🔐 API Middleware enabled - routing through proxy"),Wa=Pg()):Wa={configureApi:n.configureApi,streamChat:A,ApiClient:i};const a=await $D();me(`✅ NPM package API loaded successfully (v${a})`)}}catch(n){if(e)try{const A=await Nt(()=>import("./api-CPJLWxrl.js"),[]),i=async function*(o,l,c,u,g,d,B,h,f,w,p){yield*A.streamChat(o,l,c,u,g,d,B,h,f,w,p)};class a{constructor(l){wA(this,"client");if(r&&l.adapterName){const c=Pg();this.client=new c.ApiClient(l)}else this.client=new A.ApiClient(l)}async*streamChat(l,c,u,g,d,B,h,f,w,p,m){yield*this.client.streamChat(l,c,u,g,d,B,h,f,w,p,m)}get createThread(){var l;return(l=this.client.createThread)==null?void 0:l.bind(this.client)}get getThreadInfo(){var l;return(l=this.client.getThreadInfo)==null?void 0:l.bind(this.client)}get deleteThread(){var l;return(l=this.client.deleteThread)==null?void 0:l.bind(this.client)}get clearConversationHistory(){var l;return(l=this.client.clearConversationHistory)==null?void 0:l.bind(this.client)}get getConversationHistory(){var l;return(l=this.client.getConversationHistory)==null?void 0:l.bind(this.client)}get deleteConversationWithFiles(){var l;return(l=this.client.deleteConversationWithFiles)==null?void 0:l.bind(this.client)}get getSessionId(){var l;return(l=this.client.getSessionId)==null?void 0:l.bind(this.client)}get uploadFile(){var l;return(l=this.client.uploadFile)==null?void 0:l.bind(this.client)}get listFiles(){var l;return(l=this.client.listFiles)==null?void 0:l.bind(this.client)}get getFileInfo(){var l;return(l=this.client.getFileInfo)==null?void 0:l.bind(this.client)}get queryFile(){var l;return(l=this.client.queryFile)==null?void 0:l.bind(this.client)}get deleteFile(){var l;return(l=this.client.deleteFile)==null?void 0:l.bind(this.client)}get validateApiKey(){var l;return(l=this.client.validateApiKey)==null?void 0:l.bind(this.client)}get getAdapterInfo(){var l;return(l=this.client.getAdapterInfo)==null?void 0:l.bind(this.client)}}r?(me("🔐 API Middleware enabled - routing through proxy"),Wa=Pg()):Wa={configureApi:A.configureApi,streamChat:i,ApiClient:a};const s=await $D();me(`✅ Fallback to NPM package successful (v${s})`)}catch{throw new Error("Failed to load both local and npm API packages")}else throw n}return Wa}async function nn(){return await n$e()}const Hp=wo(),A$e=()=>{try{if(typeof window>"u"||!window.localStorage)return null;const e=window.localStorage.getItem("chat-api-url");return e&&e===Vl?(window.localStorage.removeItem("chat-api-url"),null):e}catch{return null}},Kg=e=>{const t=e==null?void 0:e.trim();if(t)return t;const r=A$e();return r&&r!==Vl?r:Hr()},Jp=()=>typeof window>"u"?null:window.CHATBOT_API_KEY||null;class kh{static async uploadFile(t,r,n,A,i){try{const a=ot.maxFileSizeMB*1024*1024;if(t.size>a)throw new Error(`File size exceeds maximum limit of ${ot.maxFileSizeMB}MB`);if(!(["application/pdf","text/plain","text/markdown","text/csv","application/json","text/html","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-excel","application/vnd.ms-excel.sheet.macroEnabled.12","text/x-python","text/x-python-script","text/x-java-source","text/x-java","text/x-sql","text/javascript","application/javascript","text/typescript","application/typescript","text/x-c++src","text/x-csrc","text/x-c","text/x-go","text/x-rust","text/x-ruby","text/x-php","text/x-shellscript","text/x-sh","text/yaml","text/x-yaml","text/xml","application/xml","text/css","text/x-scss","text/x-sass","text/x-less","image/png","image/jpeg","image/tiff","audio/wav","audio/mpeg","audio/mp3","audio/mp4","audio/ogg","audio/flac","audio/webm","audio/x-m4a","audio/aac","text/vtt"].includes(t.type)||/\.(pdf|txt|md|csv|json|html|docx|pptx|xlsx|py|java|sql|js|mjs|ts|tsx|cpp|cxx|cc|c|h|hpp|go|rs|rb|php|sh|bash|zsh|yaml|yml|xml|css|scss|sass|less|png|jpe?g|tiff?|wav|mp3|mp4|ogg|flac|webm|m4a|aac|vtt)$/i.test(t.name)||(t.type==="application/x-zip-compressed"||t.type==="application/zip")&&/\.xlsx$/i.test(t.name)))throw new Error(`File type not supported: ${t.type||"unknown"}`);r&&r({filename:t.name,progress:0,status:"uploading"});const l=await nn(),c=Kg(A),u=lr();let g=null,d=null;if(u){if(d=i||(typeof window<"u"?localStorage.getItem("chat-adapter-name"):null),!d)throw new Error("Adapter not configured. Please select an adapter from the dropdown.");me(`🔑 Using adapter: ${d}`)}else{if(g=n||localStorage.getItem("chat-api-key")||Jp()||Hp,!g||g==="your-api-key-here")throw new Error(`API key not configured or invalid. Please:
|
|
978
978
|
1. Open Settings (⚙️ icon) in the top-right corner
|
|
979
979
|
2. Enter a valid API key
|
|
980
980
|
3. To create an API key: POST to /admin/api-keys with admin credentials
|
|
@@ -1001,4 +1001,4 @@ ${cce}`,x_e=()=>{if(typeof document>"u"||document.getElementById(EV))return;cons
|
|
|
1001
1001
|
]`;try{const t=JSON.parse(e);if(Array.isArray(t)){me("Loading adapters from VITE_ADAPTERS environment variable");const r=ek(t);if(r.length>0)return r}}catch{}return null}async function Kv(){if(Po)return Po;try{const t=await fetch("/api/adapters");if(t.ok){const r=await t.json(),n=ek(r.adapters);if(n.length>0)return Po=n,me("Fetched adapters from /api/adapters:",Po),Po;me("/api/adapters response did not contain valid adapters, trying fallback")}me(`/api/adapters returned ${t.status}, trying fallback`)}catch{}const e=c$e();if(e&&e.length>0)return Po=e,Po;throw new Error("No adapters available. Configure VITE_ADAPTERS environment variable.")}async function tk(){try{const e=await Kv();return e.length>0?e[0]:null}catch{return null}}class u$e{constructor(){wA(this,"audioQueue",[]);wA(this,"isPlaying",!1);wA(this,"currentAudio",null);wA(this,"audioContext",null);wA(this,"isEnabled",!1);wA(this,"onPlaybackStart",null);wA(this,"onPlaybackEnd",null);wA(this,"onChunkPlayed",null);wA(this,"blobUrls",[]);wA(this,"suppressPlaybackErrors",!1)}async enableAudio(){try{try{const t=new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YQAAAAA=");t.volume=0,await t.play(),t.pause()}catch{me("[AudioStreamManager] Silent audio unlock deferred (will work on next interaction)")}return this.isEnabled=!0,me("[AudioStreamManager] Audio playback enabled"),!0}catch{return!1}}disableAudio(){!this.isEnabled&&!this.isPlaying||(this.isEnabled=!1,this.stop())}async ensureAudioContext(){if(!this.audioContext&&typeof AudioContext<"u")try{return this.audioContext=new AudioContext,this.audioContext.state==="suspended"&&await this.audioContext.resume(),!0}catch{return!1}if(this.audioContext&&this.audioContext.state==="suspended")try{await this.audioContext.resume()}catch{return!1}return!0}isAudioEnabled(){return this.isEnabled}setOnPlaybackStart(t){this.onPlaybackStart=t}setOnPlaybackEnd(t){this.onPlaybackEnd=t}setOnChunkPlayed(t){this.onChunkPlayed=t}async addChunk(t){if(!this.isEnabled){me(`[AudioStreamManager] Audio disabled, dropping chunk ${t.chunkIndex}`);return}me(`[AudioStreamManager] Adding chunk ${t.chunkIndex} to queue`),this.audioQueue.push(t),this.audioQueue.sort((r,n)=>r.chunkIndex-n.chunkIndex),this.isPlaying||this.playNextChunk()}async playNextChunk(){var r,n;if(this.audioQueue.length===0){this.isPlaying=!1,this.onPlaybackEnd&&this.onPlaybackEnd();return}if(!this.isEnabled){this.audioQueue=[],this.isPlaying=!1;return}this.suppressPlaybackErrors=!1,await this.ensureAudioContext(),this.isPlaying=!0;const t=this.audioQueue.shift();try{if(!this.isPlaying)return;if(this.onPlaybackStart&&t.chunkIndex===0&&this.onPlaybackStart(),me(`[AudioStreamManager] Playing chunk ${t.chunkIndex}`),!t.audio||t.audio.length===0)throw new Error(`Empty audio data for chunk ${t.chunkIndex}`);let A;try{A=atob(t.audio)}catch(u){throw new Error(`Failed to decode base64 audio for chunk ${t.chunkIndex}: ${u instanceof Error?u.message:String(u)}`)}if(A.length===0)throw new Error(`Decoded audio data is empty for chunk ${t.chunkIndex}`);const i=new Uint8Array(A.length);for(let u=0;u<A.length;u++)i[u]=A.charCodeAt(u);const a=t.audioFormat==="mp3"?"audio/mpeg":t.audioFormat==="wav"?"audio/wav":t.audioFormat==="ogg"?"audio/ogg":t.audioFormat==="opus"?"audio/ogg; codecs=opus":t.audioFormat==="webm"?"audio/webm":`audio/${t.audioFormat}`,s=new Blob([i],{type:a}),o=URL.createObjectURL(s);this.blobUrls.push(o);const l=new Audio;l.src=o,this.currentAudio=l;const c=()=>{l.src&&(l.src=""),URL.revokeObjectURL(o),this.blobUrls=this.blobUrls.filter(u=>u!==o)};await new Promise((u,g)=>{let d=!1;const B=()=>{var p;if(d)return;const f=l.error,w=f?{code:f.code,message:f.message||`MediaError code ${f.code}`,MEDIA_ERR_ABORTED:f.code===MediaError.MEDIA_ERR_ABORTED,MEDIA_ERR_NETWORK:f.code===MediaError.MEDIA_ERR_NETWORK,MEDIA_ERR_DECODE:f.code===MediaError.MEDIA_ERR_DECODE,MEDIA_ERR_SRC_NOT_SUPPORTED:f.code===MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED}:"Unknown error";if(this.suppressPlaybackErrors){d=!0,c(),u();return}d=!0,console.error(`[AudioStreamManager] Error playing chunk ${t.chunkIndex}:`,w,{audioFormat:t.audioFormat,chunkIndex:t.chunkIndex,audioLength:t.audio.length,mimeType:a,audioContextState:(p=this.audioContext)==null?void 0:p.state,audioSrc:l.src,audioReadyState:l.readyState}),Uu(`[AudioStreamManager] Error playing chunk ${t.chunkIndex}:`,w),c(),g(new Error(`Audio playback error: ${JSON.stringify(w)}`))};l.addEventListener("error",B,{once:!0});const h=async()=>{var f;if(!d)try{l.addEventListener("ended",()=>{d||(d=!0,me(`[AudioStreamManager] Chunk ${t.chunkIndex} finished`),this.onChunkPlayed&&this.onChunkPlayed(t.chunkIndex),c(),u())},{once:!0});const w=l.play();w&&await w}catch(w){if(d)return;if(this.suppressPlaybackErrors){d=!0,c(),u();return}d=!0,console.error(`[AudioStreamManager] Audio.play() rejected for chunk ${t.chunkIndex}:`,w,{audioFormat:t.audioFormat,chunkIndex:t.chunkIndex,audioContextState:(f=this.audioContext)==null?void 0:f.state,isEnabled:this.isEnabled,audioSrc:l.src,audioReadyState:l.readyState}),c(),g(w)}};l.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA?h():l.addEventListener("canplay",h,{once:!0})}),this.currentAudio=null,this.playNextChunk()}catch(A){if(this.suppressPlaybackErrors)return;const i=A instanceof Error?A.message:String(A);console.error(`[AudioStreamManager] Failed to play chunk ${t.chunkIndex}:`,i,A,{audioFormat:t.audioFormat,chunkIndex:t.chunkIndex,audioLength:(r=t.audio)==null?void 0:r.length,audioContextState:(n=this.audioContext)==null?void 0:n.state,isEnabled:this.isEnabled}),Uu(`[AudioStreamManager] Failed to play chunk ${t.chunkIndex}:`,A),this.playNextChunk()}}stop(){this.suppressPlaybackErrors=!0,this.isPlaying=!1,this.audioQueue=[],this.currentAudio&&(this.currentAudio.pause(),this.currentAudio.src="",this.currentAudio=null),this.blobUrls.forEach(t=>URL.revokeObjectURL(t)),this.blobUrls=[]}reset(){this.stop()}getQueueSize(){return this.audioQueue.length}isCurrentlyPlaying(){return this.isPlaying}}const gl=new u$e,mn=wo(),kN=Pv(),Wc=new Map,g$e=32,rk="chat-default-adapter-name",ud=kN&&kN.trim().length>0?kN.trim():null;let El=ud;const Sh=e=>{if(!e||!e.trim())return;const t=e.trim();if(El=t,typeof window<"u")try{localStorage.setItem(rk,t),localStorage.setItem("chat-adapter-name",t)}catch{}},Uf=()=>{const e=Pv();if(e&&e.trim().length>0)return e.trim();if(El&&El.trim().length>0)return El.trim()},SN=(e,t,r)=>{const n=lr(),A=n?Uf():void 0;return n&&A&&Sh(A),{id:e,sessionId:t,title:"New Chat",messages:[],createdAt:new Date,updatedAt:new Date,apiKey:n?void 0:mn,apiUrl:r,adapterName:A}};if(typeof window<"u")try{const e=localStorage.getItem(rk);ud?e!==ud&&localStorage.setItem(rk,ud):e&&(El=e)}catch{El=ud}const FV=(e,t)=>{const r=Wc.get(e);if(r){if(r.timeoutId&&(clearTimeout(r.timeoutId),r.timeoutId=null),r.content){const n=r.content;r.content="",t(A=>({conversations:A.conversations.map(i=>{if(i.id!==e)return i;const a=[...i.messages],s=a[a.length-1];return s&&s.role==="assistant"&&(a[a.length-1]={...s,content:s.content+n}),{...i,messages:a,updatedAt:new Date}})}))}Wc.delete(e)}},vf=()=>{const e=localStorage.getItem("chatbot-session-id");if(e)return e;const t=`session_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;return localStorage.setItem("chatbot-session-id",t),t},d$e=e=>{localStorage.setItem("chatbot-session-id",e)};let h$e=0;const F0=e=>{const t=Date.now(),r=++h$e,n=Math.random().toString(36).substr(2,9);return`msg_${t}_${r}_${n}_${e}`},ts=()=>{const e=Date.now(),t=Math.random().toString(36).substr(2,9);return`session_${e}_${t}`},YV=e=>e.filter(t=>!t.isThreadMessage&&!(t.role==="assistant"&&t.isStreaming)).length,B$e=(e,t)=>{if(e instanceof Date)return new Date(e);if(typeof e=="number"&&Number.isFinite(e)){const r=new Date(e);if(!Number.isNaN(r.getTime()))return r}if(typeof e=="string"){const r=new Date(e);if(!Number.isNaN(r.getTime()))return r}return t?new Date(t):new Date},p$e=(e,t)=>{const r=new Map;t.forEach((A,i)=>{A.databaseMessageId&&r.set(A.databaseMessageId,{message:A,index:i})});const n=new Set;return e.map(A=>{const i=A.role==="user"?"user":"assistant",a=typeof A.message_id=="string"&&A.message_id.length>0?A.message_id:void 0;let s;if(a&&r.has(a)){const c=r.get(a);s=c.message,n.add(c.index)}else for(let c=0;c<t.length;c++)if(!n.has(c)&&t[c].role===i){s=t[c],n.add(c);break}const o=A.timestamp?B$e(A.timestamp,s==null?void 0:s.timestamp):s!=null&&s.timestamp?new Date(s.timestamp):new Date,l=s?{...s,content:A.content??s.content,timestamp:o}:{id:a?`srv_${a}`:F0(i),content:A.content||"",role:i,timestamp:o};if(l.isStreaming=!1,a&&(l.databaseMessageId=a),!l.supportsThreading&&A.metadata&&typeof A.metadata=="object"){const c=A.metadata,u=c==null?void 0:c.retrieved_docs;Array.isArray(u)&&u.length>0&&(l.supportsThreading=!0)}return l})},w$e=(e,t)=>{if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++){const n=e[r],A=t[r];if(n.role!==A.role||n.content!==A.content||(n.databaseMessageId||null)!==(A.databaseMessageId||null)||+n.timestamp!=+A.timestamp)return!1}return!0};let Il=!1,yl="";async function Ws(){if(Il&&yl)return!0;try{const e=await nn(),t=localStorage.getItem("chat-api-url");t&&t===Vl&&localStorage.removeItem("chat-api-url");const r=t&&t!==Vl?t:Hr(),n=localStorage.getItem("chat-api-key")||mn,A=vf();return e.configureApi(r,n,A),yl=r,Il=!0,!0}catch(e){return En("Failed to configure API:",e),!1}}const ct=o$e((e,t)=>({conversations:[],currentConversationId:null,isLoading:!1,error:null,sessionId:vf(),getSessionId:()=>t().sessionId,configureApiSettings:async(r,n,A,i)=>{const a=t(),s=a.conversations.find(c=>c.id===a.currentConversationId),o=lr(),l=(s==null?void 0:s.sessionId)||A||vf();A&&d$e(A),e({sessionId:l});try{const c=await nn();if(o){if(!i||!i.trim())throw new Error("Adapter name is required when API middleware is enabled");c.configureApi(r,null,l,i),yl=r,Il=!0;let u;try{const g=new c.ApiClient({apiUrl:r,apiKey:null,sessionId:null,adapterName:i});typeof g.getAdapterInfo=="function"&&(u=await g.getAdapterInfo(),me("Adapter info loaded:",u))}catch(g){ft("Failed to load adapter info:",g)}if(s)e(g=>({conversations:g.conversations.map(d=>d.id===s.id?{...d,adapterName:i,apiUrl:r,adapterInfo:u,apiKey:void 0,updatedAt:new Date}:d)}));else if(i&&i.trim()){const g=`conv_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,d=ts();e(B=>({conversations:[...B.conversations,{id:g,sessionId:d,title:"New Conversation",messages:[],createdAt:new Date,updatedAt:new Date,adapterName:i,apiUrl:r,adapterInfo:u}],currentConversationId:g}))}}else{let u;if(n&&n.trim())try{const g=new c.ApiClient({apiUrl:r,apiKey:n,sessionId:null});if(typeof g.validateApiKey=="function"){me("Validating API key before configuration...");const d=await g.validateApiKey();me("API key validation successful:",{exists:d.exists,active:d.active,adapter_name:d.adapter_name,client_name:d.client_name})}else ft("API key validation not available (validateApiKey method not found)");if(typeof g.getAdapterInfo=="function")try{u=await g.getAdapterInfo(),me("Adapter info loaded:",u)}catch(d){ft("Failed to load adapter info:",d)}}catch(g){throw g instanceof Error?g:new Error(`API key validation failed: ${String(g)}`)}if(c.configureApi(r,n||"",l),yl=r,Il=!0,s&&n&&n.trim())e(g=>({conversations:g.conversations.map(d=>d.id===s.id?{...d,apiKey:n,apiUrl:r,adapterInfo:u,adapterName:void 0,updatedAt:new Date}:d)})),setTimeout(()=>{const g=t();localStorage.setItem("chat-state",JSON.stringify({conversations:g.conversations,currentConversationId:g.currentConversationId}))},0);else if(n&&n.trim()){const g=`conv_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,d=ts(),B={id:g,sessionId:d,title:"New Chat",messages:[],createdAt:new Date,updatedAt:new Date,apiKey:n,apiUrl:r,adapterInfo:u};e(h=>{const f=ot.maxConversations;if(f!==null&&h.conversations.length>=f){const w=`Maximum of ${f} conversations reached. Please delete an existing conversation before starting a new one.`;return ft(w),h}return{conversations:[B,...h.conversations],currentConversationId:g,sessionId:d}}),setTimeout(()=>{const h=t();localStorage.setItem("chat-state",JSON.stringify({conversations:h.conversations,currentConversationId:h.currentConversationId}))},0)}}}catch(c){throw e({isLoading:!1}),c instanceof Error?c:new Error("Failed to configure API settings")}o?i?localStorage.setItem("chat-adapter-name",i):localStorage.removeItem("chat-adapter-name"):(r&&r!==Vl?localStorage.setItem("chat-api-url",r):localStorage.removeItem("chat-api-url"),n&&localStorage.setItem("chat-api-key",n)),e({isLoading:!1})},createConversation:()=>{const r=t(),n=ot.maxConversations,A=r.conversations.length,i=r.currentConversationId?r.conversations.find(h=>h.id===r.currentConversationId):null;if(n!==null&&A>=n){const h=`Maximum of ${n} conversations reached. Please delete an existing conversation before starting a new one.`;throw e({error:h}),new Error(h)}if(i&&i.messages.length===0){const h="Finish or delete the current conversation before starting a new one.";throw e({error:h}),new Error(h)}const a=`conv_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,s=ts(),o=Hr(),l=mn,c=lr(),u=Uf(),g=c&&typeof window<"u"?localStorage.getItem("chat-adapter-name"):null,d=c&&(u||g)||void 0,B={id:a,sessionId:s,title:"New Chat",messages:[],createdAt:new Date,updatedAt:new Date,apiKey:c?void 0:l,apiUrl:o,adapterName:d};return e(h=>({conversations:[B,...h.conversations],currentConversationId:a,sessionId:s})),Ws().then(h=>{h&&nn().then(f=>{c?d&&(f.configureApi(o,null,s,d),Sh(d)):f.configureApi(o,l,s);try{if(c&&!d)return;const w=new f.ApiClient({apiUrl:o,apiKey:c?null:l,sessionId:null,adapterName:c?d:null});typeof w.getAdapterInfo=="function"&&w.getAdapterInfo().then(p=>{me("✅ Adapter info loaded for new conversation:",p);const m=ct.getState();ct.setState({conversations:m.conversations.map(C=>C.id===a?{...C,adapterInfo:p,updatedAt:new Date}:C)})}).catch(p=>{ft("Failed to load adapter info for new conversation:",p)})}catch{}})}),setTimeout(()=>{const h=t();localStorage.setItem("chat-state",JSON.stringify({conversations:h.conversations,currentConversationId:h.currentConversationId}))},0),a},selectConversation:async r=>{const n=t().conversations.find(A=>A.id===r);if(n){const A=n.messages.some(o=>o.role==="assistant"&&o.isStreaming);e({currentConversationId:r,sessionId:n.sessionId,isLoading:A});const i=n.apiUrl||Hr(),a=n.apiKey||mn;if(await Ws()){const o=await nn();if(o.configureApi(i,a,n.sessionId),!n.adapterInfo)try{const l=new o.ApiClient({apiUrl:i,apiKey:a,sessionId:null});if(typeof l.getAdapterInfo=="function"){const c=await l.getAdapterInfo();me("Adapter info loaded for conversation:",c),e(u=>({conversations:u.conversations.map(g=>g.id===r?{...g,adapterInfo:c,updatedAt:new Date}:g)})),setTimeout(()=>{const u=t();localStorage.setItem("chat-state",JSON.stringify({conversations:u.conversations,currentConversationId:u.currentConversationId}))},0)}}catch{}}}setTimeout(()=>{const A=t();localStorage.setItem("chat-state",JSON.stringify({conversations:A.conversations,currentConversationId:A.currentConversationId}))},0)},deleteConversation:async r=>{var i,a;const n=t(),A=n.conversations.find(s=>s.id===r);if(me(`🗑️ Deleting conversation ${r}:`,{conversationId:r,sessionId:A==null?void 0:A.sessionId,title:A==null?void 0:A.title,messageCount:A==null?void 0:A.messages.length,fileCount:((i=A==null?void 0:A.attachedFiles)==null?void 0:i.length)||0}),n.currentConversationId===r&&gl.stop(),A!=null&&A.sessionId)try{if(!await Ws())En("Failed to configure API for conversation deletion");else{const o=lr(),l=A.apiUrl||Hr(),c=A.apiKey||mn,u=A.adapterName;o?u?me(`🔑 Using conversation's adapter for deletion: ${u} (conversation: ${r})`):ft(`Skipping server deletion for conversation ${r}: adapter not configured`):me(`🔑 Using conversation's API key for deletion: ${c.substring(0,8)}... (conversation: ${r})`);const g=await nn(),d=new g.ApiClient({apiUrl:l,apiKey:o?null:c,sessionId:A.sessionId,adapterName:o?u:null}),B=((a=A==null?void 0:A.attachedFiles)==null?void 0:a.map(h=>h.file_id))||[];if(me(`🔧 Calling deleteConversationWithFiles for session: ${A.sessionId}`),me(`🔧 File IDs to delete: ${B.join(", ")||"none"}`),d.deleteConversationWithFiles){const h=await d.deleteConversationWithFiles(A.sessionId,B);me(`✅ Deleted conversation and files for session: ${A.sessionId}`,h),me(` - Deleted ${h.deleted_messages} messages`),me(` - Deleted ${h.deleted_files} files`),h.file_deletion_errors&&h.file_deletion_errors.length>0&&ft(` - Errors deleting files: ${h.file_deletion_errors.join(", ")}`)}else ft("⚠️ deleteConversationWithFiles method not available on API client")}}catch(s){En("Failed to clear conversation history from server:",s)}e(s=>{var c;const o=s.conversations.filter(u=>u.id!==r),l=s.currentConversationId===r?((c=o[0])==null?void 0:c.id)||null:s.currentConversationId;if(o.length===0){const u=`conv_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,g=ts(),d=Hr(),B=lr(),h=B?Uf():void 0,f={id:u,sessionId:g,title:"New Chat",messages:[],createdAt:new Date,updatedAt:new Date,apiKey:B?void 0:mn,apiUrl:d,adapterName:h};return Ws().then(w=>{w&&nn().then(async p=>{if(B){const m=async C=>{p.configureApi(d,null,g,C),Sh(C);try{const E=new p.ApiClient({apiUrl:d,apiKey:null,sessionId:null,adapterName:C});if(typeof E.getAdapterInfo=="function"){const I=await E.getAdapterInfo();me("✅ Adapter info loaded for default adapter:",I);const Q=ct.getState();ct.setState({conversations:Q.conversations.map(N=>N.id===u?{...N,adapterName:C,adapterInfo:I,updatedAt:new Date}:N)}),setTimeout(()=>{const N=ct.getState();localStorage.setItem("chat-state",JSON.stringify({conversations:N.conversations,currentConversationId:N.currentConversationId}))},0)}}catch{}};if(h)try{await m(h);return}catch{}try{const C=await tk();C?await m(C.name):ft("No adapters available to configure after deleting all conversations")}catch{}}else{p.configureApi(d,mn,g);try{const m=new p.ApiClient({apiUrl:d,apiKey:mn,sessionId:null});typeof m.validateApiKey=="function"&&m.validateApiKey().then(()=>{me("✅ Default API key validated after creating new conversation")}).catch(()=>{ft("Failed to validate default API key")}),typeof m.getAdapterInfo=="function"&&m.getAdapterInfo().then(C=>{me("✅ Adapter info loaded for default key:",C);const E=ct.getState();ct.setState({conversations:E.conversations.map(I=>I.id===u?{...I,adapterInfo:C,updatedAt:new Date}:I)})}).catch(()=>{ft("Failed to load adapter info for default key")})}catch{}}})}),setTimeout(()=>{localStorage.setItem("chat-state",JSON.stringify({conversations:[f],currentConversationId:u}))},0),{conversations:[f],currentConversationId:u,sessionId:g}}return setTimeout(()=>{localStorage.setItem("chat-state",JSON.stringify({conversations:o,currentConversationId:l}))},0),{conversations:o,currentConversationId:l}})},deleteAllConversations:async()=>{const n=[...t().conversations];gl.stop();const A=n.map(async c=>{var u;if(c!=null&&c.sessionId)try{if(!await Ws()){En("Failed to configure API for conversation deletion");return}const d=lr(),B=ga(c.apiUrl),h=c.apiKey||mn,f=c.adapterName;if(d&&!f){me(`Skipping server deletion for conversation ${c.id}: adapter not configured`);return}const w=await nn(),p=new w.ApiClient({apiUrl:B,apiKey:d?null:h,sessionId:c.sessionId,adapterName:d?f:null}),m=((u=c==null?void 0:c.attachedFiles)==null?void 0:u.map(C=>C.file_id))||[];p.deleteConversationWithFiles?(await p.deleteConversationWithFiles(c.sessionId,m),me(`✅ Deleted conversation ${c.id} and files`)):ft(`deleteConversationWithFiles not available for conversation ${c.id}`)}catch(g){En(`Failed to delete conversation ${c.id} from server:`,g)}});Promise.allSettled(A).then(c=>{const u=c.filter(g=>g.status==="rejected");u.length>0&&En(`Some conversations failed to delete from server: ${u.length}`,u)});const i=`conv_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,a=ts(),s=Hr(),o=lr(),l={id:i,sessionId:a,title:"New Chat",messages:[],createdAt:new Date,updatedAt:new Date,apiKey:o?void 0:mn,apiUrl:s};Ws().then(c=>{c&&nn().then(async u=>{if(o)try{const g=await tk();if(g){u.configureApi(s,null,a,g.name);const d=new u.ApiClient({apiUrl:s,apiKey:null,sessionId:null,adapterName:g.name});if(typeof d.getAdapterInfo=="function"){const B=await d.getAdapterInfo();me("✅ Adapter info loaded after clearing conversations:",B);const h=ct.getState();ct.setState({conversations:h.conversations.map(f=>f.id===i?{...f,adapterName:g.name,adapterInfo:B,updatedAt:new Date}:f)}),setTimeout(()=>{const f=ct.getState();localStorage.setItem("chat-state",JSON.stringify({conversations:f.conversations,currentConversationId:f.currentConversationId}))},0)}}}catch{}else{u.configureApi(s,mn,a);try{const g=new u.ApiClient({apiUrl:s,apiKey:mn,sessionId:null});typeof g.validateApiKey=="function"&&g.validateApiKey().then(()=>{me("✅ Default API key validated after clearing all conversations")}).catch(()=>{ft("Failed to validate default API key")}),typeof g.getAdapterInfo=="function"&&g.getAdapterInfo().then(d=>{me("✅ Adapter info loaded for default key:",d);const B=ct.getState();ct.setState({conversations:B.conversations.map(h=>h.id===i?{...h,adapterInfo:d,updatedAt:new Date}:h)})}).catch(()=>{ft("Failed to load adapter info for default key")})}catch{}}})}),e({conversations:[l],currentConversationId:i,sessionId:a}),setTimeout(()=>{localStorage.setItem("chat-state",JSON.stringify({conversations:[l],currentConversationId:i}))},0)},sendMessage:async(r,n,A)=>{var i,a,s,o,l,c,u,g,d,B,h;try{if(t().isLoading){ft("Another request is already in progress");return}if(!await Ws())throw new Error("API not properly configured. Please configure API settings first.");let w=t().currentConversationId;w||(w=t().createConversation());const p=t().conversations.find(v=>v.id===w);if(!p)throw new Error("Conversation not found");const m=n?n.map(v=>{var J;const L=(J=p==null?void 0:p.attachedFiles)==null?void 0:J.find(R=>R.file_id===v);return L||{file_id:v,filename:"",mime_type:"",file_size:0}}).filter(v=>v!==void 0):[];m.length>0&&m.forEach(v=>{t().addFileToConversation(w,v)});const C=A||null;let E,I=null;if(C){if(E=p.messages.find(v=>{var L;return((L=v.threadInfo)==null?void 0:L.thread_id)===C}),!E)throw new Error("Thread metadata not found. Please recreate the thread from this message.");if(I=((i=E.threadInfo)==null?void 0:i.thread_session_id)||null,!I)throw new Error("Thread session is missing. Please recreate the thread from this message.")}const Q=YV(p.messages),N=ot.maxMessagesPerConversation;if(N!==null&&Q>=N){ft(`[chatStore] Conversation ${w} reached the message limit (${N}).`),e({isLoading:!1});return}const k=ot.maxTotalMessages;if(k!==null&&t().conversations.reduce((L,J)=>L+YV(J.messages),0)>=k){ft(`[chatStore] Workspace reached the total message limit (${k}).`),e({isLoading:!1});return}const x={id:F0("user"),content:r,role:"user",timestamp:new Date,attachments:m.length>0?m:void 0},D=F0("assistant"),z={id:D,content:"",role:"assistant",timestamp:new Date,isStreaming:!0};if(C&&E){x.isThreadMessage=!0,x.threadId=C,x.parentMessageId=E.id,z.isThreadMessage=!0,z.threadId=C,z.parentMessageId=E.id;const v=ot.maxMessagesPerThread;if(v!==null&&p.messages.filter(J=>J.isThreadMessage?(J.threadId===C||J.parentMessageId===E.id)&&!(J.role==="assistant"&&J.isStreaming):!1).length>=v){ft(`[chatStore] Thread ${C} reached the message limit (${v}).`),e({isLoading:!1});return}}e(v=>{const L=v.conversations.find(O=>O.id===w),J=(L==null?void 0:L.messages.filter(O=>O.role==="assistant"&&O.isStreaming))||[];return J.length>0&&ft(`Cleaning up ${J.length} existing streaming messages`),{conversations:v.conversations.map(O=>{if(O.id!==w)return{...O,messages:O.messages};const U=O.messages.filter(K=>!(K.role==="assistant"&&K.isStreaming));return{...O,messages:[...U,x,z],updatedAt:new Date,title:O.messages.length===0?r.slice(0,50)+(r.length>50?"...":""):O.title}}),isLoading:!0,error:null}});const H=w;let T=!1;gl.reset();try{const v=t().conversations.find(q=>q.id===H);if(!v)throw new Error("Conversation not found");const L=lr();if(L){if(!v.adapterName)throw ft(`[sendMessage] Conversation ${H} has no adapter name`),new Error("Adapter not configured for this conversation. Please select an adapter first.");me(`[sendMessage] Using adapter for conversation ${H}: ${v.adapterName}`)}else{if(!v.apiKey)throw ft(`[sendMessage] Conversation ${H} has no API key`),new Error("API key not configured for this conversation. Please configure API settings first.");me(`[sendMessage] Using API key for conversation ${H}: ${v.apiKey.substring(0,8)}...`)}const J=ga(v.apiUrl),R=v.apiKey,O=v.adapterName,U=A||null,K=I||v.sessionId,Ae=await nn();L?Ae.configureApi(J,null,K,O):Ae.configureApi(J,R,K),U&&K!==v.sessionId&&me(`[chatStore] Thread mode: using thread session ${K} (original: ${v.sessionId})`),me("[chatStore] Starting streamChat with fileIds:",n);const G=t().conversations.find(q=>q.id===H),X=((s=(a=G==null?void 0:G.adapterInfo)==null?void 0:a.adapter_name)==null?void 0:s.includes("voice"))||((l=(o=G==null?void 0:G.adapterInfo)==null?void 0:o.adapter_name)==null?void 0:l.includes("audio"))||((u=(c=G==null?void 0:G.adapterInfo)==null?void 0:c.adapter_name)==null?void 0:u.includes("multilingual")),ie=()=>{try{const q=localStorage.getItem("chat-settings");if(q)return JSON.parse(q).voiceEnabled===!0}catch(q){ft("Failed to read global voice setting:",q)}return!1},ae=G==null?void 0:G.audioSettings,le=ie(),ge=(ae==null?void 0:ae.enabled)??le??X,te=(ae==null?void 0:ae.ttsVoice)||void 0,he=(ae==null?void 0:ae.language)||"en-US",we=ae==null?void 0:ae.audioFormat;me("[chatStore] Audio settings:",{returnAudio:ge,ttsVoice:te,language:he,audioFormat:we,isVoiceAdapter:X,adapterName:(g=G==null?void 0:G.adapterInfo)==null?void 0:g.adapter_name});for await(const q of Ae.streamChat(r,!0,n,U||void 0,void 0,void 0,he,ge,te)){if(me("[chatStore] Received stream chunk:",{text:(d=q.text)==null?void 0:d.substring(0,50),done:q.done,hasAudio:!!q.audio,hasAudioChunk:!!q.audio_chunk,audioFormat:q.audioFormat,audioLength:(B=q.audio)==null?void 0:B.length,chunkIndex:q.chunk_index}),q.audio_chunk){me("[chatStore] Received audio chunk:",{chunk_index:q.chunk_index,audioFormat:q.audioFormat,audioLength:(h=q.audio_chunk)==null?void 0:h.length});const be=q.chunk_index??0;gl.addChunk({audio:q.audio_chunk,audioFormat:q.audioFormat||"opus",chunkIndex:be})}if(q.text){const be=Gd(q.text);be?(t().appendToLastMessage(be,H),T=!0):q.text.length>100&&ft("[chatStore] Filtered out potential base64 audio data from message content")}if(q.audio&&q.done&&e(be=>({conversations:be.conversations.map(ke=>{if(ke.id!==H)return ke;const Be=[...ke.messages],pe=Be[Be.length-1];return pe&&pe.role==="assistant"&&(Be[Be.length-1]={...pe,audio:q.audio,audioFormat:q.audioFormat||"mp3"}),{...ke,messages:Be,updatedAt:new Date}})})),q.done){me("[chatStore] Stream completed, receivedAnyText:",T),me("[chatStore] Done chunk received:",{hasThreading:!!q.threading,threading:q.threading,assistantMessageId:D});const be=q.threading;be&&be.supports_threading&&(e(ke=>({conversations:ke.conversations.map(Be=>Be.id!==H?Be:{...Be,messages:Be.messages.map(pe=>pe.id===D?{...pe,supportsThreading:!0,databaseMessageId:be.message_id}:pe),updatedAt:new Date})})),me(`[chatStore] Message ${D} marked as supporting threading`,{message_id:be.message_id,session_id:be.session_id,databaseMessageId:be.message_id}));break}}T||(ft("[chatStore] No text received from stream, showing error message"),t().appendToLastMessage("No response received from the server. Please try again later.",H))}catch(v){En("Chat API error:",v);let L="Sorry, there was an error processing your request.";v instanceof Error&&(v.message.startsWith("Server error:")?L=v.message.substring(14):(v.message.includes("Could not connect")||v.message.includes("timed out"))&&(L=v.message)),t().appendToLastMessage(L,H)}FV(H,e),e(v=>{const L=v.conversations.map(O=>O.id===H?{...O,messages:O.messages.map(U=>U.id===D?{...U,isStreaming:!1}:U),updatedAt:new Date}:O),J=L.find(O=>O.id===v.currentConversationId),R=J?J.messages.some(O=>O.role==="assistant"&&O.isStreaming):!1;return{conversations:L,isLoading:R}}),setTimeout(()=>{const v=t();localStorage.setItem("chat-state",JSON.stringify({conversations:v.conversations,currentConversationId:v.currentConversationId}))},0)}catch(f){En("Chat store error:",f),e(()=>({isLoading:!1,error:`Failed to send message: ${f instanceof Error?f.message:"Unknown error"}`}))}},createThread:async(r,n)=>{try{const A=t().conversations.find(h=>h.sessionId===n);if(!A)throw new Error("Conversation not found for session");const i=lr();if(i&&!A.adapterName)throw new Error("Adapter not configured for this conversation");if(!i&&!A.apiKey)throw new Error("API key not configured for this conversation");const a=A.messages.find(h=>h.id===r);if(!a)throw new Error("Message not found");const s=a.databaseMessageId||r,o=ga(A.apiUrl||Hr()),l=A.apiKey||mn,c=A.adapterName,u=await nn(),g=new u.ApiClient({apiUrl:o,apiKey:i?null:l,sessionId:n,adapterName:i?c:null}),B=await new(await Nt(async()=>{const{ThreadService:h}=await import("./threadService-B9Db3n0J.js");return{ThreadService:h}},[])).ThreadService(g).createThread(s,n);e(h=>({conversations:h.conversations.map(f=>f.sessionId!==n?f:{...f,messages:f.messages.map(w=>w.id===r?{...w,threadInfo:B,supportsThreading:!0}:w),currentThreadId:void 0,currentThreadSessionId:void 0})})),me(`[chatStore] Created thread ${B.thread_id} for message ${r}`)}catch(A){throw En("Failed to create thread:",A),A}},appendToLastMessage:(r,n)=>{const A=Gd(r);if(!A&&r)return;const i=_D(A),a=n||t().currentConversationId;if(!a)return;const s=a,o=Wc.get(s);o?(o.content+=i,o.timeoutId&&clearTimeout(o.timeoutId)):Wc.set(s,{content:i,timeoutId:null});const l=()=>{const u=Wc.get(s);if(!u||!u.content)return;const g=u.content;u.content="",u.timeoutId=null,e(d=>({conversations:d.conversations.map(B=>{if(B.id!==a)return B;const h=[...B.messages],f=h[h.length-1];return f&&f.role==="assistant"&&f.isStreaming&&(h[h.length-1]={...f,content:f.content+g}),{...B,messages:h,updatedAt:new Date}})}))},c=Wc.get(s);c.timeoutId=setTimeout(l,g$e)},regenerateResponse:async r=>{var n,A,i,a,s,o;try{if(t().isLoading){ft("Another request is already in progress");return}if(!await Ws())throw new Error("API not properly configured");const c=t(),u=c.conversations.find(p=>p.id===c.currentConversationId);if(!u)return;const g=u.messages.findIndex(p=>p.id===r);if(g===-1)return;const d=u.messages[g-1];if(!d||d.role!=="user")return;const B=(d.attachments||[]).map(p=>p.file_id).filter(p=>typeof p=="string"&&p.length>0),h=F0("assistant");e(p=>({conversations:p.conversations.map(m=>m.id===p.currentConversationId?{...m,messages:[...m.messages.slice(0,g),{id:h,content:"",role:"assistant",timestamp:new Date,isStreaming:!0}],updatedAt:new Date}:m),isLoading:!0,error:null}));const f=c.currentConversationId;if(!f)throw new Error("No conversation selected");let w=!1;try{const p=t().conversations.find(H=>H.id===f);if(!p)throw new Error("Conversation not found");const m=lr();if(m){if(!p.adapterName)throw new Error("Adapter not configured for this conversation. Please select an adapter first.")}else if(!p.apiKey)throw new Error("API key not configured for this conversation. Please configure API settings first.");if(p.sessionId){const H=ga(p.apiUrl),T=p.apiKey,v=p.adapterName,L=await nn();m?L.configureApi(H,null,p.sessionId,v):L.configureApi(H,T,p.sessionId)}const C=await nn(),E=t().conversations.find(H=>H.id===f),I=((A=(n=E==null?void 0:E.adapterInfo)==null?void 0:n.adapter_name)==null?void 0:A.includes("voice"))||((a=(i=E==null?void 0:E.adapterInfo)==null?void 0:i.adapter_name)==null?void 0:a.includes("audio"))||((o=(s=E==null?void 0:E.adapterInfo)==null?void 0:s.adapter_name)==null?void 0:o.includes("multilingual")),Q=()=>{try{const H=localStorage.getItem("chat-settings");if(H)return JSON.parse(H).voiceEnabled===!0}catch(H){ft("Failed to read global voice setting:",H)}return!1},N=E==null?void 0:E.audioSettings,k=Q(),x=(N==null?void 0:N.enabled)??k??I,D=(N==null?void 0:N.ttsVoice)||void 0,z=(N==null?void 0:N.language)||"en-US";for await(const H of C.streamChat(d.content,!0,B.length>0?B:void 0,void 0,void 0,void 0,z,x,D)){if(H.text){const T=Gd(H.text);T?(t().appendToLastMessage(T,f),w=!0):H.text.length>100&&ft("[chatStore] Filtered out potential base64 audio data from regenerated message content")}if(H.audio&&H.done&&e(T=>({conversations:T.conversations.map(v=>{if(v.id!==f)return v;const L=[...v.messages],J=L[L.length-1];return J&&J.role==="assistant"&&(L[L.length-1]={...J,audio:H.audio,audioFormat:H.audioFormat||"mp3"}),{...v,messages:L,updatedAt:new Date}})})),H.done)break}w||t().appendToLastMessage("No response received from the server. Please try again later.",f)}catch(p){En("Regenerate API error:",p);let m="Sorry, there was an error regenerating the response.";p instanceof Error&&(p.message.startsWith("Server error:")?m=p.message.substring(14):(p.message.includes("Could not connect")||p.message.includes("timed out"))&&(m=p.message)),t().appendToLastMessage(m,f)}FV(f,e),e(p=>{const m=p.conversations.map(I=>I.id===f?{...I,messages:I.messages.map(Q=>Q.id===h?{...Q,isStreaming:!1}:Q),updatedAt:new Date}:I),C=m.find(I=>I.id===p.currentConversationId),E=C?C.messages.some(I=>I.role==="assistant"&&I.isStreaming):!1;return{conversations:m,isLoading:E}})}catch(l){En("Regenerate error:",l),e({isLoading:!1,error:`Failed to regenerate response: ${l instanceof Error?l.message:"Unknown error"}`})}},updateConversationTitle:(r,n)=>{e(A=>({conversations:A.conversations.map(i=>i.id===r?{...i,title:n,updatedAt:new Date}:i)})),setTimeout(()=>{const A=t();localStorage.setItem("chat-state",JSON.stringify({conversations:A.conversations,currentConversationId:A.currentConversationId}))},0)},clearError:()=>{e({error:null})},cleanupStreamingMessages:()=>{e(r=>({conversations:r.conversations.map(n=>(n.id===r.currentConversationId,n)),isLoading:!1}))},canCreateNewConversation:()=>{const r=t(),n=ot.maxConversations;if(!r.currentConversationId)return n===null||r.conversations.length<n;const A=r.conversations.find(i=>i.id===r.currentConversationId);return A&&A.messages.length>0?n===null||r.conversations.length<n:!1},getConversationCount:()=>t().conversations.length,addFileToConversation:(r,n)=>{me("[chatStore] addFileToConversation called",{conversationId:r,fileId:n.file_id,filename:n.filename}),e(A=>{var s,o;const i={conversations:A.conversations.map(l=>l.id===r?{...l,attachedFiles:[...(l.attachedFiles||[]).filter(c=>c.file_id!==n.file_id),n],updatedAt:new Date}:l)},a=i.conversations.find(l=>l.id===r);return me(`[chatStore] Updated conversation ${r}`,{hasConversation:!!a,attachedFilesCount:((s=a==null?void 0:a.attachedFiles)==null?void 0:s.length)||0,attachedFiles:(o=a==null?void 0:a.attachedFiles)==null?void 0:o.map(l=>({file_id:l.file_id,filename:l.filename}))}),i}),setTimeout(()=>{const A=t();localStorage.setItem("chat-state",JSON.stringify({conversations:A.conversations,currentConversationId:A.currentConversationId}))},0)},removeFileFromConversation:async(r,n)=>{try{const A=t().conversations.find(l=>l.id===r);if(!A)throw new Error("Conversation not found");if(lr()){if(!A.adapterName)throw new Error("Adapter not configured for this conversation. Cannot delete file.")}else if(!A.apiKey)throw new Error("API key not configured for this conversation. Cannot delete file.");const a=A.apiKey,s=A.adapterName,o=ga(A.apiUrl);me(`[chatStore] Calling FileUploadService.deleteFile for ${n}`),await kh.deleteFile(n,a,o,s),me(`[chatStore] Successfully deleted file ${n} from server`)}catch(A){A instanceof Error&&(A.message.includes("404")||A.message.includes("File not found"))}e(A=>({conversations:A.conversations.map(i=>i.id===r?{...i,attachedFiles:(i.attachedFiles||[]).filter(a=>a.file_id!==n),updatedAt:new Date}:i)})),setTimeout(()=>{const A=t();localStorage.setItem("chat-state",JSON.stringify({conversations:A.conversations,currentConversationId:A.currentConversationId}))},0)},loadConversationFiles:async r=>{try{const n=t().conversations.find(g=>g.id===r);if(!n)return;if(lr()){if(!n.adapterName){me(`Skipping file load for conversation ${r}: adapter not configured`);return}}else if(!n.apiKey){me(`Skipping file load for conversation ${r}: API key not configured`);return}const i=n.apiKey,a=n.adapterName,s=ga(n.apiUrl);if(new Set((n.attachedFiles||[]).map(g=>g.file_id)).size===0){me(`No files to sync for conversation ${r}`);return}const c=(await kh.listFiles(i,s,a)).map(g=>({file_id:g.file_id,filename:g.filename,mime_type:g.mime_type,file_size:g.file_size,upload_timestamp:g.upload_timestamp,processing_status:g.processing_status,chunk_count:g.chunk_count})),u=new Map(c.map(g=>[g.file_id,g]));e(g=>{const d=g.conversations.find(h=>h.id===r);if(!d)return g;const B=(d.attachedFiles||[]).map(h=>u.get(h.file_id)||h).filter(h=>u.has(h.file_id)||!h.processing_status||h.processing_status==="processing");return{conversations:g.conversations.map(h=>h.id===r?{...h,attachedFiles:B,updatedAt:new Date}:h)}}),setTimeout(()=>{const g=t();localStorage.setItem("chat-state",JSON.stringify({conversations:g.conversations,currentConversationId:g.currentConversationId}))},0)}catch(n){En(`Failed to load files for conversation ${r}:`,n)}},syncConversationFiles:async r=>{await t().loadConversationFiles(r)},syncConversationsWithBackend:async()=>{try{const r=t();if(r.conversations.length===0)return;const n=await nn(),A=lr(),i=ot.maxMessagesPerConversation!==null&&ot.maxMessagesPerConversation||void 0;let a=!1;const o=(await Promise.all(r.conversations.map(async l=>{var c;if(!l.sessionId)return null;if(A&&!l.adapterName)return ft(`[chatStore] Skipping backend sync for conversation ${l.id} - adapter not configured`),null;try{const u=new n.ApiClient({apiUrl:ga(l.apiUrl),apiKey:A?null:l.apiKey||mn,sessionId:l.sessionId,adapterName:A?l.adapterName:null});if(typeof u.getConversationHistory!="function")return a||(a=!0,ft("[chatStore] Conversation history endpoint not supported by current API client")),null;const g=await u.getConversationHistory(l.sessionId,i),d=Array.isArray(g==null?void 0:g.messages)?g.messages:[];if(d.length===0)return l.messages.length===0?null:{id:l.id,sessionId:(g==null?void 0:g.session_id)||l.sessionId,messages:[],cleared:!0,updatedAt:new Date};const B=p$e(d,l.messages);return w$e(l.messages,B)?null:{id:l.id,sessionId:(g==null?void 0:g.session_id)||l.sessionId,messages:B,cleared:!1,updatedAt:((c=B[B.length-1])==null?void 0:c.timestamp)||new Date}}catch(u){return ft(`[chatStore] Failed to sync session ${l.sessionId}:`,u),null}}))).filter(l=>!!l);if(o.length===0)return;e(l=>{const c=new Map(o.map(g=>[g.id,g]));return{conversations:l.conversations.map(g=>{const d=c.get(g.id);return d?d.cleared?{...g,sessionId:d.sessionId||g.sessionId,messages:[],attachedFiles:[],title:"New Chat",updatedAt:d.updatedAt}:{...g,sessionId:d.sessionId||g.sessionId,messages:d.messages,updatedAt:d.updatedAt}:g}),currentConversationId:l.currentConversationId}}),setTimeout(()=>{const l=t();localStorage.setItem("chat-state",JSON.stringify({conversations:l.conversations,currentConversationId:l.currentConversationId}))},0)}catch{}}})),f$e=async()=>{var c;const e=localStorage.getItem("chat-state"),t=Hr(),r=typeof window<"u"?!!localStorage.getItem("chat-api-url"):!1;let n=vf(),A=!1;if(e)try{const u=JSON.parse(e),g=h=>{if(h instanceof Date)return h;const f=h?new Date(h):new Date;return Number.isNaN(f.getTime())?new Date:f},d=Array.isArray(u.conversations)?u.conversations:[];if(u.conversations=d.map(h=>{const w=(Array.isArray(h.messages)?h.messages:[]).filter(E=>!(E.role==="assistant"&&E.isStreaming)).map(E=>({...E,timestamp:g(E.timestamp),isStreaming:!1})),p={id:h.id,sessionId:h.sessionId||ts(),title:h.title||"New Chat",messages:w,createdAt:g(h.createdAt),updatedAt:g(h.updatedAt),attachedFiles:h.attachedFiles||[],apiKey:h.apiKey||mn,adapterName:h.adapterName,apiUrl:h.apiUrl,adapterInfo:h.adapterInfo,audioSettings:h.audioSettings,currentThreadId:void 0,currentThreadSessionId:void 0},C=p.messages.length===0&&(!p.apiKey||p.apiKey===mn)&&!r?t:ga(h.apiUrl);return{...p,apiUrl:C}}),A=u.conversations&&u.conversations.length>0,u.currentConversationId&&u.conversations){const h=u.conversations.find(f=>f.id===u.currentConversationId);h&&h.sessionId&&(n=h.sessionId)}if(!u.conversations||u.conversations.length===0){const h=`conv_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,f=ts(),w=SN(h,f,Hr());ct.setState({conversations:[w],currentConversationId:h,sessionId:f}),n=f}else ct.setState({conversations:u.conversations||[],currentConversationId:u.currentConversationId||((c=u.conversations[0])==null?void 0:c.id)||null,sessionId:n}),!u.currentConversationId&&u.conversations.length>0&&(ct.setState({currentConversationId:u.conversations[0].id,sessionId:u.conversations[0].sessionId||n}),n=u.conversations[0].sessionId||n);const B=ct.getState().conversations;me("📋 Loaded conversations:",B.map(h=>{var f;return{id:h.id,title:h.title,sessionId:h.sessionId,messageCount:((f=h.messages)==null?void 0:f.length)||0}})),setTimeout(()=>{ct.getState().cleanupStreamingMessages()},100)}catch(u){En("Failed to load chat state:",u);const g=`conv_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,d=ts(),B=SN(g,d,Hr());ct.setState({conversations:[B],currentConversationId:g,sessionId:d}),n=d}else{const u=`conv_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,g=ts(),d=SN(u,g,Hr());ct.setState({conversations:[d],currentConversationId:u,sessionId:g}),n=g}const i=ct.getState(),a=i.currentConversationId?i.conversations.find(u=>u.id===i.currentConversationId):null,s=lr(),o=A&&(a!=null&&a.apiKey)?a.apiKey:mn,l=A&&(a!=null&&a.apiUrl)?a.apiUrl:Hr();try{const u=await nn();if(s){const g=a==null?void 0:a.adapterName;if(g){if(u.configureApi(l,null,n,g),yl=l,Il=!0,me("✅ Using existing adapter from conversation:",g),!El&&g&&Sh(g),!(a!=null&&a.adapterInfo))try{const d=new u.ApiClient({apiUrl:l,apiKey:null,sessionId:null,adapterName:g});if(typeof d.getAdapterInfo=="function"){const B=await d.getAdapterInfo();me("✅ Adapter info loaded for existing adapter:",B);const h=ct.getState();h.currentConversationId&&(ct.setState({conversations:h.conversations.map(f=>f.id===h.currentConversationId?{...f,adapterInfo:B,updatedAt:new Date}:f)}),setTimeout(()=>{const f=ct.getState();localStorage.setItem("chat-state",JSON.stringify({conversations:f.conversations,currentConversationId:f.currentConversationId}))},0))}}catch(d){ft("Failed to load adapter info for existing adapter:",d)}}else{const d=Uf(),B=async h=>{me("🔄 Auto-selecting adapter:",h),u.configureApi(l,null,n,h),yl=l,Il=!0;try{localStorage.setItem("chat-adapter-name",h)}catch{}Sh(h);try{const f=new u.ApiClient({apiUrl:l,apiKey:null,sessionId:null,adapterName:h});let w;typeof f.getAdapterInfo=="function"&&(w=await f.getAdapterInfo(),me("✅ Adapter info loaded for auto-selected adapter:",w));const p=ct.getState();p.currentConversationId&&(ct.setState({conversations:p.conversations.map(m=>m.id===p.currentConversationId?{...m,adapterName:h,adapterInfo:w,apiUrl:l,apiKey:void 0,updatedAt:new Date}:m)}),setTimeout(()=>{const m=ct.getState();localStorage.setItem("chat-state",JSON.stringify({conversations:m.conversations,currentConversationId:m.currentConversationId}))},0))}catch(f){ft("Failed to validate auto-selected adapter on startup:",f)}};if(d)await B(d);else{const h=await tk();h?await B(h.name):ft("No adapters available for auto-selection in middleware mode")}}}else if(u.configureApi(l,o,n),yl=l,Il=!0,o===mn)try{const g=new u.ApiClient({apiUrl:l,apiKey:o,sessionId:null});if(typeof g.validateApiKey=="function"&&(await g.validateApiKey(),me("✅ Default API key validated on startup")),typeof g.getAdapterInfo=="function"){const d=await g.getAdapterInfo();me("✅ Adapter info loaded for default key:",d);const B=ct.getState();B.currentConversationId&&ct.setState({conversations:B.conversations.map(h=>h.id===B.currentConversationId?{...h,adapterInfo:d,updatedAt:new Date}:h)})}}catch(g){ft("Failed to validate default API key on startup:",g)}}catch(u){En("Failed to initialize API:",u)}try{await ct.getState().syncConversationsWithBackend()}catch{}};typeof window<"u"&&f$e();const m$e=wo(),E$e=new Map,I$e=new Map,y$e=new Map,C$e=()=>{if(typeof window>"u")return null;try{return localStorage.getItem("chat-adapter-name")}catch{return null}},tse=e=>typeof e=="object"&&e!==null&&"message"in e,Q$e=e=>e instanceof Error?e.message:typeof e=="string"?e:tse(e)?e.message??"Unknown error":"Unknown error";function M$e({conversationId:e,onFilesSelected:t,onUploadError:r,onClose:n,onUploadingChange:A,onUploadSuccess:i,maxFiles:a=ot.maxFilesPerConversation,disabled:s=!1}){const[o,l]=y.useState(!1),[c,u]=y.useState(0),g=y.useRef(null),d=y.useRef(y$e),B=y.useRef(new Map),h=y.useRef(!0),f=y.useRef(E$e),w=y.useRef(I$e),p=y.useRef(e),m=ct(K=>K.conversations),C=y.useMemo(()=>{if(!e)return new Map;const K=f.current.get(e);return K?new Map(K):new Map},[e,c]),E=y.useCallback(K=>{if(!K){A==null||A(null,!1),u(X=>X+1);return}const Ae=f.current.get(K)||new Map,G=m.find(X=>X.id===K);if(G&&G.attachedFiles){const X=G.attachedFiles.filter(le=>!le.processing_status||le.processing_status==="processing"||le.processing_status==="uploading"),ie=new Map(Ae);let ae=!1;X.forEach(le=>{if(!Array.from(Ae.values()).find(te=>te.fileId===le.file_id)){const te=`${K}-${le.filename}-${le.file_id}`;ie.set(te,{filename:le.filename,progress:le.processing_status==="uploading"?50:90,status:le.processing_status||"processing",fileId:le.file_id}),ae=!0}}),ae||ie.size>0?(f.current.set(K,ie),A==null||A(K,!0)):(f.current.delete(K),A==null||A(K,!1))}else Ae.size>0?f.current.set(K,Ae):f.current.delete(K),A==null||A(K,Ae.size>0);u(X=>X+1)},[m,A]);y.useEffect(()=>{p.current=e,E(e)},[e,E]),y.useEffect(()=>{e&&E(e)},[m,e,E]);const I=y.useCallback((K,Ae)=>{if(!K)return;const G=f.current.get(K)||new Map,X=Ae(new Map(G));X.size>0?f.current.set(K,X):f.current.delete(K),A==null||A(K,X.size>0),u(ie=>ie+1)},[A]),Q=y.useCallback((K,Ae)=>{if(!K)return;const G=w.current.get(K)||[],X=Ae([...G||[]]),ie=new Set(G.map(ae=>ae.file_id));if(w.current.set(K,X),t(K,X),i){const ae=X.filter(le=>!ie.has(le.file_id));ae.length>0&&i(K,ae)}u(ae=>ae+1)},[t,i]),N=ct(K=>K.removeFileFromConversation),k=ct(K=>K.addFileToConversation);y.useEffect(()=>(h.current=!0,()=>{h.current=!1}),[]);const x=y.useCallback(()=>{h.current=!1,new Map(B.current).forEach(Ae=>Ae.abort()),setTimeout(()=>{const Ae=ct.getState(),G=new Map(Ae.conversations.map(ie=>[ie.id,ie])),X=[];d.current.forEach((ie,ae)=>{var le;if(ie){const ge=G.get(ie);if(new Set(((le=ge==null?void 0:ge.attachedFiles)==null?void 0:le.map(he=>he.file_id))||[]).has(ae)){d.current.delete(ae);return}}X.push({fileId:ae,conversationId:ie||null})}),X.length>0&&(n==null||n(),X.forEach(async({fileId:ie,conversationId:ae})=>{try{if(ae)await N(ae,ie);else{const ge=lr()?C$e():null;await kh.deleteFile(ie,void 0,void 0,ge??void 0)}}catch(le){if(tse(le)){const ge=le.message??"";!ge.includes("404")&&ge.includes("File not found")}}}))},300)},[n,N]);y.useEffect(()=>x,[x]);const D=y.useCallback(async K=>{if(!K||K.length===0)return;const Ae=Array.from(K),G=ct.getState(),X=e||G.currentConversationId;if(!X){r==null||r("Please select or create a conversation before uploading files.");return}const ie=G.conversations.find(we=>we.id===X);if(!ie){r==null||r("Conversation not found. Please try again.");return}if((w.current.get(X)||[]).length+Ae.length>a){const we=`Maximum ${a} files allowed per conversation. Please remove some files first.`;r==null||r(we);return}if(ot.maxTotalFiles!==null&&G.conversations.reduce((be,ke)=>{var Be;return be+(((Be=ke.attachedFiles)==null?void 0:Be.length)||0)},0)+Ae.length>ot.maxTotalFiles){const be=`Maximum ${ot.maxTotalFiles} total files allowed across all conversations. Please remove some files from other conversations first.`;r==null||r(be);return}const le=lr();if(le){if(!ie.adapterName){r==null||r("Adapter not configured for this conversation. Please select an adapter first.");return}}else if(!ie.apiKey||ie.apiKey===m$e){r==null||r("API key not configured for this conversation. Please configure API settings first.");return}const ge=ie.apiKey,te=ie.adapterName,he=ga(ie.apiUrl);for(let we=0;we<Ae.length;we++){const q=Ae[we],be=new AbortController;B.current.set(q.name,be);const ke=`${X}-${q.name}-${Date.now()}-${we}`;let Be=null;try{const pe=await kh.uploadFile(q,xe=>{if(I(X,Le=>(Le.set(ke,xe),Le)),xe.fileId&&!Be){Be=xe.fileId,d.current.set(xe.fileId,X);const Le={file_id:xe.fileId,filename:q.name,mime_type:q.type||"application/octet-stream",file_size:q.size,processing_status:xe.status==="uploading"?"uploading":xe.status==="processing"?"processing":xe.status==="completed"?"completed":void 0};me(`[FileUpload] Adding file ${xe.fileId} to conversation ${X} immediately (status: ${Le.processing_status})`),k(X,Le)}},ge,he,le?te:void 0).catch(xe=>{if(xe.message&&xe.message.includes("was deleted")){Be&&d.current.delete(Be);const Le=xe.message.match(/File\s+([\w-]+)\s+was deleted/);return Le&&Le[1]&&d.current.delete(Le[1]),me(`File ${q.name} was deleted during upload`),null}throw xe});pe?(d.current.set(pe.file_id,X),me(`[FileUpload] Updating file ${pe.file_id} in conversation ${X} with final status`),k(X,pe),pe.processing_status==="completed"?I(X,xe=>(xe.delete(ke),xe)):I(X,xe=>{const Le=xe.get(ke);return Le&&xe.set(ke,{...Le,progress:90,status:"processing",fileId:pe.file_id}),xe}),Q(X,xe=>{if(new Set(xe.map(Ke=>Ke.file_id)).has(pe.file_id))return xe;const Fe=[...xe,pe];return me(`[FileUpload] Updated uploadedFiles for ${X}: ${Fe.length} files`,Fe),Fe})):(ft(`Upload completed for ${q.name} but uploadedAttachment is null`),I(X,xe=>(xe.delete(ke),xe)))}catch(pe){const xe=Q$e(pe);if(pe instanceof DOMException&&pe.name==="AbortError"||be.signal.aborted){me(`Upload cancelled for ${q.name}`),Be&&d.current.delete(Be);continue}if(xe.includes("was deleted")){me(`File ${q.name} was deleted during upload`),Be&&d.current.delete(Be);const Le=xe.match(/File\s+([\w-]+)\s+was deleted/);Le&&Le[1]&&d.current.delete(Le[1]);continue}h.current?(Uu(`Failed to upload file ${q.name}:`,pe),Uu(`File type: ${q.type}, File name: ${q.name}`),r==null||r(xe||`Failed to upload ${q.name}`)):ft(`Upload error for ${q.name} (component unmounted):`,xe),Be&&d.current.delete(Be)}finally{B.current.delete(q.name)}}},[k,e,a,r,Q,I]),z=y.useCallback(K=>{K.preventDefault(),K.stopPropagation(),s||l(!0)},[s]),H=y.useCallback(K=>{K.preventDefault(),K.stopPropagation(),l(!1)},[]),T=y.useCallback(K=>{if(K.preventDefault(),K.stopPropagation(),l(!1),s)return;const Ae=K.dataTransfer.files;D(Ae)},[s,D]),v=y.useCallback(K=>{const Ae=K.target.files;D(Ae),g.current&&(g.current.value="")},[D]),L=y.useCallback(()=>{!s&&g.current&&g.current.click()},[s]),J=C.size>0,R=y.useMemo(()=>{const K=new Map;return m.forEach(Ae=>{K.set(Ae.id,Ae.title||"Conversation")}),K},[m]),O=y.useMemo(()=>{const K=[];return f.current.forEach((Ae,G)=>{G!==e&&Ae.size>0&&K.push({conversationId:G,uploads:Array.from(Ae.entries()).map(([X,ie])=>({key:X,progress:ie}))})}),K},[e,c]),U=b.jsx("div",{className:"w-full max-w-full overflow-hidden space-y-2",children:Array.from(C.values()).map(K=>b.jsxs("div",{className:"w-full max-w-full flex items-center gap-3 p-3 bg-slate-50 dark:bg-slate-800/50 rounded-lg overflow-hidden",children:[b.jsx(_c,{className:"w-4 h-4 text-emerald-600 dark:text-emerald-400 animate-spin flex-shrink-0"}),b.jsxs("div",{className:"flex-1 min-w-0 overflow-hidden",children:[b.jsx("p",{className:"text-sm font-medium text-slate-700 dark:text-slate-300 truncate",children:K.filename}),b.jsx("div",{className:"mt-1 bg-slate-200 dark:bg-slate-700 rounded-full h-1.5",children:b.jsx("div",{className:"bg-emerald-600 dark:bg-emerald-400 h-1.5 rounded-full transition-all duration-300",style:{width:`${K.progress}%`}})})]}),b.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:K.status==="uploading"?"Uploading...":K.status==="processing"?"Processing...":K.status==="completed"?"Done":"Error"})]},K.filename))});return J?b.jsx("div",{className:"w-full max-w-full overflow-hidden space-y-3",children:U}):b.jsxs("div",{className:"w-full max-w-full overflow-hidden space-y-3",children:[b.jsxs("div",{onClick:L,onDragOver:z,onDragLeave:H,onDrop:T,className:`
|
|
1002
1002
|
relative w-full max-w-full border-2 border-dashed rounded-xl p-3 sm:p-4 transition-all cursor-pointer
|
|
1003
1003
|
${o?"border-emerald-500 bg-emerald-50 dark:bg-emerald-900/20 dark:border-emerald-400":s?"border-slate-200 dark:border-slate-700 bg-slate-50 dark:bg-slate-800/50 cursor-not-allowed opacity-50":"border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-900/50 hover:border-emerald-400 hover:bg-emerald-50/30 dark:hover:bg-emerald-900/10"}
|
|
1004
|
-
`,children:[b.jsx("input",{ref:g,type:"file",multiple:!0,onChange:v,className:"hidden",disabled:s,accept:".pdf,.doc,.docx,.txt,.md,.csv,.json,.html,.pptx,.xlsx,.py,.java,.sql,.js,.mjs,.ts,.tsx,.cpp,.cxx,.cc,.c,.h,.hpp,.go,.rs,.rb,.php,.sh,.bash,.zsh,.yaml,.yml,.xml,.css,.scss,.sass,.less,.png,.jpg,.jpeg,.tiff,.wav,.mp3,.mp4,.ogg,.flac,.webm,.m4a,.aac,.vtt"}),b.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 text-center",children:[b.jsx(Ace,{className:`w-6 h-6 ${o?"text-emerald-600 dark:text-emerald-400":"text-slate-400 dark:text-slate-500"}`}),b.jsxs("div",{className:"px-2",children:[b.jsx("p",{className:"text-xs sm:text-sm font-medium text-slate-700 dark:text-slate-300",children:s?"File upload disabled":o?"Drop files here":"Click or drag files to upload"}),b.jsxs("p",{className:"text-[10px] sm:text-xs text-slate-500 dark:text-slate-400 mt-0.5 px-1",children:["PDF, DOCX, TXT, CSV, JSON, HTML, code files (.py, .js, .ts, .java, .sql, etc.), images, audio (max ",a," files)"]})]})]})]}),O.length>0&&b.jsxs("div",{className:"w-full max-w-full space-y-3 rounded-lg border border-slate-200 bg-white p-3 dark:border-slate-700 dark:bg-slate-900/40",children:[b.jsx("p",{className:"text-xs font-semibold text-slate-600 dark:text-slate-300",children:"Uploads in other conversations"}),O.map(({conversationId:K,uploads:Ae})=>b.jsxs("div",{className:"space-y-2",children:[b.jsx("div",{className:"text-xs font-medium text-slate-500 dark:text-slate-400",children:R.get(K)||"Conversation"}),Ae.map(({key:G,progress:X})=>b.jsxs("div",{className:"w-full max-w-full flex items-center gap-3 p-3 bg-slate-50 dark:bg-slate-800/50 rounded-lg overflow-hidden",children:[b.jsx(_c,{className:"w-4 h-4 text-emerald-600 dark:text-emerald-400 animate-spin flex-shrink-0"}),b.jsxs("div",{className:"flex-1 min-w-0 overflow-hidden",children:[b.jsx("p",{className:"text-sm font-medium text-slate-700 dark:text-slate-300 truncate",children:X.filename}),b.jsx("div",{className:"mt-1 bg-slate-200 dark:bg-slate-700 rounded-full h-1.5",children:b.jsx("div",{className:"bg-emerald-600 dark:bg-emerald-400 h-1.5 rounded-full transition-all duration-300",style:{width:`${X.progress}%`}})})]}),b.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:X.status==="uploading"?"Uploading...":X.status==="processing"?"Processing...":X.status==="completed"?"Done":"Error"})]},G))]},K))]})]})}const NV={"image/jpeg":"jpg","image/jpg":"jpg","image/png":"png","image/tiff":"tiff","image/tif":"tif","image/gif":"gif","image/webp":"webp","application/pdf":"pdf","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/msword":"doc","text/plain":"txt","text/markdown":"md","application/json":"json"};function F$e(e){if(!e)return"bin";if(NV[e])return NV[e];const t=e.split("/");return t.length===2&&t[1]?t[1]:"bin"}function Y$e(e){return e.replace(/[^a-zA-Z0-9._-]/g,"_").replace(/_+/g,"_")||"pasted-file"}function N$e(e){const t=e.lastIndexOf(".");return t===-1||t===e.length-1?null:e.slice(t+1).toLowerCase()}function b$e(e){const t=e.lastIndexOf(".");return t===-1?e:e.slice(0,t)}function x$e(e,t){const r=Date.now(),n=e.name&&e.name.trim().length>0?e.name.trim():"pasted-file",A=Y$e(b$e(n)),a=N$e(n)||F$e(e.type),s=`${A}-${r}-${t}.${a}`;return new File([e],s,{type:e.type||"application/octet-stream"})}function bV({onSend:e,disabled:t=!1,placeholder:r=Xae(),isCentered:n=!1}){var kB;const[A,i]=y.useState(""),[a,s]=y.useState(!1),[o,l]=y.useState(!1),[c,u]=y.useState(!1),[g,d]=y.useState([]),[B,h]=y.useState({}),[f,w]=y.useState(new Map),[p,m]=y.useState(!1),[C,E]=y.useState(!1),[I,Q]=y.useState(null),[N,k]=y.useState(null),[x,D]=y.useState(null),z=y.useRef(null),H=y.useRef(new Set),T=y.useRef(""),v=y.useRef(!1),L=y.useRef(0),J=y.useRef(null),{settings:R,updateSettings:O}=em(),U=y.useCallback((fe,He)=>{fe&&h(pt=>{if(pt[fe]===He)return pt;const Yt={...pt};return He?Yt[fe]=!0:delete Yt[fe],Yt})},[]),[K,Ae]=y.useState(0),{createConversation:G,currentConversationId:X,conversations:ie,isLoading:ae,syncConversationFiles:le}=ct(),ge=ie.find(fe=>fe.id===X),te=ge?ge.messages.filter(fe=>!(fe.role==="assistant"&&fe.isStreaming)).length:0,he=ie.reduce((fe,He)=>fe+He.messages.filter(pt=>!(pt.role==="assistant"&&pt.isStreaming)).length,0),we=!!ge&&ot.maxMessagesPerConversation!==null&&te>=ot.maxMessagesPerConversation,q=ot.maxTotalMessages!==null&&he>=ot.maxTotalMessages,be=y.useCallback(()=>{Ae(fe=>fe+1)},[]),{isListening:ke,isSupported:Be,startListening:pe,stopListening:xe,error:Le}=$_e(fe=>{i(He=>{const pt=(He+fe).slice(0,ot.maxMessageLength);return T.current=pt,pt})},be),Fe=T_e(),Ke=Fe&&Be,st=z_e(),Ot=(ge==null?void 0:ge.attachedFiles)||[],en=ie.reduce((fe,He)=>{var pt;return fe+(((pt=He.attachedFiles)==null?void 0:pt.length)||0)},0),vr=ot.maxFilesPerConversation!==null&&ot.maxFilesPerConversation>0&&Ot.length>=ot.maxFilesPerConversation,Ce=ot.maxTotalFiles!==null&&en>=ot.maxTotalFiles,_=((kB=ge==null?void 0:ge.adapterInfo)==null?void 0:kB.isFileSupported)??!1,se=g.some(fe=>fe.processing_status?fe.processing_status!=="completed"&&fe.processing_status!=="error"&&fe.processing_status!=="failed":!0)||Ot.some(fe=>fe.processing_status?fe.processing_status!=="completed"&&fe.processing_status!=="error"&&fe.processing_status!=="failed":!0),Qe=X?!!B[X]:!1,it=Object.values(B).some(Boolean),ut=t||se||Qe||(we||q),er=st&&_,oe=vr||Ce,rt=!er||ut||oe;y.useEffect(()=>{if(z.current){z.current.style.height="auto";const He=z.current.scrollHeight;z.current.style.height=`${Math.min(He,120)}px`,z.current.style.overflowY=He>120?"auto":"hidden"}},[A]);const lt=()=>{const fe=document.activeElement;return fe&&fe.tagName==="TEXTAREA"};y.useEffect(()=>{!ut&&z.current&&!lt()&&z.current.focus()},[ut]);const Et=y.useRef(ae);y.useEffect(()=>{Et.current&&!ae&&!ut&&z.current&&setTimeout(()=>{z.current&&!lt()&&z.current.focus()},100),Et.current=ae},[ae,ut]),y.useEffect(()=>{if(!Ke||(K>L.current&&(v.current=!0,L.current=K),!v.current||K===0))return;const fe=setTimeout(()=>{const He=T.current.trim(),pt=ct.getState();if(me("[MessageInput] Auto-send check after voice completion:",{hasMessage:!!He,isInputDisabled:ut,isComposing:a,isLoading:pt.isLoading}),!He){v.current=!1;return}if(!ut&&!a&&!pt.isLoading){const Yt=pt.conversations.find(Vt=>Vt.id===pt.currentConversationId),Gn=((Yt==null?void 0:Yt.attachedFiles)||[]).map(Vt=>Vt.file_id);e(He,Gn.length>0?Gn:void 0),v.current=!1,i(""),T.current="",z.current&&(z.current.style.height="auto",z.current.style.overflowY="hidden")}},400);return()=>clearTimeout(fe)},[Ke,K,ut,a,e]),y.useEffect(()=>{Qe&&c&&u(!1)},[Qe,c]),y.useEffect(()=>{!Qe&&g.length},[Qe,g.length,c]);const vt=y.useCallback((fe,He)=>{setTimeout(()=>{let pt=ct.getState(),Yt=He||pt.currentConversationId;if(Yt||(Yt=G(),pt=ct.getState(),Yt=pt.currentConversationId||Yt),!Yt)return;const dr=new Set(fe.map(Vt=>Vt.file_id)),Gn=[];H.current.forEach((Vt,tr)=>{const[,...hr]=tr.split("-"),za=hr.join("-");dr.has(za)||Gn.push(tr)}),Gn.forEach(Vt=>H.current.delete(Vt)),fe.forEach(Vt=>{const tr=`${Yt}-${Vt.file_id}`;H.current.has(tr)||(H.current.add(tr),me(`[MessageInput] Adding file ${Vt.file_id} to conversation ${Yt}`),pt.addFileToConversation(Yt,Vt))})},0)},[G]);y.useEffect(()=>{if(X!==J.current)if(J.current=X||null,X&&ge){const fe=ge.attachedFiles||[];d(fe.map(He=>({...He})))}else d([])},[X,ge]),y.useEffect(()=>{if(X&&ge){const fe=ge.attachedFiles||[];fe.length>0?d(He=>{const pt=new Set(He.map(dr=>dr.file_id)),Yt=fe.filter(dr=>!pt.has(dr.file_id));return Yt.length>0?(me(`[MessageInput] Syncing ${Yt.length} missing files from conversation to UI`),[...He,...Yt]):He}):fe.length===0&&g.length>0&&d([])}},[X,ge,ie,g.length]);const xt=y.useRef(null),Nr=y.useRef("");y.useEffect(()=>{const fe=lr();if(!X||!ge||(fe?!ge.adapterName:!ge.apiKey))return;const He=ge.attachedFiles||[],pt=He.length>0,Yt=He.filter(tr=>!tr.processing_status||tr.processing_status==="processing"||tr.processing_status==="uploading"),dr=pt?`${He.length}:${He.map(tr=>tr.file_id).join("|")}`:"";if(pt&&(xt.current!==X||Nr.current!==dr)?(me(`[MessageInput] Syncing ${He.length} files for conversation ${X}...`),xt.current=X,Nr.current=dr,le(X).catch(tr=>{})):pt||(xt.current=X,Nr.current=""),Yt.length===0)return;me(`[MessageInput] Found ${Yt.length} files still processing, starting poll...`);const Vt=setInterval(async()=>{const hr=ct.getState().conversations.find(ea=>ea.id===X);if(!hr){clearInterval(Vt);return}if((hr.attachedFiles||[]).filter(ea=>!ea.processing_status||ea.processing_status==="processing"||ea.processing_status==="uploading").length===0){clearInterval(Vt);return}try{await le(X)}catch{}},3e3);return()=>{clearInterval(Vt)}},[X,ge,le]),y.useEffect(()=>{h(fe=>{const He=new Set(ie.map(dr=>dr.id));let pt=!1;const Yt={...fe};return Object.keys(Yt).forEach(dr=>{He.has(dr)||(delete Yt[dr],pt=!0)}),pt?Yt:fe})},[ie]);const Ft=fe=>{if(fe.preventDefault(),(A.trim()||g.length>0)&&!ut&&!a){ke&&xe();const pt=((ge==null?void 0:ge.attachedFiles)||[]).map(Yt=>Yt.file_id);e(A.trim(),pt.length>0?pt:void 0),cd("messageSent",R.soundEnabled),i(""),T.current="",d([]),u(!1),z.current&&(z.current.style.height="auto",z.current.style.overflowY="hidden")}},qn=y.useCallback(fe=>{if(!fe||fe.length===0)return;const He=fe.length===1?`File "${fe[0].filename}" uploaded successfully`:`${fe.length} files uploaded successfully`;cd("success",R.soundEnabled),k(He),setTimeout(()=>{k(null)},6e3)},[R.soundEnabled]),lg=y.useCallback((fe,He)=>{me(`[MessageInput] handleFilesSelected called with ${He.length} files for conversation ${fe}:`,He),fe&&(fe===X&&d(He),vt(He,fe))},[X,vt]),$i=y.useCallback((fe,He)=>{fe===X&&qn(He)},[X,qn]),cc=fe=>{fe.key==="Enter"&&!fe.shiftKey&&!a&&(fe.preventDefault(),Ft(fe))},uc=()=>{ke?xe():pe()},gr=()=>{O({voiceEnabled:!R.voiceEnabled})},zs=y.useCallback(async fe=>{if(!st||!o||!_||ut)return;const He=fe.clipboardData;if(!He||!He.items)return;const Yt=Array.from(He.items).filter(tr=>tr.kind==="file");if(Yt.length===0)return;const dr=[];if(Yt.forEach((tr,hr)=>{const za=tr.getAsFile();za&&dr.push(x$e(za,hr))}),dr.length===0)return;fe.preventDefault(),Q(null),k(null);let Gn=null;const Vt=lr();try{const tr=ct.getState(),hr=tr.conversations.find(Ht=>Ht.id===tr.currentConversationId);if(((hr==null?void 0:hr.attachedFiles)||[]).length+dr.length>ot.maxFilesPerConversation)throw new Error(`Maximum ${ot.maxFilesPerConversation} files allowed per conversation. Please remove some files first.`);if(ot.maxTotalFiles!==null&&tr.conversations.reduce((Dt,tn)=>{var rr;return Dt+(((rr=tn.attachedFiles)==null?void 0:rr.length)||0)},0)+dr.length>ot.maxTotalFiles)throw new Error(`Maximum ${ot.maxTotalFiles} total files allowed across all conversations. Please remove some files from other conversations first.`);if(!hr)throw new Error("Conversation not found. Please select a conversation first.");if(Vt){if(!hr.adapterName)throw new Error("Adapter not configured for this conversation. Please select an adapter first.")}else if(!hr.apiKey||hr.apiKey===wo())throw new Error("API key not configured for this conversation. Please configure API settings first.");const ea=hr.apiKey,V=ga(hr.apiUrl),Ue=hr.adapterName;Gn=hr.id,U(Gn,!0);const Ye=[],jt=[];for(let Ht=0;Ht<dr.length;Ht++){const Dt=dr[Ht],tn=Dt.name||`Clipboard file ${Ht+1}`,rr=`${tn}-${Date.now()}-${Ht}`;w(pA=>{const ta=new Map(pA);return ta.set(rr,{filename:tn,progress:0,status:"uploading"}),ta});const GA=pA=>{w(ta=>{const ti=new Map(ta),ug=ti.get(rr);return ug&&ti.set(rr,{...ug,filename:tn,progress:pA.progress,status:pA.status,fileId:pA.fileId}),ti})},cg=()=>new Promise(pA=>{w(ta=>{const ti=new Map(ta),ug=ti.get(rr);return ug&&ti.set(rr,{...ug,progress:100,status:"completed"}),ti}),setTimeout(()=>{w(ta=>{const ti=new Map(ta);return ti.delete(rr),ti}),pA()},2500)});me(`[MessageInput] Pasting file: ${Dt.name}, type: ${Dt.type||"unknown"}, size: ${Dt.size}`);const rn=await kh.uploadFile(Dt,pA=>{me(`[MessageInput] Paste upload progress for ${Dt.name}: ${pA.progress}% - ${pA.status}`),GA(pA)},ea,V,Vt?Ue:void 0);Ye.push(rn),jt.push(cg())}if(Ye.length>0){let Ht=Ye;if(Gn&&Gn===X){const Dt=new Set(g.map(rr=>rr.file_id)),tn=Ye.filter(rr=>!Dt.has(rr.file_id));tn.length>0?(d(rr=>[...rr,...tn]),Ht=tn):Ht=[]}Ht.length>0&&vt(Ht,Gn),await Promise.all(jt),qn(Ye)}}catch(tr){const hr=tr instanceof Error?tr.message:"Failed to paste file";cd("error",R.soundEnabled),Q(hr),hr.toLowerCase().includes("maximum")&&D(hr),setTimeout(()=>{Q(null)},5e3),w(new Map)}finally{U(Gn,!1)}},[g,X,o,_,ut,U,R.soundEnabled,qn,vt,st]),bB=q?`Workspace limit of ${ot.maxTotalMessages} messages reached. Delete or archive old conversations to continue.`:we?`This chat hit the ${ot.maxMessagesPerConversation} message limit. Start a new conversation to continue.`:se||Qe?"Files are uploading/processing, please wait...":er?"Message ORBIT or drop files here":r,ja=[];q&&ot.maxTotalMessages!==null&&ja.push(`Workspace limit of ${ot.maxTotalMessages} total messages reached. Delete or export older conversations to continue.`),we&&ot.maxMessagesPerConversation!==null&&ja.push(`This conversation reached the ${ot.maxMessagesPerConversation} message limit. Start a new conversation to keep chatting.`),x&&ja.push(x),y.useEffect(()=>{!Fe||!Le||cd("error",R.soundEnabled)},[Fe,R.soundEnabled,Le]),y.useEffect(()=>{if(!x)return;const fe=setTimeout(()=>D(null),5e3);return()=>clearTimeout(fe)},[x]);const xB=n?"max-w-3xl":"max-w-5xl",DB=n?"flex justify-center":"";return b.jsx("div",{className:`bg-white px-3 py-3 md:px-0 md:py-4 dark:bg-[#212121] sm:px-4 ${DB}`,children:b.jsxs("div",{className:`mx-auto w-full ${xB}`,children:[Le&&Fe&&b.jsx("div",{className:"mb-3 w-full rounded-md border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-600/40 dark:bg-red-900/30 dark:text-red-200",children:Le}),I&&b.jsx("div",{className:"mb-3 w-full rounded-md border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-600/40 dark:bg-red-900/30 dark:text-red-200",children:I}),N&&b.jsxs("div",{className:"mb-3 w-full flex items-center gap-2 rounded-md border border-green-200 bg-green-50 px-3 py-2 text-sm text-green-700 dark:border-green-600/40 dark:bg-green-900/30 dark:text-green-200",children:[b.jsx(Sle,{className:"h-4 w-4 flex-shrink-0"}),b.jsx("span",{children:N})]}),ja.length>0&&b.jsx("div",{className:"mb-3 w-full rounded-md border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900 dark:border-amber-500/40 dark:bg-[#2f2410] dark:text-amber-100",children:b.jsx("ul",{className:"list-disc space-y-1 pl-4",children:ja.map((fe,He)=>b.jsx("li",{children:fe},`${fe}-${He}`))})}),b.jsxs("form",{onSubmit:Ft,className:"flex w-full flex-col gap-2 md:gap-3",children:[b.jsxs("div",{className:`flex flex-col md:flex-row md:items-center gap-3 md:gap-2 rounded-2xl md:rounded-lg border px-4 py-3 md:px-4 md:py-3 shadow-sm transition-all ${o?"border-gray-400 shadow-md dark:border-[#565869] dark:shadow-lg":"border-gray-300 dark:border-[#40414f]"} bg-gray-50 dark:bg-[#2d2f39]`,children:[b.jsx("textarea",{ref:z,value:A,onChange:fe=>i(fe.target.value),onKeyDown:cc,onPaste:zs,onCompositionStart:()=>s(!0),onCompositionEnd:()=>s(!1),onFocus:()=>l(!0),onBlur:()=>l(!1),placeholder:bB,disabled:ut,rows:1,maxLength:ot.maxMessageLength,className:"flex-1 w-full md:w-auto min-w-0 resize-none bg-transparent py-1 text-base md:text-sm text-[#353740] placeholder-gray-500 focus:outline-none dark:text-[#ececf1] dark:placeholder-[#8e8ea0]",style:{minHeight:"24px",maxHeight:"120px",border:"none",outline:"none",boxShadow:"none",WebkitAppearance:"none",MozAppearance:"none",appearance:"none",caretColor:A.trim()||o?"inherit":"transparent"}}),b.jsxs("div",{className:"flex items-center justify-between md:justify-end gap-1 md:gap-2 md:flex-shrink-0",children:[b.jsxs("div",{className:"flex items-center gap-1 md:gap-2",children:[st&&b.jsx("button",{type:"button",onClick:fe=>{fe.preventDefault(),rt||u(!c)},disabled:rt,onMouseEnter:()=>m(!0),onMouseLeave:()=>m(!1),className:`flex h-10 w-10 md:h-8 md:w-8 shrink-0 items-center justify-center rounded-full transition-all active:scale-95 ${c||g.length>0?"bg-gray-200 text-[#353740] dark:bg-[#565869] dark:text-[#ececf1]":rt?"cursor-not-allowed text-gray-300 dark:text-[#6b6f7a]":"text-gray-500 hover:bg-gray-200 hover:text-[#353740] dark:text-[#bfc2cd] dark:hover:bg-[#565869]"}`,title:_?oe&&vr&&ot.maxFilesPerConversation!==null?`Maximum of ${ot.maxFilesPerConversation} files reached in this conversation. Start a new chat to upload more.`:oe&&Ce&&ot.maxTotalFiles!==null?`Workspace limit of ${ot.maxTotalFiles} total files reached. Remove files from other conversations first.`:ut?"Files are uploading/processing. Please wait...":g.length>0?`${g.length} file(s) attached`:"Attach files":"File upload not supported by this adapter",children:rt&&p?b.jsx($c,{className:"h-5 w-5 md:h-4 md:w-4"}):b.jsx(Z6,{className:"h-5 w-5 md:h-4 md:w-4"})}),A.length>0&&b.jsx("div",{className:"px-2 text-xs text-gray-500 dark:text-[#bfc2cd] md:min-w-[72px] md:text-right",children:b.jsxs("span",{className:A.length>=ot.maxMessageLength?"text-red-600 font-semibold":"",children:[A.length,"/",ot.maxMessageLength]})})]}),b.jsxs("div",{className:"flex items-center gap-1 md:gap-2",children:[Fe&&b.jsxs(b.Fragment,{children:[b.jsx("button",{type:"button",onClick:gr,className:`flex h-10 w-10 md:h-8 md:w-8 shrink-0 items-center justify-center rounded-full transition-all active:scale-95 ${R.voiceEnabled?"bg-blue-100 text-blue-600 dark:bg-blue-900/40 dark:text-blue-300":"text-gray-500 hover:bg-gray-200 hover:text-[#353740] dark:text-[#bfc2cd] dark:hover:bg-[#565869]"}`,title:R.voiceEnabled?"Voice responses enabled - Click to disable":"Enable voice responses (text-to-speech)",children:R.voiceEnabled?b.jsx(_0,{className:"h-5 w-5"}):b.jsx(ice,{className:"h-5 w-5"})}),Ke&&b.jsx("button",{type:"button",onClick:uc,disabled:ut,onMouseEnter:()=>E(!0),onMouseLeave:()=>E(!1),className:`flex h-10 w-10 md:h-8 md:w-8 shrink-0 items-center justify-center rounded-full transition-all active:scale-95 ${ke?"bg-red-100 text-red-600 dark:bg-red-900/40 dark:text-red-300":ut?"cursor-not-allowed text-gray-300 dark:text-[#6b6f7a]":"text-gray-500 hover:bg-gray-200 hover:text-[#353740] dark:text-[#bfc2cd] dark:hover:bg-[#565869]"}`,title:ut?"Files are uploading/processing. Please wait...":ke?"Stop recording":"Start voice input",children:ke||ut&&C?b.jsx(Lle,{className:"h-5 w-5"}):b.jsx(Hle,{className:"h-5 w-5"})})]}),(se||Qe)&&b.jsx("div",{className:"flex h-10 w-10 md:h-8 md:w-8 shrink-0 items-center justify-center",children:b.jsx(_c,{className:"h-5 w-5 md:h-4 md:w-4 animate-spin text-gray-500 dark:text-[#bfc2cd]"})}),b.jsx("button",{type:"submit",disabled:!A.trim()&&g.length===0||ut||a,className:`flex h-11 w-11 md:h-8 md:w-8 shrink-0 items-center justify-center rounded-full transition-all active:scale-95 ${(A.trim()||g.length>0)&&!ut&&!a?"bg-black text-white hover:bg-gray-800 dark:bg-white dark:text-black dark:hover:bg-gray-200":"bg-gray-300 text-gray-500 dark:bg-[#565869] dark:text-[#6b6f7a]"}`,title:"Send message",children:b.jsx(V6,{className:"h-5 w-5 md:h-4 md:w-4"})})]})]})]}),g.length>0&&b.jsx("div",{className:"flex flex-wrap gap-2",children:g.map(fe=>{const He=!fe.processing_status||fe.processing_status==="processing"||fe.processing_status==="uploading";return b.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-gray-200 bg-white px-2 py-1 text-xs dark:border-[#4a4b54] dark:bg-[#2d2f39]",children:[He&&b.jsx(_c,{className:"h-3 w-3 animate-spin text-emerald-600 dark:text-emerald-400 flex-shrink-0"}),b.jsx("span",{className:"truncate max-w-[150px] text-[#353740] dark:text-[#ececf1]",children:fe.filename}),He&&b.jsx("span",{className:"text-xs text-gray-500 dark:text-[#bfc2cd]",children:fe.processing_status==="uploading"?"Uploading...":"Processing..."}),b.jsx("button",{disabled:!0,className:"text-gray-300 dark:text-[#4a4b54] cursor-not-allowed",title:"File removal disabled; use Clear All in sidebar",children:b.jsx($c,{className:"h-3 w-3"})})]},fe.file_id)})}),st&&(_||it)&&b.jsxs("div",{className:`rounded-md border border-gray-200 bg-white p-3 dark:border-[#4a4b54] dark:bg-[#2d2f39] ${!c&&!Qe&&f.size===0&&!it?"hidden":""}`,children:[c&&b.jsxs("div",{className:"mb-2 flex items-center justify-between text-sm text-[#353740] dark:text-[#ececf1]",children:[b.jsx("span",{children:"Upload files"}),b.jsx("button",{onClick:()=>u(!1),className:"rounded p-1 text-gray-500 hover:bg-gray-100 hover:text-[#353740] dark:text-[#bfc2cd] dark:hover:bg-[#3c3f4a]",title:"Close",children:b.jsx($c,{className:"h-4 w-4"})})]}),(Qe||f.size>0)&&!c&&f.size===0&&b.jsx("div",{className:"mb-2 text-sm text-[#353740] dark:text-[#ececf1]",children:"Uploading files…"}),f.size>0&&b.jsx("div",{className:"mb-2 space-y-2",children:Array.from(f.entries()).map(([fe,He])=>b.jsxs("div",{className:"w-full max-w-full flex items-center gap-3 p-3 bg-gray-50 dark:bg-[#1f1f24] rounded-lg overflow-hidden",children:[b.jsx(_c,{className:"w-4 h-4 text-emerald-600 dark:text-emerald-400 animate-spin flex-shrink-0"}),b.jsxs("div",{className:"flex-1 min-w-0 overflow-hidden",children:[b.jsx("p",{className:"text-sm font-medium text-[#353740] dark:text-[#ececf1] truncate",children:He.filename}),b.jsx("div",{className:"mt-1 bg-gray-200 dark:bg-[#3c3f4a] rounded-full h-1.5",children:b.jsx("div",{className:"bg-emerald-600 dark:bg-emerald-400 h-1.5 rounded-full transition-all duration-300",style:{width:`${He.progress??0}%`}})})]}),b.jsx("span",{className:"text-xs text-gray-500 dark:text-[#bfc2cd]",children:He.status==="uploading"?"Uploading...":He.status==="processing"?"Processing...":He.status==="completed"?"Done":"Pending"})]},fe))}),b.jsx("div",{className:c||Qe?"block":"hidden","aria-hidden":!(c||Qe),children:b.jsx(M$e,{conversationId:X,onFilesSelected:lg,onUploadError:fe=>{D(fe)},onUploadingChange:U,onUploadSuccess:$i,maxFiles:ot.maxFilesPerConversation,disabled:rt})})]}),b.jsx("div",{className:"h-5 md:h-4",children:Ke&&ke&&b.jsxs("span",{className:"flex items-center gap-2 text-sm md:text-xs text-gray-500 dark:text-[#bfc2cd]",children:[b.jsx("span",{className:"h-2.5 w-2.5 md:h-2 md:w-2 animate-pulse rounded-full bg-red-500"}),"Listening..."]})})]})]})})}function D$e({adapter:e,onSelect:t}){return b.jsxs("button",{type:"button",onClick:()=>t(e),className:"group flex w-full items-center gap-3 rounded-2xl border border-gray-200 bg-white px-4 py-4 text-left transition-all duration-200 md:hover:-translate-y-0.5 hover:border-blue-200 hover:shadow-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2 dark:border-[#3b3c49] dark:bg-[#22232b] dark:hover:border-blue-400/50 dark:focus-visible:ring-blue-400",children:[b.jsxs("div",{className:"min-w-0 flex flex-1 flex-col gap-1",children:[b.jsx("span",{className:"truncate text-base font-semibold text-gray-900 dark:text-white",children:e.name}),e.description&&b.jsx("span",{className:"line-clamp-2 text-sm text-gray-600 dark:text-gray-300",children:e.description})]}),b.jsx("div",{className:"ml-auto flex h-10 w-10 items-center justify-center rounded-full border border-transparent bg-gray-50 text-gray-400 transition-colors group-hover:border-blue-100 group-hover:bg-white group-hover:text-blue-500 dark:bg-[#2a2b34] dark:text-gray-400 dark:group-hover:border-blue-500/40 dark:group-hover:bg-transparent dark:group-hover:text-blue-300",children:b.jsx(Ule,{className:"h-5 w-5"})})]})}const k$e="h-[96px]";function S$e({onAdapterSelect:e,className:t="",title:r="Choose an agent to get started",subtitle:n="Each agent is tuned for a specific expertise. Pick one to start a focused conversation.",eyebrow:A="Meet the specialists"}){const[i,a]=y.useState([]),[s,o]=y.useState(!0),[l,c]=y.useState(null),u=y.useRef(null),[g,d]=y.useState(!1),[B,h]=y.useState(""),f=y.useMemo(()=>{const p=B.trim().toLowerCase();return p?i.filter(m=>{var I;const C=m.name.toLowerCase().includes(p),E=((I=m.description)==null?void 0:I.toLowerCase().includes(p))??!1;return C||E}):i},[i,B]);y.useEffect(()=>{let p=!0;return(async()=>{try{o(!0),c(null);const E=(await Kv()).slice().sort((I,Q)=>I.name.localeCompare(Q.name,void 0,{sensitivity:"base"}));p&&a(E)}catch{p&&c("Unable to load agents right now.")}finally{p&&o(!1)}})(),()=>{p=!1}},[]),y.useEffect(()=>{const p=()=>{const m=u.current;if(!m){d(!1);return}const C=m.scrollHeight-m.clientHeight>4;d(C)};return p(),window.addEventListener("resize",p),()=>{window.removeEventListener("resize",p)}},[f,s,l]);const w=()=>s?b.jsx("div",{className:"grid gap-4",children:Array.from({length:3}).map((p,m)=>b.jsx("div",{className:`${k$e} animate-pulse rounded-2xl border border-gray-200 bg-white dark:border-[#3b3c49] dark:bg-[#22232b]`},m))}):l?b.jsx("div",{className:"rounded-2xl border border-red-200 bg-red-50 px-4 py-6 text-sm text-red-700 dark:border-red-900 dark:bg-red-950/30 dark:text-red-200",children:l}):i.length===0?b.jsx("div",{className:"rounded-2xl border border-gray-200 bg-white px-4 py-6 text-sm text-gray-600 dark:border-[#3b3c49] dark:bg-[#22232b] dark:text-gray-300",children:"No agents are available yet. Configure adapters in your middleware settings to continue."}):f.length===0?b.jsx("div",{className:"rounded-2xl border border-gray-200 bg-white px-4 py-6 text-sm text-gray-600 dark:border-[#3b3c49] dark:bg-[#22232b] dark:text-gray-300",children:"No agents match your search."}):b.jsxs("div",{className:"relative",children:[b.jsx("div",{ref:u,className:"max-h-[75vh] lg:max-h-[70vh] overflow-y-auto pr-1",onScroll:()=>{const p=u.current;if(!p)return;const m=p.scrollHeight-p.scrollTop-p.clientHeight>4;d(m)},children:b.jsx("div",{className:"grid gap-3",children:f.map(p=>b.jsx(D$e,{adapter:p,onSelect:m=>e(m.name)},p.name))})}),g&&b.jsxs(b.Fragment,{children:[b.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-14 bg-gradient-to-b from-transparent to-white dark:to-[#1c1d23]"}),b.jsx("div",{className:"pointer-events-none absolute bottom-3 left-1/2 -translate-x-1/2 rounded-full bg-white/95 px-3 py-1 text-xs font-semibold text-gray-600 shadow-sm dark:bg-[#1c1d23]/95 dark:text-gray-200",children:"Scroll for more"})]})]});return b.jsxs("div",{className:`flex w-full flex-col gap-6 ${t}`,children:[(A||r||n)&&b.jsxs("div",{children:[A&&b.jsx("p",{className:"text-sm font-semibold uppercase tracking-wide text-blue-600 dark:text-blue-300",children:A}),r&&b.jsx("h2",{className:"mt-2 text-2xl font-bold text-gray-900 dark:text-white",children:r}),n&&b.jsx("p",{className:"mt-2 text-base text-gray-600 dark:text-gray-300",children:n})]}),b.jsxs("div",{className:"relative max-w-xl",children:[b.jsx(q6,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),b.jsx("input",{type:"text",placeholder:"Search agents",value:B,disabled:s||!!l||i.length===0,onChange:p=>h(p.target.value),className:"w-full rounded-md border border-gray-300 bg-white py-2 pl-9 pr-3 text-sm text-gray-900 placeholder-gray-400 shadow-inner focus:border-gray-400 focus:outline-none disabled:cursor-not-allowed disabled:opacity-60 dark:border-[#3b3c49] dark:bg-[#1f2027] dark:text-white dark:shadow-none"})]}),w()]})}const U$e="rounded-t-[32px] border border-white/40 bg-white/95 px-4 pb-4 pt-[max(env(safe-area-inset-top),1rem)] shadow-[0_25px_60px_rgba(15,23,42,0.15)] backdrop-blur-xl dark:border-[#2f303d] dark:bg-[#1c1d23]/95 md:rounded-none md:border-0 md:bg-transparent md:px-0 md:pb-0 md:pt-0 md:shadow-none md:backdrop-blur-0 md:dark:bg-transparent md:dark:border-0",xV="-mx-4 mt-auto overflow-hidden rounded-t-[28px] border-t border-x border-white/40 bg-white/98 pb-[max(env(safe-area-inset-bottom),0.75rem)] shadow-[0_-12px_45px_rgba(15,23,42,0.2)] backdrop-blur-xl transition-all duration-200 dark:border-[#2f303d] dark:bg-[#1c1d23]/98 md:mx-0 md:mt-0 md:overflow-visible md:rounded-none md:border-0 md:bg-transparent md:pb-0 md:shadow-none md:backdrop-blur-0 md:dark:bg-transparent md:dark:border-0 [&>div]:rounded-t-[28px] md:[&>div]:rounded-none [&>div]:bg-transparent md:[&>div]:px-0",v$e="sticky top-0 z-10 -mx-4 px-4 pt-2 pb-4 bg-white/95 backdrop-blur-xl dark:bg-[#1c1d23]/95 border-b border-white/50 dark:border-white/10 md:static md:mx-0 md:px-0 md:pt-6 md:pb-6 md:bg-transparent md:backdrop-blur-0 md:border-gray-200 md:dark:border-[#4a4b54] md:dark:bg-transparent";function G$e({onOpenSettings:e,onOpenSidebar:t}){var we,q,be,ke;const{conversations:r,currentConversationId:n,createConversation:A,canCreateNewConversation:i,sendMessage:a,regenerateResponse:s,isLoading:o,configureApiSettings:l,error:c,clearError:u,createThread:g}=ct(),{settings:d}=em(),{theme:B,isDark:h}=$f(),f=B.mode==="dark"?"dark":B.mode==="light"?"light":"",w=h?"dark":"light",p=["message-markdown w-full min-w-0","prose prose-slate dark:prose-invert max-w-none",f].filter(Boolean).join(" "),[m,C]=y.useState(!1),[E,I]=y.useState(!1),Q=r.find(Be=>Be.id===n),N=lr(),k=Xae(),x=!Q||Q.messages.length===0,D=N&&x,[z,H]=y.useState(D),T=y.useRef(null),v=N&&x&&z,L=N&&x&&!z&&!!(Q!=null&&Q.adapterName),J="mx-auto w-full max-w-4xl",R=L?J:"w-full",O=i(),U=O?"Start a new conversation":"Finish your current conversation before starting a new one.",K=!!(Q!=null&&Q.adapterInfo&&!v),G=`${v$e} ${v?"border-transparent dark:border-transparent md:border-transparent md:dark:border-transparent":""}`.trim();y.useEffect(()=>{if(!N||!x){z&&H(!1),T.current=(Q==null?void 0:Q.id)||null;return}const Be=(Q==null?void 0:Q.id)||null;T.current!==Be&&(T.current=Be,H(!0))},[N,x,Q==null?void 0:Q.id,z]),y.useEffect(()=>{var Be,pe,xe;N&&me("[ChatInterface] Middleware mode state:",{hasConversation:!!Q,adapterName:Q==null?void 0:Q.adapterName,hasAdapterInfo:!!(Q!=null&&Q.adapterInfo),hasNotes:!!((Be=Q==null?void 0:Q.adapterInfo)!=null&&Be.notes),notes:((xe=(pe=Q==null?void 0:Q.adapterInfo)==null?void 0:pe.notes)==null?void 0:xe.substring(0,50))+"..."})},[N,Q]);const X=y.useRef(null);y.useEffect(()=>{(async()=>{var Le;const pe=Q==null?void 0:Q.adapterName;if(X.current===pe)return;const xe=!(Q!=null&&Q.adapterInfo)||(Q==null?void 0:Q.adapterInfo)&&Q.adapterInfo.notes===void 0;if(N&&pe&&xe){X.current=pe,me("[ChatInterface] Loading adapter info - adapterName:",pe,"reason:",Q!=null&&Q.adapterInfo?"notes undefined":"missing");try{const Fe=(Q==null?void 0:Q.apiUrl)||Hr();me("[ChatInterface] Calling configureApiSettings for:",pe),await l(Fe,void 0,void 0,pe),me("[ChatInterface] Adapter info loaded successfully")}catch{X.current=null}}else me("[ChatInterface] Skipping adapter info load:",{isMiddlewareEnabled:N,adapterName:pe,hasAdapterInfo:!!(Q!=null&&Q.adapterInfo),hasNotes:((Le=Q==null?void 0:Q.adapterInfo)==null?void 0:Le.notes)!==void 0,refValue:X.current})})()},[N,Q==null?void 0:Q.adapterName,Q==null?void 0:Q.adapterInfo,Q==null?void 0:Q.apiUrl,l]),y.useEffect(()=>{let Be=null;const pe=()=>{Be&&(Be(),Be=null)};if(d.voiceEnabled){if(gl.isAudioEnabled())return pe;const xe=()=>{pe();const Le=async()=>{pe(),await gl.enableAudio()||xe()};document.addEventListener("pointerdown",Le,{once:!0}),document.addEventListener("keydown",Le,{once:!0}),Be=()=>{document.removeEventListener("pointerdown",Le),document.removeEventListener("keydown",Le)}};return xe(),pe}return pe(),gl.disableAudio(),pe},[d.voiceEnabled]);const ie=(Be,pe,xe)=>{a(Be,pe,xe)},ae=async(Be,pe,xe)=>{await a(xe,void 0,Be)},le=()=>{try{A()}catch(Be){ft("Cannot create new conversation:",Be instanceof Error?Be.message:"Unknown error")}},ge=async Be=>{if(!(!N||!Be)){I(!0);try{const pe=(Q==null?void 0:Q.apiUrl)||Hr();await l(pe,void 0,void 0,Be),u()}catch{}finally{I(!1)}}},te=Be=>{H(!1),ge(Be)},he=async()=>{if(!(!Q||!Q.apiKey&&!Q.adapterName)){C(!0);try{const Be=await nn(),pe=Q.apiUrl||Hr(),xe=Q.apiKey,Le=Q.adapterName,Fe=new Be.ApiClient({apiUrl:pe,apiKey:xe||null,sessionId:null,adapterName:Le||null});if(typeof Fe.getAdapterInfo=="function"){const Ke=await Fe.getAdapterInfo();me("Adapter info refreshed:",Ke),ct.setState(st=>({conversations:st.conversations.map(Ot=>Ot.id===n?{...Ot,adapterInfo:Ke,updatedAt:new Date}:Ot)})),setTimeout(()=>{const st=ct.getState();localStorage.setItem("chat-state",JSON.stringify({conversations:st.conversations,currentConversationId:st.currentConversationId}))},0)}}catch{}finally{C(!1)}}};return b.jsx("div",{className:"flex-1 flex flex-col bg-gray-50 dark:bg-[#202123] overflow-hidden",children:b.jsx("div",{className:"flex h-full w-full flex-col px-3 sm:px-6 overflow-hidden",children:b.jsxs("div",{className:`mx-auto flex h-full w-full max-w-5xl flex-col overflow-hidden ${U$e}`,children:[c&&b.jsx("div",{className:"mt-6 rounded-md border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700 dark:border-red-600/40 dark:bg-red-900/30 dark:text-red-200",children:b.jsxs("div",{className:"flex items-start justify-between",children:[b.jsx("p",{children:c}),b.jsx("button",{onClick:u,className:"ml-4 rounded p-1 text-red-500 hover:bg-red-100 hover:text-red-700 dark:text-red-200 dark:hover:bg-red-800/40","aria-label":"Dismiss error",children:"×"})]})}),b.jsxs("div",{className:G,children:[t&&b.jsxs("div",{className:"mb-4 grid grid-cols-2 gap-3 md:hidden",children:[b.jsxs("button",{onClick:t,className:"inline-flex items-center justify-center gap-2 rounded-2xl border border-white/50 bg-white/80 px-4 py-3.5 text-sm font-semibold text-gray-800 shadow-sm active:scale-[0.97] transition-all duration-150 hover:bg-white dark:border-[#2f303d] dark:bg-[#232430] dark:text-[#ececf1]","aria-label":"Open conversations menu",children:[b.jsx(Tle,{className:"h-5 w-5"}),"Chats"]}),b.jsxs("button",{onClick:e,className:"inline-flex items-center justify-center gap-2 rounded-2xl border border-white/50 bg-[#11121a]/90 px-4 py-3.5 text-sm font-semibold text-white shadow-sm active:scale-[0.97] transition-all duration-150 hover:bg-[#0c0d14] dark:border-[#3b3c49] dark:bg-[#565869] dark:hover:bg-[#6b6f7a]","aria-label":"Open settings",children:[b.jsx(_6,{className:"h-5 w-5"}),"Settings"]})]}),b.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between",children:[b.jsx("div",{className:"min-w-0 flex-1",children:K&&b.jsxs("div",{className:"mb-4",children:[b.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-3",children:[((we=Q==null?void 0:Q.adapterInfo)==null?void 0:we.model)&&b.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-gray-200 bg-gray-100 px-2.5 py-1 text-xs font-semibold uppercase tracking-wider text-gray-500 dark:border-[#4a4b54] dark:bg-[#343541] dark:text-[#bfc2cd]",children:[b.jsx("span",{children:"Model"}),b.jsx("span",{className:"text-gray-800 normal-case dark:text-[#ececf1]",children:Q.adapterInfo.model})]}),b.jsxs("div",{className:"inline-flex items-center gap-2 rounded-md border border-gray-200 bg-gray-100 px-2.5 py-1 text-xs font-semibold uppercase tracking-wider text-gray-600 dark:border-[#4a4b54] dark:bg-[#343541] dark:text-[#bfc2cd]",children:[b.jsx("span",{children:"Agent"}),b.jsx("span",{className:"text-gray-800 normal-case dark:text-[#ececf1]",children:(Q==null?void 0:Q.adapterName)||((q=Q==null?void 0:Q.adapterInfo)==null?void 0:q.adapter_name)||"Configured Agent"})]}),b.jsxs("button",{onClick:he,disabled:m||!(Q!=null&&Q.apiKey)&&!(Q!=null&&Q.adapterName),className:"inline-flex items-center gap-1 rounded-full border border-gray-200 px-2.5 py-1 text-xs font-semibold text-gray-600 transition-colors hover:bg-gray-200 hover:text-gray-900 dark:border-[#4a4b54] dark:text-[#bfc2cd] dark:hover:bg-[#4a4b54] dark:hover:text-white disabled:opacity-50 disabled:cursor-not-allowed",title:"Refresh adapter info",children:[b.jsx(qle,{className:`h-4 w-4 ${m?"animate-spin":""}`}),b.jsx("span",{className:"hidden sm:inline",children:"Refresh"})]})]}),b.jsx("h1",{className:"text-2xl font-semibold text-[#353740] dark:text-[#ececf1] mb-2",children:(Q==null?void 0:Q.title)||"New Chat"}),Q&&b.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-500 dark:text-[#bfc2cd]",children:[b.jsx("span",{className:"font-medium",children:Q.messages.length}),b.jsxs("span",{children:["Updated ",Q.updatedAt.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]})]})}),!v&&b.jsx("div",{className:"flex items-start justify-end",children:b.jsxs("button",{onClick:le,disabled:!O,className:`inline-flex items-center justify-center gap-2 rounded-full border px-3.5 py-2 text-xs font-semibold uppercase tracking-wide transition-colors ${O?"border-[#343541] text-[#343541] hover:bg-[#f2f3f5] dark:border-[#565869] dark:text-[#ececf1] dark:hover:bg-[#2c2f36]":"cursor-not-allowed border-gray-200 text-gray-400 dark:border-[#3c3f4a] dark:text-[#6b6f7a]"}`,title:U,children:[b.jsx(Zle,{className:"h-3.5 w-3.5"}),"New Conversation"]})})]})]}),x?b.jsx("div",{className:"flex flex-1 flex-col min-h-0 pt-4 md:pt-6",children:b.jsxs("div",{className:"flex-1 flex flex-col justify-between md:justify-start md:flex-none",children:[b.jsx("div",{className:"w-full space-y-6",children:v?b.jsx(S$e,{onAdapterSelect:te,className:J}):L?b.jsxs("div",{className:`${J} rounded-3xl border border-gray-200/80 bg-white/95 p-6 shadow-sm dark:border-[#3b3c49] dark:bg-[#1c1d23]/90`,children:[b.jsxs("div",{className:"flex items-start justify-between pb-4",children:[b.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Agent overview"}),b.jsx("button",{type:"button",onClick:()=>H(!0),className:"text-sm font-semibold text-blue-600 hover:text-blue-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 dark:text-blue-300 dark:hover:text-blue-200",children:"Change Agent"})]}),b.jsx("div",{className:"rounded-2xl border border-gray-200 bg-white/70 p-4 dark:border-[#3b3c49] dark:bg-[#232430]/80",children:(be=Q==null?void 0:Q.adapterInfo)!=null&&be.notes?b.jsx(Sf,{content:Q.adapterInfo.notes,className:p,syntaxTheme:w}):E?b.jsx("p",{className:"text-sm text-gray-600 dark:text-[#bfc2cd]",children:"Configuring your agent… hang tight for just a moment."}):b.jsx("p",{className:"text-sm text-gray-600 dark:text-[#bfc2cd]",children:"Fetching agent overview… this only takes a moment."})})]}):b.jsx("div",{className:`${J} mb-2`,children:(ke=Q==null?void 0:Q.adapterInfo)!=null&&ke.notes?b.jsx("div",{className:"text-base text-gray-600 dark:text-[#bfc2cd] leading-relaxed",children:b.jsx(Sf,{content:Q.adapterInfo.notes,className:p,syntaxTheme:w})}):b.jsx("h2",{className:"text-xl md:text-2xl font-medium text-[#353740] dark:text-[#ececf1]",children:"How can I assist you today?"})})}),!v&&b.jsx("div",{className:xV,children:b.jsx("div",{className:R,children:b.jsx(bV,{onSend:ie,disabled:o||!Q||(N?!(Q!=null&&Q.adapterName):!(Q!=null&&Q.apiKey)),placeholder:k})})})]})}):b.jsxs("div",{className:"flex flex-1 flex-col",children:[b.jsx(q_e,{messages:Q.messages,onRegenerate:s,onStartThread:async(Be,pe)=>{try{await g(Be,pe)}catch{}},onSendThreadMessage:ae,sessionId:Q.sessionId,isLoading:o}),b.jsx("div",{className:xV,children:b.jsx("div",{className:"w-full",children:b.jsx(bV,{onSend:ie,disabled:o||!Q||(N?!Q.adapterName:!Q.apiKey)||N&&z,placeholder:k})})})]})]})})})}function DV({isOpen:e,onClose:t,onConfirm:r,title:n,message:A,confirmText:i="Confirm",cancelText:a="Cancel",type:s="danger",isLoading:o=!1}){if(!e)return null;const l=()=>{o||r()},u=(()=>{switch(s){case"danger":return{icon:"text-red-500",iconBg:"bg-red-100 dark:bg-red-900/20",confirmButton:"bg-red-600 hover:bg-red-700 focus:ring-red-500",border:"border-red-200 dark:border-red-800"};case"warning":return{icon:"text-amber-500",iconBg:"bg-amber-100 dark:bg-amber-900/20",confirmButton:"bg-amber-600 hover:bg-amber-700 focus:ring-amber-500",border:"border-amber-200 dark:border-amber-800"};default:return{icon:"text-blue-500",iconBg:"bg-blue-100 dark:bg-blue-900/20",confirmButton:"bg-blue-600 hover:bg-blue-700 focus:ring-blue-500",border:"border-blue-200 dark:border-blue-800"}}})();return b.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center p-4 z-50 animate-fadeIn",children:b.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-2xl shadow-2xl w-full max-w-md transform animate-fadeIn",children:[b.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-700",children:[b.jsxs("div",{className:"flex items-center gap-3",children:[b.jsx("div",{className:`w-10 h-10 rounded-full ${u.iconBg} flex items-center justify-center`,children:b.jsx(qk,{className:`w-5 h-5 ${u.icon}`})}),b.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:n})]}),b.jsx("button",{onClick:t,className:"p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors",children:b.jsx($c,{className:"w-5 h-5 text-gray-500 dark:text-gray-400"})})]}),b.jsx("div",{className:"p-6",children:b.jsx("p",{className:"text-gray-600 dark:text-gray-300 leading-relaxed",children:A})}),b.jsxs("div",{className:"flex items-center justify-end gap-3 p-6 border-t border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50 rounded-b-2xl",children:[b.jsx("button",{onClick:t,disabled:o,className:"px-4 py-2.5 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700 rounded-lg transition-colors font-medium disabled:opacity-50 disabled:cursor-not-allowed",children:a}),b.jsx("button",{onClick:l,disabled:o,className:`px-4 py-2.5 text-white rounded-lg transition-all font-medium shadow-sm hover:shadow-md transform hover:scale-105 active:scale-95 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-white dark:focus:ring-offset-gray-800 disabled:opacity-50 disabled:cursor-not-allowed disabled:transform-none ${u.confirmButton}`,children:o?b.jsxs("div",{className:"flex items-center gap-2",children:[b.jsx("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"}),"Clearing..."]}):i})]})]})})}const R$e=(e,t)=>{const[r,n]=y.useState({stars:0,forks:0,license:"Apache-2.0",description:"An adaptable, open-source context-aware inference engine designed for privacy, control, and independence from proprietary models.",isLoading:!0,error:null});return y.useEffect(()=>{(async()=>{var i;try{const a=await fetch(`https://api.github.com/repos/${e}/${t}`);if(!a.ok)throw new Error(`GitHub API error: ${a.status}`);const s=await a.json();n({stars:s.stargazers_count||0,forks:s.forks_count||0,license:((i=s.license)==null?void 0:i.name)||"Apache-2.0",description:s.description||"An adaptable, open-source context-aware inference engine designed for privacy, control, and independence from proprietary models.",isLoading:!1,error:null})}catch(a){console.warn("Failed to fetch GitHub stats:",a),n({stars:104,forks:19,license:"Apache-2.0",description:"An adaptable, open-source context-aware inference engine designed for privacy, control, and independence from proprietary models.",isLoading:!1,error:a instanceof Error?a.message:"Failed to fetch stats"})}})()},[e,t]),r};function j$e({selectedAdapter:e,onAdapterChange:t,disabled:r,defaultAdapterName:n,showDescriptions:A=!1,variant:i="sidebar",label:a,showLabel:s}){const[o,l]=y.useState([]),[c,u]=y.useState(!0),[g,d]=y.useState(null),[B,h]=y.useState(!1);y.useEffect(()=>{let D=!0;async function z(){try{u(!0),d(null);const H=await Kv();D&&l(H)}catch{D&&d("Failed to load adapters. Please check your connection.")}finally{D&&u(!1)}}return z(),()=>{D=!1}},[]);const f=y.useRef(t),w=y.useRef(!1);y.useEffect(()=>{f.current=t},[t]),y.useEffect(()=>{if(e){w.current=!0;return}!n||w.current||o.length===0||!o.some(z=>z.name===n)||(w.current=!0,f.current(n))},[o,e,n]);const p=o.find(D=>D.name===e),m=typeof s=="boolean"?s:i==="prominent",C=a||(i==="prominent"?"Select an agent":"Adapter"),E=y.useMemo(()=>i==="prominent"?"relative w-full text-left":"relative w-full",[i]),I=y.useMemo(()=>{const D="w-full rounded-md border bg-white px-4 py-3 text-left text-sm text-[#353740] focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 dark:bg-[#343541] dark:text-[#ececf1]";return i==="prominent"?[D,"border-gray-300 shadow-sm transition-all duration-200 focus-visible:ring-blue-500 dark:border-[#4a4b54] dark:focus-visible:ring-blue-400"].join(" "):["w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-left text-sm text-[#353740] focus:border-gray-400 focus:outline-none dark:border-[#4a4b54] dark:bg-[#343541] dark:text-[#ececf1] dark:focus:border-[#6b6f7a]"].join(" ")},[i]),Q=y.useMemo(()=>i==="prominent"?"absolute z-20 mt-2 w-full rounded-xl border border-gray-200 bg-white shadow-xl ring-1 ring-black/5 dark:border-[#4a4b54] dark:bg-[#1f2027]":"absolute z-20 mt-1 w-full rounded-md border border-gray-200 bg-white shadow-lg ring-1 ring-black/5 dark:border-[#4a4b54] dark:bg-[#1f2027]",[i]),x=m?`mb-2 block text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-[#bfc2cd] ${i==="prominent"?"!text-sm !font-semibold !text-gray-700 dark:!text-white":""}`:"sr-only";return b.jsxs("div",{className:E,children:[b.jsx("label",{className:x,children:C}),b.jsxs("div",{className:"relative",children:[b.jsx("button",{type:"button",onClick:()=>!r&&h(!B),disabled:r||c||o.length===0,className:`${I} disabled:opacity-50 disabled:cursor-not-allowed`,"aria-label":C,children:b.jsxs("div",{className:"flex items-center justify-between gap-2",children:[b.jsxs("div",{className:"flex flex-col min-w-0",children:[b.jsx("span",{className:`truncate font-medium ${p?"text-[#11121a] dark:text-white":"text-gray-500 dark:text-gray-400"}`,children:c?"Loading agents…":g?"Error loading agents":p?p.name:o.length===0?"No agents available":"Select an agent"}),i==="prominent"&&(p==null?void 0:p.description)&&b.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:p.description})]}),b.jsx(X6,{className:`h-4 w-4 flex-shrink-0 transition-transform text-gray-400 dark:text-gray-300 ${B?"rotate-180":""}`})]})}),B&&!r&&o.length>0&&b.jsxs(b.Fragment,{children:[b.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>h(!1)}),b.jsx("div",{className:Q,children:b.jsx("div",{className:"max-h-72 overflow-auto py-2",children:o.map(D=>{const z=D.name===e;return b.jsx("button",{type:"button",onClick:()=>{z||t(D.name),h(!1)},className:`w-full px-4 py-3 text-left text-sm transition-colors ${z?"bg-blue-50 text-blue-700 dark:bg-blue-900/30 dark:text-blue-200":"text-[#353740] hover:bg-gray-50 dark:text-[#ececf1] dark:hover:bg-[#2a2d35]"}`,children:b.jsxs("div",{className:"flex flex-col gap-1",children:[b.jsx("span",{className:"font-medium truncate",children:D.name}),A&&D.description&&b.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",style:{display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:D.description})]})},D.name)})})})]})]}),g&&b.jsx("p",{className:"mt-1 text-xs text-red-600 dark:text-red-400",children:g})]})}const Wp=100,z$e={small:{cardText:"text-xs",cardPadding:"px-2.5 py-2",cardGap:"gap-0",titleText:"text-sm",metaText:"text-[10px]",metaGap:"gap-1",badgePadding:"px-1.5 py-0.5",badgeText:"text-[10px]",badgeIcon:"h-3 w-3",actionButton:"p-1.5",actionIcon:"h-3.5 w-3.5"},medium:{cardText:"text-sm",cardPadding:"px-3 py-3",cardGap:"gap-0",titleText:"text-sm",metaText:"text-[11px]",metaGap:"gap-1.5",badgePadding:"px-2 py-0.5",badgeText:"text-[11px]",badgeIcon:"h-3.5 w-3.5",actionButton:"p-2",actionIcon:"h-4 w-4"},large:{cardText:"text-base",cardPadding:"px-4 py-4",cardGap:"gap-0",titleText:"text-base",metaText:"text-sm",metaGap:"gap-2",badgePadding:"px-2.5 py-1",badgeText:"text-sm",badgeIcon:"h-4 w-4",actionButton:"p-2",actionIcon:"h-4 w-4"}};function kV({onRequestClose:e,onOpenSettings:t}){const{conversations:r,currentConversationId:n,selectConversation:A,deleteConversation:i,deleteAllConversations:a,updateConversationTitle:s,getConversationCount:o,configureApiSettings:l,clearError:c}=ct(),u=r.find(Ce=>Ce.id===n),[g,d]=y.useState(""),[B,h]=y.useState(null),[f,w]=y.useState(""),[p,m]=y.useState({isOpen:!1,conversationId:"",conversationTitle:"",isDeleting:!1}),[C,E]=y.useState({isOpen:!1,isDeleting:!1}),[I,Q]=y.useState(!1),[N,k]=y.useState(()=>Hr()),[x,D]=y.useState(()=>wo()),[z,H]=y.useState(null),[T,v]=y.useState(!1),[L,J]=y.useState(!1),[R,O]=y.useState(null),U=lr(),K=U?Pv():null,Ae=!u||u.messages.length===0,{theme:G}=$f(),X=z$e[G.fontSize??"medium"];y.useEffect(()=>{if(!U){H(null);return}u!=null&&u.adapterName?H(u.adapterName):H(null)},[U,u==null?void 0:u.adapterName]),y.useEffect(()=>{O(null)},[n]);const ie=r.filter(Ce=>Ce.title.toLowerCase().includes(g.toLowerCase())||Ce.messages.some(_=>_.content.toLowerCase().includes(g.toLowerCase()))),ae=o(),le=ae===1?"conversation":"conversations",ge=J_e(),te=R$e(IV(),yV()),he=()=>{const Ce=Hr(),_=u==null?void 0:u.apiUrl,se=_&&_!==Ce?_:Ce,Qe=(u==null?void 0:u.apiKey)||wo();k(se),D(Qe),O(null),v(!1),Q(!0)},we=async Ce=>{if(!(!U||!Ae||!Ce)){H(Ce),O(null),J(!0);try{const _=(u==null?void 0:u.apiUrl)||Hr();await l(_,void 0,void 0,Ce),c(),Q(!1)}catch(_){const se=_ instanceof Error?_.message:"Failed to configure adapter";O(se)}finally{J(!1)}}},q=async Ce=>{if(Ce&&Ce.preventDefault(),!U&&N&&x){J(!0),O(null);try{await l(N,x),c(),O(null),v(!1),Q(!1)}catch(_){const se=_ instanceof Error?_.message:"Failed to configure API settings";O(se)}finally{J(!1)}}},be=async Ce=>{try{await A(Ce),e==null||e()}catch{}},ke=(Ce,_)=>{Ce.stopPropagation(),m({isOpen:!0,conversationId:_.id,conversationTitle:_.title,isDeleting:!1})},Be=async()=>{m(Ce=>({...Ce,isDeleting:!0}));try{await i(p.conversationId),m({isOpen:!1,conversationId:"",conversationTitle:"",isDeleting:!1})}catch{m({isOpen:!1,conversationId:"",conversationTitle:"",isDeleting:!1})}},pe=()=>{m({isOpen:!1,conversationId:"",conversationTitle:"",isDeleting:!1})},xe=(Ce,_)=>{Ce.stopPropagation(),h(_.id),w(_.title.slice(0,Wp))},Le=Ce=>{const _=f.slice(0,Wp).trim();_&&s(Ce,_),h(null),w("")},Fe=()=>{h(null),w("")},Ke=()=>{E({isOpen:!0,isDeleting:!1})},st=async()=>{E(Ce=>({...Ce,isDeleting:!0}));try{await a(),E({isOpen:!1,isDeleting:!1})}catch{E({isOpen:!1,isDeleting:!1})}},Ot=()=>{E({isOpen:!1,isDeleting:!1})},en=Ce=>{const _=Ce.toLocaleDateString([],{year:"numeric",month:"short",day:"numeric"}),se=Ce.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});return`${_} · ${se}`},vr=Ce=>{var _;return Ce.adapterName&&Ce.adapterName.trim().length>0?Ce.adapterName:(_=Ce.adapterInfo)!=null&&_.adapter_name&&Ce.adapterInfo.adapter_name.trim().length>0?Ce.adapterInfo.adapter_name:null};return b.jsxs(b.Fragment,{children:[I&&b.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 px-4",children:b.jsxs("form",{onSubmit:q,className:"w-full max-w-md rounded-lg border border-gray-200 bg-white p-6 shadow-lg dark:border-[#444654] dark:bg-[#202123]",children:[b.jsx("h2",{className:"mb-4 text-lg font-medium text-[#353740] dark:text-[#ececf1]",children:U?"Select an Agent":"Configure API Settings"}),b.jsxs("div",{className:"space-y-5",children:[!U&&b.jsxs("div",{children:[b.jsx("label",{className:"mb-2 block text-sm font-medium text-[#353740] dark:text-[#d1d5db]",children:"API URL"}),b.jsx("input",{type:"text",value:N,onChange:Ce=>k(Ce.target.value),className:"w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-sm text-[#353740] focus:border-gray-400 focus:outline-none dark:border-[#4a4b54] dark:bg-[#343541] dark:text-[#ececf1]",placeholder:"https://api.example.com"})]}),U?b.jsx(j$e,{selectedAdapter:z||(u==null?void 0:u.adapterName)||null,onAdapterChange:we,disabled:L,defaultAdapterName:K,variant:"prominent",showDescriptions:!0,showLabel:!1}):b.jsxs("div",{children:[b.jsx("label",{className:"mb-2 block text-sm font-medium text-[#353740] dark:text-[#d1d5db]",children:"API Key"}),b.jsxs("div",{className:"relative",children:[b.jsx("input",{type:T?"text":"password",value:x,onChange:Ce=>{D(Ce.target.value),O(null)},className:"w-full rounded-md border border-gray-300 bg-white px-3 py-2 pr-10 text-sm text-[#353740] focus:border-gray-400 focus:outline-none dark:border-[#4a4b54] dark:bg-[#343541] dark:text-[#ececf1]",placeholder:"your-api-key",disabled:L}),b.jsx("button",{type:"button",onClick:()=>v(!T),className:"absolute right-2 top-1/2 -translate-y-1/2 rounded p-1 text-gray-500 hover:text-gray-700 dark:text-[#d1d5db] dark:hover:text-white","aria-label":T?"Hide API key":"Show API key",disabled:L,children:T?b.jsx(Rle,{className:"h-4 w-4"}):b.jsx(jle,{className:"h-4 w-4"})})]})]}),R&&b.jsx("div",{className:"rounded-md border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-600/40 dark:bg-red-900/30 dark:text-red-200",children:R}),b.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[b.jsx("button",{type:"button",onClick:()=>{const Ce=(u==null?void 0:u.apiUrl)||Hr(),_=(u==null?void 0:u.apiKey)||wo();k(Ce),D(_),O(null),v(!1),Q(!1)},className:"rounded-md border border-transparent px-4 py-2 text-sm text-gray-600 hover:border-gray-300 hover:text-gray-900 disabled:cursor-not-allowed disabled:opacity-50 dark:text-[#d1d5db] dark:hover:text-white",disabled:L,children:"Cancel"}),!U&&b.jsx("button",{type:"submit",disabled:L||!N||!x,className:"rounded-md bg-[#343541] px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-[#282b32] disabled:cursor-not-allowed disabled:opacity-50 dark:bg-[#565869] dark:hover:bg-[#6b6f7a]",children:L?"Validating...":"Update"})]})]})]})}),b.jsxs("div",{className:"flex h-full w-full md:w-72 flex-col border-r border-b border-gray-200 bg-gradient-to-b from-white via-gray-50 to-gray-100 dark:border-[#4a4b54] dark:bg-[#202123] dark:bg-none",children:[b.jsxs("div",{className:"bg-white/95 p-4 shadow-sm dark:border-[#4a4b54] dark:bg-[#202123] dark:shadow-none",children:[b.jsxs("div",{className:"space-y-3 pb-3",children:[b.jsxs("div",{className:"flex items-center justify-between text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-[#bfc2cd]",children:[b.jsx("span",{children:"Version"}),b.jsxs("span",{className:"text-gray-900 dark:text-white",children:["v",$ae]})]}),b.jsxs("button",{onClick:t,disabled:!t,className:"flex w-full items-center justify-center gap-2 rounded-md border border-gray-300 px-3 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50 hover:border-gray-400 disabled:cursor-not-allowed disabled:opacity-50 dark:border-[#4a4b54] dark:text-[#ececf1] dark:hover:bg-[#3c3f4a] dark:hover:border-[#6b6f7a] dark:disabled:hover:bg-transparent dark:disabled:hover:border-[#4a4b54]",children:[b.jsx(_6,{className:"h-4 w-4"}),"Settings"]}),r.length>0&&r.some(Ce=>Ce.messages.length>0)&&b.jsxs("button",{onClick:Ke,className:"flex w-full items-center justify-center gap-2 rounded-md border border-red-300 px-3 py-2 text-sm font-medium text-red-600 hover:bg-red-50 hover:border-red-400 dark:border-red-600/40 dark:text-red-400 dark:hover:bg-red-900/20 dark:hover:border-red-500/60 transition-colors",title:"Delete all conversations",children:[b.jsx(rce,{className:"h-4 w-4"}),"Delete Conversations"]})]}),b.jsxs("div",{className:"mt-4 space-y-3",children:[!U&&b.jsx("button",{onClick:he,disabled:!Ae,className:"flex w-full items-center justify-center gap-2 rounded-md border border-gray-300 px-3 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50 hover:border-gray-400 disabled:cursor-not-allowed disabled:opacity-50 dark:border-[#4a4b54] dark:text-[#ececf1] dark:hover:bg-[#3c3f4a] dark:hover:border-[#6b6f7a] dark:disabled:hover:bg-transparent dark:disabled:hover:border-[#4a4b54]",children:"Configure API"}),R&&!I&&b.jsx("p",{className:"text-xs text-red-600 dark:text-red-400",children:R})]}),b.jsx("div",{className:"border-t border-gray-200 pt-4 mt-4 dark:border-[#4a4b54]",children:b.jsxs("div",{className:"relative flex items-center",children:[b.jsx(q6,{className:"pointer-events-none absolute left-3 h-4 w-4 text-gray-400"}),b.jsx("input",{type:"text",placeholder:"Search Conversations",value:g,onChange:Ce=>d(Ce.target.value),className:"w-full rounded-md border border-gray-300 bg-white py-2 pl-9 pr-3 text-sm text-[#353740] placeholder-gray-400 shadow-inner focus:border-gray-400 focus:outline-none dark:border-[#4a4b54] dark:bg-[#343541] dark:text-[#ececf1] dark:shadow-none"})]})})]}),b.jsx("div",{className:"flex-1 overflow-y-auto px-3 py-3 dark:bg-[#202123] dark:bg-none",children:ie.length===0?b.jsxs("div",{className:"rounded-xl border border-dashed border-gray-300 bg-white/90 p-6 text-center text-sm text-gray-500 shadow-sm dark:border-[#4a4b54] dark:bg-[#252830] dark:text-[#bfc2cd] dark:shadow-none",children:[b.jsx(q0,{className:"mx-auto mb-3 h-6 w-6 text-gray-400 dark:text-[#6b6f7a]"}),b.jsx("p",{children:g?"No conversations found":"No conversations yet"})]}):b.jsx("div",{className:"space-y-2",children:ie.map(Ce=>{const _=vr(Ce);return b.jsx("div",{onClick:()=>be(Ce.id),className:`group flex cursor-pointer items-start rounded-xl border text-left transition shadow-sm ${X.cardGap} ${X.cardPadding} ${X.cardText} dark:shadow-none ${n===Ce.id?"border-[#343541] bg-white dark:border-[#6b6f7a] dark:bg-[#2c2f36]":"border-gray-100 bg-white hover:border-gray-300 hover:bg-gray-50 dark:border-transparent dark:bg-[#252830] dark:hover:border-[#4a4b54] dark:hover:bg-[#2f323c]"}`,children:B===Ce.id?b.jsx("input",{type:"text",value:f,onChange:se=>w(se.target.value.slice(0,Wp)),onKeyDown:se=>{se.key==="Enter"&&Le(Ce.id),se.key==="Escape"&&Fe()},onBlur:()=>Le(Ce.id),maxLength:Wp,className:`flex-1 border-none bg-transparent text-[#353740] focus:outline-none dark:text-[#ececf1] ${X.titleText}`,autoFocus:!0}):b.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[b.jsxs("div",{className:`flex items-center gap-2 ${X.cardText}`,children:[b.jsx("h3",{className:`flex-1 truncate font-semibold ${X.titleText} ${n===Ce.id?"text-[#1f2937] dark:text-white":"text-gray-700 dark:text-[#d4d7e2]"}`,children:Ce.title}),b.jsxs("div",{className:"flex items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100",children:[b.jsx("button",{onClick:se=>xe(se,Ce),className:`rounded-full text-gray-500 hover:bg-gray-200 hover:text-[#353740] dark:text-[#bfc2cd] dark:hover:bg-[#3c3f4a] ${X.actionButton}`,title:"Rename conversation",children:b.jsx(Vle,{className:X.actionIcon})}),b.jsx("button",{onClick:se=>ke(se,Ce),className:`rounded-full text-red-500 hover:bg-red-50 dark:text-red-300 dark:hover:bg-red-900/30 ${X.actionButton}`,title:"Delete conversation",children:b.jsx($6,{className:X.actionIcon})})]})]}),b.jsxs("div",{className:`mt-1 flex items-center overflow-hidden pr-1 text-gray-500 dark:text-[#a6acc5] ${X.metaGap} ${X.metaText}`,children:[b.jsx("span",{className:"min-w-0 flex-1 truncate leading-none",children:en(Ce.updatedAt)}),b.jsxs("span",{className:`inline-flex shrink-0 items-center gap-1 rounded-full bg-white/80 font-medium text-gray-600 shadow-sm dark:bg-white/10 dark:text-[#e5e7f4] leading-none ${X.badgePadding} ${X.badgeText}`,children:[b.jsx(q0,{className:X.badgeIcon}),Ce.messages.length]}),Ce.attachedFiles&&Ce.attachedFiles.length>0&&b.jsxs("span",{className:`inline-flex shrink-0 items-center gap-1 rounded-full bg-white/80 font-medium text-gray-600 shadow-sm dark:bg-white/10 dark:text-[#e5e7f4] leading-none ${X.badgePadding} ${X.badgeText}`,children:[b.jsx(Z6,{className:X.badgeIcon}),Ce.attachedFiles.length]})]}),_&&b.jsxs("div",{className:"flex items-center gap-2 text-[11px] uppercase tracking-wide text-gray-500 dark:text-[#a6acc5]",children:[b.jsx("span",{className:"inline-flex items-center rounded-full bg-blue-50 px-2 py-0.5 text-[10px] font-semibold text-blue-700 dark:bg-blue-900/30 dark:text-blue-200",children:"Agent"}),b.jsx("span",{className:"min-w-0 flex-1 truncate text-gray-600 dark:text-[#d4d7e2]",children:_})]})]})},Ce.id)})})}),ge&&b.jsx("div",{className:"border-t border-gray-200 p-4 dark:border-[#4a4b54]",children:b.jsxs("div",{className:"text-center",children:[b.jsx("div",{className:"flex items-center justify-center mb-3",children:b.jsx("span",{className:"text-sm font-medium text-gray-900 dark:text-[#ececf1]",children:"Powered by ORBIT"})}),te.isLoading?b.jsxs("div",{className:"flex items-center justify-center gap-2 text-xs text-gray-500 dark:text-[#bfc2cd] mb-3",children:[b.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-gray-400"}),b.jsx("span",{children:"Loading stats..."})]}):te.error?b.jsx("div",{className:"flex items-center justify-center gap-2 text-xs text-red-500 dark:text-red-400 mb-3",children:b.jsx("span",{children:"⚠️ Failed to load stats"})}):b.jsxs("div",{className:"flex items-center justify-center gap-4 text-xs text-gray-500 dark:text-[#bfc2cd] mb-3",children:[b.jsxs("div",{className:"flex items-center gap-1",children:[b.jsx("svg",{className:"w-4 h-4 text-yellow-500",fill:"currentColor",viewBox:"0 0 24 24",children:b.jsx("path",{d:"M12 17.27L18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z"})}),b.jsxs("span",{children:[te.stars.toLocaleString()," stars"]})]}),b.jsxs("div",{className:"flex items-center gap-1",children:[b.jsx("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 16 16",children:b.jsx("path",{d:"M5 3.25a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm0 2.122a2.25 2.25 0 10-1.5 0v.878A2.25 2.25 0 005.75 8.5h1.5v2.128a2.251 2.251 0 101.5 0V8.5h1.5a2.25 2.25 0 002.25-2.25v-.878a2.25 2.25 0 10-1.5 0v.878a.75.75 0 01-.75.75H4.5A.75.75 0 013 6.25v-.878zm3.75 7.378a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm3-8.75a.75.75 0 100-1.5.75.75 0 000 1.5z"})}),b.jsxs("span",{children:[te.forks.toLocaleString()," forks"]})]})]}),b.jsxs("a",{href:`https://github.com/${IV()}/${yV()}`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300 transition-colors",children:[b.jsx("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 24 24",children:b.jsx("path",{d:"M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"})}),"View on GitHub"]})]})})]}),b.jsx(DV,{isOpen:p.isOpen,onClose:pe,onConfirm:Be,title:"Delete Conversation",message:`Are you sure you want to delete "${p.conversationTitle}"? This will clear the conversation history.`,confirmText:"Delete",cancelText:"Cancel",type:"danger",isLoading:p.isDeleting}),b.jsx(DV,{isOpen:C.isOpen,onClose:Ot,onConfirm:st,title:"Clear All Conversations",message:`Are you sure you want to delete all ${ae} ${le}? This will clear all conversation history.`,confirmText:"Clear All",cancelText:"Cancel",type:"danger",isLoading:C.isDeleting})]})}function T$e({isOpen:e,onClose:t}){const{theme:r,updateTheme:n}=$f(),{settings:A,updateSettings:i}=em(),[a,s]=y.useState(null),[o,l]=y.useState(!1),[c,u]=y.useState(""),[g,d]=y.useState(!1);if(y.useEffect(()=>{e&&ese().then(s)},[e]),!e)return null;const B=I=>{n({mode:I})},h=I=>{n({fontSize:I})},f=()=>{n({highContrast:!r.highContrast})},w=()=>{i({soundEnabled:!A.soundEnabled})},p=()=>{u(""),d(!1),l(!0)},m=()=>{l(!1),u(""),d(!1)},C=()=>{m(),localStorage.clear(),window.location.reload()},E=g&&c.trim().toLowerCase()==="reset";return b.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50",children:b.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-2xl shadow-2xl w-full max-w-md max-h-[90vh] flex flex-col overflow-hidden relative",children:[b.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-600",children:[b.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-gray-100",children:"Settings"}),b.jsx("button",{onClick:t,className:"p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors",children:b.jsx($c,{className:"w-5 h-5 text-gray-500 dark:text-gray-400"})})]}),b.jsxs("div",{className:"flex-1 min-h-0 p-6 space-y-6 overflow-y-auto",children:[b.jsxs("div",{className:"space-y-4",children:[b.jsxs("h3",{className:"text-lg font-medium text-gray-900 dark:text-gray-100 flex items-center gap-2",children:[b.jsx(Ple,{className:"w-5 h-5"}),"Appearance"]}),b.jsxs("div",{className:"space-y-2",children:[b.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Theme"}),b.jsx("div",{className:"grid grid-cols-3 gap-2",children:[{value:"light",label:"Light",icon:$le},{value:"dark",label:"Dark",icon:Ole},{value:"system",label:"System",icon:Jle}].map(({value:I,label:Q,icon:N})=>b.jsxs("button",{onClick:()=>B(I),className:`flex flex-col items-center gap-2 p-3 rounded-lg border-2 transition-all duration-200 ${r.mode===I?"border-blue-500 bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300":"border-gray-200 dark:border-gray-600 hover:border-gray-300 dark:hover:border-gray-500 text-gray-700 dark:text-gray-300"}`,children:[b.jsx(N,{className:"w-5 h-5"}),b.jsx("span",{className:"text-sm font-medium",children:Q})]},I))})]}),b.jsxs("div",{className:"flex items-center justify-between",children:[b.jsxs("div",{children:[b.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"High Contrast"}),b.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Improve readability with enhanced contrast"})]}),b.jsx("button",{onClick:f,className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${r.highContrast?"bg-blue-600":"bg-gray-200 dark:bg-gray-600"}`,children:b.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${r.highContrast?"translate-x-6":"translate-x-1"}`})})]}),b.jsxs("div",{className:"space-y-2",children:[b.jsxs("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 flex items-center gap-2",children:[b.jsx(nce,{className:"w-4 h-4"}),"Font Size"]}),b.jsx("div",{className:"grid grid-cols-3 gap-2",children:[{value:"small",label:"Small"},{value:"medium",label:"Medium"},{value:"large",label:"Large"}].map(({value:I,label:Q})=>b.jsx("button",{onClick:()=>h(I),className:`p-2 rounded-lg border-2 transition-colors text-center ${r.fontSize===I?"border-blue-500 bg-blue-50 dark:bg-blue-900/20":"border-gray-200 dark:border-gray-600 hover:border-gray-300 dark:hover:border-gray-500"}`,children:b.jsx("span",{className:`font-medium ${I==="small"?"text-sm":I==="large"?"text-lg":"text-base"}`,children:Q})},I))})]})]}),b.jsxs("div",{className:"space-y-4",children:[b.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-gray-100",children:"Chat Preferences"}),b.jsxs("div",{className:"flex items-center justify-between",children:[b.jsxs("div",{className:"flex items-center gap-2",children:[b.jsx(_0,{className:"w-4 h-4 text-gray-600 dark:text-gray-400"}),b.jsxs("div",{children:[b.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Sound Effects"}),b.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Play sounds for notifications and events"})]})]}),b.jsx("button",{onClick:w,className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${A.soundEnabled?"bg-blue-600":"bg-gray-200 dark:bg-gray-600"}`,children:b.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${A.soundEnabled?"translate-x-6":"translate-x-1"}`})})]})]}),b.jsxs("div",{className:"space-y-4 pt-4 border-t border-gray-200 dark:border-gray-600",children:[b.jsxs("h3",{className:"text-lg font-medium text-gray-900 dark:text-gray-100 flex items-center gap-2",children:[b.jsx($6,{className:"w-5 h-5"}),"Data Management"]}),b.jsxs("div",{className:"space-y-3",children:[b.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Clear all application data including conversations, and personalized settings."}),b.jsx("button",{onClick:p,className:"w-full px-4 py-2 text-sm font-medium text-red-600 dark:text-red-400 border border-red-300 dark:border-red-700 rounded-lg hover:bg-red-50 dark:hover:bg-red-900/20 transition-colors",children:"Reset Application"})]})]}),b.jsxs("div",{className:"space-y-2 pt-4 border-t border-gray-200 dark:border-gray-600",children:[b.jsxs("h3",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 flex items-center gap-2",children:[b.jsx(Wle,{className:"w-4 h-4"}),"About"]}),b.jsxs("div",{className:"space-y-1",children:[b.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:["AI Chat Application v",(a==null?void 0:a.appVersion)||"1.0.0"]}),b.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:["API Package: @schmitech/chatbot-api v",(a==null?void 0:a.apiVersion)||"^0.5.3",(a==null?void 0:a.isLocalApi)&&b.jsx("span",{className:"ml-1 px-1.5 py-0.5 bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300 rounded text-xs font-medium",children:"Local"})]}),b.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Built with React, TypeScript, and Tailwind CSS"})]})]})]}),o&&b.jsx("div",{className:"absolute inset-0 bg-black/70 flex items-center justify-center p-4 z-50",children:b.jsxs("div",{className:"w-full max-w-sm rounded-2xl bg-white dark:bg-gray-900 border border-red-100 dark:border-red-800 shadow-2xl p-6 space-y-4",children:[b.jsxs("div",{className:"flex items-start gap-3",children:[b.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-red-100 dark:bg-red-900/40",children:b.jsx(qk,{className:"w-5 h-5 text-red-600 dark:text-red-400"})}),b.jsxs("div",{children:[b.jsx("p",{className:"text-base font-semibold text-gray-900 dark:text-gray-100",children:"Reset application data?"}),b.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:["This removes everything stored on this device. Type ",b.jsx("span",{className:"font-semibold text-gray-900 dark:text-gray-100",children:"RESET"})," to continue."]})]})]}),b.jsxs("div",{className:"space-y-2",children:[b.jsx("label",{className:"text-xs font-medium text-gray-700 dark:text-gray-300",children:"Confirmation text"}),b.jsx("input",{value:c,onChange:I=>u(I.target.value.toUpperCase()),placeholder:"RESET",className:"w-full rounded-lg border border-gray-300 dark:border-gray-600 bg-transparent px-3 py-2 text-sm uppercase tracking-widest focus:outline-none focus:ring-2 focus:ring-red-400 dark:text-gray-100"})]}),b.jsxs("label",{className:"flex items-start gap-2 text-xs text-gray-600 dark:text-gray-400",children:[b.jsx("input",{type:"checkbox",checked:g,onChange:I=>d(I.target.checked),className:"mt-0.5 h-4 w-4 rounded border-gray-300 dark:border-gray-500 text-red-600 focus:ring-red-500"}),b.jsx("span",{children:"I understand this action is permanent and will reload the app."})]}),b.jsxs("div",{className:"flex gap-2 pt-2",children:[b.jsx("button",{onClick:m,className:"flex-1 px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-300 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors",children:"Cancel"}),b.jsx("button",{onClick:C,disabled:!E,className:`flex-1 px-4 py-2 text-sm font-semibold rounded-lg transition-colors ${E?"bg-red-600 text-white hover:bg-red-700 dark:bg-red-700 dark:hover:bg-red-600":"bg-red-200 text-red-600/60 dark:bg-red-900/20 dark:text-red-400/60 cursor-not-allowed"}`,children:"Reset"})]})]})})]})})}function L$e({message:e}){return b.jsx("div",{className:"min-h-screen bg-slate-950 text-white flex items-center justify-center px-4 py-12",children:b.jsxs("div",{className:"max-w-lg w-full text-center space-y-6",children:[b.jsx("div",{className:"flex justify-center",children:b.jsx("div",{className:"bg-white/10 rounded-full p-4",children:b.jsx(qk,{className:"h-10 w-10 text-amber-300","aria-hidden":"true"})})}),b.jsx("div",{className:"space-y-2",children:b.jsx("p",{className:"text-2xl font-semibold tracking-tight",children:"Temporarily Unavailable"})}),b.jsx("p",{className:"text-sm text-white/60",children:e})]})})}function H$e(){const[e,t]=y.useState(!1),[r,n]=y.useState(!1),A=O_e();return A?b.jsx(AR,{children:b.jsx(L$e,{message:A})}):b.jsx(AR,{children:b.jsx(xle,{children:b.jsxs("div",{className:"min-h-screen flex flex-col md:flex-row bg-white dark:bg-[#212121] text-slate-900 dark:text-slate-100",children:[b.jsx("div",{className:"hidden md:flex md:min-h-screen",children:b.jsx(kV,{onOpenSettings:()=>t(!0)})}),b.jsx("div",{className:"flex-1 flex justify-center w-full",children:b.jsx(G$e,{onOpenSettings:()=>t(!0),onOpenSidebar:()=>n(!0)})}),b.jsx(T$e,{isOpen:e,onClose:()=>t(!1)}),r&&b.jsxs("div",{className:"fixed inset-0 z-50 flex md:hidden",children:[b.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>n(!1),"aria-hidden":"true"}),b.jsxs("div",{className:"relative z-10 h-full w-[min(18rem,85vw)] animate-slideIn",children:[b.jsx(kV,{onRequestClose:()=>n(!1),onOpenSettings:()=>{t(!0),n(!1)}}),b.jsx("button",{onClick:()=>n(!1),className:"absolute -right-3 top-[max(env(safe-area-inset-top),0.75rem)] rounded-full bg-white/95 p-2.5 text-gray-600 shadow-lg active:scale-95 transition-transform dark:bg-[#2d2f39] dark:text-[#ececf1]","aria-label":"Close menu",children:b.jsx($c,{className:"h-5 w-5"})})]})]})]})})})}document.title=G_e();ese().then(e=>{me(`📱 App Version: v${e.appVersion}`),me(`📦 API Package: @schmitech/chatbot-api v${e.apiVersion}`),me(`🔧 API Mode: ${e.isLocalApi?"Local":"NPM Package"}`)});W6(document.getElementById("root")).render(b.jsx(y.StrictMode,{children:b.jsx(H$e,{})}));export{hFe as $,Qs as A,NYe as B,Uje as C,tet as D,SYe as E,YYe as F,Ve as G,P$e as H,Yd as I,K$e as J,vYe as K,Wn as L,TUe as M,Jje as N,zi as O,sze as P,F as Q,DGe as R,KUe as S,PX as T,tJ as U,eJ as V,aSe as W,s2 as X,mi as Y,jZ as Z,Nt as _,Aet as a,tZ as a$,dFe as a0,$Z as a1,CU as a2,Nm as a3,VDe as a4,KDe as a5,Iu as a6,PDe as a7,WDe as a8,Mw as a9,BYe as aA,XS as aB,XH as aC,xd as aD,fGe as aE,mGe as aF,C$ as aG,Rm as aH,IGe as aI,wGe as aJ,cGe as aK,Tw as aL,M$ as aM,Wve as aN,$U as aO,uGe as aP,nc as aQ,y$ as aR,Xve as aS,Lm as aT,q2e as aU,xGe as aV,Vh as aW,CYe as aX,Kh as aY,Je as aZ,qe as a_,$h as aa,IU as ab,mU as ac,al as ad,Qw as ae,IZ as af,FA as ag,Hbe as ah,AU as ai,fZ as aj,qh as ak,V$e as al,SSe as am,RH as an,Hm as ao,uU as ap,wr as aq,bU as ar,km as as,ZFe as at,WRe as au,gU as av,xU as aw,W$e as ax,wu as ay,yGe as az,Ste as b,NU as b0,HJ as b1,LJ as b2,oq as b3,Yw as b4,_$e as b5,X$e as b6,Cu as b7,_i as b8,Z$e as b9,cve as bA,LO as bB,AB as bC,JRe as bD,HRe as bE,cU as bF,Pe as bG,u$ as bH,rGe as bI,xze as bJ,_x as bK,Ro as bL,Wu as bM,f$ as bN,zw as bO,t2 as bP,nO as bQ,tB as bR,eet as ba,q$e as bb,$$e as bc,O$e as bd,LUe as be,un as bf,jo as bg,iee as bh,ac as bi,D$ as bj,at as bk,ya as bl,_U as bm,rve as bn,qo as bo,e2 as bp,$2e as bq,ive as br,Pu as bs,Zve as bt,tve as bu,eve as bv,oO as bw,rB as bx,p$ as by,Rw as bz,iet as c,Fi as d,xYe as e,eZ as f,sn as g,bYe as h,net as i,UGe as j,Wt as k,Hu as l,jje as m,ret as n,aet as o,DYe as p,S$ as q,oet as r,ue as s,pje as t,set as u,kYe as v,kt as w,zUe as x,Rje as y,qU as z};
|
|
1004
|
+
`,children:[b.jsx("input",{ref:g,type:"file",multiple:!0,onChange:v,className:"hidden",disabled:s,accept:".pdf,.doc,.docx,.txt,.md,.csv,.json,.html,.pptx,.xlsx,.py,.java,.sql,.js,.mjs,.ts,.tsx,.cpp,.cxx,.cc,.c,.h,.hpp,.go,.rs,.rb,.php,.sh,.bash,.zsh,.yaml,.yml,.xml,.css,.scss,.sass,.less,.png,.jpg,.jpeg,.tiff,.wav,.mp3,.mp4,.ogg,.flac,.webm,.m4a,.aac,.vtt"}),b.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 text-center",children:[b.jsx(Ace,{className:`w-6 h-6 ${o?"text-emerald-600 dark:text-emerald-400":"text-slate-400 dark:text-slate-500"}`}),b.jsxs("div",{className:"px-2",children:[b.jsx("p",{className:"text-xs sm:text-sm font-medium text-slate-700 dark:text-slate-300",children:s?"File upload disabled":o?"Drop files here":"Click or drag files to upload"}),b.jsxs("p",{className:"text-[10px] sm:text-xs text-slate-500 dark:text-slate-400 mt-0.5 px-1",children:["PDF, DOCX, TXT, CSV, JSON, HTML, code files (.py, .js, .ts, .java, .sql, etc.), images, audio (max ",a," files)"]})]})]})]}),O.length>0&&b.jsxs("div",{className:"w-full max-w-full space-y-3 rounded-lg border border-slate-200 bg-white p-3 dark:border-slate-700 dark:bg-slate-900/40",children:[b.jsx("p",{className:"text-xs font-semibold text-slate-600 dark:text-slate-300",children:"Uploads in other conversations"}),O.map(({conversationId:K,uploads:Ae})=>b.jsxs("div",{className:"space-y-2",children:[b.jsx("div",{className:"text-xs font-medium text-slate-500 dark:text-slate-400",children:R.get(K)||"Conversation"}),Ae.map(({key:G,progress:X})=>b.jsxs("div",{className:"w-full max-w-full flex items-center gap-3 p-3 bg-slate-50 dark:bg-slate-800/50 rounded-lg overflow-hidden",children:[b.jsx(_c,{className:"w-4 h-4 text-emerald-600 dark:text-emerald-400 animate-spin flex-shrink-0"}),b.jsxs("div",{className:"flex-1 min-w-0 overflow-hidden",children:[b.jsx("p",{className:"text-sm font-medium text-slate-700 dark:text-slate-300 truncate",children:X.filename}),b.jsx("div",{className:"mt-1 bg-slate-200 dark:bg-slate-700 rounded-full h-1.5",children:b.jsx("div",{className:"bg-emerald-600 dark:bg-emerald-400 h-1.5 rounded-full transition-all duration-300",style:{width:`${X.progress}%`}})})]}),b.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:X.status==="uploading"?"Uploading...":X.status==="processing"?"Processing...":X.status==="completed"?"Done":"Error"})]},G))]},K))]})]})}const NV={"image/jpeg":"jpg","image/jpg":"jpg","image/png":"png","image/tiff":"tiff","image/tif":"tif","image/gif":"gif","image/webp":"webp","application/pdf":"pdf","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/msword":"doc","text/plain":"txt","text/markdown":"md","application/json":"json"};function F$e(e){if(!e)return"bin";if(NV[e])return NV[e];const t=e.split("/");return t.length===2&&t[1]?t[1]:"bin"}function Y$e(e){return e.replace(/[^a-zA-Z0-9._-]/g,"_").replace(/_+/g,"_")||"pasted-file"}function N$e(e){const t=e.lastIndexOf(".");return t===-1||t===e.length-1?null:e.slice(t+1).toLowerCase()}function b$e(e){const t=e.lastIndexOf(".");return t===-1?e:e.slice(0,t)}function x$e(e,t){const r=Date.now(),n=e.name&&e.name.trim().length>0?e.name.trim():"pasted-file",A=Y$e(b$e(n)),a=N$e(n)||F$e(e.type),s=`${A}-${r}-${t}.${a}`;return new File([e],s,{type:e.type||"application/octet-stream"})}function bV({onSend:e,disabled:t=!1,placeholder:r=Xae(),isCentered:n=!1}){var kB;const[A,i]=y.useState(""),[a,s]=y.useState(!1),[o,l]=y.useState(!1),[c,u]=y.useState(!1),[g,d]=y.useState([]),[B,h]=y.useState({}),[f,w]=y.useState(new Map),[p,m]=y.useState(!1),[C,E]=y.useState(!1),[I,Q]=y.useState(null),[N,k]=y.useState(null),[x,D]=y.useState(null),z=y.useRef(null),H=y.useRef(new Set),T=y.useRef(""),v=y.useRef(!1),L=y.useRef(0),J=y.useRef(null),{settings:R,updateSettings:O}=em(),U=y.useCallback((fe,He)=>{fe&&h(pt=>{if(pt[fe]===He)return pt;const Yt={...pt};return He?Yt[fe]=!0:delete Yt[fe],Yt})},[]),[K,Ae]=y.useState(0),{createConversation:G,currentConversationId:X,conversations:ie,isLoading:ae,syncConversationFiles:le}=ct(),ge=ie.find(fe=>fe.id===X),te=ge?ge.messages.filter(fe=>!(fe.role==="assistant"&&fe.isStreaming)).length:0,he=ie.reduce((fe,He)=>fe+He.messages.filter(pt=>!(pt.role==="assistant"&&pt.isStreaming)).length,0),we=!!ge&&ot.maxMessagesPerConversation!==null&&te>=ot.maxMessagesPerConversation,q=ot.maxTotalMessages!==null&&he>=ot.maxTotalMessages,be=y.useCallback(()=>{Ae(fe=>fe+1)},[]),{isListening:ke,isSupported:Be,startListening:pe,stopListening:xe,error:Le}=$_e(fe=>{i(He=>{const pt=(He+fe).slice(0,ot.maxMessageLength);return T.current=pt,pt})},be),Fe=T_e(),Ke=Fe&&Be,st=z_e(),Ot=(ge==null?void 0:ge.attachedFiles)||[],en=ie.reduce((fe,He)=>{var pt;return fe+(((pt=He.attachedFiles)==null?void 0:pt.length)||0)},0),vr=ot.maxFilesPerConversation!==null&&ot.maxFilesPerConversation>0&&Ot.length>=ot.maxFilesPerConversation,Ce=ot.maxTotalFiles!==null&&en>=ot.maxTotalFiles,_=((kB=ge==null?void 0:ge.adapterInfo)==null?void 0:kB.isFileSupported)??!1,se=g.some(fe=>fe.processing_status?fe.processing_status!=="completed"&&fe.processing_status!=="error"&&fe.processing_status!=="failed":!0)||Ot.some(fe=>fe.processing_status?fe.processing_status!=="completed"&&fe.processing_status!=="error"&&fe.processing_status!=="failed":!0),Qe=X?!!B[X]:!1,it=Object.values(B).some(Boolean),ut=t||se||Qe||(we||q),er=st&&_,oe=vr||Ce,rt=!er||ut||oe;y.useEffect(()=>{if(z.current){z.current.style.height="auto";const He=z.current.scrollHeight;z.current.style.height=`${Math.min(He,120)}px`,z.current.style.overflowY=He>120?"auto":"hidden"}},[A]);const lt=()=>{const fe=document.activeElement;return fe&&fe.tagName==="TEXTAREA"};y.useEffect(()=>{!ut&&z.current&&!lt()&&z.current.focus()},[ut]);const Et=y.useRef(ae);y.useEffect(()=>{Et.current&&!ae&&!ut&&z.current&&setTimeout(()=>{z.current&&!lt()&&z.current.focus()},100),Et.current=ae},[ae,ut]),y.useEffect(()=>{if(!Ke||(K>L.current&&(v.current=!0,L.current=K),!v.current||K===0))return;const fe=setTimeout(()=>{const He=T.current.trim(),pt=ct.getState();if(me("[MessageInput] Auto-send check after voice completion:",{hasMessage:!!He,isInputDisabled:ut,isComposing:a,isLoading:pt.isLoading}),!He){v.current=!1;return}if(!ut&&!a&&!pt.isLoading){const Yt=pt.conversations.find(Vt=>Vt.id===pt.currentConversationId),Gn=((Yt==null?void 0:Yt.attachedFiles)||[]).map(Vt=>Vt.file_id);e(He,Gn.length>0?Gn:void 0),v.current=!1,i(""),T.current="",z.current&&(z.current.style.height="auto",z.current.style.overflowY="hidden")}},400);return()=>clearTimeout(fe)},[Ke,K,ut,a,e]),y.useEffect(()=>{Qe&&c&&u(!1)},[Qe,c]),y.useEffect(()=>{!Qe&&g.length},[Qe,g.length,c]);const vt=y.useCallback((fe,He)=>{setTimeout(()=>{let pt=ct.getState(),Yt=He||pt.currentConversationId;if(Yt||(Yt=G(),pt=ct.getState(),Yt=pt.currentConversationId||Yt),!Yt)return;const dr=new Set(fe.map(Vt=>Vt.file_id)),Gn=[];H.current.forEach((Vt,tr)=>{const[,...hr]=tr.split("-"),za=hr.join("-");dr.has(za)||Gn.push(tr)}),Gn.forEach(Vt=>H.current.delete(Vt)),fe.forEach(Vt=>{const tr=`${Yt}-${Vt.file_id}`;H.current.has(tr)||(H.current.add(tr),me(`[MessageInput] Adding file ${Vt.file_id} to conversation ${Yt}`),pt.addFileToConversation(Yt,Vt))})},0)},[G]);y.useEffect(()=>{if(X!==J.current)if(J.current=X||null,X&&ge){const fe=ge.attachedFiles||[];d(fe.map(He=>({...He})))}else d([])},[X,ge]),y.useEffect(()=>{if(X&&ge){const fe=ge.attachedFiles||[];fe.length>0?d(He=>{const pt=new Set(He.map(dr=>dr.file_id)),Yt=fe.filter(dr=>!pt.has(dr.file_id));return Yt.length>0?(me(`[MessageInput] Syncing ${Yt.length} missing files from conversation to UI`),[...He,...Yt]):He}):fe.length===0&&g.length>0&&d([])}},[X,ge,ie,g.length]);const xt=y.useRef(null),Nr=y.useRef("");y.useEffect(()=>{const fe=lr();if(!X||!ge||(fe?!ge.adapterName:!ge.apiKey))return;const He=ge.attachedFiles||[],pt=He.length>0,Yt=He.filter(tr=>!tr.processing_status||tr.processing_status==="processing"||tr.processing_status==="uploading"),dr=pt?`${He.length}:${He.map(tr=>tr.file_id).join("|")}`:"";if(pt&&(xt.current!==X||Nr.current!==dr)?(me(`[MessageInput] Syncing ${He.length} files for conversation ${X}...`),xt.current=X,Nr.current=dr,le(X).catch(tr=>{})):pt||(xt.current=X,Nr.current=""),Yt.length===0)return;me(`[MessageInput] Found ${Yt.length} files still processing, starting poll...`);const Vt=setInterval(async()=>{const hr=ct.getState().conversations.find(ea=>ea.id===X);if(!hr){clearInterval(Vt);return}if((hr.attachedFiles||[]).filter(ea=>!ea.processing_status||ea.processing_status==="processing"||ea.processing_status==="uploading").length===0){clearInterval(Vt);return}try{await le(X)}catch{}},3e3);return()=>{clearInterval(Vt)}},[X,ge,le]),y.useEffect(()=>{h(fe=>{const He=new Set(ie.map(dr=>dr.id));let pt=!1;const Yt={...fe};return Object.keys(Yt).forEach(dr=>{He.has(dr)||(delete Yt[dr],pt=!0)}),pt?Yt:fe})},[ie]);const Ft=fe=>{if(fe.preventDefault(),(A.trim()||g.length>0)&&!ut&&!a){ke&&xe();const pt=((ge==null?void 0:ge.attachedFiles)||[]).map(Yt=>Yt.file_id);e(A.trim(),pt.length>0?pt:void 0),cd("messageSent",R.soundEnabled),i(""),T.current="",d([]),u(!1),z.current&&(z.current.style.height="auto",z.current.style.overflowY="hidden")}},qn=y.useCallback(fe=>{if(!fe||fe.length===0)return;const He=fe.length===1?`File "${fe[0].filename}" uploaded successfully`:`${fe.length} files uploaded successfully`;cd("success",R.soundEnabled),k(He),setTimeout(()=>{k(null)},6e3)},[R.soundEnabled]),lg=y.useCallback((fe,He)=>{me(`[MessageInput] handleFilesSelected called with ${He.length} files for conversation ${fe}:`,He),fe&&(fe===X&&d(He),vt(He,fe))},[X,vt]),$i=y.useCallback((fe,He)=>{fe===X&&qn(He)},[X,qn]),cc=fe=>{fe.key==="Enter"&&!fe.shiftKey&&!a&&(fe.preventDefault(),Ft(fe))},uc=()=>{ke?xe():pe()},gr=()=>{O({voiceEnabled:!R.voiceEnabled})},zs=y.useCallback(async fe=>{if(!st||!o||!_||ut)return;const He=fe.clipboardData;if(!He||!He.items)return;const Yt=Array.from(He.items).filter(tr=>tr.kind==="file");if(Yt.length===0)return;const dr=[];if(Yt.forEach((tr,hr)=>{const za=tr.getAsFile();za&&dr.push(x$e(za,hr))}),dr.length===0)return;fe.preventDefault(),Q(null),k(null);let Gn=null;const Vt=lr();try{const tr=ct.getState(),hr=tr.conversations.find(Ht=>Ht.id===tr.currentConversationId);if(((hr==null?void 0:hr.attachedFiles)||[]).length+dr.length>ot.maxFilesPerConversation)throw new Error(`Maximum ${ot.maxFilesPerConversation} files allowed per conversation. Please remove some files first.`);if(ot.maxTotalFiles!==null&&tr.conversations.reduce((Dt,tn)=>{var rr;return Dt+(((rr=tn.attachedFiles)==null?void 0:rr.length)||0)},0)+dr.length>ot.maxTotalFiles)throw new Error(`Maximum ${ot.maxTotalFiles} total files allowed across all conversations. Please remove some files from other conversations first.`);if(!hr)throw new Error("Conversation not found. Please select a conversation first.");if(Vt){if(!hr.adapterName)throw new Error("Adapter not configured for this conversation. Please select an adapter first.")}else if(!hr.apiKey||hr.apiKey===wo())throw new Error("API key not configured for this conversation. Please configure API settings first.");const ea=hr.apiKey,V=ga(hr.apiUrl),Ue=hr.adapterName;Gn=hr.id,U(Gn,!0);const Ye=[],jt=[];for(let Ht=0;Ht<dr.length;Ht++){const Dt=dr[Ht],tn=Dt.name||`Clipboard file ${Ht+1}`,rr=`${tn}-${Date.now()}-${Ht}`;w(pA=>{const ta=new Map(pA);return ta.set(rr,{filename:tn,progress:0,status:"uploading"}),ta});const GA=pA=>{w(ta=>{const ti=new Map(ta),ug=ti.get(rr);return ug&&ti.set(rr,{...ug,filename:tn,progress:pA.progress,status:pA.status,fileId:pA.fileId}),ti})},cg=()=>new Promise(pA=>{w(ta=>{const ti=new Map(ta),ug=ti.get(rr);return ug&&ti.set(rr,{...ug,progress:100,status:"completed"}),ti}),setTimeout(()=>{w(ta=>{const ti=new Map(ta);return ti.delete(rr),ti}),pA()},2500)});me(`[MessageInput] Pasting file: ${Dt.name}, type: ${Dt.type||"unknown"}, size: ${Dt.size}`);const rn=await kh.uploadFile(Dt,pA=>{me(`[MessageInput] Paste upload progress for ${Dt.name}: ${pA.progress}% - ${pA.status}`),GA(pA)},ea,V,Vt?Ue:void 0);Ye.push(rn),jt.push(cg())}if(Ye.length>0){let Ht=Ye;if(Gn&&Gn===X){const Dt=new Set(g.map(rr=>rr.file_id)),tn=Ye.filter(rr=>!Dt.has(rr.file_id));tn.length>0?(d(rr=>[...rr,...tn]),Ht=tn):Ht=[]}Ht.length>0&&vt(Ht,Gn),await Promise.all(jt),qn(Ye)}}catch(tr){const hr=tr instanceof Error?tr.message:"Failed to paste file";cd("error",R.soundEnabled),Q(hr),hr.toLowerCase().includes("maximum")&&D(hr),setTimeout(()=>{Q(null)},5e3),w(new Map)}finally{U(Gn,!1)}},[g,X,o,_,ut,U,R.soundEnabled,qn,vt,st]),bB=q?`Workspace limit of ${ot.maxTotalMessages} messages reached. Delete or archive old conversations to continue.`:we?`This chat hit the ${ot.maxMessagesPerConversation} message limit. Start a new conversation to continue.`:se||Qe?"Files are uploading/processing, please wait...":er?"Message ORBIT or drop files here":r,ja=[];q&&ot.maxTotalMessages!==null&&ja.push(`Workspace limit of ${ot.maxTotalMessages} total messages reached. Delete or export older conversations to continue.`),we&&ot.maxMessagesPerConversation!==null&&ja.push(`This conversation reached the ${ot.maxMessagesPerConversation} message limit. Start a new conversation to keep chatting.`),x&&ja.push(x),y.useEffect(()=>{!Fe||!Le||cd("error",R.soundEnabled)},[Fe,R.soundEnabled,Le]),y.useEffect(()=>{if(!x)return;const fe=setTimeout(()=>D(null),5e3);return()=>clearTimeout(fe)},[x]);const xB=n?"max-w-3xl":"max-w-5xl",DB=n?"flex justify-center":"";return b.jsx("div",{className:`bg-white px-3 py-3 md:px-0 md:py-4 dark:bg-[#212121] sm:px-4 ${DB}`,children:b.jsxs("div",{className:`mx-auto w-full ${xB}`,children:[Le&&Fe&&b.jsx("div",{className:"mb-3 w-full rounded-md border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-600/40 dark:bg-red-900/30 dark:text-red-200",children:Le}),I&&b.jsx("div",{className:"mb-3 w-full rounded-md border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-600/40 dark:bg-red-900/30 dark:text-red-200",children:I}),N&&b.jsxs("div",{className:"mb-3 w-full flex items-center gap-2 rounded-md border border-green-200 bg-green-50 px-3 py-2 text-sm text-green-700 dark:border-green-600/40 dark:bg-green-900/30 dark:text-green-200",children:[b.jsx(Sle,{className:"h-4 w-4 flex-shrink-0"}),b.jsx("span",{children:N})]}),ja.length>0&&b.jsx("div",{className:"mb-3 w-full rounded-md border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900 dark:border-amber-500/40 dark:bg-[#2f2410] dark:text-amber-100",children:b.jsx("ul",{className:"list-disc space-y-1 pl-4",children:ja.map((fe,He)=>b.jsx("li",{children:fe},`${fe}-${He}`))})}),b.jsxs("form",{onSubmit:Ft,className:"flex w-full flex-col gap-2 md:gap-3",children:[b.jsxs("div",{className:`flex flex-col md:flex-row md:items-center gap-3 md:gap-2 rounded-2xl md:rounded-lg border px-4 py-3 md:px-4 md:py-3 shadow-sm transition-all ${o?"border-gray-400 shadow-md dark:border-[#565869] dark:shadow-lg":"border-gray-300 dark:border-[#40414f]"} bg-gray-50 dark:bg-[#2d2f39]`,children:[b.jsx("textarea",{ref:z,value:A,onChange:fe=>i(fe.target.value),onKeyDown:cc,onPaste:zs,onCompositionStart:()=>s(!0),onCompositionEnd:()=>s(!1),onFocus:()=>l(!0),onBlur:()=>l(!1),placeholder:bB,disabled:ut,rows:1,maxLength:ot.maxMessageLength,className:"flex-1 w-full md:w-auto min-w-0 resize-none bg-transparent py-1 text-base md:text-sm text-[#353740] placeholder-gray-500 focus:outline-none dark:text-[#ececf1] dark:placeholder-[#8e8ea0]",style:{minHeight:"24px",maxHeight:"120px",border:"none",outline:"none",boxShadow:"none",WebkitAppearance:"none",MozAppearance:"none",appearance:"none",caretColor:A.trim()||o?"inherit":"transparent"}}),b.jsxs("div",{className:"flex items-center justify-between md:justify-end gap-1 md:gap-2 md:flex-shrink-0",children:[b.jsxs("div",{className:"flex items-center gap-1 md:gap-2",children:[st&&b.jsx("button",{type:"button",onClick:fe=>{fe.preventDefault(),rt||u(!c)},disabled:rt,onMouseEnter:()=>m(!0),onMouseLeave:()=>m(!1),className:`flex h-10 w-10 md:h-8 md:w-8 shrink-0 items-center justify-center rounded-full transition-all active:scale-95 ${c||g.length>0?"bg-gray-200 text-[#353740] dark:bg-[#565869] dark:text-[#ececf1]":rt?"cursor-not-allowed text-gray-300 dark:text-[#6b6f7a]":"text-gray-500 hover:bg-gray-200 hover:text-[#353740] dark:text-[#bfc2cd] dark:hover:bg-[#565869]"}`,title:_?oe&&vr&&ot.maxFilesPerConversation!==null?`Maximum of ${ot.maxFilesPerConversation} files reached in this conversation. Start a new chat to upload more.`:oe&&Ce&&ot.maxTotalFiles!==null?`Workspace limit of ${ot.maxTotalFiles} total files reached. Remove files from other conversations first.`:ut?"Files are uploading/processing. Please wait...":g.length>0?`${g.length} file(s) attached`:"Attach files":"File upload not supported by this adapter",children:rt&&p?b.jsx($c,{className:"h-5 w-5 md:h-4 md:w-4"}):b.jsx(Z6,{className:"h-5 w-5 md:h-4 md:w-4"})}),A.length>0&&b.jsx("div",{className:"px-2 text-xs text-gray-500 dark:text-[#bfc2cd] md:min-w-[72px] md:text-right",children:b.jsxs("span",{className:A.length>=ot.maxMessageLength?"text-red-600 font-semibold":"",children:[A.length,"/",ot.maxMessageLength]})})]}),b.jsxs("div",{className:"flex items-center gap-1 md:gap-2",children:[Fe&&b.jsxs(b.Fragment,{children:[b.jsx("button",{type:"button",onClick:gr,className:`flex h-10 w-10 md:h-8 md:w-8 shrink-0 items-center justify-center rounded-full transition-all active:scale-95 ${R.voiceEnabled?"bg-blue-100 text-blue-600 dark:bg-blue-900/40 dark:text-blue-300":"text-gray-500 hover:bg-gray-200 hover:text-[#353740] dark:text-[#bfc2cd] dark:hover:bg-[#565869]"}`,title:R.voiceEnabled?"Voice responses enabled - Click to disable":"Enable voice responses (text-to-speech)",children:R.voiceEnabled?b.jsx(_0,{className:"h-5 w-5"}):b.jsx(ice,{className:"h-5 w-5"})}),Ke&&b.jsx("button",{type:"button",onClick:uc,disabled:ut,onMouseEnter:()=>E(!0),onMouseLeave:()=>E(!1),className:`flex h-10 w-10 md:h-8 md:w-8 shrink-0 items-center justify-center rounded-full transition-all active:scale-95 ${ke?"bg-red-100 text-red-600 dark:bg-red-900/40 dark:text-red-300":ut?"cursor-not-allowed text-gray-300 dark:text-[#6b6f7a]":"text-gray-500 hover:bg-gray-200 hover:text-[#353740] dark:text-[#bfc2cd] dark:hover:bg-[#565869]"}`,title:ut?"Files are uploading/processing. Please wait...":ke?"Stop recording":"Start voice input",children:ke||ut&&C?b.jsx(Lle,{className:"h-5 w-5"}):b.jsx(Hle,{className:"h-5 w-5"})})]}),(se||Qe)&&b.jsx("div",{className:"flex h-10 w-10 md:h-8 md:w-8 shrink-0 items-center justify-center",children:b.jsx(_c,{className:"h-5 w-5 md:h-4 md:w-4 animate-spin text-gray-500 dark:text-[#bfc2cd]"})}),b.jsx("button",{type:"submit",disabled:!A.trim()&&g.length===0||ut||a,className:`flex h-11 w-11 md:h-8 md:w-8 shrink-0 items-center justify-center rounded-full transition-all active:scale-95 ${(A.trim()||g.length>0)&&!ut&&!a?"bg-black text-white hover:bg-gray-800 dark:bg-white dark:text-black dark:hover:bg-gray-200":"bg-gray-300 text-gray-500 dark:bg-[#565869] dark:text-[#6b6f7a]"}`,title:"Send message",children:b.jsx(V6,{className:"h-5 w-5 md:h-4 md:w-4"})})]})]})]}),g.length>0&&b.jsx("div",{className:"flex flex-wrap gap-2",children:g.map(fe=>{const He=!fe.processing_status||fe.processing_status==="processing"||fe.processing_status==="uploading";return b.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-gray-200 bg-white px-2 py-1 text-xs dark:border-[#4a4b54] dark:bg-[#2d2f39]",children:[He&&b.jsx(_c,{className:"h-3 w-3 animate-spin text-emerald-600 dark:text-emerald-400 flex-shrink-0"}),b.jsx("span",{className:"truncate max-w-[150px] text-[#353740] dark:text-[#ececf1]",children:fe.filename}),He&&b.jsx("span",{className:"text-xs text-gray-500 dark:text-[#bfc2cd]",children:fe.processing_status==="uploading"?"Uploading...":"Processing..."}),b.jsx("button",{disabled:!0,className:"text-gray-300 dark:text-[#4a4b54] cursor-not-allowed",title:"File removal disabled; use Clear All in sidebar",children:b.jsx($c,{className:"h-3 w-3"})})]},fe.file_id)})}),st&&(_||it)&&b.jsxs("div",{className:`rounded-md border border-gray-200 bg-white p-3 dark:border-[#4a4b54] dark:bg-[#2d2f39] ${!c&&!Qe&&f.size===0&&!it?"hidden":""}`,children:[c&&b.jsxs("div",{className:"mb-2 flex items-center justify-between text-sm text-[#353740] dark:text-[#ececf1]",children:[b.jsx("span",{children:"Upload files"}),b.jsx("button",{onClick:()=>u(!1),className:"rounded p-1 text-gray-500 hover:bg-gray-100 hover:text-[#353740] dark:text-[#bfc2cd] dark:hover:bg-[#3c3f4a]",title:"Close",children:b.jsx($c,{className:"h-4 w-4"})})]}),(Qe||f.size>0)&&!c&&f.size===0&&b.jsx("div",{className:"mb-2 text-sm text-[#353740] dark:text-[#ececf1]",children:"Uploading files…"}),f.size>0&&b.jsx("div",{className:"mb-2 space-y-2",children:Array.from(f.entries()).map(([fe,He])=>b.jsxs("div",{className:"w-full max-w-full flex items-center gap-3 p-3 bg-gray-50 dark:bg-[#1f1f24] rounded-lg overflow-hidden",children:[b.jsx(_c,{className:"w-4 h-4 text-emerald-600 dark:text-emerald-400 animate-spin flex-shrink-0"}),b.jsxs("div",{className:"flex-1 min-w-0 overflow-hidden",children:[b.jsx("p",{className:"text-sm font-medium text-[#353740] dark:text-[#ececf1] truncate",children:He.filename}),b.jsx("div",{className:"mt-1 bg-gray-200 dark:bg-[#3c3f4a] rounded-full h-1.5",children:b.jsx("div",{className:"bg-emerald-600 dark:bg-emerald-400 h-1.5 rounded-full transition-all duration-300",style:{width:`${He.progress??0}%`}})})]}),b.jsx("span",{className:"text-xs text-gray-500 dark:text-[#bfc2cd]",children:He.status==="uploading"?"Uploading...":He.status==="processing"?"Processing...":He.status==="completed"?"Done":"Pending"})]},fe))}),b.jsx("div",{className:c||Qe?"block":"hidden","aria-hidden":!(c||Qe),children:b.jsx(M$e,{conversationId:X,onFilesSelected:lg,onUploadError:fe=>{D(fe)},onUploadingChange:U,onUploadSuccess:$i,maxFiles:ot.maxFilesPerConversation,disabled:rt})})]}),b.jsx("div",{className:"h-5 md:h-4",children:Ke&&ke&&b.jsxs("span",{className:"flex items-center gap-2 text-sm md:text-xs text-gray-500 dark:text-[#bfc2cd]",children:[b.jsx("span",{className:"h-2.5 w-2.5 md:h-2 md:w-2 animate-pulse rounded-full bg-red-500"}),"Listening..."]})})]})]})})}function D$e({adapter:e,onSelect:t}){return b.jsxs("button",{type:"button",onClick:()=>t(e),className:"group flex w-full items-center gap-3 rounded-2xl border border-gray-200 bg-white px-4 py-4 text-left transition-all duration-200 md:hover:-translate-y-0.5 hover:border-blue-200 hover:shadow-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2 dark:border-[#3b3c49] dark:bg-[#22232b] dark:hover:border-blue-400/50 dark:focus-visible:ring-blue-400",children:[b.jsxs("div",{className:"min-w-0 flex flex-1 flex-col gap-1",children:[b.jsx("span",{className:"truncate text-base font-semibold text-gray-900 dark:text-white",children:e.name}),e.description&&b.jsx("span",{className:"line-clamp-2 text-sm text-gray-600 dark:text-gray-300",children:e.description})]}),b.jsx("div",{className:"ml-auto flex h-10 w-10 items-center justify-center rounded-full border border-transparent bg-gray-50 text-gray-400 transition-colors group-hover:border-blue-100 group-hover:bg-white group-hover:text-blue-500 dark:bg-[#2a2b34] dark:text-gray-400 dark:group-hover:border-blue-500/40 dark:group-hover:bg-transparent dark:group-hover:text-blue-300",children:b.jsx(Ule,{className:"h-5 w-5"})})]})}const k$e="h-[96px]";function S$e({onAdapterSelect:e,className:t="",title:r="",subtitle:n="Each agent is tuned for a specific expertise. Pick one to start a focused conversation.",eyebrow:A="Pick an Agent"}){const[i,a]=y.useState([]),[s,o]=y.useState(!0),[l,c]=y.useState(null),u=y.useRef(null),[g,d]=y.useState(!1),[B,h]=y.useState(""),f=y.useMemo(()=>{const p=B.trim().toLowerCase();return p?i.filter(m=>{var I;const C=m.name.toLowerCase().includes(p),E=((I=m.description)==null?void 0:I.toLowerCase().includes(p))??!1;return C||E}):i},[i,B]);y.useEffect(()=>{let p=!0;return(async()=>{try{o(!0),c(null);const E=(await Kv()).slice().sort((I,Q)=>I.name.localeCompare(Q.name,void 0,{sensitivity:"base"}));p&&a(E)}catch{p&&c("Unable to load agents right now.")}finally{p&&o(!1)}})(),()=>{p=!1}},[]),y.useEffect(()=>{const p=()=>{const m=u.current;if(!m){d(!1);return}const C=m.scrollHeight-m.clientHeight>4;d(C)};return p(),window.addEventListener("resize",p),()=>{window.removeEventListener("resize",p)}},[f,s,l]);const w=()=>s?b.jsx("div",{className:"grid gap-4",children:Array.from({length:3}).map((p,m)=>b.jsx("div",{className:`${k$e} animate-pulse rounded-2xl border border-gray-200 bg-white dark:border-[#3b3c49] dark:bg-[#22232b]`},m))}):l?b.jsx("div",{className:"rounded-2xl border border-red-200 bg-red-50 px-4 py-6 text-sm text-red-700 dark:border-red-900 dark:bg-red-950/30 dark:text-red-200",children:l}):i.length===0?b.jsx("div",{className:"rounded-2xl border border-gray-200 bg-white px-4 py-6 text-sm text-gray-600 dark:border-[#3b3c49] dark:bg-[#22232b] dark:text-gray-300",children:"No agents are available yet. Configure adapters in your middleware settings to continue."}):f.length===0?b.jsx("div",{className:"rounded-2xl border border-gray-200 bg-white px-4 py-6 text-sm text-gray-600 dark:border-[#3b3c49] dark:bg-[#22232b] dark:text-gray-300",children:"No agents match your search."}):b.jsxs("div",{className:"relative",children:[b.jsx("div",{ref:u,className:"max-h-[75vh] lg:max-h-[70vh] overflow-y-auto pr-1 pt-3 pb-1",onScroll:()=>{const p=u.current;if(!p)return;const m=p.scrollHeight-p.scrollTop-p.clientHeight>4;d(m)},children:b.jsx("div",{className:"grid gap-3",children:f.map(p=>b.jsx(D$e,{adapter:p,onSelect:m=>e(m.name)},p.name))})}),g&&b.jsxs(b.Fragment,{children:[b.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-14 bg-gradient-to-b from-transparent to-white dark:to-[#1c1d23]"}),b.jsx("div",{className:"pointer-events-none absolute bottom-3 left-1/2 -translate-x-1/2 rounded-full bg-white/95 px-3 py-1 text-xs font-semibold text-gray-600 shadow-sm dark:bg-[#1c1d23]/95 dark:text-gray-200",children:"Scroll for more"})]})]});return b.jsxs("div",{className:`flex w-full flex-col gap-6 ${t}`,children:[(A||r||n)&&b.jsxs("div",{children:[A&&b.jsx("p",{className:"text-sm font-semibold uppercase tracking-wide text-blue-600 dark:text-blue-300",children:A}),r&&b.jsx("h2",{className:"mt-2 text-2xl font-bold text-gray-900 dark:text-white",children:r}),n&&b.jsx("p",{className:"mt-2 text-base text-gray-600 dark:text-gray-300",children:n})]}),b.jsxs("div",{className:"relative w-full",children:[b.jsx(q6,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),b.jsx("input",{type:"text",placeholder:"Search agents",value:B,disabled:s||!!l||i.length===0,onChange:p=>h(p.target.value),className:"w-full rounded-md border border-gray-300 bg-white py-2 pl-9 pr-3 text-sm text-gray-900 placeholder-gray-400 shadow-inner focus:border-gray-400 focus:outline-none disabled:cursor-not-allowed disabled:opacity-60 dark:border-[#3b3c49] dark:bg-[#1f2027] dark:text-white dark:shadow-none"})]}),w()]})}const U$e="rounded-t-[32px] border border-white/40 bg-white/95 px-4 pb-4 pt-[max(env(safe-area-inset-top),1rem)] shadow-[0_25px_60px_rgba(15,23,42,0.15)] backdrop-blur-xl dark:border-[#2f303d] dark:bg-[#1c1d23]/95 md:rounded-none md:border-0 md:bg-transparent md:px-0 md:pb-0 md:pt-0 md:shadow-none md:backdrop-blur-0 md:dark:bg-transparent md:dark:border-0",xV="-mx-4 mt-auto overflow-hidden rounded-t-[28px] border-t border-x border-white/40 bg-white/98 pb-[max(env(safe-area-inset-bottom),0.75rem)] shadow-[0_-12px_45px_rgba(15,23,42,0.2)] backdrop-blur-xl transition-all duration-200 dark:border-[#2f303d] dark:bg-[#1c1d23]/98 md:mx-0 md:mt-0 md:overflow-visible md:rounded-none md:border-0 md:bg-transparent md:pb-0 md:shadow-none md:backdrop-blur-0 md:dark:bg-transparent md:dark:border-0 [&>div]:rounded-t-[28px] md:[&>div]:rounded-none [&>div]:bg-transparent md:[&>div]:px-0",v$e="sticky top-0 z-10 -mx-4 px-4 pt-2 pb-4 bg-white/95 backdrop-blur-xl dark:bg-[#1c1d23]/95 border-b border-white/50 dark:border-white/10 md:static md:mx-0 md:px-0 md:pt-6 md:pb-6 md:bg-transparent md:backdrop-blur-0 md:border-gray-200 md:dark:border-[#4a4b54] md:dark:bg-transparent";function G$e({onOpenSettings:e,onOpenSidebar:t}){var we,q,be,ke;const{conversations:r,currentConversationId:n,createConversation:A,canCreateNewConversation:i,sendMessage:a,regenerateResponse:s,isLoading:o,configureApiSettings:l,error:c,clearError:u,createThread:g}=ct(),{settings:d}=em(),{theme:B,isDark:h}=$f(),f=B.mode==="dark"?"dark":B.mode==="light"?"light":"",w=h?"dark":"light",p=["message-markdown w-full min-w-0","prose prose-slate dark:prose-invert max-w-none",f].filter(Boolean).join(" "),[m,C]=y.useState(!1),[E,I]=y.useState(!1),Q=r.find(Be=>Be.id===n),N=lr(),k=Xae(),x=!Q||Q.messages.length===0,D=N&&x,[z,H]=y.useState(D),T=y.useRef(null),v=N&&x&&z,L=N&&x&&!z&&!!(Q!=null&&Q.adapterName),J="mx-auto w-full max-w-4xl",R=L?J:"w-full",O=i(),U=O?"Start a new conversation":"Finish your current conversation before starting a new one.",K=!!(Q!=null&&Q.adapterInfo&&!v),G=`${v$e} ${v?"border-transparent dark:border-transparent md:border-transparent md:dark:border-transparent":""}`.trim();y.useEffect(()=>{if(!N||!x){z&&H(!1),T.current=(Q==null?void 0:Q.id)||null;return}const Be=(Q==null?void 0:Q.id)||null;T.current!==Be&&(T.current=Be,H(!0))},[N,x,Q==null?void 0:Q.id,z]),y.useEffect(()=>{var Be,pe,xe;N&&me("[ChatInterface] Middleware mode state:",{hasConversation:!!Q,adapterName:Q==null?void 0:Q.adapterName,hasAdapterInfo:!!(Q!=null&&Q.adapterInfo),hasNotes:!!((Be=Q==null?void 0:Q.adapterInfo)!=null&&Be.notes),notes:((xe=(pe=Q==null?void 0:Q.adapterInfo)==null?void 0:pe.notes)==null?void 0:xe.substring(0,50))+"..."})},[N,Q]);const X=y.useRef(null);y.useEffect(()=>{(async()=>{var Le;const pe=Q==null?void 0:Q.adapterName;if(X.current===pe)return;const xe=!(Q!=null&&Q.adapterInfo)||(Q==null?void 0:Q.adapterInfo)&&Q.adapterInfo.notes===void 0;if(N&&pe&&xe){X.current=pe,me("[ChatInterface] Loading adapter info - adapterName:",pe,"reason:",Q!=null&&Q.adapterInfo?"notes undefined":"missing");try{const Fe=(Q==null?void 0:Q.apiUrl)||Hr();me("[ChatInterface] Calling configureApiSettings for:",pe),await l(Fe,void 0,void 0,pe),me("[ChatInterface] Adapter info loaded successfully")}catch{X.current=null}}else me("[ChatInterface] Skipping adapter info load:",{isMiddlewareEnabled:N,adapterName:pe,hasAdapterInfo:!!(Q!=null&&Q.adapterInfo),hasNotes:((Le=Q==null?void 0:Q.adapterInfo)==null?void 0:Le.notes)!==void 0,refValue:X.current})})()},[N,Q==null?void 0:Q.adapterName,Q==null?void 0:Q.adapterInfo,Q==null?void 0:Q.apiUrl,l]),y.useEffect(()=>{let Be=null;const pe=()=>{Be&&(Be(),Be=null)};if(d.voiceEnabled){if(gl.isAudioEnabled())return pe;const xe=()=>{pe();const Le=async()=>{pe(),await gl.enableAudio()||xe()};document.addEventListener("pointerdown",Le,{once:!0}),document.addEventListener("keydown",Le,{once:!0}),Be=()=>{document.removeEventListener("pointerdown",Le),document.removeEventListener("keydown",Le)}};return xe(),pe}return pe(),gl.disableAudio(),pe},[d.voiceEnabled]);const ie=(Be,pe,xe)=>{a(Be,pe,xe)},ae=async(Be,pe,xe)=>{await a(xe,void 0,Be)},le=()=>{try{A()}catch(Be){ft("Cannot create new conversation:",Be instanceof Error?Be.message:"Unknown error")}},ge=async Be=>{if(!(!N||!Be)){I(!0);try{const pe=(Q==null?void 0:Q.apiUrl)||Hr();await l(pe,void 0,void 0,Be),u()}catch{}finally{I(!1)}}},te=Be=>{H(!1),ge(Be)},he=async()=>{if(!(!Q||!Q.apiKey&&!Q.adapterName)){C(!0);try{const Be=await nn(),pe=Q.apiUrl||Hr(),xe=Q.apiKey,Le=Q.adapterName,Fe=new Be.ApiClient({apiUrl:pe,apiKey:xe||null,sessionId:null,adapterName:Le||null});if(typeof Fe.getAdapterInfo=="function"){const Ke=await Fe.getAdapterInfo();me("Adapter info refreshed:",Ke),ct.setState(st=>({conversations:st.conversations.map(Ot=>Ot.id===n?{...Ot,adapterInfo:Ke,updatedAt:new Date}:Ot)})),setTimeout(()=>{const st=ct.getState();localStorage.setItem("chat-state",JSON.stringify({conversations:st.conversations,currentConversationId:st.currentConversationId}))},0)}}catch{}finally{C(!1)}}};return b.jsx("div",{className:"flex-1 flex flex-col bg-gray-50 dark:bg-[#202123] overflow-hidden",children:b.jsx("div",{className:"flex h-full w-full flex-col px-3 sm:px-6 overflow-hidden",children:b.jsxs("div",{className:`mx-auto flex h-full w-full max-w-5xl flex-col overflow-hidden ${U$e}`,children:[c&&b.jsx("div",{className:"mt-6 rounded-md border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700 dark:border-red-600/40 dark:bg-red-900/30 dark:text-red-200",children:b.jsxs("div",{className:"flex items-start justify-between",children:[b.jsx("p",{children:c}),b.jsx("button",{onClick:u,className:"ml-4 rounded p-1 text-red-500 hover:bg-red-100 hover:text-red-700 dark:text-red-200 dark:hover:bg-red-800/40","aria-label":"Dismiss error",children:"×"})]})}),b.jsxs("div",{className:G,children:[t&&b.jsxs("div",{className:"mb-4 grid grid-cols-2 gap-3 md:hidden",children:[b.jsxs("button",{onClick:t,className:"inline-flex items-center justify-center gap-2 rounded-2xl border border-white/50 bg-white/80 px-4 py-3.5 text-sm font-semibold text-gray-800 shadow-sm active:scale-[0.97] transition-all duration-150 hover:bg-white dark:border-[#2f303d] dark:bg-[#232430] dark:text-[#ececf1]","aria-label":"Open conversations menu",children:[b.jsx(Tle,{className:"h-5 w-5"}),"Chats"]}),b.jsxs("button",{onClick:e,className:"inline-flex items-center justify-center gap-2 rounded-2xl border border-white/50 bg-[#11121a]/90 px-4 py-3.5 text-sm font-semibold text-white shadow-sm active:scale-[0.97] transition-all duration-150 hover:bg-[#0c0d14] dark:border-[#3b3c49] dark:bg-[#565869] dark:hover:bg-[#6b6f7a]","aria-label":"Open settings",children:[b.jsx(_6,{className:"h-5 w-5"}),"Settings"]})]}),b.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between",children:[b.jsx("div",{className:"min-w-0 flex-1",children:K&&b.jsxs("div",{className:"mb-4",children:[b.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-3",children:[((we=Q==null?void 0:Q.adapterInfo)==null?void 0:we.model)&&b.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-gray-200 bg-gray-100 px-2.5 py-1 text-xs font-semibold uppercase tracking-wider text-gray-500 dark:border-[#4a4b54] dark:bg-[#343541] dark:text-[#bfc2cd]",children:[b.jsx("span",{children:"Model"}),b.jsx("span",{className:"text-gray-800 normal-case dark:text-[#ececf1]",children:Q.adapterInfo.model})]}),b.jsxs("div",{className:"inline-flex items-center gap-2 rounded-md border border-gray-200 bg-gray-100 px-2.5 py-1 text-xs font-semibold uppercase tracking-wider text-gray-600 dark:border-[#4a4b54] dark:bg-[#343541] dark:text-[#bfc2cd]",children:[b.jsx("span",{children:"Agent"}),b.jsx("span",{className:"text-gray-800 normal-case dark:text-[#ececf1]",children:(Q==null?void 0:Q.adapterName)||((q=Q==null?void 0:Q.adapterInfo)==null?void 0:q.adapter_name)||"Configured Agent"})]}),b.jsxs("button",{onClick:he,disabled:m||!(Q!=null&&Q.apiKey)&&!(Q!=null&&Q.adapterName),className:"inline-flex items-center gap-1 rounded-full border border-gray-200 px-2.5 py-1 text-xs font-semibold text-gray-600 transition-colors hover:bg-gray-200 hover:text-gray-900 dark:border-[#4a4b54] dark:text-[#bfc2cd] dark:hover:bg-[#4a4b54] dark:hover:text-white disabled:opacity-50 disabled:cursor-not-allowed",title:"Refresh adapter info",children:[b.jsx(qle,{className:`h-4 w-4 ${m?"animate-spin":""}`}),b.jsx("span",{className:"hidden sm:inline",children:"Refresh"})]})]}),b.jsx("h1",{className:"text-2xl font-semibold text-[#353740] dark:text-[#ececf1] mb-2",children:(Q==null?void 0:Q.title)||"New Chat"}),Q&&b.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-500 dark:text-[#bfc2cd]",children:[b.jsx("span",{className:"font-medium",children:Q.messages.length}),b.jsxs("span",{children:["Updated ",Q.updatedAt.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]})]})}),!v&&b.jsx("div",{className:"flex items-start justify-end",children:b.jsxs("button",{onClick:le,disabled:!O,className:`inline-flex items-center justify-center gap-2 rounded-full border px-3.5 py-2 text-xs font-semibold uppercase tracking-wide transition-colors ${O?"border-[#343541] text-[#343541] hover:bg-[#f2f3f5] dark:border-[#565869] dark:text-[#ececf1] dark:hover:bg-[#2c2f36]":"cursor-not-allowed border-gray-200 text-gray-400 dark:border-[#3c3f4a] dark:text-[#6b6f7a]"}`,title:U,children:[b.jsx(Zle,{className:"h-3.5 w-3.5"}),"New Conversation"]})})]})]}),x?b.jsx("div",{className:"flex flex-1 flex-col min-h-0 pt-4 md:pt-6",children:b.jsxs("div",{className:"flex-1 flex flex-col justify-between md:justify-start md:flex-none",children:[b.jsx("div",{className:"w-full space-y-6",children:v?b.jsx(S$e,{onAdapterSelect:te,className:J}):L?b.jsxs("div",{className:`${J} rounded-3xl border border-gray-200/80 bg-white/95 p-6 shadow-sm dark:border-[#3b3c49] dark:bg-[#1c1d23]/90`,children:[b.jsxs("div",{className:"flex items-start justify-between pb-4",children:[b.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Agent overview"}),b.jsx("button",{type:"button",onClick:()=>H(!0),className:"text-sm font-semibold text-blue-600 hover:text-blue-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 dark:text-blue-300 dark:hover:text-blue-200",children:"Change Agent"})]}),b.jsx("div",{className:"rounded-2xl border border-gray-200 bg-white/70 p-4 dark:border-[#3b3c49] dark:bg-[#232430]/80",children:(be=Q==null?void 0:Q.adapterInfo)!=null&&be.notes?b.jsx(Sf,{content:Q.adapterInfo.notes,className:p,syntaxTheme:w}):E?b.jsx("p",{className:"text-sm text-gray-600 dark:text-[#bfc2cd]",children:"Configuring your agent… hang tight for just a moment."}):b.jsx("p",{className:"text-sm text-gray-600 dark:text-[#bfc2cd]",children:"Fetching agent overview… this only takes a moment."})})]}):b.jsx("div",{className:`${J} mb-2`,children:(ke=Q==null?void 0:Q.adapterInfo)!=null&&ke.notes?b.jsx("div",{className:"text-base text-gray-600 dark:text-[#bfc2cd] leading-relaxed",children:b.jsx(Sf,{content:Q.adapterInfo.notes,className:p,syntaxTheme:w})}):b.jsx("h2",{className:"text-xl md:text-2xl font-medium text-[#353740] dark:text-[#ececf1]",children:"How can I assist you today?"})})}),!v&&b.jsx("div",{className:xV,children:b.jsx("div",{className:R,children:b.jsx(bV,{onSend:ie,disabled:o||!Q||(N?!(Q!=null&&Q.adapterName):!(Q!=null&&Q.apiKey)),placeholder:k})})})]})}):b.jsxs("div",{className:"flex flex-1 flex-col",children:[b.jsx(q_e,{messages:Q.messages,onRegenerate:s,onStartThread:async(Be,pe)=>{try{await g(Be,pe)}catch{}},onSendThreadMessage:ae,sessionId:Q.sessionId,isLoading:o}),b.jsx("div",{className:xV,children:b.jsx("div",{className:"w-full",children:b.jsx(bV,{onSend:ie,disabled:o||!Q||(N?!Q.adapterName:!Q.apiKey)||N&&z,placeholder:k})})})]})]})})})}function DV({isOpen:e,onClose:t,onConfirm:r,title:n,message:A,confirmText:i="Confirm",cancelText:a="Cancel",type:s="danger",isLoading:o=!1}){if(!e)return null;const l=()=>{o||r()},u=(()=>{switch(s){case"danger":return{icon:"text-red-500",iconBg:"bg-red-100 dark:bg-red-900/20",confirmButton:"bg-red-600 hover:bg-red-700 focus:ring-red-500",border:"border-red-200 dark:border-red-800"};case"warning":return{icon:"text-amber-500",iconBg:"bg-amber-100 dark:bg-amber-900/20",confirmButton:"bg-amber-600 hover:bg-amber-700 focus:ring-amber-500",border:"border-amber-200 dark:border-amber-800"};default:return{icon:"text-blue-500",iconBg:"bg-blue-100 dark:bg-blue-900/20",confirmButton:"bg-blue-600 hover:bg-blue-700 focus:ring-blue-500",border:"border-blue-200 dark:border-blue-800"}}})();return b.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center p-4 z-50 animate-fadeIn",children:b.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-2xl shadow-2xl w-full max-w-md transform animate-fadeIn",children:[b.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-700",children:[b.jsxs("div",{className:"flex items-center gap-3",children:[b.jsx("div",{className:`w-10 h-10 rounded-full ${u.iconBg} flex items-center justify-center`,children:b.jsx(qk,{className:`w-5 h-5 ${u.icon}`})}),b.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:n})]}),b.jsx("button",{onClick:t,className:"p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors",children:b.jsx($c,{className:"w-5 h-5 text-gray-500 dark:text-gray-400"})})]}),b.jsx("div",{className:"p-6",children:b.jsx("p",{className:"text-gray-600 dark:text-gray-300 leading-relaxed",children:A})}),b.jsxs("div",{className:"flex items-center justify-end gap-3 p-6 border-t border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50 rounded-b-2xl",children:[b.jsx("button",{onClick:t,disabled:o,className:"px-4 py-2.5 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700 rounded-lg transition-colors font-medium disabled:opacity-50 disabled:cursor-not-allowed",children:a}),b.jsx("button",{onClick:l,disabled:o,className:`px-4 py-2.5 text-white rounded-lg transition-all font-medium shadow-sm hover:shadow-md transform hover:scale-105 active:scale-95 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-white dark:focus:ring-offset-gray-800 disabled:opacity-50 disabled:cursor-not-allowed disabled:transform-none ${u.confirmButton}`,children:o?b.jsxs("div",{className:"flex items-center gap-2",children:[b.jsx("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"}),"Clearing..."]}):i})]})]})})}const R$e=(e,t)=>{const[r,n]=y.useState({stars:0,forks:0,license:"Apache-2.0",description:"An adaptable, open-source context-aware inference engine designed for privacy, control, and independence from proprietary models.",isLoading:!0,error:null});return y.useEffect(()=>{(async()=>{var i;try{const a=await fetch(`https://api.github.com/repos/${e}/${t}`);if(!a.ok)throw new Error(`GitHub API error: ${a.status}`);const s=await a.json();n({stars:s.stargazers_count||0,forks:s.forks_count||0,license:((i=s.license)==null?void 0:i.name)||"Apache-2.0",description:s.description||"An adaptable, open-source context-aware inference engine designed for privacy, control, and independence from proprietary models.",isLoading:!1,error:null})}catch(a){console.warn("Failed to fetch GitHub stats:",a),n({stars:104,forks:19,license:"Apache-2.0",description:"An adaptable, open-source context-aware inference engine designed for privacy, control, and independence from proprietary models.",isLoading:!1,error:a instanceof Error?a.message:"Failed to fetch stats"})}})()},[e,t]),r};function j$e({selectedAdapter:e,onAdapterChange:t,disabled:r,defaultAdapterName:n,showDescriptions:A=!1,variant:i="sidebar",label:a,showLabel:s}){const[o,l]=y.useState([]),[c,u]=y.useState(!0),[g,d]=y.useState(null),[B,h]=y.useState(!1);y.useEffect(()=>{let D=!0;async function z(){try{u(!0),d(null);const H=await Kv();D&&l(H)}catch{D&&d("Failed to load adapters. Please check your connection.")}finally{D&&u(!1)}}return z(),()=>{D=!1}},[]);const f=y.useRef(t),w=y.useRef(!1);y.useEffect(()=>{f.current=t},[t]),y.useEffect(()=>{if(e){w.current=!0;return}!n||w.current||o.length===0||!o.some(z=>z.name===n)||(w.current=!0,f.current(n))},[o,e,n]);const p=o.find(D=>D.name===e),m=typeof s=="boolean"?s:i==="prominent",C=a||(i==="prominent"?"Select an agent":"Adapter"),E=y.useMemo(()=>i==="prominent"?"relative w-full text-left":"relative w-full",[i]),I=y.useMemo(()=>{const D="w-full rounded-md border bg-white px-4 py-3 text-left text-sm text-[#353740] focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 dark:bg-[#343541] dark:text-[#ececf1]";return i==="prominent"?[D,"border-gray-300 shadow-sm transition-all duration-200 focus-visible:ring-blue-500 dark:border-[#4a4b54] dark:focus-visible:ring-blue-400"].join(" "):["w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-left text-sm text-[#353740] focus:border-gray-400 focus:outline-none dark:border-[#4a4b54] dark:bg-[#343541] dark:text-[#ececf1] dark:focus:border-[#6b6f7a]"].join(" ")},[i]),Q=y.useMemo(()=>i==="prominent"?"absolute z-20 mt-2 w-full rounded-xl border border-gray-200 bg-white shadow-xl ring-1 ring-black/5 dark:border-[#4a4b54] dark:bg-[#1f2027]":"absolute z-20 mt-1 w-full rounded-md border border-gray-200 bg-white shadow-lg ring-1 ring-black/5 dark:border-[#4a4b54] dark:bg-[#1f2027]",[i]),x=m?`mb-2 block text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-[#bfc2cd] ${i==="prominent"?"!text-sm !font-semibold !text-gray-700 dark:!text-white":""}`:"sr-only";return b.jsxs("div",{className:E,children:[b.jsx("label",{className:x,children:C}),b.jsxs("div",{className:"relative",children:[b.jsx("button",{type:"button",onClick:()=>!r&&h(!B),disabled:r||c||o.length===0,className:`${I} disabled:opacity-50 disabled:cursor-not-allowed`,"aria-label":C,children:b.jsxs("div",{className:"flex items-center justify-between gap-2",children:[b.jsxs("div",{className:"flex flex-col min-w-0",children:[b.jsx("span",{className:`truncate font-medium ${p?"text-[#11121a] dark:text-white":"text-gray-500 dark:text-gray-400"}`,children:c?"Loading agents…":g?"Error loading agents":p?p.name:o.length===0?"No agents available":"Select an agent"}),i==="prominent"&&(p==null?void 0:p.description)&&b.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:p.description})]}),b.jsx(X6,{className:`h-4 w-4 flex-shrink-0 transition-transform text-gray-400 dark:text-gray-300 ${B?"rotate-180":""}`})]})}),B&&!r&&o.length>0&&b.jsxs(b.Fragment,{children:[b.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>h(!1)}),b.jsx("div",{className:Q,children:b.jsx("div",{className:"max-h-72 overflow-auto py-2",children:o.map(D=>{const z=D.name===e;return b.jsx("button",{type:"button",onClick:()=>{z||t(D.name),h(!1)},className:`w-full px-4 py-3 text-left text-sm transition-colors ${z?"bg-blue-50 text-blue-700 dark:bg-blue-900/30 dark:text-blue-200":"text-[#353740] hover:bg-gray-50 dark:text-[#ececf1] dark:hover:bg-[#2a2d35]"}`,children:b.jsxs("div",{className:"flex flex-col gap-1",children:[b.jsx("span",{className:"font-medium truncate",children:D.name}),A&&D.description&&b.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",style:{display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:D.description})]})},D.name)})})})]})]}),g&&b.jsx("p",{className:"mt-1 text-xs text-red-600 dark:text-red-400",children:g})]})}const Wp=100,z$e={small:{cardText:"text-xs",cardPadding:"px-2.5 py-2",cardGap:"gap-0",titleText:"text-sm",metaText:"text-[10px]",metaGap:"gap-1",badgePadding:"px-1.5 py-0.5",badgeText:"text-[10px]",badgeIcon:"h-3 w-3",actionButton:"p-1.5",actionIcon:"h-3.5 w-3.5"},medium:{cardText:"text-sm",cardPadding:"px-3 py-3",cardGap:"gap-0",titleText:"text-sm",metaText:"text-[11px]",metaGap:"gap-1.5",badgePadding:"px-2 py-0.5",badgeText:"text-[11px]",badgeIcon:"h-3.5 w-3.5",actionButton:"p-2",actionIcon:"h-4 w-4"},large:{cardText:"text-base",cardPadding:"px-4 py-4",cardGap:"gap-0",titleText:"text-base",metaText:"text-sm",metaGap:"gap-2",badgePadding:"px-2.5 py-1",badgeText:"text-sm",badgeIcon:"h-4 w-4",actionButton:"p-2",actionIcon:"h-4 w-4"}};function kV({onRequestClose:e,onOpenSettings:t}){const{conversations:r,currentConversationId:n,selectConversation:A,deleteConversation:i,deleteAllConversations:a,updateConversationTitle:s,getConversationCount:o,configureApiSettings:l,clearError:c}=ct(),u=r.find(Ce=>Ce.id===n),[g,d]=y.useState(""),[B,h]=y.useState(null),[f,w]=y.useState(""),[p,m]=y.useState({isOpen:!1,conversationId:"",conversationTitle:"",isDeleting:!1}),[C,E]=y.useState({isOpen:!1,isDeleting:!1}),[I,Q]=y.useState(!1),[N,k]=y.useState(()=>Hr()),[x,D]=y.useState(()=>wo()),[z,H]=y.useState(null),[T,v]=y.useState(!1),[L,J]=y.useState(!1),[R,O]=y.useState(null),U=lr(),K=U?Pv():null,Ae=!u||u.messages.length===0,{theme:G}=$f(),X=z$e[G.fontSize??"medium"];y.useEffect(()=>{if(!U){H(null);return}u!=null&&u.adapterName?H(u.adapterName):H(null)},[U,u==null?void 0:u.adapterName]),y.useEffect(()=>{O(null)},[n]);const ie=r.filter(Ce=>Ce.title.toLowerCase().includes(g.toLowerCase())||Ce.messages.some(_=>_.content.toLowerCase().includes(g.toLowerCase()))),ae=o(),le=ae===1?"conversation":"conversations",ge=J_e(),te=R$e(IV(),yV()),he=()=>{const Ce=Hr(),_=u==null?void 0:u.apiUrl,se=_&&_!==Ce?_:Ce,Qe=(u==null?void 0:u.apiKey)||wo();k(se),D(Qe),O(null),v(!1),Q(!0)},we=async Ce=>{if(!(!U||!Ae||!Ce)){H(Ce),O(null),J(!0);try{const _=(u==null?void 0:u.apiUrl)||Hr();await l(_,void 0,void 0,Ce),c(),Q(!1)}catch(_){const se=_ instanceof Error?_.message:"Failed to configure adapter";O(se)}finally{J(!1)}}},q=async Ce=>{if(Ce&&Ce.preventDefault(),!U&&N&&x){J(!0),O(null);try{await l(N,x),c(),O(null),v(!1),Q(!1)}catch(_){const se=_ instanceof Error?_.message:"Failed to configure API settings";O(se)}finally{J(!1)}}},be=async Ce=>{try{await A(Ce),e==null||e()}catch{}},ke=(Ce,_)=>{Ce.stopPropagation(),m({isOpen:!0,conversationId:_.id,conversationTitle:_.title,isDeleting:!1})},Be=async()=>{m(Ce=>({...Ce,isDeleting:!0}));try{await i(p.conversationId),m({isOpen:!1,conversationId:"",conversationTitle:"",isDeleting:!1})}catch{m({isOpen:!1,conversationId:"",conversationTitle:"",isDeleting:!1})}},pe=()=>{m({isOpen:!1,conversationId:"",conversationTitle:"",isDeleting:!1})},xe=(Ce,_)=>{Ce.stopPropagation(),h(_.id),w(_.title.slice(0,Wp))},Le=Ce=>{const _=f.slice(0,Wp).trim();_&&s(Ce,_),h(null),w("")},Fe=()=>{h(null),w("")},Ke=()=>{E({isOpen:!0,isDeleting:!1})},st=async()=>{E(Ce=>({...Ce,isDeleting:!0}));try{await a(),E({isOpen:!1,isDeleting:!1})}catch{E({isOpen:!1,isDeleting:!1})}},Ot=()=>{E({isOpen:!1,isDeleting:!1})},en=Ce=>{const _=Ce.toLocaleDateString([],{year:"numeric",month:"short",day:"numeric"}),se=Ce.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});return`${_} · ${se}`},vr=Ce=>{var _;return Ce.adapterName&&Ce.adapterName.trim().length>0?Ce.adapterName:(_=Ce.adapterInfo)!=null&&_.adapter_name&&Ce.adapterInfo.adapter_name.trim().length>0?Ce.adapterInfo.adapter_name:null};return b.jsxs(b.Fragment,{children:[I&&b.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 px-4",children:b.jsxs("form",{onSubmit:q,className:"w-full max-w-md rounded-lg border border-gray-200 bg-white p-6 shadow-lg dark:border-[#444654] dark:bg-[#202123]",children:[b.jsx("h2",{className:"mb-4 text-lg font-medium text-[#353740] dark:text-[#ececf1]",children:U?"Select an Agent":"Configure API Settings"}),b.jsxs("div",{className:"space-y-5",children:[!U&&b.jsxs("div",{children:[b.jsx("label",{className:"mb-2 block text-sm font-medium text-[#353740] dark:text-[#d1d5db]",children:"API URL"}),b.jsx("input",{type:"text",value:N,onChange:Ce=>k(Ce.target.value),className:"w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-sm text-[#353740] focus:border-gray-400 focus:outline-none dark:border-[#4a4b54] dark:bg-[#343541] dark:text-[#ececf1]",placeholder:"https://api.example.com"})]}),U?b.jsx(j$e,{selectedAdapter:z||(u==null?void 0:u.adapterName)||null,onAdapterChange:we,disabled:L,defaultAdapterName:K,variant:"prominent",showDescriptions:!0,showLabel:!1}):b.jsxs("div",{children:[b.jsx("label",{className:"mb-2 block text-sm font-medium text-[#353740] dark:text-[#d1d5db]",children:"API Key"}),b.jsxs("div",{className:"relative",children:[b.jsx("input",{type:T?"text":"password",value:x,onChange:Ce=>{D(Ce.target.value),O(null)},className:"w-full rounded-md border border-gray-300 bg-white px-3 py-2 pr-10 text-sm text-[#353740] focus:border-gray-400 focus:outline-none dark:border-[#4a4b54] dark:bg-[#343541] dark:text-[#ececf1]",placeholder:"your-api-key",disabled:L}),b.jsx("button",{type:"button",onClick:()=>v(!T),className:"absolute right-2 top-1/2 -translate-y-1/2 rounded p-1 text-gray-500 hover:text-gray-700 dark:text-[#d1d5db] dark:hover:text-white","aria-label":T?"Hide API key":"Show API key",disabled:L,children:T?b.jsx(Rle,{className:"h-4 w-4"}):b.jsx(jle,{className:"h-4 w-4"})})]})]}),R&&b.jsx("div",{className:"rounded-md border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-600/40 dark:bg-red-900/30 dark:text-red-200",children:R}),b.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[b.jsx("button",{type:"button",onClick:()=>{const Ce=(u==null?void 0:u.apiUrl)||Hr(),_=(u==null?void 0:u.apiKey)||wo();k(Ce),D(_),O(null),v(!1),Q(!1)},className:"rounded-md border border-transparent px-4 py-2 text-sm text-gray-600 hover:border-gray-300 hover:text-gray-900 disabled:cursor-not-allowed disabled:opacity-50 dark:text-[#d1d5db] dark:hover:text-white",disabled:L,children:"Cancel"}),!U&&b.jsx("button",{type:"submit",disabled:L||!N||!x,className:"rounded-md bg-[#343541] px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-[#282b32] disabled:cursor-not-allowed disabled:opacity-50 dark:bg-[#565869] dark:hover:bg-[#6b6f7a]",children:L?"Validating...":"Update"})]})]})]})}),b.jsxs("div",{className:"flex h-full w-full md:w-72 flex-col border-r border-b border-gray-200 bg-gradient-to-b from-white via-gray-50 to-gray-100 dark:border-[#4a4b54] dark:bg-[#202123] dark:bg-none",children:[b.jsxs("div",{className:"bg-white/95 p-4 shadow-sm dark:border-[#4a4b54] dark:bg-[#202123] dark:shadow-none",children:[b.jsxs("div",{className:"space-y-3 pb-3",children:[b.jsxs("div",{className:"flex items-center justify-between text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-[#bfc2cd]",children:[b.jsx("span",{children:"Version"}),b.jsxs("span",{className:"text-gray-900 dark:text-white",children:["v",$ae]})]}),b.jsxs("button",{onClick:t,disabled:!t,className:"flex w-full items-center justify-center gap-2 rounded-md border border-gray-300 px-3 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50 hover:border-gray-400 disabled:cursor-not-allowed disabled:opacity-50 dark:border-[#4a4b54] dark:text-[#ececf1] dark:hover:bg-[#3c3f4a] dark:hover:border-[#6b6f7a] dark:disabled:hover:bg-transparent dark:disabled:hover:border-[#4a4b54]",children:[b.jsx(_6,{className:"h-4 w-4"}),"Settings"]}),r.length>0&&r.some(Ce=>Ce.messages.length>0)&&b.jsxs("button",{onClick:Ke,className:"flex w-full items-center justify-center gap-2 rounded-md border border-red-300 px-3 py-2 text-sm font-medium text-red-600 hover:bg-red-50 hover:border-red-400 dark:border-red-600/40 dark:text-red-400 dark:hover:bg-red-900/20 dark:hover:border-red-500/60 transition-colors",title:"Delete all conversations",children:[b.jsx(rce,{className:"h-4 w-4"}),"Delete Conversations"]})]}),b.jsxs("div",{className:"mt-4 space-y-3",children:[!U&&b.jsx("button",{onClick:he,disabled:!Ae,className:"flex w-full items-center justify-center gap-2 rounded-md border border-gray-300 px-3 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50 hover:border-gray-400 disabled:cursor-not-allowed disabled:opacity-50 dark:border-[#4a4b54] dark:text-[#ececf1] dark:hover:bg-[#3c3f4a] dark:hover:border-[#6b6f7a] dark:disabled:hover:bg-transparent dark:disabled:hover:border-[#4a4b54]",children:"Configure API"}),R&&!I&&b.jsx("p",{className:"text-xs text-red-600 dark:text-red-400",children:R})]}),b.jsx("div",{className:"border-t border-gray-200 pt-4 mt-4 dark:border-[#4a4b54]",children:b.jsxs("div",{className:"relative flex items-center",children:[b.jsx(q6,{className:"pointer-events-none absolute left-3 h-4 w-4 text-gray-400"}),b.jsx("input",{type:"text",placeholder:"Search Conversations",value:g,onChange:Ce=>d(Ce.target.value),className:"w-full rounded-md border border-gray-300 bg-white py-2 pl-9 pr-3 text-sm text-[#353740] placeholder-gray-400 shadow-inner focus:border-gray-400 focus:outline-none dark:border-[#4a4b54] dark:bg-[#343541] dark:text-[#ececf1] dark:shadow-none"})]})})]}),b.jsx("div",{className:"flex-1 overflow-y-auto px-3 py-3 dark:bg-[#202123] dark:bg-none",children:ie.length===0?b.jsxs("div",{className:"rounded-xl border border-dashed border-gray-300 bg-white/90 p-6 text-center text-sm text-gray-500 shadow-sm dark:border-[#4a4b54] dark:bg-[#252830] dark:text-[#bfc2cd] dark:shadow-none",children:[b.jsx(q0,{className:"mx-auto mb-3 h-6 w-6 text-gray-400 dark:text-[#6b6f7a]"}),b.jsx("p",{children:g?"No conversations found":"No conversations yet"})]}):b.jsx("div",{className:"space-y-2",children:ie.map(Ce=>{const _=vr(Ce);return b.jsx("div",{onClick:()=>be(Ce.id),className:`group flex cursor-pointer items-start rounded-xl border text-left transition shadow-sm ${X.cardGap} ${X.cardPadding} ${X.cardText} dark:shadow-none ${n===Ce.id?"border-[#343541] bg-white dark:border-[#6b6f7a] dark:bg-[#2c2f36]":"border-gray-100 bg-white hover:border-gray-300 hover:bg-gray-50 dark:border-transparent dark:bg-[#252830] dark:hover:border-[#4a4b54] dark:hover:bg-[#2f323c]"}`,children:B===Ce.id?b.jsx("input",{type:"text",value:f,onChange:se=>w(se.target.value.slice(0,Wp)),onKeyDown:se=>{se.key==="Enter"&&Le(Ce.id),se.key==="Escape"&&Fe()},onBlur:()=>Le(Ce.id),maxLength:Wp,className:`flex-1 border-none bg-transparent text-[#353740] focus:outline-none dark:text-[#ececf1] ${X.titleText}`,autoFocus:!0}):b.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[b.jsxs("div",{className:`flex items-center gap-2 ${X.cardText}`,children:[b.jsx("h3",{className:`flex-1 truncate font-semibold ${X.titleText} ${n===Ce.id?"text-[#1f2937] dark:text-white":"text-gray-700 dark:text-[#d4d7e2]"}`,children:Ce.title}),b.jsxs("div",{className:"flex items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100",children:[b.jsx("button",{onClick:se=>xe(se,Ce),className:`rounded-full text-gray-500 hover:bg-gray-200 hover:text-[#353740] dark:text-[#bfc2cd] dark:hover:bg-[#3c3f4a] ${X.actionButton}`,title:"Rename conversation",children:b.jsx(Vle,{className:X.actionIcon})}),b.jsx("button",{onClick:se=>ke(se,Ce),className:`rounded-full text-red-500 hover:bg-red-50 dark:text-red-300 dark:hover:bg-red-900/30 ${X.actionButton}`,title:"Delete conversation",children:b.jsx($6,{className:X.actionIcon})})]})]}),b.jsxs("div",{className:`mt-1 flex items-center overflow-hidden pr-1 text-gray-500 dark:text-[#a6acc5] ${X.metaGap} ${X.metaText}`,children:[b.jsx("span",{className:"min-w-0 flex-1 truncate leading-none",children:en(Ce.updatedAt)}),b.jsxs("span",{className:`inline-flex shrink-0 items-center gap-1 rounded-full bg-white/80 font-medium text-gray-600 shadow-sm dark:bg-white/10 dark:text-[#e5e7f4] leading-none ${X.badgePadding} ${X.badgeText}`,children:[b.jsx(q0,{className:X.badgeIcon}),Ce.messages.length]}),Ce.attachedFiles&&Ce.attachedFiles.length>0&&b.jsxs("span",{className:`inline-flex shrink-0 items-center gap-1 rounded-full bg-white/80 font-medium text-gray-600 shadow-sm dark:bg-white/10 dark:text-[#e5e7f4] leading-none ${X.badgePadding} ${X.badgeText}`,children:[b.jsx(Z6,{className:X.badgeIcon}),Ce.attachedFiles.length]})]}),_&&b.jsxs("div",{className:"flex items-center gap-2 text-[11px] uppercase tracking-wide text-gray-500 dark:text-[#a6acc5]",children:[b.jsx("span",{className:"inline-flex items-center rounded-full bg-blue-50 px-2 py-0.5 text-[10px] font-semibold text-blue-700 dark:bg-blue-900/30 dark:text-blue-200",children:"Agent"}),b.jsx("span",{className:"min-w-0 flex-1 truncate text-gray-600 dark:text-[#d4d7e2]",children:_})]})]})},Ce.id)})})}),ge&&b.jsx("div",{className:"border-t border-gray-200 p-4 dark:border-[#4a4b54]",children:b.jsxs("div",{className:"text-center",children:[b.jsx("div",{className:"flex items-center justify-center mb-3",children:b.jsx("span",{className:"text-sm font-medium text-gray-900 dark:text-[#ececf1]",children:"Powered by ORBIT"})}),te.isLoading?b.jsxs("div",{className:"flex items-center justify-center gap-2 text-xs text-gray-500 dark:text-[#bfc2cd] mb-3",children:[b.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-gray-400"}),b.jsx("span",{children:"Loading stats..."})]}):te.error?b.jsx("div",{className:"flex items-center justify-center gap-2 text-xs text-red-500 dark:text-red-400 mb-3",children:b.jsx("span",{children:"⚠️ Failed to load stats"})}):b.jsxs("div",{className:"flex items-center justify-center gap-4 text-xs text-gray-500 dark:text-[#bfc2cd] mb-3",children:[b.jsxs("div",{className:"flex items-center gap-1",children:[b.jsx("svg",{className:"w-4 h-4 text-yellow-500",fill:"currentColor",viewBox:"0 0 24 24",children:b.jsx("path",{d:"M12 17.27L18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z"})}),b.jsxs("span",{children:[te.stars.toLocaleString()," stars"]})]}),b.jsxs("div",{className:"flex items-center gap-1",children:[b.jsx("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 16 16",children:b.jsx("path",{d:"M5 3.25a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm0 2.122a2.25 2.25 0 10-1.5 0v.878A2.25 2.25 0 005.75 8.5h1.5v2.128a2.251 2.251 0 101.5 0V8.5h1.5a2.25 2.25 0 002.25-2.25v-.878a2.25 2.25 0 10-1.5 0v.878a.75.75 0 01-.75.75H4.5A.75.75 0 013 6.25v-.878zm3.75 7.378a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm3-8.75a.75.75 0 100-1.5.75.75 0 000 1.5z"})}),b.jsxs("span",{children:[te.forks.toLocaleString()," forks"]})]})]}),b.jsxs("a",{href:`https://github.com/${IV()}/${yV()}`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300 transition-colors",children:[b.jsx("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 24 24",children:b.jsx("path",{d:"M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"})}),"View on GitHub"]})]})})]}),b.jsx(DV,{isOpen:p.isOpen,onClose:pe,onConfirm:Be,title:"Delete Conversation",message:`Are you sure you want to delete "${p.conversationTitle}"? This will clear the conversation history.`,confirmText:"Delete",cancelText:"Cancel",type:"danger",isLoading:p.isDeleting}),b.jsx(DV,{isOpen:C.isOpen,onClose:Ot,onConfirm:st,title:"Clear All Conversations",message:`Are you sure you want to delete all ${ae} ${le}? This will clear all conversation history.`,confirmText:"Clear All",cancelText:"Cancel",type:"danger",isLoading:C.isDeleting})]})}function T$e({isOpen:e,onClose:t}){const{theme:r,updateTheme:n}=$f(),{settings:A,updateSettings:i}=em(),[a,s]=y.useState(null),[o,l]=y.useState(!1),[c,u]=y.useState(""),[g,d]=y.useState(!1);if(y.useEffect(()=>{e&&ese().then(s)},[e]),!e)return null;const B=I=>{n({mode:I})},h=I=>{n({fontSize:I})},f=()=>{n({highContrast:!r.highContrast})},w=()=>{i({soundEnabled:!A.soundEnabled})},p=()=>{u(""),d(!1),l(!0)},m=()=>{l(!1),u(""),d(!1)},C=()=>{m(),localStorage.clear(),window.location.reload()},E=g&&c.trim().toLowerCase()==="reset";return b.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50",children:b.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-2xl shadow-2xl w-full max-w-md max-h-[90vh] flex flex-col overflow-hidden relative",children:[b.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-600",children:[b.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-gray-100",children:"Settings"}),b.jsx("button",{onClick:t,className:"p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors",children:b.jsx($c,{className:"w-5 h-5 text-gray-500 dark:text-gray-400"})})]}),b.jsxs("div",{className:"flex-1 min-h-0 p-6 space-y-6 overflow-y-auto",children:[b.jsxs("div",{className:"space-y-4",children:[b.jsxs("h3",{className:"text-lg font-medium text-gray-900 dark:text-gray-100 flex items-center gap-2",children:[b.jsx(Ple,{className:"w-5 h-5"}),"Appearance"]}),b.jsxs("div",{className:"space-y-2",children:[b.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Theme"}),b.jsx("div",{className:"grid grid-cols-3 gap-2",children:[{value:"light",label:"Light",icon:$le},{value:"dark",label:"Dark",icon:Ole},{value:"system",label:"System",icon:Jle}].map(({value:I,label:Q,icon:N})=>b.jsxs("button",{onClick:()=>B(I),className:`flex flex-col items-center gap-2 p-3 rounded-lg border-2 transition-all duration-200 ${r.mode===I?"border-blue-500 bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300":"border-gray-200 dark:border-gray-600 hover:border-gray-300 dark:hover:border-gray-500 text-gray-700 dark:text-gray-300"}`,children:[b.jsx(N,{className:"w-5 h-5"}),b.jsx("span",{className:"text-sm font-medium",children:Q})]},I))})]}),b.jsxs("div",{className:"flex items-center justify-between",children:[b.jsxs("div",{children:[b.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"High Contrast"}),b.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Improve readability with enhanced contrast"})]}),b.jsx("button",{onClick:f,className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${r.highContrast?"bg-blue-600":"bg-gray-200 dark:bg-gray-600"}`,children:b.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${r.highContrast?"translate-x-6":"translate-x-1"}`})})]}),b.jsxs("div",{className:"space-y-2",children:[b.jsxs("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 flex items-center gap-2",children:[b.jsx(nce,{className:"w-4 h-4"}),"Font Size"]}),b.jsx("div",{className:"grid grid-cols-3 gap-2",children:[{value:"small",label:"Small"},{value:"medium",label:"Medium"},{value:"large",label:"Large"}].map(({value:I,label:Q})=>b.jsx("button",{onClick:()=>h(I),className:`p-2 rounded-lg border-2 transition-colors text-center ${r.fontSize===I?"border-blue-500 bg-blue-50 dark:bg-blue-900/20":"border-gray-200 dark:border-gray-600 hover:border-gray-300 dark:hover:border-gray-500"}`,children:b.jsx("span",{className:`font-medium ${I==="small"?"text-sm":I==="large"?"text-lg":"text-base"}`,children:Q})},I))})]})]}),b.jsxs("div",{className:"space-y-4",children:[b.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-gray-100",children:"Chat Preferences"}),b.jsxs("div",{className:"flex items-center justify-between",children:[b.jsxs("div",{className:"flex items-center gap-2",children:[b.jsx(_0,{className:"w-4 h-4 text-gray-600 dark:text-gray-400"}),b.jsxs("div",{children:[b.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Sound Effects"}),b.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Play sounds for notifications and events"})]})]}),b.jsx("button",{onClick:w,className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${A.soundEnabled?"bg-blue-600":"bg-gray-200 dark:bg-gray-600"}`,children:b.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${A.soundEnabled?"translate-x-6":"translate-x-1"}`})})]})]}),b.jsxs("div",{className:"space-y-4 pt-4 border-t border-gray-200 dark:border-gray-600",children:[b.jsxs("h3",{className:"text-lg font-medium text-gray-900 dark:text-gray-100 flex items-center gap-2",children:[b.jsx($6,{className:"w-5 h-5"}),"Data Management"]}),b.jsxs("div",{className:"space-y-3",children:[b.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Clear all application data including conversations, and personalized settings."}),b.jsx("button",{onClick:p,className:"w-full px-4 py-2 text-sm font-medium text-red-600 dark:text-red-400 border border-red-300 dark:border-red-700 rounded-lg hover:bg-red-50 dark:hover:bg-red-900/20 transition-colors",children:"Reset Application"})]})]}),b.jsxs("div",{className:"space-y-2 pt-4 border-t border-gray-200 dark:border-gray-600",children:[b.jsxs("h3",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 flex items-center gap-2",children:[b.jsx(Wle,{className:"w-4 h-4"}),"About"]}),b.jsxs("div",{className:"space-y-1",children:[b.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:["AI Chat Application v",(a==null?void 0:a.appVersion)||"1.0.0"]}),b.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:["API Package: @schmitech/chatbot-api v",(a==null?void 0:a.apiVersion)||"^0.5.3",(a==null?void 0:a.isLocalApi)&&b.jsx("span",{className:"ml-1 px-1.5 py-0.5 bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300 rounded text-xs font-medium",children:"Local"})]}),b.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Built with React, TypeScript, and Tailwind CSS"})]})]})]}),o&&b.jsx("div",{className:"absolute inset-0 bg-black/70 flex items-center justify-center p-4 z-50",children:b.jsxs("div",{className:"w-full max-w-sm rounded-2xl bg-white dark:bg-gray-900 border border-red-100 dark:border-red-800 shadow-2xl p-6 space-y-4",children:[b.jsxs("div",{className:"flex items-start gap-3",children:[b.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-red-100 dark:bg-red-900/40",children:b.jsx(qk,{className:"w-5 h-5 text-red-600 dark:text-red-400"})}),b.jsxs("div",{children:[b.jsx("p",{className:"text-base font-semibold text-gray-900 dark:text-gray-100",children:"Reset application data?"}),b.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:["This removes everything stored on this device. Type ",b.jsx("span",{className:"font-semibold text-gray-900 dark:text-gray-100",children:"RESET"})," to continue."]})]})]}),b.jsxs("div",{className:"space-y-2",children:[b.jsx("label",{className:"text-xs font-medium text-gray-700 dark:text-gray-300",children:"Confirmation text"}),b.jsx("input",{value:c,onChange:I=>u(I.target.value.toUpperCase()),placeholder:"RESET",className:"w-full rounded-lg border border-gray-300 dark:border-gray-600 bg-transparent px-3 py-2 text-sm uppercase tracking-widest focus:outline-none focus:ring-2 focus:ring-red-400 dark:text-gray-100"})]}),b.jsxs("label",{className:"flex items-start gap-2 text-xs text-gray-600 dark:text-gray-400",children:[b.jsx("input",{type:"checkbox",checked:g,onChange:I=>d(I.target.checked),className:"mt-0.5 h-4 w-4 rounded border-gray-300 dark:border-gray-500 text-red-600 focus:ring-red-500"}),b.jsx("span",{children:"I understand this action is permanent and will reload the app."})]}),b.jsxs("div",{className:"flex gap-2 pt-2",children:[b.jsx("button",{onClick:m,className:"flex-1 px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-300 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors",children:"Cancel"}),b.jsx("button",{onClick:C,disabled:!E,className:`flex-1 px-4 py-2 text-sm font-semibold rounded-lg transition-colors ${E?"bg-red-600 text-white hover:bg-red-700 dark:bg-red-700 dark:hover:bg-red-600":"bg-red-200 text-red-600/60 dark:bg-red-900/20 dark:text-red-400/60 cursor-not-allowed"}`,children:"Reset"})]})]})})]})})}function L$e({message:e}){return b.jsx("div",{className:"min-h-screen bg-slate-950 text-white flex items-center justify-center px-4 py-12",children:b.jsxs("div",{className:"max-w-lg w-full text-center space-y-6",children:[b.jsx("div",{className:"flex justify-center",children:b.jsx("div",{className:"bg-white/10 rounded-full p-4",children:b.jsx(qk,{className:"h-10 w-10 text-amber-300","aria-hidden":"true"})})}),b.jsx("div",{className:"space-y-2",children:b.jsx("p",{className:"text-2xl font-semibold tracking-tight",children:"Temporarily Unavailable"})}),b.jsx("p",{className:"text-sm text-white/60",children:e})]})})}function H$e(){const[e,t]=y.useState(!1),[r,n]=y.useState(!1),A=O_e();return A?b.jsx(AR,{children:b.jsx(L$e,{message:A})}):b.jsx(AR,{children:b.jsx(xle,{children:b.jsxs("div",{className:"min-h-screen flex flex-col md:flex-row bg-white dark:bg-[#212121] text-slate-900 dark:text-slate-100",children:[b.jsx("div",{className:"hidden md:flex md:min-h-screen",children:b.jsx(kV,{onOpenSettings:()=>t(!0)})}),b.jsx("div",{className:"flex-1 flex justify-center w-full",children:b.jsx(G$e,{onOpenSettings:()=>t(!0),onOpenSidebar:()=>n(!0)})}),b.jsx(T$e,{isOpen:e,onClose:()=>t(!1)}),r&&b.jsxs("div",{className:"fixed inset-0 z-50 flex md:hidden",children:[b.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>n(!1),"aria-hidden":"true"}),b.jsxs("div",{className:"relative z-10 h-full w-[min(18rem,85vw)] animate-slideIn",children:[b.jsx(kV,{onRequestClose:()=>n(!1),onOpenSettings:()=>{t(!0),n(!1)}}),b.jsx("button",{onClick:()=>n(!1),className:"absolute -right-3 top-[max(env(safe-area-inset-top),0.75rem)] rounded-full bg-white/95 p-2.5 text-gray-600 shadow-lg active:scale-95 transition-transform dark:bg-[#2d2f39] dark:text-[#ececf1]","aria-label":"Close menu",children:b.jsx($c,{className:"h-5 w-5"})})]})]})]})})})}document.title=G_e();ese().then(e=>{me(`📱 App Version: v${e.appVersion}`),me(`📦 API Package: @schmitech/chatbot-api v${e.apiVersion}`),me(`🔧 API Mode: ${e.isLocalApi?"Local":"NPM Package"}`)});W6(document.getElementById("root")).render(b.jsx(y.StrictMode,{children:b.jsx(H$e,{})}));export{hFe as $,Qs as A,NYe as B,Uje as C,tet as D,SYe as E,YYe as F,Ve as G,P$e as H,Yd as I,K$e as J,vYe as K,Wn as L,TUe as M,Jje as N,zi as O,sze as P,F as Q,DGe as R,KUe as S,PX as T,tJ as U,eJ as V,aSe as W,s2 as X,mi as Y,jZ as Z,Nt as _,Aet as a,tZ as a$,dFe as a0,$Z as a1,CU as a2,Nm as a3,VDe as a4,KDe as a5,Iu as a6,PDe as a7,WDe as a8,Mw as a9,BYe as aA,XS as aB,XH as aC,xd as aD,fGe as aE,mGe as aF,C$ as aG,Rm as aH,IGe as aI,wGe as aJ,cGe as aK,Tw as aL,M$ as aM,Wve as aN,$U as aO,uGe as aP,nc as aQ,y$ as aR,Xve as aS,Lm as aT,q2e as aU,xGe as aV,Vh as aW,CYe as aX,Kh as aY,Je as aZ,qe as a_,$h as aa,IU as ab,mU as ac,al as ad,Qw as ae,IZ as af,FA as ag,Hbe as ah,AU as ai,fZ as aj,qh as ak,V$e as al,SSe as am,RH as an,Hm as ao,uU as ap,wr as aq,bU as ar,km as as,ZFe as at,WRe as au,gU as av,xU as aw,W$e as ax,wu as ay,yGe as az,Ste as b,NU as b0,HJ as b1,LJ as b2,oq as b3,Yw as b4,_$e as b5,X$e as b6,Cu as b7,_i as b8,Z$e as b9,cve as bA,LO as bB,AB as bC,JRe as bD,HRe as bE,cU as bF,Pe as bG,u$ as bH,rGe as bI,xze as bJ,_x as bK,Ro as bL,Wu as bM,f$ as bN,zw as bO,t2 as bP,nO as bQ,tB as bR,eet as ba,q$e as bb,$$e as bc,O$e as bd,LUe as be,un as bf,jo as bg,iee as bh,ac as bi,D$ as bj,at as bk,ya as bl,_U as bm,rve as bn,qo as bo,e2 as bp,$2e as bq,ive as br,Pu as bs,Zve as bt,tve as bu,eve as bv,oO as bw,rB as bx,p$ as by,Rw as bz,iet as c,Fi as d,xYe as e,eZ as f,sn as g,bYe as h,net as i,UGe as j,Wt as k,Hu as l,jje as m,ret as n,aet as o,DYe as p,S$ as q,oet as r,ue as s,pje as t,set as u,kYe as v,kt as w,zUe as x,Rje as y,qU as z};
|