tide-commander 1.151.1 → 1.152.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/assets/{BossLogsModal-BRXVs2zX.js → BossLogsModal-DZWUfQXs.js} +1 -1
  3. package/dist/assets/{BossSpawnModal-BqM8EeOS.js → BossSpawnModal-7IwzcqE7.js} +1 -1
  4. package/dist/assets/{ControlsModal-Do6sfsyz.js → ControlsModal-D8L1xD-H.js} +1 -1
  5. package/dist/assets/{DockerLogsModal-Clb8M2rL.js → DockerLogsModal-_zLe5UFl.js} +1 -1
  6. package/dist/assets/{EmbeddedEditor-DMFNGABf.js → EmbeddedEditor-gbiFXvt_.js} +1 -1
  7. package/dist/assets/{GmailOAuthSetup-D4-bi1Rt.js → GmailOAuthSetup-CcXTV3NP.js} +1 -1
  8. package/dist/assets/{GoogleOAuthSetup-D2Wyhnw0.js → GoogleOAuthSetup-wbETidgv.js} +1 -1
  9. package/dist/assets/{IframeModal-Zun7245W.js → IframeModal-a9E5UDBk.js} +1 -1
  10. package/dist/assets/{IntegrationsPanel-U8SIOpPt.js → IntegrationsPanel-BbGyluL0.js} +2 -2
  11. package/dist/assets/{LogViewerModal-BnFRX2hq.js → LogViewerModal-cnMAbNvY.js} +1 -1
  12. package/dist/assets/{MonitoringModal-CObUxMPl.js → MonitoringModal-DymqjenY.js} +1 -1
  13. package/dist/assets/{PM2LogsModal-DLf14YCU.js → PM2LogsModal-CEaCk-dt.js} +1 -1
  14. package/dist/assets/{RestoreArchivedAreaModal-Chg4LCCi.js → RestoreArchivedAreaModal-q_FFv7L6.js} +1 -1
  15. package/dist/assets/{Scene2DCanvas-CI_QSx9i.js → Scene2DCanvas-DOvVtiYO.js} +1 -1
  16. package/dist/assets/{SceneManager-SS5ahbEe.js → SceneManager-D0NdrG8K.js} +1 -1
  17. package/dist/assets/{SkillsPanel-DgPHgt3c.js → SkillsPanel-DpqD60Hy.js} +3 -3
  18. package/dist/assets/{SlackMultiInstanceSetup-iIjyM2kW.js → SlackMultiInstanceSetup-BdoALd_g.js} +1 -1
  19. package/dist/assets/{SpawnModal-BDgxHGYh.js → SpawnModal-DFFFH2kc.js} +1 -1
  20. package/dist/assets/{StatisticsModal-BuYkJsul.js → StatisticsModal-Dv_rYZDt.js} +1 -1
  21. package/dist/assets/{SubordinateAssignmentModal-D71lnDXZ.js → SubordinateAssignmentModal-CRCCI686.js} +1 -1
  22. package/dist/assets/{TriggerManagerPanel-DKiXSpSu.js → TriggerManagerPanel-DBN8IRa-.js} +1 -1
  23. package/dist/assets/{WorkflowEditorPanel-Dz6fJy8X.js → WorkflowEditorPanel-uQEvNTs2.js} +1 -1
  24. package/dist/assets/{area-logos-UIiMtczR.js → area-logos-CuVxToGM.js} +1 -1
  25. package/dist/assets/{index-DrUrcPns.js → index-8Ghh3AQ-.js} +1 -1
  26. package/dist/assets/{index-OQ-kWRyS.js → index-BHM8V4i-.js} +1 -1
  27. package/dist/assets/index-BNzYPyBm.css +1 -0
  28. package/dist/assets/{index-Ci67fScw.js → index-Blc4MwKs.js} +3 -3
  29. package/dist/assets/{index-BXnQVuar.js → index-D4iie3Vd.js} +1 -1
  30. package/dist/assets/{index-DgxY9KIr.js → index-DKnfLe7S.js} +1 -1
  31. package/dist/assets/{index-4BenQ81a.js → index-Dwll5Eyj.js} +4 -4
  32. package/dist/assets/{index-BZKCuVK4.js → index-HvyFhszc.js} +2 -2
  33. package/dist/assets/index-OkenGYC6.js +1 -0
  34. package/dist/assets/{index-BAvhLzXF.js → index-ipuWrg1S.js} +3 -3
  35. package/dist/assets/main-DpNJ8pqp.css +1 -0
  36. package/dist/assets/main-aIpEYDDR.js +289 -0
  37. package/dist/assets/{web-DSHhrW0P.js → web-1pfPwxBS.js} +1 -1
  38. package/dist/assets/{web-BSnmr2eo.js → web-D0JSbYeo.js} +1 -1
  39. package/dist/assets/{web-jsCXVjsN.js → web-DjgiLxvi.js} +1 -1
  40. package/dist/index.html +2 -2
  41. package/dist/locales/en/config.json +18 -0
  42. package/dist/src/packages/server/routes/system.js +110 -0
  43. package/package.json +1 -1
  44. package/dist/assets/index-CLA5nZlA.css +0 -1
  45. package/dist/assets/index-DvSK7N4C.js +0 -1
  46. package/dist/assets/main-CEq_Fs_S.js +0 -289
  47. package/dist/assets/main-CX7XkoZ4.css +0 -1
@@ -1,2 +1,2 @@
1
- import{r as h,j as e,i as b,k as m}from"./main-CEq_Fs_S.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const C=["public_channel","private_channel","im","mpim"],z={public_channel:"Public channels",private_channel:"Private channels",im:"1:1 DMs",mpim:"Group DMs"};function M(t){const i=new Set;for(const a of(t||"").split(",")){const f=a.trim();C.includes(f)&&i.add(f)}return i}function $(t){return C.filter(i=>t.has(i)).join(",")}const s={container:{display:"flex",gap:16,minHeight:420},list:{width:200,flexShrink:0,background:"var(--surface-1, #181825)",borderRadius:8,border:"1px solid var(--border, #313244)",padding:8,display:"flex",flexDirection:"column",gap:4},listItem:t=>({padding:"8px 10px",borderRadius:6,cursor:"pointer",background:t?"rgba(137,180,250,0.15)":"transparent",border:t?"1px solid rgba(137,180,250,0.3)":"1px solid transparent",color:t?"#cdd6f4":"#a6adc8",fontSize:13}),label:{fontWeight:500},sub:{fontSize:11,color:"#6c7086",marginTop:2},addBtn:{marginTop:8,padding:"8px 10px",borderRadius:6,background:"transparent",color:"#89b4fa",border:"1px dashed rgba(137,180,250,0.4)",cursor:"pointer",fontSize:13},editor:{flex:1,display:"flex",flexDirection:"column",gap:12},field:{display:"flex",flexDirection:"column",gap:4},fieldLabel:{fontSize:12,fontWeight:500,color:"#a6adc8"},fieldDesc:{fontSize:11,color:"#6c7086"},input:{padding:"8px 10px",background:"var(--surface-0, #1e1e2e)",border:"1px solid var(--border, #313244)",borderRadius:6,color:"#cdd6f4",fontSize:13,fontFamily:"inherit"},badge:t=>{const a={socket:"#a6e3a1",polling:"#89b4fa",none:"#6c7086"}[t]??"#6c7086";return{display:"inline-block",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:500,background:`${a}26`,color:a,border:`1px solid ${a}55`}},rowGap:{display:"flex",gap:12},buttons:{display:"flex",gap:8,marginTop:12},btnPrimary:{padding:"8px 16px",background:"#89b4fa",color:"#1e1e2e",border:"none",borderRadius:6,cursor:"pointer",fontWeight:500,fontSize:13},btnSecondary:{padding:"8px 16px",background:"transparent",color:"#cdd6f4",border:"1px solid var(--border, #313244)",borderRadius:6,cursor:"pointer",fontSize:13},btnDanger:{padding:"8px 16px",background:"transparent",color:"#f38ba8",border:"1px solid rgba(243,139,168,0.4)",borderRadius:6,cursor:"pointer",fontSize:13},alert:t=>({padding:"8px 12px",borderRadius:6,fontSize:12,background:t==="error"?"rgba(243,139,168,0.15)":"rgba(166,227,161,0.15)",color:t==="error"?"#f38ba8":"#a6e3a1",border:`1px solid ${t==="error"?"rgba(243,139,168,0.3)":"rgba(166,227,161,0.3)"}`})},j="/api/slack/instances";async function N(){const t=await b(m(j));if(!t.ok)throw new Error(`HTTP ${t.status}`);return(await t.json()).instances}async function B(t){const i=await b(m(`${j}/${encodeURIComponent(t)}/values`));if(!i.ok)throw new Error(`HTTP ${i.status}`);return(await i.json()).values}async function K(t,i){const a=await b(m(j),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:t,label:i})});if(!a.ok){const f=await a.json().catch(()=>({}));throw new Error(f.error||`HTTP ${a.status}`)}}async function H(t,i){const a=await b(m(`${j}/${encodeURIComponent(t)}`),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!a.ok){const f=await a.json().catch(()=>({}));throw new Error(f.error||`HTTP ${a.status}`)}}async function W(t){const i=await b(m(`${j}/${encodeURIComponent(t)}`),{method:"DELETE"});if(!i.ok){const a=await i.json().catch(()=>({}));throw new Error(a.error||`HTTP ${i.status}`)}}const V=({integration:t,onCancel:i})=>{const[a,f]=h.useState([]),[o,v]=h.useState("default"),[l,S]=h.useState(null),[T,_]=h.useState(null),[g,I]=h.useState(""),[D,A]=h.useState(!1),[L,E]=h.useState(!1),[w,x]=h.useState(null),y=h.useCallback(async()=>{try{const n=await N();f(n),!n.some(d=>d.id===o)&&n.length>0&&v(n[0].id)}catch(n){x({kind:"error",message:`Failed to load instances: ${n.message}`})}},[o]),k=h.useCallback(async()=>{if(o){A(!0);try{const n=await B(o);S(n),_(n);const r=a.find(d=>d.id===o);I((r==null?void 0:r.label)??o)}catch(n){x({kind:"error",message:`Failed to load instance: ${n.message}`})}finally{A(!1)}}},[o,a]);h.useEffect(()=>{y()},[y]),h.useEffect(()=>{k()},[k]);const P=async()=>{const n=window.prompt('Instance id (kebab-case, e.g. "personal", "team-bot"):');if(!n)return;const r=window.prompt("Display label:",n)||n;try{await K(n.trim(),r.trim()),await y(),v(n.trim()),x({kind:"success",message:`Created "${n}"`})}catch(d){x({kind:"error",message:d.message})}},O=async()=>{if(o!=="default"&&window.confirm(`Delete Slack instance "${o}"? This disconnects it and removes its config.`))try{await W(o),v("default"),await y(),x({kind:"success",message:"Instance deleted"})}catch(n){x({kind:"error",message:n.message})}},R=async()=>{if(!(!l||!T)){E(!0);try{const n={};Object.keys(l).forEach(p=>{const u=l[p];if(u!==T[p]){if((p==="SLACK_BOT_TOKEN"||p==="SLACK_APP_TOKEN")&&u==="********")return;n[p]=u}});const r=a.find(p=>p.id===o),d=r&&g.trim()&&g.trim()!==r.label;await H(o,{label:d?g.trim():void 0,values:Object.keys(n).length>0?n:void 0}),x({kind:"success",message:"Saved. Slack will reconnect with the new settings."}),await y(),await k()}catch(n){x({kind:"error",message:n.message})}finally{E(!1)}}},c=(n,r)=>{l&&S({...l,[n]:r})};return e.jsxs("div",{children:[e.jsx("div",{style:{marginBottom:12,fontSize:12,color:"#a6adc8"},children:"Add multiple Slack connections side-by-side. The default instance maps to your existing bot / token; add more for personal (xoxp-) tokens or additional workspaces."}),w&&e.jsx("div",{style:{...s.alert(w.kind),marginBottom:12},children:w.message}),e.jsxs("div",{style:s.container,children:[e.jsxs("div",{style:s.list,children:[a.map(n=>{var d,p,u;const r=((d=n.config)==null?void 0:d.currentMode)??"none";return e.jsxs("div",{style:s.listItem(n.id===o),onClick:()=>v(n.id),children:[e.jsx("div",{style:s.label,children:n.label}),e.jsxs("div",{style:s.sub,children:[e.jsx("span",{style:s.badge(r),children:r==="none"?"—":r}),(p=n.status)!=null&&p.connected?" • connected":(u=n.status)!=null&&u.error?" • error":" • idle"]})]},n.id)}),e.jsx("button",{type:"button",style:s.addBtn,onClick:P,children:"+ Add Instance"})]}),e.jsxs("div",{style:s.editor,children:[D&&e.jsx("div",{style:{color:"#6c7086",fontSize:13},children:"Loading…"}),!D&&l&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:s.field,children:[e.jsx("span",{style:s.fieldLabel,children:"Display label"}),e.jsx("input",{type:"text",style:s.input,value:g,onChange:n=>I(n.target.value),disabled:!1}),e.jsxs("span",{style:s.fieldDesc,children:["Shown in the instance list. Id is fixed: ",e.jsx("code",{children:o})]})]}),e.jsxs("div",{style:s.field,children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:l.enabled,onChange:n=>c("enabled",n.target.checked)}),e.jsx("span",{style:s.fieldLabel,children:"Enabled"})]}),e.jsx("span",{style:s.fieldDesc,children:"Toggle off to disconnect this instance without deleting its config."})]}),e.jsxs("div",{style:s.field,children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:l.mirrorOwnMessages,onChange:n=>c("mirrorOwnMessages",n.target.checked)}),e.jsx("span",{style:s.fieldLabel,children:"Mirror messages I send too"})]}),e.jsxs("span",{style:s.fieldDesc,children:["Capture your outgoing messages alongside incoming ones (logged as ",e.jsx("code",{children:"direction:outbound"}),"). Recommended for personal (xoxp-) tokens. Triggers do not fire on your own messages — that would loop."]})]}),e.jsxs("div",{style:s.field,children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:l.reactOnTrigger,onChange:n=>c("reactOnTrigger",n.target.checked)}),e.jsx("span",{style:s.fieldLabel,children:"Auto-react with 👀 on trigger"})]}),e.jsxs("span",{style:s.fieldDesc,children:["When a Slack trigger fires on an incoming message, react with ",e.jsx("code",{children:":eyes:"}),' as an "I saw it, working on it" ack. Turn off for accounts where the reaction is noisy. The server env ',e.jsx("code",{children:"SLACK_REACT_ON_TRIGGER=false"})," still disables it across all instances."]})]}),e.jsxs("div",{style:s.field,children:[e.jsx("span",{style:s.fieldLabel,children:"Slack Token"}),e.jsx("input",{type:"password",style:s.input,placeholder:"xoxb-... or xoxp-...",value:l.SLACK_BOT_TOKEN,onChange:n=>c("SLACK_BOT_TOKEN",n.target.value)}),e.jsxs("span",{style:s.fieldDesc,children:["Bot token (xoxb-) → Socket Mode. User token (xoxp-) → Web API polling (~30-60s lag). Stored encrypted under a per-instance key; leave as ",e.jsx("code",{children:"********"})," to keep the existing token."]})]}),e.jsxs("div",{style:s.field,children:[e.jsx("span",{style:s.fieldLabel,children:"App Token (Socket Mode only)"}),e.jsx("input",{type:"password",style:s.input,placeholder:"xapp-...",value:l.SLACK_APP_TOKEN,onChange:n=>c("SLACK_APP_TOKEN",n.target.value)}),e.jsx("span",{style:s.fieldDesc,children:"Required for xoxb- only. Leave blank for xoxp- (polling mode)."})]}),e.jsxs("div",{style:s.rowGap,children:[e.jsxs("div",{style:{...s.field,flex:1},children:[e.jsx("span",{style:s.fieldLabel,children:"Inbound Mode"}),e.jsxs("select",{style:s.input,value:l.authMode,onChange:n=>c("authMode",n.target.value),children:[e.jsx("option",{value:"auto",children:"Auto (from token prefix)"}),e.jsx("option",{value:"socket",children:"Socket Mode (xoxb-)"}),e.jsx("option",{value:"polling",children:"Polling (xoxp-)"})]})]}),e.jsxs("div",{style:{...s.field,flex:1},children:[e.jsx("span",{style:s.fieldLabel,children:"Default Channel"}),e.jsx("input",{type:"text",style:s.input,placeholder:"C0123456789",value:l.defaultChannelId,onChange:n=>c("defaultChannelId",n.target.value)})]})]}),e.jsxs("div",{style:s.rowGap,children:[e.jsxs("div",{style:{...s.field,flex:1},children:[e.jsx("span",{style:s.fieldLabel,children:"Polling Interval (s)"}),e.jsx("input",{type:"number",style:s.input,min:10,max:600,value:l.pollingIntervalSec,onChange:n=>c("pollingIntervalSec",Number(n.target.value))})]}),e.jsxs("div",{style:{...s.field,flex:1},children:[e.jsx("span",{style:s.fieldLabel,children:"Concurrency"}),e.jsx("input",{type:"number",style:s.input,min:1,max:8,value:l.pollingConcurrency,onChange:n=>c("pollingConcurrency",Number(n.target.value))})]}),e.jsxs("div",{style:{...s.field,flex:1},children:[e.jsx("span",{style:s.fieldLabel,children:"Backfill Cap (msgs)"}),e.jsx("input",{type:"number",style:s.input,min:1,max:1e3,value:l.pollingBackfillMessageCap,onChange:n=>c("pollingBackfillMessageCap",Number(n.target.value))})]}),e.jsxs("div",{style:{...s.field,flex:1},children:[e.jsx("span",{style:s.fieldLabel,children:"Min ms between calls"}),e.jsx("input",{type:"number",style:s.input,min:0,max:1e4,value:l.pollingMinMsBetweenCalls,onChange:n=>c("pollingMinMsBetweenCalls",Number(n.target.value))}),e.jsx("span",{style:{...s.fieldDesc,fontSize:11},children:"Throttle. 1500 ≈ 40 req/min. Set 0 to disable."})]})]}),e.jsxs("div",{style:s.field,children:[e.jsx("span",{style:s.fieldLabel,children:"Channel Types (poll all of these)"}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:12,marginTop:4},children:C.map(n=>{const d=M(l.pollingChannelTypes).has(n);return e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:6,cursor:"pointer",fontSize:13},children:[e.jsx("input",{type:"checkbox",checked:d,onChange:p=>{const u=new Set(M(l.pollingChannelTypes));p.target.checked?u.add(n):u.delete(n),c("pollingChannelTypes",$(u))}}),e.jsx("span",{children:z[n]})]},n)})}),e.jsx("span",{style:s.fieldDesc,children:"Determines which channel types are polled when the allowlist below is empty. Tick all four for full coverage. Heads-up: hundreds of channels at once can hit Slack's rate limit (~50 req/min) — use the allowlist to narrow down."})]}),e.jsxs("div",{style:s.field,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("span",{style:s.fieldLabel,children:"Channel Allowlist (optional)"}),l.pollingChannelAllowlist&&e.jsx("button",{type:"button",style:{...s.btnSecondary,padding:"4px 10px",fontSize:12},onClick:()=>c("pollingChannelAllowlist",""),title:"Clear the allowlist — fall back to polling all channels per the type checkboxes above.",children:"Include all (clear list)"})]}),e.jsx("textarea",{style:{...s.input,minHeight:60,fontFamily:"monospace",fontSize:12},placeholder:`C0123456789, G0987654321
1
+ import{r as h,j as e,i as b,k as m}from"./main-aIpEYDDR.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const C=["public_channel","private_channel","im","mpim"],z={public_channel:"Public channels",private_channel:"Private channels",im:"1:1 DMs",mpim:"Group DMs"};function M(t){const i=new Set;for(const a of(t||"").split(",")){const f=a.trim();C.includes(f)&&i.add(f)}return i}function $(t){return C.filter(i=>t.has(i)).join(",")}const s={container:{display:"flex",gap:16,minHeight:420},list:{width:200,flexShrink:0,background:"var(--surface-1, #181825)",borderRadius:8,border:"1px solid var(--border, #313244)",padding:8,display:"flex",flexDirection:"column",gap:4},listItem:t=>({padding:"8px 10px",borderRadius:6,cursor:"pointer",background:t?"rgba(137,180,250,0.15)":"transparent",border:t?"1px solid rgba(137,180,250,0.3)":"1px solid transparent",color:t?"#cdd6f4":"#a6adc8",fontSize:13}),label:{fontWeight:500},sub:{fontSize:11,color:"#6c7086",marginTop:2},addBtn:{marginTop:8,padding:"8px 10px",borderRadius:6,background:"transparent",color:"#89b4fa",border:"1px dashed rgba(137,180,250,0.4)",cursor:"pointer",fontSize:13},editor:{flex:1,display:"flex",flexDirection:"column",gap:12},field:{display:"flex",flexDirection:"column",gap:4},fieldLabel:{fontSize:12,fontWeight:500,color:"#a6adc8"},fieldDesc:{fontSize:11,color:"#6c7086"},input:{padding:"8px 10px",background:"var(--surface-0, #1e1e2e)",border:"1px solid var(--border, #313244)",borderRadius:6,color:"#cdd6f4",fontSize:13,fontFamily:"inherit"},badge:t=>{const a={socket:"#a6e3a1",polling:"#89b4fa",none:"#6c7086"}[t]??"#6c7086";return{display:"inline-block",padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:500,background:`${a}26`,color:a,border:`1px solid ${a}55`}},rowGap:{display:"flex",gap:12},buttons:{display:"flex",gap:8,marginTop:12},btnPrimary:{padding:"8px 16px",background:"#89b4fa",color:"#1e1e2e",border:"none",borderRadius:6,cursor:"pointer",fontWeight:500,fontSize:13},btnSecondary:{padding:"8px 16px",background:"transparent",color:"#cdd6f4",border:"1px solid var(--border, #313244)",borderRadius:6,cursor:"pointer",fontSize:13},btnDanger:{padding:"8px 16px",background:"transparent",color:"#f38ba8",border:"1px solid rgba(243,139,168,0.4)",borderRadius:6,cursor:"pointer",fontSize:13},alert:t=>({padding:"8px 12px",borderRadius:6,fontSize:12,background:t==="error"?"rgba(243,139,168,0.15)":"rgba(166,227,161,0.15)",color:t==="error"?"#f38ba8":"#a6e3a1",border:`1px solid ${t==="error"?"rgba(243,139,168,0.3)":"rgba(166,227,161,0.3)"}`})},j="/api/slack/instances";async function N(){const t=await b(m(j));if(!t.ok)throw new Error(`HTTP ${t.status}`);return(await t.json()).instances}async function B(t){const i=await b(m(`${j}/${encodeURIComponent(t)}/values`));if(!i.ok)throw new Error(`HTTP ${i.status}`);return(await i.json()).values}async function K(t,i){const a=await b(m(j),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:t,label:i})});if(!a.ok){const f=await a.json().catch(()=>({}));throw new Error(f.error||`HTTP ${a.status}`)}}async function H(t,i){const a=await b(m(`${j}/${encodeURIComponent(t)}`),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!a.ok){const f=await a.json().catch(()=>({}));throw new Error(f.error||`HTTP ${a.status}`)}}async function W(t){const i=await b(m(`${j}/${encodeURIComponent(t)}`),{method:"DELETE"});if(!i.ok){const a=await i.json().catch(()=>({}));throw new Error(a.error||`HTTP ${i.status}`)}}const V=({integration:t,onCancel:i})=>{const[a,f]=h.useState([]),[o,v]=h.useState("default"),[l,S]=h.useState(null),[T,_]=h.useState(null),[g,I]=h.useState(""),[D,A]=h.useState(!1),[L,E]=h.useState(!1),[w,x]=h.useState(null),y=h.useCallback(async()=>{try{const n=await N();f(n),!n.some(d=>d.id===o)&&n.length>0&&v(n[0].id)}catch(n){x({kind:"error",message:`Failed to load instances: ${n.message}`})}},[o]),k=h.useCallback(async()=>{if(o){A(!0);try{const n=await B(o);S(n),_(n);const r=a.find(d=>d.id===o);I((r==null?void 0:r.label)??o)}catch(n){x({kind:"error",message:`Failed to load instance: ${n.message}`})}finally{A(!1)}}},[o,a]);h.useEffect(()=>{y()},[y]),h.useEffect(()=>{k()},[k]);const P=async()=>{const n=window.prompt('Instance id (kebab-case, e.g. "personal", "team-bot"):');if(!n)return;const r=window.prompt("Display label:",n)||n;try{await K(n.trim(),r.trim()),await y(),v(n.trim()),x({kind:"success",message:`Created "${n}"`})}catch(d){x({kind:"error",message:d.message})}},O=async()=>{if(o!=="default"&&window.confirm(`Delete Slack instance "${o}"? This disconnects it and removes its config.`))try{await W(o),v("default"),await y(),x({kind:"success",message:"Instance deleted"})}catch(n){x({kind:"error",message:n.message})}},R=async()=>{if(!(!l||!T)){E(!0);try{const n={};Object.keys(l).forEach(p=>{const u=l[p];if(u!==T[p]){if((p==="SLACK_BOT_TOKEN"||p==="SLACK_APP_TOKEN")&&u==="********")return;n[p]=u}});const r=a.find(p=>p.id===o),d=r&&g.trim()&&g.trim()!==r.label;await H(o,{label:d?g.trim():void 0,values:Object.keys(n).length>0?n:void 0}),x({kind:"success",message:"Saved. Slack will reconnect with the new settings."}),await y(),await k()}catch(n){x({kind:"error",message:n.message})}finally{E(!1)}}},c=(n,r)=>{l&&S({...l,[n]:r})};return e.jsxs("div",{children:[e.jsx("div",{style:{marginBottom:12,fontSize:12,color:"#a6adc8"},children:"Add multiple Slack connections side-by-side. The default instance maps to your existing bot / token; add more for personal (xoxp-) tokens or additional workspaces."}),w&&e.jsx("div",{style:{...s.alert(w.kind),marginBottom:12},children:w.message}),e.jsxs("div",{style:s.container,children:[e.jsxs("div",{style:s.list,children:[a.map(n=>{var d,p,u;const r=((d=n.config)==null?void 0:d.currentMode)??"none";return e.jsxs("div",{style:s.listItem(n.id===o),onClick:()=>v(n.id),children:[e.jsx("div",{style:s.label,children:n.label}),e.jsxs("div",{style:s.sub,children:[e.jsx("span",{style:s.badge(r),children:r==="none"?"—":r}),(p=n.status)!=null&&p.connected?" • connected":(u=n.status)!=null&&u.error?" • error":" • idle"]})]},n.id)}),e.jsx("button",{type:"button",style:s.addBtn,onClick:P,children:"+ Add Instance"})]}),e.jsxs("div",{style:s.editor,children:[D&&e.jsx("div",{style:{color:"#6c7086",fontSize:13},children:"Loading…"}),!D&&l&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:s.field,children:[e.jsx("span",{style:s.fieldLabel,children:"Display label"}),e.jsx("input",{type:"text",style:s.input,value:g,onChange:n=>I(n.target.value),disabled:!1}),e.jsxs("span",{style:s.fieldDesc,children:["Shown in the instance list. Id is fixed: ",e.jsx("code",{children:o})]})]}),e.jsxs("div",{style:s.field,children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:l.enabled,onChange:n=>c("enabled",n.target.checked)}),e.jsx("span",{style:s.fieldLabel,children:"Enabled"})]}),e.jsx("span",{style:s.fieldDesc,children:"Toggle off to disconnect this instance without deleting its config."})]}),e.jsxs("div",{style:s.field,children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:l.mirrorOwnMessages,onChange:n=>c("mirrorOwnMessages",n.target.checked)}),e.jsx("span",{style:s.fieldLabel,children:"Mirror messages I send too"})]}),e.jsxs("span",{style:s.fieldDesc,children:["Capture your outgoing messages alongside incoming ones (logged as ",e.jsx("code",{children:"direction:outbound"}),"). Recommended for personal (xoxp-) tokens. Triggers do not fire on your own messages — that would loop."]})]}),e.jsxs("div",{style:s.field,children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:l.reactOnTrigger,onChange:n=>c("reactOnTrigger",n.target.checked)}),e.jsx("span",{style:s.fieldLabel,children:"Auto-react with 👀 on trigger"})]}),e.jsxs("span",{style:s.fieldDesc,children:["When a Slack trigger fires on an incoming message, react with ",e.jsx("code",{children:":eyes:"}),' as an "I saw it, working on it" ack. Turn off for accounts where the reaction is noisy. The server env ',e.jsx("code",{children:"SLACK_REACT_ON_TRIGGER=false"})," still disables it across all instances."]})]}),e.jsxs("div",{style:s.field,children:[e.jsx("span",{style:s.fieldLabel,children:"Slack Token"}),e.jsx("input",{type:"password",style:s.input,placeholder:"xoxb-... or xoxp-...",value:l.SLACK_BOT_TOKEN,onChange:n=>c("SLACK_BOT_TOKEN",n.target.value)}),e.jsxs("span",{style:s.fieldDesc,children:["Bot token (xoxb-) → Socket Mode. User token (xoxp-) → Web API polling (~30-60s lag). Stored encrypted under a per-instance key; leave as ",e.jsx("code",{children:"********"})," to keep the existing token."]})]}),e.jsxs("div",{style:s.field,children:[e.jsx("span",{style:s.fieldLabel,children:"App Token (Socket Mode only)"}),e.jsx("input",{type:"password",style:s.input,placeholder:"xapp-...",value:l.SLACK_APP_TOKEN,onChange:n=>c("SLACK_APP_TOKEN",n.target.value)}),e.jsx("span",{style:s.fieldDesc,children:"Required for xoxb- only. Leave blank for xoxp- (polling mode)."})]}),e.jsxs("div",{style:s.rowGap,children:[e.jsxs("div",{style:{...s.field,flex:1},children:[e.jsx("span",{style:s.fieldLabel,children:"Inbound Mode"}),e.jsxs("select",{style:s.input,value:l.authMode,onChange:n=>c("authMode",n.target.value),children:[e.jsx("option",{value:"auto",children:"Auto (from token prefix)"}),e.jsx("option",{value:"socket",children:"Socket Mode (xoxb-)"}),e.jsx("option",{value:"polling",children:"Polling (xoxp-)"})]})]}),e.jsxs("div",{style:{...s.field,flex:1},children:[e.jsx("span",{style:s.fieldLabel,children:"Default Channel"}),e.jsx("input",{type:"text",style:s.input,placeholder:"C0123456789",value:l.defaultChannelId,onChange:n=>c("defaultChannelId",n.target.value)})]})]}),e.jsxs("div",{style:s.rowGap,children:[e.jsxs("div",{style:{...s.field,flex:1},children:[e.jsx("span",{style:s.fieldLabel,children:"Polling Interval (s)"}),e.jsx("input",{type:"number",style:s.input,min:10,max:600,value:l.pollingIntervalSec,onChange:n=>c("pollingIntervalSec",Number(n.target.value))})]}),e.jsxs("div",{style:{...s.field,flex:1},children:[e.jsx("span",{style:s.fieldLabel,children:"Concurrency"}),e.jsx("input",{type:"number",style:s.input,min:1,max:8,value:l.pollingConcurrency,onChange:n=>c("pollingConcurrency",Number(n.target.value))})]}),e.jsxs("div",{style:{...s.field,flex:1},children:[e.jsx("span",{style:s.fieldLabel,children:"Backfill Cap (msgs)"}),e.jsx("input",{type:"number",style:s.input,min:1,max:1e3,value:l.pollingBackfillMessageCap,onChange:n=>c("pollingBackfillMessageCap",Number(n.target.value))})]}),e.jsxs("div",{style:{...s.field,flex:1},children:[e.jsx("span",{style:s.fieldLabel,children:"Min ms between calls"}),e.jsx("input",{type:"number",style:s.input,min:0,max:1e4,value:l.pollingMinMsBetweenCalls,onChange:n=>c("pollingMinMsBetweenCalls",Number(n.target.value))}),e.jsx("span",{style:{...s.fieldDesc,fontSize:11},children:"Throttle. 1500 ≈ 40 req/min. Set 0 to disable."})]})]}),e.jsxs("div",{style:s.field,children:[e.jsx("span",{style:s.fieldLabel,children:"Channel Types (poll all of these)"}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:12,marginTop:4},children:C.map(n=>{const d=M(l.pollingChannelTypes).has(n);return e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:6,cursor:"pointer",fontSize:13},children:[e.jsx("input",{type:"checkbox",checked:d,onChange:p=>{const u=new Set(M(l.pollingChannelTypes));p.target.checked?u.add(n):u.delete(n),c("pollingChannelTypes",$(u))}}),e.jsx("span",{children:z[n]})]},n)})}),e.jsx("span",{style:s.fieldDesc,children:"Determines which channel types are polled when the allowlist below is empty. Tick all four for full coverage. Heads-up: hundreds of channels at once can hit Slack's rate limit (~50 req/min) — use the allowlist to narrow down."})]}),e.jsxs("div",{style:s.field,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx("span",{style:s.fieldLabel,children:"Channel Allowlist (optional)"}),l.pollingChannelAllowlist&&e.jsx("button",{type:"button",style:{...s.btnSecondary,padding:"4px 10px",fontSize:12},onClick:()=>c("pollingChannelAllowlist",""),title:"Clear the allowlist — fall back to polling all channels per the type checkboxes above.",children:"Include all (clear list)"})]}),e.jsx("textarea",{style:{...s.input,minHeight:60,fontFamily:"monospace",fontSize:12},placeholder:`C0123456789, G0987654321
2
2
  C9999999999`,value:l.pollingChannelAllowlist,onChange:n=>c("pollingChannelAllowlist",n.target.value)}),e.jsx("span",{style:s.fieldDesc,children:'Comma- or newline-separated channel IDs. When set, polling restricts to these channels (plus DMs if "Always include DMs" is on). The Channel Types checkboxes above are ignored while an allowlist is active. Leave blank to fall back to polling all channels per the type checkboxes.'})]}),e.jsxs("div",{style:s.field,children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:l.pollingDmsAlways,onChange:n=>c("pollingDmsAlways",n.target.checked)}),e.jsx("span",{style:s.fieldLabel,children:"Always include DMs"})]}),e.jsx("span",{style:s.fieldDesc,children:"When the allowlist is set, still poll all 1:1 DMs (D-prefix). Default on. Turn off for strict allowlist-only mode."})]}),e.jsxs("div",{style:s.buttons,children:[e.jsx("button",{type:"button",style:s.btnPrimary,onClick:R,disabled:L,children:L?"Saving…":"Save & Reconnect"}),e.jsx("button",{type:"button",style:s.btnSecondary,onClick:i,children:"Close"}),o!=="default"&&e.jsx("button",{type:"button",style:{...s.btnDanger,marginLeft:"auto"},onClick:O,children:"Delete Instance"})]})]})]})]})]})};export{V as SlackMultiInstanceSetup,V as default};
@@ -1 +1 @@
1
- import{u as ns,b5 as as,b6 as ts,b7 as ls,b8 as os,r as t,_ as De,S as oe,b9 as is,ba as ie,A as Ie,k as ce,i as cs,s as v,n as rs,j as e,bb as ds,a9 as _e,bc as x,bd as ps,be as re,I as de,aT as T,aR as H,bf as ms,bg as J,aS as pe,bh as me,bi as us,$ as hs}from"./main-CEq_Fs_S.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function Le(d,j){const S=j.filter(C=>!d.has(C));return S.length===0?`${j[Math.floor(Math.random()*j.length)]}-${Date.now()%1e3}`:S[Math.floor(Math.random()*S.length)]}function gs({isOpen:d,onClose:j,onSpawnStart:S,onSpawnEnd:C,spawnPosition:$e,spawnAreaId:N}){const{t:n}=ns(["terminal","common"]),P=as(),p=ts(),ue=ls(),X=ue.length>0?ue:os,[m,b]=t.useState(""),[k,F]=t.useState(()=>De(oe.LAST_CWD)),[i,M]=t.useState("scout"),[he,I]=t.useState(!1),[Te,R]=t.useState(!1),[we,Y]=t.useState(!1),[xe,fe]=t.useState(""),[y,Q]=t.useState([]),[E,O]=t.useState(null),[Pe,ge]=t.useState(!1),[_,je]=t.useState(""),[h,Fe]=t.useState(""),[U,Re]=t.useState(!1),[z,Oe]=t.useState("bypass"),[o,G]=t.useState("claude"),[f,A]=t.useState({fullAuto:!0,sandbox:"workspace-write",approvalMode:"on-request",search:!1}),[V,Z]=t.useState(new Set),[ee,Ne]=t.useState("claude-opus-4-8[1m]"),[se,be]=t.useState("xHigh"),[ne,Ue]=t.useState("gpt-5.6-luna"),[ae,ze]=t.useState("minimax/MiniMax-M1-80k"),[te,Ge]=t.useState(is),[ve,qe]=t.useState(""),[D,We]=t.useState(""),q=t.useRef(null),Se=t.useRef(!1),L=t.useCallback(()=>{window.__spawnModalAreaContext=null},[]),w=t.useMemo(()=>P.filter(s=>s.enabled),[P]),Be=["full-notifications","streaming-exec","task-label","report-task-to-boss","agent-tracking","agent-memory","send-message-to-agent"];t.useEffect(()=>{if(d&&!Se.current){if(w.length>0){const l=w.filter(r=>Be.includes(r.slug)).map(r=>r.id);l.length>0&&Z(new Set(l))}const a=De(oe.DEFAULT_AGENT_CLASS);if(a==="random"){const r=[...Object.keys(us),...p.map(u=>u.id)];M(r[Math.floor(Math.random()*r.length)])}else M(a||"scout")}Se.current=d},[d,w,p]);const Ce=t.useMemo(()=>{if(!D.trim())return w;const s=D.toLowerCase();return w.filter(a=>a.name.toLowerCase().includes(s)||a.description.toLowerCase().includes(s)||a.slug.toLowerCase().includes(s))},[w,D]),Ke=t.useCallback(s=>{Z(a=>{const l=new Set(a);return l.has(s)?l.delete(s):l.add(s),l})},[]);t.useMemo(()=>w.filter(s=>s.assignedAgentClasses.includes(i)),[w,i]);const He=t.useMemo(()=>{var a;const s=p.find(l=>l.id===i);return(a=s==null?void 0:s.defaultSkillIds)!=null&&a.length?P.filter(l=>s.defaultSkillIds.includes(l.id)):[]},[p,i,P]),ke=t.useMemo(()=>{if(!_.trim())return y;const s=_.toLowerCase();return y.filter(a=>a.sessionId.toLowerCase().includes(s)||a.projectPath.toLowerCase().includes(s)||a.firstMessage&&a.firstMessage.toLowerCase().includes(s))},[y,_]),W=t.useMemo(()=>{if(!h.trim())return p;const s=h.toLowerCase();return p.filter(a=>a.name.toLowerCase().includes(s)||a.description.toLowerCase().includes(s)||a.id.toLowerCase().includes(s))},[p,h]),B=t.useMemo(()=>{if(!h.trim())return ie;const s=h.toLowerCase();return ie.filter(a=>{const l=Ie[a.id];return a.name.toLowerCase().includes(s)||a.id.toLowerCase().includes(s)||l.description.toLowerCase().includes(s)})},[h]);t.useEffect(()=>{if(!d||!h.trim())return;const s=[...W.map(a=>a.id),...B.map(a=>a.id)];s.length===1&&s[0]!==i&&M(s[0])},[d,h,W,B,i]);const c=t.useMemo(()=>p.find(s=>s.id===i),[p,i]),Je=t.useMemo(()=>{if(c!=null&&c.model)return c.model},[c]),Xe=t.useMemo(()=>{if(c!=null&&c.customModelPath)return ce(`/api/custom-models/${c.id}`)},[c]),Ye=c==null?void 0:c.modelScale,Qe=t.useMemo(()=>c?"scout":i,[i,c]),K=t.useCallback(async s=>{ge(!0);try{const a=s?ce(`/api/agents/claude-sessions?cwd=${encodeURIComponent(s)}`):ce("/api/agents/claude-sessions"),r=await(await cs(a)).json();Q(r.sessions||[])}catch(a){console.error("Failed to fetch sessions:",a),Q([])}finally{ge(!1)}},[]);t.useEffect(()=>{d?K(k||void 0):(Q([]),O(null),je(""))},[d,K]),t.useEffect(()=>{if(!d)return;const s=setTimeout(()=>{K(k||void 0),O(null)},300);return()=>clearTimeout(s)},[k,d,K]),t.useEffect(()=>{if(!d||!N)return;const s=v.getState().areas.get(N);if(s!=null&&s.directories&&s.directories.length>0){F(s.directories[0]);return}const a=Array.from(v.getState().agents.values()).filter(g=>{var $;return(($=v.getAreaForAgent(g.id))==null?void 0:$.id)===N&&g.cwd});if(a.length===0)return;const l=new Map;for(const g of a)l.set(g.cwd,(l.get(g.cwd)||0)+1);let r="",u=0;for(const[g,$]of l)$>u&&(r=g,u=$);r&&F(r)},[d,N]),t.useEffect(()=>{if(d){const s=new Set(Array.from(v.getState().agents.values()).map(u=>u.name)),a=Le(s,X),l=p.find(u=>u.id===i),r=l?`${l.name} ${a}`:a;b(r),q.current&&(q.current.focus(),q.current.select())}},[d,X]),t.useEffect(()=>{if(!d)return;const s=p.find(a=>a.id===i);if(s){const a=p.find(l=>m.startsWith(l.name+" "));if(a){const l=m.substring(a.name.length+1);b(`${s.name} ${l}`)}else b(`${s.name} ${m}`)}else{const a=p.find(l=>m.startsWith(l.name+" "));if(a){const l=m.substring(a.name.length+1);b(l)}}},[i]),t.useEffect(()=>{i==="boss"&&Ne("claude-opus-4-8[1m]")},[i]);const Ve=()=>{var r;console.log("[SpawnModal] handleSpawn called"),R(!1);const s=E&&((r=y.find(u=>u.sessionId===E))==null?void 0:r.projectPath)||k;if(console.log("[SpawnModal] Effective CWD:",s),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"),!s.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(v.getState().agents.values()).map(g=>g.name));b(Le(u,X));return}hs(oe.LAST_CWD,s),I(!0),S();const a=Array.from(V),l=ve.trim()||void 0;console.log("[SpawnModal] Calling store.spawnAgent with:",{name:m.trim(),class:i,cwd:s.trim(),sessionId:E||void 0,useChrome:o==="claude"?U:!1,permissionMode:z,provider:o,codexConfig:o==="codex"?f:void 0,codexModel:o==="codex"?ne:void 0,opencodeModel:o==="opencode"?ae:void 0,grokModel:o==="grok"?te:void 0,initialSkillIds:a,model:o==="claude"?ee:void 0,customInstructions:l?`${l.length} chars`:void 0,spawnAreaId:N||void 0}),window.__spawnModalAreaContext=N?{areaId:N}:null,v.spawnAgent(m.trim(),i,s.trim(),$e||void 0,E||void 0,o==="claude"?U:!1,z,a,o,o==="codex"?f:void 0,o==="codex"?ne:void 0,o==="claude"?ee:void 0,l,o==="claude"||o==="grok"?se:void 0,o==="opencode"?ae:void 0,o==="grok"?te:void 0)},Me=()=>{console.log("[SpawnModal] Agent creation successful"),I(!1),b(""),Z(new Set),L(),C(),j()},ye=()=>{console.error("[SpawnModal] Agent creation failed"),I(!1),R(!0),L(),C()},Ee=s=>{console.log("[SpawnModal] Directory not found:",s),I(!1),fe(s),Y(!0),C()},Ae=()=>{Y(!1),I(!0),S(),v.createDirectoryAndSpawn(xe,m.trim(),i)},le=()=>{Y(!1),fe(""),L()};t.useEffect(()=>(window.__spawnModalSuccess=Me,window.__spawnModalError=ye,window.__spawnModalDirNotFound=Ee,()=>{L(),delete window.__spawnModalSuccess,delete window.__spawnModalError,delete window.__spawnModalDirNotFound}),[m,i,Me,ye,Ee,L]);const{handleMouseDown:Ze,handleClick:es}=rs(j),ss=s=>{s.key==="Escape"&&j()};return!d&&!we?null:we?e.jsx("div",{className:"modal-overlay visible",onClick:le,onKeyDown:s=>{s.key==="Escape"&&le(),s.key==="Enter"&&Ae()},children:e.jsxs("div",{className:"modal confirm-modal",onClick:s=>s.stopPropagation(),children:[e.jsx("div",{className:"modal-header",children:n("terminal:spawn.directoryNotFound")}),e.jsxs("div",{className:"modal-body confirm-modal-body",children:[e.jsx("p",{children:n("terminal:spawn.directoryNotExist")}),e.jsx("code",{className:"confirm-modal-path",children:xe}),e.jsx("p",{children:n("terminal:spawn.wouldYouCreate")})]}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("button",{className:"btn btn-secondary",onClick:le,children:n("common:buttons.cancel")}),e.jsx("button",{className:"btn btn-primary",onClick:Ae,autoFocus:!0,children:n("terminal:spawn.createDirectory")})]})]})}):e.jsx("div",{className:`modal-overlay ${d?"visible":""}`,onMouseDown:Ze,onClick:es,onKeyDown:ss,children:e.jsxs("div",{className:"modal spawn-modal",children:[e.jsx("div",{className:"modal-header",children:n("terminal:spawn.deployTitle")}),e.jsxs("div",{className:"modal-body spawn-modal-body",children:[e.jsxs("div",{className:"spawn-section",children:[e.jsxs("div",{className:"spawn-section-header",children:[e.jsx("h4",{className:"spawn-section-title",children:n("terminal:spawn.agentClass")}),e.jsx("span",{className:"spawn-section-hint",children:(c==null?void 0:c.name)||i})]}),e.jsxs("div",{className:"spawn-top-section",children:[e.jsxs("div",{className:"spawn-preview-compact",children:[e.jsx(ds,{agentClass:Qe,modelFile:Je,customModelUrl:Xe,modelScale:Ye,width:110,height:130}),e.jsx("div",{className:"spawn-preview-label",children:(c==null?void 0:c.name)||i})]}),e.jsxs("div",{className:"spawn-class-section",children:[p.length+ie.length>6&&e.jsx("input",{type:"text",className:"spawn-input class-search-input",placeholder:n("terminal:spawn.filterClasses"),value:h,onChange:s=>Fe(s.target.value)}),e.jsxs("div",{className:"class-selector-inline",children:[W.map(s=>e.jsxs("button",{className:`class-chip ${i===s.id?"selected":""}`,onClick:()=>M(s.id),title:s.description,children:[e.jsx(_e,{classId:s.id,size:18,className:"class-chip-icon"}),e.jsx("span",{className:"class-chip-name",children:s.name})]},s.id)),B.map(s=>{const a=Ie[s.id];return e.jsxs("button",{className:`class-chip ${i===s.id?"selected":""}`,onClick:()=>M(s.id),title:a.description,children:[e.jsx(_e,{classId:s.id,size:18,className:"class-chip-icon"}),e.jsx("span",{className:"class-chip-name",children:s.name})]},s.id)}),h&&W.length===0&&B.length===0&&e.jsx("div",{className:"class-search-empty",children:n("terminal:spawn.noClassesMatch",{query:h})})]})]})]}),e.jsxs("div",{className:"spawn-form-row",children:[e.jsxs("div",{className:"spawn-field",children:[e.jsx("label",{className:"spawn-label",children:n("common:labels.name")}),e.jsx("input",{ref:q,type:"text",className:"spawn-input",placeholder:n("terminal:spawn.agentNamePlaceholder"),value:m,onChange:s=>b(s.target.value)})]}),e.jsxs("div",{className:"spawn-field spawn-field-wide",children:[e.jsxs("label",{className:"spawn-label",children:[n("terminal:spawn.workingDir"),e.jsx(x,{text:n("terminal:spawn.helpWorkingDir"),title:n("terminal:spawn.workingDir"),position:"top",size:"sm"})]}),e.jsx(ps,{value:k,onChange:s=>{F(s),R(!1)},placeholder:n("terminal:spawn.workingDirPlaceholder"),className:`spawn-input ${Te?"error":""}`,directoriesOnly:!0})]})]})]}),e.jsxs("div",{className:"spawn-section",children:[e.jsx("div",{className:"spawn-section-header",children:e.jsx("h4",{className:"spawn-section-title",children:n("terminal:spawn.selectRuntime")})}),e.jsxs("div",{className:"spawn-form-row",children:[e.jsxs("div",{className:"spawn-field",children:[e.jsxs("label",{className:"spawn-label",children:[n("common:labels.runtime"),e.jsx(x,{text:n("terminal:spawn.helpRuntime"),title:n("terminal:spawn.runtimeTitle"),position:"top",size:"sm"})]}),e.jsxs("div",{className:"spawn-select-row",children:[e.jsxs("button",{className:`spawn-select-btn ${o==="claude"?"selected":""}`,onClick:()=>G("claude"),title:n("terminal:spawn.useClaudeCli"),children:[e.jsx("img",{src:"/assets/claude.ico",alt:"Claude",className:"spawn-provider-icon"}),e.jsx("span",{children:"Claude"})]}),e.jsxs("button",{className:`spawn-select-btn ${o==="codex"?"selected":""}`,onClick:()=>G("codex"),title:n("terminal:spawn.useCodexCli"),children:[e.jsx("img",{src:"/assets/codex.ico",alt:"Codex",className:"spawn-provider-icon"}),e.jsx("span",{children:"Codex"})]}),e.jsxs("button",{className:`spawn-select-btn spawn-select-btn--opencode ${o==="opencode"?"selected":""}`,onClick:()=>G("opencode"),title:"Use OpenCode CLI (multi-provider)",children:[e.jsx("img",{src:"/assets/opencode.svg",alt:"OpenCode",className:"spawn-provider-icon"}),e.jsx("span",{children:"OpenCode"})]}),e.jsxs("button",{className:`spawn-select-btn spawn-select-btn--grok ${o==="grok"?"selected":""}`,onClick:()=>G("grok"),title:"Use Grok CLI (headless)",children:[e.jsx("img",{src:"/assets/grok.png",alt:"Grok",className:"spawn-provider-icon"}),e.jsx("span",{children:"Grok"})]})]})]}),e.jsxs("div",{className:"spawn-field",children:[e.jsxs("label",{className:"spawn-label",children:[n("common:labels.permissions"),e.jsx(x,{text:n("terminal:spawn.helpPermission"),title:n("terminal:spawn.permissionMode"),position:"top",size:"sm"})]}),e.jsx("div",{className:"spawn-select-row",children:Object.keys(re).map(s=>e.jsxs("button",{className:`spawn-select-btn ${z===s?"selected":""}`,onClick:()=>Oe(s),title:re[s].description,children:[e.jsx("span",{children:e.jsx(de,{name:s==="bypass"?"bolt":"lock",size:12})}),e.jsx("span",{children:re[s].label})]},s))})]})]}),e.jsx("div",{className:"spawn-form-row",children:e.jsxs("div",{className:"spawn-field",children:[e.jsxs("label",{className:"spawn-label",children:[n("common:labels.model"),e.jsx(x,{text:n("terminal:spawn.helpModel"),title:n("terminal:spawn.modelTitle"),position:"top",size:"sm"})]}),o==="claude"?e.jsx("div",{className:"spawn-select-row spawn-select-row--wrap",children:Object.keys(T).filter(s=>!T[s].deprecated).map(s=>e.jsxs("button",{className:`spawn-select-btn ${ee===s?"selected":""}`,onClick:()=>Ne(s),title:T[s].description,children:[e.jsx("span",{children:T[s].icon}),e.jsx("span",{children:T[s].label})]},s))}):o==="codex"?e.jsx("div",{className:"spawn-select-row spawn-select-row--codex-models",children:Object.keys(H).map(s=>e.jsxs("button",{className:`spawn-select-btn ${ne===s?"selected":""}`,onClick:()=>Ue(s),title:H[s].description,children:[e.jsx("span",{children:H[s].icon}),e.jsx("span",{children:H[s].label})]},s))}):o==="opencode"?e.jsx(ms,{value:ae,onChange:ze,inputId:"spawn-opencode-model"}):o==="grok"?e.jsx("div",{className:"spawn-select-row spawn-select-row--wrap",children:Object.keys(J).map(s=>e.jsxs("button",{className:`spawn-select-btn ${te===s?"selected":""}`,onClick:()=>Ge(s),title:J[s].description,children:[e.jsx("span",{children:J[s].icon}),e.jsx("span",{children:J[s].label})]},s))}):e.jsx("div",{className:"spawn-inline-hint",children:n("terminal:spawn.chooseCodexModel")})]})}),e.jsxs("div",{className:"spawn-form-row",children:[(o==="claude"||o==="grok")&&e.jsxs("div",{className:"spawn-field",children:[e.jsx("label",{className:"spawn-label",children:"Effort"}),e.jsxs("div",{className:"spawn-select-row spawn-select-row--effort",children:[e.jsx("button",{className:`spawn-select-btn spawn-select-btn--compact ${se===void 0?"selected":""}`,onClick:()=>be(void 0),title:"Use default effort level",children:e.jsx("span",{children:"Default"})}),Object.keys(pe).map(s=>e.jsx("button",{className:`spawn-select-btn spawn-select-btn--compact ${se===s?"selected":""}`,onClick:()=>be(s),title:pe[s].description,children:e.jsx("span",{children:pe[s].label})},s))]})]}),e.jsxs("div",{className:"spawn-field",children:[e.jsx("label",{className:"spawn-label",children:n("terminal:spawn.browser")}),e.jsxs("label",{className:"spawn-checkbox",children:[e.jsx("input",{type:"checkbox",checked:U,onChange:s=>Re(s.target.checked),disabled:o!=="claude"}),e.jsxs("span",{children:[e.jsx(de,{name:"globe",size:12})," ",n("terminal:spawn.chromeBrowser")]}),e.jsx(x,{text:n(o==="claude"?"terminal:spawn.helpChrome":"terminal:spawn.helpChromeDisabled"),title:n("terminal:spawn.chromeBrowser"),position:"top",size:"sm"})]})]})]}),o==="codex"&&e.jsxs("div",{className:"codex-config-section",children:[e.jsx("div",{className:"codex-config-title",children:n("terminal:spawn.codex.configuration")}),e.jsxs("div",{className:"codex-config-options",children:[e.jsxs("div",{className:"codex-option-group",children:[e.jsxs("label",{className:"spawn-checkbox",children:[e.jsx("input",{type:"checkbox",checked:f.fullAuto!==!1,onChange:s=>A(a=>({...a,fullAuto:s.target.checked}))}),e.jsx("span",{children:n("terminal:spawn.codex.fullAuto")}),e.jsx(x,{text:n("terminal:spawn.helpFullAuto"),title:n("terminal:spawn.fullAutoTitle"),position:"top",size:"sm"})]}),e.jsxs("label",{className:"spawn-checkbox",children:[e.jsx("input",{type:"checkbox",checked:!!f.search,onChange:s=>A(a=>({...a,search:s.target.checked}))}),e.jsx("span",{children:n("terminal:spawn.codex.search")}),e.jsx(x,{text:n("terminal:spawn.helpSearch"),title:n("terminal:spawn.searchTitle"),position:"top",size:"sm"})]})]}),f.fullAuto===!1&&e.jsxs("div",{className:"codex-option-group",children:[e.jsx("div",{className:"codex-option-header",children:n("terminal:spawn.codex.restrictions")}),e.jsxs("select",{className:"spawn-input codex-select",value:f.sandbox||"workspace-write",onChange:s=>A(a=>({...a,sandbox:s.target.value})),children:[e.jsxs("option",{value:"read-only",children:["📖 ",n("terminal:spawn.codex.sandboxReadOnly")]}),e.jsxs("option",{value:"workspace-write",children:["✏️ ",n("terminal:spawn.codex.sandboxWorkspaceWrite")]}),e.jsxs("option",{value:"danger-full-access",children:["⚡ ",n("terminal:spawn.codex.sandboxDangerFullAccess")]})]}),e.jsxs("select",{className:"spawn-input codex-select",value:f.approvalMode||"on-request",onChange:s=>A(a=>({...a,approvalMode:s.target.value})),children:[e.jsxs("option",{value:"untrusted",children:["🔒 ",n("terminal:spawn.codex.approvalsUntrusted")]}),e.jsxs("option",{value:"on-failure",children:["⚠️ ",n("terminal:spawn.codex.approvalsOnFailure")]}),e.jsxs("option",{value:"on-request",children:["🤔 ",n("terminal:spawn.codex.approvalsOnRequest")]}),e.jsxs("option",{value:"never",children:["✅ ",n("terminal:spawn.codex.approvalsNever")]})]})]}),e.jsxs("div",{className:"codex-option-group",children:[e.jsx("div",{className:"codex-option-header",children:n("terminal:spawn.codex.profile")}),e.jsx("input",{type:"text",className:"spawn-input codex-profile-input",placeholder:n("terminal:spawn.codex.profilePlaceholder"),value:f.profile||"",onChange:s=>A(a=>({...a,profile:s.target.value||void 0}))})]}),e.jsxs("div",{className:"codex-option-group",children:[e.jsx("div",{className:"codex-option-header",children:n("terminal:spawn.codex.reasoningEffort")}),e.jsxs("select",{className:"spawn-input codex-select",value:f.reasoningEffort||"",onChange:s=>A(a=>({...a,reasoningEffort:s.target.value||void 0})),children:[e.jsx("option",{value:"",children:n("terminal:spawn.codex.reasoningEffortDefault")}),Object.keys(me).map(s=>e.jsxs("option",{value:s,children:[me[s].icon," ",me[s].label]},s))]})]})]})]})]}),w.length>0&&e.jsxs("div",{className:"spawn-section spawn-skills-section",children:[e.jsxs("div",{className:"spawn-section-header",children:[e.jsxs("h4",{className:"spawn-section-title",children:[n("terminal:spawn.skills"),e.jsx(x,{text:n("terminal:spawn.helpSkills"),title:n("terminal:spawn.skillsTitle"),position:"top",size:"sm"})]}),e.jsxs("span",{className:"spawn-section-hint",children:[V.size," selected · ",n("common:labels.optional")]})]}),w.length>6&&e.jsx("input",{type:"text",className:"spawn-input skill-search-input",placeholder:n("terminal:spawn.filterSkills"),value:D,onChange:s=>We(s.target.value)}),e.jsxs("div",{className:"spawn-skills-inline",children:[Ce.map(s=>{const a=V.has(s.id);return He.some(r=>r.id===s.id)?null:e.jsxs("button",{className:`spawn-skill-chip ${a?"selected":""}`,onClick:()=>Ke(s.id),title:s.description,children:[a&&e.jsx("span",{className:"spawn-skill-check",children:e.jsx(de,{name:"check",size:10})}),e.jsx("span",{children:s.name}),s.builtin&&e.jsx("span",{className:"spawn-skill-builtin",children:"TC"})]},s.id)}),D&&Ce.length===0&&e.jsx("div",{className:"skill-search-empty",children:n("terminal:spawn.noSkillsMatch",{query:D})})]})]}),e.jsxs("details",{className:"spawn-advanced",children:[e.jsxs("summary",{children:[n("terminal:spawn.customInstructions")," & ",n("terminal:spawn.linkSession")]}),e.jsxs("div",{className:"spawn-advanced-body",children:[e.jsxs("div",{className:"spawn-custom-instructions-section",children:[e.jsxs("label",{className:"spawn-label",children:[n("terminal:spawn.customInstructions")," ",e.jsxs("span",{className:"spawn-label-hint",children:["(",n("common:labels.optional"),")"]}),e.jsx(x,{text:n("terminal:spawn.helpCustomInstructions"),title:n("terminal:spawn.customInstructions"),position:"top",size:"sm"})]}),e.jsx("textarea",{className:"spawn-input spawn-textarea",placeholder:n("terminal:spawn.customInstructionsPlaceholder"),value:ve,onChange:s=>qe(s.target.value),rows:3})]}),e.jsxs("div",{className:"spawn-sessions-section",children:[e.jsxs("label",{className:"spawn-label",children:[n("terminal:spawn.linkSession")," ",e.jsxs("span",{className:"spawn-label-hint",children:["(",n("common:labels.optional"),")"]}),e.jsx(x,{text:n("terminal:spawn.helpLinkSession"),title:n("terminal:spawn.linkSessionTitle"),position:"top",size:"sm"})]}),y.length>0&&e.jsx("input",{type:"text",className:"spawn-input session-search-input",placeholder:n("terminal:spawn.searchSessions"),value:_,onChange:s=>je(s.target.value)}),e.jsx("div",{className:"sessions-list",children:Pe?e.jsx("div",{className:"sessions-loading",children:n("terminal:spawn.loadingSessions")}):y.length===0?e.jsx("div",{className:"sessions-empty",children:n("terminal:spawn.noSessions")}):ke.length===0?e.jsx("div",{className:"sessions-empty",children:n("terminal:spawn.noSessionsMatch",{query:_})}):ke.map(s=>{const a=E===s.sessionId,l=Date.now()-new Date(s.lastModified).getTime(),r=l<6e4?n("common:time.justNow"):l<36e5?n("common:time.minutesAgo",{count:Math.floor(l/6e4)}):l<864e5?n("common:time.hoursAgo",{count:Math.floor(l/36e5)}):n("common:time.daysAgo",{count:Math.floor(l/864e5)});return e.jsxs("div",{className:`session-item ${a?"selected":""}`,onClick:()=>{a?O(null):(O(s.sessionId),F(s.projectPath))},children:[e.jsxs("div",{className:"session-item-header",children:[e.jsx("span",{className:"session-item-path",children:s.projectPath}),e.jsx("span",{className:"session-item-age",children:r})]}),e.jsx("div",{className:"session-item-preview",children:s.firstMessage||n("terminal:spawn.messagesCount",{count:s.messageCount})})]},s.sessionId)})})]})]})]})]}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("button",{className:"btn btn-secondary",onClick:j,children:n("common:buttons.cancel")}),e.jsx("button",{className:"btn btn-primary",onClick:Ve,disabled:he,children:n(he?"common:buttons.deploying":"common:buttons2.deploy")})]})]})})}export{gs as SpawnModal};
1
+ import{u as ns,b5 as as,b6 as ts,b7 as ls,b8 as os,r as t,_ as De,S as oe,b9 as is,ba as ie,A as Ie,k as ce,i as cs,s as v,n as rs,j as e,bb as ds,a9 as _e,bc as x,bd as ps,be as re,I as de,aT as T,aR as H,bf as ms,bg as J,aS as pe,bh as me,bi as us,$ as hs}from"./main-aIpEYDDR.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function Le(d,j){const S=j.filter(C=>!d.has(C));return S.length===0?`${j[Math.floor(Math.random()*j.length)]}-${Date.now()%1e3}`:S[Math.floor(Math.random()*S.length)]}function gs({isOpen:d,onClose:j,onSpawnStart:S,onSpawnEnd:C,spawnPosition:$e,spawnAreaId:N}){const{t:n}=ns(["terminal","common"]),P=as(),p=ts(),ue=ls(),X=ue.length>0?ue:os,[m,b]=t.useState(""),[k,F]=t.useState(()=>De(oe.LAST_CWD)),[i,M]=t.useState("scout"),[he,I]=t.useState(!1),[Te,R]=t.useState(!1),[we,Y]=t.useState(!1),[xe,fe]=t.useState(""),[y,Q]=t.useState([]),[E,O]=t.useState(null),[Pe,ge]=t.useState(!1),[_,je]=t.useState(""),[h,Fe]=t.useState(""),[U,Re]=t.useState(!1),[z,Oe]=t.useState("bypass"),[o,G]=t.useState("claude"),[f,A]=t.useState({fullAuto:!0,sandbox:"workspace-write",approvalMode:"on-request",search:!1}),[V,Z]=t.useState(new Set),[ee,Ne]=t.useState("claude-opus-4-8[1m]"),[se,be]=t.useState("xHigh"),[ne,Ue]=t.useState("gpt-5.6-luna"),[ae,ze]=t.useState("minimax/MiniMax-M1-80k"),[te,Ge]=t.useState(is),[ve,qe]=t.useState(""),[D,We]=t.useState(""),q=t.useRef(null),Se=t.useRef(!1),L=t.useCallback(()=>{window.__spawnModalAreaContext=null},[]),w=t.useMemo(()=>P.filter(s=>s.enabled),[P]),Be=["full-notifications","streaming-exec","task-label","report-task-to-boss","agent-tracking","agent-memory","send-message-to-agent"];t.useEffect(()=>{if(d&&!Se.current){if(w.length>0){const l=w.filter(r=>Be.includes(r.slug)).map(r=>r.id);l.length>0&&Z(new Set(l))}const a=De(oe.DEFAULT_AGENT_CLASS);if(a==="random"){const r=[...Object.keys(us),...p.map(u=>u.id)];M(r[Math.floor(Math.random()*r.length)])}else M(a||"scout")}Se.current=d},[d,w,p]);const Ce=t.useMemo(()=>{if(!D.trim())return w;const s=D.toLowerCase();return w.filter(a=>a.name.toLowerCase().includes(s)||a.description.toLowerCase().includes(s)||a.slug.toLowerCase().includes(s))},[w,D]),Ke=t.useCallback(s=>{Z(a=>{const l=new Set(a);return l.has(s)?l.delete(s):l.add(s),l})},[]);t.useMemo(()=>w.filter(s=>s.assignedAgentClasses.includes(i)),[w,i]);const He=t.useMemo(()=>{var a;const s=p.find(l=>l.id===i);return(a=s==null?void 0:s.defaultSkillIds)!=null&&a.length?P.filter(l=>s.defaultSkillIds.includes(l.id)):[]},[p,i,P]),ke=t.useMemo(()=>{if(!_.trim())return y;const s=_.toLowerCase();return y.filter(a=>a.sessionId.toLowerCase().includes(s)||a.projectPath.toLowerCase().includes(s)||a.firstMessage&&a.firstMessage.toLowerCase().includes(s))},[y,_]),W=t.useMemo(()=>{if(!h.trim())return p;const s=h.toLowerCase();return p.filter(a=>a.name.toLowerCase().includes(s)||a.description.toLowerCase().includes(s)||a.id.toLowerCase().includes(s))},[p,h]),B=t.useMemo(()=>{if(!h.trim())return ie;const s=h.toLowerCase();return ie.filter(a=>{const l=Ie[a.id];return a.name.toLowerCase().includes(s)||a.id.toLowerCase().includes(s)||l.description.toLowerCase().includes(s)})},[h]);t.useEffect(()=>{if(!d||!h.trim())return;const s=[...W.map(a=>a.id),...B.map(a=>a.id)];s.length===1&&s[0]!==i&&M(s[0])},[d,h,W,B,i]);const c=t.useMemo(()=>p.find(s=>s.id===i),[p,i]),Je=t.useMemo(()=>{if(c!=null&&c.model)return c.model},[c]),Xe=t.useMemo(()=>{if(c!=null&&c.customModelPath)return ce(`/api/custom-models/${c.id}`)},[c]),Ye=c==null?void 0:c.modelScale,Qe=t.useMemo(()=>c?"scout":i,[i,c]),K=t.useCallback(async s=>{ge(!0);try{const a=s?ce(`/api/agents/claude-sessions?cwd=${encodeURIComponent(s)}`):ce("/api/agents/claude-sessions"),r=await(await cs(a)).json();Q(r.sessions||[])}catch(a){console.error("Failed to fetch sessions:",a),Q([])}finally{ge(!1)}},[]);t.useEffect(()=>{d?K(k||void 0):(Q([]),O(null),je(""))},[d,K]),t.useEffect(()=>{if(!d)return;const s=setTimeout(()=>{K(k||void 0),O(null)},300);return()=>clearTimeout(s)},[k,d,K]),t.useEffect(()=>{if(!d||!N)return;const s=v.getState().areas.get(N);if(s!=null&&s.directories&&s.directories.length>0){F(s.directories[0]);return}const a=Array.from(v.getState().agents.values()).filter(g=>{var $;return(($=v.getAreaForAgent(g.id))==null?void 0:$.id)===N&&g.cwd});if(a.length===0)return;const l=new Map;for(const g of a)l.set(g.cwd,(l.get(g.cwd)||0)+1);let r="",u=0;for(const[g,$]of l)$>u&&(r=g,u=$);r&&F(r)},[d,N]),t.useEffect(()=>{if(d){const s=new Set(Array.from(v.getState().agents.values()).map(u=>u.name)),a=Le(s,X),l=p.find(u=>u.id===i),r=l?`${l.name} ${a}`:a;b(r),q.current&&(q.current.focus(),q.current.select())}},[d,X]),t.useEffect(()=>{if(!d)return;const s=p.find(a=>a.id===i);if(s){const a=p.find(l=>m.startsWith(l.name+" "));if(a){const l=m.substring(a.name.length+1);b(`${s.name} ${l}`)}else b(`${s.name} ${m}`)}else{const a=p.find(l=>m.startsWith(l.name+" "));if(a){const l=m.substring(a.name.length+1);b(l)}}},[i]),t.useEffect(()=>{i==="boss"&&Ne("claude-opus-4-8[1m]")},[i]);const Ve=()=>{var r;console.log("[SpawnModal] handleSpawn called"),R(!1);const s=E&&((r=y.find(u=>u.sessionId===E))==null?void 0:r.projectPath)||k;if(console.log("[SpawnModal] Effective CWD:",s),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"),!s.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(v.getState().agents.values()).map(g=>g.name));b(Le(u,X));return}hs(oe.LAST_CWD,s),I(!0),S();const a=Array.from(V),l=ve.trim()||void 0;console.log("[SpawnModal] Calling store.spawnAgent with:",{name:m.trim(),class:i,cwd:s.trim(),sessionId:E||void 0,useChrome:o==="claude"?U:!1,permissionMode:z,provider:o,codexConfig:o==="codex"?f:void 0,codexModel:o==="codex"?ne:void 0,opencodeModel:o==="opencode"?ae:void 0,grokModel:o==="grok"?te:void 0,initialSkillIds:a,model:o==="claude"?ee:void 0,customInstructions:l?`${l.length} chars`:void 0,spawnAreaId:N||void 0}),window.__spawnModalAreaContext=N?{areaId:N}:null,v.spawnAgent(m.trim(),i,s.trim(),$e||void 0,E||void 0,o==="claude"?U:!1,z,a,o,o==="codex"?f:void 0,o==="codex"?ne:void 0,o==="claude"?ee:void 0,l,o==="claude"||o==="grok"?se:void 0,o==="opencode"?ae:void 0,o==="grok"?te:void 0)},Me=()=>{console.log("[SpawnModal] Agent creation successful"),I(!1),b(""),Z(new Set),L(),C(),j()},ye=()=>{console.error("[SpawnModal] Agent creation failed"),I(!1),R(!0),L(),C()},Ee=s=>{console.log("[SpawnModal] Directory not found:",s),I(!1),fe(s),Y(!0),C()},Ae=()=>{Y(!1),I(!0),S(),v.createDirectoryAndSpawn(xe,m.trim(),i)},le=()=>{Y(!1),fe(""),L()};t.useEffect(()=>(window.__spawnModalSuccess=Me,window.__spawnModalError=ye,window.__spawnModalDirNotFound=Ee,()=>{L(),delete window.__spawnModalSuccess,delete window.__spawnModalError,delete window.__spawnModalDirNotFound}),[m,i,Me,ye,Ee,L]);const{handleMouseDown:Ze,handleClick:es}=rs(j),ss=s=>{s.key==="Escape"&&j()};return!d&&!we?null:we?e.jsx("div",{className:"modal-overlay visible",onClick:le,onKeyDown:s=>{s.key==="Escape"&&le(),s.key==="Enter"&&Ae()},children:e.jsxs("div",{className:"modal confirm-modal",onClick:s=>s.stopPropagation(),children:[e.jsx("div",{className:"modal-header",children:n("terminal:spawn.directoryNotFound")}),e.jsxs("div",{className:"modal-body confirm-modal-body",children:[e.jsx("p",{children:n("terminal:spawn.directoryNotExist")}),e.jsx("code",{className:"confirm-modal-path",children:xe}),e.jsx("p",{children:n("terminal:spawn.wouldYouCreate")})]}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("button",{className:"btn btn-secondary",onClick:le,children:n("common:buttons.cancel")}),e.jsx("button",{className:"btn btn-primary",onClick:Ae,autoFocus:!0,children:n("terminal:spawn.createDirectory")})]})]})}):e.jsx("div",{className:`modal-overlay ${d?"visible":""}`,onMouseDown:Ze,onClick:es,onKeyDown:ss,children:e.jsxs("div",{className:"modal spawn-modal",children:[e.jsx("div",{className:"modal-header",children:n("terminal:spawn.deployTitle")}),e.jsxs("div",{className:"modal-body spawn-modal-body",children:[e.jsxs("div",{className:"spawn-section",children:[e.jsxs("div",{className:"spawn-section-header",children:[e.jsx("h4",{className:"spawn-section-title",children:n("terminal:spawn.agentClass")}),e.jsx("span",{className:"spawn-section-hint",children:(c==null?void 0:c.name)||i})]}),e.jsxs("div",{className:"spawn-top-section",children:[e.jsxs("div",{className:"spawn-preview-compact",children:[e.jsx(ds,{agentClass:Qe,modelFile:Je,customModelUrl:Xe,modelScale:Ye,width:110,height:130}),e.jsx("div",{className:"spawn-preview-label",children:(c==null?void 0:c.name)||i})]}),e.jsxs("div",{className:"spawn-class-section",children:[p.length+ie.length>6&&e.jsx("input",{type:"text",className:"spawn-input class-search-input",placeholder:n("terminal:spawn.filterClasses"),value:h,onChange:s=>Fe(s.target.value)}),e.jsxs("div",{className:"class-selector-inline",children:[W.map(s=>e.jsxs("button",{className:`class-chip ${i===s.id?"selected":""}`,onClick:()=>M(s.id),title:s.description,children:[e.jsx(_e,{classId:s.id,size:18,className:"class-chip-icon"}),e.jsx("span",{className:"class-chip-name",children:s.name})]},s.id)),B.map(s=>{const a=Ie[s.id];return e.jsxs("button",{className:`class-chip ${i===s.id?"selected":""}`,onClick:()=>M(s.id),title:a.description,children:[e.jsx(_e,{classId:s.id,size:18,className:"class-chip-icon"}),e.jsx("span",{className:"class-chip-name",children:s.name})]},s.id)}),h&&W.length===0&&B.length===0&&e.jsx("div",{className:"class-search-empty",children:n("terminal:spawn.noClassesMatch",{query:h})})]})]})]}),e.jsxs("div",{className:"spawn-form-row",children:[e.jsxs("div",{className:"spawn-field",children:[e.jsx("label",{className:"spawn-label",children:n("common:labels.name")}),e.jsx("input",{ref:q,type:"text",className:"spawn-input",placeholder:n("terminal:spawn.agentNamePlaceholder"),value:m,onChange:s=>b(s.target.value)})]}),e.jsxs("div",{className:"spawn-field spawn-field-wide",children:[e.jsxs("label",{className:"spawn-label",children:[n("terminal:spawn.workingDir"),e.jsx(x,{text:n("terminal:spawn.helpWorkingDir"),title:n("terminal:spawn.workingDir"),position:"top",size:"sm"})]}),e.jsx(ps,{value:k,onChange:s=>{F(s),R(!1)},placeholder:n("terminal:spawn.workingDirPlaceholder"),className:`spawn-input ${Te?"error":""}`,directoriesOnly:!0})]})]})]}),e.jsxs("div",{className:"spawn-section",children:[e.jsx("div",{className:"spawn-section-header",children:e.jsx("h4",{className:"spawn-section-title",children:n("terminal:spawn.selectRuntime")})}),e.jsxs("div",{className:"spawn-form-row",children:[e.jsxs("div",{className:"spawn-field",children:[e.jsxs("label",{className:"spawn-label",children:[n("common:labels.runtime"),e.jsx(x,{text:n("terminal:spawn.helpRuntime"),title:n("terminal:spawn.runtimeTitle"),position:"top",size:"sm"})]}),e.jsxs("div",{className:"spawn-select-row",children:[e.jsxs("button",{className:`spawn-select-btn ${o==="claude"?"selected":""}`,onClick:()=>G("claude"),title:n("terminal:spawn.useClaudeCli"),children:[e.jsx("img",{src:"/assets/claude.ico",alt:"Claude",className:"spawn-provider-icon"}),e.jsx("span",{children:"Claude"})]}),e.jsxs("button",{className:`spawn-select-btn ${o==="codex"?"selected":""}`,onClick:()=>G("codex"),title:n("terminal:spawn.useCodexCli"),children:[e.jsx("img",{src:"/assets/codex.ico",alt:"Codex",className:"spawn-provider-icon"}),e.jsx("span",{children:"Codex"})]}),e.jsxs("button",{className:`spawn-select-btn spawn-select-btn--opencode ${o==="opencode"?"selected":""}`,onClick:()=>G("opencode"),title:"Use OpenCode CLI (multi-provider)",children:[e.jsx("img",{src:"/assets/opencode.svg",alt:"OpenCode",className:"spawn-provider-icon"}),e.jsx("span",{children:"OpenCode"})]}),e.jsxs("button",{className:`spawn-select-btn spawn-select-btn--grok ${o==="grok"?"selected":""}`,onClick:()=>G("grok"),title:"Use Grok CLI (headless)",children:[e.jsx("img",{src:"/assets/grok.png",alt:"Grok",className:"spawn-provider-icon"}),e.jsx("span",{children:"Grok"})]})]})]}),e.jsxs("div",{className:"spawn-field",children:[e.jsxs("label",{className:"spawn-label",children:[n("common:labels.permissions"),e.jsx(x,{text:n("terminal:spawn.helpPermission"),title:n("terminal:spawn.permissionMode"),position:"top",size:"sm"})]}),e.jsx("div",{className:"spawn-select-row",children:Object.keys(re).map(s=>e.jsxs("button",{className:`spawn-select-btn ${z===s?"selected":""}`,onClick:()=>Oe(s),title:re[s].description,children:[e.jsx("span",{children:e.jsx(de,{name:s==="bypass"?"bolt":"lock",size:12})}),e.jsx("span",{children:re[s].label})]},s))})]})]}),e.jsx("div",{className:"spawn-form-row",children:e.jsxs("div",{className:"spawn-field",children:[e.jsxs("label",{className:"spawn-label",children:[n("common:labels.model"),e.jsx(x,{text:n("terminal:spawn.helpModel"),title:n("terminal:spawn.modelTitle"),position:"top",size:"sm"})]}),o==="claude"?e.jsx("div",{className:"spawn-select-row spawn-select-row--wrap",children:Object.keys(T).filter(s=>!T[s].deprecated).map(s=>e.jsxs("button",{className:`spawn-select-btn ${ee===s?"selected":""}`,onClick:()=>Ne(s),title:T[s].description,children:[e.jsx("span",{children:T[s].icon}),e.jsx("span",{children:T[s].label})]},s))}):o==="codex"?e.jsx("div",{className:"spawn-select-row spawn-select-row--codex-models",children:Object.keys(H).map(s=>e.jsxs("button",{className:`spawn-select-btn ${ne===s?"selected":""}`,onClick:()=>Ue(s),title:H[s].description,children:[e.jsx("span",{children:H[s].icon}),e.jsx("span",{children:H[s].label})]},s))}):o==="opencode"?e.jsx(ms,{value:ae,onChange:ze,inputId:"spawn-opencode-model"}):o==="grok"?e.jsx("div",{className:"spawn-select-row spawn-select-row--wrap",children:Object.keys(J).map(s=>e.jsxs("button",{className:`spawn-select-btn ${te===s?"selected":""}`,onClick:()=>Ge(s),title:J[s].description,children:[e.jsx("span",{children:J[s].icon}),e.jsx("span",{children:J[s].label})]},s))}):e.jsx("div",{className:"spawn-inline-hint",children:n("terminal:spawn.chooseCodexModel")})]})}),e.jsxs("div",{className:"spawn-form-row",children:[(o==="claude"||o==="grok")&&e.jsxs("div",{className:"spawn-field",children:[e.jsx("label",{className:"spawn-label",children:"Effort"}),e.jsxs("div",{className:"spawn-select-row spawn-select-row--effort",children:[e.jsx("button",{className:`spawn-select-btn spawn-select-btn--compact ${se===void 0?"selected":""}`,onClick:()=>be(void 0),title:"Use default effort level",children:e.jsx("span",{children:"Default"})}),Object.keys(pe).map(s=>e.jsx("button",{className:`spawn-select-btn spawn-select-btn--compact ${se===s?"selected":""}`,onClick:()=>be(s),title:pe[s].description,children:e.jsx("span",{children:pe[s].label})},s))]})]}),e.jsxs("div",{className:"spawn-field",children:[e.jsx("label",{className:"spawn-label",children:n("terminal:spawn.browser")}),e.jsxs("label",{className:"spawn-checkbox",children:[e.jsx("input",{type:"checkbox",checked:U,onChange:s=>Re(s.target.checked),disabled:o!=="claude"}),e.jsxs("span",{children:[e.jsx(de,{name:"globe",size:12})," ",n("terminal:spawn.chromeBrowser")]}),e.jsx(x,{text:n(o==="claude"?"terminal:spawn.helpChrome":"terminal:spawn.helpChromeDisabled"),title:n("terminal:spawn.chromeBrowser"),position:"top",size:"sm"})]})]})]}),o==="codex"&&e.jsxs("div",{className:"codex-config-section",children:[e.jsx("div",{className:"codex-config-title",children:n("terminal:spawn.codex.configuration")}),e.jsxs("div",{className:"codex-config-options",children:[e.jsxs("div",{className:"codex-option-group",children:[e.jsxs("label",{className:"spawn-checkbox",children:[e.jsx("input",{type:"checkbox",checked:f.fullAuto!==!1,onChange:s=>A(a=>({...a,fullAuto:s.target.checked}))}),e.jsx("span",{children:n("terminal:spawn.codex.fullAuto")}),e.jsx(x,{text:n("terminal:spawn.helpFullAuto"),title:n("terminal:spawn.fullAutoTitle"),position:"top",size:"sm"})]}),e.jsxs("label",{className:"spawn-checkbox",children:[e.jsx("input",{type:"checkbox",checked:!!f.search,onChange:s=>A(a=>({...a,search:s.target.checked}))}),e.jsx("span",{children:n("terminal:spawn.codex.search")}),e.jsx(x,{text:n("terminal:spawn.helpSearch"),title:n("terminal:spawn.searchTitle"),position:"top",size:"sm"})]})]}),f.fullAuto===!1&&e.jsxs("div",{className:"codex-option-group",children:[e.jsx("div",{className:"codex-option-header",children:n("terminal:spawn.codex.restrictions")}),e.jsxs("select",{className:"spawn-input codex-select",value:f.sandbox||"workspace-write",onChange:s=>A(a=>({...a,sandbox:s.target.value})),children:[e.jsxs("option",{value:"read-only",children:["📖 ",n("terminal:spawn.codex.sandboxReadOnly")]}),e.jsxs("option",{value:"workspace-write",children:["✏️ ",n("terminal:spawn.codex.sandboxWorkspaceWrite")]}),e.jsxs("option",{value:"danger-full-access",children:["⚡ ",n("terminal:spawn.codex.sandboxDangerFullAccess")]})]}),e.jsxs("select",{className:"spawn-input codex-select",value:f.approvalMode||"on-request",onChange:s=>A(a=>({...a,approvalMode:s.target.value})),children:[e.jsxs("option",{value:"untrusted",children:["🔒 ",n("terminal:spawn.codex.approvalsUntrusted")]}),e.jsxs("option",{value:"on-failure",children:["⚠️ ",n("terminal:spawn.codex.approvalsOnFailure")]}),e.jsxs("option",{value:"on-request",children:["🤔 ",n("terminal:spawn.codex.approvalsOnRequest")]}),e.jsxs("option",{value:"never",children:["✅ ",n("terminal:spawn.codex.approvalsNever")]})]})]}),e.jsxs("div",{className:"codex-option-group",children:[e.jsx("div",{className:"codex-option-header",children:n("terminal:spawn.codex.profile")}),e.jsx("input",{type:"text",className:"spawn-input codex-profile-input",placeholder:n("terminal:spawn.codex.profilePlaceholder"),value:f.profile||"",onChange:s=>A(a=>({...a,profile:s.target.value||void 0}))})]}),e.jsxs("div",{className:"codex-option-group",children:[e.jsx("div",{className:"codex-option-header",children:n("terminal:spawn.codex.reasoningEffort")}),e.jsxs("select",{className:"spawn-input codex-select",value:f.reasoningEffort||"",onChange:s=>A(a=>({...a,reasoningEffort:s.target.value||void 0})),children:[e.jsx("option",{value:"",children:n("terminal:spawn.codex.reasoningEffortDefault")}),Object.keys(me).map(s=>e.jsxs("option",{value:s,children:[me[s].icon," ",me[s].label]},s))]})]})]})]})]}),w.length>0&&e.jsxs("div",{className:"spawn-section spawn-skills-section",children:[e.jsxs("div",{className:"spawn-section-header",children:[e.jsxs("h4",{className:"spawn-section-title",children:[n("terminal:spawn.skills"),e.jsx(x,{text:n("terminal:spawn.helpSkills"),title:n("terminal:spawn.skillsTitle"),position:"top",size:"sm"})]}),e.jsxs("span",{className:"spawn-section-hint",children:[V.size," selected · ",n("common:labels.optional")]})]}),w.length>6&&e.jsx("input",{type:"text",className:"spawn-input skill-search-input",placeholder:n("terminal:spawn.filterSkills"),value:D,onChange:s=>We(s.target.value)}),e.jsxs("div",{className:"spawn-skills-inline",children:[Ce.map(s=>{const a=V.has(s.id);return He.some(r=>r.id===s.id)?null:e.jsxs("button",{className:`spawn-skill-chip ${a?"selected":""}`,onClick:()=>Ke(s.id),title:s.description,children:[a&&e.jsx("span",{className:"spawn-skill-check",children:e.jsx(de,{name:"check",size:10})}),e.jsx("span",{children:s.name}),s.builtin&&e.jsx("span",{className:"spawn-skill-builtin",children:"TC"})]},s.id)}),D&&Ce.length===0&&e.jsx("div",{className:"skill-search-empty",children:n("terminal:spawn.noSkillsMatch",{query:D})})]})]}),e.jsxs("details",{className:"spawn-advanced",children:[e.jsxs("summary",{children:[n("terminal:spawn.customInstructions")," & ",n("terminal:spawn.linkSession")]}),e.jsxs("div",{className:"spawn-advanced-body",children:[e.jsxs("div",{className:"spawn-custom-instructions-section",children:[e.jsxs("label",{className:"spawn-label",children:[n("terminal:spawn.customInstructions")," ",e.jsxs("span",{className:"spawn-label-hint",children:["(",n("common:labels.optional"),")"]}),e.jsx(x,{text:n("terminal:spawn.helpCustomInstructions"),title:n("terminal:spawn.customInstructions"),position:"top",size:"sm"})]}),e.jsx("textarea",{className:"spawn-input spawn-textarea",placeholder:n("terminal:spawn.customInstructionsPlaceholder"),value:ve,onChange:s=>qe(s.target.value),rows:3})]}),e.jsxs("div",{className:"spawn-sessions-section",children:[e.jsxs("label",{className:"spawn-label",children:[n("terminal:spawn.linkSession")," ",e.jsxs("span",{className:"spawn-label-hint",children:["(",n("common:labels.optional"),")"]}),e.jsx(x,{text:n("terminal:spawn.helpLinkSession"),title:n("terminal:spawn.linkSessionTitle"),position:"top",size:"sm"})]}),y.length>0&&e.jsx("input",{type:"text",className:"spawn-input session-search-input",placeholder:n("terminal:spawn.searchSessions"),value:_,onChange:s=>je(s.target.value)}),e.jsx("div",{className:"sessions-list",children:Pe?e.jsx("div",{className:"sessions-loading",children:n("terminal:spawn.loadingSessions")}):y.length===0?e.jsx("div",{className:"sessions-empty",children:n("terminal:spawn.noSessions")}):ke.length===0?e.jsx("div",{className:"sessions-empty",children:n("terminal:spawn.noSessionsMatch",{query:_})}):ke.map(s=>{const a=E===s.sessionId,l=Date.now()-new Date(s.lastModified).getTime(),r=l<6e4?n("common:time.justNow"):l<36e5?n("common:time.minutesAgo",{count:Math.floor(l/6e4)}):l<864e5?n("common:time.hoursAgo",{count:Math.floor(l/36e5)}):n("common:time.daysAgo",{count:Math.floor(l/864e5)});return e.jsxs("div",{className:`session-item ${a?"selected":""}`,onClick:()=>{a?O(null):(O(s.sessionId),F(s.projectPath))},children:[e.jsxs("div",{className:"session-item-header",children:[e.jsx("span",{className:"session-item-path",children:s.projectPath}),e.jsx("span",{className:"session-item-age",children:r})]}),e.jsx("div",{className:"session-item-preview",children:s.firstMessage||n("terminal:spawn.messagesCount",{count:s.messageCount})})]},s.sessionId)})})]})]})]})]}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("button",{className:"btn btn-secondary",onClick:j,children:n("common:buttons.cancel")}),e.jsx("button",{className:"btn btn-primary",onClick:Ve,disabled:he,children:n(he?"common:buttons.deploying":"common:buttons2.deploy")})]})]})})}export{gs as SpawnModal};
@@ -1 +1 @@
1
- import{u as R,n as U,aq as j,d0 as F,d1 as B,j as t,bA as G,I,c1 as k}from"./main-CEq_Fs_S.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const b=["#6ab8c8","#c89a5a","#9a80c0","#5cb88a","#c85a5a","#c87a9a","#c8c87a","#5a8fd4","#d45a5a","#8a6fbf"],P=14,w=720,C=260,p={top:16,right:20,bottom:42,left:64};function W(){const i=new Date;return i.setHours(0,0,0,0),i.getTime()}function $(i){if(!i)return"N/A";try{return new Date(i).toLocaleString()}catch{return"N/A"}}function q(i,s){if(i.length===0||s<=0)return"conic-gradient(rgba(50, 50, 62, 0.95) 0deg 360deg)";let a=0;return`conic-gradient(${i.map((h,l)=>{const c=a,n=h.tokens.total/s*360;return a+=n,`${b[l%b.length]} ${c.toFixed(2)}deg ${a.toFixed(2)}deg`}).join(", ")})`}function E(i){const[,s,a]=i.split("-");return!s||!a?i:`${s}/${a}`}function z(i){const s=(i==null?void 0:i.days)??[];if(s.length===0)return[];const a=new Map;for(const l of s)for(const c of l.agents){const n=a.get(c.agentId)??{agentName:c.agentName,total:0};n.total+=c.tokens.total,a.set(c.agentId,n)}const r={id:"general",name:"General",color:"#f1fa8c",values:s.map(l=>l.totalTokens),total:s.reduce((l,c)=>l+c.totalTokens,0),peak:Math.max(0,...s.map(l=>l.totalTokens)),isTotal:!0},h=[...a.entries()].sort((l,c)=>c[1].total-l[1].total).map(([l,c],n)=>({id:l,name:c.agentName,color:b[n%b.length],values:s.map(u=>{var d;return((d=u.agents.find(x=>x.agentId===l))==null?void 0:d.tokens.total)??0}),total:c.total,peak:Math.max(0,...s.map(u=>{var d;return((d=u.agents.find(x=>x.agentId===l))==null?void 0:d.tokens.total)??0}))}));return[r,...h].filter(l=>l.total>0)}function Y(i){if(i<=0)return 1;const s=10**Math.floor(Math.log10(i)),a=i/s;return(a<=1?1:a<=2?2:a<=5?5:10)*s}function H(i,s,a,r){const h=p.left,l=p.top,c=w-p.left-p.right,n=C-p.top-p.bottom,u=i<=1?h+c/2:h+s/(i-1)*c,d=l+n-a/r*n;return{x:u,y:d}}function X(i,s){return i.map((a,r)=>{const{x:h,y:l}=H(i.length,r,a,s);return`${h.toFixed(2)},${l.toFixed(2)}`}).join(" ")}function J(i,s=28){return i.length<=s?i:`${i.slice(0,s-1)}...`}function K({summary:i}){const[s,a]=j.useState(null),r=i.days,h=z(i),l=Math.max(1,...h.flatMap(e=>e.values)),c=Y(l),n=p.left,u=p.top,d=w-p.left-p.right,x=C-p.top-p.bottom,f=[0,.5,1],M=Math.max(1,Math.ceil(r.length/5)),v=190,y=86,g=s?Math.min(Math.max(s.x+12,8),w-v-8):0,_=s?Math.min(Math.max(s.y-y-10,8),C-y-8):0;return t.jsxs("div",{className:"statistics-line-chart",children:[t.jsxs("svg",{className:"statistics-line-chart__svg",viewBox:`0 0 ${w} ${C}`,role:"img","aria-label":"Daily Claude token usage by agent",preserveAspectRatio:"xMidYMid meet",onMouseLeave:()=>a(null),children:[f.map(e=>{const m=u+x-e*x;return t.jsxs("g",{children:[t.jsx("line",{className:"statistics-line-chart__grid",x1:n,y1:m,x2:n+d,y2:m}),t.jsx("text",{className:"statistics-line-chart__axis-label",x:n-10,y:m+4,textAnchor:"end",children:k(Math.round(c*e))})]},e)}),t.jsx("line",{className:"statistics-line-chart__axis",x1:n,y1:u,x2:n,y2:u+x}),t.jsx("line",{className:"statistics-line-chart__axis",x1:n,y1:u+x,x2:n+d,y2:u+x}),r.map((e,m)=>{if(m!==0&&m!==r.length-1&&m%M!==0)return null;const o=r.length<=1?n+d/2:n+m/(r.length-1)*d;return t.jsx("text",{className:"statistics-line-chart__axis-label",x:o,y:C-14,textAnchor:"middle",children:E(e.date)},e.date)}),h.map(e=>t.jsx("polyline",{className:e.isTotal?"statistics-line-chart__line statistics-line-chart__line--total":"statistics-line-chart__line",points:X(e.values,c),fill:"none",stroke:e.color,strokeWidth:e.isTotal?3:2,strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("title",{children:`${e.name}: ${e.peak.toLocaleString()} peak daily tokens`})},e.id)),h.map(e=>e.values.map((m,o)=>{var L,D,V,A;const{x:N,y:S}=H(r.length,o,m,c),T={id:`${e.id}-${(L=r[o])==null?void 0:L.date}`,date:((D=r[o])==null?void 0:D.date)??"",name:e.name,color:e.color,value:m,total:e.total,peak:e.peak,x:N,y:S};return t.jsxs("g",{children:[t.jsx("circle",{className:"statistics-line-chart__point",cx:N,cy:S,r:e.isTotal?3.4:2.6,fill:e.color}),t.jsx("circle",{className:"statistics-line-chart__point-hit",cx:N,cy:S,r:10,tabIndex:0,role:"button","aria-label":`${e.name} ${(V=r[o])==null?void 0:V.date}: ${m.toLocaleString()} tokens`,onMouseEnter:()=>a(T),onFocus:()=>a(T),onBlur:()=>a(null)})]},`${e.id}-${(A=r[o])==null?void 0:A.date}`)})),s&&t.jsxs("g",{className:"statistics-line-chart__tooltip",children:[t.jsx("line",{className:"statistics-line-chart__hover-line",x1:s.x,y1:u,x2:s.x,y2:u+x}),t.jsx("circle",{className:"statistics-line-chart__hover-point",cx:s.x,cy:s.y,r:5,fill:s.color}),t.jsx("rect",{className:"statistics-line-chart__tooltip-box",x:g,y:_,width:v,height:y,rx:6}),t.jsx("text",{className:"statistics-line-chart__tooltip-title",x:g+10,y:_+18,children:E(s.date)}),t.jsx("text",{className:"statistics-line-chart__tooltip-name",x:g+10,y:_+34,children:J(s.name)}),t.jsxs("text",{className:"statistics-line-chart__tooltip-value",x:g+10,y:_+52,children:["Daily: ",k(s.value)]}),t.jsxs("text",{className:"statistics-line-chart__tooltip-meta",x:g+10,y:_+68,children:["Peak: ",k(s.peak)]}),t.jsxs("text",{className:"statistics-line-chart__tooltip-meta",x:g+100,y:_+68,children:["Total: ",k(s.total)]})]})]}),t.jsx("div",{className:"statistics-line-chart__legend",children:h.map(e=>t.jsxs("div",{className:"statistics-line-chart__legend-item",title:`${e.name}: peak ${e.peak.toLocaleString()} daily tokens, ${e.total.toLocaleString()} period tokens`,children:[t.jsx("span",{className:"statistics-line-chart__legend-swatch",style:{backgroundColor:e.color}}),t.jsx("span",{children:e.name}),t.jsx("strong",{children:k(e.peak)})]},e.id))})]})}function tt({isOpen:i,onClose:s}){const{t:a}=R(["terminal","common"]),{handleMouseDown:r,handleClick:h}=U(s),[l,c]=j.useState(null),[n,u]=j.useState(null),[d,x]=j.useState(!1),[f,M]=j.useState(null),v=j.useMemo(()=>W(),[]),y=j.useCallback(async()=>{x(!0),M(null);try{const o=Date.now(),[N,S]=await Promise.all([F({since:v,until:o}),B({days:P,until:o})]);c(N),u(S)}catch(o){M((o==null?void 0:o.message)||"Error")}finally{x(!1)}},[v]);if(j.useEffect(()=>{i&&y()},[i,y]),!i)return null;const g=(l==null?void 0:l.entries)??[],_=(l==null?void 0:l.totalTokens)??0,e=q(g,_),m=((n==null?void 0:n.days)??[]).some(o=>o.totalTokens>0);return t.jsx(G,{children:t.jsx("div",{className:"modal-overlay visible",onMouseDown:r,onClick:h,children:t.jsxs("div",{className:"modal statistics-modal",children:[t.jsxs("div",{className:"modal-header statistics-modal__header",children:[t.jsxs("div",{className:"statistics-modal__title",children:[t.jsx("span",{className:"statistics-modal__icon",children:t.jsx(I,{name:"dashboard",size:15})}),t.jsx("span",{children:a("terminal:statistics.title",{defaultValue:"Statistics"})})]}),t.jsx("button",{className:"modal-close statistics-modal__close",onClick:s,title:a("common:buttons.close"),children:"×"})]}),t.jsxs("div",{className:"modal-body statistics-modal__body",children:[t.jsxs("section",{className:"statistics-panel",children:[t.jsxs("div",{className:"statistics-panel__header",children:[t.jsxs("div",{children:[t.jsx("h3",{children:a("terminal:statistics.usageByAgent",{defaultValue:"Claude usage today"})}),t.jsx("span",{className:"statistics-panel__subtitle",children:a("terminal:statistics.usageByAgentSubtitle",{defaultValue:"Input + cache creation + cache read + output tokens, deduped by Claude request id"})})]}),t.jsx("button",{type:"button",className:"statistics-panel__refresh",onClick:y,disabled:d,title:a("terminal:statistics.refresh",{defaultValue:"Refresh usage"}),children:t.jsx(I,{name:"refresh",size:14})})]}),d&&!l&&t.jsx("div",{className:"statistics-panel__empty",children:a("terminal:statistics.loading",{defaultValue:"Loading usage..."})}),!d&&f&&t.jsx("div",{className:"statistics-panel__empty statistics-panel__empty--error",children:a("terminal:statistics.error",{defaultValue:"Failed to load usage: {{error}}",error:f})}),!f&&l&&g.length===0&&t.jsx("div",{className:"statistics-panel__empty",children:a("terminal:statistics.empty",{defaultValue:"No Claude token usage found for today."})}),!f&&l&&g.length>0&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"statistics-panel__layout",children:[t.jsx("div",{className:"statistics-panel__chart-wrap",children:t.jsx("div",{className:"statistics-panel__pie",style:{background:e},role:"img","aria-label":a("terminal:statistics.pieLabel",{defaultValue:"Claude token usage by agent"}),children:t.jsxs("div",{className:"statistics-panel__pie-hole",children:[t.jsx("strong",{children:k(_)}),t.jsx("span",{children:a("terminal:statistics.total",{defaultValue:"total"})})]})})}),t.jsx("div",{className:"statistics-panel__list",children:g.map((o,N)=>t.jsxs("div",{className:"statistics-panel__row",title:`${o.agentName}: ${o.tokens.total.toLocaleString()} tokens`,children:[t.jsx("span",{className:"statistics-panel__swatch",style:{backgroundColor:b[N%b.length]}}),t.jsxs("div",{className:"statistics-panel__row-main",children:[t.jsx("div",{className:"statistics-panel__row-name",children:o.agentName}),t.jsxs("div",{className:"statistics-panel__row-meta",children:[o.requestCount.toLocaleString()," ",a("terminal:statistics.requests",{defaultValue:"requests"})," / ",o.percent,"%"]})]}),t.jsx("strong",{children:k(o.tokens.total)})]},o.agentId))})]}),t.jsx("div",{className:"statistics-panel__footnote",children:a("terminal:statistics.window",{defaultValue:"Window: {{since}} to {{until}}",since:$(l.since),until:$(l.until)})})]})]}),t.jsxs("section",{className:"statistics-panel",children:[t.jsx("div",{className:"statistics-panel__header",children:t.jsxs("div",{children:[t.jsx("h3",{children:a("terminal:statistics.dailyUsage",{defaultValue:"Daily usage by agent"})}),t.jsx("span",{className:"statistics-panel__subtitle",children:a("terminal:statistics.dailyUsageSubtitle",{defaultValue:"General token usage by day plus one line for each Claude agent."})})]})}),d&&!n&&t.jsx("div",{className:"statistics-panel__empty",children:a("terminal:statistics.loading",{defaultValue:"Loading usage..."})}),!d&&!f&&n&&!m&&t.jsx("div",{className:"statistics-panel__empty",children:a("terminal:statistics.dailyEmpty",{defaultValue:"No Claude token usage found for recent days."})}),!f&&n&&m&&t.jsxs(t.Fragment,{children:[t.jsx(K,{summary:n}),t.jsx("div",{className:"statistics-panel__footnote",children:a("terminal:statistics.window",{defaultValue:"Window: {{since}} to {{until}}",since:$(n.since),until:$(n.until)})})]})]})]})]})})})}export{tt as StatisticsModal};
1
+ import{u as R,n as U,aq as j,d1 as B,d2 as F,j as t,bB as G,I,c2 as k}from"./main-aIpEYDDR.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const b=["#6ab8c8","#c89a5a","#9a80c0","#5cb88a","#c85a5a","#c87a9a","#c8c87a","#5a8fd4","#d45a5a","#8a6fbf"],P=14,w=720,C=260,p={top:16,right:20,bottom:42,left:64};function W(){const i=new Date;return i.setHours(0,0,0,0),i.getTime()}function $(i){if(!i)return"N/A";try{return new Date(i).toLocaleString()}catch{return"N/A"}}function q(i,s){if(i.length===0||s<=0)return"conic-gradient(rgba(50, 50, 62, 0.95) 0deg 360deg)";let a=0;return`conic-gradient(${i.map((h,l)=>{const c=a,n=h.tokens.total/s*360;return a+=n,`${b[l%b.length]} ${c.toFixed(2)}deg ${a.toFixed(2)}deg`}).join(", ")})`}function E(i){const[,s,a]=i.split("-");return!s||!a?i:`${s}/${a}`}function z(i){const s=(i==null?void 0:i.days)??[];if(s.length===0)return[];const a=new Map;for(const l of s)for(const c of l.agents){const n=a.get(c.agentId)??{agentName:c.agentName,total:0};n.total+=c.tokens.total,a.set(c.agentId,n)}const r={id:"general",name:"General",color:"#f1fa8c",values:s.map(l=>l.totalTokens),total:s.reduce((l,c)=>l+c.totalTokens,0),peak:Math.max(0,...s.map(l=>l.totalTokens)),isTotal:!0},h=[...a.entries()].sort((l,c)=>c[1].total-l[1].total).map(([l,c],n)=>({id:l,name:c.agentName,color:b[n%b.length],values:s.map(u=>{var d;return((d=u.agents.find(x=>x.agentId===l))==null?void 0:d.tokens.total)??0}),total:c.total,peak:Math.max(0,...s.map(u=>{var d;return((d=u.agents.find(x=>x.agentId===l))==null?void 0:d.tokens.total)??0}))}));return[r,...h].filter(l=>l.total>0)}function Y(i){if(i<=0)return 1;const s=10**Math.floor(Math.log10(i)),a=i/s;return(a<=1?1:a<=2?2:a<=5?5:10)*s}function H(i,s,a,r){const h=p.left,l=p.top,c=w-p.left-p.right,n=C-p.top-p.bottom,u=i<=1?h+c/2:h+s/(i-1)*c,d=l+n-a/r*n;return{x:u,y:d}}function X(i,s){return i.map((a,r)=>{const{x:h,y:l}=H(i.length,r,a,s);return`${h.toFixed(2)},${l.toFixed(2)}`}).join(" ")}function J(i,s=28){return i.length<=s?i:`${i.slice(0,s-1)}...`}function K({summary:i}){const[s,a]=j.useState(null),r=i.days,h=z(i),l=Math.max(1,...h.flatMap(e=>e.values)),c=Y(l),n=p.left,u=p.top,d=w-p.left-p.right,x=C-p.top-p.bottom,f=[0,.5,1],M=Math.max(1,Math.ceil(r.length/5)),v=190,y=86,g=s?Math.min(Math.max(s.x+12,8),w-v-8):0,_=s?Math.min(Math.max(s.y-y-10,8),C-y-8):0;return t.jsxs("div",{className:"statistics-line-chart",children:[t.jsxs("svg",{className:"statistics-line-chart__svg",viewBox:`0 0 ${w} ${C}`,role:"img","aria-label":"Daily Claude token usage by agent",preserveAspectRatio:"xMidYMid meet",onMouseLeave:()=>a(null),children:[f.map(e=>{const m=u+x-e*x;return t.jsxs("g",{children:[t.jsx("line",{className:"statistics-line-chart__grid",x1:n,y1:m,x2:n+d,y2:m}),t.jsx("text",{className:"statistics-line-chart__axis-label",x:n-10,y:m+4,textAnchor:"end",children:k(Math.round(c*e))})]},e)}),t.jsx("line",{className:"statistics-line-chart__axis",x1:n,y1:u,x2:n,y2:u+x}),t.jsx("line",{className:"statistics-line-chart__axis",x1:n,y1:u+x,x2:n+d,y2:u+x}),r.map((e,m)=>{if(m!==0&&m!==r.length-1&&m%M!==0)return null;const o=r.length<=1?n+d/2:n+m/(r.length-1)*d;return t.jsx("text",{className:"statistics-line-chart__axis-label",x:o,y:C-14,textAnchor:"middle",children:E(e.date)},e.date)}),h.map(e=>t.jsx("polyline",{className:e.isTotal?"statistics-line-chart__line statistics-line-chart__line--total":"statistics-line-chart__line",points:X(e.values,c),fill:"none",stroke:e.color,strokeWidth:e.isTotal?3:2,strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("title",{children:`${e.name}: ${e.peak.toLocaleString()} peak daily tokens`})},e.id)),h.map(e=>e.values.map((m,o)=>{var L,D,V,A;const{x:N,y:S}=H(r.length,o,m,c),T={id:`${e.id}-${(L=r[o])==null?void 0:L.date}`,date:((D=r[o])==null?void 0:D.date)??"",name:e.name,color:e.color,value:m,total:e.total,peak:e.peak,x:N,y:S};return t.jsxs("g",{children:[t.jsx("circle",{className:"statistics-line-chart__point",cx:N,cy:S,r:e.isTotal?3.4:2.6,fill:e.color}),t.jsx("circle",{className:"statistics-line-chart__point-hit",cx:N,cy:S,r:10,tabIndex:0,role:"button","aria-label":`${e.name} ${(V=r[o])==null?void 0:V.date}: ${m.toLocaleString()} tokens`,onMouseEnter:()=>a(T),onFocus:()=>a(T),onBlur:()=>a(null)})]},`${e.id}-${(A=r[o])==null?void 0:A.date}`)})),s&&t.jsxs("g",{className:"statistics-line-chart__tooltip",children:[t.jsx("line",{className:"statistics-line-chart__hover-line",x1:s.x,y1:u,x2:s.x,y2:u+x}),t.jsx("circle",{className:"statistics-line-chart__hover-point",cx:s.x,cy:s.y,r:5,fill:s.color}),t.jsx("rect",{className:"statistics-line-chart__tooltip-box",x:g,y:_,width:v,height:y,rx:6}),t.jsx("text",{className:"statistics-line-chart__tooltip-title",x:g+10,y:_+18,children:E(s.date)}),t.jsx("text",{className:"statistics-line-chart__tooltip-name",x:g+10,y:_+34,children:J(s.name)}),t.jsxs("text",{className:"statistics-line-chart__tooltip-value",x:g+10,y:_+52,children:["Daily: ",k(s.value)]}),t.jsxs("text",{className:"statistics-line-chart__tooltip-meta",x:g+10,y:_+68,children:["Peak: ",k(s.peak)]}),t.jsxs("text",{className:"statistics-line-chart__tooltip-meta",x:g+100,y:_+68,children:["Total: ",k(s.total)]})]})]}),t.jsx("div",{className:"statistics-line-chart__legend",children:h.map(e=>t.jsxs("div",{className:"statistics-line-chart__legend-item",title:`${e.name}: peak ${e.peak.toLocaleString()} daily tokens, ${e.total.toLocaleString()} period tokens`,children:[t.jsx("span",{className:"statistics-line-chart__legend-swatch",style:{backgroundColor:e.color}}),t.jsx("span",{children:e.name}),t.jsx("strong",{children:k(e.peak)})]},e.id))})]})}function tt({isOpen:i,onClose:s}){const{t:a}=R(["terminal","common"]),{handleMouseDown:r,handleClick:h}=U(s),[l,c]=j.useState(null),[n,u]=j.useState(null),[d,x]=j.useState(!1),[f,M]=j.useState(null),v=j.useMemo(()=>W(),[]),y=j.useCallback(async()=>{x(!0),M(null);try{const o=Date.now(),[N,S]=await Promise.all([B({since:v,until:o}),F({days:P,until:o})]);c(N),u(S)}catch(o){M((o==null?void 0:o.message)||"Error")}finally{x(!1)}},[v]);if(j.useEffect(()=>{i&&y()},[i,y]),!i)return null;const g=(l==null?void 0:l.entries)??[],_=(l==null?void 0:l.totalTokens)??0,e=q(g,_),m=((n==null?void 0:n.days)??[]).some(o=>o.totalTokens>0);return t.jsx(G,{children:t.jsx("div",{className:"modal-overlay visible",onMouseDown:r,onClick:h,children:t.jsxs("div",{className:"modal statistics-modal",children:[t.jsxs("div",{className:"modal-header statistics-modal__header",children:[t.jsxs("div",{className:"statistics-modal__title",children:[t.jsx("span",{className:"statistics-modal__icon",children:t.jsx(I,{name:"dashboard",size:15})}),t.jsx("span",{children:a("terminal:statistics.title",{defaultValue:"Statistics"})})]}),t.jsx("button",{className:"modal-close statistics-modal__close",onClick:s,title:a("common:buttons.close"),children:"×"})]}),t.jsxs("div",{className:"modal-body statistics-modal__body",children:[t.jsxs("section",{className:"statistics-panel",children:[t.jsxs("div",{className:"statistics-panel__header",children:[t.jsxs("div",{children:[t.jsx("h3",{children:a("terminal:statistics.usageByAgent",{defaultValue:"Claude usage today"})}),t.jsx("span",{className:"statistics-panel__subtitle",children:a("terminal:statistics.usageByAgentSubtitle",{defaultValue:"Input + cache creation + cache read + output tokens, deduped by Claude request id"})})]}),t.jsx("button",{type:"button",className:"statistics-panel__refresh",onClick:y,disabled:d,title:a("terminal:statistics.refresh",{defaultValue:"Refresh usage"}),children:t.jsx(I,{name:"refresh",size:14})})]}),d&&!l&&t.jsx("div",{className:"statistics-panel__empty",children:a("terminal:statistics.loading",{defaultValue:"Loading usage..."})}),!d&&f&&t.jsx("div",{className:"statistics-panel__empty statistics-panel__empty--error",children:a("terminal:statistics.error",{defaultValue:"Failed to load usage: {{error}}",error:f})}),!f&&l&&g.length===0&&t.jsx("div",{className:"statistics-panel__empty",children:a("terminal:statistics.empty",{defaultValue:"No Claude token usage found for today."})}),!f&&l&&g.length>0&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"statistics-panel__layout",children:[t.jsx("div",{className:"statistics-panel__chart-wrap",children:t.jsx("div",{className:"statistics-panel__pie",style:{background:e},role:"img","aria-label":a("terminal:statistics.pieLabel",{defaultValue:"Claude token usage by agent"}),children:t.jsxs("div",{className:"statistics-panel__pie-hole",children:[t.jsx("strong",{children:k(_)}),t.jsx("span",{children:a("terminal:statistics.total",{defaultValue:"total"})})]})})}),t.jsx("div",{className:"statistics-panel__list",children:g.map((o,N)=>t.jsxs("div",{className:"statistics-panel__row",title:`${o.agentName}: ${o.tokens.total.toLocaleString()} tokens`,children:[t.jsx("span",{className:"statistics-panel__swatch",style:{backgroundColor:b[N%b.length]}}),t.jsxs("div",{className:"statistics-panel__row-main",children:[t.jsx("div",{className:"statistics-panel__row-name",children:o.agentName}),t.jsxs("div",{className:"statistics-panel__row-meta",children:[o.requestCount.toLocaleString()," ",a("terminal:statistics.requests",{defaultValue:"requests"})," / ",o.percent,"%"]})]}),t.jsx("strong",{children:k(o.tokens.total)})]},o.agentId))})]}),t.jsx("div",{className:"statistics-panel__footnote",children:a("terminal:statistics.window",{defaultValue:"Window: {{since}} to {{until}}",since:$(l.since),until:$(l.until)})})]})]}),t.jsxs("section",{className:"statistics-panel",children:[t.jsx("div",{className:"statistics-panel__header",children:t.jsxs("div",{children:[t.jsx("h3",{children:a("terminal:statistics.dailyUsage",{defaultValue:"Daily usage by agent"})}),t.jsx("span",{className:"statistics-panel__subtitle",children:a("terminal:statistics.dailyUsageSubtitle",{defaultValue:"General token usage by day plus one line for each Claude agent."})})]})}),d&&!n&&t.jsx("div",{className:"statistics-panel__empty",children:a("terminal:statistics.loading",{defaultValue:"Loading usage..."})}),!d&&!f&&n&&!m&&t.jsx("div",{className:"statistics-panel__empty",children:a("terminal:statistics.dailyEmpty",{defaultValue:"No Claude token usage found for recent days."})}),!f&&n&&m&&t.jsxs(t.Fragment,{children:[t.jsx(K,{summary:n}),t.jsx("div",{className:"statistics-panel__footnote",children:a("terminal:statistics.window",{defaultValue:"Window: {{since}} to {{until}}",since:$(n.since),until:$(n.until)})})]})]})]})]})})})}export{tt as StatisticsModal};
@@ -1 +1 @@
1
- import{u as L,aC as $,ar as D,r as m,j as s,bj as N,a9 as S,I as g,s as J}from"./main-CEq_Fs_S.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function M({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{M as SubordinateAssignmentModal};
1
+ import{u as L,aC as $,ar as D,r as m,j as s,bj as N,a9 as S,I as g,s as J}from"./main-aIpEYDDR.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function M({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{M as SubordinateAssignmentModal};
@@ -1,4 +1,4 @@
1
- import{aC as Me,r as o,i as v,k as b,j as e}from"./main-CEq_Fs_S.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const Ie=[{value:"webhook",label:"Webhook"},{value:"bitbucket",label:"Bitbucket"},{value:"cron",label:"Cron"},{value:"slack",label:"Slack"},{value:"email",label:"Email"},{value:"jira",label:"Jira"},{value:"whatsapp",label:"WhatsApp"}],Ae=[{value:"all",label:"All",icon:"◎"},{value:"webhook",label:"Webhook",icon:"🪝"},{value:"bitbucket",label:"Bitbucket",icon:"🪣"},{value:"cron",label:"Cron",icon:"⏰"},{value:"slack",label:"Slack",icon:"💬"},{value:"email",label:"Email",icon:"✉️"},{value:"jira",label:"Jira",icon:"🎫"},{value:"whatsapp",label:"WhatsApp",icon:"📱"}],Be=[{value:"pullrequest:created",label:"PR created"},{value:"pullrequest:updated",label:"PR updated"},{value:"pullrequest:approved",label:"PR approved"},{value:"pullrequest:unapproved",label:"PR unapproved"},{value:"pullrequest:fulfilled",label:"PR merged"},{value:"pullrequest:rejected",label:"PR declined"},{value:"pullrequest:comment_created",label:"PR comment created"}],Re=[{value:"structural",label:"Structural",desc:"Field-based matching (fast, free)"},{value:"llm",label:"LLM",desc:"Semantic matching via LLM (flexible, costs tokens)"},{value:"hybrid",label:"Hybrid",desc:"Structural pre-filter + LLM (recommended)"}],Fe=[{value:"structural",label:"Structural"},{value:"llm",label:"LLM"}];function Ee(w){if(!w)return"";const g=new Date(w);if(Number.isNaN(g.getTime()))return"";const m=j=>String(j).padStart(2,"0");return`${g.getFullYear()}-${m(g.getMonth()+1)}-${m(g.getDate())}T${m(g.getHours())}:${m(g.getMinutes())}`}const O=()=>({name:"",description:"",type:"webhook",agentId:"",promptTemplate:"",enabled:!0,matchMode:"structural",extractionMode:"structural",config:{method:"POST"}});function Pe({isOpen:w,onClose:g}){var Q,X,Z,ee,le,te,se,ae,ne,ie,re,oe,ce,de,pe,ue;const m=Me(),[j,xe]=o.useState([]),[S,A]=o.useState("list"),[n,k]=o.useState(O()),[h,R]=o.useState(!1),[L,D]=o.useState(!1),[P,y]=o.useState(null),[z,he]=o.useState([]),[T,ye]=o.useState(null),[F,be]=o.useState(`{
1
+ import{aC as Me,r as o,i as v,k as b,j as e}from"./main-aIpEYDDR.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const Ie=[{value:"webhook",label:"Webhook"},{value:"bitbucket",label:"Bitbucket"},{value:"cron",label:"Cron"},{value:"slack",label:"Slack"},{value:"email",label:"Email"},{value:"jira",label:"Jira"},{value:"whatsapp",label:"WhatsApp"}],Ae=[{value:"all",label:"All",icon:"◎"},{value:"webhook",label:"Webhook",icon:"🪝"},{value:"bitbucket",label:"Bitbucket",icon:"🪣"},{value:"cron",label:"Cron",icon:"⏰"},{value:"slack",label:"Slack",icon:"💬"},{value:"email",label:"Email",icon:"✉️"},{value:"jira",label:"Jira",icon:"🎫"},{value:"whatsapp",label:"WhatsApp",icon:"📱"}],Be=[{value:"pullrequest:created",label:"PR created"},{value:"pullrequest:updated",label:"PR updated"},{value:"pullrequest:approved",label:"PR approved"},{value:"pullrequest:unapproved",label:"PR unapproved"},{value:"pullrequest:fulfilled",label:"PR merged"},{value:"pullrequest:rejected",label:"PR declined"},{value:"pullrequest:comment_created",label:"PR comment created"}],Re=[{value:"structural",label:"Structural",desc:"Field-based matching (fast, free)"},{value:"llm",label:"LLM",desc:"Semantic matching via LLM (flexible, costs tokens)"},{value:"hybrid",label:"Hybrid",desc:"Structural pre-filter + LLM (recommended)"}],Fe=[{value:"structural",label:"Structural"},{value:"llm",label:"LLM"}];function Ee(w){if(!w)return"";const g=new Date(w);if(Number.isNaN(g.getTime()))return"";const m=j=>String(j).padStart(2,"0");return`${g.getFullYear()}-${m(g.getMonth()+1)}-${m(g.getDate())}T${m(g.getHours())}:${m(g.getMinutes())}`}const O=()=>({name:"",description:"",type:"webhook",agentId:"",promptTemplate:"",enabled:!0,matchMode:"structural",extractionMode:"structural",config:{method:"POST"}});function Pe({isOpen:w,onClose:g}){var Q,X,Z,ee,le,te,se,ae,ne,ie,re,oe,ce,de,pe,ue;const m=Me(),[j,xe]=o.useState([]),[S,A]=o.useState("list"),[n,k]=o.useState(O()),[h,R]=o.useState(!1),[L,D]=o.useState(!1),[P,y]=o.useState(null),[z,he]=o.useState([]),[T,ye]=o.useState(null),[F,be]=o.useState(`{
2
2
 
3
3
  }`),[u,M]=o.useState(null),[N,U]=o.useState(!1),[H,W]=o.useState([]),[I,ge]=o.useState("all"),[_,je]=o.useState([]),f=o.useCallback(async()=>{try{const t=await v(b("/api/triggers"));if(t.ok){const s=await t.json();xe(s)}}catch(t){console.error("Failed to load triggers:",t)}},[]),B=o.useCallback(async t=>{try{const s=await v(b(`/api/triggers/${t}/events?limit=20`));if(s.ok){const a=await s.json();he(a)}}catch(s){console.error("Failed to load trigger history:",s)}},[]),q=o.useCallback(async()=>{try{const t=await v(b("/api/slack/instances"));if(t.ok){const s=await t.json(),a=Array.isArray(s==null?void 0:s.instances)?s.instances:[];je(a.map(p=>({id:p.id,label:p.label||p.id})))}}catch(t){console.error("Failed to load Slack instances:",t)}},[]);o.useEffect(()=>{w&&(f(),q())},[w,f,q]),o.useEffect(()=>{T&&B(T)},[T,B]);const ve=o.useCallback(async()=>{D(!0),y(null);try{const t=h?b(`/api/triggers/${n.id}`):b("/api/triggers"),p=await v(t,{method:h?"PATCH":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!p.ok){const d=await p.json();throw new Error(d.error||"Failed to save trigger")}await f(),A("list"),k(O()),R(!1)}catch(t){y(t instanceof Error?t.message:"Save failed")}finally{D(!1)}},[n,h,f]),me=o.useCallback(async t=>{try{await v(b(`/api/triggers/${t}`),{method:"DELETE"}),await f()}catch(s){console.error("Failed to delete trigger:",s)}},[f]),fe=o.useCallback(async t=>{try{await v(b(`/api/triggers/${t.id}`),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:!t.enabled})}),await f()}catch(s){console.error("Failed to toggle trigger:",s)}},[f]),ke=o.useCallback(async t=>{try{await v(b(`/api/triggers/${t}/fire`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({variables:{}})}),T===t&&await B(t)}catch(s){console.error("Failed to test fire trigger:",s)}},[T,B]),Ce=o.useCallback(async()=>{if(n.id){U(!0),M(null);try{let t;try{t=JSON.parse(F)}catch{M({structuralMatch:void 0,extractedVariables:{},wouldFire:!1}),y("Invalid JSON payload");return}const s=await v(b(`/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();M(a),y(null)}else{const a=await s.json();y(a.error||"Test match failed")}}catch(t){y(t instanceof Error?t.message:"Test match failed")}finally{U(!1)}}},[n.id,F]),we=o.useCallback(async t=>{var s;try{const a=await v(b("/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 p=await a.json();W(p.valid?p.nextFires:[])}}catch{W([])}},[n]),$=o.useCallback(t=>{t?(k({...t}),R(!0)):(k(O()),R(!1)),M(null),y(null),A("edit")},[]),x=o.useCallback((t,s)=>{k(a=>({...a,[t]:s}))},[]),r=o.useCallback((t,s)=>{k(a=>({...a,config:{...a.config,[t]:s}}))},[]),E=o.useCallback((t,s)=>{k(a=>({...a,llmMatch:{...a.llmMatch||{prompt:""},[t]:s}}))},[]),J=o.useCallback((t,s)=>{k(a=>({...a,llmExtract:{...a.llmExtract||{prompt:"",variables:[]},[t]:s}}))},[]),Se=o.useMemo(()=>Array.from(m.values()).map(t=>({id:t.id,name:t.name,class:t.class})),[m]),Te=o.useMemo(()=>{const t={all:j.length,webhook:0,bitbucket:0,cron:0,slack:0,email:0,jira:0,whatsapp:0};for(const s of j)s.type in t&&(t[s.type]+=1);return t},[j]),G=o.useMemo(()=>I==="all"?j:j.filter(t=>t.type===I),[j,I]),[K,V]=o.useState(null),Y=o.useCallback((t,s)=>{t&&navigator.clipboard.writeText(t).then(()=>{V(s),setTimeout(()=>V(a=>a===s?null:a),1500)},()=>y("Failed to copy to clipboard"))},[]);return w?e.jsx("div",{style:l.overlay,onClick:g,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:S==="list"?"Triggers":h?"Edit Trigger":"New Trigger"}),e.jsxs("div",{style:l.headerActions,children:[S==="list"&&e.jsx("button",{style:l.addBtn,onClick:()=>$(),children:"+ New Trigger"}),S==="edit"&&e.jsx("button",{style:l.backBtn,onClick:()=>{A("list"),M(null),y(null)},children:"Back"}),e.jsx("button",{style:l.closeBtn,onClick:g,children:"X"})]})]}),P&&e.jsx("div",{style:l.error,children:P}),S==="list"&&e.jsxs("div",{style:l.content,children:[e.jsx("div",{style:l.tabBar,role:"tablist","aria-label":"Filter triggers by type",children:Ae.map(t=>{const s=Te[t.value],a=I===t.value;return e.jsxs("button",{role:"tab","aria-selected":a,onClick:()=>ge(t.value),style:{...l.tab,...a?l.tabActive:{}},title:`${t.label} (${s})`,children:[e.jsx("span",{style:l.tabIcon,children:t.icon}),e.jsx("span",{style:l.tabLabel,children:t.label}),e.jsx("span",{style:{...l.tabBadge,...a?l.tabBadgeActive:{}},children:s})]},t.value)})}),j.length===0?e.jsx("div",{style:l.empty,children:"No triggers configured. Create one to get started."}):G.length===0?e.jsxs("div",{style:l.empty,children:["No ",I," triggers configured yet."]}):G.map(t=>{var s;return e.jsxs("div",{style:{...l.triggerCard,borderLeftColor:t.status==="error"?"#e74c3c":t.enabled?"#2ecc71":"#95a5a6"},onClick:()=>{ye(t.id),$(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(),fe(t)},children:t.enabled?"Disable":"Enable"}),e.jsx("button",{style:l.smallBtn,onClick:a=>{a.stopPropagation(),ke(t.id)},children:"Test Fire"}),e.jsx("button",{style:{...l.smallBtn,color:"#e74c3c"},onClick:a=>{a.stopPropagation(),me(t.id)},children:"Delete"})]})]}),e.jsxs("div",{style:l.cardMeta,children:[e.jsxs("span",{children:["Agent: ",((s=m.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)})]}),S==="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=>x("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=>x("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;x("type",s),s==="webhook"?x("config",{method:"POST"}):s==="cron"?x("config",{expression:"0 9 * * MON-FRI",timezone:"UTC"}):s==="bitbucket"?x("config",{workspace:"",repoSlug:"",events:["pullrequest:created","pullrequest:updated"]}):x("config",{}),(n.promptTemplate??"").trim()||(s==="slack"?x("promptTemplate",`Slack message from {{slack.user}} in {{slack.channelName}}:
4
4
  {{slack.message}}
@@ -1,4 +1,4 @@
1
- import{r as x,i as M,k as P,j as e,aC as J}from"./main-CEq_Fs_S.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const H=[{id:"intake",name:"Intake",type:"action",description:"Gather CC details from the developer via Slack",action:{type:"agent_task",agentId:"",promptTemplate:`A developer has requested a new CC (Control de Cambios). Here is their message:
1
+ import{r as x,i as M,k as P,j as e,aC as J}from"./main-aIpEYDDR.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 +1 @@
1
- import{p as i,k as r,K as n}from"./main-CEq_Fs_S.js";async function c(e,o){const t=n(),a=await fetch(r(`/api/areas/${e}/logo`),{method:"POST",headers:{"Content-Type":o.type||"image/png","X-Filename":encodeURIComponent(o.name),...t?{Authorization:`Bearer ${t}`}:{}},body:o});if(!a.ok){const s=await a.json().catch(()=>({error:a.statusText}));throw new Error(s.error||`Upload failed: ${a.statusText}`)}return a.json()}async function d(e){const o=n(),t=await fetch(r(`/api/areas/${e}/logo`),{method:"DELETE",headers:{...o?{Authorization:`Bearer ${o}`}:{}}});if(!t.ok)throw new Error(`Failed to delete logo: ${t.statusText}`)}function u(e){return i(r(`/api/areas/logos/${e}`))}export{d,u as g,c as u};
1
+ import{p as i,k as r,K as n}from"./main-aIpEYDDR.js";async function c(e,o){const t=n(),a=await fetch(r(`/api/areas/${e}/logo`),{method:"POST",headers:{"Content-Type":o.type||"image/png","X-Filename":encodeURIComponent(o.name),...t?{Authorization:`Bearer ${t}`}:{}},body:o});if(!a.ok){const s=await a.json().catch(()=>({error:a.statusText}));throw new Error(s.error||`Upload failed: ${a.statusText}`)}return a.json()}async function d(e){const o=n(),t=await fetch(r(`/api/areas/${e}/logo`),{method:"DELETE",headers:{...o?{Authorization:`Bearer ${o}`}:{}}});if(!t.ok)throw new Error(`Failed to delete logo: ${t.statusText}`)}function u(e){return i(r(`/api/areas/logos/${e}`))}export{d,u as g,c as u};
@@ -1 +1 @@
1
- import{u as U,a as ee,r as l,s as u,j as e,D as oe,I as L,C as me,b as be,c as ue,d as he,g as _e,e as pe,Q as xe,R as fe}from"./main-CEq_Fs_S.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const je=({building:a,connections:j,activeConnectionId:d,activeDatabase:n,collapsed:y,onToggleCollapse:_,onConnectionChange:D,onDatabaseChange:R,onInsertTable:N,onSelectTableQuery:F})=>{const{t:x}=U(["terminal"]),f=ee(a.id),[I,G]=l.useState(new Set),[T,r]=l.useState(""),[i,g]=l.useState(""),[w,O]=l.useState(!1),[P,J]=l.useState(null),H=l.useRef(null),K=l.useRef(null),C=l.useRef(null),k=d?f.databases.get(d)??[]:[],q=d&&n?`${d}:${n}`:"",$=q?f.tables.get(q)??[]:[],h=d?f.connectionStatus.get(d):void 0,E=l.useMemo(()=>{if(!T.trim())return k;const t=T.toLowerCase();return k.filter(o=>o.toLowerCase().includes(t))},[k,T]),z=l.useMemo(()=>{if(!i.trim())return $;const t=i.toLowerCase();return $.filter(o=>o.name.toLowerCase().includes(t))},[$,i]);l.useEffect(()=>{const t=o=>{K.current&&!K.current.contains(o.target)&&O(!1)};return w&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[w]),l.useEffect(()=>{d&&!h&&u.testDatabaseConnection(a.id,d)},[a.id,d,h]),l.useEffect(()=>{d&&(h!=null&&h.connected)&&k.length===0&&u.listDatabases(a.id,d)},[a.id,d,h==null?void 0:h.connected,k.length]),l.useEffect(()=>{d&&n&&$.length===0&&u.listTables(a.id,d,n)},[a.id,d,n,$.length]),l.useEffect(()=>{J(null),g("")},[d,n]);const b=l.useCallback(t=>{G(o=>{const v=new Set(o);if(v.has(t))v.delete(t);else if(v.add(t),d&&n){const S=`${d}:${n}:${t}`;f.tableSchemas.has(S)||u.getTableSchema(a.id,d,n,t)}return v})},[a.id,d,n,f.tableSchemas]),p=t=>{if(!d||!n)return null;const o=`${d}:${n}:${t}`;return f.tableSchemas.get(o)};return y?e.jsx("div",{className:"database-sidebar database-sidebar--collapsed",children:e.jsx("button",{className:"database-sidebar__toggle",onClick:_,title:x("terminal:database.expandSidebar"),children:"»"})}):e.jsxs("div",{className:"database-sidebar",children:[e.jsxs("div",{className:"database-sidebar__header",children:[e.jsx("span",{children:x("terminal:database.explorer")}),e.jsx("button",{className:"database-sidebar__toggle",onClick:_,title:x("terminal:database.collapseSidebar"),children:"«"})]}),e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:x("terminal:database.connection")}),e.jsx("select",{className:"database-sidebar__select",value:d||"",onChange:t=>D(t.target.value),children:j.length===0?e.jsx("option",{value:"",children:x("terminal:database.noConnections")}):j.map(t=>{var o;return e.jsxs("option",{value:t.id,children:[((o=oe[t.engine])==null?void 0:o.icon)??"🗄️"," ",t.name]},t.id)})}),h&&e.jsx("div",{className:`database-sidebar__status ${h.connected?"database-sidebar__status--connected":"database-sidebar__status--error"}`,children:h.connected?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✓"}),x("terminal:database.connected"),h.serverVersion&&e.jsxs("span",{className:"database-sidebar__version",children:["(",h.serverVersion,")"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✗"}),h.error||x("terminal:database.disconnected")]})})]}),k.length>0&&e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:x("terminal:database.databaseTitle")}),e.jsxs("div",{className:"database-sidebar__searchable-select",ref:K,children:[e.jsx("input",{ref:H,className:"database-sidebar__search-input",type:"text",value:w?T:n||"",placeholder:x("terminal:database.selectDatabase"),onChange:t=>{r(t.target.value),w||O(!0)},onFocus:()=>{O(!0),r("")},onKeyDown:t=>{var o,v;t.key==="Escape"?(O(!1),r(""),(o=H.current)==null||o.blur()):t.key==="Enter"&&E.length===1&&(R(E[0]),O(!1),r(""),(v=H.current)==null||v.blur())}}),w&&e.jsx("div",{className:"database-sidebar__dropdown",children:E.length===0?e.jsx("div",{className:"database-sidebar__dropdown-empty",children:"No matches"}):E.map(t=>e.jsx("div",{className:`database-sidebar__dropdown-item ${t===n?"database-sidebar__dropdown-item--active":""}`,onMouseDown:o=>{o.preventDefault(),R(t),O(!1),r("")},children:t},t))})]})]}),$.length>0&&e.jsxs("div",{className:"database-sidebar__section database-sidebar__section--tables",children:[e.jsx("div",{className:"database-sidebar__section-title",children:i.trim()?x("terminal:database.tablesCount",{count:z.length})+` / ${$.length}`:x("terminal:database.tablesCount",{count:$.length})}),e.jsxs("div",{className:"database-sidebar__table-filter",children:[e.jsx("input",{ref:C,className:"database-sidebar__table-filter-input",type:"text",value:i,placeholder:x("terminal:database.filterTables"),onChange:t=>g(t.target.value),onKeyDown:t=>{var o;t.key==="Escape"&&(i?g(""):(o=C.current)==null||o.blur(),t.stopPropagation())}}),i&&e.jsx("button",{className:"database-sidebar__table-filter-clear",onClick:()=>{var t;g(""),(t=C.current)==null||t.focus()},title:"Clear filter",children:"×"})]}),e.jsxs("div",{className:"database-sidebar__tables",children:[i.trim()&&z.length===0&&e.jsx("div",{className:"database-sidebar__tables-empty",children:x("terminal:database.noTablesMatch")}),z.map(t=>{const o=I.has(t.name),v=o?p(t.name):null;return e.jsxs("div",{className:"database-sidebar__table",children:[e.jsxs("div",{className:"database-sidebar__table-header",children:[e.jsx("button",{className:"database-sidebar__table-expand",onClick:()=>b(t.name),title:o?"Collapse table schema":"Expand table schema",children:e.jsx(L,{name:o?"caret-down":"caret-right",size:10})}),e.jsx("span",{className:"database-sidebar__table-icon",children:e.jsx(L,{name:t.type==="view"?"eye":"clipboard",size:12})}),e.jsx("span",{className:`database-sidebar__table-name ${P===t.name?"database-sidebar__table-name--selected":""}`,onClick:()=>J(t.name),onDoubleClick:()=>{J(t.name),F(t.name)},children:t.name}),e.jsx("button",{className:"database-sidebar__table-insert",onClick:S=>{S.stopPropagation(),N(t.name)},title:x("terminal:database.insertTableName"),children:"+"})]}),o&&v&&e.jsx("div",{className:"database-sidebar__table-columns",children:v.columns.map(S=>e.jsxs("div",{className:"database-sidebar__column",onClick:()=>N(S.name),title:`${S.type}${S.nullable?" NULL":" NOT NULL"}${S.primaryKey?" PK":""}`,children:[e.jsx("span",{className:"database-sidebar__column-icon",children:S.primaryKey?e.jsx(L,{name:"key",size:11}):null}),e.jsx("span",{className:"database-sidebar__column-name",children:S.name}),e.jsx("span",{className:"database-sidebar__column-type",children:S.type})]},S.name))})]},t.name)})]})]})]})},ye=({buildingId:a,history:j,onLoadQuery:d})=>{const{t:n}=U(["terminal","common"]),[y,_]=l.useState(""),[D,R]=l.useState(!1),[N,F]=l.useState(!1),x=l.useMemo(()=>{let r=j;if(D&&(r=r.filter(i=>i.favorite)),y.trim()){const i=y.toLowerCase();r=r.filter(g=>g.query.toLowerCase().includes(i)||g.database.toLowerCase().includes(i))}return r},[j,D,y]),f=r=>{const i=new Date(r),w=new Date().getTime()-i.getTime();return w<1440*60*1e3?i.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):w<10080*60*1e3?i.toLocaleDateString([],{weekday:"short"})+" "+i.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):i.toLocaleDateString([],{month:"short",day:"numeric"})},I=l.useCallback((r,i)=>{i.stopPropagation(),u.toggleQueryFavorite(a,r)},[a]),G=l.useCallback((r,i)=>{i.stopPropagation(),u.deleteQueryFromHistory(a,r)},[a]),T=l.useCallback(()=>{F(!0)},[]);return j.length===0?e.jsxs("div",{className:"query-history query-history--empty",children:[e.jsx("p",{children:n("terminal:database.noHistory")}),e.jsx("p",{children:n("terminal:database.queriesAppearHere")})]}):e.jsxs("div",{className:"query-history",children:[e.jsxs("div",{className:"query-history__toolbar",children:[e.jsx("input",{type:"text",className:"query-history__search",placeholder:n("terminal:database.searchQueries"),value:y,onChange:r=>_(r.target.value)}),e.jsxs("label",{className:"query-history__filter",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:r=>R(r.target.checked)}),n("terminal:database.favoritesOnly")]}),e.jsx("button",{className:"query-history__clear",onClick:T,title:n("terminal:database.clearAll"),children:n("terminal:database.clearAll")})]}),e.jsxs("div",{className:"query-history__list",children:[x.map(r=>e.jsxs("div",{className:`query-history__item ${r.status==="error"?"query-history__item--error":""}`,onClick:()=>d(r.query),children:[e.jsxs("div",{className:"query-history__item-header",children:[e.jsx("span",{className:`query-history__status ${r.status==="success"?"query-history__status--success":"query-history__status--error"}`,children:e.jsx(L,{name:r.status==="success"?"check":"cross",size:12})}),e.jsx("span",{className:"query-history__database",children:r.database}),e.jsx("span",{className:"query-history__date",children:f(r.executedAt)}),e.jsxs("span",{className:"query-history__duration",children:[r.duration,"ms"]}),r.rowCount!==void 0&&e.jsx("span",{className:"query-history__row-count",children:n("terminal:database.rowCount",{count:r.rowCount})})]}),e.jsx("div",{className:"query-history__query",children:e.jsx("code",{children:r.query.length>200?r.query.substring(0,200)+"...":r.query})}),r.error&&e.jsx("div",{className:"query-history__error",children:r.error}),e.jsxs("div",{className:"query-history__actions",children:[e.jsx("button",{className:`query-history__favorite ${r.favorite?"query-history__favorite--active":""}`,onClick:i=>I(r.id,i),title:r.favorite?n("terminal:database.removeFromFavorites"):n("terminal:database.addToFavorites"),children:e.jsx(L,{name:"star",size:12,weight:r.favorite?"fill":"regular",color:r.favorite?"#facc15":void 0})}),e.jsx("button",{className:"query-history__delete",onClick:i=>G(r.id,i),title:n("terminal:database.deleteFromHistory"),children:e.jsx(L,{name:"trash",size:12})})]})]},r.id)),x.length===0&&e.jsx("div",{className:"query-history__no-results",children:n("terminal:database.noQueriesMatch")})]}),e.jsx(me,{isOpen:N,title:n("terminal:database.clearAll"),message:n("terminal:database.confirmClearHistory"),confirmLabel:n("terminal:database.clearAll"),cancelLabel:n("common:buttons.cancel"),variant:"danger",onConfirm:()=>u.clearQueryHistory(a),onClose:()=>F(!1)})]})},Ne=({tabs:a,activeTabId:j,onTabClick:d,onTabClose:n})=>{const{t:y}=U(["terminal"]);return e.jsx("div",{className:"database-tabs",children:a.map(_=>e.jsxs("div",{className:`database-tabs__tab ${j===_.id?"database-tabs__tab--active":""}`,children:[e.jsxs("button",{className:"database-tabs__tab-label",onClick:()=>d(_),title:`${_.connectionName} / ${_.database}`,children:[_.database,e.jsx("span",{className:"database-tabs__tab-connection",children:_.connectionName})]}),e.jsx("button",{className:"database-tabs__tab-close",onClick:()=>n(_.id),title:y("terminal:database.closeTab"),"aria-label":`Close ${_.database} tab`,children:"×"})]},_.id))})},ae=a=>`db-panel-${a}`;function ve(a){try{const j=localStorage.getItem(ae(a));return j?JSON.parse(j):{}}catch{return{}}}function Se(a,j){try{localStorage.setItem(ae(a),JSON.stringify(j))}catch{}}const we=({building:a,onClose:j,onMinimize:d})=>{var W,Y,X,Z;const{t:n}=U(["terminal","common"]),y=ee(a.id),_=be(a.id),D=ue(a.id),R=he(a.id),N=l.useRef(ve(a.id)),F=l.useRef(null),x=l.useRef(0),f=((W=a.database)==null?void 0:W.connections)??[],I=(s,c)=>`${s}:${c}`,G=s=>s?(N.current.queries??{})[s]??"":N.current.generalQuery??"",[T,r]=l.useState("results"),[i,g]=l.useState(0),[w,O]=l.useState(!1),[P,J]=l.useState(!1),[H,K]=l.useState(()=>(N.current.openTabs??[]).map(c=>{var m;return{id:`${c.connectionId}:${c.database}`,connectionId:c.connectionId,connectionName:((m=f.find(A=>A.id===c.connectionId))==null?void 0:m.name)??c.connectionId,database:c.database}})),[C,k]=l.useState(N.current.activeTabId??null),[q,$]=l.useState(()=>{const s=N.current.queries??{};return N.current.generalQuery,s}),[h,E]=l.useState(G(C)),z=l.useCallback(s=>{E(c=>{const m=typeof s=="function"?s(c):s;return $(A=>{const Q={...A};return C&&(Q[C]=m),Q}),m})},[C]),b=y.activeConnectionId??N.current.connectionId??((Y=a.database)==null?void 0:Y.activeConnectionId)??((X=f[0])==null?void 0:X.id),p=y.activeDatabase??N.current.database??((Z=a.database)==null?void 0:Z.activeDatabase),t=f.find(s=>s.id===b),o=b&&p?`${b}:${p}`:"",v=o?y.tables.get(o)??[]:[],S=l.useMemo(()=>{const s=new Map;return!b||!p||v.forEach(c=>{const m=y.tableSchemas.get(`${b}:${p}:${c.name}`);m&&s.set(c.name,{columns:m.columns})}),s},[b,p,v,y.tableSchemas]),V=l.useCallback((s,c)=>{var Q;const m=I(s,c),A=((Q=f.find(M=>M.id===s))==null?void 0:Q.name)??s;K(M=>{if(M.some(de=>de.id===m))return M;const ie={id:m,connectionId:s,connectionName:A,database:c};return[...M,ie]}),k(m),E(q[m]??""),u.setActiveConnection(a.id,s),u.setActiveDatabase(a.id,c)},[a.id,f,q]),se=l.useCallback(s=>{K(c=>c.filter(m=>m.id!==s)),C===s&&K(c=>{if(c.length>0){const m=c[0];k(m.id),E(q[m.id]??""),u.setActiveConnection(a.id,m.connectionId),u.setActiveDatabase(a.id,m.database)}else k(null),E("");return c})},[C,a.id,q]),te=l.useCallback(s=>{k(s.id),E(q[s.id]??""),u.setActiveConnection(a.id,s.connectionId),u.setActiveDatabase(a.id,s.database)},[a.id,q]);l.useEffect(()=>{if(!P&&f.length>0){const s=N.current;s.connectionId&&f.some(c=>c.id===s.connectionId)&&(u.setActiveConnection(a.id,s.connectionId),u.listDatabases(a.id,s.connectionId),s.database&&(u.setActiveDatabase(a.id,s.database),u.listTables(a.id,s.connectionId,s.database))),J(!0)}},[a.id,f,P]),l.useEffect(()=>{u.requestQueryHistory(a.id)},[a.id]),l.useEffect(()=>{const s=c=>{c.key==="Escape"&&(c.preventDefault(),c.stopPropagation(),j())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[j]),l.useEffect(()=>{P&&b&&Se(a.id,{connectionId:b,database:p,lastQuery:h,queries:q,generalQuery:"",openTabs:H.map(s=>({connectionId:s.connectionId,database:s.database})),activeTabId:C??void 0})},[a.id,b,p,h,P,H,C,q]);const ne=l.useCallback(s=>{var c;if(!(!b||!p||!h.trim()||R))if(s==="cursor"){const m=(c=F.current)==null?void 0:c.querySelector(".query-editor__textarea"),A=(m==null?void 0:m.selectionStart)??x.current,Q=_e(h,A);Q&&u.executeQuery(a.id,b,p,Q)}else{const m=pe(h);if(m.length<=1)u.executeQuery(a.id,b,p,h.trim());else{const A=b,Q=p;(async()=>{for(const M of m)await u.executeQueryAndWait(a.id,A,Q,M.sql)})()}}},[a.id,b,p,h,R]),re=l.useCallback(s=>{z(s),r("results")},[]),le=l.useCallback(s=>{u.setActiveConnection(a.id,s),u.listDatabases(a.id,s)},[a.id]),ce=l.useCallback(s=>{b&&(V(b,s),u.listTables(a.id,b,s))},[a.id,b,V]),B=_[i];return f.length===0?e.jsxs("div",{className:"database-panel",ref:F,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:e.jsx(L,{name:"database",size:16})}),e.jsx("span",{className:"database-panel__name",children:a.name})]}),e.jsx("button",{className:"database-panel__close",onClick:j,children:"×"})]}),e.jsx("div",{className:"database-panel__body",children:e.jsxs("div",{className:"database-panel__no-connections",children:[e.jsx("div",{className:"database-panel__no-connections-icon",children:e.jsx(L,{name:"plug",size:32})}),e.jsx("h3",{children:n("terminal:database.noConnections")}),e.jsx("p",{children:n("terminal:database.noConnectionsDesc")}),e.jsx("p",{children:n("terminal:database.toGetStarted")}),e.jsxs("ol",{children:[e.jsx("li",{children:n("terminal:database.step1Close")}),e.jsx("li",{children:n("terminal:database.step2Settings")}),e.jsx("li",{children:n("terminal:database.step3AddConnection")}),e.jsx("li",{children:n("terminal:database.step4Reopen")})]})]})})]}):e.jsxs("div",{className:"database-panel",ref:F,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:(t==null?void 0:t.engine)==="mysql"?"🐬":"🐘"}),e.jsx("span",{className:"database-panel__name",children:a.name}),t&&e.jsxs("span",{className:"database-panel__connection-info",children:[t.name," / ",p||n("terminal:database.noDatabaseSelected")]})]}),e.jsxs("div",{className:"database-panel__header-actions",children:[d&&e.jsx("button",{className:"database-panel__close",onClick:d,title:"Minimize — dock below the terminal input",children:e.jsx(L,{name:"arrow-down",size:14})}),e.jsx("button",{className:"database-panel__close",onClick:j,children:"×"})]})]}),e.jsxs("div",{className:"database-panel__body",children:[e.jsx(je,{building:a,connections:f,activeConnectionId:b,activeDatabase:p,collapsed:w,onToggleCollapse:()=>O(!w),onConnectionChange:le,onDatabaseChange:ce,onInsertTable:s=>z(c=>c+` ${s}`),onSelectTableQuery:s=>{const c=`SELECT * FROM ${s}`;z(c),b&&p&&u.executeQuery(a.id,b,p,c)}}),e.jsxs("div",{className:"database-panel__main",children:[H.length>0&&e.jsx(Ne,{tabs:H,activeTabId:C,onTabClick:te,onTabClose:se}),e.jsx(xe,{query:h,onChange:z,onExecute:ne,isExecuting:R,disabled:!b||!p,tables:v,tableSchemas:S,onRequestTableSchema:s=>{b&&p&&u.getTableSchema(a.id,b,p,s)}}),e.jsxs("div",{className:"database-panel__tabs",children:[e.jsxs("button",{className:`database-panel__tab ${T==="results"?"database-panel__tab--active":""}`,onClick:()=>r("results"),children:[n("terminal:database.results"),_.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:_.length})]}),e.jsxs("button",{className:`database-panel__tab ${T==="history"?"database-panel__tab--active":""}`,onClick:()=>r("history"),children:[n("terminal:database.history"),D.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:D.length})]}),T==="results"&&_.length>1&&e.jsxs("div",{className:"database-panel__result-nav",children:[e.jsxs("button",{disabled:i>=_.length-1,onClick:()=>g(s=>s+1),children:["← ",n("terminal:database.older")]}),e.jsxs("span",{children:[i+1," / ",_.length]}),e.jsxs("button",{disabled:i<=0,onClick:()=>g(s=>s-1),children:[n("terminal:database.newer")," →"]})]})]}),e.jsx("div",{className:"database-panel__tab-content",children:T==="results"?B?e.jsx(fe,{result:B,buildingId:a.id,building:a}):e.jsxs("div",{className:"database-panel__empty",children:[e.jsx("p",{children:n("terminal:database.noResultsYet")}),e.jsx("p",{children:n("terminal:database.selectDbAndRun")})]}):e.jsx(ye,{buildingId:a.id,history:D,onLoadQuery:re})})]})]})]})};export{we as DatabasePanel,je as DatabaseSidebar,Ne as DatabaseTabs,xe as QueryEditor,ye as QueryHistoryPanel,fe as ResultsTable};
1
+ import{u as U,a as ee,r as l,s as u,j as e,D as oe,I as L,C as me,b as be,c as ue,d as he,g as _e,e as pe,Q as xe,R as fe}from"./main-aIpEYDDR.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const je=({building:a,connections:j,activeConnectionId:d,activeDatabase:n,collapsed:y,onToggleCollapse:_,onConnectionChange:D,onDatabaseChange:R,onInsertTable:N,onSelectTableQuery:F})=>{const{t:x}=U(["terminal"]),f=ee(a.id),[I,G]=l.useState(new Set),[T,r]=l.useState(""),[i,g]=l.useState(""),[w,O]=l.useState(!1),[P,J]=l.useState(null),H=l.useRef(null),K=l.useRef(null),C=l.useRef(null),k=d?f.databases.get(d)??[]:[],q=d&&n?`${d}:${n}`:"",$=q?f.tables.get(q)??[]:[],h=d?f.connectionStatus.get(d):void 0,E=l.useMemo(()=>{if(!T.trim())return k;const t=T.toLowerCase();return k.filter(o=>o.toLowerCase().includes(t))},[k,T]),z=l.useMemo(()=>{if(!i.trim())return $;const t=i.toLowerCase();return $.filter(o=>o.name.toLowerCase().includes(t))},[$,i]);l.useEffect(()=>{const t=o=>{K.current&&!K.current.contains(o.target)&&O(!1)};return w&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[w]),l.useEffect(()=>{d&&!h&&u.testDatabaseConnection(a.id,d)},[a.id,d,h]),l.useEffect(()=>{d&&(h!=null&&h.connected)&&k.length===0&&u.listDatabases(a.id,d)},[a.id,d,h==null?void 0:h.connected,k.length]),l.useEffect(()=>{d&&n&&$.length===0&&u.listTables(a.id,d,n)},[a.id,d,n,$.length]),l.useEffect(()=>{J(null),g("")},[d,n]);const b=l.useCallback(t=>{G(o=>{const v=new Set(o);if(v.has(t))v.delete(t);else if(v.add(t),d&&n){const S=`${d}:${n}:${t}`;f.tableSchemas.has(S)||u.getTableSchema(a.id,d,n,t)}return v})},[a.id,d,n,f.tableSchemas]),p=t=>{if(!d||!n)return null;const o=`${d}:${n}:${t}`;return f.tableSchemas.get(o)};return y?e.jsx("div",{className:"database-sidebar database-sidebar--collapsed",children:e.jsx("button",{className:"database-sidebar__toggle",onClick:_,title:x("terminal:database.expandSidebar"),children:"»"})}):e.jsxs("div",{className:"database-sidebar",children:[e.jsxs("div",{className:"database-sidebar__header",children:[e.jsx("span",{children:x("terminal:database.explorer")}),e.jsx("button",{className:"database-sidebar__toggle",onClick:_,title:x("terminal:database.collapseSidebar"),children:"«"})]}),e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:x("terminal:database.connection")}),e.jsx("select",{className:"database-sidebar__select",value:d||"",onChange:t=>D(t.target.value),children:j.length===0?e.jsx("option",{value:"",children:x("terminal:database.noConnections")}):j.map(t=>{var o;return e.jsxs("option",{value:t.id,children:[((o=oe[t.engine])==null?void 0:o.icon)??"🗄️"," ",t.name]},t.id)})}),h&&e.jsx("div",{className:`database-sidebar__status ${h.connected?"database-sidebar__status--connected":"database-sidebar__status--error"}`,children:h.connected?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✓"}),x("terminal:database.connected"),h.serverVersion&&e.jsxs("span",{className:"database-sidebar__version",children:["(",h.serverVersion,")"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✗"}),h.error||x("terminal:database.disconnected")]})})]}),k.length>0&&e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:x("terminal:database.databaseTitle")}),e.jsxs("div",{className:"database-sidebar__searchable-select",ref:K,children:[e.jsx("input",{ref:H,className:"database-sidebar__search-input",type:"text",value:w?T:n||"",placeholder:x("terminal:database.selectDatabase"),onChange:t=>{r(t.target.value),w||O(!0)},onFocus:()=>{O(!0),r("")},onKeyDown:t=>{var o,v;t.key==="Escape"?(O(!1),r(""),(o=H.current)==null||o.blur()):t.key==="Enter"&&E.length===1&&(R(E[0]),O(!1),r(""),(v=H.current)==null||v.blur())}}),w&&e.jsx("div",{className:"database-sidebar__dropdown",children:E.length===0?e.jsx("div",{className:"database-sidebar__dropdown-empty",children:"No matches"}):E.map(t=>e.jsx("div",{className:`database-sidebar__dropdown-item ${t===n?"database-sidebar__dropdown-item--active":""}`,onMouseDown:o=>{o.preventDefault(),R(t),O(!1),r("")},children:t},t))})]})]}),$.length>0&&e.jsxs("div",{className:"database-sidebar__section database-sidebar__section--tables",children:[e.jsx("div",{className:"database-sidebar__section-title",children:i.trim()?x("terminal:database.tablesCount",{count:z.length})+` / ${$.length}`:x("terminal:database.tablesCount",{count:$.length})}),e.jsxs("div",{className:"database-sidebar__table-filter",children:[e.jsx("input",{ref:C,className:"database-sidebar__table-filter-input",type:"text",value:i,placeholder:x("terminal:database.filterTables"),onChange:t=>g(t.target.value),onKeyDown:t=>{var o;t.key==="Escape"&&(i?g(""):(o=C.current)==null||o.blur(),t.stopPropagation())}}),i&&e.jsx("button",{className:"database-sidebar__table-filter-clear",onClick:()=>{var t;g(""),(t=C.current)==null||t.focus()},title:"Clear filter",children:"×"})]}),e.jsxs("div",{className:"database-sidebar__tables",children:[i.trim()&&z.length===0&&e.jsx("div",{className:"database-sidebar__tables-empty",children:x("terminal:database.noTablesMatch")}),z.map(t=>{const o=I.has(t.name),v=o?p(t.name):null;return e.jsxs("div",{className:"database-sidebar__table",children:[e.jsxs("div",{className:"database-sidebar__table-header",children:[e.jsx("button",{className:"database-sidebar__table-expand",onClick:()=>b(t.name),title:o?"Collapse table schema":"Expand table schema",children:e.jsx(L,{name:o?"caret-down":"caret-right",size:10})}),e.jsx("span",{className:"database-sidebar__table-icon",children:e.jsx(L,{name:t.type==="view"?"eye":"clipboard",size:12})}),e.jsx("span",{className:`database-sidebar__table-name ${P===t.name?"database-sidebar__table-name--selected":""}`,onClick:()=>J(t.name),onDoubleClick:()=>{J(t.name),F(t.name)},children:t.name}),e.jsx("button",{className:"database-sidebar__table-insert",onClick:S=>{S.stopPropagation(),N(t.name)},title:x("terminal:database.insertTableName"),children:"+"})]}),o&&v&&e.jsx("div",{className:"database-sidebar__table-columns",children:v.columns.map(S=>e.jsxs("div",{className:"database-sidebar__column",onClick:()=>N(S.name),title:`${S.type}${S.nullable?" NULL":" NOT NULL"}${S.primaryKey?" PK":""}`,children:[e.jsx("span",{className:"database-sidebar__column-icon",children:S.primaryKey?e.jsx(L,{name:"key",size:11}):null}),e.jsx("span",{className:"database-sidebar__column-name",children:S.name}),e.jsx("span",{className:"database-sidebar__column-type",children:S.type})]},S.name))})]},t.name)})]})]})]})},ye=({buildingId:a,history:j,onLoadQuery:d})=>{const{t:n}=U(["terminal","common"]),[y,_]=l.useState(""),[D,R]=l.useState(!1),[N,F]=l.useState(!1),x=l.useMemo(()=>{let r=j;if(D&&(r=r.filter(i=>i.favorite)),y.trim()){const i=y.toLowerCase();r=r.filter(g=>g.query.toLowerCase().includes(i)||g.database.toLowerCase().includes(i))}return r},[j,D,y]),f=r=>{const i=new Date(r),w=new Date().getTime()-i.getTime();return w<1440*60*1e3?i.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):w<10080*60*1e3?i.toLocaleDateString([],{weekday:"short"})+" "+i.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):i.toLocaleDateString([],{month:"short",day:"numeric"})},I=l.useCallback((r,i)=>{i.stopPropagation(),u.toggleQueryFavorite(a,r)},[a]),G=l.useCallback((r,i)=>{i.stopPropagation(),u.deleteQueryFromHistory(a,r)},[a]),T=l.useCallback(()=>{F(!0)},[]);return j.length===0?e.jsxs("div",{className:"query-history query-history--empty",children:[e.jsx("p",{children:n("terminal:database.noHistory")}),e.jsx("p",{children:n("terminal:database.queriesAppearHere")})]}):e.jsxs("div",{className:"query-history",children:[e.jsxs("div",{className:"query-history__toolbar",children:[e.jsx("input",{type:"text",className:"query-history__search",placeholder:n("terminal:database.searchQueries"),value:y,onChange:r=>_(r.target.value)}),e.jsxs("label",{className:"query-history__filter",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:r=>R(r.target.checked)}),n("terminal:database.favoritesOnly")]}),e.jsx("button",{className:"query-history__clear",onClick:T,title:n("terminal:database.clearAll"),children:n("terminal:database.clearAll")})]}),e.jsxs("div",{className:"query-history__list",children:[x.map(r=>e.jsxs("div",{className:`query-history__item ${r.status==="error"?"query-history__item--error":""}`,onClick:()=>d(r.query),children:[e.jsxs("div",{className:"query-history__item-header",children:[e.jsx("span",{className:`query-history__status ${r.status==="success"?"query-history__status--success":"query-history__status--error"}`,children:e.jsx(L,{name:r.status==="success"?"check":"cross",size:12})}),e.jsx("span",{className:"query-history__database",children:r.database}),e.jsx("span",{className:"query-history__date",children:f(r.executedAt)}),e.jsxs("span",{className:"query-history__duration",children:[r.duration,"ms"]}),r.rowCount!==void 0&&e.jsx("span",{className:"query-history__row-count",children:n("terminal:database.rowCount",{count:r.rowCount})})]}),e.jsx("div",{className:"query-history__query",children:e.jsx("code",{children:r.query.length>200?r.query.substring(0,200)+"...":r.query})}),r.error&&e.jsx("div",{className:"query-history__error",children:r.error}),e.jsxs("div",{className:"query-history__actions",children:[e.jsx("button",{className:`query-history__favorite ${r.favorite?"query-history__favorite--active":""}`,onClick:i=>I(r.id,i),title:r.favorite?n("terminal:database.removeFromFavorites"):n("terminal:database.addToFavorites"),children:e.jsx(L,{name:"star",size:12,weight:r.favorite?"fill":"regular",color:r.favorite?"#facc15":void 0})}),e.jsx("button",{className:"query-history__delete",onClick:i=>G(r.id,i),title:n("terminal:database.deleteFromHistory"),children:e.jsx(L,{name:"trash",size:12})})]})]},r.id)),x.length===0&&e.jsx("div",{className:"query-history__no-results",children:n("terminal:database.noQueriesMatch")})]}),e.jsx(me,{isOpen:N,title:n("terminal:database.clearAll"),message:n("terminal:database.confirmClearHistory"),confirmLabel:n("terminal:database.clearAll"),cancelLabel:n("common:buttons.cancel"),variant:"danger",onConfirm:()=>u.clearQueryHistory(a),onClose:()=>F(!1)})]})},Ne=({tabs:a,activeTabId:j,onTabClick:d,onTabClose:n})=>{const{t:y}=U(["terminal"]);return e.jsx("div",{className:"database-tabs",children:a.map(_=>e.jsxs("div",{className:`database-tabs__tab ${j===_.id?"database-tabs__tab--active":""}`,children:[e.jsxs("button",{className:"database-tabs__tab-label",onClick:()=>d(_),title:`${_.connectionName} / ${_.database}`,children:[_.database,e.jsx("span",{className:"database-tabs__tab-connection",children:_.connectionName})]}),e.jsx("button",{className:"database-tabs__tab-close",onClick:()=>n(_.id),title:y("terminal:database.closeTab"),"aria-label":`Close ${_.database} tab`,children:"×"})]},_.id))})},ae=a=>`db-panel-${a}`;function ve(a){try{const j=localStorage.getItem(ae(a));return j?JSON.parse(j):{}}catch{return{}}}function Se(a,j){try{localStorage.setItem(ae(a),JSON.stringify(j))}catch{}}const we=({building:a,onClose:j,onMinimize:d})=>{var W,Y,X,Z;const{t:n}=U(["terminal","common"]),y=ee(a.id),_=be(a.id),D=ue(a.id),R=he(a.id),N=l.useRef(ve(a.id)),F=l.useRef(null),x=l.useRef(0),f=((W=a.database)==null?void 0:W.connections)??[],I=(s,c)=>`${s}:${c}`,G=s=>s?(N.current.queries??{})[s]??"":N.current.generalQuery??"",[T,r]=l.useState("results"),[i,g]=l.useState(0),[w,O]=l.useState(!1),[P,J]=l.useState(!1),[H,K]=l.useState(()=>(N.current.openTabs??[]).map(c=>{var m;return{id:`${c.connectionId}:${c.database}`,connectionId:c.connectionId,connectionName:((m=f.find(A=>A.id===c.connectionId))==null?void 0:m.name)??c.connectionId,database:c.database}})),[C,k]=l.useState(N.current.activeTabId??null),[q,$]=l.useState(()=>{const s=N.current.queries??{};return N.current.generalQuery,s}),[h,E]=l.useState(G(C)),z=l.useCallback(s=>{E(c=>{const m=typeof s=="function"?s(c):s;return $(A=>{const Q={...A};return C&&(Q[C]=m),Q}),m})},[C]),b=y.activeConnectionId??N.current.connectionId??((Y=a.database)==null?void 0:Y.activeConnectionId)??((X=f[0])==null?void 0:X.id),p=y.activeDatabase??N.current.database??((Z=a.database)==null?void 0:Z.activeDatabase),t=f.find(s=>s.id===b),o=b&&p?`${b}:${p}`:"",v=o?y.tables.get(o)??[]:[],S=l.useMemo(()=>{const s=new Map;return!b||!p||v.forEach(c=>{const m=y.tableSchemas.get(`${b}:${p}:${c.name}`);m&&s.set(c.name,{columns:m.columns})}),s},[b,p,v,y.tableSchemas]),V=l.useCallback((s,c)=>{var Q;const m=I(s,c),A=((Q=f.find(M=>M.id===s))==null?void 0:Q.name)??s;K(M=>{if(M.some(de=>de.id===m))return M;const ie={id:m,connectionId:s,connectionName:A,database:c};return[...M,ie]}),k(m),E(q[m]??""),u.setActiveConnection(a.id,s),u.setActiveDatabase(a.id,c)},[a.id,f,q]),se=l.useCallback(s=>{K(c=>c.filter(m=>m.id!==s)),C===s&&K(c=>{if(c.length>0){const m=c[0];k(m.id),E(q[m.id]??""),u.setActiveConnection(a.id,m.connectionId),u.setActiveDatabase(a.id,m.database)}else k(null),E("");return c})},[C,a.id,q]),te=l.useCallback(s=>{k(s.id),E(q[s.id]??""),u.setActiveConnection(a.id,s.connectionId),u.setActiveDatabase(a.id,s.database)},[a.id,q]);l.useEffect(()=>{if(!P&&f.length>0){const s=N.current;s.connectionId&&f.some(c=>c.id===s.connectionId)&&(u.setActiveConnection(a.id,s.connectionId),u.listDatabases(a.id,s.connectionId),s.database&&(u.setActiveDatabase(a.id,s.database),u.listTables(a.id,s.connectionId,s.database))),J(!0)}},[a.id,f,P]),l.useEffect(()=>{u.requestQueryHistory(a.id)},[a.id]),l.useEffect(()=>{const s=c=>{c.key==="Escape"&&(c.preventDefault(),c.stopPropagation(),j())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[j]),l.useEffect(()=>{P&&b&&Se(a.id,{connectionId:b,database:p,lastQuery:h,queries:q,generalQuery:"",openTabs:H.map(s=>({connectionId:s.connectionId,database:s.database})),activeTabId:C??void 0})},[a.id,b,p,h,P,H,C,q]);const ne=l.useCallback(s=>{var c;if(!(!b||!p||!h.trim()||R))if(s==="cursor"){const m=(c=F.current)==null?void 0:c.querySelector(".query-editor__textarea"),A=(m==null?void 0:m.selectionStart)??x.current,Q=_e(h,A);Q&&u.executeQuery(a.id,b,p,Q)}else{const m=pe(h);if(m.length<=1)u.executeQuery(a.id,b,p,h.trim());else{const A=b,Q=p;(async()=>{for(const M of m)await u.executeQueryAndWait(a.id,A,Q,M.sql)})()}}},[a.id,b,p,h,R]),re=l.useCallback(s=>{z(s),r("results")},[]),le=l.useCallback(s=>{u.setActiveConnection(a.id,s),u.listDatabases(a.id,s)},[a.id]),ce=l.useCallback(s=>{b&&(V(b,s),u.listTables(a.id,b,s))},[a.id,b,V]),B=_[i];return f.length===0?e.jsxs("div",{className:"database-panel",ref:F,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:e.jsx(L,{name:"database",size:16})}),e.jsx("span",{className:"database-panel__name",children:a.name})]}),e.jsx("button",{className:"database-panel__close",onClick:j,children:"×"})]}),e.jsx("div",{className:"database-panel__body",children:e.jsxs("div",{className:"database-panel__no-connections",children:[e.jsx("div",{className:"database-panel__no-connections-icon",children:e.jsx(L,{name:"plug",size:32})}),e.jsx("h3",{children:n("terminal:database.noConnections")}),e.jsx("p",{children:n("terminal:database.noConnectionsDesc")}),e.jsx("p",{children:n("terminal:database.toGetStarted")}),e.jsxs("ol",{children:[e.jsx("li",{children:n("terminal:database.step1Close")}),e.jsx("li",{children:n("terminal:database.step2Settings")}),e.jsx("li",{children:n("terminal:database.step3AddConnection")}),e.jsx("li",{children:n("terminal:database.step4Reopen")})]})]})})]}):e.jsxs("div",{className:"database-panel",ref:F,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:(t==null?void 0:t.engine)==="mysql"?"🐬":"🐘"}),e.jsx("span",{className:"database-panel__name",children:a.name}),t&&e.jsxs("span",{className:"database-panel__connection-info",children:[t.name," / ",p||n("terminal:database.noDatabaseSelected")]})]}),e.jsxs("div",{className:"database-panel__header-actions",children:[d&&e.jsx("button",{className:"database-panel__close",onClick:d,title:"Minimize — dock below the terminal input",children:e.jsx(L,{name:"arrow-down",size:14})}),e.jsx("button",{className:"database-panel__close",onClick:j,children:"×"})]})]}),e.jsxs("div",{className:"database-panel__body",children:[e.jsx(je,{building:a,connections:f,activeConnectionId:b,activeDatabase:p,collapsed:w,onToggleCollapse:()=>O(!w),onConnectionChange:le,onDatabaseChange:ce,onInsertTable:s=>z(c=>c+` ${s}`),onSelectTableQuery:s=>{const c=`SELECT * FROM ${s}`;z(c),b&&p&&u.executeQuery(a.id,b,p,c)}}),e.jsxs("div",{className:"database-panel__main",children:[H.length>0&&e.jsx(Ne,{tabs:H,activeTabId:C,onTabClick:te,onTabClose:se}),e.jsx(xe,{query:h,onChange:z,onExecute:ne,isExecuting:R,disabled:!b||!p,tables:v,tableSchemas:S,onRequestTableSchema:s=>{b&&p&&u.getTableSchema(a.id,b,p,s)}}),e.jsxs("div",{className:"database-panel__tabs",children:[e.jsxs("button",{className:`database-panel__tab ${T==="results"?"database-panel__tab--active":""}`,onClick:()=>r("results"),children:[n("terminal:database.results"),_.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:_.length})]}),e.jsxs("button",{className:`database-panel__tab ${T==="history"?"database-panel__tab--active":""}`,onClick:()=>r("history"),children:[n("terminal:database.history"),D.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:D.length})]}),T==="results"&&_.length>1&&e.jsxs("div",{className:"database-panel__result-nav",children:[e.jsxs("button",{disabled:i>=_.length-1,onClick:()=>g(s=>s+1),children:["← ",n("terminal:database.older")]}),e.jsxs("span",{children:[i+1," / ",_.length]}),e.jsxs("button",{disabled:i<=0,onClick:()=>g(s=>s-1),children:[n("terminal:database.newer")," →"]})]})]}),e.jsx("div",{className:"database-panel__tab-content",children:T==="results"?B?e.jsx(fe,{result:B,buildingId:a.id,building:a}):e.jsxs("div",{className:"database-panel__empty",children:[e.jsx("p",{children:n("terminal:database.noResultsYet")}),e.jsx("p",{children:n("terminal:database.selectDbAndRun")})]}):e.jsx(ye,{buildingId:a.id,history:D,onLoadQuery:re})})]})]})]})};export{we as DatabasePanel,je as DatabaseSidebar,Ne as DatabaseTabs,xe as QueryEditor,ye as QueryHistoryPanel,fe as ResultsTable};