cursor-local-remote 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/.next/BUILD_ID +1 -0
  2. package/.next/app-build-manifest.json +98 -0
  3. package/.next/app-path-routes-manifest.json +16 -0
  4. package/.next/build-manifest.json +33 -0
  5. package/.next/export-marker.json +6 -0
  6. package/.next/images-manifest.json +58 -0
  7. package/.next/next-minimal-server.js.nft.json +1 -0
  8. package/.next/next-server.js.nft.json +1 -0
  9. package/.next/package.json +1 -0
  10. package/.next/prerender-manifest.json +148 -0
  11. package/.next/react-loadable-manifest.json +8 -0
  12. package/.next/required-server-files.json +325 -0
  13. package/.next/routes-manifest.json +94 -0
  14. package/.next/server/app/_not-found/page.js +2 -0
  15. package/.next/server/app/_not-found/page.js.nft.json +1 -0
  16. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -0
  17. package/.next/server/app/_not-found.html +1 -0
  18. package/.next/server/app/_not-found.meta +8 -0
  19. package/.next/server/app/_not-found.rsc +18 -0
  20. package/.next/server/app/api/chat/route.js +19 -0
  21. package/.next/server/app/api/chat/route.js.nft.json +1 -0
  22. package/.next/server/app/api/chat/route_client-reference-manifest.js +1 -0
  23. package/.next/server/app/api/info/route.js +1 -0
  24. package/.next/server/app/api/info/route.js.nft.json +1 -0
  25. package/.next/server/app/api/info/route_client-reference-manifest.js +1 -0
  26. package/.next/server/app/api/models/route.js +1 -0
  27. package/.next/server/app/api/models/route.js.nft.json +1 -0
  28. package/.next/server/app/api/models/route_client-reference-manifest.js +1 -0
  29. package/.next/server/app/api/push/subscribe/route.js +19 -0
  30. package/.next/server/app/api/push/subscribe/route.js.nft.json +1 -0
  31. package/.next/server/app/api/push/subscribe/route_client-reference-manifest.js +1 -0
  32. package/.next/server/app/api/push/vapid-key/route.js +19 -0
  33. package/.next/server/app/api/push/vapid-key/route.js.nft.json +1 -0
  34. package/.next/server/app/api/push/vapid-key/route_client-reference-manifest.js +1 -0
  35. package/.next/server/app/api/sessions/active/route.js +1 -0
  36. package/.next/server/app/api/sessions/active/route.js.nft.json +1 -0
  37. package/.next/server/app/api/sessions/active/route_client-reference-manifest.js +1 -0
  38. package/.next/server/app/api/sessions/history/route.js +1 -0
  39. package/.next/server/app/api/sessions/history/route.js.nft.json +1 -0
  40. package/.next/server/app/api/sessions/history/route_client-reference-manifest.js +1 -0
  41. package/.next/server/app/api/sessions/route.js +19 -0
  42. package/.next/server/app/api/sessions/route.js.nft.json +1 -0
  43. package/.next/server/app/api/sessions/route_client-reference-manifest.js +1 -0
  44. package/.next/server/app/api/sessions/watch/route.js +4 -0
  45. package/.next/server/app/api/sessions/watch/route.js.nft.json +1 -0
  46. package/.next/server/app/api/sessions/watch/route_client-reference-manifest.js +1 -0
  47. package/.next/server/app/apple-icon.png/route.js +1 -0
  48. package/.next/server/app/apple-icon.png/route.js.nft.json +1 -0
  49. package/.next/server/app/apple-icon.png.body +0 -0
  50. package/.next/server/app/apple-icon.png.meta +1 -0
  51. package/.next/server/app/icon.png/route.js +1 -0
  52. package/.next/server/app/icon.png/route.js.nft.json +1 -0
  53. package/.next/server/app/icon.png.body +0 -0
  54. package/.next/server/app/icon.png.meta +1 -0
  55. package/.next/server/app/index.html +1 -0
  56. package/.next/server/app/index.meta +7 -0
  57. package/.next/server/app/index.rsc +21 -0
  58. package/.next/server/app/manifest.webmanifest/route.js +16 -0
  59. package/.next/server/app/manifest.webmanifest/route.js.nft.json +1 -0
  60. package/.next/server/app/manifest.webmanifest/route_client-reference-manifest.js +1 -0
  61. package/.next/server/app/manifest.webmanifest.body +1 -0
  62. package/.next/server/app/manifest.webmanifest.meta +1 -0
  63. package/.next/server/app/page.js +2 -0
  64. package/.next/server/app/page.js.nft.json +1 -0
  65. package/.next/server/app/page_client-reference-manifest.js +1 -0
  66. package/.next/server/app-paths-manifest.json +16 -0
  67. package/.next/server/chunks/267.js +9 -0
  68. package/.next/server/chunks/369.js +19 -0
  69. package/.next/server/chunks/407.js +1 -0
  70. package/.next/server/chunks/519.js +19 -0
  71. package/.next/server/chunks/540.js +184 -0
  72. package/.next/server/chunks/611.js +6 -0
  73. package/.next/server/chunks/692.js +1 -0
  74. package/.next/server/chunks/848.js +1 -0
  75. package/.next/server/chunks/873.js +22 -0
  76. package/.next/server/chunks/878.js +37 -0
  77. package/.next/server/edge-instrumentation.js +2 -0
  78. package/.next/server/edge-runtime-webpack.js +2 -0
  79. package/.next/server/functions-config-manifest.json +4 -0
  80. package/.next/server/instrumentation.js +1 -0
  81. package/.next/server/instrumentation.js.nft.json +1 -0
  82. package/.next/server/interception-route-rewrite-manifest.js +1 -0
  83. package/.next/server/middleware-build-manifest.js +1 -0
  84. package/.next/server/middleware-manifest.json +33 -0
  85. package/.next/server/middleware-react-loadable-manifest.js +1 -0
  86. package/.next/server/next-font-manifest.js +1 -0
  87. package/.next/server/next-font-manifest.json +1 -0
  88. package/.next/server/pages/404.html +1 -0
  89. package/.next/server/pages/500.html +1 -0
  90. package/.next/server/pages/_app.js +1 -0
  91. package/.next/server/pages/_app.js.nft.json +1 -0
  92. package/.next/server/pages/_document.js +1 -0
  93. package/.next/server/pages/_document.js.nft.json +1 -0
  94. package/.next/server/pages/_error.js +19 -0
  95. package/.next/server/pages/_error.js.nft.json +1 -0
  96. package/.next/server/pages-manifest.json +6 -0
  97. package/.next/server/server-reference-manifest.js +1 -0
  98. package/.next/server/server-reference-manifest.json +1 -0
  99. package/.next/server/src/middleware.js +135 -0
  100. package/.next/server/webpack-runtime.js +1 -0
  101. package/.next/static/chunks/255-ebd51be49873d76c.js +1 -0
  102. package/.next/static/chunks/391-727d95bcfba987c2.js +1 -0
  103. package/.next/static/chunks/4bd1b696-c023c6e3521b1417.js +1 -0
  104. package/.next/static/chunks/561.0dd3adbeaf3ef161.js +184 -0
  105. package/.next/static/chunks/app/_not-found/page-52dbda1443b2ae8f.js +1 -0
  106. package/.next/static/chunks/app/api/chat/route-05d013d09b933dec.js +1 -0
  107. package/.next/static/chunks/app/api/info/route-05d013d09b933dec.js +1 -0
  108. package/.next/static/chunks/app/api/models/route-05d013d09b933dec.js +1 -0
  109. package/.next/static/chunks/app/api/push/subscribe/route-05d013d09b933dec.js +1 -0
  110. package/.next/static/chunks/app/api/push/vapid-key/route-05d013d09b933dec.js +1 -0
  111. package/.next/static/chunks/app/api/sessions/active/route-05d013d09b933dec.js +1 -0
  112. package/.next/static/chunks/app/api/sessions/history/route-05d013d09b933dec.js +1 -0
  113. package/.next/static/chunks/app/api/sessions/route-05d013d09b933dec.js +1 -0
  114. package/.next/static/chunks/app/api/sessions/watch/route-05d013d09b933dec.js +1 -0
  115. package/.next/static/chunks/app/layout-11d8cab0ea5a792e.js +1 -0
  116. package/.next/static/chunks/app/manifest.webmanifest/route-05d013d09b933dec.js +1 -0
  117. package/.next/static/chunks/app/page-9b8c5cfa3bc0cd37.js +1 -0
  118. package/.next/static/chunks/framework-7c18bae94415732c.js +1 -0
  119. package/.next/static/chunks/main-app-14a04931699eb2a2.js +1 -0
  120. package/.next/static/chunks/main-d9f723dc0fb9d113.js +1 -0
  121. package/.next/static/chunks/pages/_app-79e662cab09aea11.js +1 -0
  122. package/.next/static/chunks/pages/_error-89cd7530328c75d9.js +1 -0
  123. package/.next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
  124. package/.next/static/chunks/webpack-d434b6449a9cd8f3.js +1 -0
  125. package/.next/static/css/491f5e1d36eb62fc.css +1 -0
  126. package/.next/static/css/5eacd01f773eed7f.css +11 -0
  127. package/.next/static/qH3fSSOUNLq_-dFHc2iUI/_buildManifest.js +1 -0
  128. package/.next/static/qH3fSSOUNLq_-dFHc2iUI/_ssgManifest.js +1 -0
  129. package/LICENSE +21 -0
  130. package/README.md +120 -0
  131. package/bin/cursor-remote.mjs +250 -0
  132. package/next.config.ts +26 -0
  133. package/package.json +79 -0
  134. package/public/apple-touch-icon.png +0 -0
  135. package/public/icon-192.png +0 -0
  136. package/public/icon-512.png +0 -0
  137. package/public/sw.js +68 -0
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[593],{1456:(e,t,s)=>{"use strict";s.d(t,{ChatWorkspace:()=>eu});var r=s(5155),n=s(2115),l=s(154);function a(){let{trigger:e}=(0,l.Y)();return{tap:()=>e("light"),send:()=>e("success"),select:()=>e("selection"),warn:()=>e("warning"),error:()=>e("error")}}function o(e,t){let s=Error(t);return s.name="ApiError",s.status=e,s.body={error:t},s}let i=new Set([502,503,504]);async function c(e,t,s){let{timeoutMs:r=3e4,retries:n,...l}=t,a=new AbortController,d=setTimeout(()=>a.abort(),r);try{let r=await fetch(e,{...l,credentials:"same-origin",signal:a.signal});if(!r.ok){if(s>0&&i.has(r.status))return await new Promise(e=>setTimeout(e,500)),c(e,t,s-1);let n="HTTP ".concat(r.status);try{let e=await r.json();e.error&&(n=e.error)}catch(e){}throw o(r.status,n)}return r}catch(r){if(r instanceof Error&&"AbortError"===r.name){if(s>0)return await new Promise(e=>setTimeout(e,500)),c(e,t,s-1);throw o(0,"Request timed out")}throw r}finally{clearTimeout(d)}}function d(e){var t;let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return c(e,s,null!=(t=s.retries)?t:2)}function x(){var e;return"function"==typeof(null==(e=globalThis.crypto)?void 0:e.randomUUID)?globalThis.crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}async function u(){try{let e=await d("/api/sessions/active");if(!e.ok)return[];return(await e.json()).sessions||[]}catch(e){return[]}}function m(){return"undefined"!=typeof Notification?Notification.permission:"default"}function h(){try{return"1"===localStorage.getItem("clr_sound_muted")}catch(e){return!1}}function p(e){if(e.current)return e.current;try{return e.current=new AudioContext,e.current}catch(e){return null}}function f(e,t,s,r,n){let l=e.createOscillator(),a=e.createGain();l.type="sine",l.frequency.value=t,a.gain.setValueAtTime(n,s),a.gain.exponentialRampToValueAtTime(.001,s+r),l.connect(a),a.connect(e.destination),l.start(s),l.stop(s+r)}function g(e){let t=Math.floor((Date.now()-e)/6e4);if(t<1)return"now";if(t<60)return"".concat(t,"m ago");let s=Math.floor(t/60);if(s<24)return"".concat(s,"h ago");let r=Math.floor(s/24);return"".concat(r,"d ago")}var b=s(6504),j=s(4514),v=s(5225);s(1226);let y={h1:e=>{let{children:t}=e;return(0,r.jsx)("h1",{className:"text-[17px] font-semibold mt-5 mb-2 text-text",children:t})},h2:e=>{let{children:t}=e;return(0,r.jsx)("h2",{className:"text-[15px] font-semibold mt-4 mb-1.5 text-text",children:t})},h3:e=>{let{children:t}=e;return(0,r.jsx)("h3",{className:"text-[14px] font-semibold mt-3 mb-1 text-text",children:t})},h4:e=>{let{children:t}=e;return(0,r.jsx)("h4",{className:"text-[13px] font-semibold mt-2.5 mb-1 text-text",children:t})},h5:e=>{let{children:t}=e;return(0,r.jsx)("h5",{className:"text-[13px] font-medium mt-2 mb-0.5 text-text-secondary",children:t})},h6:e=>{let{children:t}=e;return(0,r.jsx)("h6",{className:"text-[12px] font-medium mt-2 mb-0.5 text-text-secondary",children:t})},p:e=>{let{children:t}=e;return(0,r.jsx)("p",{className:"my-1 text-[13px] leading-[1.6]",children:t})},a:e=>{let{href:t,children:s}=e;return(0,r.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"text-accent underline underline-offset-2 decoration-text-muted/40 hover:decoration-accent transition-colors",children:s})},pre:e=>{let{children:t}=e;return(0,r.jsx)("pre",{className:"my-2 rounded-lg bg-[#0d0d0d] border border-border px-3.5 py-3 overflow-x-auto",children:t})},code:e=>{let{className:t,children:s}=e;return t?(0,r.jsx)("code",{className:"".concat(t," text-[12px] leading-[1.7] font-mono"),children:s}):(0,r.jsx)("code",{className:"px-1.5 py-0.5 rounded bg-[#1c1c1c] text-[#d4d4d4] text-[12px] font-mono",children:s})},ul:e=>{let{children:t}=e;return(0,r.jsx)("ul",{className:"my-1.5 space-y-0.5 list-disc pl-5",children:t})},ol:e=>{let{children:t}=e;return(0,r.jsx)("ol",{className:"my-1.5 space-y-0.5 list-decimal pl-5",children:t})},li:e=>{let{children:t}=e;return(0,r.jsx)("li",{className:"text-[13px] leading-[1.6]",children:t})},hr:()=>(0,r.jsx)("hr",{className:"my-3 border-border"}),blockquote:e=>{let{children:t}=e;return(0,r.jsx)("blockquote",{className:"my-2 pl-3 border-l-2 border-border text-text-secondary italic",children:t})},table:e=>{let{children:t}=e;return(0,r.jsx)("div",{className:"my-2 overflow-x-auto",children:(0,r.jsx)("table",{className:"min-w-full text-[13px] border-collapse",children:t})})},th:e=>{let{children:t}=e;return(0,r.jsx)("th",{className:"px-3 py-1.5 text-left font-semibold border-b border-border text-text",children:t})},td:e=>{let{children:t}=e;return(0,r.jsx)("td",{className:"px-3 py-1.5 border-b border-border/50",children:t})},img:e=>{let{src:t,alt:s}=e;return(0,r.jsx)("img",{src:t,alt:null!=s?s:"",className:"my-2 max-w-full rounded",loading:"lazy"})}},N=(0,n.memo)(function(e){let{content:t}=e;return(0,r.jsx)("div",{className:"text-text",children:(0,r.jsx)(b.oz,{remarkPlugins:[j.A],rehypePlugins:[v.A],components:y,children:t})})}),k={size:14,className:""};function w(e){let{size:t=10,className:s=""}=e;return(0,r.jsx)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:s,children:(0,r.jsx)("polyline",{points:"6 9 12 15 18 9"})})}function C(e){let{size:t=k.size,className:s=k.className}=e;return(0,r.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:s,children:[(0,r.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,r.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function S(e){let{size:t=12,className:s=k.className}=e;return(0,r.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:s,children:[(0,r.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,r.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function E(e){let{size:t=k.size,className:s=k.className}=e;return(0,r.jsx)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})})}function W(e){let{size:t=k.size,className:s=k.className}=e;return(0,r.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[(0,r.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,r.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}function T(e){let{size:t=20,className:s=k.className}=e;return(0,r.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:s,children:[(0,r.jsx)("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),(0,r.jsx)("line",{x1:"3",y1:"12",x2:"15",y2:"12"}),(0,r.jsx)("line",{x1:"3",y1:"18",x2:"18",y2:"18"})]})}function R(e){let{size:t=12,className:s=k.className}=e;return(0,r.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:s,children:[(0,r.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,r.jsx)("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]})}function M(e){let{size:t=k.size,className:s=k.className}=e;return(0,r.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:s,children:[(0,r.jsx)("path",{d:"M21 12a9 9 0 1 1-6.22-8.56"}),(0,r.jsx)("polyline",{points:"21 3 21 9 15 9"})]})}function A(e){let{size:t=12,className:s=k.className}=e;return(0,r.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:s,children:[(0,r.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,r.jsx)("polyline",{points:"19 12 12 19 5 12"})]})}function L(e){let{size:t=18,className:s=k.className}=e;return(0,r.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[(0,r.jsx)("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),(0,r.jsx)("polyline",{points:"5 12 12 5 19 12"})]})}function I(e){let{size:t=18,className:s=k.className}=e;return(0,r.jsx)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"currentColor",className:s,children:(0,r.jsx)("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})})}function B(e){let{className:t="w-3 h-3"}=e;return(0,r.jsx)("span",{className:"inline-block rounded-full border-2 border-text-muted border-t-transparent animate-spin ".concat(t)})}function O(e){let{size:t=10,className:s=k.className}=e;return(0,r.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[(0,r.jsx)("polyline",{points:"1 4 1 10 7 10"}),(0,r.jsx)("path",{d:"M3.51 15a9 9 0 1 0 2.13-9.36L1 10"})]})}function z(e){let{size:t=k.size,className:s=k.className}=e;return(0,r.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,r.jsx)("polyline",{points:"12 6 12 12 16 14"})]})}function D(e){let{size:t=12,className:s=k.className}=e;return(0,r.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:s,children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,r.jsx)("line",{x1:"2",y1:"12",x2:"22",y2:"12"}),(0,r.jsx)("path",{d:"M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"})]})}function P(e){let{copied:t,onClick:s}=e;return(0,r.jsx)("button",{onClick:s,className:"absolute top-2 right-0 opacity-0 group-hover:opacity-100 transition-opacity p-1 rounded text-text-muted hover:text-text-secondary","aria-label":t?"Copied":"Copy message",children:t?(0,r.jsx)(E,{}):(0,r.jsx)(W,{})})}let F=(0,n.memo)(function(e){let{message:t}=e,s="user"===t.role,[l,o]=(0,n.useState)(!1),i=a(),c=async()=>{try{await navigator.clipboard.writeText(t.content),i.tap(),o(!0),setTimeout(()=>o(!1),1500)}catch(e){}};return s?(0,r.jsxs)("div",{className:"py-3 group relative",children:[(0,r.jsx)("div",{className:"text-[13px] leading-[1.6] text-text whitespace-pre-wrap break-words bg-bg-surface rounded-lg px-3 py-2",children:t.content}),(0,r.jsx)(P,{copied:l,onClick:c})]}):(0,r.jsxs)("div",{className:"py-3 group relative",children:[(0,r.jsx)(N,{content:t.content}),(0,r.jsx)(P,{copied:l,onClick:c})]})}),H=new Set(["edit","write","shell","todo"]);function q(e){let{className:t}=e;return(0,r.jsxs)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,r.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,r.jsx)("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}function Q(e){let{type:t}=e,s="w-3.5 h-3.5 shrink-0";switch(t){case"read":return(0,r.jsxs)("svg",{className:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,r.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,r.jsx)("polyline",{points:"14 2 14 8 20 8"}),(0,r.jsx)("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),(0,r.jsx)("line",{x1:"16",y1:"17",x2:"8",y2:"17"})]});case"write":case"edit":return(0,r.jsxs)("svg",{className:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,r.jsx)("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),(0,r.jsx)("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]});case"shell":return(0,r.jsxs)("svg",{className:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,r.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,r.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]});case"search":return(0,r.jsxs)("svg",{className:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,r.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,r.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]});case"todo":return(0,r.jsxs)("svg",{className:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,r.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]});default:return(0,r.jsx)(q,{className:s})}}function V(e){let t=e.split("/");return t.length<=3?e:".../"+t.slice(-2).join("/")}function _(e){let{status:t}=e,s="w-3 h-3 shrink-0 mt-0.5";return t.includes("COMPLETED")?(0,r.jsx)("svg",{className:"".concat(s," text-text-secondary"),viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,r.jsx)("polyline",{points:"20 6 9 17 4 12"})}):t.includes("IN_PROGRESS")?(0,r.jsx)(B,{className:s}):(0,r.jsx)("svg",{className:"".concat(s," text-text-muted"),viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,r.jsx)("circle",{cx:"12",cy:"12",r:"9"})})}function U(e){let{diff:t,startLine:s}=e,n=t.split("\n"),l=void 0!==s,a=null!=s?s:1,o=null!=s?s:1,i=[];if(l)for(let e of n)e.startsWith("-")?(i.push(String(a)),a++):(e.startsWith("+")?i.push(String(o)):(i.push(String(o)),a++),o++);let c=l?String(Math.max(a,o)).length:0;return(0,r.jsx)("pre",{className:"bg-[#0d0d0d] rounded px-2 py-1.5 text-[11px] whitespace-pre-wrap break-all max-h-[300px] overflow-y-auto",children:n.map((e,t)=>(0,r.jsxs)("span",{className:e.startsWith("+")?"text-green-400/70":e.startsWith("-")?"text-red-400/70":"text-text-muted",children:[l&&(0,r.jsx)("span",{className:"text-text-muted/40 select-none inline-block mr-2",style:{width:"".concat(c,"ch"),textAlign:"right"},children:i[t]}),e,t<n.length-1?"\n":""]},t))})}function J(e){switch(e.type){case"read":return"Reading";case"write":return"Writing";case"edit":return"Editing";case"shell":return"Running";case"search":return"Searching";case"todo":return"Updating";default:return e.name}}function K(e){if("shell"===e.type&&e.command)return e.command;if("search"===e.type&&e.command){let t=e.path?" in ".concat(V(e.path)):"";return'"'.concat(e.command,'"').concat(t)}return"todo"===e.type?"todo list":e.path?V(e.path):e.name}function G(e){let t={};for(let s of e){let e=s.name||s.type;t[e]=(t[e]||0)+1}return Object.entries(t).map(e=>{let[t,s]=e;return"".concat(s," ").concat(t)}).join(", ")}function Y(e){let{toolCalls:t}=e,[s,l]=(0,n.useState)(!1),a=t.every(e=>"completed"===e.status);return(0,r.jsxs)("div",{className:"py-1.5",children:[(0,r.jsxs)("button",{onClick:()=>l(e=>!e),"aria-expanded":s,"aria-label":"Tool call group: ".concat(G(t)),className:"flex items-center gap-2 text-[12px] text-text-muted hover:text-text-secondary transition-colors w-full text-left",children:[(0,r.jsx)("span",{className:a?"text-text-muted":"text-text-secondary",children:a?(0,r.jsx)(q,{className:"w-3.5 h-3.5 shrink-0"}):(0,r.jsx)(B,{className:"w-3.5 h-3.5"})}),(0,r.jsx)("span",{className:"flex items-center gap-1.5 min-w-0 flex-1",children:(0,r.jsx)("span",{className:"font-mono text-text-muted truncate",children:G(t)})}),(0,r.jsx)(w,{className:"shrink-0 transition-transform ".concat(s?"rotate-180":"")})]}),s&&(0,r.jsx)("div",{className:"ml-5 pl-3 border-l-2 border-border",children:t.map(e=>(0,r.jsx)($,{toolCall:e},e.id))})]})}function $(e){let{toolCall:t,defaultExpanded:s}=e,[l,a]=(0,n.useState)(null!=s&&s),o="running"===t.status;return(0,r.jsxs)("div",{className:"py-1.5",children:[(0,r.jsxs)("button",{onClick:()=>a(e=>!e),"aria-expanded":l,"aria-label":"".concat(J(t)," ").concat(K(t)),className:"flex items-center gap-2 text-[12px] text-text-muted hover:text-text-secondary transition-colors w-full text-left",children:[(0,r.jsx)("span",{className:o?"text-text-secondary":"text-text-muted",children:o?(0,r.jsx)(B,{className:"w-3.5 h-3.5"}):(0,r.jsx)(Q,{type:t.type})}),(0,r.jsxs)("span",{className:"flex items-center gap-1.5 min-w-0 flex-1",children:[(0,r.jsx)("span",{className:"font-medium ".concat(o?"text-text-secondary":"text-text-muted"),children:J(t)}),(0,r.jsx)("span",{className:"font-mono truncate",children:K(t)})]}),t.result&&(0,r.jsx)("span",{className:"text-text-muted text-[11px] shrink-0",children:t.result}),(0,r.jsx)(w,{className:"shrink-0 transition-transform ".concat(l?"rotate-180":"")})]}),l&&(0,r.jsxs)("div",{className:"mt-1.5 ml-5 pl-3 border-l-2 border-border text-[11px] font-mono text-text-muted py-1.5 space-y-1 overflow-x-auto",children:[(0,r.jsx)("p",{className:"text-text-secondary",children:t.name}),t.path&&(0,r.jsx)("p",{className:"break-all",children:t.path}),"shell"===t.type&&t.command&&(0,r.jsxs)("pre",{className:"bg-[#0d0d0d] rounded px-2 py-1.5 text-[11px] text-[#c9d1d9] whitespace-pre-wrap break-all",children:["$ ",t.command]}),"search"===t.type&&t.command&&(0,r.jsxs)("p",{children:["pattern: ",(0,r.jsx)("span",{className:"text-text-secondary",children:t.command})]}),t.todos&&t.todos.length>0&&(0,r.jsx)("ul",{className:"space-y-0.5",children:t.todos.map(e=>(0,r.jsxs)("li",{className:"flex items-start gap-1.5",children:[(0,r.jsx)(_,{status:e.status}),(0,r.jsx)("span",{className:e.status.includes("COMPLETED")?"text-text-muted line-through":"text-text-secondary",children:e.content})]},e.id))}),t.diff&&(0,r.jsx)(U,{diff:t.diff,startLine:t.diffStartLine}),!t.diff&&!t.todos&&t.result&&(0,r.jsx)("p",{className:"text-text-secondary",children:t.result}),o&&(0,r.jsx)("p",{className:"text-text-muted animate-pulse",children:"running..."})]})]})}function X(e){let{toolCall:t}=e,[s,l]=(0,n.useState)(!0),a=t.todos;if(!a||0===a.length)return null;let o=a.filter(e=>e.status.includes("COMPLETED")).length,i=a.filter(e=>e.status.includes("IN_PROGRESS")).length;return(0,r.jsxs)("div",{className:"py-2",children:[(0,r.jsxs)("button",{onClick:()=>l(e=>!e),"aria-expanded":s,"aria-label":"Todo list: ".concat(o,"/").concat(a.length," done"),className:"flex items-center gap-2 text-[12px] text-text-muted hover:text-text-secondary transition-colors w-full text-left",children:[(0,r.jsxs)("svg",{className:"w-3.5 h-3.5 shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,r.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),(0,r.jsx)("span",{className:"font-medium text-text-secondary",children:"Todo"}),(0,r.jsxs)("span",{className:"text-text-muted text-[11px]",children:[o,"/",a.length," done",i>0?" \xb7 ".concat(i," active"):""]}),(0,r.jsx)(w,{className:"shrink-0 transition-transform ml-auto ".concat(s?"rotate-180":"")})]}),s&&(0,r.jsx)("ul",{className:"mt-1.5 ml-5 pl-3 border-l-2 border-border space-y-0.5 py-1",children:a.map(e=>(0,r.jsxs)("li",{className:"flex items-start gap-1.5 text-[11px] font-mono",children:[(0,r.jsx)(_,{status:e.status}),(0,r.jsx)("span",{className:e.status.includes("COMPLETED")?"text-text-muted line-through":"text-text-secondary",children:e.content})]},e.id))})]})}function Z(e){let{sessions:t,onSelect:s}=e;return 0===t.length?null:(0,r.jsxs)("div",{className:"mt-5 w-full max-w-xs",children:[(0,r.jsx)("p",{className:"text-text-muted text-[11px] font-medium mb-2 uppercase tracking-wider",children:"Recent sessions"}),(0,r.jsx)("div",{className:"space-y-1",children:t.map(e=>(0,r.jsxs)("button",{onClick:()=>s(e.id),className:"w-full text-left px-3 py-2 rounded-lg bg-bg-surface hover:bg-bg-hover border border-border/50 transition-colors group",children:[(0,r.jsx)("p",{className:"text-[12px] text-text-secondary group-hover:text-text truncate",children:e.title}),(0,r.jsx)("p",{className:"text-[10px] text-text-muted mt-0.5",children:g(e.updatedAt)})]},e.id))})]})}function ee(e){let{msg:t,onForceSend:s,onEdit:l,onDelete:a}=e,[o,i]=(0,n.useState)(!1),[c,d]=(0,n.useState)(t.content),x=()=>{let e=c.trim();e&&e!==t.content&&l(e),i(!1)},u=()=>{d(t.content),i(!1)};return(0,r.jsxs)("div",{className:"py-2.5 border border-dashed border-text-muted/25 rounded-lg px-3 bg-bg-surface/50",children:[(0,r.jsxs)("div",{className:"flex items-start gap-2",children:[(0,r.jsx)("span",{className:"shrink-0 mt-0.5 text-text-muted/50",children:(0,r.jsx)(z,{})}),(0,r.jsx)("div",{className:"flex-1 min-w-0",children:o?(0,r.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,r.jsx)("textarea",{autoFocus:!0,"aria-label":"Edit queued message",value:c,onChange:e=>d(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),x()),"Escape"===e.key&&u()},rows:2,className:"w-full resize-none bg-bg px-2 py-1.5 text-[13px] text-text rounded border border-border focus:outline-none focus:border-text-muted/40"}),(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsx)("button",{onClick:x,className:"px-2 py-0.5 text-[10px] font-medium rounded bg-bg-active text-text hover:bg-bg-hover transition-colors",children:"Save"}),(0,r.jsx)("button",{onClick:u,className:"px-2 py-0.5 text-[10px] font-medium rounded text-text-muted hover:text-text-secondary transition-colors",children:"Cancel"})]})]}):(0,r.jsx)("p",{className:"text-[13px] text-text-secondary whitespace-pre-wrap break-words",children:t.content})})]}),!o&&(0,r.jsxs)("div",{className:"flex items-center gap-1 mt-1.5 ml-5",children:[(0,r.jsx)("span",{className:"text-[10px] text-text-muted/50 mr-1",children:"Queued"}),(0,r.jsx)("button",{onClick:s,className:"px-2 py-0.5 text-[10px] font-medium rounded bg-bg-active text-text-secondary hover:text-text transition-colors",title:"Stop current and send this now",children:"Send now"}),(0,r.jsx)("button",{onClick:()=>{d(t.content),i(!0)},className:"px-2 py-0.5 text-[10px] font-medium rounded text-text-muted hover:text-text-secondary hover:bg-bg-hover transition-colors",children:"Edit"}),(0,r.jsx)("button",{onClick:a,className:"px-2 py-0.5 text-[10px] font-medium rounded text-text-muted hover:text-error/80 hover:bg-error/5 transition-colors",children:"Delete"})]})]})}function et(e){var t,s;let{messages:l,toolCalls:a,isStreaming:o,isLoadingHistory:i,isWatching:c,recentSessions:d=[],onSelectSession:x,onRetry:u,queuedMessages:m=[],onForceSend:h,onEditQueued:p,onDeleteQueued:f}=e,g=(0,n.useRef)(null),b=(0,n.useRef)(null),[j,v]=(0,n.useState)(!0),y=(0,n.useRef)(!1),N=(0,n.useCallback)(()=>{var e;null==(e=b.current)||e.scrollIntoView({behavior:"smooth"}),v(!0)},[]),k=(0,n.useCallback)(()=>{if(y.current)return;let e=g.current;e&&v(e.scrollHeight-e.scrollTop-e.clientHeight<60)},[]),w=l[l.length-1],C=o&&(null==w?void 0:w.role)==="user",S=(0,n.useRef)(null),E=(0,n.useRef)(!1);(0,n.useEffect)(()=>{var e;if(j||C){if(S.current){E.current=!0;return}y.current=!0,null==(e=b.current)||e.scrollIntoView({behavior:"smooth"}),S.current=setTimeout(()=>{if(S.current=null,y.current=!1,E.current){var e;E.current=!1,null==(e=b.current)||e.scrollIntoView({behavior:"smooth"})}},200)}},[l,a,j,C]);let W=[...l.map(e=>({kind:"message",timestamp:e.timestamp,message:e})),...a.map(e=>({kind:"toolcall",timestamp:e.timestamp,toolCall:e}))].sort((e,t)=>e.timestamp-t.timestamp),T=[],R=[],M=()=>{0!==R.length&&(1===R.length?T.push({kind:"toolcall",timestamp:R[0].timestamp,toolCall:R[0]}):T.push({kind:"toolgroup",timestamp:R[0].timestamp,toolCalls:[...R]}),R=[])};for(let e of W)"toolcall"===e.kind&&e.toolCall&&(s=e.toolCall,!H.has(s.type))?R.push(e.toolCall):(M(),T.push(e));if(M(),i)return(0,r.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,r.jsxs)("div",{className:"flex items-center gap-2 text-text-muted text-[13px]",children:[(0,r.jsx)(B,{className:"w-3.5 h-3.5"}),"Loading session..."]})});if(0===T.length)return(0,r.jsx)("div",{className:"flex-1 flex items-center justify-center px-6",children:(0,r.jsxs)("div",{className:"flex flex-col items-center max-w-sm",children:[(0,r.jsx)("p",{className:"text-text-secondary text-[13px] font-medium mb-1",children:"Cursor Remote"}),(0,r.jsx)("p",{className:"text-text-muted text-[12px] leading-relaxed",children:"Send a message to start an agent session."}),x&&(0,r.jsx)(Z,{sessions:d,onSelect:x})]})});let L=a.some(e=>"running"===e.status),I=T[T.length-1],z=(null==I?void 0:I.kind)==="message"&&(null==(t=I.message)?void 0:t.role)==="user",D=o&&!L&&z,P=l[l.length-1],q=!o&&(null==P?void 0:P.role)==="user"&&u;return(0,r.jsxs)("div",{className:"flex-1 overflow-hidden relative",children:[(0,r.jsx)("div",{ref:g,onScroll:k,className:"h-full overflow-y-auto",children:(0,r.jsxs)("div",{className:"px-4 max-w-3xl mx-auto w-full",children:[(0,r.jsx)("div",{className:"divide-y divide-border/50",children:T.map((e,t)=>"message"===e.kind&&e.message?(0,r.jsx)(F,{message:e.message},e.message.id):"toolcall"===e.kind&&e.toolCall?"todo"===e.toolCall.type?(0,r.jsx)(X,{toolCall:e.toolCall},e.toolCall.id):(0,r.jsx)($,{toolCall:e.toolCall},e.toolCall.id):"toolgroup"===e.kind&&e.toolCalls?(0,r.jsx)(Y,{toolCalls:e.toolCalls},"group-".concat(t)):null)}),D&&(0,r.jsxs)("div",{className:"py-3 flex items-center gap-2 text-text-muted text-[12px]",children:[(0,r.jsx)(B,{}),"Thinking..."]}),c&&!o&&T.length>0&&(0,r.jsxs)("div",{className:"py-3 flex items-center gap-2 text-text-muted text-[11px]",children:[(0,r.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-success animate-pulse"}),"Watching for updates..."]}),q&&(0,r.jsx)("div",{className:"py-1",children:(0,r.jsxs)("button",{onClick:u,className:"flex items-center gap-1 text-[10px] text-text-muted/60 hover:text-text-muted transition-colors","aria-label":"Retry last message",children:[(0,r.jsx)(O,{}),"Retry last message"]})}),m.length>0&&(0,r.jsx)("div",{className:"space-y-2 py-2",children:m.map(e=>(0,r.jsx)(ee,{msg:e,onForceSend:()=>null==h?void 0:h(e.id),onEdit:t=>null==p?void 0:p(e.id,t),onDelete:()=>null==f?void 0:f(e.id)},e.id))}),(0,r.jsx)("div",{ref:b,className:"h-4"})]})}),!j&&T.length>0&&(0,r.jsxs)("button",{onClick:N,"aria-label":"Scroll to bottom",className:"absolute bottom-3 left-1/2 -translate-x-1/2 z-10 flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-bg-elevated border border-border text-text-muted hover:text-text-secondary text-[11px] shadow-lg transition-colors",children:[(0,r.jsx)(A,{}),"Scroll to bottom"]})]})}let es=[{id:"agent",label:"Agent"},{id:"ask",label:"Ask"},{id:"plan",label:"Plan"}];function er(e){var t;let{onSend:s,onStop:l,isStreaming:o,selectedModel:i,selectedMode:c,onModelChange:x,onModeChange:u}=e,[m,h]=(0,n.useState)(""),[p,f]=(0,n.useState)(!1),[g,b]=(0,n.useState)([]),[j,v]=(0,n.useState)(!0),y=(0,n.useRef)(null),N=a();(0,n.useEffect)(()=>{let e=!1;return d("/api/models").then(e=>e.json()).then(t=>{var s;!e&&(null==(s=t.models)?void 0:s.length)>0&&b(t.models)}).catch(e=>console.error("[models] Failed to fetch:",e)).finally(()=>{e||v(!1)}),()=>{e=!0}},[]);let k=(0,n.useCallback)(()=>{let e=m.trim();e&&(N.send(),s(e),h(""),y.current&&(y.current.style.height="auto"))},[m,s,N]),C=(0,n.useCallback)(()=>{N.tap(),null==l||l()},[l,N]),E=(null==(t=g.find(e=>e.id===i))?void 0:t.label)||i,W=g.find(e=>"auto"===e.id),T=g.filter(e=>"auto"!==e.id);return(0,r.jsx)("div",{className:"shrink-0 bg-bg px-4 py-3 safe-bottom",children:(0,r.jsx)("div",{className:"max-w-3xl mx-auto",children:(0,r.jsxs)("div",{className:"relative bg-bg-surface border border-border rounded-xl focus-within:border-text-muted/40 transition-colors",children:[(0,r.jsx)("textarea",{ref:y,value:m,onChange:e=>{h(e.target.value);let t=e.target;t.style.height="auto",t.style.height=Math.min(t.scrollHeight,160)+"px"},onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),k())},placeholder:o?"Type to queue a message...":"Ask Cursor anything...","aria-label":"Message input",rows:1,className:"w-full resize-none bg-transparent px-3.5 pt-2.5 pb-1 pr-10 text-[13px] text-text placeholder:text-text-muted focus:outline-none"}),(0,r.jsxs)("div",{className:"flex items-center justify-between px-2 pb-2",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1",role:"radiogroup","aria-label":"Agent mode",children:[es.map(e=>(0,r.jsx)("button",{role:"radio","aria-checked":c===e.id,onClick:()=>{N.select(),u(e.id)},className:"px-3 py-1.5 rounded text-[12px] font-medium transition-colors ".concat(c===e.id?"bg-bg-active text-text":"text-text-muted hover:text-text-secondary hover:bg-bg-hover"),children:e.label},e.id)),(0,r.jsx)("span",{className:"hidden sm:inline text-[10px] text-text-muted/50 ml-2 select-none",children:"Enter ↵ send \xb7 Shift+Enter newline"})]}),(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsxs)("button",{onClick:()=>{N.tap(),f(!p)},"aria-haspopup":"listbox","aria-expanded":p,"aria-label":"Select model",className:"flex items-center gap-1 px-3 py-1.5 rounded text-[12px] text-text-muted hover:text-text-secondary hover:bg-bg-hover transition-colors",children:[j?(0,r.jsx)(B,{className:"w-2.5 h-2.5"}):(0,r.jsx)("span",{className:"truncate max-w-[150px]",children:E}),(0,r.jsx)(w,{})]}),p&&g.length>0&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"fixed inset-0 z-40",onClick:()=>f(!1)}),(0,r.jsxs)("div",{role:"listbox","aria-label":"Models",className:"absolute bottom-full right-0 mb-1 z-50 w-56 bg-bg-elevated border border-border rounded-lg shadow-xl py-1 max-h-80 overflow-y-auto",children:[W&&(0,r.jsx)(en,{model:W,selected:i===W.id,onSelect:()=>{x(W.id),f(!1)}},W.id),T.length>0&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"h-px bg-border mx-2 my-1"}),T.map(e=>(0,r.jsx)(en,{model:e,selected:i===e.id,onSelect:()=>{x(e.id),f(!1)}},e.id))]})]})]})]}),o&&(0,r.jsx)("button",{onClick:C,className:"p-2 rounded-md text-text-muted hover:text-text transition-colors","aria-label":"Stop streaming",children:(0,r.jsx)(I,{})}),(0,r.jsx)("button",{onClick:k,disabled:!m.trim(),className:"p-2 rounded-md text-text-muted hover:text-text disabled:opacity-20 disabled:cursor-not-allowed transition-colors","aria-label":o?"Queue message":"Send message",children:o?(0,r.jsx)(S,{size:18}):(0,r.jsx)(L,{})})]})]})]})})})}function en(e){let{model:t,selected:s,onSelect:n}=e,l=a();return(0,r.jsxs)("button",{role:"option","aria-selected":s,onClick:()=>{l.select(),n()},className:"w-full text-left px-3 py-1.5 text-[12px] flex items-center justify-between gap-2 transition-colors ".concat(s?"text-text bg-bg-active":"text-text-secondary hover:bg-bg-hover hover:text-text"),children:[(0,r.jsx)("span",{className:"truncate",children:t.label}),(0,r.jsxs)("span",{className:"flex items-center gap-1 shrink-0",children:[t.isDefault&&(0,r.jsx)("span",{className:"text-[9px] px-1 py-px rounded bg-bg-hover text-text-secondary font-medium",children:"default"}),t.isCurrent&&(0,r.jsx)("span",{className:"text-[9px] px-1 py-px rounded bg-success/15 text-success font-medium",children:"current"})]})]})}function el(e){let{initialSessionId:t,onLabelChange:s,onStreamingChange:l,onSessionIdChange:o,onSelectSession:i,onOpenSidebar:c,onOpenQr:g}=e,{messages:b,toolCalls:j,sessionId:v,isStreaming:y,isLoadingHistory:N,isWatching:k,model:w,selectedModel:C,selectedMode:S,error:E,sendMessage:W,loadSession:R,setSelectedModel:M,setSelectedMode:A,stopStreaming:L,retryLastMessage:I,queuedMessages:B,forceSendQueued:O,editQueued:z,deleteQueued:D}=function(){let[e,t]=(0,n.useState)(null),[s,r]=(0,n.useState)(!1),[l,a]=(0,n.useState)(!1),[o,i]=(0,n.useState)(null),[c,m]=(0,n.useState)("auto"),[h,p]=(0,n.useState)("agent"),[f,g]=(0,n.useState)(null),b=(0,n.useRef)(null),j=(0,n.useRef)(!1),v=(0,n.useRef)(void 0);(0,n.useEffect)(()=>{b.current=e},[e]),(0,n.useEffect)(()=>{j.current=s},[s]);let y=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},[t,s]=(0,n.useState)([]),[r,l]=(0,n.useState)([]),[a,o]=(0,n.useState)(!1),[i,c]=(0,n.useState)(!1),x=(0,n.useRef)(null),u=(0,n.useRef)(0),m=(0,n.useRef)(e.onStreamEnd),h=(0,n.useRef)(e.onStreamStart);(0,n.useEffect)(()=>{m.current=e.onStreamEnd},[e.onStreamEnd]),(0,n.useEffect)(()=>{h.current=e.onStreamStart},[e.onStreamStart]);let p=(0,n.useCallback)(()=>{x.current&&(x.current.close(),x.current=null),o(!1)},[]),f=(0,n.useCallback)(e=>{if(e.modifiedAt&&e.modifiedAt>u.current){var t,r;u.current=e.modifiedAt,(null==(t=e.messages)?void 0:t.length)>0&&s(e.messages),(null==(r=e.toolCalls)?void 0:r.length)>0&&l(e.toolCalls)}},[]),g=(0,n.useCallback)(e=>{p();let t=new EventSource("/api/sessions/watch?id=".concat(encodeURIComponent(e)));x.current=t,t.addEventListener("connected",e=>{o(!0);try{var t,r,n;let a=JSON.parse(e.data);!0===a.isActive?(c(!0),null==(n=h.current)||n.call(h)):c(!1),a.modifiedAt&&(u.current=a.modifiedAt),(null==(t=a.messages)?void 0:t.length)>0&&s(a.messages),(null==(r=a.toolCalls)?void 0:r.length)>0&&l(a.toolCalls)}catch(e){console.error("[watch] Failed to parse connected event")}}),t.addEventListener("update",e=>{try{let s=JSON.parse(e.data);if(f(s),!1===s.isActive){var t;c(!1),null==(t=m.current)||t.call(m)}else!0===s.isActive&&c(!0)}catch(e){console.error("[watch] Failed to parse update event")}}),t.addEventListener("error",()=>{})},[p,f]),b=(0,n.useCallback)(async e=>{try{var t,r;let n=await d("/api/sessions/history?id=".concat(encodeURIComponent(e)));if(!n.ok)return;let a=await n.json();(null==(t=a.messages)?void 0:t.length)>0&&s(a.messages),(null==(r=a.toolCalls)?void 0:r.length)>0&&l(a.toolCalls),a.modifiedAt&&(u.current=a.modifiedAt)}catch(e){console.error("[watch] Failed to refresh from history")}},[]),j=(0,n.useCallback)(()=>{s([]),l([]),c(!1),u.current=0},[]);return(0,n.useEffect)(()=>()=>{p()},[p]),{messages:t,setMessages:s,toolCalls:r,setToolCalls:l,isWatching:a,isActive:i,setIsActive:c,startWatching:g,stopWatching:p,refreshFromHistory:b,resetState:j,lastModifiedRef:u}}({onStreamEnd:(0,n.useCallback)(()=>{r(!1);let e=N.dequeueNext();if(e){let t=e.model||e.mode?{model:e.model,mode:e.mode}:void 0;setTimeout(()=>{var s;null==(s=v.current)||s.call(v,e.content,t)},0)}},[]),onStreamStart:(0,n.useCallback)(()=>r(!0),[])}),N=function(e){let{selectedModel:t,selectedMode:s}=e,[r,l]=(0,n.useState)([]),a=(0,n.useRef)([]);(0,n.useEffect)(()=>{a.current=r},[r]);let o=(0,n.useCallback)(e=>{let r={id:x(),content:e,timestamp:Date.now(),model:t,mode:s};l(e=>[...e,r])},[t,s]),i=(0,n.useCallback)(()=>{let e=a.current;if(0===e.length)return null;let t=e[0];return l(e=>e.slice(1)),t},[]),c=(0,n.useCallback)(e=>{let t=a.current.find(t=>t.id===e);return t?(l(t=>t.filter(t=>t.id!==e)),t):null},[]),d=(0,n.useCallback)((e,t)=>{l(s=>s.map(s=>s.id===e?{...s,content:t}:s))},[]);return{queuedMessages:r,enqueue:o,dequeueNext:i,forceSendQueued:c,editQueued:d,deleteQueued:(0,n.useCallback)(e=>{l(t=>t.filter(t=>t.id!==e))},[]),clearQueue:(0,n.useCallback)(()=>{l([])},[])}}({selectedModel:c,selectedMode:h}),k=(0,n.useCallback)(()=>{y.stopWatching(),y.resetState(),t(null),i(null),g(null),r(!1),N.clearQueue()},[y,N]),w=(0,n.useCallback)(()=>{b.current&&d("/api/sessions/active",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:b.current})}).catch(e=>console.error("[chat] Failed to stop streaming:",e)),r(!1)},[]),C=(0,n.useCallback)(async e=>{y.stopWatching(),y.resetState(),a(!0),g(null),t(e);try{await y.refreshFromHistory(e),y.startWatching(e),(await u()).includes(e)&&r(!0)}catch(e){g(e instanceof Error?e.message:"Failed to load session")}finally{a(!1)}},[y]),S=(0,n.useCallback)(async(e,s)=>{var n,l,a;if(j.current)return void N.enqueue(e);y.stopWatching(),g(null),r(!0);let o={id:x(),role:"user",content:e,timestamp:Date.now()};y.setMessages(e=>[...e,o]);let u=null!=(n=null==s?void 0:s.model)?n:c,m=null!=(l=null==s?void 0:s.mode)?l:h;try{let s=await d("/api/chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:e,sessionId:null!=(a=b.current)?a:void 0,model:"auto"!==u?u:void 0,mode:"agent"!==m?m:void 0})});if(!s.ok){let e=await s.json();throw Error(e.error||"HTTP ".concat(s.status))}let r=await s.json(),n=r.sessionId;b.current=n,t(n),r.model&&i(r.model),y.startWatching(n)}catch(e){if(e instanceof Error&&"AbortError"===e.name)return;g(e instanceof Error?e.message:"Unknown error"),r(!1)}},[c,h,y,N]);(0,n.useEffect)(()=>{v.current=S},[S]),(0,n.useEffect)(()=>{let e=async()=>{if("visible"!==document.visibilityState)return;let e=b.current;if(e)try{await y.refreshFromHistory(e);let t=await u();r(t.includes(e)),g(null),y.isWatching||y.startWatching(e)}catch(e){console.error("[chat] Failed to refresh on visibility change")}};return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[y]);let E=(0,n.useCallback)(e=>{let t=N.forceSendQueued(e);if(!t)return;r(!1);let s=t.model||t.mode?{model:t.model,mode:t.mode}:void 0;setTimeout(()=>{var e;null==(e=v.current)||e.call(v,t.content,s)},0)},[N]),W=(0,n.useCallback)(()=>{if(j.current)return;let e=y.messages,t=[...e].reverse().find(e=>"user"===e.role);if(!t)return;let s=t.content,r=e.findIndex(e=>e.id===t.id);r>=0&&y.setMessages(e.slice(0,r)),y.setToolCalls(e=>e.filter(e=>e.timestamp<t.timestamp)),S(s).catch(e=>console.error("[chat] Retry failed:",e))},[y,S]);return{messages:y.messages,toolCalls:y.toolCalls,sessionId:e,isStreaming:s,isLoadingHistory:l,isWatching:y.isWatching,model:o,selectedModel:c,selectedMode:h,error:f,queuedMessages:N.queuedMessages,sendMessage:S,loadSession:C,setSessionId:t,setSelectedModel:m,setSelectedMode:p,clearChat:k,stopStreaming:w,retryLastMessage:W,forceSendQueued:E,editQueued:N.editQueued,deleteQueued:N.deleteQueued}}(),P=a(),F=function(){let[e,t]=(0,n.useState)(m),s=(0,n.useRef)(!1),r=(0,n.useCallback)(async()=>{if(!s.current&&"serviceWorker"in navigator&&"PushManager"in window)try{let e=await navigator.serviceWorker.ready;if(await e.pushManager.getSubscription()){s.current=!0;return}let t=await d("/api/push/vapid-key");if(!t.ok)return;let{publicKey:r}=await t.json(),n=await e.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:function(e){let t="=".repeat((4-e.length%4)%4),s=atob((e+t).replace(/-/g,"+").replace(/_/g,"/")),r=new ArrayBuffer(s.length),n=new Uint8Array(r);for(let e=0;e<s.length;e++)n[e]=s.charCodeAt(e);return r}(r)});await d("/api/push/subscribe",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n.toJSON())}),s.current=!0}catch(e){console.error("[push] Subscription failed:",e)}},[]);return{permission:e,requestPermission:(0,n.useCallback)(async()=>{if("undefined"==typeof Notification)return;if("default"!==Notification.permission){t(Notification.permission),"granted"===Notification.permission&&r();return}let e=await Notification.requestPermission();t(e),"granted"===e&&r()},[r]),notify:(0,n.useCallback)((e,t)=>{"undefined"!=typeof Notification&&"granted"===Notification.permission&&document.hidden&&"serviceWorker"in navigator&&navigator.serviceWorker.ready.then(s=>{var r;null==(r=s.active)||r.postMessage({type:"SHOW_NOTIFICATION",title:e,options:{icon:"/icon-192.png",...t}})}).catch(e=>console.error("[notifications] SW notify failed:",e))},[])}}(),H=function(){let e=(0,n.useRef)(null);return{playComplete:(0,n.useCallback)(()=>{if(h())return;let t=p(e);if(!t)return;let s=t.currentTime;f(t,880,s,.12,.15),f(t,1174.66,s+.1,.18,.12)},[]),playError:(0,n.useCallback)(()=>{if(h())return;let t=p(e);if(!t)return;let s=t.currentTime;f(t,330,s,.2,.15),f(t,220,s+.15,.25,.12)},[])}}(),[q,Q]=(0,n.useState)(""),[V,_]=(0,n.useState)([]),U=(0,n.useRef)(0),J=(0,n.useRef)(!1),K=(0,n.useRef)(!1),G=(0,n.useRef)(0);(0,n.useEffect)(()=>{t&&!J.current&&(J.current=!0,R(t))},[t,R]);let Y=(0,n.useCallback)(()=>{d("/api/info").then(e=>e.json()).then(e=>Q(e.workspace||"")).catch(e=>console.error("[workspace] Failed to fetch:",e))},[]);(0,n.useEffect)(()=>{Y(),d("/api/sessions").then(e=>e.json()).then(e=>{var t;(null==(t=e.sessions)?void 0:t.length)>0&&_(e.sessions.slice(0,3))}).catch(e=>console.error("[sessions] Failed to fetch:",e))},[Y]),(0,n.useEffect)(()=>{let e=b.filter(e=>"assistant"===e.role).length;e>U.current&&e>0&&P.tap(),U.current=e},[b,P]),(0,n.useEffect)(()=>{if(y&&!K.current&&(G.current=Date.now(),F.requestPermission()),K.current&&!y){let e=Date.now()-G.current>3e3;if(E)F.notify("Agent error",{body:E}),(e||document.hidden)&&H.playError();else{let t=[...b].reverse().find(e=>"assistant"===e.role);F.notify("Agent finished",{body:(null==t?void 0:t.content.slice(0,80))||"Response complete"}),(e||document.hidden)&&H.playComplete()}}K.current=y,null==l||l(y)},[y,E]),(0,n.useEffect)(()=>{null==o||o(v)},[v]),(0,n.useEffect)(()=>{let e=b.find(e=>"user"===e.role);e&&(null==s||s(e.content.slice(0,50)))},[b]);let $=q.split("/").filter(Boolean).pop()||"~";return(0,r.jsxs)("div",{className:"h-full flex flex-col",children:[(0,r.jsxs)("header",{className:"shrink-0 flex items-center justify-between h-11 px-3 border-b border-border",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("button",{onClick:()=>{P.tap(),null==c||c()},"aria-label":"Open session sidebar",className:"p-2 rounded-md hover:bg-bg-hover transition-colors text-text-muted hover:text-text-secondary",children:(0,r.jsx)(T,{})}),(0,r.jsx)("span",{className:"text-[13px] font-medium text-text-secondary",children:$}),w&&y&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"text-text-muted text-[11px]",children:"/"}),(0,r.jsx)("span",{className:"text-[11px] text-text-muted truncate max-w-[120px]",children:w})]})]}),(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[v&&(0,r.jsx)("span",{className:"text-[10px] text-text-muted font-mono mr-1 hidden sm:inline opacity-60",children:v.slice(0,8)}),(0,r.jsx)("button",{onClick:()=>{P.tap(),null==g||g()},className:"p-2 rounded-md hover:bg-bg-hover transition-colors text-text-muted hover:text-text-secondary","aria-label":"Connect device",children:(0,r.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,r.jsx)("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),(0,r.jsx)("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),(0,r.jsx)("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),(0,r.jsx)("rect",{x:"14",y:"14",width:"3",height:"3"}),(0,r.jsx)("line",{x1:"21",y1:"14",x2:"21",y2:"14.01"}),(0,r.jsx)("line",{x1:"21",y1:"21",x2:"21",y2:"21.01"})]})})]})]}),E&&(0,r.jsx)("div",{className:"shrink-0 px-4 py-2 border-b border-error/20 text-error text-[12px] bg-error/5",children:E}),(0,r.jsx)(et,{messages:b,toolCalls:j,isStreaming:y,isLoadingHistory:N,isWatching:k,recentSessions:V,onSelectSession:null!=i?i:R,onRetry:I,queuedMessages:B,onForceSend:O,onEditQueued:z,onDeleteQueued:D}),(0,r.jsx)(er,{onSend:W,onStop:L,isStreaming:y,selectedModel:C,selectedMode:S,onModelChange:M,onModeChange:A})]})}function ea(e){let{status:t}=e;return"streaming"===t?(0,r.jsx)("span",{className:"shrink-0 w-2 h-2 rounded-full border-[1.5px] border-success border-t-transparent animate-spin"}):(0,r.jsx)("span",{className:"shrink-0 w-1.5 h-1.5 rounded-full bg-text-muted/40"})}function eo(e){let{open:t,onClose:s,currentSessionId:l,onSelectSession:o,onNewSession:i,activeStatuses:c={}}=e,[x,u]=(0,n.useState)([]),[m,h]=(0,n.useState)(!1),[p,f]=(0,n.useState)(!1),[b,j]=(0,n.useState)(null),[v,y]=(0,n.useState)(null),N=a(),k=(0,n.useCallback)(()=>(y(null),d("/api/sessions"+(p?"?all=true":"")).then(e=>e.json()).then(e=>u(e.sessions||[])).catch(()=>y("Failed to load sessions"))),[p]);(0,n.useEffect)(()=>{if(!t)return;let e=!1;return h(!0),j(null),k().finally(()=>{e||h(!1)}),()=>{e=!0}},[t,k]);let w=(e,t)=>{e.stopPropagation(),b===t?(N.error(),d("/api/sessions",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:t})}).then(()=>k()).catch(()=>y("Failed to delete session")).finally(()=>j(null))):(N.warn(),j(t))},E=e=>{e.stopPropagation(),j(null)};return(0,r.jsxs)(r.Fragment,{children:[t&&(0,r.jsx)("div",{className:"fixed inset-0 z-40 bg-black/60","aria-hidden":"true",onClick:s}),(0,r.jsxs)("div",{role:"dialog","aria-label":"Session history","aria-hidden":!t,className:"fixed top-0 left-0 z-50 h-full w-[280px] bg-bg-elevated border-r border-border transform transition-transform duration-150 flex flex-col ".concat(t?"translate-x-0":"-translate-x-full"),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between h-11 px-3 border-b border-border shrink-0",children:[(0,r.jsx)("span",{className:"text-[13px] font-medium text-text-secondary",children:"Sessions"}),(0,r.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,r.jsx)("button",{onClick:()=>{N.tap(),h(!0),k().finally(()=>h(!1))},disabled:m,"aria-label":"Refresh sessions",className:"p-1 rounded-md hover:bg-bg-hover text-text-muted hover:text-text-secondary transition-colors disabled:opacity-40",children:(0,r.jsx)(M,{size:14,className:m?"animate-spin":""})}),(0,r.jsx)("button",{onClick:s,"aria-label":"Close sidebar",className:"p-1 rounded-md hover:bg-bg-hover text-text-muted hover:text-text-secondary transition-colors",children:(0,r.jsx)(C,{size:14})})]})]}),(0,r.jsxs)("div",{className:"px-2 pt-2 pb-1 space-y-1 shrink-0",children:[(0,r.jsxs)("button",{onClick:()=>{i(),s()},className:"w-full flex items-center gap-2 px-2.5 py-1.5 rounded-md text-[12px] text-text-muted hover:text-text-secondary hover:bg-bg-hover transition-colors",children:[(0,r.jsx)(S,{}),"New session"]}),(0,r.jsxs)("button",{onClick:()=>{N.tap(),f(e=>!e)},"aria-pressed":p,className:"w-full flex items-center gap-2 px-2.5 py-1.5 rounded-md text-[12px] transition-colors ".concat(p?"text-text bg-bg-active":"text-text-muted hover:text-text-secondary hover:bg-bg-hover"),children:[(0,r.jsx)(D,{}),"All workspaces"]})]}),(0,r.jsxs)("div",{className:"overflow-y-auto flex-1 px-2 pb-2",children:[v&&(0,r.jsx)("div",{className:"mx-1 mb-2 px-2.5 py-2 rounded-md bg-error/10 text-error text-[11px]",children:v}),m?(0,r.jsx)("div",{className:"flex items-center gap-2 justify-center py-8 text-text-muted text-[12px]",children:(0,r.jsx)(B,{})}):0!==x.length||v?x.map(e=>{let t=c[e.id];return(0,r.jsxs)("div",{className:"relative mb-px",children:[(0,r.jsxs)("button",{onClick:()=>{N.select(),o(e.id),s()},"aria-current":e.id===l?"true":void 0,className:"group w-full text-left px-2.5 py-2 rounded-md transition-colors ".concat(e.id===l?"bg-bg-active text-text":"hover:bg-bg-hover text-text-secondary"),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5 flex-1 min-w-0 pr-5",children:[t&&(0,r.jsx)(ea,{status:t}),(0,r.jsx)("p",{className:"text-[12px] truncate",children:e.title})]}),(0,r.jsx)("span",{className:"text-[10px] text-text-muted shrink-0",children:g(e.updatedAt)})]}),p&&(0,r.jsx)("p",{className:"text-[10px] text-text-muted mt-0.5 font-mono truncate",children:e.workspace.split("/").pop()})]}),b===e.id?(0,r.jsxs)("div",{className:"absolute top-1 right-1 flex items-center gap-1",children:[(0,r.jsx)("button",{onClick:t=>w(t,e.id),className:"px-2 py-1 rounded text-[10px] font-medium bg-error/15 text-error hover:bg-error/25 transition-colors",children:"Delete"}),(0,r.jsx)("button",{onClick:E,"aria-label":"Cancel delete",className:"p-1 rounded text-text-muted hover:text-text-secondary hover:bg-bg-hover transition-colors",children:(0,r.jsx)(C,{size:10})})]}):(0,r.jsx)("button",{onClick:t=>w(t,e.id),"aria-label":"Delete session",className:"absolute top-1 right-1 p-1.5 rounded opacity-0 group-hover:opacity-100 hover:bg-bg-surface text-text-muted hover:text-error transition-all",children:(0,r.jsx)(R,{})})]},e.id)}):(0,r.jsx)("p",{className:"text-text-muted text-[12px] text-center py-8",children:"No sessions"})]})]})]})}var ei=s(2834);function ec(e){let{open:t,onClose:s}=e,[l,a]=(0,n.useState)(null),[o,i]=(0,n.useState)(null);return((0,n.useEffect)(()=>{if(!t)return;let e=!1;return d("/api/info").then(e=>e.json()).then(t=>{e||a(t)}).catch(()=>{e||i("Could not load network info")}),()=>{e=!0,a(null),i(null)}},[t]),t)?(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80",onClick:s,children:(0,r.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":"Connect device via QR code",className:"bg-bg-elevated border border-border rounded-xl p-6 max-w-xs w-full mx-4 text-center",onClick:e=>e.stopPropagation(),children:[(0,r.jsx)("p",{className:"text-[13px] font-medium text-text mb-1",children:"Connect device"}),(0,r.jsx)("p",{className:"text-[12px] text-text-muted mb-5",children:"Scan from any device on your network"}),l?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"bg-white rounded-lg p-3 inline-block mb-3",children:(0,r.jsx)(ei.h,{value:l.authUrl,size:180})}),(0,r.jsx)("p",{className:"font-mono text-[12px] text-text-secondary",children:l.url})]}):o?(0,r.jsx)("div",{className:"py-10 text-error text-[12px]",children:o}):(0,r.jsx)("div",{className:"py-10 text-text-muted text-[12px]",children:(0,r.jsx)(B,{className:"w-3.5 h-3.5"})}),(0,r.jsx)("button",{onClick:s,className:"mt-4 w-full py-1.5 rounded-lg text-[12px] text-text-muted hover:text-text-secondary transition-colors",children:"Close"})]})}):null}var ed=s(5932);function ex(e){return{id:x(),sessionId:null,label:e?"Loading...":"New chat",isStreaming:!1,initialSessionId:e}}function eu(){var e,t;let[s,l]=(0,n.useState)(()=>[ex()]),[o,i]=(0,n.useState)(()=>s[0].id),[c,d]=(0,n.useState)(!1),[x,m]=(0,n.useState)(!1),h=a(),p=(0,n.useRef)(!1);(0,n.useEffect)(()=>{p.current||(p.current=!0,u().then(e=>{0!==e.length&&l(t=>{let s=[...t],r=null;for(let t=0;t<e.length;t++){let n=e[t];if(s.some(e=>e.initialSessionId===n||e.sessionId===n))continue;let l=ex(n);0!==t||1!==s.length||s[0].sessionId||s[0].isStreaming?(s.push(l),r||(r=l.id)):(s[0]=l,r=l.id)}if(r){let e=r;setTimeout(()=>i(e),0)}return s})}))},[]);let f=(0,n.useMemo)(()=>{let e={};for(let t of s)t.sessionId&&(e[t.sessionId]=t.isStreaming?"streaming":"idle");return e},[s]),g=(0,n.useCallback)(()=>{h.tap();let e=s.find(e=>e.id===o);if(e&&!e.sessionId&&!e.isStreaming)return;let t=ex();l(e=>[...e,t]),i(t.id)},[h,s,o]),b=(0,n.useCallback)(e=>{let t=s.find(t=>t.sessionId===e);if(t)return void i(t.id);let r=ex(e),n=s.find(e=>e.id===o);!n||n.sessionId||n.isStreaming?l(e=>[...e,r]):l(e=>e.map(e=>e.id===o?r:e)),i(r.id)},[s,o]),j=(0,n.useCallback)((e,t)=>{l(s=>{let r=s.find(t=>t.id===e);return r&&r.label!==t?s.map(s=>s.id===e?{...s,label:t}:s):s})},[]),v=(0,n.useCallback)((e,t)=>{l(s=>{let r=s.find(t=>t.id===e);return r&&r.isStreaming!==t?s.map(s=>s.id===e?{...s,isStreaming:t}:s):s})},[]),y=(0,n.useCallback)((e,t)=>{l(s=>{let r=s.find(t=>t.id===e);return r&&r.sessionId!==t?s.map(s=>s.id===e?{...s,sessionId:t}:s):s})},[]),N=null!=(t=null==(e=s.find(e=>e.id===o))?void 0:e.sessionId)?t:null;return(0,r.jsxs)("div",{className:"h-dvh",children:[s.map(e=>(0,r.jsx)("div",{className:e.id===o?"h-full":"hidden",children:(0,r.jsx)(ed.ErrorBoundary,{fallback:"inline",children:(0,r.jsx)(el,{initialSessionId:e.initialSessionId,onLabelChange:t=>j(e.id,t),onStreamingChange:t=>v(e.id,t),onSessionIdChange:t=>y(e.id,t),onSelectSession:b,onOpenSidebar:()=>d(!0),onOpenQr:()=>m(!0)})})},e.id)),(0,r.jsx)(eo,{open:c,onClose:()=>d(!1),currentSessionId:N,onSelectSession:b,onNewSession:g,activeStatuses:f}),(0,r.jsx)(ec,{open:x,onClose:()=>m(!1)})]})}},2673:(e,t,s)=>{Promise.resolve().then(s.bind(s,1456)),Promise.resolve().then(s.bind(s,5932))},5932:(e,t,s)=>{"use strict";s.d(t,{ErrorBoundary:()=>l});var r=s(5155),n=s(2115);class l extends n.Component{static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error("Uncaught render error:",e,t.componentStack)}render(){return this.state.error?"inline"===this.props.fallback?(0,r.jsx)("div",{className:"h-full flex items-center justify-center px-6",children:(0,r.jsxs)("div",{className:"text-center max-w-sm",children:[(0,r.jsx)("p",{className:"text-[13px] font-medium text-text mb-2",children:"Something went wrong"}),(0,r.jsx)("p",{className:"text-[11px] text-text-muted mb-3 font-mono break-all",children:this.state.error.message}),(0,r.jsx)("button",{onClick:()=>this.setState({error:null}),className:"px-3 py-1 rounded-lg text-[12px] font-medium bg-bg-surface text-text border border-border hover:bg-bg-hover transition-colors",children:"Try again"})]})}):(0,r.jsx)("div",{className:"h-dvh flex items-center justify-center bg-[#0a0a0b] px-6",children:(0,r.jsxs)("div",{className:"text-center max-w-sm",children:[(0,r.jsx)("p",{className:"text-[14px] font-medium text-[#e8e8e8] mb-2",children:"Something went wrong"}),(0,r.jsx)("p",{className:"text-[12px] text-[#888] mb-4 font-mono break-all",children:this.state.error.message}),(0,r.jsx)("button",{onClick:()=>this.setState({error:null}),className:"px-4 py-1.5 rounded-lg text-[12px] font-medium bg-[#1c1c1c] text-[#e8e8e8] border border-[#2a2a2a] hover:bg-[#252525] transition-colors",children:"Try again"})]})}):this.props.children}constructor(...e){super(...e),this.state={error:null}}}}},e=>{e.O(0,[481,391,441,255,358],()=>e(e.s=2673)),_N_E=e.O()}]);