@polderlabs/bizar 4.8.0 → 5.0.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.
- package/bizar-dash/dist/assets/icons-CFqu2M-c.js +656 -0
- package/bizar-dash/dist/assets/icons-CFqu2M-c.js.map +1 -0
- package/bizar-dash/dist/assets/index-DmpSFPJY.js +9 -0
- package/bizar-dash/dist/assets/index-DmpSFPJY.js.map +1 -0
- package/bizar-dash/dist/assets/main-Dl8yY5_H.js +16 -0
- package/bizar-dash/dist/assets/main-Dl8yY5_H.js.map +1 -0
- package/bizar-dash/dist/assets/{main-DX_Jh8Wc.css → main-ZAfGKENE.css} +1 -1
- package/bizar-dash/dist/assets/markdown-DIquRulQ.js +29 -0
- package/bizar-dash/dist/assets/markdown-DIquRulQ.js.map +1 -0
- package/bizar-dash/dist/assets/mobile-C2gysFOZ.js +2 -0
- package/bizar-dash/dist/assets/mobile-C2gysFOZ.js.map +1 -0
- package/bizar-dash/dist/assets/mobile-DHXXbn1A.js +1 -0
- package/bizar-dash/dist/assets/{mobile-Chvf9u_B.js.map → mobile-DHXXbn1A.js.map} +1 -1
- package/bizar-dash/dist/assets/react-vendor-DZRUXSPQ.js +40 -0
- package/bizar-dash/dist/assets/react-vendor-DZRUXSPQ.js.map +1 -0
- package/bizar-dash/dist/index.html +6 -3
- package/bizar-dash/dist/mobile.html +5 -2
- package/bizar-dash/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -1
- package/bizar-dash/skills/eval/SKILL.md +237 -0
- package/bizar-dash/src/server/api.mjs +28 -0
- package/bizar-dash/src/server/auth.mjs +155 -1
- package/bizar-dash/src/server/eval-store.mjs +226 -0
- package/bizar-dash/src/server/eval.mjs +347 -0
- package/bizar-dash/src/server/memory-lightrag.mjs +109 -0
- package/bizar-dash/src/server/memory-store.mjs +121 -0
- package/bizar-dash/src/server/ocr.mjs +55 -0
- package/bizar-dash/src/server/otel.mjs +133 -0
- package/bizar-dash/src/server/plugins/registry.mjs +363 -0
- package/bizar-dash/src/server/plugins/sandbox.mjs +655 -0
- package/bizar-dash/src/server/plugins/store.mjs +659 -0
- package/bizar-dash/src/server/routes/chat.mjs +246 -170
- package/bizar-dash/src/server/routes/clipboard.mjs +173 -0
- package/bizar-dash/src/server/routes/eval.mjs +147 -0
- package/bizar-dash/src/server/routes/memory.mjs +46 -0
- package/bizar-dash/src/server/routes/ocr.mjs +182 -0
- package/bizar-dash/src/server/routes/opencode-sessions.mjs +82 -48
- package/bizar-dash/src/server/routes/plugins.mjs +220 -0
- package/bizar-dash/src/server/routes/users.mjs +84 -0
- package/bizar-dash/src/server/routes/voice.mjs +131 -0
- package/bizar-dash/src/server/routes/workspaces.mjs +204 -0
- package/bizar-dash/src/server/server.mjs +40 -0
- package/bizar-dash/src/server/voice-store.mjs +202 -0
- package/bizar-dash/src/server/voice-transcribe.mjs +72 -0
- package/bizar-dash/src/server/workspaces.mjs +626 -0
- package/bizar-dash/src/web/components/InviteDialog.tsx +205 -0
- package/bizar-dash/src/web/components/ScreenshotCapture.tsx +138 -0
- package/bizar-dash/src/web/components/ScreenshotOCR.tsx +42 -0
- package/bizar-dash/src/web/components/SettingsSearch.tsx +204 -89
- package/bizar-dash/src/web/components/VoiceNotesPanel.tsx +182 -0
- package/bizar-dash/src/web/components/VoiceRecorder.tsx +104 -0
- package/bizar-dash/src/web/components/WorkspaceSelector.tsx +158 -0
- package/bizar-dash/src/web/lib/search.ts +115 -0
- package/bizar-dash/src/web/mobile/views/MobileSettings.tsx +10 -35
- package/bizar-dash/src/web/mobile/views/QrCodePanel.tsx +69 -0
- package/bizar-dash/src/web/styles/memory.css +166 -1
- package/bizar-dash/src/web/styles/settings.css +80 -0
- package/bizar-dash/src/web/views/Memory.tsx +22 -2
- package/bizar-dash/src/web/views/Settings.tsx +99 -0
- package/bizar-dash/src/web/views/Workspace.tsx +294 -0
- package/bizar-dash/src/web/views/memory/FromScreenshotPanel.tsx +23 -0
- package/bizar-dash/src/web/views/memory/MemoryGraphLegend.tsx +29 -0
- package/bizar-dash/src/web/views/memory/MemoryGraphPanel.tsx +192 -0
- package/bizar-dash/src/web/views/memory/MemoryGraphView.tsx +336 -0
- package/bizar-dash/src/web/views/memory/VaultFromClipboardPanel.tsx +101 -0
- package/bizar-dash/src/web/views/settings/WorkspacesSection.tsx +189 -0
- package/bizar-dash/tests/bundle-analysis.test.mjs +73 -0
- package/bizar-dash/tests/clipboard.test.mjs +147 -0
- package/bizar-dash/tests/components/screenshot-ocr.test.tsx +75 -0
- package/bizar-dash/tests/components/settings-search.test.tsx +180 -0
- package/bizar-dash/tests/components/workspace-selector.test.tsx +73 -0
- package/bizar-dash/tests/deploy-templates.test.mjs +100 -0
- package/bizar-dash/tests/docker-build.test.mjs +96 -0
- package/bizar-dash/tests/eval/fixtures.test.mjs +141 -0
- package/bizar-dash/tests/eval/report.test.mjs +284 -0
- package/bizar-dash/tests/eval/runner.test.mjs +471 -0
- package/bizar-dash/tests/lib/search-fuzzy.test.ts +149 -0
- package/bizar-dash/tests/memory-graph-view.test.tsx +69 -0
- package/bizar-dash/tests/memory-graph.test.mjs +95 -0
- package/bizar-dash/tests/ocr.test.mjs +87 -0
- package/bizar-dash/tests/otel.test.mjs +188 -0
- package/bizar-dash/tests/plugins-registry.test.mjs +387 -0
- package/bizar-dash/tests/plugins-sandbox.test.mjs +374 -0
- package/bizar-dash/tests/plugins-store.test.mjs +455 -0
- package/bizar-dash/tests/users.test.mjs +108 -0
- package/bizar-dash/tests/voice-recorder.test.tsx +95 -0
- package/bizar-dash/tests/voice-store.test.mjs +148 -0
- package/bizar-dash/tests/voice-transcribe.test.mjs +87 -0
- package/bizar-dash/tests/workspaces.test.mjs +527 -0
- package/cli/bin.mjs +72 -2
- package/cli/commands/clip.mjs +146 -0
- package/cli/commands/dash.mjs +6 -0
- package/cli/commands/deploy/cloudflare.mjs +250 -0
- package/cli/commands/deploy/docker.mjs +221 -0
- package/cli/commands/deploy/fly.mjs +161 -0
- package/cli/commands/deploy/vercel.mjs +225 -0
- package/cli/commands/deploy.mjs +240 -0
- package/cli/commands/eval.mjs +378 -0
- package/cli/commands/marketplace.mjs +64 -0
- package/cli/commands/ocr.mjs +165 -0
- package/cli/commands/plugin.mjs +358 -0
- package/cli/commands/voice.mjs +211 -0
- package/cli/commands/workspace.mjs +247 -0
- package/package.json +12 -2
- package/templates/deploy/cloudflare/README.md +32 -0
- package/templates/deploy/cloudflare/functions-index.template.js +15 -0
- package/templates/deploy/cloudflare/wrangler.toml.template +9 -0
- package/templates/deploy/docker/.env.template +16 -0
- package/templates/deploy/docker/README.md +58 -0
- package/templates/deploy/docker/docker-compose.template.yml +23 -0
- package/templates/deploy/fly/README.md +35 -0
- package/templates/deploy/fly/fly.toml.template +28 -0
- package/templates/deploy/vercel/README.md +29 -0
- package/templates/deploy/vercel/api-index.template.js +18 -0
- package/templates/deploy/vercel/vercel.json.template +16 -0
- package/templates/eval-fixtures/README.md +58 -0
- package/templates/eval-fixtures/code-search-basic.json +28 -0
- package/templates/eval-fixtures/latency-bounds.json +16 -0
- package/templates/eval-fixtures/regression-suite.json +79 -0
- package/templates/eval-fixtures/response-format.json +30 -0
- package/templates/eval-fixtures/tool-call-correctness.json +24 -0
- package/templates/plugin-template/README.md +121 -0
- package/templates/plugin-template/index.js +66 -0
- package/templates/plugin-template/plugin.json +42 -0
- package/templates/plugin-template/tests/plugin.test.js +83 -0
- package/bizar-dash/dist/assets/main-DHZmbnxQ.js +0 -361
- package/bizar-dash/dist/assets/main-DHZmbnxQ.js.map +0 -1
- package/bizar-dash/dist/assets/mobile-BK8-ythT.js +0 -351
- package/bizar-dash/dist/assets/mobile-BK8-ythT.js.map +0 -1
- package/bizar-dash/dist/assets/mobile-Chvf9u_B.js +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-DmpSFPJY.js","assets/react-vendor-DZRUXSPQ.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
var Pt=Object.defineProperty;var Ot=(t,s,i)=>s in t?Pt(t,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[s]=i;var ne=(t,s,i)=>Ot(t,typeof s!="symbol"?s+"":s,i);import{r as a,j as e,a as Bt}from"./react-vendor-DZRUXSPQ.js";import{X as ve,T as Ut,C as Ft,s as _t,I as qt,b as We,d as Le,b0 as Wt,aI as Ht,b1 as Vt,b2 as Kt,ax as Yt,R as de,b3 as Gt,z as Se,B as Ce,b4 as Ge,i as ze,v as ht,q as Qe,b5 as Qt,a0 as Re,ai as Jt,g as Ue,p as le,a1 as Xt,E as Zt,M as ge,U as He,K as es,Q as ts,_ as bt,n as we,ay as ss,l as Fe,D as pt,t as je,k as _e,aS as ft,e as Je,a3 as Xe,b6 as ns,S as De,o as Ze,ap as as,aq as is,ar as ls,b7 as et,ae as os,b8 as cs}from"./icons-CFqu2M-c.js";import{M as rs,r as ds}from"./markdown-DIquRulQ.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))c(o);new MutationObserver(o=>{for(const d of o)if(d.type==="childList")for(const r of d.addedNodes)r.tagName==="LINK"&&r.rel==="modulepreload"&&c(r)}).observe(document,{childList:!0,subtree:!0});function i(o){const d={};return o.integrity&&(d.integrity=o.integrity),o.referrerPolicy&&(d.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?d.credentials="include":o.crossOrigin==="anonymous"?d.credentials="omit":d.credentials="same-origin",d}function c(o){if(o.ep)return;o.ep=!0;const d=i(o);fetch(o.href,d)}})();function Ve(...t){return t.filter(Boolean).join(" ")}function ke(t){if(!t&&t!==0)return"";const s=typeof t=="number"?t:new Date(t).getTime();if(Number.isNaN(s))return"";const i=Date.now()-s;return i<0||i<6e4?"just now":i<36e5?`${Math.floor(i/6e4)}m ago`:i<864e5?`${Math.floor(i/36e5)}h ago`:i<7*864e5?`${Math.floor(i/864e5)}d ago`:new Date(s).toLocaleDateString()}function ms(t){if(!t)return"";const s=typeof t=="number"?new Date(t):new Date(t);return Number.isNaN(s.getTime())?"":s.toLocaleString()}function Un(t,s=160){return t?t.length>s?t.slice(0,s)+"…":t:""}const us={low:"var(--text-dim)",normal:"var(--info)",high:"var(--error)"},$e="bizar-auth-token",tt="bizar-loopback-trusted";class qe extends Error{constructor(i,c,o){super(i);ne(this,"status");ne(this,"data");this.name="ApiError",this.status=c,this.data=o}}class hs{constructor(){ne(this,"base","/api")}getToken(){try{return localStorage.getItem($e)||""}catch{return""}}setToken(s){try{s?localStorage.setItem($e,s):localStorage.removeItem($e)}catch{}}pickupTokenFromUrl(){try{const s=new URLSearchParams(window.location.search),i=s.get("token");if(!i)return!1;this.setToken(i),s.delete("token");const c=s.toString(),o=c?`${window.location.pathname}?${c}`:window.location.pathname;return history.replaceState(null,"",o),!0}catch{return!1}}urlWithToken(s){const i=this.base+s,c=this.getToken();if(!c)return i;const o=i.includes("?")?"&":"?";return`${i}${o}token=${encodeURIComponent(c)}`}async probeAuthStatus(){try{const s=await this.get("/auth/status");try{localStorage.setItem(tt,s.loopback?"1":"0")}catch{}return s}catch{return{required:!1,loopback:!0,peer:""}}}isLoopbackTrusted(){try{return localStorage.getItem(tt)!=="0"}catch{return!0}}async get(s,i){return this.req("GET",s,void 0,i)}async post(s,i,c){return this.req("POST",s,i,c)}async put(s,i,c){return this.req("PUT",s,i,c)}async patch(s,i,c){return this.req("PATCH",s,i,c)}async del(s,i){return this.req("DELETE",s,void 0,i)}async req(s,i,c,o){const d={"Content-Type":"application/json"},r=this.getToken();r&&(d.Authorization=`Bearer ${r}`);const l={method:s,headers:d};c!=null&&(l.body=typeof c=="string"?c:JSON.stringify(c)),o&&(l.signal=o);const m=await fetch(this.base+i,l);if((m.headers.get("content-type")||"").includes("application/json")){const f=await m.json();if(!m.ok){const v=(f&&typeof f=="object"&&"message"in f?f.message:void 0)||`${s} ${i}: ${m.status}`;throw new qe(v,m.status,f)}return f}const n=await m.text();if(!m.ok)throw new qe(`${s} ${i}: ${m.status} — ${n.slice(0,200)}`,m.status,n);try{return JSON.parse(n)}catch{return n}}}const E=new hs;E.pickupTokenFromUrl();async function bs(t){return t}const xt=a.createContext(null),ps=["button:not([disabled])","[href]","input:not([disabled])","select:not([disabled])","textarea:not([disabled])",'[tabindex]:not([tabindex="-1"])'].join(", ");function fs(){const t=a.useContext(xt);return t||{open:()=>"",close:()=>{},isModalOpen:!1}}function Fn({children:t}){const[s,i]=a.useState([]),c=a.useCallback(d=>{i(r=>{if(!d)return r.slice(0,-1);const l=r.findIndex(m=>m.id===d);return l===-1||l!==r.length-1?r:r.slice(0,-1)})},[]),o=a.useCallback(d=>{const r=`m${Math.random().toString(36).slice(2,9)}`;return i(l=>[...l,{...d,id:r}]),r},[]);return a.useEffect(()=>{if(s.length===0)return;const d=r=>{r.key==="Escape"&&(r.stopPropagation(),c())};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[s.length,c]),e.jsxs(xt.Provider,{value:{open:o,close:c,isModalOpen:s.length>0},children:[t,typeof document<"u"&&Bt.createPortal(e.jsx("div",{className:"modal-stack","aria-hidden":s.length===0,children:s.map((d,r)=>e.jsx(xs,{modal:d,onClose:()=>{var l;(l=d.onClose)==null||l.call(d),c(d.id)},depth:r},d.id))}),document.body)]})}function xs({modal:t,onClose:s,depth:i}){const c=a.useRef(null),o=a.useRef(null),d=a.useId(),r=()=>{const l=c.current;return l?Array.from(l.querySelectorAll(ps)).filter(m=>!m.hasAttribute("disabled")&&m.tabIndex!==-1):[]};return a.useEffect(()=>{var x;o.current=document.activeElement instanceof HTMLElement?document.activeElement:null,(x=r()[0]??c.current)==null||x.focus();const m=n=>{var b,N,g;if(n.key!=="Tab")return;const f=r();if(f.length===0){n.preventDefault(),(b=c.current)==null||b.focus();return}const v=f[0],p=f[f.length-1],h=document.activeElement instanceof HTMLElement?document.activeElement:null;if(n.shiftKey){(!h||h===v||!((N=c.current)!=null&&N.contains(h)))&&(n.preventDefault(),p.focus());return}(!h||h===p||!((g=c.current)!=null&&g.contains(h)))&&(n.preventDefault(),v.focus())};return document.addEventListener("keydown",m),()=>{document.removeEventListener("keydown",m);const n=o.current;n&&n.isConnected&&n.focus()}},[]),e.jsx("div",{className:"modal-backdrop",onClick:l=>{l.stopPropagation(),l.target===l.currentTarget&&s()},style:i>0?{background:"rgba(0,0,0,0.4)"}:void 0,children:e.jsxs("div",{ref:c,className:"modal",role:"dialog","aria-modal":"true","aria-labelledby":t.title?d:void 0,tabIndex:-1,onClick:l=>l.stopPropagation(),style:t.width?{maxWidth:t.width}:void 0,children:[t.title&&e.jsxs("header",{className:"modal-header",children:[e.jsx("h2",{id:d,className:"modal-title",children:t.title}),e.jsx("button",{type:"button",className:"icon-btn","aria-label":"Close",onClick:s,children:e.jsx(ve,{size:16})})]}),e.jsx("div",{className:"modal-body",children:t.children}),t.footer&&e.jsx("footer",{className:"modal-footer",children:t.footer})]})})}const Ne=a.forwardRef(function({variant:s="secondary",size:i="md",iconOnly:c=!1,loading:o=!1,disabled:d,className:r,children:l,...m},x){return e.jsxs("button",{ref:x,type:m.type??"button",disabled:d||o,className:Ve("btn",`btn-${s}`,`btn-size-${i}`,c&&"btn-icon",o&&"btn-loading",r),...m,children:[o?e.jsx("span",{className:"btn-spinner","aria-hidden":!0}):null,l]})}),gt=a.createContext(null);function gs(){const t=a.useContext(gt);return t||{show:()=>{},info:()=>{},success:()=>{},error:()=>{},warning:()=>{},dismiss:()=>{},toasts:[]}}const js={info:qt,success:_t,error:Ft,warning:Ut};function _n({children:t}){const[s,i]=a.useState([]),c=a.useRef(1),o=a.useRef(new Map),d=a.useCallback(m=>{i(n=>n.filter(f=>f.id!==m));const x=o.current.get(m);x&&(clearTimeout(x),o.current.delete(m))},[]),r=a.useCallback((m,x="info",n=4e3)=>{const f=c.current++;if(i(v=>[...v,{id:f,kind:x,message:m}]),n>0){const v=setTimeout(()=>d(f),n);o.current.set(f,v)}},[d]);a.useEffect(()=>()=>{for(const m of o.current.values())clearTimeout(m);o.current.clear()},[]);const l=a.useMemo(()=>({show:r,info:(m,x)=>r(m,"info",x),success:(m,x)=>r(m,"success",x),error:(m,x)=>r(m,"error",x),warning:(m,x)=>r(m,"warning",x),dismiss:d,toasts:s}),[r,d,s]);return e.jsxs(gt.Provider,{value:l,children:[t,e.jsx(vs,{toasts:s,onDismiss:d})]})}function vs({toasts:t,onDismiss:s}){return e.jsx("div",{className:"toast-stack","aria-live":"polite",children:t.map(i=>e.jsx(ys,{toast:i,onDismiss:s},i.id))})}function ys({toast:t,onDismiss:s}){const i=js[t.kind];return e.jsxs("div",{className:`toast toast-${t.kind}`,role:"alert","aria-live":"assertive","aria-atomic":"true",children:[e.jsx(i,{size:16,className:"toast-icon"}),e.jsx("span",{className:"toast-message",children:t.message}),e.jsx("button",{type:"button",className:"toast-close","aria-label":"Dismiss",onClick:()=>s(t.id),children:e.jsx(ve,{size:14})})]})}function Ns(){if(typeof location>"u")return"ws://localhost/ws";const t=`${location.protocol==="https:"?"wss":"ws"}://${location.host}/ws`;let s="";try{s=localStorage.getItem($e)||""}catch{}return s?`${t}?token=${encodeURIComponent(s)}`:t}class jt{constructor(s){ne(this,"urlOverride");ne(this,"handlers",new Set);ne(this,"statusHandlers",new Set);ne(this,"ws",null);ne(this,"reconnectDelay",1e3);ne(this,"maxReconnectDelay",15e3);ne(this,"reconnectTimer",null);ne(this,"_status","connecting");ne(this,"pingTimer",null);ne(this,"closed",!1);this.urlOverride=s,this.connect()}on(s){return this.handlers.add(s),()=>{this.handlers.delete(s)}}onStatus(s){return this.statusHandlers.add(s),s(this._status),()=>{this.statusHandlers.delete(s)}}get status(){return this._status}send(s){return this.ws&&this.ws.readyState===WebSocket.OPEN?(this.ws.send(JSON.stringify(s)),!0):!1}close(){var s;this.closed=!0,this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.reconnectTimer=null,this.pingTimer&&clearInterval(this.pingTimer),this.pingTimer=null;try{(s=this.ws)==null||s.close()}catch{}this.ws=null,this.setStatus("disconnected")}connect(){if(this.closed)return;this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.setStatus("connecting");const s=this.urlOverride??Ns();let i;try{i=new WebSocket(s),this.ws=i}catch(c){console.warn("[ws] construct failed:",c),this.scheduleReconnect();return}i.addEventListener("open",()=>{this.ws!==i||this.closed||(this.reconnectDelay=1e3,this.setStatus("connected"),this.pingTimer&&clearInterval(this.pingTimer),this.pingTimer=setInterval(()=>{this._status==="connected"&&this.send({type:"ping"})},3e4))}),i.addEventListener("close",()=>{this.ws===i&&(this.ws=null,this.setStatus("disconnected"),this.pingTimer&&(clearInterval(this.pingTimer),this.pingTimer=null),this.closed||this.scheduleReconnect())}),i.addEventListener("error",()=>{this.ws===i&&console.warn("[ws] error")}),i.addEventListener("message",c=>{let o;try{o=JSON.parse(c.data)}catch{console.warn("[ws] bad message");return}for(const d of this.handlers)try{d(o)}catch(r){console.error("[ws] handler error:",r)}})}scheduleReconnect(){this.closed||this.reconnectTimer||(this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.connect()},this.reconnectDelay),this.reconnectDelay=Math.min(this.reconnectDelay*1.6,this.maxReconnectDelay))}setStatus(s){this._status=s;for(const i of this.statusHandlers)try{i(s)}catch(c){console.error("[ws] status handler error:",c)}}}const ks=Object.freeze(Object.defineProperty({__proto__:null,Ws:jt},Symbol.toStringTag,{value:"Module"}));function Me(t){const s=typeof t=="string"?t:t.mode,i=s==="system"?typeof window<"u"&&window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark":s==="light"?"light":"dark";return typeof document<"u"&&(i==="light"?document.documentElement.setAttribute("data-theme","light"):document.documentElement.removeAttribute("data-theme")),i}function Ee(t){if(typeof document>"u")return;const s=document.documentElement;s.style.setProperty("--accent",t.accent),s.style.setProperty("--success",t.success),s.style.setProperty("--warning",t.warning),s.style.setProperty("--error",t.error),s.style.setProperty("--info",t.info),s.style.setProperty("--accent-bg",st(t.accent,.12)),s.style.setProperty("--accent-border",st(t.accent,.4)),t.fontFamily&&s.style.setProperty("--font-sans",`'${t.fontFamily}', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif`),t.fontSize&&s.style.setProperty("--base-font-size",`${t.fontSize}px`),s.dataset.compactMode=t.compactMode?"true":"false",s.dataset.animations=t.animations?"true":"false"}function st(t,s){const i=/^#?([0-9a-f]{6})$/i.exec(t||"");if(!i)return`rgba(139, 92, 246, ${s})`;const c=parseInt(i[1],16),o=c>>16&255,d=c>>8&255,r=c&255;return`rgba(${o}, ${d}, ${r}, ${s})`}function vt({size:t="md",className:s,label:i}){return e.jsx("span",{className:Ve("spinner",`spinner-${t}`,s),role:"status","aria-label":i||"Loading"})}function ws({items:t,renderItem:s,itemHeight:i=80,height:c=400,overscan:o=5,className:d}){const[r,l]=a.useState(0),m=a.useRef(null),x=a.useMemo(()=>{const p=Math.max(0,Math.floor(r/i)-o),h=Math.min(t.length,Math.ceil((r+c)/i)+o);return{start:p,end:h}},[r,i,c,o,t.length]),n=t.length*i,f=x.start*i,v=t.slice(x.start,x.end);return e.jsx("div",{ref:m,onScroll:p=>l(p.currentTarget.scrollTop),style:{height:c,overflowY:"auto"},className:d,children:e.jsx("div",{style:{height:n,position:"relative"},children:e.jsx("div",{style:{transform:`translateY(${f}px)`},children:v.map((p,h)=>e.jsx("div",{style:{height:i},children:s(p,x.start+h)},x.start+h))})})})}function Ss({activeProject:t,sessionCount:s,sessionsOpen:i,infoOpen:c,onToggleSessions:o,onToggleInfo:d,onOpenOverview:r}){return e.jsxs("header",{className:"chat-topbar",children:[e.jsxs("button",{type:"button",className:"chat-topbar-project",onClick:r,children:[e.jsx(We,{size:14}),e.jsx("span",{className:"chat-topbar-project-name",children:(t==null?void 0:t.name)??"No project"}),e.jsx(Le,{size:12})]}),e.jsx("div",{className:"chat-topbar-spacer"}),e.jsxs("button",{type:"button",className:`chat-topbar-btn ${i?"active":""}`,onClick:o,"aria-pressed":i,children:["Sessions (",s,")"]}),e.jsx("button",{type:"button",className:`chat-topbar-btn ${c?"active":""}`,onClick:d,"aria-pressed":c,children:"Info"})]})}function Cs({icon:t,title:s,message:i,action:c}){return e.jsxs("div",{className:"chat-empty-state",children:[t&&e.jsx("div",{className:"chat-empty-state-icon",children:t}),e.jsx("h2",{className:"chat-empty-state-title",children:s}),e.jsx("p",{className:"chat-empty-state-message",children:i}),c&&e.jsx("div",{className:"chat-empty-state-action",children:c})]})}function Ts({count:t=3}){return e.jsx("div",{className:"chat-loading-skeleton","aria-label":"Loading messages",children:Array.from({length:t}).map((s,i)=>e.jsxs("div",{className:"chat-loading-skeleton-bubble",children:[e.jsx("div",{className:"chat-loading-skeleton-meta"}),e.jsx("div",{className:"chat-loading-skeleton-line"}),e.jsx("div",{className:"chat-loading-skeleton-line short"})]},i))})}function Is({projectName:t,onPickSuggestion:s}){const i=[{icon:e.jsx(Wt,{size:16}),title:t?`Explain ${t}`:"Explain this project",preview:"Give me a tour of the codebase, highlight the architecture, and call out any anti-patterns or hotspots.",prompt:t?`Explain the ${t} project. Give me a tour of the codebase, highlight the architecture, and call out any anti-patterns or hotspots.`:"Explain the current project. Give me a tour of the codebase, highlight the architecture, and call out any anti-patterns or hotspots."},{icon:e.jsx(Ht,{size:16}),title:"Summarize recent sessions",preview:"Read my last 5 chat sessions and give me a 3-bullet summary of what I worked on and what got stuck.",prompt:"Read my last 5 chat sessions and give me a 3-bullet summary of what I worked on and what got stuck."},{icon:e.jsx(Vt,{size:16}),title:"Suggest a refactor",preview:"Look for the largest, most painful files in this project and propose a concrete refactor for the worst one.",prompt:"Look for the largest, most painful files in this project and propose a concrete refactor for the worst one."},{icon:e.jsx(Kt,{size:16}),title:"Find visual regressions",preview:"Open the dashboard, screenshot the Chat tab, and flag any layout problems or anti-patterns you see.",prompt:"Open the dashboard, screenshot the Chat tab, and flag any layout problems or anti-patterns you see."}];return e.jsx("div",{className:"chat-suggestions",children:i.map((c,o)=>e.jsxs("button",{type:"button",className:"chat-suggestion",onClick:()=>s(c.prompt),children:[e.jsxs("div",{className:"chat-suggestion-title",children:[c.icon,e.jsx("span",{children:c.title})]}),e.jsx("div",{className:"chat-suggestion-preview",children:c.preview})]},o))})}function nt({variant:t,projectName:s,onPickSuggestion:i}){if(t==="no-project")return e.jsxs("div",{className:"chat-welcome",children:[e.jsx("h1",{className:"chat-welcome-h1",children:e.jsx("span",{className:"chat-greeting-hello",children:"No project selected."})}),e.jsx("p",{className:"chat-welcome-subtitle",children:"Pick a project in Overview to scope chat sessions."})]});const c=s||"there";return e.jsxs("div",{className:"chat-welcome",children:[e.jsxs("h1",{className:"chat-welcome-h1",children:[e.jsx("span",{className:"chat-greeting-hello",children:"Hello, "}),e.jsxs("span",{className:"chat-greeting-name",children:[c,"."]})]}),e.jsx("p",{className:"chat-welcome-subtitle",children:"How can I help you today?"}),e.jsx(Is,{projectName:s,onPickSuggestion:i})]})}function Es({message:t,pinned:s,onCopy:i,onDelete:c,onTogglePin:o,onRegenerate:d}){const r=(t.role||"assistant").toLowerCase(),l=t.ts?ms(t.ts):"",m=t.content||t.message||"",x=r==="user";return e.jsxs("article",{className:`chat-message ${x?"chat-message-user":"chat-message-assistant"} ${s?"chat-message-pinned":""}`,children:[e.jsxs("header",{className:"chat-message-meta",children:[e.jsx("span",{className:"chat-message-role",children:r}),t.agent&&e.jsxs("span",{className:"chat-message-agent",children:["@",t.agent]}),l&&e.jsx("time",{className:"chat-message-time",children:l}),s&&e.jsx("span",{className:"chat-message-pin",children:"pinned"}),e.jsxs("div",{className:"chat-message-actions",children:[e.jsx("button",{type:"button",className:"chat-msg-action-btn",onClick:i,title:"Copy","aria-label":"Copy",children:e.jsx(Yt,{size:12})}),!x&&e.jsx("button",{type:"button",className:"chat-msg-action-btn",onClick:d,title:"Regenerate","aria-label":"Regenerate",children:e.jsx(de,{size:12})}),e.jsx("button",{type:"button",className:"chat-msg-action-btn",onClick:o,title:"Pin","aria-label":"Pin",children:e.jsx(Gt,{size:12})}),e.jsx("button",{type:"button",className:"chat-msg-action-btn chat-msg-action-btn-danger",onClick:c,title:"Delete","aria-label":"Delete",children:e.jsx(Se,{size:12})})]})]}),e.jsx("div",{className:"chat-message-content markdown-body",children:e.jsx(rs,{remarkPlugins:[ds],children:m})})]})}function As({messages:t,loading:s,activeProject:i,sessionId:c,pinned:o,activeSource:d,onPickSuggestion:r,onCopy:l,onDelete:m,onTogglePin:x,onRegenerate:n}){const f=a.useRef(null);a.useEffect(()=>{const p=f.current;if(!p)return;let h=p.parentElement,b=!1;for(;h;){if(h.classList.contains("chat-thread-scroll")){b=!0;break}h=h.parentElement}b||(p.scrollTop=p.scrollHeight)},[t]);const v=d==="opencode"?"opencode":"bizar";return s?e.jsx("div",{className:"chat-thread legacy",ref:f,"data-stream":v,children:e.jsx(Ts,{count:3})}):i?t.length===0?e.jsx("div",{className:"chat-thread legacy",ref:f,"data-stream":v,children:e.jsx(nt,{variant:"empty",projectName:i.name,onPickSuggestion:r})}):e.jsx("div",{className:"chat-thread legacy",ref:f,children:e.jsx(ws,{items:t,itemHeight:120,height:800,className:"chat-thread-virtual",renderItem:(p,h)=>e.jsx(Es,{message:p,pinned:o.has(h),onCopy:()=>l(p),onDelete:()=>m(h),onTogglePin:()=>x(h),onRegenerate:()=>n(String(p.ts??h))})})}):e.jsx("div",{className:"chat-thread legacy",ref:f,"data-stream":v,children:e.jsx(nt,{variant:"no-project",projectName:"",onPickSuggestion:r})})}function $s({agent:t,setAgent:s,agents:i}){const[c,o]=a.useState(!1),d=a.useRef(null);a.useEffect(()=>{if(!c)return;const m=x=>{d.current&&!d.current.contains(x.target)&&o(!1)};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[c]);const r=t||"no agent",l=r.startsWith("@")?r.slice(1):r;return e.jsxs("div",{className:"chat-agent-chip",ref:d,children:[e.jsxs("button",{type:"button",className:"chat-agent-chip-btn",onClick:()=>o(m=>!m),"aria-haspopup":"listbox","aria-expanded":c,children:[e.jsx(Ce,{size:14}),e.jsx("span",{children:l}),e.jsx(Le,{size:12,className:c?"rotated":""})]}),c&&e.jsxs("div",{className:"chat-agent-chip-menu",role:"listbox",children:[e.jsx("button",{type:"button",role:"option","aria-selected":!t,onClick:()=>{s(""),o(!1)},children:e.jsx("span",{children:"no agent"})}),i.map(m=>e.jsx("button",{type:"button",role:"option","aria-selected":t===m.name,onClick:()=>{s(m.name),o(!1)},children:e.jsxs("span",{children:["@",m.name]})},m.name))]})]})}function zs(t,s,i=240){a.useLayoutEffect(()=>{const c=t.current;if(!c)return;c.style.height="auto";const o=Math.min(c.scrollHeight,i);c.style.height=`${o}px`,c.style.overflowY=c.scrollHeight>i?"auto":"hidden"},[t,s,i])}function Rs({agent:t,setAgent:s,model:i,setModel:c,text:o,setText:d,sending:r,onSend:l,attachments:m,setAttachments:x,suggestions:n,onPickSuggestion:f,agents:v,onAttach:p}){const h=a.useRef(null),b=a.useRef(null);zs(h,o,200);const N=u=>{if(u.key==="Enter"&&(u.metaKey||u.ctrlKey))u.preventDefault(),l();else if(u.key==="Enter"&&!u.shiftKey)u.preventDefault(),l();else if(u.key==="Tab"&&n.length){u.preventDefault();const S=n[0].cmd.split(" ")[0];d(`${S} `)}},g=u=>{const S=u.target.files;if(!S)return;const C=[];for(let _=0;_<S.length;_++)C.push(S[_].name);x(_=>[..._,...C]),u.target.value=""};return e.jsxs("div",{className:"chat-composer",children:[n.length>0&&e.jsx("div",{className:"chat-composer-suggestions",children:n.map(u=>e.jsxs("button",{type:"button",className:"chat-composer-suggestion",onClick:()=>{var C;const S=u.cmd.split(" ")[0];d(`${S} `),(C=h.current)==null||C.focus()},children:[e.jsx("span",{className:"mono",children:u.cmd}),e.jsx("span",{children:u.desc})]},u.cmd))}),m.length>0&&e.jsx("div",{className:"chat-composer-attachments",children:m.map((u,S)=>e.jsxs("span",{className:"chat-composer-attachment-tag",children:[e.jsx(Ge,{size:10})," ",u,e.jsx("button",{type:"button",className:"chat-composer-attachment-remove",onClick:()=>x(C=>C.filter((_,P)=>P!==S)),"aria-label":`Remove ${u}`,children:e.jsx(ve,{size:10})})]},S))}),e.jsxs("div",{className:"chat-composer-input",children:[e.jsx($s,{agent:t,setAgent:s,agents:v}),e.jsx("textarea",{ref:h,className:"chat-composer-textarea",placeholder:r?"Sending…":"Send a message…",rows:1,value:o,onChange:u=>d(u.target.value),onKeyDown:N,disabled:r,"aria-label":"Message"}),e.jsx("input",{ref:b,type:"file",multiple:!0,style:{display:"none"},onChange:g,"aria-label":"Attach files",tabIndex:-1}),e.jsx("button",{type:"button",className:"chat-attach-btn",onClick:p,title:"Attach files","aria-label":"Attach files",children:e.jsx(Ge,{size:14})}),e.jsx("button",{type:"button",className:"chat-attach-btn",onClick:async()=>{if(!o.trim())return;const u=await bs(o);u!==o&&d(u)},title:"Enhance prompt with AI","aria-label":"Enhance prompt",children:e.jsx(ze,{size:14})}),e.jsx("button",{type:"button",className:"chat-send-btn",onClick:l,disabled:r||!o.trim(),title:"Send (Enter)","aria-label":"Send message",children:e.jsx(ht,{size:16})})]})]})}const Ds="modulepreload",Ms=function(t){return"/"+t},at={},yt=function(s,i,c){let o=Promise.resolve();if(i&&i.length>0){document.getElementsByTagName("link");const r=document.querySelector("meta[property=csp-nonce]"),l=(r==null?void 0:r.nonce)||(r==null?void 0:r.getAttribute("nonce"));o=Promise.allSettled(i.map(m=>{if(m=Ms(m),m in at)return;at[m]=!0;const x=m.endsWith(".css"),n=x?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${m}"]${n}`))return;const f=document.createElement("link");if(f.rel=x?"stylesheet":Ds,x||(f.as="script"),f.crossOrigin="",f.href=m,l&&f.setAttribute("nonce",l),document.head.appendChild(f),x)return new Promise((v,p)=>{f.addEventListener("load",v),f.addEventListener("error",()=>p(new Error(`Unable to preload CSS for ${m}`)))})}))}function d(r){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=r,window.dispatchEvent(l),!l.defaultPrevented)throw r}return o.then(r=>{for(const l of r||[])l.status==="rejected"&&d(l.reason);return s().catch(d)})};function Ls(t,s,i){const[c,o]=a.useState([]),[d,r]=a.useState([]),[l,m]=a.useState(""),[x,n]=a.useState(!0),[f,v]=a.useState({create:!1,send:!1,rename:!1,delete:!1}),[p,h]=a.useState([]),[b,N]=a.useState([]),[g,u]=a.useState(null),[S,C]=a.useState(null),[_,P]=a.useState(null),[T,L]=a.useState({}),[j,w]=a.useState(!0),[k,R]=a.useState(0),[B,z]=a.useState(new Set),[Y,oe]=a.useState(new Set),Q=a.useRef(null),K=a.useRef(null),Z=a.useRef(null),Te=a.useRef(0),ee=a.useRef(null),ue=a.useRef(null),me=a.useRef(!1),be=a.useCallback(y=>{y&&N(A=>{if(y.id&&A.some(D=>D.id===y.id))return A;const $=A.findIndex(D=>typeof D.id=="string"&&D.id.startsWith("msg_")&&D.role===y.role&&(D.content||"")===(y.content||""));if($>=0){const D=A.slice();return D[$]={...y,id:y.id??A[$].id},D}return[...A,y]})},[]),pe=a.useCallback(y=>{y&&z(A=>{if(A.has(y))return A;const $=new Set(A);return $.add(y),$})},[]),ce=a.useCallback((y,A)=>{L($=>{const D=$[y]??{state:"idle",unread:0,pinned:!1};return{...$,[y]:{...D,...A}}})},[]),ae=a.useCallback((y,A)=>{ce(y,{state:A?"streaming":"idle"})},[ce]),I=a.useCallback(y=>{K.current=y},[]),U=a.useCallback(async y=>{var A;try{const $=y?`/chat?session=${encodeURIComponent(y)}`:"/chat?limit=200",D=await E.get($);o(D.messages||[]),r(D.sessions||[])}catch($){(A=K.current)==null||A.error(`Chat load failed: ${$.message}`)}finally{n(!1)}},[]),W=a.useCallback(async y=>{var A;n(!0);try{const $=await E.get(`/tasks/${encodeURIComponent(y)}/chat`);o($.messages||[]),m($.sessionId||y)}catch($){(A=K.current)==null||A.error(`Task chat load failed: ${$.message}`)}finally{n(!1)}},[]),J=a.useCallback(async()=>{try{const y=await E.get("/chat/sessions");r(y.sessions||[])}catch{}},[]),fe=a.useCallback(async()=>{try{const A=((await E.get("/opencode-sessions")).sessions||[]).map($=>({...$,source:"opencode",title:$.title||$.id}));h(A)}catch{}},[]),ye=a.useCallback(y=>{if(Z.current){try{Z.current.close()}catch{}Z.current=null}ee.current!==null&&(clearTimeout(ee.current),ee.current=null);const A=E.getToken(),$=A?`/api/opencode-sessions/${encodeURIComponent(y)}/stream?token=${encodeURIComponent(A)}`:`/api/opencode-sessions/${encodeURIComponent(y)}/stream`;ue.current=y,me.current=!0,Te.current=0,P(null);const D=()=>{if(!me.current||ue.current!==y)return;const O=new EventSource($);Z.current=O;const H=M=>{var G,se,ie,he;if(!M||!M.type||M.sessionID&&M.sessionID!==y)return;const q=new Date().toISOString(),V=y;if(M.type==="message.user.created"||M.type==="message.user.updated"){const F=M.data;be({id:(F==null?void 0:F.messageID)??M.messageID,role:"user",content:((G=F==null?void 0:F.data)==null?void 0:G.content)??"",ts:q}),pe((F==null?void 0:F.messageID)??M.messageID);return}if(M.type==="message.assistant.created"||M.type==="message.assistant.updated"){const F=M.data;be({id:(F==null?void 0:F.messageID)??M.messageID,role:"assistant",content:((se=F==null?void 0:F.data)==null?void 0:se.content)??"",ts:q}),pe((F==null?void 0:F.messageID)??M.messageID),ae(V,!0);return}if(M.type==="message.part.updated"){const F=M.data,Ye=((ie=F==null?void 0:F.part)==null?void 0:ie.text)??"";if(!Ye)return;be({id:(F==null?void 0:F.id)??(F==null?void 0:F.messageID)??M.messageID,role:"assistant",content:Ye,ts:q}),pe((F==null?void 0:F.id)??(F==null?void 0:F.messageID)??M.messageID),ae(V,!0);return}if(M.type==="session.idle"||M.type==="message.assistant.completed"||M.type==="session.completed"){ae(V,!1);return}if(M.type==="session.awaiting"||M.type==="session.awaiting_input"||M.type==="message.assistant.awaiting"){ce(V,{state:"awaiting"});return}if(M.type==="session.error"){P(((he=M.data)==null?void 0:he.message)||"opencode session error");return}},te=M=>{if(!M)return null;try{const q=JSON.parse(M);if(typeof q.type=="string"){const V=q.properties,G=q.data??V,se=typeof q.sessionID=="string"?q.sessionID:typeof(V==null?void 0:V.sessionID)=="string"?V.sessionID:typeof(G==null?void 0:G.sessionID)=="string"?G.sessionID:void 0,ie=typeof q.messageID=="string"?q.messageID:typeof(V==null?void 0:V.messageID)=="string"?V.messageID:typeof(G==null?void 0:G.messageID)=="string"?G.messageID:void 0;let he=q.type;const F=/\.\d+$/.exec(he);return F&&(he=he.slice(0,F.index)),{type:he,sessionID:se,messageID:ie,data:q}}if(q.type==="sync"&&q.syncEvent&&typeof q.syncEvent=="object"){const V=q.syncEvent;let G=V.type||"";const se=/\.\d+$/.exec(G);se&&(G=G.slice(0,se.index));const ie=V.data||{};return{type:G,sessionID:typeof ie.sessionID=="string"?ie.sessionID:void 0,messageID:typeof ie.messageID=="string"?ie.messageID:void 0,data:V}}return null}catch{return null}},X=["message.user.created","message.user.updated","message.assistant.created","message.assistant.updated","message.part.updated","session.idle","message.assistant.completed","session.completed","session.awaiting","session.awaiting_input","message.assistant.awaiting","session.error"];for(const M of X)O.addEventListener(M,q=>{H(te(q.data))});O.onerror=()=>{if(ue.current!==y)return;if(!me.current){try{O.close()}catch{}Z.current=null;return}try{O.close()}catch{}Z.current=null;const M=Te.current+1;Te.current=M;const q=Math.min(3e4,1e3*2**(M-1));ee.current!==null&&clearTimeout(ee.current),ee.current=window.setTimeout(()=>{ee.current=null,me.current&&ue.current===y&&D()},q)},O.onopen=()=>{Te.current=0,P(null)}};D()},[be,pe,ae,ce]),Ie=a.useCallback(()=>{if(me.current=!1,ue.current=null,ee.current!==null&&(clearTimeout(ee.current),ee.current=null),Z.current){try{Z.current.close()}catch{}Z.current=null}N([]),z(new Set),P(null),C(null),u("bizar")},[]),Pe=a.useCallback(async y=>{var A;if(me.current=!1,Z.current){try{Z.current.close()}catch{}Z.current=null}ee.current!==null&&(clearTimeout(ee.current),ee.current=null),P(null),n(!0);try{const $=await E.get(`/opencode-sessions/${encodeURIComponent(y)}/messages`);N($.messages||[])}catch($){const D=$.message;(A=K.current)==null||A.error(`Opencode session load failed: ${D}`),N([])}finally{n(!1)}C(y),u("opencode"),ae(y,!1),ye(y)},[ae,ye]),Ct=a.useCallback(y=>{Ie(),m(y),u("bizar"),U(y),ce(y,{unread:0})},[Ie,U,ce]),Tt=a.useCallback(async()=>{var A,$,D,O,H;if(f.create)return{ok:!1};const y=s.defaultAgent||"odin";v(te=>({...te,create:!0}));try{try{const X=await E.post("/opencode-sessions/new",{agent:y});return await fe(),await Pe(X.id),(A=K.current)==null||A.success(`Session ${X.id} created.`),{ok:!0,source:"opencode",id:X.id}}catch(X){if(!(X instanceof qe)||X.status!==503)return($=K.current)==null||$.error(`Create failed: ${X.message}`),{ok:!1}}if(!t.activeProject)return(D=K.current)==null||D.error("Pick a project in Overview to scope chat sessions."),{ok:!1};const te=await E.post("/chat/sessions",{});return m(te.id),o([]),oe(new Set),ce(te.id,{state:"idle",unread:0}),await U(te.id),J().catch(()=>{}),(O=K.current)==null||O.success(`Session ${te.id} created.`),{ok:!0,source:"bizar",id:te.id}}catch(te){return(H=K.current)==null||H.error(`Create failed: ${te.message}`),{ok:!1}}finally{v(te=>({...te,create:!1}))}},[f.create,s.defaultAgent,t.activeProject,fe,Pe,U,J,ce]),It=a.useCallback(async(y,A,$,D)=>{var te,X,M;if(f.send)return{ok:!1};const O=y.trim();if(!O)return{ok:!1};if(g==="opencode"&&S){const q=S,V=`msg_${Date.now().toString(36)}${Math.random().toString(36).slice(2,8)}`,G={id:V,role:"user",content:O,agent:A,ts:new Date().toISOString()};be(G),pe(V),v(se=>({...se,send:!0}));try{return await E.post(`/opencode-sessions/${encodeURIComponent(q)}/send`,{message:O,agent:A}),ae(q,!0),{ok:!0}}catch(se){return N(ie=>ie.filter(he=>he.id!==V)),(te=K.current)==null||te.error(`Send failed: ${se.message}`),{ok:!1}}finally{v(se=>({...se,send:!1}))}}const H={role:"user",content:O,agent:A,ts:new Date().toISOString()};o(q=>[...q,H]),v(q=>({...q,send:!0})),ae(l,!0);try{const q=await E.post("/chat",{message:O,agent:A,model:$,attachments:D||[]});if(q!=null&&q.messages)for(const V of q.messages)V.role==="assistant"&&o(G=>G.some(ie=>ie.ts===V.ts)?G:[...G,V]);else(X=K.current)==null||X.info("Still processing… the response will appear shortly.");return{ok:!0}}catch(q){return o(V=>V.filter(G=>G!==H)),(M=K.current)==null||M.error(`Send failed: ${q.message}`),{ok:!1}}finally{v(q=>({...q,send:!1})),ae(l,!1)}},[g,S,be,pe,ae,l,f.send]),Et=a.useCallback(async y=>{var A,$;if(!l){(A=K.current)==null||A.error("No active session to regenerate.");return}try{await E.post("/chat/regenerate",{sessionId:l,messageId:y}),await U(l)}catch(D){($=K.current)==null||$.error(`Regenerate failed: ${D.message}`)}},[l,U]),At=a.useCallback(y=>{g==="opencode"?N(A=>A.filter(($,D)=>D!==y)):o(A=>A.filter(($,D)=>D!==y))},[g]),$t=a.useCallback(y=>{oe(A=>{const $=new Set(A);return $.has(y)?$.delete(y):$.add(y),$})},[]),zt=a.useCallback(y=>{var $,D;const A=y.content||y.message||"";try{($=navigator.clipboard)==null||$.writeText(A).then(()=>{var O;return(O=K.current)==null?void 0:O.success("Copied.")},()=>{var O;return(O=K.current)==null?void 0:O.error("Copy failed.")})}catch{(D=K.current)==null||D.error("Copy failed.")}},[]),Rt=a.useCallback(()=>{const y=Q.current;if(!y)return;const $=y.scrollHeight-y.scrollTop-y.clientHeight<32;w($),$&&R(0)},[]),Dt=a.useCallback(()=>{const y=Q.current;y&&(y.scrollTop=y.scrollHeight,w(!0),R(0))},[]),Mt=a.useCallback(async(y,A)=>{var $,D,O;if(f.rename)return!1;v(H=>({...H,rename:!0}));try{const H=A.trim();return H?(p.some(X=>X.id===y)?(await E.patch(`/opencode-sessions/${encodeURIComponent(y)}`,{title:H}),h(X=>X.map(M=>M.id===y?{...M,title:H}:M))):(await E.post(`/chat/sessions/${encodeURIComponent(y)}/rename`,{title:H}),r(X=>X.map(M=>M.id===y?{...M,title:H}:M))),(D=K.current)==null||D.success("Renamed."),!0):(($=K.current)==null||$.error("Title cannot be empty."),!1)}catch(H){return(O=K.current)==null||O.error(`Rename failed: ${H.message}`),!1}finally{v(H=>({...H,rename:!1}))}},[f.rename,p]),Lt=a.useCallback(async y=>{var A,$;if(f.delete)return!1;v(D=>({...D,delete:!0}));try{return p.some(O=>O.id===y)?(await E.del(`/opencode-sessions/${encodeURIComponent(y)}`),h(O=>O.filter(H=>H.id!==y)),S===y&&Ie()):(await E.del(`/chat/sessions/${encodeURIComponent(y)}`),r(O=>O.filter(H=>H.id!==y)),l===y&&(m(""),o([]))),L(O=>{const H={...O};return delete H[y],H}),(A=K.current)==null||A.success("Session deleted."),!0}catch(D){return($=K.current)==null||$.error(`Delete failed: ${D.message}`),!1}finally{v(D=>({...D,delete:!1}))}},[f.delete,p,S,Ie,l]);return a.useEffect(()=>{Q.current&&(j?Q.current.scrollTop=Q.current.scrollHeight:R(y=>y+1))},[c,b]),a.useEffect(()=>()=>{if(me.current=!1,ue.current=null,ee.current!==null&&(clearTimeout(ee.current),ee.current=null),Z.current){try{Z.current.close()}catch{}Z.current=null}},[]),a.useEffect(()=>{i?W(i):U(),fe()},[]),a.useEffect(()=>{const y=A=>{var D;const $=(D=A.detail)==null?void 0:D.taskId;$&&W($)};return window.addEventListener("bizar:setChatTask",y),()=>window.removeEventListener("bizar:setChatTask",y)},[W]),a.useEffect(()=>{let y=!1;return yt(async()=>{const{Ws:A}=await Promise.resolve().then(()=>ks);return{Ws:A}},void 0).then(({Ws:A})=>{if(y)return;new A().on(D=>{if(D.type!=="chat:message")return;const O=D.message;O&&o(H=>H.some(X=>X.ts===O.ts)?H:[...H,O])})}),()=>{y=!0}},[]),{messages:g==="opencode"?b:c,bizarMessages:c,opencodeMessages:b,sessions:d,opencodeSessions:p,sessionId:l,setSessionId:m,loading:x,sending:f.send,pinned:Y,listRef:Q,activeSource:g,activeOpencodeSessionId:S,opencodeError:_,sessionStates:T,busy:f,getSessionDisplay:y=>{var A,$,D,O;return{...y,state:((A=T[y.id])==null?void 0:A.state)??"idle",unread:(($=T[y.id])==null?void 0:$.unread)??0,pinned:((D=T[y.id])==null?void 0:D.pinned)??!1,tree:(O=T[y.id])==null?void 0:O.tree}},stickToBottom:j,newMessageCount:k,handleScroll:Rt,jumpToLatest:Dt,setToast:I,loadChat:U,loadTaskChat:W,refreshSessions:J,refreshOpencodeSessions:fe,loadOpencodeSession:Pe,closeOpencodeSession:Ie,selectBizarSession:Ct,onCreateSession:Tt,onSend:It,onRegenerate:Et,deleteMessage:At,togglePin:$t,copyMessage:zt,renameSession:Mt,deleteSession:Lt,seenOpencodeMessages:B}}const Ps=[{cmd:"/visual-plan [on|off|status]",desc:"Toggle or view visual plan mode"},{cmd:"/plan new <slug> [template]",desc:"Create a new plan"},{cmd:"/plan list",desc:"List all plans"},{cmd:"/plan open <slug>",desc:"Open a plan in the viewer"},{cmd:"/plan status <slug> <status>",desc:"Set plan status"},{cmd:"/plan get <slug>",desc:"Fetch plan canvas"},{cmd:"/plan add <slug> --title T --type kind",desc:"Add element to a plan"},{cmd:"/plan update <slug> <id>",desc:"Update a plan element"},{cmd:"/plan delete <slug> <id>",desc:"Delete a plan element"},{cmd:'/plan comment <slug> [id] "text"',desc:"Add a comment"},{cmd:"/plan comments <slug> [id]",desc:"Read plan comments"},{cmd:"/bizar",desc:"Launch Bizar dashboard"},{cmd:"/bizar <args>",desc:"Route via Bizar menu"},{cmd:"/audit",desc:"Run security audit"},{cmd:"/explain <q>",desc:"Read-only code Q&A"},{cmd:"/init",desc:"Initialize .bizar/ in this project"},{cmd:"/learn",desc:"Extract patterns from session"},{cmd:"/pr-review",desc:"PR review"},{cmd:"/help | /commands",desc:"Show all Bizar commands"}];function Os(t){const[s,i]=a.useState(""),c=a.useMemo(()=>[...Ps,...(t.mods||[]).flatMap(d=>{var r;return(r=d.entry)!=null&&r.command?[{cmd:`/${d.id}`,desc:d.description||d.name,mod:d.id}]:[]})],[t.mods]),o=a.useMemo(()=>{if(!s.startsWith("/")||s.includes(" "))return[];const d=s.toLowerCase();return c.filter(r=>r.cmd.toLowerCase().startsWith(d)).slice(0,6)},[s,c]);return{allCommands:c,suggestions:o,setQuery:i}}function Bs({tabs:t,activeTab:s,onChange:i}){return e.jsx("nav",{className:"mobile-bottom-nav",role:"navigation","aria-label":"Mobile navigation",children:t.map(c=>{const o=c.icon;return e.jsxs("button",{type:"button",className:Ve("mobile-nav-btn",s===c.id&&"mobile-nav-btn-active"),onClick:()=>i(c.id),"aria-label":c.label,"aria-current":s===c.id?"page":void 0,children:[e.jsx(o,{size:22}),e.jsx("span",{className:"mobile-nav-label",children:c.label})]},c.id)})})}function re({open:t,onClose:s,title:i,children:c,actions:o,maxHeight:d="85vh"}){const r=a.useRef(null),l=a.useRef(null),m=a.useId(),x=a.useRef(null),n=a.useRef(null),f=a.useRef(0),v=a.useRef(0),p=()=>{var g;return((g=r.current)==null?void 0:g.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'))??[]};if(a.useEffect(()=>{if(!t)return;x.current=document.activeElement instanceof HTMLElement?document.activeElement:null;const g=u=>{var T;if(u.key==="Escape"&&s(),u.key!=="Tab")return;const S=Array.from(p());if(S.length===0){u.preventDefault(),(T=r.current)==null||T.focus();return}const C=S[0],_=S[S.length-1],P=document.activeElement;if(u.shiftKey){(!P||P===C||P===r.current)&&(u.preventDefault(),_==null||_.focus());return}P===_&&(u.preventDefault(),C==null||C.focus())};return window.addEventListener("keydown",g),requestAnimationFrame(()=>{var u,S;((u=l.current)==null?void 0:u.focus())??((S=r.current)==null||S.focus())}),()=>{var u;window.removeEventListener("keydown",g),(u=x.current)==null||u.focus()}},[t,s]),a.useEffect(()=>(t?(v.current=window.scrollY,document.documentElement.style.overflow="hidden",document.body.style.overflow="hidden",document.body.style.position="fixed",document.body.style.top=`-${v.current}px`,document.body.style.left="0",document.body.style.right="0",document.body.style.width="100%"):(document.documentElement.style.overflow="",document.body.style.overflow="",document.body.style.position="",document.body.style.top="",document.body.style.left="",document.body.style.right="",document.body.style.width=""),()=>{document.documentElement.style.overflow="",document.body.style.overflow="",document.body.style.position="",document.body.style.top="",document.body.style.left="",document.body.style.right="",document.body.style.width="",window.scrollTo(0,v.current)}),[t]),!t)return null;const h=g=>{var u;g.isPrimary&&(n.current=g.clientY,f.current=0,(u=r.current)==null||u.setPointerCapture(g.pointerId))},b=g=>{if(n.current==null||!r.current)return;const u=Math.max(0,g.clientY-n.current);f.current=u,r.current.style.transform=`translateY(${u}px)`},N=g=>{if(!r.current)return;g&&r.current.hasPointerCapture(g.pointerId)&&r.current.releasePointerCapture(g.pointerId);const u=f.current;r.current.style.transform="",n.current=null,f.current=0,u>72&&s()};return e.jsx("div",{className:"mobile-sheet-overlay",onClick:s,children:e.jsxs("div",{ref:r,className:"mobile-sheet",style:{maxHeight:d},onClick:g=>g.stopPropagation(),role:"dialog","aria-modal":!0,"aria-label":i?void 0:"Sheet","aria-labelledby":i?m:void 0,tabIndex:-1,children:[e.jsx("div",{className:"mobile-sheet-handle",onPointerDown:h,onPointerMove:b,onPointerUp:N,onPointerCancel:N,"aria-hidden":"true"}),e.jsxs("div",{className:"mobile-sheet-header",children:[i?e.jsx("h3",{id:m,className:"mobile-sheet-title",children:i}):e.jsx("div",{}),e.jsx("button",{ref:l,type:"button",className:"mobile-icon-btn",onClick:s,"aria-label":"Close",children:e.jsx(ve,{size:18})})]}),e.jsx("div",{className:"mobile-sheet-content",children:c}),o&&e.jsx("div",{className:"mobile-sheet-actions",children:o})]})})}function Us(t){switch(t){case"success":return"✓";case"error":return"✗";case"warning":return"⚠";default:return"ℹ"}}function Fs(t){const s=new Date(t),c=Date.now()-s.getTime();return c<6e4?"just now":c<36e5?`${Math.floor(c/6e4)}m ago`:c<864e5?`${Math.floor(c/36e5)}h ago`:s.toLocaleDateString()}function _s({onSelect:t}){const[s,i]=a.useState(!1),[c,o]=a.useState([]),[d,r]=a.useState(0),l=async()=>{var n;try{const f=await E.get("/notifications");o(f.notifications||[]),r(((n=f.stats)==null?void 0:n.unread)||0)}catch{}};a.useEffect(()=>{l()},[]),a.useEffect(()=>{s&&l()},[s]);const m=async()=>{try{await E.post("/notifications/read-all"),o(n=>n.map(f=>({...f,read:!0}))),r(0)}catch{}},x=async n=>{try{await E.post(`/notifications/${encodeURIComponent(n)}/read`),o(f=>f.map(v=>v.id===n?{...v,read:!0}:v)),r(f=>Math.max(0,f-1))}catch{}};return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",className:"mobile-icon-btn mobile-notif-btn",onClick:()=>i(!0),"aria-label":`Notifications${d>0?` (${d} unread)`:""}`,children:[e.jsx(Qe,{size:20}),d>0&&e.jsx("span",{className:"mobile-notif-badge",children:d>9?"9+":d})]}),e.jsx(re,{open:s,onClose:()=>i(!1),title:"Notifications",actions:d>0?e.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",style:{width:"100%"},onClick:m,children:[e.jsx(Qt,{size:14})," Mark all read"]}):void 0,children:e.jsxs("div",{className:"mobile-notif-list",children:[c.length===0&&e.jsxs("div",{className:"mobile-empty",children:[e.jsx(Qe,{size:32}),e.jsx("p",{children:"No notifications"})]}),c.map(n=>e.jsxs("button",{type:"button",className:`mobile-notif-item ${n.read?"read":"unread"}`,onClick:()=>{n.read||x(n.id),t(n),i(!1)},children:[e.jsx("span",{className:`mobile-notif-icon severity-${n.severity}`,children:Us(n.severity)}),e.jsxs("div",{className:"mobile-notif-body",children:[e.jsx("span",{className:"mobile-notif-title",children:n.title||n.message}),n.message&&n.title&&e.jsx("span",{className:"mobile-notif-text",children:n.message}),e.jsx("span",{className:"mobile-notif-time",children:Fs(n.ts)})]}),!n.read&&e.jsx("span",{className:"mobile-notif-dot"})]},n.id))]})})]})}const qs={activity:"Activity",chat:"Chat",tasks:"Tasks",settings:"Settings",more:"More",plans:"Plans",agents:"Agents",skills:"Skills",mods:"Mods",schedules:"Schedules",history:"History",config:"Config","plan-detail":"Plan","agent-detail":"Agent","task-detail":"Task"};function Ws({activeTab:t,snapshot:s,onSearch:i,onNavigate:c}){const[o,d]=a.useState(!1),r=async l=>{try{await E.post(`/projects/${encodeURIComponent(l)}/activate`),d(!1),window.location.reload()}catch{}};return e.jsxs("header",{className:"mobile-topbar",children:[e.jsxs("div",{className:"mobile-topbar-left",children:[e.jsx("span",{className:"mobile-logo",children:"ᛒ"}),(s==null?void 0:s.activeProject)&&e.jsxs("button",{type:"button",className:"mobile-project-btn",onClick:()=>d(!0),"aria-label":"Select project",children:[e.jsx("span",{className:"mobile-project-name",children:s.activeProject.name}),e.jsx(Le,{size:14})]}),e.jsx("span",{className:"mobile-title",children:qs[t]||"Bizar"})]}),e.jsxs("div",{className:"mobile-topbar-right",children:[e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:i,"aria-label":"Search",children:e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"m21 21-4.35-4.35"})]})}),e.jsx(_s,{onSelect:l=>{c("notification",l.link||"",l.meta??null)}}),(s==null?void 0:s.activeProject)&&e.jsx(re,{open:o,onClose:()=>d(!1),title:"Projects",children:e.jsx("div",{className:"mobile-project-list",children:(s.projects||[]).map(l=>{var m,x;return e.jsxs("button",{type:"button",className:`mobile-project-item ${l.id===((m=s.activeProject)==null?void 0:m.id)?"active":""}`,onClick:()=>r(l.id),children:[e.jsx("div",{className:"mobile-project-status","data-status":l.status}),e.jsxs("div",{className:"mobile-project-info",children:[e.jsx("span",{className:"mobile-project-item-name",children:l.name}),e.jsx("span",{className:"mobile-project-item-path",children:l.path})]}),l.id===((x=s.activeProject)==null?void 0:x.id)&&e.jsx("span",{className:"mobile-active-badge",children:"active"})]},l.id)})})})]})]})}const Hs=["all","tasks","agents","bg","artifacts","mods"],Oe={all:"All",tasks:"Tasks",agents:"Agents",bg:"Background",artifacts:"Plans",mods:"Mods"};function Vs({snapshot:t,onRefresh:s}){var L;const[i,c]=a.useState(((L=t.overview)==null?void 0:L.recentActivity)||[]),[o,d]=a.useState(!0),[r,l]=a.useState("all"),[m,x]=a.useState(!1),[n,f]=a.useState(null),[v,p]=a.useState(""),[h,b]=a.useState(!1);a.useEffect(()=>{var j;(j=t.overview)!=null&&j.recentActivity?(c(t.overview.recentActivity),d(!1)):N()},[t.overview]);const N=async()=>{var j;try{const w=await E.get("/snapshot");c(((j=w.overview)==null?void 0:j.recentActivity)||[])}catch{}finally{d(!1)}},g=r==="all"?i:i.filter(j=>{var w,k,R,B,z,Y;return r==="tasks"?(w=j.kind)==null?void 0:w.startsWith("task"):r==="agents"?(k=j.kind)==null?void 0:k.startsWith("agent"):r==="bg"?((R=j.kind)==null?void 0:R.includes("bg"))||((B=j.kind)==null?void 0:B.includes("schedule")):r==="artifacts"?(z=j.kind)==null?void 0:z.includes("artifacts"):r==="mods"?(Y=j.kind)==null?void 0:Y.includes("mod"):!0}),u=t.agents||[],S=t.tasks||[],C=S.filter(j=>j.status==="doing"||j.status==="queued"),_=S.filter(j=>j.status==="done"),P=async()=>{if(!(!v.trim()||h)){b(!0);try{await E.post("/chat",{message:v.trim(),agent:"odin"}),p(""),await s().catch(()=>{}),await N()}catch{}finally{b(!1)}}},T=async()=>{await s().catch(()=>{}),await N()};return e.jsxs("div",{className:"mobile-view",children:[e.jsxs("div",{className:"mobile-submit-hero",children:[e.jsx("textarea",{className:"mobile-submit-input",placeholder:"What needs to be done? Describe a task, bug, or refactor for Odin to artifacts…",value:v,onChange:j=>p(j.target.value),rows:2}),e.jsxs("div",{className:"mobile-submit-actions",children:[e.jsx("div",{className:"mobile-submit-chips",children:["Implement feature","Fix bug","Refactor","Investigate","Write tests"].map(j=>e.jsx("button",{type:"button",className:"mobile-submit-chip",onClick:()=>p(w=>w?`${w} ${j}`:j),children:j},j))}),e.jsxs("button",{type:"button",className:"mobile-btn",disabled:!v.trim()||h,onClick:P,children:[e.jsx(ht,{size:14})," Submit to Odin"]})]})]}),e.jsxs("div",{className:"mobile-stats",children:[e.jsxs("div",{className:"mobile-stat",children:[e.jsx("div",{className:"mobile-stat-value",children:u.length}),e.jsx("div",{className:"mobile-stat-label",children:"Agents"})]}),e.jsxs("div",{className:"mobile-stat",children:[e.jsx("div",{className:"mobile-stat-value",children:C.length}),e.jsx("div",{className:"mobile-stat-label",children:"Active"})]}),e.jsxs("div",{className:"mobile-stat",children:[e.jsx("div",{className:"mobile-stat-value",children:_.length}),e.jsx("div",{className:"mobile-stat-label",children:"Done"})]}),e.jsxs("div",{className:"mobile-stat",children:[e.jsx("div",{className:"mobile-stat-value",children:t.artifacts.length||0}),e.jsx("div",{className:"mobile-stat-label",children:"Plans"})]})]}),o&&i.length===0&&e.jsx("div",{className:"mobile-loading mobile-loading-inline",children:e.jsx("p",{children:"Loading activity…"})}),e.jsxs("div",{className:"mobile-activity-header",children:[e.jsx("h3",{className:"mobile-section-title",style:{margin:0},children:"Recent Activity"}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>x(j=>!j),"aria-label":m?"Resume":"Pause",children:m?e.jsx(Re,{size:14}):e.jsx(Jt,{size:14})}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:T,"aria-label":"Refresh",children:e.jsx(de,{size:14})})]})]}),e.jsx("div",{className:"mobile-search-scopes",children:Hs.map(j=>e.jsx("button",{type:"button",className:`mobile-scope-chip ${r===j?"active":""}`,onClick:()=>l(j),children:Oe[j]},j))}),u.length>0&&e.jsxs("section",{className:"mobile-section",children:[e.jsxs("h3",{className:"mobile-section-title",children:[e.jsx(Ce,{size:14})," Agents"]}),e.jsx("div",{className:"mobile-card-list",children:u.slice(0,6).map(j=>e.jsxs("div",{className:"mobile-agent-card",children:[e.jsx("div",{className:"mobile-agent-dot","data-status":j.status||"idle"}),e.jsxs("div",{className:"mobile-agent-info",children:[e.jsx("span",{className:"mobile-agent-name",children:j.name}),e.jsx("span",{className:"mobile-agent-meta",children:j.status||"idle"})]})]},j.name))})]}),!m&&g.length>0&&e.jsx("section",{className:"mobile-section",children:e.jsx("div",{className:"mobile-card-list",children:g.slice(0,30).map((j,w)=>e.jsxs("button",{type:"button",className:"mobile-event-item",onClick:()=>f(j),children:[e.jsx("span",{className:"mobile-event-kind","data-kind":j.kind,children:Oe[j.kind]||j.kind}),e.jsx("span",{className:"mobile-event-msg",children:Ks(j)}),e.jsx("span",{className:"mobile-event-time",children:ke(j.ts)})]},`${j.ts}-${j.kind}-${w}`))})}),!m&&g.length===0&&i.length>0&&e.jsxs("div",{className:"mobile-empty",children:[e.jsx(Ue,{size:40}),e.jsx("p",{children:"No matching activity."}),e.jsx("p",{className:"muted",children:"Try a different filter."})]}),n&&e.jsx(re,{open:!0,onClose:()=>f(null),title:Oe[n.kind]||n.kind,children:e.jsxs("div",{className:"mobile-agent-detail-meta",children:[e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Kind"}),e.jsx("span",{children:n.kind})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Time"}),e.jsx("span",{children:new Date(n.ts).toLocaleString()})]}),Object.entries(n).filter(([j])=>!["ts","kind"].includes(j)).map(([j,w])=>e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:j}),e.jsx("span",{style:{fontSize:12,maxWidth:200,wordBreak:"break-all"},children:typeof w=="object"?JSON.stringify(w):String(w)})]},j))]})}),u.length===0&&C.length===0&&e.jsxs("div",{className:"mobile-empty",children:[e.jsx(Ue,{size:40}),e.jsx("p",{children:"No activity yet."}),e.jsx("p",{className:"muted",children:"Start a task or chat to see things here."})]})]})}function Ks(t){const s=t.kind||"";return s.includes("task")?`Task: ${t.title||t.id||"updated"}`:s.includes("agent")?`Agent: ${t.name||"status changed"}`:s.includes("artifacts")?`Plan: ${t.slug||"changed"}`:s.includes("mod")?`Mod: ${t.name||"changed"}`:s.includes("schedule")?`Schedule: ${t.name||"triggered"}`:JSON.stringify(t).slice(0,80)}function xe({open:t,onClose:s,title:i,children:c,actions:o}){const d=a.useRef(null),r=a.useRef(null),l=a.useRef(null),m=a.useId(),x=a.useRef(0);return a.useEffect(()=>{if(!t)return;l.current=document.activeElement instanceof HTMLElement?document.activeElement:null;const n='button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])',f=v=>{var g,u;if(v.key==="Escape"&&s(),v.key!=="Tab")return;const p=Array.from(((g=d.current)==null?void 0:g.querySelectorAll(n))??[]);if(p.length===0){v.preventDefault(),(u=d.current)==null||u.focus();return}const h=p[0],b=p[p.length-1],N=document.activeElement;if(v.shiftKey){(!N||N===h||N===d.current)&&(v.preventDefault(),b==null||b.focus());return}N===b&&(v.preventDefault(),h==null||h.focus())};return window.addEventListener("keydown",f),x.current=window.scrollY,document.documentElement.style.overflow="hidden",document.body.style.overflow="hidden",document.body.style.position="fixed",document.body.style.top=`-${x.current}px`,document.body.style.left="0",document.body.style.right="0",document.body.style.width="100%",requestAnimationFrame(()=>{var v,p;((v=r.current)==null?void 0:v.focus())??((p=d.current)==null||p.focus())}),()=>{var v;window.removeEventListener("keydown",f),document.documentElement.style.overflow="",document.body.style.overflow="",document.body.style.position="",document.body.style.top="",document.body.style.left="",document.body.style.right="",document.body.style.width="",window.scrollTo(0,x.current),(v=l.current)==null||v.focus()}},[t,s]),t?e.jsx("div",{className:"mobile-modal-overlay",onClick:n=>{n.target===n.currentTarget&&s()},children:e.jsxs("div",{ref:d,className:"mobile-modal",onClick:n=>n.stopPropagation(),role:"dialog","aria-modal":!0,"aria-label":i?void 0:"Modal","aria-labelledby":i?m:void 0,tabIndex:-1,children:[e.jsxs("div",{className:"mobile-modal-header",children:[i?e.jsx("h2",{id:m,className:"mobile-modal-title",children:i}):e.jsx("div",{}),e.jsx("button",{ref:r,type:"button",className:"mobile-icon-btn",onClick:s,"aria-label":"Close",children:e.jsx(ve,{size:20})})]}),e.jsx("div",{className:"mobile-modal-content",children:c}),o&&e.jsx("div",{className:"mobile-modal-actions",children:o})]})}):null}const Nt=["reasoning","code","design","planning","gitops","analysis"],it={reasoning:"var(--accent)",code:"var(--info)",design:"var(--success)",planning:"var(--warning)",gitops:"var(--error)",analysis:"var(--text-dim)"};function lt({snapshot:t,onBack:s,onOpenAgent:i,selectedAgent:c,onRefresh:o}){const[d,r]=a.useState(t.agents||[]),[l,m]=a.useState(!t.agents),[x,n]=a.useState(""),[f,v]=a.useState(""),[p,h]=a.useState(null),[b,N]=a.useState(!1),[g,u]=a.useState(""),[S,C]=a.useState(!1);a.useEffect(()=>{if(c){const k=d.find(R=>R.name===c);k&&h(k)}},[c,d]);const _=async()=>{try{const k=await E.get("/agents");r(k.agents||[])}catch{}finally{m(!1)}},P=d.filter(k=>{if(x&&k.category!==x)return!1;if(f){const R=f.toLowerCase();if(!k.name.toLowerCase().includes(R)&&!(k.description||"").toLowerCase().includes(R))return!1}return!0}),T=async(k,R)=>{try{await E.post(`/agents/${encodeURIComponent(k)}/invoke`,{prompt:R}),C(!1),u("")}catch{}},L=async k=>{try{await E.post(`/agents/${encodeURIComponent(k)}/restart`),await _()}catch{}},j=async k=>{if(confirm(`Delete agent "${k}"?`))try{await E.del(`/agents/${encodeURIComponent(k)}`),r(R=>R.filter(B=>B.name!==k)),h(null),o==null||o()}catch{}},w=async k=>{try{const R=await E.post("/agents",k);r(B=>[...B,R]),N(!1),o==null||o()}catch{}};return e.jsxs("div",{className:"mobile-view",children:[e.jsxs("div",{className:"mobile-tasks-toolbar",children:[e.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search agents…",value:f,onChange:k=>v(k.target.value),style:{flex:1}}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>_(),"aria-label":"Refresh",children:e.jsx(de,{size:16})}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>N(!0),"aria-label":"New agent",children:e.jsx(le,{size:16})})]}),e.jsxs("div",{className:"mobile-search-scopes",children:[e.jsx("button",{type:"button",className:`mobile-scope-chip ${x?"":"active"}`,onClick:()=>n(""),children:"All"}),Nt.map(k=>e.jsx("button",{type:"button",className:`mobile-scope-chip ${x===k?"active":""}`,onClick:()=>n(k),children:k},k))]}),l?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading…"})}):P.length===0?e.jsxs("div",{className:"mobile-empty",children:[e.jsx(Ce,{size:40}),e.jsx("p",{children:"No agents found."})]}):e.jsx("div",{className:"mobile-card-list",children:P.map(k=>e.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>{h(k),i(k.name)},children:[e.jsx("div",{className:"mobile-agent-dot","data-status":k.status||"idle"}),e.jsxs("div",{className:"mobile-list-content",children:[e.jsx("span",{className:"mobile-list-title",children:k.name}),e.jsx("span",{className:"mobile-list-meta",children:k.model||k.mode||"—"})]}),k.category&&e.jsx("span",{className:"mobile-list-badge",style:{color:it[k.category]||"var(--text-dim)"},children:k.category}),e.jsx("span",{className:"mobile-list-badge","data-status":k.status||"idle",children:k.status||"idle"})]},k.name))}),p&&e.jsx(re,{open:!0,onClose:()=>h(null),title:p.name,actions:e.jsxs("div",{className:"mobile-task-detail-actions",children:[e.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>{u(""),C(!0)},children:[e.jsx(Re,{size:14})," Invoke"]}),(p.isStuck||p.status==="error"||p.status==="working")&&e.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>L(p.name),children:[e.jsx(Xt,{size:14})," Restart"]}),e.jsx("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>j(p.name),children:e.jsx(Se,{size:14})})]}),children:e.jsxs("div",{className:"mobile-agent-detail",children:[e.jsxs("div",{className:"mobile-agent-detail-status",children:[e.jsx("span",{className:"mobile-agent-dot","data-status":p.status||"idle"}),e.jsx("span",{className:"mobile-agent-detail-status-text",children:p.status||"idle"}),p.category&&e.jsx("span",{className:"mobile-list-badge",style:{color:it[p.category]},children:p.category})]}),e.jsx("p",{className:"mobile-agent-detail-desc",children:p.description||"No description."}),e.jsxs("div",{className:"mobile-agent-detail-meta",children:[e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Model"}),e.jsx("span",{className:"mono",children:p.model||"—"})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Mode"}),e.jsx("span",{children:p.mode||"subagent"})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Path"}),e.jsx("span",{className:"mono",style:{fontSize:11},children:p.path})]}),p.lastError&&e.jsxs("div",{className:"mobile-task-detail-row",style:{color:"var(--error)"},children:[e.jsx("span",{children:"Last error"}),e.jsx("span",{children:p.lastError.message})]}),p.tasksTotal!=null&&p.tasksTotal>0&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Success rate"}),e.jsxs("span",{children:[Math.round((p.successRate||0)*100),"%"]})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Last modified"}),e.jsx("span",{children:ke(p.mtime)})]})]})]})}),e.jsxs(xe,{open:S,onClose:()=>C(!1),title:`Invoke ${p==null?void 0:p.name}`,actions:e.jsxs("button",{type:"button",className:"mobile-btn",style:{width:"100%"},disabled:!g.trim(),onClick:()=>{p&&T(p.name,g.trim())},children:[e.jsx(Re,{size:14})," Invoke"]}),children:[e.jsxs("p",{className:"muted",style:{marginBottom:12},children:["Model: ",e.jsx("span",{className:"mono",children:(p==null?void 0:p.model)||"—"})]}),e.jsx("textarea",{className:"mobile-input",rows:5,placeholder:"What should this agent do?",value:g,onChange:k=>u(k.target.value),autoFocus:!0})]}),e.jsx(Ys,{open:b,onClose:()=>N(!1),onCreate:w})]})}function Ys({open:t,onClose:s,onCreate:i}){const[c,o]=a.useState(""),[d,r]=a.useState(""),[l,m]=a.useState(""),[x,n]=a.useState("subagent"),[f,v]=a.useState("#8b5cf6"),[p,h]=a.useState(""),[b,N]=a.useState(""),[g,u]=a.useState(""),S=C=>{C.preventDefault(),c.trim()&&(i({name:c.trim(),description:d.trim(),model:l,mode:x,color:f,tools:[],tags:b.split(",").map(_=>_.trim()).filter(Boolean),category:p,prompt:g}),o(""),r(""),m(""),n("subagent"),v("#8b5cf6"),h(""),N(""),u(""))};return e.jsx(xe,{open:t,onClose:s,title:"New Agent",actions:e.jsxs("button",{type:"submit",form:"new-agent-form",className:"mobile-btn",style:{width:"100%"},children:[e.jsx(le,{size:14})," Create"]}),children:e.jsxs("form",{id:"new-agent-form",onSubmit:S,className:"mobile-task-form",children:[e.jsx("label",{className:"mobile-field-label",children:"Name *"}),e.jsx("input",{className:"mobile-input",type:"text",placeholder:"my-agent",pattern:"[a-z0-9][a-z0-9-]{0,63}",value:c,onChange:C=>o(C.target.value),autoFocus:!0,required:!0}),e.jsx("label",{className:"mobile-field-label",children:"Description"}),e.jsx("input",{className:"mobile-input",type:"text",placeholder:"What does this agent do?",value:d,onChange:C=>r(C.target.value)}),e.jsx("label",{className:"mobile-field-label",children:"Model"}),e.jsx("input",{className:"mobile-input",type:"text",placeholder:"(provider default)",value:l,onChange:C=>m(C.target.value)}),e.jsx("label",{className:"mobile-field-label",children:"Category"}),e.jsxs("select",{className:"mobile-input",value:p,onChange:C=>h(C.target.value),children:[e.jsx("option",{value:"",children:"None"}),Nt.map(C=>e.jsx("option",{value:C,children:C},C))]}),e.jsx("label",{className:"mobile-field-label",children:"Tags (comma-separated)"}),e.jsx("input",{className:"mobile-input",type:"text",placeholder:"tag1, tag2",value:b,onChange:C=>N(C.target.value)})]})})}function Gs({sessions:t,opencodeSessions:s,activeSessionId:i,activeOpencodeSessionId:c,activeProject:o,creating:d,onCreateSession:r,onSelectSession:l,onSelectOpencodeSession:m}){const[x,n]=a.useState("all"),[f,v]=a.useState(!1),p=30,h=x==="all"?[...t,...s].sort((u,S)=>Number(S.mtime)-Number(u.mtime)):t,b=f?h:h.slice(0,p),N=s.length,g=u=>{if(u.source==="opencode"){m(u);return}l(u.id)};return e.jsxs("div",{className:"chat-sessions",children:[e.jsxs("div",{className:"chat-sessions-header",children:[e.jsx("span",{className:"chat-sessions-header-title",children:"Sessions"}),e.jsx("span",{className:"chat-sessions-count",children:b.length})]}),N>0&&e.jsxs("div",{className:"chat-sessions-toggle",children:[e.jsx("button",{type:"button",className:`chat-sessions-toggle-btn ${x==="bizar"?"active":""}`,onClick:()=>n("bizar"),children:"Bizar"}),e.jsxs("button",{type:"button",className:`chat-sessions-toggle-btn ${x==="all"?"active":""}`,onClick:()=>n("all"),children:["All (",N," opencode)"]})]}),e.jsxs("button",{type:"button",className:"chat-sessions-new",onClick:r,disabled:d||!o,title:o?"Create new session":"Pick a project first","aria-label":"Create new session",children:[d?e.jsx(vt,{size:"sm"}):e.jsx(le,{size:14}),e.jsx("span",{children:d?"Creating…":"New session"})]}),t.length===0?e.jsx("div",{className:"chat-sessions-empty",children:e.jsx(Cs,{icon:e.jsx(ze,{size:20}),title:o?"No sessions yet":"No project",message:o?"Create your first session to start chatting.":"Pick a project in Overview to scope chat sessions.",action:o?e.jsxs(Ne,{variant:"primary",size:"sm",onClick:r,loading:d,children:[e.jsx(le,{size:12})," New session"]}):e.jsxs(Ne,{variant:"secondary",size:"sm",onClick:()=>{window.location.hash="#overview"},children:[e.jsx(We,{size:12})," Open Overview"]})})}):e.jsx("ul",{className:"chat-sessions-list",children:b.map(u=>{const S=u.source==="opencode",C=S?c===u.id:i===u.id;return e.jsxs("li",{className:`chat-sessions-item ${C?"active":""} ${S?"chat-sessions-item-opencode":""}`,onClick:()=>g(u),title:S?`Open in dashboard: ${u.title||u.id}`:u.id,children:[S&&e.jsx(Zt,{size:10,className:"chat-sessions-item-icon"}),e.jsx("span",{className:"chat-sessions-item-id",children:u.title||u.id}),e.jsx("span",{className:"chat-sessions-item-meta",children:new Date(Number(u.mtime)).toLocaleDateString()})]},S?`oc-${u.id}`:u.id)})}),h.length>p&&e.jsx("button",{type:"button",className:"chat-sessions-show-more",onClick:()=>v(u=>!u),children:f?`Show less (${h.length-p} hidden)`:`Show all ${h.length} sessions`})]})}function Qs(t){const{activeSource:s}=t;return e.jsx("div",{className:`chat-composer-wrap chat-composer-source-${s??"none"} legacy`,children:e.jsx("div",{className:"chat-composer-pill",children:e.jsx(Rs,{...t})})})}function Js({sessionId:t,messages:s,pinned:i,agent:c,model:o,agents:d,mcps:r,allCommands:l,activeSource:m="bizar",onRename:x,onDelete:n}){const[f,v]=a.useState(!1),[p,h]=a.useState(!1),b=f?d:d.slice(0,4),N=p?l:l.slice(0,4),g=o.includes("/")?o.split("/")[0]:"";return e.jsxs("div",{className:"chat-info",children:[e.jsxs("div",{className:"chat-info-card",children:[e.jsxs("div",{className:"chat-info-card-title",children:[e.jsx(ge,{size:14})," Session",e.jsx("span",{className:`chat-source-badge chat-source-${m??"none"}`,style:{marginLeft:"auto"},children:m==="opencode"?"opencode":"bizar chat"})]}),e.jsxs("dl",{className:"env-table",children:[e.jsx("dt",{children:"id"}),e.jsx("dd",{className:"mono",children:t||"Live"}),e.jsx("dt",{children:"Messages"}),e.jsx("dd",{className:"mono",children:s.length}),e.jsx("dt",{children:"Pinned"}),e.jsx("dd",{className:"mono",children:i.size}),e.jsx("dt",{children:"Agent"}),e.jsx("dd",{className:"mono",children:c||"—"}),e.jsx("dt",{children:"Model"}),e.jsx("dd",{className:"mono ellipsis",title:o,children:o||"—"}),g&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Provider"}),e.jsx("dd",{className:"mono",children:g})]})]}),(x||n)&&e.jsxs("div",{className:"chat-info-actions",children:[x&&e.jsxs("button",{type:"button",className:"btn btn-ghost btn-sm",onClick:x,children:[e.jsx(He,{size:12,"aria-hidden":!0})," Rename"]}),n&&e.jsxs("button",{type:"button",className:"btn btn-ghost btn-danger btn-sm",onClick:n,children:[e.jsx(Se,{size:12,"aria-hidden":!0})," Delete"]})]})]}),e.jsxs("div",{className:"chat-info-card",children:[e.jsxs("div",{className:"chat-info-card-title",children:[e.jsx(Ce,{size:14})," Agents",e.jsx("span",{className:"chat-info-card-count",children:d.length})]}),e.jsx("ul",{className:"mod-mini-list",children:b.map(u=>e.jsxs("li",{className:"mod-mini",children:[e.jsxs("span",{className:"mod-mini-name",children:["@",u.name]}),e.jsx("span",{className:"mod-mini-meta",children:u.model||u.mode||""})]},u.name))}),d.length>4&&e.jsx("button",{type:"button",className:"chat-info-card-toggle",onClick:()=>v(u=>!u),children:f?"− Show fewer":`+ ${d.length-4} more`})]}),e.jsxs("div",{className:"chat-info-card",children:[e.jsxs("div",{className:"chat-info-card-title",children:[e.jsx(es,{size:14})," MCPs",e.jsx("span",{className:"chat-info-card-count",children:r.length})]}),e.jsxs("ul",{className:"mod-mini-list",children:[r.length===0?e.jsx("li",{className:"muted",children:"No MCPs configured."}):null,r.map(u=>e.jsxs("li",{className:"mod-mini",children:[e.jsx("span",{className:"mod-mini-name",children:u.id}),e.jsx("span",{className:`mod-mini-pill ${u.enabled?"on":"off"}`,children:u.enabled?"on":"off"})]},u.id))]})]}),e.jsxs("div",{className:"chat-info-card",children:[e.jsxs("button",{type:"button",className:"chat-info-card-title chat-info-card-title-button",onClick:()=>h(u=>!u),"aria-expanded":p,children:[e.jsx(ts,{size:14})," Slash commands",e.jsx("span",{className:"chat-info-card-count",children:l.length}),e.jsx(Le,{size:12,className:`chat-info-card-chevron ${p?"open":""}`})]}),p&&e.jsx("ul",{className:"mod-mini-list",children:N.map(u=>e.jsxs("li",{children:[e.jsx("code",{children:u.cmd}),e.jsx("span",{className:"muted",children:u.desc})]},u.cmd))})]})]})}function Xs({snapshot:t,settings:s,setActiveTab:i,initialTaskId:c,onClearTaskId:o}){const d=gs(),r=fs(),l=Ls(t,s,c??"");a.useEffect(()=>{l.setToast({error:z=>d.error(z),success:z=>d.success(z),info:z=>d.info(z),warning:z=>d.warning(z)})},[l,d]);const[m,x]=a.useState(""),[n,f]=a.useState(s.defaultAgent||"odin"),[v,p]=a.useState(s.defaultModel||""),[h,b]=a.useState([]),[N,g]=a.useState(!1),[u,S]=a.useState(!1),C=a.useRef(null),{allCommands:_,suggestions:P,setQuery:T}=Os(t);a.useEffect(()=>{T(m)},[m,T]);const L=()=>{var z;return(z=C.current)==null?void 0:z.click()},j=z=>{const Y=z.target.files;if(!Y)return;const oe=[];for(let Q=0;Q<Y.length;Q++)oe.push(Y[Q].name);b(Q=>{const K=oe.filter(Z=>!Q.includes(Z));return[...Q,...K]}),C.current&&(C.current.value="")},w=async()=>{const z=m.trim();if(!z)return;x(""),T(""),(await l.onSend(z,n,v,h)).ok&&l.jumpToLatest()},k=async()=>{l.busy.create||(await l.onCreateSession(),g(!1))},R=z=>{r.open({title:"Delete message?",children:e.jsx("p",{style:{margin:0},children:"This action cannot be undone."}),footer:e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[e.jsx(Ne,{variant:"secondary",size:"sm",onClick:()=>r.close(),children:"Cancel"}),e.jsx(Ne,{variant:"danger",size:"sm",onClick:()=>{r.close(),l.deleteMessage(z)},children:"Delete"})]})})},B=(z,Y)=>{r.open({title:"Delete session?",children:e.jsxs("p",{style:{margin:0},children:["Delete ",e.jsx("strong",{children:Y}),"? This cannot be undone."]}),footer:e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[e.jsx(Ne,{variant:"secondary",size:"sm",onClick:()=>r.close(),children:"Cancel"}),e.jsx(Ne,{variant:"danger",size:"sm",onClick:async()=>{r.close(),await l.deleteSession(z)},children:"Delete"})]})})};return e.jsxs("div",{className:"chat-shell",children:[e.jsx(Ss,{activeProject:t.activeProject,sessionCount:l.sessions.length,sessionsOpen:N,infoOpen:u,onToggleSessions:()=>g(z=>!z),onToggleInfo:()=>S(z=>!z),onOpenOverview:()=>i==null?void 0:i("overview")}),e.jsxs("div",{className:"chat-body",children:[e.jsx("aside",{className:`chat-sessions ${N?"":"chat-sessions-hidden"}`,children:e.jsx(Gs,{sessions:l.sessions,opencodeSessions:l.opencodeSessions,activeSessionId:l.sessionId,activeOpencodeSessionId:l.activeOpencodeSessionId,activeProject:t.activeProject,onCreateSession:k,onSelectSession:l.selectBizarSession,onSelectOpencodeSession:z=>l.loadOpencodeSession(z.id),creating:l.busy.create})}),e.jsxs("main",{className:"chat-main",children:[e.jsx(As,{messages:l.activeSource==="opencode"?l.opencodeMessages:l.bizarMessages,loading:l.loading,activeProject:t.activeProject,sessionId:l.activeSource==="opencode"?l.activeOpencodeSessionId??l.sessionId:l.sessionId,pinned:l.pinned,activeSource:l.activeSource,onPickSuggestion:z=>x(z),onCopy:z=>l.copyMessage(z),onDelete:R,onTogglePin:l.togglePin,onRegenerate:l.onRegenerate}),e.jsx(Qs,{agent:n,setAgent:f,model:v,setModel:p,text:m,setText:x,sending:l.sending,activeSource:l.activeSource,onSend:w,attachments:h,setAttachments:b,suggestions:P,onPickSuggestion:z=>x(`${z.split(" ")[0]} `),agents:t.agents||[],onAttach:L,sessionsOpen:N,infoOpen:u}),e.jsx("input",{ref:C,type:"file",multiple:!0,style:{display:"none"},onChange:j})]}),e.jsx("aside",{className:`chat-info ${u?"":"chat-info-hidden"}`,children:e.jsx(Js,{sessionId:l.activeSource==="opencode"?l.activeOpencodeSessionId??l.sessionId:l.sessionId,messages:l.activeSource==="opencode"?l.opencodeMessages:l.bizarMessages,pinned:l.pinned,agent:n,model:v,agents:t.agents||[],mcps:t.mcps||[],allCommands:_,activeSource:l.activeSource,onDelete:()=>{const z=l.activeSource==="opencode"?l.activeOpencodeSessionId:l.sessionId;z&&B(z,z)}})})]})]})}function Zs({onBack:t}){const[s,i]=a.useState([]),[c,o]=a.useState(!0),[d,r]=a.useState({}),[l,m]=a.useState(!1),x=async()=>{try{const b=await E.get("/config"),N=Object.entries(b).map(([g,u])=>({key:g,value:u,type:n(u)}));i(N),r(Object.fromEntries(Object.entries(b).map(([g,u])=>[g,u])))}catch{}finally{o(!1)}};a.useEffect(()=>{x()},[]);const n=b=>typeof b=="boolean"?"boolean":typeof b=="number"?"number":typeof b=="string"?"string":Array.isArray(b)?"array":b&&typeof b=="object"?"object":"unknown",f=(b,N)=>{r(g=>({...g,[b]:N}))},v=async()=>{m(!0);try{await E.patch("/config",d),await x()}catch{}finally{m(!1)}},p=(b,N)=>{r(g=>({...g,[b]:N}))},h=b=>{const N=d[b.key];switch(b.type){case"boolean":return e.jsxs("label",{className:"mobile-toggle",children:[e.jsx("input",{type:"checkbox",checked:!!N,onChange:g=>f(b.key,g.target.checked)}),e.jsx("span",{className:"mobile-toggle-slider"})]});case"number":return e.jsx("input",{className:"mobile-input mobile-input-sm",type:"number",inputMode:"numeric",value:String(N??""),onChange:g=>f(b.key,Number(g.target.value))});case"string":return e.jsx("input",{className:"mobile-input mobile-input-sm",type:"text",value:String(N??""),onChange:g=>f(b.key,g.target.value)});case"object":case"array":return e.jsx("textarea",{className:"mobile-input mobile-input-sm",rows:2,value:JSON.stringify(N??null,null,2),onChange:g=>{try{f(b.key,JSON.parse(g.target.value))}catch{}}});default:return e.jsx("span",{className:"mobile-setting-value mono",children:String(N??"null")})}};return e.jsxs("div",{className:"mobile-view",children:[e.jsxs("div",{className:"mobile-tasks-toolbar",children:[e.jsxs("span",{style:{fontSize:14,color:"var(--text-muted)",flex:1},children:[s.length," config entries"]}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>x(),"aria-label":"Refresh",children:e.jsx(de,{size:16})}),e.jsxs("button",{type:"button",className:"mobile-btn",disabled:l,onClick:()=>v(),children:[e.jsx(bt,{size:14})," ",l?"Saving…":"Save all"]})]}),c?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading…"})}):s.length===0?e.jsxs("div",{className:"mobile-empty",children:[e.jsx(we,{size:40}),e.jsx("p",{children:"No config entries."})]}):e.jsx("div",{className:"mobile-config-list",children:s.map(b=>e.jsxs("div",{className:"mobile-config-row",children:[e.jsxs("div",{className:"mobile-config-key",children:[e.jsx("span",{className:"mono",children:b.key}),e.jsx("span",{className:"mobile-config-type",children:b.type})]}),e.jsx("div",{className:"mobile-config-value",children:h(b)}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>p(b.key,b.defaultValue),"aria-label":"Reset to default",title:"Reset",children:e.jsx(ss,{size:14})})]},b.key))})]})}function en({onBack:t}){const[s,i]=a.useState([]),[c,o]=a.useState(!0),[d,r]=a.useState(null),[l,m]=a.useState(""),x=async()=>{try{const p=await E.get("/history");if(Array.isArray(p.history)){i(p.history);return}if(Array.isArray(p.projects)){const h=new Map;for(const b of p.events||[]){const N=b.projectId;if(!N)continue;const g=h.get(N);(!g||new Date(b.ts).getTime()>new Date(g.ts).getTime())&&h.set(N,b)}i(p.projects.map(b=>{const N=h.get(b.id);return{id:b.id,ts:b.lastAccessed||(N==null?void 0:N.ts)||new Date(0).toISOString(),agent:b.name,taskCount:b.tasks.total,summary:`${b.path} · ${b.tasks.done}/${b.tasks.total} done · ${b.plans} plan${b.plans===1?"":"s"}`,output:N?`${N.kind}${N.text?` — ${N.text}`:""}`:"No recent events."}}));return}i([])}catch{}finally{o(!1)}};a.useEffect(()=>{x()},[]);const n=p=>{if(!p)return"—";const h=Math.floor(p/1e3);if(h<60)return`${h}s`;const b=Math.floor(h/60),N=h%60;return`${b}m ${N}s`},f=p=>new Date(p).toLocaleString(),v=l.trim()?s.filter(p=>{const h=l.toLowerCase();return(p.agent||"session").toLowerCase().includes(h)||(p.summary||"").toLowerCase().includes(h)||(p.output||"").toLowerCase().includes(h)}):s;return e.jsxs("div",{className:"mobile-view",children:[e.jsxs("div",{className:"mobile-tasks-toolbar",children:[e.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search history…",value:l,onChange:p=>m(p.target.value),style:{flex:1}}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>x(),"aria-label":"Refresh",children:e.jsx(de,{size:16})})]}),c?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading…"})}):v.length===0?e.jsxs("div",{className:"mobile-empty",children:[e.jsx(Fe,{size:40}),e.jsx("p",{children:s.length===0?"No history yet.":"No matching sessions."})]}):e.jsx("div",{className:"mobile-card-list",children:v.map(p=>e.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>r(p),children:[e.jsx("div",{className:"mobile-list-icon",children:e.jsx(Fe,{size:16})}),e.jsxs("div",{className:"mobile-list-content",children:[e.jsx("span",{className:"mobile-list-title",children:p.agent||"Session"}),e.jsxs("span",{className:"mobile-list-meta",children:[f(p.ts),p.duration?` · ${n(p.duration)}`:"",p.taskCount?` · ${p.taskCount} tasks`:""]})]})]},p.id))}),d&&e.jsxs(re,{open:!0,onClose:()=>r(null),title:"Session Detail",children:[e.jsxs("div",{className:"mobile-agent-detail-meta",children:[e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Agent"}),e.jsx("span",{children:d.agent||"—"})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Started"}),e.jsx("span",{children:f(d.ts)})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Duration"}),e.jsx("span",{children:n(d.duration)})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Tasks"}),e.jsx("span",{children:d.taskCount||0})]})]}),d.summary&&e.jsxs("div",{style:{marginTop:12},children:[e.jsx("h4",{style:{fontSize:12,color:"var(--text-muted)",marginBottom:4},children:"Summary"}),e.jsx("p",{style:{fontSize:13},children:d.summary})]}),d.output&&e.jsxs("div",{style:{marginTop:12},children:[e.jsx("h4",{style:{fontSize:12,color:"var(--text-muted)",marginBottom:4},children:"Output"}),e.jsxs("pre",{className:"mono",style:{fontSize:11,whiteSpace:"pre-wrap",wordBreak:"break-all",background:"var(--bg-elev-2)",padding:8,borderRadius:6},children:[d.output.slice(0,1e3),d.output.length>1e3?"…":""]})]})]})]})}function tn({snapshot:t,onBack:s}){const[i,c]=a.useState(t.mods||[]),[o,d]=a.useState(!t.mods),[r,l]=a.useState(""),[m,x]=a.useState("all"),[n,f]=a.useState(null),v=async()=>{try{const b=await E.get("/mods");c(b.mods||[])}catch{}finally{d(!1)}};a.useEffect(()=>{t.mods?(c(t.mods),d(!1)):v()},[t.mods]);const p=async(b,N)=>{try{await E.patch(`/mods/${encodeURIComponent(b)}`,{enabled:N}),c(g=>g.map(u=>u.id===b?{...u,enabled:N}:u)),(n==null?void 0:n.id)===b&&f(g=>g&&{...g,enabled:N})}catch{}},h=i.filter(b=>{if(m==="enabled"&&!b.enabled||m==="disabled"&&b.enabled)return!1;if(r){const N=r.toLowerCase();return b.name.toLowerCase().includes(N)||b.description.toLowerCase().includes(N)}return!0});return e.jsxs("div",{className:"mobile-view",children:[e.jsxs("div",{className:"mobile-tasks-toolbar",children:[e.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search mods…",value:r,onChange:b=>l(b.target.value),style:{flex:1}}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>v(),"aria-label":"Refresh",children:e.jsx(de,{size:16})})]}),e.jsx("div",{className:"mobile-search-scopes",children:["all","enabled","disabled"].map(b=>e.jsx("button",{type:"button",className:`mobile-scope-chip ${m===b?"active":""}`,onClick:()=>x(b),children:b.charAt(0).toUpperCase()+b.slice(1)},b))}),o?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading…"})}):h.length===0?e.jsxs("div",{className:"mobile-empty",children:[e.jsx(we,{size:40}),e.jsx("p",{children:"No mods found."})]}):e.jsx("div",{className:"mobile-card-list",children:h.map(b=>e.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>f(b),children:[e.jsx("div",{className:"mobile-list-icon",children:e.jsx(we,{size:16})}),e.jsxs("div",{className:"mobile-list-content",children:[e.jsx("span",{className:"mobile-list-title",children:b.name}),e.jsxs("span",{className:"mobile-list-meta",children:["v",b.version," · ",b.author]})]}),e.jsx("span",{className:`mobile-list-badge ${b.enabled?"badge-on":"badge-off"}`,children:b.enabled?"on":"off"})]},b.id))}),n&&e.jsx(re,{open:!0,onClose:()=>f(null),title:n.name,actions:e.jsx("div",{className:"mobile-task-detail-actions",children:e.jsxs("button",{type:"button",className:"mobile-btn",style:{flex:1},onClick:()=>{n&&p(n.id,!n.enabled)},children:[e.jsx(pt,{size:14})," ",n.enabled?"Disable":"Enable"]})}),children:e.jsxs("div",{className:"mobile-agent-detail",children:[e.jsx("p",{className:"mobile-agent-detail-desc",children:n.description||"No description."}),e.jsxs("div",{className:"mobile-agent-detail-meta",children:[e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Version"}),e.jsx("span",{className:"mono",children:n.version})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Author"}),e.jsx("span",{children:n.author})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Bizar"}),e.jsx("span",{className:"mono",children:n.bizar})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Type"}),e.jsx("span",{children:n.type})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Permissions"}),e.jsx("span",{children:n.permissions.length})]}),n.installedAt&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Installed"}),e.jsx("span",{children:new Date(n.installedAt).toLocaleDateString()})]})]})]})})]})}function sn({snapshot:t,onNavigate:s}){var r,l,m;const[i,c]=a.useState(""),o=[{id:"artifacts",icon:je,label:"Plans",count:t.artifacts.length||0,desc:"Visual artifacts with elements & comments"},{id:"agents",icon:Ce,label:"Agents",count:((r=t.agents)==null?void 0:r.length)||0,desc:"The Norse pantheon"},{id:"skills",icon:we,label:"Skills",count:null,desc:"Agent capabilities & tools"},{id:"mods",icon:we,label:"Mods",count:((l=t.mods)==null?void 0:l.length)||0,desc:"Installed modifications"},{id:"schedules",icon:_e,label:"Schedules",count:((m=t.schedules)==null?void 0:m.length)||0,desc:"Cron jobs & automated tasks"},{id:"history",icon:Fe,label:"History",count:null,desc:"Past sessions & outputs"},{id:"config",icon:ft,label:"Config",count:null,desc:"Key-value configuration editor"}],d=i.trim()?o.filter(x=>x.label.toLowerCase().includes(i.toLowerCase())||x.desc.toLowerCase().includes(i.toLowerCase())):o;return e.jsxs("div",{className:"mobile-view",children:[e.jsx("div",{className:"mobile-tasks-toolbar",children:e.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search…",value:i,onChange:x=>c(x.target.value),style:{flex:1}})}),e.jsx("div",{className:"mobile-card-list",children:d.map(x=>{const n=x.icon;return e.jsxs("button",{type:"button",className:"mobile-more-nav-item",onClick:()=>s(x.id),children:[e.jsx("div",{className:"mobile-more-nav-icon",children:e.jsx(n,{size:20})}),e.jsxs("div",{className:"mobile-more-nav-content",children:[e.jsxs("span",{className:"mobile-more-nav-label",children:[x.label,x.count!=null&&e.jsx("span",{className:"mobile-more-nav-count",children:x.count})]}),e.jsx("span",{className:"mobile-more-nav-desc",children:x.desc})]}),e.jsx(Je,{size:16,className:"mobile-more-nav-arrow"})]},x.id)})}),e.jsx("div",{className:"mobile-more-footer",children:e.jsxs("a",{href:"/?desktop=1",className:"mobile-more-link",children:["Switch to Desktop ",e.jsx(Je,{size:14})]})})]})}const Ke=[{id:"task",label:"Task",color:"var(--info)"},{id:"note",label:"Note",color:"var(--text-dim)"},{id:"decision",label:"Decision",color:"var(--accent)"},{id:"question",label:"Question",color:"var(--warning)"}];function Be(t){var s;return((s=Ke.find(i=>i.id===t))==null?void 0:s.color)||"var(--text-dim)"}function nn({type:t,size:s=12}){switch(t){case"task":return e.jsx(De,{size:s,style:{color:"var(--info)"}});case"note":return e.jsx(Xe,{size:s,style:{color:"var(--text-dim)"}});case"decision":return e.jsx(De,{size:s,style:{color:"var(--accent)"}});case"question":return e.jsx(ns,{size:s,style:{color:"var(--warning)"}});default:return e.jsx(Xe,{size:s})}}function an({slug:t,onBack:s}){const[i,c]=a.useState(null),[o,d]=a.useState(null),[r,l]=a.useState(!0),[m,x]=a.useState(!1),[n,f]=a.useState(null),[v,p]=a.useState(!1),[h,b]=a.useState(!1),[N,g]=a.useState(!1),[u,S]=a.useState(""),C=async()=>{l(!0);try{const j=await E.get(`/plans/${encodeURIComponent(t)}`);c(j.canvas),d(j.meta)}catch{}finally{l(!1)}};a.useEffect(()=>{C()},[t]);const _=async(j,w,k)=>{try{const R=((i==null?void 0:i.elements)||[]).reduce((z,Y)=>Math.max(z,Y.x||0),40),B=((i==null?void 0:i.elements)||[]).reduce((z,Y)=>Math.max(z,Y.y||0),40);await E.post(`/plans/${encodeURIComponent(t)}/elements`,{type:j,title:w,content:k,x:20+R,y:20+B,width:240,height:120}),await C(),b(!1)}catch{}},P=async(j,w)=>{try{await E.put(`/plans/${encodeURIComponent(t)}/elements/${encodeURIComponent(j)}`,w),await C(),f(null)}catch{}},T=async j=>{if(confirm("Delete this element?"))try{await E.del(`/plans/${encodeURIComponent(t)}/elements/${encodeURIComponent(j)}`),f(null),await C()}catch{}},L=async(j,w)=>{try{const k=w?`/plans/${encodeURIComponent(t)}/elements/${encodeURIComponent(w)}/comments`:`/plans/${encodeURIComponent(t)}/comments`;await E.post(k,{text:j,elementId:w}),await C(),S(""),g(!1)}catch{}};return r||!i||!o?e.jsx("div",{className:"mobile-view",children:e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading canvas…"})})}):e.jsxs("div",{className:"mobile-view mobile-view-canvas",children:[e.jsxs("div",{className:"mobile-canvas-bar",children:[e.jsxs("div",{className:"mobile-canvas-meta",children:[e.jsx("span",{className:"mobile-canvas-title",children:o.title||t}),e.jsx("span",{className:"mobile-canvas-status","data-status":o.status,children:o.status})]}),e.jsxs("div",{className:"mobile-canvas-actions",children:[e.jsx("button",{type:"button",className:`mobile-icon-btn ${m?"active":""}`,onClick:()=>x(j=>!j),"aria-label":m?"Done editing":"Edit",children:e.jsx(He,{size:16})}),e.jsxs("button",{type:"button",className:"mobile-icon-btn",onClick:()=>p(j=>!j),"aria-label":"Comments",children:[e.jsx(ge,{size:16}),i.comments.length>0&&e.jsx("span",{className:"mobile-canvas-comment-count",children:i.comments.length})]}),m&&e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>b(!0),"aria-label":"Add element",children:e.jsx(le,{size:16})})]})]}),e.jsxs("div",{className:"mobile-canvas-elements",children:[i.elements.length===0&&e.jsxs("div",{className:"mobile-empty",children:[e.jsx("p",{children:"No elements yet."}),m&&e.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>b(!0),children:[e.jsx(le,{size:14})," Add Element"]})]}),i.elements.map(j=>e.jsxs("button",{type:"button",className:`mobile-canvas-element ${(n==null?void 0:n.id)===j.id?"selected":""}`,style:{borderColor:Be(j.type)},onClick:()=>{m&&f(j)},"aria-pressed":(n==null?void 0:n.id)===j.id,children:[e.jsxs("div",{className:"mobile-canvas-el-header",style:{background:`${Be(j.type)}18`},children:[e.jsx(nn,{type:j.type,size:12}),e.jsx("span",{className:"mobile-canvas-el-type",style:{color:Be(j.type)},children:j.type}),j.status&&j.status!=="open"&&e.jsx("span",{className:"mobile-canvas-el-status",children:j.status})]}),e.jsx("div",{className:"mobile-canvas-el-title",children:j.title||"Untitled"}),j.content&&e.jsxs("div",{className:"mobile-canvas-el-content",children:[j.content.slice(0,120),j.content.length>120?"…":""]}),e.jsxs("div",{className:"mobile-canvas-el-comments",children:[e.jsx(ge,{size:10}),i.comments.filter(w=>w.elementId===j.id).length]})]},j.id))]}),v&&e.jsxs("div",{className:"mobile-canvas-comments",children:[e.jsxs("div",{className:"mobile-canvas-comments-header",children:[e.jsxs("h4",{children:["Comments (",i.comments.length,")"]}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>p(!1),children:e.jsx(ve,{size:16})})]}),e.jsxs("div",{className:"mobile-canvas-comment-list",children:[i.comments.length===0&&e.jsx("p",{className:"mobile-empty-inline",children:"No comments yet."}),i.comments.map(j=>e.jsxs("div",{className:"mobile-canvas-comment",children:[e.jsxs("div",{className:"mobile-canvas-comment-head",children:[e.jsx("span",{className:"mono",children:j.author}),e.jsx("span",{className:"muted",children:ke(j.created)})]}),e.jsx("div",{className:"mobile-canvas-comment-text",children:j.text})]},j.id))]}),e.jsxs("div",{className:"mobile-canvas-comment-input",children:[e.jsx("textarea",{className:"mobile-input",rows:2,placeholder:"Add a comment…",value:u,onChange:j=>S(j.target.value)}),e.jsx("button",{type:"button",className:"mobile-btn",disabled:!u.trim(),onClick:()=>{L(u.trim(),null)},children:"Post"})]})]}),n&&e.jsx(re,{open:!0,onClose:()=>f(null),title:`Edit ${n.title||n.type}`,actions:e.jsxs("div",{className:"mobile-task-detail-actions",children:[e.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>T(n.id),children:[e.jsx(Se,{size:14})," Delete"]}),e.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>g(!0),children:[e.jsx(ge,{size:14})," Comment"]})]}),children:e.jsx(ln,{element:n,onSave:j=>P(n.id,j),onClose:()=>f(null)})}),e.jsx(on,{open:h,onClose:()=>b(!1),onAdd:_}),e.jsx(xe,{open:N,onClose:()=>g(!1),title:"Add Comment",actions:e.jsxs("button",{type:"button",className:"mobile-btn",style:{width:"100%"},disabled:!u.trim(),onClick:()=>{L(u.trim(),(n==null?void 0:n.id)||null),g(!1)},children:[e.jsx(ge,{size:14})," Post"]}),children:e.jsx("textarea",{className:"mobile-input",rows:3,placeholder:"Your comment…",value:u,onChange:j=>S(j.target.value),autoFocus:!0})})]})}function ln({element:t,onSave:s,onClose:i}){const[c,o]=a.useState(t.type),[d,r]=a.useState(t.title||""),[l,m]=a.useState(t.content||""),[x,n]=a.useState(t.status||"open");return e.jsxs("form",{className:"mobile-task-form",onSubmit:f=>{f.preventDefault(),s({type:c,title:d,content:l,status:x}),i()},children:[e.jsx("label",{className:"mobile-field-label",children:"Type"}),e.jsx("select",{className:"mobile-input",value:c,onChange:f=>o(f.target.value),children:Ke.map(f=>e.jsx("option",{value:f.id,children:f.label},f.id))}),e.jsx("label",{className:"mobile-field-label",children:"Title"}),e.jsx("input",{className:"mobile-input",type:"text",value:d,onChange:f=>r(f.target.value)}),e.jsx("label",{className:"mobile-field-label",children:"Status"}),e.jsx("input",{className:"mobile-input",type:"text",value:x,onChange:f=>n(f.target.value),placeholder:"open / done / blocked"}),e.jsx("label",{className:"mobile-field-label",children:"Content (markdown)"}),e.jsx("textarea",{className:"mobile-input",rows:4,value:l,onChange:f=>m(f.target.value)}),e.jsx("button",{type:"submit",className:"mobile-btn",style:{width:"100%",marginTop:8},children:"Save"})]})}function on({open:t,onClose:s,onAdd:i}){const[c,o]=a.useState("task"),[d,r]=a.useState(""),[l,m]=a.useState(""),x=n=>{n.preventDefault(),d.trim()&&(i(c,d.trim(),l.trim()),r(""),m(""))};return e.jsx(xe,{open:t,onClose:s,title:"Add Element",actions:e.jsxs("button",{type:"submit",form:"add-el-form",className:"mobile-btn",style:{width:"100%"},children:[e.jsx(le,{size:14})," Add"]}),children:e.jsxs("form",{id:"add-el-form",onSubmit:x,className:"mobile-task-form",children:[e.jsx("label",{className:"mobile-field-label",children:"Type"}),e.jsx("select",{className:"mobile-input",value:c,onChange:n=>o(n.target.value),children:Ke.map(n=>e.jsx("option",{value:n.id,children:n.label},n.id))}),e.jsx("label",{className:"mobile-field-label",children:"Title *"}),e.jsx("input",{className:"mobile-input",type:"text",placeholder:"Element title",value:d,onChange:n=>r(n.target.value),autoFocus:!0,required:!0}),e.jsx("label",{className:"mobile-field-label",children:"Content (markdown)"}),e.jsx("textarea",{className:"mobile-input",rows:3,placeholder:"Description…",value:l,onChange:n=>m(n.target.value)})]})})}function cn({snapshot:t,onBack:s,onOpenArtifact:i}){const[c,o]=a.useState(t.artifacts||[]),[d,r]=a.useState(!t.artifacts),[l,m]=a.useState(""),[x,n]=a.useState(!1),[f,v]=a.useState(""),[p,h]=a.useState(""),b=async()=>{try{const u=await E.get("/artifacts");o(u.artifacts||[])}catch{}finally{r(!1)}},N=async()=>{if(f.trim())try{const u=await E.post("/artifacts",{slug:f.trim(),title:p.trim()||void 0});n(!1),v(""),h(""),i(u.slug)}catch{}},g=l.trim()?c.filter(u=>(u.title||u.slug||"").toLowerCase().includes(l.toLowerCase())):c;return e.jsxs("div",{className:"mobile-view",children:[e.jsxs("div",{className:"mobile-tasks-toolbar",children:[e.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search artifacts…",value:l,onChange:u=>m(u.target.value),style:{flex:1}}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>b(),"aria-label":"Refresh",children:e.jsx(de,{size:16})})]}),e.jsx("div",{style:{marginBottom:12},children:e.jsxs("button",{type:"button",className:"mobile-btn",style:{width:"100%"},onClick:()=>n(!0),children:[e.jsx(le,{size:14})," New Artifact"]})}),d?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading…"})}):g.length===0?e.jsxs("div",{className:"mobile-empty",children:[e.jsx(je,{size:40}),e.jsx("p",{children:"No artifacts yet."})]}):e.jsx("div",{className:"mobile-card-list",children:g.map(u=>e.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>i(u.slug),children:[e.jsx("div",{className:"mobile-list-icon",children:e.jsx(je,{size:16})}),e.jsxs("div",{className:"mobile-list-content",children:[e.jsx("span",{className:"mobile-list-title",children:u.title||u.slug}),e.jsxs("span",{className:"mobile-list-meta",children:[u.status," · ",u.source,u.elementCount!=null?` · ${u.elementCount} elements`:"",u.commentCount!=null?` · ${u.commentCount} comments`:""]})]}),e.jsx("span",{className:"mobile-list-badge","data-status":u.status,children:u.status})]},u.slug))}),e.jsx(xe,{open:x,onClose:()=>n(!1),title:"New Artifact",actions:e.jsxs("button",{type:"submit",form:"new-plan-form",className:"mobile-btn",style:{width:"100%"},children:[e.jsx(le,{size:14})," Create"]}),children:e.jsxs("form",{id:"new-plan-form",onSubmit:u=>{u.preventDefault(),N()},className:"mobile-task-form",children:[e.jsx("label",{className:"mobile-field-label",children:"Slug *"}),e.jsx("input",{className:"mobile-input",type:"text",placeholder:"my-plan",pattern:"[a-z0-9][a-z0-9-]{0,63}",value:f,onChange:u=>v(u.target.value),autoFocus:!0,required:!0}),e.jsx("label",{className:"mobile-field-label",children:"Title (optional)"}),e.jsx("input",{className:"mobile-input",type:"text",placeholder:"My Artifact",value:p,onChange:u=>h(u.target.value)})]})})]})}const rn=["cron","interval","once"],dn=["command","agent","webhook"],ot=["UTC","America/New_York","America/Los_Angeles","Europe/London","Europe/Berlin","Asia/Tokyo"],kt=Array.from({length:24},(t,s)=>({value:s,label:s===0?"12 AM":s<12?`${s} AM`:s===12?"12 PM":`${s-12} PM`})),mn=Array.from({length:12},(t,s)=>s*5),wt=[{value:"*",label:"Every day"},{value:"0",label:"Sun"},{value:"1",label:"Mon"},{value:"2",label:"Tue"},{value:"3",label:"Wed"},{value:"4",label:"Thu"},{value:"5",label:"Fri"},{value:"6",label:"Sat"}],un=[{value:"s",label:"sec"},{value:"m",label:"min"},{value:"h",label:"hr"},{value:"d",label:"day"}];function hn({snapshot:t}){var N;const[s,i]=a.useState(t.schedules||[]),[c,o]=a.useState(!t.schedules),[d,r]=a.useState(""),[l,m]=a.useState(null),[x,n]=a.useState({open:!1}),f=async()=>{try{const g=await E.get("/schedules");i(g.schedules||[])}catch{}finally{o(!1)}};a.useEffect(()=>{t.schedules?(i(t.schedules),o(!1)):f()},[t.schedules]);const v=async(g,u)=>{try{await E.patch(`/schedules/${encodeURIComponent(g)}`,{enabled:u}),i(S=>S.map(C=>C.id===g?{...C,enabled:u}:C)),(l==null?void 0:l.id)===g&&m(S=>S&&{...S,enabled:u})}catch{}},p=async g=>{if(confirm("Delete this schedule?"))try{await E.del(`/schedules/${encodeURIComponent(g)}`),i(u=>u.filter(S=>S.id!==g)),(l==null?void 0:l.id)===g&&m(null)}catch{}},h=async g=>{try{await E.post(`/schedules/${encodeURIComponent(g)}/trigger`)}catch{}},b=d.trim()?s.filter(g=>g.name.toLowerCase().includes(d.toLowerCase())):s;return e.jsxs("div",{className:"mobile-view",children:[e.jsxs("div",{className:"mobile-tasks-toolbar",children:[e.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search schedules…",value:d,onChange:g=>r(g.target.value),style:{flex:1}}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>f(),"aria-label":"Refresh",children:e.jsx(de,{size:16})}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>n({open:!0}),"aria-label":"New schedule",children:e.jsx(le,{size:16})})]}),c?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading…"})}):b.length===0?e.jsxs("div",{className:"mobile-empty",children:[e.jsx(_e,{size:40}),e.jsx("p",{children:"No schedules found."})]}):e.jsx("div",{className:"mobile-card-list",children:b.map(g=>e.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>m(g),children:[e.jsx("div",{className:"mobile-list-icon",children:e.jsx(_e,{size:16})}),e.jsxs("div",{className:"mobile-list-content",children:[e.jsx("span",{className:"mobile-list-title",children:g.name}),e.jsxs("span",{className:"mobile-list-meta",children:[dt(g)," ·"," ",g.nextRun?`next ${rt(g.nextRun,g.timezone)}`:"no next run"]})]}),e.jsx("span",{className:`mobile-list-badge ${g.enabled?"badge-on":"badge-off"}`,children:g.enabled?"on":"off"})]},g.id))}),l&&e.jsx(re,{open:!0,onClose:()=>m(null),title:l.name,actions:e.jsxs("div",{className:"mobile-task-detail-actions",children:[e.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>{l&&h(l.id)},children:[e.jsx(Re,{size:14})," Trigger now"]}),e.jsx("button",{type:"button",className:`mobile-btn ${l.enabled?"mobile-btn-secondary":""}`,onClick:()=>{l&&v(l.id,!l.enabled)},children:l.enabled?"Disable":"Enable"}),e.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>{l&&(n({open:!0,initial:l}),m(null))},children:[e.jsx(He,{size:14})," Edit"]}),e.jsx("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>{l&&p(l.id)},children:e.jsx(Se,{size:14})})]}),children:e.jsx("div",{className:"mobile-agent-detail",children:e.jsxs("div",{className:"mobile-agent-detail-meta",children:[e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Type"}),e.jsx("span",{children:l.type})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Schedule"}),e.jsx("span",{className:"mono",children:dt(l)||l.schedule})]}),l.timezone&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Timezone"}),e.jsx("span",{className:"mono",children:l.timezone})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Action"}),e.jsxs("span",{children:[l.action.type,": ",l.action.target]})]}),l.action.type==="agent"&&l.action.prompt&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Prompt"}),e.jsx("span",{style:{fontSize:12},children:l.action.prompt})]}),((N=l.budgetCheck)==null?void 0:N.skipIfBudgetLow)&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Budget gate"}),e.jsxs("span",{children:["skip if ≥ ",l.budgetCheck.maxConcurrent??6," concurrent"]})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Next run"}),e.jsx("span",{children:l.nextRun?rt(l.nextRun,l.timezone):"—"})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Last run"}),e.jsx("span",{children:l.lastRun?fn(l.lastRun):"—"})]}),l.lastResult&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Last result"}),e.jsx("span",{style:{fontSize:12},children:l.lastResult})]}),l.lastError&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Last error"}),e.jsx("span",{style:{fontSize:12},children:l.lastError})]})]})})}),e.jsx(pn,{open:x.open,initial:x.initial,onClose:()=>n({open:!1}),onSaved:()=>{n({open:!1}),f()}})]})}function ct(t){var c,o;if(!t)return{name:"",type:"cron",cronMinute:0,cronHour:13,cronDow:"0",intervalN:30,intervalUnit:"m",onceAt:"",timezone:"UTC",actionType:"agent",actionTarget:"",actionPrompt:"",skipIfBudgetLow:!1,maxConcurrent:6,enabled:!0};const s=t.type==="cron"?St(t.schedule):null,i=t.type==="interval"?xn(t.schedule):null;return{name:t.name||"",type:t.type,cronMinute:(s==null?void 0:s.minute)??0,cronHour:(s==null?void 0:s.hour)??9,cronDow:(s==null?void 0:s.dow)??"*",intervalN:(i==null?void 0:i.n)??30,intervalUnit:(i==null?void 0:i.unit)??"m",onceAt:t.type==="once"?gn(t.schedule):"",timezone:t.timezone||"UTC",actionType:t.action.type,actionTarget:t.action.target||"",actionPrompt:t.action.prompt||"",skipIfBudgetLow:!!((c=t.budgetCheck)!=null&&c.skipIfBudgetLow),maxConcurrent:Number.isFinite((o=t.budgetCheck)==null?void 0:o.maxConcurrent)?t.budgetCheck.maxConcurrent:6,enabled:t.enabled!==!1}}function bn(t){if(t.type==="cron")return`${t.cronMinute} ${t.cronHour} * * ${t.cronDow}`;if(t.type==="interval")return`${t.intervalN}${t.intervalUnit}`;if(!t.onceAt)return"";try{return new Date(t.onceAt).toISOString()}catch{return t.onceAt}}function pn({open:t,initial:s,onClose:i,onSaved:c}){const[o,d]=a.useState(()=>ct(s)),[r,l]=a.useState(!1);a.useEffect(()=>{t&&d(ct(s))},[t,s]);const m=(n,f)=>{d(v=>({...v,[n]:f}))},x=async n=>{if(n.preventDefault(),!o.name.trim())return;const f=bn(o);if(f){l(!0);try{const v={name:o.name.trim(),type:o.type,schedule:f,timezone:o.timezone,action:{type:o.actionType,target:o.actionTarget.trim(),...o.actionType==="agent"&&o.actionPrompt.trim()?{prompt:o.actionPrompt.trim()}:{}},budgetCheck:{maxConcurrent:o.maxConcurrent,skipIfBudgetLow:o.skipIfBudgetLow},enabled:o.enabled};s?await E.put(`/schedules/${encodeURIComponent(s.id)}`,v):await E.post("/schedules",v),c()}catch{}finally{l(!1)}}};return e.jsx(xe,{open:t,onClose:i,title:s?`Edit ${s.name}`:"New schedule",actions:e.jsxs("button",{type:"submit",form:"mobile-schedule-form",className:"mobile-btn",style:{width:"100%"},disabled:r,children:[e.jsx(le,{size:14})," ",s?"Save":"Create"]}),children:e.jsxs("form",{id:"mobile-schedule-form",onSubmit:x,className:"mobile-task-form",children:[e.jsx("label",{className:"mobile-field-label",children:"Name *"}),e.jsx("input",{className:"mobile-input",type:"text",placeholder:"Weekly review",value:o.name,onChange:n=>m("name",n.target.value),autoFocus:!0,required:!0}),e.jsx("label",{className:"mobile-field-label",children:"Type"}),e.jsx("select",{className:"mobile-input",value:o.type,onChange:n=>m("type",n.target.value),children:rn.map(n=>e.jsx("option",{value:n,children:n},n))}),o.type==="cron"&&e.jsxs(e.Fragment,{children:[e.jsx("label",{className:"mobile-field-label",children:"Day of week"}),e.jsx("select",{className:"mobile-input",value:o.cronDow,onChange:n=>m("cronDow",n.target.value),children:wt.map(n=>e.jsx("option",{value:n.value,children:n.label},n.value))}),e.jsxs("div",{className:"mobile-form-row",children:[e.jsxs("div",{style:{flex:1},children:[e.jsx("label",{className:"mobile-field-label",children:"Hour"}),e.jsx("select",{className:"mobile-input",value:String(o.cronHour),onChange:n=>m("cronHour",parseInt(n.target.value,10)),children:kt.map(n=>e.jsx("option",{value:String(n.value),children:n.label},n.value))})]}),e.jsxs("div",{style:{flex:1},children:[e.jsx("label",{className:"mobile-field-label",children:"Minute"}),e.jsx("select",{className:"mobile-input",value:String(o.cronMinute),onChange:n=>m("cronMinute",parseInt(n.target.value,10)),children:mn.map(n=>e.jsx("option",{value:String(n),children:String(n).padStart(2,"0")},n))})]})]})]}),o.type==="interval"&&e.jsxs("div",{className:"mobile-form-row",children:[e.jsxs("div",{style:{flex:1},children:[e.jsx("label",{className:"mobile-field-label",children:"Every"}),e.jsx("input",{className:"mobile-input",type:"number",min:1,value:o.intervalN,onChange:n=>m("intervalN",parseInt(n.target.value,10)||1)})]}),e.jsxs("div",{style:{flex:1},children:[e.jsx("label",{className:"mobile-field-label",children:"Unit"}),e.jsx("select",{className:"mobile-input",value:o.intervalUnit,onChange:n=>m("intervalUnit",n.target.value),children:un.map(n=>e.jsx("option",{value:n.value,children:n.label},n.value))})]})]}),o.type==="once"&&e.jsxs(e.Fragment,{children:[e.jsx("label",{className:"mobile-field-label",children:"Run at"}),e.jsx("input",{className:"mobile-input",type:"datetime-local",value:o.onceAt,onChange:n=>m("onceAt",n.target.value)})]}),e.jsx("label",{className:"mobile-field-label",children:"Timezone"}),e.jsx("select",{className:"mobile-input",value:ot.includes(o.timezone)?o.timezone:"UTC",onChange:n=>m("timezone",n.target.value),children:ot.map(n=>e.jsx("option",{value:n,children:n},n))}),e.jsx("label",{className:"mobile-field-label",children:"Action type"}),e.jsx("select",{className:"mobile-input",value:o.actionType,onChange:n=>m("actionType",n.target.value),children:dn.map(n=>e.jsx("option",{value:n,children:n},n))}),e.jsx("label",{className:"mobile-field-label",children:"Target"}),e.jsx("input",{className:"mobile-input",type:"text",placeholder:o.actionType==="webhook"?"https://...":o.actionType==="agent"?"agent or task ref":"echo hello",value:o.actionTarget,onChange:n=>m("actionTarget",n.target.value)}),o.actionType==="agent"&&e.jsxs(e.Fragment,{children:[e.jsx("label",{className:"mobile-field-label",children:"Prompt"}),e.jsx("textarea",{className:"mobile-input",rows:3,placeholder:"What should the agent do?",value:o.actionPrompt,onChange:n=>m("actionPrompt",n.target.value)})]}),e.jsxs("fieldset",{className:"mobile-budget-card",children:[e.jsx("legend",{children:"Budget pre-flight"}),e.jsxs("label",{className:"mobile-checkbox-row",children:[e.jsx("input",{type:"checkbox",checked:o.skipIfBudgetLow,onChange:n=>m("skipIfBudgetLow",n.target.checked)}),e.jsx("span",{children:"Skip if too many bg tasks are running"})]}),e.jsx("label",{className:"mobile-field-label",children:"Cap"}),e.jsx("input",{className:"mobile-input",type:"number",min:1,max:64,value:o.maxConcurrent,onChange:n=>m("maxConcurrent",parseInt(n.target.value,10)||6),disabled:!o.skipIfBudgetLow})]}),e.jsxs("label",{className:"mobile-checkbox-row",children:[e.jsx("input",{type:"checkbox",checked:o.enabled,onChange:n=>m("enabled",n.target.checked)}),e.jsx("span",{children:"Enabled"})]})]})})}function fn(t){const s=Date.now()-new Date(t).getTime();return s<6e4?"just now":s<36e5?`${Math.floor(s/6e4)}m ago`:s<864e5?`${Math.floor(s/36e5)}h ago`:new Date(t).toLocaleDateString()}function rt(t,s){try{return new Date(t).toLocaleString(void 0,{timeZone:s||void 0,weekday:"short",hour:"numeric",minute:"2-digit",month:"short",day:"numeric"})}catch{return new Date(t).toLocaleString()}}function St(t){if(typeof t!="string")return null;const s=t.trim().split(/\s+/);if(s.length!==5)return null;const[i,c,,,o]=s,d=parseInt(i,10),r=parseInt(c,10);return!Number.isFinite(d)||!Number.isFinite(r)||i!==String(d)||c!==String(r)?null:{minute:d,hour:r,dow:o==="*"?"*":Number.isFinite(parseInt(o,10))?o:"*"}}function xn(t){if(typeof t!="string")return null;const s=/^(\d+)([smhd])$/i.exec(t.trim());return s?{n:parseInt(s[1],10),unit:s[2].toLowerCase()}:null}function gn(t){if(!t)return"";try{const s=new Date(t);if(Number.isNaN(s.getTime()))return"";const i=c=>String(c).padStart(2,"0");return`${s.getFullYear()}-${i(s.getMonth()+1)}-${i(s.getDate())}T${i(s.getHours())}:${i(s.getMinutes())}`}catch{return""}}function dt(t){var d,r;if(t.type!=="cron")return t.schedule;const s=St(t.schedule);if(!s)return t.schedule;const i=((d=wt.find(l=>l.value===s.dow))==null?void 0:d.label)||s.dow,c=((r=kt.find(l=>l.value===s.hour))==null?void 0:r.label)||`${s.hour}`,o=String(s.minute).padStart(2,"0");return i==="Every day"?`Every day ${c} :${o}`:`Every ${i} ${c} :${o}`}const jn=["all","tasks","agents","artifacts","projects","settings"],vn={tasks:De,agents:Ce,plans:je,projects:We,settings:we};function yn({open:t,onClose:s,onNavigate:i}){const[c,o]=a.useState(""),[d,r]=a.useState("all"),[l,m]=a.useState([]),[x,n]=a.useState(!1),f=a.useRef(null);a.useEffect(()=>{t&&(o(""),m([]),requestAnimationFrame(()=>{var h;return(h=f.current)==null?void 0:h.focus()}))},[t]),a.useEffect(()=>{if(!c.trim()){m([]);return}const h=setTimeout(async()=>{n(!0);try{const b=await E.get(`/search?q=${encodeURIComponent(c)}&scope=${d}`);m(b.results||[])}catch{m([])}finally{n(!1)}},250);return()=>clearTimeout(h)},[c,d]);const v=h=>{const b=h.item,N=b.id||b.slug||b.name||"";i(h.type,N),s()},p=l.reduce((h,b)=>(h[b.type]||(h[b.type]=[]),h[b.type].push(b),h),{});return e.jsx(xe,{open:t,onClose:s,title:"Search",children:e.jsxs("div",{className:"mobile-search-container",children:[e.jsxs("div",{className:"mobile-search-input-row",children:[e.jsx(Ze,{size:16,style:{color:"var(--text-muted)",flexShrink:0}}),e.jsx("input",{ref:f,className:"mobile-search-field",type:"text",placeholder:"Search…",value:c,onChange:h=>o(h.target.value),enterKeyHint:"search",onKeyDown:h=>{h.key==="Escape"&&s(),h.key==="Enter"&&l.length>0&&v(l[0])}}),c&&e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>o(""),"aria-label":"Clear",children:e.jsx(ve,{size:16})})]}),e.jsx("div",{className:"mobile-search-scopes",children:jn.map(h=>e.jsx("button",{type:"button",className:`mobile-scope-chip ${d===h?"active":""}`,onClick:()=>r(h),children:h==="all"?"All":h.charAt(0).toUpperCase()+h.slice(1)},h))}),e.jsxs("div",{className:"mobile-search-results",children:[x&&e.jsx("div",{className:"mobile-search-loading",children:"Searching…"}),!x&&c&&l.length===0&&e.jsxs("div",{className:"mobile-empty",children:[e.jsx(Ze,{size:32}),e.jsx("p",{children:"No results found"})]}),!x&&!c&&e.jsx("div",{className:"mobile-empty",children:e.jsx("p",{children:"Type to search across tasks, agents, plans, and more."})}),Object.entries(p).map(([h,b])=>{const N=vn[h]||je;return e.jsxs("div",{className:"mobile-search-group",children:[e.jsxs("h4",{className:"mobile-search-group-title",children:[e.jsx(N,{size:12})," ",h.charAt(0).toUpperCase()+h.slice(1)," (",b.length,")"]}),b.map((g,u)=>{const S=g.item;return e.jsxs("button",{type:"button",className:"mobile-search-result-item",onClick:()=>v(g),children:[e.jsx("span",{className:"mobile-search-result-title",children:S.title||S.name||S.slug||"(unnamed)"}),S.description&&e.jsx("span",{className:"mobile-search-result-meta",children:S.description.slice(0,80)})]},u)})]},h)})]})]})})}function Nn(t){if(t<=0)return"expired";const s=Math.floor(t/1e3),i=Math.floor(s/60),c=s%60;return`${i}:${String(c).padStart(2,"0")}`}function kn({pair:t,onStart:s}){const[i,c]=a.useState(null),[o,d]=a.useState(()=>t.expiresAt-Date.now()),r=o<=0;return a.useEffect(()=>{yt(()=>import("./index-DmpSFPJY.js"),__vite__mapDeps([0,1])).then(l=>{c(l.QRCodeSVG)})},[]),a.useEffect(()=>{if(!t)return;const l=setInterval(()=>{d(t.expiresAt-Date.now())},1e3);return()=>clearInterval(l)},[t]),i?e.jsxs("div",{style:{textAlign:"center"},children:[e.jsx("div",{style:{background:"#fff",padding:12,borderRadius:12,display:"inline-block"},children:e.jsx(i,{value:t.qrPayload,size:180,level:"M"})}),e.jsxs("div",{style:{marginTop:8,fontSize:12},children:["Expires in ",e.jsx("strong",{children:Nn(o)})]}),e.jsx("div",{className:"mono",style:{fontSize:10,wordBreak:"break-all",marginTop:4},children:t.publicUrl}),r&&e.jsxs("button",{type:"button",className:"mobile-btn",onClick:s,style:{marginTop:12,width:"100%"},children:[e.jsx(de,{size:14})," Generate new QR"]})]}):e.jsx("div",{style:{textAlign:"center",padding:"16px"},children:e.jsx("span",{style:{color:"var(--text-dim)",fontSize:13},children:"Loading QR library…"})})}const wn=[{id:"dark",label:"Dark",Icon:as},{id:"light",label:"Light",Icon:is},{id:"system",label:"System",Icon:ls}],Sn=[{name:"Purple",accent:"#8b5cf6"},{name:"Blue",accent:"#3b82f6"},{name:"Green",accent:"#10b981"},{name:"Orange",accent:"#f97316"},{name:"Red",accent:"#ef4444"},{name:"Pink",accent:"#ec4899"},{name:"Cyan",accent:"#06b6d4"},{name:"Mono",accent:"#6b7280"}];function Cn({settings:t,snapshot:s,onRefresh:i}){var g,u,S,C,_,P;const[c,o]=a.useState(t),[d,r]=a.useState(!1),[l,m]=a.useState(!1),[x,n]=a.useState(null),[f,v]=a.useState(!1);a.useEffect(()=>{o(t),r(!1),t.theme&&Ee(t.theme)},[t]);const p=T=>{o(L=>{const j={...L,theme:{...L.theme,...T}};return Me(j.theme),Ee(j.theme),j}),r(!0)},h=(T,L)=>{o(j=>({...j,[T]:L})),r(!0)},b=async()=>{m(!0);try{const T=await E.put("/settings",c);o(T.data),r(!1),Me(T.data.theme),Ee(T.data.theme),i()}catch{}finally{m(!1)}},N=async()=>{v(!0);try{const T=await E.post("/pair/start");n(T)}catch{}finally{v(!1)}};return e.jsxs("div",{className:"mobile-view",children:[d&&e.jsxs("div",{className:"mobile-settings-save-bar",children:[e.jsx("span",{children:"Unsaved changes"}),e.jsxs("button",{type:"button",className:"mobile-btn",disabled:l,onClick:b,children:[e.jsx(bt,{size:14})," ",l?"Saving…":"Save"]})]}),e.jsxs("section",{className:"mobile-section",children:[e.jsx("h3",{className:"mobile-section-title",children:"Appearance"}),e.jsxs("div",{className:"mobile-card",children:[e.jsxs("div",{className:"mobile-setting-row",children:[e.jsx("span",{className:"mobile-setting-label",children:"Theme"}),e.jsx("div",{className:"mobile-theme-btns",children:wn.map(({id:T,label:L,Icon:j})=>e.jsxs("button",{type:"button",className:`mobile-theme-btn ${c.theme.mode===T?"active":""}`,onClick:()=>p({mode:T}),children:[e.jsx(j,{size:14})," ",L]},T))})]}),e.jsxs("div",{className:"mobile-setting-row",style:{flexDirection:"column",alignItems:"flex-start",gap:8},children:[e.jsx("span",{className:"mobile-setting-label",children:"Accent color"}),e.jsx("div",{className:"mobile-accent-swatches",children:Sn.map(T=>e.jsx("button",{type:"button",className:`mobile-accent-swatch ${c.theme.accent===T.accent?"active":""}`,style:{background:T.accent},onClick:()=>p({accent:T.accent}),title:T.name},T.name))})]}),e.jsxs("div",{className:"mobile-setting-row",style:{flexDirection:"column",alignItems:"flex-start",gap:8},children:[e.jsxs("span",{className:"mobile-setting-label",children:["Font size: ",c.theme.fontSize,"px"]}),e.jsx("input",{type:"range",min:12,max:20,value:c.theme.fontSize,onChange:T=>p({fontSize:Number(T.target.value)}),style:{width:"100%"}})]}),e.jsxs("div",{className:"mobile-setting-row",children:[e.jsx("span",{className:"mobile-setting-label",children:"Compact mode"}),e.jsxs("label",{className:"mobile-toggle",children:[e.jsx("input",{type:"checkbox",checked:c.theme.compactMode,onChange:T=>p({compactMode:T.target.checked})}),e.jsx("span",{className:"mobile-toggle-slider"})]})]}),e.jsxs("div",{className:"mobile-setting-row",children:[e.jsx("span",{className:"mobile-setting-label",children:"Animations"}),e.jsxs("label",{className:"mobile-toggle",children:[e.jsx("input",{type:"checkbox",checked:c.theme.animations,onChange:T=>p({animations:T.target.checked})}),e.jsx("span",{className:"mobile-toggle-slider"})]})]})]})]}),e.jsxs("section",{className:"mobile-section",children:[e.jsx("h3",{className:"mobile-section-title",children:"Chat Defaults"}),e.jsxs("div",{className:"mobile-card",children:[e.jsx("label",{className:"mobile-field-label",children:"Default Agent"}),e.jsx("select",{className:"mobile-input",value:c.defaultAgent||"odin",onChange:T=>h("defaultAgent",T.target.value),children:((s==null?void 0:s.agents)||[]).map(T=>e.jsxs("option",{value:T.name,children:["@",T.name]},T.name))}),e.jsx("label",{className:"mobile-field-label",style:{marginTop:8},children:"Default Model"}),e.jsx("input",{className:"mobile-input",type:"text",placeholder:"(auto)",value:c.defaultModel||"",onChange:T=>h("defaultModel",T.target.value)})]})]}),e.jsxs("section",{className:"mobile-section",children:[e.jsx("h3",{className:"mobile-section-title",children:"Notifications"}),e.jsxs("div",{className:"mobile-card",children:[e.jsxs("div",{className:"mobile-setting-row",children:[e.jsx("span",{className:"mobile-setting-label",children:"Agent completion"}),e.jsxs("label",{className:"mobile-toggle",children:[e.jsx("input",{type:"checkbox",checked:!!c.notifications.onAgentComplete,onChange:T=>{o(L=>({...L,notifications:{...L.notifications,onAgentComplete:T.target.checked}})),r(!0)}}),e.jsx("span",{className:"mobile-toggle-slider"})]})]}),e.jsxs("div",{className:"mobile-setting-row",children:[e.jsx("span",{className:"mobile-setting-label",children:"Plan approval"}),e.jsxs("label",{className:"mobile-toggle",children:[e.jsx("input",{type:"checkbox",checked:!!c.notifications.onPlanApproval,onChange:T=>{o(L=>({...L,notifications:{...L.notifications,onPlanApproval:T.target.checked}})),r(!0)}}),e.jsx("span",{className:"mobile-toggle-slider"})]})]})]})]}),e.jsxs("section",{className:"mobile-section",children:[e.jsx("h3",{className:"mobile-section-title",children:"Agent Behavior"}),e.jsxs("div",{className:"mobile-card",children:[e.jsx("label",{className:"mobile-field-label",children:"Max parallel agents"}),e.jsx("input",{className:"mobile-input",type:"number",inputMode:"numeric",min:1,max:20,value:((g=c.agents)==null?void 0:g.maxParallel)??6,onChange:T=>{o(L=>({...L,agents:{...L.agents,maxParallel:Math.max(1,Math.min(20,parseInt(T.target.value,10)||6))}})),r(!0)}}),e.jsx("label",{className:"mobile-field-label",style:{marginTop:8},children:"Stuck threshold (ms)"}),e.jsx("input",{className:"mobile-input",type:"number",inputMode:"numeric",min:6e4,max:36e5,step:6e4,value:((u=c.agents)==null?void 0:u.stuckThresholdMs)??6e5,onChange:T=>{o(L=>({...L,agents:{...L.agents,stuckThresholdMs:Math.max(6e4,parseInt(T.target.value,10)||6e5)}})),r(!0)}}),e.jsxs("div",{className:"mobile-setting-row",style:{marginTop:8},children:[e.jsx("span",{className:"mobile-setting-label",children:"Auto-restart stuck agents"}),e.jsxs("label",{className:"mobile-toggle",children:[e.jsx("input",{type:"checkbox",checked:!!((S=c.agents)!=null&&S.autoRestart),onChange:T=>{o(L=>({...L,agents:{...L.agents,autoRestart:T.target.checked}})),r(!0)}}),e.jsx("span",{className:"mobile-toggle-slider"})]})]})]})]}),e.jsxs("section",{className:"mobile-section",children:[e.jsx("h3",{className:"mobile-section-title",children:"Tailscale Serve"}),e.jsx("div",{className:"mobile-card",children:e.jsxs("p",{className:"muted",style:{fontSize:13},children:["Use ",e.jsx("code",{children:"bizar service"})," commands in the terminal to configure Tailscale serve."]})})]}),e.jsxs("section",{className:"mobile-section",children:[e.jsxs("h3",{className:"mobile-section-title",children:[e.jsx(et,{size:14})," Companion App"]}),e.jsxs("div",{className:"mobile-card",children:[!x&&e.jsxs("button",{type:"button",className:"mobile-btn",onClick:N,disabled:f,style:{width:"100%"},children:[e.jsx(et,{size:14})," ",f?"Generating…":"Generate QR Code"]}),x&&e.jsx(kn,{pair:x,onStart:N})]})]}),e.jsxs("section",{className:"mobile-section",children:[e.jsx("h3",{className:"mobile-section-title",children:"About"}),e.jsxs("div",{className:"mobile-card",children:[e.jsxs("div",{className:"mobile-setting-row",children:[e.jsx("span",{className:"mobile-setting-label",children:"Version"}),e.jsx("span",{className:"mobile-setting-value mono",children:((C=c.about)==null?void 0:C.version)||"—"})]}),e.jsxs("div",{className:"mobile-setting-row",children:[e.jsx("span",{className:"mobile-setting-label",children:"Agents"}),e.jsx("span",{className:"mobile-setting-value",children:((_=s==null?void 0:s.agents)==null?void 0:_.length)||0})]}),e.jsxs("div",{className:"mobile-setting-row",children:[e.jsx("span",{className:"mobile-setting-label",children:"Tasks"}),e.jsx("span",{className:"mobile-setting-value",children:((P=s==null?void 0:s.tasks)==null?void 0:P.length)||0})]}),e.jsxs("div",{className:"mobile-setting-row",children:[e.jsx("span",{className:"mobile-setting-label",children:"Plans"}),e.jsx("span",{className:"mobile-setting-value",children:(s==null?void 0:s.artifacts.length)||0})]})]})]}),e.jsx("div",{className:"mobile-view-footer",children:e.jsx("a",{href:"/?desktop=1",className:"mobile-btn mobile-btn-secondary",children:"Switch to Desktop"})})]})}const Tn=["languages","framework","design","testing","devops","data","security","integration"];function In({snapshot:t,onBack:s}){const[i,c]=a.useState([]),[o,d]=a.useState(!0),[r,l]=a.useState(""),[m,x]=a.useState(""),[n,f]=a.useState(null),v=async()=>{try{const b=await E.get("/skills");c(b.skills||[])}catch{}finally{d(!1)}};a.useEffect(()=>{v()},[]);const p=async(b,N)=>{try{await E.patch(`/skills/${encodeURIComponent(b)}`,{enabled:N}),c(g=>g.map(u=>u.id===b?{...u,enabled:N}:u)),(n==null?void 0:n.id)===b&&f(g=>g&&{...g,enabled:N})}catch{}},h=i.filter(b=>{if(m&&b.category!==m)return!1;if(r){const N=r.toLowerCase();return b.name.toLowerCase().includes(N)||b.description.toLowerCase().includes(N)}return!0});return e.jsxs("div",{className:"mobile-view",children:[e.jsxs("div",{className:"mobile-tasks-toolbar",children:[e.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search skills…",value:r,onChange:b=>l(b.target.value),style:{flex:1}}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>v(),"aria-label":"Refresh",children:e.jsx(de,{size:16})})]}),e.jsxs("div",{className:"mobile-search-scopes",children:[e.jsx("button",{type:"button",className:`mobile-scope-chip ${m?"":"active"}`,onClick:()=>x(""),children:"All"}),Tn.map(b=>e.jsx("button",{type:"button",className:`mobile-scope-chip ${m===b?"active":""}`,onClick:()=>x(b),children:b},b))]}),o?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading…"})}):h.length===0?e.jsxs("div",{className:"mobile-empty",children:[e.jsx(ze,{size:40}),e.jsx("p",{children:"No skills found."})]}):e.jsx("div",{className:"mobile-card-list",children:h.map(b=>e.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>f(b),children:[e.jsx("div",{className:"mobile-list-icon",children:e.jsx(ze,{size:16})}),e.jsxs("div",{className:"mobile-list-content",children:[e.jsx("span",{className:"mobile-list-title",children:b.name}),e.jsxs("span",{className:"mobile-list-meta",children:[b.category," · v",b.version]})]}),e.jsx("span",{className:`mobile-list-badge ${b.enabled?"badge-on":"badge-off"}`,children:b.enabled?"on":"off"})]},b.id))}),n&&e.jsx(re,{open:!0,onClose:()=>f(null),title:n.name,actions:e.jsxs("button",{type:"button",className:`mobile-btn ${n.enabled?"mobile-btn-secondary":""}`,style:{width:"100%"},onClick:()=>{n&&p(n.id,!n.enabled)},children:[e.jsx(pt,{size:14})," ",n.enabled?"Disable":"Enable"]}),children:e.jsxs("div",{className:"mobile-agent-detail",children:[e.jsx("p",{className:"mobile-agent-detail-desc",children:n.description||"No description."}),e.jsxs("div",{className:"mobile-agent-detail-meta",children:[e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Category"}),e.jsx("span",{children:n.category})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Version"}),e.jsx("span",{className:"mono",children:n.version})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Source"}),e.jsx("span",{children:n.source})]}),n.tags.length>0&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Tags"}),e.jsx("span",{children:n.tags.join(", ")})]})]})]})})]})}const En=["queued","doing","blocked","done"],Ae={queued:"Queued",doing:"Doing",blocked:"Blocked",done:"Done"},mt={queued:"doing",doing:"done",blocked:"queued",done:"queued"};function An(t){const s=t.metadata??{};return!!(s.sessionId||s.bgInstanceId)}function $n(t){var i;const s=t.metadata??{};return!!((i=s.artifactIds)!=null&&i.length||s.artifactId)}function ut({snapshot:t,onRefresh:s,selectedTaskId:i,onCloseDetail:c,onOpenChat:o,onOpenArtifact:d}){var ce,ae;const[r,l]=a.useState(t.tasks||[]),[m,x]=a.useState(!t.tasks),[n,f]=a.useState(""),[v,p]=a.useState("queued"),[h,b]=a.useState(null),[N,g]=a.useState(!1),[u,S]=a.useState(null),[C,_]=a.useState([]),[P,T]=a.useState(""),[L,j]=a.useState(null),[w,k]=a.useState(!1),[R,B]=a.useState(""),[z,Y]=a.useState("updated");a.useEffect(()=>{var I;if(t.tasks&&(l(t.tasks),x(!1)),i){const U=(I=t.tasks)==null?void 0:I.find(W=>W.id===i);U&&b(U)}},[t.tasks,i]),a.useEffect(()=>{if(i){const I=r.find(U=>U.id===i);I&&b(I)}},[i,r]);const oe=async()=>{try{const I=await E.get("/tasks");l(Array.isArray(I)?I:[])}catch{}finally{x(!1)}},Q=async(I,U)=>{l(W=>W.map(J=>J.id===I?{...J,status:U}:J)),(h==null?void 0:h.id)===I&&b(W=>W&&{...W,status:U});try{await E.patch(`/tasks/${encodeURIComponent(I)}/status`,{status:U})}catch{await oe()}},K=async I=>{if(confirm("Delete this task?"))try{await E.del(`/tasks/${encodeURIComponent(I)}`),l(U=>U.filter(W=>W.id!==I)),(h==null?void 0:h.id)===I&&b(null)}catch{await oe()}},Z=async I=>{try{await E.post(`/tasks/${encodeURIComponent(I)}/archive`),l(U=>U.filter(W=>W.id!==I)),(h==null?void 0:h.id)===I&&b(null)}catch{}},ee=[...r.filter(I=>{var U,W;if(n.trim()){const J=n.toLowerCase();if(!(I.title||"").toLowerCase().includes(J)&&!(I.description||"").toLowerCase().includes(J))return!1}if(R.trim()){const J=R==="mine"?((W=(U=t.settings)==null?void 0:U.data)==null?void 0:W.defaultAgent)||zn(t):R.replace(/^@/,"");if((I.assignee||"").toLowerCase()!==J.toLowerCase())return!1}return!0})].sort((I,U)=>{switch(z){case"priority":{const W={high:0,normal:1,low:2};return(W[I.priority]??1)-(W[U.priority]??1)}case"created":return new Date(U.createdAt).getTime()-new Date(I.createdAt).getTime();case"updated":default:return new Date(U.updatedAt).getTime()-new Date(I.updatedAt).getTime()}}),ue=ee.filter(I=>I.status===v),me=t.agents||[],be=async(I,U,W,J)=>{try{const fe=await E.post("/tasks",{title:I,description:U,assignee:W||null,priority:J});l(ye=>[fe,...ye]),g(!1)}catch{}},pe=async I=>{k(!0),T(""),j(null),S(I);try{const W=((await E.get(`/tasks/${encodeURIComponent(I)}/artifacts`)).artifacts||[]).map(J=>J.id);if(_(W),W.length>0){const[J,fe]=await Promise.all([E.get(`/artifacts/${encodeURIComponent(W[0])}`),fetch(E.urlWithToken(`/artifacts/${encodeURIComponent(W[0])}/content`)).then(ye=>ye.text())]);j(J),T(fe)}}catch{}finally{k(!1)}};return m?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading…"})}):e.jsxs("div",{className:"mobile-view mobile-view-tasks",children:[e.jsxs("div",{className:"mobile-tasks-toolbar",children:[e.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search tasks…",value:n,onChange:I=>f(I.target.value),style:{flex:1}}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>oe(),"aria-label":"Refresh",children:e.jsx(de,{size:16})})]}),e.jsxs("div",{className:"mobile-tasks-filters",children:[e.jsxs("select",{className:"mobile-filter-select",value:R,onChange:I=>B(I.target.value),children:[e.jsx("option",{value:"",children:"All"}),e.jsx("option",{value:"mine",children:"Mine"}),me.map(I=>e.jsxs("option",{value:`@${I.name}`,children:["@",I.name]},I.name))]}),e.jsxs("select",{className:"mobile-filter-select",value:z,onChange:I=>Y(I.target.value),children:[e.jsx("option",{value:"updated",children:"Updated"}),e.jsx("option",{value:"created",children:"Created"}),e.jsx("option",{value:"priority",children:"Priority"})]})]}),e.jsx("div",{className:"mobile-kanban-tabs",children:En.map(I=>{const U=ee.filter(W=>W.status===I).length;return e.jsxs("button",{type:"button",className:`mobile-kanban-tab ${v===I?"active":""}`,onClick:()=>p(I),children:[Ae[I]," (",U,")"]},I)})}),e.jsxs("div",{className:"mobile-card-list",children:[ue.length===0&&e.jsxs("div",{className:"mobile-empty mobile-empty-compact",children:[e.jsxs("p",{children:["No ",Ae[v].toLowerCase()," tasks."]}),e.jsx("p",{className:"muted",children:"Create one or switch columns."})]}),ue.map(I=>{var U;return e.jsxs("button",{type:"button",className:"mobile-task-card",onClick:()=>b(I),children:[e.jsx("div",{className:"priority-dot",style:{background:us[I.priority]||"var(--info)"}}),e.jsxs("div",{className:"task-content",children:[e.jsx("div",{className:"task-title",children:I.title}),e.jsxs("div",{className:"task-meta",children:[I.assignee?`@${I.assignee}`:"unassigned"," · ",ke(I.updatedAt||I.createdAt),(U=I.dependencies)!=null&&U.length?` · ${I.dependencies.length} deps`:""]})]})]},I.id)})]}),e.jsx("button",{type:"button",className:"mobile-fab",onClick:()=>g(!0),"aria-label":"Add task",children:e.jsx(le,{size:24})}),e.jsx(re,{open:!!h,onClose:()=>{b(null),c==null||c()},title:"Task Detail",actions:h&&e.jsxs("div",{className:"mobile-task-detail-actions",children:[h.status!=="done"&&e.jsxs("button",{type:"button",className:"mobile-btn",style:{flex:1},onClick:()=>{h&&Q(h.id,mt[h.status])},children:["Move to ",Ae[mt[h.status]||"queued"]]}),e.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>{h&&Z(h.id)},children:[e.jsx(os,{size:14})," Archive"]}),An(h)&&e.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>{o==null||o(h.id)},children:[e.jsx(ge,{size:14})," Chat"]}),$n(h)&&e.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>{pe(h.id)},children:[e.jsx(je,{size:14})," Artifact"]}),e.jsx("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>{h&&K(h.id)},children:e.jsx(Se,{size:14})})]}),children:h&&e.jsxs("div",{className:"mobile-task-detail",children:[e.jsxs("div",{className:"mobile-task-detail-header",children:[e.jsx("span",{className:`mobile-task-status-badge status-${h.status}`,children:Ae[h.status]||h.status}),e.jsx("span",{className:`mobile-task-priority priority-${h.priority}`,children:h.priority})]}),e.jsx("h3",{className:"mobile-task-detail-title",children:h.title}),h.description&&e.jsx("p",{className:"mobile-task-detail-desc",children:h.description}),e.jsxs("div",{className:"mobile-task-detail-meta",children:[h.assignee&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Assignee"}),e.jsxs("span",{children:["@",h.assignee]})]}),h.dueDate&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Due"}),e.jsx("span",{children:new Date(h.dueDate).toLocaleDateString()})]}),h.timeSpent!=null&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Time spent"}),e.jsxs("span",{children:[Math.round(h.timeSpent/6e4),"min"]})]}),(ce=h.dependencies)!=null&&ce.length?e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Dependencies"}),e.jsx("span",{children:h.dependencies.length})]}):null,(ae=h.comments)!=null&&ae.length?e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Comments"}),e.jsx("span",{children:h.comments.length})]}):null,e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Created"}),e.jsx("span",{children:ke(h.createdAt)})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Updated"}),e.jsx("span",{children:ke(h.updatedAt)})]})]})]})}),e.jsx(Rn,{open:N,onClose:()=>g(!1),onCreate:be,agents:me}),e.jsx(re,{open:!!u,onClose:()=>{S(null),T(""),j(null)},title:(L==null?void 0:L.name)||"Artifact",actions:C.length>1?e.jsx("div",{className:"mobile-task-detail-actions",children:C.map((I,U)=>e.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",style:{flex:1},onClick:()=>{k(!0),Promise.all([E.get(`/artifacts/${encodeURIComponent(I)}`),fetch(E.urlWithToken(`/artifacts/${encodeURIComponent(I)}/content`)).then(W=>W.text())]).then(([W,J])=>{j(W),T(J),k(!1)}).catch(()=>k(!1))},children:["Artifact ",U+1]},I))}):null,children:e.jsx("div",{className:"mobile-artifact-viewer",children:w?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading artifact…"})}):P?e.jsx("iframe",{srcDoc:P,className:"mobile-artifact-iframe",sandbox:"allow-scripts allow-forms allow-popups allow-same-origin",title:(L==null?void 0:L.name)||"Artifact",loading:"lazy"}):e.jsxs("div",{className:"mobile-empty",children:[e.jsx(je,{size:32}),e.jsx("p",{className:"muted",children:"No artifact content available."})]})})})]})}function zn(t){var s,i;return((i=(s=t.settings)==null?void 0:s.data)==null?void 0:i.defaultAgent)||"odin"}function Rn({open:t,onClose:s,onCreate:i,agents:c}){const[o,d]=a.useState(""),[r,l]=a.useState(""),[m,x]=a.useState(""),[n,f]=a.useState("normal"),v=p=>{p.preventDefault(),o.trim()&&(i(o.trim(),r.trim(),m,n),d(""),l(""),x(""),f("normal"))};return e.jsx(xe,{open:t,onClose:s,title:"New Task",actions:e.jsxs("button",{type:"submit",form:"new-task-form",className:"mobile-btn",style:{width:"100%"},children:[e.jsx(le,{size:14})," Create Task"]}),children:e.jsxs("form",{id:"new-task-form",onSubmit:v,className:"mobile-task-form",children:[e.jsx("label",{className:"mobile-field-label",children:"Title *"}),e.jsx("input",{className:"mobile-input",type:"text",placeholder:"Task title",value:o,onChange:p=>d(p.target.value),autoFocus:!0,required:!0}),e.jsx("label",{className:"mobile-field-label",children:"Description"}),e.jsx("textarea",{className:"mobile-input",rows:3,placeholder:"Optional description",value:r,onChange:p=>l(p.target.value)}),e.jsx("label",{className:"mobile-field-label",children:"Assignee"}),e.jsxs("select",{className:"mobile-input",value:m,onChange:p=>x(p.target.value),children:[e.jsx("option",{value:"",children:"Unassigned"}),c.map(p=>e.jsxs("option",{value:p.name,children:["@",p.name]},p.name))]}),e.jsx("label",{className:"mobile-field-label",children:"Priority"}),e.jsxs("select",{className:"mobile-input",value:n,onChange:p=>f(p.target.value),children:[e.jsx("option",{value:"low",children:"Low"}),e.jsx("option",{value:"normal",children:"Normal"}),e.jsx("option",{value:"high",children:"High"})]})]})})}const Dn=[{id:"activity",label:"Activity",icon:Ue},{id:"chat",label:"Chat",icon:ge},{id:"tasks",label:"Tasks",icon:De},{id:"settings",label:"Settings",icon:ft},{id:"more",label:"More",icon:cs}];function Mn(t){const s=t.meta??{},i=typeof s.taskId=="string"?s.taskId:null,c=typeof s.slug=="string"?s.slug:null,o=typeof s.agent=="string"?s.agent:null;if(i)return{id:"task-detail",taskId:i};if(c)return{id:"artifacts?-detail",slug:c};if(o)return{id:"agent-detail",name:o};const d=t.link??"";return d.startsWith("/artifacts?/")?{id:"artifacts?-detail",slug:decodeURIComponent(d.slice(12))}:d.startsWith("/tasks/")?{id:"task-detail",taskId:decodeURIComponent(d.slice(7))}:d.startsWith("/agents/")?{id:"agent-detail",name:decodeURIComponent(d.slice(8))}:null}function qn(){const[t,s]=a.useState("activity"),[i,c]=a.useState([]),[o,d]=a.useState(!1),[r,l]=a.useState(null),[m,x]=a.useState(null),[n,f]=a.useState(null),[v,p]=a.useState(null),[h,b]=a.useState(!0),[N,g]=a.useState(0),u=a.useMemo(()=>i[i.length-1]??{id:t},[t,i]),S=a.useCallback(w=>{c(k=>[...k,w])},[]),C=a.useCallback(()=>{c(w=>w.slice(0,-1))},[]),_=a.useCallback(w=>{c([]),s(w)},[]),P=a.useCallback(async()=>{var w;try{const k=await E.get("/snapshot");x(k),(w=k.settings)!=null&&w.data&&f(k.settings.data),p(null)}catch(k){throw p(k.message||"Dashboard server unreachable."),k}},[]);a.useEffect(()=>{let w=!1;return Promise.all([E.get("/snapshot").catch(()=>null),E.get("/settings").catch(()=>null),E.probeAuthStatus().catch(()=>null)]).then(([k,R])=>{var z;if(w)return;const B=(R==null?void 0:R.data)??((z=k==null?void 0:k.settings)==null?void 0:z.data)??null;k&&x(k),B&&f(B),p(!k&&!B?"Dashboard server unreachable.":null)}).catch(k=>{w||p(k.message||"Dashboard server unreachable.")}).finally(()=>{w||b(!1)}),()=>{w=!0}},[]),a.useEffect(()=>{n!=null&&n.theme&&(Me(n.theme),Ee(n.theme))},[n==null?void 0:n.theme]),a.useEffect(()=>{var R;if(((R=n==null?void 0:n.theme)==null?void 0:R.mode)!=="system")return;const w=window.matchMedia("(prefers-color-scheme: light)"),k=()=>{n!=null&&n.theme&&(Me(n.theme),Ee(n.theme))};return w.addEventListener("change",k),()=>w.removeEventListener("change",k)},[n==null?void 0:n.theme]),a.useEffect(()=>{const w=()=>{g(R=>R+1),P().catch(()=>{})},k=()=>{document.visibilityState==="visible"&&w()};return window.addEventListener("online",w),window.addEventListener("pageshow",w),document.addEventListener("visibilitychange",k),()=>{window.removeEventListener("online",w),window.removeEventListener("pageshow",w),document.removeEventListener("visibilitychange",k)}},[P]),a.useEffect(()=>{const w=new jt,k=w.on(R=>{if(R.type==="snapshot"&&"data"in R&&R.data)x(B=>({...B??{},...R.data}));else if(R.type==="change")P().catch(()=>{});else if(R.type==="tasks:change"){const B=R.task;x(z=>{if(!z)return z;const Y=(z.tasks||[]).map(Q=>Q.id===B.id?B:Q),oe=Y.some(Q=>Q.id===B.id);return{...z,tasks:oe?Y:[B,...Y]}})}else R.type==="tasks:delete"?x(B=>B&&{...B,tasks:(B.tasks||[]).filter(z=>z.id!==R.id)}):R.type==="settings:change"?R.settings&&f(R.settings):R.type==="project:change"||R.type==="agents:change"||R.type==="schedules:change"||R.type==="artifact:change"?P().catch(()=>{}):(R.type==="agent:status"||R.type==="agent:restarted")&&x(B=>{if(!B)return B;const z=(B.agents||[]).map(Y=>Y.name===R.agent.name?R.agent:Y);return{...B,agents:z}})});return()=>{k(),w.close()}},[P,N]);const T=a.useCallback(w=>{(w==="activity"||w==="chat"||w==="tasks"||w==="settings"||w==="more")&&_(w)},[_]),L=a.useCallback((w,k,R)=>{if(w==="notification"){const B=Mn({link:k||null,meta:R??null});B&&S(B);return}if(w==="task"&&k){S({id:"task-detail",taskId:k});return}if(w==="artifacts?"&&k){S({id:"artifacts?-detail",slug:k});return}if(w==="agent"&&k){S({id:"agent-detail",name:k});return}if(w==="project"){_("activity");return}w==="setting"&&_("settings")},[_,S]),j=()=>{if(!m||!n)return null;if(i.length>0){const w=i[i.length-1];switch(w.id){case"artifacts?":return e.jsx(cn,{snapshot:m,onBack:C,onOpenArtifact:k=>S({id:"artifacts?-detail",slug:k})});case"agents":return e.jsx(lt,{snapshot:m,onBack:C,onOpenAgent:k=>S({id:"agent-detail",name:k}),onRefresh:P});case"skills":return e.jsx(In,{snapshot:m,onBack:C});case"mods":return e.jsx(tn,{snapshot:m,onBack:C});case"schedules":return e.jsx(hn,{snapshot:m,onBack:C});case"history":return e.jsx(en,{onBack:C});case"config":return e.jsx(Zs,{onBack:C});case"artifacts?-detail":return e.jsx(an,{slug:w.slug,onBack:C});case"agent-detail":return e.jsx(lt,{snapshot:m,onBack:C,onOpenAgent:()=>{},onRefresh:P,selectedAgent:w.name});case"task-detail":return e.jsx(ut,{snapshot:m,onRefresh:P,selectedTaskId:w.taskId,onCloseDetail:C,onOpenChat:k=>{l(k),_("chat")}});default:return null}}switch(t){case"activity":return e.jsx(Vs,{snapshot:m,onRefresh:P});case"chat":return e.jsx(Xs,{snapshot:m,settings:n,initialTaskId:r,onClearTaskId:()=>l(null)});case"tasks":return e.jsx(ut,{snapshot:m,onRefresh:P,onOpenChat:w=>{l(w),_("chat")}});case"settings":return e.jsx(Cn,{settings:n,snapshot:m,onRefresh:P});case"more":return e.jsx(sn,{snapshot:m,onNavigate:w=>{(w==="artifacts?"||w==="agents"||w==="skills"||w==="mods"||w==="schedules"||w==="history"||w==="config")&&S({id:w})}});default:return null}};return h?e.jsxs("div",{className:"mobile-loading",children:[e.jsx(vt,{size:"lg"}),e.jsx("p",{children:"Loading Bizar…"})]}):v||!m||!n?e.jsxs("div",{className:"mobile-loading",children:[e.jsx("h2",{children:"Dashboard unavailable"}),e.jsx("p",{children:v||"Dashboard server unreachable."}),e.jsx("p",{className:"muted",children:"Make sure the Bizar dashboard server is running."})]}):e.jsxs("div",{className:"mobile-app",children:[e.jsx(Ws,{activeTab:u.id,snapshot:m,onSearch:()=>d(!0),onNavigate:L}),e.jsx("main",{className:"mobile-content",children:j()}),i.length===0&&e.jsx(Bs,{tabs:Dn,activeTab:t,onChange:T}),i.length>0&&e.jsx("button",{type:"button",className:"mobile-back-btn",onClick:C,"aria-label":"Go back",children:"← Back"}),e.jsx(yn,{open:o,onClose:()=>d(!1),onNavigate:L})]})}export{qe as A,Ne as B,Rs as C,Cs as E,Fn as M,vt as S,_n as T,ws as V,jt as W,yt as _,E as a,gs as b,Ve as c,ms as d,Ls as e,ke as f,Os as g,Ss as h,As as i,bs as j,Ee as k,Me as l,qn as m,us as p,Un as t,fs as u};
|