@polderlabs/bizar 4.7.0 → 4.7.2

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 (75) hide show
  1. package/bizar-dash/dist/assets/main-DHZmbnxQ.js +361 -0
  2. package/bizar-dash/dist/assets/main-DHZmbnxQ.js.map +1 -0
  3. package/bizar-dash/dist/assets/main-DX_Jh8Wc.css +1 -0
  4. package/bizar-dash/dist/assets/{mobile-CWqPoGaT.js → mobile-BK8-ythT.js} +2 -2
  5. package/bizar-dash/dist/assets/mobile-BK8-ythT.js.map +1 -0
  6. package/bizar-dash/dist/assets/{mobile-i4Uv9eW8.js → mobile-Chvf9u_B.js} +1 -1
  7. package/bizar-dash/dist/assets/{mobile-i4Uv9eW8.js.map → mobile-Chvf9u_B.js.map} +1 -1
  8. package/bizar-dash/dist/index.html +3 -3
  9. package/bizar-dash/dist/mobile.html +2 -2
  10. package/bizar-dash/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -1
  11. package/bizar-dash/skills/publishing/SKILL.md +146 -0
  12. package/bizar-dash/src/server/api.mjs +8 -0
  13. package/bizar-dash/src/server/backup-store.mjs +525 -0
  14. package/bizar-dash/src/server/digest-store.mjs +558 -0
  15. package/bizar-dash/src/server/lib/rate-limit.mjs +122 -0
  16. package/bizar-dash/src/server/routes/backup.mjs +112 -0
  17. package/bizar-dash/src/server/routes/chat.mjs +14 -0
  18. package/bizar-dash/src/server/routes/digests.mjs +82 -0
  19. package/bizar-dash/src/server/routes-v2/events.mjs +14 -0
  20. package/bizar-dash/src/server/schedules-runner.mjs +126 -0
  21. package/bizar-dash/src/server/server.mjs +17 -0
  22. package/bizar-dash/src/web/App.tsx +8 -1
  23. package/bizar-dash/src/web/components/BackupRestore.tsx +330 -0
  24. package/bizar-dash/src/web/components/SearchModal.tsx +3 -1
  25. package/bizar-dash/src/web/components/chat/Composer.tsx +2 -0
  26. package/bizar-dash/src/web/styles/main.css +70 -8
  27. package/bizar-dash/src/web/views/Activity.tsx +11 -1
  28. package/bizar-dash/src/web/views/Agents.tsx +57 -42
  29. package/bizar-dash/src/web/views/Artifacts.tsx +38 -25
  30. package/bizar-dash/src/web/views/Chat.tsx +8 -0
  31. package/bizar-dash/src/web/views/History.tsx +4 -1
  32. package/bizar-dash/src/web/views/MiniMaxUsage.tsx +21 -4
  33. package/bizar-dash/src/web/views/Mods.tsx +30 -17
  34. package/bizar-dash/src/web/views/Overview.tsx +8 -1
  35. package/bizar-dash/src/web/views/Providers.tsx +16 -16
  36. package/bizar-dash/src/web/views/Schedules.tsx +33 -15
  37. package/bizar-dash/src/web/views/Settings.tsx +97 -1751
  38. package/bizar-dash/src/web/views/Skills.tsx +4 -1
  39. package/bizar-dash/src/web/views/Tasks.tsx +11 -2
  40. package/bizar-dash/src/web/views/memory/ConfigPanel.tsx +8 -2
  41. package/bizar-dash/src/web/views/memory/LightragPanel.tsx +3 -0
  42. package/bizar-dash/src/web/views/memory/ObsidianPanel.tsx +12 -4
  43. package/bizar-dash/src/web/views/memory/SemanticSearchPanel.tsx +3 -0
  44. package/bizar-dash/src/web/views/settings/ActivitySection.tsx +205 -0
  45. package/bizar-dash/src/web/views/settings/AgentSection.tsx +294 -0
  46. package/bizar-dash/src/web/views/settings/AuthSection.tsx +159 -0
  47. package/bizar-dash/src/web/views/settings/BackupSection.tsx +16 -0
  48. package/bizar-dash/src/web/views/settings/EnvVarsSection.tsx +16 -0
  49. package/bizar-dash/src/web/views/settings/GeneralSection.tsx +105 -0
  50. package/bizar-dash/src/web/views/settings/HeadroomSection.tsx +39 -0
  51. package/bizar-dash/src/web/views/settings/MemorySection.tsx +16 -0
  52. package/bizar-dash/src/web/views/settings/NetworkSection.tsx +87 -0
  53. package/bizar-dash/src/web/views/settings/NotificationsSection.tsx +34 -0
  54. package/bizar-dash/src/web/views/settings/ProvidersSection.tsx +16 -0
  55. package/bizar-dash/src/web/views/settings/SkillsSection.tsx +16 -0
  56. package/bizar-dash/src/web/views/settings/SystemLlmSection.tsx +81 -0
  57. package/bizar-dash/src/web/views/settings/ThemeSection.tsx +168 -0
  58. package/bizar-dash/src/web/views/settings/UpdatesSection.tsx +256 -0
  59. package/bizar-dash/tests/a11y.test.tsx +206 -0
  60. package/bizar-dash/tests/backup-restore.test.mjs +217 -0
  61. package/bizar-dash/tests/backup-restore.test.tsx +123 -0
  62. package/bizar-dash/tests/backup-store.test.mjs +300 -0
  63. package/bizar-dash/tests/cli-error-visibility.test.mjs +153 -0
  64. package/bizar-dash/tests/digest-generation.test.mjs +191 -0
  65. package/bizar-dash/tests/digest-store.test.mjs +264 -0
  66. package/bizar-dash/tests/rate-limit.test.mjs +298 -0
  67. package/cli/bin.mjs +96 -2
  68. package/cli/commands/minimax.mjs +20 -0
  69. package/cli/commands/util.mjs +154 -1
  70. package/cli/digest.mjs +149 -0
  71. package/package.json +1 -1
  72. package/bizar-dash/dist/assets/main-DAlLdW8I.css +0 -1
  73. package/bizar-dash/dist/assets/main-DGGq-iZI.js +0 -361
  74. package/bizar-dash/dist/assets/main-DGGq-iZI.js.map +0 -1
  75. package/bizar-dash/dist/assets/mobile-CWqPoGaT.js.map +0 -1
@@ -340,7 +340,7 @@ Error generating stack: `+l.message+`
340
340
  `))+1))}const s="#".repeat(i),o=n.enter("headingAtx"),u=n.enter("phrasing");l.move(s+" ");let d=n.containerPhrasing(e,{before:"# ",after:`
341
341
  `,...l.current()});return/^[\t ]/.test(d)&&(d=Pi(d.charCodeAt(0))+d.slice(1)),d=d?s+" "+d:s,n.options.closeAtx&&(d+=" "+s),u(),o(),d}Mp.peek=hS;function Mp(e){return e.value||""}function hS(){return"<"}Lp.peek=mS;function Lp(e,t,n,r){const i=Gu(n),l=i==='"'?"Quote":"Apostrophe",s=n.enter("image");let o=n.enter("label");const u=n.createTracker(r);let d=u.move("![");return d+=u.move(n.safe(e.alt,{before:d,after:"]",...u.current()})),d+=u.move("]("),o(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(o=n.enter("destinationLiteral"),d+=u.move("<"),d+=u.move(n.safe(e.url,{before:d,after:">",...u.current()})),d+=u.move(">")):(o=n.enter("destinationRaw"),d+=u.move(n.safe(e.url,{before:d,after:e.title?" ":")",...u.current()}))),o(),e.title&&(o=n.enter(`title${l}`),d+=u.move(" "+i),d+=u.move(n.safe(e.title,{before:d,after:i,...u.current()})),d+=u.move(i),o()),d+=u.move(")"),s(),d}function mS(){return"!"}Rp.peek=pS;function Rp(e,t,n,r){const i=e.referenceType,l=n.enter("imageReference");let s=n.enter("label");const o=n.createTracker(r);let u=o.move("![");const d=n.safe(e.alt,{before:u,after:"]",...o.current()});u+=o.move(d+"]["),s();const c=n.stack;n.stack=[],s=n.enter("reference");const f=n.safe(n.associationId(e),{before:u,after:"]",...o.current()});return s(),n.stack=c,l(),i==="full"||!d||d!==f?u+=o.move(f+"]"):i==="shortcut"?u=u.slice(0,-1):u+=o.move("]"),u}function pS(){return"!"}Dp.peek=gS;function Dp(e,t,n){let r=e.value||"",i="`",l=-1;for(;new RegExp("(^|[^`])"+i+"([^`]|$)").test(r);)i+="`";for(/[^ \r\n]/.test(r)&&(/^[ \r\n]/.test(r)&&/[ \r\n]$/.test(r)||/^`|`$/.test(r))&&(r=" "+r+" ");++l<n.unsafe.length;){const s=n.unsafe[l],o=n.compilePattern(s);let u;if(s.atBreak)for(;u=o.exec(r);){let d=u.index;r.charCodeAt(d)===10&&r.charCodeAt(d-1)===13&&d--,r=r.slice(0,d)+" "+r.slice(u.index+1)}}return i+r+i}function gS(){return"`"}function _p(e,t){const n=Bu(e);return!!(!t.options.resourceLink&&e.url&&!e.title&&e.children&&e.children.length===1&&e.children[0].type==="text"&&(n===e.url||"mailto:"+n===e.url)&&/^[a-z][a-z+.-]+:/i.test(e.url)&&!/[\0- <>\u007F]/.test(e.url))}Op.peek=yS;function Op(e,t,n,r){const i=Gu(n),l=i==='"'?"Quote":"Apostrophe",s=n.createTracker(r);let o,u;if(_p(e,n)){const c=n.stack;n.stack=[],o=n.enter("autolink");let f=s.move("<");return f+=s.move(n.containerPhrasing(e,{before:f,after:">",...s.current()})),f+=s.move(">"),o(),n.stack=c,f}o=n.enter("link"),u=n.enter("label");let d=s.move("[");return d+=s.move(n.containerPhrasing(e,{before:d,after:"](",...s.current()})),d+=s.move("]("),u(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(u=n.enter("destinationLiteral"),d+=s.move("<"),d+=s.move(n.safe(e.url,{before:d,after:">",...s.current()})),d+=s.move(">")):(u=n.enter("destinationRaw"),d+=s.move(n.safe(e.url,{before:d,after:e.title?" ":")",...s.current()}))),u(),e.title&&(u=n.enter(`title${l}`),d+=s.move(" "+i),d+=s.move(n.safe(e.title,{before:d,after:i,...s.current()})),d+=s.move(i),u()),d+=s.move(")"),o(),d}function yS(e,t,n){return _p(e,n)?"<":"["}Fp.peek=xS;function Fp(e,t,n,r){const i=e.referenceType,l=n.enter("linkReference");let s=n.enter("label");const o=n.createTracker(r);let u=o.move("[");const d=n.containerPhrasing(e,{before:u,after:"]",...o.current()});u+=o.move(d+"]["),s();const c=n.stack;n.stack=[],s=n.enter("reference");const f=n.safe(n.associationId(e),{before:u,after:"]",...o.current()});return s(),n.stack=c,l(),i==="full"||!d||d!==f?u+=o.move(f+"]"):i==="shortcut"?u=u.slice(0,-1):u+=o.move("]"),u}function xS(){return"["}function Xu(e){const t=e.options.bullet||"*";if(t!=="*"&&t!=="+"&&t!=="-")throw new Error("Cannot serialize items with `"+t+"` for `options.bullet`, expected `*`, `+`, or `-`");return t}function vS(e){const t=Xu(e),n=e.options.bulletOther;if(!n)return t==="*"?"-":"*";if(n!=="*"&&n!=="+"&&n!=="-")throw new Error("Cannot serialize items with `"+n+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(n===t)throw new Error("Expected `bullet` (`"+t+"`) and `bulletOther` (`"+n+"`) to be different");return n}function kS(e){const t=e.options.bulletOrdered||".";if(t!=="."&&t!==")")throw new Error("Cannot serialize items with `"+t+"` for `options.bulletOrdered`, expected `.` or `)`");return t}function $p(e){const t=e.options.rule||"*";if(t!=="*"&&t!=="-"&&t!=="_")throw new Error("Cannot serialize rules with `"+t+"` for `options.rule`, expected `*`, `-`, or `_`");return t}function wS(e,t,n,r){const i=n.enter("list"),l=n.bulletCurrent;let s=e.ordered?kS(n):Xu(n);const o=e.ordered?s==="."?")":".":vS(n);let u=t&&n.bulletLastUsed?s===n.bulletLastUsed:!1;if(!e.ordered){const c=e.children?e.children[0]:void 0;if((s==="*"||s==="-")&&c&&(!c.children||!c.children[0])&&n.stack[n.stack.length-1]==="list"&&n.stack[n.stack.length-2]==="listItem"&&n.stack[n.stack.length-3]==="list"&&n.stack[n.stack.length-4]==="listItem"&&n.indexStack[n.indexStack.length-1]===0&&n.indexStack[n.indexStack.length-2]===0&&n.indexStack[n.indexStack.length-3]===0&&(u=!0),$p(n)===s&&c){let f=-1;for(;++f<e.children.length;){const m=e.children[f];if(m&&m.type==="listItem"&&m.children&&m.children[0]&&m.children[0].type==="thematicBreak"){u=!0;break}}}}u&&(s=o),n.bulletCurrent=s;const d=n.containerFlow(e,r);return n.bulletLastUsed=s,n.bulletCurrent=l,i(),d}function bS(e){const t=e.options.listItemIndent||"one";if(t!=="tab"&&t!=="one"&&t!=="mixed")throw new Error("Cannot serialize items with `"+t+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return t}function SS(e,t,n,r){const i=bS(n);let l=n.bulletCurrent||Xu(n);t&&t.type==="list"&&t.ordered&&(l=(typeof t.start=="number"&&t.start>-1?t.start:1)+(n.options.incrementListMarker===!1?0:t.children.indexOf(e))+l);let s=l.length+1;(i==="tab"||i==="mixed"&&(t&&t.type==="list"&&t.spread||e.spread))&&(s=Math.ceil(s/4)*4);const o=n.createTracker(r);o.move(l+" ".repeat(s-l.length)),o.shift(s);const u=n.enter("listItem"),d=n.indentLines(n.containerFlow(e,o.current()),c);return u(),d;function c(f,m,h){return m?(h?"":" ".repeat(s))+f:(h?l:l+" ".repeat(s-l.length))+f}}function CS(e,t,n,r){const i=n.enter("paragraph"),l=n.enter("phrasing"),s=n.containerPhrasing(e,r);return l(),i(),s}const jS=Ts(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function NS(e,t,n,r){return(e.children.some(function(s){return jS(s)})?n.containerPhrasing:n.containerFlow).call(n,e,r)}function ES(e){const t=e.options.strong||"*";if(t!=="*"&&t!=="_")throw new Error("Cannot serialize strong with `"+t+"` for `options.strong`, expected `*`, or `_`");return t}Bp.peek=TS;function Bp(e,t,n,r){const i=ES(n),l=n.enter("strong"),s=n.createTracker(r),o=s.move(i+i);let u=s.move(n.containerPhrasing(e,{after:i,before:o,...s.current()}));const d=u.charCodeAt(0),c=ls(r.before.charCodeAt(r.before.length-1),d,i);c.inside&&(u=Pi(d)+u.slice(1));const f=u.charCodeAt(u.length-1),m=ls(r.after.charCodeAt(0),f,i);m.inside&&(u=u.slice(0,-1)+Pi(f));const h=s.move(i+i);return l(),n.attentionEncodeSurroundingInfo={after:m.outside,before:c.outside},o+u+h}function TS(e,t,n){return n.options.strong||"*"}function IS(e,t,n,r){return n.safe(e.value,r)}function zS(e){const t=e.options.ruleRepetition||3;if(t<3)throw new Error("Cannot serialize rules with repetition `"+t+"` for `options.ruleRepetition`, expected `3` or more");return t}function PS(e,t,n){const r=($p(n)+(n.options.ruleSpaces?" ":"")).repeat(zS(n));return n.options.ruleSpaces?r.slice(0,-1):r}const Up={blockquote:eS,break:cf,code:sS,definition:aS,emphasis:Ap,hardBreak:cf,heading:fS,html:Mp,image:Lp,imageReference:Rp,inlineCode:Dp,link:Op,linkReference:Fp,list:wS,listItem:SS,paragraph:CS,root:NS,strong:Bp,text:IS,thematicBreak:PS};function AS(){return{enter:{table:MS,tableData:df,tableHeader:df,tableRow:RS},exit:{codeText:DS,table:LS,tableData:So,tableHeader:So,tableRow:So}}}function MS(e){const t=e._align;this.enter({type:"table",align:t.map(function(n){return n==="none"?null:n}),children:[]},e),this.data.inTable=!0}function LS(e){this.exit(e),this.data.inTable=void 0}function RS(e){this.enter({type:"tableRow",children:[]},e)}function So(e){this.exit(e)}function df(e){this.enter({type:"tableCell",children:[]},e)}function DS(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,_S));const n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function _S(e,t){return t==="|"?t:e}function OS(e){const t=e||{},n=t.tableCellPadding,r=t.tablePipeAlign,i=t.stringLength,l=n?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:`
342
342
  `,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:m,table:s,tableCell:u,tableRow:o}};function s(h,p,x,b){return d(c(h,x,b),h.align)}function o(h,p,x,b){const y=f(h,x,b),g=d([y]);return g.slice(0,g.indexOf(`
343
- `))}function u(h,p,x,b){const y=x.enter("tableCell"),g=x.enter("phrasing"),v=x.containerPhrasing(h,{...b,before:l,after:l});return g(),y(),v}function d(h,p){return Zb(h,{align:p,alignDelimiters:r,padding:n,stringLength:i})}function c(h,p,x){const b=h.children;let y=-1;const g=[],v=p.enter("table");for(;++y<b.length;)g[y]=f(b[y],p,x);return v(),g}function f(h,p,x){const b=h.children;let y=-1;const g=[],v=p.enter("tableRow");for(;++y<b.length;)g[y]=u(b[y],h,p,x);return v(),g}function m(h,p,x){let b=Up.inlineCode(h,p,x);return x.stack.includes("tableCell")&&(b=b.replace(/\|/g,"\\$&")),b}}function FS(){return{exit:{taskListCheckValueChecked:ff,taskListCheckValueUnchecked:ff,paragraph:BS}}}function $S(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:US}}}function ff(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function BS(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const r=n.children[0];if(r&&r.type==="text"){const i=t.children;let l=-1,s;for(;++l<i.length;){const o=i[l];if(o.type==="paragraph"){s=o;break}}s===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start=Object.assign({},r.position.start)))}}this.exit(e)}function US(e,t,n,r){const i=e.children[0],l=typeof e.checked=="boolean"&&i&&i.type==="paragraph",s="["+(e.checked?"x":" ")+"] ",o=n.createTracker(r);l&&o.move(s);let u=Up.listItem(e,t,n,{...r,...o.current()});return l&&(u=u.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,d)),u;function d(c){return c+s}}function HS(){return[wb(),Ub(),Qb(),AS(),FS()]}function VS(e){return{extensions:[bb(),Hb(e),qb(),OS(e),$S()]}}const WS={tokenize:XS,partial:!0},Hp={tokenize:ZS,partial:!0},Vp={tokenize:JS,partial:!0},Wp={tokenize:e2,partial:!0},QS={tokenize:t2,partial:!0},Qp={name:"wwwAutolink",tokenize:KS,previous:Yp},qp={name:"protocolAutolink",tokenize:GS,previous:Kp},rn={name:"emailAutolink",tokenize:YS,previous:Gp},Wt={};function qS(){return{text:Wt}}let zn=48;for(;zn<123;)Wt[zn]=rn,zn++,zn===58?zn=65:zn===91&&(zn=97);Wt[43]=rn;Wt[45]=rn;Wt[46]=rn;Wt[95]=rn;Wt[72]=[rn,qp];Wt[104]=[rn,qp];Wt[87]=[rn,Qp];Wt[119]=[rn,Qp];function YS(e,t,n){const r=this;let i,l;return s;function s(f){return!Ma(f)||!Gp.call(r,r.previous)||Zu(r.events)?n(f):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),o(f))}function o(f){return Ma(f)?(e.consume(f),o):f===64?(e.consume(f),u):n(f)}function u(f){return f===46?e.check(QS,c,d)(f):f===45||f===95||Ye(f)?(l=!0,e.consume(f),u):c(f)}function d(f){return e.consume(f),i=!0,u}function c(f){return l&&i&&Ze(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(f)):n(f)}}function KS(e,t,n){const r=this;return i;function i(s){return s!==87&&s!==119||!Yp.call(r,r.previous)||Zu(r.events)?n(s):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(WS,e.attempt(Hp,e.attempt(Vp,l),n),n)(s))}function l(s){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(s)}}function GS(e,t,n){const r=this;let i="",l=!1;return s;function s(f){return(f===72||f===104)&&Kp.call(r,r.previous)&&!Zu(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(f),e.consume(f),o):n(f)}function o(f){if(Ze(f)&&i.length<5)return i+=String.fromCodePoint(f),e.consume(f),o;if(f===58){const m=i.toLowerCase();if(m==="http"||m==="https")return e.consume(f),u}return n(f)}function u(f){return f===47?(e.consume(f),l?d:(l=!0,u)):n(f)}function d(f){return f===null||ns(f)||ke(f)||Yn(f)||js(f)?n(f):e.attempt(Hp,e.attempt(Vp,c),n)(f)}function c(f){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(f)}}function XS(e,t,n){let r=0;return i;function i(s){return(s===87||s===119)&&r<3?(r++,e.consume(s),i):s===46&&r===3?(e.consume(s),l):n(s)}function l(s){return s===null?n(s):t(s)}}function ZS(e,t,n){let r,i,l;return s;function s(d){return d===46||d===95?e.check(Wp,u,o)(d):d===null||ke(d)||Yn(d)||d!==45&&js(d)?u(d):(l=!0,e.consume(d),s)}function o(d){return d===95?r=!0:(i=r,r=void 0),e.consume(d),s}function u(d){return i||r||!l?n(d):t(d)}}function JS(e,t){let n=0,r=0;return i;function i(s){return s===40?(n++,e.consume(s),i):s===41&&r<n?l(s):s===33||s===34||s===38||s===39||s===41||s===42||s===44||s===46||s===58||s===59||s===60||s===63||s===93||s===95||s===126?e.check(Wp,t,l)(s):s===null||ke(s)||Yn(s)?t(s):(e.consume(s),i)}function l(s){return s===41&&r++,e.consume(s),i}}function e2(e,t,n){return r;function r(o){return o===33||o===34||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===63||o===95||o===126?(e.consume(o),r):o===38?(e.consume(o),l):o===93?(e.consume(o),i):o===60||o===null||ke(o)||Yn(o)?t(o):n(o)}function i(o){return o===null||o===40||o===91||ke(o)||Yn(o)?t(o):r(o)}function l(o){return Ze(o)?s(o):n(o)}function s(o){return o===59?(e.consume(o),r):Ze(o)?(e.consume(o),s):n(o)}}function t2(e,t,n){return r;function r(l){return e.consume(l),i}function i(l){return Ye(l)?n(l):t(l)}}function Yp(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||ke(e)}function Kp(e){return!Ze(e)}function Gp(e){return!(e===47||Ma(e))}function Ma(e){return e===43||e===45||e===46||e===95||Ye(e)}function Zu(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const n2={tokenize:c2,partial:!0};function r2(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:o2,continuation:{tokenize:a2},exit:u2}},text:{91:{name:"gfmFootnoteCall",tokenize:s2},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:i2,resolveTo:l2}}}}function i2(e,t,n){const r=this;let i=r.events.length;const l=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s;for(;i--;){const u=r.events[i][1];if(u.type==="labelImage"){s=u;break}if(u.type==="gfmFootnoteCall"||u.type==="labelLink"||u.type==="label"||u.type==="image"||u.type==="link")break}return o;function o(u){if(!s||!s._balanced)return n(u);const d=Lt(r.sliceSerialize({start:s.end,end:r.now()}));return d.codePointAt(0)!==94||!l.includes(d.slice(1))?n(u):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(u),e.exit("gfmFootnoteCallLabelMarker"),t(u))}}function l2(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;const l={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},s={type:"chunkString",contentType:"string",start:Object.assign({},l.start),end:Object.assign({},l.end)},o=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",i,t],["exit",i,t],["enter",l,t],["enter",s,t],["exit",s,t],["exit",l,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...o),e}function s2(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let l=0,s;return o;function o(f){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),u}function u(f){return f!==94?n(f):(e.enter("gfmFootnoteCallMarker"),e.consume(f),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",d)}function d(f){if(l>999||f===93&&!s||f===null||f===91||ke(f))return n(f);if(f===93){e.exit("chunkString");const m=e.exit("gfmFootnoteCallString");return i.includes(Lt(r.sliceSerialize(m)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(f)}return ke(f)||(s=!0),l++,e.consume(f),f===92?c:d}function c(f){return f===91||f===92||f===93?(e.consume(f),l++,d):d(f)}}function o2(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let l,s=0,o;return u;function u(p){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(p),e.exit("gfmFootnoteDefinitionLabelMarker"),d}function d(p){return p===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(p),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",c):n(p)}function c(p){if(s>999||p===93&&!o||p===null||p===91||ke(p))return n(p);if(p===93){e.exit("chunkString");const x=e.exit("gfmFootnoteDefinitionLabelString");return l=Lt(r.sliceSerialize(x)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(p),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),m}return ke(p)||(o=!0),s++,e.consume(p),p===92?f:c}function f(p){return p===91||p===92||p===93?(e.consume(p),s++,c):c(p)}function m(p){return p===58?(e.enter("definitionMarker"),e.consume(p),e.exit("definitionMarker"),i.includes(l)||i.push(l),me(e,h,"gfmFootnoteDefinitionWhitespace")):n(p)}function h(p){return t(p)}}function a2(e,t,n){return e.check(Oi,t,e.attempt(n2,t,n))}function u2(e){e.exit("gfmFootnoteDefinition")}function c2(e,t,n){const r=this;return me(e,i,"gfmFootnoteDefinitionIndent",5);function i(l){const s=r.events[r.events.length-1];return s&&s[1].type==="gfmFootnoteDefinitionIndent"&&s[2].sliceSerialize(s[1],!0).length===4?t(l):n(l)}}function d2(e){let n=(e||{}).singleTilde;const r={name:"strikethrough",tokenize:l,resolveAll:i};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function i(s,o){let u=-1;for(;++u<s.length;)if(s[u][0]==="enter"&&s[u][1].type==="strikethroughSequenceTemporary"&&s[u][1]._close){let d=u;for(;d--;)if(s[d][0]==="exit"&&s[d][1].type==="strikethroughSequenceTemporary"&&s[d][1]._open&&s[u][1].end.offset-s[u][1].start.offset===s[d][1].end.offset-s[d][1].start.offset){s[u][1].type="strikethroughSequence",s[d][1].type="strikethroughSequence";const c={type:"strikethrough",start:Object.assign({},s[d][1].start),end:Object.assign({},s[u][1].end)},f={type:"strikethroughText",start:Object.assign({},s[d][1].end),end:Object.assign({},s[u][1].start)},m=[["enter",c,o],["enter",s[d][1],o],["exit",s[d][1],o],["enter",f,o]],h=o.parser.constructs.insideSpan.null;h&&gt(m,m.length,0,Ns(h,s.slice(d+1,u),o)),gt(m,m.length,0,[["exit",f,o],["enter",s[u][1],o],["exit",s[u][1],o],["exit",c,o]]),gt(s,d-1,u-d+3,m),u=d+m.length-2;break}}for(u=-1;++u<s.length;)s[u][1].type==="strikethroughSequenceTemporary"&&(s[u][1].type="data");return s}function l(s,o,u){const d=this.previous,c=this.events;let f=0;return m;function m(p){return d===126&&c[c.length-1][1].type!=="characterEscape"?u(p):(s.enter("strikethroughSequenceTemporary"),h(p))}function h(p){const x=Ar(d);if(p===126)return f>1?u(p):(s.consume(p),f++,h);if(f<2&&!n)return u(p);const b=s.exit("strikethroughSequenceTemporary"),y=Ar(p);return b._open=!y||y===2&&!!x,b._close=!x||x===2&&!!y,o(p)}}}class f2{constructor(){this.map=[]}add(t,n,r){h2(this,t,n,r)}consume(t){if(this.map.sort(function(l,s){return l[0]-s[0]}),this.map.length===0)return;let n=this.map.length;const r=[];for(;n>0;)n-=1,r.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];r.push(t.slice()),t.length=0;let i=r.pop();for(;i;){for(const l of i)t.push(l);i=r.pop()}this.map.length=0}}function h2(e,t,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i<e.map.length;){if(e.map[i][0]===t){e.map[i][1]+=n,e.map[i][2].push(...r);return}i+=1}e.map.push([t,n,r])}}function m2(e,t){let n=!1;const r=[];for(;t<e.length;){const i=e[t];if(n){if(i[0]==="enter")i[1].type==="tableContent"&&r.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const l=r.length-1;r[l]=r[l]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(n=!0);t+=1}return r}function p2(){return{flow:{null:{name:"table",tokenize:g2,resolveAll:y2}}}}function g2(e,t,n){const r=this;let i=0,l=0,s;return o;function o(k){let j=r.events.length-1;for(;j>-1;){const O=r.events[j][1].type;if(O==="lineEnding"||O==="linePrefix")j--;else break}const P=j>-1?r.events[j][1].type:null,B=P==="tableHead"||P==="tableRow"?E:u;return B===E&&r.parser.lazy[r.now().line]?n(k):B(k)}function u(k){return e.enter("tableHead"),e.enter("tableRow"),d(k)}function d(k){return k===124||(s=!0,l+=1),c(k)}function c(k){return k===null?n(k):K(k)?l>1?(l=0,r.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(k),e.exit("lineEnding"),h):n(k):ue(k)?me(e,c,"whitespace")(k):(l+=1,s&&(s=!1,i+=1),k===124?(e.enter("tableCellDivider"),e.consume(k),e.exit("tableCellDivider"),s=!0,c):(e.enter("data"),f(k)))}function f(k){return k===null||k===124||ke(k)?(e.exit("data"),c(k)):(e.consume(k),k===92?m:f)}function m(k){return k===92||k===124?(e.consume(k),f):f(k)}function h(k){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(k):(e.enter("tableDelimiterRow"),s=!1,ue(k)?me(e,p,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(k):p(k))}function p(k){return k===45||k===58?b(k):k===124?(s=!0,e.enter("tableCellDivider"),e.consume(k),e.exit("tableCellDivider"),x):z(k)}function x(k){return ue(k)?me(e,b,"whitespace")(k):b(k)}function b(k){return k===58?(l+=1,s=!0,e.enter("tableDelimiterMarker"),e.consume(k),e.exit("tableDelimiterMarker"),y):k===45?(l+=1,y(k)):k===null||K(k)?C(k):z(k)}function y(k){return k===45?(e.enter("tableDelimiterFiller"),g(k)):z(k)}function g(k){return k===45?(e.consume(k),g):k===58?(s=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(k),e.exit("tableDelimiterMarker"),v):(e.exit("tableDelimiterFiller"),v(k))}function v(k){return ue(k)?me(e,C,"whitespace")(k):C(k)}function C(k){return k===124?p(k):k===null||K(k)?!s||i!==l?z(k):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(k)):z(k)}function z(k){return n(k)}function E(k){return e.enter("tableRow"),A(k)}function A(k){return k===124?(e.enter("tableCellDivider"),e.consume(k),e.exit("tableCellDivider"),A):k===null||K(k)?(e.exit("tableRow"),t(k)):ue(k)?me(e,A,"whitespace")(k):(e.enter("data"),L(k))}function L(k){return k===null||k===124||ke(k)?(e.exit("data"),A(k)):(e.consume(k),k===92?I:L)}function I(k){return k===92||k===124?(e.consume(k),L):L(k)}}function y2(e,t){let n=-1,r=!0,i=0,l=[0,0,0,0],s=[0,0,0,0],o=!1,u=0,d,c,f;const m=new f2;for(;++n<e.length;){const h=e[n],p=h[1];h[0]==="enter"?p.type==="tableHead"?(o=!1,u!==0&&(hf(m,t,u,d,c),c=void 0,u=0),d={type:"table",start:Object.assign({},p.start),end:Object.assign({},p.end)},m.add(n,0,[["enter",d,t]])):p.type==="tableRow"||p.type==="tableDelimiterRow"?(r=!0,f=void 0,l=[0,0,0,0],s=[0,n+1,0,0],o&&(o=!1,c={type:"tableBody",start:Object.assign({},p.start),end:Object.assign({},p.end)},m.add(n,0,[["enter",c,t]])),i=p.type==="tableDelimiterRow"?2:c?3:1):i&&(p.type==="data"||p.type==="tableDelimiterMarker"||p.type==="tableDelimiterFiller")?(r=!1,s[2]===0&&(l[1]!==0&&(s[0]=s[1],f=cl(m,t,l,i,void 0,f),l=[0,0,0,0]),s[2]=n)):p.type==="tableCellDivider"&&(r?r=!1:(l[1]!==0&&(s[0]=s[1],f=cl(m,t,l,i,void 0,f)),l=s,s=[l[1],n,0,0])):p.type==="tableHead"?(o=!0,u=n):p.type==="tableRow"||p.type==="tableDelimiterRow"?(u=n,l[1]!==0?(s[0]=s[1],f=cl(m,t,l,i,n,f)):s[1]!==0&&(f=cl(m,t,s,i,n,f)),i=0):i&&(p.type==="data"||p.type==="tableDelimiterMarker"||p.type==="tableDelimiterFiller")&&(s[3]=n)}for(u!==0&&hf(m,t,u,d,c),m.consume(t.events),n=-1;++n<t.events.length;){const h=t.events[n];h[0]==="enter"&&h[1].type==="table"&&(h[1]._align=m2(t.events,n))}return e}function cl(e,t,n,r,i,l){const s=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",o="tableContent";n[0]!==0&&(l.end=Object.assign({},nr(t.events,n[0])),e.add(n[0],0,[["exit",l,t]]));const u=nr(t.events,n[1]);if(l={type:s,start:Object.assign({},u),end:Object.assign({},u)},e.add(n[1],0,[["enter",l,t]]),n[2]!==0){const d=nr(t.events,n[2]),c=nr(t.events,n[3]),f={type:o,start:Object.assign({},d),end:Object.assign({},c)};if(e.add(n[2],0,[["enter",f,t]]),r!==2){const m=t.events[n[2]],h=t.events[n[3]];if(m[1].end=Object.assign({},h[1].end),m[1].type="chunkText",m[1].contentType="text",n[3]>n[2]+1){const p=n[2]+1,x=n[3]-n[2]-1;e.add(p,x,[])}}e.add(n[3]+1,0,[["exit",f,t]])}return i!==void 0&&(l.end=Object.assign({},nr(t.events,i)),e.add(i,0,[["exit",l,t]]),l=void 0),l}function hf(e,t,n,r,i){const l=[],s=nr(t.events,n);i&&(i.end=Object.assign({},s),l.push(["exit",i,t])),r.end=Object.assign({},s),l.push(["exit",r,t]),e.add(n+1,0,l)}function nr(e,t){const n=e[t],r=n[0]==="enter"?"start":"end";return n[1][r]}const x2={name:"tasklistCheck",tokenize:k2};function v2(){return{text:{91:x2}}}function k2(e,t,n){const r=this;return i;function i(u){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(u):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(u),e.exit("taskListCheckMarker"),l)}function l(u){return ke(u)?(e.enter("taskListCheckValueUnchecked"),e.consume(u),e.exit("taskListCheckValueUnchecked"),s):u===88||u===120?(e.enter("taskListCheckValueChecked"),e.consume(u),e.exit("taskListCheckValueChecked"),s):n(u)}function s(u){return u===93?(e.enter("taskListCheckMarker"),e.consume(u),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),o):n(u)}function o(u){return K(u)?t(u):ue(u)?e.check({tokenize:w2},t,n)(u):n(u)}}function w2(e,t,n){return me(e,r,"whitespace");function r(i){return i===null?n(i):t(i)}}function b2(e){return sp([qS(),r2(),d2(e),p2(),v2()])}const S2={};function C2(e){const t=this,n=e||S2,r=t.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),l=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),s=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(b2(n)),l.push(HS()),s.push(VS(n))}function j2({message:e,pinned:t,onCopy:n,onDelete:r,onTogglePin:i,onRegenerate:l}){const s=(e.role||"assistant").toLowerCase(),o=e.ts?px(e.ts):"",u=e.content||e.message||"",d=s==="user";return a.jsxs("article",{className:`chat-message ${d?"chat-message-user":"chat-message-assistant"} ${t?"chat-message-pinned":""}`,children:[a.jsxs("header",{className:"chat-message-meta",children:[a.jsx("span",{className:"chat-message-role",children:s}),e.agent&&a.jsxs("span",{className:"chat-message-agent",children:["@",e.agent]}),o&&a.jsx("time",{className:"chat-message-time",children:o}),t&&a.jsx("span",{className:"chat-message-pin",children:"pinned"}),a.jsxs("div",{className:"chat-message-actions",children:[a.jsx("button",{type:"button",className:"chat-msg-action-btn",onClick:n,title:"Copy","aria-label":"Copy",children:a.jsx(X1,{size:12})}),!d&&a.jsx("button",{type:"button",className:"chat-msg-action-btn",onClick:l,title:"Regenerate","aria-label":"Regenerate",children:a.jsx(_t,{size:12})}),a.jsx("button",{type:"button",className:"chat-msg-action-btn",onClick:i,title:"Pin","aria-label":"Pin",children:a.jsx(sx,{size:12})}),a.jsx("button",{type:"button",className:"chat-msg-action-btn chat-msg-action-btn-danger",onClick:r,title:"Delete","aria-label":"Delete",children:a.jsx(_r,{size:12})})]})]}),a.jsx("div",{className:"chat-message-content markdown-body",children:a.jsx(db,{remarkPlugins:[C2],children:u})})]})}function N2({messages:e,loading:t,activeProject:n,sessionId:r,pinned:i,activeSource:l,onPickSuggestion:s,onCopy:o,onDelete:u,onTogglePin:d,onRegenerate:c}){const f=w.useRef(null);w.useEffect(()=>{const h=f.current;if(!h)return;let p=h.parentElement,x=!1;for(;p;){if(p.classList.contains("chat-thread-scroll")){x=!0;break}p=p.parentElement}x||(h.scrollTop=h.scrollHeight)},[e]);const m=l==="opencode"?"opencode":"bizar";return t?a.jsx("div",{className:"chat-thread legacy",ref:f,"data-stream":m,children:a.jsx(Px,{count:3})}):n?e.length===0?a.jsx("div",{className:"chat-thread legacy",ref:f,"data-stream":m,children:a.jsx(yd,{variant:"empty",projectName:n.name,onPickSuggestion:s})}):a.jsx("div",{className:"chat-thread legacy",ref:f,children:a.jsx(Tx,{items:e,itemHeight:120,height:800,className:"chat-thread-virtual",renderItem:(h,p)=>a.jsx(j2,{message:h,pinned:i.has(p),onCopy:()=>o(h),onDelete:()=>u(p),onTogglePin:()=>d(p),onRegenerate:()=>c(String(h.ts??p))})})}):a.jsx("div",{className:"chat-thread legacy",ref:f,"data-stream":m,children:a.jsx(yd,{variant:"no-project",projectName:"",onPickSuggestion:s})})}function E2({agent:e,setAgent:t,agents:n}){const[r,i]=w.useState(!1),l=w.useRef(null);w.useEffect(()=>{if(!r)return;const u=d=>{l.current&&!l.current.contains(d.target)&&i(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[r]);const s=e||"no agent",o=s.startsWith("@")?s.slice(1):s;return a.jsxs("div",{className:"chat-agent-chip",ref:l,children:[a.jsxs("button",{type:"button",className:"chat-agent-chip-btn",onClick:()=>i(u=>!u),"aria-haspopup":"listbox","aria-expanded":r,children:[a.jsx(Dr,{size:14}),a.jsx("span",{children:o}),a.jsx(Ss,{size:12,className:r?"rotated":""})]}),r&&a.jsxs("div",{className:"chat-agent-chip-menu",role:"listbox",children:[a.jsx("button",{type:"button",role:"option","aria-selected":!e,onClick:()=>{t(""),i(!1)},children:a.jsx("span",{children:"no agent"})}),n.map(u=>a.jsx("button",{type:"button",role:"option","aria-selected":e===u.name,onClick:()=>{t(u.name),i(!1)},children:a.jsxs("span",{children:["@",u.name]})},u.name))]})]})}function T2(e,t,n=240){w.useLayoutEffect(()=>{const r=e.current;if(!r)return;r.style.height="auto";const i=Math.min(r.scrollHeight,n);r.style.height=`${i}px`,r.style.overflowY=r.scrollHeight>n?"auto":"hidden"},[e,t,n])}function I2({agent:e,setAgent:t,model:n,setModel:r,text:i,setText:l,sending:s,onSend:o,attachments:u,setAttachments:d,suggestions:c,onPickSuggestion:f,agents:m,onAttach:h}){const p=w.useRef(null),x=w.useRef(null);T2(p,i,200);const b=g=>{if(g.key==="Enter"&&(g.metaKey||g.ctrlKey))g.preventDefault(),o();else if(g.key==="Enter"&&!g.shiftKey)g.preventDefault(),o();else if(g.key==="Tab"&&c.length){g.preventDefault();const v=c[0].cmd.split(" ")[0];l(`${v} `)}},y=g=>{const v=g.target.files;if(!v)return;const C=[];for(let z=0;z<v.length;z++)C.push(v[z].name);d(z=>[...z,...C]),g.target.value=""};return a.jsxs("div",{className:"chat-composer",children:[c.length>0&&a.jsx("div",{className:"chat-composer-suggestions",children:c.map(g=>a.jsxs("button",{type:"button",className:"chat-composer-suggestion",onClick:()=>{var C;const v=g.cmd.split(" ")[0];l(`${v} `),(C=p.current)==null||C.focus()},children:[a.jsx("span",{className:"mono",children:g.cmd}),a.jsx("span",{children:g.desc})]},g.cmd))}),u.length>0&&a.jsx("div",{className:"chat-composer-attachments",children:u.map((g,v)=>a.jsxs("span",{className:"chat-composer-attachment-tag",children:[a.jsx(fd,{size:10})," ",g,a.jsx("button",{type:"button",className:"chat-composer-attachment-remove",onClick:()=>d(C=>C.filter((z,E)=>E!==v)),"aria-label":`Remove ${g}`,children:a.jsx(Zn,{size:10})})]},v))}),a.jsxs("div",{className:"chat-composer-input",children:[a.jsx(E2,{agent:e,setAgent:t,agents:m}),a.jsx("textarea",{ref:p,className:"chat-composer-textarea",placeholder:s?"Sending…":"Send a message…",rows:1,value:i,onChange:g=>l(g.target.value),onKeyDown:b,disabled:s,"aria-label":"Message"}),a.jsx("input",{ref:x,type:"file",multiple:!0,style:{display:"none"},onChange:y}),a.jsx("button",{type:"button",className:"chat-attach-btn",onClick:h,title:"Attach files","aria-label":"Attach files",children:a.jsx(fd,{size:14})}),a.jsx("button",{type:"button",className:"chat-attach-btn",onClick:async()=>{if(!i.trim())return;const g=await xx(i);g!==i&&l(g)},title:"Enhance prompt with AI","aria-label":"Enhance prompt",children:a.jsx(Jl,{size:14})}),a.jsx("button",{type:"button",className:"chat-send-btn",onClick:o,disabled:s||!i.trim(),title:"Send (Enter)","aria-label":"Send message",children:a.jsx($m,{size:16})})]})]})}const z2="modulepreload",P2=function(e){return"/"+e},mf={},A2=function(t,n,r){let i=Promise.resolve();if(n&&n.length>0){document.getElementsByTagName("link");const s=document.querySelector("meta[property=csp-nonce]"),o=(s==null?void 0:s.nonce)||(s==null?void 0:s.getAttribute("nonce"));i=Promise.allSettled(n.map(u=>{if(u=P2(u),u in mf)return;mf[u]=!0;const d=u.endsWith(".css"),c=d?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${u}"]${c}`))return;const f=document.createElement("link");if(f.rel=d?"stylesheet":z2,d||(f.as="script"),f.crossOrigin="",f.href=u,o&&f.setAttribute("nonce",o),document.head.appendChild(f),d)return new Promise((m,h)=>{f.addEventListener("load",m),f.addEventListener("error",()=>h(new Error(`Unable to preload CSS for ${u}`)))})}))}function l(s){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=s,window.dispatchEvent(o),!o.defaultPrevented)throw s}return i.then(s=>{for(const o of s||[])o.status==="rejected"&&l(o.reason);return t().catch(l)})};function M2(e,t,n){const[r,i]=w.useState([]),[l,s]=w.useState([]),[o,u]=w.useState(""),[d,c]=w.useState(!0),[f,m]=w.useState({create:!1,send:!1,rename:!1,delete:!1}),[h,p]=w.useState([]),[x,b]=w.useState([]),[y,g]=w.useState(null),[v,C]=w.useState(null),[z,E]=w.useState(null),[A,L]=w.useState({}),[I,k]=w.useState(!0),[j,P]=w.useState(0),[B,O]=w.useState(new Set),[W,de]=w.useState(new Set),ee=w.useRef(null),R=w.useRef(null),V=w.useRef(null),S=w.useRef(0),Y=w.useRef(null),ie=w.useRef(null),N=w.useRef(!1),ge=w.useCallback(T=>{T&&b(D=>{if(T.id&&D.some(U=>U.id===T.id))return D;const _=D.findIndex(U=>typeof U.id=="string"&&U.id.startsWith("msg_")&&U.role===T.role&&(U.content||"")===(T.content||""));if(_>=0){const U=D.slice();return U[_]={...T,id:T.id??D[_].id},U}return[...D,T]})},[]),Le=w.useCallback(T=>{T&&O(D=>{if(D.has(T))return D;const _=new Set(D);return _.add(T),_})},[]),oe=w.useCallback((T,D)=>{L(_=>{const U=_[T]??{state:"idle",unread:0,pinned:!1};return{..._,[T]:{...U,...D}}})},[]),Ne=w.useCallback((T,D)=>{oe(T,{state:D?"streaming":"idle"})},[oe]),H=w.useCallback(T=>{R.current=T},[]),te=w.useCallback(async T=>{var D;try{const _=T?`/chat?session=${encodeURIComponent(T)}`:"/chat?limit=200",U=await q.get(_);i(U.messages||[]),s(U.sessions||[])}catch(_){(D=R.current)==null||D.error(`Chat load failed: ${_.message}`)}finally{c(!1)}},[]),re=w.useCallback(async T=>{var D;c(!0);try{const _=await q.get(`/tasks/${encodeURIComponent(T)}/chat`);i(_.messages||[]),u(_.sessionId||T)}catch(_){(D=R.current)==null||D.error(`Task chat load failed: ${_.message}`)}finally{c(!1)}},[]),Se=w.useCallback(async()=>{try{const T=await q.get("/chat/sessions");s(T.sessions||[])}catch{}},[]),Ot=w.useCallback(async()=>{try{const D=((await q.get("/opencode-sessions")).sessions||[]).map(_=>({..._,source:"opencode",title:_.title||_.id}));p(D)}catch{}},[]),ln=w.useCallback(T=>{if(V.current){try{V.current.close()}catch{}V.current=null}Y.current!==null&&(clearTimeout(Y.current),Y.current=null);const D=q.getToken(),_=D?`/api/opencode-sessions/${encodeURIComponent(T)}/stream?token=${encodeURIComponent(D)}`:`/api/opencode-sessions/${encodeURIComponent(T)}/stream`;ie.current=T,N.current=!0,S.current=0,E(null);const U=()=>{if(!N.current||ie.current!==T)return;const G=new EventSource(_);V.current=G;const le=X=>{var he,nt,dt,Qt;if(!X||!X.type||X.sessionID&&X.sessionID!==T)return;const Z=new Date().toISOString(),fe=T;if(X.type==="message.user.created"||X.type==="message.user.updated"){const se=X.data;ge({id:(se==null?void 0:se.messageID)??X.messageID,role:"user",content:((he=se==null?void 0:se.data)==null?void 0:he.content)??"",ts:Z}),Le((se==null?void 0:se.messageID)??X.messageID);return}if(X.type==="message.assistant.created"||X.type==="message.assistant.updated"){const se=X.data;ge({id:(se==null?void 0:se.messageID)??X.messageID,role:"assistant",content:((nt=se==null?void 0:se.data)==null?void 0:nt.content)??"",ts:Z}),Le((se==null?void 0:se.messageID)??X.messageID),Ne(fe,!0);return}if(X.type==="message.part.updated"){const se=X.data,ec=((dt=se==null?void 0:se.part)==null?void 0:dt.text)??"";if(!ec)return;ge({id:(se==null?void 0:se.id)??(se==null?void 0:se.messageID)??X.messageID,role:"assistant",content:ec,ts:Z}),Le((se==null?void 0:se.id)??(se==null?void 0:se.messageID)??X.messageID),Ne(fe,!0);return}if(X.type==="session.idle"||X.type==="message.assistant.completed"||X.type==="session.completed"){Ne(fe,!1);return}if(X.type==="session.awaiting"||X.type==="session.awaiting_input"||X.type==="message.assistant.awaiting"){oe(fe,{state:"awaiting"});return}if(X.type==="session.error"){E(((Qt=X.data)==null?void 0:Qt.message)||"opencode session error");return}},xe=X=>{if(!X)return null;try{const Z=JSON.parse(X);if(typeof Z.type=="string"){const fe=Z.properties,he=Z.data??fe,nt=typeof Z.sessionID=="string"?Z.sessionID:typeof(fe==null?void 0:fe.sessionID)=="string"?fe.sessionID:typeof(he==null?void 0:he.sessionID)=="string"?he.sessionID:void 0,dt=typeof Z.messageID=="string"?Z.messageID:typeof(fe==null?void 0:fe.messageID)=="string"?fe.messageID:typeof(he==null?void 0:he.messageID)=="string"?he.messageID:void 0;let Qt=Z.type;const se=/\.\d+$/.exec(Qt);return se&&(Qt=Qt.slice(0,se.index)),{type:Qt,sessionID:nt,messageID:dt,data:Z}}if(Z.type==="sync"&&Z.syncEvent&&typeof Z.syncEvent=="object"){const fe=Z.syncEvent;let he=fe.type||"";const nt=/\.\d+$/.exec(he);nt&&(he=he.slice(0,nt.index));const dt=fe.data||{};return{type:he,sessionID:typeof dt.sessionID=="string"?dt.sessionID:void 0,messageID:typeof dt.messageID=="string"?dt.messageID:void 0,data:fe}}return null}catch{return null}},we=["message.user.created","message.user.updated","message.assistant.created","message.assistant.updated","message.part.updated","session.idle","message.assistant.completed","session.completed","session.awaiting","session.awaiting_input","message.assistant.awaiting","session.error"];for(const X of we)G.addEventListener(X,Z=>{le(xe(Z.data))});G.onerror=()=>{if(ie.current!==T)return;if(!N.current){try{G.close()}catch{}V.current=null;return}try{G.close()}catch{}V.current=null;const X=S.current+1;S.current=X;const Z=Math.min(3e4,1e3*2**(X-1));Y.current!==null&&clearTimeout(Y.current),Y.current=window.setTimeout(()=>{Y.current=null,N.current&&ie.current===T&&U()},Z)},G.onopen=()=>{S.current=0,E(null)}};U()},[ge,Le,Ne,oe]),In=w.useCallback(()=>{if(N.current=!1,ie.current=null,Y.current!==null&&(clearTimeout(Y.current),Y.current=null),V.current){try{V.current.close()}catch{}V.current=null}b([]),O(new Set),E(null),C(null),g("bizar")},[]),er=w.useCallback(async T=>{var D;if(N.current=!1,V.current){try{V.current.close()}catch{}V.current=null}Y.current!==null&&(clearTimeout(Y.current),Y.current=null),E(null),c(!0);try{const _=await q.get(`/opencode-sessions/${encodeURIComponent(T)}/messages`);b(_.messages||[])}catch(_){const U=_.message;(D=R.current)==null||D.error(`Opencode session load failed: ${U}`),b([])}finally{c(!1)}C(T),g("opencode"),Ne(T,!1),ln(T)},[Ne,ln]),$i=w.useCallback(T=>{In(),u(T),g("bizar"),te(T),oe(T,{unread:0})},[In,te,oe]),Bi=w.useCallback(async()=>{var D,_,U,G,le;if(f.create)return{ok:!1};const T=t.defaultAgent||"odin";m(xe=>({...xe,create:!0}));try{try{const we=await q.post("/opencode-sessions/new",{agent:T});return await Ot(),await er(we.id),(D=R.current)==null||D.success(`Session ${we.id} created.`),{ok:!0,source:"opencode",id:we.id}}catch(we){if(!(we instanceof wa)||we.status!==503)return(_=R.current)==null||_.error(`Create failed: ${we.message}`),{ok:!1}}if(!e.activeProject)return(U=R.current)==null||U.error("Pick a project in Overview to scope chat sessions."),{ok:!1};const xe=await q.post("/chat/sessions",{});return u(xe.id),i([]),de(new Set),oe(xe.id,{state:"idle",unread:0}),await te(xe.id),Se().catch(()=>{}),(G=R.current)==null||G.success(`Session ${xe.id} created.`),{ok:!0,source:"bizar",id:xe.id}}catch(xe){return(le=R.current)==null||le.error(`Create failed: ${xe.message}`),{ok:!1}}finally{m(xe=>({...xe,create:!1}))}},[f.create,t.defaultAgent,e.activeProject,Ot,er,te,Se,oe]),zs=w.useCallback(async(T,D,_,U)=>{var xe,we,X;if(f.send)return{ok:!1};const G=T.trim();if(!G)return{ok:!1};if(y==="opencode"&&v){const Z=v,fe=`msg_${Date.now().toString(36)}${Math.random().toString(36).slice(2,8)}`,he={id:fe,role:"user",content:G,agent:D,ts:new Date().toISOString()};ge(he),Le(fe),m(nt=>({...nt,send:!0}));try{return await q.post(`/opencode-sessions/${encodeURIComponent(Z)}/send`,{message:G,agent:D}),Ne(Z,!0),{ok:!0}}catch(nt){return b(dt=>dt.filter(Qt=>Qt.id!==fe)),(xe=R.current)==null||xe.error(`Send failed: ${nt.message}`),{ok:!1}}finally{m(nt=>({...nt,send:!1}))}}const le={role:"user",content:G,agent:D,ts:new Date().toISOString()};i(Z=>[...Z,le]),m(Z=>({...Z,send:!0})),Ne(o,!0);try{const Z=await q.post("/chat",{message:G,agent:D,model:_,attachments:U||[]});if(Z!=null&&Z.messages)for(const fe of Z.messages)fe.role==="assistant"&&i(he=>he.some(dt=>dt.ts===fe.ts)?he:[...he,fe]);else(we=R.current)==null||we.info("Still processing… the response will appear shortly.");return{ok:!0}}catch(Z){return i(fe=>fe.filter(he=>he!==le)),(X=R.current)==null||X.error(`Send failed: ${Z.message}`),{ok:!1}}finally{m(Z=>({...Z,send:!1})),Ne(o,!1)}},[y,v,ge,Le,Ne,o,f.send]),Ui=w.useCallback(async T=>{var D,_;if(!o){(D=R.current)==null||D.error("No active session to regenerate.");return}try{await q.post("/chat/regenerate",{sessionId:o,messageId:T}),await te(o)}catch(U){(_=R.current)==null||_.error(`Regenerate failed: ${U.message}`)}},[o,te]),Hi=w.useCallback(T=>{y==="opencode"?b(D=>D.filter((_,U)=>U!==T)):i(D=>D.filter((_,U)=>U!==T))},[y]),Ps=w.useCallback(T=>{de(D=>{const _=new Set(D);return _.has(T)?_.delete(T):_.add(T),_})},[]),As=w.useCallback(T=>{var _,U;const D=T.content||T.message||"";try{(_=navigator.clipboard)==null||_.writeText(D).then(()=>{var G;return(G=R.current)==null?void 0:G.success("Copied.")},()=>{var G;return(G=R.current)==null?void 0:G.error("Copy failed.")})}catch{(U=R.current)==null||U.error("Copy failed.")}},[]),Ms=w.useCallback(()=>{const T=ee.current;if(!T)return;const _=T.scrollHeight-T.scrollTop-T.clientHeight<32;k(_),_&&P(0)},[]),Ls=w.useCallback(()=>{const T=ee.current;T&&(T.scrollTop=T.scrollHeight,k(!0),P(0))},[]),Rs=w.useCallback(async(T,D)=>{var _,U,G;if(f.rename)return!1;m(le=>({...le,rename:!0}));try{const le=D.trim();return le?(h.some(we=>we.id===T)?(await q.patch(`/opencode-sessions/${encodeURIComponent(T)}`,{title:le}),p(we=>we.map(X=>X.id===T?{...X,title:le}:X))):(await q.post(`/chat/sessions/${encodeURIComponent(T)}/rename`,{title:le}),s(we=>we.map(X=>X.id===T?{...X,title:le}:X))),(U=R.current)==null||U.success("Renamed."),!0):((_=R.current)==null||_.error("Title cannot be empty."),!1)}catch(le){return(G=R.current)==null||G.error(`Rename failed: ${le.message}`),!1}finally{m(le=>({...le,rename:!1}))}},[f.rename,h]),M=w.useCallback(async T=>{var D,_;if(f.delete)return!1;m(U=>({...U,delete:!0}));try{return h.some(G=>G.id===T)?(await q.del(`/opencode-sessions/${encodeURIComponent(T)}`),p(G=>G.filter(le=>le.id!==T)),v===T&&In()):(await q.del(`/chat/sessions/${encodeURIComponent(T)}`),s(G=>G.filter(le=>le.id!==T)),o===T&&(u(""),i([]))),L(G=>{const le={...G};return delete le[T],le}),(D=R.current)==null||D.success("Session deleted."),!0}catch(U){return(_=R.current)==null||_.error(`Delete failed: ${U.message}`),!1}finally{m(U=>({...U,delete:!1}))}},[f.delete,h,v,In,o]);return w.useEffect(()=>{ee.current&&(I?ee.current.scrollTop=ee.current.scrollHeight:P(T=>T+1))},[r,x]),w.useEffect(()=>()=>{if(N.current=!1,ie.current=null,Y.current!==null&&(clearTimeout(Y.current),Y.current=null),V.current){try{V.current.close()}catch{}V.current=null}},[]),w.useEffect(()=>{n?re(n):te(),Ot()},[]),w.useEffect(()=>{const T=D=>{var U;const _=(U=D.detail)==null?void 0:U.taskId;_&&re(_)};return window.addEventListener("bizar:setChatTask",T),()=>window.removeEventListener("bizar:setChatTask",T)},[re]),w.useEffect(()=>{let T=!1;return A2(async()=>{const{Ws:D}=await Promise.resolve().then(()=>Ex);return{Ws:D}},void 0).then(({Ws:D})=>{if(T)return;new D().on(U=>{if(U.type!=="chat:message")return;const G=U.message;G&&i(le=>le.some(we=>we.ts===G.ts)?le:[...le,G])})}),()=>{T=!0}},[]),{messages:y==="opencode"?x:r,bizarMessages:r,opencodeMessages:x,sessions:l,opencodeSessions:h,sessionId:o,setSessionId:u,loading:d,sending:f.send,pinned:W,listRef:ee,activeSource:y,activeOpencodeSessionId:v,opencodeError:z,sessionStates:A,busy:f,getSessionDisplay:T=>{var D,_,U,G;return{...T,state:((D=A[T.id])==null?void 0:D.state)??"idle",unread:((_=A[T.id])==null?void 0:_.unread)??0,pinned:((U=A[T.id])==null?void 0:U.pinned)??!1,tree:(G=A[T.id])==null?void 0:G.tree}},stickToBottom:I,newMessageCount:j,handleScroll:Ms,jumpToLatest:Ls,setToast:H,loadChat:te,loadTaskChat:re,refreshSessions:Se,refreshOpencodeSessions:Ot,loadOpencodeSession:er,closeOpencodeSession:In,selectBizarSession:$i,onCreateSession:Bi,onSend:zs,onRegenerate:Ui,deleteMessage:Hi,togglePin:Ps,copyMessage:As,renameSession:Rs,deleteSession:M,seenOpencodeMessages:B}}const L2=[{cmd:"/visual-plan [on|off|status]",desc:"Toggle or view visual plan mode"},{cmd:"/plan new <slug> [template]",desc:"Create a new plan"},{cmd:"/plan list",desc:"List all plans"},{cmd:"/plan open <slug>",desc:"Open a plan in the viewer"},{cmd:"/plan status <slug> <status>",desc:"Set plan status"},{cmd:"/plan get <slug>",desc:"Fetch plan canvas"},{cmd:"/plan add <slug> --title T --type kind",desc:"Add element to a plan"},{cmd:"/plan update <slug> <id>",desc:"Update a plan element"},{cmd:"/plan delete <slug> <id>",desc:"Delete a plan element"},{cmd:'/plan comment <slug> [id] "text"',desc:"Add a comment"},{cmd:"/plan comments <slug> [id]",desc:"Read plan comments"},{cmd:"/bizar",desc:"Launch Bizar dashboard"},{cmd:"/bizar <args>",desc:"Route via Bizar menu"},{cmd:"/audit",desc:"Run security audit"},{cmd:"/explain <q>",desc:"Read-only code Q&A"},{cmd:"/init",desc:"Initialize .bizar/ in this project"},{cmd:"/learn",desc:"Extract patterns from session"},{cmd:"/pr-review",desc:"PR review"},{cmd:"/help | /commands",desc:"Show all Bizar commands"}];function R2(e){const[t,n]=w.useState(""),r=w.useMemo(()=>[...L2,...(e.mods||[]).flatMap(l=>{var s;return(s=l.entry)!=null&&s.command?[{cmd:`/${l.id}`,desc:l.description||l.name,mod:l.id}]:[]})],[e.mods]),i=w.useMemo(()=>{if(!t.startsWith("/")||t.includes(" "))return[];const l=t.toLowerCase();return r.filter(s=>s.cmd.toLowerCase().startsWith(l)).slice(0,6)},[t,r]);return{allCommands:r,suggestions:i,setQuery:n}}var D2=Object.defineProperty,ss=Object.getOwnPropertySymbols,Xp=Object.prototype.hasOwnProperty,Zp=Object.prototype.propertyIsEnumerable,pf=(e,t,n)=>t in e?D2(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,La=(e,t)=>{for(var n in t||(t={}))Xp.call(t,n)&&pf(e,n,t[n]);if(ss)for(var n of ss(t))Zp.call(t,n)&&pf(e,n,t[n]);return e},Ra=(e,t)=>{var n={};for(var r in e)Xp.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&ss)for(var r of ss(e))t.indexOf(r)<0&&Zp.call(e,r)&&(n[r]=e[r]);return n};/**
343
+ `))}function u(h,p,x,b){const y=x.enter("tableCell"),g=x.enter("phrasing"),v=x.containerPhrasing(h,{...b,before:l,after:l});return g(),y(),v}function d(h,p){return Zb(h,{align:p,alignDelimiters:r,padding:n,stringLength:i})}function c(h,p,x){const b=h.children;let y=-1;const g=[],v=p.enter("table");for(;++y<b.length;)g[y]=f(b[y],p,x);return v(),g}function f(h,p,x){const b=h.children;let y=-1;const g=[],v=p.enter("tableRow");for(;++y<b.length;)g[y]=u(b[y],h,p,x);return v(),g}function m(h,p,x){let b=Up.inlineCode(h,p,x);return x.stack.includes("tableCell")&&(b=b.replace(/\|/g,"\\$&")),b}}function FS(){return{exit:{taskListCheckValueChecked:ff,taskListCheckValueUnchecked:ff,paragraph:BS}}}function $S(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:US}}}function ff(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function BS(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const r=n.children[0];if(r&&r.type==="text"){const i=t.children;let l=-1,s;for(;++l<i.length;){const o=i[l];if(o.type==="paragraph"){s=o;break}}s===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start=Object.assign({},r.position.start)))}}this.exit(e)}function US(e,t,n,r){const i=e.children[0],l=typeof e.checked=="boolean"&&i&&i.type==="paragraph",s="["+(e.checked?"x":" ")+"] ",o=n.createTracker(r);l&&o.move(s);let u=Up.listItem(e,t,n,{...r,...o.current()});return l&&(u=u.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,d)),u;function d(c){return c+s}}function HS(){return[wb(),Ub(),Qb(),AS(),FS()]}function VS(e){return{extensions:[bb(),Hb(e),qb(),OS(e),$S()]}}const WS={tokenize:XS,partial:!0},Hp={tokenize:ZS,partial:!0},Vp={tokenize:JS,partial:!0},Wp={tokenize:e2,partial:!0},QS={tokenize:t2,partial:!0},Qp={name:"wwwAutolink",tokenize:KS,previous:Yp},qp={name:"protocolAutolink",tokenize:GS,previous:Kp},rn={name:"emailAutolink",tokenize:YS,previous:Gp},Wt={};function qS(){return{text:Wt}}let zn=48;for(;zn<123;)Wt[zn]=rn,zn++,zn===58?zn=65:zn===91&&(zn=97);Wt[43]=rn;Wt[45]=rn;Wt[46]=rn;Wt[95]=rn;Wt[72]=[rn,qp];Wt[104]=[rn,qp];Wt[87]=[rn,Qp];Wt[119]=[rn,Qp];function YS(e,t,n){const r=this;let i,l;return s;function s(f){return!Ma(f)||!Gp.call(r,r.previous)||Zu(r.events)?n(f):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),o(f))}function o(f){return Ma(f)?(e.consume(f),o):f===64?(e.consume(f),u):n(f)}function u(f){return f===46?e.check(QS,c,d)(f):f===45||f===95||Ye(f)?(l=!0,e.consume(f),u):c(f)}function d(f){return e.consume(f),i=!0,u}function c(f){return l&&i&&Ze(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(f)):n(f)}}function KS(e,t,n){const r=this;return i;function i(s){return s!==87&&s!==119||!Yp.call(r,r.previous)||Zu(r.events)?n(s):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(WS,e.attempt(Hp,e.attempt(Vp,l),n),n)(s))}function l(s){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(s)}}function GS(e,t,n){const r=this;let i="",l=!1;return s;function s(f){return(f===72||f===104)&&Kp.call(r,r.previous)&&!Zu(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(f),e.consume(f),o):n(f)}function o(f){if(Ze(f)&&i.length<5)return i+=String.fromCodePoint(f),e.consume(f),o;if(f===58){const m=i.toLowerCase();if(m==="http"||m==="https")return e.consume(f),u}return n(f)}function u(f){return f===47?(e.consume(f),l?d:(l=!0,u)):n(f)}function d(f){return f===null||ns(f)||ke(f)||Yn(f)||js(f)?n(f):e.attempt(Hp,e.attempt(Vp,c),n)(f)}function c(f){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(f)}}function XS(e,t,n){let r=0;return i;function i(s){return(s===87||s===119)&&r<3?(r++,e.consume(s),i):s===46&&r===3?(e.consume(s),l):n(s)}function l(s){return s===null?n(s):t(s)}}function ZS(e,t,n){let r,i,l;return s;function s(d){return d===46||d===95?e.check(Wp,u,o)(d):d===null||ke(d)||Yn(d)||d!==45&&js(d)?u(d):(l=!0,e.consume(d),s)}function o(d){return d===95?r=!0:(i=r,r=void 0),e.consume(d),s}function u(d){return i||r||!l?n(d):t(d)}}function JS(e,t){let n=0,r=0;return i;function i(s){return s===40?(n++,e.consume(s),i):s===41&&r<n?l(s):s===33||s===34||s===38||s===39||s===41||s===42||s===44||s===46||s===58||s===59||s===60||s===63||s===93||s===95||s===126?e.check(Wp,t,l)(s):s===null||ke(s)||Yn(s)?t(s):(e.consume(s),i)}function l(s){return s===41&&r++,e.consume(s),i}}function e2(e,t,n){return r;function r(o){return o===33||o===34||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===63||o===95||o===126?(e.consume(o),r):o===38?(e.consume(o),l):o===93?(e.consume(o),i):o===60||o===null||ke(o)||Yn(o)?t(o):n(o)}function i(o){return o===null||o===40||o===91||ke(o)||Yn(o)?t(o):r(o)}function l(o){return Ze(o)?s(o):n(o)}function s(o){return o===59?(e.consume(o),r):Ze(o)?(e.consume(o),s):n(o)}}function t2(e,t,n){return r;function r(l){return e.consume(l),i}function i(l){return Ye(l)?n(l):t(l)}}function Yp(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||ke(e)}function Kp(e){return!Ze(e)}function Gp(e){return!(e===47||Ma(e))}function Ma(e){return e===43||e===45||e===46||e===95||Ye(e)}function Zu(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const n2={tokenize:c2,partial:!0};function r2(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:o2,continuation:{tokenize:a2},exit:u2}},text:{91:{name:"gfmFootnoteCall",tokenize:s2},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:i2,resolveTo:l2}}}}function i2(e,t,n){const r=this;let i=r.events.length;const l=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s;for(;i--;){const u=r.events[i][1];if(u.type==="labelImage"){s=u;break}if(u.type==="gfmFootnoteCall"||u.type==="labelLink"||u.type==="label"||u.type==="image"||u.type==="link")break}return o;function o(u){if(!s||!s._balanced)return n(u);const d=Lt(r.sliceSerialize({start:s.end,end:r.now()}));return d.codePointAt(0)!==94||!l.includes(d.slice(1))?n(u):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(u),e.exit("gfmFootnoteCallLabelMarker"),t(u))}}function l2(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;const l={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},s={type:"chunkString",contentType:"string",start:Object.assign({},l.start),end:Object.assign({},l.end)},o=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",i,t],["exit",i,t],["enter",l,t],["enter",s,t],["exit",s,t],["exit",l,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...o),e}function s2(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let l=0,s;return o;function o(f){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),u}function u(f){return f!==94?n(f):(e.enter("gfmFootnoteCallMarker"),e.consume(f),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",d)}function d(f){if(l>999||f===93&&!s||f===null||f===91||ke(f))return n(f);if(f===93){e.exit("chunkString");const m=e.exit("gfmFootnoteCallString");return i.includes(Lt(r.sliceSerialize(m)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(f)}return ke(f)||(s=!0),l++,e.consume(f),f===92?c:d}function c(f){return f===91||f===92||f===93?(e.consume(f),l++,d):d(f)}}function o2(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let l,s=0,o;return u;function u(p){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(p),e.exit("gfmFootnoteDefinitionLabelMarker"),d}function d(p){return p===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(p),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",c):n(p)}function c(p){if(s>999||p===93&&!o||p===null||p===91||ke(p))return n(p);if(p===93){e.exit("chunkString");const x=e.exit("gfmFootnoteDefinitionLabelString");return l=Lt(r.sliceSerialize(x)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(p),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),m}return ke(p)||(o=!0),s++,e.consume(p),p===92?f:c}function f(p){return p===91||p===92||p===93?(e.consume(p),s++,c):c(p)}function m(p){return p===58?(e.enter("definitionMarker"),e.consume(p),e.exit("definitionMarker"),i.includes(l)||i.push(l),me(e,h,"gfmFootnoteDefinitionWhitespace")):n(p)}function h(p){return t(p)}}function a2(e,t,n){return e.check(Oi,t,e.attempt(n2,t,n))}function u2(e){e.exit("gfmFootnoteDefinition")}function c2(e,t,n){const r=this;return me(e,i,"gfmFootnoteDefinitionIndent",5);function i(l){const s=r.events[r.events.length-1];return s&&s[1].type==="gfmFootnoteDefinitionIndent"&&s[2].sliceSerialize(s[1],!0).length===4?t(l):n(l)}}function d2(e){let n=(e||{}).singleTilde;const r={name:"strikethrough",tokenize:l,resolveAll:i};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function i(s,o){let u=-1;for(;++u<s.length;)if(s[u][0]==="enter"&&s[u][1].type==="strikethroughSequenceTemporary"&&s[u][1]._close){let d=u;for(;d--;)if(s[d][0]==="exit"&&s[d][1].type==="strikethroughSequenceTemporary"&&s[d][1]._open&&s[u][1].end.offset-s[u][1].start.offset===s[d][1].end.offset-s[d][1].start.offset){s[u][1].type="strikethroughSequence",s[d][1].type="strikethroughSequence";const c={type:"strikethrough",start:Object.assign({},s[d][1].start),end:Object.assign({},s[u][1].end)},f={type:"strikethroughText",start:Object.assign({},s[d][1].end),end:Object.assign({},s[u][1].start)},m=[["enter",c,o],["enter",s[d][1],o],["exit",s[d][1],o],["enter",f,o]],h=o.parser.constructs.insideSpan.null;h&&gt(m,m.length,0,Ns(h,s.slice(d+1,u),o)),gt(m,m.length,0,[["exit",f,o],["enter",s[u][1],o],["exit",s[u][1],o],["exit",c,o]]),gt(s,d-1,u-d+3,m),u=d+m.length-2;break}}for(u=-1;++u<s.length;)s[u][1].type==="strikethroughSequenceTemporary"&&(s[u][1].type="data");return s}function l(s,o,u){const d=this.previous,c=this.events;let f=0;return m;function m(p){return d===126&&c[c.length-1][1].type!=="characterEscape"?u(p):(s.enter("strikethroughSequenceTemporary"),h(p))}function h(p){const x=Ar(d);if(p===126)return f>1?u(p):(s.consume(p),f++,h);if(f<2&&!n)return u(p);const b=s.exit("strikethroughSequenceTemporary"),y=Ar(p);return b._open=!y||y===2&&!!x,b._close=!x||x===2&&!!y,o(p)}}}class f2{constructor(){this.map=[]}add(t,n,r){h2(this,t,n,r)}consume(t){if(this.map.sort(function(l,s){return l[0]-s[0]}),this.map.length===0)return;let n=this.map.length;const r=[];for(;n>0;)n-=1,r.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];r.push(t.slice()),t.length=0;let i=r.pop();for(;i;){for(const l of i)t.push(l);i=r.pop()}this.map.length=0}}function h2(e,t,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i<e.map.length;){if(e.map[i][0]===t){e.map[i][1]+=n,e.map[i][2].push(...r);return}i+=1}e.map.push([t,n,r])}}function m2(e,t){let n=!1;const r=[];for(;t<e.length;){const i=e[t];if(n){if(i[0]==="enter")i[1].type==="tableContent"&&r.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const l=r.length-1;r[l]=r[l]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(n=!0);t+=1}return r}function p2(){return{flow:{null:{name:"table",tokenize:g2,resolveAll:y2}}}}function g2(e,t,n){const r=this;let i=0,l=0,s;return o;function o(k){let j=r.events.length-1;for(;j>-1;){const O=r.events[j][1].type;if(O==="lineEnding"||O==="linePrefix")j--;else break}const P=j>-1?r.events[j][1].type:null,B=P==="tableHead"||P==="tableRow"?E:u;return B===E&&r.parser.lazy[r.now().line]?n(k):B(k)}function u(k){return e.enter("tableHead"),e.enter("tableRow"),d(k)}function d(k){return k===124||(s=!0,l+=1),c(k)}function c(k){return k===null?n(k):K(k)?l>1?(l=0,r.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(k),e.exit("lineEnding"),h):n(k):ue(k)?me(e,c,"whitespace")(k):(l+=1,s&&(s=!1,i+=1),k===124?(e.enter("tableCellDivider"),e.consume(k),e.exit("tableCellDivider"),s=!0,c):(e.enter("data"),f(k)))}function f(k){return k===null||k===124||ke(k)?(e.exit("data"),c(k)):(e.consume(k),k===92?m:f)}function m(k){return k===92||k===124?(e.consume(k),f):f(k)}function h(k){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(k):(e.enter("tableDelimiterRow"),s=!1,ue(k)?me(e,p,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(k):p(k))}function p(k){return k===45||k===58?b(k):k===124?(s=!0,e.enter("tableCellDivider"),e.consume(k),e.exit("tableCellDivider"),x):z(k)}function x(k){return ue(k)?me(e,b,"whitespace")(k):b(k)}function b(k){return k===58?(l+=1,s=!0,e.enter("tableDelimiterMarker"),e.consume(k),e.exit("tableDelimiterMarker"),y):k===45?(l+=1,y(k)):k===null||K(k)?C(k):z(k)}function y(k){return k===45?(e.enter("tableDelimiterFiller"),g(k)):z(k)}function g(k){return k===45?(e.consume(k),g):k===58?(s=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(k),e.exit("tableDelimiterMarker"),v):(e.exit("tableDelimiterFiller"),v(k))}function v(k){return ue(k)?me(e,C,"whitespace")(k):C(k)}function C(k){return k===124?p(k):k===null||K(k)?!s||i!==l?z(k):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(k)):z(k)}function z(k){return n(k)}function E(k){return e.enter("tableRow"),A(k)}function A(k){return k===124?(e.enter("tableCellDivider"),e.consume(k),e.exit("tableCellDivider"),A):k===null||K(k)?(e.exit("tableRow"),t(k)):ue(k)?me(e,A,"whitespace")(k):(e.enter("data"),L(k))}function L(k){return k===null||k===124||ke(k)?(e.exit("data"),A(k)):(e.consume(k),k===92?I:L)}function I(k){return k===92||k===124?(e.consume(k),L):L(k)}}function y2(e,t){let n=-1,r=!0,i=0,l=[0,0,0,0],s=[0,0,0,0],o=!1,u=0,d,c,f;const m=new f2;for(;++n<e.length;){const h=e[n],p=h[1];h[0]==="enter"?p.type==="tableHead"?(o=!1,u!==0&&(hf(m,t,u,d,c),c=void 0,u=0),d={type:"table",start:Object.assign({},p.start),end:Object.assign({},p.end)},m.add(n,0,[["enter",d,t]])):p.type==="tableRow"||p.type==="tableDelimiterRow"?(r=!0,f=void 0,l=[0,0,0,0],s=[0,n+1,0,0],o&&(o=!1,c={type:"tableBody",start:Object.assign({},p.start),end:Object.assign({},p.end)},m.add(n,0,[["enter",c,t]])),i=p.type==="tableDelimiterRow"?2:c?3:1):i&&(p.type==="data"||p.type==="tableDelimiterMarker"||p.type==="tableDelimiterFiller")?(r=!1,s[2]===0&&(l[1]!==0&&(s[0]=s[1],f=cl(m,t,l,i,void 0,f),l=[0,0,0,0]),s[2]=n)):p.type==="tableCellDivider"&&(r?r=!1:(l[1]!==0&&(s[0]=s[1],f=cl(m,t,l,i,void 0,f)),l=s,s=[l[1],n,0,0])):p.type==="tableHead"?(o=!0,u=n):p.type==="tableRow"||p.type==="tableDelimiterRow"?(u=n,l[1]!==0?(s[0]=s[1],f=cl(m,t,l,i,n,f)):s[1]!==0&&(f=cl(m,t,s,i,n,f)),i=0):i&&(p.type==="data"||p.type==="tableDelimiterMarker"||p.type==="tableDelimiterFiller")&&(s[3]=n)}for(u!==0&&hf(m,t,u,d,c),m.consume(t.events),n=-1;++n<t.events.length;){const h=t.events[n];h[0]==="enter"&&h[1].type==="table"&&(h[1]._align=m2(t.events,n))}return e}function cl(e,t,n,r,i,l){const s=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",o="tableContent";n[0]!==0&&(l.end=Object.assign({},nr(t.events,n[0])),e.add(n[0],0,[["exit",l,t]]));const u=nr(t.events,n[1]);if(l={type:s,start:Object.assign({},u),end:Object.assign({},u)},e.add(n[1],0,[["enter",l,t]]),n[2]!==0){const d=nr(t.events,n[2]),c=nr(t.events,n[3]),f={type:o,start:Object.assign({},d),end:Object.assign({},c)};if(e.add(n[2],0,[["enter",f,t]]),r!==2){const m=t.events[n[2]],h=t.events[n[3]];if(m[1].end=Object.assign({},h[1].end),m[1].type="chunkText",m[1].contentType="text",n[3]>n[2]+1){const p=n[2]+1,x=n[3]-n[2]-1;e.add(p,x,[])}}e.add(n[3]+1,0,[["exit",f,t]])}return i!==void 0&&(l.end=Object.assign({},nr(t.events,i)),e.add(i,0,[["exit",l,t]]),l=void 0),l}function hf(e,t,n,r,i){const l=[],s=nr(t.events,n);i&&(i.end=Object.assign({},s),l.push(["exit",i,t])),r.end=Object.assign({},s),l.push(["exit",r,t]),e.add(n+1,0,l)}function nr(e,t){const n=e[t],r=n[0]==="enter"?"start":"end";return n[1][r]}const x2={name:"tasklistCheck",tokenize:k2};function v2(){return{text:{91:x2}}}function k2(e,t,n){const r=this;return i;function i(u){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(u):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(u),e.exit("taskListCheckMarker"),l)}function l(u){return ke(u)?(e.enter("taskListCheckValueUnchecked"),e.consume(u),e.exit("taskListCheckValueUnchecked"),s):u===88||u===120?(e.enter("taskListCheckValueChecked"),e.consume(u),e.exit("taskListCheckValueChecked"),s):n(u)}function s(u){return u===93?(e.enter("taskListCheckMarker"),e.consume(u),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),o):n(u)}function o(u){return K(u)?t(u):ue(u)?e.check({tokenize:w2},t,n)(u):n(u)}}function w2(e,t,n){return me(e,r,"whitespace");function r(i){return i===null?n(i):t(i)}}function b2(e){return sp([qS(),r2(),d2(e),p2(),v2()])}const S2={};function C2(e){const t=this,n=e||S2,r=t.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),l=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),s=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(b2(n)),l.push(HS()),s.push(VS(n))}function j2({message:e,pinned:t,onCopy:n,onDelete:r,onTogglePin:i,onRegenerate:l}){const s=(e.role||"assistant").toLowerCase(),o=e.ts?px(e.ts):"",u=e.content||e.message||"",d=s==="user";return a.jsxs("article",{className:`chat-message ${d?"chat-message-user":"chat-message-assistant"} ${t?"chat-message-pinned":""}`,children:[a.jsxs("header",{className:"chat-message-meta",children:[a.jsx("span",{className:"chat-message-role",children:s}),e.agent&&a.jsxs("span",{className:"chat-message-agent",children:["@",e.agent]}),o&&a.jsx("time",{className:"chat-message-time",children:o}),t&&a.jsx("span",{className:"chat-message-pin",children:"pinned"}),a.jsxs("div",{className:"chat-message-actions",children:[a.jsx("button",{type:"button",className:"chat-msg-action-btn",onClick:n,title:"Copy","aria-label":"Copy",children:a.jsx(X1,{size:12})}),!d&&a.jsx("button",{type:"button",className:"chat-msg-action-btn",onClick:l,title:"Regenerate","aria-label":"Regenerate",children:a.jsx(_t,{size:12})}),a.jsx("button",{type:"button",className:"chat-msg-action-btn",onClick:i,title:"Pin","aria-label":"Pin",children:a.jsx(sx,{size:12})}),a.jsx("button",{type:"button",className:"chat-msg-action-btn chat-msg-action-btn-danger",onClick:r,title:"Delete","aria-label":"Delete",children:a.jsx(_r,{size:12})})]})]}),a.jsx("div",{className:"chat-message-content markdown-body",children:a.jsx(db,{remarkPlugins:[C2],children:u})})]})}function N2({messages:e,loading:t,activeProject:n,sessionId:r,pinned:i,activeSource:l,onPickSuggestion:s,onCopy:o,onDelete:u,onTogglePin:d,onRegenerate:c}){const f=w.useRef(null);w.useEffect(()=>{const h=f.current;if(!h)return;let p=h.parentElement,x=!1;for(;p;){if(p.classList.contains("chat-thread-scroll")){x=!0;break}p=p.parentElement}x||(h.scrollTop=h.scrollHeight)},[e]);const m=l==="opencode"?"opencode":"bizar";return t?a.jsx("div",{className:"chat-thread legacy",ref:f,"data-stream":m,children:a.jsx(Px,{count:3})}):n?e.length===0?a.jsx("div",{className:"chat-thread legacy",ref:f,"data-stream":m,children:a.jsx(yd,{variant:"empty",projectName:n.name,onPickSuggestion:s})}):a.jsx("div",{className:"chat-thread legacy",ref:f,children:a.jsx(Tx,{items:e,itemHeight:120,height:800,className:"chat-thread-virtual",renderItem:(h,p)=>a.jsx(j2,{message:h,pinned:i.has(p),onCopy:()=>o(h),onDelete:()=>u(p),onTogglePin:()=>d(p),onRegenerate:()=>c(String(h.ts??p))})})}):a.jsx("div",{className:"chat-thread legacy",ref:f,"data-stream":m,children:a.jsx(yd,{variant:"no-project",projectName:"",onPickSuggestion:s})})}function E2({agent:e,setAgent:t,agents:n}){const[r,i]=w.useState(!1),l=w.useRef(null);w.useEffect(()=>{if(!r)return;const u=d=>{l.current&&!l.current.contains(d.target)&&i(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[r]);const s=e||"no agent",o=s.startsWith("@")?s.slice(1):s;return a.jsxs("div",{className:"chat-agent-chip",ref:l,children:[a.jsxs("button",{type:"button",className:"chat-agent-chip-btn",onClick:()=>i(u=>!u),"aria-haspopup":"listbox","aria-expanded":r,children:[a.jsx(Dr,{size:14}),a.jsx("span",{children:o}),a.jsx(Ss,{size:12,className:r?"rotated":""})]}),r&&a.jsxs("div",{className:"chat-agent-chip-menu",role:"listbox",children:[a.jsx("button",{type:"button",role:"option","aria-selected":!e,onClick:()=>{t(""),i(!1)},children:a.jsx("span",{children:"no agent"})}),n.map(u=>a.jsx("button",{type:"button",role:"option","aria-selected":e===u.name,onClick:()=>{t(u.name),i(!1)},children:a.jsxs("span",{children:["@",u.name]})},u.name))]})]})}function T2(e,t,n=240){w.useLayoutEffect(()=>{const r=e.current;if(!r)return;r.style.height="auto";const i=Math.min(r.scrollHeight,n);r.style.height=`${i}px`,r.style.overflowY=r.scrollHeight>n?"auto":"hidden"},[e,t,n])}function I2({agent:e,setAgent:t,model:n,setModel:r,text:i,setText:l,sending:s,onSend:o,attachments:u,setAttachments:d,suggestions:c,onPickSuggestion:f,agents:m,onAttach:h}){const p=w.useRef(null),x=w.useRef(null);T2(p,i,200);const b=g=>{if(g.key==="Enter"&&(g.metaKey||g.ctrlKey))g.preventDefault(),o();else if(g.key==="Enter"&&!g.shiftKey)g.preventDefault(),o();else if(g.key==="Tab"&&c.length){g.preventDefault();const v=c[0].cmd.split(" ")[0];l(`${v} `)}},y=g=>{const v=g.target.files;if(!v)return;const C=[];for(let z=0;z<v.length;z++)C.push(v[z].name);d(z=>[...z,...C]),g.target.value=""};return a.jsxs("div",{className:"chat-composer",children:[c.length>0&&a.jsx("div",{className:"chat-composer-suggestions",children:c.map(g=>a.jsxs("button",{type:"button",className:"chat-composer-suggestion",onClick:()=>{var C;const v=g.cmd.split(" ")[0];l(`${v} `),(C=p.current)==null||C.focus()},children:[a.jsx("span",{className:"mono",children:g.cmd}),a.jsx("span",{children:g.desc})]},g.cmd))}),u.length>0&&a.jsx("div",{className:"chat-composer-attachments",children:u.map((g,v)=>a.jsxs("span",{className:"chat-composer-attachment-tag",children:[a.jsx(fd,{size:10})," ",g,a.jsx("button",{type:"button",className:"chat-composer-attachment-remove",onClick:()=>d(C=>C.filter((z,E)=>E!==v)),"aria-label":`Remove ${g}`,children:a.jsx(Zn,{size:10})})]},v))}),a.jsxs("div",{className:"chat-composer-input",children:[a.jsx(E2,{agent:e,setAgent:t,agents:m}),a.jsx("textarea",{ref:p,className:"chat-composer-textarea",placeholder:s?"Sending…":"Send a message…",rows:1,value:i,onChange:g=>l(g.target.value),onKeyDown:b,disabled:s,"aria-label":"Message"}),a.jsx("input",{ref:x,type:"file",multiple:!0,style:{display:"none"},onChange:y,"aria-label":"Attach files",tabIndex:-1}),a.jsx("button",{type:"button",className:"chat-attach-btn",onClick:h,title:"Attach files","aria-label":"Attach files",children:a.jsx(fd,{size:14})}),a.jsx("button",{type:"button",className:"chat-attach-btn",onClick:async()=>{if(!i.trim())return;const g=await xx(i);g!==i&&l(g)},title:"Enhance prompt with AI","aria-label":"Enhance prompt",children:a.jsx(Jl,{size:14})}),a.jsx("button",{type:"button",className:"chat-send-btn",onClick:o,disabled:s||!i.trim(),title:"Send (Enter)","aria-label":"Send message",children:a.jsx($m,{size:16})})]})]})}const z2="modulepreload",P2=function(e){return"/"+e},mf={},A2=function(t,n,r){let i=Promise.resolve();if(n&&n.length>0){document.getElementsByTagName("link");const s=document.querySelector("meta[property=csp-nonce]"),o=(s==null?void 0:s.nonce)||(s==null?void 0:s.getAttribute("nonce"));i=Promise.allSettled(n.map(u=>{if(u=P2(u),u in mf)return;mf[u]=!0;const d=u.endsWith(".css"),c=d?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${u}"]${c}`))return;const f=document.createElement("link");if(f.rel=d?"stylesheet":z2,d||(f.as="script"),f.crossOrigin="",f.href=u,o&&f.setAttribute("nonce",o),document.head.appendChild(f),d)return new Promise((m,h)=>{f.addEventListener("load",m),f.addEventListener("error",()=>h(new Error(`Unable to preload CSS for ${u}`)))})}))}function l(s){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=s,window.dispatchEvent(o),!o.defaultPrevented)throw s}return i.then(s=>{for(const o of s||[])o.status==="rejected"&&l(o.reason);return t().catch(l)})};function M2(e,t,n){const[r,i]=w.useState([]),[l,s]=w.useState([]),[o,u]=w.useState(""),[d,c]=w.useState(!0),[f,m]=w.useState({create:!1,send:!1,rename:!1,delete:!1}),[h,p]=w.useState([]),[x,b]=w.useState([]),[y,g]=w.useState(null),[v,C]=w.useState(null),[z,E]=w.useState(null),[A,L]=w.useState({}),[I,k]=w.useState(!0),[j,P]=w.useState(0),[B,O]=w.useState(new Set),[W,de]=w.useState(new Set),ee=w.useRef(null),R=w.useRef(null),V=w.useRef(null),S=w.useRef(0),Y=w.useRef(null),ie=w.useRef(null),N=w.useRef(!1),ge=w.useCallback(T=>{T&&b(D=>{if(T.id&&D.some(U=>U.id===T.id))return D;const _=D.findIndex(U=>typeof U.id=="string"&&U.id.startsWith("msg_")&&U.role===T.role&&(U.content||"")===(T.content||""));if(_>=0){const U=D.slice();return U[_]={...T,id:T.id??D[_].id},U}return[...D,T]})},[]),Le=w.useCallback(T=>{T&&O(D=>{if(D.has(T))return D;const _=new Set(D);return _.add(T),_})},[]),oe=w.useCallback((T,D)=>{L(_=>{const U=_[T]??{state:"idle",unread:0,pinned:!1};return{..._,[T]:{...U,...D}}})},[]),Ne=w.useCallback((T,D)=>{oe(T,{state:D?"streaming":"idle"})},[oe]),H=w.useCallback(T=>{R.current=T},[]),te=w.useCallback(async T=>{var D;try{const _=T?`/chat?session=${encodeURIComponent(T)}`:"/chat?limit=200",U=await q.get(_);i(U.messages||[]),s(U.sessions||[])}catch(_){(D=R.current)==null||D.error(`Chat load failed: ${_.message}`)}finally{c(!1)}},[]),re=w.useCallback(async T=>{var D;c(!0);try{const _=await q.get(`/tasks/${encodeURIComponent(T)}/chat`);i(_.messages||[]),u(_.sessionId||T)}catch(_){(D=R.current)==null||D.error(`Task chat load failed: ${_.message}`)}finally{c(!1)}},[]),Se=w.useCallback(async()=>{try{const T=await q.get("/chat/sessions");s(T.sessions||[])}catch{}},[]),Ot=w.useCallback(async()=>{try{const D=((await q.get("/opencode-sessions")).sessions||[]).map(_=>({..._,source:"opencode",title:_.title||_.id}));p(D)}catch{}},[]),ln=w.useCallback(T=>{if(V.current){try{V.current.close()}catch{}V.current=null}Y.current!==null&&(clearTimeout(Y.current),Y.current=null);const D=q.getToken(),_=D?`/api/opencode-sessions/${encodeURIComponent(T)}/stream?token=${encodeURIComponent(D)}`:`/api/opencode-sessions/${encodeURIComponent(T)}/stream`;ie.current=T,N.current=!0,S.current=0,E(null);const U=()=>{if(!N.current||ie.current!==T)return;const G=new EventSource(_);V.current=G;const le=X=>{var he,nt,dt,Qt;if(!X||!X.type||X.sessionID&&X.sessionID!==T)return;const Z=new Date().toISOString(),fe=T;if(X.type==="message.user.created"||X.type==="message.user.updated"){const se=X.data;ge({id:(se==null?void 0:se.messageID)??X.messageID,role:"user",content:((he=se==null?void 0:se.data)==null?void 0:he.content)??"",ts:Z}),Le((se==null?void 0:se.messageID)??X.messageID);return}if(X.type==="message.assistant.created"||X.type==="message.assistant.updated"){const se=X.data;ge({id:(se==null?void 0:se.messageID)??X.messageID,role:"assistant",content:((nt=se==null?void 0:se.data)==null?void 0:nt.content)??"",ts:Z}),Le((se==null?void 0:se.messageID)??X.messageID),Ne(fe,!0);return}if(X.type==="message.part.updated"){const se=X.data,ec=((dt=se==null?void 0:se.part)==null?void 0:dt.text)??"";if(!ec)return;ge({id:(se==null?void 0:se.id)??(se==null?void 0:se.messageID)??X.messageID,role:"assistant",content:ec,ts:Z}),Le((se==null?void 0:se.id)??(se==null?void 0:se.messageID)??X.messageID),Ne(fe,!0);return}if(X.type==="session.idle"||X.type==="message.assistant.completed"||X.type==="session.completed"){Ne(fe,!1);return}if(X.type==="session.awaiting"||X.type==="session.awaiting_input"||X.type==="message.assistant.awaiting"){oe(fe,{state:"awaiting"});return}if(X.type==="session.error"){E(((Qt=X.data)==null?void 0:Qt.message)||"opencode session error");return}},xe=X=>{if(!X)return null;try{const Z=JSON.parse(X);if(typeof Z.type=="string"){const fe=Z.properties,he=Z.data??fe,nt=typeof Z.sessionID=="string"?Z.sessionID:typeof(fe==null?void 0:fe.sessionID)=="string"?fe.sessionID:typeof(he==null?void 0:he.sessionID)=="string"?he.sessionID:void 0,dt=typeof Z.messageID=="string"?Z.messageID:typeof(fe==null?void 0:fe.messageID)=="string"?fe.messageID:typeof(he==null?void 0:he.messageID)=="string"?he.messageID:void 0;let Qt=Z.type;const se=/\.\d+$/.exec(Qt);return se&&(Qt=Qt.slice(0,se.index)),{type:Qt,sessionID:nt,messageID:dt,data:Z}}if(Z.type==="sync"&&Z.syncEvent&&typeof Z.syncEvent=="object"){const fe=Z.syncEvent;let he=fe.type||"";const nt=/\.\d+$/.exec(he);nt&&(he=he.slice(0,nt.index));const dt=fe.data||{};return{type:he,sessionID:typeof dt.sessionID=="string"?dt.sessionID:void 0,messageID:typeof dt.messageID=="string"?dt.messageID:void 0,data:fe}}return null}catch{return null}},we=["message.user.created","message.user.updated","message.assistant.created","message.assistant.updated","message.part.updated","session.idle","message.assistant.completed","session.completed","session.awaiting","session.awaiting_input","message.assistant.awaiting","session.error"];for(const X of we)G.addEventListener(X,Z=>{le(xe(Z.data))});G.onerror=()=>{if(ie.current!==T)return;if(!N.current){try{G.close()}catch{}V.current=null;return}try{G.close()}catch{}V.current=null;const X=S.current+1;S.current=X;const Z=Math.min(3e4,1e3*2**(X-1));Y.current!==null&&clearTimeout(Y.current),Y.current=window.setTimeout(()=>{Y.current=null,N.current&&ie.current===T&&U()},Z)},G.onopen=()=>{S.current=0,E(null)}};U()},[ge,Le,Ne,oe]),In=w.useCallback(()=>{if(N.current=!1,ie.current=null,Y.current!==null&&(clearTimeout(Y.current),Y.current=null),V.current){try{V.current.close()}catch{}V.current=null}b([]),O(new Set),E(null),C(null),g("bizar")},[]),er=w.useCallback(async T=>{var D;if(N.current=!1,V.current){try{V.current.close()}catch{}V.current=null}Y.current!==null&&(clearTimeout(Y.current),Y.current=null),E(null),c(!0);try{const _=await q.get(`/opencode-sessions/${encodeURIComponent(T)}/messages`);b(_.messages||[])}catch(_){const U=_.message;(D=R.current)==null||D.error(`Opencode session load failed: ${U}`),b([])}finally{c(!1)}C(T),g("opencode"),Ne(T,!1),ln(T)},[Ne,ln]),$i=w.useCallback(T=>{In(),u(T),g("bizar"),te(T),oe(T,{unread:0})},[In,te,oe]),Bi=w.useCallback(async()=>{var D,_,U,G,le;if(f.create)return{ok:!1};const T=t.defaultAgent||"odin";m(xe=>({...xe,create:!0}));try{try{const we=await q.post("/opencode-sessions/new",{agent:T});return await Ot(),await er(we.id),(D=R.current)==null||D.success(`Session ${we.id} created.`),{ok:!0,source:"opencode",id:we.id}}catch(we){if(!(we instanceof wa)||we.status!==503)return(_=R.current)==null||_.error(`Create failed: ${we.message}`),{ok:!1}}if(!e.activeProject)return(U=R.current)==null||U.error("Pick a project in Overview to scope chat sessions."),{ok:!1};const xe=await q.post("/chat/sessions",{});return u(xe.id),i([]),de(new Set),oe(xe.id,{state:"idle",unread:0}),await te(xe.id),Se().catch(()=>{}),(G=R.current)==null||G.success(`Session ${xe.id} created.`),{ok:!0,source:"bizar",id:xe.id}}catch(xe){return(le=R.current)==null||le.error(`Create failed: ${xe.message}`),{ok:!1}}finally{m(xe=>({...xe,create:!1}))}},[f.create,t.defaultAgent,e.activeProject,Ot,er,te,Se,oe]),zs=w.useCallback(async(T,D,_,U)=>{var xe,we,X;if(f.send)return{ok:!1};const G=T.trim();if(!G)return{ok:!1};if(y==="opencode"&&v){const Z=v,fe=`msg_${Date.now().toString(36)}${Math.random().toString(36).slice(2,8)}`,he={id:fe,role:"user",content:G,agent:D,ts:new Date().toISOString()};ge(he),Le(fe),m(nt=>({...nt,send:!0}));try{return await q.post(`/opencode-sessions/${encodeURIComponent(Z)}/send`,{message:G,agent:D}),Ne(Z,!0),{ok:!0}}catch(nt){return b(dt=>dt.filter(Qt=>Qt.id!==fe)),(xe=R.current)==null||xe.error(`Send failed: ${nt.message}`),{ok:!1}}finally{m(nt=>({...nt,send:!1}))}}const le={role:"user",content:G,agent:D,ts:new Date().toISOString()};i(Z=>[...Z,le]),m(Z=>({...Z,send:!0})),Ne(o,!0);try{const Z=await q.post("/chat",{message:G,agent:D,model:_,attachments:U||[]});if(Z!=null&&Z.messages)for(const fe of Z.messages)fe.role==="assistant"&&i(he=>he.some(dt=>dt.ts===fe.ts)?he:[...he,fe]);else(we=R.current)==null||we.info("Still processing… the response will appear shortly.");return{ok:!0}}catch(Z){return i(fe=>fe.filter(he=>he!==le)),(X=R.current)==null||X.error(`Send failed: ${Z.message}`),{ok:!1}}finally{m(Z=>({...Z,send:!1})),Ne(o,!1)}},[y,v,ge,Le,Ne,o,f.send]),Ui=w.useCallback(async T=>{var D,_;if(!o){(D=R.current)==null||D.error("No active session to regenerate.");return}try{await q.post("/chat/regenerate",{sessionId:o,messageId:T}),await te(o)}catch(U){(_=R.current)==null||_.error(`Regenerate failed: ${U.message}`)}},[o,te]),Hi=w.useCallback(T=>{y==="opencode"?b(D=>D.filter((_,U)=>U!==T)):i(D=>D.filter((_,U)=>U!==T))},[y]),Ps=w.useCallback(T=>{de(D=>{const _=new Set(D);return _.has(T)?_.delete(T):_.add(T),_})},[]),As=w.useCallback(T=>{var _,U;const D=T.content||T.message||"";try{(_=navigator.clipboard)==null||_.writeText(D).then(()=>{var G;return(G=R.current)==null?void 0:G.success("Copied.")},()=>{var G;return(G=R.current)==null?void 0:G.error("Copy failed.")})}catch{(U=R.current)==null||U.error("Copy failed.")}},[]),Ms=w.useCallback(()=>{const T=ee.current;if(!T)return;const _=T.scrollHeight-T.scrollTop-T.clientHeight<32;k(_),_&&P(0)},[]),Ls=w.useCallback(()=>{const T=ee.current;T&&(T.scrollTop=T.scrollHeight,k(!0),P(0))},[]),Rs=w.useCallback(async(T,D)=>{var _,U,G;if(f.rename)return!1;m(le=>({...le,rename:!0}));try{const le=D.trim();return le?(h.some(we=>we.id===T)?(await q.patch(`/opencode-sessions/${encodeURIComponent(T)}`,{title:le}),p(we=>we.map(X=>X.id===T?{...X,title:le}:X))):(await q.post(`/chat/sessions/${encodeURIComponent(T)}/rename`,{title:le}),s(we=>we.map(X=>X.id===T?{...X,title:le}:X))),(U=R.current)==null||U.success("Renamed."),!0):((_=R.current)==null||_.error("Title cannot be empty."),!1)}catch(le){return(G=R.current)==null||G.error(`Rename failed: ${le.message}`),!1}finally{m(le=>({...le,rename:!1}))}},[f.rename,h]),M=w.useCallback(async T=>{var D,_;if(f.delete)return!1;m(U=>({...U,delete:!0}));try{return h.some(G=>G.id===T)?(await q.del(`/opencode-sessions/${encodeURIComponent(T)}`),p(G=>G.filter(le=>le.id!==T)),v===T&&In()):(await q.del(`/chat/sessions/${encodeURIComponent(T)}`),s(G=>G.filter(le=>le.id!==T)),o===T&&(u(""),i([]))),L(G=>{const le={...G};return delete le[T],le}),(D=R.current)==null||D.success("Session deleted."),!0}catch(U){return(_=R.current)==null||_.error(`Delete failed: ${U.message}`),!1}finally{m(U=>({...U,delete:!1}))}},[f.delete,h,v,In,o]);return w.useEffect(()=>{ee.current&&(I?ee.current.scrollTop=ee.current.scrollHeight:P(T=>T+1))},[r,x]),w.useEffect(()=>()=>{if(N.current=!1,ie.current=null,Y.current!==null&&(clearTimeout(Y.current),Y.current=null),V.current){try{V.current.close()}catch{}V.current=null}},[]),w.useEffect(()=>{n?re(n):te(),Ot()},[]),w.useEffect(()=>{const T=D=>{var U;const _=(U=D.detail)==null?void 0:U.taskId;_&&re(_)};return window.addEventListener("bizar:setChatTask",T),()=>window.removeEventListener("bizar:setChatTask",T)},[re]),w.useEffect(()=>{let T=!1;return A2(async()=>{const{Ws:D}=await Promise.resolve().then(()=>Ex);return{Ws:D}},void 0).then(({Ws:D})=>{if(T)return;new D().on(U=>{if(U.type!=="chat:message")return;const G=U.message;G&&i(le=>le.some(we=>we.ts===G.ts)?le:[...le,G])})}),()=>{T=!0}},[]),{messages:y==="opencode"?x:r,bizarMessages:r,opencodeMessages:x,sessions:l,opencodeSessions:h,sessionId:o,setSessionId:u,loading:d,sending:f.send,pinned:W,listRef:ee,activeSource:y,activeOpencodeSessionId:v,opencodeError:z,sessionStates:A,busy:f,getSessionDisplay:T=>{var D,_,U,G;return{...T,state:((D=A[T.id])==null?void 0:D.state)??"idle",unread:((_=A[T.id])==null?void 0:_.unread)??0,pinned:((U=A[T.id])==null?void 0:U.pinned)??!1,tree:(G=A[T.id])==null?void 0:G.tree}},stickToBottom:I,newMessageCount:j,handleScroll:Ms,jumpToLatest:Ls,setToast:H,loadChat:te,loadTaskChat:re,refreshSessions:Se,refreshOpencodeSessions:Ot,loadOpencodeSession:er,closeOpencodeSession:In,selectBizarSession:$i,onCreateSession:Bi,onSend:zs,onRegenerate:Ui,deleteMessage:Hi,togglePin:Ps,copyMessage:As,renameSession:Rs,deleteSession:M,seenOpencodeMessages:B}}const L2=[{cmd:"/visual-plan [on|off|status]",desc:"Toggle or view visual plan mode"},{cmd:"/plan new <slug> [template]",desc:"Create a new plan"},{cmd:"/plan list",desc:"List all plans"},{cmd:"/plan open <slug>",desc:"Open a plan in the viewer"},{cmd:"/plan status <slug> <status>",desc:"Set plan status"},{cmd:"/plan get <slug>",desc:"Fetch plan canvas"},{cmd:"/plan add <slug> --title T --type kind",desc:"Add element to a plan"},{cmd:"/plan update <slug> <id>",desc:"Update a plan element"},{cmd:"/plan delete <slug> <id>",desc:"Delete a plan element"},{cmd:'/plan comment <slug> [id] "text"',desc:"Add a comment"},{cmd:"/plan comments <slug> [id]",desc:"Read plan comments"},{cmd:"/bizar",desc:"Launch Bizar dashboard"},{cmd:"/bizar <args>",desc:"Route via Bizar menu"},{cmd:"/audit",desc:"Run security audit"},{cmd:"/explain <q>",desc:"Read-only code Q&A"},{cmd:"/init",desc:"Initialize .bizar/ in this project"},{cmd:"/learn",desc:"Extract patterns from session"},{cmd:"/pr-review",desc:"PR review"},{cmd:"/help | /commands",desc:"Show all Bizar commands"}];function R2(e){const[t,n]=w.useState(""),r=w.useMemo(()=>[...L2,...(e.mods||[]).flatMap(l=>{var s;return(s=l.entry)!=null&&s.command?[{cmd:`/${l.id}`,desc:l.description||l.name,mod:l.id}]:[]})],[e.mods]),i=w.useMemo(()=>{if(!t.startsWith("/")||t.includes(" "))return[];const l=t.toLowerCase();return r.filter(s=>s.cmd.toLowerCase().startsWith(l)).slice(0,6)},[t,r]);return{allCommands:r,suggestions:i,setQuery:n}}function D2({tabs:e,activeTab:t,onChange:n}){return a.jsx("nav",{className:"mobile-bottom-nav",role:"navigation","aria-label":"Mobile navigation",children:e.map(r=>{const i=r.icon;return a.jsxs("button",{type:"button",className:Mu("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:[a.jsx(i,{size:22}),a.jsx("span",{className:"mobile-nav-label",children:r.label})]},r.id)})})}function Dt({open:e,onClose:t,title:n,children:r,actions:i,maxHeight:l="85vh"}){const s=w.useRef(null),o=w.useRef(null),u=w.useId(),d=w.useRef(null),c=w.useRef(null),f=w.useRef(0),m=w.useRef(0),h=()=>{var y;return((y=s.current)==null?void 0:y.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'))??[]};if(w.useEffect(()=>{if(!e)return;d.current=document.activeElement instanceof HTMLElement?document.activeElement:null;const y=g=>{var A;if(g.key==="Escape"&&t(),g.key!=="Tab")return;const v=Array.from(h());if(v.length===0){g.preventDefault(),(A=s.current)==null||A.focus();return}const C=v[0],z=v[v.length-1],E=document.activeElement;if(g.shiftKey){(!E||E===C||E===s.current)&&(g.preventDefault(),z==null||z.focus());return}E===z&&(g.preventDefault(),C==null||C.focus())};return window.addEventListener("keydown",y),requestAnimationFrame(()=>{var g,v;((g=o.current)==null?void 0:g.focus())??((v=s.current)==null||v.focus())}),()=>{var g;window.removeEventListener("keydown",y),(g=d.current)==null||g.focus()}},[e,t]),w.useEffect(()=>(e?(m.current=window.scrollY,document.documentElement.style.overflow="hidden",document.body.style.overflow="hidden",document.body.style.position="fixed",document.body.style.top=`-${m.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,m.current)}),[e]),!e)return null;const p=y=>{var g;y.isPrimary&&(c.current=y.clientY,f.current=0,(g=s.current)==null||g.setPointerCapture(y.pointerId))},x=y=>{if(c.current==null||!s.current)return;const g=Math.max(0,y.clientY-c.current);f.current=g,s.current.style.transform=`translateY(${g}px)`},b=y=>{if(!s.current)return;y&&s.current.hasPointerCapture(y.pointerId)&&s.current.releasePointerCapture(y.pointerId);const g=f.current;s.current.style.transform="",c.current=null,f.current=0,g>72&&t()};return a.jsx("div",{className:"mobile-sheet-overlay",onClick:t,children:a.jsxs("div",{ref:s,className:"mobile-sheet",style:{maxHeight:l},onClick:y=>y.stopPropagation(),role:"dialog","aria-modal":!0,"aria-label":n?void 0:"Sheet","aria-labelledby":n?u:void 0,tabIndex:-1,children:[a.jsx("div",{className:"mobile-sheet-handle",onPointerDown:p,onPointerMove:x,onPointerUp:b,onPointerCancel:b,"aria-hidden":"true"}),a.jsxs("div",{className:"mobile-sheet-header",children:[n?a.jsx("h3",{id:u,className:"mobile-sheet-title",children:n}):a.jsx("div",{}),a.jsx("button",{ref:o,type:"button",className:"mobile-icon-btn",onClick:t,"aria-label":"Close",children:a.jsx(Zn,{size:18})})]}),a.jsx("div",{className:"mobile-sheet-content",children:r}),i&&a.jsx("div",{className:"mobile-sheet-actions",children:i})]})})}function _2(e){switch(e){case"success":return"✓";case"error":return"✗";case"warning":return"⚠";default:return"ℹ"}}function O2(e){const t=new Date(e),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 F2({onSelect:e}){const[t,n]=w.useState(!1),[r,i]=w.useState([]),[l,s]=w.useState(0),o=async()=>{var c;try{const f=await q.get("/notifications");i(f.notifications||[]),s(((c=f.stats)==null?void 0:c.unread)||0)}catch{}};w.useEffect(()=>{o()},[]),w.useEffect(()=>{t&&o()},[t]);const u=async()=>{try{await q.post("/notifications/read-all"),i(c=>c.map(f=>({...f,read:!0}))),s(0)}catch{}},d=async c=>{try{await q.post(`/notifications/${encodeURIComponent(c)}/read`),i(f=>f.map(m=>m.id===c?{...m,read:!0}:m)),s(f=>Math.max(0,f-1))}catch{}};return a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button",className:"mobile-icon-btn mobile-notif-btn",onClick:()=>n(!0),"aria-label":`Notifications${l>0?` (${l} unread)`:""}`,children:[a.jsx(cd,{size:20}),l>0&&a.jsx("span",{className:"mobile-notif-badge",children:l>9?"9+":l})]}),a.jsx(Dt,{open:t,onClose:()=>n(!1),title:"Notifications",actions:l>0?a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",style:{width:"100%"},onClick:u,children:[a.jsx(Q1,{size:14})," Mark all read"]}):void 0,children:a.jsxs("div",{className:"mobile-notif-list",children:[r.length===0&&a.jsxs("div",{className:"mobile-empty",children:[a.jsx(cd,{size:32}),a.jsx("p",{children:"No notifications"})]}),r.map(c=>a.jsxs("button",{type:"button",className:`mobile-notif-item ${c.read?"read":"unread"}`,onClick:()=>{c.read||d(c.id),e(c),n(!1)},children:[a.jsx("span",{className:`mobile-notif-icon severity-${c.severity}`,children:_2(c.severity)}),a.jsxs("div",{className:"mobile-notif-body",children:[a.jsx("span",{className:"mobile-notif-title",children:c.title||c.message}),c.message&&c.title&&a.jsx("span",{className:"mobile-notif-text",children:c.message}),a.jsx("span",{className:"mobile-notif-time",children:O2(c.ts)})]}),!c.read&&a.jsx("span",{className:"mobile-notif-dot"})]},c.id))]})})]})}const $2={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 B2({activeTab:e,snapshot:t,onSearch:n,onNavigate:r}){const[i,l]=w.useState(!1),s=async o=>{try{await q.post(`/projects/${encodeURIComponent(o)}/activate`),l(!1),window.location.reload()}catch{}};return a.jsxs("header",{className:"mobile-topbar",children:[a.jsxs("div",{className:"mobile-topbar-left",children:[a.jsx("span",{className:"mobile-logo",children:"ᛒ"}),(t==null?void 0:t.activeProject)&&a.jsxs("button",{type:"button",className:"mobile-project-btn",onClick:()=>l(!0),"aria-label":"Select project",children:[a.jsx("span",{className:"mobile-project-name",children:t.activeProject.name}),a.jsx(Ss,{size:14})]}),a.jsx("span",{className:"mobile-title",children:$2[e]||"Bizar"})]}),a.jsxs("div",{className:"mobile-topbar-right",children:[a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:n,"aria-label":"Search",children:a.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[a.jsx("circle",{cx:"11",cy:"11",r:"8"}),a.jsx("path",{d:"m21 21-4.35-4.35"})]})}),a.jsx(F2,{onSelect:o=>{r("notification",o.link||"",o.meta??null)}}),(t==null?void 0:t.activeProject)&&a.jsx(Dt,{open:i,onClose:()=>l(!1),title:"Projects",children:a.jsx("div",{className:"mobile-project-list",children:(t.projects||[]).map(o=>{var u,d;return a.jsxs("button",{type:"button",className:`mobile-project-item ${o.id===((u=t.activeProject)==null?void 0:u.id)?"active":""}`,onClick:()=>s(o.id),children:[a.jsx("div",{className:"mobile-project-status","data-status":o.status}),a.jsxs("div",{className:"mobile-project-info",children:[a.jsx("span",{className:"mobile-project-item-name",children:o.name}),a.jsx("span",{className:"mobile-project-item-path",children:o.path})]}),o.id===((d=t.activeProject)==null?void 0:d.id)&&a.jsx("span",{className:"mobile-active-badge",children:"active"})]},o.id)})})})]})]})}const U2=["all","tasks","agents","bg","artifacts","mods"],Co={all:"All",tasks:"Tasks",agents:"Agents",bg:"Background",artifacts:"Plans",mods:"Mods"};function H2({snapshot:e,onRefresh:t}){var L;const[n,r]=w.useState(((L=e.overview)==null?void 0:L.recentActivity)||[]),[i,l]=w.useState(!0),[s,o]=w.useState("all"),[u,d]=w.useState(!1),[c,f]=w.useState(null),[m,h]=w.useState(""),[p,x]=w.useState(!1);w.useEffect(()=>{var I;(I=e.overview)!=null&&I.recentActivity?(r(e.overview.recentActivity),l(!1)):b()},[e.overview]);const b=async()=>{var I;try{const k=await q.get("/snapshot");r(((I=k.overview)==null?void 0:I.recentActivity)||[])}catch{}finally{l(!1)}},y=s==="all"?n:n.filter(I=>{var k,j,P,B,O,W;return s==="tasks"?(k=I.kind)==null?void 0:k.startsWith("task"):s==="agents"?(j=I.kind)==null?void 0:j.startsWith("agent"):s==="bg"?((P=I.kind)==null?void 0:P.includes("bg"))||((B=I.kind)==null?void 0:B.includes("schedule")):s==="artifacts"?(O=I.kind)==null?void 0:O.includes("artifacts"):s==="mods"?(W=I.kind)==null?void 0:W.includes("mod"):!0}),g=e.agents||[],v=e.tasks||[],C=v.filter(I=>I.status==="doing"||I.status==="queued"),z=v.filter(I=>I.status==="done"),E=async()=>{if(!(!m.trim()||p)){x(!0);try{await q.post("/chat",{message:m.trim(),agent:"odin"}),h(""),await t().catch(()=>{}),await b()}catch{}finally{x(!1)}}},A=async()=>{await t().catch(()=>{}),await b()};return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-submit-hero",children:[a.jsx("textarea",{className:"mobile-submit-input",placeholder:"What needs to be done? Describe a task, bug, or refactor for Odin to artifacts…",value:m,onChange:I=>h(I.target.value),rows:2}),a.jsxs("div",{className:"mobile-submit-actions",children:[a.jsx("div",{className:"mobile-submit-chips",children:["Implement feature","Fix bug","Refactor","Investigate","Write tests"].map(I=>a.jsx("button",{type:"button",className:"mobile-submit-chip",onClick:()=>h(k=>k?`${k} ${I}`:I),children:I},I))}),a.jsxs("button",{type:"button",className:"mobile-btn",disabled:!m.trim()||p,onClick:E,children:[a.jsx($m,{size:14})," Submit to Odin"]})]})]}),a.jsxs("div",{className:"mobile-stats",children:[a.jsxs("div",{className:"mobile-stat",children:[a.jsx("div",{className:"mobile-stat-value",children:g.length}),a.jsx("div",{className:"mobile-stat-label",children:"Agents"})]}),a.jsxs("div",{className:"mobile-stat",children:[a.jsx("div",{className:"mobile-stat-value",children:C.length}),a.jsx("div",{className:"mobile-stat-label",children:"Active"})]}),a.jsxs("div",{className:"mobile-stat",children:[a.jsx("div",{className:"mobile-stat-value",children:z.length}),a.jsx("div",{className:"mobile-stat-label",children:"Done"})]}),a.jsxs("div",{className:"mobile-stat",children:[a.jsx("div",{className:"mobile-stat-value",children:e.artifacts.length||0}),a.jsx("div",{className:"mobile-stat-label",children:"Plans"})]})]}),i&&n.length===0&&a.jsx("div",{className:"mobile-loading mobile-loading-inline",children:a.jsx("p",{children:"Loading activity…"})}),a.jsxs("div",{className:"mobile-activity-header",children:[a.jsx("h3",{className:"mobile-section-title",style:{margin:0},children:"Recent Activity"}),a.jsxs("div",{style:{display:"flex",gap:4},children:[a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>d(I=>!I),"aria-label":u?"Resume":"Pause",children:u?a.jsx(Zl,{size:14}):a.jsx(lx,{size:14})}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:A,"aria-label":"Refresh",children:a.jsx(_t,{size:14})})]})]}),a.jsx("div",{className:"mobile-search-scopes",children:U2.map(I=>a.jsx("button",{type:"button",className:`mobile-scope-chip ${s===I?"active":""}`,onClick:()=>o(I),children:Co[I]},I))}),g.length>0&&a.jsxs("section",{className:"mobile-section",children:[a.jsxs("h3",{className:"mobile-section-title",children:[a.jsx(Dr,{size:14})," Agents"]}),a.jsx("div",{className:"mobile-card-list",children:g.slice(0,6).map(I=>a.jsxs("div",{className:"mobile-agent-card",children:[a.jsx("div",{className:"mobile-agent-dot","data-status":I.status||"idle"}),a.jsxs("div",{className:"mobile-agent-info",children:[a.jsx("span",{className:"mobile-agent-name",children:I.name}),a.jsx("span",{className:"mobile-agent-meta",children:I.status||"idle"})]})]},I.name))})]}),!u&&y.length>0&&a.jsx("section",{className:"mobile-section",children:a.jsx("div",{className:"mobile-card-list",children:y.slice(0,30).map((I,k)=>a.jsxs("button",{type:"button",className:"mobile-event-item",onClick:()=>f(I),children:[a.jsx("span",{className:"mobile-event-kind","data-kind":I.kind,children:Co[I.kind]||I.kind}),a.jsx("span",{className:"mobile-event-msg",children:V2(I)}),a.jsx("span",{className:"mobile-event-time",children:Sr(I.ts)})]},`${I.ts}-${I.kind}-${k}`))})}),!u&&y.length===0&&n.length>0&&a.jsxs("div",{className:"mobile-empty",children:[a.jsx(xa,{size:40}),a.jsx("p",{children:"No matching activity."}),a.jsx("p",{className:"muted",children:"Try a different filter."})]}),c&&a.jsx(Dt,{open:!0,onClose:()=>f(null),title:Co[c.kind]||c.kind,children:a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Kind"}),a.jsx("span",{children:c.kind})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Time"}),a.jsx("span",{children:new Date(c.ts).toLocaleString()})]}),Object.entries(c).filter(([I])=>!["ts","kind"].includes(I)).map(([I,k])=>a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:I}),a.jsx("span",{style:{fontSize:12,maxWidth:200,wordBreak:"break-all"},children:typeof k=="object"?JSON.stringify(k):String(k)})]},I))]})}),g.length===0&&C.length===0&&a.jsxs("div",{className:"mobile-empty",children:[a.jsx(xa,{size:40}),a.jsx("p",{children:"No activity yet."}),a.jsx("p",{className:"muted",children:"Start a task or chat to see things here."})]})]})}function V2(e){const t=e.kind||"";return t.includes("task")?`Task: ${e.title||e.id||"updated"}`:t.includes("agent")?`Agent: ${e.name||"status changed"}`:t.includes("artifacts")?`Plan: ${e.slug||"changed"}`:t.includes("mod")?`Mod: ${e.name||"changed"}`:t.includes("schedule")?`Schedule: ${e.name||"triggered"}`:JSON.stringify(e).slice(0,80)}function Tn({open:e,onClose:t,title:n,children:r,actions:i}){const l=w.useRef(null),s=w.useRef(null),o=w.useRef(null),u=w.useId(),d=w.useRef(0);return w.useEffect(()=>{if(!e)return;o.current=document.activeElement instanceof HTMLElement?document.activeElement:null;const c='button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])',f=m=>{var y,g;if(m.key==="Escape"&&t(),m.key!=="Tab")return;const h=Array.from(((y=l.current)==null?void 0:y.querySelectorAll(c))??[]);if(h.length===0){m.preventDefault(),(g=l.current)==null||g.focus();return}const p=h[0],x=h[h.length-1],b=document.activeElement;if(m.shiftKey){(!b||b===p||b===l.current)&&(m.preventDefault(),x==null||x.focus());return}b===x&&(m.preventDefault(),p==null||p.focus())};return window.addEventListener("keydown",f),d.current=window.scrollY,document.documentElement.style.overflow="hidden",document.body.style.overflow="hidden",document.body.style.position="fixed",document.body.style.top=`-${d.current}px`,document.body.style.left="0",document.body.style.right="0",document.body.style.width="100%",requestAnimationFrame(()=>{var m,h;((m=s.current)==null?void 0:m.focus())??((h=l.current)==null||h.focus())}),()=>{var m;window.removeEventListener("keydown",f),document.documentElement.style.overflow="",document.body.style.overflow="",document.body.style.position="",document.body.style.top="",document.body.style.left="",document.body.style.right="",document.body.style.width="",window.scrollTo(0,d.current),(m=o.current)==null||m.focus()}},[e,t]),e?a.jsx("div",{className:"mobile-modal-overlay",onClick:c=>{c.target===c.currentTarget&&t()},children:a.jsxs("div",{ref:l,className:"mobile-modal",onClick:c=>c.stopPropagation(),role:"dialog","aria-modal":!0,"aria-label":n?void 0:"Modal","aria-labelledby":n?u:void 0,tabIndex:-1,children:[a.jsxs("div",{className:"mobile-modal-header",children:[n?a.jsx("h2",{id:u,className:"mobile-modal-title",children:n}):a.jsx("div",{}),a.jsx("button",{ref:s,type:"button",className:"mobile-icon-btn",onClick:t,"aria-label":"Close",children:a.jsx(Zn,{size:20})})]}),a.jsx("div",{className:"mobile-modal-content",children:r}),i&&a.jsx("div",{className:"mobile-modal-actions",children:i})]})}):null}const Xp=["reasoning","code","design","planning","gitops","analysis"],pf={reasoning:"var(--accent)",code:"var(--info)",design:"var(--success)",planning:"var(--warning)",gitops:"var(--error)",analysis:"var(--text-dim)"};function gf({snapshot:e,onBack:t,onOpenAgent:n,selectedAgent:r,onRefresh:i}){const[l,s]=w.useState(e.agents||[]),[o,u]=w.useState(!e.agents),[d,c]=w.useState(""),[f,m]=w.useState(""),[h,p]=w.useState(null),[x,b]=w.useState(!1),[y,g]=w.useState(""),[v,C]=w.useState(!1);w.useEffect(()=>{if(r){const j=l.find(P=>P.name===r);j&&p(j)}},[r,l]);const z=async()=>{try{const j=await q.get("/agents");s(j.agents||[])}catch{}finally{u(!1)}},E=l.filter(j=>{if(d&&j.category!==d)return!1;if(f){const P=f.toLowerCase();if(!j.name.toLowerCase().includes(P)&&!(j.description||"").toLowerCase().includes(P))return!1}return!0}),A=async(j,P)=>{try{await q.post(`/agents/${encodeURIComponent(j)}/invoke`,{prompt:P}),C(!1),g("")}catch{}},L=async j=>{try{await q.post(`/agents/${encodeURIComponent(j)}/restart`),await z()}catch{}},I=async j=>{if(confirm(`Delete agent "${j}"?`))try{await q.del(`/agents/${encodeURIComponent(j)}`),s(P=>P.filter(B=>B.name!==j)),p(null),i==null||i()}catch{}},k=async j=>{try{const P=await q.post("/agents",j);s(B=>[...B,P]),b(!1),i==null||i()}catch{}};return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search agents…",value:f,onChange:j=>m(j.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>z(),"aria-label":"Refresh",children:a.jsx(_t,{size:16})}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>b(!0),"aria-label":"New agent",children:a.jsx(xt,{size:16})})]}),a.jsxs("div",{className:"mobile-search-scopes",children:[a.jsx("button",{type:"button",className:`mobile-scope-chip ${d?"":"active"}`,onClick:()=>c(""),children:"All"}),Xp.map(j=>a.jsx("button",{type:"button",className:`mobile-scope-chip ${d===j?"active":""}`,onClick:()=>c(j),children:j},j))]}),o?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):E.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(Dr,{size:40}),a.jsx("p",{children:"No agents found."})]}):a.jsx("div",{className:"mobile-card-list",children:E.map(j=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>{p(j),n(j.name)},children:[a.jsx("div",{className:"mobile-agent-dot","data-status":j.status||"idle"}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:j.name}),a.jsx("span",{className:"mobile-list-meta",children:j.model||j.mode||"—"})]}),j.category&&a.jsx("span",{className:"mobile-list-badge",style:{color:pf[j.category]||"var(--text-dim)"},children:j.category}),a.jsx("span",{className:"mobile-list-badge","data-status":j.status||"idle",children:j.status||"idle"})]},j.name))}),h&&a.jsx(Dt,{open:!0,onClose:()=>p(null),title:h.name,actions:a.jsxs("div",{className:"mobile-task-detail-actions",children:[a.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>{g(""),C(!0)},children:[a.jsx(Zl,{size:14})," Invoke"]}),(h.isStuck||h.status==="error"||h.status==="working")&&a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>L(h.name),children:[a.jsx(ux,{size:14})," Restart"]}),a.jsx("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>I(h.name),children:a.jsx(_r,{size:14})})]}),children:a.jsxs("div",{className:"mobile-agent-detail",children:[a.jsxs("div",{className:"mobile-agent-detail-status",children:[a.jsx("span",{className:"mobile-agent-dot","data-status":h.status||"idle"}),a.jsx("span",{className:"mobile-agent-detail-status-text",children:h.status||"idle"}),h.category&&a.jsx("span",{className:"mobile-list-badge",style:{color:pf[h.category]},children:h.category})]}),a.jsx("p",{className:"mobile-agent-detail-desc",children:h.description||"No description."}),a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Model"}),a.jsx("span",{className:"mono",children:h.model||"—"})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Mode"}),a.jsx("span",{children:h.mode||"subagent"})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Path"}),a.jsx("span",{className:"mono",style:{fontSize:11},children:h.path})]}),h.lastError&&a.jsxs("div",{className:"mobile-task-detail-row",style:{color:"var(--error)"},children:[a.jsx("span",{children:"Last error"}),a.jsx("span",{children:h.lastError.message})]}),h.tasksTotal!=null&&h.tasksTotal>0&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Success rate"}),a.jsxs("span",{children:[Math.round((h.successRate||0)*100),"%"]})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Last modified"}),a.jsx("span",{children:Sr(h.mtime)})]})]})]})}),a.jsxs(Tn,{open:v,onClose:()=>C(!1),title:`Invoke ${h==null?void 0:h.name}`,actions:a.jsxs("button",{type:"button",className:"mobile-btn",style:{width:"100%"},disabled:!y.trim(),onClick:()=>{h&&A(h.name,y.trim())},children:[a.jsx(Zl,{size:14})," Invoke"]}),children:[a.jsxs("p",{className:"muted",style:{marginBottom:12},children:["Model: ",a.jsx("span",{className:"mono",children:(h==null?void 0:h.model)||"—"})]}),a.jsx("textarea",{className:"mobile-input",rows:5,placeholder:"What should this agent do?",value:y,onChange:j=>g(j.target.value),autoFocus:!0})]}),a.jsx(W2,{open:x,onClose:()=>b(!1),onCreate:k})]})}function W2({open:e,onClose:t,onCreate:n}){const[r,i]=w.useState(""),[l,s]=w.useState(""),[o,u]=w.useState(""),[d,c]=w.useState("subagent"),[f,m]=w.useState("#8b5cf6"),[h,p]=w.useState(""),[x,b]=w.useState(""),[y,g]=w.useState(""),v=C=>{C.preventDefault(),r.trim()&&(n({name:r.trim(),description:l.trim(),model:o,mode:d,color:f,tools:[],tags:x.split(",").map(z=>z.trim()).filter(Boolean),category:h,prompt:y}),i(""),s(""),u(""),c("subagent"),m("#8b5cf6"),p(""),b(""),g(""))};return a.jsx(Tn,{open:e,onClose:t,title:"New Agent",actions:a.jsxs("button",{type:"submit",form:"new-agent-form",className:"mobile-btn",style:{width:"100%"},children:[a.jsx(xt,{size:14})," Create"]}),children:a.jsxs("form",{id:"new-agent-form",onSubmit:v,className:"mobile-task-form",children:[a.jsx("label",{className:"mobile-field-label",children:"Name *"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"my-agent",pattern:"[a-z0-9][a-z0-9-]{0,63}",value:r,onChange:C=>i(C.target.value),autoFocus:!0,required:!0}),a.jsx("label",{className:"mobile-field-label",children:"Description"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"What does this agent do?",value:l,onChange:C=>s(C.target.value)}),a.jsx("label",{className:"mobile-field-label",children:"Model"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"(provider default)",value:o,onChange:C=>u(C.target.value)}),a.jsx("label",{className:"mobile-field-label",children:"Category"}),a.jsxs("select",{className:"mobile-input",value:h,onChange:C=>p(C.target.value),children:[a.jsx("option",{value:"",children:"None"}),Xp.map(C=>a.jsx("option",{value:C,children:C},C))]}),a.jsx("label",{className:"mobile-field-label",children:"Tags (comma-separated)"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"tag1, tag2",value:x,onChange:C=>b(C.target.value)})]})})}function Q2({sessions:e,opencodeSessions:t,activeSessionId:n,activeOpencodeSessionId:r,activeProject:i,creating:l,onCreateSession:s,onSelectSession:o,onSelectOpencodeSession:u}){const[d,c]=w.useState("all"),[f,m]=w.useState(!1),h=30,p=d==="all"?[...e,...t].sort((g,v)=>Number(v.mtime)-Number(g.mtime)):e,x=f?p:p.slice(0,h),b=t.length,y=g=>{if(g.source==="opencode"){u(g);return}o(g.id)};return a.jsxs("div",{className:"chat-sessions",children:[a.jsxs("div",{className:"chat-sessions-header",children:[a.jsx("span",{className:"chat-sessions-header-title",children:"Sessions"}),a.jsx("span",{className:"chat-sessions-count",children:x.length})]}),b>0&&a.jsxs("div",{className:"chat-sessions-toggle",children:[a.jsx("button",{type:"button",className:`chat-sessions-toggle-btn ${d==="bizar"?"active":""}`,onClick:()=>c("bizar"),children:"Bizar"}),a.jsxs("button",{type:"button",className:`chat-sessions-toggle-btn ${d==="all"?"active":""}`,onClick:()=>c("all"),children:["All (",b," opencode)"]})]}),a.jsxs("button",{type:"button",className:"chat-sessions-new",onClick:s,disabled:l||!i,title:i?"Create new session":"Pick a project first","aria-label":"Create new session",children:[l?a.jsx(Wm,{size:"sm"}):a.jsx(xt,{size:14}),a.jsx("span",{children:l?"Creating…":"New session"})]}),e.length===0?a.jsx("div",{className:"chat-sessions-empty",children:a.jsx(zx,{icon:a.jsx(Jl,{size:20}),title:i?"No sessions yet":"No project",message:i?"Create your first session to start chatting.":"Pick a project in Overview to scope chat sessions.",action:i?a.jsxs(pr,{variant:"primary",size:"sm",onClick:s,loading:l,children:[a.jsx(xt,{size:12})," New session"]}):a.jsxs(pr,{variant:"secondary",size:"sm",onClick:()=>{window.location.hash="#overview"},children:[a.jsx(Pu,{size:12})," Open Overview"]})})}):a.jsx("ul",{className:"chat-sessions-list",children:x.map(g=>{const v=g.source==="opencode",C=v?r===g.id:n===g.id;return a.jsxs("li",{className:`chat-sessions-item ${C?"active":""} ${v?"chat-sessions-item-opencode":""}`,onClick:()=>y(g),title:v?`Open in dashboard: ${g.title||g.id}`:g.id,children:[v&&a.jsx(Z1,{size:10,className:"chat-sessions-item-icon"}),a.jsx("span",{className:"chat-sessions-item-id",children:g.title||g.id}),a.jsx("span",{className:"chat-sessions-item-meta",children:new Date(Number(g.mtime)).toLocaleDateString()})]},v?`oc-${g.id}`:g.id)})}),p.length>h&&a.jsx("button",{type:"button",className:"chat-sessions-show-more",onClick:()=>m(g=>!g),children:f?`Show less (${p.length-h} hidden)`:`Show all ${p.length} sessions`})]})}function q2(e){const{activeSource:t}=e;return a.jsx("div",{className:`chat-composer-wrap chat-composer-source-${t??"none"} legacy`,children:a.jsx("div",{className:"chat-composer-pill",children:a.jsx(I2,{...e})})})}function Y2({sessionId:e,messages:t,pinned:n,agent:r,model:i,agents:l,mcps:s,allCommands:o,activeSource:u="bizar",onRename:d,onDelete:c}){const[f,m]=w.useState(!1),[h,p]=w.useState(!1),x=f?l:l.slice(0,4),b=h?o:o.slice(0,4),y=i.includes("/")?i.split("/")[0]:"";return a.jsxs("div",{className:"chat-info",children:[a.jsxs("div",{className:"chat-info-card",children:[a.jsxs("div",{className:"chat-info-card-title",children:[a.jsx(On,{size:14})," Session",a.jsx("span",{className:`chat-source-badge chat-source-${u??"none"}`,style:{marginLeft:"auto"},children:u==="opencode"?"opencode":"bizar chat"})]}),a.jsxs("dl",{className:"env-table",children:[a.jsx("dt",{children:"id"}),a.jsx("dd",{className:"mono",children:e||"Live"}),a.jsx("dt",{children:"Messages"}),a.jsx("dd",{className:"mono",children:t.length}),a.jsx("dt",{children:"Pinned"}),a.jsx("dd",{className:"mono",children:n.size}),a.jsx("dt",{children:"Agent"}),a.jsx("dd",{className:"mono",children:r||"—"}),a.jsx("dt",{children:"Model"}),a.jsx("dd",{className:"mono ellipsis",title:i,children:i||"—"}),y&&a.jsxs(a.Fragment,{children:[a.jsx("dt",{children:"Provider"}),a.jsx("dd",{className:"mono",children:y})]})]}),(d||c)&&a.jsxs("div",{className:"chat-info-actions",children:[d&&a.jsxs("button",{type:"button",className:"btn btn-ghost btn-sm",onClick:d,children:[a.jsx(Au,{size:12,"aria-hidden":!0})," Rename"]}),c&&a.jsxs("button",{type:"button",className:"btn btn-ghost btn-danger btn-sm",onClick:c,children:[a.jsx(_r,{size:12,"aria-hidden":!0})," Delete"]})]})]}),a.jsxs("div",{className:"chat-info-card",children:[a.jsxs("div",{className:"chat-info-card-title",children:[a.jsx(Dr,{size:14})," Agents",a.jsx("span",{className:"chat-info-card-count",children:l.length})]}),a.jsx("ul",{className:"mod-mini-list",children:x.map(g=>a.jsxs("li",{className:"mod-mini",children:[a.jsxs("span",{className:"mod-mini-name",children:["@",g.name]}),a.jsx("span",{className:"mod-mini-meta",children:g.model||g.mode||""})]},g.name))}),l.length>4&&a.jsx("button",{type:"button",className:"chat-info-card-toggle",onClick:()=>m(g=>!g),children:f?"− Show fewer":`+ ${l.length-4} more`})]}),a.jsxs("div",{className:"chat-info-card",children:[a.jsxs("div",{className:"chat-info-card-title",children:[a.jsx(cx,{size:14})," MCPs",a.jsx("span",{className:"chat-info-card-count",children:s.length})]}),a.jsxs("ul",{className:"mod-mini-list",children:[s.length===0?a.jsx("li",{className:"muted",children:"No MCPs configured."}):null,s.map(g=>a.jsxs("li",{className:"mod-mini",children:[a.jsx("span",{className:"mod-mini-name",children:g.id}),a.jsx("span",{className:`mod-mini-pill ${g.enabled?"on":"off"}`,children:g.enabled?"on":"off"})]},g.id))]})]}),a.jsxs("div",{className:"chat-info-card",children:[a.jsxs("button",{type:"button",className:"chat-info-card-title chat-info-card-title-button",onClick:()=>p(g=>!g),"aria-expanded":h,children:[a.jsx(hx,{size:14})," Slash commands",a.jsx("span",{className:"chat-info-card-count",children:o.length}),a.jsx(Ss,{size:12,className:`chat-info-card-chevron ${h?"open":""}`})]}),h&&a.jsx("ul",{className:"mod-mini-list",children:b.map(g=>a.jsxs("li",{children:[a.jsx("code",{children:g.cmd}),a.jsx("span",{className:"muted",children:g.desc})]},g.cmd))})]})]})}function K2({snapshot:e,settings:t,setActiveTab:n,initialTaskId:r,onClearTaskId:i}){const l=bx(),s=kx(),o=M2(e,t,r??"");w.useEffect(()=>{o.setToast({error:O=>l.error(O),success:O=>l.success(O),info:O=>l.info(O),warning:O=>l.warning(O)})},[o,l]);const[u,d]=w.useState(""),[c,f]=w.useState(t.defaultAgent||"odin"),[m,h]=w.useState(t.defaultModel||""),[p,x]=w.useState([]),[b,y]=w.useState(!1),[g,v]=w.useState(!1),C=w.useRef(null),{allCommands:z,suggestions:E,setQuery:A}=R2(e);w.useEffect(()=>{A(u)},[u,A]);const L=()=>{var O;return(O=C.current)==null?void 0:O.click()},I=O=>{const W=O.target.files;if(!W)return;const de=[];for(let ee=0;ee<W.length;ee++)de.push(W[ee].name);x(ee=>{const R=de.filter(V=>!ee.includes(V));return[...ee,...R]}),C.current&&(C.current.value="")},k=async()=>{const O=u.trim();if(!O)return;d(""),A(""),(await o.onSend(O,c,m,p)).ok&&o.jumpToLatest()},j=async()=>{o.busy.create||(await o.onCreateSession(),y(!1))},P=O=>{s.open({title:"Delete message?",children:a.jsx("p",{style:{margin:0},children:"This action cannot be undone."}),footer:a.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[a.jsx(pr,{variant:"secondary",size:"sm",onClick:()=>s.close(),children:"Cancel"}),a.jsx(pr,{variant:"danger",size:"sm",onClick:()=>{s.close(),o.deleteMessage(O)},children:"Delete"})]})})},B=(O,W)=>{s.open({title:"Delete session?",children:a.jsxs("p",{style:{margin:0},children:["Delete ",a.jsx("strong",{children:W}),"? This cannot be undone."]}),footer:a.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[a.jsx(pr,{variant:"secondary",size:"sm",onClick:()=>s.close(),children:"Cancel"}),a.jsx(pr,{variant:"danger",size:"sm",onClick:async()=>{s.close(),await o.deleteSession(O)},children:"Delete"})]})})};return a.jsxs("div",{className:"chat-shell",children:[a.jsx(Ix,{activeProject:e.activeProject,sessionCount:o.sessions.length,sessionsOpen:b,infoOpen:g,onToggleSessions:()=>y(O=>!O),onToggleInfo:()=>v(O=>!O),onOpenOverview:()=>n==null?void 0:n("overview")}),a.jsxs("div",{className:"chat-body",children:[a.jsx("aside",{className:`chat-sessions ${b?"":"chat-sessions-hidden"}`,children:a.jsx(Q2,{sessions:o.sessions,opencodeSessions:o.opencodeSessions,activeSessionId:o.sessionId,activeOpencodeSessionId:o.activeOpencodeSessionId,activeProject:e.activeProject,onCreateSession:j,onSelectSession:o.selectBizarSession,onSelectOpencodeSession:O=>o.loadOpencodeSession(O.id),creating:o.busy.create})}),a.jsxs("main",{className:"chat-main",children:[a.jsx(N2,{messages:o.activeSource==="opencode"?o.opencodeMessages:o.bizarMessages,loading:o.loading,activeProject:e.activeProject,sessionId:o.activeSource==="opencode"?o.activeOpencodeSessionId??o.sessionId:o.sessionId,pinned:o.pinned,activeSource:o.activeSource,onPickSuggestion:O=>d(O),onCopy:O=>o.copyMessage(O),onDelete:P,onTogglePin:o.togglePin,onRegenerate:o.onRegenerate}),a.jsx(q2,{agent:c,setAgent:f,model:m,setModel:h,text:u,setText:d,sending:o.sending,activeSource:o.activeSource,onSend:k,attachments:p,setAttachments:x,suggestions:E,onPickSuggestion:O=>d(`${O.split(" ")[0]} `),agents:e.agents||[],onAttach:L,sessionsOpen:b,infoOpen:g}),a.jsx("input",{ref:C,type:"file",multiple:!0,style:{display:"none"},onChange:I})]}),a.jsx("aside",{className:`chat-info ${g?"":"chat-info-hidden"}`,children:a.jsx(Y2,{sessionId:o.activeSource==="opencode"?o.activeOpencodeSessionId??o.sessionId:o.sessionId,messages:o.activeSource==="opencode"?o.opencodeMessages:o.bizarMessages,pinned:o.pinned,agent:c,model:m,agents:e.agents||[],mcps:e.mcps||[],allCommands:z,activeSource:o.activeSource,onDelete:()=>{const O=o.activeSource==="opencode"?o.activeOpencodeSessionId:o.sessionId;O&&B(O,O)}})})]})]})}function G2({onBack:e}){const[t,n]=w.useState([]),[r,i]=w.useState(!0),[l,s]=w.useState({}),[o,u]=w.useState(!1),d=async()=>{try{const x=await q.get("/config"),b=Object.entries(x).map(([y,g])=>({key:y,value:g,type:c(g)}));n(b),s(Object.fromEntries(Object.entries(x).map(([y,g])=>[y,g])))}catch{}finally{i(!1)}};w.useEffect(()=>{d()},[]);const c=x=>typeof x=="boolean"?"boolean":typeof x=="number"?"number":typeof x=="string"?"string":Array.isArray(x)?"array":x&&typeof x=="object"?"object":"unknown",f=(x,b)=>{s(y=>({...y,[x]:b}))},m=async()=>{u(!0);try{await q.patch("/config",l),await d()}catch{}finally{u(!1)}},h=(x,b)=>{s(y=>({...y,[x]:b}))},p=x=>{const b=l[x.key];switch(x.type){case"boolean":return a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:!!b,onChange:y=>f(x.key,y.target.checked)}),a.jsx("span",{className:"mobile-toggle-slider"})]});case"number":return a.jsx("input",{className:"mobile-input mobile-input-sm",type:"number",inputMode:"numeric",value:String(b??""),onChange:y=>f(x.key,Number(y.target.value))});case"string":return a.jsx("input",{className:"mobile-input mobile-input-sm",type:"text",value:String(b??""),onChange:y=>f(x.key,y.target.value)});case"object":case"array":return a.jsx("textarea",{className:"mobile-input mobile-input-sm",rows:2,value:JSON.stringify(b??null,null,2),onChange:y=>{try{f(x.key,JSON.parse(y.target.value))}catch{}}});default:return a.jsx("span",{className:"mobile-setting-value mono",children:String(b??"null")})}};return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsxs("span",{style:{fontSize:14,color:"var(--text-muted)",flex:1},children:[t.length," config entries"]}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>d(),"aria-label":"Refresh",children:a.jsx(_t,{size:16})}),a.jsxs("button",{type:"button",className:"mobile-btn",disabled:o,onClick:()=>m(),children:[a.jsx(Fm,{size:14})," ",o?"Saving…":"Save all"]})]}),r?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):t.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(Pr,{size:40}),a.jsx("p",{children:"No config entries."})]}):a.jsx("div",{className:"mobile-config-list",children:t.map(x=>a.jsxs("div",{className:"mobile-config-row",children:[a.jsxs("div",{className:"mobile-config-key",children:[a.jsx("span",{className:"mono",children:x.key}),a.jsx("span",{className:"mobile-config-type",children:x.type})]}),a.jsx("div",{className:"mobile-config-value",children:p(x)}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>h(x.key,x.defaultValue),"aria-label":"Reset to default",title:"Reset",children:a.jsx(ax,{size:14})})]},x.key))})]})}function X2({onBack:e}){const[t,n]=w.useState([]),[r,i]=w.useState(!0),[l,s]=w.useState(null),[o,u]=w.useState(""),d=async()=>{try{const h=await q.get("/history");if(Array.isArray(h.history)){n(h.history);return}if(Array.isArray(h.projects)){const p=new Map;for(const x of h.events||[]){const b=x.projectId;if(!b)continue;const y=p.get(b);(!y||new Date(x.ts).getTime()>new Date(y.ts).getTime())&&p.set(b,x)}n(h.projects.map(x=>{const b=p.get(x.id);return{id:x.id,ts:x.lastAccessed||(b==null?void 0:b.ts)||new Date(0).toISOString(),agent:x.name,taskCount:x.tasks.total,summary:`${x.path} · ${x.tasks.done}/${x.tasks.total} done · ${x.plans} plan${x.plans===1?"":"s"}`,output:b?`${b.kind}${b.text?` — ${b.text}`:""}`:"No recent events."}}));return}n([])}catch{}finally{i(!1)}};w.useEffect(()=>{d()},[]);const c=h=>{if(!h)return"—";const p=Math.floor(h/1e3);if(p<60)return`${p}s`;const x=Math.floor(p/60),b=p%60;return`${x}m ${b}s`},f=h=>new Date(h).toLocaleString(),m=o.trim()?t.filter(h=>{const p=o.toLowerCase();return(h.agent||"session").toLowerCase().includes(p)||(h.summary||"").toLowerCase().includes(p)||(h.output||"").toLowerCase().includes(p)}):t;return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search history…",value:o,onChange:h=>u(h.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>d(),"aria-label":"Refresh",children:a.jsx(_t,{size:16})})]}),r?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):m.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(ka,{size:40}),a.jsx("p",{children:t.length===0?"No history yet.":"No matching sessions."})]}):a.jsx("div",{className:"mobile-card-list",children:m.map(h=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>s(h),children:[a.jsx("div",{className:"mobile-list-icon",children:a.jsx(ka,{size:16})}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:h.agent||"Session"}),a.jsxs("span",{className:"mobile-list-meta",children:[f(h.ts),h.duration?` · ${c(h.duration)}`:"",h.taskCount?` · ${h.taskCount} tasks`:""]})]})]},h.id))}),l&&a.jsxs(Dt,{open:!0,onClose:()=>s(null),title:"Session Detail",children:[a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Agent"}),a.jsx("span",{children:l.agent||"—"})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Started"}),a.jsx("span",{children:f(l.ts)})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Duration"}),a.jsx("span",{children:c(l.duration)})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Tasks"}),a.jsx("span",{children:l.taskCount||0})]})]}),l.summary&&a.jsxs("div",{style:{marginTop:12},children:[a.jsx("h4",{style:{fontSize:12,color:"var(--text-muted)",marginBottom:4},children:"Summary"}),a.jsx("p",{style:{fontSize:13},children:l.summary})]}),l.output&&a.jsxs("div",{style:{marginTop:12},children:[a.jsx("h4",{style:{fontSize:12,color:"var(--text-muted)",marginBottom:4},children:"Output"}),a.jsxs("pre",{className:"mono",style:{fontSize:11,whiteSpace:"pre-wrap",wordBreak:"break-all",background:"var(--bg-elev-2)",padding:8,borderRadius:6},children:[l.output.slice(0,1e3),l.output.length>1e3?"…":""]})]})]})]})}function Z2({snapshot:e,onBack:t}){const[n,r]=w.useState(e.mods||[]),[i,l]=w.useState(!e.mods),[s,o]=w.useState(""),[u,d]=w.useState("all"),[c,f]=w.useState(null),m=async()=>{try{const x=await q.get("/mods");r(x.mods||[])}catch{}finally{l(!1)}};w.useEffect(()=>{e.mods?(r(e.mods),l(!1)):m()},[e.mods]);const h=async(x,b)=>{try{await q.patch(`/mods/${encodeURIComponent(x)}`,{enabled:b}),r(y=>y.map(g=>g.id===x?{...g,enabled:b}:g)),(c==null?void 0:c.id)===x&&f(y=>y&&{...y,enabled:b})}catch{}},p=n.filter(x=>{if(u==="enabled"&&!x.enabled||u==="disabled"&&x.enabled)return!1;if(s){const b=s.toLowerCase();return x.name.toLowerCase().includes(b)||x.description.toLowerCase().includes(b)}return!0});return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search mods…",value:s,onChange:x=>o(x.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>m(),"aria-label":"Refresh",children:a.jsx(_t,{size:16})})]}),a.jsx("div",{className:"mobile-search-scopes",children:["all","enabled","disabled"].map(x=>a.jsx("button",{type:"button",className:`mobile-scope-chip ${u===x?"active":""}`,onClick:()=>d(x),children:x.charAt(0).toUpperCase()+x.slice(1)},x))}),i?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):p.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(Pr,{size:40}),a.jsx("p",{children:"No mods found."})]}):a.jsx("div",{className:"mobile-card-list",children:p.map(x=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>f(x),children:[a.jsx("div",{className:"mobile-list-icon",children:a.jsx(Pr,{size:16})}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:x.name}),a.jsxs("span",{className:"mobile-list-meta",children:["v",x.version," · ",x.author]})]}),a.jsx("span",{className:`mobile-list-badge ${x.enabled?"badge-on":"badge-off"}`,children:x.enabled?"on":"off"})]},x.id))}),c&&a.jsx(Dt,{open:!0,onClose:()=>f(null),title:c.name,actions:a.jsx("div",{className:"mobile-task-detail-actions",children:a.jsxs("button",{type:"button",className:"mobile-btn",style:{flex:1},onClick:()=>{c&&h(c.id,!c.enabled)},children:[a.jsx(Om,{size:14})," ",c.enabled?"Disable":"Enable"]})}),children:a.jsxs("div",{className:"mobile-agent-detail",children:[a.jsx("p",{className:"mobile-agent-detail-desc",children:c.description||"No description."}),a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Version"}),a.jsx("span",{className:"mono",children:c.version})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Author"}),a.jsx("span",{children:c.author})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Bizar"}),a.jsx("span",{className:"mono",children:c.bizar})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Type"}),a.jsx("span",{children:c.type})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Permissions"}),a.jsx("span",{children:c.permissions.length})]}),c.installedAt&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Installed"}),a.jsx("span",{children:new Date(c.installedAt).toLocaleDateString()})]})]})]})})]})}function J2({snapshot:e,onNavigate:t}){var s,o,u;const[n,r]=w.useState(""),i=[{id:"artifacts",icon:qn,label:"Plans",count:e.artifacts.length||0,desc:"Visual artifacts with elements & comments"},{id:"agents",icon:Dr,label:"Agents",count:((s=e.agents)==null?void 0:s.length)||0,desc:"The Norse pantheon"},{id:"skills",icon:Pr,label:"Skills",count:null,desc:"Agent capabilities & tools"},{id:"mods",icon:Pr,label:"Mods",count:((o=e.mods)==null?void 0:o.length)||0,desc:"Installed modifications"},{id:"schedules",icon:va,label:"Schedules",count:((u=e.schedules)==null?void 0:u.length)||0,desc:"Cron jobs & automated tasks"},{id:"history",icon:ka,label:"History",count:null,desc:"Past sessions & outputs"},{id:"config",icon:Bm,label:"Config",count:null,desc:"Key-value configuration editor"}],l=n.trim()?i.filter(d=>d.label.toLowerCase().includes(n.toLowerCase())||d.desc.toLowerCase().includes(n.toLowerCase())):i;return a.jsxs("div",{className:"mobile-view",children:[a.jsx("div",{className:"mobile-tasks-toolbar",children:a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search…",value:n,onChange:d=>r(d.target.value),style:{flex:1}})}),a.jsx("div",{className:"mobile-card-list",children:l.map(d=>{const c=d.icon;return a.jsxs("button",{type:"button",className:"mobile-more-nav-item",onClick:()=>t(d.id),children:[a.jsx("div",{className:"mobile-more-nav-icon",children:a.jsx(c,{size:20})}),a.jsxs("div",{className:"mobile-more-nav-content",children:[a.jsxs("span",{className:"mobile-more-nav-label",children:[d.label,d.count!=null&&a.jsx("span",{className:"mobile-more-nav-count",children:d.count})]}),a.jsx("span",{className:"mobile-more-nav-desc",children:d.desc})]}),a.jsx(dd,{size:16,className:"mobile-more-nav-arrow"})]},d.id)})}),a.jsx("div",{className:"mobile-more-footer",children:a.jsxs("a",{href:"/?desktop=1",className:"mobile-more-link",children:["Switch to Desktop ",a.jsx(dd,{size:14})]})})]})}const Ju=[{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 jo(e){var t;return((t=Ju.find(n=>n.id===e))==null?void 0:t.color)||"var(--text-dim)"}function eC({type:e,size:t=12}){switch(e){case"task":return a.jsx(es,{size:t,style:{color:"var(--info)"}});case"note":return a.jsx(md,{size:t,style:{color:"var(--text-dim)"}});case"decision":return a.jsx(es,{size:t,style:{color:"var(--accent)"}});case"question":return a.jsx(K1,{size:t,style:{color:"var(--warning)"}});default:return a.jsx(md,{size:t})}}function tC({slug:e,onBack:t}){const[n,r]=w.useState(null),[i,l]=w.useState(null),[s,o]=w.useState(!0),[u,d]=w.useState(!1),[c,f]=w.useState(null),[m,h]=w.useState(!1),[p,x]=w.useState(!1),[b,y]=w.useState(!1),[g,v]=w.useState(""),C=async()=>{o(!0);try{const I=await q.get(`/plans/${encodeURIComponent(e)}`);r(I.canvas),l(I.meta)}catch{}finally{o(!1)}};w.useEffect(()=>{C()},[e]);const z=async(I,k,j)=>{try{const P=((n==null?void 0:n.elements)||[]).reduce((O,W)=>Math.max(O,W.x||0),40),B=((n==null?void 0:n.elements)||[]).reduce((O,W)=>Math.max(O,W.y||0),40);await q.post(`/plans/${encodeURIComponent(e)}/elements`,{type:I,title:k,content:j,x:20+P,y:20+B,width:240,height:120}),await C(),x(!1)}catch{}},E=async(I,k)=>{try{await q.put(`/plans/${encodeURIComponent(e)}/elements/${encodeURIComponent(I)}`,k),await C(),f(null)}catch{}},A=async I=>{if(confirm("Delete this element?"))try{await q.del(`/plans/${encodeURIComponent(e)}/elements/${encodeURIComponent(I)}`),f(null),await C()}catch{}},L=async(I,k)=>{try{const j=k?`/plans/${encodeURIComponent(e)}/elements/${encodeURIComponent(k)}/comments`:`/plans/${encodeURIComponent(e)}/comments`;await q.post(j,{text:I,elementId:k}),await C(),v(""),y(!1)}catch{}};return s||!n||!i?a.jsx("div",{className:"mobile-view",children:a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading canvas…"})})}):a.jsxs("div",{className:"mobile-view mobile-view-canvas",children:[a.jsxs("div",{className:"mobile-canvas-bar",children:[a.jsxs("div",{className:"mobile-canvas-meta",children:[a.jsx("span",{className:"mobile-canvas-title",children:i.title||e}),a.jsx("span",{className:"mobile-canvas-status","data-status":i.status,children:i.status})]}),a.jsxs("div",{className:"mobile-canvas-actions",children:[a.jsx("button",{type:"button",className:`mobile-icon-btn ${u?"active":""}`,onClick:()=>d(I=>!I),"aria-label":u?"Done editing":"Edit",children:a.jsx(Au,{size:16})}),a.jsxs("button",{type:"button",className:"mobile-icon-btn",onClick:()=>h(I=>!I),"aria-label":"Comments",children:[a.jsx(On,{size:16}),n.comments.length>0&&a.jsx("span",{className:"mobile-canvas-comment-count",children:n.comments.length})]}),u&&a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>x(!0),"aria-label":"Add element",children:a.jsx(xt,{size:16})})]})]}),a.jsxs("div",{className:"mobile-canvas-elements",children:[n.elements.length===0&&a.jsxs("div",{className:"mobile-empty",children:[a.jsx("p",{children:"No elements yet."}),u&&a.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>x(!0),children:[a.jsx(xt,{size:14})," Add Element"]})]}),n.elements.map(I=>a.jsxs("button",{type:"button",className:`mobile-canvas-element ${(c==null?void 0:c.id)===I.id?"selected":""}`,style:{borderColor:jo(I.type)},onClick:()=>{u&&f(I)},"aria-pressed":(c==null?void 0:c.id)===I.id,children:[a.jsxs("div",{className:"mobile-canvas-el-header",style:{background:`${jo(I.type)}18`},children:[a.jsx(eC,{type:I.type,size:12}),a.jsx("span",{className:"mobile-canvas-el-type",style:{color:jo(I.type)},children:I.type}),I.status&&I.status!=="open"&&a.jsx("span",{className:"mobile-canvas-el-status",children:I.status})]}),a.jsx("div",{className:"mobile-canvas-el-title",children:I.title||"Untitled"}),I.content&&a.jsxs("div",{className:"mobile-canvas-el-content",children:[I.content.slice(0,120),I.content.length>120?"…":""]}),a.jsxs("div",{className:"mobile-canvas-el-comments",children:[a.jsx(On,{size:10}),n.comments.filter(k=>k.elementId===I.id).length]})]},I.id))]}),m&&a.jsxs("div",{className:"mobile-canvas-comments",children:[a.jsxs("div",{className:"mobile-canvas-comments-header",children:[a.jsxs("h4",{children:["Comments (",n.comments.length,")"]}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>h(!1),children:a.jsx(Zn,{size:16})})]}),a.jsxs("div",{className:"mobile-canvas-comment-list",children:[n.comments.length===0&&a.jsx("p",{className:"mobile-empty-inline",children:"No comments yet."}),n.comments.map(I=>a.jsxs("div",{className:"mobile-canvas-comment",children:[a.jsxs("div",{className:"mobile-canvas-comment-head",children:[a.jsx("span",{className:"mono",children:I.author}),a.jsx("span",{className:"muted",children:Sr(I.created)})]}),a.jsx("div",{className:"mobile-canvas-comment-text",children:I.text})]},I.id))]}),a.jsxs("div",{className:"mobile-canvas-comment-input",children:[a.jsx("textarea",{className:"mobile-input",rows:2,placeholder:"Add a comment…",value:g,onChange:I=>v(I.target.value)}),a.jsx("button",{type:"button",className:"mobile-btn",disabled:!g.trim(),onClick:()=>{L(g.trim(),null)},children:"Post"})]})]}),c&&a.jsx(Dt,{open:!0,onClose:()=>f(null),title:`Edit ${c.title||c.type}`,actions:a.jsxs("div",{className:"mobile-task-detail-actions",children:[a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>A(c.id),children:[a.jsx(_r,{size:14})," Delete"]}),a.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>y(!0),children:[a.jsx(On,{size:14})," Comment"]})]}),children:a.jsx(nC,{element:c,onSave:I=>E(c.id,I),onClose:()=>f(null)})}),a.jsx(rC,{open:p,onClose:()=>x(!1),onAdd:z}),a.jsx(Tn,{open:b,onClose:()=>y(!1),title:"Add Comment",actions:a.jsxs("button",{type:"button",className:"mobile-btn",style:{width:"100%"},disabled:!g.trim(),onClick:()=>{L(g.trim(),(c==null?void 0:c.id)||null),y(!1)},children:[a.jsx(On,{size:14})," Post"]}),children:a.jsx("textarea",{className:"mobile-input",rows:3,placeholder:"Your comment…",value:g,onChange:I=>v(I.target.value),autoFocus:!0})})]})}function nC({element:e,onSave:t,onClose:n}){const[r,i]=w.useState(e.type),[l,s]=w.useState(e.title||""),[o,u]=w.useState(e.content||""),[d,c]=w.useState(e.status||"open");return a.jsxs("form",{className:"mobile-task-form",onSubmit:f=>{f.preventDefault(),t({type:r,title:l,content:o,status:d}),n()},children:[a.jsx("label",{className:"mobile-field-label",children:"Type"}),a.jsx("select",{className:"mobile-input",value:r,onChange:f=>i(f.target.value),children:Ju.map(f=>a.jsx("option",{value:f.id,children:f.label},f.id))}),a.jsx("label",{className:"mobile-field-label",children:"Title"}),a.jsx("input",{className:"mobile-input",type:"text",value:l,onChange:f=>s(f.target.value)}),a.jsx("label",{className:"mobile-field-label",children:"Status"}),a.jsx("input",{className:"mobile-input",type:"text",value:d,onChange:f=>c(f.target.value),placeholder:"open / done / blocked"}),a.jsx("label",{className:"mobile-field-label",children:"Content (markdown)"}),a.jsx("textarea",{className:"mobile-input",rows:4,value:o,onChange:f=>u(f.target.value)}),a.jsx("button",{type:"submit",className:"mobile-btn",style:{width:"100%",marginTop:8},children:"Save"})]})}function rC({open:e,onClose:t,onAdd:n}){const[r,i]=w.useState("task"),[l,s]=w.useState(""),[o,u]=w.useState(""),d=c=>{c.preventDefault(),l.trim()&&(n(r,l.trim(),o.trim()),s(""),u(""))};return a.jsx(Tn,{open:e,onClose:t,title:"Add Element",actions:a.jsxs("button",{type:"submit",form:"add-el-form",className:"mobile-btn",style:{width:"100%"},children:[a.jsx(xt,{size:14})," Add"]}),children:a.jsxs("form",{id:"add-el-form",onSubmit:d,className:"mobile-task-form",children:[a.jsx("label",{className:"mobile-field-label",children:"Type"}),a.jsx("select",{className:"mobile-input",value:r,onChange:c=>i(c.target.value),children:Ju.map(c=>a.jsx("option",{value:c.id,children:c.label},c.id))}),a.jsx("label",{className:"mobile-field-label",children:"Title *"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"Element title",value:l,onChange:c=>s(c.target.value),autoFocus:!0,required:!0}),a.jsx("label",{className:"mobile-field-label",children:"Content (markdown)"}),a.jsx("textarea",{className:"mobile-input",rows:3,placeholder:"Description…",value:o,onChange:c=>u(c.target.value)})]})})}function iC({snapshot:e,onBack:t,onOpenArtifact:n}){const[r,i]=w.useState(e.artifacts||[]),[l,s]=w.useState(!e.artifacts),[o,u]=w.useState(""),[d,c]=w.useState(!1),[f,m]=w.useState(""),[h,p]=w.useState(""),x=async()=>{try{const g=await q.get("/artifacts");i(g.artifacts||[])}catch{}finally{s(!1)}},b=async()=>{if(f.trim())try{const g=await q.post("/artifacts",{slug:f.trim(),title:h.trim()||void 0});c(!1),m(""),p(""),n(g.slug)}catch{}},y=o.trim()?r.filter(g=>(g.title||g.slug||"").toLowerCase().includes(o.toLowerCase())):r;return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search artifacts…",value:o,onChange:g=>u(g.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>x(),"aria-label":"Refresh",children:a.jsx(_t,{size:16})})]}),a.jsx("div",{style:{marginBottom:12},children:a.jsxs("button",{type:"button",className:"mobile-btn",style:{width:"100%"},onClick:()=>c(!0),children:[a.jsx(xt,{size:14})," New Artifact"]})}),l?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):y.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(qn,{size:40}),a.jsx("p",{children:"No artifacts yet."})]}):a.jsx("div",{className:"mobile-card-list",children:y.map(g=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>n(g.slug),children:[a.jsx("div",{className:"mobile-list-icon",children:a.jsx(qn,{size:16})}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:g.title||g.slug}),a.jsxs("span",{className:"mobile-list-meta",children:[g.status," · ",g.source,g.elementCount!=null?` · ${g.elementCount} elements`:"",g.commentCount!=null?` · ${g.commentCount} comments`:""]})]}),a.jsx("span",{className:"mobile-list-badge","data-status":g.status,children:g.status})]},g.slug))}),a.jsx(Tn,{open:d,onClose:()=>c(!1),title:"New Artifact",actions:a.jsxs("button",{type:"submit",form:"new-plan-form",className:"mobile-btn",style:{width:"100%"},children:[a.jsx(xt,{size:14})," Create"]}),children:a.jsxs("form",{id:"new-plan-form",onSubmit:g=>{g.preventDefault(),b()},className:"mobile-task-form",children:[a.jsx("label",{className:"mobile-field-label",children:"Slug *"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"my-plan",pattern:"[a-z0-9][a-z0-9-]{0,63}",value:f,onChange:g=>m(g.target.value),autoFocus:!0,required:!0}),a.jsx("label",{className:"mobile-field-label",children:"Title (optional)"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"My Artifact",value:h,onChange:g=>p(g.target.value)})]})})]})}const lC=["cron","interval","once"],sC=["command","agent","webhook"],yf=["UTC","America/New_York","America/Los_Angeles","Europe/London","Europe/Berlin","Asia/Tokyo"],Zp=Array.from({length:24},(e,t)=>({value:t,label:t===0?"12 AM":t<12?`${t} AM`:t===12?"12 PM":`${t-12} PM`})),oC=Array.from({length:12},(e,t)=>t*5),Jp=[{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"}],aC=[{value:"s",label:"sec"},{value:"m",label:"min"},{value:"h",label:"hr"},{value:"d",label:"day"}];function uC({snapshot:e}){var b;const[t,n]=w.useState(e.schedules||[]),[r,i]=w.useState(!e.schedules),[l,s]=w.useState(""),[o,u]=w.useState(null),[d,c]=w.useState({open:!1}),f=async()=>{try{const y=await q.get("/schedules");n(y.schedules||[])}catch{}finally{i(!1)}};w.useEffect(()=>{e.schedules?(n(e.schedules),i(!1)):f()},[e.schedules]);const m=async(y,g)=>{try{await q.patch(`/schedules/${encodeURIComponent(y)}`,{enabled:g}),n(v=>v.map(C=>C.id===y?{...C,enabled:g}:C)),(o==null?void 0:o.id)===y&&u(v=>v&&{...v,enabled:g})}catch{}},h=async y=>{if(confirm("Delete this schedule?"))try{await q.del(`/schedules/${encodeURIComponent(y)}`),n(g=>g.filter(v=>v.id!==y)),(o==null?void 0:o.id)===y&&u(null)}catch{}},p=async y=>{try{await q.post(`/schedules/${encodeURIComponent(y)}/trigger`)}catch{}},x=l.trim()?t.filter(y=>y.name.toLowerCase().includes(l.toLowerCase())):t;return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search schedules…",value:l,onChange:y=>s(y.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>f(),"aria-label":"Refresh",children:a.jsx(_t,{size:16})}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>c({open:!0}),"aria-label":"New schedule",children:a.jsx(xt,{size:16})})]}),r?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):x.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(va,{size:40}),a.jsx("p",{children:"No schedules found."})]}):a.jsx("div",{className:"mobile-card-list",children:x.map(y=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>u(y),children:[a.jsx("div",{className:"mobile-list-icon",children:a.jsx(va,{size:16})}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:y.name}),a.jsxs("span",{className:"mobile-list-meta",children:[kf(y)," ·"," ",y.nextRun?`next ${vf(y.nextRun,y.timezone)}`:"no next run"]})]}),a.jsx("span",{className:`mobile-list-badge ${y.enabled?"badge-on":"badge-off"}`,children:y.enabled?"on":"off"})]},y.id))}),o&&a.jsx(Dt,{open:!0,onClose:()=>u(null),title:o.name,actions:a.jsxs("div",{className:"mobile-task-detail-actions",children:[a.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>{o&&p(o.id)},children:[a.jsx(Zl,{size:14})," Trigger now"]}),a.jsx("button",{type:"button",className:`mobile-btn ${o.enabled?"mobile-btn-secondary":""}`,onClick:()=>{o&&m(o.id,!o.enabled)},children:o.enabled?"Disable":"Enable"}),a.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>{o&&(c({open:!0,initial:o}),u(null))},children:[a.jsx(Au,{size:14})," Edit"]}),a.jsx("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>{o&&h(o.id)},children:a.jsx(_r,{size:14})})]}),children:a.jsx("div",{className:"mobile-agent-detail",children:a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Type"}),a.jsx("span",{children:o.type})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Schedule"}),a.jsx("span",{className:"mono",children:kf(o)||o.schedule})]}),o.timezone&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Timezone"}),a.jsx("span",{className:"mono",children:o.timezone})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Action"}),a.jsxs("span",{children:[o.action.type,": ",o.action.target]})]}),o.action.type==="agent"&&o.action.prompt&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Prompt"}),a.jsx("span",{style:{fontSize:12},children:o.action.prompt})]}),((b=o.budgetCheck)==null?void 0:b.skipIfBudgetLow)&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Budget gate"}),a.jsxs("span",{children:["skip if ≥ ",o.budgetCheck.maxConcurrent??6," concurrent"]})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Next run"}),a.jsx("span",{children:o.nextRun?vf(o.nextRun,o.timezone):"—"})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Last run"}),a.jsx("span",{children:o.lastRun?fC(o.lastRun):"—"})]}),o.lastResult&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Last result"}),a.jsx("span",{style:{fontSize:12},children:o.lastResult})]}),o.lastError&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Last error"}),a.jsx("span",{style:{fontSize:12},children:o.lastError})]})]})})}),a.jsx(dC,{open:d.open,initial:d.initial,onClose:()=>c({open:!1}),onSaved:()=>{c({open:!1}),f()}})]})}function xf(e){var r,i;if(!e)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=e.type==="cron"?eg(e.schedule):null,n=e.type==="interval"?hC(e.schedule):null;return{name:e.name||"",type:e.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:e.type==="once"?mC(e.schedule):"",timezone:e.timezone||"UTC",actionType:e.action.type,actionTarget:e.action.target||"",actionPrompt:e.action.prompt||"",skipIfBudgetLow:!!((r=e.budgetCheck)!=null&&r.skipIfBudgetLow),maxConcurrent:Number.isFinite((i=e.budgetCheck)==null?void 0:i.maxConcurrent)?e.budgetCheck.maxConcurrent:6,enabled:e.enabled!==!1}}function cC(e){if(e.type==="cron")return`${e.cronMinute} ${e.cronHour} * * ${e.cronDow}`;if(e.type==="interval")return`${e.intervalN}${e.intervalUnit}`;if(!e.onceAt)return"";try{return new Date(e.onceAt).toISOString()}catch{return e.onceAt}}function dC({open:e,initial:t,onClose:n,onSaved:r}){const[i,l]=w.useState(()=>xf(t)),[s,o]=w.useState(!1);w.useEffect(()=>{e&&l(xf(t))},[e,t]);const u=(c,f)=>{l(m=>({...m,[c]:f}))},d=async c=>{if(c.preventDefault(),!i.name.trim())return;const f=cC(i);if(f){o(!0);try{const m={name:i.name.trim(),type:i.type,schedule:f,timezone:i.timezone,action:{type:i.actionType,target:i.actionTarget.trim(),...i.actionType==="agent"&&i.actionPrompt.trim()?{prompt:i.actionPrompt.trim()}:{}},budgetCheck:{maxConcurrent:i.maxConcurrent,skipIfBudgetLow:i.skipIfBudgetLow},enabled:i.enabled};t?await q.put(`/schedules/${encodeURIComponent(t.id)}`,m):await q.post("/schedules",m),r()}catch{}finally{o(!1)}}};return a.jsx(Tn,{open:e,onClose:n,title:t?`Edit ${t.name}`:"New schedule",actions:a.jsxs("button",{type:"submit",form:"mobile-schedule-form",className:"mobile-btn",style:{width:"100%"},disabled:s,children:[a.jsx(xt,{size:14})," ",t?"Save":"Create"]}),children:a.jsxs("form",{id:"mobile-schedule-form",onSubmit:d,className:"mobile-task-form",children:[a.jsx("label",{className:"mobile-field-label",children:"Name *"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"Weekly review",value:i.name,onChange:c=>u("name",c.target.value),autoFocus:!0,required:!0}),a.jsx("label",{className:"mobile-field-label",children:"Type"}),a.jsx("select",{className:"mobile-input",value:i.type,onChange:c=>u("type",c.target.value),children:lC.map(c=>a.jsx("option",{value:c,children:c},c))}),i.type==="cron"&&a.jsxs(a.Fragment,{children:[a.jsx("label",{className:"mobile-field-label",children:"Day of week"}),a.jsx("select",{className:"mobile-input",value:i.cronDow,onChange:c=>u("cronDow",c.target.value),children:Jp.map(c=>a.jsx("option",{value:c.value,children:c.label},c.value))}),a.jsxs("div",{className:"mobile-form-row",children:[a.jsxs("div",{style:{flex:1},children:[a.jsx("label",{className:"mobile-field-label",children:"Hour"}),a.jsx("select",{className:"mobile-input",value:String(i.cronHour),onChange:c=>u("cronHour",parseInt(c.target.value,10)),children:Zp.map(c=>a.jsx("option",{value:String(c.value),children:c.label},c.value))})]}),a.jsxs("div",{style:{flex:1},children:[a.jsx("label",{className:"mobile-field-label",children:"Minute"}),a.jsx("select",{className:"mobile-input",value:String(i.cronMinute),onChange:c=>u("cronMinute",parseInt(c.target.value,10)),children:oC.map(c=>a.jsx("option",{value:String(c),children:String(c).padStart(2,"0")},c))})]})]})]}),i.type==="interval"&&a.jsxs("div",{className:"mobile-form-row",children:[a.jsxs("div",{style:{flex:1},children:[a.jsx("label",{className:"mobile-field-label",children:"Every"}),a.jsx("input",{className:"mobile-input",type:"number",min:1,value:i.intervalN,onChange:c=>u("intervalN",parseInt(c.target.value,10)||1)})]}),a.jsxs("div",{style:{flex:1},children:[a.jsx("label",{className:"mobile-field-label",children:"Unit"}),a.jsx("select",{className:"mobile-input",value:i.intervalUnit,onChange:c=>u("intervalUnit",c.target.value),children:aC.map(c=>a.jsx("option",{value:c.value,children:c.label},c.value))})]})]}),i.type==="once"&&a.jsxs(a.Fragment,{children:[a.jsx("label",{className:"mobile-field-label",children:"Run at"}),a.jsx("input",{className:"mobile-input",type:"datetime-local",value:i.onceAt,onChange:c=>u("onceAt",c.target.value)})]}),a.jsx("label",{className:"mobile-field-label",children:"Timezone"}),a.jsx("select",{className:"mobile-input",value:yf.includes(i.timezone)?i.timezone:"UTC",onChange:c=>u("timezone",c.target.value),children:yf.map(c=>a.jsx("option",{value:c,children:c},c))}),a.jsx("label",{className:"mobile-field-label",children:"Action type"}),a.jsx("select",{className:"mobile-input",value:i.actionType,onChange:c=>u("actionType",c.target.value),children:sC.map(c=>a.jsx("option",{value:c,children:c},c))}),a.jsx("label",{className:"mobile-field-label",children:"Target"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:i.actionType==="webhook"?"https://...":i.actionType==="agent"?"agent or task ref":"echo hello",value:i.actionTarget,onChange:c=>u("actionTarget",c.target.value)}),i.actionType==="agent"&&a.jsxs(a.Fragment,{children:[a.jsx("label",{className:"mobile-field-label",children:"Prompt"}),a.jsx("textarea",{className:"mobile-input",rows:3,placeholder:"What should the agent do?",value:i.actionPrompt,onChange:c=>u("actionPrompt",c.target.value)})]}),a.jsxs("fieldset",{className:"mobile-budget-card",children:[a.jsx("legend",{children:"Budget pre-flight"}),a.jsxs("label",{className:"mobile-checkbox-row",children:[a.jsx("input",{type:"checkbox",checked:i.skipIfBudgetLow,onChange:c=>u("skipIfBudgetLow",c.target.checked)}),a.jsx("span",{children:"Skip if too many bg tasks are running"})]}),a.jsx("label",{className:"mobile-field-label",children:"Cap"}),a.jsx("input",{className:"mobile-input",type:"number",min:1,max:64,value:i.maxConcurrent,onChange:c=>u("maxConcurrent",parseInt(c.target.value,10)||6),disabled:!i.skipIfBudgetLow})]}),a.jsxs("label",{className:"mobile-checkbox-row",children:[a.jsx("input",{type:"checkbox",checked:i.enabled,onChange:c=>u("enabled",c.target.checked)}),a.jsx("span",{children:"Enabled"})]})]})})}function fC(e){const t=Date.now()-new Date(e).getTime();return t<6e4?"just now":t<36e5?`${Math.floor(t/6e4)}m ago`:t<864e5?`${Math.floor(t/36e5)}h ago`:new Date(e).toLocaleDateString()}function vf(e,t){try{return new Date(e).toLocaleString(void 0,{timeZone:t||void 0,weekday:"short",hour:"numeric",minute:"2-digit",month:"short",day:"numeric"})}catch{return new Date(e).toLocaleString()}}function eg(e){if(typeof e!="string")return null;const t=e.trim().split(/\s+/);if(t.length!==5)return null;const[n,r,,,i]=t,l=parseInt(n,10),s=parseInt(r,10);return!Number.isFinite(l)||!Number.isFinite(s)||n!==String(l)||r!==String(s)?null:{minute:l,hour:s,dow:i==="*"?"*":Number.isFinite(parseInt(i,10))?i:"*"}}function hC(e){if(typeof e!="string")return null;const t=/^(\d+)([smhd])$/i.exec(e.trim());return t?{n:parseInt(t[1],10),unit:t[2].toLowerCase()}:null}function mC(e){if(!e)return"";try{const t=new Date(e);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 kf(e){var l,s;if(e.type!=="cron")return e.schedule;const t=eg(e.schedule);if(!t)return e.schedule;const n=((l=Jp.find(o=>o.value===t.dow))==null?void 0:l.label)||t.dow,r=((s=Zp.find(o=>o.value===t.hour))==null?void 0:s.label)||`${t.hour}`,i=String(t.minute).padStart(2,"0");return n==="Every day"?`Every day ${r} :${i}`:`Every ${n} ${r} :${i}`}const pC=["all","tasks","agents","artifacts","projects","settings"],gC={tasks:es,agents:Dr,plans:qn,projects:Pu,settings:Pr};function yC({open:e,onClose:t,onNavigate:n}){const[r,i]=w.useState(""),[l,s]=w.useState("all"),[o,u]=w.useState([]),[d,c]=w.useState(!1),f=w.useRef(null);w.useEffect(()=>{e&&(i(""),u([]),requestAnimationFrame(()=>{var p;return(p=f.current)==null?void 0:p.focus()}))},[e]),w.useEffect(()=>{if(!r.trim()){u([]);return}const p=setTimeout(async()=>{c(!0);try{const x=await q.get(`/search?q=${encodeURIComponent(r)}&scope=${l}`);u(x.results||[])}catch{u([])}finally{c(!1)}},250);return()=>clearTimeout(p)},[r,l]);const m=p=>{const x=p.item,b=x.id||x.slug||x.name||"";n(p.type,b),t()},h=o.reduce((p,x)=>(p[x.type]||(p[x.type]=[]),p[x.type].push(x),p),{});return a.jsx(Tn,{open:e,onClose:t,title:"Search",children:a.jsxs("div",{className:"mobile-search-container",children:[a.jsxs("div",{className:"mobile-search-input-row",children:[a.jsx(hd,{size:16,style:{color:"var(--text-muted)",flexShrink:0}}),a.jsx("input",{ref:f,className:"mobile-search-field",type:"text",placeholder:"Search…",value:r,onChange:p=>i(p.target.value),enterKeyHint:"search",onKeyDown:p=>{p.key==="Escape"&&t(),p.key==="Enter"&&o.length>0&&m(o[0])}}),r&&a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>i(""),"aria-label":"Clear",children:a.jsx(Zn,{size:16})})]}),a.jsx("div",{className:"mobile-search-scopes",children:pC.map(p=>a.jsx("button",{type:"button",className:`mobile-scope-chip ${l===p?"active":""}`,onClick:()=>s(p),children:p==="all"?"All":p.charAt(0).toUpperCase()+p.slice(1)},p))}),a.jsxs("div",{className:"mobile-search-results",children:[d&&a.jsx("div",{className:"mobile-search-loading",children:"Searching…"}),!d&&r&&o.length===0&&a.jsxs("div",{className:"mobile-empty",children:[a.jsx(hd,{size:32}),a.jsx("p",{children:"No results found"})]}),!d&&!r&&a.jsx("div",{className:"mobile-empty",children:a.jsx("p",{children:"Type to search across tasks, agents, plans, and more."})}),Object.entries(h).map(([p,x])=>{const b=gC[p]||qn;return a.jsxs("div",{className:"mobile-search-group",children:[a.jsxs("h4",{className:"mobile-search-group-title",children:[a.jsx(b,{size:12})," ",p.charAt(0).toUpperCase()+p.slice(1)," (",x.length,")"]}),x.map((y,g)=>{const v=y.item;return a.jsxs("button",{type:"button",className:"mobile-search-result-item",onClick:()=>m(y),children:[a.jsx("span",{className:"mobile-search-result-title",children:v.title||v.name||v.slug||"(unnamed)"}),v.description&&a.jsx("span",{className:"mobile-search-result-meta",children:v.description.slice(0,80)})]},g)})]},p)})]})]})})}var xC=Object.defineProperty,ss=Object.getOwnPropertySymbols,tg=Object.prototype.hasOwnProperty,ng=Object.prototype.propertyIsEnumerable,wf=(e,t,n)=>t in e?xC(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,La=(e,t)=>{for(var n in t||(t={}))tg.call(t,n)&&wf(e,n,t[n]);if(ss)for(var n of ss(t))ng.call(t,n)&&wf(e,n,t[n]);return e},Ra=(e,t)=>{var n={};for(var r in e)tg.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&ss)for(var r of ss(e))t.indexOf(r)<0&&ng.call(e,r)&&(n[r]=e[r]);return n};/**
344
344
  * @license QR Code generator library (TypeScript)
345
345
  * Copyright (c) Project Nayuki.
346
346
  * SPDX-License-Identifier: MIT
@@ -348,4 +348,4 @@ Error generating stack: `+l.message+`
348
348
  * @license qrcode.react
349
349
  * Copyright (c) Paul O'Shannessy
350
350
  * SPDX-License-Identifier: ISC
351
- */var _2={L:gr.QrCode.Ecc.LOW,M:gr.QrCode.Ecc.MEDIUM,Q:gr.QrCode.Ecc.QUARTILE,H:gr.QrCode.Ecc.HIGH},Jp=128,eg="L",tg="#FFFFFF",ng="#000000",rg=!1,ig=1,O2=4,F2=0,$2=.1;function lg(e,t=0){const n=[];return e.forEach(function(r,i){let l=null;r.forEach(function(s,o){if(!s&&l!==null){n.push(`M${l+t} ${i+t}h${o-l}v1H${l+t}z`),l=null;return}if(o===r.length-1){if(!s)return;l===null?n.push(`M${o+t},${i+t} h1v1H${o+t}z`):n.push(`M${l+t},${i+t} h${o+1-l}v1H${l+t}z`);return}s&&l===null&&(l=o)})}),n.join("")}function sg(e,t){return e.slice().map((n,r)=>r<t.y||r>=t.y+t.h?n:n.map((i,l)=>l<t.x||l>=t.x+t.w?i:!1))}function B2(e,t,n,r){if(r==null)return null;const i=e.length+n*2,l=Math.floor(t*$2),s=i/t,o=(r.width||l)*s,u=(r.height||l)*s,d=r.x==null?e.length/2-o/2:r.x*s,c=r.y==null?e.length/2-u/2:r.y*s,f=r.opacity==null?1:r.opacity;let m=null;if(r.excavate){let p=Math.floor(d),x=Math.floor(c),b=Math.ceil(o+d-p),y=Math.ceil(u+c-x);m={x:p,y:x,w:b,h:y}}const h=r.crossOrigin;return{x:d,y:c,h:u,w:o,excavation:m,opacity:f,crossOrigin:h}}function U2(e,t){return t!=null?Math.max(Math.floor(t),0):e?O2:F2}function og({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:l,size:s,boostLevel:o}){let u=_e.useMemo(()=>{const p=(Array.isArray(e)?e:[e]).reduce((x,b)=>(x.push(...gr.QrSegment.makeSegments(b)),x),[]);return gr.QrCode.encodeSegments(p,_2[t],n,void 0,void 0,o)},[e,t,n,o]);const{cells:d,margin:c,numCells:f,calculatedImageSettings:m}=_e.useMemo(()=>{let h=u.getModules();const p=U2(r,i),x=h.length+p*2,b=B2(h,s,p,l);return{cells:h,margin:p,numCells:x,calculatedImageSettings:b}},[u,s,l,r,i]);return{qrcode:u,margin:c,cells:d,numCells:f,calculatedImageSettings:m}}var H2=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),V2=_e.forwardRef(function(t,n){const r=t,{value:i,size:l=Jp,level:s=eg,bgColor:o=tg,fgColor:u=ng,includeMargin:d=rg,minVersion:c=ig,boostLevel:f,marginSize:m,imageSettings:h}=r,x=Ra(r,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:b}=x,y=Ra(x,["style"]),g=h==null?void 0:h.src,v=_e.useRef(null),C=_e.useRef(null),z=_e.useCallback(O=>{v.current=O,typeof n=="function"?n(O):n&&(n.current=O)},[n]),[E,A]=_e.useState(!1),{margin:L,cells:I,numCells:k,calculatedImageSettings:j}=og({value:i,level:s,minVersion:c,boostLevel:f,includeMargin:d,marginSize:m,imageSettings:h,size:l});_e.useEffect(()=>{if(v.current!=null){const O=v.current,W=O.getContext("2d");if(!W)return;let de=I;const ee=C.current,R=j!=null&&ee!==null&&ee.complete&&ee.naturalHeight!==0&&ee.naturalWidth!==0;R&&j.excavation!=null&&(de=sg(I,j.excavation));const V=window.devicePixelRatio||1;O.height=O.width=l*V;const S=l/k*V;W.scale(S,S),W.fillStyle=o,W.fillRect(0,0,k,k),W.fillStyle=u,H2?W.fill(new Path2D(lg(de,L))):I.forEach(function(Y,ie){Y.forEach(function(N,ge){N&&W.fillRect(ge+L,ie+L,1,1)})}),j&&(W.globalAlpha=j.opacity),R&&W.drawImage(ee,j.x+L,j.y+L,j.w,j.h)}}),_e.useEffect(()=>{A(!1)},[g]);const P=La({height:l,width:l},b);let B=null;return g!=null&&(B=_e.createElement("img",{src:g,key:g,style:{display:"none"},onLoad:()=>{A(!0)},ref:C,crossOrigin:j==null?void 0:j.crossOrigin})),_e.createElement(_e.Fragment,null,_e.createElement("canvas",La({style:P,height:l,width:l,ref:z,role:"img"},y)),B)});V2.displayName="QRCodeCanvas";var ag=_e.forwardRef(function(t,n){const r=t,{value:i,size:l=Jp,level:s=eg,bgColor:o=tg,fgColor:u=ng,includeMargin:d=rg,minVersion:c=ig,boostLevel:f,title:m,marginSize:h,imageSettings:p}=r,x=Ra(r,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:b,cells:y,numCells:g,calculatedImageSettings:v}=og({value:i,level:s,minVersion:c,boostLevel:f,includeMargin:d,marginSize:h,imageSettings:p,size:l});let C=y,z=null;p!=null&&v!=null&&(v.excavation!=null&&(C=sg(y,v.excavation)),z=_e.createElement("image",{href:p.src,height:v.h,width:v.w,x:v.x+b,y:v.y+b,preserveAspectRatio:"none",opacity:v.opacity,crossOrigin:v.crossOrigin}));const E=lg(C,b);return _e.createElement("svg",La({height:l,width:l,viewBox:`0 0 ${g} ${g}`,ref:n,role:"img"},x),!!m&&_e.createElement("title",null,m),_e.createElement("path",{fill:o,d:`M0,0 h${g}v${g}H0z`,shapeRendering:"crispEdges"}),_e.createElement("path",{fill:u,d:E,shapeRendering:"crispEdges"}),z)});ag.displayName="QRCodeSVG";function W2({tabs:e,activeTab:t,onChange:n}){return a.jsx("nav",{className:"mobile-bottom-nav",role:"navigation","aria-label":"Mobile navigation",children:e.map(r=>{const i=r.icon;return a.jsxs("button",{type:"button",className:Mu("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:[a.jsx(i,{size:22}),a.jsx("span",{className:"mobile-nav-label",children:r.label})]},r.id)})})}function Dt({open:e,onClose:t,title:n,children:r,actions:i,maxHeight:l="85vh"}){const s=w.useRef(null),o=w.useRef(null),u=w.useId(),d=w.useRef(null),c=w.useRef(null),f=w.useRef(0),m=w.useRef(0),h=()=>{var y;return((y=s.current)==null?void 0:y.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'))??[]};if(w.useEffect(()=>{if(!e)return;d.current=document.activeElement instanceof HTMLElement?document.activeElement:null;const y=g=>{var A;if(g.key==="Escape"&&t(),g.key!=="Tab")return;const v=Array.from(h());if(v.length===0){g.preventDefault(),(A=s.current)==null||A.focus();return}const C=v[0],z=v[v.length-1],E=document.activeElement;if(g.shiftKey){(!E||E===C||E===s.current)&&(g.preventDefault(),z==null||z.focus());return}E===z&&(g.preventDefault(),C==null||C.focus())};return window.addEventListener("keydown",y),requestAnimationFrame(()=>{var g,v;((g=o.current)==null?void 0:g.focus())??((v=s.current)==null||v.focus())}),()=>{var g;window.removeEventListener("keydown",y),(g=d.current)==null||g.focus()}},[e,t]),w.useEffect(()=>(e?(m.current=window.scrollY,document.documentElement.style.overflow="hidden",document.body.style.overflow="hidden",document.body.style.position="fixed",document.body.style.top=`-${m.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,m.current)}),[e]),!e)return null;const p=y=>{var g;y.isPrimary&&(c.current=y.clientY,f.current=0,(g=s.current)==null||g.setPointerCapture(y.pointerId))},x=y=>{if(c.current==null||!s.current)return;const g=Math.max(0,y.clientY-c.current);f.current=g,s.current.style.transform=`translateY(${g}px)`},b=y=>{if(!s.current)return;y&&s.current.hasPointerCapture(y.pointerId)&&s.current.releasePointerCapture(y.pointerId);const g=f.current;s.current.style.transform="",c.current=null,f.current=0,g>72&&t()};return a.jsx("div",{className:"mobile-sheet-overlay",onClick:t,children:a.jsxs("div",{ref:s,className:"mobile-sheet",style:{maxHeight:l},onClick:y=>y.stopPropagation(),role:"dialog","aria-modal":!0,"aria-label":n?void 0:"Sheet","aria-labelledby":n?u:void 0,tabIndex:-1,children:[a.jsx("div",{className:"mobile-sheet-handle",onPointerDown:p,onPointerMove:x,onPointerUp:b,onPointerCancel:b,"aria-hidden":"true"}),a.jsxs("div",{className:"mobile-sheet-header",children:[n?a.jsx("h3",{id:u,className:"mobile-sheet-title",children:n}):a.jsx("div",{}),a.jsx("button",{ref:o,type:"button",className:"mobile-icon-btn",onClick:t,"aria-label":"Close",children:a.jsx(Zn,{size:18})})]}),a.jsx("div",{className:"mobile-sheet-content",children:r}),i&&a.jsx("div",{className:"mobile-sheet-actions",children:i})]})})}function Q2(e){switch(e){case"success":return"✓";case"error":return"✗";case"warning":return"⚠";default:return"ℹ"}}function q2(e){const t=new Date(e),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 Y2({onSelect:e}){const[t,n]=w.useState(!1),[r,i]=w.useState([]),[l,s]=w.useState(0),o=async()=>{var c;try{const f=await q.get("/notifications");i(f.notifications||[]),s(((c=f.stats)==null?void 0:c.unread)||0)}catch{}};w.useEffect(()=>{o()},[]),w.useEffect(()=>{t&&o()},[t]);const u=async()=>{try{await q.post("/notifications/read-all"),i(c=>c.map(f=>({...f,read:!0}))),s(0)}catch{}},d=async c=>{try{await q.post(`/notifications/${encodeURIComponent(c)}/read`),i(f=>f.map(m=>m.id===c?{...m,read:!0}:m)),s(f=>Math.max(0,f-1))}catch{}};return a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button",className:"mobile-icon-btn mobile-notif-btn",onClick:()=>n(!0),"aria-label":`Notifications${l>0?` (${l} unread)`:""}`,children:[a.jsx(cd,{size:20}),l>0&&a.jsx("span",{className:"mobile-notif-badge",children:l>9?"9+":l})]}),a.jsx(Dt,{open:t,onClose:()=>n(!1),title:"Notifications",actions:l>0?a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",style:{width:"100%"},onClick:u,children:[a.jsx(Q1,{size:14})," Mark all read"]}):void 0,children:a.jsxs("div",{className:"mobile-notif-list",children:[r.length===0&&a.jsxs("div",{className:"mobile-empty",children:[a.jsx(cd,{size:32}),a.jsx("p",{children:"No notifications"})]}),r.map(c=>a.jsxs("button",{type:"button",className:`mobile-notif-item ${c.read?"read":"unread"}`,onClick:()=>{c.read||d(c.id),e(c),n(!1)},children:[a.jsx("span",{className:`mobile-notif-icon severity-${c.severity}`,children:Q2(c.severity)}),a.jsxs("div",{className:"mobile-notif-body",children:[a.jsx("span",{className:"mobile-notif-title",children:c.title||c.message}),c.message&&c.title&&a.jsx("span",{className:"mobile-notif-text",children:c.message}),a.jsx("span",{className:"mobile-notif-time",children:q2(c.ts)})]}),!c.read&&a.jsx("span",{className:"mobile-notif-dot"})]},c.id))]})})]})}const K2={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 G2({activeTab:e,snapshot:t,onSearch:n,onNavigate:r}){const[i,l]=w.useState(!1),s=async o=>{try{await q.post(`/projects/${encodeURIComponent(o)}/activate`),l(!1),window.location.reload()}catch{}};return a.jsxs("header",{className:"mobile-topbar",children:[a.jsxs("div",{className:"mobile-topbar-left",children:[a.jsx("span",{className:"mobile-logo",children:"ᛒ"}),(t==null?void 0:t.activeProject)&&a.jsxs("button",{type:"button",className:"mobile-project-btn",onClick:()=>l(!0),"aria-label":"Select project",children:[a.jsx("span",{className:"mobile-project-name",children:t.activeProject.name}),a.jsx(Ss,{size:14})]}),a.jsx("span",{className:"mobile-title",children:K2[e]||"Bizar"})]}),a.jsxs("div",{className:"mobile-topbar-right",children:[a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:n,"aria-label":"Search",children:a.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[a.jsx("circle",{cx:"11",cy:"11",r:"8"}),a.jsx("path",{d:"m21 21-4.35-4.35"})]})}),a.jsx(Y2,{onSelect:o=>{r("notification",o.link||"",o.meta??null)}}),(t==null?void 0:t.activeProject)&&a.jsx(Dt,{open:i,onClose:()=>l(!1),title:"Projects",children:a.jsx("div",{className:"mobile-project-list",children:(t.projects||[]).map(o=>{var u,d;return a.jsxs("button",{type:"button",className:`mobile-project-item ${o.id===((u=t.activeProject)==null?void 0:u.id)?"active":""}`,onClick:()=>s(o.id),children:[a.jsx("div",{className:"mobile-project-status","data-status":o.status}),a.jsxs("div",{className:"mobile-project-info",children:[a.jsx("span",{className:"mobile-project-item-name",children:o.name}),a.jsx("span",{className:"mobile-project-item-path",children:o.path})]}),o.id===((d=t.activeProject)==null?void 0:d.id)&&a.jsx("span",{className:"mobile-active-badge",children:"active"})]},o.id)})})})]})]})}const X2=["all","tasks","agents","bg","artifacts","mods"],Co={all:"All",tasks:"Tasks",agents:"Agents",bg:"Background",artifacts:"Plans",mods:"Mods"};function Z2({snapshot:e,onRefresh:t}){var L;const[n,r]=w.useState(((L=e.overview)==null?void 0:L.recentActivity)||[]),[i,l]=w.useState(!0),[s,o]=w.useState("all"),[u,d]=w.useState(!1),[c,f]=w.useState(null),[m,h]=w.useState(""),[p,x]=w.useState(!1);w.useEffect(()=>{var I;(I=e.overview)!=null&&I.recentActivity?(r(e.overview.recentActivity),l(!1)):b()},[e.overview]);const b=async()=>{var I;try{const k=await q.get("/snapshot");r(((I=k.overview)==null?void 0:I.recentActivity)||[])}catch{}finally{l(!1)}},y=s==="all"?n:n.filter(I=>{var k,j,P,B,O,W;return s==="tasks"?(k=I.kind)==null?void 0:k.startsWith("task"):s==="agents"?(j=I.kind)==null?void 0:j.startsWith("agent"):s==="bg"?((P=I.kind)==null?void 0:P.includes("bg"))||((B=I.kind)==null?void 0:B.includes("schedule")):s==="artifacts"?(O=I.kind)==null?void 0:O.includes("artifacts"):s==="mods"?(W=I.kind)==null?void 0:W.includes("mod"):!0}),g=e.agents||[],v=e.tasks||[],C=v.filter(I=>I.status==="doing"||I.status==="queued"),z=v.filter(I=>I.status==="done"),E=async()=>{if(!(!m.trim()||p)){x(!0);try{await q.post("/chat",{message:m.trim(),agent:"odin"}),h(""),await t().catch(()=>{}),await b()}catch{}finally{x(!1)}}},A=async()=>{await t().catch(()=>{}),await b()};return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-submit-hero",children:[a.jsx("textarea",{className:"mobile-submit-input",placeholder:"What needs to be done? Describe a task, bug, or refactor for Odin to artifacts…",value:m,onChange:I=>h(I.target.value),rows:2}),a.jsxs("div",{className:"mobile-submit-actions",children:[a.jsx("div",{className:"mobile-submit-chips",children:["Implement feature","Fix bug","Refactor","Investigate","Write tests"].map(I=>a.jsx("button",{type:"button",className:"mobile-submit-chip",onClick:()=>h(k=>k?`${k} ${I}`:I),children:I},I))}),a.jsxs("button",{type:"button",className:"mobile-btn",disabled:!m.trim()||p,onClick:E,children:[a.jsx($m,{size:14})," Submit to Odin"]})]})]}),a.jsxs("div",{className:"mobile-stats",children:[a.jsxs("div",{className:"mobile-stat",children:[a.jsx("div",{className:"mobile-stat-value",children:g.length}),a.jsx("div",{className:"mobile-stat-label",children:"Agents"})]}),a.jsxs("div",{className:"mobile-stat",children:[a.jsx("div",{className:"mobile-stat-value",children:C.length}),a.jsx("div",{className:"mobile-stat-label",children:"Active"})]}),a.jsxs("div",{className:"mobile-stat",children:[a.jsx("div",{className:"mobile-stat-value",children:z.length}),a.jsx("div",{className:"mobile-stat-label",children:"Done"})]}),a.jsxs("div",{className:"mobile-stat",children:[a.jsx("div",{className:"mobile-stat-value",children:e.artifacts.length||0}),a.jsx("div",{className:"mobile-stat-label",children:"Plans"})]})]}),i&&n.length===0&&a.jsx("div",{className:"mobile-loading mobile-loading-inline",children:a.jsx("p",{children:"Loading activity…"})}),a.jsxs("div",{className:"mobile-activity-header",children:[a.jsx("h3",{className:"mobile-section-title",style:{margin:0},children:"Recent Activity"}),a.jsxs("div",{style:{display:"flex",gap:4},children:[a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>d(I=>!I),"aria-label":u?"Resume":"Pause",children:u?a.jsx(Zl,{size:14}):a.jsx(lx,{size:14})}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:A,"aria-label":"Refresh",children:a.jsx(_t,{size:14})})]})]}),a.jsx("div",{className:"mobile-search-scopes",children:X2.map(I=>a.jsx("button",{type:"button",className:`mobile-scope-chip ${s===I?"active":""}`,onClick:()=>o(I),children:Co[I]},I))}),g.length>0&&a.jsxs("section",{className:"mobile-section",children:[a.jsxs("h3",{className:"mobile-section-title",children:[a.jsx(Dr,{size:14})," Agents"]}),a.jsx("div",{className:"mobile-card-list",children:g.slice(0,6).map(I=>a.jsxs("div",{className:"mobile-agent-card",children:[a.jsx("div",{className:"mobile-agent-dot","data-status":I.status||"idle"}),a.jsxs("div",{className:"mobile-agent-info",children:[a.jsx("span",{className:"mobile-agent-name",children:I.name}),a.jsx("span",{className:"mobile-agent-meta",children:I.status||"idle"})]})]},I.name))})]}),!u&&y.length>0&&a.jsx("section",{className:"mobile-section",children:a.jsx("div",{className:"mobile-card-list",children:y.slice(0,30).map((I,k)=>a.jsxs("button",{type:"button",className:"mobile-event-item",onClick:()=>f(I),children:[a.jsx("span",{className:"mobile-event-kind","data-kind":I.kind,children:Co[I.kind]||I.kind}),a.jsx("span",{className:"mobile-event-msg",children:J2(I)}),a.jsx("span",{className:"mobile-event-time",children:Sr(I.ts)})]},`${I.ts}-${I.kind}-${k}`))})}),!u&&y.length===0&&n.length>0&&a.jsxs("div",{className:"mobile-empty",children:[a.jsx(xa,{size:40}),a.jsx("p",{children:"No matching activity."}),a.jsx("p",{className:"muted",children:"Try a different filter."})]}),c&&a.jsx(Dt,{open:!0,onClose:()=>f(null),title:Co[c.kind]||c.kind,children:a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Kind"}),a.jsx("span",{children:c.kind})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Time"}),a.jsx("span",{children:new Date(c.ts).toLocaleString()})]}),Object.entries(c).filter(([I])=>!["ts","kind"].includes(I)).map(([I,k])=>a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:I}),a.jsx("span",{style:{fontSize:12,maxWidth:200,wordBreak:"break-all"},children:typeof k=="object"?JSON.stringify(k):String(k)})]},I))]})}),g.length===0&&C.length===0&&a.jsxs("div",{className:"mobile-empty",children:[a.jsx(xa,{size:40}),a.jsx("p",{children:"No activity yet."}),a.jsx("p",{className:"muted",children:"Start a task or chat to see things here."})]})]})}function J2(e){const t=e.kind||"";return t.includes("task")?`Task: ${e.title||e.id||"updated"}`:t.includes("agent")?`Agent: ${e.name||"status changed"}`:t.includes("artifacts")?`Plan: ${e.slug||"changed"}`:t.includes("mod")?`Mod: ${e.name||"changed"}`:t.includes("schedule")?`Schedule: ${e.name||"triggered"}`:JSON.stringify(e).slice(0,80)}function Tn({open:e,onClose:t,title:n,children:r,actions:i}){const l=w.useRef(null),s=w.useRef(null),o=w.useRef(null),u=w.useId(),d=w.useRef(0);return w.useEffect(()=>{if(!e)return;o.current=document.activeElement instanceof HTMLElement?document.activeElement:null;const c='button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])',f=m=>{var y,g;if(m.key==="Escape"&&t(),m.key!=="Tab")return;const h=Array.from(((y=l.current)==null?void 0:y.querySelectorAll(c))??[]);if(h.length===0){m.preventDefault(),(g=l.current)==null||g.focus();return}const p=h[0],x=h[h.length-1],b=document.activeElement;if(m.shiftKey){(!b||b===p||b===l.current)&&(m.preventDefault(),x==null||x.focus());return}b===x&&(m.preventDefault(),p==null||p.focus())};return window.addEventListener("keydown",f),d.current=window.scrollY,document.documentElement.style.overflow="hidden",document.body.style.overflow="hidden",document.body.style.position="fixed",document.body.style.top=`-${d.current}px`,document.body.style.left="0",document.body.style.right="0",document.body.style.width="100%",requestAnimationFrame(()=>{var m,h;((m=s.current)==null?void 0:m.focus())??((h=l.current)==null||h.focus())}),()=>{var m;window.removeEventListener("keydown",f),document.documentElement.style.overflow="",document.body.style.overflow="",document.body.style.position="",document.body.style.top="",document.body.style.left="",document.body.style.right="",document.body.style.width="",window.scrollTo(0,d.current),(m=o.current)==null||m.focus()}},[e,t]),e?a.jsx("div",{className:"mobile-modal-overlay",onClick:c=>{c.target===c.currentTarget&&t()},children:a.jsxs("div",{ref:l,className:"mobile-modal",onClick:c=>c.stopPropagation(),role:"dialog","aria-modal":!0,"aria-label":n?void 0:"Modal","aria-labelledby":n?u:void 0,tabIndex:-1,children:[a.jsxs("div",{className:"mobile-modal-header",children:[n?a.jsx("h2",{id:u,className:"mobile-modal-title",children:n}):a.jsx("div",{}),a.jsx("button",{ref:s,type:"button",className:"mobile-icon-btn",onClick:t,"aria-label":"Close",children:a.jsx(Zn,{size:20})})]}),a.jsx("div",{className:"mobile-modal-content",children:r}),i&&a.jsx("div",{className:"mobile-modal-actions",children:i})]})}):null}const ug=["reasoning","code","design","planning","gitops","analysis"],gf={reasoning:"var(--accent)",code:"var(--info)",design:"var(--success)",planning:"var(--warning)",gitops:"var(--error)",analysis:"var(--text-dim)"};function yf({snapshot:e,onBack:t,onOpenAgent:n,selectedAgent:r,onRefresh:i}){const[l,s]=w.useState(e.agents||[]),[o,u]=w.useState(!e.agents),[d,c]=w.useState(""),[f,m]=w.useState(""),[h,p]=w.useState(null),[x,b]=w.useState(!1),[y,g]=w.useState(""),[v,C]=w.useState(!1);w.useEffect(()=>{if(r){const j=l.find(P=>P.name===r);j&&p(j)}},[r,l]);const z=async()=>{try{const j=await q.get("/agents");s(j.agents||[])}catch{}finally{u(!1)}},E=l.filter(j=>{if(d&&j.category!==d)return!1;if(f){const P=f.toLowerCase();if(!j.name.toLowerCase().includes(P)&&!(j.description||"").toLowerCase().includes(P))return!1}return!0}),A=async(j,P)=>{try{await q.post(`/agents/${encodeURIComponent(j)}/invoke`,{prompt:P}),C(!1),g("")}catch{}},L=async j=>{try{await q.post(`/agents/${encodeURIComponent(j)}/restart`),await z()}catch{}},I=async j=>{if(confirm(`Delete agent "${j}"?`))try{await q.del(`/agents/${encodeURIComponent(j)}`),s(P=>P.filter(B=>B.name!==j)),p(null),i==null||i()}catch{}},k=async j=>{try{const P=await q.post("/agents",j);s(B=>[...B,P]),b(!1),i==null||i()}catch{}};return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search agents…",value:f,onChange:j=>m(j.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>z(),"aria-label":"Refresh",children:a.jsx(_t,{size:16})}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>b(!0),"aria-label":"New agent",children:a.jsx(xt,{size:16})})]}),a.jsxs("div",{className:"mobile-search-scopes",children:[a.jsx("button",{type:"button",className:`mobile-scope-chip ${d?"":"active"}`,onClick:()=>c(""),children:"All"}),ug.map(j=>a.jsx("button",{type:"button",className:`mobile-scope-chip ${d===j?"active":""}`,onClick:()=>c(j),children:j},j))]}),o?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):E.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(Dr,{size:40}),a.jsx("p",{children:"No agents found."})]}):a.jsx("div",{className:"mobile-card-list",children:E.map(j=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>{p(j),n(j.name)},children:[a.jsx("div",{className:"mobile-agent-dot","data-status":j.status||"idle"}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:j.name}),a.jsx("span",{className:"mobile-list-meta",children:j.model||j.mode||"—"})]}),j.category&&a.jsx("span",{className:"mobile-list-badge",style:{color:gf[j.category]||"var(--text-dim)"},children:j.category}),a.jsx("span",{className:"mobile-list-badge","data-status":j.status||"idle",children:j.status||"idle"})]},j.name))}),h&&a.jsx(Dt,{open:!0,onClose:()=>p(null),title:h.name,actions:a.jsxs("div",{className:"mobile-task-detail-actions",children:[a.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>{g(""),C(!0)},children:[a.jsx(Zl,{size:14})," Invoke"]}),(h.isStuck||h.status==="error"||h.status==="working")&&a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>L(h.name),children:[a.jsx(ux,{size:14})," Restart"]}),a.jsx("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>I(h.name),children:a.jsx(_r,{size:14})})]}),children:a.jsxs("div",{className:"mobile-agent-detail",children:[a.jsxs("div",{className:"mobile-agent-detail-status",children:[a.jsx("span",{className:"mobile-agent-dot","data-status":h.status||"idle"}),a.jsx("span",{className:"mobile-agent-detail-status-text",children:h.status||"idle"}),h.category&&a.jsx("span",{className:"mobile-list-badge",style:{color:gf[h.category]},children:h.category})]}),a.jsx("p",{className:"mobile-agent-detail-desc",children:h.description||"No description."}),a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Model"}),a.jsx("span",{className:"mono",children:h.model||"—"})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Mode"}),a.jsx("span",{children:h.mode||"subagent"})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Path"}),a.jsx("span",{className:"mono",style:{fontSize:11},children:h.path})]}),h.lastError&&a.jsxs("div",{className:"mobile-task-detail-row",style:{color:"var(--error)"},children:[a.jsx("span",{children:"Last error"}),a.jsx("span",{children:h.lastError.message})]}),h.tasksTotal!=null&&h.tasksTotal>0&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Success rate"}),a.jsxs("span",{children:[Math.round((h.successRate||0)*100),"%"]})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Last modified"}),a.jsx("span",{children:Sr(h.mtime)})]})]})]})}),a.jsxs(Tn,{open:v,onClose:()=>C(!1),title:`Invoke ${h==null?void 0:h.name}`,actions:a.jsxs("button",{type:"button",className:"mobile-btn",style:{width:"100%"},disabled:!y.trim(),onClick:()=>{h&&A(h.name,y.trim())},children:[a.jsx(Zl,{size:14})," Invoke"]}),children:[a.jsxs("p",{className:"muted",style:{marginBottom:12},children:["Model: ",a.jsx("span",{className:"mono",children:(h==null?void 0:h.model)||"—"})]}),a.jsx("textarea",{className:"mobile-input",rows:5,placeholder:"What should this agent do?",value:y,onChange:j=>g(j.target.value),autoFocus:!0})]}),a.jsx(eC,{open:x,onClose:()=>b(!1),onCreate:k})]})}function eC({open:e,onClose:t,onCreate:n}){const[r,i]=w.useState(""),[l,s]=w.useState(""),[o,u]=w.useState(""),[d,c]=w.useState("subagent"),[f,m]=w.useState("#8b5cf6"),[h,p]=w.useState(""),[x,b]=w.useState(""),[y,g]=w.useState(""),v=C=>{C.preventDefault(),r.trim()&&(n({name:r.trim(),description:l.trim(),model:o,mode:d,color:f,tools:[],tags:x.split(",").map(z=>z.trim()).filter(Boolean),category:h,prompt:y}),i(""),s(""),u(""),c("subagent"),m("#8b5cf6"),p(""),b(""),g(""))};return a.jsx(Tn,{open:e,onClose:t,title:"New Agent",actions:a.jsxs("button",{type:"submit",form:"new-agent-form",className:"mobile-btn",style:{width:"100%"},children:[a.jsx(xt,{size:14})," Create"]}),children:a.jsxs("form",{id:"new-agent-form",onSubmit:v,className:"mobile-task-form",children:[a.jsx("label",{className:"mobile-field-label",children:"Name *"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"my-agent",pattern:"[a-z0-9][a-z0-9-]{0,63}",value:r,onChange:C=>i(C.target.value),autoFocus:!0,required:!0}),a.jsx("label",{className:"mobile-field-label",children:"Description"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"What does this agent do?",value:l,onChange:C=>s(C.target.value)}),a.jsx("label",{className:"mobile-field-label",children:"Model"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"(provider default)",value:o,onChange:C=>u(C.target.value)}),a.jsx("label",{className:"mobile-field-label",children:"Category"}),a.jsxs("select",{className:"mobile-input",value:h,onChange:C=>p(C.target.value),children:[a.jsx("option",{value:"",children:"None"}),ug.map(C=>a.jsx("option",{value:C,children:C},C))]}),a.jsx("label",{className:"mobile-field-label",children:"Tags (comma-separated)"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"tag1, tag2",value:x,onChange:C=>b(C.target.value)})]})})}function tC({sessions:e,opencodeSessions:t,activeSessionId:n,activeOpencodeSessionId:r,activeProject:i,creating:l,onCreateSession:s,onSelectSession:o,onSelectOpencodeSession:u}){const[d,c]=w.useState("all"),[f,m]=w.useState(!1),h=30,p=d==="all"?[...e,...t].sort((g,v)=>Number(v.mtime)-Number(g.mtime)):e,x=f?p:p.slice(0,h),b=t.length,y=g=>{if(g.source==="opencode"){u(g);return}o(g.id)};return a.jsxs("div",{className:"chat-sessions",children:[a.jsxs("div",{className:"chat-sessions-header",children:[a.jsx("span",{className:"chat-sessions-header-title",children:"Sessions"}),a.jsx("span",{className:"chat-sessions-count",children:x.length})]}),b>0&&a.jsxs("div",{className:"chat-sessions-toggle",children:[a.jsx("button",{type:"button",className:`chat-sessions-toggle-btn ${d==="bizar"?"active":""}`,onClick:()=>c("bizar"),children:"Bizar"}),a.jsxs("button",{type:"button",className:`chat-sessions-toggle-btn ${d==="all"?"active":""}`,onClick:()=>c("all"),children:["All (",b," opencode)"]})]}),a.jsxs("button",{type:"button",className:"chat-sessions-new",onClick:s,disabled:l||!i,title:i?"Create new session":"Pick a project first","aria-label":"Create new session",children:[l?a.jsx(Wm,{size:"sm"}):a.jsx(xt,{size:14}),a.jsx("span",{children:l?"Creating…":"New session"})]}),e.length===0?a.jsx("div",{className:"chat-sessions-empty",children:a.jsx(zx,{icon:a.jsx(Jl,{size:20}),title:i?"No sessions yet":"No project",message:i?"Create your first session to start chatting.":"Pick a project in Overview to scope chat sessions.",action:i?a.jsxs(pr,{variant:"primary",size:"sm",onClick:s,loading:l,children:[a.jsx(xt,{size:12})," New session"]}):a.jsxs(pr,{variant:"secondary",size:"sm",onClick:()=>{window.location.hash="#overview"},children:[a.jsx(Pu,{size:12})," Open Overview"]})})}):a.jsx("ul",{className:"chat-sessions-list",children:x.map(g=>{const v=g.source==="opencode",C=v?r===g.id:n===g.id;return a.jsxs("li",{className:`chat-sessions-item ${C?"active":""} ${v?"chat-sessions-item-opencode":""}`,onClick:()=>y(g),title:v?`Open in dashboard: ${g.title||g.id}`:g.id,children:[v&&a.jsx(Z1,{size:10,className:"chat-sessions-item-icon"}),a.jsx("span",{className:"chat-sessions-item-id",children:g.title||g.id}),a.jsx("span",{className:"chat-sessions-item-meta",children:new Date(Number(g.mtime)).toLocaleDateString()})]},v?`oc-${g.id}`:g.id)})}),p.length>h&&a.jsx("button",{type:"button",className:"chat-sessions-show-more",onClick:()=>m(g=>!g),children:f?`Show less (${p.length-h} hidden)`:`Show all ${p.length} sessions`})]})}function nC(e){const{activeSource:t}=e;return a.jsx("div",{className:`chat-composer-wrap chat-composer-source-${t??"none"} legacy`,children:a.jsx("div",{className:"chat-composer-pill",children:a.jsx(I2,{...e})})})}function rC({sessionId:e,messages:t,pinned:n,agent:r,model:i,agents:l,mcps:s,allCommands:o,activeSource:u="bizar",onRename:d,onDelete:c}){const[f,m]=w.useState(!1),[h,p]=w.useState(!1),x=f?l:l.slice(0,4),b=h?o:o.slice(0,4),y=i.includes("/")?i.split("/")[0]:"";return a.jsxs("div",{className:"chat-info",children:[a.jsxs("div",{className:"chat-info-card",children:[a.jsxs("div",{className:"chat-info-card-title",children:[a.jsx(On,{size:14})," Session",a.jsx("span",{className:`chat-source-badge chat-source-${u??"none"}`,style:{marginLeft:"auto"},children:u==="opencode"?"opencode":"bizar chat"})]}),a.jsxs("dl",{className:"env-table",children:[a.jsx("dt",{children:"id"}),a.jsx("dd",{className:"mono",children:e||"Live"}),a.jsx("dt",{children:"Messages"}),a.jsx("dd",{className:"mono",children:t.length}),a.jsx("dt",{children:"Pinned"}),a.jsx("dd",{className:"mono",children:n.size}),a.jsx("dt",{children:"Agent"}),a.jsx("dd",{className:"mono",children:r||"—"}),a.jsx("dt",{children:"Model"}),a.jsx("dd",{className:"mono ellipsis",title:i,children:i||"—"}),y&&a.jsxs(a.Fragment,{children:[a.jsx("dt",{children:"Provider"}),a.jsx("dd",{className:"mono",children:y})]})]}),(d||c)&&a.jsxs("div",{className:"chat-info-actions",children:[d&&a.jsxs("button",{type:"button",className:"btn btn-ghost btn-sm",onClick:d,children:[a.jsx(Au,{size:12,"aria-hidden":!0})," Rename"]}),c&&a.jsxs("button",{type:"button",className:"btn btn-ghost btn-danger btn-sm",onClick:c,children:[a.jsx(_r,{size:12,"aria-hidden":!0})," Delete"]})]})]}),a.jsxs("div",{className:"chat-info-card",children:[a.jsxs("div",{className:"chat-info-card-title",children:[a.jsx(Dr,{size:14})," Agents",a.jsx("span",{className:"chat-info-card-count",children:l.length})]}),a.jsx("ul",{className:"mod-mini-list",children:x.map(g=>a.jsxs("li",{className:"mod-mini",children:[a.jsxs("span",{className:"mod-mini-name",children:["@",g.name]}),a.jsx("span",{className:"mod-mini-meta",children:g.model||g.mode||""})]},g.name))}),l.length>4&&a.jsx("button",{type:"button",className:"chat-info-card-toggle",onClick:()=>m(g=>!g),children:f?"− Show fewer":`+ ${l.length-4} more`})]}),a.jsxs("div",{className:"chat-info-card",children:[a.jsxs("div",{className:"chat-info-card-title",children:[a.jsx(cx,{size:14})," MCPs",a.jsx("span",{className:"chat-info-card-count",children:s.length})]}),a.jsxs("ul",{className:"mod-mini-list",children:[s.length===0?a.jsx("li",{className:"muted",children:"No MCPs configured."}):null,s.map(g=>a.jsxs("li",{className:"mod-mini",children:[a.jsx("span",{className:"mod-mini-name",children:g.id}),a.jsx("span",{className:`mod-mini-pill ${g.enabled?"on":"off"}`,children:g.enabled?"on":"off"})]},g.id))]})]}),a.jsxs("div",{className:"chat-info-card",children:[a.jsxs("button",{type:"button",className:"chat-info-card-title chat-info-card-title-button",onClick:()=>p(g=>!g),"aria-expanded":h,children:[a.jsx(hx,{size:14})," Slash commands",a.jsx("span",{className:"chat-info-card-count",children:o.length}),a.jsx(Ss,{size:12,className:`chat-info-card-chevron ${h?"open":""}`})]}),h&&a.jsx("ul",{className:"mod-mini-list",children:b.map(g=>a.jsxs("li",{children:[a.jsx("code",{children:g.cmd}),a.jsx("span",{className:"muted",children:g.desc})]},g.cmd))})]})]})}function iC({snapshot:e,settings:t,setActiveTab:n,initialTaskId:r,onClearTaskId:i}){const l=bx(),s=kx(),o=M2(e,t,r??"");w.useEffect(()=>{o.setToast({error:O=>l.error(O),success:O=>l.success(O),info:O=>l.info(O),warning:O=>l.warning(O)})},[o,l]);const[u,d]=w.useState(""),[c,f]=w.useState(t.defaultAgent||"odin"),[m,h]=w.useState(t.defaultModel||""),[p,x]=w.useState([]),[b,y]=w.useState(!1),[g,v]=w.useState(!1),C=w.useRef(null),{allCommands:z,suggestions:E,setQuery:A}=R2(e);w.useEffect(()=>{A(u)},[u,A]);const L=()=>{var O;return(O=C.current)==null?void 0:O.click()},I=O=>{const W=O.target.files;if(!W)return;const de=[];for(let ee=0;ee<W.length;ee++)de.push(W[ee].name);x(ee=>{const R=de.filter(V=>!ee.includes(V));return[...ee,...R]}),C.current&&(C.current.value="")},k=async()=>{const O=u.trim();if(!O)return;d(""),A(""),(await o.onSend(O,c,m,p)).ok&&o.jumpToLatest()},j=async()=>{o.busy.create||(await o.onCreateSession(),y(!1))},P=O=>{s.open({title:"Delete message?",children:a.jsx("p",{style:{margin:0},children:"This action cannot be undone."}),footer:a.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[a.jsx(pr,{variant:"secondary",size:"sm",onClick:()=>s.close(),children:"Cancel"}),a.jsx(pr,{variant:"danger",size:"sm",onClick:()=>{s.close(),o.deleteMessage(O)},children:"Delete"})]})})},B=(O,W)=>{s.open({title:"Delete session?",children:a.jsxs("p",{style:{margin:0},children:["Delete ",a.jsx("strong",{children:W}),"? This cannot be undone."]}),footer:a.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[a.jsx(pr,{variant:"secondary",size:"sm",onClick:()=>s.close(),children:"Cancel"}),a.jsx(pr,{variant:"danger",size:"sm",onClick:async()=>{s.close(),await o.deleteSession(O)},children:"Delete"})]})})};return a.jsxs("div",{className:"chat-shell",children:[a.jsx(Ix,{activeProject:e.activeProject,sessionCount:o.sessions.length,sessionsOpen:b,infoOpen:g,onToggleSessions:()=>y(O=>!O),onToggleInfo:()=>v(O=>!O),onOpenOverview:()=>n==null?void 0:n("overview")}),a.jsxs("div",{className:"chat-body",children:[a.jsx("aside",{className:`chat-sessions ${b?"":"chat-sessions-hidden"}`,children:a.jsx(tC,{sessions:o.sessions,opencodeSessions:o.opencodeSessions,activeSessionId:o.sessionId,activeOpencodeSessionId:o.activeOpencodeSessionId,activeProject:e.activeProject,onCreateSession:j,onSelectSession:o.selectBizarSession,onSelectOpencodeSession:O=>o.loadOpencodeSession(O.id),creating:o.busy.create})}),a.jsxs("main",{className:"chat-main",children:[a.jsx(N2,{messages:o.activeSource==="opencode"?o.opencodeMessages:o.bizarMessages,loading:o.loading,activeProject:e.activeProject,sessionId:o.activeSource==="opencode"?o.activeOpencodeSessionId??o.sessionId:o.sessionId,pinned:o.pinned,activeSource:o.activeSource,onPickSuggestion:O=>d(O),onCopy:O=>o.copyMessage(O),onDelete:P,onTogglePin:o.togglePin,onRegenerate:o.onRegenerate}),a.jsx(nC,{agent:c,setAgent:f,model:m,setModel:h,text:u,setText:d,sending:o.sending,activeSource:o.activeSource,onSend:k,attachments:p,setAttachments:x,suggestions:E,onPickSuggestion:O=>d(`${O.split(" ")[0]} `),agents:e.agents||[],onAttach:L,sessionsOpen:b,infoOpen:g}),a.jsx("input",{ref:C,type:"file",multiple:!0,style:{display:"none"},onChange:I})]}),a.jsx("aside",{className:`chat-info ${g?"":"chat-info-hidden"}`,children:a.jsx(rC,{sessionId:o.activeSource==="opencode"?o.activeOpencodeSessionId??o.sessionId:o.sessionId,messages:o.activeSource==="opencode"?o.opencodeMessages:o.bizarMessages,pinned:o.pinned,agent:c,model:m,agents:e.agents||[],mcps:e.mcps||[],allCommands:z,activeSource:o.activeSource,onDelete:()=>{const O=o.activeSource==="opencode"?o.activeOpencodeSessionId:o.sessionId;O&&B(O,O)}})})]})]})}function lC({onBack:e}){const[t,n]=w.useState([]),[r,i]=w.useState(!0),[l,s]=w.useState({}),[o,u]=w.useState(!1),d=async()=>{try{const x=await q.get("/config"),b=Object.entries(x).map(([y,g])=>({key:y,value:g,type:c(g)}));n(b),s(Object.fromEntries(Object.entries(x).map(([y,g])=>[y,g])))}catch{}finally{i(!1)}};w.useEffect(()=>{d()},[]);const c=x=>typeof x=="boolean"?"boolean":typeof x=="number"?"number":typeof x=="string"?"string":Array.isArray(x)?"array":x&&typeof x=="object"?"object":"unknown",f=(x,b)=>{s(y=>({...y,[x]:b}))},m=async()=>{u(!0);try{await q.patch("/config",l),await d()}catch{}finally{u(!1)}},h=(x,b)=>{s(y=>({...y,[x]:b}))},p=x=>{const b=l[x.key];switch(x.type){case"boolean":return a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:!!b,onChange:y=>f(x.key,y.target.checked)}),a.jsx("span",{className:"mobile-toggle-slider"})]});case"number":return a.jsx("input",{className:"mobile-input mobile-input-sm",type:"number",inputMode:"numeric",value:String(b??""),onChange:y=>f(x.key,Number(y.target.value))});case"string":return a.jsx("input",{className:"mobile-input mobile-input-sm",type:"text",value:String(b??""),onChange:y=>f(x.key,y.target.value)});case"object":case"array":return a.jsx("textarea",{className:"mobile-input mobile-input-sm",rows:2,value:JSON.stringify(b??null,null,2),onChange:y=>{try{f(x.key,JSON.parse(y.target.value))}catch{}}});default:return a.jsx("span",{className:"mobile-setting-value mono",children:String(b??"null")})}};return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsxs("span",{style:{fontSize:14,color:"var(--text-muted)",flex:1},children:[t.length," config entries"]}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>d(),"aria-label":"Refresh",children:a.jsx(_t,{size:16})}),a.jsxs("button",{type:"button",className:"mobile-btn",disabled:o,onClick:()=>m(),children:[a.jsx(Fm,{size:14})," ",o?"Saving…":"Save all"]})]}),r?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):t.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(Pr,{size:40}),a.jsx("p",{children:"No config entries."})]}):a.jsx("div",{className:"mobile-config-list",children:t.map(x=>a.jsxs("div",{className:"mobile-config-row",children:[a.jsxs("div",{className:"mobile-config-key",children:[a.jsx("span",{className:"mono",children:x.key}),a.jsx("span",{className:"mobile-config-type",children:x.type})]}),a.jsx("div",{className:"mobile-config-value",children:p(x)}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>h(x.key,x.defaultValue),"aria-label":"Reset to default",title:"Reset",children:a.jsx(ax,{size:14})})]},x.key))})]})}function sC({onBack:e}){const[t,n]=w.useState([]),[r,i]=w.useState(!0),[l,s]=w.useState(null),[o,u]=w.useState(""),d=async()=>{try{const h=await q.get("/history");if(Array.isArray(h.history)){n(h.history);return}if(Array.isArray(h.projects)){const p=new Map;for(const x of h.events||[]){const b=x.projectId;if(!b)continue;const y=p.get(b);(!y||new Date(x.ts).getTime()>new Date(y.ts).getTime())&&p.set(b,x)}n(h.projects.map(x=>{const b=p.get(x.id);return{id:x.id,ts:x.lastAccessed||(b==null?void 0:b.ts)||new Date(0).toISOString(),agent:x.name,taskCount:x.tasks.total,summary:`${x.path} · ${x.tasks.done}/${x.tasks.total} done · ${x.plans} plan${x.plans===1?"":"s"}`,output:b?`${b.kind}${b.text?` — ${b.text}`:""}`:"No recent events."}}));return}n([])}catch{}finally{i(!1)}};w.useEffect(()=>{d()},[]);const c=h=>{if(!h)return"—";const p=Math.floor(h/1e3);if(p<60)return`${p}s`;const x=Math.floor(p/60),b=p%60;return`${x}m ${b}s`},f=h=>new Date(h).toLocaleString(),m=o.trim()?t.filter(h=>{const p=o.toLowerCase();return(h.agent||"session").toLowerCase().includes(p)||(h.summary||"").toLowerCase().includes(p)||(h.output||"").toLowerCase().includes(p)}):t;return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search history…",value:o,onChange:h=>u(h.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>d(),"aria-label":"Refresh",children:a.jsx(_t,{size:16})})]}),r?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):m.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(ka,{size:40}),a.jsx("p",{children:t.length===0?"No history yet.":"No matching sessions."})]}):a.jsx("div",{className:"mobile-card-list",children:m.map(h=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>s(h),children:[a.jsx("div",{className:"mobile-list-icon",children:a.jsx(ka,{size:16})}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:h.agent||"Session"}),a.jsxs("span",{className:"mobile-list-meta",children:[f(h.ts),h.duration?` · ${c(h.duration)}`:"",h.taskCount?` · ${h.taskCount} tasks`:""]})]})]},h.id))}),l&&a.jsxs(Dt,{open:!0,onClose:()=>s(null),title:"Session Detail",children:[a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Agent"}),a.jsx("span",{children:l.agent||"—"})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Started"}),a.jsx("span",{children:f(l.ts)})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Duration"}),a.jsx("span",{children:c(l.duration)})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Tasks"}),a.jsx("span",{children:l.taskCount||0})]})]}),l.summary&&a.jsxs("div",{style:{marginTop:12},children:[a.jsx("h4",{style:{fontSize:12,color:"var(--text-muted)",marginBottom:4},children:"Summary"}),a.jsx("p",{style:{fontSize:13},children:l.summary})]}),l.output&&a.jsxs("div",{style:{marginTop:12},children:[a.jsx("h4",{style:{fontSize:12,color:"var(--text-muted)",marginBottom:4},children:"Output"}),a.jsxs("pre",{className:"mono",style:{fontSize:11,whiteSpace:"pre-wrap",wordBreak:"break-all",background:"var(--bg-elev-2)",padding:8,borderRadius:6},children:[l.output.slice(0,1e3),l.output.length>1e3?"…":""]})]})]})]})}function oC({snapshot:e,onBack:t}){const[n,r]=w.useState(e.mods||[]),[i,l]=w.useState(!e.mods),[s,o]=w.useState(""),[u,d]=w.useState("all"),[c,f]=w.useState(null),m=async()=>{try{const x=await q.get("/mods");r(x.mods||[])}catch{}finally{l(!1)}};w.useEffect(()=>{e.mods?(r(e.mods),l(!1)):m()},[e.mods]);const h=async(x,b)=>{try{await q.patch(`/mods/${encodeURIComponent(x)}`,{enabled:b}),r(y=>y.map(g=>g.id===x?{...g,enabled:b}:g)),(c==null?void 0:c.id)===x&&f(y=>y&&{...y,enabled:b})}catch{}},p=n.filter(x=>{if(u==="enabled"&&!x.enabled||u==="disabled"&&x.enabled)return!1;if(s){const b=s.toLowerCase();return x.name.toLowerCase().includes(b)||x.description.toLowerCase().includes(b)}return!0});return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search mods…",value:s,onChange:x=>o(x.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>m(),"aria-label":"Refresh",children:a.jsx(_t,{size:16})})]}),a.jsx("div",{className:"mobile-search-scopes",children:["all","enabled","disabled"].map(x=>a.jsx("button",{type:"button",className:`mobile-scope-chip ${u===x?"active":""}`,onClick:()=>d(x),children:x.charAt(0).toUpperCase()+x.slice(1)},x))}),i?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):p.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(Pr,{size:40}),a.jsx("p",{children:"No mods found."})]}):a.jsx("div",{className:"mobile-card-list",children:p.map(x=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>f(x),children:[a.jsx("div",{className:"mobile-list-icon",children:a.jsx(Pr,{size:16})}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:x.name}),a.jsxs("span",{className:"mobile-list-meta",children:["v",x.version," · ",x.author]})]}),a.jsx("span",{className:`mobile-list-badge ${x.enabled?"badge-on":"badge-off"}`,children:x.enabled?"on":"off"})]},x.id))}),c&&a.jsx(Dt,{open:!0,onClose:()=>f(null),title:c.name,actions:a.jsx("div",{className:"mobile-task-detail-actions",children:a.jsxs("button",{type:"button",className:"mobile-btn",style:{flex:1},onClick:()=>{c&&h(c.id,!c.enabled)},children:[a.jsx(Om,{size:14})," ",c.enabled?"Disable":"Enable"]})}),children:a.jsxs("div",{className:"mobile-agent-detail",children:[a.jsx("p",{className:"mobile-agent-detail-desc",children:c.description||"No description."}),a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Version"}),a.jsx("span",{className:"mono",children:c.version})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Author"}),a.jsx("span",{children:c.author})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Bizar"}),a.jsx("span",{className:"mono",children:c.bizar})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Type"}),a.jsx("span",{children:c.type})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Permissions"}),a.jsx("span",{children:c.permissions.length})]}),c.installedAt&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Installed"}),a.jsx("span",{children:new Date(c.installedAt).toLocaleDateString()})]})]})]})})]})}function aC({snapshot:e,onNavigate:t}){var s,o,u;const[n,r]=w.useState(""),i=[{id:"artifacts",icon:qn,label:"Plans",count:e.artifacts.length||0,desc:"Visual artifacts with elements & comments"},{id:"agents",icon:Dr,label:"Agents",count:((s=e.agents)==null?void 0:s.length)||0,desc:"The Norse pantheon"},{id:"skills",icon:Pr,label:"Skills",count:null,desc:"Agent capabilities & tools"},{id:"mods",icon:Pr,label:"Mods",count:((o=e.mods)==null?void 0:o.length)||0,desc:"Installed modifications"},{id:"schedules",icon:va,label:"Schedules",count:((u=e.schedules)==null?void 0:u.length)||0,desc:"Cron jobs & automated tasks"},{id:"history",icon:ka,label:"History",count:null,desc:"Past sessions & outputs"},{id:"config",icon:Bm,label:"Config",count:null,desc:"Key-value configuration editor"}],l=n.trim()?i.filter(d=>d.label.toLowerCase().includes(n.toLowerCase())||d.desc.toLowerCase().includes(n.toLowerCase())):i;return a.jsxs("div",{className:"mobile-view",children:[a.jsx("div",{className:"mobile-tasks-toolbar",children:a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search…",value:n,onChange:d=>r(d.target.value),style:{flex:1}})}),a.jsx("div",{className:"mobile-card-list",children:l.map(d=>{const c=d.icon;return a.jsxs("button",{type:"button",className:"mobile-more-nav-item",onClick:()=>t(d.id),children:[a.jsx("div",{className:"mobile-more-nav-icon",children:a.jsx(c,{size:20})}),a.jsxs("div",{className:"mobile-more-nav-content",children:[a.jsxs("span",{className:"mobile-more-nav-label",children:[d.label,d.count!=null&&a.jsx("span",{className:"mobile-more-nav-count",children:d.count})]}),a.jsx("span",{className:"mobile-more-nav-desc",children:d.desc})]}),a.jsx(dd,{size:16,className:"mobile-more-nav-arrow"})]},d.id)})}),a.jsx("div",{className:"mobile-more-footer",children:a.jsxs("a",{href:"/?desktop=1",className:"mobile-more-link",children:["Switch to Desktop ",a.jsx(dd,{size:14})]})})]})}const Ju=[{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 jo(e){var t;return((t=Ju.find(n=>n.id===e))==null?void 0:t.color)||"var(--text-dim)"}function uC({type:e,size:t=12}){switch(e){case"task":return a.jsx(es,{size:t,style:{color:"var(--info)"}});case"note":return a.jsx(md,{size:t,style:{color:"var(--text-dim)"}});case"decision":return a.jsx(es,{size:t,style:{color:"var(--accent)"}});case"question":return a.jsx(K1,{size:t,style:{color:"var(--warning)"}});default:return a.jsx(md,{size:t})}}function cC({slug:e,onBack:t}){const[n,r]=w.useState(null),[i,l]=w.useState(null),[s,o]=w.useState(!0),[u,d]=w.useState(!1),[c,f]=w.useState(null),[m,h]=w.useState(!1),[p,x]=w.useState(!1),[b,y]=w.useState(!1),[g,v]=w.useState(""),C=async()=>{o(!0);try{const I=await q.get(`/plans/${encodeURIComponent(e)}`);r(I.canvas),l(I.meta)}catch{}finally{o(!1)}};w.useEffect(()=>{C()},[e]);const z=async(I,k,j)=>{try{const P=((n==null?void 0:n.elements)||[]).reduce((O,W)=>Math.max(O,W.x||0),40),B=((n==null?void 0:n.elements)||[]).reduce((O,W)=>Math.max(O,W.y||0),40);await q.post(`/plans/${encodeURIComponent(e)}/elements`,{type:I,title:k,content:j,x:20+P,y:20+B,width:240,height:120}),await C(),x(!1)}catch{}},E=async(I,k)=>{try{await q.put(`/plans/${encodeURIComponent(e)}/elements/${encodeURIComponent(I)}`,k),await C(),f(null)}catch{}},A=async I=>{if(confirm("Delete this element?"))try{await q.del(`/plans/${encodeURIComponent(e)}/elements/${encodeURIComponent(I)}`),f(null),await C()}catch{}},L=async(I,k)=>{try{const j=k?`/plans/${encodeURIComponent(e)}/elements/${encodeURIComponent(k)}/comments`:`/plans/${encodeURIComponent(e)}/comments`;await q.post(j,{text:I,elementId:k}),await C(),v(""),y(!1)}catch{}};return s||!n||!i?a.jsx("div",{className:"mobile-view",children:a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading canvas…"})})}):a.jsxs("div",{className:"mobile-view mobile-view-canvas",children:[a.jsxs("div",{className:"mobile-canvas-bar",children:[a.jsxs("div",{className:"mobile-canvas-meta",children:[a.jsx("span",{className:"mobile-canvas-title",children:i.title||e}),a.jsx("span",{className:"mobile-canvas-status","data-status":i.status,children:i.status})]}),a.jsxs("div",{className:"mobile-canvas-actions",children:[a.jsx("button",{type:"button",className:`mobile-icon-btn ${u?"active":""}`,onClick:()=>d(I=>!I),"aria-label":u?"Done editing":"Edit",children:a.jsx(Au,{size:16})}),a.jsxs("button",{type:"button",className:"mobile-icon-btn",onClick:()=>h(I=>!I),"aria-label":"Comments",children:[a.jsx(On,{size:16}),n.comments.length>0&&a.jsx("span",{className:"mobile-canvas-comment-count",children:n.comments.length})]}),u&&a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>x(!0),"aria-label":"Add element",children:a.jsx(xt,{size:16})})]})]}),a.jsxs("div",{className:"mobile-canvas-elements",children:[n.elements.length===0&&a.jsxs("div",{className:"mobile-empty",children:[a.jsx("p",{children:"No elements yet."}),u&&a.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>x(!0),children:[a.jsx(xt,{size:14})," Add Element"]})]}),n.elements.map(I=>a.jsxs("button",{type:"button",className:`mobile-canvas-element ${(c==null?void 0:c.id)===I.id?"selected":""}`,style:{borderColor:jo(I.type)},onClick:()=>{u&&f(I)},"aria-pressed":(c==null?void 0:c.id)===I.id,children:[a.jsxs("div",{className:"mobile-canvas-el-header",style:{background:`${jo(I.type)}18`},children:[a.jsx(uC,{type:I.type,size:12}),a.jsx("span",{className:"mobile-canvas-el-type",style:{color:jo(I.type)},children:I.type}),I.status&&I.status!=="open"&&a.jsx("span",{className:"mobile-canvas-el-status",children:I.status})]}),a.jsx("div",{className:"mobile-canvas-el-title",children:I.title||"Untitled"}),I.content&&a.jsxs("div",{className:"mobile-canvas-el-content",children:[I.content.slice(0,120),I.content.length>120?"…":""]}),a.jsxs("div",{className:"mobile-canvas-el-comments",children:[a.jsx(On,{size:10}),n.comments.filter(k=>k.elementId===I.id).length]})]},I.id))]}),m&&a.jsxs("div",{className:"mobile-canvas-comments",children:[a.jsxs("div",{className:"mobile-canvas-comments-header",children:[a.jsxs("h4",{children:["Comments (",n.comments.length,")"]}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>h(!1),children:a.jsx(Zn,{size:16})})]}),a.jsxs("div",{className:"mobile-canvas-comment-list",children:[n.comments.length===0&&a.jsx("p",{className:"mobile-empty-inline",children:"No comments yet."}),n.comments.map(I=>a.jsxs("div",{className:"mobile-canvas-comment",children:[a.jsxs("div",{className:"mobile-canvas-comment-head",children:[a.jsx("span",{className:"mono",children:I.author}),a.jsx("span",{className:"muted",children:Sr(I.created)})]}),a.jsx("div",{className:"mobile-canvas-comment-text",children:I.text})]},I.id))]}),a.jsxs("div",{className:"mobile-canvas-comment-input",children:[a.jsx("textarea",{className:"mobile-input",rows:2,placeholder:"Add a comment…",value:g,onChange:I=>v(I.target.value)}),a.jsx("button",{type:"button",className:"mobile-btn",disabled:!g.trim(),onClick:()=>{L(g.trim(),null)},children:"Post"})]})]}),c&&a.jsx(Dt,{open:!0,onClose:()=>f(null),title:`Edit ${c.title||c.type}`,actions:a.jsxs("div",{className:"mobile-task-detail-actions",children:[a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>A(c.id),children:[a.jsx(_r,{size:14})," Delete"]}),a.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>y(!0),children:[a.jsx(On,{size:14})," Comment"]})]}),children:a.jsx(dC,{element:c,onSave:I=>E(c.id,I),onClose:()=>f(null)})}),a.jsx(fC,{open:p,onClose:()=>x(!1),onAdd:z}),a.jsx(Tn,{open:b,onClose:()=>y(!1),title:"Add Comment",actions:a.jsxs("button",{type:"button",className:"mobile-btn",style:{width:"100%"},disabled:!g.trim(),onClick:()=>{L(g.trim(),(c==null?void 0:c.id)||null),y(!1)},children:[a.jsx(On,{size:14})," Post"]}),children:a.jsx("textarea",{className:"mobile-input",rows:3,placeholder:"Your comment…",value:g,onChange:I=>v(I.target.value),autoFocus:!0})})]})}function dC({element:e,onSave:t,onClose:n}){const[r,i]=w.useState(e.type),[l,s]=w.useState(e.title||""),[o,u]=w.useState(e.content||""),[d,c]=w.useState(e.status||"open");return a.jsxs("form",{className:"mobile-task-form",onSubmit:f=>{f.preventDefault(),t({type:r,title:l,content:o,status:d}),n()},children:[a.jsx("label",{className:"mobile-field-label",children:"Type"}),a.jsx("select",{className:"mobile-input",value:r,onChange:f=>i(f.target.value),children:Ju.map(f=>a.jsx("option",{value:f.id,children:f.label},f.id))}),a.jsx("label",{className:"mobile-field-label",children:"Title"}),a.jsx("input",{className:"mobile-input",type:"text",value:l,onChange:f=>s(f.target.value)}),a.jsx("label",{className:"mobile-field-label",children:"Status"}),a.jsx("input",{className:"mobile-input",type:"text",value:d,onChange:f=>c(f.target.value),placeholder:"open / done / blocked"}),a.jsx("label",{className:"mobile-field-label",children:"Content (markdown)"}),a.jsx("textarea",{className:"mobile-input",rows:4,value:o,onChange:f=>u(f.target.value)}),a.jsx("button",{type:"submit",className:"mobile-btn",style:{width:"100%",marginTop:8},children:"Save"})]})}function fC({open:e,onClose:t,onAdd:n}){const[r,i]=w.useState("task"),[l,s]=w.useState(""),[o,u]=w.useState(""),d=c=>{c.preventDefault(),l.trim()&&(n(r,l.trim(),o.trim()),s(""),u(""))};return a.jsx(Tn,{open:e,onClose:t,title:"Add Element",actions:a.jsxs("button",{type:"submit",form:"add-el-form",className:"mobile-btn",style:{width:"100%"},children:[a.jsx(xt,{size:14})," Add"]}),children:a.jsxs("form",{id:"add-el-form",onSubmit:d,className:"mobile-task-form",children:[a.jsx("label",{className:"mobile-field-label",children:"Type"}),a.jsx("select",{className:"mobile-input",value:r,onChange:c=>i(c.target.value),children:Ju.map(c=>a.jsx("option",{value:c.id,children:c.label},c.id))}),a.jsx("label",{className:"mobile-field-label",children:"Title *"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"Element title",value:l,onChange:c=>s(c.target.value),autoFocus:!0,required:!0}),a.jsx("label",{className:"mobile-field-label",children:"Content (markdown)"}),a.jsx("textarea",{className:"mobile-input",rows:3,placeholder:"Description…",value:o,onChange:c=>u(c.target.value)})]})})}function hC({snapshot:e,onBack:t,onOpenArtifact:n}){const[r,i]=w.useState(e.artifacts||[]),[l,s]=w.useState(!e.artifacts),[o,u]=w.useState(""),[d,c]=w.useState(!1),[f,m]=w.useState(""),[h,p]=w.useState(""),x=async()=>{try{const g=await q.get("/artifacts");i(g.artifacts||[])}catch{}finally{s(!1)}},b=async()=>{if(f.trim())try{const g=await q.post("/artifacts",{slug:f.trim(),title:h.trim()||void 0});c(!1),m(""),p(""),n(g.slug)}catch{}},y=o.trim()?r.filter(g=>(g.title||g.slug||"").toLowerCase().includes(o.toLowerCase())):r;return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search artifacts…",value:o,onChange:g=>u(g.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>x(),"aria-label":"Refresh",children:a.jsx(_t,{size:16})})]}),a.jsx("div",{style:{marginBottom:12},children:a.jsxs("button",{type:"button",className:"mobile-btn",style:{width:"100%"},onClick:()=>c(!0),children:[a.jsx(xt,{size:14})," New Artifact"]})}),l?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):y.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(qn,{size:40}),a.jsx("p",{children:"No artifacts yet."})]}):a.jsx("div",{className:"mobile-card-list",children:y.map(g=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>n(g.slug),children:[a.jsx("div",{className:"mobile-list-icon",children:a.jsx(qn,{size:16})}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:g.title||g.slug}),a.jsxs("span",{className:"mobile-list-meta",children:[g.status," · ",g.source,g.elementCount!=null?` · ${g.elementCount} elements`:"",g.commentCount!=null?` · ${g.commentCount} comments`:""]})]}),a.jsx("span",{className:"mobile-list-badge","data-status":g.status,children:g.status})]},g.slug))}),a.jsx(Tn,{open:d,onClose:()=>c(!1),title:"New Artifact",actions:a.jsxs("button",{type:"submit",form:"new-plan-form",className:"mobile-btn",style:{width:"100%"},children:[a.jsx(xt,{size:14})," Create"]}),children:a.jsxs("form",{id:"new-plan-form",onSubmit:g=>{g.preventDefault(),b()},className:"mobile-task-form",children:[a.jsx("label",{className:"mobile-field-label",children:"Slug *"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"my-plan",pattern:"[a-z0-9][a-z0-9-]{0,63}",value:f,onChange:g=>m(g.target.value),autoFocus:!0,required:!0}),a.jsx("label",{className:"mobile-field-label",children:"Title (optional)"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"My Artifact",value:h,onChange:g=>p(g.target.value)})]})})]})}const mC=["cron","interval","once"],pC=["command","agent","webhook"],xf=["UTC","America/New_York","America/Los_Angeles","Europe/London","Europe/Berlin","Asia/Tokyo"],cg=Array.from({length:24},(e,t)=>({value:t,label:t===0?"12 AM":t<12?`${t} AM`:t===12?"12 PM":`${t-12} PM`})),gC=Array.from({length:12},(e,t)=>t*5),dg=[{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"}],yC=[{value:"s",label:"sec"},{value:"m",label:"min"},{value:"h",label:"hr"},{value:"d",label:"day"}];function xC({snapshot:e}){var b;const[t,n]=w.useState(e.schedules||[]),[r,i]=w.useState(!e.schedules),[l,s]=w.useState(""),[o,u]=w.useState(null),[d,c]=w.useState({open:!1}),f=async()=>{try{const y=await q.get("/schedules");n(y.schedules||[])}catch{}finally{i(!1)}};w.useEffect(()=>{e.schedules?(n(e.schedules),i(!1)):f()},[e.schedules]);const m=async(y,g)=>{try{await q.patch(`/schedules/${encodeURIComponent(y)}`,{enabled:g}),n(v=>v.map(C=>C.id===y?{...C,enabled:g}:C)),(o==null?void 0:o.id)===y&&u(v=>v&&{...v,enabled:g})}catch{}},h=async y=>{if(confirm("Delete this schedule?"))try{await q.del(`/schedules/${encodeURIComponent(y)}`),n(g=>g.filter(v=>v.id!==y)),(o==null?void 0:o.id)===y&&u(null)}catch{}},p=async y=>{try{await q.post(`/schedules/${encodeURIComponent(y)}/trigger`)}catch{}},x=l.trim()?t.filter(y=>y.name.toLowerCase().includes(l.toLowerCase())):t;return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search schedules…",value:l,onChange:y=>s(y.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>f(),"aria-label":"Refresh",children:a.jsx(_t,{size:16})}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>c({open:!0}),"aria-label":"New schedule",children:a.jsx(xt,{size:16})})]}),r?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):x.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(va,{size:40}),a.jsx("p",{children:"No schedules found."})]}):a.jsx("div",{className:"mobile-card-list",children:x.map(y=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>u(y),children:[a.jsx("div",{className:"mobile-list-icon",children:a.jsx(va,{size:16})}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:y.name}),a.jsxs("span",{className:"mobile-list-meta",children:[wf(y)," ·"," ",y.nextRun?`next ${kf(y.nextRun,y.timezone)}`:"no next run"]})]}),a.jsx("span",{className:`mobile-list-badge ${y.enabled?"badge-on":"badge-off"}`,children:y.enabled?"on":"off"})]},y.id))}),o&&a.jsx(Dt,{open:!0,onClose:()=>u(null),title:o.name,actions:a.jsxs("div",{className:"mobile-task-detail-actions",children:[a.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>{o&&p(o.id)},children:[a.jsx(Zl,{size:14})," Trigger now"]}),a.jsx("button",{type:"button",className:`mobile-btn ${o.enabled?"mobile-btn-secondary":""}`,onClick:()=>{o&&m(o.id,!o.enabled)},children:o.enabled?"Disable":"Enable"}),a.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>{o&&(c({open:!0,initial:o}),u(null))},children:[a.jsx(Au,{size:14})," Edit"]}),a.jsx("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>{o&&h(o.id)},children:a.jsx(_r,{size:14})})]}),children:a.jsx("div",{className:"mobile-agent-detail",children:a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Type"}),a.jsx("span",{children:o.type})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Schedule"}),a.jsx("span",{className:"mono",children:wf(o)||o.schedule})]}),o.timezone&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Timezone"}),a.jsx("span",{className:"mono",children:o.timezone})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Action"}),a.jsxs("span",{children:[o.action.type,": ",o.action.target]})]}),o.action.type==="agent"&&o.action.prompt&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Prompt"}),a.jsx("span",{style:{fontSize:12},children:o.action.prompt})]}),((b=o.budgetCheck)==null?void 0:b.skipIfBudgetLow)&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Budget gate"}),a.jsxs("span",{children:["skip if ≥ ",o.budgetCheck.maxConcurrent??6," concurrent"]})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Next run"}),a.jsx("span",{children:o.nextRun?kf(o.nextRun,o.timezone):"—"})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Last run"}),a.jsx("span",{children:o.lastRun?wC(o.lastRun):"—"})]}),o.lastResult&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Last result"}),a.jsx("span",{style:{fontSize:12},children:o.lastResult})]}),o.lastError&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Last error"}),a.jsx("span",{style:{fontSize:12},children:o.lastError})]})]})})}),a.jsx(kC,{open:d.open,initial:d.initial,onClose:()=>c({open:!1}),onSaved:()=>{c({open:!1}),f()}})]})}function vf(e){var r,i;if(!e)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=e.type==="cron"?fg(e.schedule):null,n=e.type==="interval"?bC(e.schedule):null;return{name:e.name||"",type:e.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:e.type==="once"?SC(e.schedule):"",timezone:e.timezone||"UTC",actionType:e.action.type,actionTarget:e.action.target||"",actionPrompt:e.action.prompt||"",skipIfBudgetLow:!!((r=e.budgetCheck)!=null&&r.skipIfBudgetLow),maxConcurrent:Number.isFinite((i=e.budgetCheck)==null?void 0:i.maxConcurrent)?e.budgetCheck.maxConcurrent:6,enabled:e.enabled!==!1}}function vC(e){if(e.type==="cron")return`${e.cronMinute} ${e.cronHour} * * ${e.cronDow}`;if(e.type==="interval")return`${e.intervalN}${e.intervalUnit}`;if(!e.onceAt)return"";try{return new Date(e.onceAt).toISOString()}catch{return e.onceAt}}function kC({open:e,initial:t,onClose:n,onSaved:r}){const[i,l]=w.useState(()=>vf(t)),[s,o]=w.useState(!1);w.useEffect(()=>{e&&l(vf(t))},[e,t]);const u=(c,f)=>{l(m=>({...m,[c]:f}))},d=async c=>{if(c.preventDefault(),!i.name.trim())return;const f=vC(i);if(f){o(!0);try{const m={name:i.name.trim(),type:i.type,schedule:f,timezone:i.timezone,action:{type:i.actionType,target:i.actionTarget.trim(),...i.actionType==="agent"&&i.actionPrompt.trim()?{prompt:i.actionPrompt.trim()}:{}},budgetCheck:{maxConcurrent:i.maxConcurrent,skipIfBudgetLow:i.skipIfBudgetLow},enabled:i.enabled};t?await q.put(`/schedules/${encodeURIComponent(t.id)}`,m):await q.post("/schedules",m),r()}catch{}finally{o(!1)}}};return a.jsx(Tn,{open:e,onClose:n,title:t?`Edit ${t.name}`:"New schedule",actions:a.jsxs("button",{type:"submit",form:"mobile-schedule-form",className:"mobile-btn",style:{width:"100%"},disabled:s,children:[a.jsx(xt,{size:14})," ",t?"Save":"Create"]}),children:a.jsxs("form",{id:"mobile-schedule-form",onSubmit:d,className:"mobile-task-form",children:[a.jsx("label",{className:"mobile-field-label",children:"Name *"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"Weekly review",value:i.name,onChange:c=>u("name",c.target.value),autoFocus:!0,required:!0}),a.jsx("label",{className:"mobile-field-label",children:"Type"}),a.jsx("select",{className:"mobile-input",value:i.type,onChange:c=>u("type",c.target.value),children:mC.map(c=>a.jsx("option",{value:c,children:c},c))}),i.type==="cron"&&a.jsxs(a.Fragment,{children:[a.jsx("label",{className:"mobile-field-label",children:"Day of week"}),a.jsx("select",{className:"mobile-input",value:i.cronDow,onChange:c=>u("cronDow",c.target.value),children:dg.map(c=>a.jsx("option",{value:c.value,children:c.label},c.value))}),a.jsxs("div",{className:"mobile-form-row",children:[a.jsxs("div",{style:{flex:1},children:[a.jsx("label",{className:"mobile-field-label",children:"Hour"}),a.jsx("select",{className:"mobile-input",value:String(i.cronHour),onChange:c=>u("cronHour",parseInt(c.target.value,10)),children:cg.map(c=>a.jsx("option",{value:String(c.value),children:c.label},c.value))})]}),a.jsxs("div",{style:{flex:1},children:[a.jsx("label",{className:"mobile-field-label",children:"Minute"}),a.jsx("select",{className:"mobile-input",value:String(i.cronMinute),onChange:c=>u("cronMinute",parseInt(c.target.value,10)),children:gC.map(c=>a.jsx("option",{value:String(c),children:String(c).padStart(2,"0")},c))})]})]})]}),i.type==="interval"&&a.jsxs("div",{className:"mobile-form-row",children:[a.jsxs("div",{style:{flex:1},children:[a.jsx("label",{className:"mobile-field-label",children:"Every"}),a.jsx("input",{className:"mobile-input",type:"number",min:1,value:i.intervalN,onChange:c=>u("intervalN",parseInt(c.target.value,10)||1)})]}),a.jsxs("div",{style:{flex:1},children:[a.jsx("label",{className:"mobile-field-label",children:"Unit"}),a.jsx("select",{className:"mobile-input",value:i.intervalUnit,onChange:c=>u("intervalUnit",c.target.value),children:yC.map(c=>a.jsx("option",{value:c.value,children:c.label},c.value))})]})]}),i.type==="once"&&a.jsxs(a.Fragment,{children:[a.jsx("label",{className:"mobile-field-label",children:"Run at"}),a.jsx("input",{className:"mobile-input",type:"datetime-local",value:i.onceAt,onChange:c=>u("onceAt",c.target.value)})]}),a.jsx("label",{className:"mobile-field-label",children:"Timezone"}),a.jsx("select",{className:"mobile-input",value:xf.includes(i.timezone)?i.timezone:"UTC",onChange:c=>u("timezone",c.target.value),children:xf.map(c=>a.jsx("option",{value:c,children:c},c))}),a.jsx("label",{className:"mobile-field-label",children:"Action type"}),a.jsx("select",{className:"mobile-input",value:i.actionType,onChange:c=>u("actionType",c.target.value),children:pC.map(c=>a.jsx("option",{value:c,children:c},c))}),a.jsx("label",{className:"mobile-field-label",children:"Target"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:i.actionType==="webhook"?"https://...":i.actionType==="agent"?"agent or task ref":"echo hello",value:i.actionTarget,onChange:c=>u("actionTarget",c.target.value)}),i.actionType==="agent"&&a.jsxs(a.Fragment,{children:[a.jsx("label",{className:"mobile-field-label",children:"Prompt"}),a.jsx("textarea",{className:"mobile-input",rows:3,placeholder:"What should the agent do?",value:i.actionPrompt,onChange:c=>u("actionPrompt",c.target.value)})]}),a.jsxs("fieldset",{className:"mobile-budget-card",children:[a.jsx("legend",{children:"Budget pre-flight"}),a.jsxs("label",{className:"mobile-checkbox-row",children:[a.jsx("input",{type:"checkbox",checked:i.skipIfBudgetLow,onChange:c=>u("skipIfBudgetLow",c.target.checked)}),a.jsx("span",{children:"Skip if too many bg tasks are running"})]}),a.jsx("label",{className:"mobile-field-label",children:"Cap"}),a.jsx("input",{className:"mobile-input",type:"number",min:1,max:64,value:i.maxConcurrent,onChange:c=>u("maxConcurrent",parseInt(c.target.value,10)||6),disabled:!i.skipIfBudgetLow})]}),a.jsxs("label",{className:"mobile-checkbox-row",children:[a.jsx("input",{type:"checkbox",checked:i.enabled,onChange:c=>u("enabled",c.target.checked)}),a.jsx("span",{children:"Enabled"})]})]})})}function wC(e){const t=Date.now()-new Date(e).getTime();return t<6e4?"just now":t<36e5?`${Math.floor(t/6e4)}m ago`:t<864e5?`${Math.floor(t/36e5)}h ago`:new Date(e).toLocaleDateString()}function kf(e,t){try{return new Date(e).toLocaleString(void 0,{timeZone:t||void 0,weekday:"short",hour:"numeric",minute:"2-digit",month:"short",day:"numeric"})}catch{return new Date(e).toLocaleString()}}function fg(e){if(typeof e!="string")return null;const t=e.trim().split(/\s+/);if(t.length!==5)return null;const[n,r,,,i]=t,l=parseInt(n,10),s=parseInt(r,10);return!Number.isFinite(l)||!Number.isFinite(s)||n!==String(l)||r!==String(s)?null:{minute:l,hour:s,dow:i==="*"?"*":Number.isFinite(parseInt(i,10))?i:"*"}}function bC(e){if(typeof e!="string")return null;const t=/^(\d+)([smhd])$/i.exec(e.trim());return t?{n:parseInt(t[1],10),unit:t[2].toLowerCase()}:null}function SC(e){if(!e)return"";try{const t=new Date(e);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 wf(e){var l,s;if(e.type!=="cron")return e.schedule;const t=fg(e.schedule);if(!t)return e.schedule;const n=((l=dg.find(o=>o.value===t.dow))==null?void 0:l.label)||t.dow,r=((s=cg.find(o=>o.value===t.hour))==null?void 0:s.label)||`${t.hour}`,i=String(t.minute).padStart(2,"0");return n==="Every day"?`Every day ${r} :${i}`:`Every ${n} ${r} :${i}`}const CC=["all","tasks","agents","artifacts","projects","settings"],jC={tasks:es,agents:Dr,plans:qn,projects:Pu,settings:Pr};function NC({open:e,onClose:t,onNavigate:n}){const[r,i]=w.useState(""),[l,s]=w.useState("all"),[o,u]=w.useState([]),[d,c]=w.useState(!1),f=w.useRef(null);w.useEffect(()=>{e&&(i(""),u([]),requestAnimationFrame(()=>{var p;return(p=f.current)==null?void 0:p.focus()}))},[e]),w.useEffect(()=>{if(!r.trim()){u([]);return}const p=setTimeout(async()=>{c(!0);try{const x=await q.get(`/search?q=${encodeURIComponent(r)}&scope=${l}`);u(x.results||[])}catch{u([])}finally{c(!1)}},250);return()=>clearTimeout(p)},[r,l]);const m=p=>{const x=p.item,b=x.id||x.slug||x.name||"";n(p.type,b),t()},h=o.reduce((p,x)=>(p[x.type]||(p[x.type]=[]),p[x.type].push(x),p),{});return a.jsx(Tn,{open:e,onClose:t,title:"Search",children:a.jsxs("div",{className:"mobile-search-container",children:[a.jsxs("div",{className:"mobile-search-input-row",children:[a.jsx(hd,{size:16,style:{color:"var(--text-muted)",flexShrink:0}}),a.jsx("input",{ref:f,className:"mobile-search-field",type:"text",placeholder:"Search…",value:r,onChange:p=>i(p.target.value),enterKeyHint:"search",onKeyDown:p=>{p.key==="Escape"&&t(),p.key==="Enter"&&o.length>0&&m(o[0])}}),r&&a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>i(""),"aria-label":"Clear",children:a.jsx(Zn,{size:16})})]}),a.jsx("div",{className:"mobile-search-scopes",children:CC.map(p=>a.jsx("button",{type:"button",className:`mobile-scope-chip ${l===p?"active":""}`,onClick:()=>s(p),children:p==="all"?"All":p.charAt(0).toUpperCase()+p.slice(1)},p))}),a.jsxs("div",{className:"mobile-search-results",children:[d&&a.jsx("div",{className:"mobile-search-loading",children:"Searching…"}),!d&&r&&o.length===0&&a.jsxs("div",{className:"mobile-empty",children:[a.jsx(hd,{size:32}),a.jsx("p",{children:"No results found"})]}),!d&&!r&&a.jsx("div",{className:"mobile-empty",children:a.jsx("p",{children:"Type to search across tasks, agents, plans, and more."})}),Object.entries(h).map(([p,x])=>{const b=jC[p]||qn;return a.jsxs("div",{className:"mobile-search-group",children:[a.jsxs("h4",{className:"mobile-search-group-title",children:[a.jsx(b,{size:12})," ",p.charAt(0).toUpperCase()+p.slice(1)," (",x.length,")"]}),x.map((y,g)=>{const v=y.item;return a.jsxs("button",{type:"button",className:"mobile-search-result-item",onClick:()=>m(y),children:[a.jsx("span",{className:"mobile-search-result-title",children:v.title||v.name||v.slug||"(unnamed)"}),v.description&&a.jsx("span",{className:"mobile-search-result-meta",children:v.description.slice(0,80)})]},g)})]},p)})]})]})})}const EC=[{id:"dark",label:"Dark",Icon:ix},{id:"light",label:"Light",Icon:fx},{id:"system",label:"System",Icon:rx}],TC=[{name:"Purple",accent:"#8b5cf6"},{name:"Blue",accent:"#3b82f6"},{name:"Green",accent:"#10b981"},{name:"Orange",accent:"#f97316"},{name:"Red",accent:"#ef4444"},{name:"Pink",accent:"#ec4899"},{name:"Cyan",accent:"#06b6d4"},{name:"Mono",accent:"#6b7280"}];function IC(e){if(e<=0)return"expired";const t=Math.floor(e/1e3),n=Math.floor(t/60),r=t%60;return`${n}:${String(r).padStart(2,"0")}`}function zC({settings:e,snapshot:t,onRefresh:n}){var z,E,A,L,I,k;const[r,i]=w.useState(e),[l,s]=w.useState(!1),[o,u]=w.useState(!1),[d,c]=w.useState(null),[f,m]=w.useState(!1),[h,p]=w.useState(Date.now());w.useEffect(()=>{i(e),s(!1),e.theme&&ui(e.theme)},[e]),w.useEffect(()=>{if(!d)return;const j=setInterval(()=>p(Date.now()),1e3);return()=>clearInterval(j)},[d]);const x=j=>{i(P=>{const B={...P,theme:{...P.theme,...j}};return ts(B.theme),ui(B.theme),B}),s(!0)},b=(j,P)=>{i(B=>({...B,[j]:P})),s(!0)},y=async()=>{u(!0);try{const j=await q.put("/settings",r);i(j.data),s(!1),ts(j.data.theme),ui(j.data.theme),n()}catch{}finally{u(!1)}},g=async()=>{m(!0);try{const j=await q.post("/pair/start");c(j)}catch{}finally{m(!1)}},v=d?d.expiresAt-h:0,C=d!=null&&v<=0;return a.jsxs("div",{className:"mobile-view",children:[l&&a.jsxs("div",{className:"mobile-settings-save-bar",children:[a.jsx("span",{children:"Unsaved changes"}),a.jsxs("button",{type:"button",className:"mobile-btn",disabled:o,onClick:y,children:[a.jsx(Fm,{size:14})," ",o?"Saving…":"Save"]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"Appearance"}),a.jsxs("div",{className:"mobile-card",children:[a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Theme"}),a.jsx("div",{className:"mobile-theme-btns",children:EC.map(({id:j,label:P,Icon:B})=>a.jsxs("button",{type:"button",className:`mobile-theme-btn ${r.theme.mode===j?"active":""}`,onClick:()=>x({mode:j}),children:[a.jsx(B,{size:14})," ",P]},j))})]}),a.jsxs("div",{className:"mobile-setting-row",style:{flexDirection:"column",alignItems:"flex-start",gap:8},children:[a.jsx("span",{className:"mobile-setting-label",children:"Accent color"}),a.jsx("div",{className:"mobile-accent-swatches",children:TC.map(j=>a.jsx("button",{type:"button",className:`mobile-accent-swatch ${r.theme.accent===j.accent?"active":""}`,style:{background:j.accent},onClick:()=>x({accent:j.accent}),title:j.name},j.name))})]}),a.jsxs("div",{className:"mobile-setting-row",style:{flexDirection:"column",alignItems:"flex-start",gap:8},children:[a.jsxs("span",{className:"mobile-setting-label",children:["Font size: ",r.theme.fontSize,"px"]}),a.jsx("input",{type:"range",min:12,max:20,value:r.theme.fontSize,onChange:j=>x({fontSize:Number(j.target.value)}),style:{width:"100%"}})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Compact mode"}),a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:r.theme.compactMode,onChange:j=>x({compactMode:j.target.checked})}),a.jsx("span",{className:"mobile-toggle-slider"})]})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Animations"}),a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:r.theme.animations,onChange:j=>x({animations:j.target.checked})}),a.jsx("span",{className:"mobile-toggle-slider"})]})]})]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"Chat Defaults"}),a.jsxs("div",{className:"mobile-card",children:[a.jsx("label",{className:"mobile-field-label",children:"Default Agent"}),a.jsx("select",{className:"mobile-input",value:r.defaultAgent||"odin",onChange:j=>b("defaultAgent",j.target.value),children:((t==null?void 0:t.agents)||[]).map(j=>a.jsxs("option",{value:j.name,children:["@",j.name]},j.name))}),a.jsx("label",{className:"mobile-field-label",style:{marginTop:8},children:"Default Model"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"(auto)",value:r.defaultModel||"",onChange:j=>b("defaultModel",j.target.value)})]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"Notifications"}),a.jsxs("div",{className:"mobile-card",children:[a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Agent completion"}),a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:!!r.notifications.onAgentComplete,onChange:j=>{i(P=>({...P,notifications:{...P.notifications,onAgentComplete:j.target.checked}})),s(!0)}}),a.jsx("span",{className:"mobile-toggle-slider"})]})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Plan approval"}),a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:!!r.notifications.onPlanApproval,onChange:j=>{i(P=>({...P,notifications:{...P.notifications,onPlanApproval:j.target.checked}})),s(!0)}}),a.jsx("span",{className:"mobile-toggle-slider"})]})]})]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"Agent Behavior"}),a.jsxs("div",{className:"mobile-card",children:[a.jsx("label",{className:"mobile-field-label",children:"Max parallel agents"}),a.jsx("input",{className:"mobile-input",type:"number",inputMode:"numeric",min:1,max:20,value:((z=r.agents)==null?void 0:z.maxParallel)??6,onChange:j=>{i(P=>({...P,agents:{...P.agents,maxParallel:Math.max(1,Math.min(20,parseInt(j.target.value,10)||6))}})),s(!0)}}),a.jsx("label",{className:"mobile-field-label",style:{marginTop:8},children:"Stuck threshold (ms)"}),a.jsx("input",{className:"mobile-input",type:"number",inputMode:"numeric",min:6e4,max:36e5,step:6e4,value:((E=r.agents)==null?void 0:E.stuckThresholdMs)??6e5,onChange:j=>{i(P=>({...P,agents:{...P.agents,stuckThresholdMs:Math.max(6e4,parseInt(j.target.value,10)||6e5)}})),s(!0)}}),a.jsxs("div",{className:"mobile-setting-row",style:{marginTop:8},children:[a.jsx("span",{className:"mobile-setting-label",children:"Auto-restart stuck agents"}),a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:!!((A=r.agents)!=null&&A.autoRestart),onChange:j=>{i(P=>({...P,agents:{...P.agents,autoRestart:j.target.checked}})),s(!0)}}),a.jsx("span",{className:"mobile-toggle-slider"})]})]})]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"Tailscale Serve"}),a.jsx("div",{className:"mobile-card",children:a.jsxs("p",{className:"muted",style:{fontSize:13},children:["Use ",a.jsx("code",{children:"bizar service"})," commands in the terminal to configure Tailscale serve."]})})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsxs("h3",{className:"mobile-section-title",children:[a.jsx(dx,{size:14})," Companion App"]}),a.jsxs("div",{className:"mobile-card",children:[!d&&a.jsxs("button",{type:"button",className:"mobile-btn",onClick:g,disabled:f,style:{width:"100%"},children:[a.jsx(ox,{size:14})," ",f?"Generating…":"Generate QR Code"]}),d&&!C&&a.jsxs("div",{style:{textAlign:"center"},children:[a.jsx("div",{style:{background:"#fff",padding:12,borderRadius:12,display:"inline-block"},children:a.jsx(ag,{value:d.qrPayload,size:180,level:"M"})}),a.jsxs("div",{style:{marginTop:8,fontSize:12},children:["Expires in ",a.jsx("strong",{children:IC(v)})]}),a.jsx("div",{className:"mono",style:{fontSize:10,wordBreak:"break-all",marginTop:4},children:d.publicUrl})]}),d&&C&&a.jsxs("button",{type:"button",className:"mobile-btn",onClick:g,style:{width:"100%"},children:[a.jsx(_t,{size:14})," Generate new QR"]})]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"About"}),a.jsxs("div",{className:"mobile-card",children:[a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Version"}),a.jsx("span",{className:"mobile-setting-value mono",children:((L=r.about)==null?void 0:L.version)||"—"})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Agents"}),a.jsx("span",{className:"mobile-setting-value",children:((I=t==null?void 0:t.agents)==null?void 0:I.length)||0})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Tasks"}),a.jsx("span",{className:"mobile-setting-value",children:((k=t==null?void 0:t.tasks)==null?void 0:k.length)||0})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Plans"}),a.jsx("span",{className:"mobile-setting-value",children:(t==null?void 0:t.artifacts.length)||0})]})]})]}),a.jsx("div",{className:"mobile-view-footer",children:a.jsx("a",{href:"/?desktop=1",className:"mobile-btn mobile-btn-secondary",children:"Switch to Desktop"})})]})}const PC=["languages","framework","design","testing","devops","data","security","integration"];function AC({snapshot:e,onBack:t}){const[n,r]=w.useState([]),[i,l]=w.useState(!0),[s,o]=w.useState(""),[u,d]=w.useState(""),[c,f]=w.useState(null),m=async()=>{try{const x=await q.get("/skills");r(x.skills||[])}catch{}finally{l(!1)}};w.useEffect(()=>{m()},[]);const h=async(x,b)=>{try{await q.patch(`/skills/${encodeURIComponent(x)}`,{enabled:b}),r(y=>y.map(g=>g.id===x?{...g,enabled:b}:g)),(c==null?void 0:c.id)===x&&f(y=>y&&{...y,enabled:b})}catch{}},p=n.filter(x=>{if(u&&x.category!==u)return!1;if(s){const b=s.toLowerCase();return x.name.toLowerCase().includes(b)||x.description.toLowerCase().includes(b)}return!0});return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search skills…",value:s,onChange:x=>o(x.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>m(),"aria-label":"Refresh",children:a.jsx(_t,{size:16})})]}),a.jsxs("div",{className:"mobile-search-scopes",children:[a.jsx("button",{type:"button",className:`mobile-scope-chip ${u?"":"active"}`,onClick:()=>d(""),children:"All"}),PC.map(x=>a.jsx("button",{type:"button",className:`mobile-scope-chip ${u===x?"active":""}`,onClick:()=>d(x),children:x},x))]}),i?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):p.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(Jl,{size:40}),a.jsx("p",{children:"No skills found."})]}):a.jsx("div",{className:"mobile-card-list",children:p.map(x=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>f(x),children:[a.jsx("div",{className:"mobile-list-icon",children:a.jsx(Jl,{size:16})}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:x.name}),a.jsxs("span",{className:"mobile-list-meta",children:[x.category," · v",x.version]})]}),a.jsx("span",{className:`mobile-list-badge ${x.enabled?"badge-on":"badge-off"}`,children:x.enabled?"on":"off"})]},x.id))}),c&&a.jsx(Dt,{open:!0,onClose:()=>f(null),title:c.name,actions:a.jsxs("button",{type:"button",className:`mobile-btn ${c.enabled?"mobile-btn-secondary":""}`,style:{width:"100%"},onClick:()=>{c&&h(c.id,!c.enabled)},children:[a.jsx(Om,{size:14})," ",c.enabled?"Disable":"Enable"]}),children:a.jsxs("div",{className:"mobile-agent-detail",children:[a.jsx("p",{className:"mobile-agent-detail-desc",children:c.description||"No description."}),a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Category"}),a.jsx("span",{children:c.category})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Version"}),a.jsx("span",{className:"mono",children:c.version})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Source"}),a.jsx("span",{children:c.source})]}),c.tags.length>0&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Tags"}),a.jsx("span",{children:c.tags.join(", ")})]})]})]})})]})}const MC=["queued","doing","blocked","done"],dl={queued:"Queued",doing:"Doing",blocked:"Blocked",done:"Done"},bf={queued:"doing",doing:"done",blocked:"queued",done:"queued"};function LC(e){const t=e.metadata??{};return!!(t.sessionId||t.bgInstanceId)}function RC(e){var n;const t=e.metadata??{};return!!((n=t.artifactIds)!=null&&n.length||t.artifactId)}function Sf({snapshot:e,onRefresh:t,selectedTaskId:n,onCloseDetail:r,onOpenChat:i,onOpenArtifact:l}){var oe,Ne;const[s,o]=w.useState(e.tasks||[]),[u,d]=w.useState(!e.tasks),[c,f]=w.useState(""),[m,h]=w.useState("queued"),[p,x]=w.useState(null),[b,y]=w.useState(!1),[g,v]=w.useState(null),[C,z]=w.useState([]),[E,A]=w.useState(""),[L,I]=w.useState(null),[k,j]=w.useState(!1),[P,B]=w.useState(""),[O,W]=w.useState("updated");w.useEffect(()=>{var H;if(e.tasks&&(o(e.tasks),d(!1)),n){const te=(H=e.tasks)==null?void 0:H.find(re=>re.id===n);te&&x(te)}},[e.tasks,n]),w.useEffect(()=>{if(n){const H=s.find(te=>te.id===n);H&&x(H)}},[n,s]);const de=async()=>{try{const H=await q.get("/tasks");o(Array.isArray(H)?H:[])}catch{}finally{d(!1)}},ee=async(H,te)=>{o(re=>re.map(Se=>Se.id===H?{...Se,status:te}:Se)),(p==null?void 0:p.id)===H&&x(re=>re&&{...re,status:te});try{await q.patch(`/tasks/${encodeURIComponent(H)}/status`,{status:te})}catch{await de()}},R=async H=>{if(confirm("Delete this task?"))try{await q.del(`/tasks/${encodeURIComponent(H)}`),o(te=>te.filter(re=>re.id!==H)),(p==null?void 0:p.id)===H&&x(null)}catch{await de()}},V=async H=>{try{await q.post(`/tasks/${encodeURIComponent(H)}/archive`),o(te=>te.filter(re=>re.id!==H)),(p==null?void 0:p.id)===H&&x(null)}catch{}},Y=[...s.filter(H=>{var te,re;if(c.trim()){const Se=c.toLowerCase();if(!(H.title||"").toLowerCase().includes(Se)&&!(H.description||"").toLowerCase().includes(Se))return!1}if(P.trim()){const Se=P==="mine"?((re=(te=e.settings)==null?void 0:te.data)==null?void 0:re.defaultAgent)||DC(e):P.replace(/^@/,"");if((H.assignee||"").toLowerCase()!==Se.toLowerCase())return!1}return!0})].sort((H,te)=>{switch(O){case"priority":{const re={high:0,normal:1,low:2};return(re[H.priority]??1)-(re[te.priority]??1)}case"created":return new Date(te.createdAt).getTime()-new Date(H.createdAt).getTime();case"updated":default:return new Date(te.updatedAt).getTime()-new Date(H.updatedAt).getTime()}}),ie=Y.filter(H=>H.status===m),N=e.agents||[],ge=async(H,te,re,Se)=>{try{const Ot=await q.post("/tasks",{title:H,description:te,assignee:re||null,priority:Se});o(ln=>[Ot,...ln]),y(!1)}catch{}},Le=async H=>{j(!0),A(""),I(null),v(H);try{const re=((await q.get(`/tasks/${encodeURIComponent(H)}/artifacts`)).artifacts||[]).map(Se=>Se.id);if(z(re),re.length>0){const[Se,Ot]=await Promise.all([q.get(`/artifacts/${encodeURIComponent(re[0])}`),fetch(q.urlWithToken(`/artifacts/${encodeURIComponent(re[0])}/content`)).then(ln=>ln.text())]);I(Se),A(Ot)}}catch{}finally{j(!1)}};return u?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):a.jsxs("div",{className:"mobile-view mobile-view-tasks",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search tasks…",value:c,onChange:H=>f(H.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>de(),"aria-label":"Refresh",children:a.jsx(_t,{size:16})})]}),a.jsxs("div",{className:"mobile-tasks-filters",children:[a.jsxs("select",{className:"mobile-filter-select",value:P,onChange:H=>B(H.target.value),children:[a.jsx("option",{value:"",children:"All"}),a.jsx("option",{value:"mine",children:"Mine"}),N.map(H=>a.jsxs("option",{value:`@${H.name}`,children:["@",H.name]},H.name))]}),a.jsxs("select",{className:"mobile-filter-select",value:O,onChange:H=>W(H.target.value),children:[a.jsx("option",{value:"updated",children:"Updated"}),a.jsx("option",{value:"created",children:"Created"}),a.jsx("option",{value:"priority",children:"Priority"})]})]}),a.jsx("div",{className:"mobile-kanban-tabs",children:MC.map(H=>{const te=Y.filter(re=>re.status===H).length;return a.jsxs("button",{type:"button",className:`mobile-kanban-tab ${m===H?"active":""}`,onClick:()=>h(H),children:[dl[H]," (",te,")"]},H)})}),a.jsxs("div",{className:"mobile-card-list",children:[ie.length===0&&a.jsxs("div",{className:"mobile-empty mobile-empty-compact",children:[a.jsxs("p",{children:["No ",dl[m].toLowerCase()," tasks."]}),a.jsx("p",{className:"muted",children:"Create one or switch columns."})]}),ie.map(H=>{var te;return a.jsxs("button",{type:"button",className:"mobile-task-card",onClick:()=>x(H),children:[a.jsx("div",{className:"priority-dot",style:{background:gx[H.priority]||"var(--info)"}}),a.jsxs("div",{className:"task-content",children:[a.jsx("div",{className:"task-title",children:H.title}),a.jsxs("div",{className:"task-meta",children:[H.assignee?`@${H.assignee}`:"unassigned"," · ",Sr(H.updatedAt||H.createdAt),(te=H.dependencies)!=null&&te.length?` · ${H.dependencies.length} deps`:""]})]})]},H.id)})]}),a.jsx("button",{type:"button",className:"mobile-fab",onClick:()=>y(!0),"aria-label":"Add task",children:a.jsx(xt,{size:24})}),a.jsx(Dt,{open:!!p,onClose:()=>{x(null),r==null||r()},title:"Task Detail",actions:p&&a.jsxs("div",{className:"mobile-task-detail-actions",children:[p.status!=="done"&&a.jsxs("button",{type:"button",className:"mobile-btn",style:{flex:1},onClick:()=>{p&&ee(p.id,bf[p.status])},children:["Move to ",dl[bf[p.status]||"queued"]]}),a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>{p&&V(p.id)},children:[a.jsx(V1,{size:14})," Archive"]}),LC(p)&&a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>{i==null||i(p.id)},children:[a.jsx(On,{size:14})," Chat"]}),RC(p)&&a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>{Le(p.id)},children:[a.jsx(qn,{size:14})," Artifact"]}),a.jsx("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>{p&&R(p.id)},children:a.jsx(_r,{size:14})})]}),children:p&&a.jsxs("div",{className:"mobile-task-detail",children:[a.jsxs("div",{className:"mobile-task-detail-header",children:[a.jsx("span",{className:`mobile-task-status-badge status-${p.status}`,children:dl[p.status]||p.status}),a.jsx("span",{className:`mobile-task-priority priority-${p.priority}`,children:p.priority})]}),a.jsx("h3",{className:"mobile-task-detail-title",children:p.title}),p.description&&a.jsx("p",{className:"mobile-task-detail-desc",children:p.description}),a.jsxs("div",{className:"mobile-task-detail-meta",children:[p.assignee&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Assignee"}),a.jsxs("span",{children:["@",p.assignee]})]}),p.dueDate&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Due"}),a.jsx("span",{children:new Date(p.dueDate).toLocaleDateString()})]}),p.timeSpent!=null&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Time spent"}),a.jsxs("span",{children:[Math.round(p.timeSpent/6e4),"min"]})]}),(oe=p.dependencies)!=null&&oe.length?a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Dependencies"}),a.jsx("span",{children:p.dependencies.length})]}):null,(Ne=p.comments)!=null&&Ne.length?a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Comments"}),a.jsx("span",{children:p.comments.length})]}):null,a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Created"}),a.jsx("span",{children:Sr(p.createdAt)})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Updated"}),a.jsx("span",{children:Sr(p.updatedAt)})]})]})]})}),a.jsx(_C,{open:b,onClose:()=>y(!1),onCreate:ge,agents:N}),a.jsx(Dt,{open:!!g,onClose:()=>{v(null),A(""),I(null)},title:(L==null?void 0:L.name)||"Artifact",actions:C.length>1?a.jsx("div",{className:"mobile-task-detail-actions",children:C.map((H,te)=>a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",style:{flex:1},onClick:()=>{j(!0),Promise.all([q.get(`/artifacts/${encodeURIComponent(H)}`),fetch(q.urlWithToken(`/artifacts/${encodeURIComponent(H)}/content`)).then(re=>re.text())]).then(([re,Se])=>{I(re),A(Se),j(!1)}).catch(()=>j(!1))},children:["Artifact ",te+1]},H))}):null,children:a.jsx("div",{className:"mobile-artifact-viewer",children:k?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading artifact…"})}):E?a.jsx("iframe",{srcDoc:E,className:"mobile-artifact-iframe",sandbox:"allow-scripts allow-forms allow-popups allow-same-origin",title:(L==null?void 0:L.name)||"Artifact",loading:"lazy"}):a.jsxs("div",{className:"mobile-empty",children:[a.jsx(qn,{size:32}),a.jsx("p",{className:"muted",children:"No artifact content available."})]})})})]})}function DC(e){var t,n;return((n=(t=e.settings)==null?void 0:t.data)==null?void 0:n.defaultAgent)||"odin"}function _C({open:e,onClose:t,onCreate:n,agents:r}){const[i,l]=w.useState(""),[s,o]=w.useState(""),[u,d]=w.useState(""),[c,f]=w.useState("normal"),m=h=>{h.preventDefault(),i.trim()&&(n(i.trim(),s.trim(),u,c),l(""),o(""),d(""),f("normal"))};return a.jsx(Tn,{open:e,onClose:t,title:"New Task",actions:a.jsxs("button",{type:"submit",form:"new-task-form",className:"mobile-btn",style:{width:"100%"},children:[a.jsx(xt,{size:14})," Create Task"]}),children:a.jsxs("form",{id:"new-task-form",onSubmit:m,className:"mobile-task-form",children:[a.jsx("label",{className:"mobile-field-label",children:"Title *"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"Task title",value:i,onChange:h=>l(h.target.value),autoFocus:!0,required:!0}),a.jsx("label",{className:"mobile-field-label",children:"Description"}),a.jsx("textarea",{className:"mobile-input",rows:3,placeholder:"Optional description",value:s,onChange:h=>o(h.target.value)}),a.jsx("label",{className:"mobile-field-label",children:"Assignee"}),a.jsxs("select",{className:"mobile-input",value:u,onChange:h=>d(h.target.value),children:[a.jsx("option",{value:"",children:"Unassigned"}),r.map(h=>a.jsxs("option",{value:h.name,children:["@",h.name]},h.name))]}),a.jsx("label",{className:"mobile-field-label",children:"Priority"}),a.jsxs("select",{className:"mobile-input",value:c,onChange:h=>f(h.target.value),children:[a.jsx("option",{value:"low",children:"Low"}),a.jsx("option",{value:"normal",children:"Normal"}),a.jsx("option",{value:"high",children:"High"})]})]})})}const OC=[{id:"activity",label:"Activity",icon:xa},{id:"chat",label:"Chat",icon:On},{id:"tasks",label:"Tasks",icon:es},{id:"settings",label:"Settings",icon:Bm},{id:"more",label:"More",icon:J1}];function FC(e){const t=e.meta??{},n=typeof t.taskId=="string"?t.taskId:null,r=typeof t.slug=="string"?t.slug:null,i=typeof t.agent=="string"?t.agent:null;if(n)return{id:"task-detail",taskId:n};if(r)return{id:"artifacts?-detail",slug:r};if(i)return{id:"agent-detail",name:i};const l=e.link??"";return l.startsWith("/artifacts?/")?{id:"artifacts?-detail",slug:decodeURIComponent(l.slice(12))}:l.startsWith("/tasks/")?{id:"task-detail",taskId:decodeURIComponent(l.slice(7))}:l.startsWith("/agents/")?{id:"agent-detail",name:decodeURIComponent(l.slice(8))}:null}function QC(){const[e,t]=w.useState("activity"),[n,r]=w.useState([]),[i,l]=w.useState(!1),[s,o]=w.useState(null),[u,d]=w.useState(null),[c,f]=w.useState(null),[m,h]=w.useState(null),[p,x]=w.useState(!0),[b,y]=w.useState(0),g=w.useMemo(()=>n[n.length-1]??{id:e},[e,n]),v=w.useCallback(k=>{r(j=>[...j,k])},[]),C=w.useCallback(()=>{r(k=>k.slice(0,-1))},[]),z=w.useCallback(k=>{r([]),t(k)},[]),E=w.useCallback(async()=>{var k;try{const j=await q.get("/snapshot");d(j),(k=j.settings)!=null&&k.data&&f(j.settings.data),h(null)}catch(j){throw h(j.message||"Dashboard server unreachable."),j}},[]);w.useEffect(()=>{let k=!1;return Promise.all([q.get("/snapshot").catch(()=>null),q.get("/settings").catch(()=>null),q.probeAuthStatus().catch(()=>null)]).then(([j,P])=>{var O;if(k)return;const B=(P==null?void 0:P.data)??((O=j==null?void 0:j.settings)==null?void 0:O.data)??null;j&&d(j),B&&f(B),h(!j&&!B?"Dashboard server unreachable.":null)}).catch(j=>{k||h(j.message||"Dashboard server unreachable.")}).finally(()=>{k||x(!1)}),()=>{k=!0}},[]),w.useEffect(()=>{c!=null&&c.theme&&(ts(c.theme),ui(c.theme))},[c==null?void 0:c.theme]),w.useEffect(()=>{var P;if(((P=c==null?void 0:c.theme)==null?void 0:P.mode)!=="system")return;const k=window.matchMedia("(prefers-color-scheme: light)"),j=()=>{c!=null&&c.theme&&(ts(c.theme),ui(c.theme))};return k.addEventListener("change",j),()=>k.removeEventListener("change",j)},[c==null?void 0:c.theme]),w.useEffect(()=>{const k=()=>{y(P=>P+1),E().catch(()=>{})},j=()=>{document.visibilityState==="visible"&&k()};return window.addEventListener("online",k),window.addEventListener("pageshow",k),document.addEventListener("visibilitychange",j),()=>{window.removeEventListener("online",k),window.removeEventListener("pageshow",k),document.removeEventListener("visibilitychange",j)}},[E]),w.useEffect(()=>{const k=new Vm,j=k.on(P=>{if(P.type==="snapshot"&&"data"in P&&P.data)d(B=>({...B??{},...P.data}));else if(P.type==="change")E().catch(()=>{});else if(P.type==="tasks:change"){const B=P.task;d(O=>{if(!O)return O;const W=(O.tasks||[]).map(ee=>ee.id===B.id?B:ee),de=W.some(ee=>ee.id===B.id);return{...O,tasks:de?W:[B,...W]}})}else P.type==="tasks:delete"?d(B=>B&&{...B,tasks:(B.tasks||[]).filter(O=>O.id!==P.id)}):P.type==="settings:change"?P.settings&&f(P.settings):P.type==="project:change"||P.type==="agents:change"||P.type==="schedules:change"||P.type==="artifact:change"?E().catch(()=>{}):(P.type==="agent:status"||P.type==="agent:restarted")&&d(B=>{if(!B)return B;const O=(B.agents||[]).map(W=>W.name===P.agent.name?P.agent:W);return{...B,agents:O}})});return()=>{j(),k.close()}},[E,b]);const A=w.useCallback(k=>{(k==="activity"||k==="chat"||k==="tasks"||k==="settings"||k==="more")&&z(k)},[z]),L=w.useCallback((k,j,P)=>{if(k==="notification"){const B=FC({link:j||null,meta:P??null});B&&v(B);return}if(k==="task"&&j){v({id:"task-detail",taskId:j});return}if(k==="artifacts?"&&j){v({id:"artifacts?-detail",slug:j});return}if(k==="agent"&&j){v({id:"agent-detail",name:j});return}if(k==="project"){z("activity");return}k==="setting"&&z("settings")},[z,v]),I=()=>{if(!u||!c)return null;if(n.length>0){const k=n[n.length-1];switch(k.id){case"artifacts?":return a.jsx(hC,{snapshot:u,onBack:C,onOpenArtifact:j=>v({id:"artifacts?-detail",slug:j})});case"agents":return a.jsx(yf,{snapshot:u,onBack:C,onOpenAgent:j=>v({id:"agent-detail",name:j}),onRefresh:E});case"skills":return a.jsx(AC,{snapshot:u,onBack:C});case"mods":return a.jsx(oC,{snapshot:u,onBack:C});case"schedules":return a.jsx(xC,{snapshot:u,onBack:C});case"history":return a.jsx(sC,{onBack:C});case"config":return a.jsx(lC,{onBack:C});case"artifacts?-detail":return a.jsx(cC,{slug:k.slug,onBack:C});case"agent-detail":return a.jsx(yf,{snapshot:u,onBack:C,onOpenAgent:()=>{},onRefresh:E,selectedAgent:k.name});case"task-detail":return a.jsx(Sf,{snapshot:u,onRefresh:E,selectedTaskId:k.taskId,onCloseDetail:C,onOpenChat:j=>{o(j),z("chat")}});default:return null}}switch(e){case"activity":return a.jsx(Z2,{snapshot:u,onRefresh:E});case"chat":return a.jsx(iC,{snapshot:u,settings:c,initialTaskId:s,onClearTaskId:()=>o(null)});case"tasks":return a.jsx(Sf,{snapshot:u,onRefresh:E,onOpenChat:k=>{o(k),z("chat")}});case"settings":return a.jsx(zC,{settings:c,snapshot:u,onRefresh:E});case"more":return a.jsx(aC,{snapshot:u,onNavigate:k=>{(k==="artifacts?"||k==="agents"||k==="skills"||k==="mods"||k==="schedules"||k==="history"||k==="config")&&v({id:k})}});default:return null}};return p?a.jsxs("div",{className:"mobile-loading",children:[a.jsx(Wm,{size:"lg"}),a.jsx("p",{children:"Loading Bizar…"})]}):m||!u||!c?a.jsxs("div",{className:"mobile-loading",children:[a.jsx("h2",{children:"Dashboard unavailable"}),a.jsx("p",{children:m||"Dashboard server unreachable."}),a.jsx("p",{className:"muted",children:"Make sure the Bizar dashboard server is running."})]}):a.jsxs("div",{className:"mobile-app",children:[a.jsx(G2,{activeTab:g.id,snapshot:u,onSearch:()=>l(!0),onNavigate:L}),a.jsx("main",{className:"mobile-content",children:I()}),n.length===0&&a.jsx(W2,{tabs:OC,activeTab:e,onChange:A}),n.length>0&&a.jsx("button",{type:"button",className:"mobile-back-btn",onClick:C,"aria-label":"Go back",children:"← Back"}),a.jsx(NC,{open:i,onClose:()=>l(!1),onNavigate:L})]})}export{db as $,xa as A,Dr as B,q1 as C,I2 as D,Z1 as E,Pu as F,cx as G,ka as H,tx as I,hx as J,Au as K,M2 as L,On as M,R2 as N,Ix as O,xt as P,N2 as Q,_t as R,es as S,mx as T,Fm as U,Tx as V,BC as W,Zn as X,Zl as Y,ux as Z,md as _,q as a,C2 as a0,V1 as a1,xx as a2,gx as a3,lx as a4,A2 as a5,ui as a6,ax as a7,ix as a8,fx as a9,rx as aa,X1 as ab,ts as ac,Vm as ad,dx as ae,ag as af,ox as ag,W1 as ah,Bm as ai,HC as aj,UC as ak,wa as al,$1 as am,QC as an,Ss as b,J as c,dd as d,Jl as e,va as f,Pr as g,hd as h,Mu as i,a as j,pr as k,bx as l,cd as m,Y1 as n,Sr as o,qn as p,px as q,w as r,_e as s,Wm as t,kx as u,$m as v,_r as w,Om as x,Dm as y,zx as z};
351
+ */var vC={L:gr.QrCode.Ecc.LOW,M:gr.QrCode.Ecc.MEDIUM,Q:gr.QrCode.Ecc.QUARTILE,H:gr.QrCode.Ecc.HIGH},rg=128,ig="L",lg="#FFFFFF",sg="#000000",og=!1,ag=1,kC=4,wC=0,bC=.1;function ug(e,t=0){const n=[];return e.forEach(function(r,i){let l=null;r.forEach(function(s,o){if(!s&&l!==null){n.push(`M${l+t} ${i+t}h${o-l}v1H${l+t}z`),l=null;return}if(o===r.length-1){if(!s)return;l===null?n.push(`M${o+t},${i+t} h1v1H${o+t}z`):n.push(`M${l+t},${i+t} h${o+1-l}v1H${l+t}z`);return}s&&l===null&&(l=o)})}),n.join("")}function cg(e,t){return e.slice().map((n,r)=>r<t.y||r>=t.y+t.h?n:n.map((i,l)=>l<t.x||l>=t.x+t.w?i:!1))}function SC(e,t,n,r){if(r==null)return null;const i=e.length+n*2,l=Math.floor(t*bC),s=i/t,o=(r.width||l)*s,u=(r.height||l)*s,d=r.x==null?e.length/2-o/2:r.x*s,c=r.y==null?e.length/2-u/2:r.y*s,f=r.opacity==null?1:r.opacity;let m=null;if(r.excavate){let p=Math.floor(d),x=Math.floor(c),b=Math.ceil(o+d-p),y=Math.ceil(u+c-x);m={x:p,y:x,w:b,h:y}}const h=r.crossOrigin;return{x:d,y:c,h:u,w:o,excavation:m,opacity:f,crossOrigin:h}}function CC(e,t){return t!=null?Math.max(Math.floor(t),0):e?kC:wC}function dg({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:l,size:s,boostLevel:o}){let u=_e.useMemo(()=>{const p=(Array.isArray(e)?e:[e]).reduce((x,b)=>(x.push(...gr.QrSegment.makeSegments(b)),x),[]);return gr.QrCode.encodeSegments(p,vC[t],n,void 0,void 0,o)},[e,t,n,o]);const{cells:d,margin:c,numCells:f,calculatedImageSettings:m}=_e.useMemo(()=>{let h=u.getModules();const p=CC(r,i),x=h.length+p*2,b=SC(h,s,p,l);return{cells:h,margin:p,numCells:x,calculatedImageSettings:b}},[u,s,l,r,i]);return{qrcode:u,margin:c,cells:d,numCells:f,calculatedImageSettings:m}}var jC=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),NC=_e.forwardRef(function(t,n){const r=t,{value:i,size:l=rg,level:s=ig,bgColor:o=lg,fgColor:u=sg,includeMargin:d=og,minVersion:c=ag,boostLevel:f,marginSize:m,imageSettings:h}=r,x=Ra(r,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:b}=x,y=Ra(x,["style"]),g=h==null?void 0:h.src,v=_e.useRef(null),C=_e.useRef(null),z=_e.useCallback(O=>{v.current=O,typeof n=="function"?n(O):n&&(n.current=O)},[n]),[E,A]=_e.useState(!1),{margin:L,cells:I,numCells:k,calculatedImageSettings:j}=dg({value:i,level:s,minVersion:c,boostLevel:f,includeMargin:d,marginSize:m,imageSettings:h,size:l});_e.useEffect(()=>{if(v.current!=null){const O=v.current,W=O.getContext("2d");if(!W)return;let de=I;const ee=C.current,R=j!=null&&ee!==null&&ee.complete&&ee.naturalHeight!==0&&ee.naturalWidth!==0;R&&j.excavation!=null&&(de=cg(I,j.excavation));const V=window.devicePixelRatio||1;O.height=O.width=l*V;const S=l/k*V;W.scale(S,S),W.fillStyle=o,W.fillRect(0,0,k,k),W.fillStyle=u,jC?W.fill(new Path2D(ug(de,L))):I.forEach(function(Y,ie){Y.forEach(function(N,ge){N&&W.fillRect(ge+L,ie+L,1,1)})}),j&&(W.globalAlpha=j.opacity),R&&W.drawImage(ee,j.x+L,j.y+L,j.w,j.h)}}),_e.useEffect(()=>{A(!1)},[g]);const P=La({height:l,width:l},b);let B=null;return g!=null&&(B=_e.createElement("img",{src:g,key:g,style:{display:"none"},onLoad:()=>{A(!0)},ref:C,crossOrigin:j==null?void 0:j.crossOrigin})),_e.createElement(_e.Fragment,null,_e.createElement("canvas",La({style:P,height:l,width:l,ref:z,role:"img"},y)),B)});NC.displayName="QRCodeCanvas";var fg=_e.forwardRef(function(t,n){const r=t,{value:i,size:l=rg,level:s=ig,bgColor:o=lg,fgColor:u=sg,includeMargin:d=og,minVersion:c=ag,boostLevel:f,title:m,marginSize:h,imageSettings:p}=r,x=Ra(r,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:b,cells:y,numCells:g,calculatedImageSettings:v}=dg({value:i,level:s,minVersion:c,boostLevel:f,includeMargin:d,marginSize:h,imageSettings:p,size:l});let C=y,z=null;p!=null&&v!=null&&(v.excavation!=null&&(C=cg(y,v.excavation)),z=_e.createElement("image",{href:p.src,height:v.h,width:v.w,x:v.x+b,y:v.y+b,preserveAspectRatio:"none",opacity:v.opacity,crossOrigin:v.crossOrigin}));const E=ug(C,b);return _e.createElement("svg",La({height:l,width:l,viewBox:`0 0 ${g} ${g}`,ref:n,role:"img"},x),!!m&&_e.createElement("title",null,m),_e.createElement("path",{fill:o,d:`M0,0 h${g}v${g}H0z`,shapeRendering:"crispEdges"}),_e.createElement("path",{fill:u,d:E,shapeRendering:"crispEdges"}),z)});fg.displayName="QRCodeSVG";const EC=[{id:"dark",label:"Dark",Icon:ix},{id:"light",label:"Light",Icon:fx},{id:"system",label:"System",Icon:rx}],TC=[{name:"Purple",accent:"#8b5cf6"},{name:"Blue",accent:"#3b82f6"},{name:"Green",accent:"#10b981"},{name:"Orange",accent:"#f97316"},{name:"Red",accent:"#ef4444"},{name:"Pink",accent:"#ec4899"},{name:"Cyan",accent:"#06b6d4"},{name:"Mono",accent:"#6b7280"}];function IC(e){if(e<=0)return"expired";const t=Math.floor(e/1e3),n=Math.floor(t/60),r=t%60;return`${n}:${String(r).padStart(2,"0")}`}function zC({settings:e,snapshot:t,onRefresh:n}){var z,E,A,L,I,k;const[r,i]=w.useState(e),[l,s]=w.useState(!1),[o,u]=w.useState(!1),[d,c]=w.useState(null),[f,m]=w.useState(!1),[h,p]=w.useState(Date.now());w.useEffect(()=>{i(e),s(!1),e.theme&&ui(e.theme)},[e]),w.useEffect(()=>{if(!d)return;const j=setInterval(()=>p(Date.now()),1e3);return()=>clearInterval(j)},[d]);const x=j=>{i(P=>{const B={...P,theme:{...P.theme,...j}};return ts(B.theme),ui(B.theme),B}),s(!0)},b=(j,P)=>{i(B=>({...B,[j]:P})),s(!0)},y=async()=>{u(!0);try{const j=await q.put("/settings",r);i(j.data),s(!1),ts(j.data.theme),ui(j.data.theme),n()}catch{}finally{u(!1)}},g=async()=>{m(!0);try{const j=await q.post("/pair/start");c(j)}catch{}finally{m(!1)}},v=d?d.expiresAt-h:0,C=d!=null&&v<=0;return a.jsxs("div",{className:"mobile-view",children:[l&&a.jsxs("div",{className:"mobile-settings-save-bar",children:[a.jsx("span",{children:"Unsaved changes"}),a.jsxs("button",{type:"button",className:"mobile-btn",disabled:o,onClick:y,children:[a.jsx(Fm,{size:14})," ",o?"Saving…":"Save"]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"Appearance"}),a.jsxs("div",{className:"mobile-card",children:[a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Theme"}),a.jsx("div",{className:"mobile-theme-btns",children:EC.map(({id:j,label:P,Icon:B})=>a.jsxs("button",{type:"button",className:`mobile-theme-btn ${r.theme.mode===j?"active":""}`,onClick:()=>x({mode:j}),children:[a.jsx(B,{size:14})," ",P]},j))})]}),a.jsxs("div",{className:"mobile-setting-row",style:{flexDirection:"column",alignItems:"flex-start",gap:8},children:[a.jsx("span",{className:"mobile-setting-label",children:"Accent color"}),a.jsx("div",{className:"mobile-accent-swatches",children:TC.map(j=>a.jsx("button",{type:"button",className:`mobile-accent-swatch ${r.theme.accent===j.accent?"active":""}`,style:{background:j.accent},onClick:()=>x({accent:j.accent}),title:j.name},j.name))})]}),a.jsxs("div",{className:"mobile-setting-row",style:{flexDirection:"column",alignItems:"flex-start",gap:8},children:[a.jsxs("span",{className:"mobile-setting-label",children:["Font size: ",r.theme.fontSize,"px"]}),a.jsx("input",{type:"range",min:12,max:20,value:r.theme.fontSize,onChange:j=>x({fontSize:Number(j.target.value)}),style:{width:"100%"}})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Compact mode"}),a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:r.theme.compactMode,onChange:j=>x({compactMode:j.target.checked})}),a.jsx("span",{className:"mobile-toggle-slider"})]})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Animations"}),a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:r.theme.animations,onChange:j=>x({animations:j.target.checked})}),a.jsx("span",{className:"mobile-toggle-slider"})]})]})]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"Chat Defaults"}),a.jsxs("div",{className:"mobile-card",children:[a.jsx("label",{className:"mobile-field-label",children:"Default Agent"}),a.jsx("select",{className:"mobile-input",value:r.defaultAgent||"odin",onChange:j=>b("defaultAgent",j.target.value),children:((t==null?void 0:t.agents)||[]).map(j=>a.jsxs("option",{value:j.name,children:["@",j.name]},j.name))}),a.jsx("label",{className:"mobile-field-label",style:{marginTop:8},children:"Default Model"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"(auto)",value:r.defaultModel||"",onChange:j=>b("defaultModel",j.target.value)})]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"Notifications"}),a.jsxs("div",{className:"mobile-card",children:[a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Agent completion"}),a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:!!r.notifications.onAgentComplete,onChange:j=>{i(P=>({...P,notifications:{...P.notifications,onAgentComplete:j.target.checked}})),s(!0)}}),a.jsx("span",{className:"mobile-toggle-slider"})]})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Plan approval"}),a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:!!r.notifications.onPlanApproval,onChange:j=>{i(P=>({...P,notifications:{...P.notifications,onPlanApproval:j.target.checked}})),s(!0)}}),a.jsx("span",{className:"mobile-toggle-slider"})]})]})]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"Agent Behavior"}),a.jsxs("div",{className:"mobile-card",children:[a.jsx("label",{className:"mobile-field-label",children:"Max parallel agents"}),a.jsx("input",{className:"mobile-input",type:"number",inputMode:"numeric",min:1,max:20,value:((z=r.agents)==null?void 0:z.maxParallel)??6,onChange:j=>{i(P=>({...P,agents:{...P.agents,maxParallel:Math.max(1,Math.min(20,parseInt(j.target.value,10)||6))}})),s(!0)}}),a.jsx("label",{className:"mobile-field-label",style:{marginTop:8},children:"Stuck threshold (ms)"}),a.jsx("input",{className:"mobile-input",type:"number",inputMode:"numeric",min:6e4,max:36e5,step:6e4,value:((E=r.agents)==null?void 0:E.stuckThresholdMs)??6e5,onChange:j=>{i(P=>({...P,agents:{...P.agents,stuckThresholdMs:Math.max(6e4,parseInt(j.target.value,10)||6e5)}})),s(!0)}}),a.jsxs("div",{className:"mobile-setting-row",style:{marginTop:8},children:[a.jsx("span",{className:"mobile-setting-label",children:"Auto-restart stuck agents"}),a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:!!((A=r.agents)!=null&&A.autoRestart),onChange:j=>{i(P=>({...P,agents:{...P.agents,autoRestart:j.target.checked}})),s(!0)}}),a.jsx("span",{className:"mobile-toggle-slider"})]})]})]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"Tailscale Serve"}),a.jsx("div",{className:"mobile-card",children:a.jsxs("p",{className:"muted",style:{fontSize:13},children:["Use ",a.jsx("code",{children:"bizar service"})," commands in the terminal to configure Tailscale serve."]})})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsxs("h3",{className:"mobile-section-title",children:[a.jsx(dx,{size:14})," Companion App"]}),a.jsxs("div",{className:"mobile-card",children:[!d&&a.jsxs("button",{type:"button",className:"mobile-btn",onClick:g,disabled:f,style:{width:"100%"},children:[a.jsx(ox,{size:14})," ",f?"Generating…":"Generate QR Code"]}),d&&!C&&a.jsxs("div",{style:{textAlign:"center"},children:[a.jsx("div",{style:{background:"#fff",padding:12,borderRadius:12,display:"inline-block"},children:a.jsx(fg,{value:d.qrPayload,size:180,level:"M"})}),a.jsxs("div",{style:{marginTop:8,fontSize:12},children:["Expires in ",a.jsx("strong",{children:IC(v)})]}),a.jsx("div",{className:"mono",style:{fontSize:10,wordBreak:"break-all",marginTop:4},children:d.publicUrl})]}),d&&C&&a.jsxs("button",{type:"button",className:"mobile-btn",onClick:g,style:{width:"100%"},children:[a.jsx(_t,{size:14})," Generate new QR"]})]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"About"}),a.jsxs("div",{className:"mobile-card",children:[a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Version"}),a.jsx("span",{className:"mobile-setting-value mono",children:((L=r.about)==null?void 0:L.version)||"—"})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Agents"}),a.jsx("span",{className:"mobile-setting-value",children:((I=t==null?void 0:t.agents)==null?void 0:I.length)||0})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Tasks"}),a.jsx("span",{className:"mobile-setting-value",children:((k=t==null?void 0:t.tasks)==null?void 0:k.length)||0})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Plans"}),a.jsx("span",{className:"mobile-setting-value",children:(t==null?void 0:t.artifacts.length)||0})]})]})]}),a.jsx("div",{className:"mobile-view-footer",children:a.jsx("a",{href:"/?desktop=1",className:"mobile-btn mobile-btn-secondary",children:"Switch to Desktop"})})]})}const PC=["languages","framework","design","testing","devops","data","security","integration"];function AC({snapshot:e,onBack:t}){const[n,r]=w.useState([]),[i,l]=w.useState(!0),[s,o]=w.useState(""),[u,d]=w.useState(""),[c,f]=w.useState(null),m=async()=>{try{const x=await q.get("/skills");r(x.skills||[])}catch{}finally{l(!1)}};w.useEffect(()=>{m()},[]);const h=async(x,b)=>{try{await q.patch(`/skills/${encodeURIComponent(x)}`,{enabled:b}),r(y=>y.map(g=>g.id===x?{...g,enabled:b}:g)),(c==null?void 0:c.id)===x&&f(y=>y&&{...y,enabled:b})}catch{}},p=n.filter(x=>{if(u&&x.category!==u)return!1;if(s){const b=s.toLowerCase();return x.name.toLowerCase().includes(b)||x.description.toLowerCase().includes(b)}return!0});return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search skills…",value:s,onChange:x=>o(x.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>m(),"aria-label":"Refresh",children:a.jsx(_t,{size:16})})]}),a.jsxs("div",{className:"mobile-search-scopes",children:[a.jsx("button",{type:"button",className:`mobile-scope-chip ${u?"":"active"}`,onClick:()=>d(""),children:"All"}),PC.map(x=>a.jsx("button",{type:"button",className:`mobile-scope-chip ${u===x?"active":""}`,onClick:()=>d(x),children:x},x))]}),i?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):p.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(Jl,{size:40}),a.jsx("p",{children:"No skills found."})]}):a.jsx("div",{className:"mobile-card-list",children:p.map(x=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>f(x),children:[a.jsx("div",{className:"mobile-list-icon",children:a.jsx(Jl,{size:16})}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:x.name}),a.jsxs("span",{className:"mobile-list-meta",children:[x.category," · v",x.version]})]}),a.jsx("span",{className:`mobile-list-badge ${x.enabled?"badge-on":"badge-off"}`,children:x.enabled?"on":"off"})]},x.id))}),c&&a.jsx(Dt,{open:!0,onClose:()=>f(null),title:c.name,actions:a.jsxs("button",{type:"button",className:`mobile-btn ${c.enabled?"mobile-btn-secondary":""}`,style:{width:"100%"},onClick:()=>{c&&h(c.id,!c.enabled)},children:[a.jsx(Om,{size:14})," ",c.enabled?"Disable":"Enable"]}),children:a.jsxs("div",{className:"mobile-agent-detail",children:[a.jsx("p",{className:"mobile-agent-detail-desc",children:c.description||"No description."}),a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Category"}),a.jsx("span",{children:c.category})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Version"}),a.jsx("span",{className:"mono",children:c.version})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Source"}),a.jsx("span",{children:c.source})]}),c.tags.length>0&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Tags"}),a.jsx("span",{children:c.tags.join(", ")})]})]})]})})]})}const MC=["queued","doing","blocked","done"],dl={queued:"Queued",doing:"Doing",blocked:"Blocked",done:"Done"},bf={queued:"doing",doing:"done",blocked:"queued",done:"queued"};function LC(e){const t=e.metadata??{};return!!(t.sessionId||t.bgInstanceId)}function RC(e){var n;const t=e.metadata??{};return!!((n=t.artifactIds)!=null&&n.length||t.artifactId)}function Sf({snapshot:e,onRefresh:t,selectedTaskId:n,onCloseDetail:r,onOpenChat:i,onOpenArtifact:l}){var oe,Ne;const[s,o]=w.useState(e.tasks||[]),[u,d]=w.useState(!e.tasks),[c,f]=w.useState(""),[m,h]=w.useState("queued"),[p,x]=w.useState(null),[b,y]=w.useState(!1),[g,v]=w.useState(null),[C,z]=w.useState([]),[E,A]=w.useState(""),[L,I]=w.useState(null),[k,j]=w.useState(!1),[P,B]=w.useState(""),[O,W]=w.useState("updated");w.useEffect(()=>{var H;if(e.tasks&&(o(e.tasks),d(!1)),n){const te=(H=e.tasks)==null?void 0:H.find(re=>re.id===n);te&&x(te)}},[e.tasks,n]),w.useEffect(()=>{if(n){const H=s.find(te=>te.id===n);H&&x(H)}},[n,s]);const de=async()=>{try{const H=await q.get("/tasks");o(Array.isArray(H)?H:[])}catch{}finally{d(!1)}},ee=async(H,te)=>{o(re=>re.map(Se=>Se.id===H?{...Se,status:te}:Se)),(p==null?void 0:p.id)===H&&x(re=>re&&{...re,status:te});try{await q.patch(`/tasks/${encodeURIComponent(H)}/status`,{status:te})}catch{await de()}},R=async H=>{if(confirm("Delete this task?"))try{await q.del(`/tasks/${encodeURIComponent(H)}`),o(te=>te.filter(re=>re.id!==H)),(p==null?void 0:p.id)===H&&x(null)}catch{await de()}},V=async H=>{try{await q.post(`/tasks/${encodeURIComponent(H)}/archive`),o(te=>te.filter(re=>re.id!==H)),(p==null?void 0:p.id)===H&&x(null)}catch{}},Y=[...s.filter(H=>{var te,re;if(c.trim()){const Se=c.toLowerCase();if(!(H.title||"").toLowerCase().includes(Se)&&!(H.description||"").toLowerCase().includes(Se))return!1}if(P.trim()){const Se=P==="mine"?((re=(te=e.settings)==null?void 0:te.data)==null?void 0:re.defaultAgent)||DC(e):P.replace(/^@/,"");if((H.assignee||"").toLowerCase()!==Se.toLowerCase())return!1}return!0})].sort((H,te)=>{switch(O){case"priority":{const re={high:0,normal:1,low:2};return(re[H.priority]??1)-(re[te.priority]??1)}case"created":return new Date(te.createdAt).getTime()-new Date(H.createdAt).getTime();case"updated":default:return new Date(te.updatedAt).getTime()-new Date(H.updatedAt).getTime()}}),ie=Y.filter(H=>H.status===m),N=e.agents||[],ge=async(H,te,re,Se)=>{try{const Ot=await q.post("/tasks",{title:H,description:te,assignee:re||null,priority:Se});o(ln=>[Ot,...ln]),y(!1)}catch{}},Le=async H=>{j(!0),A(""),I(null),v(H);try{const re=((await q.get(`/tasks/${encodeURIComponent(H)}/artifacts`)).artifacts||[]).map(Se=>Se.id);if(z(re),re.length>0){const[Se,Ot]=await Promise.all([q.get(`/artifacts/${encodeURIComponent(re[0])}`),fetch(q.urlWithToken(`/artifacts/${encodeURIComponent(re[0])}/content`)).then(ln=>ln.text())]);I(Se),A(Ot)}}catch{}finally{j(!1)}};return u?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):a.jsxs("div",{className:"mobile-view mobile-view-tasks",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search tasks…",value:c,onChange:H=>f(H.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>de(),"aria-label":"Refresh",children:a.jsx(_t,{size:16})})]}),a.jsxs("div",{className:"mobile-tasks-filters",children:[a.jsxs("select",{className:"mobile-filter-select",value:P,onChange:H=>B(H.target.value),children:[a.jsx("option",{value:"",children:"All"}),a.jsx("option",{value:"mine",children:"Mine"}),N.map(H=>a.jsxs("option",{value:`@${H.name}`,children:["@",H.name]},H.name))]}),a.jsxs("select",{className:"mobile-filter-select",value:O,onChange:H=>W(H.target.value),children:[a.jsx("option",{value:"updated",children:"Updated"}),a.jsx("option",{value:"created",children:"Created"}),a.jsx("option",{value:"priority",children:"Priority"})]})]}),a.jsx("div",{className:"mobile-kanban-tabs",children:MC.map(H=>{const te=Y.filter(re=>re.status===H).length;return a.jsxs("button",{type:"button",className:`mobile-kanban-tab ${m===H?"active":""}`,onClick:()=>h(H),children:[dl[H]," (",te,")"]},H)})}),a.jsxs("div",{className:"mobile-card-list",children:[ie.length===0&&a.jsxs("div",{className:"mobile-empty mobile-empty-compact",children:[a.jsxs("p",{children:["No ",dl[m].toLowerCase()," tasks."]}),a.jsx("p",{className:"muted",children:"Create one or switch columns."})]}),ie.map(H=>{var te;return a.jsxs("button",{type:"button",className:"mobile-task-card",onClick:()=>x(H),children:[a.jsx("div",{className:"priority-dot",style:{background:gx[H.priority]||"var(--info)"}}),a.jsxs("div",{className:"task-content",children:[a.jsx("div",{className:"task-title",children:H.title}),a.jsxs("div",{className:"task-meta",children:[H.assignee?`@${H.assignee}`:"unassigned"," · ",Sr(H.updatedAt||H.createdAt),(te=H.dependencies)!=null&&te.length?` · ${H.dependencies.length} deps`:""]})]})]},H.id)})]}),a.jsx("button",{type:"button",className:"mobile-fab",onClick:()=>y(!0),"aria-label":"Add task",children:a.jsx(xt,{size:24})}),a.jsx(Dt,{open:!!p,onClose:()=>{x(null),r==null||r()},title:"Task Detail",actions:p&&a.jsxs("div",{className:"mobile-task-detail-actions",children:[p.status!=="done"&&a.jsxs("button",{type:"button",className:"mobile-btn",style:{flex:1},onClick:()=>{p&&ee(p.id,bf[p.status])},children:["Move to ",dl[bf[p.status]||"queued"]]}),a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>{p&&V(p.id)},children:[a.jsx(V1,{size:14})," Archive"]}),LC(p)&&a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>{i==null||i(p.id)},children:[a.jsx(On,{size:14})," Chat"]}),RC(p)&&a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>{Le(p.id)},children:[a.jsx(qn,{size:14})," Artifact"]}),a.jsx("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>{p&&R(p.id)},children:a.jsx(_r,{size:14})})]}),children:p&&a.jsxs("div",{className:"mobile-task-detail",children:[a.jsxs("div",{className:"mobile-task-detail-header",children:[a.jsx("span",{className:`mobile-task-status-badge status-${p.status}`,children:dl[p.status]||p.status}),a.jsx("span",{className:`mobile-task-priority priority-${p.priority}`,children:p.priority})]}),a.jsx("h3",{className:"mobile-task-detail-title",children:p.title}),p.description&&a.jsx("p",{className:"mobile-task-detail-desc",children:p.description}),a.jsxs("div",{className:"mobile-task-detail-meta",children:[p.assignee&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Assignee"}),a.jsxs("span",{children:["@",p.assignee]})]}),p.dueDate&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Due"}),a.jsx("span",{children:new Date(p.dueDate).toLocaleDateString()})]}),p.timeSpent!=null&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Time spent"}),a.jsxs("span",{children:[Math.round(p.timeSpent/6e4),"min"]})]}),(oe=p.dependencies)!=null&&oe.length?a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Dependencies"}),a.jsx("span",{children:p.dependencies.length})]}):null,(Ne=p.comments)!=null&&Ne.length?a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Comments"}),a.jsx("span",{children:p.comments.length})]}):null,a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Created"}),a.jsx("span",{children:Sr(p.createdAt)})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Updated"}),a.jsx("span",{children:Sr(p.updatedAt)})]})]})]})}),a.jsx(_C,{open:b,onClose:()=>y(!1),onCreate:ge,agents:N}),a.jsx(Dt,{open:!!g,onClose:()=>{v(null),A(""),I(null)},title:(L==null?void 0:L.name)||"Artifact",actions:C.length>1?a.jsx("div",{className:"mobile-task-detail-actions",children:C.map((H,te)=>a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",style:{flex:1},onClick:()=>{j(!0),Promise.all([q.get(`/artifacts/${encodeURIComponent(H)}`),fetch(q.urlWithToken(`/artifacts/${encodeURIComponent(H)}/content`)).then(re=>re.text())]).then(([re,Se])=>{I(re),A(Se),j(!1)}).catch(()=>j(!1))},children:["Artifact ",te+1]},H))}):null,children:a.jsx("div",{className:"mobile-artifact-viewer",children:k?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading artifact…"})}):E?a.jsx("iframe",{srcDoc:E,className:"mobile-artifact-iframe",sandbox:"allow-scripts allow-forms allow-popups allow-same-origin",title:(L==null?void 0:L.name)||"Artifact",loading:"lazy"}):a.jsxs("div",{className:"mobile-empty",children:[a.jsx(qn,{size:32}),a.jsx("p",{className:"muted",children:"No artifact content available."})]})})})]})}function DC(e){var t,n;return((n=(t=e.settings)==null?void 0:t.data)==null?void 0:n.defaultAgent)||"odin"}function _C({open:e,onClose:t,onCreate:n,agents:r}){const[i,l]=w.useState(""),[s,o]=w.useState(""),[u,d]=w.useState(""),[c,f]=w.useState("normal"),m=h=>{h.preventDefault(),i.trim()&&(n(i.trim(),s.trim(),u,c),l(""),o(""),d(""),f("normal"))};return a.jsx(Tn,{open:e,onClose:t,title:"New Task",actions:a.jsxs("button",{type:"submit",form:"new-task-form",className:"mobile-btn",style:{width:"100%"},children:[a.jsx(xt,{size:14})," Create Task"]}),children:a.jsxs("form",{id:"new-task-form",onSubmit:m,className:"mobile-task-form",children:[a.jsx("label",{className:"mobile-field-label",children:"Title *"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"Task title",value:i,onChange:h=>l(h.target.value),autoFocus:!0,required:!0}),a.jsx("label",{className:"mobile-field-label",children:"Description"}),a.jsx("textarea",{className:"mobile-input",rows:3,placeholder:"Optional description",value:s,onChange:h=>o(h.target.value)}),a.jsx("label",{className:"mobile-field-label",children:"Assignee"}),a.jsxs("select",{className:"mobile-input",value:u,onChange:h=>d(h.target.value),children:[a.jsx("option",{value:"",children:"Unassigned"}),r.map(h=>a.jsxs("option",{value:h.name,children:["@",h.name]},h.name))]}),a.jsx("label",{className:"mobile-field-label",children:"Priority"}),a.jsxs("select",{className:"mobile-input",value:c,onChange:h=>f(h.target.value),children:[a.jsx("option",{value:"low",children:"Low"}),a.jsx("option",{value:"normal",children:"Normal"}),a.jsx("option",{value:"high",children:"High"})]})]})})}const OC=[{id:"activity",label:"Activity",icon:xa},{id:"chat",label:"Chat",icon:On},{id:"tasks",label:"Tasks",icon:es},{id:"settings",label:"Settings",icon:Bm},{id:"more",label:"More",icon:J1}];function FC(e){const t=e.meta??{},n=typeof t.taskId=="string"?t.taskId:null,r=typeof t.slug=="string"?t.slug:null,i=typeof t.agent=="string"?t.agent:null;if(n)return{id:"task-detail",taskId:n};if(r)return{id:"artifacts?-detail",slug:r};if(i)return{id:"agent-detail",name:i};const l=e.link??"";return l.startsWith("/artifacts?/")?{id:"artifacts?-detail",slug:decodeURIComponent(l.slice(12))}:l.startsWith("/tasks/")?{id:"task-detail",taskId:decodeURIComponent(l.slice(7))}:l.startsWith("/agents/")?{id:"agent-detail",name:decodeURIComponent(l.slice(8))}:null}function QC(){const[e,t]=w.useState("activity"),[n,r]=w.useState([]),[i,l]=w.useState(!1),[s,o]=w.useState(null),[u,d]=w.useState(null),[c,f]=w.useState(null),[m,h]=w.useState(null),[p,x]=w.useState(!0),[b,y]=w.useState(0),g=w.useMemo(()=>n[n.length-1]??{id:e},[e,n]),v=w.useCallback(k=>{r(j=>[...j,k])},[]),C=w.useCallback(()=>{r(k=>k.slice(0,-1))},[]),z=w.useCallback(k=>{r([]),t(k)},[]),E=w.useCallback(async()=>{var k;try{const j=await q.get("/snapshot");d(j),(k=j.settings)!=null&&k.data&&f(j.settings.data),h(null)}catch(j){throw h(j.message||"Dashboard server unreachable."),j}},[]);w.useEffect(()=>{let k=!1;return Promise.all([q.get("/snapshot").catch(()=>null),q.get("/settings").catch(()=>null),q.probeAuthStatus().catch(()=>null)]).then(([j,P])=>{var O;if(k)return;const B=(P==null?void 0:P.data)??((O=j==null?void 0:j.settings)==null?void 0:O.data)??null;j&&d(j),B&&f(B),h(!j&&!B?"Dashboard server unreachable.":null)}).catch(j=>{k||h(j.message||"Dashboard server unreachable.")}).finally(()=>{k||x(!1)}),()=>{k=!0}},[]),w.useEffect(()=>{c!=null&&c.theme&&(ts(c.theme),ui(c.theme))},[c==null?void 0:c.theme]),w.useEffect(()=>{var P;if(((P=c==null?void 0:c.theme)==null?void 0:P.mode)!=="system")return;const k=window.matchMedia("(prefers-color-scheme: light)"),j=()=>{c!=null&&c.theme&&(ts(c.theme),ui(c.theme))};return k.addEventListener("change",j),()=>k.removeEventListener("change",j)},[c==null?void 0:c.theme]),w.useEffect(()=>{const k=()=>{y(P=>P+1),E().catch(()=>{})},j=()=>{document.visibilityState==="visible"&&k()};return window.addEventListener("online",k),window.addEventListener("pageshow",k),document.addEventListener("visibilitychange",j),()=>{window.removeEventListener("online",k),window.removeEventListener("pageshow",k),document.removeEventListener("visibilitychange",j)}},[E]),w.useEffect(()=>{const k=new Vm,j=k.on(P=>{if(P.type==="snapshot"&&"data"in P&&P.data)d(B=>({...B??{},...P.data}));else if(P.type==="change")E().catch(()=>{});else if(P.type==="tasks:change"){const B=P.task;d(O=>{if(!O)return O;const W=(O.tasks||[]).map(ee=>ee.id===B.id?B:ee),de=W.some(ee=>ee.id===B.id);return{...O,tasks:de?W:[B,...W]}})}else P.type==="tasks:delete"?d(B=>B&&{...B,tasks:(B.tasks||[]).filter(O=>O.id!==P.id)}):P.type==="settings:change"?P.settings&&f(P.settings):P.type==="project:change"||P.type==="agents:change"||P.type==="schedules:change"||P.type==="artifact:change"?E().catch(()=>{}):(P.type==="agent:status"||P.type==="agent:restarted")&&d(B=>{if(!B)return B;const O=(B.agents||[]).map(W=>W.name===P.agent.name?P.agent:W);return{...B,agents:O}})});return()=>{j(),k.close()}},[E,b]);const A=w.useCallback(k=>{(k==="activity"||k==="chat"||k==="tasks"||k==="settings"||k==="more")&&z(k)},[z]),L=w.useCallback((k,j,P)=>{if(k==="notification"){const B=FC({link:j||null,meta:P??null});B&&v(B);return}if(k==="task"&&j){v({id:"task-detail",taskId:j});return}if(k==="artifacts?"&&j){v({id:"artifacts?-detail",slug:j});return}if(k==="agent"&&j){v({id:"agent-detail",name:j});return}if(k==="project"){z("activity");return}k==="setting"&&z("settings")},[z,v]),I=()=>{if(!u||!c)return null;if(n.length>0){const k=n[n.length-1];switch(k.id){case"artifacts?":return a.jsx(iC,{snapshot:u,onBack:C,onOpenArtifact:j=>v({id:"artifacts?-detail",slug:j})});case"agents":return a.jsx(gf,{snapshot:u,onBack:C,onOpenAgent:j=>v({id:"agent-detail",name:j}),onRefresh:E});case"skills":return a.jsx(AC,{snapshot:u,onBack:C});case"mods":return a.jsx(Z2,{snapshot:u,onBack:C});case"schedules":return a.jsx(uC,{snapshot:u,onBack:C});case"history":return a.jsx(X2,{onBack:C});case"config":return a.jsx(G2,{onBack:C});case"artifacts?-detail":return a.jsx(tC,{slug:k.slug,onBack:C});case"agent-detail":return a.jsx(gf,{snapshot:u,onBack:C,onOpenAgent:()=>{},onRefresh:E,selectedAgent:k.name});case"task-detail":return a.jsx(Sf,{snapshot:u,onRefresh:E,selectedTaskId:k.taskId,onCloseDetail:C,onOpenChat:j=>{o(j),z("chat")}});default:return null}}switch(e){case"activity":return a.jsx(H2,{snapshot:u,onRefresh:E});case"chat":return a.jsx(K2,{snapshot:u,settings:c,initialTaskId:s,onClearTaskId:()=>o(null)});case"tasks":return a.jsx(Sf,{snapshot:u,onRefresh:E,onOpenChat:k=>{o(k),z("chat")}});case"settings":return a.jsx(zC,{settings:c,snapshot:u,onRefresh:E});case"more":return a.jsx(J2,{snapshot:u,onNavigate:k=>{(k==="artifacts?"||k==="agents"||k==="skills"||k==="mods"||k==="schedules"||k==="history"||k==="config")&&v({id:k})}});default:return null}};return p?a.jsxs("div",{className:"mobile-loading",children:[a.jsx(Wm,{size:"lg"}),a.jsx("p",{children:"Loading Bizar…"})]}):m||!u||!c?a.jsxs("div",{className:"mobile-loading",children:[a.jsx("h2",{children:"Dashboard unavailable"}),a.jsx("p",{children:m||"Dashboard server unreachable."}),a.jsx("p",{className:"muted",children:"Make sure the Bizar dashboard server is running."})]}):a.jsxs("div",{className:"mobile-app",children:[a.jsx(B2,{activeTab:g.id,snapshot:u,onSearch:()=>l(!0),onNavigate:L}),a.jsx("main",{className:"mobile-content",children:I()}),n.length===0&&a.jsx(D2,{tabs:OC,activeTab:e,onChange:A}),n.length>0&&a.jsx("button",{type:"button",className:"mobile-back-btn",onClick:C,"aria-label":"Go back",children:"← Back"}),a.jsx(yC,{open:i,onClose:()=>l(!1),onNavigate:L})]})}export{db as $,xa as A,Dr as B,q1 as C,I2 as D,Z1 as E,Pu as F,cx as G,ka as H,tx as I,hx as J,Au as K,M2 as L,On as M,R2 as N,Ix as O,xt as P,N2 as Q,_t as R,es as S,mx as T,Fm as U,Tx as V,BC as W,Zn as X,Zl as Y,ux as Z,md as _,q as a,C2 as a0,V1 as a1,xx as a2,gx as a3,lx as a4,ix as a5,fx as a6,rx as a7,Vm as a8,X1 as a9,ax as aa,A2 as ab,ui as ac,ts as ad,W1 as ae,Bm as af,HC as ag,UC as ah,wa as ai,$1 as aj,QC as ak,Ss as b,J as c,dd as d,Jl as e,va as f,Pr as g,hd as h,Mu as i,a as j,pr as k,bx as l,cd as m,Y1 as n,Sr as o,qn as p,px as q,w as r,_e as s,Wm as t,kx as u,$m as v,_r as w,Om as x,Dm as y,zx as z};