tide-commander 1.96.0 → 1.98.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist/assets/{BossLogsModal-BFy6Rxdn.js → BossLogsModal-P6MiZVuY.js} +1 -1
  2. package/dist/assets/{BossSpawnModal-KQyJYj_B.js → BossSpawnModal-DZJ1Ngsz.js} +1 -1
  3. package/dist/assets/{ControlsModal-W_ghuG_Q.js → ControlsModal-BjV0a1kc.js} +1 -1
  4. package/dist/assets/{DockerLogsModal-valTcuRy.js → DockerLogsModal-DtddubKa.js} +1 -1
  5. package/dist/assets/EmbeddedEditor-ByRepTwR.js +33 -0
  6. package/dist/assets/{GmailOAuthSetup-AcW1zAlk.js → GmailOAuthSetup-DS6NmxUi.js} +1 -1
  7. package/dist/assets/{GoogleOAuthSetup-C9uZ46Oe.js → GoogleOAuthSetup-kQyKInRW.js} +1 -1
  8. package/dist/assets/{IframeModal-CmWv7GXl.js → IframeModal-BuTPDTx1.js} +1 -1
  9. package/dist/assets/{IntegrationsPanel-CNvzosgx.js → IntegrationsPanel-Bm19ZAd6.js} +2 -2
  10. package/dist/assets/{LogViewerModal-imTE-619.js → LogViewerModal-DFlUtkDD.js} +1 -1
  11. package/dist/assets/{MonitoringModal-DLxBY738.js → MonitoringModal-BEEPwGu5.js} +1 -1
  12. package/dist/assets/{PM2LogsModal-S4n0D11V.js → PM2LogsModal-Di5MjyxZ.js} +1 -1
  13. package/dist/assets/{RestoreArchivedAreaModal-B32sqCxN.js → RestoreArchivedAreaModal-CNjmR7BX.js} +1 -1
  14. package/dist/assets/{Scene2DCanvas-bEu0UPUm.js → Scene2DCanvas-CA29sh9R.js} +1 -1
  15. package/dist/assets/{SceneManager-Ce3X0awy.js → SceneManager-duyCA_TD.js} +1 -1
  16. package/dist/assets/{SkillsPanel-Dj22nDU8.js → SkillsPanel-CkV4ci4Q.js} +1 -1
  17. package/dist/assets/SlackMultiInstanceSetup-iHZNQX3B.js +2 -0
  18. package/dist/assets/{SpawnModal-F9nspdWd.js → SpawnModal-bzQlnSQy.js} +1 -1
  19. package/dist/assets/{SubordinateAssignmentModal-DT31CkPr.js → SubordinateAssignmentModal-D6Ak_XQ1.js} +1 -1
  20. package/dist/assets/TriggerManagerPanel-CT8aMQ5P.js +9 -0
  21. package/dist/assets/{WorkflowEditorPanel-BYRi0cU9.js → WorkflowEditorPanel-DcV9ErU4.js} +1 -1
  22. package/dist/assets/{index-ByfAbkqv.js → index-BQQV5Xax.js} +1 -1
  23. package/dist/assets/index-Ba8umpS_.js +1 -0
  24. package/dist/assets/{index-B9G4hrFR.js → index-C0fIrrTS.js} +1 -1
  25. package/dist/assets/index-CDHzSAgq.js +1 -0
  26. package/dist/assets/index-CK8NcQSU.css +1 -0
  27. package/dist/assets/{index-CLr8DpLX.js → index-Cirz97EK.js} +2 -2
  28. package/dist/assets/index-Cnj2pM08.js +19 -0
  29. package/dist/assets/{index-DqZhHROd.js → index-D2L5oc5D.js} +1 -1
  30. package/dist/assets/{index-DkjWoHhy.js → index-DR7uaDtK.js} +1 -1
  31. package/dist/assets/{index-BmjrPptb.js → index-Dww2MWLN.js} +1 -1
  32. package/dist/assets/main-CD03IZnY.css +1 -0
  33. package/dist/assets/main-XbhAPjbi.js +214 -0
  34. package/dist/assets/{web-D-a3phls.js → web-C-JnApw7.js} +1 -1
  35. package/dist/assets/{web-CLuvtqCm.js → web-C4LpSGoH.js} +1 -1
  36. package/dist/assets/{web-DM2bFWBN.js → web-CaPUSaID.js} +1 -1
  37. package/dist/index.html +2 -2
  38. package/dist/locales/en/config.json +44 -0
  39. package/dist/locales/en/terminal.json +10 -0
  40. package/dist/src/packages/server/claude/backend.js +42 -0
  41. package/dist/src/packages/server/claude/permission-prompt-server.mjs +188 -0
  42. package/dist/src/packages/server/claude/runner/process-lifecycle.js +3 -0
  43. package/dist/src/packages/server/claude/runner/stdout-pipeline.js +8 -0
  44. package/dist/src/packages/server/claude/runner/tmux-helper.js +14 -0
  45. package/dist/src/packages/server/data/event-queries.js +143 -1
  46. package/dist/src/packages/server/data/migrations/007_whatsapp_messages.sql +48 -0
  47. package/dist/src/packages/server/index.js +1 -0
  48. package/dist/src/packages/server/integrations/gmail/gmail-client.js +139 -24
  49. package/dist/src/packages/server/integrations/gmail/gmail-routes.js +162 -0
  50. package/dist/src/packages/server/integrations/slack/slack-config.js +13 -0
  51. package/dist/src/packages/server/integrations/slack/slack-trigger-handler.js +12 -4
  52. package/dist/src/packages/server/integrations/whatsapp/whatsapp-routes.js +81 -0
  53. package/dist/src/packages/server/integrations/whatsapp/whatsapp-trigger-handler.js +29 -0
  54. package/dist/src/packages/server/routes/agent-prompt.js +57 -0
  55. package/dist/src/packages/server/routes/index.js +6 -1
  56. package/dist/src/packages/server/routes/skills.js +193 -0
  57. package/dist/src/packages/server/routes/trigger-routes.js +74 -17
  58. package/dist/src/packages/server/routes/webhook-signatures.js +20 -7
  59. package/dist/src/packages/server/services/agent-prompt-service.js +100 -0
  60. package/dist/src/packages/server/services/index.js +1 -0
  61. package/dist/src/packages/server/websocket/handler.js +2 -1
  62. package/dist/src/packages/server/websocket/listeners/agent-prompt-listeners.js +13 -0
  63. package/dist/src/packages/server/websocket/listeners/index.js +2 -0
  64. package/dist/src/packages/shared/whatsapp-types.js +1 -0
  65. package/package.json +2 -2
  66. package/dist/assets/EmbeddedEditor-CIsFWo6A.js +0 -1
  67. package/dist/assets/SlackMultiInstanceSetup-J9NdRY0U.js +0 -2
  68. package/dist/assets/TriggerManagerPanel-CVJ9ozHz.js +0 -9
  69. package/dist/assets/index-BPy8NE5B.js +0 -51
  70. package/dist/assets/index-BdGz_GAe.css +0 -1
  71. package/dist/assets/index-C5wC_Xis.js +0 -1
  72. package/dist/assets/index-DJm7oMXk.js +0 -1
  73. package/dist/assets/main-9uTEp9Lr.js +0 -214
  74. package/dist/assets/main-BfT_95fk.css +0 -1
@@ -1,4 +1,4 @@
1
- import{u as Ie,c4 as oo,G as so,r as i,h as Ee,j as e,C as we,s as x,c5 as ro,c6 as to,c7 as ao,aX as Le,l as K,k as ze,aE as io,ah as lo,aF as co,c8 as I,_ as no,aK as Pe,I as yo,aJ as Me}from"./main-9uTEp9Lr.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const mo=[{value:"scout",labelKey:"tools:skills.classScout",descriptionKey:"tools:skills.classScoutDesc"},{value:"builder",labelKey:"tools:skills.classBuilder",descriptionKey:"tools:skills.classBuilderDesc"},{value:"debugger",labelKey:"tools:skills.classDebugger",descriptionKey:"tools:skills.classDebuggerDesc"},{value:"architect",labelKey:"tools:skills.classArchitect",descriptionKey:"tools:skills.classArchitectDesc"},{value:"warrior",labelKey:"tools:skills.classWarrior",descriptionKey:"tools:skills.classWarriorDesc"},{value:"support",labelKey:"tools:skills.classSupport",descriptionKey:"tools:skills.classSupportDesc"},{value:"boss",labelKey:"tools:skills.classBoss",descriptionKey:"tools:skills.classBossDesc"}],go=[{labelKey:"tools:skills.toolReadFiles",value:"Read"},{labelKey:"tools:skills.toolWriteFiles",value:"Write"},{labelKey:"tools:skills.toolEditFiles",value:"Edit"},{labelKey:"tools:skills.toolRunBash",value:"Bash"},{labelKey:"tools:skills.toolGitCommands",value:"Bash(git:*)"},{labelKey:"tools:skills.toolNpmCommands",value:"Bash(npm:*)"},{labelKey:"tools:skills.toolDockerCommands",value:"Bash(docker:*)"},{labelKey:"tools:skills.toolKubectlCommands",value:"Bash(kubectl:*)"},{labelKey:"tools:skills.toolSearchFiles",value:"Grep"},{labelKey:"tools:skills.toolGlobFiles",value:"Glob"},{labelKey:"tools:skills.toolWebFetch",value:"WebFetch"},{labelKey:"tools:skills.toolWebSearch",value:"WebSearch"}],po=`## Instructions
1
+ import{u as Ie,c4 as oo,G as so,r as i,h as Ee,j as e,C as we,s as x,c5 as ro,c6 as to,c7 as ao,aX as Le,l as K,k as ze,aE as io,ah as lo,aF as co,c8 as I,_ as no,aK as Pe,I as yo,aJ as Me}from"./main-XbhAPjbi.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const mo=[{value:"scout",labelKey:"tools:skills.classScout",descriptionKey:"tools:skills.classScoutDesc"},{value:"builder",labelKey:"tools:skills.classBuilder",descriptionKey:"tools:skills.classBuilderDesc"},{value:"debugger",labelKey:"tools:skills.classDebugger",descriptionKey:"tools:skills.classDebuggerDesc"},{value:"architect",labelKey:"tools:skills.classArchitect",descriptionKey:"tools:skills.classArchitectDesc"},{value:"warrior",labelKey:"tools:skills.classWarrior",descriptionKey:"tools:skills.classWarriorDesc"},{value:"support",labelKey:"tools:skills.classSupport",descriptionKey:"tools:skills.classSupportDesc"},{value:"boss",labelKey:"tools:skills.classBoss",descriptionKey:"tools:skills.classBossDesc"}],go=[{labelKey:"tools:skills.toolReadFiles",value:"Read"},{labelKey:"tools:skills.toolWriteFiles",value:"Write"},{labelKey:"tools:skills.toolEditFiles",value:"Edit"},{labelKey:"tools:skills.toolRunBash",value:"Bash"},{labelKey:"tools:skills.toolGitCommands",value:"Bash(git:*)"},{labelKey:"tools:skills.toolNpmCommands",value:"Bash(npm:*)"},{labelKey:"tools:skills.toolDockerCommands",value:"Bash(docker:*)"},{labelKey:"tools:skills.toolKubectlCommands",value:"Bash(kubectl:*)"},{labelKey:"tools:skills.toolSearchFiles",value:"Grep"},{labelKey:"tools:skills.toolGlobFiles",value:"Glob"},{labelKey:"tools:skills.toolWebFetch",value:"WebFetch"},{labelKey:"tools:skills.toolWebSearch",value:"WebSearch"}],po=`## Instructions
2
2
 
3
3
  Describe step-by-step instructions for this skill here.
4
4
 
@@ -0,0 +1,2 @@
1
+ import{r as h,j as e,aJ as b,l as m}from"./main-XbhAPjbi.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const C=["public_channel","private_channel","im","mpim"],z={public_channel:"Public channels",private_channel:"Private channels",im:"1:1 DMs",mpim:"Group DMs"};function M(t){const i=new Set;for(const a of(t||"").split(",")){const f=a.trim();C.includes(f)&&i.add(f)}return i}function $(t){return C.filter(i=>t.has(i)).join(",")}const s={container:{display:"flex",gap:16,minHeight:420},list:{width:200,flexShrink:0,background:"var(--surface-1, #181825)",borderRadius:8,border:"1px solid var(--border, #313244)",padding:8,display:"flex",flexDirection:"column",gap:4},listItem:t=>({padding:"8px 10px",borderRadius:6,cursor:"pointer",background:t?"rgba(137,180,250,0.15)":"transparent",border:t?"1px solid rgba(137,180,250,0.3)":"1px solid transparent",color:t?"#cdd6f4":"#a6adc8",fontSize:13}),label:{fontWeight:500},sub:{fontSize:11,color:"#6c7086",marginTop:2},addBtn:{marginTop:8,padding:"8px 10px",borderRadius:6,background:"transparent",color:"#89b4fa",border:"1px dashed rgba(137,180,250,0.4)",cursor:"pointer",fontSize:13},editor:{flex:1,display:"flex",flexDirection:"column",gap:12},field:{display:"flex",flexDirection:"column",gap:4},fieldLabel:{fontSize:12,fontWeight:500,color:"#a6adc8"},fieldDesc:{fontSize:11,color:"#6c7086"},input:{padding:"8px 10px",background:"var(--surface-0, #1e1e2e)",border:"1px solid var(--border, #313244)",borderRadius:6,color:"#cdd6f4",fontSize:13,fontFamily:"inherit"},badge:t=>{const a={socket:"#a6e3a1",polling:"#89b4fa",none:"#6c7086"}[t]??"#6c7086";return{display:"inline-block",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:500,background:`${a}26`,color:a,border:`1px solid ${a}55`}},rowGap:{display:"flex",gap:12},buttons:{display:"flex",gap:8,marginTop:12},btnPrimary:{padding:"8px 16px",background:"#89b4fa",color:"#1e1e2e",border:"none",borderRadius:6,cursor:"pointer",fontWeight:500,fontSize:13},btnSecondary:{padding:"8px 16px",background:"transparent",color:"#cdd6f4",border:"1px solid var(--border, #313244)",borderRadius:6,cursor:"pointer",fontSize:13},btnDanger:{padding:"8px 16px",background:"transparent",color:"#f38ba8",border:"1px solid rgba(243,139,168,0.4)",borderRadius:6,cursor:"pointer",fontSize:13},alert:t=>({padding:"8px 12px",borderRadius:6,fontSize:12,background:t==="error"?"rgba(243,139,168,0.15)":"rgba(166,227,161,0.15)",color:t==="error"?"#f38ba8":"#a6e3a1",border:`1px solid ${t==="error"?"rgba(243,139,168,0.3)":"rgba(166,227,161,0.3)"}`})},j="/api/slack/instances";async function N(){const t=await b(m(j));if(!t.ok)throw new Error(`HTTP ${t.status}`);return(await t.json()).instances}async function B(t){const i=await b(m(`${j}/${encodeURIComponent(t)}/values`));if(!i.ok)throw new Error(`HTTP ${i.status}`);return(await i.json()).values}async function K(t,i){const a=await b(m(j),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:t,label:i})});if(!a.ok){const f=await a.json().catch(()=>({}));throw new Error(f.error||`HTTP ${a.status}`)}}async function H(t,i){const a=await b(m(`${j}/${encodeURIComponent(t)}`),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!a.ok){const f=await a.json().catch(()=>({}));throw new Error(f.error||`HTTP ${a.status}`)}}async function W(t){const i=await b(m(`${j}/${encodeURIComponent(t)}`),{method:"DELETE"});if(!i.ok){const a=await i.json().catch(()=>({}));throw new Error(a.error||`HTTP ${i.status}`)}}const V=({integration:t,onCancel:i})=>{const[a,f]=h.useState([]),[o,v]=h.useState("default"),[l,S]=h.useState(null),[T,_]=h.useState(null),[g,I]=h.useState(""),[D,A]=h.useState(!1),[L,E]=h.useState(!1),[w,x]=h.useState(null),y=h.useCallback(async()=>{try{const n=await N();f(n),!n.some(d=>d.id===o)&&n.length>0&&v(n[0].id)}catch(n){x({kind:"error",message:`Failed to load instances: ${n.message}`})}},[o]),k=h.useCallback(async()=>{if(o){A(!0);try{const n=await B(o);S(n),_(n);const r=a.find(d=>d.id===o);I((r==null?void 0:r.label)??o)}catch(n){x({kind:"error",message:`Failed to load instance: ${n.message}`})}finally{A(!1)}}},[o,a]);h.useEffect(()=>{y()},[y]),h.useEffect(()=>{k()},[k]);const P=async()=>{const n=window.prompt('Instance id (kebab-case, e.g. "personal", "team-bot"):');if(!n)return;const r=window.prompt("Display label:",n)||n;try{await K(n.trim(),r.trim()),await y(),v(n.trim()),x({kind:"success",message:`Created "${n}"`})}catch(d){x({kind:"error",message:d.message})}},O=async()=>{if(o!=="default"&&window.confirm(`Delete Slack instance "${o}"? This disconnects it and removes its config.`))try{await W(o),v("default"),await y(),x({kind:"success",message:"Instance deleted"})}catch(n){x({kind:"error",message:n.message})}},R=async()=>{if(!(!l||!T)){E(!0);try{const n={};Object.keys(l).forEach(p=>{const u=l[p];if(u!==T[p]){if((p==="SLACK_BOT_TOKEN"||p==="SLACK_APP_TOKEN")&&u==="********")return;n[p]=u}});const r=a.find(p=>p.id===o),d=r&&g.trim()&&g.trim()!==r.label;await H(o,{label:d?g.trim():void 0,values:Object.keys(n).length>0?n:void 0}),x({kind:"success",message:"Saved. Slack will reconnect with the new settings."}),await y(),await k()}catch(n){x({kind:"error",message:n.message})}finally{E(!1)}}},c=(n,r)=>{l&&S({...l,[n]:r})};return e.jsxs("div",{children:[e.jsx("div",{style:{marginBottom:12,fontSize:12,color:"#a6adc8"},children:"Add multiple Slack connections side-by-side. The default instance maps to your existing bot / token; add more for personal (xoxp-) tokens or additional workspaces."}),w&&e.jsx("div",{style:{...s.alert(w.kind),marginBottom:12},children:w.message}),e.jsxs("div",{style:s.container,children:[e.jsxs("div",{style:s.list,children:[a.map(n=>{var d,p,u;const r=((d=n.config)==null?void 0:d.currentMode)??"none";return e.jsxs("div",{style:s.listItem(n.id===o),onClick:()=>v(n.id),children:[e.jsx("div",{style:s.label,children:n.label}),e.jsxs("div",{style:s.sub,children:[e.jsx("span",{style:s.badge(r),children:r==="none"?"—":r}),(p=n.status)!=null&&p.connected?" • connected":(u=n.status)!=null&&u.error?" • error":" • idle"]})]},n.id)}),e.jsx("button",{type:"button",style:s.addBtn,onClick:P,children:"+ Add Instance"})]}),e.jsxs("div",{style:s.editor,children:[D&&e.jsx("div",{style:{color:"#6c7086",fontSize:13},children:"Loading…"}),!D&&l&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:s.field,children:[e.jsx("span",{style:s.fieldLabel,children:"Display label"}),e.jsx("input",{type:"text",style:s.input,value:g,onChange:n=>I(n.target.value),disabled:!1}),e.jsxs("span",{style:s.fieldDesc,children:["Shown in the instance list. Id is fixed: ",e.jsx("code",{children:o})]})]}),e.jsxs("div",{style:s.field,children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:l.enabled,onChange:n=>c("enabled",n.target.checked)}),e.jsx("span",{style:s.fieldLabel,children:"Enabled"})]}),e.jsx("span",{style:s.fieldDesc,children:"Toggle off to disconnect this instance without deleting its config."})]}),e.jsxs("div",{style:s.field,children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:l.mirrorOwnMessages,onChange:n=>c("mirrorOwnMessages",n.target.checked)}),e.jsx("span",{style:s.fieldLabel,children:"Mirror messages I send too"})]}),e.jsxs("span",{style:s.fieldDesc,children:["Capture your outgoing messages alongside incoming ones (logged as ",e.jsx("code",{children:"direction:outbound"}),"). Recommended for personal (xoxp-) tokens. Triggers do not fire on your own messages — that would loop."]})]}),e.jsxs("div",{style:s.field,children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:l.reactOnTrigger,onChange:n=>c("reactOnTrigger",n.target.checked)}),e.jsx("span",{style:s.fieldLabel,children:"Auto-react with 👀 on trigger"})]}),e.jsxs("span",{style:s.fieldDesc,children:["When a Slack trigger fires on an incoming message, react with ",e.jsx("code",{children:":eyes:"}),' as an "I saw it, working on it" ack. Turn off for accounts where the reaction is noisy. The server env ',e.jsx("code",{children:"SLACK_REACT_ON_TRIGGER=false"})," still disables it across all instances."]})]}),e.jsxs("div",{style:s.field,children:[e.jsx("span",{style:s.fieldLabel,children:"Slack Token"}),e.jsx("input",{type:"password",style:s.input,placeholder:"xoxb-... or xoxp-...",value:l.SLACK_BOT_TOKEN,onChange:n=>c("SLACK_BOT_TOKEN",n.target.value)}),e.jsxs("span",{style:s.fieldDesc,children:["Bot token (xoxb-) → Socket Mode. User token (xoxp-) → Web API polling (~30-60s lag). Stored encrypted under a per-instance key; leave as ",e.jsx("code",{children:"********"})," to keep the existing token."]})]}),e.jsxs("div",{style:s.field,children:[e.jsx("span",{style:s.fieldLabel,children:"App Token (Socket Mode only)"}),e.jsx("input",{type:"password",style:s.input,placeholder:"xapp-...",value:l.SLACK_APP_TOKEN,onChange:n=>c("SLACK_APP_TOKEN",n.target.value)}),e.jsx("span",{style:s.fieldDesc,children:"Required for xoxb- only. Leave blank for xoxp- (polling mode)."})]}),e.jsxs("div",{style:s.rowGap,children:[e.jsxs("div",{style:{...s.field,flex:1},children:[e.jsx("span",{style:s.fieldLabel,children:"Inbound Mode"}),e.jsxs("select",{style:s.input,value:l.authMode,onChange:n=>c("authMode",n.target.value),children:[e.jsx("option",{value:"auto",children:"Auto (from token prefix)"}),e.jsx("option",{value:"socket",children:"Socket Mode (xoxb-)"}),e.jsx("option",{value:"polling",children:"Polling (xoxp-)"})]})]}),e.jsxs("div",{style:{...s.field,flex:1},children:[e.jsx("span",{style:s.fieldLabel,children:"Default Channel"}),e.jsx("input",{type:"text",style:s.input,placeholder:"C0123456789",value:l.defaultChannelId,onChange:n=>c("defaultChannelId",n.target.value)})]})]}),e.jsxs("div",{style:s.rowGap,children:[e.jsxs("div",{style:{...s.field,flex:1},children:[e.jsx("span",{style:s.fieldLabel,children:"Polling Interval (s)"}),e.jsx("input",{type:"number",style:s.input,min:10,max:600,value:l.pollingIntervalSec,onChange:n=>c("pollingIntervalSec",Number(n.target.value))})]}),e.jsxs("div",{style:{...s.field,flex:1},children:[e.jsx("span",{style:s.fieldLabel,children:"Concurrency"}),e.jsx("input",{type:"number",style:s.input,min:1,max:8,value:l.pollingConcurrency,onChange:n=>c("pollingConcurrency",Number(n.target.value))})]}),e.jsxs("div",{style:{...s.field,flex:1},children:[e.jsx("span",{style:s.fieldLabel,children:"Backfill Cap (msgs)"}),e.jsx("input",{type:"number",style:s.input,min:1,max:1e3,value:l.pollingBackfillMessageCap,onChange:n=>c("pollingBackfillMessageCap",Number(n.target.value))})]}),e.jsxs("div",{style:{...s.field,flex:1},children:[e.jsx("span",{style:s.fieldLabel,children:"Min ms between calls"}),e.jsx("input",{type:"number",style:s.input,min:0,max:1e4,value:l.pollingMinMsBetweenCalls,onChange:n=>c("pollingMinMsBetweenCalls",Number(n.target.value))}),e.jsx("span",{style:{...s.fieldDesc,fontSize:11},children:"Throttle. 1500 ≈ 40 req/min. Set 0 to disable."})]})]}),e.jsxs("div",{style:s.field,children:[e.jsx("span",{style:s.fieldLabel,children:"Channel Types (poll all of these)"}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:12,marginTop:4},children:C.map(n=>{const d=M(l.pollingChannelTypes).has(n);return e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:6,cursor:"pointer",fontSize:13},children:[e.jsx("input",{type:"checkbox",checked:d,onChange:p=>{const u=new Set(M(l.pollingChannelTypes));p.target.checked?u.add(n):u.delete(n),c("pollingChannelTypes",$(u))}}),e.jsx("span",{children:z[n]})]},n)})}),e.jsx("span",{style:s.fieldDesc,children:"Determines which channel types are polled when the allowlist below is empty. Tick all four for full coverage. Heads-up: hundreds of channels at once can hit Slack's rate limit (~50 req/min) — use the allowlist to narrow down."})]}),e.jsxs("div",{style:s.field,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("span",{style:s.fieldLabel,children:"Channel Allowlist (optional)"}),l.pollingChannelAllowlist&&e.jsx("button",{type:"button",style:{...s.btnSecondary,padding:"4px 10px",fontSize:12},onClick:()=>c("pollingChannelAllowlist",""),title:"Clear the allowlist — fall back to polling all channels per the type checkboxes above.",children:"Include all (clear list)"})]}),e.jsx("textarea",{style:{...s.input,minHeight:60,fontFamily:"monospace",fontSize:12},placeholder:`C0123456789, G0987654321
2
+ C9999999999`,value:l.pollingChannelAllowlist,onChange:n=>c("pollingChannelAllowlist",n.target.value)}),e.jsx("span",{style:s.fieldDesc,children:'Comma- or newline-separated channel IDs. When set, polling restricts to these channels (plus DMs if "Always include DMs" is on). The Channel Types checkboxes above are ignored while an allowlist is active. Leave blank to fall back to polling all channels per the type checkboxes.'})]}),e.jsxs("div",{style:s.field,children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:l.pollingDmsAlways,onChange:n=>c("pollingDmsAlways",n.target.checked)}),e.jsx("span",{style:s.fieldLabel,children:"Always include DMs"})]}),e.jsx("span",{style:s.fieldDesc,children:"When the allowlist is set, still poll all 1:1 DMs (D-prefix). Default on. Turn off for strict allowlist-only mode."})]}),e.jsxs("div",{style:s.buttons,children:[e.jsx("button",{type:"button",style:s.btnPrimary,onClick:R,disabled:L,children:L?"Saving…":"Save & Reconnect"}),e.jsx("button",{type:"button",style:s.btnSecondary,onClick:i,children:"Close"}),o!=="default"&&e.jsx("button",{type:"button",style:{...s.btnDanger,marginLeft:"auto"},onClick:O,children:"Delete Instance"})]})]})]})]})]})};export{V as SlackMultiInstanceSetup,V as default};
@@ -1 +1 @@
1
- import{u as Ze,aE as es,aF as ss,aG as as,aH as ns,r as t,J as Ee,S as ne,aI as te,A as Ae,l as le,aJ as ts,s as S,h as ls,j as s,aK as os,_ as De,aL as x,aM as is,aN as oe,I as ie,aq as T,ao as K,aO as cs,ap as ce,aP as re,aQ as rs,K as ds}from"./main-9uTEp9Lr.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function Ie(r,j){const b=j.filter(C=>!r.has(C));return b.length===0?`${j[Math.floor(Math.random()*j.length)]}-${Date.now()%1e3}`:b[Math.floor(Math.random()*b.length)]}function hs({isOpen:r,onClose:j,onSpawnStart:b,onSpawnEnd:C,spawnPosition:_e,spawnAreaId:N}){const{t:a}=Ze(["terminal","common"]),P=es(),p=ss(),de=as(),H=de.length>0?de:ns,[m,v]=t.useState(""),[M,F]=t.useState(()=>Ee(ne.LAST_CWD)),[i,k]=t.useState("scout"),[pe,I]=t.useState(!1),[Le,R]=t.useState(!1),[me,J]=t.useState(!1),[ue,he]=t.useState(""),[y,X]=t.useState([]),[E,O]=t.useState(null),[$e,we]=t.useState(!1),[_,xe]=t.useState(""),[h,Te]=t.useState(""),[U,Pe]=t.useState(!1),[z,Fe]=t.useState("bypass"),[o,Y]=t.useState("claude"),[f,A]=t.useState({fullAuto:!0,sandbox:"workspace-write",approvalMode:"on-request",search:!1}),[fe,Q]=t.useState(new Set),[V,ge]=t.useState("opus[1m]"),[Z,je]=t.useState("xHigh"),[ee,Re]=t.useState("gpt-5.3-codex"),[se,Oe]=t.useState("minimax/MiniMax-M1-80k"),[Ne,Ue]=t.useState(""),[D,ze]=t.useState(""),q=t.useRef(null),ve=t.useRef(!1),L=t.useCallback(()=>{window.__spawnModalAreaContext=null},[]),w=t.useMemo(()=>P.filter(e=>e.enabled),[P]),qe=["full-notifications","streaming-exec","task-label","report-task-to-boss","agent-tracking","send-message-to-agent"];t.useEffect(()=>{if(r&&!ve.current){if(w.length>0){const l=w.filter(c=>qe.includes(c.slug)).map(c=>c.id);l.length>0&&Q(new Set(l))}const n=Ee(ne.DEFAULT_AGENT_CLASS);if(n==="random"){const c=[...Object.keys(rs),...p.map(u=>u.id)];k(c[Math.floor(Math.random()*c.length)])}else k(n||"scout")}ve.current=r},[r,w,p]);const Se=t.useMemo(()=>{if(!D.trim())return w;const e=D.toLowerCase();return w.filter(n=>n.name.toLowerCase().includes(e)||n.description.toLowerCase().includes(e)||n.slug.toLowerCase().includes(e))},[w,D]),Ge=t.useCallback(e=>{Q(n=>{const l=new Set(n);return l.has(e)?l.delete(e):l.add(e),l})},[]);t.useMemo(()=>w.filter(e=>e.assignedAgentClasses.includes(i)),[w,i]);const We=t.useMemo(()=>{var n;const e=p.find(l=>l.id===i);return(n=e==null?void 0:e.defaultSkillIds)!=null&&n.length?P.filter(l=>e.defaultSkillIds.includes(l.id)):[]},[p,i,P]),be=t.useMemo(()=>{if(!_.trim())return y;const e=_.toLowerCase();return y.filter(n=>n.sessionId.toLowerCase().includes(e)||n.projectPath.toLowerCase().includes(e)||n.firstMessage&&n.firstMessage.toLowerCase().includes(e))},[y,_]),G=t.useMemo(()=>{if(!h.trim())return p;const e=h.toLowerCase();return p.filter(n=>n.name.toLowerCase().includes(e)||n.description.toLowerCase().includes(e)||n.id.toLowerCase().includes(e))},[p,h]),W=t.useMemo(()=>{if(!h.trim())return te;const e=h.toLowerCase();return te.filter(n=>{const l=Ae[n.id];return n.name.toLowerCase().includes(e)||n.id.toLowerCase().includes(e)||l.description.toLowerCase().includes(e)})},[h]);t.useEffect(()=>{if(!r||!h.trim())return;const e=[...G.map(n=>n.id),...W.map(n=>n.id)];e.length===1&&e[0]!==i&&k(e[0])},[r,h,G,W,i]);const d=t.useMemo(()=>p.find(e=>e.id===i),[p,i]),Be=t.useMemo(()=>{if(d!=null&&d.model)return d.model},[d]),Ke=t.useMemo(()=>{if(d!=null&&d.customModelPath)return le(`/api/custom-models/${d.id}`)},[d]),He=d==null?void 0:d.modelScale,Je=t.useMemo(()=>d?"scout":i,[i,d]),B=t.useCallback(async e=>{we(!0);try{const n=e?le(`/api/agents/claude-sessions?cwd=${encodeURIComponent(e)}`):le("/api/agents/claude-sessions"),c=await(await ts(n)).json();X(c.sessions||[])}catch(n){console.error("Failed to fetch sessions:",n),X([])}finally{we(!1)}},[]);t.useEffect(()=>{r?B(M||void 0):(X([]),O(null),xe(""))},[r,B]),t.useEffect(()=>{if(!r)return;const e=setTimeout(()=>{B(M||void 0),O(null)},300);return()=>clearTimeout(e)},[M,r,B]),t.useEffect(()=>{if(!r||!N)return;const e=S.getState().areas.get(N);if(e!=null&&e.directories&&e.directories.length>0){F(e.directories[0]);return}const n=Array.from(S.getState().agents.values()).filter(g=>{var $;return(($=S.getAreaForAgent(g.id))==null?void 0:$.id)===N&&g.cwd});if(n.length===0)return;const l=new Map;for(const g of n)l.set(g.cwd,(l.get(g.cwd)||0)+1);let c="",u=0;for(const[g,$]of l)$>u&&(c=g,u=$);c&&F(c)},[r,N]),t.useEffect(()=>{if(r){const e=new Set(Array.from(S.getState().agents.values()).map(u=>u.name)),n=Ie(e,H),l=p.find(u=>u.id===i),c=l?`${l.name} ${n}`:n;v(c),q.current&&(q.current.focus(),q.current.select())}},[r,H]),t.useEffect(()=>{if(!r)return;const e=p.find(n=>n.id===i);if(e){const n=p.find(l=>m.startsWith(l.name+" "));if(n){const l=m.substring(n.name.length+1);v(`${e.name} ${l}`)}else v(`${e.name} ${m}`)}else{const n=p.find(l=>m.startsWith(l.name+" "));if(n){const l=m.substring(n.name.length+1);v(l)}}},[i]),t.useEffect(()=>{i==="boss"&&ge("claude-opus-4-7")},[i]);const Xe=()=>{var c;console.log("[SpawnModal] handleSpawn called"),R(!1);const e=E&&((c=y.find(u=>u.sessionId===E))==null?void 0:c.projectPath)||M;if(console.log("[SpawnModal] Effective CWD:",e),console.log("[SpawnModal] Agent name:",m),console.log("[SpawnModal] Agent class:",i),console.log("[SpawnModal] Permission mode:",z),console.log("[SpawnModal] Provider:",o),console.log("[SpawnModal] Use Chrome:",U),console.log("[SpawnModal] Session ID:",E||"none"),!e.trim()){console.error("[SpawnModal] Empty CWD, showing error"),R(!0);return}if(!m.trim()){console.log("[SpawnModal] Empty name, regenerating");const u=new Set(Array.from(S.getState().agents.values()).map(g=>g.name));v(Ie(u,H));return}ds(ne.LAST_CWD,e),I(!0),b();const n=Array.from(fe),l=Ne.trim()||void 0;console.log("[SpawnModal] Calling store.spawnAgent with:",{name:m.trim(),class:i,cwd:e.trim(),sessionId:E||void 0,useChrome:o==="claude"?U:!1,permissionMode:z,provider:o,codexConfig:o==="codex"?f:void 0,codexModel:o==="codex"?ee:void 0,opencodeModel:o==="opencode"?se:void 0,initialSkillIds:n,model:o==="claude"?V:void 0,customInstructions:l?`${l.length} chars`:void 0,spawnAreaId:N||void 0}),window.__spawnModalAreaContext=N?{areaId:N}:null,S.spawnAgent(m.trim(),i,e.trim(),_e||void 0,E||void 0,o==="claude"?U:!1,z,n,o,o==="codex"?f:void 0,o==="codex"?ee:void 0,o==="claude"?V:void 0,l,o==="claude"?Z:void 0,o==="opencode"?se:void 0)},Ce=()=>{console.log("[SpawnModal] Agent creation successful"),I(!1),v(""),Q(new Set),L(),C(),j()},Me=()=>{console.error("[SpawnModal] Agent creation failed"),I(!1),R(!0),L(),C()},ke=e=>{console.log("[SpawnModal] Directory not found:",e),I(!1),he(e),J(!0),C()},ye=()=>{J(!1),I(!0),b(),S.createDirectoryAndSpawn(ue,m.trim(),i)},ae=()=>{J(!1),he(""),L()};t.useEffect(()=>(window.__spawnModalSuccess=Ce,window.__spawnModalError=Me,window.__spawnModalDirNotFound=ke,()=>{L(),delete window.__spawnModalSuccess,delete window.__spawnModalError,delete window.__spawnModalDirNotFound}),[m,i,Ce,Me,ke,L]);const{handleMouseDown:Ye,handleClick:Qe}=ls(j),Ve=e=>{e.key==="Escape"&&j()};return!r&&!me?null:me?s.jsx("div",{className:"modal-overlay visible",onClick:ae,onKeyDown:e=>{e.key==="Escape"&&ae(),e.key==="Enter"&&ye()},children:s.jsxs("div",{className:"modal confirm-modal",onClick:e=>e.stopPropagation(),children:[s.jsx("div",{className:"modal-header",children:a("terminal:spawn.directoryNotFound")}),s.jsxs("div",{className:"modal-body confirm-modal-body",children:[s.jsx("p",{children:a("terminal:spawn.directoryNotExist")}),s.jsx("code",{className:"confirm-modal-path",children:ue}),s.jsx("p",{children:a("terminal:spawn.wouldYouCreate")})]}),s.jsxs("div",{className:"modal-footer",children:[s.jsx("button",{className:"btn btn-secondary",onClick:ae,children:a("common:buttons.cancel")}),s.jsx("button",{className:"btn btn-primary",onClick:ye,autoFocus:!0,children:a("terminal:spawn.createDirectory")})]})]})}):s.jsx("div",{className:`modal-overlay ${r?"visible":""}`,onMouseDown:Ye,onClick:Qe,onKeyDown:Ve,children:s.jsxs("div",{className:"modal spawn-modal",children:[s.jsx("div",{className:"modal-header",children:a("terminal:spawn.deployTitle")}),s.jsxs("div",{className:"modal-body spawn-modal-body",children:[s.jsxs("div",{className:"spawn-top-section",children:[s.jsx("div",{className:"spawn-preview-compact",children:s.jsx(os,{agentClass:Je,modelFile:Be,customModelUrl:Ke,modelScale:He,width:100,height:120})}),s.jsxs("div",{className:"spawn-class-section",children:[s.jsx("div",{className:"spawn-class-label",children:a("terminal:spawn.agentClass")}),p.length+te.length>6&&s.jsx("input",{type:"text",className:"spawn-input class-search-input",placeholder:a("terminal:spawn.filterClasses"),value:h,onChange:e=>Te(e.target.value)}),s.jsxs("div",{className:"class-selector-inline",children:[G.map(e=>s.jsxs("button",{className:`class-chip ${i===e.id?"selected":""}`,onClick:()=>k(e.id),title:e.description,children:[s.jsx(De,{classId:e.id,size:18,className:"class-chip-icon"}),s.jsx("span",{className:"class-chip-name",children:e.name})]},e.id)),W.map(e=>{const n=Ae[e.id];return s.jsxs("button",{className:`class-chip ${i===e.id?"selected":""}`,onClick:()=>k(e.id),title:n.description,children:[s.jsx(De,{classId:e.id,size:18,className:"class-chip-icon"}),s.jsx("span",{className:"class-chip-name",children:e.name})]},e.id)}),h&&G.length===0&&W.length===0&&s.jsx("div",{className:"class-search-empty",children:a("terminal:spawn.noClassesMatch",{query:h})})]})]})]}),s.jsxs("div",{className:"spawn-form-section",children:[s.jsxs("div",{className:"spawn-form-row",children:[s.jsxs("div",{className:"spawn-field",children:[s.jsx("label",{className:"spawn-label",children:a("common:labels.name")}),s.jsx("input",{ref:q,type:"text",className:"spawn-input",placeholder:a("terminal:spawn.agentNamePlaceholder"),value:m,onChange:e=>v(e.target.value)})]}),s.jsxs("div",{className:"spawn-field spawn-field-wide",children:[s.jsxs("label",{className:"spawn-label",children:[a("terminal:spawn.workingDir"),s.jsx(x,{text:a("terminal:spawn.helpWorkingDir"),title:a("terminal:spawn.workingDir"),position:"top",size:"sm"})]}),s.jsx(is,{value:M,onChange:e=>{F(e),R(!1)},placeholder:a("terminal:spawn.workingDirPlaceholder"),className:`spawn-input ${Le?"error":""}`,directoriesOnly:!0})]})]}),s.jsxs("div",{className:"spawn-form-row",children:[s.jsxs("div",{className:"spawn-field",children:[s.jsxs("label",{className:"spawn-label",children:[a("terminal:spawn.selectRuntime"),s.jsx(x,{text:a("terminal:spawn.helpRuntime"),title:a("terminal:spawn.runtimeTitle"),position:"top",size:"sm"})]}),s.jsxs("div",{className:"spawn-select-row",children:[s.jsxs("button",{className:`spawn-select-btn ${o==="claude"?"selected":""}`,onClick:()=>Y("claude"),title:a("terminal:spawn.useClaudeCli"),children:[s.jsx("img",{src:"/assets/claude.ico",alt:"Claude",className:"spawn-provider-icon"}),s.jsx("span",{children:"Claude"})]}),s.jsxs("button",{className:`spawn-select-btn ${o==="codex"?"selected":""}`,onClick:()=>Y("codex"),title:a("terminal:spawn.useCodexCli"),children:[s.jsx("img",{src:"/assets/codex.ico",alt:"Codex",className:"spawn-provider-icon"}),s.jsx("span",{children:"Codex"})]}),s.jsxs("button",{className:`spawn-select-btn spawn-select-btn--opencode ${o==="opencode"?"selected":""}`,onClick:()=>Y("opencode"),title:"Use OpenCode CLI (multi-provider)",children:[s.jsx("img",{src:"/assets/opencode.svg",alt:"OpenCode",className:"spawn-provider-icon"}),s.jsx("span",{children:"OpenCode"})]})]})]}),s.jsxs("div",{className:"spawn-field",children:[s.jsxs("label",{className:"spawn-label",children:[a("common:labels.permissions"),s.jsx(x,{text:a("terminal:spawn.helpPermission"),title:a("terminal:spawn.permissionMode"),position:"top",size:"sm"})]}),s.jsx("div",{className:"spawn-select-row",children:Object.keys(oe).map(e=>s.jsxs("button",{className:`spawn-select-btn ${z===e?"selected":""}`,onClick:()=>Fe(e),title:oe[e].description,children:[s.jsx("span",{children:s.jsx(ie,{name:e==="bypass"?"bolt":"lock",size:12})}),s.jsx("span",{children:oe[e].label})]},e))})]})]}),s.jsx("div",{className:"spawn-form-row",children:s.jsxs("div",{className:"spawn-field",children:[s.jsxs("label",{className:"spawn-label",children:[a("common:labels.model"),s.jsx(x,{text:a("terminal:spawn.helpModel"),title:a("terminal:spawn.modelTitle"),position:"top",size:"sm"})]}),o==="claude"?s.jsx("div",{className:"spawn-select-row spawn-select-row--wrap",children:Object.keys(T).filter(e=>!T[e].deprecated).map(e=>s.jsxs("button",{className:`spawn-select-btn ${V===e?"selected":""}`,onClick:()=>ge(e),title:T[e].description,children:[s.jsx("span",{children:T[e].icon}),s.jsx("span",{children:T[e].label})]},e))}):o==="codex"?s.jsx("div",{className:"spawn-select-row spawn-select-row--codex-models",children:Object.keys(K).map(e=>s.jsxs("button",{className:`spawn-select-btn ${ee===e?"selected":""}`,onClick:()=>Re(e),title:K[e].description,children:[s.jsx("span",{children:K[e].icon}),s.jsx("span",{children:K[e].label})]},e))}):o==="opencode"?s.jsx(cs,{value:se,onChange:Oe,inputId:"spawn-opencode-model"}):s.jsx("div",{className:"spawn-inline-hint",children:a("terminal:spawn.chooseCodexModel")})]})}),s.jsxs("div",{className:"spawn-form-row",children:[o==="claude"&&s.jsxs("div",{className:"spawn-field",children:[s.jsx("label",{className:"spawn-label",children:"Effort"}),s.jsxs("div",{className:"spawn-select-row spawn-select-row--effort",children:[s.jsx("button",{className:`spawn-select-btn spawn-select-btn--compact ${Z===void 0?"selected":""}`,onClick:()=>je(void 0),title:"Use default effort level",children:s.jsx("span",{children:"Default"})}),Object.keys(ce).map(e=>s.jsx("button",{className:`spawn-select-btn spawn-select-btn--compact ${Z===e?"selected":""}`,onClick:()=>je(e),title:ce[e].description,children:s.jsx("span",{children:ce[e].label})},e))]})]}),s.jsxs("div",{className:"spawn-field",children:[s.jsx("label",{className:"spawn-label",children:a("terminal:spawn.browser")}),s.jsxs("label",{className:"spawn-checkbox",children:[s.jsx("input",{type:"checkbox",checked:U,onChange:e=>Pe(e.target.checked),disabled:o!=="claude"}),s.jsxs("span",{children:[s.jsx(ie,{name:"globe",size:12})," ",a("terminal:spawn.chromeBrowser")]}),s.jsx(x,{text:a(o==="claude"?"terminal:spawn.helpChrome":"terminal:spawn.helpChromeDisabled"),title:a("terminal:spawn.chromeBrowser"),position:"top",size:"sm"})]})]})]}),o==="codex"&&s.jsxs("div",{className:"codex-config-section",children:[s.jsx("div",{className:"codex-config-title",children:a("terminal:spawn.codex.configuration")}),s.jsxs("div",{className:"codex-config-options",children:[s.jsxs("div",{className:"codex-option-group",children:[s.jsxs("label",{className:"spawn-checkbox",children:[s.jsx("input",{type:"checkbox",checked:f.fullAuto!==!1,onChange:e=>A(n=>({...n,fullAuto:e.target.checked}))}),s.jsx("span",{children:a("terminal:spawn.codex.fullAuto")}),s.jsx(x,{text:a("terminal:spawn.helpFullAuto"),title:a("terminal:spawn.fullAutoTitle"),position:"top",size:"sm"})]}),s.jsxs("label",{className:"spawn-checkbox",children:[s.jsx("input",{type:"checkbox",checked:!!f.search,onChange:e=>A(n=>({...n,search:e.target.checked}))}),s.jsx("span",{children:a("terminal:spawn.codex.search")}),s.jsx(x,{text:a("terminal:spawn.helpSearch"),title:a("terminal:spawn.searchTitle"),position:"top",size:"sm"})]})]}),f.fullAuto===!1&&s.jsxs("div",{className:"codex-option-group",children:[s.jsx("div",{className:"codex-option-header",children:a("terminal:spawn.codex.restrictions")}),s.jsxs("select",{className:"spawn-input codex-select",value:f.sandbox||"workspace-write",onChange:e=>A(n=>({...n,sandbox:e.target.value})),children:[s.jsxs("option",{value:"read-only",children:["📖 ",a("terminal:spawn.codex.sandboxReadOnly")]}),s.jsxs("option",{value:"workspace-write",children:["✏️ ",a("terminal:spawn.codex.sandboxWorkspaceWrite")]}),s.jsxs("option",{value:"danger-full-access",children:["⚡ ",a("terminal:spawn.codex.sandboxDangerFullAccess")]})]}),s.jsxs("select",{className:"spawn-input codex-select",value:f.approvalMode||"on-request",onChange:e=>A(n=>({...n,approvalMode:e.target.value})),children:[s.jsxs("option",{value:"untrusted",children:["🔒 ",a("terminal:spawn.codex.approvalsUntrusted")]}),s.jsxs("option",{value:"on-failure",children:["⚠️ ",a("terminal:spawn.codex.approvalsOnFailure")]}),s.jsxs("option",{value:"on-request",children:["🤔 ",a("terminal:spawn.codex.approvalsOnRequest")]}),s.jsxs("option",{value:"never",children:["✅ ",a("terminal:spawn.codex.approvalsNever")]})]})]}),s.jsxs("div",{className:"codex-option-group",children:[s.jsx("div",{className:"codex-option-header",children:a("terminal:spawn.codex.profile")}),s.jsx("input",{type:"text",className:"spawn-input codex-profile-input",placeholder:a("terminal:spawn.codex.profilePlaceholder"),value:f.profile||"",onChange:e=>A(n=>({...n,profile:e.target.value||void 0}))})]}),s.jsxs("div",{className:"codex-option-group",children:[s.jsx("div",{className:"codex-option-header",children:a("terminal:spawn.codex.reasoningEffort")}),s.jsxs("select",{className:"spawn-input codex-select",value:f.reasoningEffort||"",onChange:e=>A(n=>({...n,reasoningEffort:e.target.value||void 0})),children:[s.jsx("option",{value:"",children:a("terminal:spawn.codex.reasoningEffortDefault")}),Object.keys(re).map(e=>s.jsxs("option",{value:e,children:[re[e].icon," ",re[e].label]},e))]})]})]})]}),w.length>0&&s.jsxs("div",{className:"spawn-skills-section",children:[s.jsxs("label",{className:"spawn-label",children:[a("terminal:spawn.skills")," ",s.jsxs("span",{className:"spawn-label-hint",children:["(",a("common:labels.optional"),")"]}),s.jsx(x,{text:a("terminal:spawn.helpSkills"),title:a("terminal:spawn.skillsTitle"),position:"top",size:"sm"})]}),w.length>6&&s.jsx("input",{type:"text",className:"spawn-input skill-search-input",placeholder:a("terminal:spawn.filterSkills"),value:D,onChange:e=>ze(e.target.value)}),s.jsxs("div",{className:"spawn-skills-inline",children:[Se.map(e=>{const n=fe.has(e.id);return We.some(c=>c.id===e.id)?null:s.jsxs("button",{className:`spawn-skill-chip ${n?"selected":""}`,onClick:()=>Ge(e.id),title:e.description,children:[n&&s.jsx("span",{className:"spawn-skill-check",children:s.jsx(ie,{name:"check",size:10})}),s.jsx("span",{children:e.name}),e.builtin&&s.jsx("span",{className:"spawn-skill-builtin",children:"TC"})]},e.id)}),D&&Se.length===0&&s.jsx("div",{className:"skill-search-empty",children:a("terminal:spawn.noSkillsMatch",{query:D})})]})]}),s.jsxs("div",{className:"spawn-custom-instructions-section",children:[s.jsxs("label",{className:"spawn-label",children:[a("terminal:spawn.customInstructions")," ",s.jsxs("span",{className:"spawn-label-hint",children:["(",a("common:labels.optional"),")"]}),s.jsx(x,{text:a("terminal:spawn.helpCustomInstructions"),title:a("terminal:spawn.customInstructions"),position:"top",size:"sm"})]}),s.jsx("textarea",{className:"spawn-input spawn-textarea",placeholder:a("terminal:spawn.customInstructionsPlaceholder"),value:Ne,onChange:e=>Ue(e.target.value),rows:3})]}),s.jsxs("div",{className:"spawn-sessions-section",children:[s.jsxs("label",{className:"spawn-label",children:[a("terminal:spawn.linkSession")," ",s.jsxs("span",{className:"spawn-label-hint",children:["(",a("common:labels.optional"),")"]}),s.jsx(x,{text:a("terminal:spawn.helpLinkSession"),title:a("terminal:spawn.linkSessionTitle"),position:"top",size:"sm"})]}),y.length>0&&s.jsx("input",{type:"text",className:"spawn-input session-search-input",placeholder:a("terminal:spawn.searchSessions"),value:_,onChange:e=>xe(e.target.value)}),s.jsx("div",{className:"sessions-list",children:$e?s.jsx("div",{className:"sessions-loading",children:a("terminal:spawn.loadingSessions")}):y.length===0?s.jsx("div",{className:"sessions-empty",children:a("terminal:spawn.noSessions")}):be.length===0?s.jsx("div",{className:"sessions-empty",children:a("terminal:spawn.noSessionsMatch",{query:_})}):be.map(e=>{const n=E===e.sessionId,l=Date.now()-new Date(e.lastModified).getTime(),c=l<6e4?a("common:time.justNow"):l<36e5?a("common:time.minutesAgo",{count:Math.floor(l/6e4)}):l<864e5?a("common:time.hoursAgo",{count:Math.floor(l/36e5)}):a("common:time.daysAgo",{count:Math.floor(l/864e5)});return s.jsxs("div",{className:`session-item ${n?"selected":""}`,onClick:()=>{n?O(null):(O(e.sessionId),F(e.projectPath))},children:[s.jsxs("div",{className:"session-item-header",children:[s.jsx("span",{className:"session-item-path",children:e.projectPath}),s.jsx("span",{className:"session-item-age",children:c})]}),s.jsx("div",{className:"session-item-preview",children:e.firstMessage||a("terminal:spawn.messagesCount",{count:e.messageCount})})]},e.sessionId)})})]})]})]}),s.jsxs("div",{className:"modal-footer",children:[s.jsx("button",{className:"btn btn-secondary",onClick:j,children:a("common:buttons.cancel")}),s.jsx("button",{className:"btn btn-primary",onClick:Xe,disabled:pe,children:a(pe?"common:buttons.deploying":"common:buttons2.deploy")})]})]})})}export{hs as SpawnModal};
1
+ import{u as Ze,aE as es,aF as ss,aG as as,aH as ns,r as t,J as Ee,S as ne,aI as te,A as Ae,l as le,aJ as ts,s as S,h as ls,j as s,aK as os,_ as De,aL as x,aM as is,aN as oe,I as ie,aq as T,ao as K,aO as cs,ap as ce,aP as re,aQ as rs,K as ds}from"./main-XbhAPjbi.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function Ie(r,j){const b=j.filter(C=>!r.has(C));return b.length===0?`${j[Math.floor(Math.random()*j.length)]}-${Date.now()%1e3}`:b[Math.floor(Math.random()*b.length)]}function hs({isOpen:r,onClose:j,onSpawnStart:b,onSpawnEnd:C,spawnPosition:_e,spawnAreaId:N}){const{t:a}=Ze(["terminal","common"]),P=es(),p=ss(),de=as(),H=de.length>0?de:ns,[m,v]=t.useState(""),[M,F]=t.useState(()=>Ee(ne.LAST_CWD)),[i,k]=t.useState("scout"),[pe,I]=t.useState(!1),[Le,R]=t.useState(!1),[me,J]=t.useState(!1),[ue,he]=t.useState(""),[y,X]=t.useState([]),[E,O]=t.useState(null),[$e,we]=t.useState(!1),[_,xe]=t.useState(""),[h,Te]=t.useState(""),[U,Pe]=t.useState(!1),[z,Fe]=t.useState("bypass"),[o,Y]=t.useState("claude"),[f,A]=t.useState({fullAuto:!0,sandbox:"workspace-write",approvalMode:"on-request",search:!1}),[fe,Q]=t.useState(new Set),[V,ge]=t.useState("opus[1m]"),[Z,je]=t.useState("xHigh"),[ee,Re]=t.useState("gpt-5.3-codex"),[se,Oe]=t.useState("minimax/MiniMax-M1-80k"),[Ne,Ue]=t.useState(""),[D,ze]=t.useState(""),q=t.useRef(null),ve=t.useRef(!1),L=t.useCallback(()=>{window.__spawnModalAreaContext=null},[]),w=t.useMemo(()=>P.filter(e=>e.enabled),[P]),qe=["full-notifications","streaming-exec","task-label","report-task-to-boss","agent-tracking","send-message-to-agent"];t.useEffect(()=>{if(r&&!ve.current){if(w.length>0){const l=w.filter(c=>qe.includes(c.slug)).map(c=>c.id);l.length>0&&Q(new Set(l))}const n=Ee(ne.DEFAULT_AGENT_CLASS);if(n==="random"){const c=[...Object.keys(rs),...p.map(u=>u.id)];k(c[Math.floor(Math.random()*c.length)])}else k(n||"scout")}ve.current=r},[r,w,p]);const Se=t.useMemo(()=>{if(!D.trim())return w;const e=D.toLowerCase();return w.filter(n=>n.name.toLowerCase().includes(e)||n.description.toLowerCase().includes(e)||n.slug.toLowerCase().includes(e))},[w,D]),Ge=t.useCallback(e=>{Q(n=>{const l=new Set(n);return l.has(e)?l.delete(e):l.add(e),l})},[]);t.useMemo(()=>w.filter(e=>e.assignedAgentClasses.includes(i)),[w,i]);const We=t.useMemo(()=>{var n;const e=p.find(l=>l.id===i);return(n=e==null?void 0:e.defaultSkillIds)!=null&&n.length?P.filter(l=>e.defaultSkillIds.includes(l.id)):[]},[p,i,P]),be=t.useMemo(()=>{if(!_.trim())return y;const e=_.toLowerCase();return y.filter(n=>n.sessionId.toLowerCase().includes(e)||n.projectPath.toLowerCase().includes(e)||n.firstMessage&&n.firstMessage.toLowerCase().includes(e))},[y,_]),G=t.useMemo(()=>{if(!h.trim())return p;const e=h.toLowerCase();return p.filter(n=>n.name.toLowerCase().includes(e)||n.description.toLowerCase().includes(e)||n.id.toLowerCase().includes(e))},[p,h]),W=t.useMemo(()=>{if(!h.trim())return te;const e=h.toLowerCase();return te.filter(n=>{const l=Ae[n.id];return n.name.toLowerCase().includes(e)||n.id.toLowerCase().includes(e)||l.description.toLowerCase().includes(e)})},[h]);t.useEffect(()=>{if(!r||!h.trim())return;const e=[...G.map(n=>n.id),...W.map(n=>n.id)];e.length===1&&e[0]!==i&&k(e[0])},[r,h,G,W,i]);const d=t.useMemo(()=>p.find(e=>e.id===i),[p,i]),Be=t.useMemo(()=>{if(d!=null&&d.model)return d.model},[d]),Ke=t.useMemo(()=>{if(d!=null&&d.customModelPath)return le(`/api/custom-models/${d.id}`)},[d]),He=d==null?void 0:d.modelScale,Je=t.useMemo(()=>d?"scout":i,[i,d]),B=t.useCallback(async e=>{we(!0);try{const n=e?le(`/api/agents/claude-sessions?cwd=${encodeURIComponent(e)}`):le("/api/agents/claude-sessions"),c=await(await ts(n)).json();X(c.sessions||[])}catch(n){console.error("Failed to fetch sessions:",n),X([])}finally{we(!1)}},[]);t.useEffect(()=>{r?B(M||void 0):(X([]),O(null),xe(""))},[r,B]),t.useEffect(()=>{if(!r)return;const e=setTimeout(()=>{B(M||void 0),O(null)},300);return()=>clearTimeout(e)},[M,r,B]),t.useEffect(()=>{if(!r||!N)return;const e=S.getState().areas.get(N);if(e!=null&&e.directories&&e.directories.length>0){F(e.directories[0]);return}const n=Array.from(S.getState().agents.values()).filter(g=>{var $;return(($=S.getAreaForAgent(g.id))==null?void 0:$.id)===N&&g.cwd});if(n.length===0)return;const l=new Map;for(const g of n)l.set(g.cwd,(l.get(g.cwd)||0)+1);let c="",u=0;for(const[g,$]of l)$>u&&(c=g,u=$);c&&F(c)},[r,N]),t.useEffect(()=>{if(r){const e=new Set(Array.from(S.getState().agents.values()).map(u=>u.name)),n=Ie(e,H),l=p.find(u=>u.id===i),c=l?`${l.name} ${n}`:n;v(c),q.current&&(q.current.focus(),q.current.select())}},[r,H]),t.useEffect(()=>{if(!r)return;const e=p.find(n=>n.id===i);if(e){const n=p.find(l=>m.startsWith(l.name+" "));if(n){const l=m.substring(n.name.length+1);v(`${e.name} ${l}`)}else v(`${e.name} ${m}`)}else{const n=p.find(l=>m.startsWith(l.name+" "));if(n){const l=m.substring(n.name.length+1);v(l)}}},[i]),t.useEffect(()=>{i==="boss"&&ge("claude-opus-4-7")},[i]);const Xe=()=>{var c;console.log("[SpawnModal] handleSpawn called"),R(!1);const e=E&&((c=y.find(u=>u.sessionId===E))==null?void 0:c.projectPath)||M;if(console.log("[SpawnModal] Effective CWD:",e),console.log("[SpawnModal] Agent name:",m),console.log("[SpawnModal] Agent class:",i),console.log("[SpawnModal] Permission mode:",z),console.log("[SpawnModal] Provider:",o),console.log("[SpawnModal] Use Chrome:",U),console.log("[SpawnModal] Session ID:",E||"none"),!e.trim()){console.error("[SpawnModal] Empty CWD, showing error"),R(!0);return}if(!m.trim()){console.log("[SpawnModal] Empty name, regenerating");const u=new Set(Array.from(S.getState().agents.values()).map(g=>g.name));v(Ie(u,H));return}ds(ne.LAST_CWD,e),I(!0),b();const n=Array.from(fe),l=Ne.trim()||void 0;console.log("[SpawnModal] Calling store.spawnAgent with:",{name:m.trim(),class:i,cwd:e.trim(),sessionId:E||void 0,useChrome:o==="claude"?U:!1,permissionMode:z,provider:o,codexConfig:o==="codex"?f:void 0,codexModel:o==="codex"?ee:void 0,opencodeModel:o==="opencode"?se:void 0,initialSkillIds:n,model:o==="claude"?V:void 0,customInstructions:l?`${l.length} chars`:void 0,spawnAreaId:N||void 0}),window.__spawnModalAreaContext=N?{areaId:N}:null,S.spawnAgent(m.trim(),i,e.trim(),_e||void 0,E||void 0,o==="claude"?U:!1,z,n,o,o==="codex"?f:void 0,o==="codex"?ee:void 0,o==="claude"?V:void 0,l,o==="claude"?Z:void 0,o==="opencode"?se:void 0)},Ce=()=>{console.log("[SpawnModal] Agent creation successful"),I(!1),v(""),Q(new Set),L(),C(),j()},Me=()=>{console.error("[SpawnModal] Agent creation failed"),I(!1),R(!0),L(),C()},ke=e=>{console.log("[SpawnModal] Directory not found:",e),I(!1),he(e),J(!0),C()},ye=()=>{J(!1),I(!0),b(),S.createDirectoryAndSpawn(ue,m.trim(),i)},ae=()=>{J(!1),he(""),L()};t.useEffect(()=>(window.__spawnModalSuccess=Ce,window.__spawnModalError=Me,window.__spawnModalDirNotFound=ke,()=>{L(),delete window.__spawnModalSuccess,delete window.__spawnModalError,delete window.__spawnModalDirNotFound}),[m,i,Ce,Me,ke,L]);const{handleMouseDown:Ye,handleClick:Qe}=ls(j),Ve=e=>{e.key==="Escape"&&j()};return!r&&!me?null:me?s.jsx("div",{className:"modal-overlay visible",onClick:ae,onKeyDown:e=>{e.key==="Escape"&&ae(),e.key==="Enter"&&ye()},children:s.jsxs("div",{className:"modal confirm-modal",onClick:e=>e.stopPropagation(),children:[s.jsx("div",{className:"modal-header",children:a("terminal:spawn.directoryNotFound")}),s.jsxs("div",{className:"modal-body confirm-modal-body",children:[s.jsx("p",{children:a("terminal:spawn.directoryNotExist")}),s.jsx("code",{className:"confirm-modal-path",children:ue}),s.jsx("p",{children:a("terminal:spawn.wouldYouCreate")})]}),s.jsxs("div",{className:"modal-footer",children:[s.jsx("button",{className:"btn btn-secondary",onClick:ae,children:a("common:buttons.cancel")}),s.jsx("button",{className:"btn btn-primary",onClick:ye,autoFocus:!0,children:a("terminal:spawn.createDirectory")})]})]})}):s.jsx("div",{className:`modal-overlay ${r?"visible":""}`,onMouseDown:Ye,onClick:Qe,onKeyDown:Ve,children:s.jsxs("div",{className:"modal spawn-modal",children:[s.jsx("div",{className:"modal-header",children:a("terminal:spawn.deployTitle")}),s.jsxs("div",{className:"modal-body spawn-modal-body",children:[s.jsxs("div",{className:"spawn-top-section",children:[s.jsx("div",{className:"spawn-preview-compact",children:s.jsx(os,{agentClass:Je,modelFile:Be,customModelUrl:Ke,modelScale:He,width:100,height:120})}),s.jsxs("div",{className:"spawn-class-section",children:[s.jsx("div",{className:"spawn-class-label",children:a("terminal:spawn.agentClass")}),p.length+te.length>6&&s.jsx("input",{type:"text",className:"spawn-input class-search-input",placeholder:a("terminal:spawn.filterClasses"),value:h,onChange:e=>Te(e.target.value)}),s.jsxs("div",{className:"class-selector-inline",children:[G.map(e=>s.jsxs("button",{className:`class-chip ${i===e.id?"selected":""}`,onClick:()=>k(e.id),title:e.description,children:[s.jsx(De,{classId:e.id,size:18,className:"class-chip-icon"}),s.jsx("span",{className:"class-chip-name",children:e.name})]},e.id)),W.map(e=>{const n=Ae[e.id];return s.jsxs("button",{className:`class-chip ${i===e.id?"selected":""}`,onClick:()=>k(e.id),title:n.description,children:[s.jsx(De,{classId:e.id,size:18,className:"class-chip-icon"}),s.jsx("span",{className:"class-chip-name",children:e.name})]},e.id)}),h&&G.length===0&&W.length===0&&s.jsx("div",{className:"class-search-empty",children:a("terminal:spawn.noClassesMatch",{query:h})})]})]})]}),s.jsxs("div",{className:"spawn-form-section",children:[s.jsxs("div",{className:"spawn-form-row",children:[s.jsxs("div",{className:"spawn-field",children:[s.jsx("label",{className:"spawn-label",children:a("common:labels.name")}),s.jsx("input",{ref:q,type:"text",className:"spawn-input",placeholder:a("terminal:spawn.agentNamePlaceholder"),value:m,onChange:e=>v(e.target.value)})]}),s.jsxs("div",{className:"spawn-field spawn-field-wide",children:[s.jsxs("label",{className:"spawn-label",children:[a("terminal:spawn.workingDir"),s.jsx(x,{text:a("terminal:spawn.helpWorkingDir"),title:a("terminal:spawn.workingDir"),position:"top",size:"sm"})]}),s.jsx(is,{value:M,onChange:e=>{F(e),R(!1)},placeholder:a("terminal:spawn.workingDirPlaceholder"),className:`spawn-input ${Le?"error":""}`,directoriesOnly:!0})]})]}),s.jsxs("div",{className:"spawn-form-row",children:[s.jsxs("div",{className:"spawn-field",children:[s.jsxs("label",{className:"spawn-label",children:[a("terminal:spawn.selectRuntime"),s.jsx(x,{text:a("terminal:spawn.helpRuntime"),title:a("terminal:spawn.runtimeTitle"),position:"top",size:"sm"})]}),s.jsxs("div",{className:"spawn-select-row",children:[s.jsxs("button",{className:`spawn-select-btn ${o==="claude"?"selected":""}`,onClick:()=>Y("claude"),title:a("terminal:spawn.useClaudeCli"),children:[s.jsx("img",{src:"/assets/claude.ico",alt:"Claude",className:"spawn-provider-icon"}),s.jsx("span",{children:"Claude"})]}),s.jsxs("button",{className:`spawn-select-btn ${o==="codex"?"selected":""}`,onClick:()=>Y("codex"),title:a("terminal:spawn.useCodexCli"),children:[s.jsx("img",{src:"/assets/codex.ico",alt:"Codex",className:"spawn-provider-icon"}),s.jsx("span",{children:"Codex"})]}),s.jsxs("button",{className:`spawn-select-btn spawn-select-btn--opencode ${o==="opencode"?"selected":""}`,onClick:()=>Y("opencode"),title:"Use OpenCode CLI (multi-provider)",children:[s.jsx("img",{src:"/assets/opencode.svg",alt:"OpenCode",className:"spawn-provider-icon"}),s.jsx("span",{children:"OpenCode"})]})]})]}),s.jsxs("div",{className:"spawn-field",children:[s.jsxs("label",{className:"spawn-label",children:[a("common:labels.permissions"),s.jsx(x,{text:a("terminal:spawn.helpPermission"),title:a("terminal:spawn.permissionMode"),position:"top",size:"sm"})]}),s.jsx("div",{className:"spawn-select-row",children:Object.keys(oe).map(e=>s.jsxs("button",{className:`spawn-select-btn ${z===e?"selected":""}`,onClick:()=>Fe(e),title:oe[e].description,children:[s.jsx("span",{children:s.jsx(ie,{name:e==="bypass"?"bolt":"lock",size:12})}),s.jsx("span",{children:oe[e].label})]},e))})]})]}),s.jsx("div",{className:"spawn-form-row",children:s.jsxs("div",{className:"spawn-field",children:[s.jsxs("label",{className:"spawn-label",children:[a("common:labels.model"),s.jsx(x,{text:a("terminal:spawn.helpModel"),title:a("terminal:spawn.modelTitle"),position:"top",size:"sm"})]}),o==="claude"?s.jsx("div",{className:"spawn-select-row spawn-select-row--wrap",children:Object.keys(T).filter(e=>!T[e].deprecated).map(e=>s.jsxs("button",{className:`spawn-select-btn ${V===e?"selected":""}`,onClick:()=>ge(e),title:T[e].description,children:[s.jsx("span",{children:T[e].icon}),s.jsx("span",{children:T[e].label})]},e))}):o==="codex"?s.jsx("div",{className:"spawn-select-row spawn-select-row--codex-models",children:Object.keys(K).map(e=>s.jsxs("button",{className:`spawn-select-btn ${ee===e?"selected":""}`,onClick:()=>Re(e),title:K[e].description,children:[s.jsx("span",{children:K[e].icon}),s.jsx("span",{children:K[e].label})]},e))}):o==="opencode"?s.jsx(cs,{value:se,onChange:Oe,inputId:"spawn-opencode-model"}):s.jsx("div",{className:"spawn-inline-hint",children:a("terminal:spawn.chooseCodexModel")})]})}),s.jsxs("div",{className:"spawn-form-row",children:[o==="claude"&&s.jsxs("div",{className:"spawn-field",children:[s.jsx("label",{className:"spawn-label",children:"Effort"}),s.jsxs("div",{className:"spawn-select-row spawn-select-row--effort",children:[s.jsx("button",{className:`spawn-select-btn spawn-select-btn--compact ${Z===void 0?"selected":""}`,onClick:()=>je(void 0),title:"Use default effort level",children:s.jsx("span",{children:"Default"})}),Object.keys(ce).map(e=>s.jsx("button",{className:`spawn-select-btn spawn-select-btn--compact ${Z===e?"selected":""}`,onClick:()=>je(e),title:ce[e].description,children:s.jsx("span",{children:ce[e].label})},e))]})]}),s.jsxs("div",{className:"spawn-field",children:[s.jsx("label",{className:"spawn-label",children:a("terminal:spawn.browser")}),s.jsxs("label",{className:"spawn-checkbox",children:[s.jsx("input",{type:"checkbox",checked:U,onChange:e=>Pe(e.target.checked),disabled:o!=="claude"}),s.jsxs("span",{children:[s.jsx(ie,{name:"globe",size:12})," ",a("terminal:spawn.chromeBrowser")]}),s.jsx(x,{text:a(o==="claude"?"terminal:spawn.helpChrome":"terminal:spawn.helpChromeDisabled"),title:a("terminal:spawn.chromeBrowser"),position:"top",size:"sm"})]})]})]}),o==="codex"&&s.jsxs("div",{className:"codex-config-section",children:[s.jsx("div",{className:"codex-config-title",children:a("terminal:spawn.codex.configuration")}),s.jsxs("div",{className:"codex-config-options",children:[s.jsxs("div",{className:"codex-option-group",children:[s.jsxs("label",{className:"spawn-checkbox",children:[s.jsx("input",{type:"checkbox",checked:f.fullAuto!==!1,onChange:e=>A(n=>({...n,fullAuto:e.target.checked}))}),s.jsx("span",{children:a("terminal:spawn.codex.fullAuto")}),s.jsx(x,{text:a("terminal:spawn.helpFullAuto"),title:a("terminal:spawn.fullAutoTitle"),position:"top",size:"sm"})]}),s.jsxs("label",{className:"spawn-checkbox",children:[s.jsx("input",{type:"checkbox",checked:!!f.search,onChange:e=>A(n=>({...n,search:e.target.checked}))}),s.jsx("span",{children:a("terminal:spawn.codex.search")}),s.jsx(x,{text:a("terminal:spawn.helpSearch"),title:a("terminal:spawn.searchTitle"),position:"top",size:"sm"})]})]}),f.fullAuto===!1&&s.jsxs("div",{className:"codex-option-group",children:[s.jsx("div",{className:"codex-option-header",children:a("terminal:spawn.codex.restrictions")}),s.jsxs("select",{className:"spawn-input codex-select",value:f.sandbox||"workspace-write",onChange:e=>A(n=>({...n,sandbox:e.target.value})),children:[s.jsxs("option",{value:"read-only",children:["📖 ",a("terminal:spawn.codex.sandboxReadOnly")]}),s.jsxs("option",{value:"workspace-write",children:["✏️ ",a("terminal:spawn.codex.sandboxWorkspaceWrite")]}),s.jsxs("option",{value:"danger-full-access",children:["⚡ ",a("terminal:spawn.codex.sandboxDangerFullAccess")]})]}),s.jsxs("select",{className:"spawn-input codex-select",value:f.approvalMode||"on-request",onChange:e=>A(n=>({...n,approvalMode:e.target.value})),children:[s.jsxs("option",{value:"untrusted",children:["🔒 ",a("terminal:spawn.codex.approvalsUntrusted")]}),s.jsxs("option",{value:"on-failure",children:["⚠️ ",a("terminal:spawn.codex.approvalsOnFailure")]}),s.jsxs("option",{value:"on-request",children:["🤔 ",a("terminal:spawn.codex.approvalsOnRequest")]}),s.jsxs("option",{value:"never",children:["✅ ",a("terminal:spawn.codex.approvalsNever")]})]})]}),s.jsxs("div",{className:"codex-option-group",children:[s.jsx("div",{className:"codex-option-header",children:a("terminal:spawn.codex.profile")}),s.jsx("input",{type:"text",className:"spawn-input codex-profile-input",placeholder:a("terminal:spawn.codex.profilePlaceholder"),value:f.profile||"",onChange:e=>A(n=>({...n,profile:e.target.value||void 0}))})]}),s.jsxs("div",{className:"codex-option-group",children:[s.jsx("div",{className:"codex-option-header",children:a("terminal:spawn.codex.reasoningEffort")}),s.jsxs("select",{className:"spawn-input codex-select",value:f.reasoningEffort||"",onChange:e=>A(n=>({...n,reasoningEffort:e.target.value||void 0})),children:[s.jsx("option",{value:"",children:a("terminal:spawn.codex.reasoningEffortDefault")}),Object.keys(re).map(e=>s.jsxs("option",{value:e,children:[re[e].icon," ",re[e].label]},e))]})]})]})]}),w.length>0&&s.jsxs("div",{className:"spawn-skills-section",children:[s.jsxs("label",{className:"spawn-label",children:[a("terminal:spawn.skills")," ",s.jsxs("span",{className:"spawn-label-hint",children:["(",a("common:labels.optional"),")"]}),s.jsx(x,{text:a("terminal:spawn.helpSkills"),title:a("terminal:spawn.skillsTitle"),position:"top",size:"sm"})]}),w.length>6&&s.jsx("input",{type:"text",className:"spawn-input skill-search-input",placeholder:a("terminal:spawn.filterSkills"),value:D,onChange:e=>ze(e.target.value)}),s.jsxs("div",{className:"spawn-skills-inline",children:[Se.map(e=>{const n=fe.has(e.id);return We.some(c=>c.id===e.id)?null:s.jsxs("button",{className:`spawn-skill-chip ${n?"selected":""}`,onClick:()=>Ge(e.id),title:e.description,children:[n&&s.jsx("span",{className:"spawn-skill-check",children:s.jsx(ie,{name:"check",size:10})}),s.jsx("span",{children:e.name}),e.builtin&&s.jsx("span",{className:"spawn-skill-builtin",children:"TC"})]},e.id)}),D&&Se.length===0&&s.jsx("div",{className:"skill-search-empty",children:a("terminal:spawn.noSkillsMatch",{query:D})})]})]}),s.jsxs("div",{className:"spawn-custom-instructions-section",children:[s.jsxs("label",{className:"spawn-label",children:[a("terminal:spawn.customInstructions")," ",s.jsxs("span",{className:"spawn-label-hint",children:["(",a("common:labels.optional"),")"]}),s.jsx(x,{text:a("terminal:spawn.helpCustomInstructions"),title:a("terminal:spawn.customInstructions"),position:"top",size:"sm"})]}),s.jsx("textarea",{className:"spawn-input spawn-textarea",placeholder:a("terminal:spawn.customInstructionsPlaceholder"),value:Ne,onChange:e=>Ue(e.target.value),rows:3})]}),s.jsxs("div",{className:"spawn-sessions-section",children:[s.jsxs("label",{className:"spawn-label",children:[a("terminal:spawn.linkSession")," ",s.jsxs("span",{className:"spawn-label-hint",children:["(",a("common:labels.optional"),")"]}),s.jsx(x,{text:a("terminal:spawn.helpLinkSession"),title:a("terminal:spawn.linkSessionTitle"),position:"top",size:"sm"})]}),y.length>0&&s.jsx("input",{type:"text",className:"spawn-input session-search-input",placeholder:a("terminal:spawn.searchSessions"),value:_,onChange:e=>xe(e.target.value)}),s.jsx("div",{className:"sessions-list",children:$e?s.jsx("div",{className:"sessions-loading",children:a("terminal:spawn.loadingSessions")}):y.length===0?s.jsx("div",{className:"sessions-empty",children:a("terminal:spawn.noSessions")}):be.length===0?s.jsx("div",{className:"sessions-empty",children:a("terminal:spawn.noSessionsMatch",{query:_})}):be.map(e=>{const n=E===e.sessionId,l=Date.now()-new Date(e.lastModified).getTime(),c=l<6e4?a("common:time.justNow"):l<36e5?a("common:time.minutesAgo",{count:Math.floor(l/6e4)}):l<864e5?a("common:time.hoursAgo",{count:Math.floor(l/36e5)}):a("common:time.daysAgo",{count:Math.floor(l/864e5)});return s.jsxs("div",{className:`session-item ${n?"selected":""}`,onClick:()=>{n?O(null):(O(e.sessionId),F(e.projectPath))},children:[s.jsxs("div",{className:"session-item-header",children:[s.jsx("span",{className:"session-item-path",children:e.projectPath}),s.jsx("span",{className:"session-item-age",children:c})]}),s.jsx("div",{className:"session-item-preview",children:e.firstMessage||a("terminal:spawn.messagesCount",{count:e.messageCount})})]},e.sessionId)})})]})]})]}),s.jsxs("div",{className:"modal-footer",children:[s.jsx("button",{className:"btn btn-secondary",onClick:j,children:a("common:buttons.cancel")}),s.jsx("button",{className:"btn btn-primary",onClick:Xe,disabled:pe,children:a(pe?"common:buttons.deploying":"common:buttons2.deploy")})]})]})})}export{hs as SpawnModal};
@@ -1 +1 @@
1
- import{u as L,ah as $,ac as D,r as m,j as s,aR as N,_ as S,I as g,s as J}from"./main-9uTEp9Lr.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function B({isOpen:l,bossId:r,onClose:o}){var j;const{t:a}=L(["terminal","common"]),f=$(),n=D(r),[i,c]=m.useState(new Set),[u,b]=m.useState(!1),d=Array.from(f.values()).filter(e=>e.class!=="boss"&&(!e.bossId||e.bossId===r));m.useEffect(()=>{l&&n&&c(new Set(n.subordinateIds||[]))},[l,n]);const y=()=>{b(!0),J.assignSubordinates(r,Array.from(i)),setTimeout(()=>{b(!1),o()},300)},A=e=>{const t=new Set(i);t.has(e)?t.delete(e):t.add(e),c(t)},C=()=>{c(new Set(d.map(e=>e.id)))},p=()=>{c(new Set)},w=e=>{e.target===e.currentTarget&&o()},k=e=>{e.key==="Escape"&&o()};if(!l||!n)return null;const E=N.boss,h=((j=n.subordinateIds)==null?void 0:j.length)||0,I=i.size,x=JSON.stringify([...n.subordinateIds||[]].sort())!==JSON.stringify([...i].sort());return s.jsx("div",{className:`modal-overlay ${l?"visible":""}`,onClick:w,onKeyDown:k,children:s.jsxs("div",{className:"modal subordinate-assignment-modal",children:[s.jsxs("div",{className:"modal-header",children:[s.jsx("span",{className:"boss-header-icon",style:{color:E.color},children:s.jsx(S,{agent:n,size:22})}),a("terminal:team.manageTeam"),": ",n.name]}),s.jsxs("div",{className:"modal-body subordinate-assignment-body",children:[s.jsxs("div",{className:"subordinate-assignment-info",children:[s.jsx("p",{children:a("terminal:team.selectAgents")}),s.jsxs("div",{className:"subordinate-assignment-actions",children:[s.jsx("button",{className:"btn btn-small",onClick:C,children:a("common:buttons.selectAll")}),s.jsx("button",{className:"btn btn-small",onClick:p,children:a("common:buttons.clearAll")})]})]}),s.jsx("div",{className:"subordinates-list",children:d.length===0?s.jsx("div",{className:"subordinates-empty",children:a("terminal:team.noAgentsAvailable")}):d.map(e=>{var v;const t=i.has(e.id),T=N[e.class],z=(v=n.subordinateIds)==null?void 0:v.includes(e.id);return s.jsxs("div",{className:`subordinate-item ${t?"selected":""}`,onClick:()=>A(e.id),children:[s.jsx("div",{className:"subordinate-checkbox",children:t?s.jsx(g,{name:"check",size:12}):null}),s.jsx("div",{className:"subordinate-icon",style:{color:T.color},children:s.jsx(S,{agent:e,size:18})}),s.jsxs("div",{className:"subordinate-info",children:[s.jsx("div",{className:"subordinate-name",children:e.name}),s.jsx("div",{className:"subordinate-class",children:e.class})]}),s.jsx("div",{className:`subordinate-status status-${e.status}`,children:e.status}),z&&s.jsx("div",{className:"subordinate-badge",children:a("common:status.current")})]},e.id)})}),s.jsx("div",{className:"subordinate-assignment-summary",children:x?s.jsxs("span",{className:"summary-changed",children:[h," ",s.jsx(g,{name:"arrow-right",size:11})," ",I," ",a("terminal:team.subordinates").toLowerCase()]}):s.jsxs("span",{className:"summary-unchanged",children:[h," ",a("terminal:team.subordinates").toLowerCase()]})})]}),s.jsxs("div",{className:"modal-footer",children:[s.jsx("button",{className:"btn btn-secondary",onClick:o,children:a("common:buttons.cancel")}),s.jsx("button",{className:"btn btn-boss",onClick:y,disabled:u||!x,children:a(u?"common:status.saving":"terminal:team.saveTeam")})]})]})})}export{B as SubordinateAssignmentModal};
1
+ import{u as L,ah as $,ac as D,r as m,j as s,aR as N,_ as S,I as g,s as J}from"./main-XbhAPjbi.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function B({isOpen:l,bossId:r,onClose:o}){var j;const{t:a}=L(["terminal","common"]),f=$(),n=D(r),[i,c]=m.useState(new Set),[u,b]=m.useState(!1),d=Array.from(f.values()).filter(e=>e.class!=="boss"&&(!e.bossId||e.bossId===r));m.useEffect(()=>{l&&n&&c(new Set(n.subordinateIds||[]))},[l,n]);const y=()=>{b(!0),J.assignSubordinates(r,Array.from(i)),setTimeout(()=>{b(!1),o()},300)},A=e=>{const t=new Set(i);t.has(e)?t.delete(e):t.add(e),c(t)},C=()=>{c(new Set(d.map(e=>e.id)))},p=()=>{c(new Set)},w=e=>{e.target===e.currentTarget&&o()},k=e=>{e.key==="Escape"&&o()};if(!l||!n)return null;const E=N.boss,h=((j=n.subordinateIds)==null?void 0:j.length)||0,I=i.size,x=JSON.stringify([...n.subordinateIds||[]].sort())!==JSON.stringify([...i].sort());return s.jsx("div",{className:`modal-overlay ${l?"visible":""}`,onClick:w,onKeyDown:k,children:s.jsxs("div",{className:"modal subordinate-assignment-modal",children:[s.jsxs("div",{className:"modal-header",children:[s.jsx("span",{className:"boss-header-icon",style:{color:E.color},children:s.jsx(S,{agent:n,size:22})}),a("terminal:team.manageTeam"),": ",n.name]}),s.jsxs("div",{className:"modal-body subordinate-assignment-body",children:[s.jsxs("div",{className:"subordinate-assignment-info",children:[s.jsx("p",{children:a("terminal:team.selectAgents")}),s.jsxs("div",{className:"subordinate-assignment-actions",children:[s.jsx("button",{className:"btn btn-small",onClick:C,children:a("common:buttons.selectAll")}),s.jsx("button",{className:"btn btn-small",onClick:p,children:a("common:buttons.clearAll")})]})]}),s.jsx("div",{className:"subordinates-list",children:d.length===0?s.jsx("div",{className:"subordinates-empty",children:a("terminal:team.noAgentsAvailable")}):d.map(e=>{var v;const t=i.has(e.id),T=N[e.class],z=(v=n.subordinateIds)==null?void 0:v.includes(e.id);return s.jsxs("div",{className:`subordinate-item ${t?"selected":""}`,onClick:()=>A(e.id),children:[s.jsx("div",{className:"subordinate-checkbox",children:t?s.jsx(g,{name:"check",size:12}):null}),s.jsx("div",{className:"subordinate-icon",style:{color:T.color},children:s.jsx(S,{agent:e,size:18})}),s.jsxs("div",{className:"subordinate-info",children:[s.jsx("div",{className:"subordinate-name",children:e.name}),s.jsx("div",{className:"subordinate-class",children:e.class})]}),s.jsx("div",{className:`subordinate-status status-${e.status}`,children:e.status}),z&&s.jsx("div",{className:"subordinate-badge",children:a("common:status.current")})]},e.id)})}),s.jsx("div",{className:"subordinate-assignment-summary",children:x?s.jsxs("span",{className:"summary-changed",children:[h," ",s.jsx(g,{name:"arrow-right",size:11})," ",I," ",a("terminal:team.subordinates").toLowerCase()]}):s.jsxs("span",{className:"summary-unchanged",children:[h," ",a("terminal:team.subordinates").toLowerCase()]})})]}),s.jsxs("div",{className:"modal-footer",children:[s.jsx("button",{className:"btn btn-secondary",onClick:o,children:a("common:buttons.cancel")}),s.jsx("button",{className:"btn btn-boss",onClick:y,disabled:u||!x,children:a(u?"common:status.saving":"terminal:team.saveTeam")})]})]})})}export{B as SubordinateAssignmentModal};
@@ -0,0 +1,9 @@
1
+ import{ah as Te,r as i,aJ as j,l as y,j as e}from"./main-XbhAPjbi.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const Se=[{value:"webhook",label:"Webhook"},{value:"bitbucket",label:"Bitbucket"},{value:"cron",label:"Cron"},{value:"slack",label:"Slack"},{value:"email",label:"Email"},{value:"jira",label:"Jira"},{value:"whatsapp",label:"WhatsApp"}],we=[{value:"all",label:"All",icon:"◎"},{value:"webhook",label:"Webhook",icon:"🪝"},{value:"bitbucket",label:"Bitbucket",icon:"🪣"},{value:"cron",label:"Cron",icon:"⏰"},{value:"slack",label:"Slack",icon:"💬"},{value:"email",label:"Email",icon:"✉️"},{value:"jira",label:"Jira",icon:"🎫"},{value:"whatsapp",label:"WhatsApp",icon:"📱"}],Me=[{value:"pullrequest:created",label:"PR created"},{value:"pullrequest:updated",label:"PR updated"},{value:"pullrequest:approved",label:"PR approved"},{value:"pullrequest:unapproved",label:"PR unapproved"},{value:"pullrequest:fulfilled",label:"PR merged"},{value:"pullrequest:rejected",label:"PR declined"},{value:"pullrequest:comment_created",label:"PR comment created"}],Re=[{value:"structural",label:"Structural",desc:"Field-based matching (fast, free)"},{value:"llm",label:"LLM",desc:"Semantic matching via LLM (flexible, costs tokens)"},{value:"hybrid",label:"Hybrid",desc:"Structural pre-filter + LLM (recommended)"}],Be=[{value:"structural",label:"Structural"},{value:"llm",label:"LLM"}];function Ee(k){if(!k)return"";const b=new Date(k);if(Number.isNaN(b.getTime()))return"";const m=g=>String(g).padStart(2,"0");return`${b.getFullYear()}-${m(b.getMonth()+1)}-${m(b.getDate())}T${m(b.getHours())}:${m(b.getMinutes())}`}const L=()=>({name:"",description:"",type:"webhook",agentId:"",promptTemplate:"",enabled:!0,matchMode:"structural",extractionMode:"structural",config:{method:"POST"}});function Oe({isOpen:k,onClose:b}){var G,Y,X,K,Q,Z,ee,te,le,se,ae,ne,ie,re,oe,ce;const m=Te(),[g,de]=i.useState([]),[T,R]=i.useState("list"),[n,v]=i.useState(L()),[x,E]=i.useState(!1),[O,z]=i.useState(!1),[P,u]=i.useState(null),[I,pe]=i.useState([]),[S,xe]=i.useState(null),[A,ue]=i.useState(`{
2
+
3
+ }`),[o,w]=i.useState(null),[D,N]=i.useState(!1),[W,H]=i.useState([]),[M,he]=i.useState("all"),f=i.useCallback(async()=>{try{const l=await j(y("/api/triggers"));if(l.ok){const s=await l.json();de(s)}}catch(l){console.error("Failed to load triggers:",l)}},[]),B=i.useCallback(async l=>{try{const s=await j(y(`/api/triggers/${l}/events?limit=20`));if(s.ok){const a=await s.json();pe(a)}}catch(s){console.error("Failed to load trigger history:",s)}},[]);i.useEffect(()=>{k&&f()},[k,f]),i.useEffect(()=>{S&&B(S)},[S,B]);const be=i.useCallback(async()=>{z(!0),u(null);try{const l=x?y(`/api/triggers/${n.id}`):y("/api/triggers"),h=await j(l,{method:x?"PATCH":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!h.ok){const r=await h.json();throw new Error(r.error||"Failed to save trigger")}await f(),R("list"),v(L()),E(!1)}catch(l){u(l instanceof Error?l.message:"Save failed")}finally{z(!1)}},[n,x,f]),ge=i.useCallback(async l=>{try{await j(y(`/api/triggers/${l}`),{method:"DELETE"}),await f()}catch(s){console.error("Failed to delete trigger:",s)}},[f]),ye=i.useCallback(async l=>{try{await j(y(`/api/triggers/${l.id}`),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:!l.enabled})}),await f()}catch(s){console.error("Failed to toggle trigger:",s)}},[f]),me=i.useCallback(async l=>{try{await j(y(`/api/triggers/${l}/fire`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({variables:{}})}),S===l&&await B(l)}catch(s){console.error("Failed to test fire trigger:",s)}},[S,B]),fe=i.useCallback(async()=>{if(n.id){N(!0),w(null);try{let l;try{l=JSON.parse(A)}catch{w({structuralMatch:void 0,extractedVariables:{},wouldFire:!1}),u("Invalid JSON payload");return}const s=await j(y(`/api/triggers/${n.id}/test-match`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({payload:l})});if(s.ok){const a=await s.json();w(a),u(null)}else{const a=await s.json();u(a.error||"Test match failed")}}catch(l){u(l instanceof Error?l.message:"Test match failed")}finally{N(!1)}}},[n.id,A]),je=i.useCallback(async l=>{var s;try{const a=await j(y("/api/triggers/validate-cron"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({expression:l,timezone:((s=n.config)==null?void 0:s.timezone)||"UTC"})});if(a.ok){const h=await a.json();H(h.valid?h.nextFires:[])}}catch{H([])}},[n]),U=i.useCallback(l=>{l?(v({...l}),E(!0)):(v(L()),E(!1)),w(null),u(null),R("edit")},[]),c=i.useCallback((l,s)=>{v(a=>({...a,[l]:s}))},[]),d=i.useCallback((l,s)=>{v(a=>({...a,config:{...a.config,[l]:s}}))},[]),F=i.useCallback((l,s)=>{v(a=>({...a,llmMatch:{...a.llmMatch||{prompt:""},[l]:s}}))},[]),_=i.useCallback((l,s)=>{v(a=>({...a,llmExtract:{...a.llmExtract||{prompt:"",variables:[]},[l]:s}}))},[]),ve=i.useMemo(()=>Array.from(m.values()).map(l=>({id:l.id,name:l.name,class:l.class})),[m]),ke=i.useMemo(()=>{const l={all:g.length,webhook:0,bitbucket:0,cron:0,slack:0,email:0,jira:0,whatsapp:0};for(const s of g)s.type in l&&(l[s.type]+=1);return l},[g]),$=i.useMemo(()=>M==="all"?g:g.filter(l=>l.type===M),[g,M]),[J,q]=i.useState(null),V=i.useCallback((l,s)=>{l&&navigator.clipboard.writeText(l).then(()=>{q(s),setTimeout(()=>q(a=>a===s?null:a),1500)},()=>u("Failed to copy to clipboard"))},[]);return k?e.jsx("div",{style:t.overlay,onClick:b,children:e.jsxs("div",{style:t.panel,onClick:l=>l.stopPropagation(),children:[e.jsxs("div",{style:t.header,children:[e.jsx("h2",{style:t.title,children:T==="list"?"Triggers":x?"Edit Trigger":"New Trigger"}),e.jsxs("div",{style:t.headerActions,children:[T==="list"&&e.jsx("button",{style:t.addBtn,onClick:()=>U(),children:"+ New Trigger"}),T==="edit"&&e.jsx("button",{style:t.backBtn,onClick:()=>{R("list"),w(null),u(null)},children:"Back"}),e.jsx("button",{style:t.closeBtn,onClick:b,children:"X"})]})]}),P&&e.jsx("div",{style:t.error,children:P}),T==="list"&&e.jsxs("div",{style:t.content,children:[e.jsx("div",{style:t.tabBar,role:"tablist","aria-label":"Filter triggers by type",children:we.map(l=>{const s=ke[l.value],a=M===l.value;return e.jsxs("button",{role:"tab","aria-selected":a,onClick:()=>he(l.value),style:{...t.tab,...a?t.tabActive:{}},title:`${l.label} (${s})`,children:[e.jsx("span",{style:t.tabIcon,children:l.icon}),e.jsx("span",{style:t.tabLabel,children:l.label}),e.jsx("span",{style:{...t.tabBadge,...a?t.tabBadgeActive:{}},children:s})]},l.value)})}),g.length===0?e.jsx("div",{style:t.empty,children:"No triggers configured. Create one to get started."}):$.length===0?e.jsxs("div",{style:t.empty,children:["No ",M," triggers configured yet."]}):$.map(l=>{var s;return e.jsxs("div",{style:{...t.triggerCard,borderLeftColor:l.status==="error"?"#e74c3c":l.enabled?"#2ecc71":"#95a5a6"},onClick:()=>{xe(l.id),U(l)},children:[e.jsxs("div",{style:t.cardHeader,children:[e.jsxs("div",{style:t.cardTitle,children:[e.jsx("span",{style:t.typeTag,children:l.type}),e.jsx("span",{children:l.name}),l.type==="cron"&&(()=>{const a=l.config||{};return a.runOnce?a.completedAt?e.jsx("span",{style:{...t.matchTag,color:"#a6e3a1"},children:"Once · completed"}):a.missedAt?e.jsx("span",{style:{...t.matchTag,color:"#f38ba8"},children:"Once · missed"}):e.jsx("span",{style:{...t.matchTag,color:"#f9e2af"},children:"Once · pending"}):e.jsx("span",{style:t.matchTag,children:"Recurring"})})(),l.matchMode!=="structural"&&e.jsx("span",{style:t.matchTag,children:l.matchMode})]}),e.jsxs("div",{style:t.cardActions,children:[e.jsx("button",{style:t.smallBtn,onClick:a=>{a.stopPropagation(),ye(l)},children:l.enabled?"Disable":"Enable"}),e.jsx("button",{style:t.smallBtn,onClick:a=>{a.stopPropagation(),me(l.id)},children:"Test Fire"}),e.jsx("button",{style:{...t.smallBtn,color:"#e74c3c"},onClick:a=>{a.stopPropagation(),ge(l.id)},children:"Delete"})]})]}),e.jsxs("div",{style:t.cardMeta,children:[e.jsxs("span",{children:["Agent: ",((s=m.get(l.agentId))==null?void 0:s.name)||l.agentId]}),e.jsxs("span",{children:["Fires: ",l.fireCount]}),l.lastFiredAt&&e.jsxs("span",{children:["Last: ",new Date(l.lastFiredAt).toLocaleString()]}),l.status==="error"&&l.lastError&&e.jsxs("span",{style:{color:"#e74c3c"},children:["Error: ",l.lastError]})]})]},l.id)})]}),T==="edit"&&e.jsx("div",{style:t.content,children:e.jsxs("div",{style:t.form,children:[e.jsxs("div",{style:t.field,children:[e.jsx("label",{style:t.label,children:"Name"}),e.jsx("input",{style:t.input,value:n.name||"",onChange:l=>c("name",l.target.value),placeholder:"My Trigger"})]}),e.jsxs("div",{style:t.field,children:[e.jsx("label",{style:t.label,children:"Description"}),e.jsx("input",{style:t.input,value:n.description||"",onChange:l=>c("description",l.target.value),placeholder:"Optional description"})]}),e.jsxs("div",{style:t.row,children:[e.jsxs("div",{style:t.field,children:[e.jsx("label",{style:t.label,children:"Type"}),e.jsx("select",{style:t.select,value:n.type||"webhook",onChange:l=>{const s=l.target.value;c("type",s),s==="webhook"?c("config",{method:"POST"}):s==="cron"?c("config",{expression:"0 9 * * MON-FRI",timezone:"UTC"}):s==="bitbucket"?c("config",{workspace:"",repoSlug:"",events:["pullrequest:created","pullrequest:updated"]}):c("config",{}),(n.promptTemplate??"").trim()||(s==="slack"?c("promptTemplate",`Slack message from {{slack.user}} in {{slack.channelName}}:
4
+ {{slack.message}}
5
+
6
+ {{slack.attachmentsBlock}}`):s==="whatsapp"&&c("promptTemplate",`WhatsApp message from {{whatsapp.fromName}} ({{whatsapp.from}}):
7
+ {{whatsapp.body}}
8
+
9
+ {{whatsapp.attachmentsBlock}}`))},children:Se.map(l=>e.jsx("option",{value:l.value,children:l.label},l.value))})]}),e.jsxs("div",{style:t.field,children:[e.jsx("label",{style:t.label,children:"Agent"}),e.jsxs("select",{style:t.select,value:n.agentId||"",onChange:l=>c("agentId",l.target.value),children:[e.jsx("option",{value:"",children:"Select agent..."}),ve.map(l=>e.jsxs("option",{value:l.id,children:[l.name," (",l.class,")"]},l.id))]})]})]}),e.jsxs("div",{style:t.field,children:[e.jsx("label",{style:t.label,children:"Prompt Template"}),e.jsx("textarea",{style:t.textarea,value:n.promptTemplate||"",onChange:l=>c("promptTemplate",l.target.value),placeholder:"Message sent to agent. Use {{variable}} for interpolation.",rows:4})]}),n.type==="webhook"&&e.jsxs("div",{style:t.section,children:[e.jsx("h4",{style:t.sectionTitle,children:"Webhook Config"}),e.jsxs("div",{style:t.row,children:[e.jsxs("div",{style:t.field,children:[e.jsx("label",{style:t.label,children:"Method"}),e.jsxs("select",{style:t.select,value:((G=n.config)==null?void 0:G.method)||"POST",onChange:l=>d("method",l.target.value),children:[e.jsx("option",{value:"POST",children:"POST"}),e.jsx("option",{value:"PUT",children:"PUT"})]})]}),e.jsxs("div",{style:t.field,children:[e.jsx("label",{style:t.label,children:"Secret (HMAC)"}),e.jsx("input",{style:t.input,type:"password",value:((Y=n.config)==null?void 0:Y.secret)||"",onChange:l=>d("secret",l.target.value||void 0),placeholder:"Optional HMAC secret"})]})]}),e.jsxs("div",{style:t.field,children:[e.jsx("label",{style:t.label,children:"Extract Fields (comma-separated JSON paths)"}),e.jsx("input",{style:t.input,value:((K=(X=n.config)==null?void 0:X.extractFields)==null?void 0:K.join(", "))||"",onChange:l=>d("extractFields",l.target.value.split(",").map(s=>s.trim()).filter(Boolean)),placeholder:"body.release_name, body.version"})]}),x&&n.id&&e.jsxs("div",{style:t.webhookUrl,children:[e.jsx("label",{style:t.label,children:"Webhook URL"}),e.jsx("code",{style:t.code,children:`${window.location.origin}/api/triggers/webhook/${n.id}`})]})]}),n.type==="bitbucket"&&(()=>{const l=n.config||{},s=Array.isArray(l.events)?l.events:[],a=x&&n.id?`${window.location.origin}/api/triggers/webhook/${n.id}`:"",h=r=>{const p=s.includes(r)?s.filter(C=>C!==r):[...s,r];d("events",p)};return e.jsxs("div",{style:t.section,children:[e.jsx("h4",{style:t.sectionTitle,children:"Bitbucket Config"}),e.jsxs("div",{style:t.row,children:[e.jsxs("div",{style:t.field,children:[e.jsx("label",{style:t.label,children:"Workspace"}),e.jsx("input",{style:t.input,value:l.workspace||"",onChange:r=>d("workspace",r.target.value),placeholder:"tide"})]}),e.jsxs("div",{style:t.field,children:[e.jsx("label",{style:t.label,children:"Repository slug"}),e.jsx("input",{style:t.input,value:l.repoSlug||"",onChange:r=>d("repoSlug",r.target.value),placeholder:"wind"})]})]}),e.jsxs("div",{style:t.field,children:[e.jsx("label",{style:t.label,children:"Events"}),e.jsx("div",{style:t.checkboxGrid,children:Me.map(r=>{const p=s.includes(r.value);return e.jsxs("label",{style:t.checkboxLabel,children:[e.jsx("input",{type:"checkbox",checked:p,onChange:()=>h(r.value)}),e.jsx("span",{children:r.label}),e.jsx("code",{style:t.checkboxCode,children:r.value})]},r.value)})})]}),e.jsxs("div",{style:t.field,children:[e.jsx("label",{style:t.label,children:"HMAC secret"}),e.jsxs("div",{style:t.inlineRow,children:[e.jsx("input",{style:{...t.input,flex:1},type:"password",value:l.secret||"",onChange:r=>d("secret",r.target.value||void 0),placeholder:"Shared secret used to validate Bitbucket signature"}),e.jsx("button",{type:"button",style:t.smallBtn,onClick:()=>V(l.secret||"","bitbucket-secret"),disabled:!l.secret,children:J==="bitbucket-secret"?"Copied!":"Copy"})]}),e.jsx("span",{style:t.llmMeta,children:"Paste the same secret into Bitbucket's webhook configuration."})]}),a&&e.jsxs("div",{style:t.webhookUrl,children:[e.jsx("label",{style:t.label,children:"Webhook URL"}),e.jsxs("div",{style:t.inlineRow,children:[e.jsx("code",{style:{...t.code,flex:1},children:a}),e.jsx("button",{type:"button",style:t.smallBtn,onClick:()=>V(a,"bitbucket-url"),children:J==="bitbucket-url"?"Copied!":"Copy"})]}),e.jsx("span",{style:t.llmMeta,children:"In Bitbucket: Repository settings → Webhooks → Add webhook, then paste this URL and the secret above."})]}),!a&&e.jsx("span",{style:t.llmMeta,children:"Save the trigger to reveal its webhook URL."})]})})(),n.type==="cron"&&(()=>{const l=n.config||{},s=!!l.runOnce,a=l.completedAt,h=l.missedAt,r=!!a;return e.jsxs("div",{style:t.section,children:[e.jsx("h4",{style:t.sectionTitle,children:"Cron Config"}),e.jsxs("div",{style:t.modeSelector,children:[e.jsxs("button",{type:"button",style:{...t.modeBtn,...s?{}:t.modeBtnActive},onClick:()=>d("runOnce",!1),disabled:r,children:[e.jsx("strong",{children:"Repeats"}),e.jsx("span",{style:t.modeDesc,children:"Fires on a cron schedule"})]}),e.jsxs("button",{type:"button",style:{...t.modeBtn,...s?t.modeBtnActive:{}},onClick:()=>d("runOnce",!0),disabled:r,children:[e.jsx("strong",{children:"Run once"}),e.jsx("span",{style:t.modeDesc,children:"Fires exactly once at a specific time"})]})]}),r&&e.jsxs("div",{style:{...t.testResult,borderLeft:"3px solid #a6e3a1"},children:[e.jsx("strong",{style:{color:"#a6e3a1"},children:"Completed"}),e.jsxs("span",{style:t.llmMeta,children:["Fired at ",new Date(a).toLocaleString()]})]}),!r&&h&&e.jsxs("div",{style:{...t.testResult,borderLeft:"3px solid #f38ba8"},children:[e.jsx("strong",{style:{color:"#f38ba8"},children:"Missed"}),e.jsxs("span",{style:t.llmMeta,children:["Marked missed at ",new Date(h).toLocaleString()," (server was down at runAt)"]})]}),s?e.jsx("div",{style:t.row,children:e.jsxs("div",{style:t.field,children:[e.jsx("label",{style:t.label,children:"Run at"}),e.jsx("input",{style:t.input,type:"datetime-local",value:Ee(l.runAt),onChange:p=>{const C=p.target.value;if(!C){d("runAt",void 0);return}const Ce=new Date(C).toISOString();d("runAt",Ce)},disabled:r}),e.jsx("span",{style:t.llmMeta,children:"Interpreted in your browser's local timezone"})]})}):e.jsxs("div",{style:t.row,children:[e.jsxs("div",{style:t.field,children:[e.jsx("label",{style:t.label,children:"Expression"}),e.jsx("input",{style:t.input,value:l.expression||"",onChange:p=>{d("expression",p.target.value),p.target.value&&je(p.target.value)},placeholder:"0 9 * * MON-FRI"})]}),e.jsxs("div",{style:t.field,children:[e.jsx("label",{style:t.label,children:"Timezone"}),e.jsx("input",{style:t.input,value:l.timezone||"UTC",onChange:p=>d("timezone",p.target.value),placeholder:"America/Mexico_City"})]})]}),!s&&W.length>0&&e.jsxs("div",{style:t.nextFires,children:[e.jsx("label",{style:t.label,children:"Next fires:"}),W.map((p,C)=>e.jsx("div",{style:t.nextFireItem,children:new Date(p).toLocaleString()},C))]})]})})(),e.jsxs("div",{style:t.section,children:[e.jsx("h4",{style:t.sectionTitle,children:"Match Mode"}),e.jsx("div",{style:t.modeSelector,children:Re.map(l=>e.jsxs("button",{style:{...t.modeBtn,...n.matchMode===l.value?t.modeBtnActive:{}},onClick:()=>c("matchMode",l.value),children:[e.jsx("strong",{children:l.label}),e.jsx("span",{style:t.modeDesc,children:l.desc})]},l.value))}),(n.matchMode==="llm"||n.matchMode==="hybrid")&&e.jsxs("div",{style:t.llmConfig,children:[e.jsxs("div",{style:t.field,children:[e.jsx("label",{style:t.label,children:"LLM Match Prompt"}),e.jsx("textarea",{style:t.textarea,value:((Q=n.llmMatch)==null?void 0:Q.prompt)||"",onChange:l=>F("prompt",l.target.value),placeholder:"Does this message request a release deployment?",rows:3})]}),e.jsxs("div",{style:t.row,children:[e.jsxs("div",{style:t.field,children:[e.jsx("label",{style:t.label,children:"Model"}),e.jsxs("select",{style:t.select,value:((Z=n.llmMatch)==null?void 0:Z.model)||"haiku",onChange:l=>F("model",l.target.value),children:[e.jsx("option",{value:"haiku",children:"Haiku (fast, cheap)"}),e.jsx("option",{value:"sonnet",children:"Sonnet (balanced)"}),e.jsx("option",{value:"opus",children:"Opus (powerful)"})]})]}),e.jsxs("div",{style:t.field,children:[e.jsx("label",{style:t.label,children:"Min Confidence"}),e.jsx("input",{style:t.input,type:"number",min:"0",max:"1",step:"0.1",value:((ee=n.llmMatch)==null?void 0:ee.minConfidence)??0,onChange:l=>F("minConfidence",parseFloat(l.target.value))})]})]})]})]}),e.jsxs("div",{style:t.section,children:[e.jsx("h4",{style:t.sectionTitle,children:"Extraction Mode"}),e.jsx("div",{style:t.row,children:Be.map(l=>e.jsx("button",{style:{...t.modeBtn,...n.extractionMode===l.value?t.modeBtnActive:{}},onClick:()=>c("extractionMode",l.value),children:l.label},l.value))}),n.extractionMode==="llm"&&e.jsxs("div",{style:t.llmConfig,children:[e.jsxs("div",{style:t.field,children:[e.jsx("label",{style:t.label,children:"Extraction Instructions"}),e.jsx("textarea",{style:t.textarea,value:((te=n.llmExtract)==null?void 0:te.prompt)||"",onChange:l=>_("prompt",l.target.value),placeholder:"Extract: release version, affected systems, urgency",rows:3})]}),e.jsxs("div",{style:t.field,children:[e.jsx("label",{style:t.label,children:"Variable Names (comma-separated)"}),e.jsx("input",{style:t.input,value:((se=(le=n.llmExtract)==null?void 0:le.variables)==null?void 0:se.join(", "))||"",onChange:l=>_("variables",l.target.value.split(",").map(s=>s.trim()).filter(Boolean)),placeholder:"release_name, affected_systems, urgency"})]})]})]}),x&&e.jsxs("div",{style:t.section,children:[e.jsx("h4",{style:t.sectionTitle,children:"Test Match"}),e.jsxs("div",{style:t.field,children:[e.jsx("label",{style:t.label,children:"Sample Event Payload (JSON)"}),e.jsx("textarea",{style:t.textarea,value:A,onChange:l=>ue(l.target.value),rows:4})]}),e.jsx("button",{style:t.testBtn,onClick:fe,disabled:D,children:D?"Testing...":"Test Match"}),o&&e.jsxs("div",{style:t.testResult,children:[e.jsx("div",{style:{...t.testResultHeader,color:o.wouldFire?"#2ecc71":"#e74c3c"},children:o.wouldFire?"WOULD FIRE":"WOULD NOT FIRE"}),o.structuralMatch!==void 0&&e.jsxs("div",{children:["Structural: ",o.structuralMatch?"Match":"No match"]}),o.llmMatch&&e.jsxs("div",{style:t.llmResult,children:[e.jsxs("div",{children:["LLM: ",o.llmMatch.match?"Match":"No match"]}),e.jsxs("div",{children:["Confidence: ",(o.llmMatch.confidence*100).toFixed(0),"%"]}),e.jsxs("div",{children:["Reason: ",o.llmMatch.reason]}),e.jsxs("div",{style:t.llmMeta,children:["Model: ",o.llmMatch.model," | Tokens: ",o.llmMatch.tokensUsed," | Latency: ",o.llmMatch.durationMs,"ms"]})]}),Object.keys(o.extractedVariables).length>0&&e.jsxs("div",{children:[e.jsx("div",{style:t.label,children:"Extracted Variables:"}),Object.entries(o.extractedVariables).map(([l,s])=>e.jsxs("div",{style:t.varRow,children:[e.jsx("code",{children:l}),": ",s]},l))]})]})]}),x&&I.length>0&&e.jsxs("div",{style:t.section,children:[e.jsx("h4",{style:t.sectionTitle,children:"Recent Fires"}),e.jsx("div",{style:t.historyList,children:I.map((l,s)=>{const a=l.llm_match_result?JSON.parse(l.llm_match_result):null;return e.jsxs("div",{style:t.historyItem,children:[e.jsxs("div",{style:t.historyHeader,children:[e.jsx("span",{style:{color:l.status==="delivered"?"#2ecc71":l.status==="failed"?"#e74c3c":"#f39c12"},children:l.status}),e.jsx("span",{children:new Date(l.fired_at).toLocaleString()}),l.duration_ms&&e.jsxs("span",{children:[l.duration_ms,"ms"]})]}),l.error&&e.jsx("div",{style:{color:"#e74c3c",fontSize:"12px"},children:l.error}),a&&e.jsxs("div",{style:t.llmMeta,children:["LLM: ",a.match?"match":"no match"," (",(a.confidence*100).toFixed(0),"%) - ",a.reason]})]},l.id||s)})})]}),e.jsxs("div",{style:t.actions,children:[e.jsx("button",{style:t.cancelBtn,onClick:()=>{R("list"),u(null)},children:"Cancel"}),e.jsx("button",{style:t.saveBtn,onClick:be,disabled:O||!n.name||!n.agentId||n.type==="cron"&&!!((ae=n.config)!=null&&ae.runOnce)&&!((ne=n.config)!=null&&ne.runAt)||n.type==="bitbucket"&&(!((ie=n.config)!=null&&ie.workspace)||!((re=n.config)!=null&&re.repoSlug)||!((ce=(oe=n.config)==null?void 0:oe.events)!=null&&ce.length)),children:O?"Saving...":x?"Update":"Create"})]})]})})]})}):null}const t={overlay:{position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.6)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},panel:{background:"#1e1e2e",borderRadius:"12px",width:"680px",maxHeight:"85vh",display:"flex",flexDirection:"column",color:"#cdd6f4",boxShadow:"0 8px 32px rgba(0,0,0,0.4)"},header:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:"1px solid #313244"},title:{margin:0,fontSize:"18px",fontWeight:600},headerActions:{display:"flex",gap:"8px"},content:{overflow:"auto",padding:"16px 20px",flex:1},empty:{textAlign:"center",padding:"40px",color:"#6c7086"},error:{background:"#45252a",color:"#f38ba8",padding:"8px 20px",fontSize:"13px"},tabBar:{display:"flex",gap:"4px",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid #313244",flexWrap:"wrap"},tab:{background:"transparent",border:"1px solid transparent",borderRadius:"6px",padding:"6px 10px",color:"#a6adc8",cursor:"pointer",fontSize:"12px",display:"flex",alignItems:"center",gap:"6px",transition:"background 0.12s, color 0.12s, border-color 0.12s"},tabActive:{background:"#1e3a5f",borderColor:"#89b4fa",color:"#cdd6f4"},tabIcon:{fontSize:"13px",lineHeight:1},tabLabel:{fontWeight:500},tabBadge:{background:"#313244",color:"#a6adc8",borderRadius:"10px",padding:"1px 7px",fontSize:"10px",fontWeight:600,minWidth:"16px",textAlign:"center",lineHeight:"14px"},tabBadgeActive:{background:"#89b4fa",color:"#1e1e2e"},triggerCard:{background:"#181825",borderRadius:"8px",padding:"12px 16px",marginBottom:"8px",borderLeft:"3px solid",cursor:"pointer",transition:"background 0.15s"},cardHeader:{display:"flex",justifyContent:"space-between",alignItems:"center"},cardTitle:{display:"flex",alignItems:"center",gap:"8px",fontWeight:500},typeTag:{background:"#313244",padding:"2px 6px",borderRadius:"4px",fontSize:"11px",textTransform:"uppercase"},matchTag:{background:"#45475a",padding:"2px 6px",borderRadius:"4px",fontSize:"10px",color:"#a6e3a1"},cardActions:{display:"flex",gap:"6px"},cardMeta:{display:"flex",gap:"16px",marginTop:"8px",fontSize:"12px",color:"#6c7086"},form:{display:"flex",flexDirection:"column",gap:"12px"},field:{display:"flex",flexDirection:"column",gap:"4px",flex:1},row:{display:"flex",gap:"12px"},label:{fontSize:"12px",color:"#a6adc8",fontWeight:500},input:{background:"#313244",border:"1px solid #45475a",borderRadius:"6px",padding:"8px 10px",color:"#cdd6f4",fontSize:"13px",outline:"none"},select:{background:"#313244",border:"1px solid #45475a",borderRadius:"6px",padding:"8px 10px",color:"#cdd6f4",fontSize:"13px",outline:"none"},textarea:{background:"#313244",border:"1px solid #45475a",borderRadius:"6px",padding:"8px 10px",color:"#cdd6f4",fontSize:"13px",outline:"none",fontFamily:"monospace",resize:"vertical"},section:{borderTop:"1px solid #313244",paddingTop:"12px"},sectionTitle:{margin:"0 0 8px",fontSize:"14px",fontWeight:600,color:"#a6adc8"},modeSelector:{display:"flex",gap:"8px",marginBottom:"8px"},modeBtn:{flex:1,background:"#313244",border:"1px solid #45475a",borderRadius:"6px",padding:"8px",color:"#cdd6f4",cursor:"pointer",textAlign:"left",display:"flex",flexDirection:"column",gap:"2px",fontSize:"12px"},modeBtnActive:{borderColor:"#89b4fa",background:"#1e3a5f"},modeDesc:{fontSize:"10px",color:"#6c7086"},llmConfig:{background:"#181825",borderRadius:"6px",padding:"12px",display:"flex",flexDirection:"column",gap:"8px"},webhookUrl:{marginTop:"8px"},inlineRow:{display:"flex",gap:"6px",alignItems:"center"},checkboxGrid:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:"6px 12px"},checkboxLabel:{display:"flex",alignItems:"center",gap:"6px",fontSize:"12px",color:"#cdd6f4",cursor:"pointer"},checkboxCode:{fontSize:"10px",color:"#6c7086",background:"transparent",padding:0},code:{background:"#313244",padding:"6px 10px",borderRadius:"4px",fontSize:"12px",display:"block",wordBreak:"break-all",color:"#89b4fa"},nextFires:{marginTop:"8px"},nextFireItem:{fontSize:"12px",color:"#a6e3a1",padding:"2px 0"},testBtn:{background:"#89b4fa",border:"none",borderRadius:"6px",padding:"8px 16px",color:"#1e1e2e",fontWeight:600,cursor:"pointer",fontSize:"13px"},testResult:{background:"#181825",borderRadius:"6px",padding:"12px",marginTop:"8px",fontSize:"13px",display:"flex",flexDirection:"column",gap:"6px"},testResultHeader:{fontWeight:700,fontSize:"14px"},llmResult:{display:"flex",flexDirection:"column",gap:"2px"},llmMeta:{fontSize:"11px",color:"#6c7086",marginTop:"2px"},varRow:{fontSize:"12px",padding:"2px 0"},historyList:{display:"flex",flexDirection:"column",gap:"6px",maxHeight:"200px",overflow:"auto"},historyItem:{background:"#181825",borderRadius:"4px",padding:"8px 10px",fontSize:"12px"},historyHeader:{display:"flex",justifyContent:"space-between",alignItems:"center"},actions:{display:"flex",justifyContent:"flex-end",gap:"8px",marginTop:"16px",paddingTop:"12px",borderTop:"1px solid #313244"},addBtn:{background:"#89b4fa",border:"none",borderRadius:"6px",padding:"6px 14px",color:"#1e1e2e",fontWeight:600,cursor:"pointer",fontSize:"13px"},backBtn:{background:"transparent",border:"1px solid #45475a",borderRadius:"6px",padding:"6px 14px",color:"#cdd6f4",cursor:"pointer",fontSize:"13px"},closeBtn:{background:"transparent",border:"none",color:"#6c7086",cursor:"pointer",fontSize:"16px",padding:"4px 8px"},smallBtn:{background:"transparent",border:"1px solid #45475a",borderRadius:"4px",padding:"3px 8px",color:"#cdd6f4",cursor:"pointer",fontSize:"11px"},saveBtn:{background:"#a6e3a1",border:"none",borderRadius:"6px",padding:"8px 20px",color:"#1e1e2e",fontWeight:600,cursor:"pointer",fontSize:"13px"},cancelBtn:{background:"transparent",border:"1px solid #45475a",borderRadius:"6px",padding:"8px 20px",color:"#cdd6f4",cursor:"pointer",fontSize:"13px"}};export{Oe as TriggerManagerPanel,Oe as default};
@@ -1,4 +1,4 @@
1
- import{r as x,aJ as M,l as P,j as e,ah as J}from"./main-9uTEp9Lr.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const H=[{id:"intake",name:"Intake",type:"action",description:"Gather CC details from the developer via Slack",action:{type:"agent_task",agentId:"",promptTemplate:`A developer has requested a new CC (Control de Cambios). Here is their message:
1
+ import{r as x,aJ as M,l as P,j as e,ah as J}from"./main-XbhAPjbi.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const H=[{id:"intake",name:"Intake",type:"action",description:"Gather CC details from the developer via Slack",action:{type:"agent_task",agentId:"",promptTemplate:`A developer has requested a new CC (Control de Cambios). Here is their message:
2
2
  {{trigger.slack.message}}
3
3
  From: {{trigger.slack.user}} (Slack ID: {{trigger.slack.userId}})
4
4
 
@@ -1,2 +1,2 @@
1
- import{r as a,z as sn,B as St,u as Bt,E as ln,j as e,V as rn,G as on,H as cn,J as Mt,S as y,K as Tt,L as Nt,M as Pt,N as dt,O as se,P as dn,s as x,U as Ft,W as Wt,X as un,v as Lt,w as Rt,I as u,Y as pn,m as mn,Z as fn,_ as Ht,$ as Vt,a0 as hn,a1 as gn,a2 as xn,a3 as bn,a4 as _n,a5 as wn,a6 as vn,a7 as Cn,a8 as jn,a9 as Nn,aa as Dt,C as kn,ab as yn,ac as An,ad as In,ae as En,af as Sn,ag as Mn,ah as Tn,ai as Pn,aj as Ln,ak as Rn,al as Dn,am as zn,an as On,ao as $n,ap as Bn,aq as Fn}from"./main-9uTEp9Lr.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function Wn(w){const c=a.useRef(w);c.current=w,a.useEffect(()=>{if(!sn())return;let v=null,I=!1;return St.addListener("backButton",()=>{c.current()==="exit"&&St.exitApp()}).then(E=>{I?E.remove():v=E}),()=>{I=!0,v&&(v.remove(),v=null)}},[])}const Hn=a.memo(function({className:c=""}){const{t:v}=Bt(["common"]),[I,E]=ln(),Y=a.useRef(null),[F,Re]=a.useState(null);a.useLayoutEffect(()=>{const f=Y.current;if(!f)return;const K=f.querySelector(".view-mode-toggle__btn--active");K&&Re({left:K.offsetLeft,width:K.offsetWidth})},[I]);const ie=a.useCallback(f=>{if(f!==I){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:f}})),f==="3d"){requestAnimationFrame(()=>E(f));return}E(f)}},[I,E]);return e.jsxs("div",{className:`view-mode-toggle ${c}`,ref:Y,children:[F&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:F.left,width:F.width}}),rn.map(f=>e.jsxs("button",{className:`view-mode-toggle__btn ${I===f?"view-mode-toggle__btn--active":""}`,onClick:()=>ie(f),title:v(`common:viewMode.descriptions.${f}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[f==="2d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"})]}),f==="3d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),e.jsx("path",{d:"M2 17l10 5 10-5"}),e.jsx("path",{d:"M2 12l10 5 10-5"})]}),f==="flat"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"3",y:"13",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"13",width:"8",height:"8",rx:"1"})]}),f==="dashboard"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"12",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"3",y:"16",width:"7",height:"5",rx:"1"})]})]}),e.jsx("span",{className:"view-mode-toggle__label",children:v(`common:viewMode.labels.${f}`)})]},f))]})}),ut=3,pt=280,zt=320,jt=240,Ot=64,Vn=["simple","chat","advanced"],Xn={simple:"Simple",chat:"Chat",advanced:"Advanced"},Gn={simple:"○",chat:"◐",advanced:"◉"},Un={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},$t="flat-clear-context";function qn(w){const c=w.split("/").filter(Boolean);return c.length===0?w:c.slice(-2).join("/")}function Yn(w){if(w.provider==="codex"){const Y=w.codexModel||"gpt-5.3-codex",F=$n[Y];return{model:(F==null?void 0:F.label)||Y}}if(w.provider==="opencode")return{model:w.opencodeModel||"opencode"};const c=w.model||"sonnet",v=Fn[c],I=w.effort,E=I?Bn[I]:void 0;return{model:(v==null?void 0:v.label)||c,effort:E==null?void 0:E.label}}function Kn(w,c){if(c.type==="rectangle"&&c.width&&c.height){const v=c.width/2,I=c.height/2;return w.x>=c.center.x-v&&w.x<=c.center.x+v&&w.z>=c.center.z-I&&w.z<=c.center.z+I}if(c.type==="circle"&&c.radius){const v=w.x-c.center.x,I=w.z-c.center.z;return v*v+I*I<=c.radius*c.radius}return!1}const Zn=yn.memo(function({agentId:c,terminalViewMode:v,onTerminalViewModeChange:I,inspectorOpen:E,onToggleInspector:Y,onImageClick:F,onFileClick:Re,onBashClick:ie,onViewMarkdown:f,onRequestClearSubordinates:K,onOpenBuilding:ye,keyboard:Ve,canNavigateBack:Xe,canNavigateForward:Ge,onNavigateBack:Z,onNavigateForward:le,agentInfoOpen:W,onToggleAgentInfo:De,onHeaderContextMenu:J}){var Me,ne,at,$;const b=An(c),T=Wt(),me=a.useRef(null),Ae=a.useRef(null);a.useEffect(()=>{const i=Ae.current;if(!i)return;const r=o=>{o.button===3?(o.preventDefault(),o.stopPropagation(),Z()):o.button===4&&(o.preventDefault(),o.stopPropagation(),le())},d=o=>{(o.button===3||o.button===4)&&o.preventDefault()};return i.addEventListener("mouseup",r),i.addEventListener("mousedown",d),()=>{i.removeEventListener("mouseup",r),i.removeEventListener("mousedown",d)}},[Z,le]),a.useEffect(()=>{const i=Ae.current;if(!i)return;let r=0,d=0,o=0;const Ce=250,Te=600,Pe=80,bt=1.5,q=D=>{let M=D instanceof HTMLElement?D:null;for(;M&&M!==i;){const We=window.getComputedStyle(M).overflowX;if((We==="auto"||We==="scroll")&&M.scrollWidth>M.clientWidth)return!0;M=M.parentElement}return!1},Le=D=>{const M=Date.now();if(M<o){D.preventDefault();return}if(Math.abs(D.deltaX)<=Math.abs(D.deltaY)*bt){r=0;return}if(q(D.target)){r=0;return}M-d>Ce&&(r=0),d=M,r+=D.deltaX,r<=-Pe?(r=0,o=M+Te,D.preventDefault(),Z()):r>=Pe&&(r=0,o=M+Te,D.preventDefault(),le())};return i.addEventListener("wheel",Le,{passive:!1}),()=>i.removeEventListener("wheel",Le)},[Z,le]);const fe=Ft(),ze=a.useMemo(()=>{if(!b)return null;const i=new Set,r=[];for(const d of fe.values())d.archived||d.directories.length===0||d.assignedAgentIds.includes(c)&&(i.add(d.id),r.push(d));for(const d of fe.values())d.archived||d.directories.length===0||i.has(d.id)||Kn({x:b.position.x,z:b.position.z},d)&&(i.add(d.id),r.push(d));return r.length===0?null:r.flatMap(d=>d.directories.filter(o=>o&&o.trim().length>0).map(o=>({areaId:d.id,areaName:d.name,dir:o})))},[b,c,fe]),{branches:Ue,fetchRemote:qe,fetchingDirs:Oe}=In(ze),Ie=a.useMemo(()=>{var d;const i=x.getAreaForAgent(c);if(!i)return[];const r=[];for(const o of T.values())o.type==="terminal"&&x.isPositionInArea(o.position,i)&&r.push({id:o.id,name:o.name,hasUrl:!!((d=o.terminalStatus)!=null&&d.url)});return r},[c,T]),he=a.useMemo(()=>{var d;const i=x.getAreaForAgent(c);if(!i)return[];const r=[];for(const o of T.values())o.type==="server"&&((d=o.pm2)!=null&&d.enabled)&&x.isPositionInArea(o.position,i)&&r.push({id:o.id,name:o.name});return r},[c,T]),re=a.useMemo(()=>{const i=x.getAreaForAgent(c);if(!i)return[];const r=[];for(const d of T.values())d.type==="database"&&d.database&&x.isPositionInArea(d.position,i)&&r.push({id:d.id,name:d.name});return r},[c,T]),[,oe]=a.useReducer(i=>i+1,0),H=((Me=me.current)==null?void 0:Me.search.searchMode)??!1,mt=a.useCallback(()=>{var i;(i=me.current)==null||i.search.toggleSearch(),oe()},[]),Ye=En(),ce=Ye.isPending($t),[z,G]=a.useState(null),V=z?T.get(z):null,{height:U,onResizeStart:Ee}=Sn(),[O,Q]=a.useState(()=>Nt(y.GIT_PANEL_OPEN,!1)),[ge,Ke]=a.useState(()=>Nt(y.BUILDINGS_PANEL_OPEN,!1)),[de,xe]=a.useState(!1),ft=a.useCallback(()=>{xe(i=>{const r=!i;return r&&Mn.setEnabled(!0),r})},[]),ht=a.useCallback(()=>xe(!1),[]),be=a.useCallback(()=>{Q(i=>{const r=!i;return se(y.GIT_PANEL_OPEN,r),r})},[]),gt=a.useCallback(()=>{Ke(i=>{const r=!i;return se(y.BUILDINGS_PANEL_OPEN,r),r})},[]),Ze=a.useCallback(()=>{Q(!1),se(y.GIT_PANEL_OPEN,!1)},[]),xt=a.useCallback(()=>{Ke(!1),se(y.BUILDINGS_PANEL_OPEN,!1)},[]),$e=Tn();a.useEffect(()=>{if(!z)return;Ie.some(r=>r.id===z)||G(null)},[z,Ie]);const[_e,ue]=a.useState(!1),Be=a.useRef(null);if(a.useEffect(()=>{if(!_e)return;const i=r=>{Be.current&&!Be.current.contains(r.target)&&ue(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[_e]),!b)return e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-chat__placeholder",children:[e.jsx("span",{className:"flat-chat__placeholder-icon",children:"💬"}),e.jsx("span",{className:"flat-chat__placeholder-text",children:"Select an agent to start chatting"})]})});const ee=b.contextStats,Je=!!ee,Qe=ee?ee.totalTokens:b.contextUsed||0,we=ee?ee.contextWindow:b.contextLimit||2e5,h=ee?ee.usedPercent:Math.round(Qe/we*100),P=Math.max(0,Math.min(100,h)),X=Math.round(P*10)/10,Se=Math.round((100-P)*10)/10,Fe=P>=80?"#ff4a4a":P>=60?"#ff9e4a":P>=40?"#ffd700":"#4aff9e",et=(Qe/1e3).toFixed(1),tt=(we/1e3).toFixed(1),te=b.cwd,nt=te?qn(te):null,pe=((ne=b.subordinateIds)==null?void 0:ne.length)||0,ve=pe>0;return e.jsxs("div",{ref:Ae,className:`flat-terminal-wrapper ${O||ge||de?"flat-terminal-wrapper--with-side-panel":""}`,children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${W?"flat-terminal-wrapper__header-main--active":""}`,onClick:De,onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),J({x:i.clientX,y:i.clientY})},title:W?"Hide agent info":"Show agent info","aria-pressed":W,children:[e.jsx(Ht,{agent:b,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:b.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:Vt(b.status)},children:b.status})]}),b.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:b.taskLabel,children:["📋 ",b.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:b.provider==="codex"?"/assets/codex.png":b.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:b.provider,className:"flat-terminal-wrapper__header-provider-icon",title:b.provider==="codex"?"Codex Agent":b.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:i,effort:r}=Yn(b);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:r?`Model: ${i} · Effort: ${r}`:`Model: ${i}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:i}),r&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-sep","aria-hidden":"true",children:"·"}),e.jsx("span",{className:"flat-terminal-wrapper__header-model-effort",children:r})]})]})})()]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__header-meta",children:[e.jsx("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:Vn.map(i=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${v===i?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>I(i),title:Un[i],"aria-pressed":v===i,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:Gn[i]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:Xn[i]})]},i))}),e.jsxs("div",{className:"flat-terminal-wrapper__actions",role:"group","aria-label":"Terminal actions",children:[e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:Z,disabled:!Xe,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(u,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:le,disabled:!Ge,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(u,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${H?"flat-terminal-wrapper__action-btn--active":""}`,onClick:mt,title:H?"Close search":"Search messages","aria-pressed":H,children:e.jsx(u,{name:H?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${ce?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>Ye.handleClick($t,()=>{var i;x.clearContext(c),(i=me.current)==null||i.historyLoader.clearHistory()}),title:ce?"Click again to confirm clear context":"Clear context",children:e.jsx(u,{name:ce?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${O?"flat-terminal-wrapper__action-btn--active":""}`,onClick:be,title:O?"Hide git panel":"Show git changes","aria-pressed":O,children:e.jsx(u,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${ge?"flat-terminal-wrapper__action-btn--active":""}`,onClick:gt,title:ge?"Hide buildings panel":"Show area buildings","aria-pressed":ge,children:e.jsx(u,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:Be,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${_e?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>ue(i=>!i),title:"More actions","aria-expanded":_e,children:"⋮"}),_e&&e.jsxs("div",{className:"flat-terminal-wrapper__more-menu",role:"menu",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-terminal-wrapper__more-item ${de?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{ft(),ue(!1)},title:de?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(u,{name:"bug",size:14}),e.jsx("span",{children:de?"Hide Debug Panel":"Show Debug Panel"})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item",onClick:()=>{x.collapseContext(c),ue(!1)},disabled:b.status!=="idle",title:b.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(u,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),ve&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{K(c,pe),ue(!1)},children:[e.jsx(u,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",pe," subordinate",pe===1?"":"s"]})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{x.killAgent(c),ue(!1)},children:[e.jsx(u,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${E?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:Y,title:E?"Hide inspector panel":"Show inspector panel","aria-label":E?"Hide inspector panel":"Show inspector panel","aria-pressed":E,children:[e.jsx("span",{className:"flat-terminal-wrapper__inspector-icon","aria-hidden":"true",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"}),e.jsx("line",{x1:"10",y1:"2.5",x2:"10",y2:"13.5"})]})}),e.jsx("span",{className:"flat-terminal-wrapper__inspector-label",children:"Inspector"})]}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__close",onClick:()=>x.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(u,{name:"cross",size:14})})]})]}),e.jsx(Pn,{ref:me,agentId:c,agent:b,viewMode:v,isOpen:!0,onImageClick:F,onFileClick:Re,onBashClick:ie,onViewMarkdown:f,keyboard:Ve,hasModalOpen:!1}),V&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:Ee,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded terminal"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`Embedded terminal: ${V.name}`,style:{height:U},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(u,{name:"terminal",size:12}),e.jsx("span",{children:V.name}),!((at=V.terminalStatus)!=null&&at.url)&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>G(null),title:"Close embedded terminal","aria-label":"Close embedded terminal",children:e.jsx(u,{name:"cross",size:12})})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:($=V.terminalStatus)!=null&&$.url?e.jsx(Ln,{terminalUrl:V.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."})})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[b.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(u,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),te&&nt&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${te}`,"aria-label":`Open ${te} in file explorer`,role:"button",tabIndex:0,onClick:()=>x.openFileExplorer(te),onKeyDown:i=>{(i.key==="Enter"||i.key===" ")&&(i.preventDefault(),x.openFileExplorer(te))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(u,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:nt})]}),ze&&ze.map(({areaId:i,areaName:r,dir:d})=>{const o=Ue.get(d),Ce=Oe.has(d),Te=d.split("/").filter(Boolean).pop()||d;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${r}: ${d}${o?` (${o.branch}${o.ahead?` ↑${o.ahead}`:""}${o.behind?` ↓${o.behind}`:""})`:""}`,onClick:()=>x.openFileExplorerForAreaFolder(i,d),children:[e.jsx(u,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:Te}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(u,{name:"git-branch",size:10})," ",o.branch]}),o.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${o.ahead} ahead`,children:[e.jsx(u,{name:"arrow-up",size:9}),o.ahead]}),o.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${o.behind} behind`,children:[e.jsx(u,{name:"arrow-down",size:9}),o.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${Ce?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:Pe=>{Pe.stopPropagation(),qe(d)},children:e.jsx(u,{name:Ce?"hourglass":"download",size:12})})]})]},`${i}:${d}`)}),e.jsxs("span",{className:"flat-terminal-wrapper__context",onClick:()=>x.setContextModalAgentId(c),title:Je?`Context usage: ${et}k / ${tt}k tokens (${X}% used). Click to view stats.`:"Click to fetch context stats",children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(u,{name:"dashboard",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__context-label",children:"Ctx:"}),e.jsx("span",{className:"flat-terminal-wrapper__context-bar",children:e.jsx("span",{className:"flat-terminal-wrapper__context-bar-fill",style:{width:`${P}%`,backgroundColor:Fe}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:Fe},children:[et,"k/",tt,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",Se,"% free)"]}),!Je&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(u,{name:"warn",size:12})})]}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),Ie.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:Ie.map(i=>{const r=z===i.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""} ${i.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${r?"Hide":"Show"} terminal: ${i.name}${i.hasUrl?"":" (starting...)"}`,onClick:()=>{if(r){G(null);return}i.hasUrl||x.sendBuildingCommand(i.id,"start"),G(i.id)},children:e.jsx(u,{name:"terminal",size:14})},i.id)})}),he.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:he.map(i=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open logs: ${i.name}`,onClick:()=>ye(i.id),children:e.jsx(u,{name:"scroll",size:14})},i.id))}),re.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:re.map(i=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open database: ${i.name}`,onClick:()=>ye(i.id),children:e.jsx(u,{name:"hard-drives",size:14})},i.id))}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(Rn,{})})]}),O&&e.jsx(Dn,{agentId:c,agents:$e,onClose:Ze,branchInfoMap:Ue,fetchRemote:qe,fetchingDirs:Oe}),ge&&e.jsx(zn,{agentId:c,onClose:xt}),de&&e.jsx(On,{agentId:c,onClose:ht})]})});function ta({onAgentClick:w,onBuildingClick:c,onBuildingDoubleClick:v,onBuildingPopup:I,onAreaContextMenu:E,onOpenSpawnModal:Y,onOpenBossSpawnModal:F,onOpenAreaModal:Re}){const{t:ie}=Bt(["common"]),f=on(),K=cn(),[ye,Ve]=a.useState(null),[Xe,Ge]=a.useState(null),[Z,le]=a.useState(null),[W,De]=a.useState(null),[J,b]=a.useState(null),[T,me]=a.useState(null),[Ae,fe]=a.useState(!1),ze=a.useCallback(()=>{fe(t=>!t)},[]),Ue=a.useCallback(()=>{fe(!1)},[]),[qe,Oe]=a.useState(()=>{const t=Mt(y.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Ie=a.useCallback(t=>{Oe(t),Tt(y.VIEW_MODE,t)},[]);a.useEffect(()=>{const t=n=>{if(n.key!==y.VIEW_MODE)return;const s=n.newValue;(s==="simple"||s==="chat"||s==="advanced")&&Oe(s)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[he,re]=a.useState(()=>Nt(y.FLAT_INSPECTOR_OPEN,!1)),[oe,H]=a.useState(!1),mt=a.useCallback(()=>H(t=>!t),[]),Ye=a.useCallback(()=>H(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:oe}}))},[oe]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:he}}))},[he]),a.useEffect(()=>{const t=()=>H(_=>!_),n=()=>{re(_=>{const l=!_;return se(y.FLAT_INSPECTOR_OPEN,l),l})},s=()=>{H(!1),re(!1),se(y.FLAT_INSPECTOR_OPEN,!1)},p=()=>H(!1),m=()=>{re(!1),se(y.FLAT_INSPECTOR_OPEN,!1)};return window.addEventListener("tide-toggle-flat-agents-drawer",t),window.addEventListener("tide-toggle-flat-inspector",n),window.addEventListener("tide-close-flat-side-views",s),window.addEventListener("tide-close-flat-agents-drawer-only",p),window.addEventListener("tide-close-flat-inspector-only",m),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",n),window.removeEventListener("tide-close-flat-side-views",s),window.removeEventListener("tide-close-flat-agents-drawer-only",p),window.removeEventListener("tide-close-flat-inspector-only",m)}},[]);const ce=a.useRef(null),z=a.useRef(null),[G,V]=a.useState(()=>{const t=Pt(y.FLAT_MIDDLE_WIDTH,0);return t>=pt?t:null}),[U,Ee]=a.useState(()=>{const t=Pt(y.FLAT_INSPECTOR_WIDTH,0);return t>=jt?t:null}),O=a.useCallback(t=>{if(typeof window>"u")return t;const n=U!==null?ut+U:0,s=window.innerWidth-Ot-ut-zt-n;return Math.max(pt,Math.min(Math.max(s,pt),t))},[U]),Q=a.useCallback(t=>{var m;if(typeof window>"u")return t;const n=(m=ce.current)==null?void 0:m.querySelector(".flat-middle"),s=(n==null?void 0:n.getBoundingClientRect().width)??pt,p=window.innerWidth-Ot-s-ut-zt-ut;return Math.max(jt,Math.min(Math.max(p,jt),t))},[]);a.useEffect(()=>{if(G===null&&U===null)return;const t=()=>{V(n=>{if(n===null)return n;const s=O(n);return s===n?n:s}),Ee(n=>{if(n===null)return n;const s=Q(n);return s===n?n:s})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[G,U,O,Q]);const ge=a.useCallback(t=>{var s;if(t.button!==0)return;const n=(s=ce.current)==null?void 0:s.querySelector(".flat-middle");n&&(t.currentTarget.setPointerCapture(t.pointerId),z.current={kind:"middle",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),Ke=a.useCallback(t=>{var s;if(t.button!==0)return;const n=(s=ce.current)==null?void 0:s.querySelector(".flat-inspector");n&&(t.currentTarget.setPointerCapture(t.pointerId),z.current={kind:"inspector",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),de=a.useCallback(t=>{const n=z.current;if(!n||t.pointerId!==n.pointerId)return;const s=t.clientX-n.startX;n.kind==="middle"?V(O(n.startWidth+s)):Ee(Q(n.startWidth-s))},[O,Q]),xe=a.useCallback(t=>{const n=z.current;if(!n||t.pointerId!==n.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(z.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-n.startX)>2))return;const p=t.clientX-n.startX;if(n.kind==="middle"){const m=O(n.startWidth+p);V(m),dt(y.FLAT_MIDDLE_WIDTH,m)}else{const m=Q(n.startWidth-p);Ee(m),dt(y.FLAT_INSPECTOR_WIDTH,m)}},[O,Q]),ft=a.useCallback(()=>{V(null),dt(y.FLAT_MIDDLE_WIDTH,0)},[]),ht=a.useCallback(()=>{Ee(null),dt(y.FLAT_INSPECTOR_WIDTH,0)},[]),[be,gt]=a.useState(()=>Mt(y.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),Ze=a.useCallback(t=>{gt(t),Tt(y.FLAT_INSPECTOR_VIEW,t)},[]),xt=a.useCallback(()=>{re(t=>{const n=!t;return se(y.FLAT_INSPECTOR_OPEN,n),n})},[]),$e=a.useCallback(()=>{re(!1),se(y.FLAT_INSPECTOR_OPEN,!1)},[]),_e=dn(),ue=a.useCallback((t,n)=>{Ve({url:t,name:n})},[]),Be=a.useCallback((t,n)=>{Ge({command:t,output:n,isLive:!1})},[]),ee=a.useCallback((t,n)=>{x.setFileViewerPath(t,n)},[]),Je=a.useCallback(t=>{},[]),Qe=a.useCallback((t,n)=>{le({agentId:t,count:n})},[]),we=a.useCallback(t=>{v?v(t):c(t)},[c,v]),h=a.useMemo(()=>K.size>0?Array.from(K)[0]:null,[K]);a.useEffect(()=>{fe(!1)},[h]);const P=a.useRef([]),X=a.useRef(-1),Se=a.useRef(!1),Fe=a.useRef(null),[et,tt]=a.useState(!1),[te,nt]=a.useState(!1),pe=a.useRef(!1),ve=a.useRef(null),Me=a.useRef(!1),ne=a.useMemo(()=>new Set(f.map(t=>t.id)),[f]),at=a.useMemo(()=>{const t=new Map(f.map(s=>[s.id,s])),n=new Map;for(const s of f)if((s.isBoss||s.class==="boss")&&s.subordinateIds&&s.subordinateIds.length>0){const p=s.subordinateIds.map(m=>t.get(m)).filter(m=>m!==void 0);p.length>0&&n.set(s.id,p)}return n},[f]),$=a.useCallback(()=>{const t=P.current,n=X.current;tt(n>0),nt(n>=0&&n<t.length-1)},[]),i=a.useCallback(t=>{const n=P.current;if(n.length===0)return;let s=X.current+t;for(;s>=0&&s<n.length;){const p=n[s];if(ne.has(p)){Se.current=!0,X.current=s,$(),x.selectAgent(p);return}s+=t}},[ne,$]),r=a.useCallback(()=>i(-1),[i]),d=a.useCallback(()=>i(1),[i]);Wn(a.useCallback(()=>{const t=P.current,n=X.current;return t.length>0&&n>0?(i(-1),"handled"):"exit"},[i]));const o=a.useCallback((t,n)=>{if(typeof window>"u")return;const s=window.history.state,m={...typeof s=="object"&&s!==null?s:{},__flatAgentNav:{agentId:t}};n==="replace"?window.history.replaceState(m,"",window.location.href):window.history.pushState(m,"",window.location.href)},[]);a.useEffect(()=>{if(!h){pe.current=!1,ve.current=null;return}if(!pe.current){o(h,"replace"),pe.current=!0,ve.current=h;return}if(Me.current){Me.current=!1,ve.current=h;return}ve.current!==h&&(o(h,"push"),ve.current=h)},[h,o]),a.useEffect(()=>{const t=n=>{var _,l;const s=(l=(_=n.state)==null?void 0:_.__flatAgentNav)==null?void 0:l.agentId;if(!s||typeof s!="string"||!ne.has(s)||s===h)return;Me.current=!0,Se.current=!0;const p=P.current,m=p.lastIndexOf(s);m>=0?X.current=m:(p.push(s),X.current=p.length-1),$(),x.selectAgent(s)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[ne,h,$]),a.useEffect(()=>{if(!h){P.current=[],X.current=-1,$();return}if(Fe.current=h,Se.current){Se.current=!1,$();return}const t=P.current,n=X.current;if(n>=0&&t[n]===h){$();return}const s=n<t.length-1?t.slice(0,n+1):t.slice();s.push(h),s.length>100&&s.shift(),P.current=s,X.current=s.length-1,$()},[h,$]);const Ce=a.useCallback(t=>{w(t),H(!1)},[w]),Te=h??"",Pe=a.useCallback(()=>{},[]),bt=a.useCallback(t=>{Ce(t)},[Ce]),q=he,[Le,D]=a.useState(q),[M,We]=a.useState(q);a.useEffect(()=>{if(q){D(!0);return}We(!1);const t=setTimeout(()=>D(!1),240);return()=>clearTimeout(t)},[q]),a.useEffect(()=>{if(!Le||!q)return;let t=0;const n=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>We(!0))});return()=>{cancelAnimationFrame(n),cancelAnimationFrame(t)}},[Le,q]);const kt=a.useRef(null);a.useEffect(()=>{if(h)return;const t=n=>{if(n.key!==" "&&n.key!=="Backspace")return;const s=n.target;if(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable)return;const p=Fe.current;!p||!ne.has(p)||(n.preventDefault(),x.selectAgent(p))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[h,ne]);const[Xt,yt]=a.useState(new Set),Gt=a.useCallback(t=>{yt(n=>{const s=new Set(n);return s.has(t)?s.delete(t):s.add(t),s})},[]),[je,Ut]=a.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches);a.useEffect(()=>{if(typeof window>"u")return;const t=window.matchMedia("(max-width: 768px)"),n=s=>Ut(s.matches);return t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[]);const[st,qt]=a.useState(null),Yt=a.useCallback(t=>{qt(n=>n===t?null:t)},[]),_t=Ft(),it=Wt(),[Kt]=un(),Ne=a.useMemo(()=>{const t=new Map,n=[];for(const g of f){const k=x.getAreaForAgent(g.id);if(!Lt((k==null?void 0:k.id)??null))continue;if(!k||k.archived){n.push(g);continue}const j=t.get(k.id);j?j.push(g):t.set(k.id,[g])}const s=new Map,p=[];for(const g of it.values()){let k=!1;for(const j of _t.values())if(!j.archived&&Rt(j.id)&&x.isPositionInArea(g.position,j)){const ae=s.get(j.id);ae?ae.push(g):s.set(j.id,[g]),k=!0;break}!k&&Lt(null)&&p.push(g)}const m=[];for(const[,g]of _t){if(g.archived||!Rt(g.id))continue;const k=t.get(g.id),j=s.get(g.id)??[];(k&&k.length>0||j.length>0)&&m.push({area:g,agents:k??[],buildings:j})}(n.length>0||p.length>0)&&m.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:n,buildings:p});const _=m.filter(g=>g.area.id!=="__unassigned__"),l=m.filter(g=>g.area.id==="__unassigned__");let A=1,N=1;const B=new Map;if(_.length>1){let g=1/0,k=-1/0,j=1/0,ae=-1/0;for(const L of _)g=Math.min(g,L.area.center.x),k=Math.max(k,L.area.center.x),j=Math.min(j,L.area.center.z),ae=Math.max(ae,L.area.center.z);const rt=k-g||1,ot=ae-j||1;if(_.length<=4){A=_.length,N=1;const L=[..._].sort((R,wt)=>R.area.center.x-wt.area.center.x);for(let R=0;R<L.length;R++)B.set(L[R].area.id,{row:1,col:R+1})}else{const L=[..._].sort((C,S)=>C.area.center.x-S.area.center.x),R=[];for(let C=1;C<L.length;C++)R.push(L[C].area.center.x-L[C-1].area.center.x);const wt=R.reduce((C,S)=>C+S,0)/R.length||1;let At=1;for(const C of R)C>wt*1.3&&At++;A=Math.max(2,Math.min(At,_.length));const vt=[..._].sort((C,S)=>C.area.center.z-S.area.center.z),ct=[];for(let C=1;C<vt.length;C++)ct.push(vt[C].area.center.z-vt[C-1].area.center.z);const en=ct.reduce((C,S)=>C+S,0)/ct.length||1;let It=1;for(const C of ct)C>en*1.3&&It++;N=Math.max(2,Math.min(It,_.length)),A=Math.max(A,Math.ceil(_.length/N)),N=Math.max(N,Math.ceil(_.length/A));const tn=rt/A,nn=ot/N,Ct=new Set;for(const C of _){let S=Math.min(A-1,Math.max(0,Math.floor((C.area.center.x-g)/tn))),ke=Math.min(N-1,Math.max(0,Math.floor((C.area.center.z-j)/nn))),He=`${ke},${S}`,Et=0;const an=N*A;for(;Ct.has(He)&&Et<an;)S++,S>=A&&(S=0,ke=(ke+1)%N),He=`${ke},${S}`,Et++;Ct.has(He)&&(ke=N,S=0,He=`${ke},${S}`,N++),Ct.add(He),B.set(C.area.id,{row:ke+1,col:S+1})}}}const lt=g=>{g.sort((k,j)=>{var rt,ot,L,R;const ae=(((rt=k.position)==null?void 0:rt.z)??0)-(((ot=j.position)==null?void 0:ot.z)??0);return ae!==0?ae:(((L=k.position)==null?void 0:L.x)??0)-(((R=j.position)==null?void 0:R.x)??0)})};for(const g of _)lt(g.agents);for(const g of l)lt(g.agents);return{groups:[..._,...l],gridCols:A,gridRows:N,positions:B}},[f,_t,it,Kt]),Zt=a.useMemo(()=>{if(!W)return[];const t=f.find(n=>n.id===W.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(u,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:open-agent-edit",{detail:{agentId:t.id}}))}},{id:"open-chat",label:"Open Chat",icon:e.jsx(u,{name:"chat",size:14}),onClick:()=>w(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(u,{name:"trash",size:14}),danger:!0,onClick:()=>{me({agentId:t.id,name:t.name})}}]:[]},[W,f,w]),Jt=a.useMemo(()=>{var _;if(!J)return[];const t=it.get(J.buildingId);if(!t)return[];const n=[],s=t.type==="server"||t.type==="docker"||t.type==="terminal",p=t.status==="running",m=t.type==="boss";if(n.push({id:"open",label:t.type==="database"?"Open Database":t.type==="folder"?"Open Folder":t.type==="boss"?"View Boss Logs":t.type==="terminal"?"Open Terminal":t.type==="server"&&((_=t.pm2)!=null&&_.enabled)?"View PM2 Logs":"Open",icon:e.jsx(u,{name:t.type==="database"?"database":t.type==="folder"?"folder":t.type==="terminal"?"terminal":"eye",size:14}),onClick:()=>we(t.id)}),s&&(p||n.push({id:"start",label:"Start",icon:e.jsx(u,{name:"play",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"start")}),p&&(n.push({id:"restart",label:"Restart",icon:e.jsx(u,{name:"refresh",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"restart")}),n.push({id:"stop",label:"Stop",icon:e.jsx(u,{name:"stop",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"stop")}))),m&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(n.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(u,{name:"launch",size:14}),onClick:()=>{for(const l of t.subordinateBuildingIds)x.sendBuildingCommand(l,"start")}}),n.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(u,{name:"pause",size:14}),onClick:()=>{for(const l of t.subordinateBuildingIds)x.sendBuildingCommand(l,"stop")}}),n.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(u,{name:"restart",size:14}),onClick:()=>{for(const l of t.subordinateBuildingIds)x.sendBuildingCommand(l,"restart")}})),s&&n.push({id:"health-check",label:"Health Check",icon:e.jsx(u,{name:"health",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"healthCheck")}),n.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),n.push({id:"edit",label:"Edit Building",icon:e.jsx(u,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:building-edit",{detail:{buildingId:t.id}}))}}),n.push({id:"clone",label:"Clone Building",icon:e.jsx(u,{name:"copy",size:14}),onClick:()=>{x.createBuilding({name:`${t.name} (Copy)`,type:t.type,style:t.style,color:t.color,scale:t.scale,position:{x:t.position.x+2,z:t.position.z+2},cwd:t.cwd,folderPath:t.folderPath,commands:t.commands,pm2:t.pm2,docker:t.docker,database:t.database,terminal:t.terminal,urls:t.urls,subordinateBuildingIds:t.subordinateBuildingIds})}}),t.urls&&t.urls.length>0)for(const l of t.urls)n.push({id:`url-${l.label}`,label:l.label,icon:e.jsx(u,{name:"link",size:14}),onClick:()=>window.open(l.url,"_blank","noopener,noreferrer")});return n.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),n.push({id:"delete",label:"Delete Building",icon:e.jsx(u,{name:"trash",size:14}),danger:!0,onClick:()=>x.deleteBuilding(t.id)}),n},[J,it,we]),Qt=a.useCallback(t=>{const n=new Set(Ne.groups.map(s=>s.area.id));n.delete(t),yt(n),requestAnimationFrame(()=>{const s=kt.current;if(!s)return;const p=s.querySelector(`[data-area-id="${t}"]`);if(!p)return;const m=s.getBoundingClientRect(),l=p.getBoundingClientRect().top-m.top+s.scrollTop-8;s.scrollTo({top:Math.max(0,l),behavior:"smooth"})})},[Ne]);return e.jsxs("div",{ref:ce,className:`flat-view ${q?"flat-view--with-inspector":""} ${h?"flat-view--has-chat":""} ${oe?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(G===null&&U===null)return;const t={};return G!==null&&(t["--flat-middle-width"]=`${G}px`),U!==null&&(t["--flat-inspector-width"]=`${U}px`),t})(),children:[oe&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:Ye,"aria-hidden":"true"}),e.jsxs("div",{className:"flat-middle",children:[e.jsx("div",{className:"flat-middle__header",children:e.jsxs("div",{className:"flat-middle__actions",children:[e.jsx("button",{className:"flat-cta-btn flat-cta-btn--agent",onClick:Y,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:F,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:Re,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(pn,{activeAgentId:Te,onClose:Pe,onSelectAgent:bt,collapsedAreas:Xt,onToggleArea:Gt,agentListRef:kt})})]}),e.jsx("div",{className:"flat-splitter flat-splitter--middle",role:"separator","aria-orientation":"vertical","aria-label":"Resize agents panel",title:"Drag to resize · Double-click to reset",onPointerDown:ge,onPointerMove:de,onPointerUp:xe,onPointerCancel:xe,onDoubleClick:ft}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":oe?"Close agents sidebar":"Open agents sidebar","aria-expanded":oe,onClick:mt,children:[e.jsx(u,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),h?e.jsx(Zn,{agentId:h,terminalViewMode:qe,onTerminalViewModeChange:Ie,inspectorOpen:he,onToggleInspector:xt,onImageClick:ue,onFileClick:ee,onBashClick:Be,onViewMarkdown:Je,onRequestClearSubordinates:Qe,onOpenBuilding:we,keyboard:_e,canNavigateBack:et,canNavigateForward:te,onNavigateBack:r,onNavigateForward:d,agentInfoOpen:Ae,onToggleAgentInfo:ze,onHeaderContextMenu:t=>{h&&De({agentId:h,position:t})}}):e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-map",children:[e.jsxs("div",{className:"flat-map__header",children:[e.jsx("span",{className:"flat-map__title",children:"🗺️ Areas"}),e.jsx("span",{className:"flat-map__hint",children:"Click an area to focus it, or an agent to chat"}),e.jsx(Hn,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${Ne.gridCols}, 1fr)`},children:Ne.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(()=>{var n;const t=je&&st?((n=Ne.positions.get(st))==null?void 0:n.row)??null:null;return Ne.groups.map(s=>{const p=s.area.id,m=Ne.positions.get(p),_=je&&st!==p;return je&&t!=null&&(m==null?void 0:m.row)===t&&p!==st?null:e.jsxs("div",{className:`flat-map-area-card${_?" flat-map-area-card--collapsed":""}`,style:{"--area-color":s.area.color,gridRow:m==null?void 0:m.row,gridColumn:m==null?void 0:m.col},onContextMenu:l=>{E&&(l.preventDefault(),l.stopPropagation(),E(p,{x:l.clientX,y:l.clientY}))},children:[e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>je?Yt(p):Qt(p),title:je?_?`Expand ${s.area.name}`:`Collapse ${s.area.name}`:`Focus ${s.area.name} in left panel`,"aria-expanded":je?!_:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:s.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:s.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:s.agents.length}),je&&e.jsx(u,{name:_?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:s.agents.map(l=>{const A=l.isBoss||l.class==="boss",N=A?at.get(l.id):void 0,B=mn(l),lt=B.usedPercent>=80?"#ff4a4a":B.usedPercent>=60?"#ff9e4a":B.usedPercent>=40?"#ffd700":"#4aff9e",g=`Context: ${(B.totalTokens/1e3).toFixed(1)}k / ${(B.contextWindow/1e3).toFixed(1)}k (${B.usedPercent}% used, ${B.freePercent}% free)`,k=l.latestTodos&&l.latestTodos.length>0||N&&N.length>0;return e.jsx(fn,{todos:l.latestTodos,subordinates:N,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${l.status}`,onClick:()=>w(l.id),onContextMenu:j=>{j.preventDefault(),j.stopPropagation(),De({agentId:l.id,position:{x:j.clientX,y:j.clientY}})},title:k?void 0:`${A?"Boss · ":""}Open chat with ${l.name}
1
+ import{r as a,z as sn,B as St,u as Bt,E as ln,j as e,V as rn,G as on,H as cn,J as Mt,S as y,K as Tt,L as Nt,M as Pt,N as dt,O as se,P as dn,s as x,U as Ft,W as Wt,X as un,v as Lt,w as Rt,I as u,Y as pn,m as mn,Z as fn,_ as Ht,$ as Vt,a0 as hn,a1 as gn,a2 as xn,a3 as bn,a4 as _n,a5 as wn,a6 as vn,a7 as Cn,a8 as jn,a9 as Nn,aa as Dt,C as kn,ab as yn,ac as An,ad as In,ae as En,af as Sn,ag as Mn,ah as Tn,ai as Pn,aj as Ln,ak as Rn,al as Dn,am as zn,an as On,ao as $n,ap as Bn,aq as Fn}from"./main-XbhAPjbi.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function Wn(w){const c=a.useRef(w);c.current=w,a.useEffect(()=>{if(!sn())return;let v=null,I=!1;return St.addListener("backButton",()=>{c.current()==="exit"&&St.exitApp()}).then(E=>{I?E.remove():v=E}),()=>{I=!0,v&&(v.remove(),v=null)}},[])}const Hn=a.memo(function({className:c=""}){const{t:v}=Bt(["common"]),[I,E]=ln(),Y=a.useRef(null),[F,Re]=a.useState(null);a.useLayoutEffect(()=>{const f=Y.current;if(!f)return;const K=f.querySelector(".view-mode-toggle__btn--active");K&&Re({left:K.offsetLeft,width:K.offsetWidth})},[I]);const ie=a.useCallback(f=>{if(f!==I){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:f}})),f==="3d"){requestAnimationFrame(()=>E(f));return}E(f)}},[I,E]);return e.jsxs("div",{className:`view-mode-toggle ${c}`,ref:Y,children:[F&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:F.left,width:F.width}}),rn.map(f=>e.jsxs("button",{className:`view-mode-toggle__btn ${I===f?"view-mode-toggle__btn--active":""}`,onClick:()=>ie(f),title:v(`common:viewMode.descriptions.${f}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[f==="2d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"})]}),f==="3d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),e.jsx("path",{d:"M2 17l10 5 10-5"}),e.jsx("path",{d:"M2 12l10 5 10-5"})]}),f==="flat"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"3",y:"13",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"13",width:"8",height:"8",rx:"1"})]}),f==="dashboard"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"12",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"3",y:"16",width:"7",height:"5",rx:"1"})]})]}),e.jsx("span",{className:"view-mode-toggle__label",children:v(`common:viewMode.labels.${f}`)})]},f))]})}),ut=3,pt=280,zt=320,jt=240,Ot=64,Vn=["simple","chat","advanced"],Xn={simple:"Simple",chat:"Chat",advanced:"Advanced"},Gn={simple:"○",chat:"◐",advanced:"◉"},Un={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},$t="flat-clear-context";function qn(w){const c=w.split("/").filter(Boolean);return c.length===0?w:c.slice(-2).join("/")}function Yn(w){if(w.provider==="codex"){const Y=w.codexModel||"gpt-5.3-codex",F=$n[Y];return{model:(F==null?void 0:F.label)||Y}}if(w.provider==="opencode")return{model:w.opencodeModel||"opencode"};const c=w.model||"sonnet",v=Fn[c],I=w.effort,E=I?Bn[I]:void 0;return{model:(v==null?void 0:v.label)||c,effort:E==null?void 0:E.label}}function Kn(w,c){if(c.type==="rectangle"&&c.width&&c.height){const v=c.width/2,I=c.height/2;return w.x>=c.center.x-v&&w.x<=c.center.x+v&&w.z>=c.center.z-I&&w.z<=c.center.z+I}if(c.type==="circle"&&c.radius){const v=w.x-c.center.x,I=w.z-c.center.z;return v*v+I*I<=c.radius*c.radius}return!1}const Zn=yn.memo(function({agentId:c,terminalViewMode:v,onTerminalViewModeChange:I,inspectorOpen:E,onToggleInspector:Y,onImageClick:F,onFileClick:Re,onBashClick:ie,onViewMarkdown:f,onRequestClearSubordinates:K,onOpenBuilding:ye,keyboard:Ve,canNavigateBack:Xe,canNavigateForward:Ge,onNavigateBack:Z,onNavigateForward:le,agentInfoOpen:W,onToggleAgentInfo:De,onHeaderContextMenu:J}){var Me,ne,at,$;const b=An(c),T=Wt(),me=a.useRef(null),Ae=a.useRef(null);a.useEffect(()=>{const i=Ae.current;if(!i)return;const r=o=>{o.button===3?(o.preventDefault(),o.stopPropagation(),Z()):o.button===4&&(o.preventDefault(),o.stopPropagation(),le())},d=o=>{(o.button===3||o.button===4)&&o.preventDefault()};return i.addEventListener("mouseup",r),i.addEventListener("mousedown",d),()=>{i.removeEventListener("mouseup",r),i.removeEventListener("mousedown",d)}},[Z,le]),a.useEffect(()=>{const i=Ae.current;if(!i)return;let r=0,d=0,o=0;const Ce=250,Te=600,Pe=80,bt=1.5,q=D=>{let M=D instanceof HTMLElement?D:null;for(;M&&M!==i;){const We=window.getComputedStyle(M).overflowX;if((We==="auto"||We==="scroll")&&M.scrollWidth>M.clientWidth)return!0;M=M.parentElement}return!1},Le=D=>{const M=Date.now();if(M<o){D.preventDefault();return}if(Math.abs(D.deltaX)<=Math.abs(D.deltaY)*bt){r=0;return}if(q(D.target)){r=0;return}M-d>Ce&&(r=0),d=M,r+=D.deltaX,r<=-Pe?(r=0,o=M+Te,D.preventDefault(),Z()):r>=Pe&&(r=0,o=M+Te,D.preventDefault(),le())};return i.addEventListener("wheel",Le,{passive:!1}),()=>i.removeEventListener("wheel",Le)},[Z,le]);const fe=Ft(),ze=a.useMemo(()=>{if(!b)return null;const i=new Set,r=[];for(const d of fe.values())d.archived||d.directories.length===0||d.assignedAgentIds.includes(c)&&(i.add(d.id),r.push(d));for(const d of fe.values())d.archived||d.directories.length===0||i.has(d.id)||Kn({x:b.position.x,z:b.position.z},d)&&(i.add(d.id),r.push(d));return r.length===0?null:r.flatMap(d=>d.directories.filter(o=>o&&o.trim().length>0).map(o=>({areaId:d.id,areaName:d.name,dir:o})))},[b,c,fe]),{branches:Ue,fetchRemote:qe,fetchingDirs:Oe}=In(ze),Ie=a.useMemo(()=>{var d;const i=x.getAreaForAgent(c);if(!i)return[];const r=[];for(const o of T.values())o.type==="terminal"&&x.isPositionInArea(o.position,i)&&r.push({id:o.id,name:o.name,hasUrl:!!((d=o.terminalStatus)!=null&&d.url)});return r},[c,T]),he=a.useMemo(()=>{var d;const i=x.getAreaForAgent(c);if(!i)return[];const r=[];for(const o of T.values())o.type==="server"&&((d=o.pm2)!=null&&d.enabled)&&x.isPositionInArea(o.position,i)&&r.push({id:o.id,name:o.name});return r},[c,T]),re=a.useMemo(()=>{const i=x.getAreaForAgent(c);if(!i)return[];const r=[];for(const d of T.values())d.type==="database"&&d.database&&x.isPositionInArea(d.position,i)&&r.push({id:d.id,name:d.name});return r},[c,T]),[,oe]=a.useReducer(i=>i+1,0),H=((Me=me.current)==null?void 0:Me.search.searchMode)??!1,mt=a.useCallback(()=>{var i;(i=me.current)==null||i.search.toggleSearch(),oe()},[]),Ye=En(),ce=Ye.isPending($t),[z,G]=a.useState(null),V=z?T.get(z):null,{height:U,onResizeStart:Ee}=Sn(),[O,Q]=a.useState(()=>Nt(y.GIT_PANEL_OPEN,!1)),[ge,Ke]=a.useState(()=>Nt(y.BUILDINGS_PANEL_OPEN,!1)),[de,xe]=a.useState(!1),ft=a.useCallback(()=>{xe(i=>{const r=!i;return r&&Mn.setEnabled(!0),r})},[]),ht=a.useCallback(()=>xe(!1),[]),be=a.useCallback(()=>{Q(i=>{const r=!i;return se(y.GIT_PANEL_OPEN,r),r})},[]),gt=a.useCallback(()=>{Ke(i=>{const r=!i;return se(y.BUILDINGS_PANEL_OPEN,r),r})},[]),Ze=a.useCallback(()=>{Q(!1),se(y.GIT_PANEL_OPEN,!1)},[]),xt=a.useCallback(()=>{Ke(!1),se(y.BUILDINGS_PANEL_OPEN,!1)},[]),$e=Tn();a.useEffect(()=>{if(!z)return;Ie.some(r=>r.id===z)||G(null)},[z,Ie]);const[_e,ue]=a.useState(!1),Be=a.useRef(null);if(a.useEffect(()=>{if(!_e)return;const i=r=>{Be.current&&!Be.current.contains(r.target)&&ue(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[_e]),!b)return e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-chat__placeholder",children:[e.jsx("span",{className:"flat-chat__placeholder-icon",children:"💬"}),e.jsx("span",{className:"flat-chat__placeholder-text",children:"Select an agent to start chatting"})]})});const ee=b.contextStats,Je=!!ee,Qe=ee?ee.totalTokens:b.contextUsed||0,we=ee?ee.contextWindow:b.contextLimit||2e5,h=ee?ee.usedPercent:Math.round(Qe/we*100),P=Math.max(0,Math.min(100,h)),X=Math.round(P*10)/10,Se=Math.round((100-P)*10)/10,Fe=P>=80?"#ff4a4a":P>=60?"#ff9e4a":P>=40?"#ffd700":"#4aff9e",et=(Qe/1e3).toFixed(1),tt=(we/1e3).toFixed(1),te=b.cwd,nt=te?qn(te):null,pe=((ne=b.subordinateIds)==null?void 0:ne.length)||0,ve=pe>0;return e.jsxs("div",{ref:Ae,className:`flat-terminal-wrapper ${O||ge||de?"flat-terminal-wrapper--with-side-panel":""}`,children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${W?"flat-terminal-wrapper__header-main--active":""}`,onClick:De,onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),J({x:i.clientX,y:i.clientY})},title:W?"Hide agent info":"Show agent info","aria-pressed":W,children:[e.jsx(Ht,{agent:b,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:b.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:Vt(b.status)},children:b.status})]}),b.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:b.taskLabel,children:["📋 ",b.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:b.provider==="codex"?"/assets/codex.png":b.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:b.provider,className:"flat-terminal-wrapper__header-provider-icon",title:b.provider==="codex"?"Codex Agent":b.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:i,effort:r}=Yn(b);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:r?`Model: ${i} · Effort: ${r}`:`Model: ${i}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:i}),r&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-sep","aria-hidden":"true",children:"·"}),e.jsx("span",{className:"flat-terminal-wrapper__header-model-effort",children:r})]})]})})()]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__header-meta",children:[e.jsx("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:Vn.map(i=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${v===i?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>I(i),title:Un[i],"aria-pressed":v===i,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:Gn[i]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:Xn[i]})]},i))}),e.jsxs("div",{className:"flat-terminal-wrapper__actions",role:"group","aria-label":"Terminal actions",children:[e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:Z,disabled:!Xe,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(u,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:le,disabled:!Ge,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(u,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${H?"flat-terminal-wrapper__action-btn--active":""}`,onClick:mt,title:H?"Close search":"Search messages","aria-pressed":H,children:e.jsx(u,{name:H?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${ce?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>Ye.handleClick($t,()=>{var i;x.clearContext(c),(i=me.current)==null||i.historyLoader.clearHistory()}),title:ce?"Click again to confirm clear context":"Clear context",children:e.jsx(u,{name:ce?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${O?"flat-terminal-wrapper__action-btn--active":""}`,onClick:be,title:O?"Hide git panel":"Show git changes","aria-pressed":O,children:e.jsx(u,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${ge?"flat-terminal-wrapper__action-btn--active":""}`,onClick:gt,title:ge?"Hide buildings panel":"Show area buildings","aria-pressed":ge,children:e.jsx(u,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:Be,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${_e?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>ue(i=>!i),title:"More actions","aria-expanded":_e,children:"⋮"}),_e&&e.jsxs("div",{className:"flat-terminal-wrapper__more-menu",role:"menu",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-terminal-wrapper__more-item ${de?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{ft(),ue(!1)},title:de?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(u,{name:"bug",size:14}),e.jsx("span",{children:de?"Hide Debug Panel":"Show Debug Panel"})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item",onClick:()=>{x.collapseContext(c),ue(!1)},disabled:b.status!=="idle",title:b.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(u,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),ve&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{K(c,pe),ue(!1)},children:[e.jsx(u,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",pe," subordinate",pe===1?"":"s"]})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{x.killAgent(c),ue(!1)},children:[e.jsx(u,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${E?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:Y,title:E?"Hide inspector panel":"Show inspector panel","aria-label":E?"Hide inspector panel":"Show inspector panel","aria-pressed":E,children:[e.jsx("span",{className:"flat-terminal-wrapper__inspector-icon","aria-hidden":"true",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"}),e.jsx("line",{x1:"10",y1:"2.5",x2:"10",y2:"13.5"})]})}),e.jsx("span",{className:"flat-terminal-wrapper__inspector-label",children:"Inspector"})]}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__close",onClick:()=>x.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(u,{name:"cross",size:14})})]})]}),e.jsx(Pn,{ref:me,agentId:c,agent:b,viewMode:v,isOpen:!0,onImageClick:F,onFileClick:Re,onBashClick:ie,onViewMarkdown:f,keyboard:Ve,hasModalOpen:!1}),V&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:Ee,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded terminal"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`Embedded terminal: ${V.name}`,style:{height:U},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(u,{name:"terminal",size:12}),e.jsx("span",{children:V.name}),!((at=V.terminalStatus)!=null&&at.url)&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>G(null),title:"Close embedded terminal","aria-label":"Close embedded terminal",children:e.jsx(u,{name:"cross",size:12})})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:($=V.terminalStatus)!=null&&$.url?e.jsx(Ln,{terminalUrl:V.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."})})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[b.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(u,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),te&&nt&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${te}`,"aria-label":`Open ${te} in file explorer`,role:"button",tabIndex:0,onClick:()=>x.openFileExplorer(te),onKeyDown:i=>{(i.key==="Enter"||i.key===" ")&&(i.preventDefault(),x.openFileExplorer(te))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(u,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:nt})]}),ze&&ze.map(({areaId:i,areaName:r,dir:d})=>{const o=Ue.get(d),Ce=Oe.has(d),Te=d.split("/").filter(Boolean).pop()||d;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${r}: ${d}${o?` (${o.branch}${o.ahead?` ↑${o.ahead}`:""}${o.behind?` ↓${o.behind}`:""})`:""}`,onClick:()=>x.openFileExplorerForAreaFolder(i,d),children:[e.jsx(u,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:Te}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(u,{name:"git-branch",size:10})," ",o.branch]}),o.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${o.ahead} ahead`,children:[e.jsx(u,{name:"arrow-up",size:9}),o.ahead]}),o.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${o.behind} behind`,children:[e.jsx(u,{name:"arrow-down",size:9}),o.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${Ce?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:Pe=>{Pe.stopPropagation(),qe(d)},children:e.jsx(u,{name:Ce?"hourglass":"download",size:12})})]})]},`${i}:${d}`)}),e.jsxs("span",{className:"flat-terminal-wrapper__context",onClick:()=>x.setContextModalAgentId(c),title:Je?`Context usage: ${et}k / ${tt}k tokens (${X}% used). Click to view stats.`:"Click to fetch context stats",children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(u,{name:"dashboard",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__context-label",children:"Ctx:"}),e.jsx("span",{className:"flat-terminal-wrapper__context-bar",children:e.jsx("span",{className:"flat-terminal-wrapper__context-bar-fill",style:{width:`${P}%`,backgroundColor:Fe}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:Fe},children:[et,"k/",tt,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",Se,"% free)"]}),!Je&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(u,{name:"warn",size:12})})]}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),Ie.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:Ie.map(i=>{const r=z===i.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""} ${i.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${r?"Hide":"Show"} terminal: ${i.name}${i.hasUrl?"":" (starting...)"}`,onClick:()=>{if(r){G(null);return}i.hasUrl||x.sendBuildingCommand(i.id,"start"),G(i.id)},children:e.jsx(u,{name:"terminal",size:14})},i.id)})}),he.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:he.map(i=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open logs: ${i.name}`,onClick:()=>ye(i.id),children:e.jsx(u,{name:"scroll",size:14})},i.id))}),re.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:re.map(i=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open database: ${i.name}`,onClick:()=>ye(i.id),children:e.jsx(u,{name:"hard-drives",size:14})},i.id))}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(Rn,{})})]}),O&&e.jsx(Dn,{agentId:c,agents:$e,onClose:Ze,branchInfoMap:Ue,fetchRemote:qe,fetchingDirs:Oe}),ge&&e.jsx(zn,{agentId:c,onClose:xt}),de&&e.jsx(On,{agentId:c,onClose:ht})]})});function ta({onAgentClick:w,onBuildingClick:c,onBuildingDoubleClick:v,onBuildingPopup:I,onAreaContextMenu:E,onOpenSpawnModal:Y,onOpenBossSpawnModal:F,onOpenAreaModal:Re}){const{t:ie}=Bt(["common"]),f=on(),K=cn(),[ye,Ve]=a.useState(null),[Xe,Ge]=a.useState(null),[Z,le]=a.useState(null),[W,De]=a.useState(null),[J,b]=a.useState(null),[T,me]=a.useState(null),[Ae,fe]=a.useState(!1),ze=a.useCallback(()=>{fe(t=>!t)},[]),Ue=a.useCallback(()=>{fe(!1)},[]),[qe,Oe]=a.useState(()=>{const t=Mt(y.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Ie=a.useCallback(t=>{Oe(t),Tt(y.VIEW_MODE,t)},[]);a.useEffect(()=>{const t=n=>{if(n.key!==y.VIEW_MODE)return;const s=n.newValue;(s==="simple"||s==="chat"||s==="advanced")&&Oe(s)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[he,re]=a.useState(()=>Nt(y.FLAT_INSPECTOR_OPEN,!1)),[oe,H]=a.useState(!1),mt=a.useCallback(()=>H(t=>!t),[]),Ye=a.useCallback(()=>H(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:oe}}))},[oe]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:he}}))},[he]),a.useEffect(()=>{const t=()=>H(_=>!_),n=()=>{re(_=>{const l=!_;return se(y.FLAT_INSPECTOR_OPEN,l),l})},s=()=>{H(!1),re(!1),se(y.FLAT_INSPECTOR_OPEN,!1)},p=()=>H(!1),m=()=>{re(!1),se(y.FLAT_INSPECTOR_OPEN,!1)};return window.addEventListener("tide-toggle-flat-agents-drawer",t),window.addEventListener("tide-toggle-flat-inspector",n),window.addEventListener("tide-close-flat-side-views",s),window.addEventListener("tide-close-flat-agents-drawer-only",p),window.addEventListener("tide-close-flat-inspector-only",m),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",n),window.removeEventListener("tide-close-flat-side-views",s),window.removeEventListener("tide-close-flat-agents-drawer-only",p),window.removeEventListener("tide-close-flat-inspector-only",m)}},[]);const ce=a.useRef(null),z=a.useRef(null),[G,V]=a.useState(()=>{const t=Pt(y.FLAT_MIDDLE_WIDTH,0);return t>=pt?t:null}),[U,Ee]=a.useState(()=>{const t=Pt(y.FLAT_INSPECTOR_WIDTH,0);return t>=jt?t:null}),O=a.useCallback(t=>{if(typeof window>"u")return t;const n=U!==null?ut+U:0,s=window.innerWidth-Ot-ut-zt-n;return Math.max(pt,Math.min(Math.max(s,pt),t))},[U]),Q=a.useCallback(t=>{var m;if(typeof window>"u")return t;const n=(m=ce.current)==null?void 0:m.querySelector(".flat-middle"),s=(n==null?void 0:n.getBoundingClientRect().width)??pt,p=window.innerWidth-Ot-s-ut-zt-ut;return Math.max(jt,Math.min(Math.max(p,jt),t))},[]);a.useEffect(()=>{if(G===null&&U===null)return;const t=()=>{V(n=>{if(n===null)return n;const s=O(n);return s===n?n:s}),Ee(n=>{if(n===null)return n;const s=Q(n);return s===n?n:s})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[G,U,O,Q]);const ge=a.useCallback(t=>{var s;if(t.button!==0)return;const n=(s=ce.current)==null?void 0:s.querySelector(".flat-middle");n&&(t.currentTarget.setPointerCapture(t.pointerId),z.current={kind:"middle",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),Ke=a.useCallback(t=>{var s;if(t.button!==0)return;const n=(s=ce.current)==null?void 0:s.querySelector(".flat-inspector");n&&(t.currentTarget.setPointerCapture(t.pointerId),z.current={kind:"inspector",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),de=a.useCallback(t=>{const n=z.current;if(!n||t.pointerId!==n.pointerId)return;const s=t.clientX-n.startX;n.kind==="middle"?V(O(n.startWidth+s)):Ee(Q(n.startWidth-s))},[O,Q]),xe=a.useCallback(t=>{const n=z.current;if(!n||t.pointerId!==n.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(z.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-n.startX)>2))return;const p=t.clientX-n.startX;if(n.kind==="middle"){const m=O(n.startWidth+p);V(m),dt(y.FLAT_MIDDLE_WIDTH,m)}else{const m=Q(n.startWidth-p);Ee(m),dt(y.FLAT_INSPECTOR_WIDTH,m)}},[O,Q]),ft=a.useCallback(()=>{V(null),dt(y.FLAT_MIDDLE_WIDTH,0)},[]),ht=a.useCallback(()=>{Ee(null),dt(y.FLAT_INSPECTOR_WIDTH,0)},[]),[be,gt]=a.useState(()=>Mt(y.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),Ze=a.useCallback(t=>{gt(t),Tt(y.FLAT_INSPECTOR_VIEW,t)},[]),xt=a.useCallback(()=>{re(t=>{const n=!t;return se(y.FLAT_INSPECTOR_OPEN,n),n})},[]),$e=a.useCallback(()=>{re(!1),se(y.FLAT_INSPECTOR_OPEN,!1)},[]),_e=dn(),ue=a.useCallback((t,n)=>{Ve({url:t,name:n})},[]),Be=a.useCallback((t,n)=>{Ge({command:t,output:n,isLive:!1})},[]),ee=a.useCallback((t,n)=>{x.setFileViewerPath(t,n)},[]),Je=a.useCallback(t=>{},[]),Qe=a.useCallback((t,n)=>{le({agentId:t,count:n})},[]),we=a.useCallback(t=>{v?v(t):c(t)},[c,v]),h=a.useMemo(()=>K.size>0?Array.from(K)[0]:null,[K]);a.useEffect(()=>{fe(!1)},[h]);const P=a.useRef([]),X=a.useRef(-1),Se=a.useRef(!1),Fe=a.useRef(null),[et,tt]=a.useState(!1),[te,nt]=a.useState(!1),pe=a.useRef(!1),ve=a.useRef(null),Me=a.useRef(!1),ne=a.useMemo(()=>new Set(f.map(t=>t.id)),[f]),at=a.useMemo(()=>{const t=new Map(f.map(s=>[s.id,s])),n=new Map;for(const s of f)if((s.isBoss||s.class==="boss")&&s.subordinateIds&&s.subordinateIds.length>0){const p=s.subordinateIds.map(m=>t.get(m)).filter(m=>m!==void 0);p.length>0&&n.set(s.id,p)}return n},[f]),$=a.useCallback(()=>{const t=P.current,n=X.current;tt(n>0),nt(n>=0&&n<t.length-1)},[]),i=a.useCallback(t=>{const n=P.current;if(n.length===0)return;let s=X.current+t;for(;s>=0&&s<n.length;){const p=n[s];if(ne.has(p)){Se.current=!0,X.current=s,$(),x.selectAgent(p);return}s+=t}},[ne,$]),r=a.useCallback(()=>i(-1),[i]),d=a.useCallback(()=>i(1),[i]);Wn(a.useCallback(()=>{const t=P.current,n=X.current;return t.length>0&&n>0?(i(-1),"handled"):"exit"},[i]));const o=a.useCallback((t,n)=>{if(typeof window>"u")return;const s=window.history.state,m={...typeof s=="object"&&s!==null?s:{},__flatAgentNav:{agentId:t}};n==="replace"?window.history.replaceState(m,"",window.location.href):window.history.pushState(m,"",window.location.href)},[]);a.useEffect(()=>{if(!h){pe.current=!1,ve.current=null;return}if(!pe.current){o(h,"replace"),pe.current=!0,ve.current=h;return}if(Me.current){Me.current=!1,ve.current=h;return}ve.current!==h&&(o(h,"push"),ve.current=h)},[h,o]),a.useEffect(()=>{const t=n=>{var _,l;const s=(l=(_=n.state)==null?void 0:_.__flatAgentNav)==null?void 0:l.agentId;if(!s||typeof s!="string"||!ne.has(s)||s===h)return;Me.current=!0,Se.current=!0;const p=P.current,m=p.lastIndexOf(s);m>=0?X.current=m:(p.push(s),X.current=p.length-1),$(),x.selectAgent(s)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[ne,h,$]),a.useEffect(()=>{if(!h){P.current=[],X.current=-1,$();return}if(Fe.current=h,Se.current){Se.current=!1,$();return}const t=P.current,n=X.current;if(n>=0&&t[n]===h){$();return}const s=n<t.length-1?t.slice(0,n+1):t.slice();s.push(h),s.length>100&&s.shift(),P.current=s,X.current=s.length-1,$()},[h,$]);const Ce=a.useCallback(t=>{w(t),H(!1)},[w]),Te=h??"",Pe=a.useCallback(()=>{},[]),bt=a.useCallback(t=>{Ce(t)},[Ce]),q=he,[Le,D]=a.useState(q),[M,We]=a.useState(q);a.useEffect(()=>{if(q){D(!0);return}We(!1);const t=setTimeout(()=>D(!1),240);return()=>clearTimeout(t)},[q]),a.useEffect(()=>{if(!Le||!q)return;let t=0;const n=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>We(!0))});return()=>{cancelAnimationFrame(n),cancelAnimationFrame(t)}},[Le,q]);const kt=a.useRef(null);a.useEffect(()=>{if(h)return;const t=n=>{if(n.key!==" "&&n.key!=="Backspace")return;const s=n.target;if(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable)return;const p=Fe.current;!p||!ne.has(p)||(n.preventDefault(),x.selectAgent(p))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[h,ne]);const[Xt,yt]=a.useState(new Set),Gt=a.useCallback(t=>{yt(n=>{const s=new Set(n);return s.has(t)?s.delete(t):s.add(t),s})},[]),[je,Ut]=a.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches);a.useEffect(()=>{if(typeof window>"u")return;const t=window.matchMedia("(max-width: 768px)"),n=s=>Ut(s.matches);return t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[]);const[st,qt]=a.useState(null),Yt=a.useCallback(t=>{qt(n=>n===t?null:t)},[]),_t=Ft(),it=Wt(),[Kt]=un(),Ne=a.useMemo(()=>{const t=new Map,n=[];for(const g of f){const k=x.getAreaForAgent(g.id);if(!Lt((k==null?void 0:k.id)??null))continue;if(!k||k.archived){n.push(g);continue}const j=t.get(k.id);j?j.push(g):t.set(k.id,[g])}const s=new Map,p=[];for(const g of it.values()){let k=!1;for(const j of _t.values())if(!j.archived&&Rt(j.id)&&x.isPositionInArea(g.position,j)){const ae=s.get(j.id);ae?ae.push(g):s.set(j.id,[g]),k=!0;break}!k&&Lt(null)&&p.push(g)}const m=[];for(const[,g]of _t){if(g.archived||!Rt(g.id))continue;const k=t.get(g.id),j=s.get(g.id)??[];(k&&k.length>0||j.length>0)&&m.push({area:g,agents:k??[],buildings:j})}(n.length>0||p.length>0)&&m.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:n,buildings:p});const _=m.filter(g=>g.area.id!=="__unassigned__"),l=m.filter(g=>g.area.id==="__unassigned__");let A=1,N=1;const B=new Map;if(_.length>1){let g=1/0,k=-1/0,j=1/0,ae=-1/0;for(const L of _)g=Math.min(g,L.area.center.x),k=Math.max(k,L.area.center.x),j=Math.min(j,L.area.center.z),ae=Math.max(ae,L.area.center.z);const rt=k-g||1,ot=ae-j||1;if(_.length<=4){A=_.length,N=1;const L=[..._].sort((R,wt)=>R.area.center.x-wt.area.center.x);for(let R=0;R<L.length;R++)B.set(L[R].area.id,{row:1,col:R+1})}else{const L=[..._].sort((C,S)=>C.area.center.x-S.area.center.x),R=[];for(let C=1;C<L.length;C++)R.push(L[C].area.center.x-L[C-1].area.center.x);const wt=R.reduce((C,S)=>C+S,0)/R.length||1;let At=1;for(const C of R)C>wt*1.3&&At++;A=Math.max(2,Math.min(At,_.length));const vt=[..._].sort((C,S)=>C.area.center.z-S.area.center.z),ct=[];for(let C=1;C<vt.length;C++)ct.push(vt[C].area.center.z-vt[C-1].area.center.z);const en=ct.reduce((C,S)=>C+S,0)/ct.length||1;let It=1;for(const C of ct)C>en*1.3&&It++;N=Math.max(2,Math.min(It,_.length)),A=Math.max(A,Math.ceil(_.length/N)),N=Math.max(N,Math.ceil(_.length/A));const tn=rt/A,nn=ot/N,Ct=new Set;for(const C of _){let S=Math.min(A-1,Math.max(0,Math.floor((C.area.center.x-g)/tn))),ke=Math.min(N-1,Math.max(0,Math.floor((C.area.center.z-j)/nn))),He=`${ke},${S}`,Et=0;const an=N*A;for(;Ct.has(He)&&Et<an;)S++,S>=A&&(S=0,ke=(ke+1)%N),He=`${ke},${S}`,Et++;Ct.has(He)&&(ke=N,S=0,He=`${ke},${S}`,N++),Ct.add(He),B.set(C.area.id,{row:ke+1,col:S+1})}}}const lt=g=>{g.sort((k,j)=>{var rt,ot,L,R;const ae=(((rt=k.position)==null?void 0:rt.z)??0)-(((ot=j.position)==null?void 0:ot.z)??0);return ae!==0?ae:(((L=k.position)==null?void 0:L.x)??0)-(((R=j.position)==null?void 0:R.x)??0)})};for(const g of _)lt(g.agents);for(const g of l)lt(g.agents);return{groups:[..._,...l],gridCols:A,gridRows:N,positions:B}},[f,_t,it,Kt]),Zt=a.useMemo(()=>{if(!W)return[];const t=f.find(n=>n.id===W.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(u,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:open-agent-edit",{detail:{agentId:t.id}}))}},{id:"open-chat",label:"Open Chat",icon:e.jsx(u,{name:"chat",size:14}),onClick:()=>w(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(u,{name:"trash",size:14}),danger:!0,onClick:()=>{me({agentId:t.id,name:t.name})}}]:[]},[W,f,w]),Jt=a.useMemo(()=>{var _;if(!J)return[];const t=it.get(J.buildingId);if(!t)return[];const n=[],s=t.type==="server"||t.type==="docker"||t.type==="terminal",p=t.status==="running",m=t.type==="boss";if(n.push({id:"open",label:t.type==="database"?"Open Database":t.type==="folder"?"Open Folder":t.type==="boss"?"View Boss Logs":t.type==="terminal"?"Open Terminal":t.type==="server"&&((_=t.pm2)!=null&&_.enabled)?"View PM2 Logs":"Open",icon:e.jsx(u,{name:t.type==="database"?"database":t.type==="folder"?"folder":t.type==="terminal"?"terminal":"eye",size:14}),onClick:()=>we(t.id)}),s&&(p||n.push({id:"start",label:"Start",icon:e.jsx(u,{name:"play",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"start")}),p&&(n.push({id:"restart",label:"Restart",icon:e.jsx(u,{name:"refresh",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"restart")}),n.push({id:"stop",label:"Stop",icon:e.jsx(u,{name:"stop",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"stop")}))),m&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(n.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(u,{name:"launch",size:14}),onClick:()=>{for(const l of t.subordinateBuildingIds)x.sendBuildingCommand(l,"start")}}),n.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(u,{name:"pause",size:14}),onClick:()=>{for(const l of t.subordinateBuildingIds)x.sendBuildingCommand(l,"stop")}}),n.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(u,{name:"restart",size:14}),onClick:()=>{for(const l of t.subordinateBuildingIds)x.sendBuildingCommand(l,"restart")}})),s&&n.push({id:"health-check",label:"Health Check",icon:e.jsx(u,{name:"health",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"healthCheck")}),n.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),n.push({id:"edit",label:"Edit Building",icon:e.jsx(u,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:building-edit",{detail:{buildingId:t.id}}))}}),n.push({id:"clone",label:"Clone Building",icon:e.jsx(u,{name:"copy",size:14}),onClick:()=>{x.createBuilding({name:`${t.name} (Copy)`,type:t.type,style:t.style,color:t.color,scale:t.scale,position:{x:t.position.x+2,z:t.position.z+2},cwd:t.cwd,folderPath:t.folderPath,commands:t.commands,pm2:t.pm2,docker:t.docker,database:t.database,terminal:t.terminal,urls:t.urls,subordinateBuildingIds:t.subordinateBuildingIds})}}),t.urls&&t.urls.length>0)for(const l of t.urls)n.push({id:`url-${l.label}`,label:l.label,icon:e.jsx(u,{name:"link",size:14}),onClick:()=>window.open(l.url,"_blank","noopener,noreferrer")});return n.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),n.push({id:"delete",label:"Delete Building",icon:e.jsx(u,{name:"trash",size:14}),danger:!0,onClick:()=>x.deleteBuilding(t.id)}),n},[J,it,we]),Qt=a.useCallback(t=>{const n=new Set(Ne.groups.map(s=>s.area.id));n.delete(t),yt(n),requestAnimationFrame(()=>{const s=kt.current;if(!s)return;const p=s.querySelector(`[data-area-id="${t}"]`);if(!p)return;const m=s.getBoundingClientRect(),l=p.getBoundingClientRect().top-m.top+s.scrollTop-8;s.scrollTo({top:Math.max(0,l),behavior:"smooth"})})},[Ne]);return e.jsxs("div",{ref:ce,className:`flat-view ${q?"flat-view--with-inspector":""} ${h?"flat-view--has-chat":""} ${oe?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(G===null&&U===null)return;const t={};return G!==null&&(t["--flat-middle-width"]=`${G}px`),U!==null&&(t["--flat-inspector-width"]=`${U}px`),t})(),children:[oe&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:Ye,"aria-hidden":"true"}),e.jsxs("div",{className:"flat-middle",children:[e.jsx("div",{className:"flat-middle__header",children:e.jsxs("div",{className:"flat-middle__actions",children:[e.jsx("button",{className:"flat-cta-btn flat-cta-btn--agent",onClick:Y,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:F,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:Re,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(pn,{activeAgentId:Te,onClose:Pe,onSelectAgent:bt,collapsedAreas:Xt,onToggleArea:Gt,agentListRef:kt})})]}),e.jsx("div",{className:"flat-splitter flat-splitter--middle",role:"separator","aria-orientation":"vertical","aria-label":"Resize agents panel",title:"Drag to resize · Double-click to reset",onPointerDown:ge,onPointerMove:de,onPointerUp:xe,onPointerCancel:xe,onDoubleClick:ft}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":oe?"Close agents sidebar":"Open agents sidebar","aria-expanded":oe,onClick:mt,children:[e.jsx(u,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),h?e.jsx(Zn,{agentId:h,terminalViewMode:qe,onTerminalViewModeChange:Ie,inspectorOpen:he,onToggleInspector:xt,onImageClick:ue,onFileClick:ee,onBashClick:Be,onViewMarkdown:Je,onRequestClearSubordinates:Qe,onOpenBuilding:we,keyboard:_e,canNavigateBack:et,canNavigateForward:te,onNavigateBack:r,onNavigateForward:d,agentInfoOpen:Ae,onToggleAgentInfo:ze,onHeaderContextMenu:t=>{h&&De({agentId:h,position:t})}}):e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-map",children:[e.jsxs("div",{className:"flat-map__header",children:[e.jsx("span",{className:"flat-map__title",children:"🗺️ Areas"}),e.jsx("span",{className:"flat-map__hint",children:"Click an area to focus it, or an agent to chat"}),e.jsx(Hn,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${Ne.gridCols}, 1fr)`},children:Ne.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(()=>{var n;const t=je&&st?((n=Ne.positions.get(st))==null?void 0:n.row)??null:null;return Ne.groups.map(s=>{const p=s.area.id,m=Ne.positions.get(p),_=je&&st!==p;return je&&t!=null&&(m==null?void 0:m.row)===t&&p!==st?null:e.jsxs("div",{className:`flat-map-area-card${_?" flat-map-area-card--collapsed":""}`,style:{"--area-color":s.area.color,gridRow:m==null?void 0:m.row,gridColumn:m==null?void 0:m.col},onContextMenu:l=>{E&&(l.preventDefault(),l.stopPropagation(),E(p,{x:l.clientX,y:l.clientY}))},children:[e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>je?Yt(p):Qt(p),title:je?_?`Expand ${s.area.name}`:`Collapse ${s.area.name}`:`Focus ${s.area.name} in left panel`,"aria-expanded":je?!_:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:s.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:s.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:s.agents.length}),je&&e.jsx(u,{name:_?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:s.agents.map(l=>{const A=l.isBoss||l.class==="boss",N=A?at.get(l.id):void 0,B=mn(l),lt=B.usedPercent>=80?"#ff4a4a":B.usedPercent>=60?"#ff9e4a":B.usedPercent>=40?"#ffd700":"#4aff9e",g=`Context: ${(B.totalTokens/1e3).toFixed(1)}k / ${(B.contextWindow/1e3).toFixed(1)}k (${B.usedPercent}% used, ${B.freePercent}% free)`,k=l.latestTodos&&l.latestTodos.length>0||N&&N.length>0;return e.jsx(fn,{todos:l.latestTodos,subordinates:N,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${l.status}`,onClick:()=>w(l.id),onContextMenu:j=>{j.preventDefault(),j.stopPropagation(),De({agentId:l.id,position:{x:j.clientX,y:j.clientY}})},title:k?void 0:`${A?"Boss · ":""}Open chat with ${l.name}
2
2
  ${g}`,children:[e.jsx(Ht,{agent:l,size:16}),A&&e.jsx("span",{className:"flat-map-agent-chip__crown","aria-hidden":"true",children:e.jsx(u,{name:"crown",size:11,color:"#ffd700",weight:"fill"})}),e.jsx("span",{className:"flat-map-agent-chip__name",children:l.name}),e.jsx("img",{src:l.provider==="codex"?"/assets/codex.png":l.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:l.provider,className:"flat-map-agent-chip__provider-icon",title:l.provider==="codex"?"Codex Agent":l.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),e.jsx("span",{className:"flat-map-agent-chip__dot",style:{backgroundColor:Vt(l.status)}}),l.latestTodos&&l.latestTodos.length>0&&e.jsx(hn,{todos:l.latestTodos,maxDots:6}),A&&N&&N.length>0&&e.jsx(gn,{subordinates:N,maxDots:6}),e.jsx("span",{className:"flat-map-agent-chip__context-bar","aria-hidden":"true",children:e.jsx("span",{className:"flat-map-agent-chip__context-bar-fill",style:{width:`${B.usedPercent}%`,backgroundColor:lt}})})]})},l.id)})}),s.buildings.length>0&&e.jsx("div",{className:"flat-map-area-card__buildings",children:s.buildings.map(l=>e.jsxs("button",{type:"button",className:`flat-map-building-chip flat-map-building-chip--${l.status}`,onClick:A=>{if(I){const N=A.currentTarget.getBoundingClientRect();I(l.id,{x:N.right,y:N.top+N.height/2})}else we(l.id)},onContextMenu:A=>{A.preventDefault(),A.stopPropagation(),b({buildingId:l.id,position:{x:A.clientX,y:A.clientY}})},title:`${l.name} · ${l.type} · ${l.status}`,children:[e.jsx(u,{name:xn(l.type),size:12}),e.jsx("span",{className:"flat-map-building-chip__name",children:l.name}),e.jsx("span",{className:"flat-map-building-chip__dot",style:{backgroundColor:bn(l.status)}})]},l.id))})]},p)})})()})]})})]}),q&&e.jsx("div",{className:"flat-splitter flat-splitter--inspector",role:"separator","aria-orientation":"vertical","aria-label":"Resize inspector panel",title:"Drag to resize · Double-click to reset",onPointerDown:Ke,onPointerMove:de,onPointerUp:xe,onPointerCancel:xe,onDoubleClick:ht}),Le&&e.jsxs("aside",{className:`flat-inspector ${M?"flat-inspector--open":"flat-inspector--closing"}`,"aria-label":"Inspector panel",children:[e.jsxs("div",{className:"flat-inspector__header",children:[e.jsxs("div",{className:"flat-inspector__tabs",role:"tablist","aria-label":"Inspector view",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":be==="agent",className:`flat-inspector__tab ${be==="agent"?"flat-inspector__tab--active":""}`,onClick:()=>Ze("agent"),children:"Agent"}),e.jsx("button",{type:"button",role:"tab","aria-selected":be==="tracking",className:`flat-inspector__tab ${be==="tracking"?"flat-inspector__tab--active":""}`,onClick:()=>Ze("tracking"),children:"Tracking"})]}),e.jsx("button",{type:"button",className:"flat-inspector__close",onClick:$e,title:"Close inspector","aria-label":"Close inspector",children:"✕"})]}),e.jsx("div",{className:"flat-inspector__body",children:be==="tracking"?e.jsx(_n,{activeAgentId:h??"",onSelectAgent:t=>{w(t),window.innerWidth<=768&&$e()}}):(()=>{if(!h)return e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Select an agent to inspect"})});const t=f.find(n=>n.id===h);return t?e.jsx(wn,{agent:t,onFocusAgent:n=>{w(n),window.innerWidth<=768&&$e()},onKillAgent:n=>x.killAgent(n)}):e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Agent not found"})})})()})]}),ye&&e.jsx(vn,{url:ye.url,name:ye.name,onClose:()=>Ve(null)}),Xe&&e.jsx(Cn,{state:Xe,onClose:()=>Ge(null)}),Z&&e.jsx(jn,{action:"clear-subordinates",selectedAgentId:Z.agentId,subordinateCount:Z.count,onClose:()=>le(null),onClearHistory:()=>{}}),e.jsx(Nn,{agent:h?f.find(t=>t.id===h)??null:null,isOpen:Ae&&!!h,onClose:Ue}),e.jsx(Dt,{isOpen:W!==null,position:(W==null?void 0:W.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:Zt,onClose:()=>De(null)}),e.jsx(Dt,{isOpen:J!==null,position:(J==null?void 0:J.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:Jt,onClose:()=>b(null)}),e.jsx(kn,{isOpen:T!==null,title:ie("common:confirm.removeAgentTitle"),message:ie("common:confirm.removeAgentMessage",{name:(T==null?void 0:T.name)??""}),confirmLabel:ie("common:buttons.remove"),cancelLabel:ie("common:buttons.cancel"),variant:"danger",onConfirm:()=>{T&&x.removeAgentFromServer(T.agentId)},onClose:()=>me(null)})]})}export{ta as FlatView};