tide-commander 1.91.0 → 1.92.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{BossLogsModal-XsTxfWM8.js → BossLogsModal-BTTK3SDM.js} +1 -1
- package/dist/assets/{BossSpawnModal-DqQMPxHu.js → BossSpawnModal-BNbFVewB.js} +1 -1
- package/dist/assets/{ControlsModal-5mzDDdS5.js → ControlsModal-DnKdyYiv.js} +1 -1
- package/dist/assets/{DockerLogsModal-2eHlxyKa.js → DockerLogsModal-BRFhRQka.js} +1 -1
- package/dist/assets/{EmbeddedEditor-Bi9Ysd99.js → EmbeddedEditor-BFnSppyy.js} +1 -1
- package/dist/assets/{GmailOAuthSetup-5u85N8Br.js → GmailOAuthSetup-9uMrVRsz.js} +1 -1
- package/dist/assets/{GoogleOAuthSetup-OxT_QwZL.js → GoogleOAuthSetup-CLAy54pj.js} +1 -1
- package/dist/assets/{IframeModal-Bn1kdP1S.js → IframeModal-Cy5KHwqs.js} +1 -1
- package/dist/assets/{IntegrationsPanel-BehHkKJu.js → IntegrationsPanel-C_a9pmU1.js} +2 -2
- package/dist/assets/{LogViewerModal-JuUpWFPL.js → LogViewerModal-D68ppO94.js} +1 -1
- package/dist/assets/{MonitoringModal-CLk3uqDa.js → MonitoringModal-CoZ0uDPq.js} +1 -1
- package/dist/assets/{PM2LogsModal-C_NpOsos.js → PM2LogsModal-Bbwdouj-.js} +1 -1
- package/dist/assets/{RestoreArchivedAreaModal-Cbcg2Fm8.js → RestoreArchivedAreaModal-Dqi_ofXl.js} +1 -1
- package/dist/assets/{Scene2DCanvas-4C-jHERv.js → Scene2DCanvas-CnqwS4QZ.js} +1 -1
- package/dist/assets/{SceneManager-BoRV8xt3.js → SceneManager-W7pJrfEW.js} +1 -1
- package/dist/assets/{SkillsPanel-Bwk3UEY_.js → SkillsPanel-Cw-tVu6j.js} +1 -1
- package/dist/assets/{SlackMultiInstanceSetup-t-g3hdbr.js → SlackMultiInstanceSetup-DddkR8Zr.js} +1 -1
- package/dist/assets/{SpawnModal-BOXkPtaJ.js → SpawnModal-DZODgZFD.js} +1 -1
- package/dist/assets/{SubordinateAssignmentModal-CLHq5a9b.js → SubordinateAssignmentModal-BkhktU8i.js} +1 -1
- package/dist/assets/TriggerManagerPanel-YcbVJ2Rc.js +9 -0
- package/dist/assets/{WorkflowEditorPanel-Bevs1fpc.js → WorkflowEditorPanel-ZadWONKw.js} +1 -1
- package/dist/assets/{index-CiXA-Zp-.js → index-Bi8u2UlO.js} +1 -1
- package/dist/assets/{index-DxHwQ6CI.js → index-CF1hOKKa.js} +3 -3
- package/dist/assets/{index-CdKOXIM2.js → index-CN-XkbYd.js} +1 -1
- package/dist/assets/{index-CJuTMFz9.js → index-Ckn27_lZ.js} +1 -1
- package/dist/assets/{index-DBt10C9K.js → index-CtEyTmv-.js} +1 -1
- package/dist/assets/{index-H8kj1tuO.js → index-CyPV_nq1.js} +1 -1
- package/dist/assets/{index-Dd063aRs.js → index-DRsSsabz.js} +1 -1
- package/dist/assets/{index-B4JdUiAe.js → index-cK048gKM.js} +2 -2
- package/dist/assets/{index-vFrHpR5s.js → index-pqOlU6XT.js} +1 -1
- package/dist/assets/{main-5eyR3isL.js → main-jN7LzP4f.js} +95 -96
- package/dist/assets/{web-Cx_ySRHK.js → web-CfwxlY8x.js} +1 -1
- package/dist/assets/{web-DMjkVCWy.js → web-DZfyqisM.js} +1 -1
- package/dist/assets/{web-DGO1VHbi.js → web-DbhP1mtF.js} +1 -1
- package/dist/index.html +1 -1
- package/dist/src/packages/server/index.js +4 -0
- package/dist/src/packages/server/integrations/slack/slack-instance.js +89 -0
- package/dist/src/packages/server/integrations/slack/slack-polling-client.js +150 -42
- package/dist/src/packages/server/integrations/slack/slack-skill.js +16 -0
- package/dist/src/packages/server/integrations/slack/slack-trigger-handler.js +19 -0
- package/dist/src/packages/server/integrations/whatsapp/whatsapp-skill.js +12 -0
- package/dist/src/packages/server/integrations/whatsapp/whatsapp-trigger-handler.js +226 -16
- package/dist/src/packages/server/routes/files.js +4 -2
- package/dist/src/packages/server/services/attachment-downloader.js +317 -0
- package/dist/src/packages/server/services/attachment-janitor.js +110 -0
- package/package.json +1 -1
- package/dist/assets/TriggerManagerPanel-DuWagsLi.js +0 -3
|
@@ -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-
|
|
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-jN7LzP4f.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
|
|
package/dist/assets/{SlackMultiInstanceSetup-t-g3hdbr.js → SlackMultiInstanceSetup-DddkR8Zr.js}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as u,j as e,aJ as b,l as m}from"./main-5eyR3isL.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const C=["public_channel","private_channel","im","mpim"],O={public_channel:"Public channels",private_channel:"Private channels",im:"1:1 DMs",mpim:"Group DMs"};function M(l){const i=new Set;for(const s of(l||"").split(",")){const f=s.trim();C.includes(f)&&i.add(f)}return i}function N(l){return C.filter(i=>l.has(i)).join(",")}const t={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:l=>({padding:"8px 10px",borderRadius:6,cursor:"pointer",background:l?"rgba(137,180,250,0.15)":"transparent",border:l?"1px solid rgba(137,180,250,0.3)":"1px solid transparent",color:l?"#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:l=>{const s={socket:"#a6e3a1",polling:"#89b4fa",none:"#6c7086"}[l]??"#6c7086";return{display:"inline-block",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:500,background:`${s}26`,color:s,border:`1px solid ${s}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:l=>({padding:"8px 12px",borderRadius:6,fontSize:12,background:l==="error"?"rgba(243,139,168,0.15)":"rgba(166,227,161,0.15)",color:l==="error"?"#f38ba8":"#a6e3a1",border:`1px solid ${l==="error"?"rgba(243,139,168,0.3)":"rgba(166,227,161,0.3)"}`})},j="/api/slack/instances";async function R(){const l=await b(m(j));if(!l.ok)throw new Error(`HTTP ${l.status}`);return(await l.json()).instances}async function B(l){const i=await b(m(`${j}/${encodeURIComponent(l)}/values`));if(!i.ok)throw new Error(`HTTP ${i.status}`);return(await i.json()).values}async function K(l,i){const s=await b(m(j),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:l,label:i})});if(!s.ok){const f=await s.json().catch(()=>({}));throw new Error(f.error||`HTTP ${s.status}`)}}async function H(l,i){const s=await b(m(`${j}/${encodeURIComponent(l)}`),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!s.ok){const f=await s.json().catch(()=>({}));throw new Error(f.error||`HTTP ${s.status}`)}}async function W(l){const i=await b(m(`${j}/${encodeURIComponent(l)}`),{method:"DELETE"});if(!i.ok){const s=await i.json().catch(()=>({}));throw new Error(s.error||`HTTP ${i.status}`)}}const V=({integration:l,onCancel:i})=>{const[s,f]=u.useState([]),[o,v]=u.useState("default"),[a,S]=u.useState(null),[T,P]=u.useState(null),[g,D]=u.useState(""),[I,A]=u.useState(!1),[L,E]=u.useState(!1),[w,x]=u.useState(null),y=u.useCallback(async()=>{try{const n=await R();f(n),!n.some(c=>c.id===o)&&n.length>0&&v(n[0].id)}catch(n){x({kind:"error",message:`Failed to load instances: ${n.message}`})}},[o]),k=u.useCallback(async()=>{if(o){A(!0);try{const n=await B(o);S(n),P(n);const r=s.find(c=>c.id===o);D((r==null?void 0:r.label)??o)}catch(n){x({kind:"error",message:`Failed to load instance: ${n.message}`})}finally{A(!1)}}},[o,s]);u.useEffect(()=>{y()},[y]),u.useEffect(()=>{k()},[k]);const _=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(c){x({kind:"error",message:c.message})}},z=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})}},$=async()=>{if(!(!a||!T)){E(!0);try{const n={};Object.keys(a).forEach(p=>{const h=a[p];if(h!==T[p]){if((p==="SLACK_BOT_TOKEN"||p==="SLACK_APP_TOKEN")&&h==="********")return;n[p]=h}});const r=s.find(p=>p.id===o),c=r&&g.trim()&&g.trim()!==r.label;await H(o,{label:c?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)}}},d=(n,r)=>{a&&S({...a,[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:{...t.alert(w.kind),marginBottom:12},children:w.message}),e.jsxs("div",{style:t.container,children:[e.jsxs("div",{style:t.list,children:[s.map(n=>{var c,p,h;const r=((c=n.config)==null?void 0:c.currentMode)??"none";return e.jsxs("div",{style:t.listItem(n.id===o),onClick:()=>v(n.id),children:[e.jsx("div",{style:t.label,children:n.label}),e.jsxs("div",{style:t.sub,children:[e.jsx("span",{style:t.badge(r),children:r==="none"?"—":r}),(p=n.status)!=null&&p.connected?" • connected":(h=n.status)!=null&&h.error?" • error":" • idle"]})]},n.id)}),e.jsx("button",{type:"button",style:t.addBtn,onClick:_,children:"+ Add Instance"})]}),e.jsxs("div",{style:t.editor,children:[I&&e.jsx("div",{style:{color:"#6c7086",fontSize:13},children:"Loading…"}),!I&&a&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:t.field,children:[e.jsx("span",{style:t.fieldLabel,children:"Display label"}),e.jsx("input",{type:"text",style:t.input,value:g,onChange:n=>D(n.target.value),disabled:!1}),e.jsxs("span",{style:t.fieldDesc,children:["Shown in the instance list. Id is fixed: ",e.jsx("code",{children:o})]})]}),e.jsxs("div",{style:t.field,children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:a.enabled,onChange:n=>d("enabled",n.target.checked)}),e.jsx("span",{style:t.fieldLabel,children:"Enabled"})]}),e.jsx("span",{style:t.fieldDesc,children:"Toggle off to disconnect this instance without deleting its config."})]}),e.jsxs("div",{style:t.field,children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:a.mirrorOwnMessages,onChange:n=>d("mirrorOwnMessages",n.target.checked)}),e.jsx("span",{style:t.fieldLabel,children:"Mirror messages I send too"})]}),e.jsxs("span",{style:t.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:t.field,children:[e.jsx("span",{style:t.fieldLabel,children:"Slack Token"}),e.jsx("input",{type:"password",style:t.input,placeholder:"xoxb-... or xoxp-...",value:a.SLACK_BOT_TOKEN,onChange:n=>d("SLACK_BOT_TOKEN",n.target.value)}),e.jsxs("span",{style:t.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:t.field,children:[e.jsx("span",{style:t.fieldLabel,children:"App Token (Socket Mode only)"}),e.jsx("input",{type:"password",style:t.input,placeholder:"xapp-...",value:a.SLACK_APP_TOKEN,onChange:n=>d("SLACK_APP_TOKEN",n.target.value)}),e.jsx("span",{style:t.fieldDesc,children:"Required for xoxb- only. Leave blank for xoxp- (polling mode)."})]}),e.jsxs("div",{style:t.rowGap,children:[e.jsxs("div",{style:{...t.field,flex:1},children:[e.jsx("span",{style:t.fieldLabel,children:"Inbound Mode"}),e.jsxs("select",{style:t.input,value:a.authMode,onChange:n=>d("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:{...t.field,flex:1},children:[e.jsx("span",{style:t.fieldLabel,children:"Default Channel"}),e.jsx("input",{type:"text",style:t.input,placeholder:"C0123456789",value:a.defaultChannelId,onChange:n=>d("defaultChannelId",n.target.value)})]})]}),e.jsxs("div",{style:t.rowGap,children:[e.jsxs("div",{style:{...t.field,flex:1},children:[e.jsx("span",{style:t.fieldLabel,children:"Polling Interval (s)"}),e.jsx("input",{type:"number",style:t.input,min:10,max:600,value:a.pollingIntervalSec,onChange:n=>d("pollingIntervalSec",Number(n.target.value))})]}),e.jsxs("div",{style:{...t.field,flex:1},children:[e.jsx("span",{style:t.fieldLabel,children:"Concurrency"}),e.jsx("input",{type:"number",style:t.input,min:1,max:8,value:a.pollingConcurrency,onChange:n=>d("pollingConcurrency",Number(n.target.value))})]}),e.jsxs("div",{style:{...t.field,flex:1},children:[e.jsx("span",{style:t.fieldLabel,children:"Backfill Cap (msgs)"}),e.jsx("input",{type:"number",style:t.input,min:1,max:1e3,value:a.pollingBackfillMessageCap,onChange:n=>d("pollingBackfillMessageCap",Number(n.target.value))})]}),e.jsxs("div",{style:{...t.field,flex:1},children:[e.jsx("span",{style:t.fieldLabel,children:"Min ms between calls"}),e.jsx("input",{type:"number",style:t.input,min:0,max:1e4,value:a.pollingMinMsBetweenCalls,onChange:n=>d("pollingMinMsBetweenCalls",Number(n.target.value))}),e.jsx("span",{style:{...t.fieldDesc,fontSize:11},children:"Throttle. 1500 ≈ 40 req/min. Set 0 to disable."})]})]}),e.jsxs("div",{style:t.field,children:[e.jsx("span",{style:t.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 c=M(a.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:c,onChange:p=>{const h=new Set(M(a.pollingChannelTypes));p.target.checked?h.add(n):h.delete(n),d("pollingChannelTypes",N(h))}}),e.jsx("span",{children:O[n]})]},n)})}),e.jsx("span",{style:t.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:t.field,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("span",{style:t.fieldLabel,children:"Channel Allowlist (optional)"}),a.pollingChannelAllowlist&&e.jsx("button",{type:"button",style:{...t.btnSecondary,padding:"4px 10px",fontSize:12},onClick:()=>d("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:{...t.input,minHeight:60,fontFamily:"monospace",fontSize:12},placeholder:`C0123456789, G0987654321
|
|
1
|
+
import{r as u,j as e,aJ as b,l as m}from"./main-jN7LzP4f.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const C=["public_channel","private_channel","im","mpim"],O={public_channel:"Public channels",private_channel:"Private channels",im:"1:1 DMs",mpim:"Group DMs"};function M(l){const i=new Set;for(const s of(l||"").split(",")){const f=s.trim();C.includes(f)&&i.add(f)}return i}function N(l){return C.filter(i=>l.has(i)).join(",")}const t={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:l=>({padding:"8px 10px",borderRadius:6,cursor:"pointer",background:l?"rgba(137,180,250,0.15)":"transparent",border:l?"1px solid rgba(137,180,250,0.3)":"1px solid transparent",color:l?"#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:l=>{const s={socket:"#a6e3a1",polling:"#89b4fa",none:"#6c7086"}[l]??"#6c7086";return{display:"inline-block",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:500,background:`${s}26`,color:s,border:`1px solid ${s}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:l=>({padding:"8px 12px",borderRadius:6,fontSize:12,background:l==="error"?"rgba(243,139,168,0.15)":"rgba(166,227,161,0.15)",color:l==="error"?"#f38ba8":"#a6e3a1",border:`1px solid ${l==="error"?"rgba(243,139,168,0.3)":"rgba(166,227,161,0.3)"}`})},j="/api/slack/instances";async function R(){const l=await b(m(j));if(!l.ok)throw new Error(`HTTP ${l.status}`);return(await l.json()).instances}async function B(l){const i=await b(m(`${j}/${encodeURIComponent(l)}/values`));if(!i.ok)throw new Error(`HTTP ${i.status}`);return(await i.json()).values}async function K(l,i){const s=await b(m(j),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:l,label:i})});if(!s.ok){const f=await s.json().catch(()=>({}));throw new Error(f.error||`HTTP ${s.status}`)}}async function H(l,i){const s=await b(m(`${j}/${encodeURIComponent(l)}`),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!s.ok){const f=await s.json().catch(()=>({}));throw new Error(f.error||`HTTP ${s.status}`)}}async function W(l){const i=await b(m(`${j}/${encodeURIComponent(l)}`),{method:"DELETE"});if(!i.ok){const s=await i.json().catch(()=>({}));throw new Error(s.error||`HTTP ${i.status}`)}}const V=({integration:l,onCancel:i})=>{const[s,f]=u.useState([]),[o,v]=u.useState("default"),[a,S]=u.useState(null),[T,P]=u.useState(null),[g,D]=u.useState(""),[I,A]=u.useState(!1),[L,E]=u.useState(!1),[w,x]=u.useState(null),y=u.useCallback(async()=>{try{const n=await R();f(n),!n.some(c=>c.id===o)&&n.length>0&&v(n[0].id)}catch(n){x({kind:"error",message:`Failed to load instances: ${n.message}`})}},[o]),k=u.useCallback(async()=>{if(o){A(!0);try{const n=await B(o);S(n),P(n);const r=s.find(c=>c.id===o);D((r==null?void 0:r.label)??o)}catch(n){x({kind:"error",message:`Failed to load instance: ${n.message}`})}finally{A(!1)}}},[o,s]);u.useEffect(()=>{y()},[y]),u.useEffect(()=>{k()},[k]);const _=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(c){x({kind:"error",message:c.message})}},z=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})}},$=async()=>{if(!(!a||!T)){E(!0);try{const n={};Object.keys(a).forEach(p=>{const h=a[p];if(h!==T[p]){if((p==="SLACK_BOT_TOKEN"||p==="SLACK_APP_TOKEN")&&h==="********")return;n[p]=h}});const r=s.find(p=>p.id===o),c=r&&g.trim()&&g.trim()!==r.label;await H(o,{label:c?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)}}},d=(n,r)=>{a&&S({...a,[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:{...t.alert(w.kind),marginBottom:12},children:w.message}),e.jsxs("div",{style:t.container,children:[e.jsxs("div",{style:t.list,children:[s.map(n=>{var c,p,h;const r=((c=n.config)==null?void 0:c.currentMode)??"none";return e.jsxs("div",{style:t.listItem(n.id===o),onClick:()=>v(n.id),children:[e.jsx("div",{style:t.label,children:n.label}),e.jsxs("div",{style:t.sub,children:[e.jsx("span",{style:t.badge(r),children:r==="none"?"—":r}),(p=n.status)!=null&&p.connected?" • connected":(h=n.status)!=null&&h.error?" • error":" • idle"]})]},n.id)}),e.jsx("button",{type:"button",style:t.addBtn,onClick:_,children:"+ Add Instance"})]}),e.jsxs("div",{style:t.editor,children:[I&&e.jsx("div",{style:{color:"#6c7086",fontSize:13},children:"Loading…"}),!I&&a&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:t.field,children:[e.jsx("span",{style:t.fieldLabel,children:"Display label"}),e.jsx("input",{type:"text",style:t.input,value:g,onChange:n=>D(n.target.value),disabled:!1}),e.jsxs("span",{style:t.fieldDesc,children:["Shown in the instance list. Id is fixed: ",e.jsx("code",{children:o})]})]}),e.jsxs("div",{style:t.field,children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:a.enabled,onChange:n=>d("enabled",n.target.checked)}),e.jsx("span",{style:t.fieldLabel,children:"Enabled"})]}),e.jsx("span",{style:t.fieldDesc,children:"Toggle off to disconnect this instance without deleting its config."})]}),e.jsxs("div",{style:t.field,children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:a.mirrorOwnMessages,onChange:n=>d("mirrorOwnMessages",n.target.checked)}),e.jsx("span",{style:t.fieldLabel,children:"Mirror messages I send too"})]}),e.jsxs("span",{style:t.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:t.field,children:[e.jsx("span",{style:t.fieldLabel,children:"Slack Token"}),e.jsx("input",{type:"password",style:t.input,placeholder:"xoxb-... or xoxp-...",value:a.SLACK_BOT_TOKEN,onChange:n=>d("SLACK_BOT_TOKEN",n.target.value)}),e.jsxs("span",{style:t.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:t.field,children:[e.jsx("span",{style:t.fieldLabel,children:"App Token (Socket Mode only)"}),e.jsx("input",{type:"password",style:t.input,placeholder:"xapp-...",value:a.SLACK_APP_TOKEN,onChange:n=>d("SLACK_APP_TOKEN",n.target.value)}),e.jsx("span",{style:t.fieldDesc,children:"Required for xoxb- only. Leave blank for xoxp- (polling mode)."})]}),e.jsxs("div",{style:t.rowGap,children:[e.jsxs("div",{style:{...t.field,flex:1},children:[e.jsx("span",{style:t.fieldLabel,children:"Inbound Mode"}),e.jsxs("select",{style:t.input,value:a.authMode,onChange:n=>d("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:{...t.field,flex:1},children:[e.jsx("span",{style:t.fieldLabel,children:"Default Channel"}),e.jsx("input",{type:"text",style:t.input,placeholder:"C0123456789",value:a.defaultChannelId,onChange:n=>d("defaultChannelId",n.target.value)})]})]}),e.jsxs("div",{style:t.rowGap,children:[e.jsxs("div",{style:{...t.field,flex:1},children:[e.jsx("span",{style:t.fieldLabel,children:"Polling Interval (s)"}),e.jsx("input",{type:"number",style:t.input,min:10,max:600,value:a.pollingIntervalSec,onChange:n=>d("pollingIntervalSec",Number(n.target.value))})]}),e.jsxs("div",{style:{...t.field,flex:1},children:[e.jsx("span",{style:t.fieldLabel,children:"Concurrency"}),e.jsx("input",{type:"number",style:t.input,min:1,max:8,value:a.pollingConcurrency,onChange:n=>d("pollingConcurrency",Number(n.target.value))})]}),e.jsxs("div",{style:{...t.field,flex:1},children:[e.jsx("span",{style:t.fieldLabel,children:"Backfill Cap (msgs)"}),e.jsx("input",{type:"number",style:t.input,min:1,max:1e3,value:a.pollingBackfillMessageCap,onChange:n=>d("pollingBackfillMessageCap",Number(n.target.value))})]}),e.jsxs("div",{style:{...t.field,flex:1},children:[e.jsx("span",{style:t.fieldLabel,children:"Min ms between calls"}),e.jsx("input",{type:"number",style:t.input,min:0,max:1e4,value:a.pollingMinMsBetweenCalls,onChange:n=>d("pollingMinMsBetweenCalls",Number(n.target.value))}),e.jsx("span",{style:{...t.fieldDesc,fontSize:11},children:"Throttle. 1500 ≈ 40 req/min. Set 0 to disable."})]})]}),e.jsxs("div",{style:t.field,children:[e.jsx("span",{style:t.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 c=M(a.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:c,onChange:p=>{const h=new Set(M(a.pollingChannelTypes));p.target.checked?h.add(n):h.delete(n),d("pollingChannelTypes",N(h))}}),e.jsx("span",{children:O[n]})]},n)})}),e.jsx("span",{style:t.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:t.field,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("span",{style:t.fieldLabel,children:"Channel Allowlist (optional)"}),a.pollingChannelAllowlist&&e.jsx("button",{type:"button",style:{...t.btnSecondary,padding:"4px 10px",fontSize:12},onClick:()=>d("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:{...t.input,minHeight:60,fontFamily:"monospace",fontSize:12},placeholder:`C0123456789, G0987654321
|
|
2
2
|
C9999999999`,value:a.pollingChannelAllowlist,onChange:n=>d("pollingChannelAllowlist",n.target.value)}),e.jsx("span",{style:t.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:t.field,children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:a.pollingDmsAlways,onChange:n=>d("pollingDmsAlways",n.target.checked)}),e.jsx("span",{style:t.fieldLabel,children:"Always include DMs"})]}),e.jsx("span",{style:t.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:t.buttons,children:[e.jsx("button",{type:"button",style:t.btnPrimary,onClick:$,disabled:L,children:L?"Saving…":"Save & Reconnect"}),e.jsx("button",{type:"button",style:t.btnSecondary,onClick:i,children:"Close"}),o!=="default"&&e.jsx("button",{type:"button",style:{...t.btnDanger,marginLeft:"auto"},onClick:z,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-5eyR3isL.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-jN7LzP4f.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-
|
|
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-jN7LzP4f.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 he,r as i,aJ as f,l as u,j as e}from"./main-jN7LzP4f.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const ue=[{value:"webhook",label:"Webhook"},{value:"cron",label:"Cron"},{value:"slack",label:"Slack"},{value:"email",label:"Email"},{value:"jira",label:"Jira"},{value:"whatsapp",label:"WhatsApp"}],ye=[{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)"}],ge=[{value:"structural",label:"Structural"},{value:"llm",label:"LLM"}];function me(v){if(!v)return"";const d=new Date(v);if(Number.isNaN(d.getTime()))return"";const y=S=>String(S).padStart(2,"0");return`${d.getFullYear()}-${y(d.getMonth()+1)}-${y(d.getDate())}T${y(d.getHours())}:${y(d.getMinutes())}`}const A=()=>({name:"",description:"",type:"webhook",agentId:"",promptTemplate:"",enabled:!0,matchMode:"structural",extractionMode:"structural",config:{method:"POST"}});function ve({isOpen:v,onClose:d}){var _,$,J,V,G,X,Y,q,K,Q,Z,ee;const y=he(),[S,te]=i.useState([]),[T,w]=i.useState("list"),[n,b]=i.useState(A()),[c,E]=i.useState(!1),[z,L]=i.useState(!1),[B,p]=i.useState(null),[D,le]=i.useState([]),[k,se]=i.useState(null),[F,ae]=i.useState(`{
|
|
2
|
+
|
|
3
|
+
}`),[r,C]=i.useState(null),[N,I]=i.useState(!1),[P,H]=i.useState([]),g=i.useCallback(async()=>{try{const t=await f(u("/api/triggers"));if(t.ok){const s=await t.json();te(s)}}catch(t){console.error("Failed to load triggers:",t)}},[]),M=i.useCallback(async t=>{try{const s=await f(u(`/api/triggers/${t}/events?limit=20`));if(s.ok){const a=await s.json();le(a)}}catch(s){console.error("Failed to load trigger history:",s)}},[]);i.useEffect(()=>{v&&g()},[v,g]),i.useEffect(()=>{k&&M(k)},[k,M]);const ne=i.useCallback(async()=>{L(!0),p(null);try{const t=c?u(`/api/triggers/${n.id}`):u("/api/triggers"),m=await f(t,{method:c?"PATCH":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!m.ok){const j=await m.json();throw new Error(j.error||"Failed to save trigger")}await g(),w("list"),b(A()),E(!1)}catch(t){p(t instanceof Error?t.message:"Save failed")}finally{L(!1)}},[n,c,g]),ie=i.useCallback(async t=>{try{await f(u(`/api/triggers/${t}`),{method:"DELETE"}),await g()}catch(s){console.error("Failed to delete trigger:",s)}},[g]),re=i.useCallback(async t=>{try{await f(u(`/api/triggers/${t.id}`),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:!t.enabled})}),await g()}catch(s){console.error("Failed to toggle trigger:",s)}},[g]),oe=i.useCallback(async t=>{try{await f(u(`/api/triggers/${t}/fire`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({variables:{}})}),k===t&&await M(t)}catch(s){console.error("Failed to test fire trigger:",s)}},[k,M]),de=i.useCallback(async()=>{if(n.id){I(!0),C(null);try{let t;try{t=JSON.parse(F)}catch{C({structuralMatch:void 0,extractedVariables:{},wouldFire:!1}),p("Invalid JSON payload");return}const s=await f(u(`/api/triggers/${n.id}/test-match`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({payload:t})});if(s.ok){const a=await s.json();C(a),p(null)}else{const a=await s.json();p(a.error||"Test match failed")}}catch(t){p(t instanceof Error?t.message:"Test match failed")}finally{I(!1)}}},[n.id,F]),ce=i.useCallback(async t=>{var s;try{const a=await f(u("/api/triggers/validate-cron"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({expression:t,timezone:((s=n.config)==null?void 0:s.timezone)||"UTC"})});if(a.ok){const m=await a.json();H(m.valid?m.nextFires:[])}}catch{H([])}},[n]),W=i.useCallback(t=>{t?(b({...t}),E(!0)):(b(A()),E(!1)),C(null),p(null),w("edit")},[]),o=i.useCallback((t,s)=>{b(a=>({...a,[t]:s}))},[]),x=i.useCallback((t,s)=>{b(a=>({...a,config:{...a.config,[t]:s}}))},[]),O=i.useCallback((t,s)=>{b(a=>({...a,llmMatch:{...a.llmMatch||{prompt:""},[t]:s}}))},[]),U=i.useCallback((t,s)=>{b(a=>({...a,llmExtract:{...a.llmExtract||{prompt:"",variables:[]},[t]:s}}))},[]),pe=i.useMemo(()=>Array.from(y.values()).map(t=>({id:t.id,name:t.name})),[y]);return v?e.jsx("div",{style:l.overlay,onClick:d,children:e.jsxs("div",{style:l.panel,onClick:t=>t.stopPropagation(),children:[e.jsxs("div",{style:l.header,children:[e.jsx("h2",{style:l.title,children:T==="list"?"Triggers":c?"Edit Trigger":"New Trigger"}),e.jsxs("div",{style:l.headerActions,children:[T==="list"&&e.jsx("button",{style:l.addBtn,onClick:()=>W(),children:"+ New Trigger"}),T==="edit"&&e.jsx("button",{style:l.backBtn,onClick:()=>{w("list"),C(null),p(null)},children:"Back"}),e.jsx("button",{style:l.closeBtn,onClick:d,children:"X"})]})]}),B&&e.jsx("div",{style:l.error,children:B}),T==="list"&&e.jsx("div",{style:l.content,children:S.length===0?e.jsx("div",{style:l.empty,children:"No triggers configured. Create one to get started."}):S.map(t=>{var s;return e.jsxs("div",{style:{...l.triggerCard,borderLeftColor:t.status==="error"?"#e74c3c":t.enabled?"#2ecc71":"#95a5a6"},onClick:()=>{se(t.id),W(t)},children:[e.jsxs("div",{style:l.cardHeader,children:[e.jsxs("div",{style:l.cardTitle,children:[e.jsx("span",{style:l.typeTag,children:t.type}),e.jsx("span",{children:t.name}),t.type==="cron"&&(()=>{const a=t.config||{};return a.runOnce?a.completedAt?e.jsx("span",{style:{...l.matchTag,color:"#a6e3a1"},children:"Once · completed"}):a.missedAt?e.jsx("span",{style:{...l.matchTag,color:"#f38ba8"},children:"Once · missed"}):e.jsx("span",{style:{...l.matchTag,color:"#f9e2af"},children:"Once · pending"}):e.jsx("span",{style:l.matchTag,children:"Recurring"})})(),t.matchMode!=="structural"&&e.jsx("span",{style:l.matchTag,children:t.matchMode})]}),e.jsxs("div",{style:l.cardActions,children:[e.jsx("button",{style:l.smallBtn,onClick:a=>{a.stopPropagation(),re(t)},children:t.enabled?"Disable":"Enable"}),e.jsx("button",{style:l.smallBtn,onClick:a=>{a.stopPropagation(),oe(t.id)},children:"Test Fire"}),e.jsx("button",{style:{...l.smallBtn,color:"#e74c3c"},onClick:a=>{a.stopPropagation(),ie(t.id)},children:"Delete"})]})]}),e.jsxs("div",{style:l.cardMeta,children:[e.jsxs("span",{children:["Agent: ",((s=y.get(t.agentId))==null?void 0:s.name)||t.agentId]}),e.jsxs("span",{children:["Fires: ",t.fireCount]}),t.lastFiredAt&&e.jsxs("span",{children:["Last: ",new Date(t.lastFiredAt).toLocaleString()]}),t.status==="error"&&t.lastError&&e.jsxs("span",{style:{color:"#e74c3c"},children:["Error: ",t.lastError]})]})]},t.id)})}),T==="edit"&&e.jsx("div",{style:l.content,children:e.jsxs("div",{style:l.form,children:[e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Name"}),e.jsx("input",{style:l.input,value:n.name||"",onChange:t=>o("name",t.target.value),placeholder:"My Trigger"})]}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Description"}),e.jsx("input",{style:l.input,value:n.description||"",onChange:t=>o("description",t.target.value),placeholder:"Optional description"})]}),e.jsxs("div",{style:l.row,children:[e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Type"}),e.jsx("select",{style:l.select,value:n.type||"webhook",onChange:t=>{const s=t.target.value;o("type",s),s==="webhook"?o("config",{method:"POST"}):s==="cron"?o("config",{expression:"0 9 * * MON-FRI",timezone:"UTC"}):o("config",{}),(n.promptTemplate??"").trim()||(s==="slack"?o("promptTemplate",`Slack message from {{slack.user}} in {{slack.channelName}}:
|
|
4
|
+
{{slack.message}}
|
|
5
|
+
|
|
6
|
+
{{slack.attachmentsBlock}}`):s==="whatsapp"&&o("promptTemplate",`WhatsApp message from {{whatsapp.fromName}} ({{whatsapp.from}}):
|
|
7
|
+
{{whatsapp.body}}
|
|
8
|
+
|
|
9
|
+
{{whatsapp.attachmentsBlock}}`))},children:ue.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))})]}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Agent"}),e.jsxs("select",{style:l.select,value:n.agentId||"",onChange:t=>o("agentId",t.target.value),children:[e.jsx("option",{value:"",children:"Select agent..."}),pe.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))]})]})]}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Prompt Template"}),e.jsx("textarea",{style:l.textarea,value:n.promptTemplate||"",onChange:t=>o("promptTemplate",t.target.value),placeholder:"Message sent to agent. Use {{variable}} for interpolation.",rows:4})]}),n.type==="webhook"&&e.jsxs("div",{style:l.section,children:[e.jsx("h4",{style:l.sectionTitle,children:"Webhook Config"}),e.jsxs("div",{style:l.row,children:[e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Method"}),e.jsxs("select",{style:l.select,value:((_=n.config)==null?void 0:_.method)||"POST",onChange:t=>x("method",t.target.value),children:[e.jsx("option",{value:"POST",children:"POST"}),e.jsx("option",{value:"PUT",children:"PUT"})]})]}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Secret (HMAC)"}),e.jsx("input",{style:l.input,type:"password",value:(($=n.config)==null?void 0:$.secret)||"",onChange:t=>x("secret",t.target.value||void 0),placeholder:"Optional HMAC secret"})]})]}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Extract Fields (comma-separated JSON paths)"}),e.jsx("input",{style:l.input,value:((V=(J=n.config)==null?void 0:J.extractFields)==null?void 0:V.join(", "))||"",onChange:t=>x("extractFields",t.target.value.split(",").map(s=>s.trim()).filter(Boolean)),placeholder:"body.release_name, body.version"})]}),c&&n.id&&e.jsxs("div",{style:l.webhookUrl,children:[e.jsx("label",{style:l.label,children:"Webhook URL"}),e.jsx("code",{style:l.code,children:`${window.location.origin}/api/triggers/webhook/${n.id}`})]})]}),n.type==="cron"&&(()=>{const t=n.config||{},s=!!t.runOnce,a=t.completedAt,m=t.missedAt,j=!!a;return e.jsxs("div",{style:l.section,children:[e.jsx("h4",{style:l.sectionTitle,children:"Cron Config"}),e.jsxs("div",{style:l.modeSelector,children:[e.jsxs("button",{type:"button",style:{...l.modeBtn,...s?{}:l.modeBtnActive},onClick:()=>x("runOnce",!1),disabled:j,children:[e.jsx("strong",{children:"Repeats"}),e.jsx("span",{style:l.modeDesc,children:"Fires on a cron schedule"})]}),e.jsxs("button",{type:"button",style:{...l.modeBtn,...s?l.modeBtnActive:{}},onClick:()=>x("runOnce",!0),disabled:j,children:[e.jsx("strong",{children:"Run once"}),e.jsx("span",{style:l.modeDesc,children:"Fires exactly once at a specific time"})]})]}),j&&e.jsxs("div",{style:{...l.testResult,borderLeft:"3px solid #a6e3a1"},children:[e.jsx("strong",{style:{color:"#a6e3a1"},children:"Completed"}),e.jsxs("span",{style:l.llmMeta,children:["Fired at ",new Date(a).toLocaleString()]})]}),!j&&m&&e.jsxs("div",{style:{...l.testResult,borderLeft:"3px solid #f38ba8"},children:[e.jsx("strong",{style:{color:"#f38ba8"},children:"Missed"}),e.jsxs("span",{style:l.llmMeta,children:["Marked missed at ",new Date(m).toLocaleString()," (server was down at runAt)"]})]}),s?e.jsx("div",{style:l.row,children:e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Run at"}),e.jsx("input",{style:l.input,type:"datetime-local",value:me(t.runAt),onChange:h=>{const R=h.target.value;if(!R){x("runAt",void 0);return}const xe=new Date(R).toISOString();x("runAt",xe)},disabled:j}),e.jsx("span",{style:l.llmMeta,children:"Interpreted in your browser's local timezone"})]})}):e.jsxs("div",{style:l.row,children:[e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Expression"}),e.jsx("input",{style:l.input,value:t.expression||"",onChange:h=>{x("expression",h.target.value),h.target.value&&ce(h.target.value)},placeholder:"0 9 * * MON-FRI"})]}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Timezone"}),e.jsx("input",{style:l.input,value:t.timezone||"UTC",onChange:h=>x("timezone",h.target.value),placeholder:"America/Mexico_City"})]})]}),!s&&P.length>0&&e.jsxs("div",{style:l.nextFires,children:[e.jsx("label",{style:l.label,children:"Next fires:"}),P.map((h,R)=>e.jsx("div",{style:l.nextFireItem,children:new Date(h).toLocaleString()},R))]})]})})(),e.jsxs("div",{style:l.section,children:[e.jsx("h4",{style:l.sectionTitle,children:"Match Mode"}),e.jsx("div",{style:l.modeSelector,children:ye.map(t=>e.jsxs("button",{style:{...l.modeBtn,...n.matchMode===t.value?l.modeBtnActive:{}},onClick:()=>o("matchMode",t.value),children:[e.jsx("strong",{children:t.label}),e.jsx("span",{style:l.modeDesc,children:t.desc})]},t.value))}),(n.matchMode==="llm"||n.matchMode==="hybrid")&&e.jsxs("div",{style:l.llmConfig,children:[e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"LLM Match Prompt"}),e.jsx("textarea",{style:l.textarea,value:((G=n.llmMatch)==null?void 0:G.prompt)||"",onChange:t=>O("prompt",t.target.value),placeholder:"Does this message request a release deployment?",rows:3})]}),e.jsxs("div",{style:l.row,children:[e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Model"}),e.jsxs("select",{style:l.select,value:((X=n.llmMatch)==null?void 0:X.model)||"haiku",onChange:t=>O("model",t.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:l.field,children:[e.jsx("label",{style:l.label,children:"Min Confidence"}),e.jsx("input",{style:l.input,type:"number",min:"0",max:"1",step:"0.1",value:((Y=n.llmMatch)==null?void 0:Y.minConfidence)??0,onChange:t=>O("minConfidence",parseFloat(t.target.value))})]})]})]})]}),e.jsxs("div",{style:l.section,children:[e.jsx("h4",{style:l.sectionTitle,children:"Extraction Mode"}),e.jsx("div",{style:l.row,children:ge.map(t=>e.jsx("button",{style:{...l.modeBtn,...n.extractionMode===t.value?l.modeBtnActive:{}},onClick:()=>o("extractionMode",t.value),children:t.label},t.value))}),n.extractionMode==="llm"&&e.jsxs("div",{style:l.llmConfig,children:[e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Extraction Instructions"}),e.jsx("textarea",{style:l.textarea,value:((q=n.llmExtract)==null?void 0:q.prompt)||"",onChange:t=>U("prompt",t.target.value),placeholder:"Extract: release version, affected systems, urgency",rows:3})]}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Variable Names (comma-separated)"}),e.jsx("input",{style:l.input,value:((Q=(K=n.llmExtract)==null?void 0:K.variables)==null?void 0:Q.join(", "))||"",onChange:t=>U("variables",t.target.value.split(",").map(s=>s.trim()).filter(Boolean)),placeholder:"release_name, affected_systems, urgency"})]})]})]}),c&&e.jsxs("div",{style:l.section,children:[e.jsx("h4",{style:l.sectionTitle,children:"Test Match"}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Sample Event Payload (JSON)"}),e.jsx("textarea",{style:l.textarea,value:F,onChange:t=>ae(t.target.value),rows:4})]}),e.jsx("button",{style:l.testBtn,onClick:de,disabled:N,children:N?"Testing...":"Test Match"}),r&&e.jsxs("div",{style:l.testResult,children:[e.jsx("div",{style:{...l.testResultHeader,color:r.wouldFire?"#2ecc71":"#e74c3c"},children:r.wouldFire?"WOULD FIRE":"WOULD NOT FIRE"}),r.structuralMatch!==void 0&&e.jsxs("div",{children:["Structural: ",r.structuralMatch?"Match":"No match"]}),r.llmMatch&&e.jsxs("div",{style:l.llmResult,children:[e.jsxs("div",{children:["LLM: ",r.llmMatch.match?"Match":"No match"]}),e.jsxs("div",{children:["Confidence: ",(r.llmMatch.confidence*100).toFixed(0),"%"]}),e.jsxs("div",{children:["Reason: ",r.llmMatch.reason]}),e.jsxs("div",{style:l.llmMeta,children:["Model: ",r.llmMatch.model," | Tokens: ",r.llmMatch.tokensUsed," | Latency: ",r.llmMatch.durationMs,"ms"]})]}),Object.keys(r.extractedVariables).length>0&&e.jsxs("div",{children:[e.jsx("div",{style:l.label,children:"Extracted Variables:"}),Object.entries(r.extractedVariables).map(([t,s])=>e.jsxs("div",{style:l.varRow,children:[e.jsx("code",{children:t}),": ",s]},t))]})]})]}),c&&D.length>0&&e.jsxs("div",{style:l.section,children:[e.jsx("h4",{style:l.sectionTitle,children:"Recent Fires"}),e.jsx("div",{style:l.historyList,children:D.map((t,s)=>{const a=t.llm_match_result?JSON.parse(t.llm_match_result):null;return e.jsxs("div",{style:l.historyItem,children:[e.jsxs("div",{style:l.historyHeader,children:[e.jsx("span",{style:{color:t.status==="delivered"?"#2ecc71":t.status==="failed"?"#e74c3c":"#f39c12"},children:t.status}),e.jsx("span",{children:new Date(t.fired_at).toLocaleString()}),t.duration_ms&&e.jsxs("span",{children:[t.duration_ms,"ms"]})]}),t.error&&e.jsx("div",{style:{color:"#e74c3c",fontSize:"12px"},children:t.error}),a&&e.jsxs("div",{style:l.llmMeta,children:["LLM: ",a.match?"match":"no match"," (",(a.confidence*100).toFixed(0),"%) - ",a.reason]})]},t.id||s)})})]}),e.jsxs("div",{style:l.actions,children:[e.jsx("button",{style:l.cancelBtn,onClick:()=>{w("list"),p(null)},children:"Cancel"}),e.jsx("button",{style:l.saveBtn,onClick:ne,disabled:z||!n.name||!n.agentId||n.type==="cron"&&!!((Z=n.config)!=null&&Z.runOnce)&&!((ee=n.config)!=null&&ee.runAt),children:z?"Saving...":c?"Update":"Create"})]})]})})]})}):null}const l={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"},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"},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{ve as TriggerManagerPanel,ve 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-
|
|
1
|
+
import{r as x,aJ as M,l as P,j as e,ah as J}from"./main-jN7LzP4f.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 jt,M as Pt,N as ct,O as ie,P as dn,s as b,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-5eyR3isL.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function Wn(w){const o=a.useRef(w);o.current=w,a.useEffect(()=>{if(!sn())return;let v=null,I=!1;return St.addListener("backButton",()=>{o.current()==="exit"&&St.exitApp()}).then(E=>{I?E.remove():v=E}),()=>{I=!0,v&&(v.remove(),v=null)}},[])}const Hn=a.memo(function({className:o=""}){const{t:v}=Bt(["common"]),[I,E]=ln(),Y=a.useRef(null),[O,Te]=a.useState(null);a.useLayoutEffect(()=>{const g=Y.current;if(!g)return;const K=g.querySelector(".view-mode-toggle__btn--active");K&&Te({left:K.offsetLeft,width:K.offsetWidth})},[I]);const le=a.useCallback(g=>{if(g!==I){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:g}})),g==="3d"){requestAnimationFrame(()=>E(g));return}E(g)}},[I,E]);return e.jsxs("div",{className:`view-mode-toggle ${o}`,ref:Y,children:[O&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:O.left,width:O.width}}),rn.map(g=>e.jsxs("button",{className:`view-mode-toggle__btn ${I===g?"view-mode-toggle__btn--active":""}`,onClick:()=>le(g),title:v(`common:viewMode.descriptions.${g}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[g==="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"})]}),g==="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"})]}),g==="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"})]}),g==="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.${g}`)})]},g))]})}),dt=3,ut=280,zt=320,Ct=240,Ot=64,Vn=["simple","chat","advanced"],Gn={simple:"Simple",chat:"Chat",advanced:"Advanced"},Xn={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 o=w.split("/").filter(Boolean);return o.length===0?w:o.slice(-2).join("/")}function Yn(w){if(w.provider==="codex"){const Y=w.codexModel||"gpt-5.3-codex",O=$n[Y];return{model:(O==null?void 0:O.label)||Y}}if(w.provider==="opencode")return{model:w.opencodeModel||"opencode"};const o=w.model||"sonnet",v=Fn[o],I=w.effort,E=I?Bn[I]:void 0;return{model:(v==null?void 0:v.label)||o,effort:E==null?void 0:E.label}}function Kn(w,o){if(o.type==="rectangle"&&o.width&&o.height){const v=o.width/2,I=o.height/2;return w.x>=o.center.x-v&&w.x<=o.center.x+v&&w.z>=o.center.z-I&&w.z<=o.center.z+I}if(o.type==="circle"&&o.radius){const v=w.x-o.center.x,I=w.z-o.center.z;return v*v+I*I<=o.radius*o.radius}return!1}const Zn=yn.memo(function({agentId:o,terminalViewMode:v,onTerminalViewModeChange:I,inspectorOpen:E,onToggleInspector:Y,onImageClick:O,onFileClick:Te,onBashClick:le,onViewMarkdown:g,onRequestClearSubordinates:K,onOpenBuilding:je,keyboard:$e,canNavigateBack:Be,canNavigateForward:Fe,onNavigateBack:Z,onNavigateForward:re,agentInfoOpen:$,onToggleAgentInfo:We}){var de,Se,ae,tt;const f=An(o),G=Wt(),B=a.useRef(null),Ne=a.useRef(null);a.useEffect(()=>{const i=Ne.current;if(!i)return;const r=c=>{c.button===3?(c.preventDefault(),c.stopPropagation(),Z()):c.button===4&&(c.preventDefault(),c.stopPropagation(),re())},d=c=>{(c.button===3||c.button===4)&&c.preventDefault()};return i.addEventListener("mouseup",r),i.addEventListener("mousedown",d),()=>{i.removeEventListener("mouseup",r),i.removeEventListener("mousedown",d)}},[Z,re]),a.useEffect(()=>{const i=Ne.current;if(!i)return;let r=0,d=0,c=0;const ue=250,_e=600,Me=80,gt=1.5,xt=T=>{let S=T instanceof HTMLElement?T:null;for(;S&&S!==i;){const nt=window.getComputedStyle(S).overflowX;if((nt==="auto"||nt==="scroll")&&S.scrollWidth>S.clientWidth)return!0;S=S.parentElement}return!1},V=T=>{const S=Date.now();if(S<c){T.preventDefault();return}if(Math.abs(T.deltaX)<=Math.abs(T.deltaY)*gt){r=0;return}if(xt(T.target)){r=0;return}S-d>ue&&(r=0),d=S,r+=T.deltaX,r<=-Me?(r=0,c=S+_e,T.preventDefault(),Z()):r>=Me&&(r=0,c=S+_e,T.preventDefault(),re())};return i.addEventListener("wheel",V,{passive:!1}),()=>i.removeEventListener("wheel",V)},[Z,re]);const ke=Ft(),pe=a.useMemo(()=>{if(!f)return null;const i=new Set,r=[];for(const d of ke.values())d.archived||d.directories.length===0||d.assignedAgentIds.includes(o)&&(i.add(d.id),r.push(d));for(const d of ke.values())d.archived||d.directories.length===0||i.has(d.id)||Kn({x:f.position.x,z:f.position.z},d)&&(i.add(d.id),r.push(d));return r.length===0?null:r.flatMap(d=>d.directories.filter(c=>c&&c.trim().length>0).map(c=>({areaId:d.id,areaName:d.name,dir:c})))},[f,o,ke]),{branches:He,fetchRemote:Ve,fetchingDirs:Ge}=In(pe),me=a.useMemo(()=>{var d;const i=b.getAreaForAgent(o);if(!i)return[];const r=[];for(const c of G.values())c.type==="terminal"&&b.isPositionInArea(c.position,i)&&r.push({id:c.id,name:c.name,hasUrl:!!((d=c.terminalStatus)!=null&&d.url)});return r},[o,G]),Xe=a.useMemo(()=>{var d;const i=b.getAreaForAgent(o);if(!i)return[];const r=[];for(const c of G.values())c.type==="server"&&((d=c.pm2)!=null&&d.enabled)&&b.isPositionInArea(c.position,i)&&r.push({id:c.id,name:c.name});return r},[o,G]),fe=a.useMemo(()=>{const i=b.getAreaForAgent(o);if(!i)return[];const r=[];for(const d of G.values())d.type==="database"&&d.database&&b.isPositionInArea(d.position,i)&&r.push({id:d.id,name:d.name});return r},[o,G]),[,he]=a.useReducer(i=>i+1,0),F=((de=B.current)==null?void 0:de.search.searchMode)??!1,oe=a.useCallback(()=>{var i;(i=B.current)==null||i.search.toggleSearch(),he()},[]),Ue=En(),Pe=Ue.isPending($t),[W,X]=a.useState(null),R=W?G.get(W):null,{height:ye,onResizeStart:U}=Sn(),[q,J]=a.useState(()=>jt(y.GIT_PANEL_OPEN,!1)),[D,qe]=a.useState(()=>jt(y.BUILDINGS_PANEL_OPEN,!1)),[ge,Le]=a.useState(!1),Ae=a.useCallback(()=>{Le(i=>{const r=!i;return r&&Mn.setEnabled(!0),r})},[]),pt=a.useCallback(()=>Le(!1),[]),mt=a.useCallback(()=>{J(i=>{const r=!i;return ie(y.GIT_PANEL_OPEN,r),r})},[]),xe=a.useCallback(()=>{qe(i=>{const r=!i;return ie(y.BUILDINGS_PANEL_OPEN,r),r})},[]),ft=a.useCallback(()=>{J(!1),ie(y.GIT_PANEL_OPEN,!1)},[]),Ye=a.useCallback(()=>{qe(!1),ie(y.BUILDINGS_PANEL_OPEN,!1)},[]),ht=Tn();a.useEffect(()=>{if(!W)return;me.some(r=>r.id===W)||X(null)},[W,me]);const[Q,ce]=a.useState(!1),Re=a.useRef(null);if(a.useEffect(()=>{if(!Q)return;const i=r=>{Re.current&&!Re.current.contains(r.target)&&ce(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[Q]),!f)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=f.contextStats,Ke=!!ee,Ze=ee?ee.totalTokens:f.contextUsed||0,Je=ee?ee.contextWindow:f.contextLimit||2e5,Ie=ee?ee.usedPercent:Math.round(Ze/Je*100),h=Math.max(0,Math.min(100,Ie)),te=Math.round(h*10)/10,H=Math.round((100-h)*10)/10,be=h>=80?"#ff4a4a":h>=60?"#ff9e4a":h>=40?"#ffd700":"#4aff9e",De=(Ze/1e3).toFixed(1),Qe=(Je/1e3).toFixed(1),ne=f.cwd,et=ne?qn(ne):null,Ee=((Se=f.subordinateIds)==null?void 0:Se.length)||0,ze=Ee>0;return e.jsxs("div",{ref:Ne,className:`flat-terminal-wrapper ${q||D||ge?"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 ${$?"flat-terminal-wrapper__header-main--active":""}`,onClick:We,title:$?"Hide agent info":"Show agent info","aria-pressed":$,children:[e.jsx(Ht,{agent:f,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:f.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:Vt(f.status)},children:f.status})]}),f.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:f.taskLabel,children:["📋 ",f.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:f.provider==="codex"?"/assets/codex.png":f.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:f.provider,className:"flat-terminal-wrapper__header-provider-icon",title:f.provider==="codex"?"Codex Agent":f.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:i,effort:r}=Yn(f);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:Xn[i]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:Gn[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:!Be,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:re,disabled:!Fe,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 ${F?"flat-terminal-wrapper__action-btn--active":""}`,onClick:oe,title:F?"Close search":"Search messages","aria-pressed":F,children:e.jsx(u,{name:F?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${Pe?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>Ue.handleClick($t,()=>{var i;b.clearContext(o),(i=B.current)==null||i.historyLoader.clearHistory()}),title:Pe?"Click again to confirm clear context":"Clear context",children:e.jsx(u,{name:Pe?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${q?"flat-terminal-wrapper__action-btn--active":""}`,onClick:mt,title:q?"Hide git panel":"Show git changes","aria-pressed":q,children:e.jsx(u,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${D?"flat-terminal-wrapper__action-btn--active":""}`,onClick:xe,title:D?"Hide buildings panel":"Show area buildings","aria-pressed":D,children:e.jsx(u,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:Re,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Q?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>ce(i=>!i),title:"More actions","aria-expanded":Q,children:"⋮"}),Q&&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 ${ge?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{Ae(),ce(!1)},title:ge?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(u,{name:"bug",size:14}),e.jsx("span",{children:ge?"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:()=>{b.collapseContext(o),ce(!1)},disabled:f.status!=="idle",title:f.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"})]}),ze&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{K(o,Ee),ce(!1)},children:[e.jsx(u,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",Ee," subordinate",Ee===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:()=>{b.killAgent(o),ce(!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:()=>b.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(u,{name:"cross",size:14})})]})]}),e.jsx(Pn,{ref:B,agentId:o,agent:f,viewMode:v,isOpen:!0,onImageClick:O,onFileClick:Te,onBashClick:le,onViewMarkdown:g,keyboard:$e,hasModalOpen:!1}),R&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:U,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded terminal"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`Embedded terminal: ${R.name}`,style:{height:ye},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:R.name}),!((ae=R.terminalStatus)!=null&&ae.url)&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>X(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:(tt=R.terminalStatus)!=null&&tt.url?e.jsx(Ln,{terminalUrl:R.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:[f.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"})]}),ne&&et&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${ne}`,"aria-label":`Open ${ne} in file explorer`,role:"button",tabIndex:0,onClick:()=>b.openFileExplorer(ne),onKeyDown:i=>{(i.key==="Enter"||i.key===" ")&&(i.preventDefault(),b.openFileExplorer(ne))},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:et})]}),pe&&pe.map(({areaId:i,areaName:r,dir:d})=>{const c=He.get(d),ue=Ge.has(d),_e=d.split("/").filter(Boolean).pop()||d;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${r}: ${d}${c?` (${c.branch}${c.ahead?` ↑${c.ahead}`:""}${c.behind?` ↓${c.behind}`:""})`:""}`,onClick:()=>b.openFileExplorerForAreaFolder(i,d),children:[e.jsx(u,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:_e}),c&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(u,{name:"git-branch",size:10})," ",c.branch]}),c.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${c.ahead} ahead`,children:[e.jsx(u,{name:"arrow-up",size:9}),c.ahead]}),c.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${c.behind} behind`,children:[e.jsx(u,{name:"arrow-down",size:9}),c.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${ue?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:Me=>{Me.stopPropagation(),Ve(d)},children:e.jsx(u,{name:ue?"hourglass":"download",size:12})})]})]},`${i}:${d}`)}),e.jsxs("span",{className:"flat-terminal-wrapper__context",onClick:()=>b.setContextModalAgentId(o),title:Ke?`Context usage: ${De}k / ${Qe}k tokens (${te}% 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:`${h}%`,backgroundColor:be}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:be},children:[De,"k/",Qe,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",H,"% free)"]}),!Ke&&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"}),me.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:me.map(i=>{const r=W===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){X(null);return}i.hasUrl||b.sendBuildingCommand(i.id,"start"),X(i.id)},children:e.jsx(u,{name:"terminal",size:14})},i.id)})}),Xe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:Xe.map(i=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open logs: ${i.name}`,onClick:()=>je(i.id),children:e.jsx(u,{name:"scroll",size:14})},i.id))}),fe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:fe.map(i=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open database: ${i.name}`,onClick:()=>je(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,{})})]}),q&&e.jsx(Dn,{agentId:o,agents:ht,onClose:ft,branchInfoMap:He,fetchRemote:Ve,fetchingDirs:Ge}),D&&e.jsx(zn,{agentId:o,onClose:Ye}),ge&&e.jsx(On,{agentId:o,onClose:pt})]})});function ta({onAgentClick:w,onBuildingClick:o,onBuildingDoubleClick:v,onBuildingPopup:I,onAreaContextMenu:E,onOpenSpawnModal:Y,onOpenBossSpawnModal:O,onOpenAreaModal:Te}){const{t:le}=Bt(["common"]),g=on(),K=cn(),[je,$e]=a.useState(null),[Be,Fe]=a.useState(null),[Z,re]=a.useState(null),[$,We]=a.useState(null),[f,G]=a.useState(null),[B,Ne]=a.useState(null),[ke,pe]=a.useState(!1),He=a.useCallback(()=>{pe(t=>!t)},[]),Ve=a.useCallback(()=>{pe(!1)},[]),[Ge,me]=a.useState(()=>{const t=Mt(y.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Xe=a.useCallback(t=>{me(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")&&me(s)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[fe,he]=a.useState(()=>jt(y.FLAT_INSPECTOR_OPEN,!1)),[F,oe]=a.useState(!1),Ue=a.useCallback(()=>oe(t=>!t),[]),Pe=a.useCallback(()=>oe(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:F}}))},[F]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:fe}}))},[fe]),a.useEffect(()=>{const t=()=>oe(_=>!_),n=()=>{he(_=>{const l=!_;return ie(y.FLAT_INSPECTOR_OPEN,l),l})},s=()=>{oe(!1),he(!1),ie(y.FLAT_INSPECTOR_OPEN,!1)},p=()=>oe(!1),m=()=>{he(!1),ie(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 W=a.useRef(null),X=a.useRef(null),[R,ye]=a.useState(()=>{const t=Pt(y.FLAT_MIDDLE_WIDTH,0);return t>=ut?t:null}),[U,q]=a.useState(()=>{const t=Pt(y.FLAT_INSPECTOR_WIDTH,0);return t>=Ct?t:null}),J=a.useCallback(t=>{if(typeof window>"u")return t;const n=U!==null?dt+U:0,s=window.innerWidth-Ot-dt-zt-n;return Math.max(ut,Math.min(Math.max(s,ut),t))},[U]),D=a.useCallback(t=>{var m;if(typeof window>"u")return t;const n=(m=W.current)==null?void 0:m.querySelector(".flat-middle"),s=(n==null?void 0:n.getBoundingClientRect().width)??ut,p=window.innerWidth-Ot-s-dt-zt-dt;return Math.max(Ct,Math.min(Math.max(p,Ct),t))},[]);a.useEffect(()=>{if(R===null&&U===null)return;const t=()=>{ye(n=>{if(n===null)return n;const s=J(n);return s===n?n:s}),q(n=>{if(n===null)return n;const s=D(n);return s===n?n:s})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[R,U,J,D]);const qe=a.useCallback(t=>{var s;if(t.button!==0)return;const n=(s=W.current)==null?void 0:s.querySelector(".flat-middle");n&&(t.currentTarget.setPointerCapture(t.pointerId),X.current={kind:"middle",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),ge=a.useCallback(t=>{var s;if(t.button!==0)return;const n=(s=W.current)==null?void 0:s.querySelector(".flat-inspector");n&&(t.currentTarget.setPointerCapture(t.pointerId),X.current={kind:"inspector",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),Le=a.useCallback(t=>{const n=X.current;if(!n||t.pointerId!==n.pointerId)return;const s=t.clientX-n.startX;n.kind==="middle"?ye(J(n.startWidth+s)):q(D(n.startWidth-s))},[J,D]),Ae=a.useCallback(t=>{const n=X.current;if(!n||t.pointerId!==n.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(X.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=J(n.startWidth+p);ye(m),ct(y.FLAT_MIDDLE_WIDTH,m)}else{const m=D(n.startWidth-p);q(m),ct(y.FLAT_INSPECTOR_WIDTH,m)}},[J,D]),pt=a.useCallback(()=>{ye(null),ct(y.FLAT_MIDDLE_WIDTH,0)},[]),mt=a.useCallback(()=>{q(null),ct(y.FLAT_INSPECTOR_WIDTH,0)},[]),[xe,ft]=a.useState(()=>Mt(y.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),Ye=a.useCallback(t=>{ft(t),Tt(y.FLAT_INSPECTOR_VIEW,t)},[]),ht=a.useCallback(()=>{he(t=>{const n=!t;return ie(y.FLAT_INSPECTOR_OPEN,n),n})},[]),Q=a.useCallback(()=>{he(!1),ie(y.FLAT_INSPECTOR_OPEN,!1)},[]),ce=dn(),Re=a.useCallback((t,n)=>{$e({url:t,name:n})},[]),ee=a.useCallback((t,n)=>{Fe({command:t,output:n,isLive:!1})},[]),Ke=a.useCallback((t,n)=>{b.setFileViewerPath(t,n)},[]),Ze=a.useCallback(t=>{},[]),Je=a.useCallback((t,n)=>{re({agentId:t,count:n})},[]),Ie=a.useCallback(t=>{v?v(t):o(t)},[o,v]),h=a.useMemo(()=>K.size>0?Array.from(K)[0]:null,[K]);a.useEffect(()=>{pe(!1)},[h]);const te=a.useRef([]),H=a.useRef(-1),be=a.useRef(!1),De=a.useRef(null),[Qe,ne]=a.useState(!1),[et,Ee]=a.useState(!1),ze=a.useRef(!1),de=a.useRef(null),Se=a.useRef(!1),ae=a.useMemo(()=>new Set(g.map(t=>t.id)),[g]),tt=a.useMemo(()=>{const t=new Map(g.map(s=>[s.id,s])),n=new Map;for(const s of g)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},[g]),i=a.useCallback(()=>{const t=te.current,n=H.current;ne(n>0),Ee(n>=0&&n<t.length-1)},[]),r=a.useCallback(t=>{const n=te.current;if(n.length===0)return;let s=H.current+t;for(;s>=0&&s<n.length;){const p=n[s];if(ae.has(p)){be.current=!0,H.current=s,i(),b.selectAgent(p);return}s+=t}},[ae,i]),d=a.useCallback(()=>r(-1),[r]),c=a.useCallback(()=>r(1),[r]);Wn(a.useCallback(()=>{const t=te.current,n=H.current;return t.length>0&&n>0?(r(-1),"handled"):"exit"},[r]));const ue=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){ze.current=!1,de.current=null;return}if(!ze.current){ue(h,"replace"),ze.current=!0,de.current=h;return}if(Se.current){Se.current=!1,de.current=h;return}de.current!==h&&(ue(h,"push"),de.current=h)},[h,ue]),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"||!ae.has(s)||s===h)return;Se.current=!0,be.current=!0;const p=te.current,m=p.lastIndexOf(s);m>=0?H.current=m:(p.push(s),H.current=p.length-1),i(),b.selectAgent(s)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[ae,h,i]),a.useEffect(()=>{if(!h){te.current=[],H.current=-1,i();return}if(De.current=h,be.current){be.current=!1,i();return}const t=te.current,n=H.current;if(n>=0&&t[n]===h){i();return}const s=n<t.length-1?t.slice(0,n+1):t.slice();s.push(h),s.length>100&&s.shift(),te.current=s,H.current=s.length-1,i()},[h,i]);const _e=a.useCallback(t=>{w(t),oe(!1)},[w]),Me=h??"",gt=a.useCallback(()=>{},[]),xt=a.useCallback(t=>{_e(t)},[_e]),V=fe,[T,S]=a.useState(V),[nt,Nt]=a.useState(V);a.useEffect(()=>{if(V){S(!0);return}Nt(!1);const t=setTimeout(()=>S(!1),240);return()=>clearTimeout(t)},[V]),a.useEffect(()=>{if(!T||!V)return;let t=0;const n=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>Nt(!0))});return()=>{cancelAnimationFrame(n),cancelAnimationFrame(t)}},[T,V]);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=De.current;!p||!ae.has(p)||(n.preventDefault(),b.selectAgent(p))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[h,ae]);const[Gt,yt]=a.useState(new Set),Xt=a.useCallback(t=>{yt(n=>{const s=new Set(n);return s.has(t)?s.delete(t):s.add(t),s})},[]),[we,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[at,qt]=a.useState(null),Yt=a.useCallback(t=>{qt(n=>n===t?null:t)},[]),bt=Ft(),st=Wt(),[Kt]=un(),ve=a.useMemo(()=>{const t=new Map,n=[];for(const x of g){const k=b.getAreaForAgent(x.id);if(!Lt((k==null?void 0:k.id)??null))continue;if(!k||k.archived){n.push(x);continue}const j=t.get(k.id);j?j.push(x):t.set(k.id,[x])}const s=new Map,p=[];for(const x of st.values()){let k=!1;for(const j of bt.values())if(!j.archived&&Rt(j.id)&&b.isPositionInArea(x.position,j)){const se=s.get(j.id);se?se.push(x):s.set(j.id,[x]),k=!0;break}!k&&Lt(null)&&p.push(x)}const m=[];for(const[,x]of bt){if(x.archived||!Rt(x.id))continue;const k=t.get(x.id),j=s.get(x.id)??[];(k&&k.length>0||j.length>0)&&m.push({area:x,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(x=>x.area.id!=="__unassigned__"),l=m.filter(x=>x.area.id==="__unassigned__");let A=1,N=1;const z=new Map;if(_.length>1){let x=1/0,k=-1/0,j=1/0,se=-1/0;for(const P of _)x=Math.min(x,P.area.center.x),k=Math.max(k,P.area.center.x),j=Math.min(j,P.area.center.z),se=Math.max(se,P.area.center.z);const lt=k-x||1,rt=se-j||1;if(_.length<=4){A=_.length,N=1;const P=[..._].sort((L,_t)=>L.area.center.x-_t.area.center.x);for(let L=0;L<P.length;L++)z.set(P[L].area.id,{row:1,col:L+1})}else{const P=[..._].sort((C,M)=>C.area.center.x-M.area.center.x),L=[];for(let C=1;C<P.length;C++)L.push(P[C].area.center.x-P[C-1].area.center.x);const _t=L.reduce((C,M)=>C+M,0)/L.length||1;let At=1;for(const C of L)C>_t*1.3&&At++;A=Math.max(2,Math.min(At,_.length));const wt=[..._].sort((C,M)=>C.area.center.z-M.area.center.z),ot=[];for(let C=1;C<wt.length;C++)ot.push(wt[C].area.center.z-wt[C-1].area.center.z);const en=ot.reduce((C,M)=>C+M,0)/ot.length||1;let It=1;for(const C of ot)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=lt/A,nn=rt/N,vt=new Set;for(const C of _){let M=Math.min(A-1,Math.max(0,Math.floor((C.area.center.x-x)/tn))),Ce=Math.min(N-1,Math.max(0,Math.floor((C.area.center.z-j)/nn))),Oe=`${Ce},${M}`,Et=0;const an=N*A;for(;vt.has(Oe)&&Et<an;)M++,M>=A&&(M=0,Ce=(Ce+1)%N),Oe=`${Ce},${M}`,Et++;vt.has(Oe)&&(Ce=N,M=0,Oe=`${Ce},${M}`,N++),vt.add(Oe),z.set(C.area.id,{row:Ce+1,col:M+1})}}}const it=x=>{x.sort((k,j)=>{var lt,rt,P,L;const se=(((lt=k.position)==null?void 0:lt.z)??0)-(((rt=j.position)==null?void 0:rt.z)??0);return se!==0?se:(((P=k.position)==null?void 0:P.x)??0)-(((L=j.position)==null?void 0:L.x)??0)})};for(const x of _)it(x.agents);for(const x of l)it(x.agents);return{groups:[..._,...l],gridCols:A,gridRows:N,positions:z}},[g,bt,st,Kt]),Zt=a.useMemo(()=>{if(!$)return[];const t=g.find(n=>n.id===$.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:()=>{Ne({agentId:t.id,name:t.name})}}]:[]},[$,g,w]),Jt=a.useMemo(()=>{var _;if(!f)return[];const t=st.get(f.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:()=>Ie(t.id)}),s&&(p||n.push({id:"start",label:"Start",icon:e.jsx(u,{name:"play",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"start")}),p&&(n.push({id:"restart",label:"Restart",icon:e.jsx(u,{name:"refresh",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"restart")}),n.push({id:"stop",label:"Stop",icon:e.jsx(u,{name:"stop",size:14}),onClick:()=>b.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)b.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)b.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)b.sendBuildingCommand(l,"restart")}})),s&&n.push({id:"health-check",label:"Health Check",icon:e.jsx(u,{name:"health",size:14}),onClick:()=>b.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:()=>{b.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:()=>b.deleteBuilding(t.id)}),n},[f,st,Ie]),Qt=a.useCallback(t=>{const n=new Set(ve.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"})})},[ve]);return e.jsxs("div",{ref:W,className:`flat-view ${V?"flat-view--with-inspector":""} ${h?"flat-view--has-chat":""} ${F?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(R===null&&U===null)return;const t={};return R!==null&&(t["--flat-middle-width"]=`${R}px`),U!==null&&(t["--flat-inspector-width"]=`${U}px`),t})(),children:[F&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:Pe,"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:O,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:Te,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(pn,{activeAgentId:Me,onClose:gt,onSelectAgent:xt,collapsedAreas:Gt,onToggleArea:Xt,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:qe,onPointerMove:Le,onPointerUp:Ae,onPointerCancel:Ae,onDoubleClick:pt}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":F?"Close agents sidebar":"Open agents sidebar","aria-expanded":F,onClick:Ue,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:Ge,onTerminalViewModeChange:Xe,inspectorOpen:fe,onToggleInspector:ht,onImageClick:Re,onFileClick:Ke,onBashClick:ee,onViewMarkdown:Ze,onRequestClearSubordinates:Je,onOpenBuilding:Ie,keyboard:ce,canNavigateBack:Qe,canNavigateForward:et,onNavigateBack:d,onNavigateForward:c,agentInfoOpen:ke,onToggleAgentInfo:He}):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(${ve.gridCols}, 1fr)`},children:ve.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(()=>{var n;const t=we&&at?((n=ve.positions.get(at))==null?void 0:n.row)??null:null;return ve.groups.map(s=>{const p=s.area.id,m=ve.positions.get(p),_=we&&at!==p;return we&&t!=null&&(m==null?void 0:m.row)===t&&p!==at?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:()=>we?Yt(p):Qt(p),title:we?_?`Expand ${s.area.name}`:`Collapse ${s.area.name}`:`Focus ${s.area.name} in left panel`,"aria-expanded":we?!_: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}),we&&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?tt.get(l.id):void 0,z=mn(l),it=z.usedPercent>=80?"#ff4a4a":z.usedPercent>=60?"#ff9e4a":z.usedPercent>=40?"#ffd700":"#4aff9e",x=`Context: ${(z.totalTokens/1e3).toFixed(1)}k / ${(z.contextWindow/1e3).toFixed(1)}k (${z.usedPercent}% used, ${z.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(),We({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 jt,M as Pt,N as ct,O as ie,P as dn,s as b,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-jN7LzP4f.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function Wn(w){const o=a.useRef(w);o.current=w,a.useEffect(()=>{if(!sn())return;let v=null,I=!1;return St.addListener("backButton",()=>{o.current()==="exit"&&St.exitApp()}).then(E=>{I?E.remove():v=E}),()=>{I=!0,v&&(v.remove(),v=null)}},[])}const Hn=a.memo(function({className:o=""}){const{t:v}=Bt(["common"]),[I,E]=ln(),Y=a.useRef(null),[O,Te]=a.useState(null);a.useLayoutEffect(()=>{const g=Y.current;if(!g)return;const K=g.querySelector(".view-mode-toggle__btn--active");K&&Te({left:K.offsetLeft,width:K.offsetWidth})},[I]);const le=a.useCallback(g=>{if(g!==I){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:g}})),g==="3d"){requestAnimationFrame(()=>E(g));return}E(g)}},[I,E]);return e.jsxs("div",{className:`view-mode-toggle ${o}`,ref:Y,children:[O&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:O.left,width:O.width}}),rn.map(g=>e.jsxs("button",{className:`view-mode-toggle__btn ${I===g?"view-mode-toggle__btn--active":""}`,onClick:()=>le(g),title:v(`common:viewMode.descriptions.${g}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[g==="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"})]}),g==="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"})]}),g==="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"})]}),g==="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.${g}`)})]},g))]})}),dt=3,ut=280,zt=320,Ct=240,Ot=64,Vn=["simple","chat","advanced"],Gn={simple:"Simple",chat:"Chat",advanced:"Advanced"},Xn={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 o=w.split("/").filter(Boolean);return o.length===0?w:o.slice(-2).join("/")}function Yn(w){if(w.provider==="codex"){const Y=w.codexModel||"gpt-5.3-codex",O=$n[Y];return{model:(O==null?void 0:O.label)||Y}}if(w.provider==="opencode")return{model:w.opencodeModel||"opencode"};const o=w.model||"sonnet",v=Fn[o],I=w.effort,E=I?Bn[I]:void 0;return{model:(v==null?void 0:v.label)||o,effort:E==null?void 0:E.label}}function Kn(w,o){if(o.type==="rectangle"&&o.width&&o.height){const v=o.width/2,I=o.height/2;return w.x>=o.center.x-v&&w.x<=o.center.x+v&&w.z>=o.center.z-I&&w.z<=o.center.z+I}if(o.type==="circle"&&o.radius){const v=w.x-o.center.x,I=w.z-o.center.z;return v*v+I*I<=o.radius*o.radius}return!1}const Zn=yn.memo(function({agentId:o,terminalViewMode:v,onTerminalViewModeChange:I,inspectorOpen:E,onToggleInspector:Y,onImageClick:O,onFileClick:Te,onBashClick:le,onViewMarkdown:g,onRequestClearSubordinates:K,onOpenBuilding:je,keyboard:$e,canNavigateBack:Be,canNavigateForward:Fe,onNavigateBack:Z,onNavigateForward:re,agentInfoOpen:$,onToggleAgentInfo:We}){var de,Se,ae,tt;const f=An(o),G=Wt(),B=a.useRef(null),Ne=a.useRef(null);a.useEffect(()=>{const i=Ne.current;if(!i)return;const r=c=>{c.button===3?(c.preventDefault(),c.stopPropagation(),Z()):c.button===4&&(c.preventDefault(),c.stopPropagation(),re())},d=c=>{(c.button===3||c.button===4)&&c.preventDefault()};return i.addEventListener("mouseup",r),i.addEventListener("mousedown",d),()=>{i.removeEventListener("mouseup",r),i.removeEventListener("mousedown",d)}},[Z,re]),a.useEffect(()=>{const i=Ne.current;if(!i)return;let r=0,d=0,c=0;const ue=250,_e=600,Me=80,gt=1.5,xt=T=>{let S=T instanceof HTMLElement?T:null;for(;S&&S!==i;){const nt=window.getComputedStyle(S).overflowX;if((nt==="auto"||nt==="scroll")&&S.scrollWidth>S.clientWidth)return!0;S=S.parentElement}return!1},V=T=>{const S=Date.now();if(S<c){T.preventDefault();return}if(Math.abs(T.deltaX)<=Math.abs(T.deltaY)*gt){r=0;return}if(xt(T.target)){r=0;return}S-d>ue&&(r=0),d=S,r+=T.deltaX,r<=-Me?(r=0,c=S+_e,T.preventDefault(),Z()):r>=Me&&(r=0,c=S+_e,T.preventDefault(),re())};return i.addEventListener("wheel",V,{passive:!1}),()=>i.removeEventListener("wheel",V)},[Z,re]);const ke=Ft(),pe=a.useMemo(()=>{if(!f)return null;const i=new Set,r=[];for(const d of ke.values())d.archived||d.directories.length===0||d.assignedAgentIds.includes(o)&&(i.add(d.id),r.push(d));for(const d of ke.values())d.archived||d.directories.length===0||i.has(d.id)||Kn({x:f.position.x,z:f.position.z},d)&&(i.add(d.id),r.push(d));return r.length===0?null:r.flatMap(d=>d.directories.filter(c=>c&&c.trim().length>0).map(c=>({areaId:d.id,areaName:d.name,dir:c})))},[f,o,ke]),{branches:He,fetchRemote:Ve,fetchingDirs:Ge}=In(pe),me=a.useMemo(()=>{var d;const i=b.getAreaForAgent(o);if(!i)return[];const r=[];for(const c of G.values())c.type==="terminal"&&b.isPositionInArea(c.position,i)&&r.push({id:c.id,name:c.name,hasUrl:!!((d=c.terminalStatus)!=null&&d.url)});return r},[o,G]),Xe=a.useMemo(()=>{var d;const i=b.getAreaForAgent(o);if(!i)return[];const r=[];for(const c of G.values())c.type==="server"&&((d=c.pm2)!=null&&d.enabled)&&b.isPositionInArea(c.position,i)&&r.push({id:c.id,name:c.name});return r},[o,G]),fe=a.useMemo(()=>{const i=b.getAreaForAgent(o);if(!i)return[];const r=[];for(const d of G.values())d.type==="database"&&d.database&&b.isPositionInArea(d.position,i)&&r.push({id:d.id,name:d.name});return r},[o,G]),[,he]=a.useReducer(i=>i+1,0),F=((de=B.current)==null?void 0:de.search.searchMode)??!1,oe=a.useCallback(()=>{var i;(i=B.current)==null||i.search.toggleSearch(),he()},[]),Ue=En(),Pe=Ue.isPending($t),[W,X]=a.useState(null),R=W?G.get(W):null,{height:ye,onResizeStart:U}=Sn(),[q,J]=a.useState(()=>jt(y.GIT_PANEL_OPEN,!1)),[D,qe]=a.useState(()=>jt(y.BUILDINGS_PANEL_OPEN,!1)),[ge,Le]=a.useState(!1),Ae=a.useCallback(()=>{Le(i=>{const r=!i;return r&&Mn.setEnabled(!0),r})},[]),pt=a.useCallback(()=>Le(!1),[]),mt=a.useCallback(()=>{J(i=>{const r=!i;return ie(y.GIT_PANEL_OPEN,r),r})},[]),xe=a.useCallback(()=>{qe(i=>{const r=!i;return ie(y.BUILDINGS_PANEL_OPEN,r),r})},[]),ft=a.useCallback(()=>{J(!1),ie(y.GIT_PANEL_OPEN,!1)},[]),Ye=a.useCallback(()=>{qe(!1),ie(y.BUILDINGS_PANEL_OPEN,!1)},[]),ht=Tn();a.useEffect(()=>{if(!W)return;me.some(r=>r.id===W)||X(null)},[W,me]);const[Q,ce]=a.useState(!1),Re=a.useRef(null);if(a.useEffect(()=>{if(!Q)return;const i=r=>{Re.current&&!Re.current.contains(r.target)&&ce(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[Q]),!f)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=f.contextStats,Ke=!!ee,Ze=ee?ee.totalTokens:f.contextUsed||0,Je=ee?ee.contextWindow:f.contextLimit||2e5,Ie=ee?ee.usedPercent:Math.round(Ze/Je*100),h=Math.max(0,Math.min(100,Ie)),te=Math.round(h*10)/10,H=Math.round((100-h)*10)/10,be=h>=80?"#ff4a4a":h>=60?"#ff9e4a":h>=40?"#ffd700":"#4aff9e",De=(Ze/1e3).toFixed(1),Qe=(Je/1e3).toFixed(1),ne=f.cwd,et=ne?qn(ne):null,Ee=((Se=f.subordinateIds)==null?void 0:Se.length)||0,ze=Ee>0;return e.jsxs("div",{ref:Ne,className:`flat-terminal-wrapper ${q||D||ge?"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 ${$?"flat-terminal-wrapper__header-main--active":""}`,onClick:We,title:$?"Hide agent info":"Show agent info","aria-pressed":$,children:[e.jsx(Ht,{agent:f,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:f.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:Vt(f.status)},children:f.status})]}),f.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:f.taskLabel,children:["📋 ",f.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:f.provider==="codex"?"/assets/codex.png":f.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:f.provider,className:"flat-terminal-wrapper__header-provider-icon",title:f.provider==="codex"?"Codex Agent":f.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:i,effort:r}=Yn(f);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:Xn[i]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:Gn[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:!Be,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:re,disabled:!Fe,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 ${F?"flat-terminal-wrapper__action-btn--active":""}`,onClick:oe,title:F?"Close search":"Search messages","aria-pressed":F,children:e.jsx(u,{name:F?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${Pe?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>Ue.handleClick($t,()=>{var i;b.clearContext(o),(i=B.current)==null||i.historyLoader.clearHistory()}),title:Pe?"Click again to confirm clear context":"Clear context",children:e.jsx(u,{name:Pe?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${q?"flat-terminal-wrapper__action-btn--active":""}`,onClick:mt,title:q?"Hide git panel":"Show git changes","aria-pressed":q,children:e.jsx(u,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${D?"flat-terminal-wrapper__action-btn--active":""}`,onClick:xe,title:D?"Hide buildings panel":"Show area buildings","aria-pressed":D,children:e.jsx(u,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:Re,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Q?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>ce(i=>!i),title:"More actions","aria-expanded":Q,children:"⋮"}),Q&&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 ${ge?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{Ae(),ce(!1)},title:ge?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(u,{name:"bug",size:14}),e.jsx("span",{children:ge?"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:()=>{b.collapseContext(o),ce(!1)},disabled:f.status!=="idle",title:f.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"})]}),ze&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{K(o,Ee),ce(!1)},children:[e.jsx(u,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",Ee," subordinate",Ee===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:()=>{b.killAgent(o),ce(!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:()=>b.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(u,{name:"cross",size:14})})]})]}),e.jsx(Pn,{ref:B,agentId:o,agent:f,viewMode:v,isOpen:!0,onImageClick:O,onFileClick:Te,onBashClick:le,onViewMarkdown:g,keyboard:$e,hasModalOpen:!1}),R&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:U,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded terminal"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`Embedded terminal: ${R.name}`,style:{height:ye},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:R.name}),!((ae=R.terminalStatus)!=null&&ae.url)&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>X(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:(tt=R.terminalStatus)!=null&&tt.url?e.jsx(Ln,{terminalUrl:R.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:[f.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"})]}),ne&&et&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${ne}`,"aria-label":`Open ${ne} in file explorer`,role:"button",tabIndex:0,onClick:()=>b.openFileExplorer(ne),onKeyDown:i=>{(i.key==="Enter"||i.key===" ")&&(i.preventDefault(),b.openFileExplorer(ne))},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:et})]}),pe&&pe.map(({areaId:i,areaName:r,dir:d})=>{const c=He.get(d),ue=Ge.has(d),_e=d.split("/").filter(Boolean).pop()||d;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${r}: ${d}${c?` (${c.branch}${c.ahead?` ↑${c.ahead}`:""}${c.behind?` ↓${c.behind}`:""})`:""}`,onClick:()=>b.openFileExplorerForAreaFolder(i,d),children:[e.jsx(u,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:_e}),c&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(u,{name:"git-branch",size:10})," ",c.branch]}),c.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${c.ahead} ahead`,children:[e.jsx(u,{name:"arrow-up",size:9}),c.ahead]}),c.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${c.behind} behind`,children:[e.jsx(u,{name:"arrow-down",size:9}),c.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${ue?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:Me=>{Me.stopPropagation(),Ve(d)},children:e.jsx(u,{name:ue?"hourglass":"download",size:12})})]})]},`${i}:${d}`)}),e.jsxs("span",{className:"flat-terminal-wrapper__context",onClick:()=>b.setContextModalAgentId(o),title:Ke?`Context usage: ${De}k / ${Qe}k tokens (${te}% 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:`${h}%`,backgroundColor:be}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:be},children:[De,"k/",Qe,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",H,"% free)"]}),!Ke&&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"}),me.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:me.map(i=>{const r=W===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){X(null);return}i.hasUrl||b.sendBuildingCommand(i.id,"start"),X(i.id)},children:e.jsx(u,{name:"terminal",size:14})},i.id)})}),Xe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:Xe.map(i=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open logs: ${i.name}`,onClick:()=>je(i.id),children:e.jsx(u,{name:"scroll",size:14})},i.id))}),fe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:fe.map(i=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open database: ${i.name}`,onClick:()=>je(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,{})})]}),q&&e.jsx(Dn,{agentId:o,agents:ht,onClose:ft,branchInfoMap:He,fetchRemote:Ve,fetchingDirs:Ge}),D&&e.jsx(zn,{agentId:o,onClose:Ye}),ge&&e.jsx(On,{agentId:o,onClose:pt})]})});function ta({onAgentClick:w,onBuildingClick:o,onBuildingDoubleClick:v,onBuildingPopup:I,onAreaContextMenu:E,onOpenSpawnModal:Y,onOpenBossSpawnModal:O,onOpenAreaModal:Te}){const{t:le}=Bt(["common"]),g=on(),K=cn(),[je,$e]=a.useState(null),[Be,Fe]=a.useState(null),[Z,re]=a.useState(null),[$,We]=a.useState(null),[f,G]=a.useState(null),[B,Ne]=a.useState(null),[ke,pe]=a.useState(!1),He=a.useCallback(()=>{pe(t=>!t)},[]),Ve=a.useCallback(()=>{pe(!1)},[]),[Ge,me]=a.useState(()=>{const t=Mt(y.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Xe=a.useCallback(t=>{me(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")&&me(s)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[fe,he]=a.useState(()=>jt(y.FLAT_INSPECTOR_OPEN,!1)),[F,oe]=a.useState(!1),Ue=a.useCallback(()=>oe(t=>!t),[]),Pe=a.useCallback(()=>oe(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:F}}))},[F]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:fe}}))},[fe]),a.useEffect(()=>{const t=()=>oe(_=>!_),n=()=>{he(_=>{const l=!_;return ie(y.FLAT_INSPECTOR_OPEN,l),l})},s=()=>{oe(!1),he(!1),ie(y.FLAT_INSPECTOR_OPEN,!1)},p=()=>oe(!1),m=()=>{he(!1),ie(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 W=a.useRef(null),X=a.useRef(null),[R,ye]=a.useState(()=>{const t=Pt(y.FLAT_MIDDLE_WIDTH,0);return t>=ut?t:null}),[U,q]=a.useState(()=>{const t=Pt(y.FLAT_INSPECTOR_WIDTH,0);return t>=Ct?t:null}),J=a.useCallback(t=>{if(typeof window>"u")return t;const n=U!==null?dt+U:0,s=window.innerWidth-Ot-dt-zt-n;return Math.max(ut,Math.min(Math.max(s,ut),t))},[U]),D=a.useCallback(t=>{var m;if(typeof window>"u")return t;const n=(m=W.current)==null?void 0:m.querySelector(".flat-middle"),s=(n==null?void 0:n.getBoundingClientRect().width)??ut,p=window.innerWidth-Ot-s-dt-zt-dt;return Math.max(Ct,Math.min(Math.max(p,Ct),t))},[]);a.useEffect(()=>{if(R===null&&U===null)return;const t=()=>{ye(n=>{if(n===null)return n;const s=J(n);return s===n?n:s}),q(n=>{if(n===null)return n;const s=D(n);return s===n?n:s})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[R,U,J,D]);const qe=a.useCallback(t=>{var s;if(t.button!==0)return;const n=(s=W.current)==null?void 0:s.querySelector(".flat-middle");n&&(t.currentTarget.setPointerCapture(t.pointerId),X.current={kind:"middle",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),ge=a.useCallback(t=>{var s;if(t.button!==0)return;const n=(s=W.current)==null?void 0:s.querySelector(".flat-inspector");n&&(t.currentTarget.setPointerCapture(t.pointerId),X.current={kind:"inspector",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),Le=a.useCallback(t=>{const n=X.current;if(!n||t.pointerId!==n.pointerId)return;const s=t.clientX-n.startX;n.kind==="middle"?ye(J(n.startWidth+s)):q(D(n.startWidth-s))},[J,D]),Ae=a.useCallback(t=>{const n=X.current;if(!n||t.pointerId!==n.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(X.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=J(n.startWidth+p);ye(m),ct(y.FLAT_MIDDLE_WIDTH,m)}else{const m=D(n.startWidth-p);q(m),ct(y.FLAT_INSPECTOR_WIDTH,m)}},[J,D]),pt=a.useCallback(()=>{ye(null),ct(y.FLAT_MIDDLE_WIDTH,0)},[]),mt=a.useCallback(()=>{q(null),ct(y.FLAT_INSPECTOR_WIDTH,0)},[]),[xe,ft]=a.useState(()=>Mt(y.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),Ye=a.useCallback(t=>{ft(t),Tt(y.FLAT_INSPECTOR_VIEW,t)},[]),ht=a.useCallback(()=>{he(t=>{const n=!t;return ie(y.FLAT_INSPECTOR_OPEN,n),n})},[]),Q=a.useCallback(()=>{he(!1),ie(y.FLAT_INSPECTOR_OPEN,!1)},[]),ce=dn(),Re=a.useCallback((t,n)=>{$e({url:t,name:n})},[]),ee=a.useCallback((t,n)=>{Fe({command:t,output:n,isLive:!1})},[]),Ke=a.useCallback((t,n)=>{b.setFileViewerPath(t,n)},[]),Ze=a.useCallback(t=>{},[]),Je=a.useCallback((t,n)=>{re({agentId:t,count:n})},[]),Ie=a.useCallback(t=>{v?v(t):o(t)},[o,v]),h=a.useMemo(()=>K.size>0?Array.from(K)[0]:null,[K]);a.useEffect(()=>{pe(!1)},[h]);const te=a.useRef([]),H=a.useRef(-1),be=a.useRef(!1),De=a.useRef(null),[Qe,ne]=a.useState(!1),[et,Ee]=a.useState(!1),ze=a.useRef(!1),de=a.useRef(null),Se=a.useRef(!1),ae=a.useMemo(()=>new Set(g.map(t=>t.id)),[g]),tt=a.useMemo(()=>{const t=new Map(g.map(s=>[s.id,s])),n=new Map;for(const s of g)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},[g]),i=a.useCallback(()=>{const t=te.current,n=H.current;ne(n>0),Ee(n>=0&&n<t.length-1)},[]),r=a.useCallback(t=>{const n=te.current;if(n.length===0)return;let s=H.current+t;for(;s>=0&&s<n.length;){const p=n[s];if(ae.has(p)){be.current=!0,H.current=s,i(),b.selectAgent(p);return}s+=t}},[ae,i]),d=a.useCallback(()=>r(-1),[r]),c=a.useCallback(()=>r(1),[r]);Wn(a.useCallback(()=>{const t=te.current,n=H.current;return t.length>0&&n>0?(r(-1),"handled"):"exit"},[r]));const ue=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){ze.current=!1,de.current=null;return}if(!ze.current){ue(h,"replace"),ze.current=!0,de.current=h;return}if(Se.current){Se.current=!1,de.current=h;return}de.current!==h&&(ue(h,"push"),de.current=h)},[h,ue]),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"||!ae.has(s)||s===h)return;Se.current=!0,be.current=!0;const p=te.current,m=p.lastIndexOf(s);m>=0?H.current=m:(p.push(s),H.current=p.length-1),i(),b.selectAgent(s)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[ae,h,i]),a.useEffect(()=>{if(!h){te.current=[],H.current=-1,i();return}if(De.current=h,be.current){be.current=!1,i();return}const t=te.current,n=H.current;if(n>=0&&t[n]===h){i();return}const s=n<t.length-1?t.slice(0,n+1):t.slice();s.push(h),s.length>100&&s.shift(),te.current=s,H.current=s.length-1,i()},[h,i]);const _e=a.useCallback(t=>{w(t),oe(!1)},[w]),Me=h??"",gt=a.useCallback(()=>{},[]),xt=a.useCallback(t=>{_e(t)},[_e]),V=fe,[T,S]=a.useState(V),[nt,Nt]=a.useState(V);a.useEffect(()=>{if(V){S(!0);return}Nt(!1);const t=setTimeout(()=>S(!1),240);return()=>clearTimeout(t)},[V]),a.useEffect(()=>{if(!T||!V)return;let t=0;const n=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>Nt(!0))});return()=>{cancelAnimationFrame(n),cancelAnimationFrame(t)}},[T,V]);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=De.current;!p||!ae.has(p)||(n.preventDefault(),b.selectAgent(p))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[h,ae]);const[Gt,yt]=a.useState(new Set),Xt=a.useCallback(t=>{yt(n=>{const s=new Set(n);return s.has(t)?s.delete(t):s.add(t),s})},[]),[we,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[at,qt]=a.useState(null),Yt=a.useCallback(t=>{qt(n=>n===t?null:t)},[]),bt=Ft(),st=Wt(),[Kt]=un(),ve=a.useMemo(()=>{const t=new Map,n=[];for(const x of g){const k=b.getAreaForAgent(x.id);if(!Lt((k==null?void 0:k.id)??null))continue;if(!k||k.archived){n.push(x);continue}const j=t.get(k.id);j?j.push(x):t.set(k.id,[x])}const s=new Map,p=[];for(const x of st.values()){let k=!1;for(const j of bt.values())if(!j.archived&&Rt(j.id)&&b.isPositionInArea(x.position,j)){const se=s.get(j.id);se?se.push(x):s.set(j.id,[x]),k=!0;break}!k&&Lt(null)&&p.push(x)}const m=[];for(const[,x]of bt){if(x.archived||!Rt(x.id))continue;const k=t.get(x.id),j=s.get(x.id)??[];(k&&k.length>0||j.length>0)&&m.push({area:x,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(x=>x.area.id!=="__unassigned__"),l=m.filter(x=>x.area.id==="__unassigned__");let A=1,N=1;const z=new Map;if(_.length>1){let x=1/0,k=-1/0,j=1/0,se=-1/0;for(const P of _)x=Math.min(x,P.area.center.x),k=Math.max(k,P.area.center.x),j=Math.min(j,P.area.center.z),se=Math.max(se,P.area.center.z);const lt=k-x||1,rt=se-j||1;if(_.length<=4){A=_.length,N=1;const P=[..._].sort((L,_t)=>L.area.center.x-_t.area.center.x);for(let L=0;L<P.length;L++)z.set(P[L].area.id,{row:1,col:L+1})}else{const P=[..._].sort((C,M)=>C.area.center.x-M.area.center.x),L=[];for(let C=1;C<P.length;C++)L.push(P[C].area.center.x-P[C-1].area.center.x);const _t=L.reduce((C,M)=>C+M,0)/L.length||1;let At=1;for(const C of L)C>_t*1.3&&At++;A=Math.max(2,Math.min(At,_.length));const wt=[..._].sort((C,M)=>C.area.center.z-M.area.center.z),ot=[];for(let C=1;C<wt.length;C++)ot.push(wt[C].area.center.z-wt[C-1].area.center.z);const en=ot.reduce((C,M)=>C+M,0)/ot.length||1;let It=1;for(const C of ot)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=lt/A,nn=rt/N,vt=new Set;for(const C of _){let M=Math.min(A-1,Math.max(0,Math.floor((C.area.center.x-x)/tn))),Ce=Math.min(N-1,Math.max(0,Math.floor((C.area.center.z-j)/nn))),Oe=`${Ce},${M}`,Et=0;const an=N*A;for(;vt.has(Oe)&&Et<an;)M++,M>=A&&(M=0,Ce=(Ce+1)%N),Oe=`${Ce},${M}`,Et++;vt.has(Oe)&&(Ce=N,M=0,Oe=`${Ce},${M}`,N++),vt.add(Oe),z.set(C.area.id,{row:Ce+1,col:M+1})}}}const it=x=>{x.sort((k,j)=>{var lt,rt,P,L;const se=(((lt=k.position)==null?void 0:lt.z)??0)-(((rt=j.position)==null?void 0:rt.z)??0);return se!==0?se:(((P=k.position)==null?void 0:P.x)??0)-(((L=j.position)==null?void 0:L.x)??0)})};for(const x of _)it(x.agents);for(const x of l)it(x.agents);return{groups:[..._,...l],gridCols:A,gridRows:N,positions:z}},[g,bt,st,Kt]),Zt=a.useMemo(()=>{if(!$)return[];const t=g.find(n=>n.id===$.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:()=>{Ne({agentId:t.id,name:t.name})}}]:[]},[$,g,w]),Jt=a.useMemo(()=>{var _;if(!f)return[];const t=st.get(f.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:()=>Ie(t.id)}),s&&(p||n.push({id:"start",label:"Start",icon:e.jsx(u,{name:"play",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"start")}),p&&(n.push({id:"restart",label:"Restart",icon:e.jsx(u,{name:"refresh",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"restart")}),n.push({id:"stop",label:"Stop",icon:e.jsx(u,{name:"stop",size:14}),onClick:()=>b.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)b.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)b.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)b.sendBuildingCommand(l,"restart")}})),s&&n.push({id:"health-check",label:"Health Check",icon:e.jsx(u,{name:"health",size:14}),onClick:()=>b.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:()=>{b.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:()=>b.deleteBuilding(t.id)}),n},[f,st,Ie]),Qt=a.useCallback(t=>{const n=new Set(ve.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"})})},[ve]);return e.jsxs("div",{ref:W,className:`flat-view ${V?"flat-view--with-inspector":""} ${h?"flat-view--has-chat":""} ${F?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(R===null&&U===null)return;const t={};return R!==null&&(t["--flat-middle-width"]=`${R}px`),U!==null&&(t["--flat-inspector-width"]=`${U}px`),t})(),children:[F&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:Pe,"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:O,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:Te,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(pn,{activeAgentId:Me,onClose:gt,onSelectAgent:xt,collapsedAreas:Gt,onToggleArea:Xt,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:qe,onPointerMove:Le,onPointerUp:Ae,onPointerCancel:Ae,onDoubleClick:pt}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":F?"Close agents sidebar":"Open agents sidebar","aria-expanded":F,onClick:Ue,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:Ge,onTerminalViewModeChange:Xe,inspectorOpen:fe,onToggleInspector:ht,onImageClick:Re,onFileClick:Ke,onBashClick:ee,onViewMarkdown:Ze,onRequestClearSubordinates:Je,onOpenBuilding:Ie,keyboard:ce,canNavigateBack:Qe,canNavigateForward:et,onNavigateBack:d,onNavigateForward:c,agentInfoOpen:ke,onToggleAgentInfo:He}):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(${ve.gridCols}, 1fr)`},children:ve.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(()=>{var n;const t=we&&at?((n=ve.positions.get(at))==null?void 0:n.row)??null:null;return ve.groups.map(s=>{const p=s.area.id,m=ve.positions.get(p),_=we&&at!==p;return we&&t!=null&&(m==null?void 0:m.row)===t&&p!==at?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:()=>we?Yt(p):Qt(p),title:we?_?`Expand ${s.area.name}`:`Collapse ${s.area.name}`:`Focus ${s.area.name} in left panel`,"aria-expanded":we?!_: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}),we&&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?tt.get(l.id):void 0,z=mn(l),it=z.usedPercent>=80?"#ff4a4a":z.usedPercent>=60?"#ff9e4a":z.usedPercent>=40?"#ffd700":"#4aff9e",x=`Context: ${(z.totalTokens/1e3).toFixed(1)}k / ${(z.contextWindow/1e3).toFixed(1)}k (${z.usedPercent}% used, ${z.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(),We({agentId:l.id,position:{x:j.clientX,y:j.clientY}})},title:k?void 0:`${A?"Boss · ":""}Open chat with ${l.name}
|
|
2
2
|
${x}`,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:`${z.usedPercent}%`,backgroundColor:it}})})]})},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 Ie(l.id)},onContextMenu:A=>{A.preventDefault(),A.stopPropagation(),G({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)})})()})]})})]}),V&&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:ge,onPointerMove:Le,onPointerUp:Ae,onPointerCancel:Ae,onDoubleClick:mt}),T&&e.jsxs("aside",{className:`flat-inspector ${nt?"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":xe==="agent",className:`flat-inspector__tab ${xe==="agent"?"flat-inspector__tab--active":""}`,onClick:()=>Ye("agent"),children:"Agent"}),e.jsx("button",{type:"button",role:"tab","aria-selected":xe==="tracking",className:`flat-inspector__tab ${xe==="tracking"?"flat-inspector__tab--active":""}`,onClick:()=>Ye("tracking"),children:"Tracking"})]}),e.jsx("button",{type:"button",className:"flat-inspector__close",onClick:Q,title:"Close inspector","aria-label":"Close inspector",children:"✕"})]}),e.jsx("div",{className:"flat-inspector__body",children:xe==="tracking"?e.jsx(_n,{activeAgentId:h??"",onSelectAgent:t=>{w(t),window.innerWidth<=768&&Q()}}):(()=>{if(!h)return e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Select an agent to inspect"})});const t=g.find(n=>n.id===h);return t?e.jsx(wn,{agent:t,onFocusAgent:n=>{w(n),window.innerWidth<=768&&Q()},onKillAgent:n=>b.killAgent(n)}):e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Agent not found"})})})()})]}),je&&e.jsx(vn,{url:je.url,name:je.name,onClose:()=>$e(null)}),Be&&e.jsx(Cn,{state:Be,onClose:()=>Fe(null)}),Z&&e.jsx(jn,{action:"clear-subordinates",selectedAgentId:Z.agentId,subordinateCount:Z.count,onClose:()=>re(null),onClearHistory:()=>{}}),e.jsx(Nn,{agent:h?g.find(t=>t.id===h)??null:null,isOpen:ke&&!!h,onClose:Ve}),e.jsx(Dt,{isOpen:$!==null,position:($==null?void 0:$.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:Zt,onClose:()=>We(null)}),e.jsx(Dt,{isOpen:f!==null,position:(f==null?void 0:f.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:Jt,onClose:()=>G(null)}),e.jsx(kn,{isOpen:B!==null,title:le("common:confirm.removeAgentTitle"),message:le("common:confirm.removeAgentMessage",{name:(B==null?void 0:B.name)??""}),confirmLabel:le("common:buttons.remove"),cancelLabel:le("common:buttons.cancel"),variant:"danger",onConfirm:()=>{B&&b.removeAgentFromServer(B.agentId)},onClose:()=>Ne(null)})]})}export{ta as FlatView};
|