@polderlabs/bizar 5.2.0 → 5.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/bizar-dash/dist/assets/{MobileChat-TCputYzr.js → MobileChat-OidrxXR9.js} +1 -1
  2. package/bizar-dash/dist/assets/{MobileChat-TCputYzr.js.map → MobileChat-OidrxXR9.js.map} +1 -1
  3. package/bizar-dash/dist/assets/{MobileSettings-BxcbL5XT.js → MobileSettings-B91gVFii.js} +1 -1
  4. package/bizar-dash/dist/assets/{MobileSettings-BxcbL5XT.js.map → MobileSettings-B91gVFii.js.map} +1 -1
  5. package/bizar-dash/dist/assets/{icons-DRDXfbBP.js → icons-Bd8piSb2.js} +18 -13
  6. package/bizar-dash/dist/assets/icons-Bd8piSb2.js.map +1 -0
  7. package/bizar-dash/dist/assets/{main-xFpWMd32.css → main-3G6mOhiK.css} +1 -1
  8. package/bizar-dash/dist/assets/main-6YUZY968.js +19 -0
  9. package/bizar-dash/dist/assets/main-6YUZY968.js.map +1 -0
  10. package/bizar-dash/dist/assets/{mobile-j3rOZK6v.js → mobile-CSsp30lr.js} +2 -2
  11. package/bizar-dash/dist/assets/{mobile-j3rOZK6v.js.map → mobile-CSsp30lr.js.map} +1 -1
  12. package/bizar-dash/dist/assets/{mobile--17fkfrl.js → mobile-DtwK7DOV.js} +1 -1
  13. package/bizar-dash/dist/assets/{mobile--17fkfrl.js.map → mobile-DtwK7DOV.js.map} +1 -1
  14. package/bizar-dash/dist/assets/{useSlashCommands-BG-DhEck.js → useSlashCommands-DEkxEvOO.js} +2 -2
  15. package/bizar-dash/dist/assets/{useSlashCommands-BG-DhEck.js.map → useSlashCommands-DEkxEvOO.js.map} +1 -1
  16. package/bizar-dash/dist/index.html +5 -5
  17. package/bizar-dash/dist/mobile.html +3 -3
  18. package/bizar-dash/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -1
  19. package/bizar-dash/src/server/auth.mjs +14 -1
  20. package/bizar-dash/src/server/eval-store.mjs +55 -0
  21. package/bizar-dash/src/server/eval.mjs +63 -0
  22. package/bizar-dash/src/server/plugins/permission-audit.mjs +109 -0
  23. package/bizar-dash/src/server/plugins/sandbox.mjs +76 -2
  24. package/bizar-dash/src/server/plugins/store.mjs +4 -0
  25. package/bizar-dash/src/server/routes/eval.mjs +42 -2
  26. package/bizar-dash/src/server/routes/plugins.mjs +44 -4
  27. package/bizar-dash/src/server/routes/users.mjs +18 -0
  28. package/bizar-dash/src/server/schedules-runner.mjs +61 -0
  29. package/bizar-dash/src/web/components/EvalExportButton.tsx +27 -0
  30. package/bizar-dash/src/web/components/InstallConfirmDialog.tsx +62 -0
  31. package/bizar-dash/src/web/components/MarketplacePluginCard.tsx +51 -0
  32. package/bizar-dash/src/web/components/PluginCard.tsx +2 -2
  33. package/bizar-dash/src/web/components/PluginPermissions.tsx +1 -1
  34. package/bizar-dash/src/web/components/ScheduleTemplateCard.tsx +1 -0
  35. package/bizar-dash/src/web/components/Topbar.tsx +3 -0
  36. package/bizar-dash/src/web/components/VoiceNotesPanel.tsx +28 -0
  37. package/bizar-dash/src/web/styles/main.css +139 -0
  38. package/bizar-dash/src/web/views/Doctor.tsx +3 -3
  39. package/bizar-dash/src/web/views/Eval.tsx +225 -25
  40. package/bizar-dash/src/web/views/EvalReport.tsx +7 -3
  41. package/bizar-dash/src/web/views/Marketplace.tsx +135 -0
  42. package/bizar-dash/src/web/views/Plugins.tsx +9 -3
  43. package/bizar-dash/src/web/views/Schedules.tsx +1 -1
  44. package/bizar-dash/tests/a11y/components.test.tsx +149 -0
  45. package/bizar-dash/tests/a11y/forms.test.tsx +191 -0
  46. package/bizar-dash/tests/a11y/navigation.test.tsx +112 -0
  47. package/bizar-dash/tests/components/marketplace-plugin-card.test.tsx +144 -0
  48. package/bizar-dash/tests/eval-csv.test.mjs +67 -0
  49. package/bizar-dash/tests/eval-scheduled.test.mjs +84 -0
  50. package/bizar-dash/tests/plugins-permissions.test.mjs +525 -0
  51. package/cli/commands/dash.mjs +5 -0
  52. package/cli/commands/tailscale.mjs +8 -1
  53. package/package.json +1 -1
  54. package/bizar-dash/dist/assets/icons-DRDXfbBP.js.map +0 -1
  55. package/bizar-dash/dist/assets/main-D5Ditnrd.js +0 -19
  56. package/bizar-dash/dist/assets/main-D5Ditnrd.js.map +0 -1
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MobileSettings-BxcbL5XT.js","assets/react-vendor-Dn4wqh4Z.js","assets/icons-DRDXfbBP.js","assets/MobileChat-TCputYzr.js","assets/useSlashCommands-BG-DhEck.js","assets/markdown-C6mXtQxD.js","assets/vendor-CeHGtduv.js"])))=>i.map(i=>d[i]);
2
- var Qe=Object.defineProperty;var Xe=(s,t,n)=>t in s?Qe(s,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):s[t]=n;var U=(s,t,n)=>Xe(s,typeof t!="symbol"?t+"":t,n);import{j as e,r as i,R as Me}from"./react-vendor-Dn4wqh4Z.js";import{X as ee,y as xe,bd as Ze,d as et,Q as tt,aa as X,aq as st,R as q,B as te,g as ce,s as B,a1 as at,Y as se,a8 as nt,p as V,aG as it,l as re,Z as Pe,K as W,k as de,aS as Oe,e as je,a4 as Ue,M as Y,ac as ge,be as lt,S as Z,q as ve,b as ot,i as ye,x as ct,bf as rt}from"./icons-DRDXfbBP.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const l of document.querySelectorAll('link[rel="modulepreload"]'))r(l);new MutationObserver(l=>{for(const u of l)if(u.type==="childList")for(const b of u.addedNodes)b.tagName==="LINK"&&b.rel==="modulepreload"&&r(b)}).observe(document,{childList:!0,subtree:!0});function n(l){const u={};return l.integrity&&(u.integrity=l.integrity),l.referrerPolicy&&(u.referrerPolicy=l.referrerPolicy),l.crossOrigin==="use-credentials"?u.credentials="include":l.crossOrigin==="anonymous"?u.credentials="omit":u.credentials="same-origin",u}function r(l){if(l.ep)return;l.ep=!0;const u=n(l);fetch(l.href,u)}})();function Be(...s){return s.filter(Boolean).join(" ")}function K(s){if(!s&&s!==0)return"";const t=typeof s=="number"?s:new Date(s).getTime();if(Number.isNaN(t))return"";const n=Date.now()-t;return n<0||n<6e4?"just now":n<36e5?`${Math.floor(n/6e4)}m ago`:n<864e5?`${Math.floor(n/36e5)}h ago`:n<7*864e5?`${Math.floor(n/864e5)}d ago`:new Date(t).toLocaleDateString()}function cs(s){if(!s)return"";const t=typeof s=="number"?new Date(s):new Date(s);return Number.isNaN(t.getTime())?"":t.toLocaleString()}function rs(s,t=160){return s?s.length>t?s.slice(0,t)+"…":s:""}const dt={low:"var(--text-dim)",normal:"var(--info)",high:"var(--error)"},Q="bizar-auth-token",Ne="bizar-loopback-trusted";class ke extends Error{constructor(n,r,l){super(n);U(this,"status");U(this,"data");this.name="ApiError",this.status=r,this.data=l}}class mt{constructor(){U(this,"base","/api")}getToken(){try{return localStorage.getItem(Q)||""}catch{return""}}setToken(t){try{t?localStorage.setItem(Q,t):localStorage.removeItem(Q)}catch{}}pickupTokenFromUrl(){try{const t=new URLSearchParams(window.location.search),n=t.get("token");if(!n)return!1;this.setToken(n),t.delete("token");const r=t.toString(),l=r?`${window.location.pathname}?${r}`:window.location.pathname;return history.replaceState(null,"",l),!0}catch{return!1}}urlWithToken(t){const n=this.base+t,r=this.getToken();if(!r)return n;const l=n.includes("?")?"&":"?";return`${n}${l}token=${encodeURIComponent(r)}`}async probeAuthStatus(){try{const t=await this.get("/auth/status");try{localStorage.setItem(Ne,t.loopback?"1":"0")}catch{}return t}catch{return{required:!1,loopback:!0,peer:""}}}isLoopbackTrusted(){try{return localStorage.getItem(Ne)!=="0"}catch{return!0}}async get(t,n){return this.req("GET",t,void 0,n)}async post(t,n,r){return this.req("POST",t,n,r)}async put(t,n,r){return this.req("PUT",t,n,r)}async patch(t,n,r){return this.req("PATCH",t,n,r)}async del(t,n){return this.req("DELETE",t,void 0,n)}async req(t,n,r,l){const u={"Content-Type":"application/json"},b=this.getToken();b&&(u.Authorization=`Bearer ${b}`);const c={method:t,headers:u};r!=null&&(c.body=typeof r=="string"?r:JSON.stringify(r)),l&&(c.signal=l);const m=await fetch(this.base+n,c);if((m.headers.get("content-type")||"").includes("application/json")){const x=await m.json();if(!m.ok){const k=(x&&typeof x=="object"&&"message"in x?x.message:void 0)||`${t} ${n}: ${m.status}`;throw new ke(k,m.status,x)}return x}const a=await m.text();if(!m.ok)throw new ke(`${t} ${n}: ${m.status} — ${a.slice(0,200)}`,m.status,a);try{return JSON.parse(a)}catch{return a}}}const T=new mt;T.pickupTokenFromUrl();async function ds(s){return s}function ut(){if(typeof location>"u")return"ws://localhost/ws";const s=`${location.protocol==="https:"?"wss":"ws"}://${location.host}/ws`;let t="";try{t=localStorage.getItem(Q)||""}catch{}return t?`${s}?token=${encodeURIComponent(t)}`:s}class Fe{constructor(t){U(this,"urlOverride");U(this,"handlers",new Set);U(this,"statusHandlers",new Set);U(this,"ws",null);U(this,"reconnectDelay",1e3);U(this,"maxReconnectDelay",15e3);U(this,"reconnectTimer",null);U(this,"_status","connecting");U(this,"pingTimer",null);U(this,"closed",!1);this.urlOverride=t,this.connect()}on(t){return this.handlers.add(t),()=>{this.handlers.delete(t)}}onStatus(t){return this.statusHandlers.add(t),t(this._status),()=>{this.statusHandlers.delete(t)}}get status(){return this._status}send(t){return this.ws&&this.ws.readyState===WebSocket.OPEN?(this.ws.send(JSON.stringify(t)),!0):!1}close(){var t;this.closed=!0,this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.reconnectTimer=null,this.pingTimer&&clearInterval(this.pingTimer),this.pingTimer=null;try{(t=this.ws)==null||t.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 t=this.urlOverride??ut();let n;try{n=new WebSocket(t),this.ws=n}catch(r){console.warn("[ws] construct failed:",r),this.scheduleReconnect();return}n.addEventListener("open",()=>{this.ws!==n||this.closed||(this.reconnectDelay=1e3,this.setStatus("connected"),this.pingTimer&&clearInterval(this.pingTimer),this.pingTimer=setInterval(()=>{this._status==="connected"&&this.send({type:"ping"})},3e4))}),n.addEventListener("close",()=>{this.ws===n&&(this.ws=null,this.setStatus("disconnected"),this.pingTimer&&(clearInterval(this.pingTimer),this.pingTimer=null),this.closed||this.scheduleReconnect())}),n.addEventListener("error",()=>{this.ws===n&&console.warn("[ws] error")}),n.addEventListener("message",r=>{let l;try{l=JSON.parse(r.data)}catch{console.warn("[ws] bad message");return}for(const u of this.handlers)try{u(l)}catch(b){console.error("[ws] handler error:",b)}})}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(t){this._status=t;for(const n of this.statusHandlers)try{n(t)}catch(r){console.error("[ws] status handler error:",r)}}}const ms=Object.freeze(Object.defineProperty({__proto__:null,Ws:Fe},Symbol.toStringTag,{value:"Module"}));function we(s){const t=typeof s=="string"?s:s.mode,n=t==="system"?typeof window<"u"&&window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark":t==="light"?"light":"dark";return typeof document<"u"&&(n==="light"?document.documentElement.setAttribute("data-theme","light"):document.documentElement.removeAttribute("data-theme")),n}function Se(s){if(typeof document>"u")return;const t=document.documentElement;t.style.setProperty("--accent",s.accent),t.style.setProperty("--success",s.success),t.style.setProperty("--warning",s.warning),t.style.setProperty("--error",s.error),t.style.setProperty("--info",s.info),t.style.setProperty("--accent-bg",Ce(s.accent,.12)),t.style.setProperty("--accent-border",Ce(s.accent,.4)),s.fontFamily&&t.style.setProperty("--font-sans",`'${s.fontFamily}', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif`),s.fontSize&&t.style.setProperty("--base-font-size",`${s.fontSize}px`),t.dataset.compactMode=s.compactMode?"true":"false",t.dataset.animations=s.animations?"true":"false"}function Ce(s,t){const n=/^#?([0-9a-f]{6})$/i.exec(s||"");if(!n)return`rgba(139, 92, 246, ${t})`;const r=parseInt(n[1],16),l=r>>16&255,u=r>>8&255,b=r&255;return`rgba(${l}, ${u}, ${b}, ${t})`}function ie({size:s="md",className:t,label:n}){return e.jsx("span",{className:Be("spinner",`spinner-${s}`,t),role:"status","aria-label":n||"Loading"})}const ht="modulepreload",bt=function(s){return"/"+s},Te={},qe=function(t,n,r){let l=Promise.resolve();if(n&&n.length>0){document.getElementsByTagName("link");const b=document.querySelector("meta[property=csp-nonce]"),c=(b==null?void 0:b.nonce)||(b==null?void 0:b.getAttribute("nonce"));l=Promise.allSettled(n.map(m=>{if(m=bt(m),m in Te)return;Te[m]=!0;const y=m.endsWith(".css"),a=y?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${m}"]${a}`))return;const x=document.createElement("link");if(x.rel=y?"stylesheet":ht,y||(x.as="script"),x.crossOrigin="",x.href=m,c&&x.setAttribute("nonce",c),document.head.appendChild(x),y)return new Promise((k,h)=>{x.addEventListener("load",k),x.addEventListener("error",()=>h(new Error(`Unable to preload CSS for ${m}`)))})}))}function u(b){const c=new Event("vite:preloadError",{cancelable:!0});if(c.payload=b,window.dispatchEvent(c),!c.defaultPrevented)throw b}return l.then(b=>{for(const c of b||[])c.status==="rejected"&&u(c.reason);return t().catch(u)})};function pt({tabs:s,activeTab:t,onChange:n}){return e.jsx("nav",{className:"mobile-bottom-nav",role:"navigation","aria-label":"Mobile navigation",children:s.map(r=>{const l=r.icon;return e.jsxs("button",{type:"button",className:Be("mobile-nav-btn",t===r.id&&"mobile-nav-btn-active"),onClick:()=>n(r.id),"aria-label":r.label,"aria-current":t===r.id?"page":void 0,children:[e.jsx(l,{size:22}),e.jsx("span",{className:"mobile-nav-label",children:r.label})]},r.id)})})}function F({open:s,onClose:t,title:n,children:r,actions:l,maxHeight:u="85vh"}){const b=i.useRef(null),c=i.useRef(null),m=i.useId(),y=i.useRef(null),a=i.useRef(null),x=i.useRef(0),k=i.useRef(0),h=()=>{var p;return((p=b.current)==null?void 0:p.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'))??[]};if(i.useEffect(()=>{if(!s)return;y.current=document.activeElement instanceof HTMLElement?document.activeElement:null;const p=j=>{var P;if(j.key==="Escape"&&t(),j.key!=="Tab")return;const A=Array.from(h());if(A.length===0){j.preventDefault(),(P=b.current)==null||P.focus();return}const S=A[0],R=A[A.length-1],z=document.activeElement;if(j.shiftKey){(!z||z===S||z===b.current)&&(j.preventDefault(),R==null||R.focus());return}z===R&&(j.preventDefault(),S==null||S.focus())};return window.addEventListener("keydown",p),requestAnimationFrame(()=>{var j,A;((j=c.current)==null?void 0:j.focus())??((A=b.current)==null||A.focus())}),()=>{var j;window.removeEventListener("keydown",p),(j=y.current)==null||j.focus()}},[s,t]),i.useEffect(()=>(s?(k.current=window.scrollY,document.documentElement.style.overflow="hidden",document.body.style.overflow="hidden",document.body.style.position="fixed",document.body.style.top=`-${k.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,k.current)}),[s]),!s)return null;const d=p=>{var j;p.isPrimary&&(a.current=p.clientY,x.current=0,(j=b.current)==null||j.setPointerCapture(p.pointerId))},o=p=>{if(a.current==null||!b.current)return;const j=Math.max(0,p.clientY-a.current);x.current=j,b.current.style.transform=`translateY(${j}px)`},N=p=>{if(!b.current)return;p&&b.current.hasPointerCapture(p.pointerId)&&b.current.releasePointerCapture(p.pointerId);const j=x.current;b.current.style.transform="",a.current=null,x.current=0,j>72&&t()};return e.jsx("div",{className:"mobile-sheet-overlay",onClick:t,children:e.jsxs("div",{ref:b,className:"mobile-sheet",style:{maxHeight:u},onClick:p=>p.stopPropagation(),role:"dialog","aria-modal":!0,"aria-label":n?void 0:"Sheet","aria-labelledby":n?m:void 0,tabIndex:-1,children:[e.jsx("div",{className:"mobile-sheet-handle",onPointerDown:d,onPointerMove:o,onPointerUp:N,onPointerCancel:N,"aria-hidden":"true"}),e.jsxs("div",{className:"mobile-sheet-header",children:[n?e.jsx("h3",{id:m,className:"mobile-sheet-title",children:n}):e.jsx("div",{}),e.jsx("button",{ref:c,type:"button",className:"mobile-icon-btn",onClick:t,"aria-label":"Close",children:e.jsx(ee,{size:18})})]}),e.jsx("div",{className:"mobile-sheet-content",children:r}),l&&e.jsx("div",{className:"mobile-sheet-actions",children:l})]})})}function ft(s){switch(s){case"success":return"✓";case"error":return"✗";case"warning":return"⚠";default:return"ℹ"}}function xt(s){const t=new Date(s),r=Date.now()-t.getTime();return r<6e4?"just now":r<36e5?`${Math.floor(r/6e4)}m ago`:r<864e5?`${Math.floor(r/36e5)}h ago`:t.toLocaleDateString()}function jt({onSelect:s}){const[t,n]=i.useState(!1),[r,l]=i.useState([]),[u,b]=i.useState(0),c=async()=>{var a;try{const x=await T.get("/notifications");l(x.notifications||[]),b(((a=x.stats)==null?void 0:a.unread)||0)}catch{}};i.useEffect(()=>{c()},[]),i.useEffect(()=>{t&&c()},[t]);const m=async()=>{try{await T.post("/notifications/read-all"),l(a=>a.map(x=>({...x,read:!0}))),b(0)}catch{}},y=async a=>{try{await T.post(`/notifications/${encodeURIComponent(a)}/read`),l(x=>x.map(k=>k.id===a?{...k,read:!0}:k)),b(x=>Math.max(0,x-1))}catch{}};return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",className:"mobile-icon-btn mobile-notif-btn",onClick:()=>n(!0),"aria-label":`Notifications${u>0?` (${u} unread)`:""}`,children:[e.jsx(xe,{size:20}),u>0&&e.jsx("span",{className:"mobile-notif-badge",children:u>9?"9+":u})]}),e.jsx(F,{open:t,onClose:()=>n(!1),title:"Notifications",actions:u>0?e.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",style:{width:"100%"},onClick:m,children:[e.jsx(Ze,{size:14})," Mark all read"]}):void 0,children:e.jsxs("div",{className:"mobile-notif-list",children:[r.length===0&&e.jsxs("div",{className:"mobile-empty",children:[e.jsx(xe,{size:32}),e.jsx("p",{children:"No notifications"})]}),r.map(a=>e.jsxs("button",{type:"button",className:`mobile-notif-item ${a.read?"read":"unread"}`,onClick:()=>{a.read||y(a.id),s(a),n(!1)},children:[e.jsx("span",{className:`mobile-notif-icon severity-${a.severity}`,children:ft(a.severity)}),e.jsxs("div",{className:"mobile-notif-body",children:[e.jsx("span",{className:"mobile-notif-title",children:a.title||a.message}),a.message&&a.title&&e.jsx("span",{className:"mobile-notif-text",children:a.message}),e.jsx("span",{className:"mobile-notif-time",children:xt(a.ts)})]}),!a.read&&e.jsx("span",{className:"mobile-notif-dot"})]},a.id))]})})]})}const gt={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 vt({activeTab:s,snapshot:t,onSearch:n,onNavigate:r}){const[l,u]=i.useState(!1),b=async c=>{try{await T.post(`/projects/${encodeURIComponent(c)}/activate`),u(!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:"ᛒ"}),(t==null?void 0:t.activeProject)&&e.jsxs("button",{type:"button",className:"mobile-project-btn",onClick:()=>u(!0),"aria-label":"Select project",children:[e.jsx("span",{className:"mobile-project-name",children:t.activeProject.name}),e.jsx(et,{size:14})]}),e.jsx("span",{className:"mobile-title",children:gt[s]||"Bizar"})]}),e.jsxs("div",{className:"mobile-topbar-right",children:[e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:n,"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(jt,{onSelect:c=>{r("notification",c.link||"",c.meta??null)}}),(t==null?void 0:t.activeProject)&&e.jsx(F,{open:l,onClose:()=>u(!1),title:"Projects",children:e.jsx("div",{className:"mobile-project-list",children:(t.projects||[]).map(c=>{var m,y;return e.jsxs("button",{type:"button",className:`mobile-project-item ${c.id===((m=t.activeProject)==null?void 0:m.id)?"active":""}`,onClick:()=>b(c.id),children:[e.jsx("div",{className:"mobile-project-status","data-status":c.status}),e.jsxs("div",{className:"mobile-project-info",children:[e.jsx("span",{className:"mobile-project-item-name",children:c.name}),e.jsx("span",{className:"mobile-project-item-path",children:c.path})]}),c.id===((y=t.activeProject)==null?void 0:y.id)&&e.jsx("span",{className:"mobile-active-badge",children:"active"})]},c.id)})})})]})]})}const yt=["all","tasks","agents","bg","artifacts","mods"],le={all:"All",tasks:"Tasks",agents:"Agents",bg:"Background",artifacts:"Plans",mods:"Mods"};function Nt({snapshot:s,onRefresh:t}){var D;const[n,r]=i.useState(((D=s.overview)==null?void 0:D.recentActivity)||[]),[l,u]=i.useState(!0),[b,c]=i.useState("all"),[m,y]=i.useState(!1),[a,x]=i.useState(null),[k,h]=i.useState(""),[d,o]=i.useState(!1);i.useEffect(()=>{var f;(f=s.overview)!=null&&f.recentActivity?(r(s.overview.recentActivity),u(!1)):N()},[s.overview]);const N=async()=>{var f;try{const v=await T.get("/snapshot");r(((f=v.overview)==null?void 0:f.recentActivity)||[])}catch{}finally{u(!1)}},p=b==="all"?n:n.filter(f=>{var v,g,C,E,I,O;return b==="tasks"?(v=f.kind)==null?void 0:v.startsWith("task"):b==="agents"?(g=f.kind)==null?void 0:g.startsWith("agent"):b==="bg"?((C=f.kind)==null?void 0:C.includes("bg"))||((E=f.kind)==null?void 0:E.includes("schedule")):b==="artifacts"?(I=f.kind)==null?void 0:I.includes("artifacts"):b==="mods"?(O=f.kind)==null?void 0:O.includes("mod"):!0}),j=s.agents||[],A=s.tasks||[],S=A.filter(f=>f.status==="doing"||f.status==="queued"),R=A.filter(f=>f.status==="done"),z=async()=>{if(!(!k.trim()||d)){o(!0);try{await T.post("/chat",{message:k.trim(),agent:"odin"}),h(""),await t().catch(()=>{}),await N()}catch{}finally{o(!1)}}},P=async()=>{await t().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:k,onChange:f=>h(f.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(f=>e.jsx("button",{type:"button",className:"mobile-submit-chip",onClick:()=>h(v=>v?`${v} ${f}`:f),children:f},f))}),e.jsxs("button",{type:"button",className:"mobile-btn",disabled:!k.trim()||d,onClick:z,children:[e.jsx(tt,{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:j.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:S.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:R.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:s.artifacts.length||0}),e.jsx("div",{className:"mobile-stat-label",children:"Plans"})]})]}),l&&n.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:()=>y(f=>!f),"aria-label":m?"Resume":"Pause",children:m?e.jsx(X,{size:14}):e.jsx(st,{size:14})}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:P,"aria-label":"Refresh",children:e.jsx(q,{size:14})})]})]}),e.jsx("div",{className:"mobile-search-scopes",children:yt.map(f=>e.jsx("button",{type:"button",className:`mobile-scope-chip ${b===f?"active":""}`,onClick:()=>c(f),children:le[f]},f))}),j.length>0&&e.jsxs("section",{className:"mobile-section",children:[e.jsxs("h3",{className:"mobile-section-title",children:[e.jsx(te,{size:14})," Agents"]}),e.jsx("div",{className:"mobile-card-list",children:j.slice(0,6).map(f=>e.jsxs("div",{className:"mobile-agent-card",children:[e.jsx("div",{className:"mobile-agent-dot","data-status":f.status||"idle"}),e.jsxs("div",{className:"mobile-agent-info",children:[e.jsx("span",{className:"mobile-agent-name",children:f.name}),e.jsx("span",{className:"mobile-agent-meta",children:f.status||"idle"})]})]},f.name))})]}),!m&&p.length>0&&e.jsx("section",{className:"mobile-section",children:e.jsx("div",{className:"mobile-card-list",children:p.slice(0,30).map((f,v)=>e.jsxs("button",{type:"button",className:"mobile-event-item",onClick:()=>x(f),children:[e.jsx("span",{className:"mobile-event-kind","data-kind":f.kind,children:le[f.kind]||f.kind}),e.jsx("span",{className:"mobile-event-msg",children:kt(f)}),e.jsx("span",{className:"mobile-event-time",children:K(f.ts)})]},`${f.ts}-${f.kind}-${v}`))})}),!m&&p.length===0&&n.length>0&&e.jsxs("div",{className:"mobile-empty",children:[e.jsx(ce,{size:40}),e.jsx("p",{children:"No matching activity."}),e.jsx("p",{className:"muted",children:"Try a different filter."})]}),a&&e.jsx(F,{open:!0,onClose:()=>x(null),title:le[a.kind]||a.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:a.kind})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Time"}),e.jsx("span",{children:new Date(a.ts).toLocaleString()})]}),Object.entries(a).filter(([f])=>!["ts","kind"].includes(f)).map(([f,v])=>e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:f}),e.jsx("span",{style:{fontSize:12,maxWidth:200,wordBreak:"break-all"},children:typeof v=="object"?JSON.stringify(v):String(v)})]},f))]})}),j.length===0&&S.length===0&&e.jsxs("div",{className:"mobile-empty",children:[e.jsx(ce,{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 kt(s){const t=s.kind||"";return t.includes("task")?`Task: ${s.title||s.id||"updated"}`:t.includes("agent")?`Agent: ${s.name||"status changed"}`:t.includes("artifacts")?`Plan: ${s.slug||"changed"}`:t.includes("mod")?`Mod: ${s.name||"changed"}`:t.includes("schedule")?`Schedule: ${s.name||"triggered"}`:JSON.stringify(s).slice(0,80)}function _({open:s,onClose:t,title:n,children:r,actions:l}){const u=i.useRef(null),b=i.useRef(null),c=i.useRef(null),m=i.useId(),y=i.useRef(0);return i.useEffect(()=>{if(!s)return;c.current=document.activeElement instanceof HTMLElement?document.activeElement:null;const a='button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])',x=k=>{var p,j;if(k.key==="Escape"&&t(),k.key!=="Tab")return;const h=Array.from(((p=u.current)==null?void 0:p.querySelectorAll(a))??[]);if(h.length===0){k.preventDefault(),(j=u.current)==null||j.focus();return}const d=h[0],o=h[h.length-1],N=document.activeElement;if(k.shiftKey){(!N||N===d||N===u.current)&&(k.preventDefault(),o==null||o.focus());return}N===o&&(k.preventDefault(),d==null||d.focus())};return window.addEventListener("keydown",x),y.current=window.scrollY,document.documentElement.style.overflow="hidden",document.body.style.overflow="hidden",document.body.style.position="fixed",document.body.style.top=`-${y.current}px`,document.body.style.left="0",document.body.style.right="0",document.body.style.width="100%",requestAnimationFrame(()=>{var k,h;((k=b.current)==null?void 0:k.focus())??((h=u.current)==null||h.focus())}),()=>{var k;window.removeEventListener("keydown",x),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,y.current),(k=c.current)==null||k.focus()}},[s,t]),s?e.jsx("div",{className:"mobile-modal-overlay",onClick:a=>{a.target===a.currentTarget&&t()},children:e.jsxs("div",{ref:u,className:"mobile-modal",onClick:a=>a.stopPropagation(),role:"dialog","aria-modal":!0,"aria-label":n?void 0:"Modal","aria-labelledby":n?m:void 0,tabIndex:-1,children:[e.jsxs("div",{className:"mobile-modal-header",children:[n?e.jsx("h2",{id:m,className:"mobile-modal-title",children:n}):e.jsx("div",{}),e.jsx("button",{ref:b,type:"button",className:"mobile-icon-btn",onClick:t,"aria-label":"Close",children:e.jsx(ee,{size:20})})]}),e.jsx("div",{className:"mobile-modal-content",children:r}),l&&e.jsx("div",{className:"mobile-modal-actions",children:l})]})}):null}const _e=["reasoning","code","design","planning","gitops","analysis"],Ae={reasoning:"var(--accent)",code:"var(--info)",design:"var(--success)",planning:"var(--warning)",gitops:"var(--error)",analysis:"var(--text-dim)"};function Ee({snapshot:s,onBack:t,onOpenAgent:n,selectedAgent:r,onRefresh:l}){const[u,b]=i.useState(s.agents||[]),[c,m]=i.useState(!s.agents),[y,a]=i.useState(""),[x,k]=i.useState(""),[h,d]=i.useState(null),[o,N]=i.useState(!1),[p,j]=i.useState(""),[A,S]=i.useState(!1);i.useEffect(()=>{if(r){const g=u.find(C=>C.name===r);g&&d(g)}},[r,u]);const R=async()=>{try{const g=await T.get("/agents");b(g.agents||[])}catch{}finally{m(!1)}},z=u.filter(g=>{if(y&&g.category!==y)return!1;if(x){const C=x.toLowerCase();if(!g.name.toLowerCase().includes(C)&&!(g.description||"").toLowerCase().includes(C))return!1}return!0}),P=async(g,C)=>{try{await T.post(`/agents/${encodeURIComponent(g)}/invoke`,{prompt:C}),S(!1),j("")}catch{}},D=async g=>{try{await T.post(`/agents/${encodeURIComponent(g)}/restart`),await R()}catch{}},f=async g=>{if(confirm(`Delete agent "${g}"?`))try{await T.del(`/agents/${encodeURIComponent(g)}`),b(C=>C.filter(E=>E.name!==g)),d(null),l==null||l()}catch{}},v=async g=>{try{const C=await T.post("/agents",g);b(E=>[...E,C]),N(!1),l==null||l()}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:x,onChange:g=>k(g.target.value),style:{flex:1}}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>R(),"aria-label":"Refresh",children:e.jsx(q,{size:16})}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>N(!0),"aria-label":"New agent",children:e.jsx(B,{size:16})})]}),e.jsxs("div",{className:"mobile-search-scopes",children:[e.jsx("button",{type:"button",className:`mobile-scope-chip ${y?"":"active"}`,onClick:()=>a(""),children:"All"}),_e.map(g=>e.jsx("button",{type:"button",className:`mobile-scope-chip ${y===g?"active":""}`,onClick:()=>a(g),children:g},g))]}),c?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading…"})}):z.length===0?e.jsxs("div",{className:"mobile-empty",children:[e.jsx(te,{size:40}),e.jsx("p",{children:"No agents found."})]}):e.jsx("div",{className:"mobile-card-list",children:z.map(g=>e.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>{d(g),n(g.name)},children:[e.jsx("div",{className:"mobile-agent-dot","data-status":g.status||"idle"}),e.jsxs("div",{className:"mobile-list-content",children:[e.jsx("span",{className:"mobile-list-title",children:g.name}),e.jsx("span",{className:"mobile-list-meta",children:g.model||g.mode||"—"})]}),g.category&&e.jsx("span",{className:"mobile-list-badge",style:{color:Ae[g.category]||"var(--text-dim)"},children:g.category}),e.jsx("span",{className:"mobile-list-badge","data-status":g.status||"idle",children:g.status||"idle"})]},g.name))}),h&&e.jsx(F,{open:!0,onClose:()=>d(null),title:h.name,actions:e.jsxs("div",{className:"mobile-task-detail-actions",children:[e.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>{j(""),S(!0)},children:[e.jsx(X,{size:14})," Invoke"]}),(h.isStuck||h.status==="error"||h.status==="working")&&e.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>D(h.name),children:[e.jsx(at,{size:14})," Restart"]}),e.jsx("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>f(h.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":h.status||"idle"}),e.jsx("span",{className:"mobile-agent-detail-status-text",children:h.status||"idle"}),h.category&&e.jsx("span",{className:"mobile-list-badge",style:{color:Ae[h.category]},children:h.category})]}),e.jsx("p",{className:"mobile-agent-detail-desc",children:h.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:h.model||"—"})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Mode"}),e.jsx("span",{children:h.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:h.path})]}),h.lastError&&e.jsxs("div",{className:"mobile-task-detail-row",style:{color:"var(--error)"},children:[e.jsx("span",{children:"Last error"}),e.jsx("span",{children:h.lastError.message})]}),h.tasksTotal!=null&&h.tasksTotal>0&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Success rate"}),e.jsxs("span",{children:[Math.round((h.successRate||0)*100),"%"]})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Last modified"}),e.jsx("span",{children:K(h.mtime)})]})]})]})}),e.jsxs(_,{open:A,onClose:()=>S(!1),title:`Invoke ${h==null?void 0:h.name}`,actions:e.jsxs("button",{type:"button",className:"mobile-btn",style:{width:"100%"},disabled:!p.trim(),onClick:()=>{h&&P(h.name,p.trim())},children:[e.jsx(X,{size:14})," Invoke"]}),children:[e.jsxs("p",{className:"muted",style:{marginBottom:12},children:["Model: ",e.jsx("span",{className:"mono",children:(h==null?void 0:h.model)||"—"})]}),e.jsx("textarea",{className:"mobile-input",rows:5,placeholder:"What should this agent do?",value:p,onChange:g=>j(g.target.value),autoFocus:!0})]}),e.jsx(wt,{open:o,onClose:()=>N(!1),onCreate:v})]})}function wt({open:s,onClose:t,onCreate:n}){const[r,l]=i.useState(""),[u,b]=i.useState(""),[c,m]=i.useState(""),[y,a]=i.useState("subagent"),[x,k]=i.useState("#8b5cf6"),[h,d]=i.useState(""),[o,N]=i.useState(""),[p,j]=i.useState(""),A=S=>{S.preventDefault(),r.trim()&&(n({name:r.trim(),description:u.trim(),model:c,mode:y,color:x,tools:[],tags:o.split(",").map(R=>R.trim()).filter(Boolean),category:h,prompt:p}),l(""),b(""),m(""),a("subagent"),k("#8b5cf6"),d(""),N(""),j(""))};return e.jsx(_,{open:s,onClose:t,title:"New Agent",actions:e.jsxs("button",{type:"submit",form:"new-agent-form",className:"mobile-btn",style:{width:"100%"},children:[e.jsx(B,{size:14})," Create"]}),children:e.jsxs("form",{id:"new-agent-form",onSubmit:A,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:r,onChange:S=>l(S.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:u,onChange:S=>b(S.target.value)}),e.jsx("label",{className:"mobile-field-label",children:"Model"}),e.jsx("input",{className:"mobile-input",type:"text",placeholder:"(provider default)",value:c,onChange:S=>m(S.target.value)}),e.jsx("label",{className:"mobile-field-label",children:"Category"}),e.jsxs("select",{className:"mobile-input",value:h,onChange:S=>d(S.target.value),children:[e.jsx("option",{value:"",children:"None"}),_e.map(S=>e.jsx("option",{value:S,children:S},S))]}),e.jsx("label",{className:"mobile-field-label",children:"Tags (comma-separated)"}),e.jsx("input",{className:"mobile-input",type:"text",placeholder:"tag1, tag2",value:o,onChange:S=>N(S.target.value)})]})})}function St({onBack:s}){const[t,n]=i.useState([]),[r,l]=i.useState(!0),[u,b]=i.useState({}),[c,m]=i.useState(!1),y=async()=>{try{const o=await T.get("/config"),N=Object.entries(o).map(([p,j])=>({key:p,value:j,type:a(j)}));n(N),b(Object.fromEntries(Object.entries(o).map(([p,j])=>[p,j])))}catch{}finally{l(!1)}};i.useEffect(()=>{y()},[]);const a=o=>typeof o=="boolean"?"boolean":typeof o=="number"?"number":typeof o=="string"?"string":Array.isArray(o)?"array":o&&typeof o=="object"?"object":"unknown",x=(o,N)=>{b(p=>({...p,[o]:N}))},k=async()=>{m(!0);try{await T.patch("/config",u),await y()}catch{}finally{m(!1)}},h=(o,N)=>{b(p=>({...p,[o]:N}))},d=o=>{const N=u[o.key];switch(o.type){case"boolean":return e.jsxs("label",{className:"mobile-toggle",children:[e.jsx("input",{type:"checkbox",checked:!!N,onChange:p=>x(o.key,p.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:p=>x(o.key,Number(p.target.value))});case"string":return e.jsx("input",{className:"mobile-input mobile-input-sm",type:"text",value:String(N??""),onChange:p=>x(o.key,p.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:p=>{try{x(o.key,JSON.parse(p.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:[t.length," config entries"]}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>y(),"aria-label":"Refresh",children:e.jsx(q,{size:16})}),e.jsxs("button",{type:"button",className:"mobile-btn",disabled:c,onClick:()=>k(),children:[e.jsx(nt,{size:14})," ",c?"Saving…":"Save all"]})]}),r?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading…"})}):t.length===0?e.jsxs("div",{className:"mobile-empty",children:[e.jsx(V,{size:40}),e.jsx("p",{children:"No config entries."})]}):e.jsx("div",{className:"mobile-config-list",children:t.map(o=>e.jsxs("div",{className:"mobile-config-row",children:[e.jsxs("div",{className:"mobile-config-key",children:[e.jsx("span",{className:"mono",children:o.key}),e.jsx("span",{className:"mobile-config-type",children:o.type})]}),e.jsx("div",{className:"mobile-config-value",children:d(o)}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>h(o.key,o.defaultValue),"aria-label":"Reset to default",title:"Reset",children:e.jsx(it,{size:14})})]},o.key))})]})}function Ct({onBack:s}){const[t,n]=i.useState([]),[r,l]=i.useState(!0),[u,b]=i.useState(null),[c,m]=i.useState(""),y=async()=>{try{const h=await T.get("/history");if(Array.isArray(h.history)){n(h.history);return}if(Array.isArray(h.projects)){const d=new Map;for(const o of h.events||[]){const N=o.projectId;if(!N)continue;const p=d.get(N);(!p||new Date(o.ts).getTime()>new Date(p.ts).getTime())&&d.set(N,o)}n(h.projects.map(o=>{const N=d.get(o.id);return{id:o.id,ts:o.lastAccessed||(N==null?void 0:N.ts)||new Date(0).toISOString(),agent:o.name,taskCount:o.tasks.total,summary:`${o.path} · ${o.tasks.done}/${o.tasks.total} done · ${o.plans} plan${o.plans===1?"":"s"}`,output:N?`${N.kind}${N.text?` — ${N.text}`:""}`:"No recent events."}}));return}n([])}catch{}finally{l(!1)}};i.useEffect(()=>{y()},[]);const a=h=>{if(!h)return"—";const d=Math.floor(h/1e3);if(d<60)return`${d}s`;const o=Math.floor(d/60),N=d%60;return`${o}m ${N}s`},x=h=>new Date(h).toLocaleString(),k=c.trim()?t.filter(h=>{const d=c.toLowerCase();return(h.agent||"session").toLowerCase().includes(d)||(h.summary||"").toLowerCase().includes(d)||(h.output||"").toLowerCase().includes(d)}):t;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:c,onChange:h=>m(h.target.value),style:{flex:1}}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>y(),"aria-label":"Refresh",children:e.jsx(q,{size:16})})]}),r?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading…"})}):k.length===0?e.jsxs("div",{className:"mobile-empty",children:[e.jsx(re,{size:40}),e.jsx("p",{children:t.length===0?"No history yet.":"No matching sessions."})]}):e.jsx("div",{className:"mobile-card-list",children:k.map(h=>e.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>b(h),children:[e.jsx("div",{className:"mobile-list-icon",children:e.jsx(re,{size:16})}),e.jsxs("div",{className:"mobile-list-content",children:[e.jsx("span",{className:"mobile-list-title",children:h.agent||"Session"}),e.jsxs("span",{className:"mobile-list-meta",children:[x(h.ts),h.duration?` · ${a(h.duration)}`:"",h.taskCount?` · ${h.taskCount} tasks`:""]})]})]},h.id))}),u&&e.jsxs(F,{open:!0,onClose:()=>b(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:u.agent||"—"})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Started"}),e.jsx("span",{children:x(u.ts)})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Duration"}),e.jsx("span",{children:a(u.duration)})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Tasks"}),e.jsx("span",{children:u.taskCount||0})]})]}),u.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:u.summary})]}),u.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:[u.output.slice(0,1e3),u.output.length>1e3?"…":""]})]})]})]})}function Tt({snapshot:s,onBack:t}){const[n,r]=i.useState(s.mods||[]),[l,u]=i.useState(!s.mods),[b,c]=i.useState(""),[m,y]=i.useState("all"),[a,x]=i.useState(null),k=async()=>{try{const o=await T.get("/mods");r(o.mods||[])}catch{}finally{u(!1)}};i.useEffect(()=>{s.mods?(r(s.mods),u(!1)):k()},[s.mods]);const h=async(o,N)=>{try{await T.patch(`/mods/${encodeURIComponent(o)}`,{enabled:N}),r(p=>p.map(j=>j.id===o?{...j,enabled:N}:j)),(a==null?void 0:a.id)===o&&x(p=>p&&{...p,enabled:N})}catch{}},d=n.filter(o=>{if(m==="enabled"&&!o.enabled||m==="disabled"&&o.enabled)return!1;if(b){const N=b.toLowerCase();return o.name.toLowerCase().includes(N)||o.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:b,onChange:o=>c(o.target.value),style:{flex:1}}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>k(),"aria-label":"Refresh",children:e.jsx(q,{size:16})})]}),e.jsx("div",{className:"mobile-search-scopes",children:["all","enabled","disabled"].map(o=>e.jsx("button",{type:"button",className:`mobile-scope-chip ${m===o?"active":""}`,onClick:()=>y(o),children:o.charAt(0).toUpperCase()+o.slice(1)},o))}),l?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading…"})}):d.length===0?e.jsxs("div",{className:"mobile-empty",children:[e.jsx(V,{size:40}),e.jsx("p",{children:"No mods found."})]}):e.jsx("div",{className:"mobile-card-list",children:d.map(o=>e.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>x(o),children:[e.jsx("div",{className:"mobile-list-icon",children:e.jsx(V,{size:16})}),e.jsxs("div",{className:"mobile-list-content",children:[e.jsx("span",{className:"mobile-list-title",children:o.name}),e.jsxs("span",{className:"mobile-list-meta",children:["v",o.version," · ",o.author]})]}),e.jsx("span",{className:`mobile-list-badge ${o.enabled?"badge-on":"badge-off"}`,children:o.enabled?"on":"off"})]},o.id))}),a&&e.jsx(F,{open:!0,onClose:()=>x(null),title:a.name,actions:e.jsx("div",{className:"mobile-task-detail-actions",children:e.jsxs("button",{type:"button",className:"mobile-btn",style:{flex:1},onClick:()=>{a&&h(a.id,!a.enabled)},children:[e.jsx(Pe,{size:14})," ",a.enabled?"Disable":"Enable"]})}),children:e.jsxs("div",{className:"mobile-agent-detail",children:[e.jsx("p",{className:"mobile-agent-detail-desc",children:a.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:a.version})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Author"}),e.jsx("span",{children:a.author})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Bizar"}),e.jsx("span",{className:"mono",children:a.bizar})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Type"}),e.jsx("span",{children:a.type})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Permissions"}),e.jsx("span",{children:a.permissions.length})]}),a.installedAt&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Installed"}),e.jsx("span",{children:new Date(a.installedAt).toLocaleDateString()})]})]})]})})]})}function At({snapshot:s,onNavigate:t}){var b,c,m;const[n,r]=i.useState(""),l=[{id:"artifacts",icon:W,label:"Plans",count:s.artifacts.length||0,desc:"Visual artifacts with elements & comments"},{id:"agents",icon:te,label:"Agents",count:((b=s.agents)==null?void 0:b.length)||0,desc:"The Norse pantheon"},{id:"skills",icon:V,label:"Skills",count:null,desc:"Agent capabilities & tools"},{id:"mods",icon:V,label:"Mods",count:((c=s.mods)==null?void 0:c.length)||0,desc:"Installed modifications"},{id:"schedules",icon:de,label:"Schedules",count:((m=s.schedules)==null?void 0:m.length)||0,desc:"Cron jobs & automated tasks"},{id:"history",icon:re,label:"History",count:null,desc:"Past sessions & outputs"},{id:"config",icon:Oe,label:"Config",count:null,desc:"Key-value configuration editor"}],u=n.trim()?l.filter(y=>y.label.toLowerCase().includes(n.toLowerCase())||y.desc.toLowerCase().includes(n.toLowerCase())):l;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:n,onChange:y=>r(y.target.value),style:{flex:1}})}),e.jsx("div",{className:"mobile-card-list",children:u.map(y=>{const a=y.icon;return e.jsxs("button",{type:"button",className:"mobile-more-nav-item",onClick:()=>t(y.id),children:[e.jsx("div",{className:"mobile-more-nav-icon",children:e.jsx(a,{size:20})}),e.jsxs("div",{className:"mobile-more-nav-content",children:[e.jsxs("span",{className:"mobile-more-nav-label",children:[y.label,y.count!=null&&e.jsx("span",{className:"mobile-more-nav-count",children:y.count})]}),e.jsx("span",{className:"mobile-more-nav-desc",children:y.desc})]}),e.jsx(je,{size:16,className:"mobile-more-nav-arrow"})]},y.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 me=[{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 oe(s){var t;return((t=me.find(n=>n.id===s))==null?void 0:t.color)||"var(--text-dim)"}function Et({type:s,size:t=12}){switch(s){case"task":return e.jsx(Z,{size:t,style:{color:"var(--info)"}});case"note":return e.jsx(ge,{size:t,style:{color:"var(--text-dim)"}});case"decision":return e.jsx(Z,{size:t,style:{color:"var(--accent)"}});case"question":return e.jsx(lt,{size:t,style:{color:"var(--warning)"}});default:return e.jsx(ge,{size:t})}}function $t({slug:s,onBack:t}){const[n,r]=i.useState(null),[l,u]=i.useState(null),[b,c]=i.useState(!0),[m,y]=i.useState(!1),[a,x]=i.useState(null),[k,h]=i.useState(!1),[d,o]=i.useState(!1),[N,p]=i.useState(!1),[j,A]=i.useState(""),S=async()=>{c(!0);try{const f=await T.get(`/plans/${encodeURIComponent(s)}`);r(f.canvas),u(f.meta)}catch{}finally{c(!1)}};i.useEffect(()=>{S()},[s]);const R=async(f,v,g)=>{try{const C=((n==null?void 0:n.elements)||[]).reduce((I,O)=>Math.max(I,O.x||0),40),E=((n==null?void 0:n.elements)||[]).reduce((I,O)=>Math.max(I,O.y||0),40);await T.post(`/plans/${encodeURIComponent(s)}/elements`,{type:f,title:v,content:g,x:20+C,y:20+E,width:240,height:120}),await S(),o(!1)}catch{}},z=async(f,v)=>{try{await T.put(`/plans/${encodeURIComponent(s)}/elements/${encodeURIComponent(f)}`,v),await S(),x(null)}catch{}},P=async f=>{if(confirm("Delete this element?"))try{await T.del(`/plans/${encodeURIComponent(s)}/elements/${encodeURIComponent(f)}`),x(null),await S()}catch{}},D=async(f,v)=>{try{const g=v?`/plans/${encodeURIComponent(s)}/elements/${encodeURIComponent(v)}/comments`:`/plans/${encodeURIComponent(s)}/comments`;await T.post(g,{text:f,elementId:v}),await S(),A(""),p(!1)}catch{}};return b||!n||!l?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:l.title||s}),e.jsx("span",{className:"mobile-canvas-status","data-status":l.status,children:l.status})]}),e.jsxs("div",{className:"mobile-canvas-actions",children:[e.jsx("button",{type:"button",className:`mobile-icon-btn ${m?"active":""}`,onClick:()=>y(f=>!f),"aria-label":m?"Done editing":"Edit",children:e.jsx(Ue,{size:16})}),e.jsxs("button",{type:"button",className:"mobile-icon-btn",onClick:()=>h(f=>!f),"aria-label":"Comments",children:[e.jsx(Y,{size:16}),n.comments.length>0&&e.jsx("span",{className:"mobile-canvas-comment-count",children:n.comments.length})]}),m&&e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>o(!0),"aria-label":"Add element",children:e.jsx(B,{size:16})})]})]}),e.jsxs("div",{className:"mobile-canvas-elements",children:[n.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:()=>o(!0),children:[e.jsx(B,{size:14})," Add Element"]})]}),n.elements.map(f=>e.jsxs("button",{type:"button",className:`mobile-canvas-element ${(a==null?void 0:a.id)===f.id?"selected":""}`,style:{borderColor:oe(f.type)},onClick:()=>{m&&x(f)},"aria-pressed":(a==null?void 0:a.id)===f.id,children:[e.jsxs("div",{className:"mobile-canvas-el-header",style:{background:`${oe(f.type)}18`},children:[e.jsx(Et,{type:f.type,size:12}),e.jsx("span",{className:"mobile-canvas-el-type",style:{color:oe(f.type)},children:f.type}),f.status&&f.status!=="open"&&e.jsx("span",{className:"mobile-canvas-el-status",children:f.status})]}),e.jsx("div",{className:"mobile-canvas-el-title",children:f.title||"Untitled"}),f.content&&e.jsxs("div",{className:"mobile-canvas-el-content",children:[f.content.slice(0,120),f.content.length>120?"…":""]}),e.jsxs("div",{className:"mobile-canvas-el-comments",children:[e.jsx(Y,{size:10}),n.comments.filter(v=>v.elementId===f.id).length]})]},f.id))]}),k&&e.jsxs("div",{className:"mobile-canvas-comments",children:[e.jsxs("div",{className:"mobile-canvas-comments-header",children:[e.jsxs("h4",{children:["Comments (",n.comments.length,")"]}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>h(!1),children:e.jsx(ee,{size:16})})]}),e.jsxs("div",{className:"mobile-canvas-comment-list",children:[n.comments.length===0&&e.jsx("p",{className:"mobile-empty-inline",children:"No comments yet."}),n.comments.map(f=>e.jsxs("div",{className:"mobile-canvas-comment",children:[e.jsxs("div",{className:"mobile-canvas-comment-head",children:[e.jsx("span",{className:"mono",children:f.author}),e.jsx("span",{className:"muted",children:K(f.created)})]}),e.jsx("div",{className:"mobile-canvas-comment-text",children:f.text})]},f.id))]}),e.jsxs("div",{className:"mobile-canvas-comment-input",children:[e.jsx("textarea",{className:"mobile-input",rows:2,placeholder:"Add a comment…",value:j,onChange:f=>A(f.target.value)}),e.jsx("button",{type:"button",className:"mobile-btn",disabled:!j.trim(),onClick:()=>{D(j.trim(),null)},children:"Post"})]})]}),a&&e.jsx(F,{open:!0,onClose:()=>x(null),title:`Edit ${a.title||a.type}`,actions:e.jsxs("div",{className:"mobile-task-detail-actions",children:[e.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>P(a.id),children:[e.jsx(se,{size:14})," Delete"]}),e.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>p(!0),children:[e.jsx(Y,{size:14})," Comment"]})]}),children:e.jsx(Lt,{element:a,onSave:f=>z(a.id,f),onClose:()=>x(null)})}),e.jsx(zt,{open:d,onClose:()=>o(!1),onAdd:R}),e.jsx(_,{open:N,onClose:()=>p(!1),title:"Add Comment",actions:e.jsxs("button",{type:"button",className:"mobile-btn",style:{width:"100%"},disabled:!j.trim(),onClick:()=>{D(j.trim(),(a==null?void 0:a.id)||null),p(!1)},children:[e.jsx(Y,{size:14})," Post"]}),children:e.jsx("textarea",{className:"mobile-input",rows:3,placeholder:"Your comment…",value:j,onChange:f=>A(f.target.value),autoFocus:!0})})]})}function Lt({element:s,onSave:t,onClose:n}){const[r,l]=i.useState(s.type),[u,b]=i.useState(s.title||""),[c,m]=i.useState(s.content||""),[y,a]=i.useState(s.status||"open");return e.jsxs("form",{className:"mobile-task-form",onSubmit:x=>{x.preventDefault(),t({type:r,title:u,content:c,status:y}),n()},children:[e.jsx("label",{className:"mobile-field-label",children:"Type"}),e.jsx("select",{className:"mobile-input",value:r,onChange:x=>l(x.target.value),children:me.map(x=>e.jsx("option",{value:x.id,children:x.label},x.id))}),e.jsx("label",{className:"mobile-field-label",children:"Title"}),e.jsx("input",{className:"mobile-input",type:"text",value:u,onChange:x=>b(x.target.value)}),e.jsx("label",{className:"mobile-field-label",children:"Status"}),e.jsx("input",{className:"mobile-input",type:"text",value:y,onChange:x=>a(x.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:c,onChange:x=>m(x.target.value)}),e.jsx("button",{type:"submit",className:"mobile-btn",style:{width:"100%",marginTop:8},children:"Save"})]})}function zt({open:s,onClose:t,onAdd:n}){const[r,l]=i.useState("task"),[u,b]=i.useState(""),[c,m]=i.useState(""),y=a=>{a.preventDefault(),u.trim()&&(n(r,u.trim(),c.trim()),b(""),m(""))};return e.jsx(_,{open:s,onClose:t,title:"Add Element",actions:e.jsxs("button",{type:"submit",form:"add-el-form",className:"mobile-btn",style:{width:"100%"},children:[e.jsx(B,{size:14})," Add"]}),children:e.jsxs("form",{id:"add-el-form",onSubmit:y,className:"mobile-task-form",children:[e.jsx("label",{className:"mobile-field-label",children:"Type"}),e.jsx("select",{className:"mobile-input",value:r,onChange:a=>l(a.target.value),children:me.map(a=>e.jsx("option",{value:a.id,children:a.label},a.id))}),e.jsx("label",{className:"mobile-field-label",children:"Title *"}),e.jsx("input",{className:"mobile-input",type:"text",placeholder:"Element title",value:u,onChange:a=>b(a.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:c,onChange:a=>m(a.target.value)})]})})}function Rt({snapshot:s,onBack:t,onOpenArtifact:n}){const[r,l]=i.useState(s.artifacts||[]),[u,b]=i.useState(!s.artifacts),[c,m]=i.useState(""),[y,a]=i.useState(!1),[x,k]=i.useState(""),[h,d]=i.useState(""),o=async()=>{try{const j=await T.get("/artifacts");l(j.artifacts||[])}catch{}finally{b(!1)}},N=async()=>{if(x.trim())try{const j=await T.post("/artifacts",{slug:x.trim(),title:h.trim()||void 0});a(!1),k(""),d(""),n(j.slug)}catch{}},p=c.trim()?r.filter(j=>(j.title||j.slug||"").toLowerCase().includes(c.toLowerCase())):r;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:c,onChange:j=>m(j.target.value),style:{flex:1}}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>o(),"aria-label":"Refresh",children:e.jsx(q,{size:16})})]}),e.jsx("div",{style:{marginBottom:12},children:e.jsxs("button",{type:"button",className:"mobile-btn",style:{width:"100%"},onClick:()=>a(!0),children:[e.jsx(B,{size:14})," New Artifact"]})}),u?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading…"})}):p.length===0?e.jsxs("div",{className:"mobile-empty",children:[e.jsx(W,{size:40}),e.jsx("p",{children:"No artifacts yet."})]}):e.jsx("div",{className:"mobile-card-list",children:p.map(j=>e.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>n(j.slug),children:[e.jsx("div",{className:"mobile-list-icon",children:e.jsx(W,{size:16})}),e.jsxs("div",{className:"mobile-list-content",children:[e.jsx("span",{className:"mobile-list-title",children:j.title||j.slug}),e.jsxs("span",{className:"mobile-list-meta",children:[j.status," · ",j.source,j.elementCount!=null?` · ${j.elementCount} elements`:"",j.commentCount!=null?` · ${j.commentCount} comments`:""]})]}),e.jsx("span",{className:"mobile-list-badge","data-status":j.status,children:j.status})]},j.slug))}),e.jsx(_,{open:y,onClose:()=>a(!1),title:"New Artifact",actions:e.jsxs("button",{type:"submit",form:"new-plan-form",className:"mobile-btn",style:{width:"100%"},children:[e.jsx(B,{size:14})," Create"]}),children:e.jsxs("form",{id:"new-plan-form",onSubmit:j=>{j.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:x,onChange:j=>k(j.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:h,onChange:j=>d(j.target.value)})]})})]})}const It=["cron","interval","once"],Dt=["command","agent","webhook"],$e=["UTC","America/New_York","America/Los_Angeles","Europe/London","Europe/Berlin","Asia/Tokyo"],We=Array.from({length:24},(s,t)=>({value:t,label:t===0?"12 AM":t<12?`${t} AM`:t===12?"12 PM":`${t-12} PM`})),Mt=Array.from({length:12},(s,t)=>t*5),He=[{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"}],Pt=[{value:"s",label:"sec"},{value:"m",label:"min"},{value:"h",label:"hr"},{value:"d",label:"day"}];function Ot({snapshot:s}){var N;const[t,n]=i.useState(s.schedules||[]),[r,l]=i.useState(!s.schedules),[u,b]=i.useState(""),[c,m]=i.useState(null),[y,a]=i.useState({open:!1}),x=async()=>{try{const p=await T.get("/schedules");n(p.schedules||[])}catch{}finally{l(!1)}};i.useEffect(()=>{s.schedules?(n(s.schedules),l(!1)):x()},[s.schedules]);const k=async(p,j)=>{try{await T.patch(`/schedules/${encodeURIComponent(p)}`,{enabled:j}),n(A=>A.map(S=>S.id===p?{...S,enabled:j}:S)),(c==null?void 0:c.id)===p&&m(A=>A&&{...A,enabled:j})}catch{}},h=async p=>{if(confirm("Delete this schedule?"))try{await T.del(`/schedules/${encodeURIComponent(p)}`),n(j=>j.filter(A=>A.id!==p)),(c==null?void 0:c.id)===p&&m(null)}catch{}},d=async p=>{try{await T.post(`/schedules/${encodeURIComponent(p)}/trigger`)}catch{}},o=u.trim()?t.filter(p=>p.name.toLowerCase().includes(u.toLowerCase())):t;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:u,onChange:p=>b(p.target.value),style:{flex:1}}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>x(),"aria-label":"Refresh",children:e.jsx(q,{size:16})}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>a({open:!0}),"aria-label":"New schedule",children:e.jsx(B,{size:16})})]}),r?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading…"})}):o.length===0?e.jsxs("div",{className:"mobile-empty",children:[e.jsx(de,{size:40}),e.jsx("p",{children:"No schedules found."})]}):e.jsx("div",{className:"mobile-card-list",children:o.map(p=>e.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>m(p),children:[e.jsx("div",{className:"mobile-list-icon",children:e.jsx(de,{size:16})}),e.jsxs("div",{className:"mobile-list-content",children:[e.jsx("span",{className:"mobile-list-title",children:p.name}),e.jsxs("span",{className:"mobile-list-meta",children:[Re(p)," ·"," ",p.nextRun?`next ${ze(p.nextRun,p.timezone)}`:"no next run"]})]}),e.jsx("span",{className:`mobile-list-badge ${p.enabled?"badge-on":"badge-off"}`,children:p.enabled?"on":"off"})]},p.id))}),c&&e.jsx(F,{open:!0,onClose:()=>m(null),title:c.name,actions:e.jsxs("div",{className:"mobile-task-detail-actions",children:[e.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>{c&&d(c.id)},children:[e.jsx(X,{size:14})," Trigger now"]}),e.jsx("button",{type:"button",className:`mobile-btn ${c.enabled?"mobile-btn-secondary":""}`,onClick:()=>{c&&k(c.id,!c.enabled)},children:c.enabled?"Disable":"Enable"}),e.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>{c&&(a({open:!0,initial:c}),m(null))},children:[e.jsx(Ue,{size:14})," Edit"]}),e.jsx("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>{c&&h(c.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:c.type})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Schedule"}),e.jsx("span",{className:"mono",children:Re(c)||c.schedule})]}),c.timezone&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Timezone"}),e.jsx("span",{className:"mono",children:c.timezone})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Action"}),e.jsxs("span",{children:[c.action.type,": ",c.action.target]})]}),c.action.type==="agent"&&c.action.prompt&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Prompt"}),e.jsx("span",{style:{fontSize:12},children:c.action.prompt})]}),((N=c.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 ≥ ",c.budgetCheck.maxConcurrent??6," concurrent"]})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Next run"}),e.jsx("span",{children:c.nextRun?ze(c.nextRun,c.timezone):"—"})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Last run"}),e.jsx("span",{children:c.lastRun?Ft(c.lastRun):"—"})]}),c.lastResult&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Last result"}),e.jsx("span",{style:{fontSize:12},children:c.lastResult})]}),c.lastError&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Last error"}),e.jsx("span",{style:{fontSize:12},children:c.lastError})]})]})})}),e.jsx(Bt,{open:y.open,initial:y.initial,onClose:()=>a({open:!1}),onSaved:()=>{a({open:!1}),x()}})]})}function Le(s){var r,l;if(!s)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 t=s.type==="cron"?Ye(s.schedule):null,n=s.type==="interval"?qt(s.schedule):null;return{name:s.name||"",type:s.type,cronMinute:(t==null?void 0:t.minute)??0,cronHour:(t==null?void 0:t.hour)??9,cronDow:(t==null?void 0:t.dow)??"*",intervalN:(n==null?void 0:n.n)??30,intervalUnit:(n==null?void 0:n.unit)??"m",onceAt:s.type==="once"?_t(s.schedule):"",timezone:s.timezone||"UTC",actionType:s.action.type,actionTarget:s.action.target||"",actionPrompt:s.action.prompt||"",skipIfBudgetLow:!!((r=s.budgetCheck)!=null&&r.skipIfBudgetLow),maxConcurrent:Number.isFinite((l=s.budgetCheck)==null?void 0:l.maxConcurrent)?s.budgetCheck.maxConcurrent:6,enabled:s.enabled!==!1}}function Ut(s){if(s.type==="cron")return`${s.cronMinute} ${s.cronHour} * * ${s.cronDow}`;if(s.type==="interval")return`${s.intervalN}${s.intervalUnit}`;if(!s.onceAt)return"";try{return new Date(s.onceAt).toISOString()}catch{return s.onceAt}}function Bt({open:s,initial:t,onClose:n,onSaved:r}){const[l,u]=i.useState(()=>Le(t)),[b,c]=i.useState(!1);i.useEffect(()=>{s&&u(Le(t))},[s,t]);const m=(a,x)=>{u(k=>({...k,[a]:x}))},y=async a=>{if(a.preventDefault(),!l.name.trim())return;const x=Ut(l);if(x){c(!0);try{const k={name:l.name.trim(),type:l.type,schedule:x,timezone:l.timezone,action:{type:l.actionType,target:l.actionTarget.trim(),...l.actionType==="agent"&&l.actionPrompt.trim()?{prompt:l.actionPrompt.trim()}:{}},budgetCheck:{maxConcurrent:l.maxConcurrent,skipIfBudgetLow:l.skipIfBudgetLow},enabled:l.enabled};t?await T.put(`/schedules/${encodeURIComponent(t.id)}`,k):await T.post("/schedules",k),r()}catch{}finally{c(!1)}}};return e.jsx(_,{open:s,onClose:n,title:t?`Edit ${t.name}`:"New schedule",actions:e.jsxs("button",{type:"submit",form:"mobile-schedule-form",className:"mobile-btn",style:{width:"100%"},disabled:b,children:[e.jsx(B,{size:14})," ",t?"Save":"Create"]}),children:e.jsxs("form",{id:"mobile-schedule-form",onSubmit:y,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:l.name,onChange:a=>m("name",a.target.value),autoFocus:!0,required:!0}),e.jsx("label",{className:"mobile-field-label",children:"Type"}),e.jsx("select",{className:"mobile-input",value:l.type,onChange:a=>m("type",a.target.value),children:It.map(a=>e.jsx("option",{value:a,children:a},a))}),l.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:l.cronDow,onChange:a=>m("cronDow",a.target.value),children:He.map(a=>e.jsx("option",{value:a.value,children:a.label},a.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(l.cronHour),onChange:a=>m("cronHour",parseInt(a.target.value,10)),children:We.map(a=>e.jsx("option",{value:String(a.value),children:a.label},a.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(l.cronMinute),onChange:a=>m("cronMinute",parseInt(a.target.value,10)),children:Mt.map(a=>e.jsx("option",{value:String(a),children:String(a).padStart(2,"0")},a))})]})]})]}),l.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:l.intervalN,onChange:a=>m("intervalN",parseInt(a.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:l.intervalUnit,onChange:a=>m("intervalUnit",a.target.value),children:Pt.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))})]})]}),l.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:l.onceAt,onChange:a=>m("onceAt",a.target.value)})]}),e.jsx("label",{className:"mobile-field-label",children:"Timezone"}),e.jsx("select",{className:"mobile-input",value:$e.includes(l.timezone)?l.timezone:"UTC",onChange:a=>m("timezone",a.target.value),children:$e.map(a=>e.jsx("option",{value:a,children:a},a))}),e.jsx("label",{className:"mobile-field-label",children:"Action type"}),e.jsx("select",{className:"mobile-input",value:l.actionType,onChange:a=>m("actionType",a.target.value),children:Dt.map(a=>e.jsx("option",{value:a,children:a},a))}),e.jsx("label",{className:"mobile-field-label",children:"Target"}),e.jsx("input",{className:"mobile-input",type:"text",placeholder:l.actionType==="webhook"?"https://...":l.actionType==="agent"?"agent or task ref":"echo hello",value:l.actionTarget,onChange:a=>m("actionTarget",a.target.value)}),l.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:l.actionPrompt,onChange:a=>m("actionPrompt",a.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:l.skipIfBudgetLow,onChange:a=>m("skipIfBudgetLow",a.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:l.maxConcurrent,onChange:a=>m("maxConcurrent",parseInt(a.target.value,10)||6),disabled:!l.skipIfBudgetLow})]}),e.jsxs("label",{className:"mobile-checkbox-row",children:[e.jsx("input",{type:"checkbox",checked:l.enabled,onChange:a=>m("enabled",a.target.checked)}),e.jsx("span",{children:"Enabled"})]})]})})}function Ft(s){const t=Date.now()-new Date(s).getTime();return t<6e4?"just now":t<36e5?`${Math.floor(t/6e4)}m ago`:t<864e5?`${Math.floor(t/36e5)}h ago`:new Date(s).toLocaleDateString()}function ze(s,t){try{return new Date(s).toLocaleString(void 0,{timeZone:t||void 0,weekday:"short",hour:"numeric",minute:"2-digit",month:"short",day:"numeric"})}catch{return new Date(s).toLocaleString()}}function Ye(s){if(typeof s!="string")return null;const t=s.trim().split(/\s+/);if(t.length!==5)return null;const[n,r,,,l]=t,u=parseInt(n,10),b=parseInt(r,10);return!Number.isFinite(u)||!Number.isFinite(b)||n!==String(u)||r!==String(b)?null:{minute:u,hour:b,dow:l==="*"?"*":Number.isFinite(parseInt(l,10))?l:"*"}}function qt(s){if(typeof s!="string")return null;const t=/^(\d+)([smhd])$/i.exec(s.trim());return t?{n:parseInt(t[1],10),unit:t[2].toLowerCase()}:null}function _t(s){if(!s)return"";try{const t=new Date(s);if(Number.isNaN(t.getTime()))return"";const n=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}catch{return""}}function Re(s){var u,b;if(s.type!=="cron")return s.schedule;const t=Ye(s.schedule);if(!t)return s.schedule;const n=((u=He.find(c=>c.value===t.dow))==null?void 0:u.label)||t.dow,r=((b=We.find(c=>c.value===t.hour))==null?void 0:b.label)||`${t.hour}`,l=String(t.minute).padStart(2,"0");return n==="Every day"?`Every day ${r} :${l}`:`Every ${n} ${r} :${l}`}const Wt=["all","tasks","agents","artifacts","projects","settings"],Ht={tasks:Z,agents:te,plans:W,projects:ot,settings:V};function Yt({open:s,onClose:t,onNavigate:n}){const[r,l]=i.useState(""),[u,b]=i.useState("all"),[c,m]=i.useState([]),[y,a]=i.useState(!1),x=i.useRef(null);i.useEffect(()=>{s&&(l(""),m([]),requestAnimationFrame(()=>{var d;return(d=x.current)==null?void 0:d.focus()}))},[s]),i.useEffect(()=>{if(!r.trim()){m([]);return}const d=setTimeout(async()=>{a(!0);try{const o=await T.get(`/search?q=${encodeURIComponent(r)}&scope=${u}`);m(o.results||[])}catch{m([])}finally{a(!1)}},250);return()=>clearTimeout(d)},[r,u]);const k=d=>{const o=d.item,N=o.id||o.slug||o.name||"";n(d.type,N),t()},h=c.reduce((d,o)=>(d[o.type]||(d[o.type]=[]),d[o.type].push(o),d),{});return e.jsx(_,{open:s,onClose:t,title:"Search",children:e.jsxs("div",{className:"mobile-search-container",children:[e.jsxs("div",{className:"mobile-search-input-row",children:[e.jsx(ve,{size:16,style:{color:"var(--text-muted)",flexShrink:0}}),e.jsx("input",{ref:x,className:"mobile-search-field",type:"text",placeholder:"Search…",value:r,onChange:d=>l(d.target.value),enterKeyHint:"search",onKeyDown:d=>{d.key==="Escape"&&t(),d.key==="Enter"&&c.length>0&&k(c[0])}}),r&&e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>l(""),"aria-label":"Clear",children:e.jsx(ee,{size:16})})]}),e.jsx("div",{className:"mobile-search-scopes",children:Wt.map(d=>e.jsx("button",{type:"button",className:`mobile-scope-chip ${u===d?"active":""}`,onClick:()=>b(d),children:d==="all"?"All":d.charAt(0).toUpperCase()+d.slice(1)},d))}),e.jsxs("div",{className:"mobile-search-results",children:[y&&e.jsx("div",{className:"mobile-search-loading",children:"Searching…"}),!y&&r&&c.length===0&&e.jsxs("div",{className:"mobile-empty",children:[e.jsx(ve,{size:32}),e.jsx("p",{children:"No results found"})]}),!y&&!r&&e.jsx("div",{className:"mobile-empty",children:e.jsx("p",{children:"Type to search across tasks, agents, plans, and more."})}),Object.entries(h).map(([d,o])=>{const N=Ht[d]||W;return e.jsxs("div",{className:"mobile-search-group",children:[e.jsxs("h4",{className:"mobile-search-group-title",children:[e.jsx(N,{size:12})," ",d.charAt(0).toUpperCase()+d.slice(1)," (",o.length,")"]}),o.map((p,j)=>{const A=p.item;return e.jsxs("button",{type:"button",className:"mobile-search-result-item",onClick:()=>k(p),children:[e.jsx("span",{className:"mobile-search-result-title",children:A.title||A.name||A.slug||"(unnamed)"}),A.description&&e.jsx("span",{className:"mobile-search-result-meta",children:A.description.slice(0,80)})]},j)})]},d)})]})]})})}const Kt=["languages","framework","design","testing","devops","data","security","integration"];function Vt({snapshot:s,onBack:t}){const[n,r]=i.useState([]),[l,u]=i.useState(!0),[b,c]=i.useState(""),[m,y]=i.useState(""),[a,x]=i.useState(null),k=async()=>{try{const o=await T.get("/skills");r(o.skills||[])}catch{}finally{u(!1)}};i.useEffect(()=>{k()},[]);const h=async(o,N)=>{try{await T.patch(`/skills/${encodeURIComponent(o)}`,{enabled:N}),r(p=>p.map(j=>j.id===o?{...j,enabled:N}:j)),(a==null?void 0:a.id)===o&&x(p=>p&&{...p,enabled:N})}catch{}},d=n.filter(o=>{if(m&&o.category!==m)return!1;if(b){const N=b.toLowerCase();return o.name.toLowerCase().includes(N)||o.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:b,onChange:o=>c(o.target.value),style:{flex:1}}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>k(),"aria-label":"Refresh",children:e.jsx(q,{size:16})})]}),e.jsxs("div",{className:"mobile-search-scopes",children:[e.jsx("button",{type:"button",className:`mobile-scope-chip ${m?"":"active"}`,onClick:()=>y(""),children:"All"}),Kt.map(o=>e.jsx("button",{type:"button",className:`mobile-scope-chip ${m===o?"active":""}`,onClick:()=>y(o),children:o},o))]}),l?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading…"})}):d.length===0?e.jsxs("div",{className:"mobile-empty",children:[e.jsx(ye,{size:40}),e.jsx("p",{children:"No skills found."})]}):e.jsx("div",{className:"mobile-card-list",children:d.map(o=>e.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>x(o),children:[e.jsx("div",{className:"mobile-list-icon",children:e.jsx(ye,{size:16})}),e.jsxs("div",{className:"mobile-list-content",children:[e.jsx("span",{className:"mobile-list-title",children:o.name}),e.jsxs("span",{className:"mobile-list-meta",children:[o.category," · v",o.version]})]}),e.jsx("span",{className:`mobile-list-badge ${o.enabled?"badge-on":"badge-off"}`,children:o.enabled?"on":"off"})]},o.id))}),a&&e.jsx(F,{open:!0,onClose:()=>x(null),title:a.name,actions:e.jsxs("button",{type:"button",className:`mobile-btn ${a.enabled?"mobile-btn-secondary":""}`,style:{width:"100%"},onClick:()=>{a&&h(a.id,!a.enabled)},children:[e.jsx(Pe,{size:14})," ",a.enabled?"Disable":"Enable"]}),children:e.jsxs("div",{className:"mobile-agent-detail",children:[e.jsx("p",{className:"mobile-agent-detail-desc",children:a.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:a.category})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Version"}),e.jsx("span",{className:"mono",children:a.version})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Source"}),e.jsx("span",{children:a.source})]}),a.tags.length>0&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Tags"}),e.jsx("span",{children:a.tags.join(", ")})]})]})]})})]})}const Jt=["queued","doing","blocked","done"],G={queued:"Queued",doing:"Doing",blocked:"Blocked",done:"Done"},Ie={queued:"doing",doing:"done",blocked:"queued",done:"queued"};function Gt(s){const t=s.metadata??{};return!!(t.sessionId||t.bgInstanceId)}function Qt(s){var n;const t=s.metadata??{};return!!((n=t.artifactIds)!=null&&n.length||t.artifactId)}function De({snapshot:s,onRefresh:t,selectedTaskId:n,onCloseDetail:r,onOpenChat:l,onOpenArtifact:u}){var pe,fe;const[b,c]=i.useState(s.tasks||[]),[m,y]=i.useState(!s.tasks),[a,x]=i.useState(""),[k,h]=i.useState("queued"),[d,o]=i.useState(null),[N,p]=i.useState(!1),[j,A]=i.useState(null),[S,R]=i.useState([]),[z,P]=i.useState(""),[D,f]=i.useState(null),[v,g]=i.useState(!1),[C,E]=i.useState(""),[I,O]=i.useState("updated");i.useEffect(()=>{var w;if(s.tasks&&(c(s.tasks),y(!1)),n){const L=(w=s.tasks)==null?void 0:w.find($=>$.id===n);L&&o(L)}},[s.tasks,n]),i.useEffect(()=>{if(n){const w=b.find(L=>L.id===n);w&&o(w)}},[n,b]);const J=async()=>{try{const w=await T.get("/tasks");c(Array.isArray(w)?w:[])}catch{}finally{y(!1)}},H=async(w,L)=>{c($=>$.map(M=>M.id===w?{...M,status:L}:M)),(d==null?void 0:d.id)===w&&o($=>$&&{...$,status:L});try{await T.patch(`/tasks/${encodeURIComponent(w)}/status`,{status:L})}catch{await J()}},Ke=async w=>{if(confirm("Delete this task?"))try{await T.del(`/tasks/${encodeURIComponent(w)}`),c(L=>L.filter($=>$.id!==w)),(d==null?void 0:d.id)===w&&o(null)}catch{await J()}},Ve=async w=>{try{await T.post(`/tasks/${encodeURIComponent(w)}/archive`),c(L=>L.filter($=>$.id!==w)),(d==null?void 0:d.id)===w&&o(null)}catch{}},ue=[...b.filter(w=>{var L,$;if(a.trim()){const M=a.toLowerCase();if(!(w.title||"").toLowerCase().includes(M)&&!(w.description||"").toLowerCase().includes(M))return!1}if(C.trim()){const M=C==="mine"?(($=(L=s.settings)==null?void 0:L.data)==null?void 0:$.defaultAgent)||Xt(s):C.replace(/^@/,"");if((w.assignee||"").toLowerCase()!==M.toLowerCase())return!1}return!0})].sort((w,L)=>{switch(I){case"priority":{const $={high:0,normal:1,low:2};return($[w.priority]??1)-($[L.priority]??1)}case"created":return new Date(L.createdAt).getTime()-new Date(w.createdAt).getTime();case"updated":default:return new Date(L.updatedAt).getTime()-new Date(w.updatedAt).getTime()}}),he=ue.filter(w=>w.status===k),be=s.agents||[],Je=async(w,L,$,M)=>{try{const ae=await T.post("/tasks",{title:w,description:L,assignee:$||null,priority:M});c(ne=>[ae,...ne]),p(!1)}catch{}},Ge=async w=>{g(!0),P(""),f(null),A(w);try{const $=((await T.get(`/tasks/${encodeURIComponent(w)}/artifacts`)).artifacts||[]).map(M=>M.id);if(R($),$.length>0){const[M,ae]=await Promise.all([T.get(`/artifacts/${encodeURIComponent($[0])}`),fetch(T.urlWithToken(`/artifacts/${encodeURIComponent($[0])}/content`)).then(ne=>ne.text())]);f(M),P(ae)}}catch{}finally{g(!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:a,onChange:w=>x(w.target.value),style:{flex:1}}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>J(),"aria-label":"Refresh",children:e.jsx(q,{size:16})})]}),e.jsxs("div",{className:"mobile-tasks-filters",children:[e.jsxs("select",{className:"mobile-filter-select",value:C,onChange:w=>E(w.target.value),children:[e.jsx("option",{value:"",children:"All"}),e.jsx("option",{value:"mine",children:"Mine"}),be.map(w=>e.jsxs("option",{value:`@${w.name}`,children:["@",w.name]},w.name))]}),e.jsxs("select",{className:"mobile-filter-select",value:I,onChange:w=>O(w.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:Jt.map(w=>{const L=ue.filter($=>$.status===w).length;return e.jsxs("button",{type:"button",className:`mobile-kanban-tab ${k===w?"active":""}`,onClick:()=>h(w),children:[G[w]," (",L,")"]},w)})}),e.jsxs("div",{className:"mobile-card-list",children:[he.length===0&&e.jsxs("div",{className:"mobile-empty mobile-empty-compact",children:[e.jsxs("p",{children:["No ",G[k].toLowerCase()," tasks."]}),e.jsx("p",{className:"muted",children:"Create one or switch columns."})]}),he.map(w=>{var L;return e.jsxs("button",{type:"button",className:"mobile-task-card",onClick:()=>o(w),children:[e.jsx("div",{className:"priority-dot",style:{background:dt[w.priority]||"var(--info)"}}),e.jsxs("div",{className:"task-content",children:[e.jsx("div",{className:"task-title",children:w.title}),e.jsxs("div",{className:"task-meta",children:[w.assignee?`@${w.assignee}`:"unassigned"," · ",K(w.updatedAt||w.createdAt),(L=w.dependencies)!=null&&L.length?` · ${w.dependencies.length} deps`:""]})]})]},w.id)})]}),e.jsx("button",{type:"button",className:"mobile-fab",onClick:()=>p(!0),"aria-label":"Add task",children:e.jsx(B,{size:24})}),e.jsx(F,{open:!!d,onClose:()=>{o(null),r==null||r()},title:"Task Detail",actions:d&&e.jsxs("div",{className:"mobile-task-detail-actions",children:[d.status!=="done"&&e.jsxs("button",{type:"button",className:"mobile-btn",style:{flex:1},onClick:()=>{d&&H(d.id,Ie[d.status])},children:["Move to ",G[Ie[d.status]||"queued"]]}),e.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>{d&&Ve(d.id)},children:[e.jsx(ct,{size:14})," Archive"]}),Gt(d)&&e.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>{l==null||l(d.id)},children:[e.jsx(Y,{size:14})," Chat"]}),Qt(d)&&e.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>{Ge(d.id)},children:[e.jsx(W,{size:14})," Artifact"]}),e.jsx("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>{d&&Ke(d.id)},children:e.jsx(se,{size:14})})]}),children:d&&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-${d.status}`,children:G[d.status]||d.status}),e.jsx("span",{className:`mobile-task-priority priority-${d.priority}`,children:d.priority})]}),e.jsx("h3",{className:"mobile-task-detail-title",children:d.title}),d.description&&e.jsx("p",{className:"mobile-task-detail-desc",children:d.description}),e.jsxs("div",{className:"mobile-task-detail-meta",children:[d.assignee&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Assignee"}),e.jsxs("span",{children:["@",d.assignee]})]}),d.dueDate&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Due"}),e.jsx("span",{children:new Date(d.dueDate).toLocaleDateString()})]}),d.timeSpent!=null&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Time spent"}),e.jsxs("span",{children:[Math.round(d.timeSpent/6e4),"min"]})]}),(pe=d.dependencies)!=null&&pe.length?e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Dependencies"}),e.jsx("span",{children:d.dependencies.length})]}):null,(fe=d.comments)!=null&&fe.length?e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Comments"}),e.jsx("span",{children:d.comments.length})]}):null,e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Created"}),e.jsx("span",{children:K(d.createdAt)})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Updated"}),e.jsx("span",{children:K(d.updatedAt)})]})]})]})}),e.jsx(Zt,{open:N,onClose:()=>p(!1),onCreate:Je,agents:be}),e.jsx(F,{open:!!j,onClose:()=>{A(null),P(""),f(null)},title:(D==null?void 0:D.name)||"Artifact",actions:S.length>1?e.jsx("div",{className:"mobile-task-detail-actions",children:S.map((w,L)=>e.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",style:{flex:1},onClick:()=>{g(!0),Promise.all([T.get(`/artifacts/${encodeURIComponent(w)}`),fetch(T.urlWithToken(`/artifacts/${encodeURIComponent(w)}/content`)).then($=>$.text())]).then(([$,M])=>{f($),P(M),g(!1)}).catch(()=>g(!1))},children:["Artifact ",L+1]},w))}):null,children:e.jsx("div",{className:"mobile-artifact-viewer",children:v?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading artifact…"})}):z?e.jsx("iframe",{srcDoc:z,className:"mobile-artifact-iframe",sandbox:"allow-scripts allow-forms allow-popups allow-same-origin",title:(D==null?void 0:D.name)||"Artifact",loading:"lazy"}):e.jsxs("div",{className:"mobile-empty",children:[e.jsx(W,{size:32}),e.jsx("p",{className:"muted",children:"No artifact content available."})]})})})]})}function Xt(s){var t,n;return((n=(t=s.settings)==null?void 0:t.data)==null?void 0:n.defaultAgent)||"odin"}function Zt({open:s,onClose:t,onCreate:n,agents:r}){const[l,u]=i.useState(""),[b,c]=i.useState(""),[m,y]=i.useState(""),[a,x]=i.useState("normal"),k=h=>{h.preventDefault(),l.trim()&&(n(l.trim(),b.trim(),m,a),u(""),c(""),y(""),x("normal"))};return e.jsx(_,{open:s,onClose:t,title:"New Task",actions:e.jsxs("button",{type:"submit",form:"new-task-form",className:"mobile-btn",style:{width:"100%"},children:[e.jsx(B,{size:14})," Create Task"]}),children:e.jsxs("form",{id:"new-task-form",onSubmit:k,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:l,onChange:h=>u(h.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:b,onChange:h=>c(h.target.value)}),e.jsx("label",{className:"mobile-field-label",children:"Assignee"}),e.jsxs("select",{className:"mobile-input",value:m,onChange:h=>y(h.target.value),children:[e.jsx("option",{value:"",children:"Unassigned"}),r.map(h=>e.jsxs("option",{value:h.name,children:["@",h.name]},h.name))]}),e.jsx("label",{className:"mobile-field-label",children:"Priority"}),e.jsxs("select",{className:"mobile-input",value:a,onChange:h=>x(h.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 es=Me.lazy(()=>qe(()=>import("./MobileSettings-BxcbL5XT.js"),__vite__mapDeps([0,1,2])).then(s=>({default:s.MobileSettings}))),ts=Me.lazy(()=>qe(()=>import("./MobileChat-TCputYzr.js"),__vite__mapDeps([3,1,4,2,5,6])).then(s=>({default:s.MobileChat}))),ss=[{id:"activity",label:"Activity",icon:ce},{id:"chat",label:"Chat",icon:Y},{id:"tasks",label:"Tasks",icon:Z},{id:"settings",label:"Settings",icon:Oe},{id:"more",label:"More",icon:rt}];function as(s){const t=s.meta??{},n=typeof t.taskId=="string"?t.taskId:null,r=typeof t.slug=="string"?t.slug:null,l=typeof t.agent=="string"?t.agent:null;if(n)return{id:"task-detail",taskId:n};if(r)return{id:"artifacts?-detail",slug:r};if(l)return{id:"agent-detail",name:l};const u=s.link??"";return u.startsWith("/artifacts?/")?{id:"artifacts?-detail",slug:decodeURIComponent(u.slice(12))}:u.startsWith("/tasks/")?{id:"task-detail",taskId:decodeURIComponent(u.slice(7))}:u.startsWith("/agents/")?{id:"agent-detail",name:decodeURIComponent(u.slice(8))}:null}function us(){const[s,t]=i.useState("activity"),[n,r]=i.useState([]),[l,u]=i.useState(!1),[b,c]=i.useState(null),[m,y]=i.useState(null),[a,x]=i.useState(null),[k,h]=i.useState(null),[d,o]=i.useState(!0),[N,p]=i.useState(0),j=i.useMemo(()=>n[n.length-1]??{id:s},[s,n]),A=i.useCallback(v=>{r(g=>[...g,v])},[]),S=i.useCallback(()=>{r(v=>v.slice(0,-1))},[]),R=i.useCallback(v=>{r([]),t(v)},[]),z=i.useCallback(async()=>{var v;try{const g=await T.get("/snapshot");y(g),(v=g.settings)!=null&&v.data&&x(g.settings.data),h(null)}catch(g){throw h(g.message||"Dashboard server unreachable."),g}},[]);i.useEffect(()=>{let v=!1;return Promise.all([T.get("/snapshot").catch(()=>null),T.get("/settings").catch(()=>null),T.probeAuthStatus().catch(()=>null)]).then(([g,C])=>{var I;if(v)return;const E=(C==null?void 0:C.data)??((I=g==null?void 0:g.settings)==null?void 0:I.data)??null;g&&y(g),E&&x(E),h(!g&&!E?"Dashboard server unreachable.":null)}).catch(g=>{v||h(g.message||"Dashboard server unreachable.")}).finally(()=>{v||o(!1)}),()=>{v=!0}},[]),i.useEffect(()=>{a!=null&&a.theme&&(we(a.theme),Se(a.theme))},[a==null?void 0:a.theme]),i.useEffect(()=>{var C;if(((C=a==null?void 0:a.theme)==null?void 0:C.mode)!=="system")return;const v=window.matchMedia("(prefers-color-scheme: light)"),g=()=>{a!=null&&a.theme&&(we(a.theme),Se(a.theme))};return v.addEventListener("change",g),()=>v.removeEventListener("change",g)},[a==null?void 0:a.theme]),i.useEffect(()=>{const v=()=>{p(C=>C+1),z().catch(()=>{})},g=()=>{document.visibilityState==="visible"&&v()};return window.addEventListener("online",v),window.addEventListener("pageshow",v),document.addEventListener("visibilitychange",g),()=>{window.removeEventListener("online",v),window.removeEventListener("pageshow",v),document.removeEventListener("visibilitychange",g)}},[z]),i.useEffect(()=>{const v=new Fe,g=v.on(C=>{if(C.type==="snapshot"&&"data"in C&&C.data)y(E=>({...E??{},...C.data}));else if(C.type==="change")z().catch(()=>{});else if(C.type==="tasks:change"){const E=C.task;y(I=>{if(!I)return I;const O=(I.tasks||[]).map(H=>H.id===E.id?E:H),J=O.some(H=>H.id===E.id);return{...I,tasks:J?O:[E,...O]}})}else C.type==="tasks:delete"?y(E=>E&&{...E,tasks:(E.tasks||[]).filter(I=>I.id!==C.id)}):C.type==="settings:change"?C.settings&&x(C.settings):C.type==="project:change"||C.type==="agents:change"||C.type==="schedules:change"||C.type==="artifact:change"?z().catch(()=>{}):(C.type==="agent:status"||C.type==="agent:restarted")&&y(E=>{if(!E)return E;const I=(E.agents||[]).map(O=>O.name===C.agent.name?C.agent:O);return{...E,agents:I}})});return()=>{g(),v.close()}},[z,N]);const P=i.useCallback(v=>{(v==="activity"||v==="chat"||v==="tasks"||v==="settings"||v==="more")&&R(v)},[R]),D=i.useCallback((v,g,C)=>{if(v==="notification"){const E=as({link:g||null,meta:C??null});E&&A(E);return}if(v==="task"&&g){A({id:"task-detail",taskId:g});return}if(v==="artifacts?"&&g){A({id:"artifacts?-detail",slug:g});return}if(v==="agent"&&g){A({id:"agent-detail",name:g});return}if(v==="project"){R("activity");return}v==="setting"&&R("settings")},[R,A]),f=()=>{if(!m||!a)return null;if(n.length>0){const v=n[n.length-1];switch(v.id){case"artifacts?":return e.jsx(Rt,{snapshot:m,onBack:S,onOpenArtifact:g=>A({id:"artifacts?-detail",slug:g})});case"agents":return e.jsx(Ee,{snapshot:m,onBack:S,onOpenAgent:g=>A({id:"agent-detail",name:g}),onRefresh:z});case"skills":return e.jsx(Vt,{snapshot:m,onBack:S});case"mods":return e.jsx(Tt,{snapshot:m,onBack:S});case"schedules":return e.jsx(Ot,{snapshot:m,onBack:S});case"history":return e.jsx(Ct,{onBack:S});case"config":return e.jsx(St,{onBack:S});case"artifacts?-detail":return e.jsx($t,{slug:v.slug,onBack:S});case"agent-detail":return e.jsx(Ee,{snapshot:m,onBack:S,onOpenAgent:()=>{},onRefresh:z,selectedAgent:v.name});case"task-detail":return e.jsx(De,{snapshot:m,onRefresh:z,selectedTaskId:v.taskId,onCloseDetail:S,onOpenChat:g=>{c(g),R("chat")}});default:return null}}switch(s){case"activity":return e.jsx(Nt,{snapshot:m,onRefresh:z});case"chat":return e.jsx(i.Suspense,{fallback:e.jsx("div",{className:"mobile-loading",children:e.jsx(ie,{size:"lg"})}),children:e.jsx(ts,{snapshot:m,settings:a,initialTaskId:b,onClearTaskId:()=>c(null)})});case"tasks":return e.jsx(De,{snapshot:m,onRefresh:z,onOpenChat:v=>{c(v),R("chat")}});case"settings":return e.jsx(i.Suspense,{fallback:e.jsx("div",{className:"mobile-loading",children:e.jsx(ie,{size:"lg"})}),children:e.jsx(es,{settings:a,snapshot:m,onRefresh:z})});case"more":return e.jsx(At,{snapshot:m,onNavigate:v=>{(v==="artifacts?"||v==="agents"||v==="skills"||v==="mods"||v==="schedules"||v==="history"||v==="config")&&A({id:v})}});default:return null}};return d?e.jsxs("div",{className:"mobile-loading",children:[e.jsx(ie,{size:"lg"}),e.jsx("p",{children:"Loading Bizar…"})]}):k||!m||!a?e.jsxs("div",{className:"mobile-loading",children:[e.jsx("h2",{children:"Dashboard unavailable"}),e.jsx("p",{children:k||"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(vt,{activeTab:j.id,snapshot:m,onSearch:()=>u(!0),onNavigate:D}),e.jsx("main",{className:"mobile-content",children:f()}),n.length===0&&e.jsx(pt,{tabs:ss,activeTab:s,onChange:P}),n.length>0&&e.jsx("button",{type:"button",className:"mobile-back-btn",onClick:S,"aria-label":"Go back",children:"← Back"}),e.jsx(Yt,{open:l,onClose:()=>u(!1),onNavigate:D})]})}export{ke as A,us as M,ie as S,Fe as W,qe as _,T as a,cs as b,Be as c,Se as d,ds as e,K as f,we as g,dt as p,rs as t,ms as w};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MobileSettings-B91gVFii.js","assets/react-vendor-Dn4wqh4Z.js","assets/icons-Bd8piSb2.js","assets/MobileChat-OidrxXR9.js","assets/useSlashCommands-DEkxEvOO.js","assets/markdown-C6mXtQxD.js","assets/vendor-CeHGtduv.js"])))=>i.map(i=>d[i]);
2
+ var Qe=Object.defineProperty;var Xe=(s,t,n)=>t in s?Qe(s,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):s[t]=n;var O=(s,t,n)=>Xe(s,typeof t!="symbol"?t+"":t,n);import{j as e,r as i,R as Me}from"./react-vendor-Dn4wqh4Z.js";import{X as ee,z as xe,be as Ze,d as et,U as tt,ab as X,ar as st,R as q,B as te,g as ce,t as B,a2 as at,Z as se,a9 as nt,q as K,aH as it,m as re,_ as Pe,N as W,l as de,aT as Ue,e as je,a5 as Oe,M as Y,ad as ge,bf as lt,S as Z,r as ve,b as ot,i as ye,y as ct,bg as rt}from"./icons-Bd8piSb2.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const l of document.querySelectorAll('link[rel="modulepreload"]'))r(l);new MutationObserver(l=>{for(const u of l)if(u.type==="childList")for(const b of u.addedNodes)b.tagName==="LINK"&&b.rel==="modulepreload"&&r(b)}).observe(document,{childList:!0,subtree:!0});function n(l){const u={};return l.integrity&&(u.integrity=l.integrity),l.referrerPolicy&&(u.referrerPolicy=l.referrerPolicy),l.crossOrigin==="use-credentials"?u.credentials="include":l.crossOrigin==="anonymous"?u.credentials="omit":u.credentials="same-origin",u}function r(l){if(l.ep)return;l.ep=!0;const u=n(l);fetch(l.href,u)}})();function Be(...s){return s.filter(Boolean).join(" ")}function V(s){if(!s&&s!==0)return"";const t=typeof s=="number"?s:new Date(s).getTime();if(Number.isNaN(t))return"";const n=Date.now()-t;return n<0||n<6e4?"just now":n<36e5?`${Math.floor(n/6e4)}m ago`:n<864e5?`${Math.floor(n/36e5)}h ago`:n<7*864e5?`${Math.floor(n/864e5)}d ago`:new Date(t).toLocaleDateString()}function cs(s){if(!s)return"";const t=typeof s=="number"?new Date(s):new Date(s);return Number.isNaN(t.getTime())?"":t.toLocaleString()}function rs(s,t=160){return s?s.length>t?s.slice(0,t)+"…":s:""}const dt={low:"var(--text-dim)",normal:"var(--info)",high:"var(--error)"},Q="bizar-auth-token",Ne="bizar-loopback-trusted";class ke extends Error{constructor(n,r,l){super(n);O(this,"status");O(this,"data");this.name="ApiError",this.status=r,this.data=l}}class mt{constructor(){O(this,"base","/api")}getToken(){try{return localStorage.getItem(Q)||""}catch{return""}}setToken(t){try{t?localStorage.setItem(Q,t):localStorage.removeItem(Q)}catch{}}pickupTokenFromUrl(){try{const t=new URLSearchParams(window.location.search),n=t.get("token");if(!n)return!1;this.setToken(n),t.delete("token");const r=t.toString(),l=r?`${window.location.pathname}?${r}`:window.location.pathname;return history.replaceState(null,"",l),!0}catch{return!1}}urlWithToken(t){const n=this.base+t,r=this.getToken();if(!r)return n;const l=n.includes("?")?"&":"?";return`${n}${l}token=${encodeURIComponent(r)}`}async probeAuthStatus(){try{const t=await this.get("/auth/status");try{localStorage.setItem(Ne,t.loopback?"1":"0")}catch{}return t}catch{return{required:!1,loopback:!0,peer:""}}}isLoopbackTrusted(){try{return localStorage.getItem(Ne)!=="0"}catch{return!0}}async get(t,n){return this.req("GET",t,void 0,n)}async post(t,n,r){return this.req("POST",t,n,r)}async put(t,n,r){return this.req("PUT",t,n,r)}async patch(t,n,r){return this.req("PATCH",t,n,r)}async del(t,n){return this.req("DELETE",t,void 0,n)}async req(t,n,r,l){const u={"Content-Type":"application/json"},b=this.getToken();b&&(u.Authorization=`Bearer ${b}`);const c={method:t,headers:u};r!=null&&(c.body=typeof r=="string"?r:JSON.stringify(r)),l&&(c.signal=l);const m=await fetch(this.base+n,c);if((m.headers.get("content-type")||"").includes("application/json")){const x=await m.json();if(!m.ok){const k=(x&&typeof x=="object"&&"message"in x?x.message:void 0)||`${t} ${n}: ${m.status}`;throw new ke(k,m.status,x)}return x}const a=await m.text();if(!m.ok)throw new ke(`${t} ${n}: ${m.status} — ${a.slice(0,200)}`,m.status,a);try{return JSON.parse(a)}catch{return a}}}const T=new mt;T.pickupTokenFromUrl();async function ds(s){return s}function ut(){if(typeof location>"u")return"ws://localhost/ws";const s=`${location.protocol==="https:"?"wss":"ws"}://${location.host}/ws`;let t="";try{t=localStorage.getItem(Q)||""}catch{}return t?`${s}?token=${encodeURIComponent(t)}`:s}class Fe{constructor(t){O(this,"urlOverride");O(this,"handlers",new Set);O(this,"statusHandlers",new Set);O(this,"ws",null);O(this,"reconnectDelay",1e3);O(this,"maxReconnectDelay",15e3);O(this,"reconnectTimer",null);O(this,"_status","connecting");O(this,"pingTimer",null);O(this,"closed",!1);this.urlOverride=t,this.connect()}on(t){return this.handlers.add(t),()=>{this.handlers.delete(t)}}onStatus(t){return this.statusHandlers.add(t),t(this._status),()=>{this.statusHandlers.delete(t)}}get status(){return this._status}send(t){return this.ws&&this.ws.readyState===WebSocket.OPEN?(this.ws.send(JSON.stringify(t)),!0):!1}close(){var t;this.closed=!0,this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.reconnectTimer=null,this.pingTimer&&clearInterval(this.pingTimer),this.pingTimer=null;try{(t=this.ws)==null||t.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 t=this.urlOverride??ut();let n;try{n=new WebSocket(t),this.ws=n}catch(r){console.warn("[ws] construct failed:",r),this.scheduleReconnect();return}n.addEventListener("open",()=>{this.ws!==n||this.closed||(this.reconnectDelay=1e3,this.setStatus("connected"),this.pingTimer&&clearInterval(this.pingTimer),this.pingTimer=setInterval(()=>{this._status==="connected"&&this.send({type:"ping"})},3e4))}),n.addEventListener("close",()=>{this.ws===n&&(this.ws=null,this.setStatus("disconnected"),this.pingTimer&&(clearInterval(this.pingTimer),this.pingTimer=null),this.closed||this.scheduleReconnect())}),n.addEventListener("error",()=>{this.ws===n&&console.warn("[ws] error")}),n.addEventListener("message",r=>{let l;try{l=JSON.parse(r.data)}catch{console.warn("[ws] bad message");return}for(const u of this.handlers)try{u(l)}catch(b){console.error("[ws] handler error:",b)}})}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(t){this._status=t;for(const n of this.statusHandlers)try{n(t)}catch(r){console.error("[ws] status handler error:",r)}}}const ms=Object.freeze(Object.defineProperty({__proto__:null,Ws:Fe},Symbol.toStringTag,{value:"Module"}));function we(s){const t=typeof s=="string"?s:s.mode,n=t==="system"?typeof window<"u"&&window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark":t==="light"?"light":"dark";return typeof document<"u"&&(n==="light"?document.documentElement.setAttribute("data-theme","light"):document.documentElement.removeAttribute("data-theme")),n}function Se(s){if(typeof document>"u")return;const t=document.documentElement;t.style.setProperty("--accent",s.accent),t.style.setProperty("--success",s.success),t.style.setProperty("--warning",s.warning),t.style.setProperty("--error",s.error),t.style.setProperty("--info",s.info),t.style.setProperty("--accent-bg",Ce(s.accent,.12)),t.style.setProperty("--accent-border",Ce(s.accent,.4)),s.fontFamily&&t.style.setProperty("--font-sans",`'${s.fontFamily}', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif`),s.fontSize&&t.style.setProperty("--base-font-size",`${s.fontSize}px`),t.dataset.compactMode=s.compactMode?"true":"false",t.dataset.animations=s.animations?"true":"false"}function Ce(s,t){const n=/^#?([0-9a-f]{6})$/i.exec(s||"");if(!n)return`rgba(139, 92, 246, ${t})`;const r=parseInt(n[1],16),l=r>>16&255,u=r>>8&255,b=r&255;return`rgba(${l}, ${u}, ${b}, ${t})`}function ie({size:s="md",className:t,label:n}){return e.jsx("span",{className:Be("spinner",`spinner-${s}`,t),role:"status","aria-label":n||"Loading"})}const ht="modulepreload",bt=function(s){return"/"+s},Te={},qe=function(t,n,r){let l=Promise.resolve();if(n&&n.length>0){document.getElementsByTagName("link");const b=document.querySelector("meta[property=csp-nonce]"),c=(b==null?void 0:b.nonce)||(b==null?void 0:b.getAttribute("nonce"));l=Promise.allSettled(n.map(m=>{if(m=bt(m),m in Te)return;Te[m]=!0;const y=m.endsWith(".css"),a=y?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${m}"]${a}`))return;const x=document.createElement("link");if(x.rel=y?"stylesheet":ht,y||(x.as="script"),x.crossOrigin="",x.href=m,c&&x.setAttribute("nonce",c),document.head.appendChild(x),y)return new Promise((k,h)=>{x.addEventListener("load",k),x.addEventListener("error",()=>h(new Error(`Unable to preload CSS for ${m}`)))})}))}function u(b){const c=new Event("vite:preloadError",{cancelable:!0});if(c.payload=b,window.dispatchEvent(c),!c.defaultPrevented)throw b}return l.then(b=>{for(const c of b||[])c.status==="rejected"&&u(c.reason);return t().catch(u)})};function pt({tabs:s,activeTab:t,onChange:n}){return e.jsx("nav",{className:"mobile-bottom-nav",role:"navigation","aria-label":"Mobile navigation",children:s.map(r=>{const l=r.icon;return e.jsxs("button",{type:"button",className:Be("mobile-nav-btn",t===r.id&&"mobile-nav-btn-active"),onClick:()=>n(r.id),"aria-label":r.label,"aria-current":t===r.id?"page":void 0,children:[e.jsx(l,{size:22}),e.jsx("span",{className:"mobile-nav-label",children:r.label})]},r.id)})})}function F({open:s,onClose:t,title:n,children:r,actions:l,maxHeight:u="85vh"}){const b=i.useRef(null),c=i.useRef(null),m=i.useId(),y=i.useRef(null),a=i.useRef(null),x=i.useRef(0),k=i.useRef(0),h=()=>{var p;return((p=b.current)==null?void 0:p.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'))??[]};if(i.useEffect(()=>{if(!s)return;y.current=document.activeElement instanceof HTMLElement?document.activeElement:null;const p=j=>{var P;if(j.key==="Escape"&&t(),j.key!=="Tab")return;const A=Array.from(h());if(A.length===0){j.preventDefault(),(P=b.current)==null||P.focus();return}const S=A[0],R=A[A.length-1],z=document.activeElement;if(j.shiftKey){(!z||z===S||z===b.current)&&(j.preventDefault(),R==null||R.focus());return}z===R&&(j.preventDefault(),S==null||S.focus())};return window.addEventListener("keydown",p),requestAnimationFrame(()=>{var j,A;((j=c.current)==null?void 0:j.focus())??((A=b.current)==null||A.focus())}),()=>{var j;window.removeEventListener("keydown",p),(j=y.current)==null||j.focus()}},[s,t]),i.useEffect(()=>(s?(k.current=window.scrollY,document.documentElement.style.overflow="hidden",document.body.style.overflow="hidden",document.body.style.position="fixed",document.body.style.top=`-${k.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,k.current)}),[s]),!s)return null;const d=p=>{var j;p.isPrimary&&(a.current=p.clientY,x.current=0,(j=b.current)==null||j.setPointerCapture(p.pointerId))},o=p=>{if(a.current==null||!b.current)return;const j=Math.max(0,p.clientY-a.current);x.current=j,b.current.style.transform=`translateY(${j}px)`},N=p=>{if(!b.current)return;p&&b.current.hasPointerCapture(p.pointerId)&&b.current.releasePointerCapture(p.pointerId);const j=x.current;b.current.style.transform="",a.current=null,x.current=0,j>72&&t()};return e.jsx("div",{className:"mobile-sheet-overlay",onClick:t,children:e.jsxs("div",{ref:b,className:"mobile-sheet",style:{maxHeight:u},onClick:p=>p.stopPropagation(),role:"dialog","aria-modal":!0,"aria-label":n?void 0:"Sheet","aria-labelledby":n?m:void 0,tabIndex:-1,children:[e.jsx("div",{className:"mobile-sheet-handle",onPointerDown:d,onPointerMove:o,onPointerUp:N,onPointerCancel:N,"aria-hidden":"true"}),e.jsxs("div",{className:"mobile-sheet-header",children:[n?e.jsx("h3",{id:m,className:"mobile-sheet-title",children:n}):e.jsx("div",{}),e.jsx("button",{ref:c,type:"button",className:"mobile-icon-btn",onClick:t,"aria-label":"Close",children:e.jsx(ee,{size:18})})]}),e.jsx("div",{className:"mobile-sheet-content",children:r}),l&&e.jsx("div",{className:"mobile-sheet-actions",children:l})]})})}function ft(s){switch(s){case"success":return"✓";case"error":return"✗";case"warning":return"⚠";default:return"ℹ"}}function xt(s){const t=new Date(s),r=Date.now()-t.getTime();return r<6e4?"just now":r<36e5?`${Math.floor(r/6e4)}m ago`:r<864e5?`${Math.floor(r/36e5)}h ago`:t.toLocaleDateString()}function jt({onSelect:s}){const[t,n]=i.useState(!1),[r,l]=i.useState([]),[u,b]=i.useState(0),c=async()=>{var a;try{const x=await T.get("/notifications");l(x.notifications||[]),b(((a=x.stats)==null?void 0:a.unread)||0)}catch{}};i.useEffect(()=>{c()},[]),i.useEffect(()=>{t&&c()},[t]);const m=async()=>{try{await T.post("/notifications/read-all"),l(a=>a.map(x=>({...x,read:!0}))),b(0)}catch{}},y=async a=>{try{await T.post(`/notifications/${encodeURIComponent(a)}/read`),l(x=>x.map(k=>k.id===a?{...k,read:!0}:k)),b(x=>Math.max(0,x-1))}catch{}};return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",className:"mobile-icon-btn mobile-notif-btn",onClick:()=>n(!0),"aria-label":`Notifications${u>0?` (${u} unread)`:""}`,children:[e.jsx(xe,{size:20}),u>0&&e.jsx("span",{className:"mobile-notif-badge",children:u>9?"9+":u})]}),e.jsx(F,{open:t,onClose:()=>n(!1),title:"Notifications",actions:u>0?e.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",style:{width:"100%"},onClick:m,children:[e.jsx(Ze,{size:14})," Mark all read"]}):void 0,children:e.jsxs("div",{className:"mobile-notif-list",children:[r.length===0&&e.jsxs("div",{className:"mobile-empty",children:[e.jsx(xe,{size:32}),e.jsx("p",{children:"No notifications"})]}),r.map(a=>e.jsxs("button",{type:"button",className:`mobile-notif-item ${a.read?"read":"unread"}`,onClick:()=>{a.read||y(a.id),s(a),n(!1)},children:[e.jsx("span",{className:`mobile-notif-icon severity-${a.severity}`,children:ft(a.severity)}),e.jsxs("div",{className:"mobile-notif-body",children:[e.jsx("span",{className:"mobile-notif-title",children:a.title||a.message}),a.message&&a.title&&e.jsx("span",{className:"mobile-notif-text",children:a.message}),e.jsx("span",{className:"mobile-notif-time",children:xt(a.ts)})]}),!a.read&&e.jsx("span",{className:"mobile-notif-dot"})]},a.id))]})})]})}const gt={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 vt({activeTab:s,snapshot:t,onSearch:n,onNavigate:r}){const[l,u]=i.useState(!1),b=async c=>{try{await T.post(`/projects/${encodeURIComponent(c)}/activate`),u(!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:"ᛒ"}),(t==null?void 0:t.activeProject)&&e.jsxs("button",{type:"button",className:"mobile-project-btn",onClick:()=>u(!0),"aria-label":"Select project",children:[e.jsx("span",{className:"mobile-project-name",children:t.activeProject.name}),e.jsx(et,{size:14})]}),e.jsx("span",{className:"mobile-title",children:gt[s]||"Bizar"})]}),e.jsxs("div",{className:"mobile-topbar-right",children:[e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:n,"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(jt,{onSelect:c=>{r("notification",c.link||"",c.meta??null)}}),(t==null?void 0:t.activeProject)&&e.jsx(F,{open:l,onClose:()=>u(!1),title:"Projects",children:e.jsx("div",{className:"mobile-project-list",children:(t.projects||[]).map(c=>{var m,y;return e.jsxs("button",{type:"button",className:`mobile-project-item ${c.id===((m=t.activeProject)==null?void 0:m.id)?"active":""}`,onClick:()=>b(c.id),children:[e.jsx("div",{className:"mobile-project-status","data-status":c.status}),e.jsxs("div",{className:"mobile-project-info",children:[e.jsx("span",{className:"mobile-project-item-name",children:c.name}),e.jsx("span",{className:"mobile-project-item-path",children:c.path})]}),c.id===((y=t.activeProject)==null?void 0:y.id)&&e.jsx("span",{className:"mobile-active-badge",children:"active"})]},c.id)})})})]})]})}const yt=["all","tasks","agents","bg","artifacts","mods"],le={all:"All",tasks:"Tasks",agents:"Agents",bg:"Background",artifacts:"Plans",mods:"Mods"};function Nt({snapshot:s,onRefresh:t}){var D;const[n,r]=i.useState(((D=s.overview)==null?void 0:D.recentActivity)||[]),[l,u]=i.useState(!0),[b,c]=i.useState("all"),[m,y]=i.useState(!1),[a,x]=i.useState(null),[k,h]=i.useState(""),[d,o]=i.useState(!1);i.useEffect(()=>{var f;(f=s.overview)!=null&&f.recentActivity?(r(s.overview.recentActivity),u(!1)):N()},[s.overview]);const N=async()=>{var f;try{const v=await T.get("/snapshot");r(((f=v.overview)==null?void 0:f.recentActivity)||[])}catch{}finally{u(!1)}},p=b==="all"?n:n.filter(f=>{var v,g,C,E,I,U;return b==="tasks"?(v=f.kind)==null?void 0:v.startsWith("task"):b==="agents"?(g=f.kind)==null?void 0:g.startsWith("agent"):b==="bg"?((C=f.kind)==null?void 0:C.includes("bg"))||((E=f.kind)==null?void 0:E.includes("schedule")):b==="artifacts"?(I=f.kind)==null?void 0:I.includes("artifacts"):b==="mods"?(U=f.kind)==null?void 0:U.includes("mod"):!0}),j=s.agents||[],A=s.tasks||[],S=A.filter(f=>f.status==="doing"||f.status==="queued"),R=A.filter(f=>f.status==="done"),z=async()=>{if(!(!k.trim()||d)){o(!0);try{await T.post("/chat",{message:k.trim(),agent:"odin"}),h(""),await t().catch(()=>{}),await N()}catch{}finally{o(!1)}}},P=async()=>{await t().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:k,onChange:f=>h(f.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(f=>e.jsx("button",{type:"button",className:"mobile-submit-chip",onClick:()=>h(v=>v?`${v} ${f}`:f),children:f},f))}),e.jsxs("button",{type:"button",className:"mobile-btn",disabled:!k.trim()||d,onClick:z,children:[e.jsx(tt,{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:j.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:S.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:R.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:s.artifacts.length||0}),e.jsx("div",{className:"mobile-stat-label",children:"Plans"})]})]}),l&&n.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:()=>y(f=>!f),"aria-label":m?"Resume":"Pause",children:m?e.jsx(X,{size:14}):e.jsx(st,{size:14})}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:P,"aria-label":"Refresh",children:e.jsx(q,{size:14})})]})]}),e.jsx("div",{className:"mobile-search-scopes",children:yt.map(f=>e.jsx("button",{type:"button",className:`mobile-scope-chip ${b===f?"active":""}`,onClick:()=>c(f),children:le[f]},f))}),j.length>0&&e.jsxs("section",{className:"mobile-section",children:[e.jsxs("h3",{className:"mobile-section-title",children:[e.jsx(te,{size:14})," Agents"]}),e.jsx("div",{className:"mobile-card-list",children:j.slice(0,6).map(f=>e.jsxs("div",{className:"mobile-agent-card",children:[e.jsx("div",{className:"mobile-agent-dot","data-status":f.status||"idle"}),e.jsxs("div",{className:"mobile-agent-info",children:[e.jsx("span",{className:"mobile-agent-name",children:f.name}),e.jsx("span",{className:"mobile-agent-meta",children:f.status||"idle"})]})]},f.name))})]}),!m&&p.length>0&&e.jsx("section",{className:"mobile-section",children:e.jsx("div",{className:"mobile-card-list",children:p.slice(0,30).map((f,v)=>e.jsxs("button",{type:"button",className:"mobile-event-item",onClick:()=>x(f),children:[e.jsx("span",{className:"mobile-event-kind","data-kind":f.kind,children:le[f.kind]||f.kind}),e.jsx("span",{className:"mobile-event-msg",children:kt(f)}),e.jsx("span",{className:"mobile-event-time",children:V(f.ts)})]},`${f.ts}-${f.kind}-${v}`))})}),!m&&p.length===0&&n.length>0&&e.jsxs("div",{className:"mobile-empty",children:[e.jsx(ce,{size:40}),e.jsx("p",{children:"No matching activity."}),e.jsx("p",{className:"muted",children:"Try a different filter."})]}),a&&e.jsx(F,{open:!0,onClose:()=>x(null),title:le[a.kind]||a.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:a.kind})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Time"}),e.jsx("span",{children:new Date(a.ts).toLocaleString()})]}),Object.entries(a).filter(([f])=>!["ts","kind"].includes(f)).map(([f,v])=>e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:f}),e.jsx("span",{style:{fontSize:12,maxWidth:200,wordBreak:"break-all"},children:typeof v=="object"?JSON.stringify(v):String(v)})]},f))]})}),j.length===0&&S.length===0&&e.jsxs("div",{className:"mobile-empty",children:[e.jsx(ce,{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 kt(s){const t=s.kind||"";return t.includes("task")?`Task: ${s.title||s.id||"updated"}`:t.includes("agent")?`Agent: ${s.name||"status changed"}`:t.includes("artifacts")?`Plan: ${s.slug||"changed"}`:t.includes("mod")?`Mod: ${s.name||"changed"}`:t.includes("schedule")?`Schedule: ${s.name||"triggered"}`:JSON.stringify(s).slice(0,80)}function _({open:s,onClose:t,title:n,children:r,actions:l}){const u=i.useRef(null),b=i.useRef(null),c=i.useRef(null),m=i.useId(),y=i.useRef(0);return i.useEffect(()=>{if(!s)return;c.current=document.activeElement instanceof HTMLElement?document.activeElement:null;const a='button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])',x=k=>{var p,j;if(k.key==="Escape"&&t(),k.key!=="Tab")return;const h=Array.from(((p=u.current)==null?void 0:p.querySelectorAll(a))??[]);if(h.length===0){k.preventDefault(),(j=u.current)==null||j.focus();return}const d=h[0],o=h[h.length-1],N=document.activeElement;if(k.shiftKey){(!N||N===d||N===u.current)&&(k.preventDefault(),o==null||o.focus());return}N===o&&(k.preventDefault(),d==null||d.focus())};return window.addEventListener("keydown",x),y.current=window.scrollY,document.documentElement.style.overflow="hidden",document.body.style.overflow="hidden",document.body.style.position="fixed",document.body.style.top=`-${y.current}px`,document.body.style.left="0",document.body.style.right="0",document.body.style.width="100%",requestAnimationFrame(()=>{var k,h;((k=b.current)==null?void 0:k.focus())??((h=u.current)==null||h.focus())}),()=>{var k;window.removeEventListener("keydown",x),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,y.current),(k=c.current)==null||k.focus()}},[s,t]),s?e.jsx("div",{className:"mobile-modal-overlay",onClick:a=>{a.target===a.currentTarget&&t()},children:e.jsxs("div",{ref:u,className:"mobile-modal",onClick:a=>a.stopPropagation(),role:"dialog","aria-modal":!0,"aria-label":n?void 0:"Modal","aria-labelledby":n?m:void 0,tabIndex:-1,children:[e.jsxs("div",{className:"mobile-modal-header",children:[n?e.jsx("h2",{id:m,className:"mobile-modal-title",children:n}):e.jsx("div",{}),e.jsx("button",{ref:b,type:"button",className:"mobile-icon-btn",onClick:t,"aria-label":"Close",children:e.jsx(ee,{size:20})})]}),e.jsx("div",{className:"mobile-modal-content",children:r}),l&&e.jsx("div",{className:"mobile-modal-actions",children:l})]})}):null}const _e=["reasoning","code","design","planning","gitops","analysis"],Ae={reasoning:"var(--accent)",code:"var(--info)",design:"var(--success)",planning:"var(--warning)",gitops:"var(--error)",analysis:"var(--text-dim)"};function Ee({snapshot:s,onBack:t,onOpenAgent:n,selectedAgent:r,onRefresh:l}){const[u,b]=i.useState(s.agents||[]),[c,m]=i.useState(!s.agents),[y,a]=i.useState(""),[x,k]=i.useState(""),[h,d]=i.useState(null),[o,N]=i.useState(!1),[p,j]=i.useState(""),[A,S]=i.useState(!1);i.useEffect(()=>{if(r){const g=u.find(C=>C.name===r);g&&d(g)}},[r,u]);const R=async()=>{try{const g=await T.get("/agents");b(g.agents||[])}catch{}finally{m(!1)}},z=u.filter(g=>{if(y&&g.category!==y)return!1;if(x){const C=x.toLowerCase();if(!g.name.toLowerCase().includes(C)&&!(g.description||"").toLowerCase().includes(C))return!1}return!0}),P=async(g,C)=>{try{await T.post(`/agents/${encodeURIComponent(g)}/invoke`,{prompt:C}),S(!1),j("")}catch{}},D=async g=>{try{await T.post(`/agents/${encodeURIComponent(g)}/restart`),await R()}catch{}},f=async g=>{if(confirm(`Delete agent "${g}"?`))try{await T.del(`/agents/${encodeURIComponent(g)}`),b(C=>C.filter(E=>E.name!==g)),d(null),l==null||l()}catch{}},v=async g=>{try{const C=await T.post("/agents",g);b(E=>[...E,C]),N(!1),l==null||l()}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:x,onChange:g=>k(g.target.value),style:{flex:1}}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>R(),"aria-label":"Refresh",children:e.jsx(q,{size:16})}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>N(!0),"aria-label":"New agent",children:e.jsx(B,{size:16})})]}),e.jsxs("div",{className:"mobile-search-scopes",children:[e.jsx("button",{type:"button",className:`mobile-scope-chip ${y?"":"active"}`,onClick:()=>a(""),children:"All"}),_e.map(g=>e.jsx("button",{type:"button",className:`mobile-scope-chip ${y===g?"active":""}`,onClick:()=>a(g),children:g},g))]}),c?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading…"})}):z.length===0?e.jsxs("div",{className:"mobile-empty",children:[e.jsx(te,{size:40}),e.jsx("p",{children:"No agents found."})]}):e.jsx("div",{className:"mobile-card-list",children:z.map(g=>e.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>{d(g),n(g.name)},children:[e.jsx("div",{className:"mobile-agent-dot","data-status":g.status||"idle"}),e.jsxs("div",{className:"mobile-list-content",children:[e.jsx("span",{className:"mobile-list-title",children:g.name}),e.jsx("span",{className:"mobile-list-meta",children:g.model||g.mode||"—"})]}),g.category&&e.jsx("span",{className:"mobile-list-badge",style:{color:Ae[g.category]||"var(--text-dim)"},children:g.category}),e.jsx("span",{className:"mobile-list-badge","data-status":g.status||"idle",children:g.status||"idle"})]},g.name))}),h&&e.jsx(F,{open:!0,onClose:()=>d(null),title:h.name,actions:e.jsxs("div",{className:"mobile-task-detail-actions",children:[e.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>{j(""),S(!0)},children:[e.jsx(X,{size:14})," Invoke"]}),(h.isStuck||h.status==="error"||h.status==="working")&&e.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>D(h.name),children:[e.jsx(at,{size:14})," Restart"]}),e.jsx("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>f(h.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":h.status||"idle"}),e.jsx("span",{className:"mobile-agent-detail-status-text",children:h.status||"idle"}),h.category&&e.jsx("span",{className:"mobile-list-badge",style:{color:Ae[h.category]},children:h.category})]}),e.jsx("p",{className:"mobile-agent-detail-desc",children:h.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:h.model||"—"})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Mode"}),e.jsx("span",{children:h.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:h.path})]}),h.lastError&&e.jsxs("div",{className:"mobile-task-detail-row",style:{color:"var(--error)"},children:[e.jsx("span",{children:"Last error"}),e.jsx("span",{children:h.lastError.message})]}),h.tasksTotal!=null&&h.tasksTotal>0&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Success rate"}),e.jsxs("span",{children:[Math.round((h.successRate||0)*100),"%"]})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Last modified"}),e.jsx("span",{children:V(h.mtime)})]})]})]})}),e.jsxs(_,{open:A,onClose:()=>S(!1),title:`Invoke ${h==null?void 0:h.name}`,actions:e.jsxs("button",{type:"button",className:"mobile-btn",style:{width:"100%"},disabled:!p.trim(),onClick:()=>{h&&P(h.name,p.trim())},children:[e.jsx(X,{size:14})," Invoke"]}),children:[e.jsxs("p",{className:"muted",style:{marginBottom:12},children:["Model: ",e.jsx("span",{className:"mono",children:(h==null?void 0:h.model)||"—"})]}),e.jsx("textarea",{className:"mobile-input",rows:5,placeholder:"What should this agent do?",value:p,onChange:g=>j(g.target.value),autoFocus:!0})]}),e.jsx(wt,{open:o,onClose:()=>N(!1),onCreate:v})]})}function wt({open:s,onClose:t,onCreate:n}){const[r,l]=i.useState(""),[u,b]=i.useState(""),[c,m]=i.useState(""),[y,a]=i.useState("subagent"),[x,k]=i.useState("#8b5cf6"),[h,d]=i.useState(""),[o,N]=i.useState(""),[p,j]=i.useState(""),A=S=>{S.preventDefault(),r.trim()&&(n({name:r.trim(),description:u.trim(),model:c,mode:y,color:x,tools:[],tags:o.split(",").map(R=>R.trim()).filter(Boolean),category:h,prompt:p}),l(""),b(""),m(""),a("subagent"),k("#8b5cf6"),d(""),N(""),j(""))};return e.jsx(_,{open:s,onClose:t,title:"New Agent",actions:e.jsxs("button",{type:"submit",form:"new-agent-form",className:"mobile-btn",style:{width:"100%"},children:[e.jsx(B,{size:14})," Create"]}),children:e.jsxs("form",{id:"new-agent-form",onSubmit:A,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:r,onChange:S=>l(S.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:u,onChange:S=>b(S.target.value)}),e.jsx("label",{className:"mobile-field-label",children:"Model"}),e.jsx("input",{className:"mobile-input",type:"text",placeholder:"(provider default)",value:c,onChange:S=>m(S.target.value)}),e.jsx("label",{className:"mobile-field-label",children:"Category"}),e.jsxs("select",{className:"mobile-input",value:h,onChange:S=>d(S.target.value),children:[e.jsx("option",{value:"",children:"None"}),_e.map(S=>e.jsx("option",{value:S,children:S},S))]}),e.jsx("label",{className:"mobile-field-label",children:"Tags (comma-separated)"}),e.jsx("input",{className:"mobile-input",type:"text",placeholder:"tag1, tag2",value:o,onChange:S=>N(S.target.value)})]})})}function St({onBack:s}){const[t,n]=i.useState([]),[r,l]=i.useState(!0),[u,b]=i.useState({}),[c,m]=i.useState(!1),y=async()=>{try{const o=await T.get("/config"),N=Object.entries(o).map(([p,j])=>({key:p,value:j,type:a(j)}));n(N),b(Object.fromEntries(Object.entries(o).map(([p,j])=>[p,j])))}catch{}finally{l(!1)}};i.useEffect(()=>{y()},[]);const a=o=>typeof o=="boolean"?"boolean":typeof o=="number"?"number":typeof o=="string"?"string":Array.isArray(o)?"array":o&&typeof o=="object"?"object":"unknown",x=(o,N)=>{b(p=>({...p,[o]:N}))},k=async()=>{m(!0);try{await T.patch("/config",u),await y()}catch{}finally{m(!1)}},h=(o,N)=>{b(p=>({...p,[o]:N}))},d=o=>{const N=u[o.key];switch(o.type){case"boolean":return e.jsxs("label",{className:"mobile-toggle",children:[e.jsx("input",{type:"checkbox",checked:!!N,onChange:p=>x(o.key,p.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:p=>x(o.key,Number(p.target.value))});case"string":return e.jsx("input",{className:"mobile-input mobile-input-sm",type:"text",value:String(N??""),onChange:p=>x(o.key,p.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:p=>{try{x(o.key,JSON.parse(p.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:[t.length," config entries"]}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>y(),"aria-label":"Refresh",children:e.jsx(q,{size:16})}),e.jsxs("button",{type:"button",className:"mobile-btn",disabled:c,onClick:()=>k(),children:[e.jsx(nt,{size:14})," ",c?"Saving…":"Save all"]})]}),r?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading…"})}):t.length===0?e.jsxs("div",{className:"mobile-empty",children:[e.jsx(K,{size:40}),e.jsx("p",{children:"No config entries."})]}):e.jsx("div",{className:"mobile-config-list",children:t.map(o=>e.jsxs("div",{className:"mobile-config-row",children:[e.jsxs("div",{className:"mobile-config-key",children:[e.jsx("span",{className:"mono",children:o.key}),e.jsx("span",{className:"mobile-config-type",children:o.type})]}),e.jsx("div",{className:"mobile-config-value",children:d(o)}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>h(o.key,o.defaultValue),"aria-label":"Reset to default",title:"Reset",children:e.jsx(it,{size:14})})]},o.key))})]})}function Ct({onBack:s}){const[t,n]=i.useState([]),[r,l]=i.useState(!0),[u,b]=i.useState(null),[c,m]=i.useState(""),y=async()=>{try{const h=await T.get("/history");if(Array.isArray(h.history)){n(h.history);return}if(Array.isArray(h.projects)){const d=new Map;for(const o of h.events||[]){const N=o.projectId;if(!N)continue;const p=d.get(N);(!p||new Date(o.ts).getTime()>new Date(p.ts).getTime())&&d.set(N,o)}n(h.projects.map(o=>{const N=d.get(o.id);return{id:o.id,ts:o.lastAccessed||(N==null?void 0:N.ts)||new Date(0).toISOString(),agent:o.name,taskCount:o.tasks.total,summary:`${o.path} · ${o.tasks.done}/${o.tasks.total} done · ${o.plans} plan${o.plans===1?"":"s"}`,output:N?`${N.kind}${N.text?` — ${N.text}`:""}`:"No recent events."}}));return}n([])}catch{}finally{l(!1)}};i.useEffect(()=>{y()},[]);const a=h=>{if(!h)return"—";const d=Math.floor(h/1e3);if(d<60)return`${d}s`;const o=Math.floor(d/60),N=d%60;return`${o}m ${N}s`},x=h=>new Date(h).toLocaleString(),k=c.trim()?t.filter(h=>{const d=c.toLowerCase();return(h.agent||"session").toLowerCase().includes(d)||(h.summary||"").toLowerCase().includes(d)||(h.output||"").toLowerCase().includes(d)}):t;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:c,onChange:h=>m(h.target.value),style:{flex:1}}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>y(),"aria-label":"Refresh",children:e.jsx(q,{size:16})})]}),r?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading…"})}):k.length===0?e.jsxs("div",{className:"mobile-empty",children:[e.jsx(re,{size:40}),e.jsx("p",{children:t.length===0?"No history yet.":"No matching sessions."})]}):e.jsx("div",{className:"mobile-card-list",children:k.map(h=>e.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>b(h),children:[e.jsx("div",{className:"mobile-list-icon",children:e.jsx(re,{size:16})}),e.jsxs("div",{className:"mobile-list-content",children:[e.jsx("span",{className:"mobile-list-title",children:h.agent||"Session"}),e.jsxs("span",{className:"mobile-list-meta",children:[x(h.ts),h.duration?` · ${a(h.duration)}`:"",h.taskCount?` · ${h.taskCount} tasks`:""]})]})]},h.id))}),u&&e.jsxs(F,{open:!0,onClose:()=>b(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:u.agent||"—"})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Started"}),e.jsx("span",{children:x(u.ts)})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Duration"}),e.jsx("span",{children:a(u.duration)})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Tasks"}),e.jsx("span",{children:u.taskCount||0})]})]}),u.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:u.summary})]}),u.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:[u.output.slice(0,1e3),u.output.length>1e3?"…":""]})]})]})]})}function Tt({snapshot:s,onBack:t}){const[n,r]=i.useState(s.mods||[]),[l,u]=i.useState(!s.mods),[b,c]=i.useState(""),[m,y]=i.useState("all"),[a,x]=i.useState(null),k=async()=>{try{const o=await T.get("/mods");r(o.mods||[])}catch{}finally{u(!1)}};i.useEffect(()=>{s.mods?(r(s.mods),u(!1)):k()},[s.mods]);const h=async(o,N)=>{try{await T.patch(`/mods/${encodeURIComponent(o)}`,{enabled:N}),r(p=>p.map(j=>j.id===o?{...j,enabled:N}:j)),(a==null?void 0:a.id)===o&&x(p=>p&&{...p,enabled:N})}catch{}},d=n.filter(o=>{if(m==="enabled"&&!o.enabled||m==="disabled"&&o.enabled)return!1;if(b){const N=b.toLowerCase();return o.name.toLowerCase().includes(N)||o.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:b,onChange:o=>c(o.target.value),style:{flex:1}}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>k(),"aria-label":"Refresh",children:e.jsx(q,{size:16})})]}),e.jsx("div",{className:"mobile-search-scopes",children:["all","enabled","disabled"].map(o=>e.jsx("button",{type:"button",className:`mobile-scope-chip ${m===o?"active":""}`,onClick:()=>y(o),children:o.charAt(0).toUpperCase()+o.slice(1)},o))}),l?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading…"})}):d.length===0?e.jsxs("div",{className:"mobile-empty",children:[e.jsx(K,{size:40}),e.jsx("p",{children:"No mods found."})]}):e.jsx("div",{className:"mobile-card-list",children:d.map(o=>e.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>x(o),children:[e.jsx("div",{className:"mobile-list-icon",children:e.jsx(K,{size:16})}),e.jsxs("div",{className:"mobile-list-content",children:[e.jsx("span",{className:"mobile-list-title",children:o.name}),e.jsxs("span",{className:"mobile-list-meta",children:["v",o.version," · ",o.author]})]}),e.jsx("span",{className:`mobile-list-badge ${o.enabled?"badge-on":"badge-off"}`,children:o.enabled?"on":"off"})]},o.id))}),a&&e.jsx(F,{open:!0,onClose:()=>x(null),title:a.name,actions:e.jsx("div",{className:"mobile-task-detail-actions",children:e.jsxs("button",{type:"button",className:"mobile-btn",style:{flex:1},onClick:()=>{a&&h(a.id,!a.enabled)},children:[e.jsx(Pe,{size:14})," ",a.enabled?"Disable":"Enable"]})}),children:e.jsxs("div",{className:"mobile-agent-detail",children:[e.jsx("p",{className:"mobile-agent-detail-desc",children:a.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:a.version})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Author"}),e.jsx("span",{children:a.author})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Bizar"}),e.jsx("span",{className:"mono",children:a.bizar})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Type"}),e.jsx("span",{children:a.type})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Permissions"}),e.jsx("span",{children:a.permissions.length})]}),a.installedAt&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Installed"}),e.jsx("span",{children:new Date(a.installedAt).toLocaleDateString()})]})]})]})})]})}function At({snapshot:s,onNavigate:t}){var b,c,m;const[n,r]=i.useState(""),l=[{id:"artifacts",icon:W,label:"Plans",count:s.artifacts.length||0,desc:"Visual artifacts with elements & comments"},{id:"agents",icon:te,label:"Agents",count:((b=s.agents)==null?void 0:b.length)||0,desc:"The Norse pantheon"},{id:"skills",icon:K,label:"Skills",count:null,desc:"Agent capabilities & tools"},{id:"mods",icon:K,label:"Mods",count:((c=s.mods)==null?void 0:c.length)||0,desc:"Installed modifications"},{id:"schedules",icon:de,label:"Schedules",count:((m=s.schedules)==null?void 0:m.length)||0,desc:"Cron jobs & automated tasks"},{id:"history",icon:re,label:"History",count:null,desc:"Past sessions & outputs"},{id:"config",icon:Ue,label:"Config",count:null,desc:"Key-value configuration editor"}],u=n.trim()?l.filter(y=>y.label.toLowerCase().includes(n.toLowerCase())||y.desc.toLowerCase().includes(n.toLowerCase())):l;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:n,onChange:y=>r(y.target.value),style:{flex:1}})}),e.jsx("div",{className:"mobile-card-list",children:u.map(y=>{const a=y.icon;return e.jsxs("button",{type:"button",className:"mobile-more-nav-item",onClick:()=>t(y.id),children:[e.jsx("div",{className:"mobile-more-nav-icon",children:e.jsx(a,{size:20})}),e.jsxs("div",{className:"mobile-more-nav-content",children:[e.jsxs("span",{className:"mobile-more-nav-label",children:[y.label,y.count!=null&&e.jsx("span",{className:"mobile-more-nav-count",children:y.count})]}),e.jsx("span",{className:"mobile-more-nav-desc",children:y.desc})]}),e.jsx(je,{size:16,className:"mobile-more-nav-arrow"})]},y.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 me=[{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 oe(s){var t;return((t=me.find(n=>n.id===s))==null?void 0:t.color)||"var(--text-dim)"}function Et({type:s,size:t=12}){switch(s){case"task":return e.jsx(Z,{size:t,style:{color:"var(--info)"}});case"note":return e.jsx(ge,{size:t,style:{color:"var(--text-dim)"}});case"decision":return e.jsx(Z,{size:t,style:{color:"var(--accent)"}});case"question":return e.jsx(lt,{size:t,style:{color:"var(--warning)"}});default:return e.jsx(ge,{size:t})}}function $t({slug:s,onBack:t}){const[n,r]=i.useState(null),[l,u]=i.useState(null),[b,c]=i.useState(!0),[m,y]=i.useState(!1),[a,x]=i.useState(null),[k,h]=i.useState(!1),[d,o]=i.useState(!1),[N,p]=i.useState(!1),[j,A]=i.useState(""),S=async()=>{c(!0);try{const f=await T.get(`/plans/${encodeURIComponent(s)}`);r(f.canvas),u(f.meta)}catch{}finally{c(!1)}};i.useEffect(()=>{S()},[s]);const R=async(f,v,g)=>{try{const C=((n==null?void 0:n.elements)||[]).reduce((I,U)=>Math.max(I,U.x||0),40),E=((n==null?void 0:n.elements)||[]).reduce((I,U)=>Math.max(I,U.y||0),40);await T.post(`/plans/${encodeURIComponent(s)}/elements`,{type:f,title:v,content:g,x:20+C,y:20+E,width:240,height:120}),await S(),o(!1)}catch{}},z=async(f,v)=>{try{await T.put(`/plans/${encodeURIComponent(s)}/elements/${encodeURIComponent(f)}`,v),await S(),x(null)}catch{}},P=async f=>{if(confirm("Delete this element?"))try{await T.del(`/plans/${encodeURIComponent(s)}/elements/${encodeURIComponent(f)}`),x(null),await S()}catch{}},D=async(f,v)=>{try{const g=v?`/plans/${encodeURIComponent(s)}/elements/${encodeURIComponent(v)}/comments`:`/plans/${encodeURIComponent(s)}/comments`;await T.post(g,{text:f,elementId:v}),await S(),A(""),p(!1)}catch{}};return b||!n||!l?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:l.title||s}),e.jsx("span",{className:"mobile-canvas-status","data-status":l.status,children:l.status})]}),e.jsxs("div",{className:"mobile-canvas-actions",children:[e.jsx("button",{type:"button",className:`mobile-icon-btn ${m?"active":""}`,onClick:()=>y(f=>!f),"aria-label":m?"Done editing":"Edit",children:e.jsx(Oe,{size:16})}),e.jsxs("button",{type:"button",className:"mobile-icon-btn",onClick:()=>h(f=>!f),"aria-label":"Comments",children:[e.jsx(Y,{size:16}),n.comments.length>0&&e.jsx("span",{className:"mobile-canvas-comment-count",children:n.comments.length})]}),m&&e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>o(!0),"aria-label":"Add element",children:e.jsx(B,{size:16})})]})]}),e.jsxs("div",{className:"mobile-canvas-elements",children:[n.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:()=>o(!0),children:[e.jsx(B,{size:14})," Add Element"]})]}),n.elements.map(f=>e.jsxs("button",{type:"button",className:`mobile-canvas-element ${(a==null?void 0:a.id)===f.id?"selected":""}`,style:{borderColor:oe(f.type)},onClick:()=>{m&&x(f)},"aria-pressed":(a==null?void 0:a.id)===f.id,children:[e.jsxs("div",{className:"mobile-canvas-el-header",style:{background:`${oe(f.type)}18`},children:[e.jsx(Et,{type:f.type,size:12}),e.jsx("span",{className:"mobile-canvas-el-type",style:{color:oe(f.type)},children:f.type}),f.status&&f.status!=="open"&&e.jsx("span",{className:"mobile-canvas-el-status",children:f.status})]}),e.jsx("div",{className:"mobile-canvas-el-title",children:f.title||"Untitled"}),f.content&&e.jsxs("div",{className:"mobile-canvas-el-content",children:[f.content.slice(0,120),f.content.length>120?"…":""]}),e.jsxs("div",{className:"mobile-canvas-el-comments",children:[e.jsx(Y,{size:10}),n.comments.filter(v=>v.elementId===f.id).length]})]},f.id))]}),k&&e.jsxs("div",{className:"mobile-canvas-comments",children:[e.jsxs("div",{className:"mobile-canvas-comments-header",children:[e.jsxs("h4",{children:["Comments (",n.comments.length,")"]}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>h(!1),children:e.jsx(ee,{size:16})})]}),e.jsxs("div",{className:"mobile-canvas-comment-list",children:[n.comments.length===0&&e.jsx("p",{className:"mobile-empty-inline",children:"No comments yet."}),n.comments.map(f=>e.jsxs("div",{className:"mobile-canvas-comment",children:[e.jsxs("div",{className:"mobile-canvas-comment-head",children:[e.jsx("span",{className:"mono",children:f.author}),e.jsx("span",{className:"muted",children:V(f.created)})]}),e.jsx("div",{className:"mobile-canvas-comment-text",children:f.text})]},f.id))]}),e.jsxs("div",{className:"mobile-canvas-comment-input",children:[e.jsx("textarea",{className:"mobile-input",rows:2,placeholder:"Add a comment…",value:j,onChange:f=>A(f.target.value)}),e.jsx("button",{type:"button",className:"mobile-btn",disabled:!j.trim(),onClick:()=>{D(j.trim(),null)},children:"Post"})]})]}),a&&e.jsx(F,{open:!0,onClose:()=>x(null),title:`Edit ${a.title||a.type}`,actions:e.jsxs("div",{className:"mobile-task-detail-actions",children:[e.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>P(a.id),children:[e.jsx(se,{size:14})," Delete"]}),e.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>p(!0),children:[e.jsx(Y,{size:14})," Comment"]})]}),children:e.jsx(Lt,{element:a,onSave:f=>z(a.id,f),onClose:()=>x(null)})}),e.jsx(zt,{open:d,onClose:()=>o(!1),onAdd:R}),e.jsx(_,{open:N,onClose:()=>p(!1),title:"Add Comment",actions:e.jsxs("button",{type:"button",className:"mobile-btn",style:{width:"100%"},disabled:!j.trim(),onClick:()=>{D(j.trim(),(a==null?void 0:a.id)||null),p(!1)},children:[e.jsx(Y,{size:14})," Post"]}),children:e.jsx("textarea",{className:"mobile-input",rows:3,placeholder:"Your comment…",value:j,onChange:f=>A(f.target.value),autoFocus:!0})})]})}function Lt({element:s,onSave:t,onClose:n}){const[r,l]=i.useState(s.type),[u,b]=i.useState(s.title||""),[c,m]=i.useState(s.content||""),[y,a]=i.useState(s.status||"open");return e.jsxs("form",{className:"mobile-task-form",onSubmit:x=>{x.preventDefault(),t({type:r,title:u,content:c,status:y}),n()},children:[e.jsx("label",{className:"mobile-field-label",children:"Type"}),e.jsx("select",{className:"mobile-input",value:r,onChange:x=>l(x.target.value),children:me.map(x=>e.jsx("option",{value:x.id,children:x.label},x.id))}),e.jsx("label",{className:"mobile-field-label",children:"Title"}),e.jsx("input",{className:"mobile-input",type:"text",value:u,onChange:x=>b(x.target.value)}),e.jsx("label",{className:"mobile-field-label",children:"Status"}),e.jsx("input",{className:"mobile-input",type:"text",value:y,onChange:x=>a(x.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:c,onChange:x=>m(x.target.value)}),e.jsx("button",{type:"submit",className:"mobile-btn",style:{width:"100%",marginTop:8},children:"Save"})]})}function zt({open:s,onClose:t,onAdd:n}){const[r,l]=i.useState("task"),[u,b]=i.useState(""),[c,m]=i.useState(""),y=a=>{a.preventDefault(),u.trim()&&(n(r,u.trim(),c.trim()),b(""),m(""))};return e.jsx(_,{open:s,onClose:t,title:"Add Element",actions:e.jsxs("button",{type:"submit",form:"add-el-form",className:"mobile-btn",style:{width:"100%"},children:[e.jsx(B,{size:14})," Add"]}),children:e.jsxs("form",{id:"add-el-form",onSubmit:y,className:"mobile-task-form",children:[e.jsx("label",{className:"mobile-field-label",children:"Type"}),e.jsx("select",{className:"mobile-input",value:r,onChange:a=>l(a.target.value),children:me.map(a=>e.jsx("option",{value:a.id,children:a.label},a.id))}),e.jsx("label",{className:"mobile-field-label",children:"Title *"}),e.jsx("input",{className:"mobile-input",type:"text",placeholder:"Element title",value:u,onChange:a=>b(a.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:c,onChange:a=>m(a.target.value)})]})})}function Rt({snapshot:s,onBack:t,onOpenArtifact:n}){const[r,l]=i.useState(s.artifacts||[]),[u,b]=i.useState(!s.artifacts),[c,m]=i.useState(""),[y,a]=i.useState(!1),[x,k]=i.useState(""),[h,d]=i.useState(""),o=async()=>{try{const j=await T.get("/artifacts");l(j.artifacts||[])}catch{}finally{b(!1)}},N=async()=>{if(x.trim())try{const j=await T.post("/artifacts",{slug:x.trim(),title:h.trim()||void 0});a(!1),k(""),d(""),n(j.slug)}catch{}},p=c.trim()?r.filter(j=>(j.title||j.slug||"").toLowerCase().includes(c.toLowerCase())):r;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:c,onChange:j=>m(j.target.value),style:{flex:1}}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>o(),"aria-label":"Refresh",children:e.jsx(q,{size:16})})]}),e.jsx("div",{style:{marginBottom:12},children:e.jsxs("button",{type:"button",className:"mobile-btn",style:{width:"100%"},onClick:()=>a(!0),children:[e.jsx(B,{size:14})," New Artifact"]})}),u?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading…"})}):p.length===0?e.jsxs("div",{className:"mobile-empty",children:[e.jsx(W,{size:40}),e.jsx("p",{children:"No artifacts yet."})]}):e.jsx("div",{className:"mobile-card-list",children:p.map(j=>e.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>n(j.slug),children:[e.jsx("div",{className:"mobile-list-icon",children:e.jsx(W,{size:16})}),e.jsxs("div",{className:"mobile-list-content",children:[e.jsx("span",{className:"mobile-list-title",children:j.title||j.slug}),e.jsxs("span",{className:"mobile-list-meta",children:[j.status," · ",j.source,j.elementCount!=null?` · ${j.elementCount} elements`:"",j.commentCount!=null?` · ${j.commentCount} comments`:""]})]}),e.jsx("span",{className:"mobile-list-badge","data-status":j.status,children:j.status})]},j.slug))}),e.jsx(_,{open:y,onClose:()=>a(!1),title:"New Artifact",actions:e.jsxs("button",{type:"submit",form:"new-plan-form",className:"mobile-btn",style:{width:"100%"},children:[e.jsx(B,{size:14})," Create"]}),children:e.jsxs("form",{id:"new-plan-form",onSubmit:j=>{j.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:x,onChange:j=>k(j.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:h,onChange:j=>d(j.target.value)})]})})]})}const It=["cron","interval","once"],Dt=["command","agent","webhook"],$e=["UTC","America/New_York","America/Los_Angeles","Europe/London","Europe/Berlin","Asia/Tokyo"],We=Array.from({length:24},(s,t)=>({value:t,label:t===0?"12 AM":t<12?`${t} AM`:t===12?"12 PM":`${t-12} PM`})),Mt=Array.from({length:12},(s,t)=>t*5),He=[{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"}],Pt=[{value:"s",label:"sec"},{value:"m",label:"min"},{value:"h",label:"hr"},{value:"d",label:"day"}];function Ut({snapshot:s}){var N;const[t,n]=i.useState(s.schedules||[]),[r,l]=i.useState(!s.schedules),[u,b]=i.useState(""),[c,m]=i.useState(null),[y,a]=i.useState({open:!1}),x=async()=>{try{const p=await T.get("/schedules");n(p.schedules||[])}catch{}finally{l(!1)}};i.useEffect(()=>{s.schedules?(n(s.schedules),l(!1)):x()},[s.schedules]);const k=async(p,j)=>{try{await T.patch(`/schedules/${encodeURIComponent(p)}`,{enabled:j}),n(A=>A.map(S=>S.id===p?{...S,enabled:j}:S)),(c==null?void 0:c.id)===p&&m(A=>A&&{...A,enabled:j})}catch{}},h=async p=>{if(confirm("Delete this schedule?"))try{await T.del(`/schedules/${encodeURIComponent(p)}`),n(j=>j.filter(A=>A.id!==p)),(c==null?void 0:c.id)===p&&m(null)}catch{}},d=async p=>{try{await T.post(`/schedules/${encodeURIComponent(p)}/trigger`)}catch{}},o=u.trim()?t.filter(p=>p.name.toLowerCase().includes(u.toLowerCase())):t;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:u,onChange:p=>b(p.target.value),style:{flex:1}}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>x(),"aria-label":"Refresh",children:e.jsx(q,{size:16})}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>a({open:!0}),"aria-label":"New schedule",children:e.jsx(B,{size:16})})]}),r?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading…"})}):o.length===0?e.jsxs("div",{className:"mobile-empty",children:[e.jsx(de,{size:40}),e.jsx("p",{children:"No schedules found."})]}):e.jsx("div",{className:"mobile-card-list",children:o.map(p=>e.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>m(p),children:[e.jsx("div",{className:"mobile-list-icon",children:e.jsx(de,{size:16})}),e.jsxs("div",{className:"mobile-list-content",children:[e.jsx("span",{className:"mobile-list-title",children:p.name}),e.jsxs("span",{className:"mobile-list-meta",children:[Re(p)," ·"," ",p.nextRun?`next ${ze(p.nextRun,p.timezone)}`:"no next run"]})]}),e.jsx("span",{className:`mobile-list-badge ${p.enabled?"badge-on":"badge-off"}`,children:p.enabled?"on":"off"})]},p.id))}),c&&e.jsx(F,{open:!0,onClose:()=>m(null),title:c.name,actions:e.jsxs("div",{className:"mobile-task-detail-actions",children:[e.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>{c&&d(c.id)},children:[e.jsx(X,{size:14})," Trigger now"]}),e.jsx("button",{type:"button",className:`mobile-btn ${c.enabled?"mobile-btn-secondary":""}`,onClick:()=>{c&&k(c.id,!c.enabled)},children:c.enabled?"Disable":"Enable"}),e.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>{c&&(a({open:!0,initial:c}),m(null))},children:[e.jsx(Oe,{size:14})," Edit"]}),e.jsx("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>{c&&h(c.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:c.type})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Schedule"}),e.jsx("span",{className:"mono",children:Re(c)||c.schedule})]}),c.timezone&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Timezone"}),e.jsx("span",{className:"mono",children:c.timezone})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Action"}),e.jsxs("span",{children:[c.action.type,": ",c.action.target]})]}),c.action.type==="agent"&&c.action.prompt&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Prompt"}),e.jsx("span",{style:{fontSize:12},children:c.action.prompt})]}),((N=c.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 ≥ ",c.budgetCheck.maxConcurrent??6," concurrent"]})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Next run"}),e.jsx("span",{children:c.nextRun?ze(c.nextRun,c.timezone):"—"})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Last run"}),e.jsx("span",{children:c.lastRun?Ft(c.lastRun):"—"})]}),c.lastResult&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Last result"}),e.jsx("span",{style:{fontSize:12},children:c.lastResult})]}),c.lastError&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Last error"}),e.jsx("span",{style:{fontSize:12},children:c.lastError})]})]})})}),e.jsx(Bt,{open:y.open,initial:y.initial,onClose:()=>a({open:!1}),onSaved:()=>{a({open:!1}),x()}})]})}function Le(s){var r,l;if(!s)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 t=s.type==="cron"?Ye(s.schedule):null,n=s.type==="interval"?qt(s.schedule):null;return{name:s.name||"",type:s.type,cronMinute:(t==null?void 0:t.minute)??0,cronHour:(t==null?void 0:t.hour)??9,cronDow:(t==null?void 0:t.dow)??"*",intervalN:(n==null?void 0:n.n)??30,intervalUnit:(n==null?void 0:n.unit)??"m",onceAt:s.type==="once"?_t(s.schedule):"",timezone:s.timezone||"UTC",actionType:s.action.type,actionTarget:s.action.target||"",actionPrompt:s.action.prompt||"",skipIfBudgetLow:!!((r=s.budgetCheck)!=null&&r.skipIfBudgetLow),maxConcurrent:Number.isFinite((l=s.budgetCheck)==null?void 0:l.maxConcurrent)?s.budgetCheck.maxConcurrent:6,enabled:s.enabled!==!1}}function Ot(s){if(s.type==="cron")return`${s.cronMinute} ${s.cronHour} * * ${s.cronDow}`;if(s.type==="interval")return`${s.intervalN}${s.intervalUnit}`;if(!s.onceAt)return"";try{return new Date(s.onceAt).toISOString()}catch{return s.onceAt}}function Bt({open:s,initial:t,onClose:n,onSaved:r}){const[l,u]=i.useState(()=>Le(t)),[b,c]=i.useState(!1);i.useEffect(()=>{s&&u(Le(t))},[s,t]);const m=(a,x)=>{u(k=>({...k,[a]:x}))},y=async a=>{if(a.preventDefault(),!l.name.trim())return;const x=Ot(l);if(x){c(!0);try{const k={name:l.name.trim(),type:l.type,schedule:x,timezone:l.timezone,action:{type:l.actionType,target:l.actionTarget.trim(),...l.actionType==="agent"&&l.actionPrompt.trim()?{prompt:l.actionPrompt.trim()}:{}},budgetCheck:{maxConcurrent:l.maxConcurrent,skipIfBudgetLow:l.skipIfBudgetLow},enabled:l.enabled};t?await T.put(`/schedules/${encodeURIComponent(t.id)}`,k):await T.post("/schedules",k),r()}catch{}finally{c(!1)}}};return e.jsx(_,{open:s,onClose:n,title:t?`Edit ${t.name}`:"New schedule",actions:e.jsxs("button",{type:"submit",form:"mobile-schedule-form",className:"mobile-btn",style:{width:"100%"},disabled:b,children:[e.jsx(B,{size:14})," ",t?"Save":"Create"]}),children:e.jsxs("form",{id:"mobile-schedule-form",onSubmit:y,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:l.name,onChange:a=>m("name",a.target.value),autoFocus:!0,required:!0}),e.jsx("label",{className:"mobile-field-label",children:"Type"}),e.jsx("select",{className:"mobile-input",value:l.type,onChange:a=>m("type",a.target.value),children:It.map(a=>e.jsx("option",{value:a,children:a},a))}),l.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:l.cronDow,onChange:a=>m("cronDow",a.target.value),children:He.map(a=>e.jsx("option",{value:a.value,children:a.label},a.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(l.cronHour),onChange:a=>m("cronHour",parseInt(a.target.value,10)),children:We.map(a=>e.jsx("option",{value:String(a.value),children:a.label},a.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(l.cronMinute),onChange:a=>m("cronMinute",parseInt(a.target.value,10)),children:Mt.map(a=>e.jsx("option",{value:String(a),children:String(a).padStart(2,"0")},a))})]})]})]}),l.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:l.intervalN,onChange:a=>m("intervalN",parseInt(a.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:l.intervalUnit,onChange:a=>m("intervalUnit",a.target.value),children:Pt.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))})]})]}),l.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:l.onceAt,onChange:a=>m("onceAt",a.target.value)})]}),e.jsx("label",{className:"mobile-field-label",children:"Timezone"}),e.jsx("select",{className:"mobile-input",value:$e.includes(l.timezone)?l.timezone:"UTC",onChange:a=>m("timezone",a.target.value),children:$e.map(a=>e.jsx("option",{value:a,children:a},a))}),e.jsx("label",{className:"mobile-field-label",children:"Action type"}),e.jsx("select",{className:"mobile-input",value:l.actionType,onChange:a=>m("actionType",a.target.value),children:Dt.map(a=>e.jsx("option",{value:a,children:a},a))}),e.jsx("label",{className:"mobile-field-label",children:"Target"}),e.jsx("input",{className:"mobile-input",type:"text",placeholder:l.actionType==="webhook"?"https://...":l.actionType==="agent"?"agent or task ref":"echo hello",value:l.actionTarget,onChange:a=>m("actionTarget",a.target.value)}),l.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:l.actionPrompt,onChange:a=>m("actionPrompt",a.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:l.skipIfBudgetLow,onChange:a=>m("skipIfBudgetLow",a.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:l.maxConcurrent,onChange:a=>m("maxConcurrent",parseInt(a.target.value,10)||6),disabled:!l.skipIfBudgetLow})]}),e.jsxs("label",{className:"mobile-checkbox-row",children:[e.jsx("input",{type:"checkbox",checked:l.enabled,onChange:a=>m("enabled",a.target.checked)}),e.jsx("span",{children:"Enabled"})]})]})})}function Ft(s){const t=Date.now()-new Date(s).getTime();return t<6e4?"just now":t<36e5?`${Math.floor(t/6e4)}m ago`:t<864e5?`${Math.floor(t/36e5)}h ago`:new Date(s).toLocaleDateString()}function ze(s,t){try{return new Date(s).toLocaleString(void 0,{timeZone:t||void 0,weekday:"short",hour:"numeric",minute:"2-digit",month:"short",day:"numeric"})}catch{return new Date(s).toLocaleString()}}function Ye(s){if(typeof s!="string")return null;const t=s.trim().split(/\s+/);if(t.length!==5)return null;const[n,r,,,l]=t,u=parseInt(n,10),b=parseInt(r,10);return!Number.isFinite(u)||!Number.isFinite(b)||n!==String(u)||r!==String(b)?null:{minute:u,hour:b,dow:l==="*"?"*":Number.isFinite(parseInt(l,10))?l:"*"}}function qt(s){if(typeof s!="string")return null;const t=/^(\d+)([smhd])$/i.exec(s.trim());return t?{n:parseInt(t[1],10),unit:t[2].toLowerCase()}:null}function _t(s){if(!s)return"";try{const t=new Date(s);if(Number.isNaN(t.getTime()))return"";const n=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}catch{return""}}function Re(s){var u,b;if(s.type!=="cron")return s.schedule;const t=Ye(s.schedule);if(!t)return s.schedule;const n=((u=He.find(c=>c.value===t.dow))==null?void 0:u.label)||t.dow,r=((b=We.find(c=>c.value===t.hour))==null?void 0:b.label)||`${t.hour}`,l=String(t.minute).padStart(2,"0");return n==="Every day"?`Every day ${r} :${l}`:`Every ${n} ${r} :${l}`}const Wt=["all","tasks","agents","artifacts","projects","settings"],Ht={tasks:Z,agents:te,plans:W,projects:ot,settings:K};function Yt({open:s,onClose:t,onNavigate:n}){const[r,l]=i.useState(""),[u,b]=i.useState("all"),[c,m]=i.useState([]),[y,a]=i.useState(!1),x=i.useRef(null);i.useEffect(()=>{s&&(l(""),m([]),requestAnimationFrame(()=>{var d;return(d=x.current)==null?void 0:d.focus()}))},[s]),i.useEffect(()=>{if(!r.trim()){m([]);return}const d=setTimeout(async()=>{a(!0);try{const o=await T.get(`/search?q=${encodeURIComponent(r)}&scope=${u}`);m(o.results||[])}catch{m([])}finally{a(!1)}},250);return()=>clearTimeout(d)},[r,u]);const k=d=>{const o=d.item,N=o.id||o.slug||o.name||"";n(d.type,N),t()},h=c.reduce((d,o)=>(d[o.type]||(d[o.type]=[]),d[o.type].push(o),d),{});return e.jsx(_,{open:s,onClose:t,title:"Search",children:e.jsxs("div",{className:"mobile-search-container",children:[e.jsxs("div",{className:"mobile-search-input-row",children:[e.jsx(ve,{size:16,style:{color:"var(--text-muted)",flexShrink:0}}),e.jsx("input",{ref:x,className:"mobile-search-field",type:"text",placeholder:"Search…",value:r,onChange:d=>l(d.target.value),enterKeyHint:"search",onKeyDown:d=>{d.key==="Escape"&&t(),d.key==="Enter"&&c.length>0&&k(c[0])}}),r&&e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>l(""),"aria-label":"Clear",children:e.jsx(ee,{size:16})})]}),e.jsx("div",{className:"mobile-search-scopes",children:Wt.map(d=>e.jsx("button",{type:"button",className:`mobile-scope-chip ${u===d?"active":""}`,onClick:()=>b(d),children:d==="all"?"All":d.charAt(0).toUpperCase()+d.slice(1)},d))}),e.jsxs("div",{className:"mobile-search-results",children:[y&&e.jsx("div",{className:"mobile-search-loading",children:"Searching…"}),!y&&r&&c.length===0&&e.jsxs("div",{className:"mobile-empty",children:[e.jsx(ve,{size:32}),e.jsx("p",{children:"No results found"})]}),!y&&!r&&e.jsx("div",{className:"mobile-empty",children:e.jsx("p",{children:"Type to search across tasks, agents, plans, and more."})}),Object.entries(h).map(([d,o])=>{const N=Ht[d]||W;return e.jsxs("div",{className:"mobile-search-group",children:[e.jsxs("h4",{className:"mobile-search-group-title",children:[e.jsx(N,{size:12})," ",d.charAt(0).toUpperCase()+d.slice(1)," (",o.length,")"]}),o.map((p,j)=>{const A=p.item;return e.jsxs("button",{type:"button",className:"mobile-search-result-item",onClick:()=>k(p),children:[e.jsx("span",{className:"mobile-search-result-title",children:A.title||A.name||A.slug||"(unnamed)"}),A.description&&e.jsx("span",{className:"mobile-search-result-meta",children:A.description.slice(0,80)})]},j)})]},d)})]})]})})}const Vt=["languages","framework","design","testing","devops","data","security","integration"];function Kt({snapshot:s,onBack:t}){const[n,r]=i.useState([]),[l,u]=i.useState(!0),[b,c]=i.useState(""),[m,y]=i.useState(""),[a,x]=i.useState(null),k=async()=>{try{const o=await T.get("/skills");r(o.skills||[])}catch{}finally{u(!1)}};i.useEffect(()=>{k()},[]);const h=async(o,N)=>{try{await T.patch(`/skills/${encodeURIComponent(o)}`,{enabled:N}),r(p=>p.map(j=>j.id===o?{...j,enabled:N}:j)),(a==null?void 0:a.id)===o&&x(p=>p&&{...p,enabled:N})}catch{}},d=n.filter(o=>{if(m&&o.category!==m)return!1;if(b){const N=b.toLowerCase();return o.name.toLowerCase().includes(N)||o.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:b,onChange:o=>c(o.target.value),style:{flex:1}}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>k(),"aria-label":"Refresh",children:e.jsx(q,{size:16})})]}),e.jsxs("div",{className:"mobile-search-scopes",children:[e.jsx("button",{type:"button",className:`mobile-scope-chip ${m?"":"active"}`,onClick:()=>y(""),children:"All"}),Vt.map(o=>e.jsx("button",{type:"button",className:`mobile-scope-chip ${m===o?"active":""}`,onClick:()=>y(o),children:o},o))]}),l?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading…"})}):d.length===0?e.jsxs("div",{className:"mobile-empty",children:[e.jsx(ye,{size:40}),e.jsx("p",{children:"No skills found."})]}):e.jsx("div",{className:"mobile-card-list",children:d.map(o=>e.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>x(o),children:[e.jsx("div",{className:"mobile-list-icon",children:e.jsx(ye,{size:16})}),e.jsxs("div",{className:"mobile-list-content",children:[e.jsx("span",{className:"mobile-list-title",children:o.name}),e.jsxs("span",{className:"mobile-list-meta",children:[o.category," · v",o.version]})]}),e.jsx("span",{className:`mobile-list-badge ${o.enabled?"badge-on":"badge-off"}`,children:o.enabled?"on":"off"})]},o.id))}),a&&e.jsx(F,{open:!0,onClose:()=>x(null),title:a.name,actions:e.jsxs("button",{type:"button",className:`mobile-btn ${a.enabled?"mobile-btn-secondary":""}`,style:{width:"100%"},onClick:()=>{a&&h(a.id,!a.enabled)},children:[e.jsx(Pe,{size:14})," ",a.enabled?"Disable":"Enable"]}),children:e.jsxs("div",{className:"mobile-agent-detail",children:[e.jsx("p",{className:"mobile-agent-detail-desc",children:a.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:a.category})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Version"}),e.jsx("span",{className:"mono",children:a.version})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Source"}),e.jsx("span",{children:a.source})]}),a.tags.length>0&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Tags"}),e.jsx("span",{children:a.tags.join(", ")})]})]})]})})]})}const Jt=["queued","doing","blocked","done"],G={queued:"Queued",doing:"Doing",blocked:"Blocked",done:"Done"},Ie={queued:"doing",doing:"done",blocked:"queued",done:"queued"};function Gt(s){const t=s.metadata??{};return!!(t.sessionId||t.bgInstanceId)}function Qt(s){var n;const t=s.metadata??{};return!!((n=t.artifactIds)!=null&&n.length||t.artifactId)}function De({snapshot:s,onRefresh:t,selectedTaskId:n,onCloseDetail:r,onOpenChat:l,onOpenArtifact:u}){var pe,fe;const[b,c]=i.useState(s.tasks||[]),[m,y]=i.useState(!s.tasks),[a,x]=i.useState(""),[k,h]=i.useState("queued"),[d,o]=i.useState(null),[N,p]=i.useState(!1),[j,A]=i.useState(null),[S,R]=i.useState([]),[z,P]=i.useState(""),[D,f]=i.useState(null),[v,g]=i.useState(!1),[C,E]=i.useState(""),[I,U]=i.useState("updated");i.useEffect(()=>{var w;if(s.tasks&&(c(s.tasks),y(!1)),n){const L=(w=s.tasks)==null?void 0:w.find($=>$.id===n);L&&o(L)}},[s.tasks,n]),i.useEffect(()=>{if(n){const w=b.find(L=>L.id===n);w&&o(w)}},[n,b]);const J=async()=>{try{const w=await T.get("/tasks");c(Array.isArray(w)?w:[])}catch{}finally{y(!1)}},H=async(w,L)=>{c($=>$.map(M=>M.id===w?{...M,status:L}:M)),(d==null?void 0:d.id)===w&&o($=>$&&{...$,status:L});try{await T.patch(`/tasks/${encodeURIComponent(w)}/status`,{status:L})}catch{await J()}},Ve=async w=>{if(confirm("Delete this task?"))try{await T.del(`/tasks/${encodeURIComponent(w)}`),c(L=>L.filter($=>$.id!==w)),(d==null?void 0:d.id)===w&&o(null)}catch{await J()}},Ke=async w=>{try{await T.post(`/tasks/${encodeURIComponent(w)}/archive`),c(L=>L.filter($=>$.id!==w)),(d==null?void 0:d.id)===w&&o(null)}catch{}},ue=[...b.filter(w=>{var L,$;if(a.trim()){const M=a.toLowerCase();if(!(w.title||"").toLowerCase().includes(M)&&!(w.description||"").toLowerCase().includes(M))return!1}if(C.trim()){const M=C==="mine"?(($=(L=s.settings)==null?void 0:L.data)==null?void 0:$.defaultAgent)||Xt(s):C.replace(/^@/,"");if((w.assignee||"").toLowerCase()!==M.toLowerCase())return!1}return!0})].sort((w,L)=>{switch(I){case"priority":{const $={high:0,normal:1,low:2};return($[w.priority]??1)-($[L.priority]??1)}case"created":return new Date(L.createdAt).getTime()-new Date(w.createdAt).getTime();case"updated":default:return new Date(L.updatedAt).getTime()-new Date(w.updatedAt).getTime()}}),he=ue.filter(w=>w.status===k),be=s.agents||[],Je=async(w,L,$,M)=>{try{const ae=await T.post("/tasks",{title:w,description:L,assignee:$||null,priority:M});c(ne=>[ae,...ne]),p(!1)}catch{}},Ge=async w=>{g(!0),P(""),f(null),A(w);try{const $=((await T.get(`/tasks/${encodeURIComponent(w)}/artifacts`)).artifacts||[]).map(M=>M.id);if(R($),$.length>0){const[M,ae]=await Promise.all([T.get(`/artifacts/${encodeURIComponent($[0])}`),fetch(T.urlWithToken(`/artifacts/${encodeURIComponent($[0])}/content`)).then(ne=>ne.text())]);f(M),P(ae)}}catch{}finally{g(!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:a,onChange:w=>x(w.target.value),style:{flex:1}}),e.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>J(),"aria-label":"Refresh",children:e.jsx(q,{size:16})})]}),e.jsxs("div",{className:"mobile-tasks-filters",children:[e.jsxs("select",{className:"mobile-filter-select",value:C,onChange:w=>E(w.target.value),children:[e.jsx("option",{value:"",children:"All"}),e.jsx("option",{value:"mine",children:"Mine"}),be.map(w=>e.jsxs("option",{value:`@${w.name}`,children:["@",w.name]},w.name))]}),e.jsxs("select",{className:"mobile-filter-select",value:I,onChange:w=>U(w.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:Jt.map(w=>{const L=ue.filter($=>$.status===w).length;return e.jsxs("button",{type:"button",className:`mobile-kanban-tab ${k===w?"active":""}`,onClick:()=>h(w),children:[G[w]," (",L,")"]},w)})}),e.jsxs("div",{className:"mobile-card-list",children:[he.length===0&&e.jsxs("div",{className:"mobile-empty mobile-empty-compact",children:[e.jsxs("p",{children:["No ",G[k].toLowerCase()," tasks."]}),e.jsx("p",{className:"muted",children:"Create one or switch columns."})]}),he.map(w=>{var L;return e.jsxs("button",{type:"button",className:"mobile-task-card",onClick:()=>o(w),children:[e.jsx("div",{className:"priority-dot",style:{background:dt[w.priority]||"var(--info)"}}),e.jsxs("div",{className:"task-content",children:[e.jsx("div",{className:"task-title",children:w.title}),e.jsxs("div",{className:"task-meta",children:[w.assignee?`@${w.assignee}`:"unassigned"," · ",V(w.updatedAt||w.createdAt),(L=w.dependencies)!=null&&L.length?` · ${w.dependencies.length} deps`:""]})]})]},w.id)})]}),e.jsx("button",{type:"button",className:"mobile-fab",onClick:()=>p(!0),"aria-label":"Add task",children:e.jsx(B,{size:24})}),e.jsx(F,{open:!!d,onClose:()=>{o(null),r==null||r()},title:"Task Detail",actions:d&&e.jsxs("div",{className:"mobile-task-detail-actions",children:[d.status!=="done"&&e.jsxs("button",{type:"button",className:"mobile-btn",style:{flex:1},onClick:()=>{d&&H(d.id,Ie[d.status])},children:["Move to ",G[Ie[d.status]||"queued"]]}),e.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>{d&&Ke(d.id)},children:[e.jsx(ct,{size:14})," Archive"]}),Gt(d)&&e.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>{l==null||l(d.id)},children:[e.jsx(Y,{size:14})," Chat"]}),Qt(d)&&e.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>{Ge(d.id)},children:[e.jsx(W,{size:14})," Artifact"]}),e.jsx("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>{d&&Ve(d.id)},children:e.jsx(se,{size:14})})]}),children:d&&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-${d.status}`,children:G[d.status]||d.status}),e.jsx("span",{className:`mobile-task-priority priority-${d.priority}`,children:d.priority})]}),e.jsx("h3",{className:"mobile-task-detail-title",children:d.title}),d.description&&e.jsx("p",{className:"mobile-task-detail-desc",children:d.description}),e.jsxs("div",{className:"mobile-task-detail-meta",children:[d.assignee&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Assignee"}),e.jsxs("span",{children:["@",d.assignee]})]}),d.dueDate&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Due"}),e.jsx("span",{children:new Date(d.dueDate).toLocaleDateString()})]}),d.timeSpent!=null&&e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Time spent"}),e.jsxs("span",{children:[Math.round(d.timeSpent/6e4),"min"]})]}),(pe=d.dependencies)!=null&&pe.length?e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Dependencies"}),e.jsx("span",{children:d.dependencies.length})]}):null,(fe=d.comments)!=null&&fe.length?e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Comments"}),e.jsx("span",{children:d.comments.length})]}):null,e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Created"}),e.jsx("span",{children:V(d.createdAt)})]}),e.jsxs("div",{className:"mobile-task-detail-row",children:[e.jsx("span",{children:"Updated"}),e.jsx("span",{children:V(d.updatedAt)})]})]})]})}),e.jsx(Zt,{open:N,onClose:()=>p(!1),onCreate:Je,agents:be}),e.jsx(F,{open:!!j,onClose:()=>{A(null),P(""),f(null)},title:(D==null?void 0:D.name)||"Artifact",actions:S.length>1?e.jsx("div",{className:"mobile-task-detail-actions",children:S.map((w,L)=>e.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",style:{flex:1},onClick:()=>{g(!0),Promise.all([T.get(`/artifacts/${encodeURIComponent(w)}`),fetch(T.urlWithToken(`/artifacts/${encodeURIComponent(w)}/content`)).then($=>$.text())]).then(([$,M])=>{f($),P(M),g(!1)}).catch(()=>g(!1))},children:["Artifact ",L+1]},w))}):null,children:e.jsx("div",{className:"mobile-artifact-viewer",children:v?e.jsx("div",{className:"mobile-loading",children:e.jsx("p",{children:"Loading artifact…"})}):z?e.jsx("iframe",{srcDoc:z,className:"mobile-artifact-iframe",sandbox:"allow-scripts allow-forms allow-popups allow-same-origin",title:(D==null?void 0:D.name)||"Artifact",loading:"lazy"}):e.jsxs("div",{className:"mobile-empty",children:[e.jsx(W,{size:32}),e.jsx("p",{className:"muted",children:"No artifact content available."})]})})})]})}function Xt(s){var t,n;return((n=(t=s.settings)==null?void 0:t.data)==null?void 0:n.defaultAgent)||"odin"}function Zt({open:s,onClose:t,onCreate:n,agents:r}){const[l,u]=i.useState(""),[b,c]=i.useState(""),[m,y]=i.useState(""),[a,x]=i.useState("normal"),k=h=>{h.preventDefault(),l.trim()&&(n(l.trim(),b.trim(),m,a),u(""),c(""),y(""),x("normal"))};return e.jsx(_,{open:s,onClose:t,title:"New Task",actions:e.jsxs("button",{type:"submit",form:"new-task-form",className:"mobile-btn",style:{width:"100%"},children:[e.jsx(B,{size:14})," Create Task"]}),children:e.jsxs("form",{id:"new-task-form",onSubmit:k,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:l,onChange:h=>u(h.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:b,onChange:h=>c(h.target.value)}),e.jsx("label",{className:"mobile-field-label",children:"Assignee"}),e.jsxs("select",{className:"mobile-input",value:m,onChange:h=>y(h.target.value),children:[e.jsx("option",{value:"",children:"Unassigned"}),r.map(h=>e.jsxs("option",{value:h.name,children:["@",h.name]},h.name))]}),e.jsx("label",{className:"mobile-field-label",children:"Priority"}),e.jsxs("select",{className:"mobile-input",value:a,onChange:h=>x(h.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 es=Me.lazy(()=>qe(()=>import("./MobileSettings-B91gVFii.js"),__vite__mapDeps([0,1,2])).then(s=>({default:s.MobileSettings}))),ts=Me.lazy(()=>qe(()=>import("./MobileChat-OidrxXR9.js"),__vite__mapDeps([3,1,4,2,5,6])).then(s=>({default:s.MobileChat}))),ss=[{id:"activity",label:"Activity",icon:ce},{id:"chat",label:"Chat",icon:Y},{id:"tasks",label:"Tasks",icon:Z},{id:"settings",label:"Settings",icon:Ue},{id:"more",label:"More",icon:rt}];function as(s){const t=s.meta??{},n=typeof t.taskId=="string"?t.taskId:null,r=typeof t.slug=="string"?t.slug:null,l=typeof t.agent=="string"?t.agent:null;if(n)return{id:"task-detail",taskId:n};if(r)return{id:"artifacts?-detail",slug:r};if(l)return{id:"agent-detail",name:l};const u=s.link??"";return u.startsWith("/artifacts?/")?{id:"artifacts?-detail",slug:decodeURIComponent(u.slice(12))}:u.startsWith("/tasks/")?{id:"task-detail",taskId:decodeURIComponent(u.slice(7))}:u.startsWith("/agents/")?{id:"agent-detail",name:decodeURIComponent(u.slice(8))}:null}function us(){const[s,t]=i.useState("activity"),[n,r]=i.useState([]),[l,u]=i.useState(!1),[b,c]=i.useState(null),[m,y]=i.useState(null),[a,x]=i.useState(null),[k,h]=i.useState(null),[d,o]=i.useState(!0),[N,p]=i.useState(0),j=i.useMemo(()=>n[n.length-1]??{id:s},[s,n]),A=i.useCallback(v=>{r(g=>[...g,v])},[]),S=i.useCallback(()=>{r(v=>v.slice(0,-1))},[]),R=i.useCallback(v=>{r([]),t(v)},[]),z=i.useCallback(async()=>{var v;try{const g=await T.get("/snapshot");y(g),(v=g.settings)!=null&&v.data&&x(g.settings.data),h(null)}catch(g){throw h(g.message||"Dashboard server unreachable."),g}},[]);i.useEffect(()=>{let v=!1;return Promise.all([T.get("/snapshot").catch(()=>null),T.get("/settings").catch(()=>null),T.probeAuthStatus().catch(()=>null)]).then(([g,C])=>{var I;if(v)return;const E=(C==null?void 0:C.data)??((I=g==null?void 0:g.settings)==null?void 0:I.data)??null;g&&y(g),E&&x(E),h(!g&&!E?"Dashboard server unreachable.":null)}).catch(g=>{v||h(g.message||"Dashboard server unreachable.")}).finally(()=>{v||o(!1)}),()=>{v=!0}},[]),i.useEffect(()=>{a!=null&&a.theme&&(we(a.theme),Se(a.theme))},[a==null?void 0:a.theme]),i.useEffect(()=>{var C;if(((C=a==null?void 0:a.theme)==null?void 0:C.mode)!=="system")return;const v=window.matchMedia("(prefers-color-scheme: light)"),g=()=>{a!=null&&a.theme&&(we(a.theme),Se(a.theme))};return v.addEventListener("change",g),()=>v.removeEventListener("change",g)},[a==null?void 0:a.theme]),i.useEffect(()=>{const v=()=>{p(C=>C+1),z().catch(()=>{})},g=()=>{document.visibilityState==="visible"&&v()};return window.addEventListener("online",v),window.addEventListener("pageshow",v),document.addEventListener("visibilitychange",g),()=>{window.removeEventListener("online",v),window.removeEventListener("pageshow",v),document.removeEventListener("visibilitychange",g)}},[z]),i.useEffect(()=>{const v=new Fe,g=v.on(C=>{if(C.type==="snapshot"&&"data"in C&&C.data)y(E=>({...E??{},...C.data}));else if(C.type==="change")z().catch(()=>{});else if(C.type==="tasks:change"){const E=C.task;y(I=>{if(!I)return I;const U=(I.tasks||[]).map(H=>H.id===E.id?E:H),J=U.some(H=>H.id===E.id);return{...I,tasks:J?U:[E,...U]}})}else C.type==="tasks:delete"?y(E=>E&&{...E,tasks:(E.tasks||[]).filter(I=>I.id!==C.id)}):C.type==="settings:change"?C.settings&&x(C.settings):C.type==="project:change"||C.type==="agents:change"||C.type==="schedules:change"||C.type==="artifact:change"?z().catch(()=>{}):(C.type==="agent:status"||C.type==="agent:restarted")&&y(E=>{if(!E)return E;const I=(E.agents||[]).map(U=>U.name===C.agent.name?C.agent:U);return{...E,agents:I}})});return()=>{g(),v.close()}},[z,N]);const P=i.useCallback(v=>{(v==="activity"||v==="chat"||v==="tasks"||v==="settings"||v==="more")&&R(v)},[R]),D=i.useCallback((v,g,C)=>{if(v==="notification"){const E=as({link:g||null,meta:C??null});E&&A(E);return}if(v==="task"&&g){A({id:"task-detail",taskId:g});return}if(v==="artifacts?"&&g){A({id:"artifacts?-detail",slug:g});return}if(v==="agent"&&g){A({id:"agent-detail",name:g});return}if(v==="project"){R("activity");return}v==="setting"&&R("settings")},[R,A]),f=()=>{if(!m||!a)return null;if(n.length>0){const v=n[n.length-1];switch(v.id){case"artifacts?":return e.jsx(Rt,{snapshot:m,onBack:S,onOpenArtifact:g=>A({id:"artifacts?-detail",slug:g})});case"agents":return e.jsx(Ee,{snapshot:m,onBack:S,onOpenAgent:g=>A({id:"agent-detail",name:g}),onRefresh:z});case"skills":return e.jsx(Kt,{snapshot:m,onBack:S});case"mods":return e.jsx(Tt,{snapshot:m,onBack:S});case"schedules":return e.jsx(Ut,{snapshot:m,onBack:S});case"history":return e.jsx(Ct,{onBack:S});case"config":return e.jsx(St,{onBack:S});case"artifacts?-detail":return e.jsx($t,{slug:v.slug,onBack:S});case"agent-detail":return e.jsx(Ee,{snapshot:m,onBack:S,onOpenAgent:()=>{},onRefresh:z,selectedAgent:v.name});case"task-detail":return e.jsx(De,{snapshot:m,onRefresh:z,selectedTaskId:v.taskId,onCloseDetail:S,onOpenChat:g=>{c(g),R("chat")}});default:return null}}switch(s){case"activity":return e.jsx(Nt,{snapshot:m,onRefresh:z});case"chat":return e.jsx(i.Suspense,{fallback:e.jsx("div",{className:"mobile-loading",children:e.jsx(ie,{size:"lg"})}),children:e.jsx(ts,{snapshot:m,settings:a,initialTaskId:b,onClearTaskId:()=>c(null)})});case"tasks":return e.jsx(De,{snapshot:m,onRefresh:z,onOpenChat:v=>{c(v),R("chat")}});case"settings":return e.jsx(i.Suspense,{fallback:e.jsx("div",{className:"mobile-loading",children:e.jsx(ie,{size:"lg"})}),children:e.jsx(es,{settings:a,snapshot:m,onRefresh:z})});case"more":return e.jsx(At,{snapshot:m,onNavigate:v=>{(v==="artifacts?"||v==="agents"||v==="skills"||v==="mods"||v==="schedules"||v==="history"||v==="config")&&A({id:v})}});default:return null}};return d?e.jsxs("div",{className:"mobile-loading",children:[e.jsx(ie,{size:"lg"}),e.jsx("p",{children:"Loading Bizar…"})]}):k||!m||!a?e.jsxs("div",{className:"mobile-loading",children:[e.jsx("h2",{children:"Dashboard unavailable"}),e.jsx("p",{children:k||"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(vt,{activeTab:j.id,snapshot:m,onSearch:()=>u(!0),onNavigate:D}),e.jsx("main",{className:"mobile-content",children:f()}),n.length===0&&e.jsx(pt,{tabs:ss,activeTab:s,onChange:P}),n.length>0&&e.jsx("button",{type:"button",className:"mobile-back-btn",onClick:S,"aria-label":"Go back",children:"← Back"}),e.jsx(Yt,{open:l,onClose:()=>u(!1),onNavigate:D})]})}export{ke as A,us as M,ie as S,Fe as W,qe as _,T as a,cs as b,Be as c,Se as d,ds as e,V as f,we as g,dt as p,rs as t,ms as w};