limixbot 0.3.22 → 0.3.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{ActivityPanel-ChjWicVw.js → ActivityPanel-BkpnvFMV.js} +1 -1
- package/dist/assets/App-5fWd2qWI.js +242 -0
- package/dist/assets/{AppEventEditor-NdlNZYiU.js → AppEventEditor-4U6g9rYH.js} +1 -1
- package/dist/assets/{BotSettingsDialog-DKIuZdV6.js → BotSettingsDialog-DBAjMChc.js} +1 -1
- package/dist/assets/{BrowserPanel-DjEwiL31.js → BrowserPanel-DKxFFmVF.js} +1 -1
- package/dist/assets/{BrowserProfilesManager-1DLRt4N9.js → BrowserProfilesManager-DbsOGGoV.js} +1 -1
- package/dist/assets/{CloudAddDialog-C0DMYGOm.js → CloudAddDialog-I2EDWXA8.js} +1 -1
- package/dist/assets/{ComputerFilesPane-Dk8NcRrf.js → ComputerFilesPane-DA4Txmh9.js} +1 -1
- package/dist/assets/{ComputerPanel-DoVcLtW7.js → ComputerPanel-B3EgKF7M.js} +2 -2
- package/dist/assets/{DataPanel-C0Fx7K2G.js → DataPanel-DALLlVzz.js} +1 -1
- package/dist/assets/{DesktopViewer-DTBmRKHz.js → DesktopViewer-BTFnhvej.js} +1 -1
- package/dist/assets/{FilesView-D5s67U7H.js → FilesView-DfvDhNdO.js} +1 -1
- package/dist/assets/{GrokMoveDialog-itIjM39_.js → GrokMoveDialog-CVgxiDZG.js} +1 -1
- package/dist/assets/{InspectorPanel-NMTlN3H-.js → InspectorPanel-B8d5f_Z7.js} +1 -1
- package/dist/assets/{KeyboardShortcutsModal-O3skmvQm.js → KeyboardShortcutsModal-C4Sy1Y5Q.js} +1 -1
- package/dist/assets/{LiveDesktop-CO9mKNtY.js → LiveDesktop-BdLw7_qb.js} +1 -1
- package/dist/assets/{LocalVmWorkspace-BLrh4g6E.js → LocalVmWorkspace-Dd8v6HSb.js} +1 -1
- package/dist/assets/{MacLocalControl-DyhXTfbp.js → MacLocalControl-DBItoJQX.js} +1 -1
- package/dist/assets/{MarkdownFilePreview-CyJn1rQP.js → MarkdownFilePreview-tXLtgk1m.js} +1 -1
- package/dist/assets/{MenuMotion-CobYpP7L.js → MenuMotion-DnbwlBMa.js} +1 -1
- package/dist/assets/{NewBotDialog-coMM5O6x.js → NewBotDialog-sfd-FzAz.js} +1 -1
- package/dist/assets/{PhoneAppDialog-D_CgApJp.js → PhoneAppDialog-D4klvpz5.js} +1 -1
- package/dist/assets/{PlacesRail-CUntVv3u.js → PlacesRail-BYBRFGDz.js} +1 -1
- package/dist/assets/{PluginsPanel-C2bbrSB3.js → PluginsPanel-DUOw0nhP.js} +1 -1
- package/dist/assets/{ProIntroduction-8BVPIU2J.js → ProIntroduction-B1eqbu20.js} +1 -1
- package/dist/assets/{RemoteAgentSettingsPanel-JMsDeyDs.js → RemoteAgentSettingsPanel-B46lWStL.js} +1 -1
- package/dist/assets/{RoomPanel-BcFX5BFK.js → RoomPanel-DBKyhryu.js} +1 -1
- package/dist/assets/{RoutinesPage-BZhG-dR9.js → RoutinesPage-CCSHgNRs.js} +1 -1
- package/dist/assets/SettingsModal-CwXiblca.js +15 -0
- package/dist/assets/{ShareTeamDialog-Cf4VzjYH.js → ShareTeamDialog-DuSs1saG.js} +1 -1
- package/dist/assets/{SignedInSites-31u9pN2b.js → SignedInSites-BdxFX6Wt.js} +1 -1
- package/dist/assets/{TeamLibraryPanel-Bzvx_MlH.js → TeamLibraryPanel-Djaf5q_z.js} +1 -1
- package/dist/assets/{TeamMapPage-BrrWMFul.js → TeamMapPage-PW3Ots-y.js} +1 -1
- package/dist/assets/{TriggersPage-GuMhNUuU.js → TriggersPage-D5jH7bR3.js} +1 -1
- package/dist/assets/{VisibilitySection-C6eVm1Hd.js → VisibilitySection-yE3ZIXKk.js} +1 -1
- package/dist/assets/{WebhookTrigger-BGm39FBT.js → WebhookTrigger-doGyrUZA.js} +1 -1
- package/dist/assets/{WorksOnGrid-9NWPGzbE.js → WorksOnGrid-DWvjM4aV.js} +1 -1
- package/dist/assets/{abnfDiagram-YUKMZFIV-DEyDkr0Q.js → abnfDiagram-YUKMZFIV-Bs9i-eLj.js} +1 -1
- package/dist/assets/{activity-CbpNb0MQ.js → activity-DIhOTAmd.js} +1 -1
- package/dist/assets/{architectureDiagram-47P4ROYG-CGTtcA9N.js → architectureDiagram-47P4ROYG-CR-7WHVu.js} +1 -1
- package/dist/assets/{blockDiagram-E7TT5TSB-DT9DFOL_.js → blockDiagram-E7TT5TSB-Cx9qUsrY.js} +1 -1
- package/dist/assets/{c4Diagram-CRA5TL53-DpERK75F.js → c4Diagram-CRA5TL53-CtuUaTlE.js} +1 -1
- package/dist/assets/{calendar-days-DE6WL-x2.js → calendar-days-DyyECwZf.js} +1 -1
- package/dist/assets/channel-DXuqtdcQ.js +1 -0
- package/dist/assets/{chunk-2Q5K7J3B-wHwpVFi3.js → chunk-2Q5K7J3B-DIvFRpG0.js} +1 -1
- package/dist/assets/{chunk-5VM5RSS4-CfqwqtdU.js → chunk-5VM5RSS4-Cxp3RKyR.js} +1 -1
- package/dist/assets/{chunk-7TKQ45FW-BRxQFxT-.js → chunk-7TKQ45FW-DSOW_9p2.js} +1 -1
- package/dist/assets/{chunk-AW2ZBBNX-Ca3w_5Wz.js → chunk-AW2ZBBNX-zV216OhN.js} +1 -1
- package/dist/assets/{chunk-FVRAUYC3-CO8Syt2Z.js → chunk-FVRAUYC3-BOtXkSrZ.js} +2 -2
- package/dist/assets/{chunk-HTAEGDNF-Cnx9DnWv.js → chunk-HTAEGDNF-DiV1eG2w.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-DefKEriK.js → chunk-JWPE2WC7-BZJyqcw-.js} +1 -1
- package/dist/assets/{chunk-KQW6MTUR-B6WWWz_R.js → chunk-KQW6MTUR-DabkPo_d.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY-BFU1-B3X.js → chunk-XXDRQBXY-CcZGTVYy.js} +1 -1
- package/dist/assets/{classDiagram-v2-K4WV4PDN-BePCpZI3.js → classDiagram-v2-K4WV4PDN-DfOdVcjL.js} +1 -1
- package/dist/assets/{coins-D1fhjgas.js → coins-s4HyWHyQ.js} +1 -1
- package/dist/assets/{core-GxNVTB-X.js → core-D7M03RiE.js} +1 -1
- package/dist/assets/{cose-bilkent-JH36ORCC-D8emtvin.js → cose-bilkent-JH36ORCC-CqrD5E-Q.js} +1 -1
- package/dist/assets/{cynefin-EF2NZ3EQ-DUEsfFVq.js → cynefin-EF2NZ3EQ-fcIOWtrM.js} +1 -1
- package/dist/assets/{cynefinDiagram-3GCD6N5R-duonepNA.js → cynefinDiagram-3GCD6N5R-Cx2XYJ57.js} +1 -1
- package/dist/assets/{dagre-W4DXFKR2-D4NywFNB.js → dagre-W4DXFKR2-D6f_32GP.js} +1 -1
- package/dist/assets/{diagram-2UJZ2QOL-cjiJTdiH.js → diagram-2UJZ2QOL-IxXxA3zr.js} +1 -1
- package/dist/assets/{diagram-OVF4WLC6-D6M8A9DS.js → diagram-OVF4WLC6-DzRS9og-.js} +1 -1
- package/dist/assets/{diagram-PFPMY2P6-CVAzAz2N.js → diagram-PFPMY2P6-CA4cF9TP.js} +1 -1
- package/dist/assets/{diagram-UMYRVEAY-DLvfYJwO.js → diagram-UMYRVEAY-B5YdB3mN.js} +1 -1
- package/dist/assets/{diagram-YEKJPTXX-D8qCH--0.js → diagram-YEKJPTXX-D8jMUZQ7.js} +1 -1
- package/dist/assets/{diagram-ZIFT7M5P-s55SHvTR.js → diagram-ZIFT7M5P-D9FKtuee.js} +1 -1
- package/dist/assets/{ebnfDiagram-VR2GEFS7-B93cNJNn.js → ebnfDiagram-VR2GEFS7-BipEfLA3.js} +1 -1
- package/dist/assets/{elk-IJKZMXRS-BsJqO8aU.js → elk-IJKZMXRS-ByA43ZYx.js} +1 -1
- package/dist/assets/{erDiagram-O2IAPWRE-BXF1G3Js.js → erDiagram-O2IAPWRE-hlDRgJN-.js} +1 -1
- package/dist/assets/{file-up-Cg2kYQkd.js → file-up-DXcOpz8w.js} +1 -1
- package/dist/assets/{flowDiagram-OXPTDLAJ-BKjjYwz9.js → flowDiagram-OXPTDLAJ-BuCuOW1m.js} +1 -1
- package/dist/assets/{ganttDiagram-R7TSEDQI-DhtZJtPm.js → ganttDiagram-R7TSEDQI-Bk16Ilgi.js} +1 -1
- package/dist/assets/{gitGraphDiagram-XJZIOB7I-BfRlcF5z.js → gitGraphDiagram-XJZIOB7I-CN3BXWBF.js} +1 -1
- package/dist/assets/{import-name-B8g_Hj2F.js → import-name-wz0BNJ-d.js} +1 -1
- package/dist/assets/{index-LBC94myy.js → index-BJo4IICg.js} +2 -2
- package/dist/assets/{index-B8LCAG4-.js → index-BR_1_bou.js} +1 -1
- package/dist/assets/{infoDiagram-5W2HQ5XZ-CywmYwco.js → infoDiagram-5W2HQ5XZ-DSUAydoj.js} +1 -1
- package/dist/assets/{ishikawaDiagram-K3B6WC7H-DpXXqau5.js → ishikawaDiagram-K3B6WC7H-C1_ZiQE2.js} +1 -1
- package/dist/assets/{journeyDiagram-COXZFDF6-D1uMWGbz.js → journeyDiagram-COXZFDF6-CAGOqBTO.js} +1 -1
- package/dist/assets/{kanban-definition-P3RFRI5V-Bz0zjqQs.js → kanban-definition-P3RFRI5V-Dj3_9GgV.js} +1 -1
- package/dist/assets/{mcp-servers-C_F4MXjY.js → mcp-servers-qzidl6IU.js} +1 -1
- package/dist/assets/{mermaid.core-Dnv6mcJ4.js → mermaid.core-CcbkAG9m.js} +4 -4
- package/dist/assets/{mindmap-definition-LZFPQGKD-CFEkTgom.js → mindmap-definition-LZFPQGKD-C_gFeuC9.js} +1 -1
- package/dist/assets/{minimize-o-OFVasg.js → minimize-DixQTKye.js} +1 -1
- package/dist/assets/{monitor-7oLB-7rZ.js → monitor-IwDx0ohO.js} +1 -1
- package/dist/assets/{new-bot-CFOYR98I.js → new-bot-COptZjiW.js} +1 -1
- package/dist/assets/{org-library-TYYMsAm5.js → org-library-97Cfj4XD.js} +1 -1
- package/dist/assets/{package-format-CrrPupM8.js → package-format-MbGfBQ0g.js} +1 -1
- package/dist/assets/{pegDiagram-BGZESJAR-DKt4SMwc.js → pegDiagram-BGZESJAR-CYa91QJf.js} +1 -1
- package/dist/assets/{pieDiagram-CAPJLFHJ-B9taKUge.js → pieDiagram-CAPJLFHJ-H4g7rmhD.js} +1 -1
- package/dist/assets/{quadrantDiagram-GDMTTRAM-DQjB7Jbz.js → quadrantDiagram-GDMTTRAM-CkHV6SSw.js} +1 -1
- package/dist/assets/{rail-BBdJiVR1.js → rail-SzaGJCSZ.js} +1 -1
- package/dist/assets/{railroadDiagram-SM67HX2B-DQOivC56.js → railroadDiagram-SM67HX2B-Kx3ccbrH.js} +1 -1
- package/dist/assets/{remote-desktop-panel-BmwpQiDu.js → remote-desktop-panel-CVuN83Ny.js} +1 -1
- package/dist/assets/{requirementDiagram-X7JNWC4A-BLgwXDEl.js → requirementDiagram-X7JNWC4A-BcNRqLgf.js} +1 -1
- package/dist/assets/{sankeyDiagram-UM26HJRW-g2GlJNjj.js → sankeyDiagram-UM26HJRW-CQP982o-.js} +1 -1
- package/dist/assets/{sequenceDiagram-ZO4K6R2Y-_08U7Ixl.js → sequenceDiagram-ZO4K6R2Y-BXkOAwlC.js} +1 -1
- package/dist/assets/{sizeCapture-INFHLROL-DZPfU3_U.js → sizeCapture-INFHLROL-BtuN-EAh.js} +1 -1
- package/dist/assets/{stateDiagram-v2-TBUQTH76-PXBjCkxd.js → stateDiagram-v2-TBUQTH76-CmlsJGhT.js} +1 -1
- package/dist/assets/styles-Di_mG4l3.css +1 -0
- package/dist/assets/{swimlanes-N4OXWK64-q1MhehBF.js → swimlanes-N4OXWK64-GH4PBeGD.js} +1 -1
- package/dist/assets/swimlanesDiagram-K3J5GTZL-VqQY3wNh.js +8 -0
- package/dist/assets/{team-share-xt--eeM_.js → team-share-B2cRBtNk.js} +1 -1
- package/dist/assets/{timeline-definition-YOQAKGHF-UBKh0GG-.js → timeline-definition-YOQAKGHF-j8Q7uetA.js} +1 -1
- package/dist/assets/{usecaseDiagram-VIAY4XPW-CccLioTT.js → usecaseDiagram-VIAY4XPW-Cz4ej3SQ.js} +1 -1
- package/dist/assets/{vennDiagram-BLWOH2XV-3Q39wQgE.js → vennDiagram-BLWOH2XV-BZ3IAGpt.js} +1 -1
- package/dist/assets/{wardleyDiagram-YMQ3BMBF-DtgEYK7j.js → wardleyDiagram-YMQ3BMBF-Bc32JfGA.js} +1 -1
- package/dist/assets/{xychartDiagram-TAQBALBS-DLTmsflK.js → xychartDiagram-TAQBALBS-s5XbB-l2.js} +1 -1
- package/dist/index.html +3 -3
- package/dist/rail.html +5 -5
- package/dist-server/index.js +12 -12
- package/dist-server/package.json +1 -1
- package/dist-server/server/limix-skill-hub.js +6 -8
- package/package.json +1 -1
- package/dist/assets/App-D-SXyZXT.js +0 -242
- package/dist/assets/SettingsModal-CWtO0RWS.js +0 -11
- package/dist/assets/channel-CETDvzTH.js +0 -1
- package/dist/assets/styles-B9SGxFnK.css +0 -1
- package/dist/assets/swimlanesDiagram-K3J5GTZL-pLYSpGVX.js +0 -8
- /package/dist/assets/{styles-BHtUK2qB.js → styles-ElM5u1od.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as We,t as s,r as a,j as e,a as ne,z as Qe,X as Be,f as kt,i as Ee,a8 as jt}from"./styles-BHtUK2qB.js";import{L as Re,X as wt,B as Ze,E as Ct,P as Ke,r as et,z as Nt,u as St}from"./PlacesRail-CUntVv3u.js";import{n as te,l as It,a0 as Mt,u as Ne,aQ as dt,by as ut,di as mt,cM as Tt,T as pt,dj as ft,dk as Et,dl as At,dm as Rt,dn as Ot,ck as xt,bw as Bt,ai as Ye,b5 as tt,dp as zt,dq as Dt,dr as Lt,D as ht,_ as $e,a3 as Je,ds as Pt,C as Ve,dt as $t,du as _t,e as Ht,dv as Kt,dw as Ut,dx as qt,dy as Ft,d2 as Xt,dz as Yt,dA as Jt,bP as Vt,dB as Gt,cN as Wt,dC as Qt,a4 as Zt,dD as en,dE as tn,dF as nn}from"./App-D-SXyZXT.js";import{M as Oe}from"./monitor-7oLB-7rZ.js";import{R as sn,a as an}from"./MenuMotion-CobYpP7L.js";import"./index-LBC94myy.js";const rn=[["path",{d:"M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719",key:"1sd12s"}]],on=We("message-circle",rn);const ln=[["path",{d:"M17 17H4a2 2 0 0 1-2-2V5c0-1.5 1-2 1-2",key:"k0q8oc"}],["path",{d:"M22 15V5a2 2 0 0 0-2-2H9",key:"cp1ac0"}],["path",{d:"M8 21h8",key:"1ev6f3"}],["path",{d:"M12 17v4",key:"1riwvh"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],cn=We("monitor-off",ln);const dn=[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]],un=We("save",dn),mn={collaborations:[],queued:[],running:[]};function pn(n,r=[]){const l=new Map;for(const d of n){if(d.hidden)continue;const i=d.section?.trim()||"";l.set(i,[...l.get(i)??[],d])}for(const d of r){const i=d.trim();i&&!l.has(i)&&l.set(i,[])}return[...l].map(([d,i])=>({key:d,name:d||s("teamSettings.general"),chiefs:i.filter(c=>c.chiefOfStaff),members:i.filter(c=>!c.chiefOfStaff)}))}function fn(n,r){const l=new Set(n.filter(c=>!c.hidden).map(c=>c.id)),d=new Map,i=(c,I)=>[c,I].sort().join(":");for(const c of r.collaborations){const[I,g]=c.botIds;!l.has(I)||!l.has(g)||d.set(i(I,g),{sourceBotId:I,targetBotId:g,state:"connected",groupId:c.groupId,lastAt:c.lastAt})}for(const c of r.queued)!l.has(c.sourceBotId)||!l.has(c.targetBotId)||d.set(i(c.sourceBotId,c.targetBotId),{sourceBotId:c.sourceBotId,targetBotId:c.targetBotId,state:"queued",reason:c.reason,groupId:c.groupId,threadId:c.threadId});for(const c of r.running)!l.has(c.sourceBotId)||!l.has(c.targetBotId)||d.set(i(c.sourceBotId,c.targetBotId),{sourceBotId:c.sourceBotId,targetBotId:c.targetBotId,state:"running",groupId:c.groupId,threadId:c.threadId});return[...d.values()].sort((c,I)=>{const g={running:0,queued:1,connected:2};return g[c.state]-g[I.state]||(I.lastAt??0)-(c.lastAt??0)})}function xn(n){return n.activity==="waiting-on-you"?{label:s("canvas.status.waiting"),tone:"warning"}:n.activity==="dead"||n.activity==="no-signal"?{label:s("canvas.status.noSignal"),tone:"danger"}:n.busy||n.activity==="working"?{label:s("canvas.status.working"),tone:"success"}:{label:s("canvas.status.ready"),tone:"idle"}}function hn(n){return n===1?s("canvas.botCountOne"):s("canvas.botCount",{count:n})}const _e=236,Me=126,He=16,we=20,Te=64,qe="application/x-omb-computer";function ke(n,r=[]){const l=new Map(r.map((d,i)=>[d,i]));return[...n].sort((d,i)=>(l.get(d.id)??1/0)-(l.get(i.id)??1/0))}function gn(n,r,l){const d=n.map(c=>c.id);if(!d.includes(r))return d;const i=d.filter(c=>c!==r);return i.splice(Math.max(0,Math.min(i.length,l)),0,r),i}function bn(n){try{const r=JSON.parse(n??"null");return r===null||typeof r!="object"||Array.isArray(r)?{}:Object.fromEntries(Object.entries(r).flatMap(([l,d])=>Array.isArray(d)?[[l,[...new Set(d.filter(i=>typeof i=="string"&&i.length>0))]]]:[]))}catch{return{}}}function gt(n){const r=n.chiefs.length>0&&n.members.length>0,l=r?Math.max(n.chiefs.length,n.members.length):Math.max(1,n.chiefs.length+n.members.length);return{width:_e*(r?2:1)+we*2+(r?40:0),height:Te+we+l*(Me+He)-He}}function yn(n,r,l={}){const d=l.sizes??n.map(gt),i=Math.max(1,Math.floor(l.columns??2)),c=[40];for(let g=1;g<i;g++){const x=Math.max(0,...d.filter((M,h)=>h%i===g-1).map(M=>M.width));c.push(c[g-1]+x+56)}let I=40;return n.map((g,x)=>{x>0&&x%i===0&&(I+=Math.max(...d.slice(x-i,x).map(h=>h.height))+56);const M=Object.hasOwn(r,g.key)?r[g.key]:void 0;return{key:g.key,x:M?.x??c[x%i],y:M?.y??I,...d[x]}})}function vn(n,r,l){if(!n.length)return{x:0,y:0,scale:1};const d=Math.min(...n.map(x=>x.x)),i=Math.min(...n.map(x=>x.y)),c=Math.max(...n.map(x=>x.x+x.width))-d,I=Math.max(...n.map(x=>x.y+x.height))-i,g=Math.max(.3,Math.min(1,(r-80)/c,(l-80)/I));return{x:(r-c*g)/2-d*g,y:(l-I*g)/2-i*g,scale:g}}function at(n,r,l){const d=r/n.scale;return{x:l.x-(l.x-n.x)*d,y:l.y-(l.y-n.y)*d,scale:r}}function kn(n){try{const r=JSON.parse(n??"null");return r===null||typeof r!="object"||Array.isArray(r)?{}:Object.fromEntries(Object.entries(r).flatMap(([l,d])=>{if(d===null||typeof d!="object"||Array.isArray(d))return[];const{x:i,y:c}=d;return typeof i=="number"&&Number.isFinite(i)&&Math.abs(i)<1e5&&typeof c=="number"&&Number.isFinite(c)&&Math.abs(c)<1e5?[[l,{x:i,y:c}]]:[]}))}catch{return{}}}const Ge=272,je=208,Fe=44,Xe=28;function jn(n,r){const l=[...n.chiefs,...n.members],d=l.filter(v=>r.own.has(v.id));if(!d.length&&!r.team)return null;const i=n.chiefs.length>0&&n.members.length>0,c=d.length?je:Me,I=v=>Te+v*(c+He),g=v=>I(v)+c/2,x=we+(i?Xe:0)+_e,M=x+Fe,h=l.map((v,y)=>({botId:v.id,x:we+(i&&y>=n.chiefs.length?Xe:0),y:I(y)+(c-Me)/2})),w=[],b=[];l.forEach((v,y)=>{const j=r.own.get(v.id);j&&(w.push({id:j,x:M,y:I(y)+(c-je)/2}),b.push({botId:v.id,computerId:j,points:[{x:h[y].x+_e,y:g(y)},{x:M,y:g(y)}]}))});const O=I(l.length)-He;let U=Math.max(O,Te+Me),A=d.length?M+Ge:x;if(r.team){const v=l.map((H,G)=>({bot:H,index:G})).filter(({bot:H})=>r.team.botIds.includes(H.id)),y=(v.length?v:l.map((H,G)=>({bot:H,index:G}))).map(({index:H})=>g(H)),j=y.length?(Math.min(...y)+Math.max(...y))/2:Te+je/2,B=A+Fe*(d.length?1.5:2),L=Math.max(Te,j-je/2),Y=B-Fe/2,_=L+je/2;w.push({id:r.team.id,x:B,y:L});for(const{bot:H,index:G}of v){const R={x:h[G].x+_e,y:g(G)};b.push({botId:H.id,computerId:r.team.id,points:[R,{x:Y,y:R.y},{x:Y,y:_},{x:B,y:_}]})}A=B+Ge,U=Math.max(U,L+je)}const K=[];if(i){const v=we+Xe/2,y=n.chiefs.length;K.push([{x:v,y:h[y-1].y+Me},{x:v,y:g(l.length-1)}]);for(let j=y;j<l.length;j++)K.push([{x:v,y:g(j)},{x:h[j].x,y:g(j)}])}return{width:A+we,height:U+we,cards:h,monitors:w,links:b,tree:K}}function wn(n,r,l=56){if(n.length<2||r.width<=0||r.height<=0)return 2;let d={columns:2,scale:0};for(let i=1;i<=Math.min(n.length,6);i++){const c=Array.from({length:i},(w,b)=>Math.max(0,...n.filter((O,U)=>U%i===b).map(O=>O.width))),I=Math.ceil(n.length/i),g=Array.from({length:I},(w,b)=>Math.max(0,...n.slice(b*i,b*i+i).map(O=>O.height))),x=c.reduce((w,b)=>w+b,0)+l*(i-1),M=g.reduce((w,b)=>w+b,0)+l*(I-1),h=Math.min((r.width-80)/x,(r.height-80)/M);h>d.scale+.01&&(d={columns:i,scale:h})}return d.columns}function rt(n){return n.map((r,l)=>`${l?"L":"M"}${r.x} ${r.y}`).join(" ")}const Cn=2e3;function Nn(n,r){return n.find(l=>l.kind==="bot"&&l.id===r)??n.find(l=>l.kind==="team"&&l.botIds.includes(r))}function Sn(n,r,l){const d=new Set(r),i=l.find(c=>c.kind==="team"&&c.section===n);return{own:new Map(l.filter(c=>c.kind==="bot"&&d.has(c.id)).map(c=>[c.id,c.id])),...i?{team:{id:i.id,botIds:i.botIds.filter(c=>d.has(c))}}:{}}}function In(n){return Object.entries(n).map(([r,l])=>`${r}:${l.version}`).join(",")}function Mn(n,r,l){return l-Math.max(0,r-n)}function Tn(n,r){const l=atob(n),d=new Uint8Array(l.length);for(let i=0;i<l.length;i++)d[i]=l.charCodeAt(i);return new Blob([d],{type:r})}function En(n){const[r,l]=a.useState(null),[d,i]=a.useState({}),[c,I]=a.useState(null),g=a.useRef(d);g.current=d;const x=a.useRef([]);x.current=r?.computers??[];const M=a.useRef(new Set),h=a.useRef(!0),w=a.useCallback(async(b,O,U,A,K)=>{if((g.current[b]?.at??-1/0)>=A)return;let v;try{v=URL.createObjectURL(Tn(O,U))}catch{return}try{const j=new Image;j.src=v,await j.decode()}catch{URL.revokeObjectURL(v);return}if(!h.current||(g.current[b]?.at??-1/0)>=A){URL.revokeObjectURL(v);return}const y=g.current[b]?.url;g.current={...g.current,[b]:{url:v,at:A,version:K}},i(g.current),y&&(M.current.add(y),window.setTimeout(()=>{URL.revokeObjectURL(y),M.current.delete(y)},2e3))},[]);return a.useEffect(()=>(h.current=!0,()=>{h.current=!1;for(const b of Object.values(g.current))URL.revokeObjectURL(b.url);for(const b of M.current)URL.revokeObjectURL(b)}),[]),a.useEffect(()=>{if(!n)return;let b=!1,O=!1;const U=async()=>{if(!(b||O||document.visibilityState!=="visible")){O=!0;try{const v=In(g.current),y=await te(`/api/computers/frames${v?`?have=${encodeURIComponent(v)}`:""}`,{signal:AbortSignal.timeout(3e4)});if(b)return;const j=Date.now();l(y),I(null);for(const B of y.computers){const L=B.frame;L?.data&&w(B.id,L.data,L.mime,Mn(L.at,y.now,j),L.version)}}catch(v){b||I(v instanceof Error?v.message:String(v))}finally{O=!1}}};U();const A=window.setInterval(U,Cn),K=It({screens:!0,onFrame:v=>{if(v.kind!=="screen"||v.surface!=="computer"||!v.png)return;const y=Nn(x.current,v.botId);y&&w(y.id,v.png,v.mime??"image/png",Date.now(),"live")}});return()=>{b=!0,window.clearInterval(A),K()}},[n,w]),{computers:r?.computers??[],configured:r?.configured??null,frames:d,error:c}}function An(n){const[r,l]=a.useState(null),[d,i]=a.useState(null),[c,I]=a.useState(!1);a.useEffect(()=>{let x=!0;return te("/.well-known/openmausbot/environment",{signal:AbortSignal.timeout(5e3)}).then(M=>{if(!x||typeof M.environmentId!="string")return;const h=`omb-team-canvas:${M.environmentId}:computers`;l(h);try{const w=localStorage.getItem(h);(w==="on"||w==="off")&&i(w==="on")}catch{}}).catch(()=>{}).finally(()=>{x&&I(!0)}),()=>{x=!1}},[]);const g=a.useCallback(x=>{if(i(x),!!r)try{localStorage.setItem(r,x?"on":"off")}catch{}},[r]);return{show:d??n,loaded:c,choose:g}}const ot=28;function Rn(n){if(n&&typeof n=="object"&&!Array.isArray(n))return n;if(typeof n!="string")return{};try{const r=JSON.parse(n);return r&&typeof r=="object"&&!Array.isArray(r)?r:{}}catch{return{}}}function On(n){const r=/(?:^|__)computer__(\w+)$/.exec(n.name)?.[1]??null;if(!r)return null;const l=Rn(n.input);if(r==="open_url")try{return s("mapComputer.step.open",{site:new URL(String(l.url)).hostname.replace(/^www\./,"")})}catch{return s("mapComputer.step.openPage")}if(r==="type_text"&&typeof l.text=="string"&&l.text.trim()){const d=l.text.replace(/\s+/g," ").trim();return s("mapComputer.step.type",{text:d.length>ot?`${d.slice(0,ot)}…`:d})}if(r==="key_press"){const d=[l.keys,l.key,l.combo].find(c=>typeof c=="string"||Array.isArray(c)),i=Array.isArray(d)?d.join("+"):typeof d=="string"?d:"";return i?s("mapComputer.step.key",{keys:i.slice(0,24)}):s("mapComputer.step.keyAny")}return r==="click"||r==="double_click"||r==="right_click"?s("mapComputer.step.click"):r==="scroll"?s("mapComputer.step.scroll"):r==="screenshot"?s("mapComputer.step.look"):r==="drag"?s("mapComputer.step.drag"):null}const it={starting:"mapComputer.state.starting",working:"mapComputer.state.working",idle:"mapComputer.state.idle",asleep:"mapComputer.state.asleep",off:"mapComputer.state.off",problem:"mapComputer.state.problem"},Bn={starting:"bg-warning",working:"bg-success",idle:"bg-sky-400",asleep:"bg-white/35",off:"bg-white/25",problem:"bg-danger"},zn=a.memo(function({computer:r,bots:l,frameUrl:d,state:i,activity:c,x:I,y:g,onOpen:x}){const M=i==="working",h=r.kind==="team"?r.name:s("mapComputer.botComputer",{name:r.name});return e.jsxs("div",{"data-computer-node":r.id,className:"absolute",style:{left:I,top:g,width:Ge,height:je},children:[M&&e.jsx("span",{"aria-hidden":!0,className:"pointer-events-none absolute -inset-[5px] animate-computer-glow rounded-[22px] border-2 border-success/70 shadow-[0_0_24px_rgba(52,199,89,0.35)]"}),e.jsxs("button",{type:"button",onClick:x,disabled:!x,title:c?`${h} · ${c}`:h,"aria-label":s("mapComputer.open",{name:h,state:s(it[i])}),className:"relative flex size-full flex-col rounded-[18px] border border-white/10 bg-[#0f1117] p-2 text-left shadow-[0_10px_30px_rgba(0,0,0,0.35)] outline-none transition-transform hover:-translate-y-0.5 focus-visible:ring-2 focus-visible:ring-accent disabled:cursor-default",children:[e.jsxs("span",{className:"relative block h-[160px] w-full overflow-hidden rounded-[8px] bg-[#06070b] [contain:paint]",children:[d?e.jsx("img",{src:d,alt:"",draggable:!1,decoding:"async",className:ne("size-full object-cover",i==="asleep"||i==="off"?"opacity-40 grayscale":"")}):e.jsxs("span",{className:"flex size-full flex-col items-center justify-center gap-2 bg-[radial-gradient(circle_at_50%_40%,#1b2030,#06070b_70%)] text-[11px] text-white/45",children:[i==="starting"?e.jsx(Re,{size:20,className:"animate-spin"}):i==="asleep"?e.jsx(wt,{size:20}):i==="problem"?e.jsx(Mt,{size:20}):e.jsx(cn,{size:20}),s(i==="starting"?"mapComputer.empty.starting":i==="asleep"?"mapComputer.empty.asleep":i==="problem"?"mapComputer.empty.problem":i==="off"?"mapComputer.empty.off":"mapComputer.empty.waiting")]}),e.jsxs("span",{className:"absolute left-2 top-2 flex items-center gap-1.5 rounded-full bg-black/65 px-2 py-0.5 text-[10px] font-medium text-white/90 backdrop-blur-[2px]",children:[e.jsx("span",{className:ne("size-1.5 rounded-full",Bn[i],M&&"animate-pulse")}),s(it[i])]}),c&&M&&e.jsx("span",{className:"absolute inset-x-0 bottom-0 truncate bg-gradient-to-t from-black/85 via-black/55 to-transparent px-2.5 pb-1.5 pt-6 text-[11px] leading-tight text-white/90",children:c})]}),e.jsxs("span",{className:"flex h-[32px] min-w-0 items-center gap-2 px-1 pt-1.5",children:[e.jsx("span",{className:"flex shrink-0 -space-x-1.5",children:l.slice(0,3).map(w=>e.jsx("span",{className:"rounded-full ring-2 ring-[#0f1117]",children:e.jsx(Ze,{bot:w,size:20,animated:!1,motion:"none",motionKey:0})},w.id))}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-medium text-white/90",children:h}),l.length>3&&e.jsxs("span",{className:"shrink-0 text-[10px] text-white/50",children:["+",l.length-3]})]})]})]})}),Ae="flex size-9 shrink-0 items-center justify-center rounded-lg text-ink-secondary hover:bg-control hover:text-ink focus-visible:outline-2 focus-visible:outline-accent",Ie="flex w-full items-center gap-2 rounded-lg px-3 py-2.5 text-left text-[12px] text-ink-secondary hover:bg-control hover:text-ink";function Dn({bot:n,selected:r,moving:l,connected:d,tagged:i=!1,sent:c,onComputer:I,onArrange:g}){const{state:x,dispatch:M}=Ne(),h=Qe(),w=xn(n),b=Ot(n,xt()),O=x.instances.find(A=>A.instanceId===n.modelSelection.instanceId),U=O?.models.options.find(A=>A.id===n.modelSelection.model)?.label??n.modelSelection.model;return e.jsxs("article",{className:ne("relative h-[126px] w-[236px] shrink-0 rounded-xl border bg-card shadow-sm transition-colors",r?"border-accent/60 ring-1 ring-accent/15":d?"border-accent/40":"border-hairline/50 hover:border-ink-secondary/40",i&&"border-accent ring-4 ring-accent/25",l&&"opacity-35"),children:[c!==void 0&&e.jsx("span",{"data-sent-highlight":!0,"aria-hidden":!0,className:"pointer-events-none absolute -inset-px animate-sent-border rounded-xl border-2 border-accent"},c),e.jsxs("button",{"data-bot-id":n.id,"aria-label":s("canvas.editBot",{name:b}),onClick:()=>Ye(M,"identity",{botId:n.id}),title:g?s("canvas.reorderHint"):void 0,onKeyDown:A=>{!g||!A.altKey||A.key!=="ArrowUp"&&A.key!=="ArrowDown"||(A.preventDefault(),A.stopPropagation(),g(n,A.key==="ArrowUp"?-1:1))},className:"flex h-[82px] w-full cursor-grab items-center gap-3 rounded-t-xl px-4 text-left active:cursor-grabbing focus-visible:outline-2 focus-visible:outline-accent",children:[e.jsx(Ze,{bot:n,size:38,motion:"none",motionKey:0,animated:!1}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-[14px] font-semibold",children:b}),n.chiefOfStaff&&e.jsx(Bt,{size:12,className:"shrink-0 text-warning","aria-label":s("chat.chiefOfStaff")})]}),e.jsx("span",{className:"mt-1 block truncate text-[11px] text-ink-secondary",children:n.title||(n.chiefOfStaff?s("chat.chiefOfStaff"):s("canvas.bot"))})]})]}),e.jsxs("div",{className:"flex h-[43px] items-center gap-1 border-t border-hairline/30 px-2",children:[e.jsx("button",{className:ne(Ae,"size-8"),"aria-label":s("canvas.openBotChat",{name:n.name}),title:s("canvas.openChat"),onClick:()=>tt(M,n,h),children:e.jsx(on,{size:13})}),w.tone!=="idle"&&e.jsxs("span",{className:"flex items-center gap-1.5 text-[10px] text-ink-secondary",title:w.label,children:[e.jsx("span",{className:ne("size-1.5 rounded-full",w.tone==="success"?"bg-success":w.tone==="warning"?"bg-warning":w.tone==="danger"?"bg-danger":"bg-ink-secondary/35")}),w.label]}),r&&I&&e.jsx("button",{className:ne(Ae,"size-8"),"aria-label":s("canvas.botComputer",{name:n.name}),title:s("computer.tab.computer"),onClick:()=>I(n),children:e.jsx(Oe,{size:13})}),e.jsxs("button",{"aria-label":s("canvas.changeModel",{name:n.name}),title:`${s("canvas.defaultModel")}: ${U}`,onClick:()=>Ye(M,"model",{botId:n.id}),className:"ml-auto flex h-8 min-w-0 max-w-[130px] items-center gap-1.5 rounded-md px-2 text-[10px] text-ink-secondary hover:bg-control hover:text-ink focus-visible:outline-2 focus-visible:outline-accent",children:[e.jsx("span",{className:"flex size-3.5 shrink-0 items-center justify-center",children:O?e.jsx(zt,{instance:O,size:13}):e.jsx(Dt,{driverKind:"",size:13})}),e.jsx("span",{className:"truncate",children:U||s("canvas.defaultModel")})]})]})]})}const Ln=[];function Pn(n,r){if(!n?.busy)return;const l=n.tasks?.find(i=>i.threadId===n.threadId),d=!l||l.busy?n.messages.findLast(i=>i.kind==="activity"&&i.tool):void 0;return d?.tool?On(d.tool)??At(d.tool,Rt(n,r),d.dataResult):n.tasks?.find(i=>i.busy&&i.threadId!==n.threadId&&i.title.trim())?.title}function $n({sections:n,canManage:r,onMove:l,onInstructions:d,onMemory:i,onEditTeam:c,onDeleteTeam:I,onComputer:g,onComputerDrop:x,onTeamComputer:M,teamComputers:h={},connectedBotIds:w=[],computers:b=Ln,computerFrames:O={},onOpenComputer:U,taggedBotIds:A=[],sent:K,bottomInset:v=0}){const{state:y}=Ne(),j=a.useRef(null),B=a.useRef(null),L=a.useRef(!1),Y=a.useRef(!1),_=a.useRef(null),[H,G]=a.useState({}),[R,q]=a.useState({}),[m,z]=a.useState({x:40,y:40,scale:1}),[N,$]=a.useState(null),[T,P]=a.useState(null),[se,S]=a.useState(null),[F,ee]=a.useState(null),[ie,re]=a.useState(null),[ue,de]=a.useState(""),[fe,me]=a.useState(!1),[he,ge]=a.useState(null),[ve,Se]=a.useState({width:0,height:0}),oe=a.useMemo(()=>n.map(t=>{if(!b.length)return null;const p=Object.hasOwn(R,t.key)?R[t.key]:[],u=ke(t.chiefs,p),C=ke(t.members,p);return jn({chiefs:u,members:C},Sn(t.key,[...u,...C].map(E=>E.id),b))}),[n,b,R]),pe=a.useMemo(()=>{if(!oe.some(Boolean))return;const t=oe.map((p,u)=>p??gt(n[u]));return{sizes:t,columns:wn(t,{width:Math.round(ve.width/200)*200,height:Math.round(ve.height/200)*200})}},[oe,n,ve]),be=a.useMemo(()=>yn(n,H,pe),[n,H,pe]),ce=a.useRef({view:m,positions:H,tiles:be,selectedId:y.selectedId,settingsOpen:y.settingsOpen,bottomInset:v});ce.current={view:m,positions:H,tiles:be,selectedId:y.selectedId,settingsOpen:y.settingsOpen,bottomInset:v},a.useEffect(()=>{let t=!0;return te("/.well-known/openmausbot/environment",{signal:AbortSignal.timeout(5e3)}).then(p=>{if(!(!t||typeof p.environmentId!="string")){_.current=`omb-team-canvas:${p.environmentId}`;try{const u=kn(localStorage.getItem(_.current));G(C=>({...u,...C})),q(bn(localStorage.getItem(`${_.current}:bot-order`)))}catch{}}}).catch(()=>{}).finally(()=>{t&&me(!0)}),()=>{t=!1}},[]);const f=t=>{if(G(t),!!_.current)try{localStorage.setItem(_.current,JSON.stringify(Object.fromEntries(n.filter(p=>Object.hasOwn(t,p.key)).map(p=>[p.key,t[p.key]]))))}catch{}},o=t=>Object.hasOwn(R,t)?R[t]:[],k=(t,p,u,C)=>{const E={...R,[t.key]:[...gn(p,u.id,C),...ke(u.chiefOfStaff?t.members:t.chiefs,o(t.key)).map(Q=>Q.id)]};if(q(E),_.current)try{localStorage.setItem(`${_.current}:bot-order`,JSON.stringify(E))}catch{}de(s("canvas.arrangedBot",{name:u.name,team:t.name}))},J=(t,p)=>{const u=n.find(E=>E.key===(t.section?.trim()??""));if(!u)return;const C=ke(t.chiefOfStaff?u.chiefs:u.members,o(u.key));k(u,C,t,C.findIndex(E=>E.id===t.id)+p)},Z=a.useCallback(()=>{const t=j.current?.getBoundingClientRect();t&&z(vn(ce.current.tiles,t.width,Math.max(200,t.height-ce.current.bottomInset)))},[]);a.useEffect(()=>{const t=j.current;if(!t)return;let p=null;const u=new ResizeObserver(()=>{const C=t.getBoundingClientRect();if(Se({width:C.width,height:C.height}),!p)Z();else{const E=ce.current.settingsOpen?[...t.querySelectorAll("[data-bot-id]")].find(V=>V.dataset.botId===ce.current.selectedId)?.getBoundingClientRect():void 0,Q=E?C.width/2-(E.left-C.left+E.width/2):(C.width-p.width)/2,ae=E?C.height/2-(E.top-C.top+E.height/2):(C.height-p.height)/2;z(V=>({...V,x:V.x+Q,y:V.y+ae}))}p={width:C.width,height:C.height}});return u.observe(t),()=>u.disconnect()},[Z]);const le=JSON.stringify(be.map(({key:t,width:p,height:u})=>[t,p,u]));a.useEffect(()=>{Z()},[Z,le,fe]),a.useEffect(()=>{const t=j.current?.querySelector("details[open]"),p=j.current?.getBoundingClientRect();t&&p&&ge(t.getBoundingClientRect().bottom>p.bottom-210*m.scale?t.closest("[data-team-key]")?.dataset.teamKey??null:null)},[m,le]),a.useEffect(()=>{const t=j.current;if(!t)return;const p=u=>{if(u.target.closest("details[open]")||(u.preventDefault(),B.current))return;const C=ce.current.view,E=t.getBoundingClientRect();if(u.ctrlKey||u.metaKey){const Q=Math.min(1.5,Math.max(.3,C.scale*Math.exp(-u.deltaY*.006)));z(at(C,Q,{x:u.clientX-E.left,y:u.clientY-E.top}))}else{const Q=u.deltaMode===1?16:u.deltaMode===2?E.height:1;z({...C,x:C.x-u.deltaX*Q,y:C.y-u.deltaY*Q})}};return t.addEventListener("wheel",p,{passive:!1}),()=>t.removeEventListener("wheel",p)},[]);const W=t=>{if(t.button!==0||!t.isPrimary||B.current)return;const p=t.target,u=p.closest("[data-bot-id]")?.dataset.botId,C=p.closest("[data-arrange-team]")?.dataset.arrangeTeam,E=u?n.flatMap(V=>[...V.chiefs,...V.members]).find(V=>V.id===u):void 0;if(!E&&C===void 0&&p.closest("button, details, a, input, [data-team-key]")||E&&(ie||!fe)||C!==void 0&&!fe)return;const Q={id:t.pointerId,start:{x:t.clientX,y:t.clientY},view:m,positions:H,moved:!1},ae=C===void 0?void 0:be.find(V=>V.key===C);B.current=E?{...Q,kind:"bot",bot:E}:ae?{...Q,kind:"team",key:ae.key,origin:ae}:{...Q,kind:"pan"},L.current=!1},nt=(t,p)=>{const u=document.elementFromPoint(t,p)?.closest("[data-team-key]");return u&&j.current?.contains(u)?u.dataset.teamKey??null:null},st=(t,p)=>{const u=n.find(V=>V.key===(t.section?.trim()??""));if(!u)return null;const C=ke(t.chiefOfStaff?u.chiefs:u.members,o(u.key)),E=C.filter(V=>V.id!==t.id),Q=[...j.current?.querySelectorAll("[data-bot-id]")??[]],ae=E.findIndex(V=>{const D=Q.find(X=>X.dataset.botId===V.id)?.closest("article")?.getBoundingClientRect();return D?p<D.top+D.height/2:!1});return{section:u,lane:C,remaining:E,index:ae<0?E.length:ae}},bt=t=>{const p=B.current;if(!p||p.id!==t.pointerId)return;if(t.buttons===0){Ce(t,!0);return}const u=t.clientX-p.start.x,C=t.clientY-p.start.y;if(!(!p.moved&&Math.hypot(u,C)<5)&&(p.moved=!0,t.currentTarget.setPointerCapture(t.pointerId),p.kind==="pan"&&z({...p.view,x:p.view.x+u,y:p.view.y+C}),p.kind==="team"&&G({...p.positions,[p.key]:{x:p.origin.x+u/m.scale,y:p.origin.y+C/m.scale}}),p.kind==="bot")){const E=t.currentTarget.getBoundingClientRect();$({bot:p.bot,point:{x:t.clientX-E.left,y:t.clientY-E.top}});const Q=nt(t.clientX,t.clientY),ae=Q===(p.bot.section?.trim()??"");P(ae||r?Q:null);const V=ae?st(p.bot,t.clientY):null,D=V?.remaining[V.index]??V?.remaining.at(-1);ee(V&&D?{botId:D.id,after:V.index===V.remaining.length}:null)}},Ce=(t,p=!1)=>{const u=B.current;if(!(!u||t&&u.id!==t.pointerId)){if(B.current=null,L.current=u.moved,window.setTimeout(()=>{L.current=!1},0),$(null),P(null),ee(null),j.current?.hasPointerCapture(u.id)&&j.current.releasePointerCapture(u.id),p){G(u.positions),z(u.view);return}if(u.moved&&(u.kind==="team"&&t&&f({...u.positions,[u.key]:{x:u.origin.x+(t.clientX-u.start.x)/u.view.scale,y:u.origin.y+(t.clientY-u.start.y)/u.view.scale}}),u.kind==="bot"&&t)){const C=nt(t.clientX,t.clientY);if(C===null)return;if(C===(u.bot.section?.trim()??"")){const E=st(u.bot,t.clientY);E&&k(E.section,E.lane,u.bot,E.index);return}if(!r)return;re(u.bot.id),de(s("canvas.reviewMove",{name:u.bot.name,team:C||s("settings.section.general")})),l(u.bot,C).then(E=>{de(E===!1?s("canvas.moveCancelled"):s("canvas.moved",{name:u.bot.name,team:C||s("settings.section.general")}))}).catch(E=>{de(E instanceof Error?E.message:String(E))}).finally(()=>re(null))}}},ze=t=>{const p=j.current?.getBoundingClientRect();p&&z(at(m,Math.max(.3,Math.min(1.5,m.scale*t)),{x:p.width/2,y:p.height/2}))},De=new Map(n.flatMap(t=>[...t.chiefs,...t.members]).map(t=>[t.id,t])),yt=new Map(b.map(t=>[t.id,t])),vt=t=>{const p=t.botIds.flatMap(u=>De.get(u)??[]);return t.state==="idle"&&p.some(u=>u.busy)?"working":t.state!=="working"&&p.some(u=>y.computerStarts[u.id])?"starting":t.state},Le=n.find(t=>t.key===T),Pe=se!==null?s("canvas.assignComputer",{team:n.find(t=>t.key===se)?.name??se}):N&&Le?(N.bot.section?.trim()??"")===Le.key?s("canvas.arrangeBot",{name:N.bot.name,team:Le.name}):s("canvas.moveBot",{name:N.bot.name,team:Le.name}):null;return e.jsxs("div",{ref:j,role:"region","aria-label":s("canvas.region"),tabIndex:0,"data-team-canvas":!0,className:"relative min-h-0 flex-1 touch-none overflow-clip outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent/40",style:{backgroundImage:"radial-gradient(circle, color-mix(in srgb, var(--color-ink-secondary) 18%, transparent) 1px, transparent 1px)",backgroundSize:`${24*m.scale}px ${24*m.scale}px`,backgroundPosition:`${m.x}px ${m.y}px`},onPointerDown:W,onPointerMove:bt,onPointerUp:t=>Ce(t),onPointerCancel:t=>Ce(t,!0),onDragOver:t=>{if(!r||!x||!t.dataTransfer.types.includes(qe))return;const p=t.target.closest("[data-team-key]"),u=p&&t.currentTarget.contains(p)?p.dataset.teamKey??null:null;S(u),u!==null&&(t.preventDefault(),t.dataTransfer.dropEffect="link")},onDragLeave:t=>{(!(t.relatedTarget instanceof Node)||!t.currentTarget.contains(t.relatedTarget))&&S(null)},onDrop:t=>{if(S(null),!r||!x||!t.dataTransfer.types.includes(qe))return;const p=t.target.closest("[data-team-key]"),u=p&&t.currentTarget.contains(p)?p.dataset.teamKey:void 0,C=t.dataTransfer.getData(qe);u===void 0||!n.some(E=>E.key===u)||!C||(t.preventDefault(),x(C,u))},onDragEnd:()=>S(null),onPointerDownCapture:t=>{Y.current=!1,t.target.closest("details")||t.currentTarget.querySelectorAll("details[open]").forEach(p=>p.removeAttribute("open"))},onKeyDownCapture:t=>{t.key==="Tab"&&(Y.current=!0)},onPointerLeave:()=>{B.current&&!B.current.moved&&Ce(void 0,!0)},onLostPointerCapture:()=>{B.current&&Ce(void 0,!0)},onFocusCapture:t=>{if(!Y.current||!(t.target instanceof HTMLElement)||!t.target.closest("[data-canvas-world]"))return;const p=t.currentTarget.getBoundingClientRect(),u=t.target.getBoundingClientRect(),C=u.left<p.left+16?p.left+16-u.left:u.right>p.right-16?p.right-16-u.right:0,E=u.top<p.top+16?p.top+16-u.top:u.bottom>p.bottom-70?p.bottom-70-u.bottom:0;(C||E)&&z(Q=>({...Q,x:Q.x+C,y:Q.y+E}))},onClickCapture:t=>{L.current&&(L.current=!1,t.preventDefault(),t.stopPropagation())},onKeyDown:t=>{if(t.key==="Escape"&&(Ce(void 0,!0),t.currentTarget.querySelectorAll("details[open]").forEach(C=>{C.querySelector("summary")?.focus({preventScroll:!0}),C.removeAttribute("open")})),t.target!==t.currentTarget)return;const u={ArrowLeft:{x:60,y:0},ArrowRight:{x:-60,y:0},ArrowUp:{x:0,y:60},ArrowDown:{x:0,y:-60}}[t.key];u&&(t.preventDefault(),z({...m,x:m.x+u.x,y:m.y+u.y})),(t.key==="+"||t.key==="=")&&(t.preventDefault(),ze(1.2)),t.key==="-"&&(t.preventDefault(),ze(1/1.2)),t.key==="0"&&(t.preventDefault(),Z())},children:[e.jsx("div",{"data-canvas-world":!0,className:"absolute left-0 top-0 origin-top-left",style:{transform:`translate(${m.x}px, ${m.y}px) scale(${m.scale})`},children:n.map((t,p)=>{const u=be[p],C=oe[p],E=t.chiefs.length>0&&t.members.length>0,Q=se===t.key||N&&T===t.key&&(N.bot.section?.trim()??"")!==t.key,ae=Object.hasOwn(h,t.key)?h[t.key]:void 0,V=D=>e.jsxs("div",{className:"relative",children:[F?.botId===D.id&&e.jsx("div",{className:ne("pointer-events-none absolute inset-x-1 h-0.5 rounded bg-accent",F.after?"-bottom-[9px]":"-top-[9px]")}),e.jsx(Dn,{bot:D,selected:y.selectedId===D.id&&y.settingsOpen,moving:N?.bot.id===D.id||ie===D.id,connected:w.includes(D.id),tagged:A.includes(D.id),sent:K?.botIds.includes(D.id)?K.key:void 0,onComputer:g,onArrange:fe?J:void 0})]},D.id);return e.jsxs("section",{"data-team-key":t.key,"aria-label":s("canvas.teamRegion",{name:t.name}),className:ne("absolute rounded-2xl border bg-panel/90 shadow-sm has-[details[open]]:z-20 data-[computer-dropping=true]:border-accent data-[computer-dropping=true]:ring-2 data-[computer-dropping=true]:ring-accent/25",Q?"border-accent ring-2 ring-accent/25":"border-hairline/50"),style:{left:u.x,top:u.y,width:u.width,height:u.height},children:[e.jsxs("header",{className:"flex h-16 items-center gap-2 px-5",children:[e.jsx("button",{"data-arrange-team":t.key,disabled:!fe,"aria-label":s("canvas.arrange",{name:t.name}),title:s("canvas.arrangeHint"),className:"min-w-0 flex-1 cursor-grab rounded-md py-2 text-left active:cursor-grabbing focus-visible:outline-2 focus-visible:outline-accent",onKeyDown:D=>{const X={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]}[D.key];if(!X)return;D.preventDefault(),D.stopPropagation();const ye=D.shiftKey?40:10;f({...H,[t.key]:{x:u.x+X[0]*ye,y:u.y+X[1]*ye}})},children:e.jsx("h2",{className:"truncate text-[13px] font-semibold tracking-tight",children:t.name})}),ae&&e.jsxs("button",{"aria-label":s("canvas.teamComputer",{team:t.name,name:ae.name}),title:`${ae.name}${ae.state?` · ${ae.state}`:""}`,disabled:!M,onClick:()=>M?.(t.key),className:"flex min-w-0 max-w-[120px] shrink items-center gap-1.5 rounded-md px-1.5 py-2 text-[10px] text-ink-secondary hover:bg-control hover:text-ink focus-visible:outline-2 focus-visible:outline-accent disabled:pointer-events-none",children:[e.jsx(Oe,{size:12,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:ae.name})]}),e.jsx("span",{className:"text-[11px] tabular-nums text-ink-secondary",children:t.chiefs.length+t.members.length}),r&&e.jsxs("details",{className:"relative",onToggle:D=>{if(D.currentTarget.open){const X=j.current?.getBoundingClientRect();ge(X&&D.currentTarget.getBoundingClientRect().bottom>X.bottom-210*m.scale?t.key:null),j.current?.querySelectorAll("details[open]").forEach(ye=>{ye!==D.currentTarget&&ye.removeAttribute("open")})}},children:[e.jsx("summary",{"aria-label":s("canvas.manageTeam",{name:t.name}),className:ne(Ae,"cursor-pointer list-none [&::-webkit-details-marker]:hidden"),children:e.jsx(Ct,{size:17})}),e.jsxs("div",{className:ne("absolute right-0 z-30 w-[220px] animate-pop-in rounded-xl border border-hairline bg-panel p-1.5 shadow-xl",he===t.key?"bottom-10":"top-10"),onClick:D=>{const X=D.currentTarget.closest("details");X?.querySelector("summary")?.focus(),X?.removeAttribute("open")},children:[e.jsxs("button",{className:Ie,onClick:()=>c(t.key),"aria-label":s("team.moveTo",{name:t.name}),children:[e.jsx(dt,{size:14}),s("team.moveTo",{name:t.name})]}),e.jsxs("button",{className:Ie,onClick:()=>d(t.key,t.name),"aria-label":s("team.instructionsEdit",{name:t.name}),children:[e.jsx(ut,{size:14}),s("team.instructions")]}),i&&e.jsxs("button",{className:Ie,onClick:()=>i(t.key,t.name),"aria-label":s("team.memoryFor",{name:t.name}),children:[e.jsx(mt,{size:14}),s("team.memory")]}),t.key&&e.jsxs("button",{className:Ie,onClick:()=>c(t.key,!0),"aria-label":s("team.renameAria",{name:t.name}),children:[e.jsx(Tt,{size:14}),s("team.rename")]}),t.key&&e.jsxs("button",{className:ne(Ie,"hover:text-danger"),onClick:()=>I(t.key),"aria-label":s("team.deleteAria",{name:t.name}),children:[e.jsx(pt,{size:14}),s("team.delete")]})]})]})]}),Q&&e.jsx("div",{className:"pointer-events-none absolute -top-7 left-2 z-30 max-w-[calc(100%-16px)] truncate rounded-md bg-accent px-2 py-1 text-[10px] text-white shadow-sm",children:Pe}),C?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 overflow-visible",width:u.width,height:u.height,children:[C.tree.map((D,X)=>e.jsx("path",{d:rt(D),fill:"none",strokeWidth:1.5,className:"stroke-ink-secondary/25"},`tree-${X}`)),C.links.map(D=>{const X=De.get(D.botId)?.busy===!0;return e.jsx("path",{d:rt(D.points),fill:"none",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:X?2.25:1.5,strokeDasharray:X?"7 5":void 0,className:X?"animate-link-flow stroke-success/80":"stroke-ink-secondary/35"},`${D.botId}:${D.computerId}`)})]}),C.cards.map(D=>{const X=De.get(D.botId);return X?e.jsx("div",{className:"absolute",style:{left:D.x,top:D.y},children:V(X)},X.id):null}),C.monitors.map(D=>{const X=yt.get(D.id);if(!X)return null;const ye=X.botIds.flatMap(Ue=>De.get(Ue)??[]);return e.jsx(zn,{computer:X,bots:ye,x:D.x,y:D.y,frameUrl:Object.hasOwn(O,X.id)?O[X.id].url:void 0,state:vt(X),activity:Pn(ye.find(Ue=>Ue.busy),y.instances),onOpen:U?()=>U(X):void 0},X.id)})]}):e.jsxs("div",{className:"flex items-center px-5 pb-5",children:[t.chiefs.length>0&&e.jsx("div",{className:"flex flex-col gap-4",children:ke(t.chiefs,o(t.key)).map(V)}),E&&e.jsx("div",{className:"flex w-10 shrink-0 justify-center text-ink-secondary/35","aria-hidden":"true",children:e.jsx(ft,{size:22,strokeWidth:1})}),t.members.length>0&&e.jsx("div",{className:"flex flex-col gap-4",children:ke(t.members,o(t.key)).map(V)}),t.chiefs.length+t.members.length===0&&e.jsx("p",{className:"flex h-[126px] w-[236px] items-center justify-center rounded-xl border border-dashed border-hairline/70 px-6 text-center text-[12px] leading-relaxed text-ink-secondary",children:s("canvas.dropHere")})]})]},t.key)})}),N&&e.jsxs("div",{className:"pointer-events-none absolute z-40 rounded-xl border border-accent/40 bg-card px-4 py-3 text-[13px] shadow-lg",style:{left:N.point.x+16,top:N.point.y+16},children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Ze,{bot:N.bot,size:24,animated:!1}),N.bot.name]}),Pe&&e.jsx("p",{className:"mt-1 text-[10px] text-ink-secondary",children:Pe})]}),e.jsxs("div",{className:"pointer-events-none absolute inset-x-5 bottom-5 flex items-end justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 rounded-lg bg-app/90 px-2 py-1.5 text-[11px] text-ink-secondary",children:[!v&&e.jsx("p",{className:"max-sm:hidden",children:s("canvas.hint")}),e.jsx("p",{role:"status","aria-live":"polite",className:"max-w-[440px]",children:Pe??ue})]}),e.jsxs("div",{className:"pointer-events-auto flex shrink-0 items-center gap-0.5 rounded-xl border border-hairline/60 bg-panel p-1 shadow-sm",children:[e.jsx("button",{className:Ae,"aria-label":s("canvas.zoomOut"),onClick:()=>ze(1/1.2),children:e.jsx(Et,{size:15})}),e.jsxs("button",{className:"min-w-12 rounded-md px-1 py-2 text-[11px] tabular-nums text-ink-secondary hover:bg-control","aria-label":s("canvas.fit"),title:s("canvas.fitHint"),onClick:Z,children:[Math.round(m.scale*100),"%"]}),e.jsx("button",{className:Ae,"aria-label":s("canvas.zoomIn"),onClick:()=>ze(1.2),children:e.jsx(Ke,{size:15})})]})]})]})}const lt=[{kind:"person",titleKey:"teamMemory.kind.people",hintKey:"teamMemory.kind.peopleHint"},{kind:"place",titleKey:"teamMemory.kind.places",hintKey:"teamMemory.kind.placesHint"},{kind:"decision",titleKey:"teamMemory.kind.decisions",hintKey:"teamMemory.kind.decisionsHint"},{kind:"term",titleKey:"teamMemory.kind.terms",hintKey:"teamMemory.kind.termsHint"}];function _n({section:n,label:r,onClose:l}){const d=a.useRef(null),[i,c]=a.useState(null),[I,g]=a.useState([]),[x,M]=a.useState({}),[h,w]=a.useState(null),[b,O]=a.useState(null),U=a.useRef(!1),A=a.useRef(0),[K,v]=a.useState(!1),[y,j]=a.useState({kind:"term",name:"",detail:""}),B=`section=${encodeURIComponent(n)}`,L=a.useCallback(async()=>{const m=++A.current;try{const z=await te(`/api/team-memory?${B}`);if(A.current!==m)return;c(z.entries),g(z.loadedIds),w(null)}catch(z){if(A.current!==m)return;w(z instanceof Error?z.message:String(z))}},[B]);a.useEffect(()=>(c(null),w(null),L(),()=>{A.current+=1}),[L]),a.useEffect(()=>{const m=document.activeElement instanceof HTMLElement?document.activeElement:null;d.current?.focus();const z=N=>{if(N.key==="Escape"&&(N.preventDefault(),l()),N.key==="Tab"){const $=d.current?.querySelectorAll("button:enabled, input:enabled, select:enabled");if(!$?.length)return;const T=$[0],P=$[$.length-1];N.shiftKey&&document.activeElement===T?(N.preventDefault(),P.focus()):!N.shiftKey&&document.activeElement===P&&(N.preventDefault(),T.focus())}};return window.addEventListener("keydown",z),()=>{window.removeEventListener("keydown",z),m?.focus()}},[l]);const Y=async(m,z)=>{if(U.current)return!1;U.current=!0;const N=++A.current;O(m??"new"),w(null);try{const $=await z();return A.current!==N?!1:(c($.entries),O(null),$.loadedIds?g($.loadedIds):L(),!0)}catch($){return A.current===N&&w($ instanceof Error?$.message:String($)),!1}finally{U.current=!1,A.current===N&&O(null)}},_=m=>Y(m.id,()=>te(`/api/team-memory/${m.id}?${B}`,{method:"PATCH",body:JSON.stringify({accept:!0,expectedRevision:m.revision})})),H=m=>Y(m.id,()=>te(`/api/team-memory/${m.id}?${B}&revision=${m.revision}`,{method:"DELETE"})),G=(m,z,N)=>{z.trim()===m.detail&&(N===void 0||N===m.name)||Y(m.id,()=>te(`/api/team-memory/${m.id}?${B}`,{method:"PATCH",body:JSON.stringify({detail:z,...N===void 0?{}:{name:N},expectedRevision:m.revision})})).then($=>M(T=>{const P={...T};return $?delete P[m.id]:P[m.id]={name:N??m.name,text:z},P}))},R=()=>{!y.name.trim()||!y.detail.trim()||Y(null,()=>te(`/api/team-memory?${B}`,{method:"POST",body:JSON.stringify(y)})).then(m=>{m&&(j({kind:y.kind,name:"",detail:""}),v(!1))})},q=(i??[]).filter(m=>m.status==="proposed");return et.createPortal(e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/55 p-4 sm:p-6",onMouseDown:m=>m.target===m.currentTarget&&l(),children:e.jsxs("div",{ref:d,role:"dialog","aria-modal":"true","aria-labelledby":"team-memory-title",tabIndex:-1,className:"animate-pop-in flex max-h-[min(720px,calc(100dvh-2rem))] w-full max-w-[720px] flex-col overflow-hidden rounded-2xl border border-hairline/50 bg-panel shadow-2xl shadow-black/50 outline-none",children:[e.jsxs("header",{className:"flex items-start justify-between gap-4 border-b border-hairline/40 px-6 pb-4 pt-6 sm:px-8 sm:pt-7",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(mt,{size:19,className:"text-accent"}),e.jsx("h2",{id:"team-memory-title",className:"text-[20px] font-semibold tracking-[-0.01em] text-ink",children:s("teamMemory.title",{name:r})})]}),e.jsx("p",{className:"mt-1.5 max-w-[560px] text-[13px] leading-relaxed text-ink-secondary",children:s("teamMemory.description")})]}),e.jsx("button",{onClick:l,"aria-label":s("teamMemory.close"),className:"flex size-9 shrink-0 items-center justify-center rounded-lg text-ink-secondary hover:bg-raised hover:text-ink",children:e.jsx(Be,{size:19})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 py-5 sm:px-8",children:[i===null&&!h&&e.jsx("div",{className:"flex min-h-[200px] items-center justify-center text-ink-secondary",children:e.jsx(Re,{size:20,className:"animate-spin","aria-label":s("teamMemory.loading")})}),i&&e.jsx("p",{className:"mb-3 text-[12px] text-ink-secondary",children:s("teamMemory.loadedSummary",{loaded:I.length,total:i.filter(m=>m.status==="accepted").length})}),h&&e.jsxs("div",{role:"alert",className:"mb-3 rounded-lg border border-danger/30 bg-danger/10 px-3 py-2 text-[12px] text-danger",children:[h," ",e.jsx("button",{onClick:()=>{L()},className:"underline",children:s("teamMemory.reload")})]}),Object.entries(x).map(([m,z])=>e.jsxs("p",{className:"mb-3 text-[12px] text-ink-secondary",children:[e.jsx("strong",{children:z.name})," · ",s("teamMemory.unsaved",{text:z.text})]},m)),q.length>0&&e.jsxs("section",{className:"mb-5 rounded-xl border border-accent/30 bg-accent/5 p-3",children:[e.jsx("h3",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-accent",children:s("teamMemory.waiting")}),e.jsx("ul",{className:"mt-2 space-y-2",children:q.map(m=>e.jsxs("li",{className:"flex items-start gap-3 text-[13px]",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"text-ink-secondary",children:[s(`teamMemory.kind.${m.kind}`),": "]}),e.jsx("span",{className:"font-medium text-ink",children:m.name}),m.aliases.length>0&&e.jsxs("span",{className:"text-ink-secondary",children:[" (",s("teamMemory.also")," ",m.aliases.join(", "),")"]}),e.jsxs("span",{className:"text-ink",children:[" — ",m.detail]}),e.jsxs("span",{className:"block text-[11px] text-ink-secondary",children:[s("teamMemory.source",{name:m.source.botName}),m.source.quote&&` · ${s("teamMemory.sourceQuote",{quote:m.source.quote})}`]})]}),e.jsxs("button",{onClick:()=>{_(m)},disabled:b!==null,className:"flex shrink-0 items-center gap-1 rounded-md bg-accent px-2.5 py-1 text-[12px] font-medium text-white disabled:opacity-50",children:[e.jsx(kt,{size:12})," ",s("teamMemory.remember")]}),e.jsx("button",{onClick:()=>{H(m)},disabled:b!==null,className:"shrink-0 rounded-md px-2 py-1 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:s("teamMemory.skip")})]},m.id))})]}),i!==null&&i.filter(m=>m.status==="accepted").length===0&&q.length===0&&e.jsx("div",{className:"rounded-xl bg-inset px-4 py-6 text-center text-[13px] text-ink-secondary",children:s("teamMemory.empty")}),lt.map(({kind:m,titleKey:z,hintKey:N})=>{const $=(i??[]).filter(T=>T.status==="accepted"&&T.kind===m);return $.length===0?null:e.jsxs("section",{className:"mb-5",children:[e.jsx("h3",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-ink-secondary",title:s(N),children:s(z)}),e.jsx("ul",{className:"mt-2 divide-y divide-hairline/20 rounded-xl bg-inset",children:$.map(T=>e.jsxs("li",{className:"flex items-start gap-3 px-3 py-2 text-[13px]",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"font-medium text-ink",children:T.name}),T.aliases.length>0&&e.jsxs("span",{className:"text-ink-secondary",children:[" (",s("teamMemory.also")," ",T.aliases.join(", "),")"]}),e.jsx("input",{defaultValue:T.detail,disabled:b!==null,onBlur:P=>G(T,P.target.value),onKeyDown:P=>{P.key==="Enter"&&P.target.blur()},"aria-label":s("teamMemory.entryDetailLabel",{name:T.name}),className:"mt-0.5 block w-full rounded bg-transparent px-1 py-0.5 text-[13px] text-ink outline-none hover:bg-card focus:bg-card"},T.revision),e.jsxs("span",{className:"block px-1 text-[11px] text-ink-secondary",children:[T.source.botName||s("teamMemory.you")," · ",new Date(T.updatedAt).toLocaleDateString(Ee())," · ",I.includes(T.id)?s("teamMemory.loaded"):s("teamMemory.searchable")]}),!!T.history?.length&&e.jsxs("details",{className:"mt-1 text-[11px] text-ink-secondary",children:[e.jsx("summary",{children:s("teamMemory.history")}),T.history.map((P,se)=>e.jsxs("div",{className:"mt-1",children:[new Date(P.at).toLocaleDateString(Ee()),": ",P.name," — ",P.detail," ",e.jsx("button",{disabled:b!==null,onClick:()=>G(T,P.detail,P.name),className:"underline",children:s("teamMemory.restore")})]},se))]})]}),e.jsx("button",{"aria-label":s(T.pinned?"teamMemory.unpin":"teamMemory.pin",{name:T.name}),"aria-pressed":T.pinned??!1,disabled:b!==null,className:"p-1 text-ink-secondary hover:text-accent",onClick:()=>{Y(T.id,()=>te(`/api/team-memory/${T.id}?${B}`,{method:"PATCH",body:JSON.stringify({pinned:!T.pinned,expectedRevision:T.revision})}))},children:e.jsx(Lt,{size:13})}),e.jsx("button",{onClick:()=>{H(T)},disabled:b!==null,"aria-label":s("teamMemory.remove",{name:T.name}),className:"shrink-0 rounded-md p-1 text-ink-secondary hover:text-danger disabled:opacity-50",children:e.jsx(pt,{size:13})})]},T.id))})]},m)}),K?e.jsxs("div",{className:"rounded-xl border border-hairline/40 bg-card p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(ht,{size:"sm",value:y.kind,onChange:m=>j({...y,kind:m.target.value}),"aria-label":s("teamMemory.kindLabel"),children:lt.map(({kind:m})=>e.jsx("option",{value:m,children:s(`teamMemory.kind.${m}`)},m))}),e.jsx("input",{value:y.name,onChange:m=>j({...y,name:m.target.value}),placeholder:s("teamMemory.namePlaceholder"),"aria-label":s("teamMemory.nameLabel"),className:"min-w-[140px] flex-1 rounded-lg border border-hairline/40 bg-inset px-2 py-1 text-[13px] text-ink outline-none focus:border-accent"})]}),e.jsx("input",{value:y.detail,onChange:m=>j({...y,detail:m.target.value}),onKeyDown:m=>{m.key==="Enter"&&R()},placeholder:s("teamMemory.detailPlaceholder"),"aria-label":s("teamMemory.detailLabel"),className:"mt-2 w-full rounded-lg border border-hairline/40 bg-inset px-2 py-1 text-[13px] text-ink outline-none focus:border-accent"}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("button",{onClick:R,disabled:b!==null||!y.name.trim()||!y.detail.trim(),className:"rounded-lg bg-accent px-3 py-1 text-[13px] font-medium text-white disabled:opacity-50",children:b==="new"?s("teamMemory.adding"):s("teamMemory.add")}),e.jsx("button",{onClick:()=>v(!1),className:"text-[13px] text-ink-secondary hover:text-ink",children:s("common.cancel")})]})]}):e.jsxs("button",{onClick:()=>v(!0),className:ne("flex items-center gap-1.5 text-[13px] text-ink-secondary hover:text-ink",i===null&&"hidden"),children:[e.jsx(Ke,{size:13})," ",s("teamMemory.addEntry")]})]})]})}),document.body)}const xe="rounded-lg px-3 py-2 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",Hn="w-full rounded-lg border border-hairline/60 bg-inset px-3 py-2 text-[12px] text-ink outline-none focus:border-accent";function Kn(n,r){if(r)return s("canvasComputers.updating");const l={idle:"idle",ready:"ready",running:"running",init:"starting",provisioning:"provisioning",provisioned:"starting",cloning:"starting",starting:"starting",sleeping:"sleeping"}[n];return l?s(`canvasComputers.state.${l}`):n}function Un({open:n,createRequest:r,drop:l,sections:d,onClose:i,onDropHandled:c,onChange:I}){const{dispatch:g}=Ne(),[x,M]=a.useState(null),[h,w]=a.useState(!1),[b,O]=a.useState(""),[U,A]=a.useState(""),[K,v]=a.useState(null),[y,j]=a.useState(!1),[B,L]=a.useState(""),Y=a.useRef($e()),_=a.useRef(null),H=a.useRef(null),G=a.useRef(null),R=a.useRef(!1),q=a.useRef(!0),m=a.useRef(null),z=a.useRef(I);z.current=I;const[N,$]=a.useState(null),[T,P]=a.useState(null),[se,S]=a.useState(null),F=a.useRef($e()),ee=a.useRef(null),ie=a.useRef(null),re=a.useRef(null),ue=a.useRef(null),[de,fe]=a.useState(null),me=a.useCallback(()=>{const o=re.current;re.current=null,ue.current?.removeAttribute("data-computer-dropping"),ue.current=null,o?.handle.hasPointerCapture(o.id)&&o.handle.releasePointerCapture(o.id),fe(null)},[]);a.useEffect(()=>(n||me(),()=>{ue.current?.removeAttribute("data-computer-dropping")}),[n,me]),a.useEffect(()=>{ee.current=se},[se]),a.useEffect(()=>()=>{const o=ee.current;o&&fetch(`/api/team-computers/${encodeURIComponent(o)}/control`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({action:"release",controlLeaseId:F.current}),keepalive:!0}).catch(()=>{})},[]);const he=a.useCallback((o,k)=>{if(!(R.current||o.section===k)){if(o.section!==null&&k!==null){O(s("canvasComputers.unassignBeforeMove",{computer:o.name,team:o.section||s("settings.section.general")}));return}O(""),$({computer:o,section:k})}},[]),ge=(o,k)=>{const J=ie.current?.parentElement?.querySelector("[data-team-canvas]"),Z=document.elementFromPoint(o,k)?.closest("[data-team-key]");return Z&&J?.contains(Z)&&d.some(le=>le.key===Z.dataset.teamKey)?Z:null},ve=o=>{const k=re.current;if(!k||o.pointerId!==k.id)return;if(o.buttons===0){me();return}if(!k.moved&&Math.hypot(o.clientX-k.x,o.clientY-k.y)<5)return;k.moved=!0,o.currentTarget.setPointerCapture(o.pointerId);const J=ge(o.clientX,o.clientY);ue.current!==J&&(ue.current?.removeAttribute("data-computer-dropping"),J?.setAttribute("data-computer-dropping","true"),ue.current=J);const Z=J?d.find(le=>le.key===J.dataset.teamKey):null;fe({name:k.computer.name,x:o.clientX,y:o.clientY,hint:Z?k.computer.section!==null&&k.computer.section!==Z.key?s("canvasComputers.unassignBeforeMoving"):s("canvasComputers.assignTo",{team:Z.name}):s("canvasComputers.dropOntoTeam")})},Se=o=>{const k=re.current;if(!k||k.id!==o.pointerId)return;const J=k.moved?ge(o.clientX,o.clientY)?.dataset.teamKey:void 0;me(),J!==void 0&&he(k.computer,J)},oe=a.useCallback(async(o=!1)=>{m.current?.abort();const k=new AbortController;m.current=k,w(!0);try{const J=await te("/api/team-computers",{signal:AbortSignal.any([k.signal,AbortSignal.timeout(3e4)]),background:o});if(k.signal.aborted||!q.current)return;M(J),A(""),z.current(J.computers)}catch(J){!k.signal.aborted&&q.current&&A(J instanceof Error?J.message:String(J))}finally{!k.signal.aborted&&q.current&&w(!1)}},[]);a.useEffect(()=>(q.current=!0,oe(),()=>{q.current=!1,m.current?.abort()}),[oe]),a.useEffect(()=>{if(!n)return;oe();const o=window.setInterval(()=>{!R.current&&document.visibilityState==="visible"&&oe(!0)},2e4);return()=>window.clearInterval(o)},[n,oe]),a.useEffect(()=>{r>0&&j(!0)},[r]),a.useEffect(()=>{if(!n)return;const o=document.activeElement instanceof HTMLElement?document.activeElement:null;return G.current?.focus(),()=>{o?.isConnected&&o.focus()}},[n]),a.useEffect(()=>{n&&y&&H.current?.focus()},[n,y]),a.useEffect(()=>{if(!l)return;const o=x?.computers.find(k=>k.id===l.id);o&&he(o,l.section),c()},[l,x,c,he]);const pe=async(o,k,J,Z)=>{if(!R.current){R.current=!0,v(o),O(""),m.current?.abort();try{const le=await k();q.current&&J?.(le)}catch(le){q.current&&(O(le instanceof Error?le.message:String(le)),Z?.())}finally{R.current=!1,q.current&&(v(null),await oe())}}},be=a.useCallback(()=>$(null),[]),ce=(o,k,J={})=>te(`/api/team-computers/${encodeURIComponent(o)}/${k}`,{method:"POST",body:JSON.stringify(J)}),f=()=>{i(),g({type:"toggleAppSettings",open:!0,section:"computer"})};return e.jsxs(e.Fragment,{children:[n&&e.jsxs("aside",{ref:ie,"aria-label":s("canvasComputers.title"),onKeyDown:o=>{o.key==="Escape"&&!N&&(o.stopPropagation(),re.current?me():i())},className:"flex w-[300px] max-w-[90vw] shrink-0 flex-col border-l border-hairline/50 bg-panel max-sm:absolute max-sm:inset-y-0 max-sm:right-0 max-sm:z-30 max-sm:shadow-xl",children:[e.jsxs("header",{className:"flex items-center gap-2 border-b border-hairline/40 px-4 py-3",children:[e.jsx(Oe,{size:16,className:"text-ink-secondary"}),e.jsx("h2",{className:"flex-1 text-[13px] font-semibold",children:s("canvasComputers.title")}),e.jsx("button",{"aria-label":s("canvasComputers.refresh"),className:xe,disabled:h||K!==null,onClick:()=>{O(""),oe()},children:e.jsx(sn,{size:14,className:h?"animate-spin":""})}),e.jsx("button",{ref:G,"aria-label":s("canvasComputers.close"),className:xe,onClick:i,children:e.jsx(Be,{size:15})})]}),e.jsxs("div",{className:"min-h-0 flex-1 space-y-3 overflow-y-auto p-4",children:[e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:s("canvasComputers.hint")}),(b||U||x?.problem)&&e.jsx("p",{role:"alert",className:"rounded-lg bg-danger/10 p-3 text-[12px] text-danger",children:b||U||x?.problem}),x&&!x.configured&&e.jsxs("div",{className:"rounded-xl border border-hairline/50 p-3 text-[12px]",children:[e.jsx("p",{className:"text-ink-secondary",children:s("canvasComputers.connectBoatHint")}),e.jsx("button",{className:`${xe} mt-2 border border-hairline/50`,onClick:f,children:s("canvasComputers.connectBoat")})]}),y?e.jsxs("form",{className:"space-y-3 rounded-xl border border-hairline/60 bg-card p-3",onSubmit:o=>{o.preventDefault();const k=_.current??B.trim();!k||!x?.configured||(_.current=k,pe("create",()=>te("/api/team-computers",{method:"POST",body:JSON.stringify({name:k,requestId:Y.current,acknowledgeCost:!0})}),()=>{L(""),j(!1),Y.current=$e(),_.current=null},()=>{_.current=null}))},children:[e.jsx("label",{className:"block text-[12px] font-medium",htmlFor:"canvas-computer-name",children:s("canvasComputers.newCloud")}),e.jsx("input",{ref:H,id:"canvas-computer-name",className:Hn,value:B,maxLength:60,placeholder:s("canvasComputers.namePlaceholder"),disabled:K!==null||_.current!==null,onChange:o=>L(o.target.value)}),e.jsx("p",{className:"text-[11px] leading-relaxed text-ink-secondary",children:s("canvasComputers.createHint")}),e.jsxs("div",{className:"flex justify-end gap-1",children:[e.jsx("button",{type:"button",className:xe,disabled:K!==null,onClick:()=>j(!1),children:s("common.cancel")}),e.jsxs("button",{type:"submit",className:"flex items-center gap-2 rounded-lg bg-accent px-3 py-2 text-[12px] font-medium text-white disabled:opacity-40",disabled:!x?.configured||!B.trim()||K!==null,children:[K==="create"&&e.jsx(Re,{size:13,className:"animate-spin"}),s("canvasComputers.create")]})]})]}):e.jsxs("button",{className:"flex w-full items-center justify-center gap-2 rounded-xl border border-dashed border-hairline/60 px-3 py-3 text-[12px] text-ink-secondary hover:bg-control hover:text-ink",disabled:K!==null,onClick:()=>j(!0),children:[e.jsx(Ke,{size:14})," ",s("canvasComputers.newCloud")]}),x?.computers.map(o=>{const k=["idle","ready","running"].includes(o.state),J=["init","provisioning","provisioned","cloning","starting"].includes(o.state),Z=se===o.id,le=o.held||Z;return e.jsxs("article",{"data-computer-id":o.id,className:"rounded-xl border border-hairline/60 bg-card p-3",children:[e.jsxs("div",{"data-computer-drag-id":o.id,role:"group",tabIndex:-1,"aria-label":s("canvasComputers.dragToTeam",{name:o.name}),onPointerDown:W=>{R.current||re.current||W.button!==0||!W.isPrimary||(W.currentTarget.focus({preventScroll:!0}),re.current={id:W.pointerId,x:W.clientX,y:W.clientY,moved:!1,computer:o,handle:W.currentTarget},W.currentTarget.setPointerCapture(W.pointerId))},onPointerMove:ve,onPointerUp:Se,onPointerCancel:me,onLostPointerCapture:()=>{re.current&&me()},className:"flex touch-none select-none cursor-grab items-center gap-2.5 rounded-lg py-1 outline-none active:cursor-grabbing",children:[e.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-lg bg-control text-ink-secondary",children:e.jsx(Je,{size:18})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-[13px] font-medium",children:o.name}),e.jsxs("span",{className:"block text-[11px] text-ink-secondary",children:[s("canvasComputers.cloudComputer")," · ",Kn(o.state,K===o.id)]})]})]}),o.problem&&e.jsx("p",{className:"mt-2 text-[11px] text-danger",children:o.problem}),e.jsx("label",{className:"sr-only",htmlFor:`computer-team-${o.id}`,children:s("canvasComputers.teamFor",{name:o.name})}),e.jsxs(ht,{id:`computer-team-${o.id}`,className:"mt-3 w-full",disabled:K!==null,value:o.section===null?"unassigned":`team:${o.section}`,onChange:W=>he(o,W.target.value==="unassigned"?null:W.target.value.slice(5)),children:[e.jsx("option",{value:"unassigned",children:s("canvasComputers.unassigned")}),d.filter(W=>o.section===null||W.key===o.section).map(W=>e.jsx("option",{value:`team:${W.key}`,children:W.name},W.key))]}),o.section!==null&&e.jsx("p",{className:"mt-1.5 text-[10px] text-ink-secondary",children:s("canvasComputers.unassignHint")}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-1",children:[!k&&!J&&e.jsx("button",{className:xe,title:s("canvasComputers.startTitle"),disabled:K!==null||le,onClick:()=>{pe(o.id,()=>ce(o.id,"provision",{acknowledgeCost:!0}))},children:s("canvasComputers.startRetry")}),k&&!le&&e.jsx("button",{className:xe,disabled:K!==null,onClick:()=>{pe(o.id,()=>ce(o.id,"sleep"))},children:s("canvasComputers.sleep")}),k&&e.jsxs("button",{className:`${xe} flex items-center gap-1.5`,title:s("canvasComputers.openTitle"),disabled:K!==null,onClick:()=>{pe(o.id,async()=>(await ce(o.id,"control",{action:"take",controlLeaseId:F.current}),S(o.id),ce(o.id,"join")),W=>{typeof W.joinUrl=="string"&&W.joinUrl.startsWith("https://")&&P({id:o.id,url:W.joinUrl})})},children:[s("canvasComputers.openDesktop")," ",e.jsx(Nt,{size:11})]}),Z&&e.jsx("button",{className:`${xe} text-accent`,disabled:K!==null,onClick:()=>{pe(o.id,()=>ce(o.id,"control",{action:"release",controlLeaseId:F.current}),()=>{S(null),P(null)})},children:s("canvasComputers.returnToBots")}),o.held&&!Z&&e.jsx("button",{className:xe,disabled:!0,title:s("canvasComputers.inUseTitle"),children:s("canvasComputers.inUse")})]}),T?.id===o.id&&e.jsxs("a",{href:T.url,target:"_blank",rel:"noopener noreferrer",className:"mt-2 block rounded-lg px-3 py-2 text-[12px] text-accent hover:bg-control",children:[s("canvasComputers.openSecure")," ",e.jsx(Pt,{size:14,"aria-hidden":"true",className:"inline align-[-2px]"})]})]},o.id)})]}),e.jsx("footer",{className:"border-t border-hairline/40 p-3",children:e.jsx("button",{className:`${xe} w-full text-left`,onClick:f,children:s("canvasComputers.moreSettings")})})]}),de&&et.createPortal(e.jsxs("div",{role:"status",className:"pointer-events-none fixed z-[70] rounded-xl border border-accent/40 bg-card px-4 py-3 text-[12px] text-ink shadow-xl",style:{left:de.x+14,top:de.y+14},children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Je,{size:15}),de.name]}),e.jsx("p",{className:"mt-1 text-[10px] text-ink-secondary",children:de.hint})]}),document.body),e.jsx(Ve,{open:N!==null,tone:"neutral",title:N?.section===null?s("canvasComputers.unassignTitle",{name:N?.computer.name??s("canvasComputers.computer")}):s("canvasComputers.assignTitle",{name:N?.computer.name??s("canvasComputers.computer"),team:N?.section||s("settings.section.general")}),body:N?.section===null?s("canvasComputers.unassignBody"):s("canvasComputers.assignBody"),confirmLabel:N?.section===null?s("canvasComputers.unassign"):s("canvasComputers.assign"),onCancel:be,onConfirm:()=>{const o=N;o&&($(null),P(null),pe(o.computer.id,()=>te(`/api/team-computers/${encodeURIComponent(o.computer.id)}`,{method:"PATCH",body:JSON.stringify({section:o.section,acknowledgeSharedAccess:!0})})))}})]})}function qn(n,r,l){const d=r.filter(h=>!h.hidden&&h.name.trim()),i=[...d.map(h=>({name:h.name,tag:{kind:"bot",name:h.name,botIds:[h.id]}})),...l.filter(h=>h.name.trim()).map(h=>({name:h.name,tag:{kind:"team",name:h.name,botIds:d.filter(w=>(w.section?.trim()??"")===h.key).map(w=>w.id)}})),{name:"everyone",tag:{kind:"everyone",name:"everyone",botIds:d.map(h=>h.id)}}].sort((h,w)=>w.name.length-h.name.length),c=[],I=[],g=[];let x=-1;for(;(x=n.indexOf("@",x+1))!==-1;){if(!$t(n,x))continue;const h=n.slice(x+1),w=i.find(({name:O})=>h.slice(0,O.length).toLowerCase()===O.toLowerCase()&&!_t(h.slice(O.length)));if(w){c.push(w.tag),g.push([x,x+1+w.name.length]),x+=w.name.length;continue}const b=/^[\p{L}\p{N}\p{M}_.-]+/u.exec(h)?.[0];b&&I.push(b)}const M=g.reduceRight((h,[w,b])=>h.slice(0,w)+h.slice(b),n).replace(/\s+/g," ").trim();return{botIds:[...new Set(c.flatMap(h=>h.botIds))],tags:c,unknown:I,words:M}}function ct(n,r,l){if(!n.tags.some(c=>c.kind==="everyone"))return{botIds:n.botIds};if(l)return{botIds:n.botIds,text:n.words};const d=Fn(r);if(!d)return{botIds:n.botIds};const i=n.tags.filter(c=>c.kind!=="everyone").flatMap(c=>c.botIds);return{botIds:[...new Set([d.id,...i])],chief:d}}function Fn(n){const r=n.filter(l=>l.chiefOfStaff&&!l.hidden);return r.find(l=>!l.section?.trim())??r[0]}function Xn(n,r=2){return n.length<=r+1?{names:[...n],more:0}:{names:n.slice(0,r),more:n.length-r}}function Yn({bots:n,teams:r,onTagged:l,onSent:d}){const{dispatch:i}=Ne(),c=Qe(),I=Ht(),g=a.useRef(null),x=a.useRef(null),[M,h]=a.useState(""),[w,b]=a.useState(0),[O,U]=a.useState(null),[A,K]=a.useState(0),[v,y]=a.useState(null),j=a.useMemo(()=>n.filter(S=>!S.hidden),[n]),B=a.useMemo(()=>qn(M,j,r),[M,j,r]),L=a.useMemo(()=>ct(B,j,!1),[B,j]),Y=L.botIds.join(",");a.useEffect(()=>{l(Y?Y.split(","):[])},[Y,l]),a.useEffect(()=>()=>l([]),[l]);const _=Kt(M,w),H=a.useMemo(()=>{if(!_||_.start===O)return[];const S=[...j.length>1?[{id:"__everyone__",name:"everyone",all:{count:j.length}}]:[],...r.filter(F=>F.count>0).map(F=>({id:`team:${F.key}`,name:F.name,team:{count:F.count}})),...j.map(F=>({id:F.id,name:F.name,bot:F}))];return Ut(S,_.query)},[_,O,j,r]),G=H.length>0,R=an(G);a.useEffect(()=>K(0),[_?.start,_?.query]),a.useEffect(()=>{G&&x.current?.querySelector(`[data-mention-index="${A}"]`)?.scrollIntoView({block:"nearest"})},[A,G]);const q=S=>{if(!_)return;const F=`${M.slice(0,_.start)}@${S.name} ${M.slice(w)}`,ee=_.start+S.name.length+2;h(F),b(ee),U(_.start),requestAnimationFrame(()=>{g.current?.focus(),g.current?.setSelectionRange(ee,ee)})},m=M.trim().length>0&&B.botIds.length>0,z=async()=>{if(!m)return;const S=M.trim(),F=B;h(""),b(0),U(null);const ee=L.chief?await te("/api/stop-line",{method:"POST",body:JSON.stringify({text:F.words})}).then(re=>re.stop===!0,()=>null):!1,ie=ee===null?{botIds:F.botIds}:ct(F,j,ee);for(const re of ie.botIds)i({type:"send",botId:re,text:ie.text||S,sendId:$e()});d(ie.botIds),y({botIds:ie.botIds,expanded:!1,...ie.chief?{chiefId:ie.chief.id}:{}})},N=v?.chiefId?j.find(S=>S.id===v.chiefId):void 0,$=(v?.botIds??[]).filter(S=>S!==N?.id).flatMap(S=>j.find(F=>F.id===S)??[]),T=Xn($.map(S=>S.name)),P=v?.expanded?$:$.slice(0,T.names.length),se=M.trim()&&!B.botIds.length?s("mapComposer.tagHint"):L.chief?s("mapComposer.willSendViaChief",{name:L.chief.name}):null;return e.jsx(e.Fragment,{children:e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-5 z-30 flex justify-center px-4",children:e.jsxs("div",{className:"pointer-events-auto w-full max-w-[620px]",children:[v&&(N||$.length>0)&&e.jsxs("p",{role:"status",className:"mb-2 flex flex-wrap items-center gap-x-1 gap-y-0.5 rounded-xl bg-panel/95 px-3 py-1.5 text-[12px] text-ink-secondary shadow-sm ring-1 ring-hairline/50",children:[N&&e.jsxs("span",{children:[s("mapComposer.sentViaChief",{name:N.name}),$.length>0?" ·":""]}),$.length>0&&e.jsx("span",{children:s("mapComposer.sentTo")}),P.map((S,F)=>e.jsxs("span",{children:[e.jsx("button",{className:"font-medium text-ink underline-offset-2 hover:underline",onClick:()=>tt(i,S,c),children:S.name}),F<P.length-1?",":""]},S.id)),!v.expanded&&T.more>0&&e.jsx("button",{className:"text-ink underline-offset-2 hover:underline",onClick:()=>y({...v,expanded:!0}),children:s("mapComposer.andMore",{count:T.more})}),e.jsx("button",{"aria-label":s("common.close"),className:"ml-auto rounded p-0.5 hover:bg-control",onClick:()=>y(null),children:e.jsx(Be,{size:12})})]}),e.jsxs("div",{className:"relative flex items-end gap-2 rounded-2xl bg-composer px-3 py-2 shadow-lg ring-1 ring-composer-ring",children:[e.jsx(qt,{listRef:x,motion:R,choices:H,highlight:A,everyoneCount:j.length,onPick:q,onHighlight:K}),e.jsx(Ft,{inputRef:g,peers:[...j,...r.map(S=>({name:S.name}))],everyone:!0,"aria-label":s("mapComposer.label"),placeholder:s("mapComposer.placeholder"),dir:"auto",rows:1,value:M,className:"block max-h-[9rem] min-h-6 w-full resize-none overflow-y-auto bg-transparent px-1 py-1 text-[15px] leading-6 placeholder:text-ink-secondary focus:outline-none",onChange:S=>{h(S.target.value),b(S.target.selectionStart??S.target.value.length),U(null)},onKeyUp:S=>b(S.target.selectionStart??0),onClick:S=>b(S.target.selectionStart??0),onKeyDown:S=>{if(!Xt(S.nativeEvent)){if(G){if(S.key==="ArrowDown"||S.key==="ArrowUp"){S.preventDefault(),K(F=>(F+(S.key==="ArrowDown"?1:-1)+H.length)%H.length);return}if(S.key==="Enter"||S.key==="Tab"){S.preventDefault(),q(H[A]);return}if(S.key==="Escape"){S.preventDefault(),S.stopPropagation(),U(_?.start??null);return}}Yt(S.nativeEvent,I)&&(S.preventDefault(),z())}}}),e.jsx("button",{onClick:()=>{z()},disabled:!m,"aria-label":s("mapComposer.send"),title:m?L.botIds.length===1?s("mapComposer.sendToOne"):s("mapComposer.sendTo",{count:L.botIds.length}):s("mapComposer.tagHint"),className:ne("mb-0.5 flex size-8 shrink-0 items-center justify-center rounded-full text-white transition-opacity",m?"bg-accent hover:brightness-110":"bg-ink-secondary/30"),children:e.jsx(Jt,{size:16})})]}),(se||B.botIds.length>0)&&e.jsx("p",{className:"mt-1.5 px-3 text-[11px] text-ink-secondary",children:se??(L.botIds.length===1?s("mapComposer.willSendOne"):s("mapComposer.willSend",{count:L.botIds.length}))})]})})})}function Jn({edge:n,bots:r}){const{state:l,dispatch:d}=Ne(),i=Qe(),c=r.find(x=>x.id===n.sourceBotId),I=r.find(x=>x.id===n.targetBotId);if(!c||!I)return null;const g=n.state!=="connected";return e.jsxs("button",{onClick:()=>{!n.groupId&&n.threadId?nn(d,{botId:I.id,threadId:n.threadId},l,i):n.groupId?d({type:"select",id:n.groupId}):tt(d,I,i)},className:"flex w-full items-center gap-3 rounded-xl border border-hairline/40 bg-card px-3 py-2.5 text-left transition hover:bg-raised/50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx("span",{className:"truncate text-[13px] font-medium text-ink",children:c.name}),e.jsx(ft,{size:13,className:ne("shrink-0",g?"text-accent":"text-ink-secondary")}),e.jsx("span",{className:"truncate text-[13px] font-medium text-ink",children:I.name})]}),n.reason&&e.jsx("span",{className:"max-w-[220px] truncate text-[12px] text-ink-secondary",children:n.reason}),e.jsx("span",{className:ne("rounded-full px-2 py-0.5 text-[11px] font-medium",n.state==="running"?"bg-success/15 text-success":n.state==="queued"?"bg-warning/15 text-warning":"bg-control text-ink-secondary"),children:n.state==="running"?s("canvas.edge.running"):n.state==="queued"?s("canvas.edge.queued"):n.lastAt?jt(n.lastAt):s("canvas.edge.connected")})]})}function Vn({section:n,label:r,onClose:l}){const d=a.useRef(null),i=a.useRef(null),c=a.useRef(l),I=a.useRef(!1),g=a.useRef(!1),[x,M]=a.useState(""),[h,w]=a.useState(""),[b,O]=a.useState(24e3),[U,A]=a.useState(null),[K,v]=a.useState(!0),[y,j]=a.useState(!1),[B,L]=a.useState(null),Y=x!==h,_=a.useMemo(()=>new TextEncoder().encode(x).byteLength,[x]);c.current=l,I.current=y,g.current=Y;const H=a.useCallback(()=>{I.current||g.current&&!window.confirm(s("team.instructionsDiscard"))||c.current()},[]);a.useEffect(()=>{const R=document.activeElement instanceof HTMLElement?document.activeElement:null;d.current?.focus();const q=m=>{if(m.key==="Escape"&&!I.current){m.preventDefault(),H();return}if(m.key!=="Tab")return;const z=d.current;if(!z)return;const N=[...z.querySelectorAll('button:not([disabled]), textarea:not([disabled]), input:not([disabled]), [href], [tabindex]:not([tabindex="-1"])')];if(N.length===0){m.preventDefault(),z.focus();return}const $=N[0],T=N[N.length-1];m.shiftKey&&document.activeElement===$?(m.preventDefault(),T.focus()):!m.shiftKey&&document.activeElement===T&&(m.preventDefault(),$.focus())};return window.addEventListener("keydown",q),()=>{window.removeEventListener("keydown",q),R?.focus()}},[H]),a.useEffect(()=>{let R=!1;return v(!0),L(null),te(`/api/section-context?section=${encodeURIComponent(n)}`).then(q=>{R||(M(q.text),w(q.text),A(q.updatedAt),O(q.maxBytes),window.setTimeout(()=>i.current?.focus(),0))}).catch(q=>{R||L(q instanceof Error?q.message:String(q))}).finally(()=>{R||v(!1)}),()=>{R=!0}},[n]);const G=async()=>{if(!(_>b)){j(!0),L(null);try{const R=await te(`/api/section-context?section=${encodeURIComponent(n)}`,{method:"PUT",body:JSON.stringify({text:x})});w(R.text),M(R.text),A(R.updatedAt),O(R.maxBytes)}catch(R){L(R instanceof Error?R.message:String(R))}finally{j(!1)}}};return et.createPortal(e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/55 p-4 sm:p-6",onMouseDown:R=>R.target===R.currentTarget&&H(),children:e.jsxs("div",{ref:d,role:"dialog","aria-modal":"true","aria-labelledby":"section-context-title",tabIndex:-1,className:"animate-pop-in flex max-h-[min(680px,calc(100dvh-2rem))] w-full max-w-[680px] flex-col overflow-hidden rounded-2xl border border-hairline/50 bg-panel shadow-2xl shadow-black/50 outline-none",children:[e.jsxs("header",{className:"flex items-start justify-between gap-4 border-b border-hairline/40 px-6 pb-4 pt-6 sm:px-8 sm:pt-7",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ut,{size:19,className:"text-accent"}),e.jsx("h2",{id:"section-context-title",className:"text-[20px] font-semibold tracking-[-0.01em] text-ink",children:s("team.instructionsTitle",{name:r})})]}),e.jsx("p",{className:"mt-1.5 max-w-[520px] text-[13px] leading-relaxed text-ink-secondary",children:s("team.instructionsHint")})]}),e.jsx("button",{onClick:H,disabled:y,"aria-label":s("team.instructionsClose"),className:"flex size-9 shrink-0 items-center justify-center rounded-lg text-ink-secondary hover:bg-raised hover:text-ink disabled:opacity-40",children:e.jsx(Be,{size:19})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 py-5 sm:px-8",children:[K?e.jsx("div",{className:"flex min-h-[260px] items-center justify-center text-ink-secondary",children:e.jsx(Re,{size:20,className:"animate-spin","aria-label":s("team.instructionsLoading")})}):e.jsxs(e.Fragment,{children:[e.jsx("textarea",{ref:i,value:x,onChange:R=>M(R.target.value),placeholder:s("team.instructionsPlaceholder"),"aria-label":s("team.instructionsTitle",{name:r}),className:"min-h-[280px] w-full resize-y rounded-xl border border-hairline/60 bg-inset px-4 py-3 font-mono text-[13px] leading-relaxed text-ink outline-none placeholder:text-ink-tertiary focus:border-accent/50"}),e.jsxs("div",{className:"mt-2 flex items-start justify-between gap-4 text-[12px] text-ink-secondary",children:[e.jsxs("span",{children:[s("team.instructionsFactHint")," ",U?` ${s("team.instructionsLastSaved",{time:new Date(U).toLocaleString(Ee())})}`:""]}),e.jsx("span",{className:ne("shrink-0 tabular-nums",_>b&&"text-danger"),children:s("team.instructionsBytes",{bytes:_.toLocaleString(Ee()),limit:b.toLocaleString(Ee())})})]})]}),B&&e.jsx("div",{className:"mt-3 rounded-lg border border-danger/30 bg-danger/10 px-3 py-2 text-[12px] text-danger",children:B})]}),e.jsxs("footer",{className:"flex items-center justify-end gap-2 border-t border-hairline/40 px-6 py-4 sm:px-8",children:[e.jsx("button",{onClick:H,disabled:y,className:"rounded-lg px-3.5 py-2 text-[13px] text-ink-secondary hover:bg-raised hover:text-ink disabled:opacity-40",children:s("common.cancel")}),e.jsxs("button",{onClick:()=>{G()},disabled:K||y||!Y||_>b,className:"flex items-center gap-2 rounded-lg bg-accent px-4 py-2 text-[13px] font-medium text-white hover:brightness-110 disabled:opacity-40",children:[y?e.jsx(Re,{size:14,className:"animate-spin"}):e.jsx(un,{size:14}),s("team.instructionsSave")]})]})]})}),document.body)}const Gn=1400;function ss(){const{state:n,dispatch:r}=Ne(),{dragProps:l}=St(),d=window.ogb?.remoteClient?.active===!0,i=xt(),c=Vt(),I=Gt()==="people"&&i!==null,[g,x]=a.useState(mn),[M,h]=a.useState(null),[w,b]=a.useState(null),[O,U]=a.useState(null),[A,K]=a.useState(null),[v,y]=a.useState(null),[j,B]=a.useState(null),[L,Y]=a.useState(!1),[_,H]=a.useState(0),[G,R]=a.useState([]),[q,m]=a.useState(null),z=a.useCallback(()=>m(null),[]),[N,$]=a.useState(null),T=a.useRef(N);T.current=N,a.useEffect(()=>()=>T.current?.resolve(!1),[]);const P=a.useMemo(()=>n.bots.filter(f=>!f.hidden),[n.bots]),se=a.useMemo(()=>{const f=[...new Set([...n.sections??[],...n.groups.flatMap(k=>k.section?[k.section]:[])])],o=k=>k===""?-1:f.includes(k)?f.indexOf(k):f.length;return pn(P,f).sort((k,J)=>o(k.key)-o(J.key))},[P,n.sections,n.groups]),S=a.useMemo(()=>fn(P,g),[P,g]),F=P.some(f=>f.computer==="cloud"&&f.cloudBackend!=="vps")||G.some(f=>f.section!==null),{show:ee,loaded:ie,choose:re}=An(F),ue=En(!d&&ie&&ee),[de,fe]=a.useState([]),[me,he]=a.useState(null),ge=a.useRef(void 0),ve=a.useCallback(f=>{window.clearTimeout(ge.current),he(o=>({botIds:f,key:(o?.key??0)+1})),ge.current=window.setTimeout(()=>he(null),Gn)},[]);a.useEffect(()=>()=>window.clearTimeout(ge.current),[]);const Se=a.useMemo(()=>se.map(f=>({key:f.key,name:f.name,count:f.chiefs.length+f.members.length})),[se]),oe=a.useCallback(async(f=!1)=>{try{x(await te("/api/team-map",f?{background:f}:void 0)),b(null)}catch(o){b(o instanceof Error?o.message:String(o))}},[]);a.useEffect(()=>{oe();const f=window.setInterval(()=>{document.visibilityState==="visible"&&oe(!0)},3e3);return()=>window.clearInterval(f)},[oe]);const pe=async(f,o)=>{h(null);try{const k=await te("/api/sidebar-sections",{method:"POST",body:JSON.stringify({name:o,botIds:[f.id]})});r({type:"sections",sections:k.sections});for(const J of k.bots)r({type:"botPatched",bot:J})}catch(k){throw h(k instanceof Error?k.message:String(k)),k}},be=(f,o)=>new Promise(k=>{T.current?.resolve(!1),$({bot:f,destination:o,resolve:k})}),ce=a.useCallback(()=>{T.current?.resolve(!1),$(null)},[]);return e.jsxs("main",{className:"flex min-w-0 flex-1 flex-col overflow-hidden bg-app text-ink",children:[e.jsxs("header",{...l,className:"flex shrink-0 flex-wrap items-center justify-between gap-3 border-b border-hairline/40 px-6 py-4 max-md:pl-12",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(Wt,{size:18,className:"text-ink-secondary"}),e.jsx("h1",{className:"text-[17px] font-semibold",children:s("canvas.title")}),e.jsx("span",{className:"ml-1 text-[11px] text-ink-secondary",children:hn(P.length)})]}),e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:s("canvas.description")})]}),i&&e.jsx(Qt,{}),!d&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>re(!ee),"aria-pressed":ee,title:s("canvas.showComputersHint"),className:ne("flex items-center gap-2 rounded-lg border px-3 py-2 text-[12px] font-medium transition-colors",ee?"border-accent/40 bg-accent/10 text-ink":"border-hairline/60 bg-panel text-ink-secondary hover:bg-control hover:text-ink"),children:[e.jsx("span",{"aria-hidden":!0,className:ne("relative h-4 w-7 shrink-0 rounded-full transition-colors",ee?"bg-accent":"bg-control"),children:e.jsx("span",{className:ne("absolute top-0.5 size-3 rounded-full bg-white shadow-sm transition-[left]",ee?"left-3.5":"left-0.5")})}),s("canvas.showComputers")]}),e.jsx("button",{onClick:()=>Y(f=>!f),"aria-label":s("canvas.computers"),"aria-expanded":L,className:"rounded-lg p-2 text-ink-secondary hover:bg-control hover:text-ink",children:e.jsx(Oe,{size:17})}),c!==!1&&e.jsxs("details",{className:"relative",onBlur:f=>{f.currentTarget.contains(f.relatedTarget)||f.currentTarget.removeAttribute("open")},onKeyDown:f=>{f.key==="Escape"&&(f.currentTarget.removeAttribute("open"),f.currentTarget.querySelector("summary")?.focus())},children:[e.jsxs("summary",{"aria-label":s("canvas.addToMap"),className:"flex cursor-pointer list-none items-center gap-1.5 rounded-lg border border-hairline/60 bg-panel px-3 py-2 text-[12px] font-medium hover:bg-control [&::-webkit-details-marker]:hidden",children:[e.jsx(Ke,{size:14})," ",s("common.add")]}),e.jsxs("div",{className:"absolute right-0 top-full z-40 mt-2 w-52 rounded-xl border border-hairline/60 bg-panel p-1.5 shadow-xl",onClick:f=>{const o=f.currentTarget.closest("details");o?.querySelector("summary")?.focus(),o?.removeAttribute("open")},children:[e.jsxs("button",{className:"flex w-full items-center gap-2 rounded-lg px-3 py-2.5 text-left text-[12px] hover:bg-control",onClick:()=>y({}),children:[e.jsx(dt,{size:14}),s("team.create")]}),e.jsxs("button",{className:"flex w-full items-center gap-2 rounded-lg px-3 py-2.5 text-left text-[12px] hover:bg-control",onClick:()=>{Y(!0),H(f=>f+1)},children:[e.jsx(Je,{size:14}),s("canvas.cloudComputer")]}),Zt("vm",n.config)&&e.jsxs("button",{className:"flex w-full items-center gap-2 rounded-lg px-3 py-2.5 text-left text-[12px] hover:bg-control",onClick:()=>r({type:"toggleAppSettings",section:"computer",open:!0}),children:[e.jsx(Oe,{size:14}),s("canvas.localVm")]})]})]})]})]}),(M||w)&&e.jsxs("div",{role:"alert",className:"flex shrink-0 items-center justify-between gap-3 border-b border-danger/20 bg-danger/10 px-6 py-2 text-[12px] text-danger",children:[M||w,e.jsx("button",{"aria-label":s("common.close"),className:"rounded p-1 hover:bg-danger/10",onClick:()=>{h(null),b(null)},children:e.jsx(Be,{size:14})})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-1",children:[e.jsxs("div",{className:"relative flex min-h-0 min-w-0 flex-1",children:[I?e.jsx(en,{bots:P}):e.jsx($n,{sections:se,canManage:!d&&c!==!1,onMove:be,taggedBotIds:de,sent:me,bottomInset:P.length?96:0,connectedBotIds:n.settingsOpen?S.flatMap(f=>f.sourceBotId===n.selectedId?[f.targetBotId]:f.targetBotId===n.selectedId?[f.sourceBotId]:[]):[],onComputer:f=>Ye(r,"access",{botId:f.id}),computers:ee&&ie&&!d?ue.computers:void 0,computerFrames:ue.frames,onOpenComputer:f=>f.kind==="team"?Y(!0):r({type:"toggleComputer",open:!0,botId:f.id}),teamComputers:Object.fromEntries(G.filter(f=>f.section!==null).map(f=>[f.section,{name:f.name,state:f.state}])),onTeamComputer:()=>Y(!0),onComputerDrop:(f,o)=>{d||(Y(!0),m({id:f,section:o}))},onInstructions:(f,o)=>U({section:f,label:o}),onMemory:(f,o)=>K({section:f,label:o}),onEditTeam:(f,o)=>y({section:f,rename:o}),onDeleteTeam:B,isEmpty:f=>![...n.bots,...n.groups].some(o=>o.section?.trim()===f)}),P.length>0&&e.jsx(Yn,{bots:P,teams:Se,onTagged:fe,onSent:ve})]}),!d&&e.jsx(Un,{open:L,createRequest:_,drop:q,sections:se,onClose:()=>Y(!1),onDropHandled:z,onChange:R})]}),S.length>0&&e.jsxs("details",{className:"shrink-0 border-t border-hairline/40 bg-panel px-6 py-3",children:[e.jsxs("summary",{className:"cursor-pointer text-[12px] text-ink-secondary",children:[s("canvas.whoHandsOn")," · ",S.length]}),e.jsx("div",{className:"mt-3 max-h-48 space-y-2 overflow-y-auto",children:S.slice(0,12).map(f=>e.jsx(Jn,{edge:f,bots:P},`${f.sourceBotId}:${f.targetBotId}`))})]}),O&&e.jsx(Vn,{section:O.section,label:O.label,onClose:()=>U(null)}),v&&e.jsx(tn,{...v,onClose:()=>y(null)}),A&&e.jsx(_n,{...A,onClose:()=>K(null)},A.section),e.jsx(Ve,{open:N!==null,tone:"neutral",title:s("canvas.moveConfirmTitle",{name:N?.bot.name??s("canvas.bot"),team:N?.destination||s("settings.section.general")}),body:s("canvas.moveConfirmBody"),confirmLabel:s("canvas.moveConfirm"),onCancel:ce,onConfirm:()=>{const f=T.current;f&&($(null),pe(f.bot,f.destination).then(()=>f.resolve(!0),()=>f.resolve(!1)))}}),e.jsx(Ve,{open:j!==null,title:s("team.deleteTitle",{name:j??""}),body:s("team.deleteKeepBotsDescription"),confirmLabel:s("team.delete"),onCancel:()=>B(null),onConfirm:()=>{const f=j;B(null),f&&te(`/api/sidebar-sections?section=${encodeURIComponent(f)}`,{method:"DELETE"}).then(({sections:o})=>r({type:"sections",sections:o})).catch(o=>h(o instanceof Error?o.message:String(o)))}})]})}export{Jn as EdgeRow,Vn as SectionContextDialog,ss as TeamMapPage};
|
|
1
|
+
import{c as We,t as s,r as a,j as e,a as ne,z as Qe,X as Be,f as kt,i as Ee,a8 as jt}from"./styles-ElM5u1od.js";import{L as Re,X as wt,B as Ze,E as Ct,P as Ke,r as et,z as Nt,u as St}from"./PlacesRail-BYBRFGDz.js";import{n as te,l as It,a0 as Mt,u as Ne,aQ as dt,by as ut,di as mt,cM as Tt,T as pt,dj as ft,dk as Et,dl as At,dm as Rt,dn as Ot,ck as xt,bw as Bt,ai as Ye,b5 as tt,dp as zt,dq as Dt,dr as Lt,D as ht,_ as $e,a3 as Je,ds as Pt,C as Ve,dt as $t,du as _t,e as Ht,dv as Kt,dw as Ut,dx as qt,dy as Ft,d2 as Xt,dz as Yt,dA as Jt,bP as Vt,dB as Gt,cN as Wt,dC as Qt,a4 as Zt,dD as en,dE as tn,dF as nn}from"./App-5fWd2qWI.js";import{M as Oe}from"./monitor-IwDx0ohO.js";import{R as sn,a as an}from"./MenuMotion-DnbwlBMa.js";import"./index-BJo4IICg.js";const rn=[["path",{d:"M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719",key:"1sd12s"}]],on=We("message-circle",rn);const ln=[["path",{d:"M17 17H4a2 2 0 0 1-2-2V5c0-1.5 1-2 1-2",key:"k0q8oc"}],["path",{d:"M22 15V5a2 2 0 0 0-2-2H9",key:"cp1ac0"}],["path",{d:"M8 21h8",key:"1ev6f3"}],["path",{d:"M12 17v4",key:"1riwvh"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],cn=We("monitor-off",ln);const dn=[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]],un=We("save",dn),mn={collaborations:[],queued:[],running:[]};function pn(n,r=[]){const l=new Map;for(const d of n){if(d.hidden)continue;const i=d.section?.trim()||"";l.set(i,[...l.get(i)??[],d])}for(const d of r){const i=d.trim();i&&!l.has(i)&&l.set(i,[])}return[...l].map(([d,i])=>({key:d,name:d||s("teamSettings.general"),chiefs:i.filter(c=>c.chiefOfStaff),members:i.filter(c=>!c.chiefOfStaff)}))}function fn(n,r){const l=new Set(n.filter(c=>!c.hidden).map(c=>c.id)),d=new Map,i=(c,I)=>[c,I].sort().join(":");for(const c of r.collaborations){const[I,g]=c.botIds;!l.has(I)||!l.has(g)||d.set(i(I,g),{sourceBotId:I,targetBotId:g,state:"connected",groupId:c.groupId,lastAt:c.lastAt})}for(const c of r.queued)!l.has(c.sourceBotId)||!l.has(c.targetBotId)||d.set(i(c.sourceBotId,c.targetBotId),{sourceBotId:c.sourceBotId,targetBotId:c.targetBotId,state:"queued",reason:c.reason,groupId:c.groupId,threadId:c.threadId});for(const c of r.running)!l.has(c.sourceBotId)||!l.has(c.targetBotId)||d.set(i(c.sourceBotId,c.targetBotId),{sourceBotId:c.sourceBotId,targetBotId:c.targetBotId,state:"running",groupId:c.groupId,threadId:c.threadId});return[...d.values()].sort((c,I)=>{const g={running:0,queued:1,connected:2};return g[c.state]-g[I.state]||(I.lastAt??0)-(c.lastAt??0)})}function xn(n){return n.activity==="waiting-on-you"?{label:s("canvas.status.waiting"),tone:"warning"}:n.activity==="dead"||n.activity==="no-signal"?{label:s("canvas.status.noSignal"),tone:"danger"}:n.busy||n.activity==="working"?{label:s("canvas.status.working"),tone:"success"}:{label:s("canvas.status.ready"),tone:"idle"}}function hn(n){return n===1?s("canvas.botCountOne"):s("canvas.botCount",{count:n})}const _e=236,Me=126,He=16,we=20,Te=64,qe="application/x-omb-computer";function ke(n,r=[]){const l=new Map(r.map((d,i)=>[d,i]));return[...n].sort((d,i)=>(l.get(d.id)??1/0)-(l.get(i.id)??1/0))}function gn(n,r,l){const d=n.map(c=>c.id);if(!d.includes(r))return d;const i=d.filter(c=>c!==r);return i.splice(Math.max(0,Math.min(i.length,l)),0,r),i}function bn(n){try{const r=JSON.parse(n??"null");return r===null||typeof r!="object"||Array.isArray(r)?{}:Object.fromEntries(Object.entries(r).flatMap(([l,d])=>Array.isArray(d)?[[l,[...new Set(d.filter(i=>typeof i=="string"&&i.length>0))]]]:[]))}catch{return{}}}function gt(n){const r=n.chiefs.length>0&&n.members.length>0,l=r?Math.max(n.chiefs.length,n.members.length):Math.max(1,n.chiefs.length+n.members.length);return{width:_e*(r?2:1)+we*2+(r?40:0),height:Te+we+l*(Me+He)-He}}function yn(n,r,l={}){const d=l.sizes??n.map(gt),i=Math.max(1,Math.floor(l.columns??2)),c=[40];for(let g=1;g<i;g++){const x=Math.max(0,...d.filter((M,h)=>h%i===g-1).map(M=>M.width));c.push(c[g-1]+x+56)}let I=40;return n.map((g,x)=>{x>0&&x%i===0&&(I+=Math.max(...d.slice(x-i,x).map(h=>h.height))+56);const M=Object.hasOwn(r,g.key)?r[g.key]:void 0;return{key:g.key,x:M?.x??c[x%i],y:M?.y??I,...d[x]}})}function vn(n,r,l){if(!n.length)return{x:0,y:0,scale:1};const d=Math.min(...n.map(x=>x.x)),i=Math.min(...n.map(x=>x.y)),c=Math.max(...n.map(x=>x.x+x.width))-d,I=Math.max(...n.map(x=>x.y+x.height))-i,g=Math.max(.3,Math.min(1,(r-80)/c,(l-80)/I));return{x:(r-c*g)/2-d*g,y:(l-I*g)/2-i*g,scale:g}}function at(n,r,l){const d=r/n.scale;return{x:l.x-(l.x-n.x)*d,y:l.y-(l.y-n.y)*d,scale:r}}function kn(n){try{const r=JSON.parse(n??"null");return r===null||typeof r!="object"||Array.isArray(r)?{}:Object.fromEntries(Object.entries(r).flatMap(([l,d])=>{if(d===null||typeof d!="object"||Array.isArray(d))return[];const{x:i,y:c}=d;return typeof i=="number"&&Number.isFinite(i)&&Math.abs(i)<1e5&&typeof c=="number"&&Number.isFinite(c)&&Math.abs(c)<1e5?[[l,{x:i,y:c}]]:[]}))}catch{return{}}}const Ge=272,je=208,Fe=44,Xe=28;function jn(n,r){const l=[...n.chiefs,...n.members],d=l.filter(v=>r.own.has(v.id));if(!d.length&&!r.team)return null;const i=n.chiefs.length>0&&n.members.length>0,c=d.length?je:Me,I=v=>Te+v*(c+He),g=v=>I(v)+c/2,x=we+(i?Xe:0)+_e,M=x+Fe,h=l.map((v,y)=>({botId:v.id,x:we+(i&&y>=n.chiefs.length?Xe:0),y:I(y)+(c-Me)/2})),w=[],b=[];l.forEach((v,y)=>{const j=r.own.get(v.id);j&&(w.push({id:j,x:M,y:I(y)+(c-je)/2}),b.push({botId:v.id,computerId:j,points:[{x:h[y].x+_e,y:g(y)},{x:M,y:g(y)}]}))});const O=I(l.length)-He;let U=Math.max(O,Te+Me),A=d.length?M+Ge:x;if(r.team){const v=l.map((H,G)=>({bot:H,index:G})).filter(({bot:H})=>r.team.botIds.includes(H.id)),y=(v.length?v:l.map((H,G)=>({bot:H,index:G}))).map(({index:H})=>g(H)),j=y.length?(Math.min(...y)+Math.max(...y))/2:Te+je/2,B=A+Fe*(d.length?1.5:2),L=Math.max(Te,j-je/2),Y=B-Fe/2,_=L+je/2;w.push({id:r.team.id,x:B,y:L});for(const{bot:H,index:G}of v){const R={x:h[G].x+_e,y:g(G)};b.push({botId:H.id,computerId:r.team.id,points:[R,{x:Y,y:R.y},{x:Y,y:_},{x:B,y:_}]})}A=B+Ge,U=Math.max(U,L+je)}const K=[];if(i){const v=we+Xe/2,y=n.chiefs.length;K.push([{x:v,y:h[y-1].y+Me},{x:v,y:g(l.length-1)}]);for(let j=y;j<l.length;j++)K.push([{x:v,y:g(j)},{x:h[j].x,y:g(j)}])}return{width:A+we,height:U+we,cards:h,monitors:w,links:b,tree:K}}function wn(n,r,l=56){if(n.length<2||r.width<=0||r.height<=0)return 2;let d={columns:2,scale:0};for(let i=1;i<=Math.min(n.length,6);i++){const c=Array.from({length:i},(w,b)=>Math.max(0,...n.filter((O,U)=>U%i===b).map(O=>O.width))),I=Math.ceil(n.length/i),g=Array.from({length:I},(w,b)=>Math.max(0,...n.slice(b*i,b*i+i).map(O=>O.height))),x=c.reduce((w,b)=>w+b,0)+l*(i-1),M=g.reduce((w,b)=>w+b,0)+l*(I-1),h=Math.min((r.width-80)/x,(r.height-80)/M);h>d.scale+.01&&(d={columns:i,scale:h})}return d.columns}function rt(n){return n.map((r,l)=>`${l?"L":"M"}${r.x} ${r.y}`).join(" ")}const Cn=2e3;function Nn(n,r){return n.find(l=>l.kind==="bot"&&l.id===r)??n.find(l=>l.kind==="team"&&l.botIds.includes(r))}function Sn(n,r,l){const d=new Set(r),i=l.find(c=>c.kind==="team"&&c.section===n);return{own:new Map(l.filter(c=>c.kind==="bot"&&d.has(c.id)).map(c=>[c.id,c.id])),...i?{team:{id:i.id,botIds:i.botIds.filter(c=>d.has(c))}}:{}}}function In(n){return Object.entries(n).map(([r,l])=>`${r}:${l.version}`).join(",")}function Mn(n,r,l){return l-Math.max(0,r-n)}function Tn(n,r){const l=atob(n),d=new Uint8Array(l.length);for(let i=0;i<l.length;i++)d[i]=l.charCodeAt(i);return new Blob([d],{type:r})}function En(n){const[r,l]=a.useState(null),[d,i]=a.useState({}),[c,I]=a.useState(null),g=a.useRef(d);g.current=d;const x=a.useRef([]);x.current=r?.computers??[];const M=a.useRef(new Set),h=a.useRef(!0),w=a.useCallback(async(b,O,U,A,K)=>{if((g.current[b]?.at??-1/0)>=A)return;let v;try{v=URL.createObjectURL(Tn(O,U))}catch{return}try{const j=new Image;j.src=v,await j.decode()}catch{URL.revokeObjectURL(v);return}if(!h.current||(g.current[b]?.at??-1/0)>=A){URL.revokeObjectURL(v);return}const y=g.current[b]?.url;g.current={...g.current,[b]:{url:v,at:A,version:K}},i(g.current),y&&(M.current.add(y),window.setTimeout(()=>{URL.revokeObjectURL(y),M.current.delete(y)},2e3))},[]);return a.useEffect(()=>(h.current=!0,()=>{h.current=!1;for(const b of Object.values(g.current))URL.revokeObjectURL(b.url);for(const b of M.current)URL.revokeObjectURL(b)}),[]),a.useEffect(()=>{if(!n)return;let b=!1,O=!1;const U=async()=>{if(!(b||O||document.visibilityState!=="visible")){O=!0;try{const v=In(g.current),y=await te(`/api/computers/frames${v?`?have=${encodeURIComponent(v)}`:""}`,{signal:AbortSignal.timeout(3e4)});if(b)return;const j=Date.now();l(y),I(null);for(const B of y.computers){const L=B.frame;L?.data&&w(B.id,L.data,L.mime,Mn(L.at,y.now,j),L.version)}}catch(v){b||I(v instanceof Error?v.message:String(v))}finally{O=!1}}};U();const A=window.setInterval(U,Cn),K=It({screens:!0,onFrame:v=>{if(v.kind!=="screen"||v.surface!=="computer"||!v.png)return;const y=Nn(x.current,v.botId);y&&w(y.id,v.png,v.mime??"image/png",Date.now(),"live")}});return()=>{b=!0,window.clearInterval(A),K()}},[n,w]),{computers:r?.computers??[],configured:r?.configured??null,frames:d,error:c}}function An(n){const[r,l]=a.useState(null),[d,i]=a.useState(null),[c,I]=a.useState(!1);a.useEffect(()=>{let x=!0;return te("/.well-known/openmausbot/environment",{signal:AbortSignal.timeout(5e3)}).then(M=>{if(!x||typeof M.environmentId!="string")return;const h=`omb-team-canvas:${M.environmentId}:computers`;l(h);try{const w=localStorage.getItem(h);(w==="on"||w==="off")&&i(w==="on")}catch{}}).catch(()=>{}).finally(()=>{x&&I(!0)}),()=>{x=!1}},[]);const g=a.useCallback(x=>{if(i(x),!!r)try{localStorage.setItem(r,x?"on":"off")}catch{}},[r]);return{show:d??n,loaded:c,choose:g}}const ot=28;function Rn(n){if(n&&typeof n=="object"&&!Array.isArray(n))return n;if(typeof n!="string")return{};try{const r=JSON.parse(n);return r&&typeof r=="object"&&!Array.isArray(r)?r:{}}catch{return{}}}function On(n){const r=/(?:^|__)computer__(\w+)$/.exec(n.name)?.[1]??null;if(!r)return null;const l=Rn(n.input);if(r==="open_url")try{return s("mapComputer.step.open",{site:new URL(String(l.url)).hostname.replace(/^www\./,"")})}catch{return s("mapComputer.step.openPage")}if(r==="type_text"&&typeof l.text=="string"&&l.text.trim()){const d=l.text.replace(/\s+/g," ").trim();return s("mapComputer.step.type",{text:d.length>ot?`${d.slice(0,ot)}…`:d})}if(r==="key_press"){const d=[l.keys,l.key,l.combo].find(c=>typeof c=="string"||Array.isArray(c)),i=Array.isArray(d)?d.join("+"):typeof d=="string"?d:"";return i?s("mapComputer.step.key",{keys:i.slice(0,24)}):s("mapComputer.step.keyAny")}return r==="click"||r==="double_click"||r==="right_click"?s("mapComputer.step.click"):r==="scroll"?s("mapComputer.step.scroll"):r==="screenshot"?s("mapComputer.step.look"):r==="drag"?s("mapComputer.step.drag"):null}const it={starting:"mapComputer.state.starting",working:"mapComputer.state.working",idle:"mapComputer.state.idle",asleep:"mapComputer.state.asleep",off:"mapComputer.state.off",problem:"mapComputer.state.problem"},Bn={starting:"bg-warning",working:"bg-success",idle:"bg-sky-400",asleep:"bg-white/35",off:"bg-white/25",problem:"bg-danger"},zn=a.memo(function({computer:r,bots:l,frameUrl:d,state:i,activity:c,x:I,y:g,onOpen:x}){const M=i==="working",h=r.kind==="team"?r.name:s("mapComputer.botComputer",{name:r.name});return e.jsxs("div",{"data-computer-node":r.id,className:"absolute",style:{left:I,top:g,width:Ge,height:je},children:[M&&e.jsx("span",{"aria-hidden":!0,className:"pointer-events-none absolute -inset-[5px] animate-computer-glow rounded-[22px] border-2 border-success/70 shadow-[0_0_24px_rgba(52,199,89,0.35)]"}),e.jsxs("button",{type:"button",onClick:x,disabled:!x,title:c?`${h} · ${c}`:h,"aria-label":s("mapComputer.open",{name:h,state:s(it[i])}),className:"relative flex size-full flex-col rounded-[18px] border border-white/10 bg-[#0f1117] p-2 text-left shadow-[0_10px_30px_rgba(0,0,0,0.35)] outline-none transition-transform hover:-translate-y-0.5 focus-visible:ring-2 focus-visible:ring-accent disabled:cursor-default",children:[e.jsxs("span",{className:"relative block h-[160px] w-full overflow-hidden rounded-[8px] bg-[#06070b] [contain:paint]",children:[d?e.jsx("img",{src:d,alt:"",draggable:!1,decoding:"async",className:ne("size-full object-cover",i==="asleep"||i==="off"?"opacity-40 grayscale":"")}):e.jsxs("span",{className:"flex size-full flex-col items-center justify-center gap-2 bg-[radial-gradient(circle_at_50%_40%,#1b2030,#06070b_70%)] text-[11px] text-white/45",children:[i==="starting"?e.jsx(Re,{size:20,className:"animate-spin"}):i==="asleep"?e.jsx(wt,{size:20}):i==="problem"?e.jsx(Mt,{size:20}):e.jsx(cn,{size:20}),s(i==="starting"?"mapComputer.empty.starting":i==="asleep"?"mapComputer.empty.asleep":i==="problem"?"mapComputer.empty.problem":i==="off"?"mapComputer.empty.off":"mapComputer.empty.waiting")]}),e.jsxs("span",{className:"absolute left-2 top-2 flex items-center gap-1.5 rounded-full bg-black/65 px-2 py-0.5 text-[10px] font-medium text-white/90 backdrop-blur-[2px]",children:[e.jsx("span",{className:ne("size-1.5 rounded-full",Bn[i],M&&"animate-pulse")}),s(it[i])]}),c&&M&&e.jsx("span",{className:"absolute inset-x-0 bottom-0 truncate bg-gradient-to-t from-black/85 via-black/55 to-transparent px-2.5 pb-1.5 pt-6 text-[11px] leading-tight text-white/90",children:c})]}),e.jsxs("span",{className:"flex h-[32px] min-w-0 items-center gap-2 px-1 pt-1.5",children:[e.jsx("span",{className:"flex shrink-0 -space-x-1.5",children:l.slice(0,3).map(w=>e.jsx("span",{className:"rounded-full ring-2 ring-[#0f1117]",children:e.jsx(Ze,{bot:w,size:20,animated:!1,motion:"none",motionKey:0})},w.id))}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-medium text-white/90",children:h}),l.length>3&&e.jsxs("span",{className:"shrink-0 text-[10px] text-white/50",children:["+",l.length-3]})]})]})]})}),Ae="flex size-9 shrink-0 items-center justify-center rounded-lg text-ink-secondary hover:bg-control hover:text-ink focus-visible:outline-2 focus-visible:outline-accent",Ie="flex w-full items-center gap-2 rounded-lg px-3 py-2.5 text-left text-[12px] text-ink-secondary hover:bg-control hover:text-ink";function Dn({bot:n,selected:r,moving:l,connected:d,tagged:i=!1,sent:c,onComputer:I,onArrange:g}){const{state:x,dispatch:M}=Ne(),h=Qe(),w=xn(n),b=Ot(n,xt()),O=x.instances.find(A=>A.instanceId===n.modelSelection.instanceId),U=O?.models.options.find(A=>A.id===n.modelSelection.model)?.label??n.modelSelection.model;return e.jsxs("article",{className:ne("relative h-[126px] w-[236px] shrink-0 rounded-xl border bg-card shadow-sm transition-colors",r?"border-accent/60 ring-1 ring-accent/15":d?"border-accent/40":"border-hairline/50 hover:border-ink-secondary/40",i&&"border-accent ring-4 ring-accent/25",l&&"opacity-35"),children:[c!==void 0&&e.jsx("span",{"data-sent-highlight":!0,"aria-hidden":!0,className:"pointer-events-none absolute -inset-px animate-sent-border rounded-xl border-2 border-accent"},c),e.jsxs("button",{"data-bot-id":n.id,"aria-label":s("canvas.editBot",{name:b}),onClick:()=>Ye(M,"identity",{botId:n.id}),title:g?s("canvas.reorderHint"):void 0,onKeyDown:A=>{!g||!A.altKey||A.key!=="ArrowUp"&&A.key!=="ArrowDown"||(A.preventDefault(),A.stopPropagation(),g(n,A.key==="ArrowUp"?-1:1))},className:"flex h-[82px] w-full cursor-grab items-center gap-3 rounded-t-xl px-4 text-left active:cursor-grabbing focus-visible:outline-2 focus-visible:outline-accent",children:[e.jsx(Ze,{bot:n,size:38,motion:"none",motionKey:0,animated:!1}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-[14px] font-semibold",children:b}),n.chiefOfStaff&&e.jsx(Bt,{size:12,className:"shrink-0 text-warning","aria-label":s("chat.chiefOfStaff")})]}),e.jsx("span",{className:"mt-1 block truncate text-[11px] text-ink-secondary",children:n.title||(n.chiefOfStaff?s("chat.chiefOfStaff"):s("canvas.bot"))})]})]}),e.jsxs("div",{className:"flex h-[43px] items-center gap-1 border-t border-hairline/30 px-2",children:[e.jsx("button",{className:ne(Ae,"size-8"),"aria-label":s("canvas.openBotChat",{name:n.name}),title:s("canvas.openChat"),onClick:()=>tt(M,n,h),children:e.jsx(on,{size:13})}),w.tone!=="idle"&&e.jsxs("span",{className:"flex items-center gap-1.5 text-[10px] text-ink-secondary",title:w.label,children:[e.jsx("span",{className:ne("size-1.5 rounded-full",w.tone==="success"?"bg-success":w.tone==="warning"?"bg-warning":w.tone==="danger"?"bg-danger":"bg-ink-secondary/35")}),w.label]}),r&&I&&e.jsx("button",{className:ne(Ae,"size-8"),"aria-label":s("canvas.botComputer",{name:n.name}),title:s("computer.tab.computer"),onClick:()=>I(n),children:e.jsx(Oe,{size:13})}),e.jsxs("button",{"aria-label":s("canvas.changeModel",{name:n.name}),title:`${s("canvas.defaultModel")}: ${U}`,onClick:()=>Ye(M,"model",{botId:n.id}),className:"ml-auto flex h-8 min-w-0 max-w-[130px] items-center gap-1.5 rounded-md px-2 text-[10px] text-ink-secondary hover:bg-control hover:text-ink focus-visible:outline-2 focus-visible:outline-accent",children:[e.jsx("span",{className:"flex size-3.5 shrink-0 items-center justify-center",children:O?e.jsx(zt,{instance:O,size:13}):e.jsx(Dt,{driverKind:"",size:13})}),e.jsx("span",{className:"truncate",children:U||s("canvas.defaultModel")})]})]})]})}const Ln=[];function Pn(n,r){if(!n?.busy)return;const l=n.tasks?.find(i=>i.threadId===n.threadId),d=!l||l.busy?n.messages.findLast(i=>i.kind==="activity"&&i.tool):void 0;return d?.tool?On(d.tool)??At(d.tool,Rt(n,r),d.dataResult):n.tasks?.find(i=>i.busy&&i.threadId!==n.threadId&&i.title.trim())?.title}function $n({sections:n,canManage:r,onMove:l,onInstructions:d,onMemory:i,onEditTeam:c,onDeleteTeam:I,onComputer:g,onComputerDrop:x,onTeamComputer:M,teamComputers:h={},connectedBotIds:w=[],computers:b=Ln,computerFrames:O={},onOpenComputer:U,taggedBotIds:A=[],sent:K,bottomInset:v=0}){const{state:y}=Ne(),j=a.useRef(null),B=a.useRef(null),L=a.useRef(!1),Y=a.useRef(!1),_=a.useRef(null),[H,G]=a.useState({}),[R,q]=a.useState({}),[m,z]=a.useState({x:40,y:40,scale:1}),[N,$]=a.useState(null),[T,P]=a.useState(null),[se,S]=a.useState(null),[F,ee]=a.useState(null),[ie,re]=a.useState(null),[ue,de]=a.useState(""),[fe,me]=a.useState(!1),[he,ge]=a.useState(null),[ve,Se]=a.useState({width:0,height:0}),oe=a.useMemo(()=>n.map(t=>{if(!b.length)return null;const p=Object.hasOwn(R,t.key)?R[t.key]:[],u=ke(t.chiefs,p),C=ke(t.members,p);return jn({chiefs:u,members:C},Sn(t.key,[...u,...C].map(E=>E.id),b))}),[n,b,R]),pe=a.useMemo(()=>{if(!oe.some(Boolean))return;const t=oe.map((p,u)=>p??gt(n[u]));return{sizes:t,columns:wn(t,{width:Math.round(ve.width/200)*200,height:Math.round(ve.height/200)*200})}},[oe,n,ve]),be=a.useMemo(()=>yn(n,H,pe),[n,H,pe]),ce=a.useRef({view:m,positions:H,tiles:be,selectedId:y.selectedId,settingsOpen:y.settingsOpen,bottomInset:v});ce.current={view:m,positions:H,tiles:be,selectedId:y.selectedId,settingsOpen:y.settingsOpen,bottomInset:v},a.useEffect(()=>{let t=!0;return te("/.well-known/openmausbot/environment",{signal:AbortSignal.timeout(5e3)}).then(p=>{if(!(!t||typeof p.environmentId!="string")){_.current=`omb-team-canvas:${p.environmentId}`;try{const u=kn(localStorage.getItem(_.current));G(C=>({...u,...C})),q(bn(localStorage.getItem(`${_.current}:bot-order`)))}catch{}}}).catch(()=>{}).finally(()=>{t&&me(!0)}),()=>{t=!1}},[]);const f=t=>{if(G(t),!!_.current)try{localStorage.setItem(_.current,JSON.stringify(Object.fromEntries(n.filter(p=>Object.hasOwn(t,p.key)).map(p=>[p.key,t[p.key]]))))}catch{}},o=t=>Object.hasOwn(R,t)?R[t]:[],k=(t,p,u,C)=>{const E={...R,[t.key]:[...gn(p,u.id,C),...ke(u.chiefOfStaff?t.members:t.chiefs,o(t.key)).map(Q=>Q.id)]};if(q(E),_.current)try{localStorage.setItem(`${_.current}:bot-order`,JSON.stringify(E))}catch{}de(s("canvas.arrangedBot",{name:u.name,team:t.name}))},J=(t,p)=>{const u=n.find(E=>E.key===(t.section?.trim()??""));if(!u)return;const C=ke(t.chiefOfStaff?u.chiefs:u.members,o(u.key));k(u,C,t,C.findIndex(E=>E.id===t.id)+p)},Z=a.useCallback(()=>{const t=j.current?.getBoundingClientRect();t&&z(vn(ce.current.tiles,t.width,Math.max(200,t.height-ce.current.bottomInset)))},[]);a.useEffect(()=>{const t=j.current;if(!t)return;let p=null;const u=new ResizeObserver(()=>{const C=t.getBoundingClientRect();if(Se({width:C.width,height:C.height}),!p)Z();else{const E=ce.current.settingsOpen?[...t.querySelectorAll("[data-bot-id]")].find(V=>V.dataset.botId===ce.current.selectedId)?.getBoundingClientRect():void 0,Q=E?C.width/2-(E.left-C.left+E.width/2):(C.width-p.width)/2,ae=E?C.height/2-(E.top-C.top+E.height/2):(C.height-p.height)/2;z(V=>({...V,x:V.x+Q,y:V.y+ae}))}p={width:C.width,height:C.height}});return u.observe(t),()=>u.disconnect()},[Z]);const le=JSON.stringify(be.map(({key:t,width:p,height:u})=>[t,p,u]));a.useEffect(()=>{Z()},[Z,le,fe]),a.useEffect(()=>{const t=j.current?.querySelector("details[open]"),p=j.current?.getBoundingClientRect();t&&p&&ge(t.getBoundingClientRect().bottom>p.bottom-210*m.scale?t.closest("[data-team-key]")?.dataset.teamKey??null:null)},[m,le]),a.useEffect(()=>{const t=j.current;if(!t)return;const p=u=>{if(u.target.closest("details[open]")||(u.preventDefault(),B.current))return;const C=ce.current.view,E=t.getBoundingClientRect();if(u.ctrlKey||u.metaKey){const Q=Math.min(1.5,Math.max(.3,C.scale*Math.exp(-u.deltaY*.006)));z(at(C,Q,{x:u.clientX-E.left,y:u.clientY-E.top}))}else{const Q=u.deltaMode===1?16:u.deltaMode===2?E.height:1;z({...C,x:C.x-u.deltaX*Q,y:C.y-u.deltaY*Q})}};return t.addEventListener("wheel",p,{passive:!1}),()=>t.removeEventListener("wheel",p)},[]);const W=t=>{if(t.button!==0||!t.isPrimary||B.current)return;const p=t.target,u=p.closest("[data-bot-id]")?.dataset.botId,C=p.closest("[data-arrange-team]")?.dataset.arrangeTeam,E=u?n.flatMap(V=>[...V.chiefs,...V.members]).find(V=>V.id===u):void 0;if(!E&&C===void 0&&p.closest("button, details, a, input, [data-team-key]")||E&&(ie||!fe)||C!==void 0&&!fe)return;const Q={id:t.pointerId,start:{x:t.clientX,y:t.clientY},view:m,positions:H,moved:!1},ae=C===void 0?void 0:be.find(V=>V.key===C);B.current=E?{...Q,kind:"bot",bot:E}:ae?{...Q,kind:"team",key:ae.key,origin:ae}:{...Q,kind:"pan"},L.current=!1},nt=(t,p)=>{const u=document.elementFromPoint(t,p)?.closest("[data-team-key]");return u&&j.current?.contains(u)?u.dataset.teamKey??null:null},st=(t,p)=>{const u=n.find(V=>V.key===(t.section?.trim()??""));if(!u)return null;const C=ke(t.chiefOfStaff?u.chiefs:u.members,o(u.key)),E=C.filter(V=>V.id!==t.id),Q=[...j.current?.querySelectorAll("[data-bot-id]")??[]],ae=E.findIndex(V=>{const D=Q.find(X=>X.dataset.botId===V.id)?.closest("article")?.getBoundingClientRect();return D?p<D.top+D.height/2:!1});return{section:u,lane:C,remaining:E,index:ae<0?E.length:ae}},bt=t=>{const p=B.current;if(!p||p.id!==t.pointerId)return;if(t.buttons===0){Ce(t,!0);return}const u=t.clientX-p.start.x,C=t.clientY-p.start.y;if(!(!p.moved&&Math.hypot(u,C)<5)&&(p.moved=!0,t.currentTarget.setPointerCapture(t.pointerId),p.kind==="pan"&&z({...p.view,x:p.view.x+u,y:p.view.y+C}),p.kind==="team"&&G({...p.positions,[p.key]:{x:p.origin.x+u/m.scale,y:p.origin.y+C/m.scale}}),p.kind==="bot")){const E=t.currentTarget.getBoundingClientRect();$({bot:p.bot,point:{x:t.clientX-E.left,y:t.clientY-E.top}});const Q=nt(t.clientX,t.clientY),ae=Q===(p.bot.section?.trim()??"");P(ae||r?Q:null);const V=ae?st(p.bot,t.clientY):null,D=V?.remaining[V.index]??V?.remaining.at(-1);ee(V&&D?{botId:D.id,after:V.index===V.remaining.length}:null)}},Ce=(t,p=!1)=>{const u=B.current;if(!(!u||t&&u.id!==t.pointerId)){if(B.current=null,L.current=u.moved,window.setTimeout(()=>{L.current=!1},0),$(null),P(null),ee(null),j.current?.hasPointerCapture(u.id)&&j.current.releasePointerCapture(u.id),p){G(u.positions),z(u.view);return}if(u.moved&&(u.kind==="team"&&t&&f({...u.positions,[u.key]:{x:u.origin.x+(t.clientX-u.start.x)/u.view.scale,y:u.origin.y+(t.clientY-u.start.y)/u.view.scale}}),u.kind==="bot"&&t)){const C=nt(t.clientX,t.clientY);if(C===null)return;if(C===(u.bot.section?.trim()??"")){const E=st(u.bot,t.clientY);E&&k(E.section,E.lane,u.bot,E.index);return}if(!r)return;re(u.bot.id),de(s("canvas.reviewMove",{name:u.bot.name,team:C||s("settings.section.general")})),l(u.bot,C).then(E=>{de(E===!1?s("canvas.moveCancelled"):s("canvas.moved",{name:u.bot.name,team:C||s("settings.section.general")}))}).catch(E=>{de(E instanceof Error?E.message:String(E))}).finally(()=>re(null))}}},ze=t=>{const p=j.current?.getBoundingClientRect();p&&z(at(m,Math.max(.3,Math.min(1.5,m.scale*t)),{x:p.width/2,y:p.height/2}))},De=new Map(n.flatMap(t=>[...t.chiefs,...t.members]).map(t=>[t.id,t])),yt=new Map(b.map(t=>[t.id,t])),vt=t=>{const p=t.botIds.flatMap(u=>De.get(u)??[]);return t.state==="idle"&&p.some(u=>u.busy)?"working":t.state!=="working"&&p.some(u=>y.computerStarts[u.id])?"starting":t.state},Le=n.find(t=>t.key===T),Pe=se!==null?s("canvas.assignComputer",{team:n.find(t=>t.key===se)?.name??se}):N&&Le?(N.bot.section?.trim()??"")===Le.key?s("canvas.arrangeBot",{name:N.bot.name,team:Le.name}):s("canvas.moveBot",{name:N.bot.name,team:Le.name}):null;return e.jsxs("div",{ref:j,role:"region","aria-label":s("canvas.region"),tabIndex:0,"data-team-canvas":!0,className:"relative min-h-0 flex-1 touch-none overflow-clip outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent/40",style:{backgroundImage:"radial-gradient(circle, color-mix(in srgb, var(--color-ink-secondary) 18%, transparent) 1px, transparent 1px)",backgroundSize:`${24*m.scale}px ${24*m.scale}px`,backgroundPosition:`${m.x}px ${m.y}px`},onPointerDown:W,onPointerMove:bt,onPointerUp:t=>Ce(t),onPointerCancel:t=>Ce(t,!0),onDragOver:t=>{if(!r||!x||!t.dataTransfer.types.includes(qe))return;const p=t.target.closest("[data-team-key]"),u=p&&t.currentTarget.contains(p)?p.dataset.teamKey??null:null;S(u),u!==null&&(t.preventDefault(),t.dataTransfer.dropEffect="link")},onDragLeave:t=>{(!(t.relatedTarget instanceof Node)||!t.currentTarget.contains(t.relatedTarget))&&S(null)},onDrop:t=>{if(S(null),!r||!x||!t.dataTransfer.types.includes(qe))return;const p=t.target.closest("[data-team-key]"),u=p&&t.currentTarget.contains(p)?p.dataset.teamKey:void 0,C=t.dataTransfer.getData(qe);u===void 0||!n.some(E=>E.key===u)||!C||(t.preventDefault(),x(C,u))},onDragEnd:()=>S(null),onPointerDownCapture:t=>{Y.current=!1,t.target.closest("details")||t.currentTarget.querySelectorAll("details[open]").forEach(p=>p.removeAttribute("open"))},onKeyDownCapture:t=>{t.key==="Tab"&&(Y.current=!0)},onPointerLeave:()=>{B.current&&!B.current.moved&&Ce(void 0,!0)},onLostPointerCapture:()=>{B.current&&Ce(void 0,!0)},onFocusCapture:t=>{if(!Y.current||!(t.target instanceof HTMLElement)||!t.target.closest("[data-canvas-world]"))return;const p=t.currentTarget.getBoundingClientRect(),u=t.target.getBoundingClientRect(),C=u.left<p.left+16?p.left+16-u.left:u.right>p.right-16?p.right-16-u.right:0,E=u.top<p.top+16?p.top+16-u.top:u.bottom>p.bottom-70?p.bottom-70-u.bottom:0;(C||E)&&z(Q=>({...Q,x:Q.x+C,y:Q.y+E}))},onClickCapture:t=>{L.current&&(L.current=!1,t.preventDefault(),t.stopPropagation())},onKeyDown:t=>{if(t.key==="Escape"&&(Ce(void 0,!0),t.currentTarget.querySelectorAll("details[open]").forEach(C=>{C.querySelector("summary")?.focus({preventScroll:!0}),C.removeAttribute("open")})),t.target!==t.currentTarget)return;const u={ArrowLeft:{x:60,y:0},ArrowRight:{x:-60,y:0},ArrowUp:{x:0,y:60},ArrowDown:{x:0,y:-60}}[t.key];u&&(t.preventDefault(),z({...m,x:m.x+u.x,y:m.y+u.y})),(t.key==="+"||t.key==="=")&&(t.preventDefault(),ze(1.2)),t.key==="-"&&(t.preventDefault(),ze(1/1.2)),t.key==="0"&&(t.preventDefault(),Z())},children:[e.jsx("div",{"data-canvas-world":!0,className:"absolute left-0 top-0 origin-top-left",style:{transform:`translate(${m.x}px, ${m.y}px) scale(${m.scale})`},children:n.map((t,p)=>{const u=be[p],C=oe[p],E=t.chiefs.length>0&&t.members.length>0,Q=se===t.key||N&&T===t.key&&(N.bot.section?.trim()??"")!==t.key,ae=Object.hasOwn(h,t.key)?h[t.key]:void 0,V=D=>e.jsxs("div",{className:"relative",children:[F?.botId===D.id&&e.jsx("div",{className:ne("pointer-events-none absolute inset-x-1 h-0.5 rounded bg-accent",F.after?"-bottom-[9px]":"-top-[9px]")}),e.jsx(Dn,{bot:D,selected:y.selectedId===D.id&&y.settingsOpen,moving:N?.bot.id===D.id||ie===D.id,connected:w.includes(D.id),tagged:A.includes(D.id),sent:K?.botIds.includes(D.id)?K.key:void 0,onComputer:g,onArrange:fe?J:void 0})]},D.id);return e.jsxs("section",{"data-team-key":t.key,"aria-label":s("canvas.teamRegion",{name:t.name}),className:ne("absolute rounded-2xl border bg-panel/90 shadow-sm has-[details[open]]:z-20 data-[computer-dropping=true]:border-accent data-[computer-dropping=true]:ring-2 data-[computer-dropping=true]:ring-accent/25",Q?"border-accent ring-2 ring-accent/25":"border-hairline/50"),style:{left:u.x,top:u.y,width:u.width,height:u.height},children:[e.jsxs("header",{className:"flex h-16 items-center gap-2 px-5",children:[e.jsx("button",{"data-arrange-team":t.key,disabled:!fe,"aria-label":s("canvas.arrange",{name:t.name}),title:s("canvas.arrangeHint"),className:"min-w-0 flex-1 cursor-grab rounded-md py-2 text-left active:cursor-grabbing focus-visible:outline-2 focus-visible:outline-accent",onKeyDown:D=>{const X={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]}[D.key];if(!X)return;D.preventDefault(),D.stopPropagation();const ye=D.shiftKey?40:10;f({...H,[t.key]:{x:u.x+X[0]*ye,y:u.y+X[1]*ye}})},children:e.jsx("h2",{className:"truncate text-[13px] font-semibold tracking-tight",children:t.name})}),ae&&e.jsxs("button",{"aria-label":s("canvas.teamComputer",{team:t.name,name:ae.name}),title:`${ae.name}${ae.state?` · ${ae.state}`:""}`,disabled:!M,onClick:()=>M?.(t.key),className:"flex min-w-0 max-w-[120px] shrink items-center gap-1.5 rounded-md px-1.5 py-2 text-[10px] text-ink-secondary hover:bg-control hover:text-ink focus-visible:outline-2 focus-visible:outline-accent disabled:pointer-events-none",children:[e.jsx(Oe,{size:12,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:ae.name})]}),e.jsx("span",{className:"text-[11px] tabular-nums text-ink-secondary",children:t.chiefs.length+t.members.length}),r&&e.jsxs("details",{className:"relative",onToggle:D=>{if(D.currentTarget.open){const X=j.current?.getBoundingClientRect();ge(X&&D.currentTarget.getBoundingClientRect().bottom>X.bottom-210*m.scale?t.key:null),j.current?.querySelectorAll("details[open]").forEach(ye=>{ye!==D.currentTarget&&ye.removeAttribute("open")})}},children:[e.jsx("summary",{"aria-label":s("canvas.manageTeam",{name:t.name}),className:ne(Ae,"cursor-pointer list-none [&::-webkit-details-marker]:hidden"),children:e.jsx(Ct,{size:17})}),e.jsxs("div",{className:ne("absolute right-0 z-30 w-[220px] animate-pop-in rounded-xl border border-hairline bg-panel p-1.5 shadow-xl",he===t.key?"bottom-10":"top-10"),onClick:D=>{const X=D.currentTarget.closest("details");X?.querySelector("summary")?.focus(),X?.removeAttribute("open")},children:[e.jsxs("button",{className:Ie,onClick:()=>c(t.key),"aria-label":s("team.moveTo",{name:t.name}),children:[e.jsx(dt,{size:14}),s("team.moveTo",{name:t.name})]}),e.jsxs("button",{className:Ie,onClick:()=>d(t.key,t.name),"aria-label":s("team.instructionsEdit",{name:t.name}),children:[e.jsx(ut,{size:14}),s("team.instructions")]}),i&&e.jsxs("button",{className:Ie,onClick:()=>i(t.key,t.name),"aria-label":s("team.memoryFor",{name:t.name}),children:[e.jsx(mt,{size:14}),s("team.memory")]}),t.key&&e.jsxs("button",{className:Ie,onClick:()=>c(t.key,!0),"aria-label":s("team.renameAria",{name:t.name}),children:[e.jsx(Tt,{size:14}),s("team.rename")]}),t.key&&e.jsxs("button",{className:ne(Ie,"hover:text-danger"),onClick:()=>I(t.key),"aria-label":s("team.deleteAria",{name:t.name}),children:[e.jsx(pt,{size:14}),s("team.delete")]})]})]})]}),Q&&e.jsx("div",{className:"pointer-events-none absolute -top-7 left-2 z-30 max-w-[calc(100%-16px)] truncate rounded-md bg-accent px-2 py-1 text-[10px] text-white shadow-sm",children:Pe}),C?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 overflow-visible",width:u.width,height:u.height,children:[C.tree.map((D,X)=>e.jsx("path",{d:rt(D),fill:"none",strokeWidth:1.5,className:"stroke-ink-secondary/25"},`tree-${X}`)),C.links.map(D=>{const X=De.get(D.botId)?.busy===!0;return e.jsx("path",{d:rt(D.points),fill:"none",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:X?2.25:1.5,strokeDasharray:X?"7 5":void 0,className:X?"animate-link-flow stroke-success/80":"stroke-ink-secondary/35"},`${D.botId}:${D.computerId}`)})]}),C.cards.map(D=>{const X=De.get(D.botId);return X?e.jsx("div",{className:"absolute",style:{left:D.x,top:D.y},children:V(X)},X.id):null}),C.monitors.map(D=>{const X=yt.get(D.id);if(!X)return null;const ye=X.botIds.flatMap(Ue=>De.get(Ue)??[]);return e.jsx(zn,{computer:X,bots:ye,x:D.x,y:D.y,frameUrl:Object.hasOwn(O,X.id)?O[X.id].url:void 0,state:vt(X),activity:Pn(ye.find(Ue=>Ue.busy),y.instances),onOpen:U?()=>U(X):void 0},X.id)})]}):e.jsxs("div",{className:"flex items-center px-5 pb-5",children:[t.chiefs.length>0&&e.jsx("div",{className:"flex flex-col gap-4",children:ke(t.chiefs,o(t.key)).map(V)}),E&&e.jsx("div",{className:"flex w-10 shrink-0 justify-center text-ink-secondary/35","aria-hidden":"true",children:e.jsx(ft,{size:22,strokeWidth:1})}),t.members.length>0&&e.jsx("div",{className:"flex flex-col gap-4",children:ke(t.members,o(t.key)).map(V)}),t.chiefs.length+t.members.length===0&&e.jsx("p",{className:"flex h-[126px] w-[236px] items-center justify-center rounded-xl border border-dashed border-hairline/70 px-6 text-center text-[12px] leading-relaxed text-ink-secondary",children:s("canvas.dropHere")})]})]},t.key)})}),N&&e.jsxs("div",{className:"pointer-events-none absolute z-40 rounded-xl border border-accent/40 bg-card px-4 py-3 text-[13px] shadow-lg",style:{left:N.point.x+16,top:N.point.y+16},children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Ze,{bot:N.bot,size:24,animated:!1}),N.bot.name]}),Pe&&e.jsx("p",{className:"mt-1 text-[10px] text-ink-secondary",children:Pe})]}),e.jsxs("div",{className:"pointer-events-none absolute inset-x-5 bottom-5 flex items-end justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 rounded-lg bg-app/90 px-2 py-1.5 text-[11px] text-ink-secondary",children:[!v&&e.jsx("p",{className:"max-sm:hidden",children:s("canvas.hint")}),e.jsx("p",{role:"status","aria-live":"polite",className:"max-w-[440px]",children:Pe??ue})]}),e.jsxs("div",{className:"pointer-events-auto flex shrink-0 items-center gap-0.5 rounded-xl border border-hairline/60 bg-panel p-1 shadow-sm",children:[e.jsx("button",{className:Ae,"aria-label":s("canvas.zoomOut"),onClick:()=>ze(1/1.2),children:e.jsx(Et,{size:15})}),e.jsxs("button",{className:"min-w-12 rounded-md px-1 py-2 text-[11px] tabular-nums text-ink-secondary hover:bg-control","aria-label":s("canvas.fit"),title:s("canvas.fitHint"),onClick:Z,children:[Math.round(m.scale*100),"%"]}),e.jsx("button",{className:Ae,"aria-label":s("canvas.zoomIn"),onClick:()=>ze(1.2),children:e.jsx(Ke,{size:15})})]})]})]})}const lt=[{kind:"person",titleKey:"teamMemory.kind.people",hintKey:"teamMemory.kind.peopleHint"},{kind:"place",titleKey:"teamMemory.kind.places",hintKey:"teamMemory.kind.placesHint"},{kind:"decision",titleKey:"teamMemory.kind.decisions",hintKey:"teamMemory.kind.decisionsHint"},{kind:"term",titleKey:"teamMemory.kind.terms",hintKey:"teamMemory.kind.termsHint"}];function _n({section:n,label:r,onClose:l}){const d=a.useRef(null),[i,c]=a.useState(null),[I,g]=a.useState([]),[x,M]=a.useState({}),[h,w]=a.useState(null),[b,O]=a.useState(null),U=a.useRef(!1),A=a.useRef(0),[K,v]=a.useState(!1),[y,j]=a.useState({kind:"term",name:"",detail:""}),B=`section=${encodeURIComponent(n)}`,L=a.useCallback(async()=>{const m=++A.current;try{const z=await te(`/api/team-memory?${B}`);if(A.current!==m)return;c(z.entries),g(z.loadedIds),w(null)}catch(z){if(A.current!==m)return;w(z instanceof Error?z.message:String(z))}},[B]);a.useEffect(()=>(c(null),w(null),L(),()=>{A.current+=1}),[L]),a.useEffect(()=>{const m=document.activeElement instanceof HTMLElement?document.activeElement:null;d.current?.focus();const z=N=>{if(N.key==="Escape"&&(N.preventDefault(),l()),N.key==="Tab"){const $=d.current?.querySelectorAll("button:enabled, input:enabled, select:enabled");if(!$?.length)return;const T=$[0],P=$[$.length-1];N.shiftKey&&document.activeElement===T?(N.preventDefault(),P.focus()):!N.shiftKey&&document.activeElement===P&&(N.preventDefault(),T.focus())}};return window.addEventListener("keydown",z),()=>{window.removeEventListener("keydown",z),m?.focus()}},[l]);const Y=async(m,z)=>{if(U.current)return!1;U.current=!0;const N=++A.current;O(m??"new"),w(null);try{const $=await z();return A.current!==N?!1:(c($.entries),O(null),$.loadedIds?g($.loadedIds):L(),!0)}catch($){return A.current===N&&w($ instanceof Error?$.message:String($)),!1}finally{U.current=!1,A.current===N&&O(null)}},_=m=>Y(m.id,()=>te(`/api/team-memory/${m.id}?${B}`,{method:"PATCH",body:JSON.stringify({accept:!0,expectedRevision:m.revision})})),H=m=>Y(m.id,()=>te(`/api/team-memory/${m.id}?${B}&revision=${m.revision}`,{method:"DELETE"})),G=(m,z,N)=>{z.trim()===m.detail&&(N===void 0||N===m.name)||Y(m.id,()=>te(`/api/team-memory/${m.id}?${B}`,{method:"PATCH",body:JSON.stringify({detail:z,...N===void 0?{}:{name:N},expectedRevision:m.revision})})).then($=>M(T=>{const P={...T};return $?delete P[m.id]:P[m.id]={name:N??m.name,text:z},P}))},R=()=>{!y.name.trim()||!y.detail.trim()||Y(null,()=>te(`/api/team-memory?${B}`,{method:"POST",body:JSON.stringify(y)})).then(m=>{m&&(j({kind:y.kind,name:"",detail:""}),v(!1))})},q=(i??[]).filter(m=>m.status==="proposed");return et.createPortal(e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/55 p-4 sm:p-6",onMouseDown:m=>m.target===m.currentTarget&&l(),children:e.jsxs("div",{ref:d,role:"dialog","aria-modal":"true","aria-labelledby":"team-memory-title",tabIndex:-1,className:"animate-pop-in flex max-h-[min(720px,calc(100dvh-2rem))] w-full max-w-[720px] flex-col overflow-hidden rounded-2xl border border-hairline/50 bg-panel shadow-2xl shadow-black/50 outline-none",children:[e.jsxs("header",{className:"flex items-start justify-between gap-4 border-b border-hairline/40 px-6 pb-4 pt-6 sm:px-8 sm:pt-7",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(mt,{size:19,className:"text-accent"}),e.jsx("h2",{id:"team-memory-title",className:"text-[20px] font-semibold tracking-[-0.01em] text-ink",children:s("teamMemory.title",{name:r})})]}),e.jsx("p",{className:"mt-1.5 max-w-[560px] text-[13px] leading-relaxed text-ink-secondary",children:s("teamMemory.description")})]}),e.jsx("button",{onClick:l,"aria-label":s("teamMemory.close"),className:"flex size-9 shrink-0 items-center justify-center rounded-lg text-ink-secondary hover:bg-raised hover:text-ink",children:e.jsx(Be,{size:19})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 py-5 sm:px-8",children:[i===null&&!h&&e.jsx("div",{className:"flex min-h-[200px] items-center justify-center text-ink-secondary",children:e.jsx(Re,{size:20,className:"animate-spin","aria-label":s("teamMemory.loading")})}),i&&e.jsx("p",{className:"mb-3 text-[12px] text-ink-secondary",children:s("teamMemory.loadedSummary",{loaded:I.length,total:i.filter(m=>m.status==="accepted").length})}),h&&e.jsxs("div",{role:"alert",className:"mb-3 rounded-lg border border-danger/30 bg-danger/10 px-3 py-2 text-[12px] text-danger",children:[h," ",e.jsx("button",{onClick:()=>{L()},className:"underline",children:s("teamMemory.reload")})]}),Object.entries(x).map(([m,z])=>e.jsxs("p",{className:"mb-3 text-[12px] text-ink-secondary",children:[e.jsx("strong",{children:z.name})," · ",s("teamMemory.unsaved",{text:z.text})]},m)),q.length>0&&e.jsxs("section",{className:"mb-5 rounded-xl border border-accent/30 bg-accent/5 p-3",children:[e.jsx("h3",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-accent",children:s("teamMemory.waiting")}),e.jsx("ul",{className:"mt-2 space-y-2",children:q.map(m=>e.jsxs("li",{className:"flex items-start gap-3 text-[13px]",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"text-ink-secondary",children:[s(`teamMemory.kind.${m.kind}`),": "]}),e.jsx("span",{className:"font-medium text-ink",children:m.name}),m.aliases.length>0&&e.jsxs("span",{className:"text-ink-secondary",children:[" (",s("teamMemory.also")," ",m.aliases.join(", "),")"]}),e.jsxs("span",{className:"text-ink",children:[" — ",m.detail]}),e.jsxs("span",{className:"block text-[11px] text-ink-secondary",children:[s("teamMemory.source",{name:m.source.botName}),m.source.quote&&` · ${s("teamMemory.sourceQuote",{quote:m.source.quote})}`]})]}),e.jsxs("button",{onClick:()=>{_(m)},disabled:b!==null,className:"flex shrink-0 items-center gap-1 rounded-md bg-accent px-2.5 py-1 text-[12px] font-medium text-white disabled:opacity-50",children:[e.jsx(kt,{size:12})," ",s("teamMemory.remember")]}),e.jsx("button",{onClick:()=>{H(m)},disabled:b!==null,className:"shrink-0 rounded-md px-2 py-1 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:s("teamMemory.skip")})]},m.id))})]}),i!==null&&i.filter(m=>m.status==="accepted").length===0&&q.length===0&&e.jsx("div",{className:"rounded-xl bg-inset px-4 py-6 text-center text-[13px] text-ink-secondary",children:s("teamMemory.empty")}),lt.map(({kind:m,titleKey:z,hintKey:N})=>{const $=(i??[]).filter(T=>T.status==="accepted"&&T.kind===m);return $.length===0?null:e.jsxs("section",{className:"mb-5",children:[e.jsx("h3",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-ink-secondary",title:s(N),children:s(z)}),e.jsx("ul",{className:"mt-2 divide-y divide-hairline/20 rounded-xl bg-inset",children:$.map(T=>e.jsxs("li",{className:"flex items-start gap-3 px-3 py-2 text-[13px]",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"font-medium text-ink",children:T.name}),T.aliases.length>0&&e.jsxs("span",{className:"text-ink-secondary",children:[" (",s("teamMemory.also")," ",T.aliases.join(", "),")"]}),e.jsx("input",{defaultValue:T.detail,disabled:b!==null,onBlur:P=>G(T,P.target.value),onKeyDown:P=>{P.key==="Enter"&&P.target.blur()},"aria-label":s("teamMemory.entryDetailLabel",{name:T.name}),className:"mt-0.5 block w-full rounded bg-transparent px-1 py-0.5 text-[13px] text-ink outline-none hover:bg-card focus:bg-card"},T.revision),e.jsxs("span",{className:"block px-1 text-[11px] text-ink-secondary",children:[T.source.botName||s("teamMemory.you")," · ",new Date(T.updatedAt).toLocaleDateString(Ee())," · ",I.includes(T.id)?s("teamMemory.loaded"):s("teamMemory.searchable")]}),!!T.history?.length&&e.jsxs("details",{className:"mt-1 text-[11px] text-ink-secondary",children:[e.jsx("summary",{children:s("teamMemory.history")}),T.history.map((P,se)=>e.jsxs("div",{className:"mt-1",children:[new Date(P.at).toLocaleDateString(Ee()),": ",P.name," — ",P.detail," ",e.jsx("button",{disabled:b!==null,onClick:()=>G(T,P.detail,P.name),className:"underline",children:s("teamMemory.restore")})]},se))]})]}),e.jsx("button",{"aria-label":s(T.pinned?"teamMemory.unpin":"teamMemory.pin",{name:T.name}),"aria-pressed":T.pinned??!1,disabled:b!==null,className:"p-1 text-ink-secondary hover:text-accent",onClick:()=>{Y(T.id,()=>te(`/api/team-memory/${T.id}?${B}`,{method:"PATCH",body:JSON.stringify({pinned:!T.pinned,expectedRevision:T.revision})}))},children:e.jsx(Lt,{size:13})}),e.jsx("button",{onClick:()=>{H(T)},disabled:b!==null,"aria-label":s("teamMemory.remove",{name:T.name}),className:"shrink-0 rounded-md p-1 text-ink-secondary hover:text-danger disabled:opacity-50",children:e.jsx(pt,{size:13})})]},T.id))})]},m)}),K?e.jsxs("div",{className:"rounded-xl border border-hairline/40 bg-card p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(ht,{size:"sm",value:y.kind,onChange:m=>j({...y,kind:m.target.value}),"aria-label":s("teamMemory.kindLabel"),children:lt.map(({kind:m})=>e.jsx("option",{value:m,children:s(`teamMemory.kind.${m}`)},m))}),e.jsx("input",{value:y.name,onChange:m=>j({...y,name:m.target.value}),placeholder:s("teamMemory.namePlaceholder"),"aria-label":s("teamMemory.nameLabel"),className:"min-w-[140px] flex-1 rounded-lg border border-hairline/40 bg-inset px-2 py-1 text-[13px] text-ink outline-none focus:border-accent"})]}),e.jsx("input",{value:y.detail,onChange:m=>j({...y,detail:m.target.value}),onKeyDown:m=>{m.key==="Enter"&&R()},placeholder:s("teamMemory.detailPlaceholder"),"aria-label":s("teamMemory.detailLabel"),className:"mt-2 w-full rounded-lg border border-hairline/40 bg-inset px-2 py-1 text-[13px] text-ink outline-none focus:border-accent"}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("button",{onClick:R,disabled:b!==null||!y.name.trim()||!y.detail.trim(),className:"rounded-lg bg-accent px-3 py-1 text-[13px] font-medium text-white disabled:opacity-50",children:b==="new"?s("teamMemory.adding"):s("teamMemory.add")}),e.jsx("button",{onClick:()=>v(!1),className:"text-[13px] text-ink-secondary hover:text-ink",children:s("common.cancel")})]})]}):e.jsxs("button",{onClick:()=>v(!0),className:ne("flex items-center gap-1.5 text-[13px] text-ink-secondary hover:text-ink",i===null&&"hidden"),children:[e.jsx(Ke,{size:13})," ",s("teamMemory.addEntry")]})]})]})}),document.body)}const xe="rounded-lg px-3 py-2 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",Hn="w-full rounded-lg border border-hairline/60 bg-inset px-3 py-2 text-[12px] text-ink outline-none focus:border-accent";function Kn(n,r){if(r)return s("canvasComputers.updating");const l={idle:"idle",ready:"ready",running:"running",init:"starting",provisioning:"provisioning",provisioned:"starting",cloning:"starting",starting:"starting",sleeping:"sleeping"}[n];return l?s(`canvasComputers.state.${l}`):n}function Un({open:n,createRequest:r,drop:l,sections:d,onClose:i,onDropHandled:c,onChange:I}){const{dispatch:g}=Ne(),[x,M]=a.useState(null),[h,w]=a.useState(!1),[b,O]=a.useState(""),[U,A]=a.useState(""),[K,v]=a.useState(null),[y,j]=a.useState(!1),[B,L]=a.useState(""),Y=a.useRef($e()),_=a.useRef(null),H=a.useRef(null),G=a.useRef(null),R=a.useRef(!1),q=a.useRef(!0),m=a.useRef(null),z=a.useRef(I);z.current=I;const[N,$]=a.useState(null),[T,P]=a.useState(null),[se,S]=a.useState(null),F=a.useRef($e()),ee=a.useRef(null),ie=a.useRef(null),re=a.useRef(null),ue=a.useRef(null),[de,fe]=a.useState(null),me=a.useCallback(()=>{const o=re.current;re.current=null,ue.current?.removeAttribute("data-computer-dropping"),ue.current=null,o?.handle.hasPointerCapture(o.id)&&o.handle.releasePointerCapture(o.id),fe(null)},[]);a.useEffect(()=>(n||me(),()=>{ue.current?.removeAttribute("data-computer-dropping")}),[n,me]),a.useEffect(()=>{ee.current=se},[se]),a.useEffect(()=>()=>{const o=ee.current;o&&fetch(`/api/team-computers/${encodeURIComponent(o)}/control`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({action:"release",controlLeaseId:F.current}),keepalive:!0}).catch(()=>{})},[]);const he=a.useCallback((o,k)=>{if(!(R.current||o.section===k)){if(o.section!==null&&k!==null){O(s("canvasComputers.unassignBeforeMove",{computer:o.name,team:o.section||s("settings.section.general")}));return}O(""),$({computer:o,section:k})}},[]),ge=(o,k)=>{const J=ie.current?.parentElement?.querySelector("[data-team-canvas]"),Z=document.elementFromPoint(o,k)?.closest("[data-team-key]");return Z&&J?.contains(Z)&&d.some(le=>le.key===Z.dataset.teamKey)?Z:null},ve=o=>{const k=re.current;if(!k||o.pointerId!==k.id)return;if(o.buttons===0){me();return}if(!k.moved&&Math.hypot(o.clientX-k.x,o.clientY-k.y)<5)return;k.moved=!0,o.currentTarget.setPointerCapture(o.pointerId);const J=ge(o.clientX,o.clientY);ue.current!==J&&(ue.current?.removeAttribute("data-computer-dropping"),J?.setAttribute("data-computer-dropping","true"),ue.current=J);const Z=J?d.find(le=>le.key===J.dataset.teamKey):null;fe({name:k.computer.name,x:o.clientX,y:o.clientY,hint:Z?k.computer.section!==null&&k.computer.section!==Z.key?s("canvasComputers.unassignBeforeMoving"):s("canvasComputers.assignTo",{team:Z.name}):s("canvasComputers.dropOntoTeam")})},Se=o=>{const k=re.current;if(!k||k.id!==o.pointerId)return;const J=k.moved?ge(o.clientX,o.clientY)?.dataset.teamKey:void 0;me(),J!==void 0&&he(k.computer,J)},oe=a.useCallback(async(o=!1)=>{m.current?.abort();const k=new AbortController;m.current=k,w(!0);try{const J=await te("/api/team-computers",{signal:AbortSignal.any([k.signal,AbortSignal.timeout(3e4)]),background:o});if(k.signal.aborted||!q.current)return;M(J),A(""),z.current(J.computers)}catch(J){!k.signal.aborted&&q.current&&A(J instanceof Error?J.message:String(J))}finally{!k.signal.aborted&&q.current&&w(!1)}},[]);a.useEffect(()=>(q.current=!0,oe(),()=>{q.current=!1,m.current?.abort()}),[oe]),a.useEffect(()=>{if(!n)return;oe();const o=window.setInterval(()=>{!R.current&&document.visibilityState==="visible"&&oe(!0)},2e4);return()=>window.clearInterval(o)},[n,oe]),a.useEffect(()=>{r>0&&j(!0)},[r]),a.useEffect(()=>{if(!n)return;const o=document.activeElement instanceof HTMLElement?document.activeElement:null;return G.current?.focus(),()=>{o?.isConnected&&o.focus()}},[n]),a.useEffect(()=>{n&&y&&H.current?.focus()},[n,y]),a.useEffect(()=>{if(!l)return;const o=x?.computers.find(k=>k.id===l.id);o&&he(o,l.section),c()},[l,x,c,he]);const pe=async(o,k,J,Z)=>{if(!R.current){R.current=!0,v(o),O(""),m.current?.abort();try{const le=await k();q.current&&J?.(le)}catch(le){q.current&&(O(le instanceof Error?le.message:String(le)),Z?.())}finally{R.current=!1,q.current&&(v(null),await oe())}}},be=a.useCallback(()=>$(null),[]),ce=(o,k,J={})=>te(`/api/team-computers/${encodeURIComponent(o)}/${k}`,{method:"POST",body:JSON.stringify(J)}),f=()=>{i(),g({type:"toggleAppSettings",open:!0,section:"computer"})};return e.jsxs(e.Fragment,{children:[n&&e.jsxs("aside",{ref:ie,"aria-label":s("canvasComputers.title"),onKeyDown:o=>{o.key==="Escape"&&!N&&(o.stopPropagation(),re.current?me():i())},className:"flex w-[300px] max-w-[90vw] shrink-0 flex-col border-l border-hairline/50 bg-panel max-sm:absolute max-sm:inset-y-0 max-sm:right-0 max-sm:z-30 max-sm:shadow-xl",children:[e.jsxs("header",{className:"flex items-center gap-2 border-b border-hairline/40 px-4 py-3",children:[e.jsx(Oe,{size:16,className:"text-ink-secondary"}),e.jsx("h2",{className:"flex-1 text-[13px] font-semibold",children:s("canvasComputers.title")}),e.jsx("button",{"aria-label":s("canvasComputers.refresh"),className:xe,disabled:h||K!==null,onClick:()=>{O(""),oe()},children:e.jsx(sn,{size:14,className:h?"animate-spin":""})}),e.jsx("button",{ref:G,"aria-label":s("canvasComputers.close"),className:xe,onClick:i,children:e.jsx(Be,{size:15})})]}),e.jsxs("div",{className:"min-h-0 flex-1 space-y-3 overflow-y-auto p-4",children:[e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:s("canvasComputers.hint")}),(b||U||x?.problem)&&e.jsx("p",{role:"alert",className:"rounded-lg bg-danger/10 p-3 text-[12px] text-danger",children:b||U||x?.problem}),x&&!x.configured&&e.jsxs("div",{className:"rounded-xl border border-hairline/50 p-3 text-[12px]",children:[e.jsx("p",{className:"text-ink-secondary",children:s("canvasComputers.connectBoatHint")}),e.jsx("button",{className:`${xe} mt-2 border border-hairline/50`,onClick:f,children:s("canvasComputers.connectBoat")})]}),y?e.jsxs("form",{className:"space-y-3 rounded-xl border border-hairline/60 bg-card p-3",onSubmit:o=>{o.preventDefault();const k=_.current??B.trim();!k||!x?.configured||(_.current=k,pe("create",()=>te("/api/team-computers",{method:"POST",body:JSON.stringify({name:k,requestId:Y.current,acknowledgeCost:!0})}),()=>{L(""),j(!1),Y.current=$e(),_.current=null},()=>{_.current=null}))},children:[e.jsx("label",{className:"block text-[12px] font-medium",htmlFor:"canvas-computer-name",children:s("canvasComputers.newCloud")}),e.jsx("input",{ref:H,id:"canvas-computer-name",className:Hn,value:B,maxLength:60,placeholder:s("canvasComputers.namePlaceholder"),disabled:K!==null||_.current!==null,onChange:o=>L(o.target.value)}),e.jsx("p",{className:"text-[11px] leading-relaxed text-ink-secondary",children:s("canvasComputers.createHint")}),e.jsxs("div",{className:"flex justify-end gap-1",children:[e.jsx("button",{type:"button",className:xe,disabled:K!==null,onClick:()=>j(!1),children:s("common.cancel")}),e.jsxs("button",{type:"submit",className:"flex items-center gap-2 rounded-lg bg-accent px-3 py-2 text-[12px] font-medium text-white disabled:opacity-40",disabled:!x?.configured||!B.trim()||K!==null,children:[K==="create"&&e.jsx(Re,{size:13,className:"animate-spin"}),s("canvasComputers.create")]})]})]}):e.jsxs("button",{className:"flex w-full items-center justify-center gap-2 rounded-xl border border-dashed border-hairline/60 px-3 py-3 text-[12px] text-ink-secondary hover:bg-control hover:text-ink",disabled:K!==null,onClick:()=>j(!0),children:[e.jsx(Ke,{size:14})," ",s("canvasComputers.newCloud")]}),x?.computers.map(o=>{const k=["idle","ready","running"].includes(o.state),J=["init","provisioning","provisioned","cloning","starting"].includes(o.state),Z=se===o.id,le=o.held||Z;return e.jsxs("article",{"data-computer-id":o.id,className:"rounded-xl border border-hairline/60 bg-card p-3",children:[e.jsxs("div",{"data-computer-drag-id":o.id,role:"group",tabIndex:-1,"aria-label":s("canvasComputers.dragToTeam",{name:o.name}),onPointerDown:W=>{R.current||re.current||W.button!==0||!W.isPrimary||(W.currentTarget.focus({preventScroll:!0}),re.current={id:W.pointerId,x:W.clientX,y:W.clientY,moved:!1,computer:o,handle:W.currentTarget},W.currentTarget.setPointerCapture(W.pointerId))},onPointerMove:ve,onPointerUp:Se,onPointerCancel:me,onLostPointerCapture:()=>{re.current&&me()},className:"flex touch-none select-none cursor-grab items-center gap-2.5 rounded-lg py-1 outline-none active:cursor-grabbing",children:[e.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-lg bg-control text-ink-secondary",children:e.jsx(Je,{size:18})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-[13px] font-medium",children:o.name}),e.jsxs("span",{className:"block text-[11px] text-ink-secondary",children:[s("canvasComputers.cloudComputer")," · ",Kn(o.state,K===o.id)]})]})]}),o.problem&&e.jsx("p",{className:"mt-2 text-[11px] text-danger",children:o.problem}),e.jsx("label",{className:"sr-only",htmlFor:`computer-team-${o.id}`,children:s("canvasComputers.teamFor",{name:o.name})}),e.jsxs(ht,{id:`computer-team-${o.id}`,className:"mt-3 w-full",disabled:K!==null,value:o.section===null?"unassigned":`team:${o.section}`,onChange:W=>he(o,W.target.value==="unassigned"?null:W.target.value.slice(5)),children:[e.jsx("option",{value:"unassigned",children:s("canvasComputers.unassigned")}),d.filter(W=>o.section===null||W.key===o.section).map(W=>e.jsx("option",{value:`team:${W.key}`,children:W.name},W.key))]}),o.section!==null&&e.jsx("p",{className:"mt-1.5 text-[10px] text-ink-secondary",children:s("canvasComputers.unassignHint")}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-1",children:[!k&&!J&&e.jsx("button",{className:xe,title:s("canvasComputers.startTitle"),disabled:K!==null||le,onClick:()=>{pe(o.id,()=>ce(o.id,"provision",{acknowledgeCost:!0}))},children:s("canvasComputers.startRetry")}),k&&!le&&e.jsx("button",{className:xe,disabled:K!==null,onClick:()=>{pe(o.id,()=>ce(o.id,"sleep"))},children:s("canvasComputers.sleep")}),k&&e.jsxs("button",{className:`${xe} flex items-center gap-1.5`,title:s("canvasComputers.openTitle"),disabled:K!==null,onClick:()=>{pe(o.id,async()=>(await ce(o.id,"control",{action:"take",controlLeaseId:F.current}),S(o.id),ce(o.id,"join")),W=>{typeof W.joinUrl=="string"&&W.joinUrl.startsWith("https://")&&P({id:o.id,url:W.joinUrl})})},children:[s("canvasComputers.openDesktop")," ",e.jsx(Nt,{size:11})]}),Z&&e.jsx("button",{className:`${xe} text-accent`,disabled:K!==null,onClick:()=>{pe(o.id,()=>ce(o.id,"control",{action:"release",controlLeaseId:F.current}),()=>{S(null),P(null)})},children:s("canvasComputers.returnToBots")}),o.held&&!Z&&e.jsx("button",{className:xe,disabled:!0,title:s("canvasComputers.inUseTitle"),children:s("canvasComputers.inUse")})]}),T?.id===o.id&&e.jsxs("a",{href:T.url,target:"_blank",rel:"noopener noreferrer",className:"mt-2 block rounded-lg px-3 py-2 text-[12px] text-accent hover:bg-control",children:[s("canvasComputers.openSecure")," ",e.jsx(Pt,{size:14,"aria-hidden":"true",className:"inline align-[-2px]"})]})]},o.id)})]}),e.jsx("footer",{className:"border-t border-hairline/40 p-3",children:e.jsx("button",{className:`${xe} w-full text-left`,onClick:f,children:s("canvasComputers.moreSettings")})})]}),de&&et.createPortal(e.jsxs("div",{role:"status",className:"pointer-events-none fixed z-[70] rounded-xl border border-accent/40 bg-card px-4 py-3 text-[12px] text-ink shadow-xl",style:{left:de.x+14,top:de.y+14},children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Je,{size:15}),de.name]}),e.jsx("p",{className:"mt-1 text-[10px] text-ink-secondary",children:de.hint})]}),document.body),e.jsx(Ve,{open:N!==null,tone:"neutral",title:N?.section===null?s("canvasComputers.unassignTitle",{name:N?.computer.name??s("canvasComputers.computer")}):s("canvasComputers.assignTitle",{name:N?.computer.name??s("canvasComputers.computer"),team:N?.section||s("settings.section.general")}),body:N?.section===null?s("canvasComputers.unassignBody"):s("canvasComputers.assignBody"),confirmLabel:N?.section===null?s("canvasComputers.unassign"):s("canvasComputers.assign"),onCancel:be,onConfirm:()=>{const o=N;o&&($(null),P(null),pe(o.computer.id,()=>te(`/api/team-computers/${encodeURIComponent(o.computer.id)}`,{method:"PATCH",body:JSON.stringify({section:o.section,acknowledgeSharedAccess:!0})})))}})]})}function qn(n,r,l){const d=r.filter(h=>!h.hidden&&h.name.trim()),i=[...d.map(h=>({name:h.name,tag:{kind:"bot",name:h.name,botIds:[h.id]}})),...l.filter(h=>h.name.trim()).map(h=>({name:h.name,tag:{kind:"team",name:h.name,botIds:d.filter(w=>(w.section?.trim()??"")===h.key).map(w=>w.id)}})),{name:"everyone",tag:{kind:"everyone",name:"everyone",botIds:d.map(h=>h.id)}}].sort((h,w)=>w.name.length-h.name.length),c=[],I=[],g=[];let x=-1;for(;(x=n.indexOf("@",x+1))!==-1;){if(!$t(n,x))continue;const h=n.slice(x+1),w=i.find(({name:O})=>h.slice(0,O.length).toLowerCase()===O.toLowerCase()&&!_t(h.slice(O.length)));if(w){c.push(w.tag),g.push([x,x+1+w.name.length]),x+=w.name.length;continue}const b=/^[\p{L}\p{N}\p{M}_.-]+/u.exec(h)?.[0];b&&I.push(b)}const M=g.reduceRight((h,[w,b])=>h.slice(0,w)+h.slice(b),n).replace(/\s+/g," ").trim();return{botIds:[...new Set(c.flatMap(h=>h.botIds))],tags:c,unknown:I,words:M}}function ct(n,r,l){if(!n.tags.some(c=>c.kind==="everyone"))return{botIds:n.botIds};if(l)return{botIds:n.botIds,text:n.words};const d=Fn(r);if(!d)return{botIds:n.botIds};const i=n.tags.filter(c=>c.kind!=="everyone").flatMap(c=>c.botIds);return{botIds:[...new Set([d.id,...i])],chief:d}}function Fn(n){const r=n.filter(l=>l.chiefOfStaff&&!l.hidden);return r.find(l=>!l.section?.trim())??r[0]}function Xn(n,r=2){return n.length<=r+1?{names:[...n],more:0}:{names:n.slice(0,r),more:n.length-r}}function Yn({bots:n,teams:r,onTagged:l,onSent:d}){const{dispatch:i}=Ne(),c=Qe(),I=Ht(),g=a.useRef(null),x=a.useRef(null),[M,h]=a.useState(""),[w,b]=a.useState(0),[O,U]=a.useState(null),[A,K]=a.useState(0),[v,y]=a.useState(null),j=a.useMemo(()=>n.filter(S=>!S.hidden),[n]),B=a.useMemo(()=>qn(M,j,r),[M,j,r]),L=a.useMemo(()=>ct(B,j,!1),[B,j]),Y=L.botIds.join(",");a.useEffect(()=>{l(Y?Y.split(","):[])},[Y,l]),a.useEffect(()=>()=>l([]),[l]);const _=Kt(M,w),H=a.useMemo(()=>{if(!_||_.start===O)return[];const S=[...j.length>1?[{id:"__everyone__",name:"everyone",all:{count:j.length}}]:[],...r.filter(F=>F.count>0).map(F=>({id:`team:${F.key}`,name:F.name,team:{count:F.count}})),...j.map(F=>({id:F.id,name:F.name,bot:F}))];return Ut(S,_.query)},[_,O,j,r]),G=H.length>0,R=an(G);a.useEffect(()=>K(0),[_?.start,_?.query]),a.useEffect(()=>{G&&x.current?.querySelector(`[data-mention-index="${A}"]`)?.scrollIntoView({block:"nearest"})},[A,G]);const q=S=>{if(!_)return;const F=`${M.slice(0,_.start)}@${S.name} ${M.slice(w)}`,ee=_.start+S.name.length+2;h(F),b(ee),U(_.start),requestAnimationFrame(()=>{g.current?.focus(),g.current?.setSelectionRange(ee,ee)})},m=M.trim().length>0&&B.botIds.length>0,z=async()=>{if(!m)return;const S=M.trim(),F=B;h(""),b(0),U(null);const ee=L.chief?await te("/api/stop-line",{method:"POST",body:JSON.stringify({text:F.words})}).then(re=>re.stop===!0,()=>null):!1,ie=ee===null?{botIds:F.botIds}:ct(F,j,ee);for(const re of ie.botIds)i({type:"send",botId:re,text:ie.text||S,sendId:$e()});d(ie.botIds),y({botIds:ie.botIds,expanded:!1,...ie.chief?{chiefId:ie.chief.id}:{}})},N=v?.chiefId?j.find(S=>S.id===v.chiefId):void 0,$=(v?.botIds??[]).filter(S=>S!==N?.id).flatMap(S=>j.find(F=>F.id===S)??[]),T=Xn($.map(S=>S.name)),P=v?.expanded?$:$.slice(0,T.names.length),se=M.trim()&&!B.botIds.length?s("mapComposer.tagHint"):L.chief?s("mapComposer.willSendViaChief",{name:L.chief.name}):null;return e.jsx(e.Fragment,{children:e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-5 z-30 flex justify-center px-4",children:e.jsxs("div",{className:"pointer-events-auto w-full max-w-[620px]",children:[v&&(N||$.length>0)&&e.jsxs("p",{role:"status",className:"mb-2 flex flex-wrap items-center gap-x-1 gap-y-0.5 rounded-xl bg-panel/95 px-3 py-1.5 text-[12px] text-ink-secondary shadow-sm ring-1 ring-hairline/50",children:[N&&e.jsxs("span",{children:[s("mapComposer.sentViaChief",{name:N.name}),$.length>0?" ·":""]}),$.length>0&&e.jsx("span",{children:s("mapComposer.sentTo")}),P.map((S,F)=>e.jsxs("span",{children:[e.jsx("button",{className:"font-medium text-ink underline-offset-2 hover:underline",onClick:()=>tt(i,S,c),children:S.name}),F<P.length-1?",":""]},S.id)),!v.expanded&&T.more>0&&e.jsx("button",{className:"text-ink underline-offset-2 hover:underline",onClick:()=>y({...v,expanded:!0}),children:s("mapComposer.andMore",{count:T.more})}),e.jsx("button",{"aria-label":s("common.close"),className:"ml-auto rounded p-0.5 hover:bg-control",onClick:()=>y(null),children:e.jsx(Be,{size:12})})]}),e.jsxs("div",{className:"relative flex items-end gap-2 rounded-2xl bg-composer px-3 py-2 shadow-lg ring-1 ring-composer-ring",children:[e.jsx(qt,{listRef:x,motion:R,choices:H,highlight:A,everyoneCount:j.length,onPick:q,onHighlight:K}),e.jsx(Ft,{inputRef:g,peers:[...j,...r.map(S=>({name:S.name}))],everyone:!0,"aria-label":s("mapComposer.label"),placeholder:s("mapComposer.placeholder"),dir:"auto",rows:1,value:M,className:"block max-h-[9rem] min-h-6 w-full resize-none overflow-y-auto bg-transparent px-1 py-1 text-[15px] leading-6 placeholder:text-ink-secondary focus:outline-none",onChange:S=>{h(S.target.value),b(S.target.selectionStart??S.target.value.length),U(null)},onKeyUp:S=>b(S.target.selectionStart??0),onClick:S=>b(S.target.selectionStart??0),onKeyDown:S=>{if(!Xt(S.nativeEvent)){if(G){if(S.key==="ArrowDown"||S.key==="ArrowUp"){S.preventDefault(),K(F=>(F+(S.key==="ArrowDown"?1:-1)+H.length)%H.length);return}if(S.key==="Enter"||S.key==="Tab"){S.preventDefault(),q(H[A]);return}if(S.key==="Escape"){S.preventDefault(),S.stopPropagation(),U(_?.start??null);return}}Yt(S.nativeEvent,I)&&(S.preventDefault(),z())}}}),e.jsx("button",{onClick:()=>{z()},disabled:!m,"aria-label":s("mapComposer.send"),title:m?L.botIds.length===1?s("mapComposer.sendToOne"):s("mapComposer.sendTo",{count:L.botIds.length}):s("mapComposer.tagHint"),className:ne("mb-0.5 flex size-8 shrink-0 items-center justify-center rounded-full text-white transition-opacity",m?"bg-accent hover:brightness-110":"bg-ink-secondary/30"),children:e.jsx(Jt,{size:16})})]}),(se||B.botIds.length>0)&&e.jsx("p",{className:"mt-1.5 px-3 text-[11px] text-ink-secondary",children:se??(L.botIds.length===1?s("mapComposer.willSendOne"):s("mapComposer.willSend",{count:L.botIds.length}))})]})})})}function Jn({edge:n,bots:r}){const{state:l,dispatch:d}=Ne(),i=Qe(),c=r.find(x=>x.id===n.sourceBotId),I=r.find(x=>x.id===n.targetBotId);if(!c||!I)return null;const g=n.state!=="connected";return e.jsxs("button",{onClick:()=>{!n.groupId&&n.threadId?nn(d,{botId:I.id,threadId:n.threadId},l,i):n.groupId?d({type:"select",id:n.groupId}):tt(d,I,i)},className:"flex w-full items-center gap-3 rounded-xl border border-hairline/40 bg-card px-3 py-2.5 text-left transition hover:bg-raised/50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx("span",{className:"truncate text-[13px] font-medium text-ink",children:c.name}),e.jsx(ft,{size:13,className:ne("shrink-0",g?"text-accent":"text-ink-secondary")}),e.jsx("span",{className:"truncate text-[13px] font-medium text-ink",children:I.name})]}),n.reason&&e.jsx("span",{className:"max-w-[220px] truncate text-[12px] text-ink-secondary",children:n.reason}),e.jsx("span",{className:ne("rounded-full px-2 py-0.5 text-[11px] font-medium",n.state==="running"?"bg-success/15 text-success":n.state==="queued"?"bg-warning/15 text-warning":"bg-control text-ink-secondary"),children:n.state==="running"?s("canvas.edge.running"):n.state==="queued"?s("canvas.edge.queued"):n.lastAt?jt(n.lastAt):s("canvas.edge.connected")})]})}function Vn({section:n,label:r,onClose:l}){const d=a.useRef(null),i=a.useRef(null),c=a.useRef(l),I=a.useRef(!1),g=a.useRef(!1),[x,M]=a.useState(""),[h,w]=a.useState(""),[b,O]=a.useState(24e3),[U,A]=a.useState(null),[K,v]=a.useState(!0),[y,j]=a.useState(!1),[B,L]=a.useState(null),Y=x!==h,_=a.useMemo(()=>new TextEncoder().encode(x).byteLength,[x]);c.current=l,I.current=y,g.current=Y;const H=a.useCallback(()=>{I.current||g.current&&!window.confirm(s("team.instructionsDiscard"))||c.current()},[]);a.useEffect(()=>{const R=document.activeElement instanceof HTMLElement?document.activeElement:null;d.current?.focus();const q=m=>{if(m.key==="Escape"&&!I.current){m.preventDefault(),H();return}if(m.key!=="Tab")return;const z=d.current;if(!z)return;const N=[...z.querySelectorAll('button:not([disabled]), textarea:not([disabled]), input:not([disabled]), [href], [tabindex]:not([tabindex="-1"])')];if(N.length===0){m.preventDefault(),z.focus();return}const $=N[0],T=N[N.length-1];m.shiftKey&&document.activeElement===$?(m.preventDefault(),T.focus()):!m.shiftKey&&document.activeElement===T&&(m.preventDefault(),$.focus())};return window.addEventListener("keydown",q),()=>{window.removeEventListener("keydown",q),R?.focus()}},[H]),a.useEffect(()=>{let R=!1;return v(!0),L(null),te(`/api/section-context?section=${encodeURIComponent(n)}`).then(q=>{R||(M(q.text),w(q.text),A(q.updatedAt),O(q.maxBytes),window.setTimeout(()=>i.current?.focus(),0))}).catch(q=>{R||L(q instanceof Error?q.message:String(q))}).finally(()=>{R||v(!1)}),()=>{R=!0}},[n]);const G=async()=>{if(!(_>b)){j(!0),L(null);try{const R=await te(`/api/section-context?section=${encodeURIComponent(n)}`,{method:"PUT",body:JSON.stringify({text:x})});w(R.text),M(R.text),A(R.updatedAt),O(R.maxBytes)}catch(R){L(R instanceof Error?R.message:String(R))}finally{j(!1)}}};return et.createPortal(e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/55 p-4 sm:p-6",onMouseDown:R=>R.target===R.currentTarget&&H(),children:e.jsxs("div",{ref:d,role:"dialog","aria-modal":"true","aria-labelledby":"section-context-title",tabIndex:-1,className:"animate-pop-in flex max-h-[min(680px,calc(100dvh-2rem))] w-full max-w-[680px] flex-col overflow-hidden rounded-2xl border border-hairline/50 bg-panel shadow-2xl shadow-black/50 outline-none",children:[e.jsxs("header",{className:"flex items-start justify-between gap-4 border-b border-hairline/40 px-6 pb-4 pt-6 sm:px-8 sm:pt-7",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ut,{size:19,className:"text-accent"}),e.jsx("h2",{id:"section-context-title",className:"text-[20px] font-semibold tracking-[-0.01em] text-ink",children:s("team.instructionsTitle",{name:r})})]}),e.jsx("p",{className:"mt-1.5 max-w-[520px] text-[13px] leading-relaxed text-ink-secondary",children:s("team.instructionsHint")})]}),e.jsx("button",{onClick:H,disabled:y,"aria-label":s("team.instructionsClose"),className:"flex size-9 shrink-0 items-center justify-center rounded-lg text-ink-secondary hover:bg-raised hover:text-ink disabled:opacity-40",children:e.jsx(Be,{size:19})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 py-5 sm:px-8",children:[K?e.jsx("div",{className:"flex min-h-[260px] items-center justify-center text-ink-secondary",children:e.jsx(Re,{size:20,className:"animate-spin","aria-label":s("team.instructionsLoading")})}):e.jsxs(e.Fragment,{children:[e.jsx("textarea",{ref:i,value:x,onChange:R=>M(R.target.value),placeholder:s("team.instructionsPlaceholder"),"aria-label":s("team.instructionsTitle",{name:r}),className:"min-h-[280px] w-full resize-y rounded-xl border border-hairline/60 bg-inset px-4 py-3 font-mono text-[13px] leading-relaxed text-ink outline-none placeholder:text-ink-tertiary focus:border-accent/50"}),e.jsxs("div",{className:"mt-2 flex items-start justify-between gap-4 text-[12px] text-ink-secondary",children:[e.jsxs("span",{children:[s("team.instructionsFactHint")," ",U?` ${s("team.instructionsLastSaved",{time:new Date(U).toLocaleString(Ee())})}`:""]}),e.jsx("span",{className:ne("shrink-0 tabular-nums",_>b&&"text-danger"),children:s("team.instructionsBytes",{bytes:_.toLocaleString(Ee()),limit:b.toLocaleString(Ee())})})]})]}),B&&e.jsx("div",{className:"mt-3 rounded-lg border border-danger/30 bg-danger/10 px-3 py-2 text-[12px] text-danger",children:B})]}),e.jsxs("footer",{className:"flex items-center justify-end gap-2 border-t border-hairline/40 px-6 py-4 sm:px-8",children:[e.jsx("button",{onClick:H,disabled:y,className:"rounded-lg px-3.5 py-2 text-[13px] text-ink-secondary hover:bg-raised hover:text-ink disabled:opacity-40",children:s("common.cancel")}),e.jsxs("button",{onClick:()=>{G()},disabled:K||y||!Y||_>b,className:"flex items-center gap-2 rounded-lg bg-accent px-4 py-2 text-[13px] font-medium text-white hover:brightness-110 disabled:opacity-40",children:[y?e.jsx(Re,{size:14,className:"animate-spin"}):e.jsx(un,{size:14}),s("team.instructionsSave")]})]})]})}),document.body)}const Gn=1400;function ss(){const{state:n,dispatch:r}=Ne(),{dragProps:l}=St(),d=window.ogb?.remoteClient?.active===!0,i=xt(),c=Vt(),I=Gt()==="people"&&i!==null,[g,x]=a.useState(mn),[M,h]=a.useState(null),[w,b]=a.useState(null),[O,U]=a.useState(null),[A,K]=a.useState(null),[v,y]=a.useState(null),[j,B]=a.useState(null),[L,Y]=a.useState(!1),[_,H]=a.useState(0),[G,R]=a.useState([]),[q,m]=a.useState(null),z=a.useCallback(()=>m(null),[]),[N,$]=a.useState(null),T=a.useRef(N);T.current=N,a.useEffect(()=>()=>T.current?.resolve(!1),[]);const P=a.useMemo(()=>n.bots.filter(f=>!f.hidden),[n.bots]),se=a.useMemo(()=>{const f=[...new Set([...n.sections??[],...n.groups.flatMap(k=>k.section?[k.section]:[])])],o=k=>k===""?-1:f.includes(k)?f.indexOf(k):f.length;return pn(P,f).sort((k,J)=>o(k.key)-o(J.key))},[P,n.sections,n.groups]),S=a.useMemo(()=>fn(P,g),[P,g]),F=P.some(f=>f.computer==="cloud"&&f.cloudBackend!=="vps")||G.some(f=>f.section!==null),{show:ee,loaded:ie,choose:re}=An(F),ue=En(!d&&ie&&ee),[de,fe]=a.useState([]),[me,he]=a.useState(null),ge=a.useRef(void 0),ve=a.useCallback(f=>{window.clearTimeout(ge.current),he(o=>({botIds:f,key:(o?.key??0)+1})),ge.current=window.setTimeout(()=>he(null),Gn)},[]);a.useEffect(()=>()=>window.clearTimeout(ge.current),[]);const Se=a.useMemo(()=>se.map(f=>({key:f.key,name:f.name,count:f.chiefs.length+f.members.length})),[se]),oe=a.useCallback(async(f=!1)=>{try{x(await te("/api/team-map",f?{background:f}:void 0)),b(null)}catch(o){b(o instanceof Error?o.message:String(o))}},[]);a.useEffect(()=>{oe();const f=window.setInterval(()=>{document.visibilityState==="visible"&&oe(!0)},3e3);return()=>window.clearInterval(f)},[oe]);const pe=async(f,o)=>{h(null);try{const k=await te("/api/sidebar-sections",{method:"POST",body:JSON.stringify({name:o,botIds:[f.id]})});r({type:"sections",sections:k.sections});for(const J of k.bots)r({type:"botPatched",bot:J})}catch(k){throw h(k instanceof Error?k.message:String(k)),k}},be=(f,o)=>new Promise(k=>{T.current?.resolve(!1),$({bot:f,destination:o,resolve:k})}),ce=a.useCallback(()=>{T.current?.resolve(!1),$(null)},[]);return e.jsxs("main",{className:"flex min-w-0 flex-1 flex-col overflow-hidden bg-app text-ink",children:[e.jsxs("header",{...l,className:"flex shrink-0 flex-wrap items-center justify-between gap-3 border-b border-hairline/40 px-6 py-4 max-md:pl-12",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(Wt,{size:18,className:"text-ink-secondary"}),e.jsx("h1",{className:"text-[17px] font-semibold",children:s("canvas.title")}),e.jsx("span",{className:"ml-1 text-[11px] text-ink-secondary",children:hn(P.length)})]}),e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:s("canvas.description")})]}),i&&e.jsx(Qt,{}),!d&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>re(!ee),"aria-pressed":ee,title:s("canvas.showComputersHint"),className:ne("flex items-center gap-2 rounded-lg border px-3 py-2 text-[12px] font-medium transition-colors",ee?"border-accent/40 bg-accent/10 text-ink":"border-hairline/60 bg-panel text-ink-secondary hover:bg-control hover:text-ink"),children:[e.jsx("span",{"aria-hidden":!0,className:ne("relative h-4 w-7 shrink-0 rounded-full transition-colors",ee?"bg-accent":"bg-control"),children:e.jsx("span",{className:ne("absolute top-0.5 size-3 rounded-full bg-white shadow-sm transition-[left]",ee?"left-3.5":"left-0.5")})}),s("canvas.showComputers")]}),e.jsx("button",{onClick:()=>Y(f=>!f),"aria-label":s("canvas.computers"),"aria-expanded":L,className:"rounded-lg p-2 text-ink-secondary hover:bg-control hover:text-ink",children:e.jsx(Oe,{size:17})}),c!==!1&&e.jsxs("details",{className:"relative",onBlur:f=>{f.currentTarget.contains(f.relatedTarget)||f.currentTarget.removeAttribute("open")},onKeyDown:f=>{f.key==="Escape"&&(f.currentTarget.removeAttribute("open"),f.currentTarget.querySelector("summary")?.focus())},children:[e.jsxs("summary",{"aria-label":s("canvas.addToMap"),className:"flex cursor-pointer list-none items-center gap-1.5 rounded-lg border border-hairline/60 bg-panel px-3 py-2 text-[12px] font-medium hover:bg-control [&::-webkit-details-marker]:hidden",children:[e.jsx(Ke,{size:14})," ",s("common.add")]}),e.jsxs("div",{className:"absolute right-0 top-full z-40 mt-2 w-52 rounded-xl border border-hairline/60 bg-panel p-1.5 shadow-xl",onClick:f=>{const o=f.currentTarget.closest("details");o?.querySelector("summary")?.focus(),o?.removeAttribute("open")},children:[e.jsxs("button",{className:"flex w-full items-center gap-2 rounded-lg px-3 py-2.5 text-left text-[12px] hover:bg-control",onClick:()=>y({}),children:[e.jsx(dt,{size:14}),s("team.create")]}),e.jsxs("button",{className:"flex w-full items-center gap-2 rounded-lg px-3 py-2.5 text-left text-[12px] hover:bg-control",onClick:()=>{Y(!0),H(f=>f+1)},children:[e.jsx(Je,{size:14}),s("canvas.cloudComputer")]}),Zt("vm",n.config)&&e.jsxs("button",{className:"flex w-full items-center gap-2 rounded-lg px-3 py-2.5 text-left text-[12px] hover:bg-control",onClick:()=>r({type:"toggleAppSettings",section:"computer",open:!0}),children:[e.jsx(Oe,{size:14}),s("canvas.localVm")]})]})]})]})]}),(M||w)&&e.jsxs("div",{role:"alert",className:"flex shrink-0 items-center justify-between gap-3 border-b border-danger/20 bg-danger/10 px-6 py-2 text-[12px] text-danger",children:[M||w,e.jsx("button",{"aria-label":s("common.close"),className:"rounded p-1 hover:bg-danger/10",onClick:()=>{h(null),b(null)},children:e.jsx(Be,{size:14})})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-1",children:[e.jsxs("div",{className:"relative flex min-h-0 min-w-0 flex-1",children:[I?e.jsx(en,{bots:P}):e.jsx($n,{sections:se,canManage:!d&&c!==!1,onMove:be,taggedBotIds:de,sent:me,bottomInset:P.length?96:0,connectedBotIds:n.settingsOpen?S.flatMap(f=>f.sourceBotId===n.selectedId?[f.targetBotId]:f.targetBotId===n.selectedId?[f.sourceBotId]:[]):[],onComputer:f=>Ye(r,"access",{botId:f.id}),computers:ee&&ie&&!d?ue.computers:void 0,computerFrames:ue.frames,onOpenComputer:f=>f.kind==="team"?Y(!0):r({type:"toggleComputer",open:!0,botId:f.id}),teamComputers:Object.fromEntries(G.filter(f=>f.section!==null).map(f=>[f.section,{name:f.name,state:f.state}])),onTeamComputer:()=>Y(!0),onComputerDrop:(f,o)=>{d||(Y(!0),m({id:f,section:o}))},onInstructions:(f,o)=>U({section:f,label:o}),onMemory:(f,o)=>K({section:f,label:o}),onEditTeam:(f,o)=>y({section:f,rename:o}),onDeleteTeam:B,isEmpty:f=>![...n.bots,...n.groups].some(o=>o.section?.trim()===f)}),P.length>0&&e.jsx(Yn,{bots:P,teams:Se,onTagged:fe,onSent:ve})]}),!d&&e.jsx(Un,{open:L,createRequest:_,drop:q,sections:se,onClose:()=>Y(!1),onDropHandled:z,onChange:R})]}),S.length>0&&e.jsxs("details",{className:"shrink-0 border-t border-hairline/40 bg-panel px-6 py-3",children:[e.jsxs("summary",{className:"cursor-pointer text-[12px] text-ink-secondary",children:[s("canvas.whoHandsOn")," · ",S.length]}),e.jsx("div",{className:"mt-3 max-h-48 space-y-2 overflow-y-auto",children:S.slice(0,12).map(f=>e.jsx(Jn,{edge:f,bots:P},`${f.sourceBotId}:${f.targetBotId}`))})]}),O&&e.jsx(Vn,{section:O.section,label:O.label,onClose:()=>U(null)}),v&&e.jsx(tn,{...v,onClose:()=>y(null)}),A&&e.jsx(_n,{...A,onClose:()=>K(null)},A.section),e.jsx(Ve,{open:N!==null,tone:"neutral",title:s("canvas.moveConfirmTitle",{name:N?.bot.name??s("canvas.bot"),team:N?.destination||s("settings.section.general")}),body:s("canvas.moveConfirmBody"),confirmLabel:s("canvas.moveConfirm"),onCancel:ce,onConfirm:()=>{const f=T.current;f&&($(null),pe(f.bot,f.destination).then(()=>f.resolve(!0),()=>f.resolve(!1)))}}),e.jsx(Ve,{open:j!==null,title:s("team.deleteTitle",{name:j??""}),body:s("team.deleteKeepBotsDescription"),confirmLabel:s("team.delete"),onCancel:()=>B(null),onConfirm:()=>{const f=j;B(null),f&&te(`/api/sidebar-sections?section=${encodeURIComponent(f)}`,{method:"DELETE"}).then(({sections:o})=>r({type:"sections",sections:o})).catch(o=>h(o instanceof Error?o.message:String(o)))}})]})}export{Jn as EdgeRow,Vn as SectionContextDialog,ss as TeamMapPage};
|