orbitchat 2.3.6 → 2.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/assets/{_basePickBy-C3-QE0dl-DaERZ69h.js → _basePickBy-C3-QE0dl-BdHP3nar.js} +1 -1
  2. package/dist/assets/{_baseUniq-CstiM9Lp-D99kOC-p.js → _baseUniq-CstiM9Lp-sg1SK4tt.js} +1 -1
  3. package/dist/assets/{api-WG4VIze6.js → api-BI2PB5P1.js} +1 -1
  4. package/dist/assets/{arc-W3NKKXLI-Dh0Mpq8a.js → arc-W3NKKXLI-7mbpslwQ.js} +1 -1
  5. package/dist/assets/{architectureDiagram-VXUJARFQ-zzJsgPC6-BDBBw-Cv.js → architectureDiagram-VXUJARFQ-zzJsgPC6-BCj0AMrk.js} +1 -1
  6. package/dist/assets/{blockDiagram-VD42YOAC-D-In4h7h-CQqw_F61.js → blockDiagram-VD42YOAC-D-In4h7h-Br-Y9zbo.js} +1 -1
  7. package/dist/assets/{c4Diagram-YG6GDRKO-DBs8r9gh-p_RHAUJz.js → c4Diagram-YG6GDRKO-DBs8r9gh-Pa9UrC-Z.js} +1 -1
  8. package/dist/assets/channel-RBWQyMSg-CMXxl1oW.js +1 -0
  9. package/dist/assets/{chunk-4BX2VUAB-BqD7w0AR-Cou_FjlZ.js → chunk-4BX2VUAB-BqD7w0AR-DU5vzRnW.js} +1 -1
  10. package/dist/assets/{chunk-55IACEB6-D8pvDVEJ-C6XzcRna.js → chunk-55IACEB6-D8pvDVEJ-BhXa_l4b.js} +1 -1
  11. package/dist/assets/{chunk-B4BG7PRW-Dwma1pSy-kLVh1vdr.js → chunk-B4BG7PRW-Dwma1pSy-TfhazoD0.js} +1 -1
  12. package/dist/assets/{chunk-DI55MBZ5-BY2XXvZz-x2g2hlyp.js → chunk-DI55MBZ5-BY2XXvZz-snxVcg7c.js} +1 -1
  13. package/dist/assets/{chunk-FMBD7UC4-BeiLbQ8U-BMXy6to7.js → chunk-FMBD7UC4-BeiLbQ8U-CdQgXw4y.js} +1 -1
  14. package/dist/assets/{chunk-QN33PNHL-BkO3hOeq-DiWEGSlc.js → chunk-QN33PNHL-BkO3hOeq-B5a9WlV5.js} +1 -1
  15. package/dist/assets/{chunk-QZHKN3VN-Cwlo2qTG-KuSX1Rm7.js → chunk-QZHKN3VN-Cwlo2qTG-DnNOZr-i.js} +1 -1
  16. package/dist/assets/{chunk-TZMSLE5B-BnXK-OiF-sIvUmXfY.js → chunk-TZMSLE5B-BnXK-OiF-BZ8lc2IH.js} +1 -1
  17. package/dist/assets/{classDiagram-2ON5EDUG-Crd6O69V-D1lKB4NL.js → classDiagram-2ON5EDUG-Crd6O69V-MN032DUQ.js} +1 -1
  18. package/dist/assets/{classDiagram-v2-WZHVMYZB-Crd6O69V-D1lKB4NL.js → classDiagram-v2-WZHVMYZB-Crd6O69V-MN032DUQ.js} +1 -1
  19. package/dist/assets/clone-CfLgyC8S-CLTtorvZ.js +1 -0
  20. package/dist/assets/{cose-bilkent-S5V4N54A-DKeVcPDK-DticP2G8.js → cose-bilkent-S5V4N54A-DKeVcPDK-mJVf3lNR.js} +1 -1
  21. package/dist/assets/{dagre-6UL2VRFP-BPf604Df-DTl7pEOf.js → dagre-6UL2VRFP-BPf604Df-D5Kf_SYk.js} +1 -1
  22. package/dist/assets/{diagram-PSM6KHXK-DeLcpEV3-C8Dg3t3s.js → diagram-PSM6KHXK-DeLcpEV3-Dukssp-t.js} +1 -1
  23. package/dist/assets/{diagram-QEK2KX5R-C_5RR1NJ-CthAZGTk.js → diagram-QEK2KX5R-C_5RR1NJ-DoMbOYty.js} +1 -1
  24. package/dist/assets/{diagram-S2PKOQOG-DVx43aon-CzuqYj6u.js → diagram-S2PKOQOG-DVx43aon-e-szHMGh.js} +1 -1
  25. package/dist/assets/{erDiagram-Q2GNP2WA-DgUeO5_h-B10o2Z3B.js → erDiagram-Q2GNP2WA-DgUeO5_h-CFnOfmEf.js} +1 -1
  26. package/dist/assets/{flowDiagram-NV44I4VS-C5HQUzU9-BMlGy7zr.js → flowDiagram-NV44I4VS-C5HQUzU9-mqbeW3C_.js} +1 -1
  27. package/dist/assets/{ganttDiagram-JELNMOA3-DgSZ1ixF-B1Ndkv46.js → ganttDiagram-JELNMOA3-DgSZ1ixF-B8Zggijx.js} +1 -1
  28. package/dist/assets/{gitGraphDiagram-NY62KEGX-DY5loT9K-CQgKKw7L.js → gitGraphDiagram-NY62KEGX-DY5loT9K-D_90OrH1.js} +1 -1
  29. package/dist/assets/{graph-BfwqPHx6-DCty7MCX.js → graph-BfwqPHx6-CYzYynMk.js} +1 -1
  30. package/dist/assets/{index-D0noNJdP.css → index-6v4weZvo.css} +1 -1
  31. package/dist/assets/{index-BAOVR-xx-mY3h8ORI.js → index-BAOVR-xx-BK1n-mv5.js} +1 -1
  32. package/dist/assets/{index-DpvHV0s6.js → index-UpaB79am.js} +7 -7
  33. package/dist/assets/{infoDiagram-WHAUD3N6-DIqQ6vCk-TQ2ptWzN.js → infoDiagram-WHAUD3N6-DIqQ6vCk-UZ0FgGso.js} +1 -1
  34. package/dist/assets/{journeyDiagram-XKPGCS4Q-DXjg3S3r-D3ZEePHz.js → journeyDiagram-XKPGCS4Q-DXjg3S3r-dHm7IAFG.js} +1 -1
  35. package/dist/assets/{kanban-definition-3W4ZIXB7-Uxt7Am6n-CP98Evqj.js → kanban-definition-3W4ZIXB7-Uxt7Am6n-B9bQ02P6.js} +1 -1
  36. package/dist/assets/{layout-CSfkE668-BJwz4b5a.js → layout-CSfkE668-CZgl_LvY.js} +1 -1
  37. package/dist/assets/{mindmap-definition-VGOIOE7T-DXwVuAPE-b3w3y4jB.js → mindmap-definition-VGOIOE7T-DXwVuAPE-DhnC7fKh.js} +1 -1
  38. package/dist/assets/{pieDiagram-ADFJNKIX-Cj0EHHtj-CJmeR5Go.js → pieDiagram-ADFJNKIX-Cj0EHHtj-BQo25u1Z.js} +1 -1
  39. package/dist/assets/{quadrantDiagram-AYHSOK5B-CnLDz007-BBwq_eos.js → quadrantDiagram-AYHSOK5B-CnLDz007-Dbh5Cnqc.js} +1 -1
  40. package/dist/assets/{requirementDiagram-UZGBJVZJ-rDaI-8Be-CPfDgzaT.js → requirementDiagram-UZGBJVZJ-rDaI-8Be-B8HxHPgu.js} +1 -1
  41. package/dist/assets/{sankeyDiagram-TZEHDZUN-A0YO8ixs-nWE2CCQ1.js → sankeyDiagram-TZEHDZUN-A0YO8ixs-HQijCezt.js} +1 -1
  42. package/dist/assets/{sequenceDiagram-WL72ISMW-BFF7TtP7-EVJst8pN.js → sequenceDiagram-WL72ISMW-BFF7TtP7-CHXRBdcJ.js} +1 -1
  43. package/dist/assets/{stateDiagram-FKZM4ZOC-ofFsB7HJ-DeMNFpXB.js → stateDiagram-FKZM4ZOC-ofFsB7HJ-BfMmEB3I.js} +1 -1
  44. package/dist/assets/{stateDiagram-v2-4FDKWEC3-CEZFbksU-AkUlLjzO.js → stateDiagram-v2-4FDKWEC3-CEZFbksU-BqK74He7.js} +1 -1
  45. package/dist/assets/{timeline-definition-IT6M3QCI-5W361ZNm-C3N-P08W.js → timeline-definition-IT6M3QCI-5W361ZNm-CMTu-sAv.js} +1 -1
  46. package/dist/assets/{treemap-KMMF4GRG-pGRoYcSn-D8MozjzQ.js → treemap-KMMF4GRG-pGRoYcSn-pbWctAiz.js} +1 -1
  47. package/dist/assets/{xychartDiagram-PRI3JC2R-CSr0GxaP-BeuqTvUj.js → xychartDiagram-PRI3JC2R-CSr0GxaP-yU88x4fm.js} +1 -1
  48. package/dist/index.html +2 -2
  49. package/package.json +1 -1
  50. package/dist/assets/channel-RBWQyMSg-hFdpnWXj.js +0 -1
  51. package/dist/assets/clone-CfLgyC8S-DOPEIn2g.js +0 -1
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dagre-6UL2VRFP-BPf604Df-DTl7pEOf.js","assets/graph-BfwqPHx6-DCty7MCX.js","assets/_baseUniq-CstiM9Lp-D99kOC-p.js","assets/layout-CSfkE668-BJwz4b5a.js","assets/_basePickBy-C3-QE0dl-DaERZ69h.js","assets/clone-CfLgyC8S-DOPEIn2g.js","assets/cose-bilkent-S5V4N54A-DKeVcPDK-DticP2G8.js","assets/cytoscape.esm-CjI2IsL8-Da6dFVsf.js","assets/c4Diagram-YG6GDRKO-DBs8r9gh-p_RHAUJz.js","assets/chunk-TZMSLE5B-BnXK-OiF-sIvUmXfY.js","assets/flowDiagram-NV44I4VS-C5HQUzU9-BMlGy7zr.js","assets/chunk-FMBD7UC4-BeiLbQ8U-BMXy6to7.js","assets/chunk-55IACEB6-D8pvDVEJ-C6XzcRna.js","assets/chunk-QN33PNHL-BkO3hOeq-DiWEGSlc.js","assets/channel-RBWQyMSg-hFdpnWXj.js","assets/erDiagram-Q2GNP2WA-DgUeO5_h-B10o2Z3B.js","assets/gitGraphDiagram-NY62KEGX-DY5loT9K-CQgKKw7L.js","assets/chunk-4BX2VUAB-BqD7w0AR-Cou_FjlZ.js","assets/chunk-QZHKN3VN-Cwlo2qTG-KuSX1Rm7.js","assets/treemap-KMMF4GRG-pGRoYcSn-D8MozjzQ.js","assets/infoDiagram-WHAUD3N6-DIqQ6vCk-TQ2ptWzN.js","assets/pieDiagram-ADFJNKIX-Cj0EHHtj-CJmeR5Go.js","assets/arc-W3NKKXLI-Dh0Mpq8a.js","assets/requirementDiagram-UZGBJVZJ-rDaI-8Be-CPfDgzaT.js","assets/sequenceDiagram-WL72ISMW-BFF7TtP7-EVJst8pN.js","assets/classDiagram-2ON5EDUG-Crd6O69V-D1lKB4NL.js","assets/chunk-B4BG7PRW-Dwma1pSy-kLVh1vdr.js","assets/classDiagram-v2-WZHVMYZB-Crd6O69V-D1lKB4NL.js","assets/stateDiagram-FKZM4ZOC-ofFsB7HJ-DeMNFpXB.js","assets/chunk-DI55MBZ5-BY2XXvZz-x2g2hlyp.js","assets/stateDiagram-v2-4FDKWEC3-CEZFbksU-AkUlLjzO.js","assets/journeyDiagram-XKPGCS4Q-DXjg3S3r-D3ZEePHz.js","assets/timeline-definition-IT6M3QCI-5W361ZNm-C3N-P08W.js","assets/mindmap-definition-VGOIOE7T-DXwVuAPE-b3w3y4jB.js","assets/kanban-definition-3W4ZIXB7-Uxt7Am6n-CP98Evqj.js","assets/diagram-S2PKOQOG-DVx43aon-CzuqYj6u.js","assets/diagram-QEK2KX5R-C_5RR1NJ-CthAZGTk.js","assets/blockDiagram-VD42YOAC-D-In4h7h-CQqw_F61.js","assets/architectureDiagram-VXUJARFQ-zzJsgPC6-BDBBw-Cv.js","assets/diagram-PSM6KHXK-DeLcpEV3-C8Dg3t3s.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dagre-6UL2VRFP-BPf604Df-D5Kf_SYk.js","assets/graph-BfwqPHx6-CYzYynMk.js","assets/_baseUniq-CstiM9Lp-sg1SK4tt.js","assets/layout-CSfkE668-CZgl_LvY.js","assets/_basePickBy-C3-QE0dl-BdHP3nar.js","assets/clone-CfLgyC8S-CLTtorvZ.js","assets/cose-bilkent-S5V4N54A-DKeVcPDK-mJVf3lNR.js","assets/cytoscape.esm-CjI2IsL8-Da6dFVsf.js","assets/c4Diagram-YG6GDRKO-DBs8r9gh-Pa9UrC-Z.js","assets/chunk-TZMSLE5B-BnXK-OiF-BZ8lc2IH.js","assets/flowDiagram-NV44I4VS-C5HQUzU9-mqbeW3C_.js","assets/chunk-FMBD7UC4-BeiLbQ8U-CdQgXw4y.js","assets/chunk-55IACEB6-D8pvDVEJ-BhXa_l4b.js","assets/chunk-QN33PNHL-BkO3hOeq-B5a9WlV5.js","assets/channel-RBWQyMSg-CMXxl1oW.js","assets/erDiagram-Q2GNP2WA-DgUeO5_h-CFnOfmEf.js","assets/gitGraphDiagram-NY62KEGX-DY5loT9K-D_90OrH1.js","assets/chunk-4BX2VUAB-BqD7w0AR-DU5vzRnW.js","assets/chunk-QZHKN3VN-Cwlo2qTG-DnNOZr-i.js","assets/treemap-KMMF4GRG-pGRoYcSn-pbWctAiz.js","assets/infoDiagram-WHAUD3N6-DIqQ6vCk-UZ0FgGso.js","assets/pieDiagram-ADFJNKIX-Cj0EHHtj-BQo25u1Z.js","assets/arc-W3NKKXLI-7mbpslwQ.js","assets/requirementDiagram-UZGBJVZJ-rDaI-8Be-B8HxHPgu.js","assets/sequenceDiagram-WL72ISMW-BFF7TtP7-CHXRBdcJ.js","assets/classDiagram-2ON5EDUG-Crd6O69V-MN032DUQ.js","assets/chunk-B4BG7PRW-Dwma1pSy-TfhazoD0.js","assets/classDiagram-v2-WZHVMYZB-Crd6O69V-MN032DUQ.js","assets/stateDiagram-FKZM4ZOC-ofFsB7HJ-BfMmEB3I.js","assets/chunk-DI55MBZ5-BY2XXvZz-snxVcg7c.js","assets/stateDiagram-v2-4FDKWEC3-CEZFbksU-BqK74He7.js","assets/journeyDiagram-XKPGCS4Q-DXjg3S3r-dHm7IAFG.js","assets/timeline-definition-IT6M3QCI-5W361ZNm-CMTu-sAv.js","assets/mindmap-definition-VGOIOE7T-DXwVuAPE-DhnC7fKh.js","assets/kanban-definition-3W4ZIXB7-Uxt7Am6n-B9bQ02P6.js","assets/diagram-S2PKOQOG-DVx43aon-e-szHMGh.js","assets/diagram-QEK2KX5R-C_5RR1NJ-DoMbOYty.js","assets/blockDiagram-VD42YOAC-D-In4h7h-Br-Y9zbo.js","assets/architectureDiagram-VXUJARFQ-zzJsgPC6-BCj0AMrk.js","assets/diagram-PSM6KHXK-DeLcpEV3-Dukssp-t.js"])))=>i.map(i=>d[i]);
2
2
  var vce=Object.defineProperty;var Gce=(e,t,r)=>t in e?vce(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var gA=(e,t,r)=>Gce(e,typeof t!="symbol"?t+"":t,r);(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))n(i);new MutationObserver(i=>{for(const A of i)if(A.type==="childList")for(const a of A.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&n(a)}).observe(document,{childList:!0,subtree:!0});function r(i){const A={};return i.integrity&&(A.integrity=i.integrity),i.referrerPolicy&&(A.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?A.credentials="include":i.crossOrigin==="anonymous"?A.credentials="omit":A.credentials="same-origin",A}function n(i){if(i.ep)return;i.ep=!0;const A=r(i);fetch(i.href,A)}})();function Rce(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var oV={exports:{}},Kf={},lV={exports:{}},$t={};/**
3
3
  * @license React
4
4
  * react.production.min.js
@@ -1078,8 +1078,8 @@ Please report this to https://github.com/markedjs/marked.`,e){let n="<p>An error
1078
1078
  node : x:${e.x} y:${e.y} w:${e.width} h:${e.height}`);const n=e.x,i=e.y,A=Math.abs(n-r.x),a=e.width/2;let s=r.x<t.x?a-A:a+A;const o=e.height/2,l=Math.abs(t.y-r.y),c=Math.abs(t.x-r.x);if(Math.abs(i-t.y)*a>Math.abs(n-t.x)*o){let u=r.y<t.y?t.y-o-i:i-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),ve.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,h=r.y<t.y?r.y+u:r.y-u;return ve.debug(`sides calc abc89, Q ${l}, q ${u}, R ${c}, r ${s}`,{_x:g,_y:h}),s===0&&(g=t.x,h=t.y),c===0&&(g=t.x),l===0&&(h=t.y),{x:g,y:h}}},"intersection"),NJ=k((e,t)=>{ve.warn("abc88 cutPathAtIntersect",e,t);let r=[],n=e[0],i=!1;return e.forEach(A=>{if(ve.info("abc88 checking point",A,t),!ETe(t,A)&&!i){const a=ITe(t,n,A);ve.debug("abc88 inside",A,n,a),ve.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)?ve.warn("abc88 no intersect",a,r):r.push(a),i=!0}else ve.warn("abc88 outside",A,n),n=A,i||r.push(A)}),ve.debug("returning points",r),r},"cutPathAtIntersect");function oie(e){const t=[],r=[];for(let n=1;n<e.length-1;n++){const i=e[n-1],A=e[n],a=e[n+1];(i.x===A.x&&A.y===a.y&&Math.abs(A.x-a.x)>5&&Math.abs(A.y-i.y)>5||i.y===A.y&&A.x===a.x&&Math.abs(A.x-i.x)>5&&Math.abs(A.y-a.y)>5)&&(t.push(A),r.push(n))}return{cornerPoints:t,cornerPointPositions:r}}k(oie,"extractCornerPoints");var DJ=k(function(e,t,r){const n=t.x-e.x,i=t.y-e.y,A=Math.sqrt(n*n+i*i),a=r/A;return{x:t.x-a*n,y:t.y-a*i}},"findAdjacentPoint"),CTe=k(function(e){const{cornerPointPositions:t}=oie(e),r=[];for(let n=0;n<e.length;n++)if(t.includes(n)){const i=e[n-1],A=e[n+1],a=e[n],s=DJ(i,a,5),o=DJ(A,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(A.x-i.x)>10&&Math.abs(A.y-i.y)>=10){ve.debug("Corner point fixing",Math.abs(A.x-i.x),Math.abs(A.y-i.y));const h=5;a.x===s.x?g={x:l<0?s.x-h+u:s.x+h-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-h+u:s.y+h-u}}else ve.debug("Corner point skipping fixing",Math.abs(A.x-i.x),Math.abs(A.y-i.y));r.push(g,o)}else r.push(e[n]);return r},"fixCorners"),QTe=k((e,t,r)=>{const n=e-t-r,i=2,A=2,a=i+A,s=Math.floor(n/a),o=Array(s).fill(`${i} ${A}`).join(" ");return`0 ${t} ${o} ${r}`},"generateDashArray"),MTe=k(function(e,t,r,n,i,A,a,s=!1){var o;const{handDrawnSeed:l}=Cr();let c=t.points,u=!1;const g=i;var h=A;const d=[];for(const Z in t.cssCompiledStyles)Tte(Z)||d.push(t.cssCompiledStyles[Z]);ve.debug("UIO intersect check",t.points,h.x,g.x),h.intersect&&g.intersect&&!s&&(c=c.slice(1,t.points.length-1),c.unshift(g.intersect(c[0])),ve.debug("Last point UIO",t.start,"-->",t.end,c[c.length-1],h,h.intersect(c[c.length-1])),c.push(h.intersect(c[c.length-1])));const B=btoa(JSON.stringify(c));t.toCluster&&(ve.info("to cluster abc88",r.get(t.toCluster)),c=NJ(t.points,r.get(t.toCluster).node),u=!0),t.fromCluster&&(ve.debug("from cluster abc88",r.get(t.fromCluster),JSON.stringify(c,null,2)),c=NJ(c.reverse(),r.get(t.fromCluster).node).reverse(),u=!0);let f=c.filter(Z=>!Number.isNaN(Z.y));f=CTe(f);let w=Rh;switch(w=jc,t.curve){case"linear":w=jc;break;case"basis":w=Rh;break;case"cardinal":w=V$;break;case"bumpX":w=mS;break;case"bumpY":w=wS;break;case"catmullRom":w=Z$;break;case"monotoneX":w=QS;break;case"monotoneY":w=MS;break;case"natural":w=FS;break;case"step":w=YS;break;case"stepAfter":w=xS;break;case"stepBefore":w=bS;break;default:w=Rh}const{x:y,y:I}=C3e(t),Y=pS().x(y).y(I).curve(w);let Q;switch(t.thickness){case"normal":Q="edge-thickness-normal";break;case"thick":Q="edge-thickness-thick";break;case"invisible":Q="edge-thickness-invisible";break;default:Q="edge-thickness-normal"}switch(t.pattern){case"solid":Q+=" edge-pattern-solid";break;case"dotted":Q+=" edge-pattern-dotted";break;case"dashed":Q+=" edge-pattern-dashed";break;default:Q+=" edge-pattern-solid"}let M,D=t.curve==="rounded"?lie(cie(f,t),5):Y(f);const G=Array.isArray(t.style)?t.style:[t.style];let T=G.find(Z=>Z==null?void 0:Z.startsWith("stroke:")),R=!1;if(t.look==="handDrawn"){const Z=ht.svg(e);Object.assign([],f);const ee=Z.path(D,{roughness:.3,seed:l});Q+=" transition",M=Ar(ee).select("path").attr("id",t.id).attr("class"," "+Q+(t.classes?" "+t.classes:"")).attr("style",G?G.reduce((K,$)=>K+";"+$,""):"");let ie=M.attr("d");M.attr("d",ie),e.node().appendChild(M.node())}else{const Z=d.join(";"),ee=G?G.reduce((O,de)=>O+de+";",""):"";let ie="";t.animate&&(ie=" edge-animation-fast"),t.animation&&(ie=" edge-animation-"+t.animation);const K=(Z?Z+";"+ee+";":ee)+";"+(G?G.reduce((O,de)=>O+";"+de,""):"");M=e.append("path").attr("d",D).attr("id",t.id).attr("class"," "+Q+(t.classes?" "+t.classes:"")+(ie??"")).attr("style",K),T=(o=K.match(/stroke:([^;]+)/))==null?void 0:o[1],R=t.animate===!0||!!t.animation||Z.includes("animation");const $=M.node(),P=typeof $.getTotalLength=="function"?$.getTotalLength():0,oe=K6[t.arrowTypeStart]||0,le=K6[t.arrowTypeEnd]||0;if(t.look==="neo"&&!R){const O=`stroke-dasharray: ${t.pattern==="dotted"||t.pattern==="dashed"?QTe(P,oe,le):`0 ${oe} ${P-oe-le} ${le}`}; stroke-dashoffset: 0;`;M.attr("style",O+M.attr("style"))}}M.attr("data-edge",!0),M.attr("data-et","edge"),M.attr("data-id",t.id),M.attr("data-points",B),t.showPoints&&f.forEach(Z=>{e.append("circle").style("stroke","red").style("fill","red").attr("r",1).attr("cx",Z.x).attr("cy",Z.y)});let L="";(Cr().flowchart.arrowMarkerAbsolute||Cr().state.arrowMarkerAbsolute)&&(L=window.location.protocol+"//"+window.location.host+window.location.pathname+window.location.search,L=L.replace(/\(/g,"\\(").replace(/\)/g,"\\)")),ve.info("arrowTypeStart",t.arrowTypeStart),ve.info("arrowTypeEnd",t.arrowTypeEnd),mTe(M,t,L,a,n,T);const z=Math.floor(c.length/2),te=c[z];Ta.isLabelCoordinateInPath(te,M.attr("d"))||(u=!0);let V={};return u&&(V.updatedPath=c),V.originalPath=t.points,V},"insertEdge");function lie(e,t){if(e.length<2)return"";let r="";const n=e.length,i=1e-5;for(let A=0;A<n;A++){const a=e[A],s=e[A-1],o=e[A+1];if(A===0)r+=`M${a.x},${a.y}`;else if(A===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,h=Math.hypot(l,c),d=Math.hypot(u,g);if(h<i||d<i){r+=`L${a.x},${a.y}`;continue}const B=l/h,f=c/h,w=u/d,y=g/d,I=B*w+f*y,Y=Math.max(-1,Math.min(1,I)),Q=Math.acos(Y);if(Q<i||Math.abs(Math.PI-Q)<i){r+=`L${a.x},${a.y}`;continue}const M=Math.min(t/Math.sin(Q/2),h/2,d/2),D=a.x-B*M,G=a.y-f*M,T=a.x+w*M,R=a.y+y*M;r+=`L${D},${G}`,r+=`Q${a.x},${a.y} ${T},${R}`}}return r}k(lie,"generateRoundedPath");function G2(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}}k(G2,"calculateDeltaAndAngle");function cie(e,t){const r=e.map(i=>({...i}));if(e.length>=2&&ki[t.arrowTypeStart]){const i=ki[t.arrowTypeStart],A=e[0],a=e[1],{angle:s}=G2(A,a),o=i*Math.cos(s),l=i*Math.sin(s);r[0].x=A.x+o,r[0].y=A.y+l}const n=e.length;if(n>=2&&ki[t.arrowTypeEnd]){const i=ki[t.arrowTypeEnd],A=e[n-1],a=e[n-2],{angle:s}=G2(a,A),o=i*Math.cos(s),l=i*Math.sin(s);r[n-1].x=A.x-o,r[n-1].y=A.y-l}return r}k(cie,"applyMarkerOffsetsToPoints");var FTe=k((e,t,r,n)=>{t.forEach(i=>{HTe[i](e,r,n)})},"insertMarkers"),YTe=k((e,t,r)=>{ve.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"),bTe=k((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"),xTe=k((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"),NTe=k((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"),DTe=k((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"),kTe=k((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"),STe=k((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"),UTe=k((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"),vTe=k((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"),GTe=k((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"),RTe=k((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 i=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");i.append("circle").attr("fill","white").attr("cx",9).attr("cy",9).attr("r",6),i.append("path").attr("d","M21,0 L21,18")},"zero_or_one"),zTe=k((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"),TTe=k((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 i=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");i.append("circle").attr("fill","white").attr("cx",9).attr("cy",18).attr("r",6),i.append("path").attr("d","M21,18 Q39,0 57,18 Q39,36 21,18")},"zero_or_more"),jTe=k((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
1079
1079
  L20,10
1080
1080
  M20,10
1081
- L0,20`)},"requirement_arrow"),LTe=k((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"),HTe={extension:YTe,composition:bTe,aggregation:xTe,dependency:NTe,lollipop:DTe,point:kTe,circle:STe,cross:UTe,barb:vTe,only_one:GTe,zero_or_one:RTe,one_or_more:zTe,zero_or_more:TTe,requirement_arrow:jTe,requirement_contains:LTe},JTe=FTe,OTe={common:Vg,getConfig:Ri,insertCluster:_ze,insertEdge:MTe,insertEdgeLabel:fTe,insertMarkers:JTe,insertNode:sie,interpolateToCurve:HS,labelHelper:Ft,log:ve,positionEdgeLabel:yTe},Qd={},uie=k(e=>{for(const t of e)Qd[t.name]=t},"registerLayoutLoaders"),WTe=k(()=>{uie([{name:"dagre",loader:k(async()=>await nr(()=>import("./dagre-6UL2VRFP-BPf604Df-DTl7pEOf.js"),__vite__mapDeps([0,1,2,3,4,5])),"loader")},{name:"cose-bilkent",loader:k(async()=>await nr(()=>import("./cose-bilkent-S5V4N54A-DKeVcPDK-DticP2G8.js"),__vite__mapDeps([6,7])),"loader")}])},"registerDefaultLayoutLoaders");WTe();var ynt=k(async(e,t)=>{if(!(e.layoutAlgorithm in Qd))throw new Error(`Unknown layout algorithm: ${e.layoutAlgorithm}`);const r=Qd[e.layoutAlgorithm];return(await r.loader()).render(e,t,OTe,{algorithm:r.algorithm})},"render"),Ent=k((e="",{fallback:t="dagre"}={})=>{if(e in Qd)return e;if(t in Qd)return ve.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"),gie="comm",hie="rule",die="decl",PTe="@import",KTe="@namespace",VTe="@keyframes",XTe="@layer",Bie=Math.abs,oU=String.fromCharCode;function pie(e){return e.trim()}function km(e,t,r){return e.replace(t,r)}function ZTe(e,t,r){return e.indexOf(t,r)}function ug(e,t){return e.charCodeAt(t)|0}function Sg(e,t,r){return e.slice(t,r)}function gs(e){return e.length}function qTe(e){return e.length}function Lp(e,t){return t.push(e),e}var aE=1,Ug=1,mie=0,ya=0,Gn=0,e0="";function lU(e,t,r,n,i,A,a,s){return{value:e,root:t,parent:r,type:n,props:i,children:A,line:aE,column:Ug,length:a,return:"",siblings:s}}function _Te(){return Gn}function $Te(){return Gn=ya>0?ug(e0,--ya):0,Ug--,Gn===10&&(Ug=1,aE--),Gn}function Pa(){return Gn=ya<mie?ug(e0,ya++):0,Ug++,Gn===10&&(Ug=1,aE++),Gn}function cl(){return ug(e0,ya)}function Sm(){return ya}function sE(e,t){return Sg(e0,e,t)}function Md(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 eje(e){return aE=Ug=1,mie=gs(e0=e),ya=0,[]}function tje(e){return e0="",e}function Zx(e){return pie(sE(ya-1,R2(e===91?e+2:e===40?e+1:e)))}function rje(e){for(;(Gn=cl())&&Gn<33;)Pa();return Md(e)>2||Md(Gn)>3?"":" "}function nje(e,t){for(;--t&&Pa()&&!(Gn<48||Gn>102||Gn>57&&Gn<65||Gn>70&&Gn<97););return sE(e,Sm()+(t<6&&cl()==32&&Pa()==32))}function R2(e){for(;Pa();)switch(Gn){case e:return ya;case 34:case 39:e!==34&&e!==39&&R2(Gn);break;case 40:e===41&&R2(e);break;case 92:Pa();break}return ya}function ije(e,t){for(;Pa()&&e+Gn!==57&&!(e+Gn===84&&cl()===47););return"/*"+sE(t,ya-1)+"*"+oU(e===47?e:Pa())}function Aje(e){for(;!Md(cl());)Pa();return sE(e,ya)}function aje(e){return tje(Um("",null,null,null,[""],e=eje(e),0,[0],e))}function Um(e,t,r,n,i,A,a,s,o){for(var l=0,c=0,u=a,g=0,h=0,d=0,B=1,f=1,w=1,y=0,I="",Y=i,Q=A,M=n,D=I;f;)switch(d=y,y=Pa()){case 40:if(d!=108&&ug(D,u-1)==58){ZTe(D+=km(Zx(y),"&","&\f"),"&\f",Bie(l?s[l-1]:0))!=-1&&(w=-1);break}case 34:case 39:case 91:D+=Zx(y);break;case 9:case 10:case 13:case 32:D+=rje(d);break;case 92:D+=nje(Sm()-1,7);continue;case 47:switch(cl()){case 42:case 47:Lp(sje(ije(Pa(),Sm()),t,r,o),o),(Md(d||1)==5||Md(cl()||1)==5)&&gs(D)&&Sg(D,-1,void 0)!==" "&&(D+=" ");break;default:D+="/"}break;case 123*B:s[l++]=gs(D)*w;case 125*B:case 59:case 0:switch(y){case 0:case 125:f=0;case 59+c:w==-1&&(D=km(D,/\f/g,"")),h>0&&(gs(D)-u||B===0&&d===47)&&Lp(h>32?SJ(D+";",n,r,u-1,o):SJ(km(D," ","")+";",n,r,u-2,o),o);break;case 59:D+=";";default:if(Lp(M=kJ(D,t,r,l,c,i,s,I,Y=[],Q=[],u,A),A),y===123)if(c===0)Um(D,t,M,M,Y,A,u,s,Q);else{switch(g){case 99:if(ug(D,3)===110)break;case 108:if(ug(D,2)===97)break;default:c=0;case 100:case 109:case 115:}c?Um(e,M,M,n&&Lp(kJ(e,M,M,0,0,i,s,I,i,Y=[],u,Q),Q),i,Q,u,s,n?Y:Q):Um(D,M,M,M,[""],Q,0,s,Q)}}l=c=h=0,B=w=1,I=D="",u=a;break;case 58:u=1+gs(D),h=d;default:if(B<1){if(y==123)--B;else if(y==125&&B++==0&&$Te()==125)continue}switch(D+=oU(y),y*B){case 38:w=c>0?1:(D+="\f",-1);break;case 44:s[l++]=(gs(D)-1)*w,w=1;break;case 64:cl()===45&&(D+=Zx(Pa())),g=cl(),c=u=gs(I=D+=Aje(Sm())),y++;break;case 45:d===45&&gs(D)==2&&(B=0)}}return A}function kJ(e,t,r,n,i,A,a,s,o,l,c,u){for(var g=i-1,h=i===0?A:[""],d=qTe(h),B=0,f=0,w=0;B<n;++B)for(var y=0,I=Sg(e,g+1,g=Bie(f=a[B])),Y=e;y<d;++y)(Y=pie(f>0?h[y]+" "+I:km(I,/&\f/g,h[y])))&&(o[w++]=Y);return lU(e,t,r,i===0?hie:s,o,l,c,u)}function sje(e,t,r,n){return lU(e,t,r,gie,oU(_Te()),Sg(e,2,-2),0,n)}function SJ(e,t,r,n,i){return lU(e,t,r,die,Sg(e,0,n),Sg(e,n+1,-1),n,i)}function z2(e,t){for(var r="",n=0;n<e.length;n++)r+=t(e[n],n,e,t)||"";return r}function oje(e,t,r,n){switch(e.type){case XTe:if(e.children.length)break;case PTe:case KTe:case die:return e.return=e.return||e.value;case gie:return"";case VTe:return e.return=e.value+"{"+z2(e.children,n)+"}";case hie:if(!gs(e.value=e.props.join(",")))return""}return gs(r=z2(e.children,n))?e.return=e.value+"{"+r+"}":""}var lje=Jte(Object.keys,Object),cje=Object.prototype,uje=cje.hasOwnProperty;function gje(e){if(!Zy(e))return lje(e);var t=[];for(var r in Object(e))uje.call(e,r)&&r!="constructor"&&t.push(r);return t}var T2=cu(ks,"DataView"),j2=cu(ks,"Promise"),L2=cu(ks,"Set"),H2=cu(ks,"WeakMap"),UJ="[object Map]",hje="[object Object]",vJ="[object Promise]",GJ="[object Set]",RJ="[object WeakMap]",zJ="[object DataView]",dje=lu(T2),Bje=lu(Id),pje=lu(j2),mje=lu(L2),wje=lu(H2),nc=qg;(T2&&nc(new T2(new ArrayBuffer(1)))!=zJ||Id&&nc(new Id)!=UJ||j2&&nc(j2.resolve())!=vJ||L2&&nc(new L2)!=GJ||H2&&nc(new H2)!=RJ)&&(nc=function(e){var t=qg(e),r=t==hje?e.constructor:void 0,n=r?lu(r):"";if(n)switch(n){case dje:return zJ;case Bje:return UJ;case pje:return vJ;case mje:return GJ;case wje:return RJ}return t});var fje="[object Map]",yje="[object Set]",Eje=Object.prototype,Ije=Eje.hasOwnProperty;function TJ(e){if(e==null)return!0;if(qy(e)&&($w(e)||typeof e=="string"||typeof e.splice=="function"||jS(e)||LS(e)||_w(e)))return!e.length;var t=nc(e);if(t==fje||t==yje)return!e.size;if(Zy(e))return!gje(e).length;for(var r in e)if(Ije.call(e,r))return!1;return!0}var wie="c4",Cje=k(e=>/^\s*C4Context|C4Container|C4Component|C4Dynamic|C4Deployment/.test(e),"detector"),Qje=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./c4Diagram-YG6GDRKO-DBs8r9gh-p_RHAUJz.js");return{diagram:t}},__vite__mapDeps([8,9]));return{id:wie,diagram:e}},"loader"),Mje={id:wie,detector:Cje,loader:Qje},Fje=Mje,fie="flowchart",Yje=k((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"),bje=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./flowDiagram-NV44I4VS-C5HQUzU9-BMlGy7zr.js");return{diagram:t}},__vite__mapDeps([10,11,12,13,14]));return{id:fie,diagram:e}},"loader"),xje={id:fie,detector:Yje,loader:bje},Nje=xje,yie="flowchart-v2",Dje=k((e,t)=>{var r,n,i;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)&&((i=t==null?void 0:t.flowchart)==null?void 0:i.defaultRenderer)==="dagre-wrapper"?!0:/^\s*flowchart/.test(e))},"detector"),kje=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./flowDiagram-NV44I4VS-C5HQUzU9-BMlGy7zr.js");return{diagram:t}},__vite__mapDeps([10,11,12,13,14]));return{id:yie,diagram:e}},"loader"),Sje={id:yie,detector:Dje,loader:kje},Uje=Sje,Eie="er",vje=k(e=>/^\s*erDiagram/.test(e),"detector"),Gje=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./erDiagram-Q2GNP2WA-DgUeO5_h-B10o2Z3B.js");return{diagram:t}},__vite__mapDeps([15,12,13,14]));return{id:Eie,diagram:e}},"loader"),Rje={id:Eie,detector:vje,loader:Gje},zje=Rje,Iie="gitGraph",Tje=k(e=>/^\s*gitGraph/.test(e),"detector"),jje=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./gitGraphDiagram-NY62KEGX-DY5loT9K-CQgKKw7L.js");return{diagram:t}},__vite__mapDeps([16,17,18,19,2,4,5]));return{id:Iie,diagram:e}},"loader"),Lje={id:Iie,detector:Tje,loader:jje},Hje=Lje,Cie="gantt",Jje=k(e=>/^\s*gantt/.test(e),"detector"),Oje=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./ganttDiagram-JELNMOA3-DgSZ1ixF-B1Ndkv46.js");return{diagram:t}},[]);return{id:Cie,diagram:e}},"loader"),Wje={id:Cie,detector:Jje,loader:Oje},Pje=Wje,Qie="info",Kje=k(e=>/^\s*info/.test(e),"detector"),Vje=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./infoDiagram-WHAUD3N6-DIqQ6vCk-TQ2ptWzN.js");return{diagram:t}},__vite__mapDeps([20,19,2,4,5]));return{id:Qie,diagram:e}},"loader"),Xje={id:Qie,detector:Kje,loader:Vje},Mie="pie",Zje=k(e=>/^\s*pie/.test(e),"detector"),qje=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./pieDiagram-ADFJNKIX-Cj0EHHtj-CJmeR5Go.js");return{diagram:t}},__vite__mapDeps([21,17,19,2,4,5,22]));return{id:Mie,diagram:e}},"loader"),_je={id:Mie,detector:Zje,loader:qje},Fie="quadrantChart",$je=k(e=>/^\s*quadrantChart/.test(e),"detector"),eLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./quadrantDiagram-AYHSOK5B-CnLDz007-BBwq_eos.js");return{diagram:t}},[]);return{id:Fie,diagram:e}},"loader"),tLe={id:Fie,detector:$je,loader:eLe},rLe=tLe,Yie="xychart",nLe=k(e=>/^\s*xychart(-beta)?/.test(e),"detector"),iLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./xychartDiagram-PRI3JC2R-CSr0GxaP-BeuqTvUj.js");return{diagram:t}},[]);return{id:Yie,diagram:e}},"loader"),ALe={id:Yie,detector:nLe,loader:iLe},aLe=ALe,bie="requirement",sLe=k(e=>/^\s*requirement(Diagram)?/.test(e),"detector"),oLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./requirementDiagram-UZGBJVZJ-rDaI-8Be-CPfDgzaT.js");return{diagram:t}},__vite__mapDeps([23,12,13]));return{id:bie,diagram:e}},"loader"),lLe={id:bie,detector:sLe,loader:oLe},cLe=lLe,xie="sequence",uLe=k(e=>/^\s*sequenceDiagram/.test(e),"detector"),gLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./sequenceDiagram-WL72ISMW-BFF7TtP7-EVJst8pN.js");return{diagram:t}},__vite__mapDeps([24,9,18]));return{id:xie,diagram:e}},"loader"),hLe={id:xie,detector:uLe,loader:gLe},dLe=hLe,Nie="class",BLe=k((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"),pLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./classDiagram-2ON5EDUG-Crd6O69V-D1lKB4NL.js");return{diagram:t}},__vite__mapDeps([25,26,11,12,13]));return{id:Nie,diagram:e}},"loader"),mLe={id:Nie,detector:BLe,loader:pLe},wLe=mLe,Die="classDiagram",fLe=k((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"),yLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./classDiagram-v2-WZHVMYZB-Crd6O69V-D1lKB4NL.js");return{diagram:t}},__vite__mapDeps([27,26,11,12,13]));return{id:Die,diagram:e}},"loader"),ELe={id:Die,detector:fLe,loader:yLe},ILe=ELe,kie="state",CLe=k((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"),QLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./stateDiagram-FKZM4ZOC-ofFsB7HJ-DeMNFpXB.js");return{diagram:t}},__vite__mapDeps([28,29,12,13,1,2,3,4]));return{id:kie,diagram:e}},"loader"),MLe={id:kie,detector:CLe,loader:QLe},FLe=MLe,Sie="stateDiagram",YLe=k((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"),bLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./stateDiagram-v2-4FDKWEC3-CEZFbksU-AkUlLjzO.js");return{diagram:t}},__vite__mapDeps([30,29,12,13]));return{id:Sie,diagram:e}},"loader"),xLe={id:Sie,detector:YLe,loader:bLe},NLe=xLe,Uie="journey",DLe=k(e=>/^\s*journey/.test(e),"detector"),kLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./journeyDiagram-XKPGCS4Q-DXjg3S3r-D3ZEePHz.js");return{diagram:t}},__vite__mapDeps([31,9,11,22]));return{id:Uie,diagram:e}},"loader"),SLe={id:Uie,detector:DLe,loader:kLe},ULe=SLe,vLe=k((e,t,r)=>{ve.debug(`rendering svg for syntax error
1082
- `);const n=BUe(t),i=n.append("g");n.attr("viewBox","0 0 2412 512"),b_(n,100,512,!0),i.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"),i.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"),i.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"),i.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"),i.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"),i.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"),i.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"),i.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"),vie={draw:vLe},GLe=vie,RLe={db:{},renderer:vie,parser:{parse:k(()=>{},"parse")}},zLe=RLe,Gie="flowchart-elk",TLe=k((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"),jLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./flowDiagram-NV44I4VS-C5HQUzU9-BMlGy7zr.js");return{diagram:t}},__vite__mapDeps([10,11,12,13,14]));return{id:Gie,diagram:e}},"loader"),LLe={id:Gie,detector:TLe,loader:jLe},HLe=LLe,Rie="timeline",JLe=k(e=>/^\s*timeline/.test(e),"detector"),OLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./timeline-definition-IT6M3QCI-5W361ZNm-C3N-P08W.js");return{diagram:t}},__vite__mapDeps([32,22]));return{id:Rie,diagram:e}},"loader"),WLe={id:Rie,detector:JLe,loader:OLe},PLe=WLe,zie="mindmap",KLe=k(e=>/^\s*mindmap/.test(e),"detector"),VLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./mindmap-definition-VGOIOE7T-DXwVuAPE-b3w3y4jB.js");return{diagram:t}},__vite__mapDeps([33,12,13]));return{id:zie,diagram:e}},"loader"),XLe={id:zie,detector:KLe,loader:VLe},ZLe=XLe,Tie="kanban",qLe=k(e=>/^\s*kanban/.test(e),"detector"),_Le=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./kanban-definition-3W4ZIXB7-Uxt7Am6n-CP98Evqj.js");return{diagram:t}},__vite__mapDeps([34,11]));return{id:Tie,diagram:e}},"loader"),$Le={id:Tie,detector:qLe,loader:_Le},e8e=$Le,jie="sankey",t8e=k(e=>/^\s*sankey(-beta)?/.test(e),"detector"),r8e=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./sankeyDiagram-TZEHDZUN-A0YO8ixs-nWE2CCQ1.js");return{diagram:t}},[]);return{id:jie,diagram:e}},"loader"),n8e={id:jie,detector:t8e,loader:r8e},i8e=n8e,Lie="packet",A8e=k(e=>/^\s*packet(-beta)?/.test(e),"detector"),a8e=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./diagram-S2PKOQOG-DVx43aon-CzuqYj6u.js");return{diagram:t}},__vite__mapDeps([35,17,19,2,4,5]));return{id:Lie,diagram:e}},"loader"),s8e={id:Lie,detector:A8e,loader:a8e},Hie="radar",o8e=k(e=>/^\s*radar-beta/.test(e),"detector"),l8e=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./diagram-QEK2KX5R-C_5RR1NJ-CthAZGTk.js");return{diagram:t}},__vite__mapDeps([36,17,19,2,4,5]));return{id:Hie,diagram:e}},"loader"),c8e={id:Hie,detector:o8e,loader:l8e},Jie="block",u8e=k(e=>/^\s*block(-beta)?/.test(e),"detector"),g8e=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./blockDiagram-VD42YOAC-D-In4h7h-CQqw_F61.js");return{diagram:t}},__vite__mapDeps([37,11,5,2,1,14]));return{id:Jie,diagram:e}},"loader"),h8e={id:Jie,detector:u8e,loader:g8e},d8e=h8e,Oie="architecture",B8e=k(e=>/^\s*architecture/.test(e),"detector"),p8e=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./architectureDiagram-VXUJARFQ-zzJsgPC6-BDBBw-Cv.js");return{diagram:t}},__vite__mapDeps([38,17,19,2,4,5,7]));return{id:Oie,diagram:e}},"loader"),m8e={id:Oie,detector:B8e,loader:p8e},w8e=m8e,Wie="treemap",f8e=k(e=>/^\s*treemap/.test(e),"detector"),y8e=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./diagram-PSM6KHXK-DeLcpEV3-C8Dg3t3s.js");return{diagram:t}},__vite__mapDeps([39,13,17,19,2,4,5]));return{id:Wie,diagram:e}},"loader"),E8e={id:Wie,detector:f8e,loader:y8e},jJ=!1,oE=k(()=>{jJ||(jJ=!0,Fw("error",zLe,e=>e.toLowerCase().trim()==="error"),Fw("---",{db:{clear:k(()=>{},"clear")},styles:{},renderer:{draw:k(()=>{},"draw")},parser:{parse:k(()=>{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:k(()=>null,"init")},e=>e.toLowerCase().trimStart().startsWith("---")),J1(HLe,ZLe,w8e),J1(Fje,e8e,ILe,wLe,zje,Pje,Xje,_je,cLe,dLe,Uje,Nje,PLe,Hje,NLe,FLe,ULe,rLe,i8e,s8e,aLe,d8e,c8e,E8e))},"addDiagrams"),I8e=k(async()=>{ve.debug("Loading registered diagrams");const e=(await Promise.allSettled(Object.entries(Gc).map(async([t,{detector:r,loader:n}])=>{if(n)try{K1(t)}catch{try{const{diagram:i,id:A}=await n();Fw(A,i,r)}catch(i){throw ve.error(`Failed to load external diagram with key ${t}. Removing from detectors.`),delete Gc[t],i}}}))).filter(t=>t.status==="rejected");if(e.length>0){ve.error(`Failed to load ${e.length} external diagrams`);for(const t of e)ve.error(t);throw new Error(`Failed to load ${e.length} external diagrams`)}},"loadRegisteredDiagrams"),C8e="graphics-document document";function Pie(e,t){e.attr("role",C8e),t!==""&&e.attr("aria-roledescription",t)}k(Pie,"setA11yDiagramInfo");function Kie(e,t,r,n){if(e.insert!==void 0){if(r){const i=`chart-desc-${n}`;e.attr("aria-describedby",i),e.insert("desc",":first-child").attr("id",i).text(r)}if(t){const i=`chart-title-${n}`;e.attr("aria-labelledby",i),e.insert("title",":first-child").attr("id",i).text(t)}}}k(Kie,"addSVGa11yTitleDescription");var Hp,J2=(Hp=class{constructor(e,t,r,n,i){this.type=e,this.text=t,this.db=r,this.parser=n,this.renderer=i}static async fromText(e,t={}){var r,n;const i=Ri(),A=Uk(e,i);e=ERe(e)+`
1081
+ L0,20`)},"requirement_arrow"),LTe=k((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"),HTe={extension:YTe,composition:bTe,aggregation:xTe,dependency:NTe,lollipop:DTe,point:kTe,circle:STe,cross:UTe,barb:vTe,only_one:GTe,zero_or_one:RTe,one_or_more:zTe,zero_or_more:TTe,requirement_arrow:jTe,requirement_contains:LTe},JTe=FTe,OTe={common:Vg,getConfig:Ri,insertCluster:_ze,insertEdge:MTe,insertEdgeLabel:fTe,insertMarkers:JTe,insertNode:sie,interpolateToCurve:HS,labelHelper:Ft,log:ve,positionEdgeLabel:yTe},Qd={},uie=k(e=>{for(const t of e)Qd[t.name]=t},"registerLayoutLoaders"),WTe=k(()=>{uie([{name:"dagre",loader:k(async()=>await nr(()=>import("./dagre-6UL2VRFP-BPf604Df-D5Kf_SYk.js"),__vite__mapDeps([0,1,2,3,4,5])),"loader")},{name:"cose-bilkent",loader:k(async()=>await nr(()=>import("./cose-bilkent-S5V4N54A-DKeVcPDK-mJVf3lNR.js"),__vite__mapDeps([6,7])),"loader")}])},"registerDefaultLayoutLoaders");WTe();var ynt=k(async(e,t)=>{if(!(e.layoutAlgorithm in Qd))throw new Error(`Unknown layout algorithm: ${e.layoutAlgorithm}`);const r=Qd[e.layoutAlgorithm];return(await r.loader()).render(e,t,OTe,{algorithm:r.algorithm})},"render"),Ent=k((e="",{fallback:t="dagre"}={})=>{if(e in Qd)return e;if(t in Qd)return ve.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"),gie="comm",hie="rule",die="decl",PTe="@import",KTe="@namespace",VTe="@keyframes",XTe="@layer",Bie=Math.abs,oU=String.fromCharCode;function pie(e){return e.trim()}function km(e,t,r){return e.replace(t,r)}function ZTe(e,t,r){return e.indexOf(t,r)}function ug(e,t){return e.charCodeAt(t)|0}function Sg(e,t,r){return e.slice(t,r)}function gs(e){return e.length}function qTe(e){return e.length}function Lp(e,t){return t.push(e),e}var aE=1,Ug=1,mie=0,ya=0,Gn=0,e0="";function lU(e,t,r,n,i,A,a,s){return{value:e,root:t,parent:r,type:n,props:i,children:A,line:aE,column:Ug,length:a,return:"",siblings:s}}function _Te(){return Gn}function $Te(){return Gn=ya>0?ug(e0,--ya):0,Ug--,Gn===10&&(Ug=1,aE--),Gn}function Pa(){return Gn=ya<mie?ug(e0,ya++):0,Ug++,Gn===10&&(Ug=1,aE++),Gn}function cl(){return ug(e0,ya)}function Sm(){return ya}function sE(e,t){return Sg(e0,e,t)}function Md(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 eje(e){return aE=Ug=1,mie=gs(e0=e),ya=0,[]}function tje(e){return e0="",e}function Zx(e){return pie(sE(ya-1,R2(e===91?e+2:e===40?e+1:e)))}function rje(e){for(;(Gn=cl())&&Gn<33;)Pa();return Md(e)>2||Md(Gn)>3?"":" "}function nje(e,t){for(;--t&&Pa()&&!(Gn<48||Gn>102||Gn>57&&Gn<65||Gn>70&&Gn<97););return sE(e,Sm()+(t<6&&cl()==32&&Pa()==32))}function R2(e){for(;Pa();)switch(Gn){case e:return ya;case 34:case 39:e!==34&&e!==39&&R2(Gn);break;case 40:e===41&&R2(e);break;case 92:Pa();break}return ya}function ije(e,t){for(;Pa()&&e+Gn!==57&&!(e+Gn===84&&cl()===47););return"/*"+sE(t,ya-1)+"*"+oU(e===47?e:Pa())}function Aje(e){for(;!Md(cl());)Pa();return sE(e,ya)}function aje(e){return tje(Um("",null,null,null,[""],e=eje(e),0,[0],e))}function Um(e,t,r,n,i,A,a,s,o){for(var l=0,c=0,u=a,g=0,h=0,d=0,B=1,f=1,w=1,y=0,I="",Y=i,Q=A,M=n,D=I;f;)switch(d=y,y=Pa()){case 40:if(d!=108&&ug(D,u-1)==58){ZTe(D+=km(Zx(y),"&","&\f"),"&\f",Bie(l?s[l-1]:0))!=-1&&(w=-1);break}case 34:case 39:case 91:D+=Zx(y);break;case 9:case 10:case 13:case 32:D+=rje(d);break;case 92:D+=nje(Sm()-1,7);continue;case 47:switch(cl()){case 42:case 47:Lp(sje(ije(Pa(),Sm()),t,r,o),o),(Md(d||1)==5||Md(cl()||1)==5)&&gs(D)&&Sg(D,-1,void 0)!==" "&&(D+=" ");break;default:D+="/"}break;case 123*B:s[l++]=gs(D)*w;case 125*B:case 59:case 0:switch(y){case 0:case 125:f=0;case 59+c:w==-1&&(D=km(D,/\f/g,"")),h>0&&(gs(D)-u||B===0&&d===47)&&Lp(h>32?SJ(D+";",n,r,u-1,o):SJ(km(D," ","")+";",n,r,u-2,o),o);break;case 59:D+=";";default:if(Lp(M=kJ(D,t,r,l,c,i,s,I,Y=[],Q=[],u,A),A),y===123)if(c===0)Um(D,t,M,M,Y,A,u,s,Q);else{switch(g){case 99:if(ug(D,3)===110)break;case 108:if(ug(D,2)===97)break;default:c=0;case 100:case 109:case 115:}c?Um(e,M,M,n&&Lp(kJ(e,M,M,0,0,i,s,I,i,Y=[],u,Q),Q),i,Q,u,s,n?Y:Q):Um(D,M,M,M,[""],Q,0,s,Q)}}l=c=h=0,B=w=1,I=D="",u=a;break;case 58:u=1+gs(D),h=d;default:if(B<1){if(y==123)--B;else if(y==125&&B++==0&&$Te()==125)continue}switch(D+=oU(y),y*B){case 38:w=c>0?1:(D+="\f",-1);break;case 44:s[l++]=(gs(D)-1)*w,w=1;break;case 64:cl()===45&&(D+=Zx(Pa())),g=cl(),c=u=gs(I=D+=Aje(Sm())),y++;break;case 45:d===45&&gs(D)==2&&(B=0)}}return A}function kJ(e,t,r,n,i,A,a,s,o,l,c,u){for(var g=i-1,h=i===0?A:[""],d=qTe(h),B=0,f=0,w=0;B<n;++B)for(var y=0,I=Sg(e,g+1,g=Bie(f=a[B])),Y=e;y<d;++y)(Y=pie(f>0?h[y]+" "+I:km(I,/&\f/g,h[y])))&&(o[w++]=Y);return lU(e,t,r,i===0?hie:s,o,l,c,u)}function sje(e,t,r,n){return lU(e,t,r,gie,oU(_Te()),Sg(e,2,-2),0,n)}function SJ(e,t,r,n,i){return lU(e,t,r,die,Sg(e,0,n),Sg(e,n+1,-1),n,i)}function z2(e,t){for(var r="",n=0;n<e.length;n++)r+=t(e[n],n,e,t)||"";return r}function oje(e,t,r,n){switch(e.type){case XTe:if(e.children.length)break;case PTe:case KTe:case die:return e.return=e.return||e.value;case gie:return"";case VTe:return e.return=e.value+"{"+z2(e.children,n)+"}";case hie:if(!gs(e.value=e.props.join(",")))return""}return gs(r=z2(e.children,n))?e.return=e.value+"{"+r+"}":""}var lje=Jte(Object.keys,Object),cje=Object.prototype,uje=cje.hasOwnProperty;function gje(e){if(!Zy(e))return lje(e);var t=[];for(var r in Object(e))uje.call(e,r)&&r!="constructor"&&t.push(r);return t}var T2=cu(ks,"DataView"),j2=cu(ks,"Promise"),L2=cu(ks,"Set"),H2=cu(ks,"WeakMap"),UJ="[object Map]",hje="[object Object]",vJ="[object Promise]",GJ="[object Set]",RJ="[object WeakMap]",zJ="[object DataView]",dje=lu(T2),Bje=lu(Id),pje=lu(j2),mje=lu(L2),wje=lu(H2),nc=qg;(T2&&nc(new T2(new ArrayBuffer(1)))!=zJ||Id&&nc(new Id)!=UJ||j2&&nc(j2.resolve())!=vJ||L2&&nc(new L2)!=GJ||H2&&nc(new H2)!=RJ)&&(nc=function(e){var t=qg(e),r=t==hje?e.constructor:void 0,n=r?lu(r):"";if(n)switch(n){case dje:return zJ;case Bje:return UJ;case pje:return vJ;case mje:return GJ;case wje:return RJ}return t});var fje="[object Map]",yje="[object Set]",Eje=Object.prototype,Ije=Eje.hasOwnProperty;function TJ(e){if(e==null)return!0;if(qy(e)&&($w(e)||typeof e=="string"||typeof e.splice=="function"||jS(e)||LS(e)||_w(e)))return!e.length;var t=nc(e);if(t==fje||t==yje)return!e.size;if(Zy(e))return!gje(e).length;for(var r in e)if(Ije.call(e,r))return!1;return!0}var wie="c4",Cje=k(e=>/^\s*C4Context|C4Container|C4Component|C4Dynamic|C4Deployment/.test(e),"detector"),Qje=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./c4Diagram-YG6GDRKO-DBs8r9gh-Pa9UrC-Z.js");return{diagram:t}},__vite__mapDeps([8,9]));return{id:wie,diagram:e}},"loader"),Mje={id:wie,detector:Cje,loader:Qje},Fje=Mje,fie="flowchart",Yje=k((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"),bje=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./flowDiagram-NV44I4VS-C5HQUzU9-mqbeW3C_.js");return{diagram:t}},__vite__mapDeps([10,11,12,13,14]));return{id:fie,diagram:e}},"loader"),xje={id:fie,detector:Yje,loader:bje},Nje=xje,yie="flowchart-v2",Dje=k((e,t)=>{var r,n,i;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)&&((i=t==null?void 0:t.flowchart)==null?void 0:i.defaultRenderer)==="dagre-wrapper"?!0:/^\s*flowchart/.test(e))},"detector"),kje=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./flowDiagram-NV44I4VS-C5HQUzU9-mqbeW3C_.js");return{diagram:t}},__vite__mapDeps([10,11,12,13,14]));return{id:yie,diagram:e}},"loader"),Sje={id:yie,detector:Dje,loader:kje},Uje=Sje,Eie="er",vje=k(e=>/^\s*erDiagram/.test(e),"detector"),Gje=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./erDiagram-Q2GNP2WA-DgUeO5_h-CFnOfmEf.js");return{diagram:t}},__vite__mapDeps([15,12,13,14]));return{id:Eie,diagram:e}},"loader"),Rje={id:Eie,detector:vje,loader:Gje},zje=Rje,Iie="gitGraph",Tje=k(e=>/^\s*gitGraph/.test(e),"detector"),jje=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./gitGraphDiagram-NY62KEGX-DY5loT9K-D_90OrH1.js");return{diagram:t}},__vite__mapDeps([16,17,18,19,2,4,5]));return{id:Iie,diagram:e}},"loader"),Lje={id:Iie,detector:Tje,loader:jje},Hje=Lje,Cie="gantt",Jje=k(e=>/^\s*gantt/.test(e),"detector"),Oje=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./ganttDiagram-JELNMOA3-DgSZ1ixF-B8Zggijx.js");return{diagram:t}},[]);return{id:Cie,diagram:e}},"loader"),Wje={id:Cie,detector:Jje,loader:Oje},Pje=Wje,Qie="info",Kje=k(e=>/^\s*info/.test(e),"detector"),Vje=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./infoDiagram-WHAUD3N6-DIqQ6vCk-UZ0FgGso.js");return{diagram:t}},__vite__mapDeps([20,19,2,4,5]));return{id:Qie,diagram:e}},"loader"),Xje={id:Qie,detector:Kje,loader:Vje},Mie="pie",Zje=k(e=>/^\s*pie/.test(e),"detector"),qje=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./pieDiagram-ADFJNKIX-Cj0EHHtj-BQo25u1Z.js");return{diagram:t}},__vite__mapDeps([21,17,19,2,4,5,22]));return{id:Mie,diagram:e}},"loader"),_je={id:Mie,detector:Zje,loader:qje},Fie="quadrantChart",$je=k(e=>/^\s*quadrantChart/.test(e),"detector"),eLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./quadrantDiagram-AYHSOK5B-CnLDz007-Dbh5Cnqc.js");return{diagram:t}},[]);return{id:Fie,diagram:e}},"loader"),tLe={id:Fie,detector:$je,loader:eLe},rLe=tLe,Yie="xychart",nLe=k(e=>/^\s*xychart(-beta)?/.test(e),"detector"),iLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./xychartDiagram-PRI3JC2R-CSr0GxaP-yU88x4fm.js");return{diagram:t}},[]);return{id:Yie,diagram:e}},"loader"),ALe={id:Yie,detector:nLe,loader:iLe},aLe=ALe,bie="requirement",sLe=k(e=>/^\s*requirement(Diagram)?/.test(e),"detector"),oLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./requirementDiagram-UZGBJVZJ-rDaI-8Be-B8HxHPgu.js");return{diagram:t}},__vite__mapDeps([23,12,13]));return{id:bie,diagram:e}},"loader"),lLe={id:bie,detector:sLe,loader:oLe},cLe=lLe,xie="sequence",uLe=k(e=>/^\s*sequenceDiagram/.test(e),"detector"),gLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./sequenceDiagram-WL72ISMW-BFF7TtP7-CHXRBdcJ.js");return{diagram:t}},__vite__mapDeps([24,9,18]));return{id:xie,diagram:e}},"loader"),hLe={id:xie,detector:uLe,loader:gLe},dLe=hLe,Nie="class",BLe=k((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"),pLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./classDiagram-2ON5EDUG-Crd6O69V-MN032DUQ.js");return{diagram:t}},__vite__mapDeps([25,26,11,12,13]));return{id:Nie,diagram:e}},"loader"),mLe={id:Nie,detector:BLe,loader:pLe},wLe=mLe,Die="classDiagram",fLe=k((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"),yLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./classDiagram-v2-WZHVMYZB-Crd6O69V-MN032DUQ.js");return{diagram:t}},__vite__mapDeps([27,26,11,12,13]));return{id:Die,diagram:e}},"loader"),ELe={id:Die,detector:fLe,loader:yLe},ILe=ELe,kie="state",CLe=k((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"),QLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./stateDiagram-FKZM4ZOC-ofFsB7HJ-BfMmEB3I.js");return{diagram:t}},__vite__mapDeps([28,29,12,13,1,2,3,4]));return{id:kie,diagram:e}},"loader"),MLe={id:kie,detector:CLe,loader:QLe},FLe=MLe,Sie="stateDiagram",YLe=k((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"),bLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./stateDiagram-v2-4FDKWEC3-CEZFbksU-BqK74He7.js");return{diagram:t}},__vite__mapDeps([30,29,12,13]));return{id:Sie,diagram:e}},"loader"),xLe={id:Sie,detector:YLe,loader:bLe},NLe=xLe,Uie="journey",DLe=k(e=>/^\s*journey/.test(e),"detector"),kLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./journeyDiagram-XKPGCS4Q-DXjg3S3r-dHm7IAFG.js");return{diagram:t}},__vite__mapDeps([31,9,11,22]));return{id:Uie,diagram:e}},"loader"),SLe={id:Uie,detector:DLe,loader:kLe},ULe=SLe,vLe=k((e,t,r)=>{ve.debug(`rendering svg for syntax error
1082
+ `);const n=BUe(t),i=n.append("g");n.attr("viewBox","0 0 2412 512"),b_(n,100,512,!0),i.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"),i.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"),i.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"),i.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"),i.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"),i.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"),i.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"),i.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"),vie={draw:vLe},GLe=vie,RLe={db:{},renderer:vie,parser:{parse:k(()=>{},"parse")}},zLe=RLe,Gie="flowchart-elk",TLe=k((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"),jLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./flowDiagram-NV44I4VS-C5HQUzU9-mqbeW3C_.js");return{diagram:t}},__vite__mapDeps([10,11,12,13,14]));return{id:Gie,diagram:e}},"loader"),LLe={id:Gie,detector:TLe,loader:jLe},HLe=LLe,Rie="timeline",JLe=k(e=>/^\s*timeline/.test(e),"detector"),OLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./timeline-definition-IT6M3QCI-5W361ZNm-CMTu-sAv.js");return{diagram:t}},__vite__mapDeps([32,22]));return{id:Rie,diagram:e}},"loader"),WLe={id:Rie,detector:JLe,loader:OLe},PLe=WLe,zie="mindmap",KLe=k(e=>/^\s*mindmap/.test(e),"detector"),VLe=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./mindmap-definition-VGOIOE7T-DXwVuAPE-DhnC7fKh.js");return{diagram:t}},__vite__mapDeps([33,12,13]));return{id:zie,diagram:e}},"loader"),XLe={id:zie,detector:KLe,loader:VLe},ZLe=XLe,Tie="kanban",qLe=k(e=>/^\s*kanban/.test(e),"detector"),_Le=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./kanban-definition-3W4ZIXB7-Uxt7Am6n-B9bQ02P6.js");return{diagram:t}},__vite__mapDeps([34,11]));return{id:Tie,diagram:e}},"loader"),$Le={id:Tie,detector:qLe,loader:_Le},e8e=$Le,jie="sankey",t8e=k(e=>/^\s*sankey(-beta)?/.test(e),"detector"),r8e=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./sankeyDiagram-TZEHDZUN-A0YO8ixs-HQijCezt.js");return{diagram:t}},[]);return{id:jie,diagram:e}},"loader"),n8e={id:jie,detector:t8e,loader:r8e},i8e=n8e,Lie="packet",A8e=k(e=>/^\s*packet(-beta)?/.test(e),"detector"),a8e=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./diagram-S2PKOQOG-DVx43aon-e-szHMGh.js");return{diagram:t}},__vite__mapDeps([35,17,19,2,4,5]));return{id:Lie,diagram:e}},"loader"),s8e={id:Lie,detector:A8e,loader:a8e},Hie="radar",o8e=k(e=>/^\s*radar-beta/.test(e),"detector"),l8e=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./diagram-QEK2KX5R-C_5RR1NJ-DoMbOYty.js");return{diagram:t}},__vite__mapDeps([36,17,19,2,4,5]));return{id:Hie,diagram:e}},"loader"),c8e={id:Hie,detector:o8e,loader:l8e},Jie="block",u8e=k(e=>/^\s*block(-beta)?/.test(e),"detector"),g8e=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./blockDiagram-VD42YOAC-D-In4h7h-Br-Y9zbo.js");return{diagram:t}},__vite__mapDeps([37,11,5,2,1,14]));return{id:Jie,diagram:e}},"loader"),h8e={id:Jie,detector:u8e,loader:g8e},d8e=h8e,Oie="architecture",B8e=k(e=>/^\s*architecture/.test(e),"detector"),p8e=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./architectureDiagram-VXUJARFQ-zzJsgPC6-BCj0AMrk.js");return{diagram:t}},__vite__mapDeps([38,17,19,2,4,5,7]));return{id:Oie,diagram:e}},"loader"),m8e={id:Oie,detector:B8e,loader:p8e},w8e=m8e,Wie="treemap",f8e=k(e=>/^\s*treemap/.test(e),"detector"),y8e=k(async()=>{const{diagram:e}=await nr(async()=>{const{diagram:t}=await import("./diagram-PSM6KHXK-DeLcpEV3-Dukssp-t.js");return{diagram:t}},__vite__mapDeps([39,13,17,19,2,4,5]));return{id:Wie,diagram:e}},"loader"),E8e={id:Wie,detector:f8e,loader:y8e},jJ=!1,oE=k(()=>{jJ||(jJ=!0,Fw("error",zLe,e=>e.toLowerCase().trim()==="error"),Fw("---",{db:{clear:k(()=>{},"clear")},styles:{},renderer:{draw:k(()=>{},"draw")},parser:{parse:k(()=>{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:k(()=>null,"init")},e=>e.toLowerCase().trimStart().startsWith("---")),J1(HLe,ZLe,w8e),J1(Fje,e8e,ILe,wLe,zje,Pje,Xje,_je,cLe,dLe,Uje,Nje,PLe,Hje,NLe,FLe,ULe,rLe,i8e,s8e,aLe,d8e,c8e,E8e))},"addDiagrams"),I8e=k(async()=>{ve.debug("Loading registered diagrams");const e=(await Promise.allSettled(Object.entries(Gc).map(async([t,{detector:r,loader:n}])=>{if(n)try{K1(t)}catch{try{const{diagram:i,id:A}=await n();Fw(A,i,r)}catch(i){throw ve.error(`Failed to load external diagram with key ${t}. Removing from detectors.`),delete Gc[t],i}}}))).filter(t=>t.status==="rejected");if(e.length>0){ve.error(`Failed to load ${e.length} external diagrams`);for(const t of e)ve.error(t);throw new Error(`Failed to load ${e.length} external diagrams`)}},"loadRegisteredDiagrams"),C8e="graphics-document document";function Pie(e,t){e.attr("role",C8e),t!==""&&e.attr("aria-roledescription",t)}k(Pie,"setA11yDiagramInfo");function Kie(e,t,r,n){if(e.insert!==void 0){if(r){const i=`chart-desc-${n}`;e.attr("aria-describedby",i),e.insert("desc",":first-child").attr("id",i).text(r)}if(t){const i=`chart-title-${n}`;e.attr("aria-labelledby",i),e.insert("title",":first-child").attr("id",i).text(t)}}}k(Kie,"addSVGa11yTitleDescription");var Hp,J2=(Hp=class{constructor(e,t,r,n,i){this.type=e,this.text=t,this.db=r,this.parser=n,this.renderer=i}static async fromText(e,t={}){var r,n;const i=Ri(),A=Uk(e,i);e=ERe(e)+`
1083
1083
  `;try{K1(A)}catch{const c=FNe(A);if(!c)throw new p_(`Diagram ${A} not found.`);const{id:u,diagram:g}=await c();Fw(u,g)}const{db:a,parser:s,renderer:o,init:l}=K1(A);return s.parser&&(s.parser.yy=a),(r=a.clear)==null||r.call(a),l==null||l(i),t.title&&((n=a.setDiagramTitle)==null||n.call(a,t.title)),await s.parse(e),new Hp(A,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}},k(Hp,"Diagram"),Hp),LJ=[],Q8e=k(()=>{LJ.forEach(e=>{e()}),LJ=[]},"attachFunctions"),M8e=k(e=>e.replace(/^\s*%%(?!{)[^\n]+\n?/gm,"").trimStart(),"cleanupComments");function Vie(e){const t=e.match(B_);if(!t)return{text:e,metadata:{}};let r=I3e(t[1],{schema:E3e})??{};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}}k(Vie,"extractFrontMatter");var F8e=k(e=>e.replace(/\r\n?/g,`
1084
1084
  `).replace(/<(\w+)([^>]*)>/g,(t,r,n)=>"<"+r+n.replace(/="([^"]*)"/g,"='$1'")+">"),"cleanupText"),Y8e=k(e=>{const{text:t,metadata:r}=Vie(e),{displayMode:n,title:i,config:A={}}=r;return n&&(A.gantt||(A.gantt={}),A.gantt.displayMode=n),{title:i,config:A,text:t}},"processFrontmatter"),b8e=k(e=>{const t=Ta.detectInit(e)??{},r=Ta.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:oRe(e),directive:t}},"processDirectives");function cU(e){const t=F8e(e),r=Y8e(t),n=b8e(r.text),i=KS(r.config,n.directive);return e=M8e(n.text),{code:e,title:r.title,config:i}}k(cU,"preprocessDiagram");function Xie(e){const t=new TextEncoder().encode(e),r=Array.from(t,n=>String.fromCodePoint(n)).join("");return btoa(r)}k(Xie,"toBase64");var x8e=5e4,N8e="graph TB;a[Maximum text size in diagram exceeded];style a fill:#faa",D8e="sandbox",k8e="loose",S8e="http://www.w3.org/2000/svg",U8e="http://www.w3.org/1999/xlink",v8e="http://www.w3.org/1999/xhtml",G8e="100%",R8e="100%",z8e="border:0;margin:0;",T8e="margin:0",j8e="allow-top-navigation-by-user-activation allow-popups",L8e='The "iframe" tag is not supported by your browser.',H8e=["foreignobject"],J8e=["dominant-baseline"];function uU(e){const t=cU(e);return Qw(),HNe(t.config??{}),t}k(uU,"processAndSetConfigs");async function Zie(e,t){oE();try{const{code:r,config:n}=uU(e);return{diagramType:(await _ie(r)).type,config:n}}catch(r){if(t!=null&&t.suppressErrors)return!1;throw r}}k(Zie,"parse");var HJ=k((e,t,r=[])=>`
1085
1085
  .${e} ${t} { ${r.join(" !important; ")} !important; }`,"cssImportantStyles"),O8e=k((e,t=new Map)=>{var r;let n="";if(e.themeCSS!==void 0&&(n+=`
@@ -1178,7 +1178,7 @@ ${e.themeCSS}`),e.fontFamily!==void 0&&(n+=`
1178
1178
  from { transform: rotate(0deg); }
1179
1179
  to { transform: rotate(360deg); }
1180
1180
  }
1181
- `})]}),s.title&&fe.jsx("h4",{style:{textAlign:"center",marginBottom:s.description?"4px":"12px",marginTop:0,color:V,fontWeight:600,background:"transparent"},children:s.title}),s.description&&fe.jsx("p",{style:{textAlign:"center",marginTop:0,marginBottom:"12px",color:K,fontSize:"0.9rem"},children:s.description}),fe.jsxs(zJe,{width:"100%",height:y,children:[s.type==="bar"&&fe.jsxs(ftt,{data:s.data,margin:Xe,barCategoryGap:"20%",children:[M&&fe.jsx(Uu,{strokeDasharray:"3 3",stroke:te}),fe.jsx(vu,{dataKey:s.xKey||"name",label:vt,...$,...je,tickFormatter:hr}),fe.jsx(ls,{yAxisId:"left",width:80,tickFormatter:et,...$,children:Ws(R,"left")}),Y&&fe.jsx(ls,{yAxisId:"right",orientation:"right",width:80,tickFormatter:et,...$,children:Ws(L,"right")}),fe.jsx(bu,{contentStyle:Ne,labelStyle:Qe,itemStyle:Se,formatter:Ve,labelFormatter:yr,cursor:Te}),Q&&fe.jsx(Ac,{wrapperStyle:Ge,iconSize:10,iconType:"square"}),D,I.map(De=>fe.jsx(ND,{name:De.name,dataKey:De.key,fill:De.color,stackId:De.stackId,yAxisId:De.yAxisId,radius:[4,4,0,0]},De.key))]}),s.type==="line"&&fe.jsxs(mtt,{data:s.data,margin:Xe,children:[M&&fe.jsx(Uu,{strokeDasharray:"3 3",stroke:te}),fe.jsx(vu,{dataKey:s.xKey||"name",label:vt,...$,...je,tickFormatter:hr}),fe.jsx(ls,{yAxisId:"left",width:80,tickFormatter:et,...$,children:Ws(R,"left")}),Y&&fe.jsx(ls,{yAxisId:"right",orientation:"right",width:80,tickFormatter:et,...$,children:Ws(L,"right")}),fe.jsx(bu,{contentStyle:Ne,labelStyle:Qe,itemStyle:Se,formatter:Ve,labelFormatter:yr,cursor:Te}),Q&&fe.jsx(Ac,{wrapperStyle:Ge,iconSize:10,iconType:"square"}),D,I.map(De=>fe.jsx(DD,{name:De.name,type:"monotone",dataKey:De.key,stroke:De.color,yAxisId:De.yAxisId,strokeWidth:De.strokeWidth,dot:De.dot},De.key))]}),s.type==="area"&&fe.jsxs(vtt,{data:s.data,margin:Xe,children:[M&&fe.jsx(Uu,{strokeDasharray:"3 3",stroke:te}),fe.jsx(vu,{dataKey:s.xKey||"name",label:vt,...$,...je,tickFormatter:hr}),fe.jsx(ls,{yAxisId:"left",width:80,tickFormatter:et,...$,children:Ws(R,"left")}),Y&&fe.jsx(ls,{yAxisId:"right",orientation:"right",width:80,tickFormatter:et,...$,children:Ws(L,"right")}),fe.jsx(bu,{contentStyle:Ne,labelStyle:Qe,itemStyle:Se,formatter:Ve,labelFormatter:yr,cursor:Te}),Q&&fe.jsx(Ac,{wrapperStyle:Ge,iconSize:10,iconType:"square"}),D,I.map(De=>fe.jsx(kD,{name:De.name,type:"monotone",dataKey:De.key,stroke:De.color,yAxisId:De.yAxisId,fill:De.color,fillOpacity:De.opacity,stackId:De.stackId},De.key))]}),s.type==="composed"&&fe.jsxs(Rtt,{data:s.data,margin:Xe,children:[M&&fe.jsx(Uu,{strokeDasharray:"3 3",stroke:te}),fe.jsx(vu,{dataKey:s.xKey||"name",label:vt,...$,...je,tickFormatter:hr}),fe.jsx(ls,{yAxisId:"left",width:80,tickFormatter:et,...$,children:Ws(R,"left")}),Y&&fe.jsx(ls,{yAxisId:"right",orientation:"right",width:80,tickFormatter:et,...$,children:Ws(L,"right")}),fe.jsx(bu,{contentStyle:Ne,labelStyle:Qe,itemStyle:Se,formatter:Ve,labelFormatter:yr,cursor:Te}),Q&&fe.jsx(Ac,{wrapperStyle:Ge,iconSize:10,iconType:"square"}),D,I.map(De=>{switch(De.type){case"line":return fe.jsx(DD,{name:De.name,type:"monotone",dataKey:De.key,stroke:De.color,yAxisId:De.yAxisId,strokeWidth:De.strokeWidth,dot:De.dot},De.key);case"area":return fe.jsx(kD,{name:De.name,type:"monotone",dataKey:De.key,stroke:De.color,yAxisId:De.yAxisId,fill:De.color,fillOpacity:De.opacity,stackId:De.stackId},De.key);case"scatter":return fe.jsx(UD,{name:De.name,dataKey:De.key,fill:De.color,yAxisId:De.yAxisId},De.key);default:return fe.jsx(ND,{name:De.name,dataKey:De.key,fill:De.color,stackId:De.stackId,yAxisId:De.yAxisId,radius:[4,4,0,0]},De.key)}})]}),s.type==="pie"&&fe.jsxs(Dtt,{children:[fe.jsx(boe,{data:s.data,dataKey:((n=s.dataKeys)==null?void 0:n[0])||"value",nameKey:s.xKey||"name",cx:"50%",cy:"50%",outerRadius:y/3,label:{fill:V},children:s.data.map((De,Yt)=>fe.jsx(d0,{fill:w[Yt%w.length]},`cell-${Yt}`))}),fe.jsx(bu,{contentStyle:Ne,itemStyle:Se,formatter:Ve}),Q&&fe.jsx(Ac,{wrapperStyle:Ge,iconSize:10,iconType:"square"})]}),s.type==="scatter"&&fe.jsxs(Stt,{margin:Xe,children:[M&&fe.jsx(Uu,{strokeDasharray:"3 3",stroke:te}),fe.jsx(vu,{dataKey:s.xKey||"x",label:vt,...$,...je,tickFormatter:hr}),fe.jsx(ls,{dataKey:((i=s.dataKeys)==null?void 0:i[0])||"y",width:80,tickFormatter:et,...$,children:Ws(R,"left")}),fe.jsx(bu,{contentStyle:Ne,labelStyle:Qe,itemStyle:Se,formatter:Ve,labelFormatter:yr,cursor:Te}),Q&&fe.jsx(Ac,{wrapperStyle:Ge,iconSize:10,iconType:"square"}),D,fe.jsx(UD,{name:"Data",data:s.data,fill:w[0]})]})]})]})};let xu=null;const Wtt=async()=>{if(typeof window>"u")throw new Error("abcjs requires a browser environment");if(xu)return xu;try{const e=await nr(()=>import("./index-BAOVR-xx-mY3h8ORI.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 xu=t,xu}catch(e){if(typeof window<"u"&&window.ABCJS)return xu=window.ABCJS,xu;const t=e instanceof Error?e.message:"Failed to load abcjs";throw new Error(`Failed to load abcjs: ${t}`)}},Ptt=e=>{const t=e.trim();return/^[XMTLK]:/m.test(t)||/^X:\d+/m.test(t)},Ktt=e=>{const t=e.trim();if(!t.includes("X:")||!/^K:/m.test(t))return!0;const r=t.split(`
1181
+ `})]}),s.title&&fe.jsx("h4",{style:{textAlign:"center",marginBottom:s.description?"4px":"12px",marginTop:0,color:V,fontWeight:600,background:"transparent"},children:s.title}),s.description&&fe.jsx("p",{style:{textAlign:"center",marginTop:0,marginBottom:"12px",color:K,fontSize:"0.9rem"},children:s.description}),fe.jsxs(zJe,{width:"100%",height:y,children:[s.type==="bar"&&fe.jsxs(ftt,{data:s.data,margin:Xe,barCategoryGap:"20%",children:[M&&fe.jsx(Uu,{strokeDasharray:"3 3",stroke:te}),fe.jsx(vu,{dataKey:s.xKey||"name",label:vt,...$,...je,tickFormatter:hr}),fe.jsx(ls,{yAxisId:"left",width:80,tickFormatter:et,...$,children:Ws(R,"left")}),Y&&fe.jsx(ls,{yAxisId:"right",orientation:"right",width:80,tickFormatter:et,...$,children:Ws(L,"right")}),fe.jsx(bu,{contentStyle:Ne,labelStyle:Qe,itemStyle:Se,formatter:Ve,labelFormatter:yr,cursor:Te}),Q&&fe.jsx(Ac,{wrapperStyle:Ge,iconSize:10,iconType:"square"}),D,I.map(De=>fe.jsx(ND,{name:De.name,dataKey:De.key,fill:De.color,stackId:De.stackId,yAxisId:De.yAxisId,radius:[4,4,0,0]},De.key))]}),s.type==="line"&&fe.jsxs(mtt,{data:s.data,margin:Xe,children:[M&&fe.jsx(Uu,{strokeDasharray:"3 3",stroke:te}),fe.jsx(vu,{dataKey:s.xKey||"name",label:vt,...$,...je,tickFormatter:hr}),fe.jsx(ls,{yAxisId:"left",width:80,tickFormatter:et,...$,children:Ws(R,"left")}),Y&&fe.jsx(ls,{yAxisId:"right",orientation:"right",width:80,tickFormatter:et,...$,children:Ws(L,"right")}),fe.jsx(bu,{contentStyle:Ne,labelStyle:Qe,itemStyle:Se,formatter:Ve,labelFormatter:yr,cursor:Te}),Q&&fe.jsx(Ac,{wrapperStyle:Ge,iconSize:10,iconType:"square"}),D,I.map(De=>fe.jsx(DD,{name:De.name,type:"monotone",dataKey:De.key,stroke:De.color,yAxisId:De.yAxisId,strokeWidth:De.strokeWidth,dot:De.dot},De.key))]}),s.type==="area"&&fe.jsxs(vtt,{data:s.data,margin:Xe,children:[M&&fe.jsx(Uu,{strokeDasharray:"3 3",stroke:te}),fe.jsx(vu,{dataKey:s.xKey||"name",label:vt,...$,...je,tickFormatter:hr}),fe.jsx(ls,{yAxisId:"left",width:80,tickFormatter:et,...$,children:Ws(R,"left")}),Y&&fe.jsx(ls,{yAxisId:"right",orientation:"right",width:80,tickFormatter:et,...$,children:Ws(L,"right")}),fe.jsx(bu,{contentStyle:Ne,labelStyle:Qe,itemStyle:Se,formatter:Ve,labelFormatter:yr,cursor:Te}),Q&&fe.jsx(Ac,{wrapperStyle:Ge,iconSize:10,iconType:"square"}),D,I.map(De=>fe.jsx(kD,{name:De.name,type:"monotone",dataKey:De.key,stroke:De.color,yAxisId:De.yAxisId,fill:De.color,fillOpacity:De.opacity,stackId:De.stackId},De.key))]}),s.type==="composed"&&fe.jsxs(Rtt,{data:s.data,margin:Xe,children:[M&&fe.jsx(Uu,{strokeDasharray:"3 3",stroke:te}),fe.jsx(vu,{dataKey:s.xKey||"name",label:vt,...$,...je,tickFormatter:hr}),fe.jsx(ls,{yAxisId:"left",width:80,tickFormatter:et,...$,children:Ws(R,"left")}),Y&&fe.jsx(ls,{yAxisId:"right",orientation:"right",width:80,tickFormatter:et,...$,children:Ws(L,"right")}),fe.jsx(bu,{contentStyle:Ne,labelStyle:Qe,itemStyle:Se,formatter:Ve,labelFormatter:yr,cursor:Te}),Q&&fe.jsx(Ac,{wrapperStyle:Ge,iconSize:10,iconType:"square"}),D,I.map(De=>{switch(De.type){case"line":return fe.jsx(DD,{name:De.name,type:"monotone",dataKey:De.key,stroke:De.color,yAxisId:De.yAxisId,strokeWidth:De.strokeWidth,dot:De.dot},De.key);case"area":return fe.jsx(kD,{name:De.name,type:"monotone",dataKey:De.key,stroke:De.color,yAxisId:De.yAxisId,fill:De.color,fillOpacity:De.opacity,stackId:De.stackId},De.key);case"scatter":return fe.jsx(UD,{name:De.name,dataKey:De.key,fill:De.color,yAxisId:De.yAxisId},De.key);default:return fe.jsx(ND,{name:De.name,dataKey:De.key,fill:De.color,stackId:De.stackId,yAxisId:De.yAxisId,radius:[4,4,0,0]},De.key)}})]}),s.type==="pie"&&fe.jsxs(Dtt,{children:[fe.jsx(boe,{data:s.data,dataKey:((n=s.dataKeys)==null?void 0:n[0])||"value",nameKey:s.xKey||"name",cx:"50%",cy:"50%",outerRadius:y/3,label:{fill:V},children:s.data.map((De,Yt)=>fe.jsx(d0,{fill:w[Yt%w.length]},`cell-${Yt}`))}),fe.jsx(bu,{contentStyle:Ne,itemStyle:Se,formatter:Ve}),Q&&fe.jsx(Ac,{wrapperStyle:Ge,iconSize:10,iconType:"square"})]}),s.type==="scatter"&&fe.jsxs(Stt,{margin:Xe,children:[M&&fe.jsx(Uu,{strokeDasharray:"3 3",stroke:te}),fe.jsx(vu,{dataKey:s.xKey||"x",label:vt,...$,...je,tickFormatter:hr}),fe.jsx(ls,{dataKey:((i=s.dataKeys)==null?void 0:i[0])||"y",width:80,tickFormatter:et,...$,children:Ws(R,"left")}),fe.jsx(bu,{contentStyle:Ne,labelStyle:Qe,itemStyle:Se,formatter:Ve,labelFormatter:yr,cursor:Te}),Q&&fe.jsx(Ac,{wrapperStyle:Ge,iconSize:10,iconType:"square"}),D,fe.jsx(UD,{name:"Data",data:s.data,fill:w[0]})]})]})]})};let xu=null;const Wtt=async()=>{if(typeof window>"u")throw new Error("abcjs requires a browser environment");if(xu)return xu;try{const e=await nr(()=>import("./index-BAOVR-xx-BK1n-mv5.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 xu=t,xu}catch(e){if(typeof window<"u"&&window.ABCJS)return xu=window.ABCJS,xu;const t=e instanceof Error?e.message:"Failed to load abcjs";throw new Error(`Failed to load abcjs: ${t}`)}},Ptt=e=>{const t=e.trim();return/^[XMTLK]:/m.test(t)||/^X:\d+/m.test(t)},Ktt=e=>{const t=e.trim();if(!t.includes("X:")||!/^K:/m.test(t))return!0;const r=t.split(`
1182
1182
  `),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)},Vtt=({code:e})=>{const t=F.useRef(null),[r,n]=F.useState(null),[i,A]=F.useState(!0),[a,s]=F.useState(!1),[o,l]=F.useState(!1),[c,u]=F.useState(!1),g=F.useRef(""),h=F.useRef(0),d=F.useRef(null);return F.useEffect(()=>{const B=e.trim();if(!B){A(!1),l(!1),s(!1);return}const f=Date.now(),w=f-h.current,y=e!==g.current;g.current=e,h.current=f;const I=Ktt(B),Y=y&&w<500&&w>0,Q=I||Y;if(I){s(!0),A(!0),n(null);return}Ptt(e)?(l(!0),n(null),Q&&s(!0)):(l(!1),Q?(s(!0),n(null)):(n("Unable to detect ABC notation. Expected ABC notation starting with headers like X:, T:, M:, L:, or K:"),A(!1),s(!1)))},[e]),F.useEffect(()=>!o||!e.trim()?void 0:(a&&(d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{s(!1)},400)),(async()=>{try{A(!0);let B=0;const f=10;for(;!t.current&&B<f;)await new Promise(y=>setTimeout(y,50)),B++;if(!t.current)throw new Error("Container element not found after waiting");const w=await Wtt();t.current.innerHTML="",w.renderAbc(t.current,e,{responsive:"resize",staffwidth:740,paddingleft:0,paddingright:0,paddingtop:15,paddingbottom:15,scale:1}),n(null),A(!1)}catch(B){const f=B instanceof Error?B.message:"Failed to render ABC notation";n(f),A(!1)}})(),()=>{d.current&&clearTimeout(d.current)}),[e,o,a]),r?fe.jsxs("div",{className:"graph-error",children:[fe.jsxs("div",{className:"graph-error-header",children:[fe.jsx("div",{className:"graph-error-icon",children:"⚠️"}),fe.jsxs("div",{className:"graph-error-content",children:[fe.jsx("div",{className:"graph-error-title",children:"ABC Notation Rendering Error"}),fe.jsx("div",{className:"graph-error-message",children:r})]})]}),fe.jsxs("button",{className:"graph-error-toggle",onClick:()=>u(!c),type:"button",children:[c?"Hide":"Show"," Details"]}),c&&fe.jsxs("details",{className:"graph-error-details",open:!0,children:[fe.jsx("summary",{style:{cursor:"pointer",marginBottom:"8px",fontWeight:500},children:"ABC Notation Code"}),fe.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:fe.jsx("code",{children:e})})]})]}):(i||a)&&!o?fe.jsx("div",{className:"graph-container music-container abc-container",children:fe.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"30px 20px",color:"var(--md-text-secondary, #6b7280)",minHeight:"120px"},children:[fe.jsx("svg",{style:{animation:"spin 1s linear infinite",marginBottom:"10px",width:"28px",height:"28px"},viewBox:"0 0 24 24",fill:"none",children:fe.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",strokeDasharray:"32",strokeLinecap:"round"})}),fe.jsx("span",{style:{fontWeight:500,fontSize:"14px"},children:a?"Receiving music notation...":"Loading music notation..."}),fe.jsx("style",{children:`
1183
1183
  @keyframes spin {
1184
1184
  from { transform: rotate(0deg); }
@@ -1207,9 +1207,9 @@ ${O0e}`,nrt=()=>{if(typeof document>"u"||document.getElementById(XK))return;cons
1207
1207
  { "name": "Travel Expenses", "apiKey": "travel-expenses", "apiUrl": "http://16.52.153.174:3000" }
1208
1208
  ]`,VITE_API_URL:"http://16.52.153.174:3000",VITE_CONSOLE_DEBUG:"false",VITE_DEFAULT_KEY:"default-key",VITE_ENABLE_API_MIDDLEWARE:"true",VITE_ENABLE_AUDIO_OUTPUT:"true",VITE_ENABLE_CONVERSATION_THREADS:"true",VITE_ENABLE_FEEDBACK:"false",VITE_ENABLE_UPLOAD:"true",VITE_GITHUB_OWNER:"schmitech",VITE_GITHUB_REPO:"orbit",VITE_LOCALE:"en-US",VITE_MAX_CONVERSATIONS:"10",VITE_MAX_FILES_PER_CONVERSATION:"5",VITE_MAX_FILE_SIZE_MB:"50",VITE_MAX_MESSAGES_PER_CONVERSATION:"1000",VITE_MAX_MESSAGE_LENGTH:"500",VITE_MAX_TOTAL_FILES:"100",VITE_MAX_TOTAL_MESSAGES:"10000",VITE_SHOW_GITHUB_STATS:"true",VITE_USE_LOCAL_API:"false"},$c="http://localhost:3000";function Art(e){return typeof e=="object"&&e!==null}const art={apiUrl:"VITE_API_URL",defaultKey:"VITE_DEFAULT_KEY",useLocalApi:"VITE_USE_LOCAL_API",localApiPath:"VITE_LOCAL_API_PATH",consoleDebug:"VITE_CONSOLE_DEBUG",enableUploadButton:"VITE_ENABLE_UPLOAD",enableAudioOutput:"VITE_ENABLE_AUDIO_OUTPUT",enableFeedbackButtons:"VITE_ENABLE_FEEDBACK",enableConversationThreads:"VITE_ENABLE_CONVERSATION_THREADS",enableApiMiddleware:"VITE_ENABLE_API_MIDDLEWARE",showGitHubStats:"VITE_SHOW_GITHUB_STATS",githubOwner:"VITE_GITHUB_OWNER",githubRepo:"VITE_GITHUB_REPO",adapters:"VITE_ADAPTERS",maxFilesPerConversation:"VITE_MAX_FILES_PER_CONVERSATION",maxFileSizeMB:"VITE_MAX_FILE_SIZE_MB",maxTotalFiles:"VITE_MAX_TOTAL_FILES",maxConversations:"VITE_MAX_CONVERSATIONS",maxMessagesPerConversation:"VITE_MAX_MESSAGES_PER_CONVERSATION",maxTotalMessages:"VITE_MAX_TOTAL_MESSAGES",maxMessageLength:"VITE_MAX_MESSAGE_LENGTH"};function srt(){return typeof window<"u"&&Art(window.ORBIT_CHAT_CONFIG)}function xr(e,t,r="string"){var o;const n=e==="showGitHubStats"||e==="githubOwner"||e==="githubRepo",i=srt();if(!n){if(i){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 A=art[e],s=A?irt[A]: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 nm(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 wN(e,t){if(e===void 0||e==="")return t;const r=parseInt(e,10);return isNaN(r)||r<0?t:r}const hs={apiUrl:xr("apiUrl",$c,"string"),defaultKey:xr("defaultKey","default-key","string"),useLocalApi:xr("useLocalApi",!1,"boolean"),localApiPath:xr("localApiPath",void 0,"string"),consoleDebug:xr("consoleDebug",!1,"boolean"),enableUploadButton:xr("enableUploadButton",!1,"boolean"),enableAudioOutput:xr("enableAudioOutput",!1,"boolean"),enableFeedbackButtons:xr("enableFeedbackButtons",!1,"boolean"),enableConversationThreads:xr("enableConversationThreads",!0,"boolean"),enableApiMiddleware:xr("enableApiMiddleware",!1,"boolean"),showGitHubStats:xr("showGitHubStats",!0,"boolean"),githubOwner:xr("githubOwner","schmitech","string"),githubRepo:xr("githubRepo","orbit","string"),maxFilesPerConversation:(()=>{const e=xr("maxFilesPerConversation","5","string");return wN(e,5)})(),maxFileSizeMB:(()=>{const e=xr("maxFileSizeMB","50","string");return wN(e,50)})(),maxTotalFiles:(()=>{const e=xr("maxTotalFiles","100","string");return nm(e,100)})(),maxConversations:(()=>{const e=xr("maxConversations","10","string");return nm(e,10)})(),maxMessagesPerConversation:(()=>{const e=xr("maxMessagesPerConversation","1000","string");return nm(e,1e3)})(),maxTotalMessages:(()=>{const e=xr("maxTotalMessages","10000","string");return nm(e,1e4)})(),maxMessageLength:(()=>{const e=xr("maxMessageLength","1000","string");return wN(e,1e3)})()};function Rn(){return xr("apiUrl",$c,"string")}function to(e){const t=e==null?void 0:e.trim();return t&&t.length>0?t:Rn()}function Fc(){return xr("defaultKey","default-key","string")}function ort(){return xr("useLocalApi",!1,"boolean")}function lrt(){return xr("localApiPath",void 0,"string")}function crt(){return xr("enableUploadButton",!1,"boolean")}function urt(){return xr("enableAudioOutput",!1,"boolean")}function grt(){return xr("enableFeedbackButtons",!1,"boolean")}function hrt(){return xr("enableConversationThreads",!0,"boolean")}function Wn(){return xr("enableApiMiddleware",!1,"boolean")}function drt(){return hs.showGitHubStats}function ZK(){return hs.githubOwner}function qK(){return hs.githubRepo}function Brt({audio:e,audioFormat:t="mp3",autoPlay:r=!1,maxSizeMB:n=10}){const i=F.useRef(null),[A,a]=F.useState(!1),[s,o]=F.useState(0),[l,c]=F.useState(0),[u,g]=F.useState(!0),[h,d]=F.useState(null),[B,f]=F.useState(null);F.useEffect(()=>{if(!e)return;let T=null,R=!0;return(async()=>{try{g(!0),d(null),f(null);const te=e.length*3/4/(1024*1024);if(te>n)throw new Error(`Audio file too large (${te.toFixed(1)}MB > ${n}MB limit)`);if(te>2&&(f(`Large audio file (${te.toFixed(1)}MB) - may take time to load`),Je("[AudioPlayer] Large audio file detected",{sizeMB:te.toFixed(2)})),!/^[A-Za-z0-9+/=]+$/.test(e.replace(/\s/g,"")))throw new Error("Invalid base64 audio data");const V=atob(e),Z=new Uint8Array(V.length);for(let K=0;K<V.length;K++)Z[K]=V.charCodeAt(K);const ee=t==="mp3"?"audio/mpeg":t==="wav"?"audio/wav":t==="ogg"?"audio/ogg":t==="opus"?"audio/opus":t==="webm"?"audio/webm":`audio/${t}`,ie=new Blob([Z],{type:ee});if(T=URL.createObjectURL(ie),!R||!i.current){T&&URL.revokeObjectURL(T);return}i.current.src=T,g(!1),Je("[AudioPlayer] Audio loaded successfully",{format:t,mimeType:ee,size:ie.size}),r&&i.current&&i.current.play().catch(K=>{jg("[AudioPlayer] Auto-play failed:",K)})}catch{R&&(d("Failed to load audio"),g(!1))}})(),()=>{R=!1,T&&URL.revokeObjectURL(T)}},[e,t,r,n]);const w=()=>{i.current&&o(i.current.duration)},y=()=>{i.current&&c(i.current.currentTime)},I=()=>a(!0),Y=()=>a(!1),Q=()=>{a(!1),c(0)},M=()=>{i.current&&(A?i.current.pause():i.current.play().catch(T=>{d("Playback failed")}))},D=T=>{if(!i.current)return;const R=parseFloat(T.target.value);i.current.currentTime=R,c(R)},G=T=>{if(!isFinite(T))return"0:00";const R=Math.floor(T/60),L=Math.floor(T%60);return`${R}:${L.toString().padStart(2,"0")}`};return h?j.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:[j.jsx(uw,{className:"h-4 w-4"}),j.jsx("span",{children:h})]}):j.jsxs("div",{className:"mt-3 flex flex-col gap-1",children:[B&&j.jsxs("div",{className:"text-xs text-amber-600 dark:text-amber-400 px-1",children:["⚠️ ",B]}),j.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:[j.jsx("audio",{ref:i,onLoadedMetadata:w,onTimeUpdate:y,onPlay:I,onPause:Y,onEnded:Q}),j.jsx("button",{onClick:M,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:A?"Pause":"Play",children:u?j.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-gray-400 border-t-transparent"}):A?j.jsx(F0e,{className:"h-4 w-4 text-gray-700 dark:text-[#ececf1]"}):j.jsx(b0e,{className:"h-4 w-4 text-gray-700 dark:text-[#ececf1]"})}),j.jsxs("div",{className:"flex flex-1 items-center gap-2",children:[j.jsx("span",{className:"text-xs text-gray-500 dark:text-[#bfc2cd]",children:G(l)}),j.jsx("input",{type:"range",min:"0",max:s||0,value:l,onChange:D,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)"}}),j.jsx("span",{className:"text-xs text-gray-500 dark:text-[#bfc2cd]",children:G(s)})]}),j.jsx(uw,{className:"h-4 w-4 text-gray-500 dark:text-[#bfc2cd]"})]})]})}const prt=["#","*","`","[","]","(",")","{","}","|","<",">"],fle=e=>prt.some(t=>e.includes(t));function yle(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),i=fle(e),A=/[.,;:!?'"()-]/.test(e);if(!n&&!i&&!A)return!0}return!!(r.length>5e4&&t.test(r)&&e.replace(/[A-Za-z0-9+/=\s]/g,"").length<10)}function Jh(e){if(!e)return e;if(yle(e))return"";const t=/([A-Za-z0-9+/=]{10000,})/g;return e.replace(t,n=>{const i=n.replace(/\s+/g,"");if(i.length>1e4&&/^[A-Za-z0-9+/=]+$/.test(i)){const A=/\b(function|const|let|var|class|return|import|export|if|else|while|for|true|false|null|def|print)\b/i.test(n),a=fle(n),s=/[.,;:!?'"()-]/.test(n);if(!A&&!a&&!s)return""}return n}).trim()}function HD(e,t=5e4){return!e||e.length<=t?e:yle(e)?"":e.substring(0,t)+`
1209
1209
 
1210
- ... (content truncated due to length)`}const Nr={maxFilesPerConversation:hs.maxFilesPerConversation,maxFileSizeMB:hs.maxFileSizeMB,maxTotalFiles:hs.maxTotalFiles,maxConversations:hs.maxConversations,maxMessagesPerConversation:hs.maxMessagesPerConversation,maxTotalMessages:hs.maxTotalMessages,maxMessageLength:hs.maxMessageLength},mrt=[];function wrt({message:e,onRegenerate:t,onStartThread:r,onSendThreadMessage:n,threadMessages:i,sessionId:A,isThreadSendDisabled:a}){var Ne,Qe;const[s,o]=F.useState(!1),[l,c]=F.useState(null),[u,g]=F.useState(""),[h,d]=F.useState(!1),[B,f]=F.useState(!1),w=F.useRef(((Ne=e.threadInfo)==null?void 0:Ne.thread_id)||null),y=F.useRef(null),I=e.role==="assistant",Y=i??mrt,Q=Y.filter(Se=>Se.role==="assistant").length,M=Y.some(Se=>Se.isStreaming),D="en-US",G=hrt(),T=Nr.maxMessageLength,{theme:R,isDark:L}=IX(),z=R.mode==="dark"?"dark":R.mode==="light"?"light":"",te=L?"dark":"light",V=F.useMemo(()=>["message-markdown w-full min-w-0","prose prose-slate dark:prose-invert max-w-none",z].filter(Boolean).join(" "),[z]),Z=F.useMemo(()=>["message-markdown w-full min-w-0","prose prose-invert max-w-none",z].filter(Boolean).join(" "),[z]),ee=I?V:Z,ie=`${V} text-sm leading-6`,K=`${Z} text-sm leading-6`;F.useEffect(()=>{var Se,Te;!w.current&&((Se=e.threadInfo)!=null&&Se.thread_id)&&d(!0),w.current=((Te=e.threadInfo)==null?void 0:Te.thread_id)||null},[(Qe=e.threadInfo)==null?void 0:Qe.thread_id]),F.useEffect(()=>{e.threadInfo||(g(""),d(!1),f(!1))},[e.threadInfo]),F.useEffect(()=>{Q>0&&d(!0)},[Q]);const $=F.useMemo(()=>{const Se=e.timestamp instanceof Date?e.timestamp:new Date(e.timestamp),Te=Se.toLocaleDateString(D,{weekday:"short"}),Ve=Se.toLocaleDateString(D,{month:"short"}),et=Se.getDate().toString().padStart(2,"0"),rt=Se.getFullYear(),It=Se.toLocaleTimeString(D,{hour:"2-digit",minute:"2-digit",hour12:!0});return`${Te}, ${Ve} ${et}, ${rt} ${It}`},[e.timestamp,D]),P=I?"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]",oe=`message-bubble min-w-0 break-words leading-relaxed ${I?"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`,le=I?"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",O=async()=>{try{await navigator.clipboard.writeText(e.content),o(!0),setTimeout(()=>o(!1),2e3)}catch{}},de=Se=>{c(l===Se?null:Se)},Ee=F.useCallback(Se=>(Se instanceof Date?Se:new Date(Se)).toLocaleTimeString(D,{hour:"2-digit",minute:"2-digit"}),[D]),Ce=async()=>{if(!n||!e.threadInfo)return;const Se=u.trim();if(Se){f(!0);try{await n(e.threadInfo.thread_id,e.id,Se),g(""),setTimeout(()=>{y.current&&y.current.focus()},100)}catch{setTimeout(()=>{y.current&&y.current.focus()},100)}finally{f(!1)}}},pe=Se=>{Se.key==="Enter"&&!Se.shiftKey&&(Se.preventDefault(),Ce())},xe=!e.threadInfo||!n||a||M||B;F.useEffect(()=>{if(!h||xe)return;const Se=y.current;if(!Se)return;const Te=requestAnimationFrame(()=>{Se.focus();const Ve=Se.value.length;Se.setSelectionRange(Ve,Ve)});return()=>cancelAnimationFrame(Te)},[h,xe,B]),F.useEffect(()=>{if(y.current){const Te=y.current;Te.style.height="auto";const Ve=Te.scrollHeight;Te.style.height=`${Math.min(Ve,120)}px`,Te.style.overflowY=Ve>120?"auto":"hidden"}},[u]);const ye=F.useMemo(()=>e.isStreaming&&(!e.content||e.content==="…")?j.jsx("div",{className:ee,children:j.jsxs("div",{className:"flex items-center gap-1.5 py-1",children:[j.jsx("span",{className:"inline-block h-2.5 w-2.5 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"0ms"}}),j.jsx("span",{className:"inline-block h-2.5 w-2.5 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"150ms"}}),j.jsx("span",{className:"inline-block h-2.5 w-2.5 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"300ms"}})]})}):j.jsx(LD,{content:HD(Jh(e.content||"")),className:ee,syntaxTheme:te}),[ee,e.content,e.isStreaming,te]),je=F.useMemo(()=>[...Y].sort((Te,Ve)=>{const et=Te.timestamp instanceof Date?Te.timestamp.getTime():new Date(Te.timestamp).getTime(),rt=Ve.timestamp instanceof Date?Ve.timestamp.getTime():new Date(Ve.timestamp).getTime();return et-rt}).map(Te=>{const Ve=Te.role==="assistant",et=Ve?ie:K,rt=Te.isStreaming&&(!Te.content||Te.content==="…")?j.jsx("div",{className:et,children:j.jsxs("div",{className:"flex items-center gap-1.5 py-1",children:[j.jsx("span",{className:"inline-block h-2 w-2 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"0ms"}}),j.jsx("span",{className:"inline-block h-2 w-2 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"150ms"}}),j.jsx("span",{className:"inline-block h-2 w-2 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"300ms"}})]})}):j.jsx(LD,{content:HD(Jh(Te.content||"")),className:et,syntaxTheme:te});return j.jsxs("div",{className:"flex items-start gap-3",children:[j.jsx("div",{className:`mt-0.5 flex h-7 w-7 flex-shrink-0 items-center justify-center rounded-full ${Ve?"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:Ve?j.jsx(tR,{className:"h-3.5 w-3.5"}):j.jsx(nR,{className:"h-3.5 w-3.5"})}),j.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:[j.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:[j.jsx("span",{children:Ve?"Assistant":"You"}),j.jsx("span",{children:Ee(Te.timestamp)})]}),j.jsx("div",{className:"thread-markdown-wrapper overflow-x-auto",children:rt})]})]},Te.id)}),[Ee,te,ie,Y,K]);return j.jsxs("div",{className:"group flex items-start gap-3 px-1 animate-fadeIn min-w-0 sm:px-0",children:[j.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 ${P}`,children:I?j.jsx(tR,{className:"h-5 w-5"}):j.jsx(nR,{className:"h-5 w-5"})}),j.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[j.jsxs("div",{className:"flex flex-col gap-1.5 mb-1",children:[j.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-gray-700 dark:text-[#ececf1]",children:I?"Assistant":"You"}),j.jsx("span",{className:"text-xs text-gray-500 dark:text-[#bfc2cd]",children:$})]}),j.jsxs("div",{className:oe,children:[ye,e.attachments&&e.attachments.length>0&&j.jsx("div",{className:"mt-3 space-y-2",children:e.attachments.map(Se=>j.jsxs("div",{className:`flex items-center gap-3 rounded-xl border p-3 ${le}`,children:[j.jsx(w0e,{className:"h-4 w-4 text-gray-500 dark:text-[#bfc2cd]"}),j.jsxs("div",{className:"min-w-0 flex-1",children:[j.jsx("p",{className:"truncate text-sm font-medium text-[#353740] dark:text-[#ececf1]",children:Se.filename}),j.jsxs("p",{className:"text-xs text-gray-500 dark:text-[#bfc2cd]",children:[(Se.file_size/1024).toFixed(1)," KB"]})]})]},Se.file_id))}),e.audio&&I&&!e.isStreaming&&j.jsx(Brt,{audio:e.audio,audioFormat:e.audioFormat,autoPlay:!1})]}),I&&!e.isStreaming&&j.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:[j.jsxs("button",{onClick:O,className:"inline-flex items-center gap-1 rounded px-2 py-1 hover:bg-gray-200 dark:hover:bg-[#3c3f4a]",title:"Copy message",children:[j.jsx(B0e,{className:"h-4 w-4"}),j.jsx("span",{className:"hidden sm:inline",children:"Copy"})]}),t&&j.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:[j.jsx(D0e,{className:"h-4 w-4"}),j.jsx("span",{className:"hidden sm:inline",children:"Retry"})]}),G&&r&&e.supportsThreading&&!e.threadInfo&&A&&j.jsxs("button",{onClick:()=>r(e.id,A),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:[j.jsx(Yh,{className:"h-4 w-4"}),j.jsx("span",{className:"hidden sm:inline",children:"Start Thread"})]}),grt()&&j.jsxs("div",{className:"flex items-center gap-1",children:[j.jsx("button",{onClick:()=>de("up"),className:`rounded p-1 hover:bg-gray-200 dark:hover:bg-[#3c3f4a] ${l==="up"?"text-[#353740] dark:text-[#ececf1]":""}`,title:"Good response",children:j.jsx(v0e,{className:"h-4 w-4"})}),j.jsx("button",{onClick:()=>de("down"),className:`rounded p-1 hover:bg-gray-200 dark:hover:bg-[#3c3f4a] ${l==="down"?"text-[#353740] dark:text-[#ececf1]":""}`,title:"Poor response",children:j.jsx(U0e,{className:"h-4 w-4"})})]}),s&&j.jsx("span",{children:"Copied"})]}),G&&e.threadInfo&&j.jsxs("div",{className:"ml-0 sm:ml-12 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:[j.jsxs("div",{className:"flex items-center justify-between gap-2 text-sm font-semibold text-blue-900 dark:text-[#c5d7ff]",children:[j.jsxs("div",{className:"inline-flex items-center gap-2 uppercase tracking-wide text-xs sm:text-sm",children:[j.jsx(Yh,{className:"h-3.5 w-3.5"}),j.jsxs("span",{children:["Thread",Q>0?` (${Q})`:""]})]}),j.jsx("button",{onClick:()=>d(Se=>!Se),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:h?j.jsxs(j.Fragment,{children:[j.jsx("span",{className:"hidden sm:inline",children:"Hide"}),j.jsx(d0e,{className:"h-4 w-4 sm:h-3 sm:w-3"})]}):j.jsxs(j.Fragment,{children:[j.jsx("span",{className:"hidden sm:inline",children:"Show"}),j.jsx(FX,{className:"h-4 w-4 sm:h-3 sm:w-3"})]})})]}),h&&j.jsxs(j.Fragment,{children:[j.jsx("div",{className:"mt-3 space-y-3",children:je}),j.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:j.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-3",children:[j.jsx("textarea",{ref:y,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:Se=>g(Se.target.value),onKeyDown:pe,disabled:xe,rows:1,maxLength:T,style:{minHeight:"44px",maxHeight:"120px",outline:"none",boxShadow:"none",WebkitAppearance:"none",MozAppearance:"none",appearance:"none"}}),j.jsxs("div",{className:"flex items-center justify-between sm:justify-end gap-2",children:[u.length>0&&j.jsx("div",{className:"text-xs text-gray-500 dark:text-[#bfc2cd] whitespace-nowrap",children:j.jsxs("span",{className:u.length>=T?"text-red-600 font-semibold":"",children:[u.length,"/",T]})}),j.jsx("button",{type:"button",onClick:Ce,disabled:xe||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&&!xe?"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:B?j.jsx(Ag,{className:"h-5 w-5 sm:h-4 sm:w-4 animate-spin"}):j.jsx(MX,{className:"h-5 w-5 sm:h-4 sm:w-4"})})]})]})})]})]})]})]})}function frt(e=800,t=100,r="sine"){try{if(typeof window>"u"){Je("[SoundEffects] Window is not available for audio playback");return}const n=window.AudioContext??window.webkitAudioContext;if(!n){Je("[SoundEffects] AudioContext not supported in this browser");return}const i=new n,A=i.createOscillator(),a=i.createGain();A.connect(a),a.connect(i.destination),A.frequency.value=e,A.type=r,a.gain.setValueAtTime(.3,i.currentTime),a.gain.exponentialRampToValueAtTime(.01,i.currentTime+t/1e3),A.start(i.currentTime),A.stop(i.currentTime+t/1e3)}catch{}}const yrt={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 mh(e,t){if(!t)return;const r=yrt[e];if(r)try{frt(r.frequency,r.duration,r.type),Je(`[SoundEffects] Playing ${e} sound effect`)}catch{}}function Ert({messages:e,onRegenerate:t,onStartThread:r,onSendThreadMessage:n,sessionId:i,isLoading:A}){const a=F.useRef(null),s=F.useRef(null),o=F.useRef(e.length),l=F.useRef(""),c=F.useRef(A),u=F.useRef(!0),{settings:g}=cy(),{topLevelMessages:h,threadLookup:d}=F.useMemo(()=>{const w=new Map,y=[];return e.forEach(I=>{if(I.isThreadMessage&&I.parentMessageId){const Y=w.get(I.parentMessageId)||[];w.set(I.parentMessageId,[...Y,I]);return}y.push(I)}),{topLevelMessages:y,threadLookup:w}},[e]),B=()=>{if(!s.current)return;const{scrollTop:w,scrollHeight:y,clientHeight:I}=s.current,Q=y-w-I<200;u.current=Q},f=(w="smooth")=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{a.current?a.current.scrollIntoView({behavior:w}):s.current&&(s.current.scrollTop=s.current.scrollHeight)})})};return F.useEffect(()=>{const w=e.length,y=o.current,I=w>y,Y=e[e.length-1],Q=(Y==null?void 0:Y.content)||"",M=Q!==l.current;I||Y!=null&&Y.isStreaming||M&&(Y==null?void 0:Y.role)==="assistant"?(f(I?"auto":"smooth"),u.current=!0):u.current&&M&&f("smooth"),o.current=w,l.current=Q},[e]),F.useEffect(()=>{A&&(f("auto"),u.current=!0)},[A]),F.useEffect(()=>{if(c.current&&!A){const w=e[e.length-1];(w==null?void 0:w.role)==="assistant"&&w.content&&mh("messageReceived",g.soundEnabled)}c.current=A},[A,e,g.soundEnabled]),h.length===0?j.jsx("div",{className:"flex-1 flex items-center justify-center px-4 sm:px-6",children:j.jsxs("div",{className:"text-center text-lg text-gray-500 dark:text-[#bfc2cd]",children:[j.jsx("p",{className:"text-xl",children:"Your messages will appear here."}),j.jsx("p",{className:"mt-1 text-lg",children:"Start the conversation by sending a prompt below."})]})}):j.jsx("div",{ref:s,className:"message-list flex-1 overflow-y-auto py-6",onScroll:B,children:j.jsxs("div",{className:"space-y-6 px-3 sm:px-4",children:[h.map(w=>j.jsx(wrt,{message:w,onRegenerate:t,onStartThread:r,onSendThreadMessage:n,threadMessages:d.get(w.id),sessionId:i,isThreadSendDisabled:A},w.id)),j.jsx("div",{ref:a,className:"h-8"})]})})}const Irt=2e3;function Crt(e,t){const[r,n]=F.useState(!1),[i,A]=F.useState(null),a=F.useRef(null),s=F.useRef(""),o=F.useRef(!1),l=F.useRef(null),c=F.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=F.useCallback(()=>{!t||o.current||(o.current=!0,t())},[t]),h=F.useCallback(()=>{l.current!==null&&(clearTimeout(l.current),l.current=null)},[]),d=F.useCallback(()=>{h(),l.current=setTimeout(()=>{a.current?a.current.stop():g()},Irt)},[h,g]),B=F.useCallback(()=>{if(!u){A("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,y=new w;y.continuous=!0,y.interimResults=!0,y.lang=navigator.language||"en-US",y.maxAlternatives=1,y.onstart=()=>{n(!0),A(null),Je("Speech recognition started"),d()},y.onresult=I=>{let Y="",Q="";for(let M=I.resultIndex;M<I.results.length;M++){const D=I.results[M][0].transcript;I.results[M].isFinal?Y+=D:Q+=D}Q&&(s.current=Q),Y&&(s.current="",e(" "+Y)),d()},y.onend=()=>{h(),c(),n(!1),a.current=null,Je("Speech recognition ended"),g()},y.onerror=I=>{switch(h(),jg("Speech recognition error:",I.error),n(!1),a.current=null,s.current="",g(),I.error){case"no-speech":A("No speech detected. Please try again.");break;case"audio-capture":A("Microphone access denied. Please allow microphone access and try again.");break;case"not-allowed":A("Microphone access not allowed. Please enable microphone permissions.");break;case"network":A("Network error occurred. Please check your connection.");break;default:A(`Speech recognition error: ${I.error}`)}},y.start(),a.current=y}catch{A("Failed to start speech recognition. Please try again."),n(!1)}},[u,e,r,c,g,d,h]),f=F.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}h(),c(),n(!1),A(null),g()},[h,c,g]);return{isListening:r,isSupported:u,startListening:B,stopListening:f,error:i}}const Qrt="2.3.6",Mrt={"@schmitech/chatbot-api":"^2.1.2"},Ele={version:Qrt,dependencies:Mrt},Ile=Ele.version,_K=Ele.dependencies["@schmitech/chatbot-api"];async function JD(){try{return(await nr(()=>import("./api-WG4VIze6.js"),[])).version||_K}catch{return _K}}async function Cle(){const e=await JD();return{appVersion:Ile,apiVersion:e,isLocalApi:!1}}let Ps=null;function $0(){let e=null,t=null;const r=(i,A,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(i,A,a,s,o,l,c,u,g,h,d){var w,y;const B={messages:[{role:"user",content:i}],stream:A!==!1};a&&a.length>0&&(B.file_ids=a),s&&(B.thread_id=s),o&&(B.audio_input=o),l&&(B.audio_format=l),c&&(B.language=c),u!==void 0&&(B.return_audio=u),g&&(B.tts_voice=g),h&&(B.source_language=h),d&&(B.target_language=d);const f=await fetch("/api/proxy/v1/chat",{method:"POST",headers:{"Content-Type":"application/json","X-Adapter-Name":t,...e?{"X-Session-ID":e}:{}},body:JSON.stringify(B)});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 I=(y=f.body)==null?void 0:y.getReader(),Y=new TextDecoder;let Q="";if(!I)throw new Error("Response body is not readable");for(;;){const{done:M,value:D}=await I.read();if(M)break;Q+=Y.decode(D,{stream:!0});const G=Q.split(`
1210
+ ... (content truncated due to length)`}const Nr={maxFilesPerConversation:hs.maxFilesPerConversation,maxFileSizeMB:hs.maxFileSizeMB,maxTotalFiles:hs.maxTotalFiles,maxConversations:hs.maxConversations,maxMessagesPerConversation:hs.maxMessagesPerConversation,maxTotalMessages:hs.maxTotalMessages,maxMessageLength:hs.maxMessageLength},mrt=[];function wrt({message:e,onRegenerate:t,onStartThread:r,onSendThreadMessage:n,threadMessages:i,sessionId:A,isThreadSendDisabled:a}){var Ne,Qe;const[s,o]=F.useState(!1),[l,c]=F.useState(null),[u,g]=F.useState(""),[h,d]=F.useState(!1),[B,f]=F.useState(!1),w=F.useRef(((Ne=e.threadInfo)==null?void 0:Ne.thread_id)||null),y=F.useRef(null),I=e.role==="assistant",Y=i??mrt,Q=Y.filter(Se=>Se.role==="assistant").length,M=Y.some(Se=>Se.isStreaming),D="en-US",G=hrt(),T=Nr.maxMessageLength,{theme:R,isDark:L}=IX(),z=R.mode==="dark"?"dark":R.mode==="light"?"light":"",te=L?"dark":"light",V=F.useMemo(()=>["message-markdown w-full min-w-0","prose prose-slate dark:prose-invert max-w-none",z].filter(Boolean).join(" "),[z]),Z=F.useMemo(()=>["message-markdown w-full min-w-0","prose prose-invert max-w-none",z].filter(Boolean).join(" "),[z]),ee=I?V:Z,ie=`${V} text-sm leading-6`,K=`${Z} text-sm leading-6`;F.useEffect(()=>{var Se,Te;!w.current&&((Se=e.threadInfo)!=null&&Se.thread_id)&&d(!0),w.current=((Te=e.threadInfo)==null?void 0:Te.thread_id)||null},[(Qe=e.threadInfo)==null?void 0:Qe.thread_id]),F.useEffect(()=>{e.threadInfo||(g(""),d(!1),f(!1))},[e.threadInfo]),F.useEffect(()=>{Q>0&&d(!0)},[Q]);const $=F.useMemo(()=>{const Se=e.timestamp instanceof Date?e.timestamp:new Date(e.timestamp),Te=Se.toLocaleDateString(D,{weekday:"short"}),Ve=Se.toLocaleDateString(D,{month:"short"}),et=Se.getDate().toString().padStart(2,"0"),rt=Se.getFullYear(),It=Se.toLocaleTimeString(D,{hour:"2-digit",minute:"2-digit",hour12:!0});return`${Te}, ${Ve} ${et}, ${rt} ${It}`},[e.timestamp,D]),P=I?"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]",oe=`message-bubble min-w-0 break-words leading-relaxed ${I?"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`,le=I?"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",O=async()=>{try{await navigator.clipboard.writeText(e.content),o(!0),setTimeout(()=>o(!1),2e3)}catch{}},de=Se=>{c(l===Se?null:Se)},Ee=F.useCallback(Se=>(Se instanceof Date?Se:new Date(Se)).toLocaleTimeString(D,{hour:"2-digit",minute:"2-digit"}),[D]),Ce=async()=>{if(!n||!e.threadInfo)return;const Se=u.trim();if(Se){f(!0);try{await n(e.threadInfo.thread_id,e.id,Se),g(""),setTimeout(()=>{y.current&&y.current.focus()},100)}catch{setTimeout(()=>{y.current&&y.current.focus()},100)}finally{f(!1)}}},pe=Se=>{Se.key==="Enter"&&!Se.shiftKey&&(Se.preventDefault(),Ce())},xe=!e.threadInfo||!n||a||M||B;F.useEffect(()=>{if(!h||xe)return;const Se=y.current;if(!Se)return;const Te=requestAnimationFrame(()=>{Se.focus();const Ve=Se.value.length;Se.setSelectionRange(Ve,Ve)});return()=>cancelAnimationFrame(Te)},[h,xe,B]),F.useEffect(()=>{if(y.current){const Te=y.current;Te.style.height="auto";const Ve=Te.scrollHeight;Te.style.height=`${Math.min(Ve,120)}px`,Te.style.overflowY=Ve>120?"auto":"hidden"}},[u]);const ye=F.useMemo(()=>e.isStreaming&&(!e.content||e.content==="…")?j.jsx("div",{className:ee,children:j.jsxs("div",{className:"flex items-center gap-1.5 py-1",children:[j.jsx("span",{className:"inline-block h-2.5 w-2.5 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"0ms"}}),j.jsx("span",{className:"inline-block h-2.5 w-2.5 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"150ms"}}),j.jsx("span",{className:"inline-block h-2.5 w-2.5 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"300ms"}})]})}):j.jsx(LD,{content:HD(Jh(e.content||"")),className:ee,syntaxTheme:te}),[ee,e.content,e.isStreaming,te]),je=F.useMemo(()=>[...Y].sort((Te,Ve)=>{const et=Te.timestamp instanceof Date?Te.timestamp.getTime():new Date(Te.timestamp).getTime(),rt=Ve.timestamp instanceof Date?Ve.timestamp.getTime():new Date(Ve.timestamp).getTime();return et-rt}).map(Te=>{const Ve=Te.role==="assistant",et=Ve?ie:K,rt=Te.isStreaming&&(!Te.content||Te.content==="…")?j.jsx("div",{className:et,children:j.jsxs("div",{className:"flex items-center gap-1.5 py-1",children:[j.jsx("span",{className:"inline-block h-2 w-2 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"0ms"}}),j.jsx("span",{className:"inline-block h-2 w-2 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"150ms"}}),j.jsx("span",{className:"inline-block h-2 w-2 animate-bounce rounded-full bg-gray-400 dark:bg-[#bfc2cd]",style:{animationDelay:"300ms"}})]})}):j.jsx(LD,{content:HD(Jh(Te.content||"")),className:et,syntaxTheme:te});return j.jsxs("div",{className:"flex items-start gap-3",children:[j.jsx("div",{className:`mt-0.5 flex h-7 w-7 flex-shrink-0 items-center justify-center rounded-full ${Ve?"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:Ve?j.jsx(tR,{className:"h-3.5 w-3.5"}):j.jsx(nR,{className:"h-3.5 w-3.5"})}),j.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:[j.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:[j.jsx("span",{children:Ve?"Assistant":"You"}),j.jsx("span",{children:Ee(Te.timestamp)})]}),j.jsx("div",{className:"thread-markdown-wrapper overflow-x-auto",children:rt})]})]},Te.id)}),[Ee,te,ie,Y,K]);return j.jsxs("div",{className:"group flex items-start gap-3 px-1 animate-fadeIn min-w-0 sm:px-0",children:[j.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 ${P}`,children:I?j.jsx(tR,{className:"h-5 w-5"}):j.jsx(nR,{className:"h-5 w-5"})}),j.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[j.jsxs("div",{className:"flex flex-col gap-1.5 mb-1",children:[j.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-gray-700 dark:text-[#ececf1]",children:I?"Assistant":"You"}),j.jsx("span",{className:"text-xs text-gray-500 dark:text-[#bfc2cd]",children:$})]}),j.jsxs("div",{className:oe,children:[ye,e.attachments&&e.attachments.length>0&&j.jsx("div",{className:"mt-3 space-y-2",children:e.attachments.map(Se=>j.jsxs("div",{className:`flex items-center gap-3 rounded-xl border p-3 ${le}`,children:[j.jsx(w0e,{className:"h-4 w-4 text-gray-500 dark:text-[#bfc2cd]"}),j.jsxs("div",{className:"min-w-0 flex-1",children:[j.jsx("p",{className:"truncate text-sm font-medium text-[#353740] dark:text-[#ececf1]",children:Se.filename}),j.jsxs("p",{className:"text-xs text-gray-500 dark:text-[#bfc2cd]",children:[(Se.file_size/1024).toFixed(1)," KB"]})]})]},Se.file_id))}),e.audio&&I&&!e.isStreaming&&j.jsx(Brt,{audio:e.audio,audioFormat:e.audioFormat,autoPlay:!1})]}),I&&!e.isStreaming&&j.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:[j.jsxs("button",{onClick:O,className:"inline-flex items-center gap-1 rounded px-2 py-1 hover:bg-gray-200 dark:hover:bg-[#3c3f4a]",title:"Copy message",children:[j.jsx(B0e,{className:"h-4 w-4"}),j.jsx("span",{className:"hidden sm:inline",children:"Copy"})]}),t&&j.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:[j.jsx(D0e,{className:"h-4 w-4"}),j.jsx("span",{className:"hidden sm:inline",children:"Retry"})]}),G&&r&&e.supportsThreading&&!e.threadInfo&&A&&j.jsxs("button",{onClick:()=>r(e.id,A),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:[j.jsx(Yh,{className:"h-4 w-4"}),j.jsx("span",{className:"hidden sm:inline",children:"Start Thread"})]}),grt()&&j.jsxs("div",{className:"flex items-center gap-1",children:[j.jsx("button",{onClick:()=>de("up"),className:`rounded p-1 hover:bg-gray-200 dark:hover:bg-[#3c3f4a] ${l==="up"?"text-[#353740] dark:text-[#ececf1]":""}`,title:"Good response",children:j.jsx(v0e,{className:"h-4 w-4"})}),j.jsx("button",{onClick:()=>de("down"),className:`rounded p-1 hover:bg-gray-200 dark:hover:bg-[#3c3f4a] ${l==="down"?"text-[#353740] dark:text-[#ececf1]":""}`,title:"Poor response",children:j.jsx(U0e,{className:"h-4 w-4"})})]}),s&&j.jsx("span",{children:"Copied"})]}),G&&e.threadInfo&&j.jsxs("div",{className:"ml-0 sm:ml-12 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:[j.jsxs("div",{className:"flex items-center justify-between gap-2 text-sm font-semibold text-blue-900 dark:text-[#c5d7ff]",children:[j.jsxs("div",{className:"inline-flex items-center gap-2 uppercase tracking-wide text-xs sm:text-sm",children:[j.jsx(Yh,{className:"h-3.5 w-3.5"}),j.jsxs("span",{children:["Thread",Q>0?` (${Q})`:""]})]}),j.jsx("button",{onClick:()=>d(Se=>!Se),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:h?j.jsxs(j.Fragment,{children:[j.jsx("span",{className:"hidden sm:inline",children:"Hide"}),j.jsx(d0e,{className:"h-4 w-4 sm:h-3 sm:w-3"})]}):j.jsxs(j.Fragment,{children:[j.jsx("span",{className:"hidden sm:inline",children:"Show"}),j.jsx(FX,{className:"h-4 w-4 sm:h-3 sm:w-3"})]})})]}),h&&j.jsxs(j.Fragment,{children:[j.jsx("div",{className:"mt-3 space-y-3",children:je}),j.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:j.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-3",children:[j.jsx("textarea",{ref:y,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:Se=>g(Se.target.value),onKeyDown:pe,disabled:xe,rows:1,maxLength:T,style:{minHeight:"44px",maxHeight:"120px",outline:"none",boxShadow:"none",WebkitAppearance:"none",MozAppearance:"none",appearance:"none"}}),j.jsxs("div",{className:"flex items-center justify-between sm:justify-end gap-2",children:[u.length>0&&j.jsx("div",{className:"text-xs text-gray-500 dark:text-[#bfc2cd] whitespace-nowrap",children:j.jsxs("span",{className:u.length>=T?"text-red-600 font-semibold":"",children:[u.length,"/",T]})}),j.jsx("button",{type:"button",onClick:Ce,disabled:xe||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&&!xe?"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:B?j.jsx(Ag,{className:"h-5 w-5 sm:h-4 sm:w-4 animate-spin"}):j.jsx(MX,{className:"h-5 w-5 sm:h-4 sm:w-4"})})]})]})})]})]})]})]})}function frt(e=800,t=100,r="sine"){try{if(typeof window>"u"){Je("[SoundEffects] Window is not available for audio playback");return}const n=window.AudioContext??window.webkitAudioContext;if(!n){Je("[SoundEffects] AudioContext not supported in this browser");return}const i=new n,A=i.createOscillator(),a=i.createGain();A.connect(a),a.connect(i.destination),A.frequency.value=e,A.type=r,a.gain.setValueAtTime(.3,i.currentTime),a.gain.exponentialRampToValueAtTime(.01,i.currentTime+t/1e3),A.start(i.currentTime),A.stop(i.currentTime+t/1e3)}catch{}}const yrt={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 mh(e,t){if(!t)return;const r=yrt[e];if(r)try{frt(r.frequency,r.duration,r.type),Je(`[SoundEffects] Playing ${e} sound effect`)}catch{}}function Ert({messages:e,onRegenerate:t,onStartThread:r,onSendThreadMessage:n,sessionId:i,isLoading:A}){const a=F.useRef(null),s=F.useRef(null),o=F.useRef(e.length),l=F.useRef(""),c=F.useRef(A),u=F.useRef(!0),{settings:g}=cy(),{topLevelMessages:h,threadLookup:d}=F.useMemo(()=>{const w=new Map,y=[];return e.forEach(I=>{if(I.isThreadMessage&&I.parentMessageId){const Y=w.get(I.parentMessageId)||[];w.set(I.parentMessageId,[...Y,I]);return}y.push(I)}),{topLevelMessages:y,threadLookup:w}},[e]),B=()=>{if(!s.current)return;const{scrollTop:w,scrollHeight:y,clientHeight:I}=s.current,Q=y-w-I<200;u.current=Q},f=(w="smooth")=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{a.current?a.current.scrollIntoView({behavior:w}):s.current&&(s.current.scrollTop=s.current.scrollHeight)})})};return F.useEffect(()=>{const w=e.length,y=o.current,I=w>y,Y=e[e.length-1],Q=(Y==null?void 0:Y.content)||"",M=Q!==l.current;I||Y!=null&&Y.isStreaming||M&&(Y==null?void 0:Y.role)==="assistant"?(f(I?"auto":"smooth"),u.current=!0):u.current&&M&&f("smooth"),o.current=w,l.current=Q},[e]),F.useEffect(()=>{A&&(f("auto"),u.current=!0)},[A]),F.useEffect(()=>{if(c.current&&!A){const w=e[e.length-1];(w==null?void 0:w.role)==="assistant"&&w.content&&mh("messageReceived",g.soundEnabled)}c.current=A},[A,e,g.soundEnabled]),h.length===0?j.jsx("div",{className:"flex-1 flex items-center justify-center px-4 sm:px-6",children:j.jsxs("div",{className:"text-center text-lg text-gray-500 dark:text-[#bfc2cd]",children:[j.jsx("p",{className:"text-xl",children:"Your messages will appear here."}),j.jsx("p",{className:"mt-1 text-lg",children:"Start the conversation by sending a prompt below."})]})}):j.jsx("div",{ref:s,className:"message-list flex-1 overflow-y-auto py-6",onScroll:B,children:j.jsxs("div",{className:"space-y-6 px-3 sm:px-4",children:[h.map(w=>j.jsx(wrt,{message:w,onRegenerate:t,onStartThread:r,onSendThreadMessage:n,threadMessages:d.get(w.id),sessionId:i,isThreadSendDisabled:A},w.id)),j.jsx("div",{ref:a,className:"h-8"})]})})}const Irt=2e3;function Crt(e,t){const[r,n]=F.useState(!1),[i,A]=F.useState(null),a=F.useRef(null),s=F.useRef(""),o=F.useRef(!1),l=F.useRef(null),c=F.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=F.useCallback(()=>{!t||o.current||(o.current=!0,t())},[t]),h=F.useCallback(()=>{l.current!==null&&(clearTimeout(l.current),l.current=null)},[]),d=F.useCallback(()=>{h(),l.current=setTimeout(()=>{a.current?a.current.stop():g()},Irt)},[h,g]),B=F.useCallback(()=>{if(!u){A("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,y=new w;y.continuous=!0,y.interimResults=!0,y.lang=navigator.language||"en-US",y.maxAlternatives=1,y.onstart=()=>{n(!0),A(null),Je("Speech recognition started"),d()},y.onresult=I=>{let Y="",Q="";for(let M=I.resultIndex;M<I.results.length;M++){const D=I.results[M][0].transcript;I.results[M].isFinal?Y+=D:Q+=D}Q&&(s.current=Q),Y&&(s.current="",e(" "+Y)),d()},y.onend=()=>{h(),c(),n(!1),a.current=null,Je("Speech recognition ended"),g()},y.onerror=I=>{switch(h(),jg("Speech recognition error:",I.error),n(!1),a.current=null,s.current="",g(),I.error){case"no-speech":A("No speech detected. Please try again.");break;case"audio-capture":A("Microphone access denied. Please allow microphone access and try again.");break;case"not-allowed":A("Microphone access not allowed. Please enable microphone permissions.");break;case"network":A("Network error occurred. Please check your connection.");break;default:A(`Speech recognition error: ${I.error}`)}},y.start(),a.current=y}catch{A("Failed to start speech recognition. Please try again."),n(!1)}},[u,e,r,c,g,d,h]),f=F.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}h(),c(),n(!1),A(null),g()},[h,c,g]);return{isListening:r,isSupported:u,startListening:B,stopListening:f,error:i}}const Qrt="2.3.7",Mrt={"@schmitech/chatbot-api":"^2.1.2"},Ele={version:Qrt,dependencies:Mrt},Ile=Ele.version,_K=Ele.dependencies["@schmitech/chatbot-api"];async function JD(){try{return(await nr(()=>import("./api-BI2PB5P1.js"),[])).version||_K}catch{return _K}}async function Cle(){const e=await JD();return{appVersion:Ile,apiVersion:e,isLocalApi:!1}}let Ps=null;function $0(){let e=null,t=null;const r=(i,A,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(i,A,a,s,o,l,c,u,g,h,d){var w,y;const B={messages:[{role:"user",content:i}],stream:A!==!1};a&&a.length>0&&(B.file_ids=a),s&&(B.thread_id=s),o&&(B.audio_input=o),l&&(B.audio_format=l),c&&(B.language=c),u!==void 0&&(B.return_audio=u),g&&(B.tts_voice=g),h&&(B.source_language=h),d&&(B.target_language=d);const f=await fetch("/api/proxy/v1/chat",{method:"POST",headers:{"Content-Type":"application/json","X-Adapter-Name":t,...e?{"X-Session-ID":e}:{}},body:JSON.stringify(B)});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 I=(y=f.body)==null?void 0:y.getReader(),Y=new TextDecoder;let Q="";if(!I)throw new Error("Response body is not readable");for(;;){const{done:M,value:D}=await I.read();if(M)break;Q+=Y.decode(D,{stream:!0});const G=Q.split(`
1211
1211
  `);Q=G.pop()||"";for(const T of G)if(T.startsWith("data: "))try{const R=JSON.parse(T.substring(6));yield{text:R.text||R.content||R.message||R.response||"",done:R.done||!1,audio:R.audio,audioFormat:R.audio_format||R.audioFormat,audio_chunk:R.audio_chunk,chunk_index:R.chunk_index,threading:R.threading}}catch{}}if(Q.trim()){const M=Q.split(`
1212
- `);for(const D of M)if(D.startsWith("data: "))try{const G=JSON.parse(D.substring(6));yield{text:G.text||G.content||G.message||G.response||"",done:G.done||!1,audio:G.audio,audioFormat:G.audio_format||G.audioFormat,audio_chunk:G.audio_chunk,chunk_index:G.chunk_index,threading:G.threading}}catch{}}}else{const I=await f.json();yield{text:I.message||I.response||"",done:!0}}},async createThread(i,A){const a=await fetch("/api/proxy/api/threads",{method:"POST",headers:{"Content-Type":"application/json","X-Adapter-Name":t,"X-Session-ID":A},body:JSON.stringify({message_id:i,session_id:A})});if(!a.ok)throw new Error(`Failed to create thread: ${a.statusText}`);return a.json()},async getThreadInfo(i){const A=await fetch(`/api/proxy/api/threads/${i}`,{headers:{"X-Adapter-Name":t}});if(!A.ok)throw new Error(`Failed to get thread info: ${A.statusText}`);return A.json()},async deleteThread(i){const A=await fetch(`/api/proxy/api/threads/${i}`,{method:"DELETE",headers:{"X-Adapter-Name":t}});if(!A.ok)throw new Error(`Failed to delete thread: ${A.statusText}`);return A.json()},async clearConversationHistory(i){const A=await fetch(`/api/proxy/admin/chat-history/${i||e}`,{method:"DELETE",headers:{"X-Adapter-Name":t}});if(!A.ok)throw new Error(`Failed to clear history: ${A.statusText}`);return A.json()},async deleteConversationWithFiles(i,A){const a=i||e,s=A&&A.length>0?`?file_ids=${A.join(",")}`:"",o=await fetch(`/api/proxy/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(i){const A=new FormData;A.append("file",i);const a=await fetch("/api/proxy/api/files/upload",{method:"POST",headers:{"X-Adapter-Name":t},body:A});if(!a.ok)throw new Error(`Failed to upload file: ${a.statusText}`);return a.json()},async listFiles(){const i=await fetch("/api/proxy/api/files",{headers:{"X-Adapter-Name":t}});if(!i.ok)throw new Error(`Failed to list files: ${i.statusText}`);const A=await i.json();return Array.isArray(A)?A:A.files||[]},async getFileInfo(i){const A=await fetch(`/api/proxy/api/files/${i}`,{headers:{"X-Adapter-Name":t}});if(!A.ok)throw new Error(`Failed to get file info: ${A.statusText}`);return A.json()},async queryFile(i,A,a){const s=await fetch(`/api/proxy/api/files/${i}/query`,{method:"POST",headers:{"Content-Type":"application/json","X-Adapter-Name":t},body:JSON.stringify({query:A,max_results:a})});if(!s.ok)throw new Error(`Failed to query file: ${s.statusText}`);return s.json()},async deleteFile(i){const A=await fetch(`/api/proxy/api/files/${i}`,{method:"DELETE",headers:{"X-Adapter-Name":t}});if(!A.ok)throw new Error(`Failed to delete file: ${A.statusText}`);return A.json()},async validateApiKey(){const i=await fetch(`/api/proxy/admin/api-keys/${t}/status`,{headers:{"X-Adapter-Name":t}});if(!i.ok)throw new Error(`Failed to validate API key: ${i.statusText}`);return i.json()},async getAdapterInfo(){const i=await fetch("/api/proxy/admin/api-keys/info",{headers:{"X-Adapter-Name":t}});if(!i.ok){const A=await i.text();throw new Error(`Failed to get adapter info: ${i.status} ${i.statusText} - ${A}`)}return i.json()}}};return{configureApi:r,streamChat:async function*(i,A,a,s,o,l,c,u,g,h,d){yield*n().streamChat(i,A,a,s,o,l,c,u,g,h,d)},ApiClient:class{constructor(A){gA(this,"client");t=A.adapterName||null,e=A.sessionId||null,this.client=n()}async*streamChat(...A){yield*this.client.streamChat(...A)}get createThread(){var A;return(A=this.client.createThread)==null?void 0:A.bind(this.client)}get getThreadInfo(){var A;return(A=this.client.getThreadInfo)==null?void 0:A.bind(this.client)}get deleteThread(){var A;return(A=this.client.deleteThread)==null?void 0:A.bind(this.client)}get clearConversationHistory(){var A;return(A=this.client.clearConversationHistory)==null?void 0:A.bind(this.client)}get deleteConversationWithFiles(){var A;return(A=this.client.deleteConversationWithFiles)==null?void 0:A.bind(this.client)}get getSessionId(){var A;return(A=this.client.getSessionId)==null?void 0:A.bind(this.client)}get uploadFile(){var A;return(A=this.client.uploadFile)==null?void 0:A.bind(this.client)}get listFiles(){var A;return(A=this.client.listFiles)==null?void 0:A.bind(this.client)}get getFileInfo(){var A;return(A=this.client.getFileInfo)==null?void 0:A.bind(this.client)}get queryFile(){var A;return(A=this.client.queryFile)==null?void 0:A.bind(this.client)}get deleteFile(){var A;return(A=this.client.deleteFile)==null?void 0:A.bind(this.client)}get validateApiKey(){var A;return(A=this.client.validateApiKey)==null?void 0:A.bind(this.client)}get getAdapterInfo(){var A;return(A=this.client.getAdapterInfo)==null?void 0:A.bind(this.client)}}}}async function Frt(e){return e==="@local-node-api/api.mjs"?nr(()=>import("./api-BHF9IxKN.js"),[]):import(e)}async function Yrt(){if(Ps)return Ps;const e=ort(),t=lrt(),r=Wn();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",Je(`🔧 Loading local API from: ${n}`);const i=await Frt(n);r?(Je("🔐 API Middleware enabled - routing through proxy"),Ps=$0()):Ps={configureApi:i.configureApi,streamChat:i.streamChat,ApiClient:i.ApiClient},Je("✅ Local API loaded successfully")}else{Je("📦 Loading npm package API");const n=await nr(()=>import("./api-WG4VIze6.js"),[]),i=async function*(s,o,l,c,u,g,h,d,B,f,w){yield*n.streamChat(s,o,l,c,u,g,h,d,B,f,w)};class A{constructor(o){gA(this,"client");if(r&&o.adapterName){const l=$0();this.client=new l.ApiClient(o)}else this.client=new n.ApiClient(o)}async*streamChat(o,l,c,u,g,h,d,B,f,w,y){yield*this.client.streamChat(o,l,c,u,g,h,d,B,f,w,y)}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 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?(Je("🔐 API Middleware enabled - routing through proxy"),Ps=$0()):Ps={configureApi:n.configureApi,streamChat:i,ApiClient:A};const a=await JD();Je(`✅ NPM package API loaded successfully (v${a})`)}}catch(n){if(e)try{const i=await nr(()=>import("./api-WG4VIze6.js"),[]),A=async function*(o,l,c,u,g,h,d,B,f,w,y){yield*i.streamChat(o,l,c,u,g,h,d,B,f,w,y)};class a{constructor(l){gA(this,"client");if(r&&l.adapterName){const c=$0();this.client=new c.ApiClient(l)}else this.client=new i.ApiClient(l)}async*streamChat(l,c,u,g,h,d,B,f,w,y,I){yield*this.client.streamChat(l,c,u,g,h,d,B,f,w,y,I)}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 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?(Je("🔐 API Middleware enabled - routing through proxy"),Ps=$0()):Ps={configureApi:i.configureApi,streamChat:A,ApiClient:a};const s=await JD();Je(`✅ Fallback to NPM package successful (v${s})`)}catch{throw new Error("Failed to load both local and npm API packages")}else throw n}return Ps}async function ci(){return await Yrt()}const im=Fc(),brt=()=>{try{if(typeof window>"u"||!window.localStorage)return null;const e=window.localStorage.getItem("chat-api-url");return e&&e===$c?(window.localStorage.removeItem("chat-api-url"),null):e}catch{return null}},eh=e=>{const t=e==null?void 0:e.trim();if(t)return t;const r=brt();return r&&r!==$c?r:Rn()},Am=()=>typeof window>"u"?null:window.CHATBOT_API_KEY||null;class Td{static async uploadFile(t,r,n,i,A){try{const a=Nr.maxFileSizeMB*1024*1024;if(t.size>a)throw new Error(`File size exceeds maximum limit of ${Nr.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 ci(),c=eh(i),u=Wn();let g=null,h=null;if(u){if(h=A||(typeof window<"u"?localStorage.getItem("chat-adapter-name"):null),!h)throw new Error("Adapter not configured. Please select an adapter from the dropdown.");Je(`🔑 Using adapter: ${h}`)}else{if(g=n||localStorage.getItem("chat-api-key")||Am()||im,!g||g==="your-api-key-here")throw new Error(`API key not configured or invalid. Please:
1212
+ `);for(const D of M)if(D.startsWith("data: "))try{const G=JSON.parse(D.substring(6));yield{text:G.text||G.content||G.message||G.response||"",done:G.done||!1,audio:G.audio,audioFormat:G.audio_format||G.audioFormat,audio_chunk:G.audio_chunk,chunk_index:G.chunk_index,threading:G.threading}}catch{}}}else{const I=await f.json();yield{text:I.message||I.response||"",done:!0}}},async createThread(i,A){const a=await fetch("/api/proxy/api/threads",{method:"POST",headers:{"Content-Type":"application/json","X-Adapter-Name":t,"X-Session-ID":A},body:JSON.stringify({message_id:i,session_id:A})});if(!a.ok)throw new Error(`Failed to create thread: ${a.statusText}`);return a.json()},async getThreadInfo(i){const A=await fetch(`/api/proxy/api/threads/${i}`,{headers:{"X-Adapter-Name":t}});if(!A.ok)throw new Error(`Failed to get thread info: ${A.statusText}`);return A.json()},async deleteThread(i){const A=await fetch(`/api/proxy/api/threads/${i}`,{method:"DELETE",headers:{"X-Adapter-Name":t}});if(!A.ok)throw new Error(`Failed to delete thread: ${A.statusText}`);return A.json()},async clearConversationHistory(i){const A=await fetch(`/api/proxy/admin/chat-history/${i||e}`,{method:"DELETE",headers:{"X-Adapter-Name":t}});if(!A.ok)throw new Error(`Failed to clear history: ${A.statusText}`);return A.json()},async deleteConversationWithFiles(i,A){const a=i||e,s=A&&A.length>0?`?file_ids=${A.join(",")}`:"",o=await fetch(`/api/proxy/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(i){const A=new FormData;A.append("file",i);const a=await fetch("/api/proxy/api/files/upload",{method:"POST",headers:{"X-Adapter-Name":t},body:A});if(!a.ok)throw new Error(`Failed to upload file: ${a.statusText}`);return a.json()},async listFiles(){const i=await fetch("/api/proxy/api/files",{headers:{"X-Adapter-Name":t}});if(!i.ok)throw new Error(`Failed to list files: ${i.statusText}`);const A=await i.json();return Array.isArray(A)?A:A.files||[]},async getFileInfo(i){const A=await fetch(`/api/proxy/api/files/${i}`,{headers:{"X-Adapter-Name":t}});if(!A.ok)throw new Error(`Failed to get file info: ${A.statusText}`);return A.json()},async queryFile(i,A,a){const s=await fetch(`/api/proxy/api/files/${i}/query`,{method:"POST",headers:{"Content-Type":"application/json","X-Adapter-Name":t},body:JSON.stringify({query:A,max_results:a})});if(!s.ok)throw new Error(`Failed to query file: ${s.statusText}`);return s.json()},async deleteFile(i){const A=await fetch(`/api/proxy/api/files/${i}`,{method:"DELETE",headers:{"X-Adapter-Name":t}});if(!A.ok)throw new Error(`Failed to delete file: ${A.statusText}`);return A.json()},async validateApiKey(){const i=await fetch(`/api/proxy/admin/api-keys/${t}/status`,{headers:{"X-Adapter-Name":t}});if(!i.ok)throw new Error(`Failed to validate API key: ${i.statusText}`);return i.json()},async getAdapterInfo(){const i=await fetch("/api/proxy/admin/api-keys/info",{headers:{"X-Adapter-Name":t}});if(!i.ok){const A=await i.text();throw new Error(`Failed to get adapter info: ${i.status} ${i.statusText} - ${A}`)}return i.json()}}};return{configureApi:r,streamChat:async function*(i,A,a,s,o,l,c,u,g,h,d){yield*n().streamChat(i,A,a,s,o,l,c,u,g,h,d)},ApiClient:class{constructor(A){gA(this,"client");t=A.adapterName||null,e=A.sessionId||null,this.client=n()}async*streamChat(...A){yield*this.client.streamChat(...A)}get createThread(){var A;return(A=this.client.createThread)==null?void 0:A.bind(this.client)}get getThreadInfo(){var A;return(A=this.client.getThreadInfo)==null?void 0:A.bind(this.client)}get deleteThread(){var A;return(A=this.client.deleteThread)==null?void 0:A.bind(this.client)}get clearConversationHistory(){var A;return(A=this.client.clearConversationHistory)==null?void 0:A.bind(this.client)}get deleteConversationWithFiles(){var A;return(A=this.client.deleteConversationWithFiles)==null?void 0:A.bind(this.client)}get getSessionId(){var A;return(A=this.client.getSessionId)==null?void 0:A.bind(this.client)}get uploadFile(){var A;return(A=this.client.uploadFile)==null?void 0:A.bind(this.client)}get listFiles(){var A;return(A=this.client.listFiles)==null?void 0:A.bind(this.client)}get getFileInfo(){var A;return(A=this.client.getFileInfo)==null?void 0:A.bind(this.client)}get queryFile(){var A;return(A=this.client.queryFile)==null?void 0:A.bind(this.client)}get deleteFile(){var A;return(A=this.client.deleteFile)==null?void 0:A.bind(this.client)}get validateApiKey(){var A;return(A=this.client.validateApiKey)==null?void 0:A.bind(this.client)}get getAdapterInfo(){var A;return(A=this.client.getAdapterInfo)==null?void 0:A.bind(this.client)}}}}async function Frt(e){return e==="@local-node-api/api.mjs"?nr(()=>import("./api-BHF9IxKN.js"),[]):import(e)}async function Yrt(){if(Ps)return Ps;const e=ort(),t=lrt(),r=Wn();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",Je(`🔧 Loading local API from: ${n}`);const i=await Frt(n);r?(Je("🔐 API Middleware enabled - routing through proxy"),Ps=$0()):Ps={configureApi:i.configureApi,streamChat:i.streamChat,ApiClient:i.ApiClient},Je("✅ Local API loaded successfully")}else{Je("📦 Loading npm package API");const n=await nr(()=>import("./api-BI2PB5P1.js"),[]),i=async function*(s,o,l,c,u,g,h,d,B,f,w){yield*n.streamChat(s,o,l,c,u,g,h,d,B,f,w)};class A{constructor(o){gA(this,"client");if(r&&o.adapterName){const l=$0();this.client=new l.ApiClient(o)}else this.client=new n.ApiClient(o)}async*streamChat(o,l,c,u,g,h,d,B,f,w,y){yield*this.client.streamChat(o,l,c,u,g,h,d,B,f,w,y)}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 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?(Je("🔐 API Middleware enabled - routing through proxy"),Ps=$0()):Ps={configureApi:n.configureApi,streamChat:i,ApiClient:A};const a=await JD();Je(`✅ NPM package API loaded successfully (v${a})`)}}catch(n){if(e)try{const i=await nr(()=>import("./api-BI2PB5P1.js"),[]),A=async function*(o,l,c,u,g,h,d,B,f,w,y){yield*i.streamChat(o,l,c,u,g,h,d,B,f,w,y)};class a{constructor(l){gA(this,"client");if(r&&l.adapterName){const c=$0();this.client=new c.ApiClient(l)}else this.client=new i.ApiClient(l)}async*streamChat(l,c,u,g,h,d,B,f,w,y,I){yield*this.client.streamChat(l,c,u,g,h,d,B,f,w,y,I)}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 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?(Je("🔐 API Middleware enabled - routing through proxy"),Ps=$0()):Ps={configureApi:i.configureApi,streamChat:A,ApiClient:a};const s=await JD();Je(`✅ Fallback to NPM package successful (v${s})`)}catch{throw new Error("Failed to load both local and npm API packages")}else throw n}return Ps}async function ci(){return await Yrt()}const im=Fc(),brt=()=>{try{if(typeof window>"u"||!window.localStorage)return null;const e=window.localStorage.getItem("chat-api-url");return e&&e===$c?(window.localStorage.removeItem("chat-api-url"),null):e}catch{return null}},eh=e=>{const t=e==null?void 0:e.trim();if(t)return t;const r=brt();return r&&r!==$c?r:Rn()},Am=()=>typeof window>"u"?null:window.CHATBOT_API_KEY||null;class Td{static async uploadFile(t,r,n,i,A){try{const a=Nr.maxFileSizeMB*1024*1024;if(t.size>a)throw new Error(`File size exceeds maximum limit of ${Nr.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 ci(),c=eh(i),u=Wn();let g=null,h=null;if(u){if(h=A||(typeof window<"u"?localStorage.getItem("chat-adapter-name"):null),!h)throw new Error("Adapter not configured. Please select an adapter from the dropdown.");Je(`🔑 Using adapter: ${h}`)}else{if(g=n||localStorage.getItem("chat-api-key")||Am()||im,!g||g==="your-api-key-here")throw new Error(`API key not configured or invalid. Please:
1213
1213
  1. Open Settings (⚙️ icon) in the top-right corner
1214
1214
  2. Enter a valid API key
1215
1215
  3. To create an API key: POST to /admin/api-keys with admin credentials
@@ -1233,4 +1233,4 @@ ${O0e}`,nrt=()=>{if(typeof document>"u"||document.getElementById(XK))return;cons
1233
1233
  ]`;try{const t=JSON.parse(e);if(Array.isArray(t)){Je("Loading adapters from VITE_ADAPTERS environment variable");const r=t.map(tV).filter(n=>n!==null);if(r.length>0)return r}}catch{}return null}async function Qle(){if(_l)return _l;try{const t=await fetch("/api/adapters");if(t.ok)return _l=(await t.json()).adapters,Je("Fetched adapters from /api/adapters:",_l),_l;Je(`/api/adapters returned ${t.status}, trying fallback`)}catch{}const e=Srt();if(e&&e.length>0)return _l=e,_l;throw new Error("No adapters available. Configure VITE_ADAPTERS environment variable.")}async function Mle(){try{const e=await Qle();return e.length>0?e[0]:null}catch{return null}}class Urt{constructor(){gA(this,"audioQueue",[]);gA(this,"isPlaying",!1);gA(this,"currentAudio",null);gA(this,"audioContext",null);gA(this,"isEnabled",!1);gA(this,"onPlaybackStart",null);gA(this,"onPlaybackEnd",null);gA(this,"onChunkPlayed",null);gA(this,"blobUrls",[]);gA(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{Je("[AudioStreamManager] Silent audio unlock deferred (will work on next interaction)")}return this.isEnabled=!0,Je("[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){Je(`[AudioStreamManager] Audio disabled, dropping chunk ${t.chunkIndex}`);return}Je(`[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(),Je(`[AudioStreamManager] Playing chunk ${t.chunkIndex}`),!t.audio||t.audio.length===0)throw new Error(`Empty audio data for chunk ${t.chunkIndex}`);let i;try{i=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(i.length===0)throw new Error(`Decoded audio data is empty for chunk ${t.chunkIndex}`);const A=new Uint8Array(i.length);for(let u=0;u<i.length;u++)A[u]=i.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([A],{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 h=!1;const d=()=>{var y;if(h)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){h=!0,c(),u();return}h=!0,console.error(`[AudioStreamManager] Error playing chunk ${t.chunkIndex}:`,w,{audioFormat:t.audioFormat,chunkIndex:t.chunkIndex,audioLength:t.audio.length,mimeType:a,audioContextState:(y=this.audioContext)==null?void 0:y.state,audioSrc:l.src,audioReadyState:l.readyState}),jg(`[AudioStreamManager] Error playing chunk ${t.chunkIndex}:`,w),c(),g(new Error(`Audio playback error: ${JSON.stringify(w)}`))};l.addEventListener("error",d,{once:!0});const B=async()=>{var f;if(!h)try{l.addEventListener("ended",()=>{h||(h=!0,Je(`[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(h)return;if(this.suppressPlaybackErrors){h=!0,c(),u();return}h=!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?B():l.addEventListener("canplay",B,{once:!0})}),this.currentAudio=null,this.playNextChunk()}catch(i){if(this.suppressPlaybackErrors)return;const A=i instanceof Error?i.message:String(i);console.error(`[AudioStreamManager] Failed to play chunk ${t.chunkIndex}:`,A,i,{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}),jg(`[AudioStreamManager] Failed to play chunk ${t.chunkIndex}:`,i),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 mc=new Urt,On=Fc(),Pf=()=>{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},vrt=e=>{localStorage.setItem("chatbot-session-id",e)};let Grt=0;const fN=e=>{const t=Date.now(),r=++Grt,n=Math.random().toString(36).substr(2,9);return`msg_${t}_${r}_${n}_${e}`},io=()=>{const e=Date.now(),t=Math.random().toString(36).substr(2,9);return`session_${e}_${t}`};let Yc=!1,bc="";async function qo(){if(Yc&&bc)return!0;try{const e=await ci(),t=localStorage.getItem("chat-api-url");t&&t===$c&&localStorage.removeItem("chat-api-url");const r=t&&t!==$c?t:Rn(),n=localStorage.getItem("chat-api-key")||On,i=Pf();return e.configureApi(r,n,i),bc=r,Yc=!0,!0}catch(e){return li("Failed to configure API:",e),!1}}const Ot=krt((e,t)=>({conversations:[],currentConversationId:null,isLoading:!1,error:null,sessionId:Pf(),getSessionId:()=>t().sessionId,configureApiSettings:async(r,n,i,A)=>{const a=t(),s=a.conversations.find(c=>c.id===a.currentConversationId),o=Wn(),l=(s==null?void 0:s.sessionId)||i||Pf();i&&vrt(i),e({sessionId:l});try{const c=await ci();if(o){if(!A||!A.trim())throw new Error("Adapter name is required when API middleware is enabled");c.configureApi(r,null,l,A),bc=r,Yc=!0;let u;try{const g=new c.ApiClient({apiUrl:r,apiKey:null,sessionId:null,adapterName:A});typeof g.getAdapterInfo=="function"&&(u=await g.getAdapterInfo(),Je("Adapter info loaded:",u))}catch(g){Ir("Failed to load adapter info:",g)}if(s)e(g=>({conversations:g.conversations.map(h=>h.id===s.id?{...h,adapterName:A,apiUrl:r,adapterInfo:u,apiKey:void 0,updatedAt:new Date}:h)}));else if(A&&A.trim()){const g=`conv_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,h=io();e(d=>({conversations:[...d.conversations,{id:g,sessionId:h,title:"New Conversation",messages:[],createdAt:new Date,updatedAt:new Date,adapterName:A,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"){Je("Validating API key before configuration...");const h=await g.validateApiKey();Je("API key validation successful:",{exists:h.exists,active:h.active,adapter_name:h.adapter_name,client_name:h.client_name})}else Ir("API key validation not available (validateApiKey method not found)");if(typeof g.getAdapterInfo=="function")try{u=await g.getAdapterInfo(),Je("Adapter info loaded:",u)}catch(h){Ir("Failed to load adapter info:",h)}}catch(g){throw g instanceof Error?g:new Error(`API key validation failed: ${String(g)}`)}if(c.configureApi(r,n||"",l),bc=r,Yc=!0,s&&n&&n.trim())e(g=>({conversations:g.conversations.map(h=>h.id===s.id?{...h,apiKey:n,apiUrl:r,adapterInfo:u,adapterName:void 0,updatedAt:new Date}:h)})),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)}`,h=io(),d={id:g,sessionId:h,title:"New Chat",messages:[],createdAt:new Date,updatedAt:new Date,apiKey:n,apiUrl:r,adapterInfo:u};e(B=>{let f=[d,...B.conversations];const w=Nr.maxConversations;return w!==null&&f.length>w&&(f=f.slice(0,w)),{conversations:f,currentConversationId:g,sessionId:h}}),setTimeout(()=>{const B=t();localStorage.setItem("chat-state",JSON.stringify({conversations:B.conversations,currentConversationId:B.currentConversationId}))},0)}}}catch(c){throw e({isLoading:!1}),c instanceof Error?c:new Error("Failed to configure API settings")}o?A?localStorage.setItem("chat-adapter-name",A):localStorage.removeItem("chat-adapter-name"):(r&&r!==$c?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=Nr.maxConversations,i=r.conversations.length,A=r.currentConversationId?r.conversations.find(h=>h.id===r.currentConversationId):null;if(n!==null&&i>=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(A&&A.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=io(),o=Rn(),l=On,c=Wn(),u=c&&typeof window<"u"?localStorage.getItem("chat-adapter-name"):null,g={id:a,sessionId:s,title:"New Chat",messages:[],createdAt:new Date,updatedAt:new Date,apiKey:c?void 0:l,apiUrl:o,adapterName:u||void 0};return e(h=>{let d=[g,...h.conversations];const B=Nr.maxConversations;return B!==null&&d.length>B&&(d=d.slice(0,B)),{conversations:d,currentConversationId:a,sessionId:s}}),qo().then(h=>{h&&ci().then(d=>{c&&u?d.configureApi(o,null,s,u):d.configureApi(o,l,s);try{const B=new d.ApiClient({apiUrl:o,apiKey:c?null:l,sessionId:null,adapterName:c?u:null});typeof B.getAdapterInfo=="function"&&B.getAdapterInfo().then(f=>{Je("✅ Adapter info loaded for new conversation:",f);const w=Ot.getState();Ot.setState({conversations:w.conversations.map(y=>y.id===a?{...y,adapterInfo:f,updatedAt:new Date}:y)})}).catch(f=>{Ir("Failed to load adapter info for new conversation:",f)})}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(i=>i.id===r);if(n){const i=n.messages.some(o=>o.role==="assistant"&&o.isStreaming);e({currentConversationId:r,sessionId:n.sessionId,isLoading:i});const A=n.apiUrl||Rn(),a=n.apiKey||On;if(await qo()){const o=await ci();if(o.configureApi(A,a,n.sessionId),!n.adapterInfo)try{const l=new o.ApiClient({apiUrl:A,apiKey:a,sessionId:null});if(typeof l.getAdapterInfo=="function"){const c=await l.getAdapterInfo();Je("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 i=t();localStorage.setItem("chat-state",JSON.stringify({conversations:i.conversations,currentConversationId:i.currentConversationId}))},0)},deleteConversation:async r=>{var A,a;const n=t(),i=n.conversations.find(s=>s.id===r);if(Je(`🗑️ Deleting conversation ${r}:`,{conversationId:r,sessionId:i==null?void 0:i.sessionId,title:i==null?void 0:i.title,messageCount:i==null?void 0:i.messages.length,fileCount:((A=i==null?void 0:i.attachedFiles)==null?void 0:A.length)||0}),n.currentConversationId===r&&mc.stop(),i!=null&&i.sessionId)try{if(!await qo())li("Failed to configure API for conversation deletion");else{const o=Wn(),l=i.apiUrl||Rn(),c=i.apiKey||On,u=i.adapterName;o?u?Je(`🔑 Using conversation's adapter for deletion: ${u} (conversation: ${r})`):Ir(`Skipping server deletion for conversation ${r}: adapter not configured`):Je(`🔑 Using conversation's API key for deletion: ${c.substring(0,8)}... (conversation: ${r})`);const g=await ci(),h=new g.ApiClient({apiUrl:l,apiKey:o?null:c,sessionId:i.sessionId,adapterName:o?u:null}),d=((a=i==null?void 0:i.attachedFiles)==null?void 0:a.map(B=>B.file_id))||[];if(Je(`🔧 Calling deleteConversationWithFiles for session: ${i.sessionId}`),Je(`🔧 File IDs to delete: ${d.join(", ")||"none"}`),h.deleteConversationWithFiles){const B=await h.deleteConversationWithFiles(i.sessionId,d);Je(`✅ Deleted conversation and files for session: ${i.sessionId}`,B),Je(` - Deleted ${B.deleted_messages} messages`),Je(` - Deleted ${B.deleted_files} files`),B.file_deletion_errors&&B.file_deletion_errors.length>0&&Ir(` - Errors deleting files: ${B.file_deletion_errors.join(", ")}`)}else Ir("⚠️ deleteConversationWithFiles method not available on API client")}}catch(s){li("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=io(),h=Rn(),d={id:u,sessionId:g,title:"New Chat",messages:[],createdAt:new Date,updatedAt:new Date,apiKey:On,apiUrl:h};return qo().then(B=>{B&&ci().then(f=>{f.configureApi(h,On,g);try{const w=new f.ApiClient({apiUrl:h,apiKey:On,sessionId:null});typeof w.validateApiKey=="function"&&w.validateApiKey().then(()=>{Je("✅ Default API key validated after creating new conversation")}).catch(()=>{Ir("Failed to validate default API key")}),typeof w.getAdapterInfo=="function"&&w.getAdapterInfo().then(y=>{Je("✅ Adapter info loaded for default key:",y);const I=Ot.getState();Ot.setState({conversations:I.conversations.map(Y=>Y.id===u?{...Y,adapterInfo:y,updatedAt:new Date}:Y)})}).catch(()=>{Ir("Failed to load adapter info for default key")})}catch{}})}),setTimeout(()=>{localStorage.setItem("chat-state",JSON.stringify({conversations:[d],currentConversationId:u}))},0),{conversations:[d],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];mc.stop();const i=n.map(async c=>{var u;if(c!=null&&c.sessionId)try{if(!await qo()){li("Failed to configure API for conversation deletion");return}const h=Wn(),d=to(c.apiUrl),B=c.apiKey||On,f=c.adapterName;if(h&&!f){Je(`Skipping server deletion for conversation ${c.id}: adapter not configured`);return}const w=await ci(),y=new w.ApiClient({apiUrl:d,apiKey:h?null:B,sessionId:c.sessionId,adapterName:h?f:null}),I=((u=c==null?void 0:c.attachedFiles)==null?void 0:u.map(Y=>Y.file_id))||[];y.deleteConversationWithFiles?(await y.deleteConversationWithFiles(c.sessionId,I),Je(`✅ Deleted conversation ${c.id} and files`)):Ir(`deleteConversationWithFiles not available for conversation ${c.id}`)}catch(g){li(`Failed to delete conversation ${c.id} from server:`,g)}});Promise.allSettled(i).then(c=>{const u=c.filter(g=>g.status==="rejected");u.length>0&&li(`Some conversations failed to delete from server: ${u.length}`,u)});const A=`conv_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,a=io(),s=Rn(),o=Wn(),l={id:A,sessionId:a,title:"New Chat",messages:[],createdAt:new Date,updatedAt:new Date,apiKey:o?void 0:On,apiUrl:s};qo().then(c=>{c&&ci().then(async u=>{if(o)try{const g=await Mle();if(g){u.configureApi(s,null,a,g.name);const h=new u.ApiClient({apiUrl:s,apiKey:null,sessionId:null,adapterName:g.name});if(typeof h.getAdapterInfo=="function"){const d=await h.getAdapterInfo();Je("✅ Adapter info loaded after clearing conversations:",d);const B=Ot.getState();Ot.setState({conversations:B.conversations.map(f=>f.id===A?{...f,adapterName:g.name,adapterInfo:d,updatedAt:new Date}:f)}),setTimeout(()=>{const f=Ot.getState();localStorage.setItem("chat-state",JSON.stringify({conversations:f.conversations,currentConversationId:f.currentConversationId}))},0)}}}catch{}else{u.configureApi(s,On,a);try{const g=new u.ApiClient({apiUrl:s,apiKey:On,sessionId:null});typeof g.validateApiKey=="function"&&g.validateApiKey().then(()=>{Je("✅ Default API key validated after clearing all conversations")}).catch(()=>{Ir("Failed to validate default API key")}),typeof g.getAdapterInfo=="function"&&g.getAdapterInfo().then(h=>{Je("✅ Adapter info loaded for default key:",h);const d=Ot.getState();Ot.setState({conversations:d.conversations.map(B=>B.id===A?{...B,adapterInfo:h,updatedAt:new Date}:B)})}).catch(()=>{Ir("Failed to load adapter info for default key")})}catch{}}})}),e({conversations:[l],currentConversationId:A,sessionId:a}),setTimeout(()=>{localStorage.setItem("chat-state",JSON.stringify({conversations:[l],currentConversationId:A}))},0)},sendMessage:async(r,n,i)=>{var A,a,s,o,l,c,u,g,h,d,B;try{if(t().isLoading){Ir("Another request is already in progress");return}if(!await qo())throw new Error("API not properly configured. Please configure API settings first.");let w=t().currentConversationId;w||(w=t().createConversation());const y=t().conversations.find(V=>V.id===w);if(!y)throw new Error("Conversation not found");const I=n?n.map(V=>{var ee;const Z=(ee=y==null?void 0:y.attachedFiles)==null?void 0:ee.find(ie=>ie.file_id===V);return Z||{file_id:V,filename:"",mime_type:"",file_size:0}}).filter(V=>V!==void 0):[];I.length>0&&I.forEach(V=>{t().addFileToConversation(w,V)});const Y=i||null;let Q,M=null;if(Y){if(Q=y.messages.find(V=>{var Z;return((Z=V.threadInfo)==null?void 0:Z.thread_id)===Y}),!Q)throw new Error("Thread metadata not found. Please recreate the thread from this message.");if(M=((A=Q.threadInfo)==null?void 0:A.thread_session_id)||null,!M)throw new Error("Thread session is missing. Please recreate the thread from this message.")}const D={id:fN("user"),content:r,role:"user",timestamp:new Date,attachments:I.length>0?I:void 0},G=fN("assistant"),T={id:G,content:"",role:"assistant",timestamp:new Date,isStreaming:!0};Y&&Q&&(D.isThreadMessage=!0,D.threadId=Y,D.parentMessageId=Q.id,T.isThreadMessage=!0,T.threadId=Y,T.parentMessageId=Q.id);let R=!1,L=!1;if(e(V=>{const Z=V.conversations.find($=>$.id===w),ee=(Z==null?void 0:Z.messages.filter($=>$.role==="assistant"&&$.isStreaming))||[];ee.length>0&&Ir(`Cleaning up ${ee.length} existing streaming messages`);const ie=V.conversations.map($=>{if($.id!==w){const O=Nr.maxMessagesPerConversation;if(O!==null){const de=$.messages.filter(Ee=>!(Ee.role==="assistant"&&Ee.isStreaming));if(de.length>=O){R=!0;const Ee=Math.max(1,O-1),Ce=de.slice(-Ee),pe=$.messages.filter(xe=>xe.role==="assistant"&&xe.isStreaming);return{...$,messages:[...Ce,...pe]}}}return $}const P=$.messages.filter(O=>!(O.role==="assistant"&&O.isStreaming)),oe=Nr.maxMessagesPerConversation;let le=P;if(oe!==null&&P.length>=oe){R=!0;const O=Math.max(1,oe-1);le=P.slice(-O)}return{...$,messages:[...le,D,T],updatedAt:new Date,title:$.messages.length===0?r.slice(0,50)+(r.length>50?"...":""):$.title}}),K=Nr.maxTotalMessages;if(K!==null){const $=ie.reduce((P,oe)=>P+oe.messages.filter(le=>!(le.role==="assistant"&&le.isStreaming)).length,0);if($>K){L=!0;let P=$-K;const oe=[...ie].sort((le,O)=>le.updatedAt.getTime()-O.updatedAt.getTime());for(const le of oe){if(P<=0)break;const O=le.messages.filter(de=>!(de.role==="assistant"&&de.isStreaming));if(O.length>0){const de=Math.min(P,O.length),Ee=le.messages.filter(xe=>xe.role==="assistant"&&xe.isStreaming),Ce=[...O.slice(de),...Ee],pe=ie.findIndex(xe=>xe.id===le.id);pe!==-1&&(ie[pe]={...le,messages:Ce}),P-=de}}}}return{conversations:ie,isLoading:!0,error:null}}),R||L){const V=[];R&&Nr.maxMessagesPerConversation!==null&&V.push(`Only the most recent ${Nr.maxMessagesPerConversation} messages are kept per conversation. Older messages in this chat were removed automatically.`),L&&Nr.maxTotalMessages!==null&&V.push(`There is a workspace limit of ${Nr.maxTotalMessages} total messages. Older conversations were trimmed to stay within that limit.`),V.length>0&&e({error:V.join(" ")})}const z=w;let te=!1;mc.reset();try{const V=t().conversations.find(Ne=>Ne.id===z);if(!V)throw new Error("Conversation not found");const Z=Wn();if(Z){if(!V.adapterName)throw Ir(`[sendMessage] Conversation ${z} has no adapter name`),new Error("Adapter not configured for this conversation. Please select an adapter first.");Je(`[sendMessage] Using adapter for conversation ${z}: ${V.adapterName}`)}else{if(!V.apiKey)throw Ir(`[sendMessage] Conversation ${z} has no API key`),new Error("API key not configured for this conversation. Please configure API settings first.");Je(`[sendMessage] Using API key for conversation ${z}: ${V.apiKey.substring(0,8)}...`)}const ee=to(V.apiUrl),ie=V.apiKey,K=V.adapterName,$=i||null,P=M||V.sessionId,oe=await ci();Z?oe.configureApi(ee,null,P,K):oe.configureApi(ee,ie,P),$&&P!==V.sessionId&&Je(`[chatStore] Thread mode: using thread session ${P} (original: ${V.sessionId})`),Je("[chatStore] Starting streamChat with fileIds:",n);const le=t().conversations.find(Ne=>Ne.id===z),O=((s=(a=le==null?void 0:le.adapterInfo)==null?void 0:a.adapter_name)==null?void 0:s.includes("voice"))||((l=(o=le==null?void 0:le.adapterInfo)==null?void 0:o.adapter_name)==null?void 0:l.includes("audio"))||((u=(c=le==null?void 0:le.adapterInfo)==null?void 0:c.adapter_name)==null?void 0:u.includes("multilingual")),de=()=>{try{const Ne=localStorage.getItem("chat-settings");if(Ne)return JSON.parse(Ne).voiceEnabled===!0}catch(Ne){Ir("Failed to read global voice setting:",Ne)}return!1},Ee=le==null?void 0:le.audioSettings,Ce=de(),pe=(Ee==null?void 0:Ee.enabled)??Ce??O,xe=(Ee==null?void 0:Ee.ttsVoice)||void 0,ye=(Ee==null?void 0:Ee.language)||"en-US",je=Ee==null?void 0:Ee.audioFormat;Je("[chatStore] Audio settings:",{returnAudio:pe,ttsVoice:xe,language:ye,audioFormat:je,isVoiceAdapter:O,adapterName:(g=le==null?void 0:le.adapterInfo)==null?void 0:g.adapter_name});for await(const Ne of oe.streamChat(r,!0,n,$||void 0,void 0,void 0,ye,pe,xe)){if(Je("[chatStore] Received stream chunk:",{text:(h=Ne.text)==null?void 0:h.substring(0,50),done:Ne.done,hasAudio:!!Ne.audio,hasAudioChunk:!!Ne.audio_chunk,audioFormat:Ne.audioFormat,audioLength:(d=Ne.audio)==null?void 0:d.length,chunkIndex:Ne.chunk_index}),Ne.audio_chunk){Je("[chatStore] Received audio chunk:",{chunk_index:Ne.chunk_index,audioFormat:Ne.audioFormat,audioLength:(B=Ne.audio_chunk)==null?void 0:B.length});const Qe=Ne.chunk_index??0;mc.addChunk({audio:Ne.audio_chunk,audioFormat:Ne.audioFormat||"opus",chunkIndex:Qe})}if(Ne.text){const Qe=Jh(Ne.text);Qe?(t().appendToLastMessage(Qe,z),te=!0,await new Promise(Se=>setTimeout(Se,30))):Ne.text.length>100&&Ir("[chatStore] Filtered out potential base64 audio data from message content")}if(Ne.audio&&Ne.done&&e(Qe=>({conversations:Qe.conversations.map(Se=>{if(Se.id!==z)return Se;const Te=[...Se.messages],Ve=Te[Te.length-1];return Ve&&Ve.role==="assistant"&&(Te[Te.length-1]={...Ve,audio:Ne.audio,audioFormat:Ne.audioFormat||"mp3"}),{...Se,messages:Te,updatedAt:new Date}})})),Ne.done){Je("[chatStore] Stream completed, receivedAnyText:",te),Je("[chatStore] Done chunk received:",{hasThreading:!!Ne.threading,threading:Ne.threading,assistantMessageId:G});const Qe=Ne.threading;Qe&&Qe.supports_threading&&(e(Se=>({conversations:Se.conversations.map(Te=>Te.id!==z?Te:{...Te,messages:Te.messages.map(Ve=>Ve.id===G?{...Ve,supportsThreading:!0,databaseMessageId:Qe.message_id}:Ve),updatedAt:new Date})})),Je(`[chatStore] Message ${G} marked as supporting threading`,{message_id:Qe.message_id,session_id:Qe.session_id,databaseMessageId:Qe.message_id}));break}}te||(Ir("[chatStore] No text received from stream, showing error message"),t().appendToLastMessage("No response received from the server. Please try again later.",z))}catch(V){li("Chat API error:",V),t().appendToLastMessage("Sorry, there was an error processing your request.",z)}e(V=>{const Z=V.conversations.map(K=>K.id===z?{...K,messages:K.messages.map($=>$.id===G?{...$,isStreaming:!1}:$),updatedAt:new Date}:K),ee=Z.find(K=>K.id===V.currentConversationId),ie=ee?ee.messages.some(K=>K.role==="assistant"&&K.isStreaming):!1;return{conversations:Z,isLoading:ie}}),setTimeout(()=>{const V=t();localStorage.setItem("chat-state",JSON.stringify({conversations:V.conversations,currentConversationId:V.currentConversationId}))},0)}catch(f){li("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 i=t().conversations.find(B=>B.sessionId===n);if(!i)throw new Error("Conversation not found for session");const A=Wn();if(A&&!i.adapterName)throw new Error("Adapter not configured for this conversation");if(!A&&!i.apiKey)throw new Error("API key not configured for this conversation");const a=i.messages.find(B=>B.id===r);if(!a)throw new Error("Message not found");const s=a.databaseMessageId||r,o=to(i.apiUrl||Rn()),l=i.apiKey||On,c=i.adapterName,u=await ci(),g=new u.ApiClient({apiUrl:o,apiKey:A?null:l,sessionId:n,adapterName:A?c:null}),d=await new(await nr(async()=>{const{ThreadService:B}=await import("./threadService-B9Db3n0J.js");return{ThreadService:B}},[])).ThreadService(g).createThread(s,n);e(B=>({conversations:B.conversations.map(f=>f.sessionId!==n?f:{...f,messages:f.messages.map(w=>w.id===r?{...w,threadInfo:d,supportsThreading:!0}:w),currentThreadId:void 0,currentThreadSessionId:void 0})})),Je(`[chatStore] Created thread ${d.thread_id} for message ${r}`)}catch(i){throw li("Failed to create thread:",i),i}},appendToLastMessage:(r,n)=>{const i=Jh(r);if(!i&&r)return;const A=HD(i);e(a=>{const s=n||a.currentConversationId;return{conversations:a.conversations.map(o=>{if(o.id!==s)return o;const l=[...o.messages],c=l[l.length-1];return c&&c.role==="assistant"&&c.isStreaming&&(l[l.length-1]={...c,content:c.content+A}),{...o,messages:l,updatedAt:new Date}})}})},regenerateResponse:async r=>{var n,i,A,a,s,o;try{if(t().isLoading){Ir("Another request is already in progress");return}if(!await qo())throw new Error("API not properly configured");const c=t(),u=c.conversations.find(y=>y.id===c.currentConversationId);if(!u)return;const g=u.messages.findIndex(y=>y.id===r);if(g===-1)return;const h=u.messages[g-1];if(!h||h.role!=="user")return;const d=(h.attachments||[]).map(y=>y.file_id).filter(y=>typeof y=="string"&&y.length>0),B=fN("assistant");e(y=>({conversations:y.conversations.map(I=>I.id===y.currentConversationId?{...I,messages:[...I.messages.slice(0,g),{id:B,content:"",role:"assistant",timestamp:new Date,isStreaming:!0}],updatedAt:new Date}:I),isLoading:!0,error:null}));const f=c.currentConversationId;if(!f)throw new Error("No conversation selected");let w=!1;try{const y=t().conversations.find(te=>te.id===f);if(!y)throw new Error("Conversation not found");const I=Wn();if(I){if(!y.adapterName)throw new Error("Adapter not configured for this conversation. Please select an adapter first.")}else if(!y.apiKey)throw new Error("API key not configured for this conversation. Please configure API settings first.");if(y.sessionId){const te=to(y.apiUrl),V=y.apiKey,Z=y.adapterName,ee=await ci();I?ee.configureApi(te,null,y.sessionId,Z):ee.configureApi(te,V,y.sessionId)}const Y=await ci(),Q=t().conversations.find(te=>te.id===f),M=((i=(n=Q==null?void 0:Q.adapterInfo)==null?void 0:n.adapter_name)==null?void 0:i.includes("voice"))||((a=(A=Q==null?void 0:Q.adapterInfo)==null?void 0:A.adapter_name)==null?void 0:a.includes("audio"))||((o=(s=Q==null?void 0:Q.adapterInfo)==null?void 0:s.adapter_name)==null?void 0:o.includes("multilingual")),D=()=>{try{const te=localStorage.getItem("chat-settings");if(te)return JSON.parse(te).voiceEnabled===!0}catch(te){Ir("Failed to read global voice setting:",te)}return!1},G=Q==null?void 0:Q.audioSettings,T=D(),R=(G==null?void 0:G.enabled)??T??M,L=(G==null?void 0:G.ttsVoice)||void 0,z=(G==null?void 0:G.language)||"en-US";for await(const te of Y.streamChat(h.content,!0,d.length>0?d:void 0,void 0,void 0,void 0,z,R,L)){if(te.text){const V=Jh(te.text);V?(t().appendToLastMessage(V,f),w=!0,await new Promise(Z=>setTimeout(Z,30))):te.text.length>100&&Ir("[chatStore] Filtered out potential base64 audio data from regenerated message content")}if(te.audio&&te.done&&e(V=>({conversations:V.conversations.map(Z=>{if(Z.id!==f)return Z;const ee=[...Z.messages],ie=ee[ee.length-1];return ie&&ie.role==="assistant"&&(ee[ee.length-1]={...ie,audio:te.audio,audioFormat:te.audioFormat||"mp3"}),{...Z,messages:ee,updatedAt:new Date}})})),te.done)break}w||t().appendToLastMessage("No response received from the server. Please try again later.",f)}catch(y){li("Regenerate API error:",y),t().appendToLastMessage("Sorry, there was an error regenerating the response.",f)}e(y=>{const I=y.conversations.map(M=>M.id===f?{...M,messages:M.messages.map(D=>D.id===B?{...D,isStreaming:!1}:D),updatedAt:new Date}:M),Y=I.find(M=>M.id===y.currentConversationId),Q=Y?Y.messages.some(M=>M.role==="assistant"&&M.isStreaming):!1;return{conversations:I,isLoading:Q}})}catch(l){li("Regenerate error:",l),e({isLoading:!1,error:`Failed to regenerate response: ${l instanceof Error?l.message:"Unknown error"}`})}},updateConversationTitle:(r,n)=>{e(i=>({conversations:i.conversations.map(A=>A.id===r?{...A,title:n,updatedAt:new Date}:A)})),setTimeout(()=>{const i=t();localStorage.setItem("chat-state",JSON.stringify({conversations:i.conversations,currentConversationId:i.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=Nr.maxConversations;if(!r.currentConversationId)return n===null||r.conversations.length<n;const i=r.conversations.find(A=>A.id===r.currentConversationId);return i&&i.messages.length>0?n===null||r.conversations.length<n:!1},getConversationCount:()=>t().conversations.length,addFileToConversation:(r,n)=>{Je("[chatStore] addFileToConversation called",{conversationId:r,fileId:n.file_id,filename:n.filename}),e(i=>{var s,o;const A={conversations:i.conversations.map(l=>l.id===r?{...l,attachedFiles:[...(l.attachedFiles||[]).filter(c=>c.file_id!==n.file_id),n],updatedAt:new Date}:l)},a=A.conversations.find(l=>l.id===r);return Je(`[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}))}),A}),setTimeout(()=>{const i=t();localStorage.setItem("chat-state",JSON.stringify({conversations:i.conversations,currentConversationId:i.currentConversationId}))},0)},removeFileFromConversation:async(r,n)=>{try{const i=t().conversations.find(l=>l.id===r);if(!i)throw new Error("Conversation not found");if(Wn()){if(!i.adapterName)throw new Error("Adapter not configured for this conversation. Cannot delete file.")}else if(!i.apiKey)throw new Error("API key not configured for this conversation. Cannot delete file.");const a=i.apiKey,s=i.adapterName,o=to(i.apiUrl);Je(`[chatStore] Calling FileUploadService.deleteFile for ${n}`),await Td.deleteFile(n,a,o,s),Je(`[chatStore] Successfully deleted file ${n} from server`)}catch(i){i instanceof Error&&(i.message.includes("404")||i.message.includes("File not found"))}e(i=>({conversations:i.conversations.map(A=>A.id===r?{...A,attachedFiles:(A.attachedFiles||[]).filter(a=>a.file_id!==n),updatedAt:new Date}:A)})),setTimeout(()=>{const i=t();localStorage.setItem("chat-state",JSON.stringify({conversations:i.conversations,currentConversationId:i.currentConversationId}))},0)},loadConversationFiles:async r=>{try{const n=t().conversations.find(g=>g.id===r);if(!n)return;if(Wn()){if(!n.adapterName){Je(`Skipping file load for conversation ${r}: adapter not configured`);return}}else if(!n.apiKey){Je(`Skipping file load for conversation ${r}: API key not configured`);return}const A=n.apiKey,a=n.adapterName,s=to(n.apiUrl);if(new Set((n.attachedFiles||[]).map(g=>g.file_id)).size===0){Je(`No files to sync for conversation ${r}`);return}const c=(await Td.listFiles(A,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 h=g.conversations.find(B=>B.id===r);if(!h)return g;const d=(h.attachedFiles||[]).map(B=>u.get(B.file_id)||B).filter(B=>u.has(B.file_id)||!B.processing_status||B.processing_status==="processing");return{conversations:g.conversations.map(B=>B.id===r?{...B,attachedFiles:d,updatedAt:new Date}:B)}}),setTimeout(()=>{const g=t();localStorage.setItem("chat-state",JSON.stringify({conversations:g.conversations,currentConversationId:g.currentConversationId}))},0)}catch(n){li(`Failed to load files for conversation ${r}:`,n)}},syncConversationFiles:async r=>{await t().loadConversationFiles(r)}})),Rrt=async()=>{var c;const e=localStorage.getItem("chat-state"),t=Rn(),r=typeof window<"u"?!!localStorage.getItem("chat-api-url"):!1;let n=Pf(),i=!1;if(e)try{const u=JSON.parse(e),g=B=>{if(B instanceof Date)return B;const f=B?new Date(B):new Date;return Number.isNaN(f.getTime())?new Date:f},h=Array.isArray(u.conversations)?u.conversations:[];if(u.conversations=h.map(B=>{const w=(Array.isArray(B.messages)?B.messages:[]).filter(Q=>!(Q.role==="assistant"&&Q.isStreaming)).map(Q=>({...Q,timestamp:g(Q.timestamp),isStreaming:!1})),y={id:B.id,sessionId:B.sessionId||io(),title:B.title||"New Chat",messages:w,createdAt:g(B.createdAt),updatedAt:g(B.updatedAt),attachedFiles:B.attachedFiles||[],apiKey:B.apiKey||On,adapterName:B.adapterName,apiUrl:B.apiUrl,adapterInfo:B.adapterInfo,audioSettings:B.audioSettings,currentThreadId:void 0,currentThreadSessionId:void 0},Y=y.messages.length===0&&(!y.apiKey||y.apiKey===On)&&!r?t:to(B.apiUrl);return{...y,apiUrl:Y}}),i=u.conversations&&u.conversations.length>0,u.currentConversationId&&u.conversations){const B=u.conversations.find(f=>f.id===u.currentConversationId);B&&B.sessionId&&(n=B.sessionId)}if(!u.conversations||u.conversations.length===0){const B=`conv_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,f=io(),w={id:B,sessionId:f,title:"New Chat",messages:[],createdAt:new Date,updatedAt:new Date,apiKey:On,apiUrl:Rn()};Ot.setState({conversations:[w],currentConversationId:B,sessionId:f}),n=f}else Ot.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&&(Ot.setState({currentConversationId:u.conversations[0].id,sessionId:u.conversations[0].sessionId||n}),n=u.conversations[0].sessionId||n);const d=Ot.getState().conversations;Je("📋 Loaded conversations:",d.map(B=>{var f;return{id:B.id,title:B.title,sessionId:B.sessionId,messageCount:((f=B.messages)==null?void 0:f.length)||0}})),setTimeout(()=>{Ot.getState().cleanupStreamingMessages()},100)}catch(u){li("Failed to load chat state:",u);const g=`conv_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,h=io(),d=Rn(),B={id:g,sessionId:h,title:"New Chat",messages:[],createdAt:new Date,updatedAt:new Date,apiKey:On,apiUrl:d};Ot.setState({conversations:[B],currentConversationId:g,sessionId:h}),n=h}else{const u=`conv_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,g=io(),h=Rn(),d={id:u,sessionId:g,title:"New Chat",messages:[],createdAt:new Date,updatedAt:new Date,apiKey:On,apiUrl:h};Ot.setState({conversations:[d],currentConversationId:u,sessionId:g}),n=g}const A=Ot.getState(),a=A.currentConversationId?A.conversations.find(u=>u.id===A.currentConversationId):null,s=Wn(),o=i&&(a!=null&&a.apiKey)?a.apiKey:On,l=i&&(a!=null&&a.apiUrl)?a.apiUrl:Rn();try{const u=await ci();if(s){const g=a==null?void 0:a.adapterName;if(g){if(u.configureApi(l,null,n,g),bc=l,Yc=!0,Je("✅ Using existing adapter from conversation:",g),!(a!=null&&a.adapterInfo))try{const h=new u.ApiClient({apiUrl:l,apiKey:null,sessionId:null,adapterName:g});if(typeof h.getAdapterInfo=="function"){const d=await h.getAdapterInfo();Je("✅ Adapter info loaded for existing adapter:",d);const B=Ot.getState();B.currentConversationId&&(Ot.setState({conversations:B.conversations.map(f=>f.id===B.currentConversationId?{...f,adapterInfo:d,updatedAt:new Date}:f)}),setTimeout(()=>{const f=Ot.getState();localStorage.setItem("chat-state",JSON.stringify({conversations:f.conversations,currentConversationId:f.currentConversationId}))},0))}}catch(h){Ir("Failed to load adapter info for existing adapter:",h)}}else{const h=await Mle();if(h){Je("🔄 Auto-selecting first adapter:",h.name),u.configureApi(l,null,n,h.name),bc=l,Yc=!0,localStorage.setItem("chat-adapter-name",h.name);try{const d=new u.ApiClient({apiUrl:l,apiKey:null,sessionId:null,adapterName:h.name});let B;typeof d.getAdapterInfo=="function"&&(B=await d.getAdapterInfo(),Je("✅ Adapter info loaded for auto-selected adapter:",B));const f=Ot.getState();f.currentConversationId&&(Ot.setState({conversations:f.conversations.map(w=>w.id===f.currentConversationId?{...w,adapterName:h.name,adapterInfo:B,apiUrl:l,apiKey:void 0,updatedAt:new Date}:w)}),setTimeout(()=>{const w=Ot.getState();localStorage.setItem("chat-state",JSON.stringify({conversations:w.conversations,currentConversationId:w.currentConversationId}))},0))}catch(d){Ir("Failed to validate auto-selected adapter on startup:",d)}}else Ir("No adapters available for auto-selection in middleware mode")}}else if(u.configureApi(l,o,n),bc=l,Yc=!0,o===On)try{const g=new u.ApiClient({apiUrl:l,apiKey:o,sessionId:null});if(typeof g.validateApiKey=="function"&&(await g.validateApiKey(),Je("✅ Default API key validated on startup")),typeof g.getAdapterInfo=="function"){const h=await g.getAdapterInfo();Je("✅ Adapter info loaded for default key:",h);const d=Ot.getState();d.currentConversationId&&Ot.setState({conversations:d.conversations.map(B=>B.id===d.currentConversationId?{...B,adapterInfo:h,updatedAt:new Date}:B)})}}catch(g){Ir("Failed to validate default API key on startup:",g)}}catch(u){li("Failed to initialize API:",u)}};typeof window<"u"&&Rrt();const zrt=Fc(),Trt=new Map,jrt=new Map,Lrt=new Map,Hrt=()=>{if(typeof window>"u")return null;try{return localStorage.getItem("chat-adapter-name")}catch{return null}},Fle=e=>typeof e=="object"&&e!==null&&"message"in e,Jrt=e=>e instanceof Error?e.message:typeof e=="string"?e:Fle(e)?e.message??"Unknown error":"Unknown error";function Ort({conversationId:e,onFilesSelected:t,onUploadError:r,onClose:n,onUploadingChange:i,onUploadSuccess:A,maxFiles:a=Nr.maxFilesPerConversation,disabled:s=!1}){const[o,l]=F.useState(!1),[c,u]=F.useState(0),g=F.useRef(null),h=F.useRef(Lrt),d=F.useRef(new Map),B=F.useRef(!0),f=F.useRef(Trt),w=F.useRef(jrt),y=F.useRef(e),I=Ot(oe=>oe.conversations),Y=F.useMemo(()=>{if(!e)return new Map;const oe=f.current.get(e);return oe?new Map(oe):new Map},[e,c]),Q=F.useCallback(oe=>{if(!oe){i==null||i(null,!1),u(de=>de+1);return}const le=f.current.get(oe)||new Map,O=I.find(de=>de.id===oe);if(O&&O.attachedFiles){const de=O.attachedFiles.filter(pe=>!pe.processing_status||pe.processing_status==="processing"||pe.processing_status==="uploading"),Ee=new Map(le);let Ce=!1;de.forEach(pe=>{if(!Array.from(le.values()).find(ye=>ye.fileId===pe.file_id)){const ye=`${oe}-${pe.filename}-${pe.file_id}`;Ee.set(ye,{filename:pe.filename,progress:pe.processing_status==="uploading"?50:90,status:pe.processing_status||"processing",fileId:pe.file_id}),Ce=!0}}),Ce||Ee.size>0?(f.current.set(oe,Ee),i==null||i(oe,!0)):(f.current.delete(oe),i==null||i(oe,!1))}else le.size>0?f.current.set(oe,le):f.current.delete(oe),i==null||i(oe,le.size>0);u(de=>de+1)},[I,i]);F.useEffect(()=>{y.current=e,Q(e)},[e,Q]),F.useEffect(()=>{e&&Q(e)},[I,e,Q]);const M=F.useCallback((oe,le)=>{if(!oe)return;const O=f.current.get(oe)||new Map,de=le(new Map(O));de.size>0?f.current.set(oe,de):f.current.delete(oe),i==null||i(oe,de.size>0),u(Ee=>Ee+1)},[i]),D=F.useCallback((oe,le)=>{if(!oe)return;const O=w.current.get(oe)||[],de=le([...O||[]]),Ee=new Set(O.map(Ce=>Ce.file_id));if(w.current.set(oe,de),t(oe,de),A){const Ce=de.filter(pe=>!Ee.has(pe.file_id));Ce.length>0&&A(oe,Ce)}u(Ce=>Ce+1)},[t,A]),G=Ot(oe=>oe.removeFileFromConversation),T=Ot(oe=>oe.addFileToConversation);F.useEffect(()=>(B.current=!0,()=>{B.current=!1}),[]);const R=F.useCallback(()=>{B.current=!1,new Map(d.current).forEach(le=>le.abort()),setTimeout(()=>{const le=Ot.getState(),O=new Map(le.conversations.map(Ee=>[Ee.id,Ee])),de=[];h.current.forEach((Ee,Ce)=>{var pe;if(Ee){const xe=O.get(Ee);if(new Set(((pe=xe==null?void 0:xe.attachedFiles)==null?void 0:pe.map(je=>je.file_id))||[]).has(Ce)){h.current.delete(Ce);return}}de.push({fileId:Ce,conversationId:Ee||null})}),de.length>0&&(n==null||n(),de.forEach(async({fileId:Ee,conversationId:Ce})=>{try{if(Ce)await G(Ce,Ee);else{const xe=Wn()?Hrt():null;await Td.deleteFile(Ee,void 0,void 0,xe??void 0)}}catch(pe){if(Fle(pe)){const xe=pe.message??"";!xe.includes("404")&&xe.includes("File not found")}}}))},300)},[n,G]);F.useEffect(()=>R,[R]);const L=F.useCallback(async oe=>{if(!oe||oe.length===0)return;const le=Array.from(oe),O=Ot.getState(),de=e||O.currentConversationId;if(!de){r==null||r("Please select or create a conversation before uploading files.");return}const Ee=O.conversations.find(Ne=>Ne.id===de);if(!Ee){r==null||r("Conversation not found. Please try again.");return}if((w.current.get(de)||[]).length+le.length>a){const Ne=`Maximum ${a} files allowed per conversation. Please remove some files first.`;r==null||r(Ne);return}if(Nr.maxTotalFiles!==null&&O.conversations.reduce((Se,Te)=>{var Ve;return Se+(((Ve=Te.attachedFiles)==null?void 0:Ve.length)||0)},0)+le.length>Nr.maxTotalFiles){const Se=`Maximum ${Nr.maxTotalFiles} total files allowed across all conversations. Please remove some files from other conversations first.`;r==null||r(Se);return}const pe=Wn();if(pe){if(!Ee.adapterName){r==null||r("Adapter not configured for this conversation. Please select an adapter first.");return}}else if(!Ee.apiKey||Ee.apiKey===zrt){r==null||r("API key not configured for this conversation. Please configure API settings first.");return}const xe=Ee.apiKey,ye=Ee.adapterName,je=to(Ee.apiUrl);for(let Ne=0;Ne<le.length;Ne++){const Qe=le[Ne],Se=new AbortController;d.current.set(Qe.name,Se);const Te=`${de}-${Qe.name}-${Date.now()}-${Ne}`;let Ve=null;try{const et=await Td.uploadFile(Qe,rt=>{if(M(de,It=>(It.set(Te,rt),It)),rt.fileId&&!Ve){Ve=rt.fileId,h.current.set(rt.fileId,de);const It={file_id:rt.fileId,filename:Qe.name,mime_type:Qe.type||"application/octet-stream",file_size:Qe.size,processing_status:rt.status==="uploading"?"uploading":rt.status==="processing"?"processing":rt.status==="completed"?"completed":void 0};Je(`[FileUpload] Adding file ${rt.fileId} to conversation ${de} immediately (status: ${It.processing_status})`),T(de,It)}},xe,je,pe?ye:void 0).catch(rt=>{if(rt.message&&rt.message.includes("was deleted")){Ve&&h.current.delete(Ve);const It=rt.message.match(/File\s+([\w-]+)\s+was deleted/);return It&&It[1]&&h.current.delete(It[1]),Je(`File ${Qe.name} was deleted during upload`),null}throw rt});et?(h.current.set(et.file_id,de),Je(`[FileUpload] Updating file ${et.file_id} in conversation ${de} with final status`),T(de,et),et.processing_status==="completed"?M(de,rt=>(rt.delete(Te),rt)):M(de,rt=>{const It=rt.get(Te);return It&&rt.set(Te,{...It,progress:90,status:"processing",fileId:et.file_id}),rt}),D(de,rt=>{if(new Set(rt.map(yr=>yr.file_id)).has(et.file_id))return rt;const hr=[...rt,et];return Je(`[FileUpload] Updated uploadedFiles for ${de}: ${hr.length} files`,hr),hr})):(Ir(`Upload completed for ${Qe.name} but uploadedAttachment is null`),M(de,rt=>(rt.delete(Te),rt)))}catch(et){const rt=Jrt(et);if(et instanceof DOMException&&et.name==="AbortError"||Se.signal.aborted){Je(`Upload cancelled for ${Qe.name}`),Ve&&h.current.delete(Ve);continue}if(rt.includes("was deleted")){Je(`File ${Qe.name} was deleted during upload`),Ve&&h.current.delete(Ve);const It=rt.match(/File\s+([\w-]+)\s+was deleted/);It&&It[1]&&h.current.delete(It[1]);continue}B.current?(jg(`Failed to upload file ${Qe.name}:`,et),jg(`File type: ${Qe.type}, File name: ${Qe.name}`),r==null||r(rt||`Failed to upload ${Qe.name}`)):Ir(`Upload error for ${Qe.name} (component unmounted):`,rt),Ve&&h.current.delete(Ve)}finally{d.current.delete(Qe.name)}}},[T,e,a,r,D,M]),z=F.useCallback(oe=>{oe.preventDefault(),oe.stopPropagation(),s||l(!0)},[s]),te=F.useCallback(oe=>{oe.preventDefault(),oe.stopPropagation(),l(!1)},[]),V=F.useCallback(oe=>{if(oe.preventDefault(),oe.stopPropagation(),l(!1),s)return;const le=oe.dataTransfer.files;L(le)},[s,L]),Z=F.useCallback(oe=>{const le=oe.target.files;L(le),g.current&&(g.current.value="")},[L]),ee=F.useCallback(()=>{!s&&g.current&&g.current.click()},[s]),ie=Y.size>0,K=F.useMemo(()=>{const oe=new Map;return I.forEach(le=>{oe.set(le.id,le.title||"Conversation")}),oe},[I]),$=F.useMemo(()=>{const oe=[];return f.current.forEach((le,O)=>{O!==e&&le.size>0&&oe.push({conversationId:O,uploads:Array.from(le.entries()).map(([de,Ee])=>({key:de,progress:Ee}))})}),oe},[e,c]),P=j.jsx("div",{className:"w-full max-w-full overflow-hidden space-y-2",children:Array.from(Y.values()).map(oe=>j.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:[j.jsx(Ag,{className:"w-4 h-4 text-emerald-600 dark:text-emerald-400 animate-spin flex-shrink-0"}),j.jsxs("div",{className:"flex-1 min-w-0 overflow-hidden",children:[j.jsx("p",{className:"text-sm font-medium text-slate-700 dark:text-slate-300 truncate",children:oe.filename}),j.jsx("div",{className:"mt-1 bg-slate-200 dark:bg-slate-700 rounded-full h-1.5",children:j.jsx("div",{className:"bg-emerald-600 dark:bg-emerald-400 h-1.5 rounded-full transition-all duration-300",style:{width:`${oe.progress}%`}})})]}),j.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:oe.status==="uploading"?"Uploading...":oe.status==="processing"?"Processing...":oe.status==="completed"?"Done":"Error"})]},oe.filename))});return ie?j.jsx("div",{className:"w-full max-w-full overflow-hidden space-y-3",children:P}):j.jsxs("div",{className:"w-full max-w-full overflow-hidden space-y-3",children:[j.jsxs("div",{onClick:ee,onDragOver:z,onDragLeave:te,onDrop:V,className:`
1234
1234
  relative w-full max-w-full border-2 border-dashed rounded-xl p-3 sm:p-4 transition-all cursor-pointer
1235
1235
  ${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"}
1236
- `,children:[j.jsx("input",{ref:g,type:"file",multiple:!0,onChange:Z,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"}),j.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 text-center",children:[j.jsx(z0e,{className:`w-6 h-6 ${o?"text-emerald-600 dark:text-emerald-400":"text-slate-400 dark:text-slate-500"}`}),j.jsxs("div",{className:"px-2",children:[j.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"}),j.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)"]})]})]})]}),$.length>0&&j.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:[j.jsx("p",{className:"text-xs font-semibold text-slate-600 dark:text-slate-300",children:"Uploads in other conversations"}),$.map(({conversationId:oe,uploads:le})=>j.jsxs("div",{className:"space-y-2",children:[j.jsx("div",{className:"text-xs font-medium text-slate-500 dark:text-slate-400",children:K.get(oe)||"Conversation"}),le.map(({key:O,progress:de})=>j.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:[j.jsx(Ag,{className:"w-4 h-4 text-emerald-600 dark:text-emerald-400 animate-spin flex-shrink-0"}),j.jsxs("div",{className:"flex-1 min-w-0 overflow-hidden",children:[j.jsx("p",{className:"text-sm font-medium text-slate-700 dark:text-slate-300 truncate",children:de.filename}),j.jsx("div",{className:"mt-1 bg-slate-200 dark:bg-slate-700 rounded-full h-1.5",children:j.jsx("div",{className:"bg-emerald-600 dark:bg-emerald-400 h-1.5 rounded-full transition-all duration-300",style:{width:`${de.progress}%`}})})]}),j.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:de.status==="uploading"?"Uploading...":de.status==="processing"?"Processing...":de.status==="completed"?"Done":"Error"})]},O))]},oe))]})]})}const rV={"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 Wrt(e){if(!e)return"bin";if(rV[e])return rV[e];const t=e.split("/");return t.length===2&&t[1]?t[1]:"bin"}function Prt(e){return e.replace(/[^a-zA-Z0-9._-]/g,"_").replace(/_+/g,"_")||"pasted-file"}function Krt(e){const t=e.lastIndexOf(".");return t===-1||t===e.length-1?null:e.slice(t+1).toLowerCase()}function Vrt(e){const t=e.lastIndexOf(".");return t===-1?e:e.slice(0,t)}function Xrt(e,t){const r=Date.now(),n=e.name&&e.name.trim().length>0?e.name.trim():"pasted-file",i=Prt(Vrt(n)),a=Krt(n)||Wrt(e.type),s=`${i}-${r}-${t}.${a}`;return new File([e],s,{type:e.type||"application/octet-stream"})}function nV({onSend:e,disabled:t=!1,placeholder:r="Ask me anything...",isCentered:n=!1}){var Wt;const[i,A]=F.useState(""),[a,s]=F.useState(!1),[o,l]=F.useState(!1),[c,u]=F.useState(!1),[g,h]=F.useState([]),[d,B]=F.useState({}),[f,w]=F.useState(new Map),[y,I]=F.useState(!1),[Y,Q]=F.useState(!1),[M,D]=F.useState(null),[G,T]=F.useState(null),R=F.useRef(null),L=F.useRef(new Set),z=F.useRef(""),te=F.useRef(!1),V=F.useRef(0),Z=F.useRef(null),{settings:ee,updateSettings:ie}=cy(),K=F.useCallback((ze,Ze)=>{ze&&B(Jt=>{if(Jt[ze]===Ze)return Jt;const bt={...Jt};return Ze?bt[ze]=!0:delete bt[ze],bt})},[]),[$,P]=F.useState(0),{createConversation:oe,currentConversationId:le,conversations:O,isLoading:de,syncConversationFiles:Ee}=Ot(),Ce=O.find(ze=>ze.id===le),pe=F.useCallback(()=>{P(ze=>ze+1)},[]),{isListening:xe,isSupported:ye,startListening:je,stopListening:Ne,error:Qe}=Crt(ze=>{A(Ze=>{const Jt=(Ze+ze).slice(0,Nr.maxMessageLength);return z.current=Jt,Jt})},pe),Se=urt(),Te=Se&&ye,Ve=crt(),et=(Ce==null?void 0:Ce.attachedFiles)||[],rt=((Wt=Ce==null?void 0:Ce.adapterInfo)==null?void 0:Wt.isFileSupported)??!1,It=g.some(ze=>ze.processing_status?ze.processing_status!=="completed"&&ze.processing_status!=="error"&&ze.processing_status!=="failed":!0)||et.some(ze=>ze.processing_status?ze.processing_status!=="completed"&&ze.processing_status!=="error"&&ze.processing_status!=="failed":!0),hr=le?!!d[le]:!1,yr=Object.values(d).some(Boolean),Xt=t||It||hr,ii=Ve&&rt,mi=!ii||Xt;F.useEffect(()=>{if(R.current){R.current.style.height="auto";const Ze=R.current.scrollHeight;R.current.style.height=`${Math.min(Ze,120)}px`,R.current.style.overflowY=Ze>120?"auto":"hidden"}},[i]);const Mn=()=>{const ze=document.activeElement;return ze&&ze.tagName==="TEXTAREA"};F.useEffect(()=>{!Xt&&R.current&&!Mn()&&R.current.focus()},[Xt]);const Fr=F.useRef(de);F.useEffect(()=>{Fr.current&&!de&&!Xt&&R.current&&setTimeout(()=>{R.current&&!Mn()&&R.current.focus()},100),Fr.current=de},[de,Xt]),F.useEffect(()=>{if(!Te||($>V.current&&(te.current=!0,V.current=$),!te.current||$===0))return;const ze=setTimeout(()=>{const Ze=z.current.trim(),Jt=Ot.getState();if(Je("[MessageInput] Auto-send check after voice completion:",{hasMessage:!!Ze,isInputDisabled:Xt,isComposing:a,isLoading:Jt.isLoading}),!Ze){te.current=!1;return}if(!Xt&&!a&&!Jt.isLoading){const bt=Jt.conversations.find(Er=>Er.id===Jt.currentConversationId),Yr=((bt==null?void 0:bt.attachedFiles)||[]).map(Er=>Er.file_id);e(Ze,Yr.length>0?Yr:void 0),te.current=!1,A(""),z.current="",R.current&&(R.current.style.height="auto",R.current.style.overflowY="hidden")}},400);return()=>clearTimeout(ze)},[Te,$,Xt,a,e]),F.useEffect(()=>{hr&&c&&u(!1)},[hr,c]),F.useEffect(()=>{!hr&&g.length},[hr,g.length,c]);const Ye=F.useCallback((ze,Ze)=>{setTimeout(()=>{let Jt=Ot.getState(),bt=Ze||Jt.currentConversationId;if(bt||(bt=oe(),Jt=Ot.getState(),bt=Jt.currentConversationId||bt),!bt)return;const Tt=new Set(ze.map(Er=>Er.file_id)),Yr=[];L.current.forEach((Er,Ut)=>{const[,...Vr]=Ut.split("-"),$a=Vr.join("-");Tt.has($a)||Yr.push(Ut)}),Yr.forEach(Er=>L.current.delete(Er)),ze.forEach(Er=>{const Ut=`${bt}-${Er.file_id}`;L.current.has(Ut)||(L.current.add(Ut),Je(`[MessageInput] Adding file ${Er.file_id} to conversation ${bt}`),Jt.addFileToConversation(bt,Er))})},0)},[oe]);F.useEffect(()=>{if(le!==Z.current)if(Z.current=le||null,le&&Ce){const ze=Ce.attachedFiles||[];h(ze.map(Ze=>({...Ze})))}else h([])},[le,Ce]),F.useEffect(()=>{if(le&&Ce){const ze=Ce.attachedFiles||[];ze.length>0?h(Ze=>{const Jt=new Set(Ze.map(Tt=>Tt.file_id)),bt=ze.filter(Tt=>!Jt.has(Tt.file_id));return bt.length>0?(Je(`[MessageInput] Syncing ${bt.length} missing files from conversation to UI`),[...Ze,...bt]):Ze}):ze.length===0&&g.length>0&&h([])}},[le,Ce,O,g.length]),F.useEffect(()=>{var Yr;const ze=typeof window<"u"&&((Yr=window.ORBIT_CHAT_CONFIG)==null?void 0:Yr.enableApiMiddleware)===!0;if(!le||!Ce||(ze?!Ce.adapterName:!Ce.apiKey))return;const Ze=Ce.attachedFiles||[],Jt=Ze.length>0,bt=Ze.filter(Er=>!Er.processing_status||Er.processing_status==="processing"||Er.processing_status==="uploading");if(Jt&&(Je(`[MessageInput] Syncing ${Ze.length} files for conversation ${le}...`),Ee(le).catch(Er=>{})),bt.length===0)return;Je(`[MessageInput] Found ${bt.length} files still processing, starting poll...`);const Tt=setInterval(async()=>{const Ut=Ot.getState().conversations.find(_A=>_A.id===le);if(!Ut){clearInterval(Tt);return}if((Ut.attachedFiles||[]).filter(_A=>!_A.processing_status||_A.processing_status==="processing"||_A.processing_status==="uploading").length===0){clearInterval(Tt);return}try{await Ee(le)}catch{}},3e3);return()=>{clearInterval(Tt)}},[le,Ce,Ee]),F.useEffect(()=>{B(ze=>{const Ze=new Set(O.map(Tt=>Tt.id));let Jt=!1;const bt={...ze};return Object.keys(bt).forEach(Tt=>{Ze.has(Tt)||(delete bt[Tt],Jt=!0)}),Jt?bt:ze})},[O]);const Ue=ze=>{if(ze.preventDefault(),(i.trim()||g.length>0)&&!Xt&&!a){xe&&Ne();const Jt=((Ce==null?void 0:Ce.attachedFiles)||[]).map(bt=>bt.file_id);e(i.trim(),Jt.length>0?Jt:void 0),mh("messageSent",ee.soundEnabled),A(""),z.current="",h([]),u(!1),R.current&&(R.current.style.height="auto",R.current.style.overflowY="hidden")}},Xe=F.useCallback(ze=>{if(!ze||ze.length===0)return;const Ze=ze.length===1?`File "${ze[0].filename}" uploaded successfully`:`${ze.length} files uploaded successfully`;mh("success",ee.soundEnabled),T(Ze),setTimeout(()=>{T(null)},6e3)},[ee.soundEnabled]),Nt=F.useCallback((ze,Ze)=>{Je(`[MessageInput] handleFilesSelected called with ${Ze.length} files for conversation ${ze}:`,Ze),ze&&(ze===le&&h(Ze),Ye(Ze,ze))},[le,Ye]),vt=F.useCallback((ze,Ze)=>{ze===le&&Xe(Ze)},[le,Xe]),Dt=ze=>{ze.key==="Enter"&&!ze.shiftKey&&!a&&(ze.preventDefault(),Ue(ze))},Ge=()=>{xe?Ne():je()},De=()=>{ie({voiceEnabled:!ee.voiceEnabled})},Yt=F.useCallback(async ze=>{var Er;if(!Ve||!o||!rt||Xt)return;const Ze=ze.clipboardData;if(!Ze||!Ze.items)return;const bt=Array.from(Ze.items).filter(Ut=>Ut.kind==="file");if(bt.length===0)return;const Tt=[];if(bt.forEach((Ut,Vr)=>{const $a=Ut.getAsFile();$a&&Tt.push(Xrt($a,Vr))}),Tt.length===0)return;ze.preventDefault(),D(null),T(null);let Yr=null;try{const Ut=Ot.getState(),Vr=Ut.conversations.find(ke=>ke.id===Ut.currentConversationId);if(((Vr==null?void 0:Vr.attachedFiles)||[]).length+Tt.length>Nr.maxFilesPerConversation)throw new Error(`Maximum ${Nr.maxFilesPerConversation} files allowed per conversation. Please remove some files first.`);if(Nr.maxTotalFiles!==null&&Ut.conversations.reduce((J,Ae)=>{var Gt;return J+(((Gt=Ae.attachedFiles)==null?void 0:Gt.length)||0)},0)+Tt.length>Nr.maxTotalFiles)throw new Error(`Maximum ${Nr.maxTotalFiles} total files allowed across all conversations. Please remove some files from other conversations first.`);if(!Vr||!Vr.apiKey||Vr.apiKey===Fc())throw new Error("API key not configured for this conversation. Please configure API settings first.");const es=Vr.apiKey,vr=to(Vr.apiUrl);Yr=Vr.id,K(Yr,!0);const x=[],U=[];for(let ke=0;ke<Tt.length;ke++){const J=Tt[ke],Ae=J.name||`Clipboard file ${ke+1}`,Gt=`${Ae}-${Date.now()}-${ke}`;w(Gr=>{const Yi=new Map(Gr);return Yi.set(Gt,{filename:Ae,progress:0,status:"uploading"}),Yi});const nt=Gr=>{w(Yi=>{const ae=new Map(Yi),ce=ae.get(Gt);return ce&&ae.set(Gt,{...ce,filename:Ae,progress:Gr.progress,status:Gr.status,fileId:Gr.fileId}),ae})},kn=()=>new Promise(Gr=>{w(Yi=>{const ae=new Map(Yi),ce=ae.get(Gt);return ce&&ae.set(Gt,{...ce,progress:100,status:"completed"}),ae}),setTimeout(()=>{w(Yi=>{const ae=new Map(Yi);return ae.delete(Gt),ae}),Gr()},2500)});Je(`[MessageInput] Pasting file: ${J.name}, type: ${J.type||"unknown"}, size: ${J.size}`);const Ai=typeof window<"u"&&((Er=window.ORBIT_CHAT_CONFIG)==null?void 0:Er.enableApiMiddleware)===!0,ft=Ce==null?void 0:Ce.adapterName,Xr=await Td.uploadFile(J,Gr=>{Je(`[MessageInput] Paste upload progress for ${J.name}: ${Gr.progress}% - ${Gr.status}`),nt(Gr)},es,vr,Ai?ft:void 0);x.push(Xr),U.push(kn())}if(x.length>0){let ke=x;if(Yr&&Yr===le){const J=new Set(g.map(Gt=>Gt.file_id)),Ae=x.filter(Gt=>!J.has(Gt.file_id));Ae.length>0?(h(Gt=>[...Gt,...Ae]),ke=Ae):ke=[]}ke.length>0&&Ye(ke,Yr),await Promise.all(U),Xe(x)}}catch(Ut){const Vr=Ut instanceof Error?Ut.message:"Failed to paste file";mh("error",ee.soundEnabled),D(Vr),setTimeout(()=>{D(null)},5e3),w(new Map)}finally{K(Yr,!1)}},[g,Ce==null?void 0:Ce.adapterName,le,o,rt,Xt,K,ee.soundEnabled,Xe,Ye,Ve]),zt=It||hr?"Files are uploading/processing, please wait...":ii?"Message ORBIT or drop files here":r;F.useEffect(()=>{!Se||!Qe||mh("error",ee.soundEnabled)},[Se,ee.soundEnabled,Qe]);const tr=n?"max-w-3xl":"max-w-5xl",sr=n?"flex justify-center":"";return j.jsx("div",{className:`bg-white px-3 py-3 md:px-0 md:py-4 dark:bg-[#212121] sm:px-4 ${sr}`,children:j.jsxs("div",{className:`mx-auto w-full ${tr}`,children:[Qe&&Se&&j.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:Qe}),M&&j.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:M}),G&&j.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:[j.jsx(h0e,{className:"h-4 w-4 flex-shrink-0"}),j.jsx("span",{children:G})]}),j.jsxs("form",{onSubmit:Ue,className:"flex w-full flex-col gap-2 md:gap-3",children:[j.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:[j.jsx("textarea",{ref:R,value:i,onChange:ze=>A(ze.target.value),onKeyDown:Dt,onPaste:Yt,onCompositionStart:()=>s(!0),onCompositionEnd:()=>s(!1),onFocus:()=>l(!0),onBlur:()=>l(!1),placeholder:zt,disabled:Xt,rows:1,maxLength:Nr.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:i.trim()||o?"inherit":"transparent"}}),j.jsxs("div",{className:"flex items-center justify-between md:justify-end gap-1 md:gap-2 md:flex-shrink-0",children:[j.jsxs("div",{className:"flex items-center gap-1 md:gap-2",children:[Ve&&j.jsx("button",{type:"button",onClick:ze=>{ze.preventDefault(),mi||u(!c)},disabled:mi,onMouseEnter:()=>I(!0),onMouseLeave:()=>I(!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]":mi?"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:rt?Xt?"Files are uploading/processing. Please wait...":g.length>0?`${g.length} file(s) attached`:"Attach files":"File upload not supported by this adapter",children:mi&&y?j.jsx(ag,{className:"h-5 w-5 md:h-4 md:w-4"}):j.jsx(YX,{className:"h-5 w-5 md:h-4 md:w-4"})}),i.length>0&&j.jsx("div",{className:"px-2 text-xs text-gray-500 dark:text-[#bfc2cd] md:min-w-[72px] md:text-right",children:j.jsxs("span",{className:i.length>=Nr.maxMessageLength?"text-red-600 font-semibold":"",children:[i.length,"/",Nr.maxMessageLength]})})]}),j.jsxs("div",{className:"flex items-center gap-1 md:gap-2",children:[Se&&j.jsxs(j.Fragment,{children:[j.jsx("button",{type:"button",onClick:De,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 ${ee.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:ee.voiceEnabled?"Voice responses enabled - Click to disable":"Enable voice responses (text-to-speech)",children:ee.voiceEnabled?j.jsx(uw,{className:"h-5 w-5"}):j.jsx(T0e,{className:"h-5 w-5"})}),Te&&j.jsx("button",{type:"button",onClick:Ge,disabled:Xt,onMouseEnter:()=>Q(!0),onMouseLeave:()=>Q(!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 ${xe?"bg-red-100 text-red-600 dark:bg-red-900/40 dark:text-red-300":Xt?"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:Xt?"Files are uploading/processing. Please wait...":xe?"Stop recording":"Start voice input",children:xe||Xt&&Y?j.jsx(y0e,{className:"h-5 w-5"}):j.jsx(E0e,{className:"h-5 w-5"})})]}),(It||hr)&&j.jsx("div",{className:"flex h-10 w-10 md:h-8 md:w-8 shrink-0 items-center justify-center",children:j.jsx(Ag,{className:"h-5 w-5 md:h-4 md:w-4 animate-spin text-gray-500 dark:text-[#bfc2cd]"})}),j.jsx("button",{type:"submit",disabled:!i.trim()&&g.length===0||Xt||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 ${(i.trim()||g.length>0)&&!Xt&&!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:j.jsx(MX,{className:"h-5 w-5 md:h-4 md:w-4"})})]})]})]}),g.length>0&&j.jsx("div",{className:"flex flex-wrap gap-2",children:g.map(ze=>{const Ze=!ze.processing_status||ze.processing_status==="processing"||ze.processing_status==="uploading";return j.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:[Ze&&j.jsx(Ag,{className:"h-3 w-3 animate-spin text-emerald-600 dark:text-emerald-400 flex-shrink-0"}),j.jsx("span",{className:"truncate max-w-[150px] text-[#353740] dark:text-[#ececf1]",children:ze.filename}),Ze&&j.jsx("span",{className:"text-xs text-gray-500 dark:text-[#bfc2cd]",children:ze.processing_status==="uploading"?"Uploading...":"Processing..."}),j.jsx("button",{disabled:!0,className:"text-gray-300 dark:text-[#4a4b54] cursor-not-allowed",title:"File removal disabled; use Clear All in sidebar",children:j.jsx(ag,{className:"h-3 w-3"})})]},ze.file_id)})}),Ve&&(rt||yr)&&j.jsxs("div",{className:`rounded-md border border-gray-200 bg-white p-3 dark:border-[#4a4b54] dark:bg-[#2d2f39] ${!c&&!hr&&f.size===0&&!yr?"hidden":""}`,children:[c&&j.jsxs("div",{className:"mb-2 flex items-center justify-between text-sm text-[#353740] dark:text-[#ececf1]",children:[j.jsx("span",{children:"Upload files"}),j.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:j.jsx(ag,{className:"h-4 w-4"})})]}),(hr||f.size>0)&&!c&&f.size===0&&j.jsx("div",{className:"mb-2 text-sm text-[#353740] dark:text-[#ececf1]",children:"Uploading files…"}),f.size>0&&j.jsx("div",{className:"mb-2 space-y-2",children:Array.from(f.entries()).map(([ze,Ze])=>j.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:[j.jsx(Ag,{className:"w-4 h-4 text-emerald-600 dark:text-emerald-400 animate-spin flex-shrink-0"}),j.jsxs("div",{className:"flex-1 min-w-0 overflow-hidden",children:[j.jsx("p",{className:"text-sm font-medium text-[#353740] dark:text-[#ececf1] truncate",children:Ze.filename}),j.jsx("div",{className:"mt-1 bg-gray-200 dark:bg-[#3c3f4a] rounded-full h-1.5",children:j.jsx("div",{className:"bg-emerald-600 dark:bg-emerald-400 h-1.5 rounded-full transition-all duration-300",style:{width:`${Ze.progress??0}%`}})})]}),j.jsx("span",{className:"text-xs text-gray-500 dark:text-[#bfc2cd]",children:Ze.status==="uploading"?"Uploading...":Ze.status==="processing"?"Processing...":Ze.status==="completed"?"Done":"Pending"})]},ze))}),j.jsx(Ort,{conversationId:le,onFilesSelected:Nt,onUploadError:ze=>{},onUploadingChange:K,onUploadSuccess:vt,maxFiles:Nr.maxFilesPerConversation,disabled:mi})]}),j.jsx("div",{className:"h-5 md:h-4",children:Te&&xe&&j.jsxs("span",{className:"flex items-center gap-2 text-sm md:text-xs text-gray-500 dark:text-[#bfc2cd]",children:[j.jsx("span",{className:"h-2.5 w-2.5 md:h-2 md:w-2 animate-pulse rounded-full bg-red-500"}),"Listening..."]})})]})]})})}function iV({selectedAdapter:e,onAdapterChange:t,disabled:r}){const[n,i]=F.useState([]),[A,a]=F.useState(!0),[s,o]=F.useState(null),[l,c]=F.useState(!1);F.useEffect(()=>{let d=!0;async function B(){try{a(!0),o(null);const f=await Qle();d&&i(f)}catch{d&&o("Failed to load adapters. Please check your connection.")}finally{d&&a(!1)}}return B(),()=>{d=!1}},[]);const u=F.useRef(!1),g=F.useRef(t);F.useEffect(()=>{g.current=t},[t]),F.useEffect(()=>{if(e){u.current=!0;return}!u.current&&n.length>0&&(u.current=!0)},[n,e]);const h=n.find(d=>d.name===e);return j.jsxs("div",{className:"relative w-full sm:w-[220px]",children:[j.jsx("label",{className:"sr-only",children:"Adapter"}),j.jsxs("div",{className:"relative",children:[j.jsx("button",{type:"button",onClick:()=>!r&&c(!l),disabled:r||A||n.length===0,className:"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 disabled:opacity-50 disabled:cursor-not-allowed dark:border-[#4a4b54] dark:bg-[#343541] dark:text-[#ececf1] dark:focus:border-[#6b6f7a]",children:j.jsxs("div",{className:"flex items-center justify-between gap-2",children:[j.jsx("span",{className:`truncate ${h?"":"text-gray-500 dark:text-gray-400"}`,children:A?"Loading adapters…":s?"Error loading adapters":h?h.name:n.length===0?"No adapters available":"Select agent"}),j.jsx(FX,{className:`h-4 w-4 flex-shrink-0 transition-transform ${l?"rotate-180":""}`})]})}),l&&!r&&n.length>0&&j.jsxs(j.Fragment,{children:[j.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>c(!1)}),j.jsx("div",{className:"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]",children:j.jsx("div",{className:"max-h-60 overflow-auto py-1",children:n.map(d=>{const B=d.name===e;return j.jsx("button",{type:"button",onClick:()=>{B||t(d.name),c(!1)},className:`w-full px-3 py-2 text-left text-sm transition-colors ${B?"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:j.jsx("span",{className:"font-medium truncate",children:d.name})},d.name)})})})]})]}),s&&j.jsx("p",{className:"mt-1 text-xs text-red-600 dark:text-red-400",children:s})]})}const Zrt="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",AV="-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 [&>div]:rounded-t-[28px] md:[&>div]:rounded-none [&>div]:bg-transparent md:[&>div]:px-0",qrt="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]";function _rt({onOpenSettings:e,onOpenSidebar:t}){var oe;const{conversations:r,currentConversationId:n,sendMessage:i,regenerateResponse:A,isLoading:a,configureApiSettings:s,error:o,clearError:l,createThread:c}=Ot(),{settings:u}=cy(),[g,h]=F.useState(!1),[d,B]=F.useState(()=>Rn()),[f,w]=F.useState(()=>Fc()),[y,I]=F.useState(null),[Y,Q]=F.useState(!1),[M,D]=F.useState(!1),[G,T]=F.useState(null),[R,L]=F.useState(!1),z=r.find(le=>le.id===n),te=Wn();F.useEffect(()=>{te&&(z!=null&&z.adapterName)&&I(z.adapterName)},[te,z==null?void 0:z.adapterName]),F.useEffect(()=>{var le,O,de;te&&Je("[ChatInterface] Middleware mode state:",{hasConversation:!!z,adapterName:z==null?void 0:z.adapterName,hasAdapterInfo:!!(z!=null&&z.adapterInfo),hasNotes:!!((le=z==null?void 0:z.adapterInfo)!=null&&le.notes),notes:((de=(O=z==null?void 0:z.adapterInfo)==null?void 0:O.notes)==null?void 0:de.substring(0,50))+"..."})},[te,z==null?void 0:z.adapterName,z==null?void 0:z.adapterInfo]);const V=F.useRef(null);F.useEffect(()=>{(async()=>{var Ee;const O=z==null?void 0:z.adapterName;if(V.current===O)return;const de=!(z!=null&&z.adapterInfo)||(z==null?void 0:z.adapterInfo)&&z.adapterInfo.notes===void 0;if(te&&O&&de){V.current=O,Je("[ChatInterface] Loading adapter info - adapterName:",O,"reason:",z!=null&&z.adapterInfo?"notes undefined":"missing");try{const Ce=(z==null?void 0:z.apiUrl)||Rn();Je("[ChatInterface] Calling configureApiSettings for:",O),await s(Ce,void 0,void 0,O),Je("[ChatInterface] Adapter info loaded successfully")}catch{V.current=null}}else Je("[ChatInterface] Skipping adapter info load:",{isMiddlewareEnabled:te,adapterName:O,hasAdapterInfo:!!(z!=null&&z.adapterInfo),hasNotes:((Ee=z==null?void 0:z.adapterInfo)==null?void 0:Ee.notes)!==void 0,refValue:V.current})})()},[te,z==null?void 0:z.adapterName,z==null?void 0:z.adapterInfo,z==null?void 0:z.apiUrl,s]);const Z=!z||z.messages.length===0;F.useEffect(()=>{let le=null;const O=()=>{le&&(le(),le=null)};if(u.voiceEnabled){if(mc.isAudioEnabled())return O;const de=()=>{O();const Ee=async()=>{O(),await mc.enableAudio()||de()};document.addEventListener("pointerdown",Ee,{once:!0}),document.addEventListener("keydown",Ee,{once:!0}),le=()=>{document.removeEventListener("pointerdown",Ee),document.removeEventListener("keydown",Ee)}};return de(),O}return O(),mc.disableAudio(),O},[u.voiceEnabled]);const ee=(le,O,de)=>{i(le,O,de)},ie=async(le,O,de)=>{await i(de,void 0,le)},K=async()=>{if(!(!z||!z.apiKey&&!z.adapterName)){L(!0);try{const le=await ci(),O=z.apiUrl||Rn(),de=z.apiKey,Ee=z.adapterName,Ce=new le.ApiClient({apiUrl:O,apiKey:de||null,sessionId:null,adapterName:Ee||null});if(typeof Ce.getAdapterInfo=="function"){const pe=await Ce.getAdapterInfo();Je("Adapter info refreshed:",pe),Ot.setState(xe=>({conversations:xe.conversations.map(ye=>ye.id===n?{...ye,adapterInfo:pe,updatedAt:new Date}:ye)})),setTimeout(()=>{const xe=Ot.getState();localStorage.setItem("chat-state",JSON.stringify({conversations:xe.conversations,currentConversationId:xe.currentConversationId}))},0)}}catch{}finally{L(!1)}}},$=async le=>{if(le&&le.preventDefault(),te){if(d&&y){D(!0),T(null);try{await s(d,void 0,void 0,y),l(),T(null),h(!1)}catch(O){const de=O instanceof Error?O.message:"Failed to configure adapter";T(de)}finally{D(!1)}}}else if(d&&f){D(!0),T(null);try{await s(d,f),l(),T(null),Q(!1),h(!1)}catch(O){const de=O instanceof Error?O.message:"Failed to configure API settings";T(de)}finally{D(!1)}}},P=le=>{I(le),T(null)};return j.jsx("div",{className:"flex-1 flex flex-col bg-gray-50 dark:bg-[#0d0e11] md:bg-transparent md:dark:bg-transparent overflow-hidden",children:j.jsx("div",{className:"flex h-full w-full flex-col px-3 sm:px-6 overflow-hidden",children:j.jsxs("div",{className:`mx-auto flex h-full w-full max-w-5xl flex-col overflow-hidden ${Zrt}`,children:[g&&j.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 px-4",children:j.jsxs("form",{onSubmit:$,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:[j.jsx("h2",{className:"text-lg font-medium text-[#353740] dark:text-[#ececf1] mb-4",children:te?"Select Adapter":"Configure API Settings"}),j.jsxs("div",{className:"space-y-5",children:[!te&&j.jsxs("div",{children:[j.jsx("label",{className:"block text-sm font-medium text-[#353740] dark:text-[#d1d5db] mb-2",children:"API URL"}),j.jsx("input",{type:"text",value:d,onChange:le=>B(le.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"})]}),te?j.jsx(iV,{selectedAdapter:y,onAdapterChange:P,disabled:M}):j.jsxs("div",{children:[j.jsx("label",{className:"block text-sm font-medium text-[#353740] dark:text-[#d1d5db] mb-2",children:"API Key"}),j.jsxs("div",{className:"relative",children:[j.jsx("input",{type:Y?"text":"password",value:f,onChange:le=>{w(le.target.value),T(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:M}),j.jsx("button",{type:"button",onClick:()=>Q(!Y),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":Y?"Hide API key":"Show API key",disabled:M,children:Y?j.jsx(p0e,{className:"h-4 w-4"}):j.jsx(m0e,{className:"h-4 w-4"})})]})]}),G&&j.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:G}),j.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[j.jsx("button",{type:"button",onClick:()=>{const le=(z==null?void 0:z.apiUrl)||Rn(),O=(z==null?void 0:z.apiKey)||Fc();B(le),w(O),T(null),Q(!1),h(!1)},className:"rounded-md border border-transparent px-4 py-2 text-sm text-gray-600 hover:border-gray-300 hover:text-gray-900 dark:text-[#d1d5db] dark:hover:text-white disabled:cursor-not-allowed disabled:opacity-50",disabled:M,children:"Cancel"}),j.jsx("button",{type:"submit",disabled:M||(te?!y:!d||!f),className:"rounded-md bg-[#343541] px-4 py-2 text-sm font-medium text-white hover:bg-[#282b32] disabled:cursor-not-allowed disabled:opacity-50 dark:bg-[#565869] dark:hover:bg-[#6b6f7a]",children:M?"Validating...":"Update"})]})]})]})}),o&&j.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:j.jsxs("div",{className:"flex items-start justify-between",children:[j.jsx("p",{children:o}),j.jsx("button",{onClick:l,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:"×"})]})}),j.jsxs("div",{className:qrt,children:[t&&j.jsxs("div",{className:"mb-4 grid grid-cols-2 gap-3 md:hidden",children:[j.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:[j.jsx(f0e,{className:"h-5 w-5"}),"Chats"]}),j.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:[j.jsx(rR,{className:"h-5 w-5"}),"Settings"]})]}),j.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between",children:[j.jsx("div",{className:"min-w-0 flex-1",children:(z==null?void 0:z.adapterInfo)&&j.jsxs("div",{className:"mb-4",children:[j.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-3",children:[z.adapterInfo.model&&j.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:[j.jsx("span",{children:"Model"}),j.jsx("span",{className:"text-gray-800 normal-case dark:text-[#ececf1]",children:z.adapterInfo.model})]}),j.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:[j.jsx("span",{children:"Agent"}),j.jsx("span",{className:"text-gray-800 normal-case dark:text-[#ececf1]",children:z.adapterInfo.client_name})]}),j.jsxs("button",{onClick:K,disabled:R||!(z!=null&&z.apiKey)&&!(z!=null&&z.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:[j.jsx(N0e,{className:`h-4 w-4 ${R?"animate-spin":""}`}),j.jsx("span",{className:"hidden sm:inline",children:"Refresh"})]})]}),j.jsx("h1",{className:"text-2xl font-semibold text-[#353740] dark:text-[#ececf1] mb-2",children:(z==null?void 0:z.title)||"New Chat"}),z&&j.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-500 dark:text-[#bfc2cd]",children:[j.jsx("span",{className:"font-medium",children:z.messages.length}),j.jsxs("span",{children:["Updated ",z.updatedAt.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]})]})}),j.jsxs("div",{className:"flex w-full flex-wrap items-center gap-3 sm:w-auto sm:flex-nowrap sm:justify-end",children:[j.jsxs("span",{className:"text-sm text-gray-500 dark:text-[#bfc2cd] sm:text-right",children:["v",Ile]}),!te&&j.jsx("button",{onClick:()=>{const le=Rn(),O=z==null?void 0:z.apiUrl,de=O&&O!==le?O:le,Ee=(z==null?void 0:z.apiKey)||Fc();B(de),w(Ee),T(null),Q(!1),h(!0)},disabled:!Z,className:"w-full rounded-md border border-gray-300 px-3 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 hover:border-gray-400 transition-colors disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:border-gray-300 dark:border-[#4a4b54] dark:text-[#ececf1] dark:hover:bg-[#3c3f4a] dark:hover:border-[#6b6f7a] dark:disabled:hover:bg-transparent dark:disabled:hover:border-[#4a4b54] sm:w-auto",title:Z?"Configure API settings":"API key cannot be changed once conversation has started. Create a new conversation to use a different API key.",children:"Configure API"}),te&&j.jsx("div",{className:"w-full sm:w-auto",children:j.jsx(iV,{selectedAdapter:y||(z==null?void 0:z.adapterName)||null,onAdapterChange:async le=>{I(le);const O=(z==null?void 0:z.apiUrl)||Rn();try{await s(O,void 0,void 0,le),l()}catch{}},disabled:!Z})}),j.jsx("button",{onClick:e,className:"hidden rounded-md bg-[#343541] p-2 text-white hover:bg-[#282b32] transition-colors dark:bg-[#565869] dark:hover:bg-[#6b6f7a] md:inline-flex",title:"Settings",children:j.jsx(rR,{className:"h-4 w-4"})})]})]})]}),!z||z.messages.length===0?j.jsx("div",{className:"flex flex-1 flex-col min-h-0 pt-4 md:pt-6",children:j.jsx("div",{className:"flex-1 flex flex-col justify-between md:justify-start md:flex-none",children:j.jsxs("div",{className:"w-full space-y-3",children:[j.jsx("div",{className:"mb-2",children:(oe=z==null?void 0:z.adapterInfo)!=null&&oe.notes?j.jsx("div",{className:"text-base text-gray-600 dark:text-[#bfc2cd] leading-relaxed prose prose-sm dark:prose-invert prose-p:my-1 prose-ul:my-2 prose-ol:my-2 prose-li:my-0.5",children:j.jsx(LD,{content:z.adapterInfo.notes})}):j.jsx("h2",{className:"text-xl md:text-2xl font-medium text-[#353740] dark:text-[#ececf1]",children:"How can I assist you today?"})}),j.jsx("div",{className:AV,children:j.jsx(nV,{onSend:ee,disabled:a||!z||(te?!z.adapterName:!z.apiKey),placeholder:"Message ORBIT..."})})]})})}):j.jsxs("div",{className:"flex flex-1 flex-col",children:[j.jsx(Ert,{messages:z.messages,onRegenerate:A,onStartThread:async(le,O)=>{try{await c(le,O)}catch{}},onSendThreadMessage:ie,sessionId:z.sessionId,isLoading:a}),j.jsx("div",{className:AV,children:j.jsx(nV,{onSend:ee,disabled:a||!z||(te?!z.adapterName:!z.apiKey),placeholder:"Message ORBIT..."})})]})]})})})}function aV({isOpen:e,onClose:t,onConfirm:r,title:n,message:i,confirmText:A="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 j.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center p-4 z-50 animate-fadeIn",children:j.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-2xl shadow-2xl w-full max-w-md transform animate-fadeIn",children:[j.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-700",children:[j.jsxs("div",{className:"flex items-center gap-3",children:[j.jsx("div",{className:`w-10 h-10 rounded-full ${u.iconBg} flex items-center justify-center`,children:j.jsx(QX,{className:`w-5 h-5 ${u.icon}`})}),j.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:n})]}),j.jsx("button",{onClick:t,className:"p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors",children:j.jsx(ag,{className:"w-5 h-5 text-gray-500 dark:text-gray-400"})})]}),j.jsx("div",{className:"p-6",children:j.jsx("p",{className:"text-gray-600 dark:text-gray-300 leading-relaxed",children:i})}),j.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:[j.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}),j.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?j.jsxs("div",{className:"flex items-center gap-2",children:[j.jsx("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"}),"Clearing..."]}):A})]})]})})}const $rt=(e,t)=>{const[r,n]=F.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 F.useEffect(()=>{(async()=>{var A;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:((A=s.license)==null?void 0:A.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},am=100;function sV({onRequestClose:e}){const{conversations:t,currentConversationId:r,createConversation:n,selectConversation:i,deleteConversation:A,deleteAllConversations:a,updateConversationTitle:s,canCreateNewConversation:o,getConversationCount:l}=Ot(),c=t.find(pe=>pe.id===r),[u,g]=F.useState(""),[h,d]=F.useState(null),[B,f]=F.useState(""),[w,y]=F.useState({isOpen:!1,conversationId:"",conversationTitle:"",isDeleting:!1}),[I,Y]=F.useState({isOpen:!1,isDeleting:!1}),Q=t.filter(pe=>pe.title.toLowerCase().includes(u.toLowerCase())||pe.messages.some(xe=>xe.content.toLowerCase().includes(u.toLowerCase()))),M=o(),D=l(),G=Nr.maxConversations,T=G!==null&&D>=G,R=c?c.messages.length===0:!1,L=G!==null?`${D}/${G} conversations`:`${D} conversation${D===1?"":"s"}`,z=M?"Start a new conversation":T?`Maximum ${G} conversations reached. Delete a conversation to create a new one.`:R?"Current conversation is empty. Send a message first to create a new conversation.":"Finish your current conversation before starting a new one.",te=drt(),V=$rt(ZK(),qK()),Z=()=>{try{n(),e==null||e()}catch(pe){Ir("Cannot create new conversation:",pe instanceof Error?pe.message:"Unknown error")}},ee=async pe=>{try{await i(pe),e==null||e()}catch{}},ie=(pe,xe)=>{pe.stopPropagation(),y({isOpen:!0,conversationId:xe.id,conversationTitle:xe.title,isDeleting:!1})},K=async()=>{y(pe=>({...pe,isDeleting:!0}));try{await A(w.conversationId),y({isOpen:!1,conversationId:"",conversationTitle:"",isDeleting:!1})}catch{y({isOpen:!1,conversationId:"",conversationTitle:"",isDeleting:!1})}},$=()=>{y({isOpen:!1,conversationId:"",conversationTitle:"",isDeleting:!1})},P=(pe,xe)=>{pe.stopPropagation(),d(xe.id),f(xe.title.slice(0,am))},oe=pe=>{const xe=B.slice(0,am).trim();xe&&s(pe,xe),d(null),f("")},le=()=>{d(null),f("")},O=()=>{Y({isOpen:!0,isDeleting:!1})},de=async()=>{Y(pe=>({...pe,isDeleting:!0}));try{await a(),Y({isOpen:!1,isDeleting:!1})}catch{Y({isOpen:!1,isDeleting:!1})}},Ee=()=>{Y({isOpen:!1,isDeleting:!1})},Ce=pe=>{const xe=pe.toLocaleDateString([],{year:"numeric",month:"short",day:"numeric"}),ye=pe.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});return`${xe} · ${ye}`};return j.jsxs(j.Fragment,{children:[j.jsxs("div",{className:"flex h-full w-full md:w-72 flex-col border-r border-b border-gray-200 bg-gray-50 dark:border-[#4a4b54] dark:bg-[#202123]",children:[j.jsxs("div",{className:"border-b border-gray-200 p-4 dark:border-[#4a4b54]",children:[j.jsxs("button",{onClick:Z,disabled:!M,className:`flex w-full items-center justify-center gap-2 rounded-md px-3 py-2 text-sm font-medium ${M?"bg-[#343541] text-white hover:bg-[#2c2f36] dark:bg-[#565869] dark:hover:bg-[#6b6f7a]":"cursor-not-allowed bg-gray-200 text-gray-500 dark:bg-[#3c3f4a] dark:text-[#6b6f7a]"}`,title:z,children:[j.jsx(x0e,{className:"h-4 w-4"}),"New Conversation"]}),j.jsxs("div",{className:"mt-3 space-y-2",children:[j.jsx("div",{className:"text-center",children:j.jsx("span",{className:"text-xs text-gray-500 dark:text-[#bfc2cd]",children:L})}),t.length>0&&t.some(pe=>pe.messages.length>0)&&j.jsxs("button",{onClick:O,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:[j.jsx(G0e,{className:"h-4 w-4"}),"Clear All"]})]})]}),j.jsx("div",{className:"border-b border-gray-200 px-4 py-3 dark:border-[#4a4b54]",children:j.jsxs("div",{className:"relative flex items-center",children:[j.jsx(k0e,{className:"pointer-events-none absolute left-3 h-4 w-4 text-gray-400"}),j.jsx("input",{type:"text",placeholder:"Search conversations",value:u,onChange:pe=>g(pe.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 focus:border-gray-400 focus:outline-none dark:border-[#4a4b54] dark:bg-[#343541] dark:text-[#ececf1]"})]})}),j.jsx("div",{className:"flex-1 overflow-y-auto px-3 py-3",children:Q.length===0?j.jsxs("div",{className:"rounded-md border border-dashed border-gray-300 p-6 text-center text-sm text-gray-500 dark:border-[#4a4b54] dark:text-[#bfc2cd]",children:[j.jsx(Yh,{className:"mx-auto mb-3 h-6 w-6 text-gray-400 dark:text-[#6b6f7a]"}),j.jsx("p",{children:u?"No conversations found":"No conversations yet"})]}):j.jsx("div",{className:"space-y-2",children:Q.map(pe=>j.jsxs("div",{onClick:()=>ee(pe.id),className:`group flex cursor-pointer items-start gap-3 rounded-xl border px-3 py-3 text-left transition ${r===pe.id?"border-[#343541] bg-white shadow-sm dark:border-[#6b6f7a] dark:bg-[#2c2f36]":"border-transparent bg-gray-100/70 hover:border-gray-300 hover:bg-white dark:bg-[#252830] dark:hover:border-[#4a4b54] dark:hover:bg-[#2f323c]"}`,children:[j.jsx("div",{className:`rounded-xl p-2 shadow-sm ${r===pe.id?"bg-[#eceefc] text-[#1d2559] dark:bg-[#3b4055] dark:text-white":"bg-white text-gray-500 dark:bg-[#3a3d46] dark:text-[#bfc2cd]"}`,children:j.jsx(Yh,{className:"h-4 w-4"})}),h===pe.id?j.jsx("input",{type:"text",value:B,onChange:xe=>f(xe.target.value.slice(0,am)),onKeyDown:xe=>{xe.key==="Enter"&&oe(pe.id),xe.key==="Escape"&&le()},onBlur:()=>oe(pe.id),maxLength:am,className:"flex-1 border-none bg-transparent text-sm text-[#353740] focus:outline-none dark:text-[#ececf1]",autoFocus:!0}):j.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[j.jsxs("div",{className:"flex items-center gap-2",children:[j.jsx("h3",{className:`flex-1 truncate text-sm font-semibold ${r===pe.id?"text-[#1f2937] dark:text-white":"text-gray-700 dark:text-[#d4d7e2]"}`,children:pe.title}),j.jsxs("div",{className:"flex items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100",children:[j.jsx("button",{onClick:xe=>P(xe,pe),className:"rounded-full p-2 text-gray-500 hover:bg-gray-200 hover:text-[#353740] dark:text-[#bfc2cd] dark:hover:bg-[#3c3f4a]",title:"Rename conversation",children:j.jsx(Y0e,{className:"h-4 w-4"})}),j.jsx("button",{onClick:xe=>ie(xe,pe),className:"rounded-full p-2 text-red-500 hover:bg-red-50 dark:text-red-300 dark:hover:bg-red-900/30",title:"Delete conversation",children:j.jsx(bX,{className:"h-4 w-4"})})]})]}),j.jsxs("div",{className:"mt-1 flex items-center gap-1.5 pr-1 text-[11px] text-gray-500 dark:text-[#a6acc5]",children:[j.jsx("span",{className:"whitespace-nowrap leading-none",children:Ce(pe.updatedAt)}),j.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 rounded-full bg-white/80 px-2 py-0.5 font-medium text-gray-600 shadow-sm dark:bg-white/10 dark:text-[#e5e7f4] leading-none",children:[j.jsx(Yh,{className:"h-3 w-3"}),pe.messages.length]}),pe.attachedFiles&&pe.attachedFiles.length>0&&j.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 rounded-full bg-white/80 px-2 py-0.5 font-medium text-gray-600 shadow-sm dark:bg-white/10 dark:text-[#e5e7f4] leading-none",children:[j.jsx(YX,{className:"h-3 w-3"}),pe.attachedFiles.length]})]})]})]},pe.id))})}),te&&j.jsx("div",{className:"border-t border-gray-200 p-4 dark:border-[#4a4b54]",children:j.jsxs("div",{className:"text-center",children:[j.jsx("div",{className:"flex items-center justify-center mb-3",children:j.jsx("span",{className:"text-sm font-medium text-gray-900 dark:text-[#ececf1]",children:"Powered by ORBIT"})}),V.isLoading?j.jsxs("div",{className:"flex items-center justify-center gap-2 text-xs text-gray-500 dark:text-[#bfc2cd] mb-3",children:[j.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-gray-400"}),j.jsx("span",{children:"Loading stats..."})]}):V.error?j.jsx("div",{className:"flex items-center justify-center gap-2 text-xs text-red-500 dark:text-red-400 mb-3",children:j.jsx("span",{children:"⚠️ Failed to load stats"})}):j.jsxs("div",{className:"flex items-center justify-center gap-4 text-xs text-gray-500 dark:text-[#bfc2cd] mb-3",children:[j.jsxs("div",{className:"flex items-center gap-1",children:[j.jsx("svg",{className:"w-4 h-4 text-yellow-500",fill:"currentColor",viewBox:"0 0 24 24",children:j.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"})}),j.jsxs("span",{children:[V.stars.toLocaleString()," stars"]})]}),j.jsxs("div",{className:"flex items-center gap-1",children:[j.jsx("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 16 16",children:j.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"})}),j.jsxs("span",{children:[V.forks.toLocaleString()," forks"]})]})]}),j.jsxs("a",{href:`https://github.com/${ZK()}/${qK()}`,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:[j.jsx("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 24 24",children:j.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"]})]})})]}),j.jsx(aV,{isOpen:w.isOpen,onClose:$,onConfirm:K,title:"Delete Conversation",message:`Are you sure you want to delete "${w.conversationTitle}"? This will clear the conversation history from both the server and your local storage. This action cannot be undone.`,confirmText:"Delete",cancelText:"Cancel",type:"danger",isLoading:w.isDeleting}),j.jsx(aV,{isOpen:I.isOpen,onClose:Ee,onConfirm:de,title:"Clear All Conversations",message:`Are you sure you want to delete all ${D} conversation${D!==1?"s":""}? This will clear all conversation history from both the server and your local storage. This action cannot be undone.`,confirmText:"Clear All",cancelText:"Cancel",type:"danger",isLoading:I.isDeleting})]})}function ent({isOpen:e,onClose:t}){const{theme:r,updateTheme:n}=IX(),{settings:i,updateSettings:A}=cy(),[a,s]=F.useState(null),[o,l]=F.useState(!1),[c,u]=F.useState(""),[g,h]=F.useState(!1);if(F.useEffect(()=>{e&&Cle().then(s)},[e]),!e)return null;const d=M=>{n({mode:M})},B=M=>{n({fontSize:M})},f=()=>{n({highContrast:!r.highContrast})},w=()=>{A({soundEnabled:!i.soundEnabled})},y=()=>{u(""),h(!1),l(!0)},I=()=>{l(!1),u(""),h(!1)},Y=()=>{I(),localStorage.clear(),window.location.reload()},Q=g&&c.trim().toLowerCase()==="reset";return j.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50",children:j.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:[j.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-600",children:[j.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-gray-100",children:"Settings"}),j.jsx("button",{onClick:t,className:"p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors",children:j.jsx(ag,{className:"w-5 h-5 text-gray-500 dark:text-gray-400"})})]}),j.jsxs("div",{className:"flex-1 min-h-0 p-6 space-y-6 overflow-y-auto",children:[j.jsxs("div",{className:"space-y-4",children:[j.jsxs("h3",{className:"text-lg font-medium text-gray-900 dark:text-gray-100 flex items-center gap-2",children:[j.jsx(M0e,{className:"w-5 h-5"}),"Appearance"]}),j.jsxs("div",{className:"space-y-2",children:[j.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Theme"}),j.jsx("div",{className:"grid grid-cols-3 gap-2",children:[{value:"light",label:"Light",icon:S0e},{value:"dark",label:"Dark",icon:C0e},{value:"system",label:"System",icon:I0e}].map(({value:M,label:D,icon:G})=>j.jsxs("button",{onClick:()=>d(M),className:`flex flex-col items-center gap-2 p-3 rounded-lg border-2 transition-all duration-200 ${r.mode===M?"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:[j.jsx(G,{className:"w-5 h-5"}),j.jsx("span",{className:"text-sm font-medium",children:D})]},M))})]}),j.jsxs("div",{className:"flex items-center justify-between",children:[j.jsxs("div",{children:[j.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"High Contrast"}),j.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Improve readability with enhanced contrast"})]}),j.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:j.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${r.highContrast?"translate-x-6":"translate-x-1"}`})})]}),j.jsxs("div",{className:"space-y-2",children:[j.jsxs("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 flex items-center gap-2",children:[j.jsx(R0e,{className:"w-4 h-4"}),"Font Size"]}),j.jsx("div",{className:"grid grid-cols-3 gap-2",children:[{value:"small",label:"Small"},{value:"medium",label:"Medium"},{value:"large",label:"Large"}].map(({value:M,label:D})=>j.jsx("button",{onClick:()=>B(M),className:`p-2 rounded-lg border-2 transition-colors text-center ${r.fontSize===M?"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:j.jsx("span",{className:`font-medium ${M==="small"?"text-sm":M==="large"?"text-lg":"text-base"}`,children:D})},M))})]})]}),j.jsxs("div",{className:"space-y-4",children:[j.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-gray-100",children:"Chat Preferences"}),j.jsxs("div",{className:"flex items-center justify-between",children:[j.jsxs("div",{className:"flex items-center gap-2",children:[j.jsx(uw,{className:"w-4 h-4 text-gray-600 dark:text-gray-400"}),j.jsxs("div",{children:[j.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Sound Effects"}),j.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Play sounds for notifications and events"})]})]}),j.jsx("button",{onClick:w,className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${i.soundEnabled?"bg-blue-600":"bg-gray-200 dark:bg-gray-600"}`,children:j.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${i.soundEnabled?"translate-x-6":"translate-x-1"}`})})]})]}),j.jsxs("div",{className:"space-y-4 pt-4 border-t border-gray-200 dark:border-gray-600",children:[j.jsxs("h3",{className:"text-lg font-medium text-gray-900 dark:text-gray-100 flex items-center gap-2",children:[j.jsx(bX,{className:"w-5 h-5"}),"Data Management"]}),j.jsxs("div",{className:"space-y-3",children:[j.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Clear all application data including conversations, and personalized settings."}),j.jsx("button",{onClick:y,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"})]})]}),j.jsxs("div",{className:"space-y-2 pt-4 border-t border-gray-200 dark:border-gray-600",children:[j.jsxs("h3",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 flex items-center gap-2",children:[j.jsx(Q0e,{className:"w-4 h-4"}),"About"]}),j.jsxs("div",{className:"space-y-1",children:[j.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"]}),j.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)&&j.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"})]}),j.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Built with React, TypeScript, and Tailwind CSS"})]})]})]}),o&&j.jsx("div",{className:"absolute inset-0 bg-black/70 flex items-center justify-center p-4 z-50",children:j.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:[j.jsxs("div",{className:"flex items-start gap-3",children:[j.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-red-100 dark:bg-red-900/40",children:j.jsx(QX,{className:"w-5 h-5 text-red-600 dark:text-red-400"})}),j.jsxs("div",{children:[j.jsx("p",{className:"text-base font-semibold text-gray-900 dark:text-gray-100",children:"Reset application data?"}),j.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:["This removes everything stored on this device. Type ",j.jsx("span",{className:"font-semibold text-gray-900 dark:text-gray-100",children:"RESET"})," to continue."]})]})]}),j.jsxs("div",{className:"space-y-2",children:[j.jsx("label",{className:"text-xs font-medium text-gray-700 dark:text-gray-300",children:"Confirmation text"}),j.jsx("input",{value:c,onChange:M=>u(M.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"})]}),j.jsxs("label",{className:"flex items-start gap-2 text-xs text-gray-600 dark:text-gray-400",children:[j.jsx("input",{type:"checkbox",checked:g,onChange:M=>h(M.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"}),j.jsx("span",{children:"I understand this action is permanent and will reload the app."})]}),j.jsxs("div",{className:"flex gap-2 pt-2",children:[j.jsx("button",{onClick:I,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:"Keep my data"}),j.jsx("button",{onClick:Y,disabled:!Q,className:`flex-1 px-4 py-2 text-sm font-semibold rounded-lg transition-colors ${Q?"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:"Delete everything"})]})]})})]})})}function tnt(){const[e,t]=F.useState(!1),[r,n]=F.useState(!1);return j.jsx(l0e,{children:j.jsx(c0e,{children:j.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:[j.jsx("div",{className:"hidden md:flex md:min-h-screen",children:j.jsx(sV,{})}),j.jsx("div",{className:"flex-1 flex justify-center w-full",children:j.jsx(_rt,{onOpenSettings:()=>t(!0),onOpenSidebar:()=>n(!0)})}),j.jsx(ent,{isOpen:e,onClose:()=>t(!1)}),r&&j.jsxs("div",{className:"fixed inset-0 z-50 flex md:hidden",children:[j.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>n(!1),"aria-hidden":"true"}),j.jsxs("div",{className:"relative z-10 h-full w-[min(18rem,85vw)] animate-slideIn",children:[j.jsx(sV,{onRequestClose:()=>n(!1)}),j.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:j.jsx(ag,{className:"h-5 w-5"})})]})]})]})})})}Cle().then(e=>{Je(`📱 App Version: v${e.appVersion}`),Je(`📦 API Package: @schmitech/chatbot-api v${e.apiVersion}`),Je(`🔧 API Mode: ${e.isLocalApi?"Local":"NPM Package"}`)});yX(document.getElementById("root")).render(j.jsx(F.StrictMode,{children:j.jsx(tnt,{})}));export{_ze as $,Bnt as A,h1e as B,I3e as C,Fa as D,fTe as E,MTe as F,b_ as G,E3e as H,yTe as I,Ant as J,pTe as K,dnt as L,l1e as M,ant as N,JTe as O,Zxe as P,m1e as Q,Uh as R,KS as S,Ri as T,y_ as U,hRe as V,HSe as W,$7 as X,_7 as Y,g$ as Z,nr as _,ve as a,G$ as a$,Xxe as a0,Y$ as a1,lS as a2,zy as a3,Nke as a4,xke as a5,Yg as a6,bke as a7,Yke as a8,zw as a9,qNe as aA,vk as aB,K7 as aC,Rh as aD,eRe as aE,tRe as aF,nRe as aG,$Ge as aH,PGe as aI,$w as aJ,$te as aK,YGe as aL,TS as aM,KGe as aN,DGe as aO,Sve as aP,qte as aQ,gRe as aR,eB as aS,A1e as aT,$d as aU,gt as aV,Et as aW,x_ as aX,dS as aY,j6 as aZ,T6 as a_,AB as aa,sS as ab,AS as ac,gc as ad,Rw as ae,X_ as af,IA as ag,QDe as ah,Ok as ai,P_ as aj,nB as ak,snt as al,BUe as am,v7 as an,_y as ao,qk as ap,en as aq,BS as ar,Hy as as,kNe as at,Yze as au,_k as av,pS as aw,int as ax,Cg as ay,iRe as az,pt as b,jw as b0,unt as b1,ont as b2,xg as b3,_a as b4,lnt as b5,hnt as b6,cnt as b7,gnt as b8,nnt as b9,vve as bA,Lve as bB,_g as bC,L2 as bD,Ll as bE,kGe as bF,Rve as bG,Gve as bH,aJ as bI,oB as bJ,Ote as bK,Zw as bL,qg as bM,Pte as bN,_w as bO,LS as bP,tJ as bQ,sB as bR,rRe as bS,Zy as bT,C3e as ba,$n as bb,Hl as bc,Sre as bd,uu as be,Are as bf,St as bg,Cs as bh,zS as bi,Pve as bj,TJ as bk,cB as bl,Mze as bm,Qze as bn,Zk as bo,Bt as bp,Tte as bq,qy as br,Ky as bs,ou as bt,Zte as bu,zGe as bv,gje as bw,zve as bx,nc as by,jS as bz,fnt as c,pnt as d,sie as e,Ar as f,u1e as g,g1e as h,Xn as i,RS as j,bo as k,x3e as l,pRe as m,Vg as n,wnt as o,Cr as p,sre as q,Ent as r,mnt as s,ynt as t,c1e as u,Ta as v,d1e as w,k as x,fa as y,B1e as z};
1236
+ `,children:[j.jsx("input",{ref:g,type:"file",multiple:!0,onChange:Z,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"}),j.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 text-center",children:[j.jsx(z0e,{className:`w-6 h-6 ${o?"text-emerald-600 dark:text-emerald-400":"text-slate-400 dark:text-slate-500"}`}),j.jsxs("div",{className:"px-2",children:[j.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"}),j.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)"]})]})]})]}),$.length>0&&j.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:[j.jsx("p",{className:"text-xs font-semibold text-slate-600 dark:text-slate-300",children:"Uploads in other conversations"}),$.map(({conversationId:oe,uploads:le})=>j.jsxs("div",{className:"space-y-2",children:[j.jsx("div",{className:"text-xs font-medium text-slate-500 dark:text-slate-400",children:K.get(oe)||"Conversation"}),le.map(({key:O,progress:de})=>j.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:[j.jsx(Ag,{className:"w-4 h-4 text-emerald-600 dark:text-emerald-400 animate-spin flex-shrink-0"}),j.jsxs("div",{className:"flex-1 min-w-0 overflow-hidden",children:[j.jsx("p",{className:"text-sm font-medium text-slate-700 dark:text-slate-300 truncate",children:de.filename}),j.jsx("div",{className:"mt-1 bg-slate-200 dark:bg-slate-700 rounded-full h-1.5",children:j.jsx("div",{className:"bg-emerald-600 dark:bg-emerald-400 h-1.5 rounded-full transition-all duration-300",style:{width:`${de.progress}%`}})})]}),j.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:de.status==="uploading"?"Uploading...":de.status==="processing"?"Processing...":de.status==="completed"?"Done":"Error"})]},O))]},oe))]})]})}const rV={"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 Wrt(e){if(!e)return"bin";if(rV[e])return rV[e];const t=e.split("/");return t.length===2&&t[1]?t[1]:"bin"}function Prt(e){return e.replace(/[^a-zA-Z0-9._-]/g,"_").replace(/_+/g,"_")||"pasted-file"}function Krt(e){const t=e.lastIndexOf(".");return t===-1||t===e.length-1?null:e.slice(t+1).toLowerCase()}function Vrt(e){const t=e.lastIndexOf(".");return t===-1?e:e.slice(0,t)}function Xrt(e,t){const r=Date.now(),n=e.name&&e.name.trim().length>0?e.name.trim():"pasted-file",i=Prt(Vrt(n)),a=Krt(n)||Wrt(e.type),s=`${i}-${r}-${t}.${a}`;return new File([e],s,{type:e.type||"application/octet-stream"})}function nV({onSend:e,disabled:t=!1,placeholder:r="Ask me anything...",isCentered:n=!1}){var Wt;const[i,A]=F.useState(""),[a,s]=F.useState(!1),[o,l]=F.useState(!1),[c,u]=F.useState(!1),[g,h]=F.useState([]),[d,B]=F.useState({}),[f,w]=F.useState(new Map),[y,I]=F.useState(!1),[Y,Q]=F.useState(!1),[M,D]=F.useState(null),[G,T]=F.useState(null),R=F.useRef(null),L=F.useRef(new Set),z=F.useRef(""),te=F.useRef(!1),V=F.useRef(0),Z=F.useRef(null),{settings:ee,updateSettings:ie}=cy(),K=F.useCallback((ze,Ze)=>{ze&&B(Jt=>{if(Jt[ze]===Ze)return Jt;const bt={...Jt};return Ze?bt[ze]=!0:delete bt[ze],bt})},[]),[$,P]=F.useState(0),{createConversation:oe,currentConversationId:le,conversations:O,isLoading:de,syncConversationFiles:Ee}=Ot(),Ce=O.find(ze=>ze.id===le),pe=F.useCallback(()=>{P(ze=>ze+1)},[]),{isListening:xe,isSupported:ye,startListening:je,stopListening:Ne,error:Qe}=Crt(ze=>{A(Ze=>{const Jt=(Ze+ze).slice(0,Nr.maxMessageLength);return z.current=Jt,Jt})},pe),Se=urt(),Te=Se&&ye,Ve=crt(),et=(Ce==null?void 0:Ce.attachedFiles)||[],rt=((Wt=Ce==null?void 0:Ce.adapterInfo)==null?void 0:Wt.isFileSupported)??!1,It=g.some(ze=>ze.processing_status?ze.processing_status!=="completed"&&ze.processing_status!=="error"&&ze.processing_status!=="failed":!0)||et.some(ze=>ze.processing_status?ze.processing_status!=="completed"&&ze.processing_status!=="error"&&ze.processing_status!=="failed":!0),hr=le?!!d[le]:!1,yr=Object.values(d).some(Boolean),Xt=t||It||hr,ii=Ve&&rt,mi=!ii||Xt;F.useEffect(()=>{if(R.current){R.current.style.height="auto";const Ze=R.current.scrollHeight;R.current.style.height=`${Math.min(Ze,120)}px`,R.current.style.overflowY=Ze>120?"auto":"hidden"}},[i]);const Mn=()=>{const ze=document.activeElement;return ze&&ze.tagName==="TEXTAREA"};F.useEffect(()=>{!Xt&&R.current&&!Mn()&&R.current.focus()},[Xt]);const Fr=F.useRef(de);F.useEffect(()=>{Fr.current&&!de&&!Xt&&R.current&&setTimeout(()=>{R.current&&!Mn()&&R.current.focus()},100),Fr.current=de},[de,Xt]),F.useEffect(()=>{if(!Te||($>V.current&&(te.current=!0,V.current=$),!te.current||$===0))return;const ze=setTimeout(()=>{const Ze=z.current.trim(),Jt=Ot.getState();if(Je("[MessageInput] Auto-send check after voice completion:",{hasMessage:!!Ze,isInputDisabled:Xt,isComposing:a,isLoading:Jt.isLoading}),!Ze){te.current=!1;return}if(!Xt&&!a&&!Jt.isLoading){const bt=Jt.conversations.find(Er=>Er.id===Jt.currentConversationId),Yr=((bt==null?void 0:bt.attachedFiles)||[]).map(Er=>Er.file_id);e(Ze,Yr.length>0?Yr:void 0),te.current=!1,A(""),z.current="",R.current&&(R.current.style.height="auto",R.current.style.overflowY="hidden")}},400);return()=>clearTimeout(ze)},[Te,$,Xt,a,e]),F.useEffect(()=>{hr&&c&&u(!1)},[hr,c]),F.useEffect(()=>{!hr&&g.length},[hr,g.length,c]);const Ye=F.useCallback((ze,Ze)=>{setTimeout(()=>{let Jt=Ot.getState(),bt=Ze||Jt.currentConversationId;if(bt||(bt=oe(),Jt=Ot.getState(),bt=Jt.currentConversationId||bt),!bt)return;const Tt=new Set(ze.map(Er=>Er.file_id)),Yr=[];L.current.forEach((Er,Ut)=>{const[,...Vr]=Ut.split("-"),$a=Vr.join("-");Tt.has($a)||Yr.push(Ut)}),Yr.forEach(Er=>L.current.delete(Er)),ze.forEach(Er=>{const Ut=`${bt}-${Er.file_id}`;L.current.has(Ut)||(L.current.add(Ut),Je(`[MessageInput] Adding file ${Er.file_id} to conversation ${bt}`),Jt.addFileToConversation(bt,Er))})},0)},[oe]);F.useEffect(()=>{if(le!==Z.current)if(Z.current=le||null,le&&Ce){const ze=Ce.attachedFiles||[];h(ze.map(Ze=>({...Ze})))}else h([])},[le,Ce]),F.useEffect(()=>{if(le&&Ce){const ze=Ce.attachedFiles||[];ze.length>0?h(Ze=>{const Jt=new Set(Ze.map(Tt=>Tt.file_id)),bt=ze.filter(Tt=>!Jt.has(Tt.file_id));return bt.length>0?(Je(`[MessageInput] Syncing ${bt.length} missing files from conversation to UI`),[...Ze,...bt]):Ze}):ze.length===0&&g.length>0&&h([])}},[le,Ce,O,g.length]),F.useEffect(()=>{var Yr;const ze=typeof window<"u"&&((Yr=window.ORBIT_CHAT_CONFIG)==null?void 0:Yr.enableApiMiddleware)===!0;if(!le||!Ce||(ze?!Ce.adapterName:!Ce.apiKey))return;const Ze=Ce.attachedFiles||[],Jt=Ze.length>0,bt=Ze.filter(Er=>!Er.processing_status||Er.processing_status==="processing"||Er.processing_status==="uploading");if(Jt&&(Je(`[MessageInput] Syncing ${Ze.length} files for conversation ${le}...`),Ee(le).catch(Er=>{})),bt.length===0)return;Je(`[MessageInput] Found ${bt.length} files still processing, starting poll...`);const Tt=setInterval(async()=>{const Ut=Ot.getState().conversations.find(_A=>_A.id===le);if(!Ut){clearInterval(Tt);return}if((Ut.attachedFiles||[]).filter(_A=>!_A.processing_status||_A.processing_status==="processing"||_A.processing_status==="uploading").length===0){clearInterval(Tt);return}try{await Ee(le)}catch{}},3e3);return()=>{clearInterval(Tt)}},[le,Ce,Ee]),F.useEffect(()=>{B(ze=>{const Ze=new Set(O.map(Tt=>Tt.id));let Jt=!1;const bt={...ze};return Object.keys(bt).forEach(Tt=>{Ze.has(Tt)||(delete bt[Tt],Jt=!0)}),Jt?bt:ze})},[O]);const Ue=ze=>{if(ze.preventDefault(),(i.trim()||g.length>0)&&!Xt&&!a){xe&&Ne();const Jt=((Ce==null?void 0:Ce.attachedFiles)||[]).map(bt=>bt.file_id);e(i.trim(),Jt.length>0?Jt:void 0),mh("messageSent",ee.soundEnabled),A(""),z.current="",h([]),u(!1),R.current&&(R.current.style.height="auto",R.current.style.overflowY="hidden")}},Xe=F.useCallback(ze=>{if(!ze||ze.length===0)return;const Ze=ze.length===1?`File "${ze[0].filename}" uploaded successfully`:`${ze.length} files uploaded successfully`;mh("success",ee.soundEnabled),T(Ze),setTimeout(()=>{T(null)},6e3)},[ee.soundEnabled]),Nt=F.useCallback((ze,Ze)=>{Je(`[MessageInput] handleFilesSelected called with ${Ze.length} files for conversation ${ze}:`,Ze),ze&&(ze===le&&h(Ze),Ye(Ze,ze))},[le,Ye]),vt=F.useCallback((ze,Ze)=>{ze===le&&Xe(Ze)},[le,Xe]),Dt=ze=>{ze.key==="Enter"&&!ze.shiftKey&&!a&&(ze.preventDefault(),Ue(ze))},Ge=()=>{xe?Ne():je()},De=()=>{ie({voiceEnabled:!ee.voiceEnabled})},Yt=F.useCallback(async ze=>{var Er;if(!Ve||!o||!rt||Xt)return;const Ze=ze.clipboardData;if(!Ze||!Ze.items)return;const bt=Array.from(Ze.items).filter(Ut=>Ut.kind==="file");if(bt.length===0)return;const Tt=[];if(bt.forEach((Ut,Vr)=>{const $a=Ut.getAsFile();$a&&Tt.push(Xrt($a,Vr))}),Tt.length===0)return;ze.preventDefault(),D(null),T(null);let Yr=null;try{const Ut=Ot.getState(),Vr=Ut.conversations.find(ke=>ke.id===Ut.currentConversationId);if(((Vr==null?void 0:Vr.attachedFiles)||[]).length+Tt.length>Nr.maxFilesPerConversation)throw new Error(`Maximum ${Nr.maxFilesPerConversation} files allowed per conversation. Please remove some files first.`);if(Nr.maxTotalFiles!==null&&Ut.conversations.reduce((J,Ae)=>{var Gt;return J+(((Gt=Ae.attachedFiles)==null?void 0:Gt.length)||0)},0)+Tt.length>Nr.maxTotalFiles)throw new Error(`Maximum ${Nr.maxTotalFiles} total files allowed across all conversations. Please remove some files from other conversations first.`);if(!Vr||!Vr.apiKey||Vr.apiKey===Fc())throw new Error("API key not configured for this conversation. Please configure API settings first.");const es=Vr.apiKey,vr=to(Vr.apiUrl);Yr=Vr.id,K(Yr,!0);const x=[],U=[];for(let ke=0;ke<Tt.length;ke++){const J=Tt[ke],Ae=J.name||`Clipboard file ${ke+1}`,Gt=`${Ae}-${Date.now()}-${ke}`;w(Gr=>{const Yi=new Map(Gr);return Yi.set(Gt,{filename:Ae,progress:0,status:"uploading"}),Yi});const nt=Gr=>{w(Yi=>{const ae=new Map(Yi),ce=ae.get(Gt);return ce&&ae.set(Gt,{...ce,filename:Ae,progress:Gr.progress,status:Gr.status,fileId:Gr.fileId}),ae})},kn=()=>new Promise(Gr=>{w(Yi=>{const ae=new Map(Yi),ce=ae.get(Gt);return ce&&ae.set(Gt,{...ce,progress:100,status:"completed"}),ae}),setTimeout(()=>{w(Yi=>{const ae=new Map(Yi);return ae.delete(Gt),ae}),Gr()},2500)});Je(`[MessageInput] Pasting file: ${J.name}, type: ${J.type||"unknown"}, size: ${J.size}`);const Ai=typeof window<"u"&&((Er=window.ORBIT_CHAT_CONFIG)==null?void 0:Er.enableApiMiddleware)===!0,ft=Ce==null?void 0:Ce.adapterName,Xr=await Td.uploadFile(J,Gr=>{Je(`[MessageInput] Paste upload progress for ${J.name}: ${Gr.progress}% - ${Gr.status}`),nt(Gr)},es,vr,Ai?ft:void 0);x.push(Xr),U.push(kn())}if(x.length>0){let ke=x;if(Yr&&Yr===le){const J=new Set(g.map(Gt=>Gt.file_id)),Ae=x.filter(Gt=>!J.has(Gt.file_id));Ae.length>0?(h(Gt=>[...Gt,...Ae]),ke=Ae):ke=[]}ke.length>0&&Ye(ke,Yr),await Promise.all(U),Xe(x)}}catch(Ut){const Vr=Ut instanceof Error?Ut.message:"Failed to paste file";mh("error",ee.soundEnabled),D(Vr),setTimeout(()=>{D(null)},5e3),w(new Map)}finally{K(Yr,!1)}},[g,Ce==null?void 0:Ce.adapterName,le,o,rt,Xt,K,ee.soundEnabled,Xe,Ye,Ve]),zt=It||hr?"Files are uploading/processing, please wait...":ii?"Message ORBIT or drop files here":r;F.useEffect(()=>{!Se||!Qe||mh("error",ee.soundEnabled)},[Se,ee.soundEnabled,Qe]);const tr=n?"max-w-3xl":"max-w-5xl",sr=n?"flex justify-center":"";return j.jsx("div",{className:`bg-white px-3 py-3 md:px-0 md:py-4 dark:bg-[#212121] sm:px-4 ${sr}`,children:j.jsxs("div",{className:`mx-auto w-full ${tr}`,children:[Qe&&Se&&j.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:Qe}),M&&j.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:M}),G&&j.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:[j.jsx(h0e,{className:"h-4 w-4 flex-shrink-0"}),j.jsx("span",{children:G})]}),j.jsxs("form",{onSubmit:Ue,className:"flex w-full flex-col gap-2 md:gap-3",children:[j.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:[j.jsx("textarea",{ref:R,value:i,onChange:ze=>A(ze.target.value),onKeyDown:Dt,onPaste:Yt,onCompositionStart:()=>s(!0),onCompositionEnd:()=>s(!1),onFocus:()=>l(!0),onBlur:()=>l(!1),placeholder:zt,disabled:Xt,rows:1,maxLength:Nr.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:i.trim()||o?"inherit":"transparent"}}),j.jsxs("div",{className:"flex items-center justify-between md:justify-end gap-1 md:gap-2 md:flex-shrink-0",children:[j.jsxs("div",{className:"flex items-center gap-1 md:gap-2",children:[Ve&&j.jsx("button",{type:"button",onClick:ze=>{ze.preventDefault(),mi||u(!c)},disabled:mi,onMouseEnter:()=>I(!0),onMouseLeave:()=>I(!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]":mi?"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:rt?Xt?"Files are uploading/processing. Please wait...":g.length>0?`${g.length} file(s) attached`:"Attach files":"File upload not supported by this adapter",children:mi&&y?j.jsx(ag,{className:"h-5 w-5 md:h-4 md:w-4"}):j.jsx(YX,{className:"h-5 w-5 md:h-4 md:w-4"})}),i.length>0&&j.jsx("div",{className:"px-2 text-xs text-gray-500 dark:text-[#bfc2cd] md:min-w-[72px] md:text-right",children:j.jsxs("span",{className:i.length>=Nr.maxMessageLength?"text-red-600 font-semibold":"",children:[i.length,"/",Nr.maxMessageLength]})})]}),j.jsxs("div",{className:"flex items-center gap-1 md:gap-2",children:[Se&&j.jsxs(j.Fragment,{children:[j.jsx("button",{type:"button",onClick:De,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 ${ee.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:ee.voiceEnabled?"Voice responses enabled - Click to disable":"Enable voice responses (text-to-speech)",children:ee.voiceEnabled?j.jsx(uw,{className:"h-5 w-5"}):j.jsx(T0e,{className:"h-5 w-5"})}),Te&&j.jsx("button",{type:"button",onClick:Ge,disabled:Xt,onMouseEnter:()=>Q(!0),onMouseLeave:()=>Q(!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 ${xe?"bg-red-100 text-red-600 dark:bg-red-900/40 dark:text-red-300":Xt?"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:Xt?"Files are uploading/processing. Please wait...":xe?"Stop recording":"Start voice input",children:xe||Xt&&Y?j.jsx(y0e,{className:"h-5 w-5"}):j.jsx(E0e,{className:"h-5 w-5"})})]}),(It||hr)&&j.jsx("div",{className:"flex h-10 w-10 md:h-8 md:w-8 shrink-0 items-center justify-center",children:j.jsx(Ag,{className:"h-5 w-5 md:h-4 md:w-4 animate-spin text-gray-500 dark:text-[#bfc2cd]"})}),j.jsx("button",{type:"submit",disabled:!i.trim()&&g.length===0||Xt||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 ${(i.trim()||g.length>0)&&!Xt&&!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:j.jsx(MX,{className:"h-5 w-5 md:h-4 md:w-4"})})]})]})]}),g.length>0&&j.jsx("div",{className:"flex flex-wrap gap-2",children:g.map(ze=>{const Ze=!ze.processing_status||ze.processing_status==="processing"||ze.processing_status==="uploading";return j.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:[Ze&&j.jsx(Ag,{className:"h-3 w-3 animate-spin text-emerald-600 dark:text-emerald-400 flex-shrink-0"}),j.jsx("span",{className:"truncate max-w-[150px] text-[#353740] dark:text-[#ececf1]",children:ze.filename}),Ze&&j.jsx("span",{className:"text-xs text-gray-500 dark:text-[#bfc2cd]",children:ze.processing_status==="uploading"?"Uploading...":"Processing..."}),j.jsx("button",{disabled:!0,className:"text-gray-300 dark:text-[#4a4b54] cursor-not-allowed",title:"File removal disabled; use Clear All in sidebar",children:j.jsx(ag,{className:"h-3 w-3"})})]},ze.file_id)})}),Ve&&(rt||yr)&&j.jsxs("div",{className:`rounded-md border border-gray-200 bg-white p-3 dark:border-[#4a4b54] dark:bg-[#2d2f39] ${!c&&!hr&&f.size===0&&!yr?"hidden":""}`,children:[c&&j.jsxs("div",{className:"mb-2 flex items-center justify-between text-sm text-[#353740] dark:text-[#ececf1]",children:[j.jsx("span",{children:"Upload files"}),j.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:j.jsx(ag,{className:"h-4 w-4"})})]}),(hr||f.size>0)&&!c&&f.size===0&&j.jsx("div",{className:"mb-2 text-sm text-[#353740] dark:text-[#ececf1]",children:"Uploading files…"}),f.size>0&&j.jsx("div",{className:"mb-2 space-y-2",children:Array.from(f.entries()).map(([ze,Ze])=>j.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:[j.jsx(Ag,{className:"w-4 h-4 text-emerald-600 dark:text-emerald-400 animate-spin flex-shrink-0"}),j.jsxs("div",{className:"flex-1 min-w-0 overflow-hidden",children:[j.jsx("p",{className:"text-sm font-medium text-[#353740] dark:text-[#ececf1] truncate",children:Ze.filename}),j.jsx("div",{className:"mt-1 bg-gray-200 dark:bg-[#3c3f4a] rounded-full h-1.5",children:j.jsx("div",{className:"bg-emerald-600 dark:bg-emerald-400 h-1.5 rounded-full transition-all duration-300",style:{width:`${Ze.progress??0}%`}})})]}),j.jsx("span",{className:"text-xs text-gray-500 dark:text-[#bfc2cd]",children:Ze.status==="uploading"?"Uploading...":Ze.status==="processing"?"Processing...":Ze.status==="completed"?"Done":"Pending"})]},ze))}),j.jsx(Ort,{conversationId:le,onFilesSelected:Nt,onUploadError:ze=>{},onUploadingChange:K,onUploadSuccess:vt,maxFiles:Nr.maxFilesPerConversation,disabled:mi})]}),j.jsx("div",{className:"h-5 md:h-4",children:Te&&xe&&j.jsxs("span",{className:"flex items-center gap-2 text-sm md:text-xs text-gray-500 dark:text-[#bfc2cd]",children:[j.jsx("span",{className:"h-2.5 w-2.5 md:h-2 md:w-2 animate-pulse rounded-full bg-red-500"}),"Listening..."]})})]})]})})}function iV({selectedAdapter:e,onAdapterChange:t,disabled:r}){const[n,i]=F.useState([]),[A,a]=F.useState(!0),[s,o]=F.useState(null),[l,c]=F.useState(!1);F.useEffect(()=>{let d=!0;async function B(){try{a(!0),o(null);const f=await Qle();d&&i(f)}catch{d&&o("Failed to load adapters. Please check your connection.")}finally{d&&a(!1)}}return B(),()=>{d=!1}},[]);const u=F.useRef(!1),g=F.useRef(t);F.useEffect(()=>{g.current=t},[t]),F.useEffect(()=>{if(e){u.current=!0;return}!u.current&&n.length>0&&(u.current=!0)},[n,e]);const h=n.find(d=>d.name===e);return j.jsxs("div",{className:"relative w-full sm:w-[220px]",children:[j.jsx("label",{className:"sr-only",children:"Adapter"}),j.jsxs("div",{className:"relative",children:[j.jsx("button",{type:"button",onClick:()=>!r&&c(!l),disabled:r||A||n.length===0,className:"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 disabled:opacity-50 disabled:cursor-not-allowed dark:border-[#4a4b54] dark:bg-[#343541] dark:text-[#ececf1] dark:focus:border-[#6b6f7a]",children:j.jsxs("div",{className:"flex items-center justify-between gap-2",children:[j.jsx("span",{className:`truncate ${h?"":"text-gray-500 dark:text-gray-400"}`,children:A?"Loading adapters…":s?"Error loading adapters":h?h.name:n.length===0?"No adapters available":"Select agent"}),j.jsx(FX,{className:`h-4 w-4 flex-shrink-0 transition-transform ${l?"rotate-180":""}`})]})}),l&&!r&&n.length>0&&j.jsxs(j.Fragment,{children:[j.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>c(!1)}),j.jsx("div",{className:"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]",children:j.jsx("div",{className:"max-h-60 overflow-auto py-1",children:n.map(d=>{const B=d.name===e;return j.jsx("button",{type:"button",onClick:()=>{B||t(d.name),c(!1)},className:`w-full px-3 py-2 text-left text-sm transition-colors ${B?"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:j.jsx("span",{className:"font-medium truncate",children:d.name})},d.name)})})})]})]}),s&&j.jsx("p",{className:"mt-1 text-xs text-red-600 dark:text-red-400",children:s})]})}const Zrt="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",AV="-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",qrt="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 _rt({onOpenSettings:e,onOpenSidebar:t}){var oe;const{conversations:r,currentConversationId:n,sendMessage:i,regenerateResponse:A,isLoading:a,configureApiSettings:s,error:o,clearError:l,createThread:c}=Ot(),{settings:u}=cy(),[g,h]=F.useState(!1),[d,B]=F.useState(()=>Rn()),[f,w]=F.useState(()=>Fc()),[y,I]=F.useState(null),[Y,Q]=F.useState(!1),[M,D]=F.useState(!1),[G,T]=F.useState(null),[R,L]=F.useState(!1),z=r.find(le=>le.id===n),te=Wn();F.useEffect(()=>{te&&(z!=null&&z.adapterName)&&I(z.adapterName)},[te,z==null?void 0:z.adapterName]),F.useEffect(()=>{var le,O,de;te&&Je("[ChatInterface] Middleware mode state:",{hasConversation:!!z,adapterName:z==null?void 0:z.adapterName,hasAdapterInfo:!!(z!=null&&z.adapterInfo),hasNotes:!!((le=z==null?void 0:z.adapterInfo)!=null&&le.notes),notes:((de=(O=z==null?void 0:z.adapterInfo)==null?void 0:O.notes)==null?void 0:de.substring(0,50))+"..."})},[te,z==null?void 0:z.adapterName,z==null?void 0:z.adapterInfo]);const V=F.useRef(null);F.useEffect(()=>{(async()=>{var Ee;const O=z==null?void 0:z.adapterName;if(V.current===O)return;const de=!(z!=null&&z.adapterInfo)||(z==null?void 0:z.adapterInfo)&&z.adapterInfo.notes===void 0;if(te&&O&&de){V.current=O,Je("[ChatInterface] Loading adapter info - adapterName:",O,"reason:",z!=null&&z.adapterInfo?"notes undefined":"missing");try{const Ce=(z==null?void 0:z.apiUrl)||Rn();Je("[ChatInterface] Calling configureApiSettings for:",O),await s(Ce,void 0,void 0,O),Je("[ChatInterface] Adapter info loaded successfully")}catch{V.current=null}}else Je("[ChatInterface] Skipping adapter info load:",{isMiddlewareEnabled:te,adapterName:O,hasAdapterInfo:!!(z!=null&&z.adapterInfo),hasNotes:((Ee=z==null?void 0:z.adapterInfo)==null?void 0:Ee.notes)!==void 0,refValue:V.current})})()},[te,z==null?void 0:z.adapterName,z==null?void 0:z.adapterInfo,z==null?void 0:z.apiUrl,s]);const Z=!z||z.messages.length===0;F.useEffect(()=>{let le=null;const O=()=>{le&&(le(),le=null)};if(u.voiceEnabled){if(mc.isAudioEnabled())return O;const de=()=>{O();const Ee=async()=>{O(),await mc.enableAudio()||de()};document.addEventListener("pointerdown",Ee,{once:!0}),document.addEventListener("keydown",Ee,{once:!0}),le=()=>{document.removeEventListener("pointerdown",Ee),document.removeEventListener("keydown",Ee)}};return de(),O}return O(),mc.disableAudio(),O},[u.voiceEnabled]);const ee=(le,O,de)=>{i(le,O,de)},ie=async(le,O,de)=>{await i(de,void 0,le)},K=async()=>{if(!(!z||!z.apiKey&&!z.adapterName)){L(!0);try{const le=await ci(),O=z.apiUrl||Rn(),de=z.apiKey,Ee=z.adapterName,Ce=new le.ApiClient({apiUrl:O,apiKey:de||null,sessionId:null,adapterName:Ee||null});if(typeof Ce.getAdapterInfo=="function"){const pe=await Ce.getAdapterInfo();Je("Adapter info refreshed:",pe),Ot.setState(xe=>({conversations:xe.conversations.map(ye=>ye.id===n?{...ye,adapterInfo:pe,updatedAt:new Date}:ye)})),setTimeout(()=>{const xe=Ot.getState();localStorage.setItem("chat-state",JSON.stringify({conversations:xe.conversations,currentConversationId:xe.currentConversationId}))},0)}}catch{}finally{L(!1)}}},$=async le=>{if(le&&le.preventDefault(),te){if(d&&y){D(!0),T(null);try{await s(d,void 0,void 0,y),l(),T(null),h(!1)}catch(O){const de=O instanceof Error?O.message:"Failed to configure adapter";T(de)}finally{D(!1)}}}else if(d&&f){D(!0),T(null);try{await s(d,f),l(),T(null),Q(!1),h(!1)}catch(O){const de=O instanceof Error?O.message:"Failed to configure API settings";T(de)}finally{D(!1)}}},P=le=>{I(le),T(null)};return j.jsx("div",{className:"flex-1 flex flex-col bg-gray-50 dark:bg-[#202123] overflow-hidden",children:j.jsx("div",{className:"flex h-full w-full flex-col px-3 sm:px-6 overflow-hidden",children:j.jsxs("div",{className:`mx-auto flex h-full w-full max-w-5xl flex-col overflow-hidden ${Zrt}`,children:[g&&j.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 px-4",children:j.jsxs("form",{onSubmit:$,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:[j.jsx("h2",{className:"text-lg font-medium text-[#353740] dark:text-[#ececf1] mb-4",children:te?"Select Adapter":"Configure API Settings"}),j.jsxs("div",{className:"space-y-5",children:[!te&&j.jsxs("div",{children:[j.jsx("label",{className:"block text-sm font-medium text-[#353740] dark:text-[#d1d5db] mb-2",children:"API URL"}),j.jsx("input",{type:"text",value:d,onChange:le=>B(le.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"})]}),te?j.jsx(iV,{selectedAdapter:y,onAdapterChange:P,disabled:M}):j.jsxs("div",{children:[j.jsx("label",{className:"block text-sm font-medium text-[#353740] dark:text-[#d1d5db] mb-2",children:"API Key"}),j.jsxs("div",{className:"relative",children:[j.jsx("input",{type:Y?"text":"password",value:f,onChange:le=>{w(le.target.value),T(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:M}),j.jsx("button",{type:"button",onClick:()=>Q(!Y),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":Y?"Hide API key":"Show API key",disabled:M,children:Y?j.jsx(p0e,{className:"h-4 w-4"}):j.jsx(m0e,{className:"h-4 w-4"})})]})]}),G&&j.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:G}),j.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[j.jsx("button",{type:"button",onClick:()=>{const le=(z==null?void 0:z.apiUrl)||Rn(),O=(z==null?void 0:z.apiKey)||Fc();B(le),w(O),T(null),Q(!1),h(!1)},className:"rounded-md border border-transparent px-4 py-2 text-sm text-gray-600 hover:border-gray-300 hover:text-gray-900 dark:text-[#d1d5db] dark:hover:text-white disabled:cursor-not-allowed disabled:opacity-50",disabled:M,children:"Cancel"}),j.jsx("button",{type:"submit",disabled:M||(te?!y:!d||!f),className:"rounded-md bg-[#343541] px-4 py-2 text-sm font-medium text-white hover:bg-[#282b32] disabled:cursor-not-allowed disabled:opacity-50 dark:bg-[#565869] dark:hover:bg-[#6b6f7a]",children:M?"Validating...":"Update"})]})]})]})}),o&&j.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:j.jsxs("div",{className:"flex items-start justify-between",children:[j.jsx("p",{children:o}),j.jsx("button",{onClick:l,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:"×"})]})}),j.jsxs("div",{className:qrt,children:[t&&j.jsxs("div",{className:"mb-4 grid grid-cols-2 gap-3 md:hidden",children:[j.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:[j.jsx(f0e,{className:"h-5 w-5"}),"Chats"]}),j.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:[j.jsx(rR,{className:"h-5 w-5"}),"Settings"]})]}),j.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between",children:[j.jsx("div",{className:"min-w-0 flex-1",children:(z==null?void 0:z.adapterInfo)&&j.jsxs("div",{className:"mb-4",children:[j.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-3",children:[z.adapterInfo.model&&j.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:[j.jsx("span",{children:"Model"}),j.jsx("span",{className:"text-gray-800 normal-case dark:text-[#ececf1]",children:z.adapterInfo.model})]}),j.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:[j.jsx("span",{children:"Agent"}),j.jsx("span",{className:"text-gray-800 normal-case dark:text-[#ececf1]",children:z.adapterInfo.client_name})]}),j.jsxs("button",{onClick:K,disabled:R||!(z!=null&&z.apiKey)&&!(z!=null&&z.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:[j.jsx(N0e,{className:`h-4 w-4 ${R?"animate-spin":""}`}),j.jsx("span",{className:"hidden sm:inline",children:"Refresh"})]})]}),j.jsx("h1",{className:"text-2xl font-semibold text-[#353740] dark:text-[#ececf1] mb-2",children:(z==null?void 0:z.title)||"New Chat"}),z&&j.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-500 dark:text-[#bfc2cd]",children:[j.jsx("span",{className:"font-medium",children:z.messages.length}),j.jsxs("span",{children:["Updated ",z.updatedAt.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]})]})}),j.jsxs("div",{className:"flex w-full flex-wrap items-center gap-3 sm:w-auto sm:flex-nowrap sm:justify-end",children:[j.jsxs("span",{className:"text-sm text-gray-500 dark:text-[#bfc2cd] sm:text-right",children:["v",Ile]}),!te&&j.jsx("button",{onClick:()=>{const le=Rn(),O=z==null?void 0:z.apiUrl,de=O&&O!==le?O:le,Ee=(z==null?void 0:z.apiKey)||Fc();B(de),w(Ee),T(null),Q(!1),h(!0)},disabled:!Z,className:"w-full rounded-md border border-gray-300 px-3 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 hover:border-gray-400 transition-colors disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:border-gray-300 dark:border-[#4a4b54] dark:text-[#ececf1] dark:hover:bg-[#3c3f4a] dark:hover:border-[#6b6f7a] dark:disabled:hover:bg-transparent dark:disabled:hover:border-[#4a4b54] sm:w-auto",title:Z?"Configure API settings":"API key cannot be changed once conversation has started. Create a new conversation to use a different API key.",children:"Configure API"}),te&&j.jsx("div",{className:"w-full sm:w-auto",children:j.jsx(iV,{selectedAdapter:y||(z==null?void 0:z.adapterName)||null,onAdapterChange:async le=>{I(le);const O=(z==null?void 0:z.apiUrl)||Rn();try{await s(O,void 0,void 0,le),l()}catch{}},disabled:!Z})}),j.jsx("button",{onClick:e,className:"hidden rounded-md bg-[#343541] p-2 text-white hover:bg-[#282b32] transition-colors dark:bg-[#565869] dark:hover:bg-[#6b6f7a] md:inline-flex",title:"Settings",children:j.jsx(rR,{className:"h-4 w-4"})})]})]})]}),!z||z.messages.length===0?j.jsx("div",{className:"flex flex-1 flex-col min-h-0 pt-4 md:pt-6",children:j.jsx("div",{className:"flex-1 flex flex-col justify-between md:justify-start md:flex-none",children:j.jsxs("div",{className:"w-full space-y-3",children:[j.jsx("div",{className:"mb-2",children:(oe=z==null?void 0:z.adapterInfo)!=null&&oe.notes?j.jsx("div",{className:"text-base text-gray-600 dark:text-[#bfc2cd] leading-relaxed prose prose-sm dark:prose-invert prose-p:my-1 prose-ul:my-2 prose-ol:my-2 prose-li:my-0.5",children:j.jsx(LD,{content:z.adapterInfo.notes})}):j.jsx("h2",{className:"text-xl md:text-2xl font-medium text-[#353740] dark:text-[#ececf1]",children:"How can I assist you today?"})}),j.jsx("div",{className:AV,children:j.jsx(nV,{onSend:ee,disabled:a||!z||(te?!z.adapterName:!z.apiKey),placeholder:"Message ORBIT..."})})]})})}):j.jsxs("div",{className:"flex flex-1 flex-col",children:[j.jsx(Ert,{messages:z.messages,onRegenerate:A,onStartThread:async(le,O)=>{try{await c(le,O)}catch{}},onSendThreadMessage:ie,sessionId:z.sessionId,isLoading:a}),j.jsx("div",{className:AV,children:j.jsx(nV,{onSend:ee,disabled:a||!z||(te?!z.adapterName:!z.apiKey),placeholder:"Message ORBIT..."})})]})]})})})}function aV({isOpen:e,onClose:t,onConfirm:r,title:n,message:i,confirmText:A="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 j.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center p-4 z-50 animate-fadeIn",children:j.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-2xl shadow-2xl w-full max-w-md transform animate-fadeIn",children:[j.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-700",children:[j.jsxs("div",{className:"flex items-center gap-3",children:[j.jsx("div",{className:`w-10 h-10 rounded-full ${u.iconBg} flex items-center justify-center`,children:j.jsx(QX,{className:`w-5 h-5 ${u.icon}`})}),j.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:n})]}),j.jsx("button",{onClick:t,className:"p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors",children:j.jsx(ag,{className:"w-5 h-5 text-gray-500 dark:text-gray-400"})})]}),j.jsx("div",{className:"p-6",children:j.jsx("p",{className:"text-gray-600 dark:text-gray-300 leading-relaxed",children:i})}),j.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:[j.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}),j.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?j.jsxs("div",{className:"flex items-center gap-2",children:[j.jsx("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"}),"Clearing..."]}):A})]})]})})}const $rt=(e,t)=>{const[r,n]=F.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 F.useEffect(()=>{(async()=>{var A;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:((A=s.license)==null?void 0:A.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},am=100;function sV({onRequestClose:e}){const{conversations:t,currentConversationId:r,createConversation:n,selectConversation:i,deleteConversation:A,deleteAllConversations:a,updateConversationTitle:s,canCreateNewConversation:o,getConversationCount:l}=Ot(),c=t.find(pe=>pe.id===r),[u,g]=F.useState(""),[h,d]=F.useState(null),[B,f]=F.useState(""),[w,y]=F.useState({isOpen:!1,conversationId:"",conversationTitle:"",isDeleting:!1}),[I,Y]=F.useState({isOpen:!1,isDeleting:!1}),Q=t.filter(pe=>pe.title.toLowerCase().includes(u.toLowerCase())||pe.messages.some(xe=>xe.content.toLowerCase().includes(u.toLowerCase()))),M=o(),D=l(),G=Nr.maxConversations,T=G!==null&&D>=G,R=c?c.messages.length===0:!1,L=G!==null?`${D}/${G} conversations`:`${D} conversation${D===1?"":"s"}`,z=M?"Start a new conversation":T?`Maximum ${G} conversations reached. Delete a conversation to create a new one.`:R?"Current conversation is empty. Send a message first to create a new conversation.":"Finish your current conversation before starting a new one.",te=drt(),V=$rt(ZK(),qK()),Z=()=>{try{n(),e==null||e()}catch(pe){Ir("Cannot create new conversation:",pe instanceof Error?pe.message:"Unknown error")}},ee=async pe=>{try{await i(pe),e==null||e()}catch{}},ie=(pe,xe)=>{pe.stopPropagation(),y({isOpen:!0,conversationId:xe.id,conversationTitle:xe.title,isDeleting:!1})},K=async()=>{y(pe=>({...pe,isDeleting:!0}));try{await A(w.conversationId),y({isOpen:!1,conversationId:"",conversationTitle:"",isDeleting:!1})}catch{y({isOpen:!1,conversationId:"",conversationTitle:"",isDeleting:!1})}},$=()=>{y({isOpen:!1,conversationId:"",conversationTitle:"",isDeleting:!1})},P=(pe,xe)=>{pe.stopPropagation(),d(xe.id),f(xe.title.slice(0,am))},oe=pe=>{const xe=B.slice(0,am).trim();xe&&s(pe,xe),d(null),f("")},le=()=>{d(null),f("")},O=()=>{Y({isOpen:!0,isDeleting:!1})},de=async()=>{Y(pe=>({...pe,isDeleting:!0}));try{await a(),Y({isOpen:!1,isDeleting:!1})}catch{Y({isOpen:!1,isDeleting:!1})}},Ee=()=>{Y({isOpen:!1,isDeleting:!1})},Ce=pe=>{const xe=pe.toLocaleDateString([],{year:"numeric",month:"short",day:"numeric"}),ye=pe.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});return`${xe} · ${ye}`};return j.jsxs(j.Fragment,{children:[j.jsxs("div",{className:"flex h-full w-full md:w-72 flex-col border-r border-b border-gray-200 bg-gray-50 dark:border-[#4a4b54] dark:bg-[#202123]",children:[j.jsxs("div",{className:"border-b border-gray-200 p-4 dark:border-[#4a4b54]",children:[j.jsxs("button",{onClick:Z,disabled:!M,className:`flex w-full items-center justify-center gap-2 rounded-md px-3 py-2 text-sm font-medium ${M?"bg-[#343541] text-white hover:bg-[#2c2f36] dark:bg-[#565869] dark:hover:bg-[#6b6f7a]":"cursor-not-allowed bg-gray-200 text-gray-500 dark:bg-[#3c3f4a] dark:text-[#6b6f7a]"}`,title:z,children:[j.jsx(x0e,{className:"h-4 w-4"}),"New Conversation"]}),j.jsxs("div",{className:"mt-3 space-y-2",children:[j.jsx("div",{className:"text-center",children:j.jsx("span",{className:"text-xs text-gray-500 dark:text-[#bfc2cd]",children:L})}),t.length>0&&t.some(pe=>pe.messages.length>0)&&j.jsxs("button",{onClick:O,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:[j.jsx(G0e,{className:"h-4 w-4"}),"Clear All"]})]})]}),j.jsx("div",{className:"border-b border-gray-200 px-4 py-3 dark:border-[#4a4b54]",children:j.jsxs("div",{className:"relative flex items-center",children:[j.jsx(k0e,{className:"pointer-events-none absolute left-3 h-4 w-4 text-gray-400"}),j.jsx("input",{type:"text",placeholder:"Search conversations",value:u,onChange:pe=>g(pe.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 focus:border-gray-400 focus:outline-none dark:border-[#4a4b54] dark:bg-[#343541] dark:text-[#ececf1]"})]})}),j.jsx("div",{className:"flex-1 overflow-y-auto px-3 py-3",children:Q.length===0?j.jsxs("div",{className:"rounded-md border border-dashed border-gray-300 p-6 text-center text-sm text-gray-500 dark:border-[#4a4b54] dark:text-[#bfc2cd]",children:[j.jsx(Yh,{className:"mx-auto mb-3 h-6 w-6 text-gray-400 dark:text-[#6b6f7a]"}),j.jsx("p",{children:u?"No conversations found":"No conversations yet"})]}):j.jsx("div",{className:"space-y-2",children:Q.map(pe=>j.jsxs("div",{onClick:()=>ee(pe.id),className:`group flex cursor-pointer items-start gap-3 rounded-xl border px-3 py-3 text-left transition ${r===pe.id?"border-[#343541] bg-white shadow-sm dark:border-[#6b6f7a] dark:bg-[#2c2f36]":"border-transparent bg-gray-100/70 hover:border-gray-300 hover:bg-white dark:bg-[#252830] dark:hover:border-[#4a4b54] dark:hover:bg-[#2f323c]"}`,children:[j.jsx("div",{className:`rounded-xl p-2 shadow-sm ${r===pe.id?"bg-[#eceefc] text-[#1d2559] dark:bg-[#3b4055] dark:text-white":"bg-white text-gray-500 dark:bg-[#3a3d46] dark:text-[#bfc2cd]"}`,children:j.jsx(Yh,{className:"h-4 w-4"})}),h===pe.id?j.jsx("input",{type:"text",value:B,onChange:xe=>f(xe.target.value.slice(0,am)),onKeyDown:xe=>{xe.key==="Enter"&&oe(pe.id),xe.key==="Escape"&&le()},onBlur:()=>oe(pe.id),maxLength:am,className:"flex-1 border-none bg-transparent text-sm text-[#353740] focus:outline-none dark:text-[#ececf1]",autoFocus:!0}):j.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[j.jsxs("div",{className:"flex items-center gap-2",children:[j.jsx("h3",{className:`flex-1 truncate text-sm font-semibold ${r===pe.id?"text-[#1f2937] dark:text-white":"text-gray-700 dark:text-[#d4d7e2]"}`,children:pe.title}),j.jsxs("div",{className:"flex items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100",children:[j.jsx("button",{onClick:xe=>P(xe,pe),className:"rounded-full p-2 text-gray-500 hover:bg-gray-200 hover:text-[#353740] dark:text-[#bfc2cd] dark:hover:bg-[#3c3f4a]",title:"Rename conversation",children:j.jsx(Y0e,{className:"h-4 w-4"})}),j.jsx("button",{onClick:xe=>ie(xe,pe),className:"rounded-full p-2 text-red-500 hover:bg-red-50 dark:text-red-300 dark:hover:bg-red-900/30",title:"Delete conversation",children:j.jsx(bX,{className:"h-4 w-4"})})]})]}),j.jsxs("div",{className:"mt-1 flex items-center gap-1.5 pr-1 text-[11px] text-gray-500 dark:text-[#a6acc5]",children:[j.jsx("span",{className:"whitespace-nowrap leading-none",children:Ce(pe.updatedAt)}),j.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 rounded-full bg-white/80 px-2 py-0.5 font-medium text-gray-600 shadow-sm dark:bg-white/10 dark:text-[#e5e7f4] leading-none",children:[j.jsx(Yh,{className:"h-3 w-3"}),pe.messages.length]}),pe.attachedFiles&&pe.attachedFiles.length>0&&j.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 rounded-full bg-white/80 px-2 py-0.5 font-medium text-gray-600 shadow-sm dark:bg-white/10 dark:text-[#e5e7f4] leading-none",children:[j.jsx(YX,{className:"h-3 w-3"}),pe.attachedFiles.length]})]})]})]},pe.id))})}),te&&j.jsx("div",{className:"border-t border-gray-200 p-4 dark:border-[#4a4b54]",children:j.jsxs("div",{className:"text-center",children:[j.jsx("div",{className:"flex items-center justify-center mb-3",children:j.jsx("span",{className:"text-sm font-medium text-gray-900 dark:text-[#ececf1]",children:"Powered by ORBIT"})}),V.isLoading?j.jsxs("div",{className:"flex items-center justify-center gap-2 text-xs text-gray-500 dark:text-[#bfc2cd] mb-3",children:[j.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-gray-400"}),j.jsx("span",{children:"Loading stats..."})]}):V.error?j.jsx("div",{className:"flex items-center justify-center gap-2 text-xs text-red-500 dark:text-red-400 mb-3",children:j.jsx("span",{children:"⚠️ Failed to load stats"})}):j.jsxs("div",{className:"flex items-center justify-center gap-4 text-xs text-gray-500 dark:text-[#bfc2cd] mb-3",children:[j.jsxs("div",{className:"flex items-center gap-1",children:[j.jsx("svg",{className:"w-4 h-4 text-yellow-500",fill:"currentColor",viewBox:"0 0 24 24",children:j.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"})}),j.jsxs("span",{children:[V.stars.toLocaleString()," stars"]})]}),j.jsxs("div",{className:"flex items-center gap-1",children:[j.jsx("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 16 16",children:j.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"})}),j.jsxs("span",{children:[V.forks.toLocaleString()," forks"]})]})]}),j.jsxs("a",{href:`https://github.com/${ZK()}/${qK()}`,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:[j.jsx("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 24 24",children:j.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"]})]})})]}),j.jsx(aV,{isOpen:w.isOpen,onClose:$,onConfirm:K,title:"Delete Conversation",message:`Are you sure you want to delete "${w.conversationTitle}"? This will clear the conversation history from both the server and your local storage. This action cannot be undone.`,confirmText:"Delete",cancelText:"Cancel",type:"danger",isLoading:w.isDeleting}),j.jsx(aV,{isOpen:I.isOpen,onClose:Ee,onConfirm:de,title:"Clear All Conversations",message:`Are you sure you want to delete all ${D} conversation${D!==1?"s":""}? This will clear all conversation history from both the server and your local storage. This action cannot be undone.`,confirmText:"Clear All",cancelText:"Cancel",type:"danger",isLoading:I.isDeleting})]})}function ent({isOpen:e,onClose:t}){const{theme:r,updateTheme:n}=IX(),{settings:i,updateSettings:A}=cy(),[a,s]=F.useState(null),[o,l]=F.useState(!1),[c,u]=F.useState(""),[g,h]=F.useState(!1);if(F.useEffect(()=>{e&&Cle().then(s)},[e]),!e)return null;const d=M=>{n({mode:M})},B=M=>{n({fontSize:M})},f=()=>{n({highContrast:!r.highContrast})},w=()=>{A({soundEnabled:!i.soundEnabled})},y=()=>{u(""),h(!1),l(!0)},I=()=>{l(!1),u(""),h(!1)},Y=()=>{I(),localStorage.clear(),window.location.reload()},Q=g&&c.trim().toLowerCase()==="reset";return j.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50",children:j.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:[j.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-600",children:[j.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-gray-100",children:"Settings"}),j.jsx("button",{onClick:t,className:"p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors",children:j.jsx(ag,{className:"w-5 h-5 text-gray-500 dark:text-gray-400"})})]}),j.jsxs("div",{className:"flex-1 min-h-0 p-6 space-y-6 overflow-y-auto",children:[j.jsxs("div",{className:"space-y-4",children:[j.jsxs("h3",{className:"text-lg font-medium text-gray-900 dark:text-gray-100 flex items-center gap-2",children:[j.jsx(M0e,{className:"w-5 h-5"}),"Appearance"]}),j.jsxs("div",{className:"space-y-2",children:[j.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Theme"}),j.jsx("div",{className:"grid grid-cols-3 gap-2",children:[{value:"light",label:"Light",icon:S0e},{value:"dark",label:"Dark",icon:C0e},{value:"system",label:"System",icon:I0e}].map(({value:M,label:D,icon:G})=>j.jsxs("button",{onClick:()=>d(M),className:`flex flex-col items-center gap-2 p-3 rounded-lg border-2 transition-all duration-200 ${r.mode===M?"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:[j.jsx(G,{className:"w-5 h-5"}),j.jsx("span",{className:"text-sm font-medium",children:D})]},M))})]}),j.jsxs("div",{className:"flex items-center justify-between",children:[j.jsxs("div",{children:[j.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"High Contrast"}),j.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Improve readability with enhanced contrast"})]}),j.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:j.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${r.highContrast?"translate-x-6":"translate-x-1"}`})})]}),j.jsxs("div",{className:"space-y-2",children:[j.jsxs("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 flex items-center gap-2",children:[j.jsx(R0e,{className:"w-4 h-4"}),"Font Size"]}),j.jsx("div",{className:"grid grid-cols-3 gap-2",children:[{value:"small",label:"Small"},{value:"medium",label:"Medium"},{value:"large",label:"Large"}].map(({value:M,label:D})=>j.jsx("button",{onClick:()=>B(M),className:`p-2 rounded-lg border-2 transition-colors text-center ${r.fontSize===M?"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:j.jsx("span",{className:`font-medium ${M==="small"?"text-sm":M==="large"?"text-lg":"text-base"}`,children:D})},M))})]})]}),j.jsxs("div",{className:"space-y-4",children:[j.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-gray-100",children:"Chat Preferences"}),j.jsxs("div",{className:"flex items-center justify-between",children:[j.jsxs("div",{className:"flex items-center gap-2",children:[j.jsx(uw,{className:"w-4 h-4 text-gray-600 dark:text-gray-400"}),j.jsxs("div",{children:[j.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Sound Effects"}),j.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Play sounds for notifications and events"})]})]}),j.jsx("button",{onClick:w,className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${i.soundEnabled?"bg-blue-600":"bg-gray-200 dark:bg-gray-600"}`,children:j.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${i.soundEnabled?"translate-x-6":"translate-x-1"}`})})]})]}),j.jsxs("div",{className:"space-y-4 pt-4 border-t border-gray-200 dark:border-gray-600",children:[j.jsxs("h3",{className:"text-lg font-medium text-gray-900 dark:text-gray-100 flex items-center gap-2",children:[j.jsx(bX,{className:"w-5 h-5"}),"Data Management"]}),j.jsxs("div",{className:"space-y-3",children:[j.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Clear all application data including conversations, and personalized settings."}),j.jsx("button",{onClick:y,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"})]})]}),j.jsxs("div",{className:"space-y-2 pt-4 border-t border-gray-200 dark:border-gray-600",children:[j.jsxs("h3",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 flex items-center gap-2",children:[j.jsx(Q0e,{className:"w-4 h-4"}),"About"]}),j.jsxs("div",{className:"space-y-1",children:[j.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"]}),j.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)&&j.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"})]}),j.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Built with React, TypeScript, and Tailwind CSS"})]})]})]}),o&&j.jsx("div",{className:"absolute inset-0 bg-black/70 flex items-center justify-center p-4 z-50",children:j.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:[j.jsxs("div",{className:"flex items-start gap-3",children:[j.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-red-100 dark:bg-red-900/40",children:j.jsx(QX,{className:"w-5 h-5 text-red-600 dark:text-red-400"})}),j.jsxs("div",{children:[j.jsx("p",{className:"text-base font-semibold text-gray-900 dark:text-gray-100",children:"Reset application data?"}),j.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:["This removes everything stored on this device. Type ",j.jsx("span",{className:"font-semibold text-gray-900 dark:text-gray-100",children:"RESET"})," to continue."]})]})]}),j.jsxs("div",{className:"space-y-2",children:[j.jsx("label",{className:"text-xs font-medium text-gray-700 dark:text-gray-300",children:"Confirmation text"}),j.jsx("input",{value:c,onChange:M=>u(M.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"})]}),j.jsxs("label",{className:"flex items-start gap-2 text-xs text-gray-600 dark:text-gray-400",children:[j.jsx("input",{type:"checkbox",checked:g,onChange:M=>h(M.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"}),j.jsx("span",{children:"I understand this action is permanent and will reload the app."})]}),j.jsxs("div",{className:"flex gap-2 pt-2",children:[j.jsx("button",{onClick:I,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:"Keep my data"}),j.jsx("button",{onClick:Y,disabled:!Q,className:`flex-1 px-4 py-2 text-sm font-semibold rounded-lg transition-colors ${Q?"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:"Delete everything"})]})]})})]})})}function tnt(){const[e,t]=F.useState(!1),[r,n]=F.useState(!1);return j.jsx(l0e,{children:j.jsx(c0e,{children:j.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:[j.jsx("div",{className:"hidden md:flex md:min-h-screen",children:j.jsx(sV,{})}),j.jsx("div",{className:"flex-1 flex justify-center w-full",children:j.jsx(_rt,{onOpenSettings:()=>t(!0),onOpenSidebar:()=>n(!0)})}),j.jsx(ent,{isOpen:e,onClose:()=>t(!1)}),r&&j.jsxs("div",{className:"fixed inset-0 z-50 flex md:hidden",children:[j.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>n(!1),"aria-hidden":"true"}),j.jsxs("div",{className:"relative z-10 h-full w-[min(18rem,85vw)] animate-slideIn",children:[j.jsx(sV,{onRequestClose:()=>n(!1)}),j.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:j.jsx(ag,{className:"h-5 w-5"})})]})]})]})})})}Cle().then(e=>{Je(`📱 App Version: v${e.appVersion}`),Je(`📦 API Package: @schmitech/chatbot-api v${e.apiVersion}`),Je(`🔧 API Mode: ${e.isLocalApi?"Local":"NPM Package"}`)});yX(document.getElementById("root")).render(j.jsx(F.StrictMode,{children:j.jsx(tnt,{})}));export{_ze as $,Bnt as A,h1e as B,I3e as C,Fa as D,fTe as E,MTe as F,b_ as G,E3e as H,yTe as I,Ant as J,pTe as K,dnt as L,l1e as M,ant as N,JTe as O,Zxe as P,m1e as Q,Uh as R,KS as S,Ri as T,y_ as U,hRe as V,HSe as W,$7 as X,_7 as Y,g$ as Z,nr as _,ve as a,G$ as a$,Xxe as a0,Y$ as a1,lS as a2,zy as a3,Nke as a4,xke as a5,Yg as a6,bke as a7,Yke as a8,zw as a9,qNe as aA,vk as aB,K7 as aC,Rh as aD,eRe as aE,tRe as aF,nRe as aG,$Ge as aH,PGe as aI,$w as aJ,$te as aK,YGe as aL,TS as aM,KGe as aN,DGe as aO,Sve as aP,qte as aQ,gRe as aR,eB as aS,A1e as aT,$d as aU,gt as aV,Et as aW,x_ as aX,dS as aY,j6 as aZ,T6 as a_,AB as aa,sS as ab,AS as ac,gc as ad,Rw as ae,X_ as af,IA as ag,QDe as ah,Ok as ai,P_ as aj,nB as ak,snt as al,BUe as am,v7 as an,_y as ao,qk as ap,en as aq,BS as ar,Hy as as,kNe as at,Yze as au,_k as av,pS as aw,int as ax,Cg as ay,iRe as az,pt as b,jw as b0,unt as b1,ont as b2,xg as b3,_a as b4,lnt as b5,hnt as b6,cnt as b7,gnt as b8,nnt as b9,vve as bA,Lve as bB,_g as bC,L2 as bD,Ll as bE,kGe as bF,Rve as bG,Gve as bH,aJ as bI,oB as bJ,Ote as bK,Zw as bL,qg as bM,Pte as bN,_w as bO,LS as bP,tJ as bQ,sB as bR,rRe as bS,Zy as bT,C3e as ba,$n as bb,Hl as bc,Sre as bd,uu as be,Are as bf,St as bg,Cs as bh,zS as bi,Pve as bj,TJ as bk,cB as bl,Mze as bm,Qze as bn,Zk as bo,Bt as bp,Tte as bq,qy as br,Ky as bs,ou as bt,Zte as bu,zGe as bv,gje as bw,zve as bx,nc as by,jS as bz,fnt as c,pnt as d,sie as e,Ar as f,u1e as g,g1e as h,Xn as i,RS as j,bo as k,x3e as l,pRe as m,Vg as n,wnt as o,Cr as p,sre as q,Ent as r,mnt as s,ynt as t,c1e as u,Ta as v,d1e as w,k as x,fa as y,B1e as z};