limixbot 0.3.148 → 0.3.150
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-F9d7zvpT.js → ActivityPanel-DbYr6aYG.js} +1 -1
- package/dist/assets/{App-BgdjoCaG.js → App-DMdy7cvM.js} +112 -112
- package/dist/assets/{AppEventEditor-CbDxf3ao.js → AppEventEditor-BnXvgtnu.js} +1 -1
- package/dist/assets/{BotSettingsDialog-B-yEj47w.js → BotSettingsDialog-DgDog5Vz.js} +4 -4
- package/dist/assets/{BrowserPanel-BDo5f1Jm.js → BrowserPanel-CfxLa87P.js} +2 -2
- package/dist/assets/{BrowserProfilesManager-BAzvLmnn.js → BrowserProfilesManager-h9vTMyYV.js} +1 -1
- package/dist/assets/CloudAddDialog-BarUVj7I.js +1 -0
- package/dist/assets/{ComputerFilesPane-Bp9DOa3Y.js → ComputerFilesPane-6jyzomuX.js} +1 -1
- package/dist/assets/ComputerPanel-DSFxuBSX.js +2 -0
- package/dist/assets/{DataPanel-C8nr8Ajt.js → DataPanel-YetCcoMW.js} +1 -1
- package/dist/assets/{DesktopViewer-uyCSG2he.js → DesktopViewer-BXR4GFU3.js} +1 -1
- package/dist/assets/{GrokMoveDialog-d8kG3z3l.js → GrokMoveDialog-DjSRpKew.js} +1 -1
- package/dist/assets/{InspectorPanel-D0n9O2Sh.js → InspectorPanel-CddEUpZ6.js} +1 -1
- package/dist/assets/{KeyboardShortcutsModal-DVhBpOOB.js → KeyboardShortcutsModal-Dnk1-1wi.js} +1 -1
- package/dist/assets/{KnowledgePanel-BifuCuZi.js → KnowledgePanel-DD271XCa.js} +1 -1
- package/dist/assets/LimixResizeHandles-CY1lhGls.js +1 -0
- package/dist/assets/{LiveDesktop-CDBbQAjn.js → LiveDesktop-BkeilR0x.js} +1 -1
- package/dist/assets/{LocalVmWorkspace-D_NB8bZ5.js → LocalVmWorkspace-C-ZV6wNM.js} +1 -1
- package/dist/assets/{MacLocalControl-DU5oNvcq.js → MacLocalControl-WmgLxL2q.js} +1 -1
- package/dist/assets/{MarkdownFilePreview-DfMNn9qG.js → MarkdownFilePreview-xo7sq3Gv.js} +1 -1
- package/dist/assets/{MenuMotion-B0aZnuh_.js → MenuMotion-DG3_zhAW.js} +1 -1
- package/dist/assets/{NewBotDialog-JyiygOxT.js → NewBotDialog-CdRjfcXW.js} +1 -1
- package/dist/assets/PhoneAppDialog--fCFY0LE.js +1 -0
- package/dist/assets/PlacesRail-DxAWLcZN.js +1 -0
- package/dist/assets/{PluginsPanel-sPLPWkdl.js → PluginsPanel-0vdY_sy3.js} +5 -5
- package/dist/assets/{ProIntroduction-Cq3nswpJ.js → ProIntroduction-DqqHWmYG.js} +1 -1
- package/dist/assets/{RemoteAgentSettingsPanel-DuYzU2nQ.js → RemoteAgentSettingsPanel-Bpx08vUp.js} +1 -1
- package/dist/assets/{RoomPanel-vXOP5sr5.js → RoomPanel-DmHDsBy5.js} +1 -1
- package/dist/assets/{RoutinesPage-CY3YGT8X.js → RoutinesPage-CWVJMviD.js} +3 -3
- package/dist/assets/SettingsModal-LStDRjh3.js +20 -0
- package/dist/assets/{ShareTeamDialog-DVidCcmp.js → ShareTeamDialog-Cu1bC5ch.js} +1 -1
- package/dist/assets/{SignedInSites-RCz33HaF.js → SignedInSites-DxaWkOBZ.js} +1 -1
- package/dist/assets/{TeamLibraryPanel-DlCtaa3S.js → TeamLibraryPanel-CALrJ95_.js} +2 -2
- package/dist/assets/TeamMapPage-CckHySu4.js +1 -0
- package/dist/assets/{TriggersPage-Bngst1v9.js → TriggersPage-_aLKe0p7.js} +1 -1
- package/dist/assets/VisibilitySection-Bw7GQ8wR.js +22 -0
- package/dist/assets/{WebhookTrigger-DEoEYgVK.js → WebhookTrigger-BDNVmmb9.js} +1 -1
- package/dist/assets/WorksOnGrid-J81hjFzK.js +1 -0
- package/dist/assets/{abnfDiagram-YUKMZFIV-DDXPrZzl.js → abnfDiagram-YUKMZFIV-Bgfbq9qO.js} +1 -1
- package/dist/assets/{activity-BlL5ycb5.js → activity-CTL6M7Nw.js} +1 -1
- package/dist/assets/{architectureDiagram-47P4ROYG-BiqBgMDV.js → architectureDiagram-47P4ROYG-O3f9TC9A.js} +1 -1
- package/dist/assets/{blockDiagram-E7TT5TSB-vc1neoFp.js → blockDiagram-E7TT5TSB-ynUBtTdY.js} +1 -1
- package/dist/assets/{c4Diagram-CRA5TL53-CQbtBKOv.js → c4Diagram-CRA5TL53-DPsm_A9P.js} +1 -1
- package/dist/assets/{calendar-days-_dtxyR4U.js → calendar-days-BMRd2qAl.js} +1 -1
- package/dist/assets/channel-CDEIRnOe.js +1 -0
- package/dist/assets/{chunk-2Q5K7J3B-Dq_aCCIt.js → chunk-2Q5K7J3B-DUNGHp3y.js} +1 -1
- package/dist/assets/{chunk-5VM5RSS4-EcX_ZXzF.js → chunk-5VM5RSS4-D9denHw1.js} +1 -1
- package/dist/assets/{chunk-7TKQ45FW-BA7CgKU2.js → chunk-7TKQ45FW-Dey4MHBQ.js} +1 -1
- package/dist/assets/{chunk-AW2ZBBNX-DkvVwaph.js → chunk-AW2ZBBNX-CFGfN9SB.js} +1 -1
- package/dist/assets/{chunk-FVRAUYC3-CdyGRg6v.js → chunk-FVRAUYC3-BUtXxxy9.js} +2 -2
- package/dist/assets/{chunk-HTAEGDNF-CS-veEVV.js → chunk-HTAEGDNF-Cql4WK8l.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-BiUYpinX.js → chunk-JWPE2WC7-CYf-wOeu.js} +1 -1
- package/dist/assets/{chunk-KQW6MTUR-DDPkIuwB.js → chunk-KQW6MTUR-W-3blh4U.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY-C4YyKEem.js → chunk-XXDRQBXY-VmWvo27u.js} +1 -1
- package/dist/assets/{classDiagram-v2-K4WV4PDN-BjmVbVHi.js → classDiagram-v2-K4WV4PDN-BLqM7WG5.js} +1 -1
- package/dist/assets/{coins-Cu3qn-3t.js → coins-C-LzbiEQ.js} +1 -1
- package/dist/assets/{core-DK9jR4up.js → core-CMPKx_ai.js} +1 -1
- package/dist/assets/{cose-bilkent-JH36ORCC-Bra0B-5z.js → cose-bilkent-JH36ORCC-BPybX2kh.js} +1 -1
- package/dist/assets/{cynefin-EF2NZ3EQ-BRMKNbnx.js → cynefin-EF2NZ3EQ-Bi_Q7Ytj.js} +1 -1
- package/dist/assets/{cynefinDiagram-3GCD6N5R-DMhNix9A.js → cynefinDiagram-3GCD6N5R-Dv7Kek2q.js} +1 -1
- package/dist/assets/{dagre-W4DXFKR2-BWwdFKCx.js → dagre-W4DXFKR2-D3_ZNQw-.js} +1 -1
- package/dist/assets/{diagram-2UJZ2QOL-D_4J-D-V.js → diagram-2UJZ2QOL-CFngbRxv.js} +1 -1
- package/dist/assets/{diagram-OVF4WLC6-CQ4l30Dm.js → diagram-OVF4WLC6-Py92D3Eq.js} +1 -1
- package/dist/assets/{diagram-PFPMY2P6-D3W2IEHX.js → diagram-PFPMY2P6-Bj2AziyO.js} +1 -1
- package/dist/assets/{diagram-UMYRVEAY-C9cpNhET.js → diagram-UMYRVEAY-TFRq5xde.js} +1 -1
- package/dist/assets/{diagram-YEKJPTXX-DIyquCXt.js → diagram-YEKJPTXX-Djlbu2mG.js} +1 -1
- package/dist/assets/{diagram-ZIFT7M5P-CO6216kK.js → diagram-ZIFT7M5P-6WlLtaDx.js} +1 -1
- package/dist/assets/{ebnfDiagram-VR2GEFS7-BeHXJPN4.js → ebnfDiagram-VR2GEFS7-CqxlFgJ9.js} +1 -1
- package/dist/assets/{elk-IJKZMXRS-BdT_tK3j.js → elk-IJKZMXRS-DDdM00S4.js} +1 -1
- package/dist/assets/{erDiagram-O2IAPWRE-Cz_TiHab.js → erDiagram-O2IAPWRE-DlWtXesJ.js} +1 -1
- package/dist/assets/{file-up-flw1aUka.js → file-up-Dqe3RNVz.js} +1 -1
- package/dist/assets/{flowDiagram-OXPTDLAJ-BXLr0anm.js → flowDiagram-OXPTDLAJ-nwNleALg.js} +1 -1
- package/dist/assets/{ganttDiagram-R7TSEDQI-C37QIpaR.js → ganttDiagram-R7TSEDQI-Cs_gbPNT.js} +1 -1
- package/dist/assets/{gitGraphDiagram-XJZIOB7I-Cs8fTfJZ.js → gitGraphDiagram-XJZIOB7I-C2NPrP0G.js} +1 -1
- package/dist/assets/{import-name-C3ytLH-g.js → import-name-UStBgXlp.js} +1 -1
- package/dist/assets/{index-BQM4L4RU.js → index-C3QkWpbg.js} +3 -3
- package/dist/assets/{index-ZJsaQ9Ga.js → index-D8Y6bPwt.js} +1 -1
- package/dist/assets/{infoDiagram-5W2HQ5XZ-BpliNVPR.js → infoDiagram-5W2HQ5XZ-CLwf4Y1H.js} +1 -1
- package/dist/assets/{ishikawaDiagram-K3B6WC7H-Dov7w4qz.js → ishikawaDiagram-K3B6WC7H-BzO0Dn0V.js} +1 -1
- package/dist/assets/{journeyDiagram-COXZFDF6-DoihiGaK.js → journeyDiagram-COXZFDF6-DRbYHF6c.js} +1 -1
- package/dist/assets/{kanban-definition-P3RFRI5V-D_gNx8dG.js → kanban-definition-P3RFRI5V-BdB-0mlZ.js} +1 -1
- package/dist/assets/{mermaid.core-BYPxVPn-.js → mermaid.core-BQDLCsjv.js} +4 -4
- package/dist/assets/{mindmap-definition-LZFPQGKD-wH2aKxFy.js → mindmap-definition-LZFPQGKD-BA6ze6xb.js} +1 -1
- package/dist/assets/{minimize-sGQL0Xsy.js → minimize--MbSo_De.js} +1 -1
- package/dist/assets/{monitor-zecPzfR5.js → monitor-CHGFGy9c.js} +1 -1
- package/dist/assets/{new-bot-CG838Ldv.js → new-bot-CstvBWIB.js} +2 -2
- package/dist/assets/org-library-iMfdBShq.js +1 -0
- package/dist/assets/{package-format-DQXSLHZJ.js → package-format-BZvL-kqt.js} +1 -1
- package/dist/assets/{pegDiagram-BGZESJAR-B7RTZksQ.js → pegDiagram-BGZESJAR-CMJU1HyF.js} +1 -1
- package/dist/assets/{pieDiagram-CAPJLFHJ-B5mPB7O-.js → pieDiagram-CAPJLFHJ-B6sZCFvm.js} +1 -1
- package/dist/assets/{pt-br-D-uO3BNY.js → pt-br-DW318t9V.js} +1 -1
- package/dist/assets/{quadrantDiagram-GDMTTRAM-CZqo7j7U.js → quadrantDiagram-GDMTTRAM-DuW0EnlR.js} +1 -1
- package/dist/assets/{rail-Ok0cs7cA.js → rail-BLp5VtOY.js} +1 -1
- package/dist/assets/{railroadDiagram-SM67HX2B-MFpfIts_.js → railroadDiagram-SM67HX2B-DghH6KW5.js} +1 -1
- package/dist/assets/{remote-desktop-panel-D-0l80ko.js → remote-desktop-panel-Cv5hyn-6.js} +1 -1
- package/dist/assets/{requirementDiagram-X7JNWC4A-CJ49gC_q.js → requirementDiagram-X7JNWC4A-CDOIsz5H.js} +1 -1
- package/dist/assets/{sankeyDiagram-UM26HJRW-DxpTSw3D.js → sankeyDiagram-UM26HJRW-Dgw5A7WO.js} +1 -1
- package/dist/assets/{sequenceDiagram-ZO4K6R2Y-XEyCx2Ue.js → sequenceDiagram-ZO4K6R2Y-c7yMm19a.js} +1 -1
- package/dist/assets/{sizeCapture-INFHLROL-1Fx1tcNn.js → sizeCapture-INFHLROL-BI17YAUb.js} +1 -1
- package/dist/assets/{stateDiagram-v2-TBUQTH76-CwxyNDK4.js → stateDiagram-v2-TBUQTH76-BnVESwRu.js} +1 -1
- package/dist/assets/{styles-DO3EUxm2.js → styles-CInetnea.js} +7 -7
- package/dist/assets/{swimlanes-N4OXWK64-BuwwuENy.js → swimlanes-N4OXWK64-_n5_yOn8.js} +1 -1
- package/dist/assets/swimlanesDiagram-K3J5GTZL-DcF6PiTM.js +8 -0
- package/dist/assets/{team-share-CL18_anr.js → team-share-PC0DJAzZ.js} +1 -1
- package/dist/assets/{timeline-definition-YOQAKGHF-CauwqKMA.js → timeline-definition-YOQAKGHF-DJ9vz4Mm.js} +1 -1
- package/dist/assets/{usecaseDiagram-VIAY4XPW-YZ3Cf2do.js → usecaseDiagram-VIAY4XPW-pKJIv5SC.js} +1 -1
- package/dist/assets/{vennDiagram-BLWOH2XV-CDX8i7ID.js → vennDiagram-BLWOH2XV-D3r45Ztx.js} +1 -1
- package/dist/assets/{wardleyDiagram-YMQ3BMBF-CCdRrEMh.js → wardleyDiagram-YMQ3BMBF-B7LVmnGA.js} +1 -1
- package/dist/assets/{xychartDiagram-TAQBALBS-Vz4NaN0U.js → xychartDiagram-TAQBALBS-BT4mbGTI.js} +1 -1
- package/dist/index.html +2 -2
- package/dist/rail.html +4 -4
- package/dist-server/drivers/agents-proxy.js +6 -6
- package/dist-server/drivers/pi-mcp-extension.ts +3 -3
- package/dist-server/index.js +155 -152
- package/dist-server/limixbot.js +117 -116
- package/dist-server/package.json +1 -1
- package/dist-server/pair-cli.js +117 -116
- package/dist-server/server/app-settings/host.js +1 -1
- package/dist-server/server/app-settings/registry-config.js +1 -1
- package/dist-server/server/app-settings/registry-window.js +4 -4
- package/dist-server/server/app-settings/registry.js +3 -3
- package/dist-server/server/checkpoints.js +3 -2
- package/dist-server/server/cli-setup.js +1 -1
- package/dist-server/server/cloud-health.js +1 -1
- package/dist-server/server/drivers/agents-app-settings-tool.js +1 -1
- package/dist-server/server/drivers/agents-catalog.js +1 -1
- package/dist-server/server/drivers/codex-shared-home.js +1 -1
- package/dist-server/server/drivers/codex.js +23 -9
- package/dist-server/server/environment.js +1 -1
- package/dist-server/server/first-reply-rescue.js +10 -3
- package/dist-server/server/fleet-cli.js +2 -2
- package/dist-server/server/fleet-client.js +2 -2
- package/dist-server/server/headless/client.js +2 -2
- package/dist-server/server/headless/commands.js +8 -8
- package/dist-server/server/headless/connect.js +1 -1
- package/dist-server/server/headless/context.js +4 -4
- package/dist-server/server/headless/engine.js +1 -1
- package/dist-server/server/headless/export.js +1 -1
- package/dist-server/server/headless/run.js +3 -3
- package/dist-server/server/headless/team-apply.js +4 -4
- package/dist-server/server/headless/token.js +6 -6
- package/dist-server/server/index.js +1 -1
- package/dist-server/server/lent-computers.js +2 -2
- package/dist-server/server/login-handoff.js +1 -1
- package/dist-server/server/phone-link.js +1 -1
- package/dist-server/server/phone-relay.js +1 -1
- package/dist-server/server/routes/status.js +1 -1
- package/dist-server/server/routes/x-research.js +1 -1
- package/dist-server/server/sentinel/cli.js +6 -6
- package/dist-server/server/themes/routes.js +1 -1
- package/dist-server/server/thread-events.js +2 -0
- package/dist-server/shared/theme.js +1 -1
- package/package.json +1 -1
- package/dist/assets/CloudAddDialog-LRUAy-7y.js +0 -1
- package/dist/assets/ComputerPanel-BocEhfqe.js +0 -2
- package/dist/assets/LimixResizeHandles-Co-9OI_G.js +0 -1
- package/dist/assets/PhoneAppDialog-DKYpfRuQ.js +0 -1
- package/dist/assets/PlacesRail-tZyNm-l3.js +0 -1
- package/dist/assets/SettingsModal-B-mRTq4f.js +0 -20
- package/dist/assets/TeamMapPage-CF4keIXL.js +0 -1
- package/dist/assets/VisibilitySection-PkgvzaLZ.js +0 -22
- package/dist/assets/WorksOnGrid-RadKXaob.js +0 -1
- package/dist/assets/channel-BzyEyDo_.js +0 -1
- package/dist/assets/org-library-ByuDQUvu.js +0 -1
- package/dist/assets/swimlanesDiagram-K3J5GTZL-CcmXEgRh.js +0 -8
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as We,t as s,r as a,j as e,a as ne,H as Qe,X as Be,d as kt,i as Ee,ae as jt}from"./styles-CInetnea.js";import{L as Re,W as wt,B as Ze,E as Ct,P as Ke,r as et,v as Nt,u as St}from"./PlacesRail-DxAWLcZN.js";import{j as te,l as It,X as Mt,u as Ne,aP as dt,bD as ut,du as mt,cX as Tt,T as pt,bU as ft,dv as Et,dw as At,dx as Rt,dy as Ot,cw as xt,bB as Bt,ag as Ye,bh as tt,dz as Dt,dA as zt,dB as Pt,w as ht,U as $e,_ as Je,dC as Lt,dD as Ge,dE as $t,dF as _t,b as Ht,dG as Kt,dH as Ut,dI as qt,dJ as Ft,dd as Xt,dK as Yt,dL as Jt,b_ as Gt,dM as Vt,cY as Wt,dN as Qt,$ as Zt,dO as en,dP as tn,dQ as nn}from"./App-DMdy7cvM.js";import{M as Oe}from"./monitor-CHGFGy9c.js";import{R as sn,a as an}from"./MenuMotion-DG3_zhAW.js";import"./index-C3QkWpbg.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 Ve=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 R=I(l.length)-He;let U=Math.max(R,Te+Me),A=d.length?M+Ve:x;if(r.team){const v=l.map((K,V)=>({bot:K,index:V})).filter(({bot:K})=>r.team.botIds.includes(K.id)),y=(v.length?v:l.map((K,V)=>({bot:K,index:V}))).map(({index:K})=>g(K)),j=y.length?(Math.min(...y)+Math.max(...y))/2:Te+je/2,O=A+Fe*(d.length?1.5:2),P=Math.max(Te,j-je/2),Y=O-Fe/2,_=P+je/2;w.push({id:r.team.id,x:O,y:P});for(const{bot:K,index:V}of v){const B={x:h[V].x+_e,y:g(V)};b.push({botId:K.id,computerId:r.team.id,points:[B,{x:Y,y:B.y},{x:Y,y:_},{x:O,y:_}]})}A=O+Ve,U=Math.max(U,P+je)}const H=[];if(i){const v=we+Xe/2,y=n.chiefs.length;H.push([{x:v,y:h[y-1].y+Me},{x:v,y:g(l.length-1)}]);for(let j=y;j<l.length;j++)H.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:H}}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((R,U)=>U%i===b).map(R=>R.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(R=>R.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,R,U,A,H)=>{if((g.current[b]?.at??-1/0)>=A)return;let v;try{v=URL.createObjectURL(Tn(R,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:H}},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,R=!1;const U=async()=>{if(!(b||R||document.visibilityState!=="visible")){R=!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 O of y.computers){const P=O.frame;P?.data&&w(O.id,P.data,P.mime,Mn(P.at,y.now,j),P.version)}}catch(v){b||I(v instanceof Error?v.message:String(v))}finally{R=!1}}};U();const A=window.setInterval(U,Cn),H=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),H()}},[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"},Dn=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:Ve,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 zn({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()),R=x.instances.find(A=>A.instanceId===n.modelSelection.instanceId),U=R?.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:R?e.jsx(Dt,{instance:R,size:13}):e.jsx(zt,{driverKind:"",size:13})}),e.jsx("span",{className:"truncate",children:U||s("canvas.defaultModel")})]})]})]})}const Pn=[];function Ln(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=Pn,computerFrames:R={},onOpenComputer:U,taggedBotIds:A=[],sent:H,bottomInset:v=0}){const{state:y}=Ne(),j=a.useRef(null),O=a.useRef(null),P=a.useRef(!1),Y=a.useRef(!1),_=a.useRef(null),[K,V]=a.useState({}),[B,q]=a.useState({}),[m,D]=a.useState({x:40,y:40,scale:1}),[N,$]=a.useState(null),[T,L]=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(B,t.key)?B[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,B]),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,K,pe),[n,K,pe]),ce=a.useRef({view:m,positions:K,tiles:be,selectedId:y.selectedId,settingsOpen:y.settingsOpen,bottomInset:v});ce.current={view:m,positions:K,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));V(C=>({...u,...C})),q(bn(localStorage.getItem(`${_.current}:bot-order`)))}catch{}}}).catch(()=>{}).finally(()=>{t&&me(!0)}),()=>{t=!1}},[]);const f=t=>{if(V(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(B,t)?B[t]:[],k=(t,p,u,C)=>{const E={...B,[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&&D(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(G=>G.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;D(G=>({...G,x:G.x+Q,y:G.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(),O.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)));D(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;D({...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||O.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(G=>[...G.chiefs,...G.members]).find(G=>G.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:K,moved:!1},ae=C===void 0?void 0:be.find(G=>G.key===C);O.current=E?{...Q,kind:"bot",bot:E}:ae?{...Q,kind:"team",key:ae.key,origin:ae}:{...Q,kind:"pan"},P.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(G=>G.key===(t.section?.trim()??""));if(!u)return null;const C=ke(t.chiefOfStaff?u.chiefs:u.members,o(u.key)),E=C.filter(G=>G.id!==t.id),Q=[...j.current?.querySelectorAll("[data-bot-id]")??[]],ae=E.findIndex(G=>{const z=Q.find(X=>X.dataset.botId===G.id)?.closest("article")?.getBoundingClientRect();return z?p<z.top+z.height/2:!1});return{section:u,lane:C,remaining:E,index:ae<0?E.length:ae}},bt=t=>{const p=O.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"&&D({...p.view,x:p.view.x+u,y:p.view.y+C}),p.kind==="team"&&V({...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()??"");L(ae||r?Q:null);const G=ae?st(p.bot,t.clientY):null,z=G?.remaining[G.index]??G?.remaining.at(-1);ee(G&&z?{botId:z.id,after:G.index===G.remaining.length}:null)}},Ce=(t,p=!1)=>{const u=O.current;if(!(!u||t&&u.id!==t.pointerId)){if(O.current=null,P.current=u.moved,window.setTimeout(()=>{P.current=!1},0),$(null),L(null),ee(null),j.current?.hasPointerCapture(u.id)&&j.current.releasePointerCapture(u.id),p){V(u.positions),D(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))}}},De=t=>{const p=j.current?.getBoundingClientRect();p&&D(at(m,Math.max(.3,Math.min(1.5,m.scale*t)),{x:p.width/2,y:p.height/2}))},ze=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=>ze.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},Pe=n.find(t=>t.key===T),Le=se!==null?s("canvas.assignComputer",{team:n.find(t=>t.key===se)?.name??se}):N&&Pe?(N.bot.section?.trim()??"")===Pe.key?s("canvas.arrangeBot",{name:N.bot.name,team:Pe.name}):s("canvas.moveBot",{name:N.bot.name,team:Pe.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:()=>{O.current&&!O.current.moved&&Ce(void 0,!0)},onLostPointerCapture:()=>{O.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)&&D(Q=>({...Q,x:Q.x+C,y:Q.y+E}))},onClickCapture:t=>{P.current&&(P.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(),D({...m,x:m.x+u.x,y:m.y+u.y})),(t.key==="+"||t.key==="=")&&(t.preventDefault(),De(1.2)),t.key==="-"&&(t.preventDefault(),De(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,G=z=>e.jsxs("div",{className:"relative",children:[F?.botId===z.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(zn,{bot:z,selected:y.selectedId===z.id&&y.settingsOpen,moving:N?.bot.id===z.id||ie===z.id,connected:w.includes(z.id),tagged:A.includes(z.id),sent:H?.botIds.includes(z.id)?H.key:void 0,onComputer:g,onArrange:fe?J:void 0})]},z.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:z=>{const X={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]}[z.key];if(!X)return;z.preventDefault(),z.stopPropagation();const ye=z.shiftKey?40:10;f({...K,[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:z=>{if(z.currentTarget.open){const X=j.current?.getBoundingClientRect();ge(X&&z.currentTarget.getBoundingClientRect().bottom>X.bottom-210*m.scale?t.key:null),j.current?.querySelectorAll("details[open]").forEach(ye=>{ye!==z.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:z=>{const X=z.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:Le}),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((z,X)=>e.jsx("path",{d:rt(z),fill:"none",strokeWidth:1.5,className:"stroke-ink-secondary/25"},`tree-${X}`)),C.links.map(z=>{const X=ze.get(z.botId)?.busy===!0;return e.jsx("path",{d:rt(z.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"},`${z.botId}:${z.computerId}`)})]}),C.cards.map(z=>{const X=ze.get(z.botId);return X?e.jsx("div",{className:"absolute",style:{left:z.x,top:z.y},children:G(X)},X.id):null}),C.monitors.map(z=>{const X=yt.get(z.id);if(!X)return null;const ye=X.botIds.flatMap(Ue=>ze.get(Ue)??[]);return e.jsx(Dn,{computer:X,bots:ye,x:z.x,y:z.y,frameUrl:Object.hasOwn(R,X.id)?R[X.id].url:void 0,state:vt(X),activity:Ln(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(G)}),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(G)}),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]}),Le&&e.jsx("p",{className:"mt-1 text-[10px] text-ink-secondary",children:Le})]}),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:Le??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:()=>De(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:()=>De(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,R]=a.useState(null),U=a.useRef(!1),A=a.useRef(0),[H,v]=a.useState(!1),[y,j]=a.useState({kind:"term",name:"",detail:""}),O=`section=${encodeURIComponent(n)}`,P=a.useCallback(async()=>{const m=++A.current;try{const D=await te(`/api/team-memory?${O}`);if(A.current!==m)return;c(D.entries),g(D.loadedIds),w(null)}catch(D){if(A.current!==m)return;w(D instanceof Error?D.message:String(D))}},[O]);a.useEffect(()=>(c(null),w(null),P(),()=>{A.current+=1}),[P]),a.useEffect(()=>{const m=document.activeElement instanceof HTMLElement?document.activeElement:null;d.current?.focus();const D=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],L=$[$.length-1];N.shiftKey&&document.activeElement===T?(N.preventDefault(),L.focus()):!N.shiftKey&&document.activeElement===L&&(N.preventDefault(),T.focus())}};return window.addEventListener("keydown",D),()=>{window.removeEventListener("keydown",D),m?.focus()}},[l]);const Y=async(m,D)=>{if(U.current)return!1;U.current=!0;const N=++A.current;R(m??"new"),w(null);try{const $=await D();return A.current!==N?!1:(c($.entries),R(null),$.loadedIds?g($.loadedIds):P(),!0)}catch($){return A.current===N&&w($ instanceof Error?$.message:String($)),!1}finally{U.current=!1,A.current===N&&R(null)}},_=m=>Y(m.id,()=>te(`/api/team-memory/${m.id}?${O}`,{method:"PATCH",body:JSON.stringify({accept:!0,expectedRevision:m.revision})})),K=m=>Y(m.id,()=>te(`/api/team-memory/${m.id}?${O}&revision=${m.revision}`,{method:"DELETE"})),V=(m,D,N)=>{D.trim()===m.detail&&(N===void 0||N===m.name)||Y(m.id,()=>te(`/api/team-memory/${m.id}?${O}`,{method:"PATCH",body:JSON.stringify({detail:D,...N===void 0?{}:{name:N},expectedRevision:m.revision})})).then($=>M(T=>{const L={...T};return $?delete L[m.id]:L[m.id]={name:N??m.name,text:D},L}))},B=()=>{!y.name.trim()||!y.detail.trim()||Y(null,()=>te(`/api/team-memory?${O}`,{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.stopPropagation(),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:()=>{P()},className:"underline",children:s("teamMemory.reload")})]}),Object.entries(x).map(([m,D])=>e.jsxs("p",{className:"mb-3 text-[12px] text-ink-secondary",children:[e.jsx("strong",{children:D.name})," · ",s("teamMemory.unsaved",{text:D.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:()=>{K(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:D,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(D)}),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:L=>V(T,L.target.value),onKeyDown:L=>{L.key==="Enter"&&L.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((L,se)=>e.jsxs("div",{className:"mt-1",children:[new Date(L.at).toLocaleDateString(Ee()),": ",L.name," — ",L.detail," ",e.jsx("button",{disabled:b!==null,onClick:()=>V(T,L.detail,L.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}?${O}`,{method:"PATCH",body:JSON.stringify({pinned:!T.pinned,expectedRevision:T.revision})}))},children:e.jsx(Pt,{size:13})}),e.jsx("button",{onClick:()=>{K(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)}),H?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"&&B()},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:B,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,R]=a.useState(""),[U,A]=a.useState(""),[H,v]=a.useState(null),[y,j]=a.useState(!1),[O,P]=a.useState(""),Y=a.useRef($e()),_=a.useRef(null),K=a.useRef(null),V=a.useRef(null),B=a.useRef(!1),q=a.useRef(!0),m=a.useRef(null),D=a.useRef(I);D.current=I;const[N,$]=a.useState(null),[T,L]=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(!(B.current||o.section===k)){if(o.section!==null&&k!==null){R(s("canvasComputers.unassignBeforeMove",{computer:o.name,team:o.section||s("settings.section.general")}));return}R(""),$({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(""),D.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(()=>{!B.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 V.current?.focus(),()=>{o?.isConnected&&o.focus()}},[n]),a.useEffect(()=>{n&&y&&K.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(!B.current){B.current=!0,v(o),R(""),m.current?.abort();try{const le=await k();q.current&&J?.(le)}catch(le){q.current&&(R(le instanceof Error?le.message:String(le)),Z?.())}finally{B.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||H!==null,onClick:()=>{R(""),oe()},children:e.jsx(sn,{size:14,className:h?"animate-spin":""})}),e.jsx("button",{ref:V,"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??O.trim();!k||!x?.configured||(_.current=k,pe("create",()=>te("/api/team-computers",{method:"POST",body:JSON.stringify({name:k,requestId:Y.current,acknowledgeCost:!0})}),()=>{P(""),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:K,id:"canvas-computer-name",className:Hn,value:O,maxLength:60,placeholder:s("canvasComputers.namePlaceholder"),disabled:H!==null||_.current!==null,onChange:o=>P(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:H!==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||!O.trim()||H!==null,children:[H==="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:H!==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=>{B.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,H===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:H!==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:H!==null||le,onClick:()=>{pe(o.id,()=>ce(o.id,"provision",{acknowledgeCost:!0}))},children:s("canvasComputers.startRetry")}),k&&!le&&e.jsx("button",{className:xe,disabled:H!==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:H!==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://")&&L({id:o.id,url:W.joinUrl})})},children:[s("canvasComputers.openDesktop")," ",e.jsx(Nt,{size:11})]}),Z&&e.jsx("button",{className:`${xe} text-accent`,disabled:H!==null,onClick:()=>{pe(o.id,()=>ce(o.id,"control",{action:"release",controlLeaseId:F.current}),()=>{S(null),L(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(Lt,{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(Ge,{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),L(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:R})=>h.slice(0,R.length).toLowerCase()===R.toLowerCase()&&!_t(h.slice(R.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),[R,U]=a.useState(null),[A,H]=a.useState(0),[v,y]=a.useState(null),j=a.useMemo(()=>n.filter(S=>!S.hidden),[n]),O=a.useMemo(()=>qn(M,j,r),[M,j,r]),P=a.useMemo(()=>ct(O,j,!1),[O,j]),Y=P.botIds.join(",");a.useEffect(()=>{l(Y?Y.split(","):[])},[Y,l]),a.useEffect(()=>()=>l([]),[l]);const _=Kt(M,w),K=a.useMemo(()=>{if(!_||_.start===R)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)},[_,R,j,r]),V=K.length>0,B=an(V);a.useEffect(()=>H(0),[_?.start,_?.query]),a.useEffect(()=>{V&&x.current?.querySelector(`[data-mention-index="${A}"]`)?.scrollIntoView({block:"nearest"})},[A,V]);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&&O.botIds.length>0,D=async()=>{if(!m)return;const S=M.trim(),F=O;h(""),b(0),U(null);const ee=P.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)),L=v?.expanded?$:$.slice(0,T.names.length),se=M.trim()&&!O.botIds.length?s("mapComposer.tagHint"):P.chief?s("mapComposer.willSendViaChief",{name:P.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")}),L.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<L.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:B,choices:K,highlight:A,everyoneCount:j.length,onPick:q,onHighlight:H}),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(V){if(S.key==="ArrowDown"||S.key==="ArrowUp"){S.preventDefault(),H(F=>(F+(S.key==="ArrowDown"?1:-1)+K.length)%K.length);return}if(S.key==="Enter"||S.key==="Tab"){S.preventDefault(),q(K[A]);return}if(S.key==="Escape"){S.preventDefault(),S.stopPropagation(),U(_?.start??null);return}}Yt(S.nativeEvent,I)&&(S.preventDefault(),D())}}}),e.jsx("button",{onClick:()=>{D()},disabled:!m,"aria-label":s("mapComposer.send"),title:m?P.botIds.length===1?s("mapComposer.sendToOne"):s("mapComposer.sendTo",{count:P.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||O.botIds.length>0)&&e.jsx("p",{className:"mt-1.5 px-3 text-[11px] text-ink-secondary",children:se??(P.botIds.length===1?s("mapComposer.willSendOne"):s("mapComposer.willSend",{count:P.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 Gn({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,R]=a.useState(24e3),[U,A]=a.useState(null),[H,v]=a.useState(!0),[y,j]=a.useState(!1),[O,P]=a.useState(null),Y=x!==h,_=a.useMemo(()=>new TextEncoder().encode(x).byteLength,[x]);c.current=l,I.current=y,g.current=Y;const K=a.useCallback(()=>{I.current||g.current&&!window.confirm(s("team.instructionsDiscard"))||c.current()},[]);a.useEffect(()=>{const B=document.activeElement instanceof HTMLElement?document.activeElement:null;d.current?.focus();const q=m=>{if(m.key==="Escape"&&!I.current){m.preventDefault(),K();return}if(m.key!=="Tab")return;const D=d.current;if(!D)return;const N=[...D.querySelectorAll('button:not([disabled]), textarea:not([disabled]), input:not([disabled]), [href], [tabindex]:not([tabindex="-1"])')];if(N.length===0){m.preventDefault(),D.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),B?.focus()}},[K]),a.useEffect(()=>{let B=!1;return v(!0),P(null),te(`/api/section-context?section=${encodeURIComponent(n)}`).then(q=>{B||(M(q.text),w(q.text),A(q.updatedAt),R(q.maxBytes),window.setTimeout(()=>i.current?.focus(),0))}).catch(q=>{B||P(q instanceof Error?q.message:String(q))}).finally(()=>{B||v(!1)}),()=>{B=!0}},[n]);const V=async()=>{if(!(_>b)){j(!0),P(null);try{const B=await te(`/api/section-context?section=${encodeURIComponent(n)}`,{method:"PUT",body:JSON.stringify({text:x})});w(B.text),M(B.text),A(B.updatedAt),R(B.maxBytes)}catch(B){P(B instanceof Error?B.message:String(B))}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:B=>B.stopPropagation(),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:K,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:[H?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:B=>M(B.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())})})]})]}),O&&e.jsx("div",{className:"mt-3 rounded-lg border border-danger/30 bg-danger/10 px-3 py-2 text-[12px] text-danger",children:O})]}),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:K,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:()=>{V()},disabled:H||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 Vn=1400;function ss(){const{state:n,dispatch:r}=Ne(),{dragProps:l}=St(),d=window.ogb?.remoteClient?.active===!0,i=xt(),c=Gt(),I=Vt()==="people"&&i!==null,[g,x]=a.useState(mn),[M,h]=a.useState(null),[w,b]=a.useState(null),[R,U]=a.useState(null),[A,H]=a.useState(null),[v,y]=a.useState(null),[j,O]=a.useState(null),[P,Y]=a.useState(!1),[_,K]=a.useState(0),[V,B]=a.useState([]),[q,m]=a.useState(null),D=a.useCallback(()=>m(null),[]),[N,$]=a.useState(null),T=a.useRef(N);T.current=N,a.useEffect(()=>()=>T.current?.resolve(!1),[]);const L=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(L,f).sort((k,J)=>o(k.key)-o(J.key))},[L,n.sections,n.groups]),S=a.useMemo(()=>fn(L,g),[L,g]),F=L.some(f=>f.computer==="cloud"&&f.cloudBackend!=="vps")||V.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),Vn)},[]);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(L.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":P,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),K(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:L}):e.jsx($n,{sections:se,canManage:!d&&c!==!1,onMove:be,taggedBotIds:de,sent:me,bottomInset:L.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(V.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)=>H({section:f,label:o}),onEditTeam:(f,o)=>y({section:f,rename:o}),onDeleteTeam:O,isEmpty:f=>![...n.bots,...n.groups].some(o=>o.section?.trim()===f)}),L.length>0&&e.jsx(Yn,{bots:L,teams:Se,onTagged:fe,onSent:ve})]}),!d&&e.jsx(Un,{open:P,createRequest:_,drop:q,sections:se,onClose:()=>Y(!1),onDropHandled:D,onChange:B})]}),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:L},`${f.sourceBotId}:${f.targetBotId}`))})]}),R&&e.jsx(Gn,{section:R.section,label:R.label,onClose:()=>U(null)}),v&&e.jsx(tn,{...v,onClose:()=>y(null)}),A&&e.jsx(_n,{...A,onClose:()=>H(null)},A.section),e.jsx(Ge,{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(Ge,{open:j!==null,title:s("team.deleteTitle",{name:j??""}),body:s("team.deleteKeepBotsDescription"),confirmLabel:s("team.delete"),onCancel:()=>O(null),onConfirm:()=>{const f=j;O(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,Gn as SectionContextDialog,ss as TeamMapPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,t,a as S,i as ie,d as he,r as m,X as be,C as fe,n as Re,S as Ae}from"./styles-DO3EUxm2.js";import{C as Ee,K as Te,B as ze,c as Me,d as Le,P as ce,V as Oe}from"./PlacesRail-tZyNm-l3.js";import{cF as ge,cG as Pe,cH as Fe,cI as oe,Y as $e,u as H,cJ as We,cK as Ye,cL as ee,cM as ye,cN as de,cO as _e,cP as ke,cQ as He,cR as Ue,cS as Ge,cT as Je,bw as Ke,cU as Qe,cV as je,cW as ue,cX as qe,cY as Ve,T as Xe,cZ as Ze,c_ as et,c$ as Z,d0 as ve,cx as we,d1 as tt,d2 as ne,d3 as st,d4 as nt,d5 as Ne,j as W,d6 as Ce,d7 as at,d8 as it,d9 as ot,da as xe,db as rt,dc as lt,dd as dt,de as ct,w as re,C as ut,df as xt,bT as pt,dg as mt,bR as ht,dh as bt,di as ft,S as Se,dj as gt,dk as yt}from"./App-BgdjoCaG.js";import{AppEventEditor as kt}from"./AppEventEditor-CbDxf3ao.js";import{C as Ie,S as jt}from"./MenuMotion-B0aZnuh_.js";import{C as vt,E as wt,Q as Nt,b as Ct,H as St,R as It}from"./RoutinesPage-CY3YGT8X.js";import{WebhookEditor as Bt}from"./WebhookTrigger-DEoEYgVK.js";import"./monitor-zecPzfR5.js";import"./index-BQM4L4RU.js";import"./remote-desktop-DDRRx8uY.js";import"./ProIntroduction-Cq3nswpJ.js";const le="\0general";function Dt(n,r){const l=n.filter(h=>!h.hidden),g=new Set(l.map(h=>h.section).filter(h=>!!h));return{names:r.filter(h=>g.has(h)),hasGeneral:l.some(h=>!h.section)}}function te(n,r){return r==="all"?!0:n?r===le?!n.section:n.section===r:!1}function Rt({trigger:n}){const{attempts:r,service:l}=ge(),g=r.filter(o=>o.triggerId===n.id).slice(-6).reverse(),h=Pe(n);return e.jsxs("section",{"data-app-events":n.id,children:[e.jsx("h3",{className:"mb-2 text-[12px] font-semibold uppercase tracking-wider text-ink-tertiary",children:t("automations.panel.events")}),h&&e.jsx("p",{className:"mb-2 rounded-lg bg-warning/10 px-2.5 py-1.5 text-[12px] text-warning",children:h}),g.length===0?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("automations.panel.noEvents")}):e.jsx("ul",{className:"space-y-1",children:g.map(o=>{const b=Fe(o),p=oe(o.at);return e.jsxs("li",{className:"flex items-baseline gap-2 px-2 py-1 text-[13px]",children:[e.jsx("span",{className:"shrink-0 text-ink-secondary",children:p.charAt(0).toLocaleUpperCase()+p.slice(1)}),e.jsx("span",{className:S("shrink-0 font-semibold",b.mark==="✓"?"text-success":b.mark==="✗"?"text-danger":"text-ink-tertiary"),children:b.mark}),e.jsx("span",{className:"min-w-0 truncate text-ink",title:b.text,children:b.text})]},o.id)})}),l?.eventsPerDay&&e.jsx("p",{className:"mt-2 text-[11px] text-ink-tertiary",children:t("automations.app.limit",{count:l.eventsPerDay.toLocaleString(ie()),place:t(l.plan==="cloud"?"automations.app.placeCloud":"automations.app.placeDesktop")})})]})}function Be({status:n,className:r}){return n.state==="needs-you"?e.jsx($e,{size:15,"aria-hidden":"true",className:S("shrink-0 text-warning",r)}):n.state==="done"?e.jsx(he,{size:14,"aria-hidden":"true",className:S("shrink-0 text-ink-tertiary",r)}):e.jsx("span",{"aria-hidden":"true",className:S("size-2.5 shrink-0 rounded-full",n.state==="working"?"bg-success":"bg-ink-tertiary/60",r)})}function De({automation:n,status:r,actions:l,onEdit:g,className:h}){const{dispatch:o}=H();if(r.state!=="needs-you"||!r.fix)return null;const b=r.fix,p=b==="answer"?We(n.runs):void 0,i=()=>{b==="answer"?l.openRun(n,p):b==="sign-in"?l.openRun(n,n.runs.find(x=>x.status!=="queued")):b==="usage"?o({type:"toggleAppSettings",open:!0,section:"usage"}):b==="edit"?g():b==="reconnect"?o({type:"togglePlugins",open:!0,surface:"apps"}):l.runNow(n)};return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:i,disabled:!!l.busy,className:S("shrink-0 rounded-lg bg-warning/15 px-2.5 py-1 text-[12px] font-medium text-warning hover:bg-warning/25 disabled:opacity-50",h),children:t(Ye[b])}),p&&e.jsx("button",{type:"button","data-automation-cancel-run":!0,onClick:()=>{l.cancelRun(n,p)},disabled:!!l.busy,className:S("shrink-0 rounded-lg px-2.5 py-1 text-[12px] text-ink-secondary hover:bg-raised hover:text-ink disabled:opacity-50",h),children:t("routines.drawer.cancelRun")})]})}const At=5,q="flex items-center justify-center gap-1.5 rounded-lg px-3 py-2 text-[13px] font-medium disabled:opacity-50";function Et({automation:n,sentence:r,onClose:l,onEdit:g,onDeleted:h}){const{state:o,dispatch:b}=H(),[p]=m.useState(()=>new Set(n.runs.filter(u=>ee(u)&&!u.seenAt).map(u=>u.id))),i=n.runs.filter((u,C)=>C<At||p.has(u.id)||ee(u)&&!u.seenAt);m.useEffect(()=>{for(const u of n.runs)ee(u)&&!u.seenAt&&b({type:"markRoutineRunSeen",runId:u.id})},[n.runs,b]);const x=ye(),j=de(n),f=n.kind==="webhook"?o.webhooks.find(u=>u.id===n.id):void 0,v=f?_e(ke())[f.id]:void 0,y=o.webhookIngress?.available!==!1,N=t(He[j.state]),w=n.name.trim(),A=o.bots.find(u=>u.id===n.botId)?.name??t("routines.unavailableBot"),B=n.instructions.trim(),c=j.state==="done"?t("automations.reason.done"):j.reason,I=f?Ue(f.id,o.webhookAttempts):[],z=f?Ge(f,o.webhookAttempts):null,[R,Y]=m.useState(null),[M,D]=m.useState(!1),[E,_]=m.useState(!1),T=async u=>{if(await Te(u)!=="copied"){x.setError(t("automations.address.copyFailed"));return}_(!0),setTimeout(()=>_(!1),1800)};return e.jsxs("aside",{"aria-label":t("automations.panel.label"),className:"flex h-full w-[min(380px,100vw)] shrink-0 flex-col border-l border-hairline/40 bg-panel",children:[e.jsxs("div",{className:"flex items-start gap-3 border-b border-hairline/40 px-5 py-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h2",{className:"text-[16px] font-semibold leading-snug text-ink",children:w||r}),w&&e.jsx("p",{className:"mt-0.5 text-[13px] text-ink-secondary",children:Je(n,A)})]}),e.jsx("button",{type:"button",onClick:l,className:"rounded-full p-1.5 text-ink-secondary hover:bg-raised hover:text-ink","aria-label":t("automations.panel.close"),children:e.jsx(be,{size:16})})]}),e.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto px-5 py-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[13px]","data-automation-status":j.state,children:[e.jsx(Be,{status:j}),e.jsx("span",{className:S("font-medium",j.state==="needs-you"?"text-warning":"text-ink"),children:N}),c&&e.jsx("span",{className:"min-w-0 text-ink-secondary",children:c}),e.jsx(De,{automation:n,status:j,actions:x,onEdit:g})]}),f&&e.jsxs("section",{className:"rounded-xl border border-hairline/45 bg-inset/50 p-3.5",children:[e.jsx("h3",{className:"text-[13px] font-medium text-ink",children:t("automations.address.title")}),e.jsxs("button",{type:"button",disabled:!!x.busy||!y,onClick:()=>{x.copyAddress(f.id)},className:S(q,"mt-2.5 bg-accent text-accent-ink hover:brightness-110"),children:[x.copied===f.id?e.jsx(he,{size:14}):e.jsx(Ee,{size:14}),x.copied===f.id?t("automations.address.copied"):t("automations.address.copy")]}),(!y||!o.config?.cloudHome)&&e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:y?t("automations.address.keepOpen"):t("automations.address.unavailable")}),e.jsxs("details",{className:"mt-2.5 text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer select-none font-medium text-ink-secondary hover:text-ink",children:t("automations.more")}),e.jsxs("div",{className:"mt-2 space-y-2 leading-relaxed",children:[z&&e.jsxs("section",{"aria-label":t("automations.received.title"),children:[e.jsxs("p",{className:"font-medium text-ink",children:[t("automations.received.title")," · ",oe(z.at)]}),e.jsx("p",{className:"mt-0.5",children:t("automations.received.help")}),e.jsx("pre",{className:"mt-1.5 max-h-40 overflow-auto whitespace-pre-wrap break-all rounded-lg bg-inset px-2.5 py-2 font-mono text-[11px] text-ink",children:z.preview.slice(0,1e3)})]}),e.jsxs("section",{"aria-label":t("automations.calls.title"),children:[e.jsx("p",{className:"font-medium text-ink",children:t("automations.calls.title")}),I.length===0?e.jsx("p",{className:"mt-0.5",children:t("automations.calls.none")}):e.jsx("ul",{className:"mt-1 space-y-0.5",children:I.map(u=>e.jsxs("li",{"data-call":u.ok?"ok":"refused",children:[e.jsxs("button",{type:"button","aria-expanded":R===u.id,onClick:()=>Y(C=>C===u.id?null:u.id),className:"flex w-full items-baseline gap-2 rounded-md px-1.5 py-1 text-left hover:bg-raised",children:[e.jsx("span",{className:"shrink-0",children:Ke(oe(u.at))}),e.jsx("span",{className:S("shrink-0 font-semibold",u.ok?"text-success":"text-danger"),children:u.ok?"✓":"✗"}),e.jsx("span",{className:"min-w-0 truncate text-ink",children:u.reason})]}),R===u.id&&e.jsx("pre",{className:"mx-1.5 mb-1 whitespace-pre-wrap break-all rounded-md bg-inset px-2 py-1.5 font-mono text-[11px] text-ink",children:u.preview||t("automations.calls.empty")})]},u.id))})]}),e.jsx("p",{className:"font-medium text-ink",children:t("automations.address.showSecret")}),v?e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1","data-secret":M?"shown":"masked",children:[e.jsx("span",{className:"min-w-0 break-all font-mono text-[11px]",children:t("automations.address.secret",{secret:M?v.secret:"••••••••"})}),e.jsx("button",{type:"button","aria-label":t(M?"automations.address.hideSecretLabel":"automations.address.showSecretLabel"),onClick:()=>D(u=>!u),className:"rounded-md px-1.5 py-0.5 font-medium text-ink hover:bg-raised",children:t(M?"automations.address.hideSecret":"automations.address.revealSecret")}),e.jsx("button",{type:"button","aria-label":t("automations.address.copySecretLabel"),onClick:()=>{T(v.secret)},className:"rounded-md px-1.5 py-0.5 font-medium text-ink hover:bg-raised",children:E?t("automations.address.copied"):t("automations.address.copySecret")})]}):e.jsx("p",{className:"break-all font-mono text-[11px]",children:t("automations.address.secretUnknown")}),e.jsx("p",{children:t("automations.address.header")}),f.eventTypes?.length?e.jsx("p",{children:t("automations.address.events",{events:f.eventTypes.join(", ")})}):null,e.jsxs("button",{type:"button",disabled:!!x.busy,onClick:()=>{window.confirm(t("automations.address.replaceConfirm"))&&x.copyAddress(f.id,!0)},className:"flex items-center gap-1.5 rounded-lg border border-hairline/50 px-2.5 py-1.5 text-ink hover:bg-raised",children:[e.jsx(Qe,{size:12}),t("automations.address.replace")]})]})]})]}),w&&B&&e.jsx("p",{"data-testid":"automation-instructions",className:"whitespace-pre-wrap break-words text-[13px] leading-relaxed text-ink",children:B}),n.appTrigger&&e.jsx(Rt,{trigger:n.appTrigger}),e.jsxs("section",{children:[e.jsx("h3",{className:"mb-2 text-[12px] font-semibold uppercase tracking-wider text-ink-tertiary",children:t("automations.panel.recent")}),n.runs.length===0?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("automations.panel.noRuns")}):e.jsx("ul",{className:"space-y-1",children:i.map(u=>{const C=je(u);return e.jsx("li",{children:e.jsxs("button",{type:"button",disabled:!u.threadId,onClick:()=>x.openRun(n,u),title:u.threadId?t("automations.panel.open"):void 0,className:"flex w-full items-baseline gap-2 rounded-lg px-2 py-1.5 text-left text-[13px] hover:bg-raised disabled:hover:bg-transparent",children:[e.jsx("span",{className:"shrink-0 text-ink-secondary",children:C.when}),e.jsx("span",{className:S("shrink-0 font-semibold",C.mark==="✓"?"text-success":C.mark==="✗"?"text-danger":"text-warning"),children:C.mark}),e.jsx("span",{className:"min-w-0 truncate text-ink",children:C.text})]})},u.id)})})]}),x.error&&e.jsx("p",{role:"alert",className:"rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:x.error})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 border-t border-hairline/40 px-5 py-3.5",children:[e.jsxs("button",{type:"button",disabled:!!x.busy,onClick:()=>{x.runNow(n)},className:S(q,"bg-accent text-accent-ink hover:brightness-110"),children:[e.jsx(ue,{size:14}),x.busy===`run:${n.id}`?t("automations.starting"):t("automations.runNow")]}),j.state!=="done"&&e.jsxs("button",{type:"button",disabled:!!x.busy,onClick:()=>{x.toggle(n)},className:S(q,"border border-hairline/50 bg-control text-ink hover:bg-raised-hover"),children:[n.enabled?e.jsx(qe,{size:14}):e.jsx(ue,{size:14}),n.enabled?t("automations.pause"):t("automations.resume")]}),e.jsxs("button",{type:"button",onClick:g,className:S(q,"text-ink hover:bg-raised"),children:[e.jsx(Ve,{size:14}),t("automations.edit")]}),e.jsxs("button",{type:"button",disabled:!!x.busy,onClick:()=>{x.remove(n,t("automations.deleteConfirm",{sentence:r})).then(u=>{u&&h()})},className:S(q,"text-danger hover:bg-danger/10"),children:[e.jsx(Xe,{size:14}),t("automations.delete")]})]})]})}const Tt=()=>Array.from({length:7},(n,r)=>new Intl.DateTimeFormat(Re(),{weekday:"narrow",timeZone:"UTC"}).format(Date.UTC(2023,0,2+r)));function ae(n){const r=new Date(n);return new Date(r.getFullYear(),r.getMonth(),1)}function pe(n,r){return n.getFullYear()===r.getFullYear()&&n.getMonth()===r.getMonth()&&n.getDate()===r.getDate()}function me(n,r){return new Date(n.getFullYear(),n.getMonth()+r,1)}function zt({anchor:n,onSelect:r}){const[l,g]=m.useState(()=>ae(n));m.useEffect(()=>{g(ae(n))},[n]);const h=m.useMemo(()=>{const i=ae(l),x=(i.getDay()+6)%7,j=new Date(i);return j.setDate(i.getDate()-x),Array.from({length:42},(f,v)=>{const y=new Date(j);return y.setDate(j.getDate()+v),y})},[l]),o=new Date(n),b=new Date,p=l.toLocaleDateString(ie(),{month:"long",year:"numeric"});return e.jsxs("section",{"aria-label":t("routines.miniCalendar.label"),className:"select-none px-3 py-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between px-1",children:[e.jsx("div",{className:"text-[13px] font-semibold text-ink",children:p}),e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsx("button",{type:"button",onClick:()=>g(i=>me(i,-1)),className:"flex size-7 items-center justify-center rounded-full text-ink-secondary transition-colors hover:bg-raised hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/60","aria-label":t("routines.miniCalendar.previous"),children:e.jsx(fe,{size:15,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>g(i=>me(i,1)),className:"flex size-7 items-center justify-center rounded-full text-ink-secondary transition-colors hover:bg-raised hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/60","aria-label":t("routines.miniCalendar.next"),children:e.jsx(Ie,{size:15,"aria-hidden":"true"})})]})]}),e.jsx("div",{className:"grid grid-cols-7","aria-hidden":"true",children:Tt().map((i,x)=>e.jsx("div",{className:"flex h-6 items-center justify-center text-[9px] font-semibold uppercase tracking-[0.08em] text-ink-tertiary",children:i},`${i}-${x}`))}),e.jsx("div",{className:"grid grid-cols-7 gap-y-0.5",children:h.map(i=>{const x=pe(i,o),j=pe(i,b),f=i.getMonth()!==l.getMonth(),v=i.toLocaleDateString(ie(),{weekday:"long",month:"long",day:"numeric",year:"numeric"});return e.jsx("button",{type:"button",onClick:()=>r(i.getTime()),"aria-label":v,"aria-current":j?"date":void 0,"aria-pressed":x,className:"group flex h-7 items-center justify-center rounded-full focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/60",children:e.jsx("span",{className:`flex size-6 items-center justify-center rounded-full text-[11px] transition-colors ${x?"bg-accent font-semibold text-white shadow-sm":j?"font-semibold text-accent group-hover:bg-accent/12":f?"text-ink-tertiary group-hover:bg-raised group-hover:text-ink":"text-ink group-hover:bg-raised"}`,children:i.getDate()})},`${i.getFullYear()}-${i.getMonth()}-${i.getDate()}`)})})]})}const Mt="application/x-openmaus-bot";function Lt({bots:n,anchor:r,onSelectDate:l}){const[g,h]=m.useState(""),o=m.useMemo(()=>{const p=g.trim().toLocaleLowerCase();return p?n.filter(i=>`${i.name} ${i.title} ${i.description}`.toLocaleLowerCase().includes(p)):n},[n,g]),b=(p,i)=>{p.dataTransfer.effectAllowed="copy",p.dataTransfer.setData(Mt,i.id),p.dataTransfer.setData("text/plain",i.id)};return e.jsxs("aside",{"aria-label":t("routines.sidebar.label"),className:"flex h-full w-[320px] shrink-0 flex-col overflow-hidden border-r border-hairline/40 bg-panel",children:[e.jsx(zt,{anchor:r,onSelect:l}),e.jsx("div",{className:"mx-4 border-t border-hairline/40"}),e.jsxs("section",{"aria-labelledby":"calendar-bots-heading",className:"flex min-h-0 flex-1 flex-col px-3 pb-3 pt-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between px-1",children:[e.jsxs("div",{id:"calendar-bots-heading",className:"flex items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.11em] text-ink-secondary",children:[e.jsx(Ze,{size:13,"aria-hidden":"true"}),t("routines.sidebar.myBots")]}),e.jsx("span",{className:"rounded-full bg-raised px-1.5 py-0.5 text-[9px] tabular-nums text-ink-secondary",children:n.length})]}),e.jsxs("label",{className:"relative mb-2 block",children:[e.jsx("span",{className:"sr-only",children:t("routines.sidebar.searchBots")}),e.jsx(Ae,{size:13,className:"pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2 text-ink-tertiary","aria-hidden":"true"}),e.jsx("input",{value:g,onChange:p=>h(p.target.value),type:"search",placeholder:t("routines.sidebar.searchBots"),className:"h-8 w-full rounded-lg border border-hairline/45 bg-control/55 pl-8 pr-2.5 text-[12px] text-ink outline-none placeholder:text-ink-tertiary focus:border-accent/60 focus:bg-control"})]}),e.jsxs("div",{role:"list","aria-label":t("routines.sidebar.availableBots"),className:"min-h-0 flex-1 space-y-0.5 overflow-y-auto pr-0.5",children:[o.map(p=>e.jsxs("div",{draggable:!0,onDragStart:i=>b(i,p),role:"listitem",className:"group flex cursor-grab items-center gap-2 rounded-xl px-2 py-2 transition-colors hover:bg-raised/80 active:cursor-grabbing","aria-label":t("routines.sidebar.dragBot",{name:p.name}),title:t("routines.sidebar.dragBot",{name:p.name}),children:[e.jsx(et,{size:13,className:"shrink-0 text-ink-secondary/35 transition-colors group-hover:text-ink-secondary","aria-hidden":"true"}),e.jsx(ze,{bot:p,size:27,animated:!1}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[12px] font-medium text-ink",children:p.name}),e.jsx("div",{className:"truncate text-[10px] text-ink-tertiary",children:p.title||t("routines.sidebar.botFallback")})]}),e.jsx("span",{className:"shrink-0 rounded-full border border-hairline/50 px-1.5 py-0.5 text-[9px] text-ink-tertiary opacity-0 transition-opacity group-hover:opacity-100",children:t("routines.sidebar.drag")})]},p.id)),o.length===0&&e.jsx("div",{className:"px-3 py-8 text-center text-[11px] leading-relaxed text-ink-secondary",children:n.length===0?t("routines.sidebar.noBots"):t("routines.sidebar.noMatch")})]}),e.jsx("p",{className:"mt-2 px-2 text-[10px] leading-relaxed text-ink-tertiary",children:t("routines.sidebar.dragHint")})]})]})}function Ot({botFilter:n,department:r="all",selectedAutomationId:l,onOpenAutomation:g,onOpenRoom:h}){const{state:o,dispatch:b}=H(),p=window.ogb?.remoteClient?.active===!0,[i,x]=m.useState(()=>window.innerWidth<640?1:7),[j,f]=m.useState(()=>Z(Date.now())),[v,y]=m.useState([]),[N,w]=m.useState(null),[A,B]=m.useState(null),[c,I]=m.useState(null),[z,R]=m.useState(""),Y=o.bots.filter(a=>!a.hidden),M=ve(Y,we(),A?.botIds[0]),D=i===7?tt(j):Z(j),E=ne(D,i);st(D);const _=nt(Ne(),D,E),T=m.useCallback(async()=>{try{y((await W("/api/calendar-calls")).calls??[])}catch(a){R(a instanceof Error?a.message:String(a))}},[]);m.useEffect(()=>{p||T()},[T,p]);const u=m.useMemo(()=>{const a=new Set(o.bots.map(k=>k.id)),s=o.routines.filter(k=>a.has(k.botId)),d=new Set(Ce({routines:s,webhooks:[],runs:o.routineRuns}).filter(k=>de(k).state==="needs-you").map(k=>k.id)),P=at(s,o.routineRuns.filter(k=>a.has(k.botId)),D,E).map(k=>({...k,kind:"routine",needsYou:!!(k.routine&&!k.run&&d.has(k.routine.id))})),F=it(v,D,E).map(k=>({...k,kind:"call"})),$=k=>o.bots.find(Q=>Q.id===k);return[...P,...F].filter(k=>k.kind==="call"?k.call.botIds.some(Q=>te($(Q),r)):te($(k.routine?.botId??k.run?.botId),r)).filter(k=>n==="all"||(k.kind==="call"?k.call.botIds.includes(n):(k.routine?.botId??k.run?.botId)===n)).sort((k,Q)=>k.at-Q.at)},[o.routines,o.routineRuns,o.bots,v,D,E,n,r]),C=c?.kind==="call"?(()=>{const a=v.find(s=>s.id===c.call.id);return a?{...c,call:a}:null})():null,U=a=>{if(a.kind==="call"){I(a);return}I(null);const s=a.routine?.id??a.run?.routineId;s&&g(s)},V=a=>g(a.routineId),L=C?.id??u.find(a=>a.kind==="routine"&&(a.routine?.id??a.run?.routineId)===l)?.id,O=a=>y(s=>s.some(d=>d.id===a.id)?s.map(d=>d.id===a.id?a:d):[a,...s]),G=async(a,s)=>{if(s!==a.at)try{if(a.kind==="routine"){const d=o.routines.find(F=>F.id===a.id);if(!d)return;if(d.schedule.type==="cron")throw new Error(t("automations.calendar.cronMove"));if(d.schedule.type!=="once"&&!window.confirm(t("automations.calendar.moveSeries")))return;const P=await W(`/api/routines/${d.id}`,{method:"PATCH",body:JSON.stringify({schedule:xe(d.schedule,a.at,s)})});b({type:"routinePatched",routine:P.routine})}else{const d=v.find(F=>F.id===a.id);if(!d||d.schedule.type==="daily"&&!window.confirm(t("automations.calendar.moveSeries")))return;const P=await W(`/api/calendar-calls/${d.id}`,{method:"PATCH",body:JSON.stringify({schedule:xe(d.schedule,a.at,s)})});O(P.call)}}catch(d){R(d instanceof Error?d.message:String(d))}},se=async(a,s)=>{if("botId"in a){I(null),w({kind:"routine",at:s.at,durationMinutes:30,botIds:[a.botId],limitReset:{engine:s.engine}});return}if(a.event.kind!=="routine")return R(t("limits.callNotOnReset"));try{const d=await W(`/api/routines/${a.event.id}`,{method:"PATCH",body:JSON.stringify({schedule:{type:"limit_reset",engine:s.engine,repeat:"once"}})});b({type:"routinePatched",routine:d.routine})}catch(d){R(d instanceof Error?d.message:String(d))}},X=async(a,s)=>{try{if(a.kind==="routine"&&a.routine){const d=await W(`/api/routines/${a.routine.id}`,{method:"PATCH",body:JSON.stringify({durationMinutes:s})});b({type:"routinePatched",routine:d.routine})}else if(a.kind==="call"){const d=await W(`/api/calendar-calls/${a.call.id}`,{method:"PATCH",body:JSON.stringify({durationMinutes:s})});O(d.call)}}catch(d){R(d instanceof Error?d.message:String(d))}},J=()=>{C&&(B({kind:"call",at:C.at,durationMinutes:C.call.durationMinutes,botIds:C.call.botIds,call:C.call}),I(null))},K=a=>S("rounded-md px-3 py-1 text-[12px] font-medium",a?"bg-raised text-ink shadow-sm":"text-ink-secondary hover:text-ink");return e.jsxs("div",{className:"@container/routines relative flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b border-hairline/30 px-4 py-2",children:[e.jsx("button",{type:"button",onClick:()=>f(a=>ne(a,-i)),className:"rounded-md p-1.5 text-ink-secondary hover:bg-raised hover:text-ink","aria-label":t("routines.previous"),children:e.jsx(fe,{size:16})}),e.jsx("button",{type:"button",onClick:()=>f(a=>ne(a,i)),className:"rounded-md p-1.5 text-ink-secondary hover:bg-raised hover:text-ink","aria-label":t("routines.next"),children:e.jsx(Ie,{size:16})}),e.jsx("div",{className:"min-w-0 truncate px-1 text-[14px] font-medium text-ink","aria-live":"polite",children:ot(D,i)}),e.jsx("button",{type:"button",onClick:()=>f(Z(Date.now())),className:"rounded-lg border border-hairline/50 px-2.5 py-1 text-[12px] font-medium text-ink hover:bg-raised",children:t("routines.today")}),e.jsxs("div",{role:"group",className:"ml-auto flex items-center rounded-lg border border-hairline/50 bg-panel p-0.5","aria-label":t("routines.view.label"),children:[e.jsx("button",{type:"button","aria-pressed":i===1,onClick:()=>x(1),className:K(i===1),children:t("routines.view.day")}),e.jsx("button",{type:"button","aria-pressed":i===7,onClick:()=>x(7),className:K(i===7),children:t("routines.view.week")})]}),z&&e.jsx("button",{type:"button",onClick:()=>R(""),className:"w-full text-left text-[12px] text-danger",children:z})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-1",children:[!C&&e.jsx("div",{className:"hidden shrink-0 @min-[1040px]/routines:block",children:e.jsx(Lt,{bots:Y,anchor:j,onSelectDate:a=>f(Z(a))})}),e.jsx(vt,{anchor:D,days:i,items:u,bots:o.bots,groups:o.groups,selectedId:L,onOpen:U,onCreate:a=>{I(null),w(a)},onMove:(a,s)=>{G(a,s)},onResize:(a,s)=>{X(a,s)},markers:_,onDropOnReset:(a,s)=>{se(a,s)}}),C&&e.jsx("div",{className:"absolute inset-y-0 right-0 z-30 flex shadow-2xl @min-[760px]/routines:static @min-[760px]/routines:shadow-none",children:e.jsx(wt,{item:C,bots:o.bots,onClose:()=>I(null),onEdit:J,onOpenRun:V,onCallChanged:a=>{a?y(s=>s.filter(d=>d.id!==a)):T()},onOpenRoom:h},`${C.kind}:${C.id}`)})]}),N&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40 bg-black/25",onMouseDown:()=>w(null)}),e.jsx(Nt,{seed:N,bots:M,routinesOnly:p,onClose:()=>w(null),onMore:a=>{w(null),B(a)},onSavedRoutine:a=>b({type:"routinePatched",routine:a}),onSavedCall:O})]}),A&&e.jsx(Ct,{seed:A,bots:M,routinesOnly:p,onClose:()=>B(null),onSavedCall:O})]})}function Pt({botFilter:n="all"}){const{state:r,dispatch:l}=H(),g=rt(Ne()),[h,o]=m.useState(null),[b,p]=m.useState(null),[i,x]=m.useState("");if(!g.length)return null;const j=y=>r.bots.find(N=>N.id===y)?.modelSelection?.instanceId,f=r.routines.filter(y=>n==="all"||y.botId===n),v=async(y,N)=>{o(y.engine),x("");try{for(const w of N){const A=await W("/api/limit-resets/after-reset",{method:"POST",body:JSON.stringify({routineId:w.id,engine:y.engine})});l({type:"routinePatched",routine:A.routine})}p(y.engine)}catch(w){x(w instanceof Error?w.message:String(w))}finally{o(null)}};return e.jsxs("section",{"aria-label":t("limits.title"),className:"mb-4 space-y-2",children:[g.map(y=>{const N=lt(f,j,y);return e.jsxs("div",{"data-limit-warning":y.engine,role:"status",className:"flex flex-wrap items-center gap-x-2.5 gap-y-1.5 rounded-xl border border-warning/40 bg-warning/10 px-3.5 py-2.5 text-[13px] text-ink",children:[e.jsx(St,{size:15,className:"shrink-0 text-warning","aria-hidden":"true"}),e.jsx("span",{className:"font-medium tabular-nums",children:dt(y)}),N.length>0?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-ink-secondary",children:t(N.length===1?"limits.dueOne":"limits.dueMany",{count:N.length})}),e.jsx("button",{type:"button",disabled:h===y.engine,onClick:()=>{v(y,N)},className:"ml-auto rounded-lg bg-accent px-3 py-1.5 text-[13px] font-medium text-accent-ink hover:brightness-110 disabled:opacity-50",children:t("limits.moveAfterReset")})]}):b===y.engine&&e.jsx("span",{className:"text-ink-secondary",children:t("limits.moved")})]},y.engine)}),i&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:i})]})}function Ft(n,r){const l=n.find(h=>h.id===r);if(l)return l;const g=h=>h.messages.at(-1)?.at??0;return[...n].sort((h,o)=>g(o)-g(h))[0]}function $t({initialText:n="",onClose:r,onSetUpYourself:l}){const{state:g,dispatch:h}=H(),o=g.bots.filter(c=>!c.hidden),[b,p]=m.useState(n),[i,x]=m.useState(()=>Ft(o,g.selectedId)?.id??""),[j,f]=m.useState(!1),[v,y]=m.useState("schedule"),N=m.useRef(null);Me(N,r);const w=o.find(c=>c.id===i),A=()=>{const c=b.trim();!c||!w||(h({type:"select",id:w.id}),h({type:"send",botId:w.id,text:c,threadId:w.threadId}),r())},B=(c,I,z)=>e.jsxs("button",{type:"button",role:"radio","aria-checked":v===c,onClick:()=>y(c),className:S("flex w-full items-center gap-3 rounded-xl border px-3.5 py-3 text-left text-[14px]",v===c?"border-accent/70 bg-accent/10 text-ink":"border-hairline/50 text-ink-secondary hover:bg-raised"),children:[e.jsx(z,{size:16,className:"shrink-0 text-accent"}),I]});return e.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/50 p-5 pt-[14vh] backdrop-blur-sm",onMouseDown:c=>c.stopPropagation(),children:e.jsxs("div",{ref:N,role:"dialog","aria-modal":"true","aria-label":t("automations.newBox.title"),tabIndex:-1,className:"w-full max-w-[560px] rounded-2xl border border-hairline/60 bg-panel p-5 shadow-2xl",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("h2",{className:"text-[17px] font-semibold text-ink",children:j?t("automations.newBox.when"):t("automations.newBox.title")}),e.jsx("button",{type:"button",onClick:r,"aria-label":t("automations.newBox.cancel"),className:"rounded-full p-1.5 text-ink-secondary hover:bg-raised hover:text-ink",children:e.jsx(be,{size:16})})]}),j?e.jsxs(e.Fragment,{children:[e.jsxs("div",{role:"radiogroup","aria-label":t("automations.newBox.when"),className:"mt-4 space-y-2",children:[B("schedule",t("automations.newBox.onSchedule"),ut),B("app",t("automations.newBox.whenAppEvent"),xt),B("webhook",t("automations.newBox.whenApp"),pt)]}),e.jsxs("div",{className:"mt-5 flex items-center justify-between gap-2",children:[e.jsx("button",{type:"button",onClick:()=>f(!1),className:"rounded-lg px-2 py-1.5 text-[13px] text-ink-secondary hover:bg-raised hover:text-ink",children:t("automations.newBox.back")}),e.jsx("button",{type:"button",onClick:()=>l(v,w?.id??""),className:"rounded-xl bg-accent px-4 py-2 text-[13px] font-medium text-accent-ink hover:brightness-110",children:t("automations.newBox.continue")})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("textarea",{autoFocus:!0,value:b,onChange:c=>p(c.target.value),rows:3,"aria-label":t("automations.newBox.title"),placeholder:t("automations.newBox.placeholder"),onKeyDown:c=>{c.key==="Enter"&&!c.shiftKey&&!ct(c.nativeEvent)&&(c.preventDefault(),A())},className:"mt-4 w-full resize-none rounded-xl border border-hairline/60 bg-inset px-3.5 py-3 text-[14px] leading-relaxed text-ink outline-none placeholder:text-ink-tertiary focus:border-accent/70"}),o.length===0&&e.jsx("p",{className:"mt-2 text-[13px] text-warning",children:t("automations.newBox.noBots")}),o.length>1&&e.jsxs("label",{className:"mt-3 flex items-center gap-2 text-[13px] text-ink-secondary",children:[t("automations.newBox.bot"),e.jsx(re,{size:"sm",value:i,onChange:c=>x(c.target.value),"aria-label":t("automations.newBox.bot"),className:"max-w-[220px]",children:o.map(c=>e.jsx("option",{value:c.id,children:c.name},c.id))})]}),e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2",children:[e.jsx("button",{type:"button",onClick:()=>f(!0),className:"rounded-lg px-2 py-1.5 text-[13px] text-ink-secondary underline-offset-2 hover:text-ink hover:underline",children:t("automations.newBox.yourself")}),e.jsxs("button",{type:"button",disabled:!b.trim()||!w,onClick:A,className:"flex items-center gap-2 rounded-xl bg-accent px-4 py-2 text-[13px] font-medium text-accent-ink hover:brightness-110 disabled:opacity-40",children:[e.jsx(jt,{size:14}),t("automations.newBox.send")]})]})]})]})})}const Wt=9;function es({onBack:n,onOpenRoom:r}){const{state:l,dispatch:g}=H(),{capabilities:h}=Le(),o=ye(),b=ge(),p=m.useRef(null),i=l.routinesFocus,x=i?.view==="calendar"?"calendar":"list",[j,f]=m.useState(i?.section!=="logs"?i?.routineId??null:null),[v,y]=m.useState(i?.botId??"all"),[N,w]=m.useState("all"),[A,B]=m.useState(null),[c,I]=m.useState(null),z=window.ogb?.remoteClient?.active===!0,R=l.bots.filter(s=>!s.hidden),Y=we(),M=s=>l.bots.find(d=>d.id===s)?.name??t("routines.unavailableBot");m.useEffect(()=>{y(i?.botId??"all"),i?.routineId&&i.section!=="logs"&&f(i.routineId)},[i]),m.useEffect(()=>{p.current?.focus({preventScroll:!0})},[]);const D=m.useMemo(()=>Ce({routines:l.routines,webhooks:z?[]:l.webhooks,appTriggers:b.triggers,runs:l.routineRuns,bots:l.bots}),[l.routines,l.webhooks,b.triggers,l.routineRuns,l.bots,z]),E=Dt(l.bots,[...new Set([...l.sections??[],...l.bots.flatMap(s=>s.section?[s.section]:[])])]),_=E.names.length+(E.hasGeneral?1:0)>1,T=N==="all"||(N===le?E.hasGeneral:E.names.includes(N))?N:"all";m.useEffect(()=>{T!==N&&(w("all"),y("all"))},[T,N]);const u=s=>te(l.bots.find(d=>d.id===s),T),C=R.filter(s=>te(s,T)),U=D.length>=Wt&&new Set(D.map(s=>s.botId)).size>1,V=mt(D.filter(s=>u(s.botId)&&(!U||v==="all"||s.botId===v))),L=D.find(s=>s.id===j)??null,O=s=>yt(s,M(s.botId)),G=h.windowChrome==="mac-inset",se=G?{WebkitAppRegion:"drag"}:void 0,X=G?{WebkitAppRegion:"no-drag"}:void 0,J=c?.kind==="schedule"?l.routines.find(s=>s.id===c.id):void 0,K=c?.kind==="webhook"?l.webhooks.find(s=>s.id===c.id):void 0,a=c?.kind==="app"?b.triggers.find(s=>s.id===c.id):void 0;return e.jsxs("main",{className:"flex h-full min-w-0 flex-1 flex-col bg-app animate-workspace-in",children:[e.jsx("header",{className:S("shrink-0 border-b border-hairline/35 bg-app py-3 pr-4",G&&!Oe(h)&&x==="calendar"?"pl-[86px]":x==="list"?"pl-12 md:pl-4":"pl-4"),style:se,children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",ref:p,onClick:n,"aria-label":t("automations.back"),title:t("automations.back"),className:"flex size-9 shrink-0 items-center justify-center rounded-lg text-ink-secondary hover:bg-raised hover:text-ink",style:X,children:e.jsx(ht,{size:18})}),e.jsx("h1",{"data-tour":"automations-page",className:"mr-1 text-[18px] font-semibold tracking-tight text-ink",children:t("automations.title")}),e.jsxs("div",{className:"ml-auto flex items-center gap-3",style:X,children:[_&&e.jsxs(re,{size:"sm","aria-label":t("automations.allDepartments"),value:T,onChange:s=>{w(s.target.value),y("all")},className:"max-w-[180px]",children:[e.jsx("option",{value:"all",children:t("automations.allDepartments")}),E.names.map(s=>e.jsx("option",{value:s,children:s},s)),E.hasGeneral&&e.jsx("option",{value:le,children:t("automations.generalDepartment")})]}),U&&x==="list"&&e.jsxs(re,{size:"sm","aria-label":t("automations.allBots"),value:v,onChange:s=>y(s.target.value),className:"max-w-[180px]",children:[e.jsx("option",{value:"all",children:t("automations.allBots")}),C.map(s=>e.jsx("option",{value:s.id,children:s.name},s.id))]}),e.jsx("div",{role:"group","aria-label":t("automations.view"),className:"flex items-center rounded-lg border border-hairline/50 bg-panel p-0.5",children:["list","calendar"].map(s=>e.jsx("button",{type:"button","aria-pressed":x===s,onClick:()=>g({type:"showRoutines",view:s,botId:v==="all"?void 0:v}),className:S("rounded-md px-3 py-1 text-[13px] font-medium",x===s?"bg-raised text-ink shadow-sm":"text-ink-secondary hover:text-ink"),children:s==="list"?t("automations.list"):t("automations.calendar")},s))}),e.jsxs("button",{type:"button",onClick:()=>B(""),className:"flex items-center gap-1.5 rounded-lg bg-accent px-3.5 py-2 text-[13px] font-semibold text-accent-ink hover:brightness-110",children:[e.jsx(ce,{size:15,"aria-hidden":"true"}),t("automations.new")]})]})]})}),e.jsxs("div",{className:"relative flex min-h-0 flex-1",children:[x==="calendar"?e.jsx(Ot,{botFilter:v,department:T,selectedAutomationId:j,onOpenAutomation:f,onOpenRoom:r}):e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:e.jsxs("div",{className:"mx-auto w-full max-w-3xl p-4 sm:p-6",children:[e.jsx(Pt,{botFilter:U?v:"all"}),D.length===0&&l.routinesLoadState!=="loading"&&l.hydrated?e.jsxs("section",{"aria-label":t("automations.empty.title"),className:"px-6 py-16 text-center",children:[e.jsx("div",{className:"mx-auto mb-4 flex size-12 items-center justify-center rounded-2xl bg-accent/10 text-accent",children:e.jsx(bt,{size:22})}),e.jsx("h2",{className:"text-[17px] font-semibold text-ink",children:t("automations.empty.title")}),e.jsx("button",{type:"button",onClick:()=>B(t("automations.empty.example")),className:"mt-3 text-[14px] text-accent-text underline-offset-2 hover:underline",children:t("automations.empty.try")}),e.jsx("div",{children:e.jsxs("button",{type:"button",onClick:()=>B(""),className:"mt-6 inline-flex items-center gap-2 rounded-xl bg-accent px-4 py-2.5 text-[13px] font-medium text-accent-ink hover:brightness-110",children:[e.jsx(ce,{size:15}),t("automations.new")]})})]}):e.jsx("ul",{"aria-label":t("automations.title"),className:"divide-y divide-hairline/30 overflow-hidden rounded-2xl border border-hairline/40 bg-card",children:V.map(s=>{const d=de(s),P=s.name.trim(),F=s.runs.find(k=>ee(k)&&!k.seenAt),$=F&&je(F);return e.jsxs("li",{"data-automation":s.id,"data-automation-status":d.state,className:S("flex items-start gap-3 px-4 py-3.5",j===s.id&&"bg-raised/60"),children:[e.jsx(Be,{status:d,className:"mt-[5px]"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("button",{type:"button",onClick:()=>f(s.id),className:"block text-left text-[15px] font-medium leading-snug text-ink hover:text-accent-text",children:P||O(s)}),P&&e.jsx("div",{className:"mt-0.5 text-[13px] text-ink",children:O(s)}),d.state==="needs-you"?e.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-2 text-[13px] text-warning",children:[t("automations.needsYou",{reason:d.reason??""}),e.jsx(De,{automation:s,status:d,actions:o,onEdit:()=>I({kind:s.kind,id:s.id})})]}):e.jsx("div",{className:"mt-0.5 text-[13px] text-ink-secondary",children:ft(s)}),$&&e.jsxs("button",{type:"button",onClick:()=>f(s.id),className:"mt-1 flex items-baseline gap-2 text-left text-[13px] text-danger",children:[e.jsx("span",{"aria-hidden":"true",className:"size-2 shrink-0 self-center rounded-full bg-danger"}),e.jsxs("span",{children:[$.when," ",$.mark," ",$.text]})]}),o.error&&o.errorFor?.endsWith(`:${s.id}`)&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:o.error})]}),d.state!=="done"&&e.jsx(Se,{checked:s.enabled,disabled:o.busy===`toggle:${s.id}`,"aria-label":t("automations.toggle",{name:s.name}),onClick:()=>{o.toggle(s)},className:"mt-0.5 shrink-0"})]},s.id)})}),o.error&&!V.some(s=>o.errorFor?.endsWith(`:${s.id}`))&&e.jsx("p",{role:"alert",className:"mt-3 text-[12px] text-danger",children:o.error}),e.jsx(Yt,{})]})}),L&&e.jsx("div",{className:"absolute inset-y-0 right-0 z-30 flex shadow-2xl lg:static lg:shadow-none",children:e.jsx(Et,{automation:L,sentence:O(L),onClose:()=>f(null),onDeleted:()=>f(null),onEdit:()=>I({kind:L.kind,id:L.id})},L.id)})]}),A!==null&&e.jsx($t,{initialText:A,onClose:()=>B(null),onSetUpYourself:(s,d)=>{B(null),I({kind:s,botId:d})}}),c?.kind==="schedule"&&(J||!c.id)&&e.jsx(It,{routine:J,bots:ve(R,Y,J?.botId),initialBotId:c.botId,plain:!0,onClose:()=>I(null)}),c?.kind==="webhook"&&(K||!c.id)&&e.jsx(Bt,{webhook:K,bots:R,initialBotId:c.botId,onClose:()=>I(null),onCredential:(s,d)=>{gt(ke(),d,s),f(d)}}),c?.kind==="app"&&(a||!c.id)&&e.jsx(kt,{trigger:a,bots:R,initialBotId:c.botId,onClose:()=>I(null),onSaved:s=>f(s.id)})]})}function Yt(){const n=typeof window<"u"?window.ogb?.routines:void 0,[r,l]=m.useState(null),[g,h]=m.useState(!1);return m.useEffect(()=>{if(!n)return;let o=!1;const b=()=>n.wakeState().then(i=>{o||l(i)}).catch(()=>{});b();const p=window.setInterval(b,3e4);return()=>{o=!0,window.clearInterval(p)}},[n]),!n||!r?null:e.jsxs("div",{className:"mt-6 flex items-center justify-between gap-4 px-1 text-[12px] text-ink-secondary",children:[e.jsxs("span",{children:[t("automations.wake"),r.keepAwake&&r.onBattery?` ${t("automations.wakeBattery")}`:""]}),e.jsx(Se,{checked:r.keepAwake,disabled:g,"aria-label":t("automations.wake"),onClick:()=>{h(!0),n.keepAwake(!r.keepAwake).then(l).catch(()=>{}).finally(()=>h(!1))},className:"shrink-0 disabled:cursor-wait disabled:opacity-50"})]})}export{es as TriggersPage};
|
|
1
|
+
import{j as e,t,a as S,i as ie,d as he,r as m,X as be,C as fe,n as Re,S as Ae}from"./styles-CInetnea.js";import{C as Ee,K as ze,B as Te,c as Me,d as Le,P as ce,V as Oe}from"./PlacesRail-DxAWLcZN.js";import{cE as ge,cF as Pe,cG as Fe,cH as oe,X as $e,u as H,cI as We,cJ as Ye,cK as ee,cL as ye,cM as de,cN as _e,cO as ke,cP as He,cQ as Ue,cR as Ge,cS as Je,bv as Qe,cT as Ke,cU as je,cV as ue,cW as qe,cX as Ve,T as Xe,cY as Ze,cZ as et,c_ as Z,c$ as ve,cw as we,d0 as tt,d1 as ne,d2 as st,d3 as nt,d4 as Ne,j as W,d5 as Ce,d6 as at,d7 as it,d8 as ot,d9 as xe,da as rt,db as lt,dc as dt,dd as ct,w as re,C as ut,de as xt,bS as pt,df as mt,bQ as ht,dg as bt,dh as ft,S as Se,di as gt,dj as yt}from"./App-DMdy7cvM.js";import{AppEventEditor as kt}from"./AppEventEditor-BnXvgtnu.js";import{C as Ie,S as jt}from"./MenuMotion-DG3_zhAW.js";import{C as vt,E as wt,Q as Nt,b as Ct,H as St,R as It}from"./RoutinesPage-CWVJMviD.js";import{WebhookEditor as Bt}from"./WebhookTrigger-BDNVmmb9.js";import"./monitor-CHGFGy9c.js";import"./index-C3QkWpbg.js";import"./remote-desktop-DDRRx8uY.js";import"./ProIntroduction-DqqHWmYG.js";const le="\0general";function Dt(n,r){const l=n.filter(h=>!h.hidden),g=new Set(l.map(h=>h.section).filter(h=>!!h));return{names:r.filter(h=>g.has(h)),hasGeneral:l.some(h=>!h.section)}}function te(n,r){return r==="all"?!0:n?r===le?!n.section:n.section===r:!1}function Rt({trigger:n}){const{attempts:r,service:l}=ge(),g=r.filter(o=>o.triggerId===n.id).slice(-6).reverse(),h=Pe(n);return e.jsxs("section",{"data-app-events":n.id,children:[e.jsx("h3",{className:"mb-2 text-[12px] font-semibold uppercase tracking-wider text-ink-tertiary",children:t("automations.panel.events")}),h&&e.jsx("p",{className:"mb-2 rounded-lg bg-warning/10 px-2.5 py-1.5 text-[12px] text-warning",children:h}),g.length===0?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("automations.panel.noEvents")}):e.jsx("ul",{className:"space-y-1",children:g.map(o=>{const b=Fe(o),p=oe(o.at);return e.jsxs("li",{className:"flex items-baseline gap-2 px-2 py-1 text-[13px]",children:[e.jsx("span",{className:"shrink-0 text-ink-secondary",children:p.charAt(0).toLocaleUpperCase()+p.slice(1)}),e.jsx("span",{className:S("shrink-0 font-semibold",b.mark==="✓"?"text-success":b.mark==="✗"?"text-danger":"text-ink-tertiary"),children:b.mark}),e.jsx("span",{className:"min-w-0 truncate text-ink",title:b.text,children:b.text})]},o.id)})}),l?.eventsPerDay&&e.jsx("p",{className:"mt-2 text-[11px] text-ink-tertiary",children:t("automations.app.limit",{count:l.eventsPerDay.toLocaleString(ie()),place:t(l.plan==="cloud"?"automations.app.placeCloud":"automations.app.placeDesktop")})})]})}function Be({status:n,className:r}){return n.state==="needs-you"?e.jsx($e,{size:15,"aria-hidden":"true",className:S("shrink-0 text-warning",r)}):n.state==="done"?e.jsx(he,{size:14,"aria-hidden":"true",className:S("shrink-0 text-ink-tertiary",r)}):e.jsx("span",{"aria-hidden":"true",className:S("size-2.5 shrink-0 rounded-full",n.state==="working"?"bg-success":"bg-ink-tertiary/60",r)})}function De({automation:n,status:r,actions:l,onEdit:g,className:h}){const{dispatch:o}=H();if(r.state!=="needs-you"||!r.fix)return null;const b=r.fix,p=b==="answer"?We(n.runs):void 0,i=()=>{b==="answer"?l.openRun(n,p):b==="sign-in"?l.openRun(n,n.runs.find(x=>x.status!=="queued")):b==="usage"?o({type:"toggleAppSettings",open:!0,section:"usage"}):b==="edit"?g():b==="reconnect"?o({type:"togglePlugins",open:!0,surface:"apps"}):l.runNow(n)};return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:i,disabled:!!l.busy,className:S("shrink-0 rounded-lg bg-warning/15 px-2.5 py-1 text-[12px] font-medium text-warning hover:bg-warning/25 disabled:opacity-50",h),children:t(Ye[b])}),p&&e.jsx("button",{type:"button","data-automation-cancel-run":!0,onClick:()=>{l.cancelRun(n,p)},disabled:!!l.busy,className:S("shrink-0 rounded-lg px-2.5 py-1 text-[12px] text-ink-secondary hover:bg-raised hover:text-ink disabled:opacity-50",h),children:t("routines.drawer.cancelRun")})]})}const At=5,q="flex items-center justify-center gap-1.5 rounded-lg px-3 py-2 text-[13px] font-medium disabled:opacity-50";function Et({automation:n,sentence:r,onClose:l,onEdit:g,onDeleted:h}){const{state:o,dispatch:b}=H(),[p]=m.useState(()=>new Set(n.runs.filter(u=>ee(u)&&!u.seenAt).map(u=>u.id))),i=n.runs.filter((u,C)=>C<At||p.has(u.id)||ee(u)&&!u.seenAt);m.useEffect(()=>{for(const u of n.runs)ee(u)&&!u.seenAt&&b({type:"markRoutineRunSeen",runId:u.id})},[n.runs,b]);const x=ye(),j=de(n),f=n.kind==="webhook"?o.webhooks.find(u=>u.id===n.id):void 0,v=f?_e(ke())[f.id]:void 0,y=o.webhookIngress?.available!==!1,N=t(He[j.state]),w=n.name.trim(),A=o.bots.find(u=>u.id===n.botId)?.name??t("routines.unavailableBot"),B=n.instructions.trim(),c=j.state==="done"?t("automations.reason.done"):j.reason,I=f?Ue(f.id,o.webhookAttempts):[],T=f?Ge(f,o.webhookAttempts):null,[R,Y]=m.useState(null),[M,D]=m.useState(!1),[E,_]=m.useState(!1),z=async u=>{if(await ze(u)!=="copied"){x.setError(t("automations.address.copyFailed"));return}_(!0),setTimeout(()=>_(!1),1800)};return e.jsxs("aside",{"aria-label":t("automations.panel.label"),className:"flex h-full w-[min(380px,100vw)] shrink-0 flex-col border-l border-hairline/40 bg-panel",children:[e.jsxs("div",{className:"flex items-start gap-3 border-b border-hairline/40 px-5 py-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h2",{className:"text-[16px] font-semibold leading-snug text-ink",children:w||r}),w&&e.jsx("p",{className:"mt-0.5 text-[13px] text-ink-secondary",children:Je(n,A)})]}),e.jsx("button",{type:"button",onClick:l,className:"rounded-full p-1.5 text-ink-secondary hover:bg-raised hover:text-ink","aria-label":t("automations.panel.close"),children:e.jsx(be,{size:16})})]}),e.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto px-5 py-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[13px]","data-automation-status":j.state,children:[e.jsx(Be,{status:j}),e.jsx("span",{className:S("font-medium",j.state==="needs-you"?"text-warning":"text-ink"),children:N}),c&&e.jsx("span",{className:"min-w-0 text-ink-secondary",children:c}),e.jsx(De,{automation:n,status:j,actions:x,onEdit:g})]}),f&&e.jsxs("section",{className:"rounded-xl border border-hairline/45 bg-inset/50 p-3.5",children:[e.jsx("h3",{className:"text-[13px] font-medium text-ink",children:t("automations.address.title")}),e.jsxs("button",{type:"button",disabled:!!x.busy||!y,onClick:()=>{x.copyAddress(f.id)},className:S(q,"mt-2.5 bg-accent text-accent-ink hover:brightness-110"),children:[x.copied===f.id?e.jsx(he,{size:14}):e.jsx(Ee,{size:14}),x.copied===f.id?t("automations.address.copied"):t("automations.address.copy")]}),(!y||!o.config?.cloudHome)&&e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:y?t("automations.address.keepOpen"):t("automations.address.unavailable")}),e.jsxs("details",{className:"mt-2.5 text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer select-none font-medium text-ink-secondary hover:text-ink",children:t("automations.more")}),e.jsxs("div",{className:"mt-2 space-y-2 leading-relaxed",children:[T&&e.jsxs("section",{"aria-label":t("automations.received.title"),children:[e.jsxs("p",{className:"font-medium text-ink",children:[t("automations.received.title")," · ",oe(T.at)]}),e.jsx("p",{className:"mt-0.5",children:t("automations.received.help")}),e.jsx("pre",{className:"mt-1.5 max-h-40 overflow-auto whitespace-pre-wrap break-all rounded-lg bg-inset px-2.5 py-2 font-mono text-[11px] text-ink",children:T.preview.slice(0,1e3)})]}),e.jsxs("section",{"aria-label":t("automations.calls.title"),children:[e.jsx("p",{className:"font-medium text-ink",children:t("automations.calls.title")}),I.length===0?e.jsx("p",{className:"mt-0.5",children:t("automations.calls.none")}):e.jsx("ul",{className:"mt-1 space-y-0.5",children:I.map(u=>e.jsxs("li",{"data-call":u.ok?"ok":"refused",children:[e.jsxs("button",{type:"button","aria-expanded":R===u.id,onClick:()=>Y(C=>C===u.id?null:u.id),className:"flex w-full items-baseline gap-2 rounded-md px-1.5 py-1 text-left hover:bg-raised",children:[e.jsx("span",{className:"shrink-0",children:Qe(oe(u.at))}),e.jsx("span",{className:S("shrink-0 font-semibold",u.ok?"text-success":"text-danger"),children:u.ok?"✓":"✗"}),e.jsx("span",{className:"min-w-0 truncate text-ink",children:u.reason})]}),R===u.id&&e.jsx("pre",{className:"mx-1.5 mb-1 whitespace-pre-wrap break-all rounded-md bg-inset px-2 py-1.5 font-mono text-[11px] text-ink",children:u.preview||t("automations.calls.empty")})]},u.id))})]}),e.jsx("p",{className:"font-medium text-ink",children:t("automations.address.showSecret")}),v?e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1","data-secret":M?"shown":"masked",children:[e.jsx("span",{className:"min-w-0 break-all font-mono text-[11px]",children:t("automations.address.secret",{secret:M?v.secret:"••••••••"})}),e.jsx("button",{type:"button","aria-label":t(M?"automations.address.hideSecretLabel":"automations.address.showSecretLabel"),onClick:()=>D(u=>!u),className:"rounded-md px-1.5 py-0.5 font-medium text-ink hover:bg-raised",children:t(M?"automations.address.hideSecret":"automations.address.revealSecret")}),e.jsx("button",{type:"button","aria-label":t("automations.address.copySecretLabel"),onClick:()=>{z(v.secret)},className:"rounded-md px-1.5 py-0.5 font-medium text-ink hover:bg-raised",children:E?t("automations.address.copied"):t("automations.address.copySecret")})]}):e.jsx("p",{className:"break-all font-mono text-[11px]",children:t("automations.address.secretUnknown")}),e.jsx("p",{children:t("automations.address.header")}),f.eventTypes?.length?e.jsx("p",{children:t("automations.address.events",{events:f.eventTypes.join(", ")})}):null,e.jsxs("button",{type:"button",disabled:!!x.busy,onClick:()=>{window.confirm(t("automations.address.replaceConfirm"))&&x.copyAddress(f.id,!0)},className:"flex items-center gap-1.5 rounded-lg border border-hairline/50 px-2.5 py-1.5 text-ink hover:bg-raised",children:[e.jsx(Ke,{size:12}),t("automations.address.replace")]})]})]})]}),w&&B&&e.jsx("p",{"data-testid":"automation-instructions",className:"whitespace-pre-wrap break-words text-[13px] leading-relaxed text-ink",children:B}),n.appTrigger&&e.jsx(Rt,{trigger:n.appTrigger}),e.jsxs("section",{children:[e.jsx("h3",{className:"mb-2 text-[12px] font-semibold uppercase tracking-wider text-ink-tertiary",children:t("automations.panel.recent")}),n.runs.length===0?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("automations.panel.noRuns")}):e.jsx("ul",{className:"space-y-1",children:i.map(u=>{const C=je(u);return e.jsx("li",{children:e.jsxs("button",{type:"button",disabled:!u.threadId,onClick:()=>x.openRun(n,u),title:u.threadId?t("automations.panel.open"):void 0,className:"flex w-full items-baseline gap-2 rounded-lg px-2 py-1.5 text-left text-[13px] hover:bg-raised disabled:hover:bg-transparent",children:[e.jsx("span",{className:"shrink-0 text-ink-secondary",children:C.when}),e.jsx("span",{className:S("shrink-0 font-semibold",C.mark==="✓"?"text-success":C.mark==="✗"?"text-danger":"text-warning"),children:C.mark}),e.jsx("span",{className:"min-w-0 truncate text-ink",children:C.text})]})},u.id)})})]}),x.error&&e.jsx("p",{role:"alert",className:"rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:x.error})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 border-t border-hairline/40 px-5 py-3.5",children:[e.jsxs("button",{type:"button",disabled:!!x.busy,onClick:()=>{x.runNow(n)},className:S(q,"bg-accent text-accent-ink hover:brightness-110"),children:[e.jsx(ue,{size:14}),x.busy===`run:${n.id}`?t("automations.starting"):t("automations.runNow")]}),j.state!=="done"&&e.jsxs("button",{type:"button",disabled:!!x.busy,onClick:()=>{x.toggle(n)},className:S(q,"border border-hairline/50 bg-control text-ink hover:bg-raised-hover"),children:[n.enabled?e.jsx(qe,{size:14}):e.jsx(ue,{size:14}),n.enabled?t("automations.pause"):t("automations.resume")]}),e.jsxs("button",{type:"button",onClick:g,className:S(q,"text-ink hover:bg-raised"),children:[e.jsx(Ve,{size:14}),t("automations.edit")]}),e.jsxs("button",{type:"button",disabled:!!x.busy,onClick:()=>{x.remove(n,t("automations.deleteConfirm",{sentence:r})).then(u=>{u&&h()})},className:S(q,"text-danger hover:bg-danger/10"),children:[e.jsx(Xe,{size:14}),t("automations.delete")]})]})]})}const zt=()=>Array.from({length:7},(n,r)=>new Intl.DateTimeFormat(Re(),{weekday:"narrow",timeZone:"UTC"}).format(Date.UTC(2023,0,2+r)));function ae(n){const r=new Date(n);return new Date(r.getFullYear(),r.getMonth(),1)}function pe(n,r){return n.getFullYear()===r.getFullYear()&&n.getMonth()===r.getMonth()&&n.getDate()===r.getDate()}function me(n,r){return new Date(n.getFullYear(),n.getMonth()+r,1)}function Tt({anchor:n,onSelect:r}){const[l,g]=m.useState(()=>ae(n));m.useEffect(()=>{g(ae(n))},[n]);const h=m.useMemo(()=>{const i=ae(l),x=(i.getDay()+6)%7,j=new Date(i);return j.setDate(i.getDate()-x),Array.from({length:42},(f,v)=>{const y=new Date(j);return y.setDate(j.getDate()+v),y})},[l]),o=new Date(n),b=new Date,p=l.toLocaleDateString(ie(),{month:"long",year:"numeric"});return e.jsxs("section",{"aria-label":t("routines.miniCalendar.label"),className:"select-none px-3 py-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between px-1",children:[e.jsx("div",{className:"text-[13px] font-semibold text-ink",children:p}),e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsx("button",{type:"button",onClick:()=>g(i=>me(i,-1)),className:"flex size-7 items-center justify-center rounded-full text-ink-secondary transition-colors hover:bg-raised hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/60","aria-label":t("routines.miniCalendar.previous"),children:e.jsx(fe,{size:15,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>g(i=>me(i,1)),className:"flex size-7 items-center justify-center rounded-full text-ink-secondary transition-colors hover:bg-raised hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/60","aria-label":t("routines.miniCalendar.next"),children:e.jsx(Ie,{size:15,"aria-hidden":"true"})})]})]}),e.jsx("div",{className:"grid grid-cols-7","aria-hidden":"true",children:zt().map((i,x)=>e.jsx("div",{className:"flex h-6 items-center justify-center text-[9px] font-semibold uppercase tracking-[0.08em] text-ink-tertiary",children:i},`${i}-${x}`))}),e.jsx("div",{className:"grid grid-cols-7 gap-y-0.5",children:h.map(i=>{const x=pe(i,o),j=pe(i,b),f=i.getMonth()!==l.getMonth(),v=i.toLocaleDateString(ie(),{weekday:"long",month:"long",day:"numeric",year:"numeric"});return e.jsx("button",{type:"button",onClick:()=>r(i.getTime()),"aria-label":v,"aria-current":j?"date":void 0,"aria-pressed":x,className:"group flex h-7 items-center justify-center rounded-full focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/60",children:e.jsx("span",{className:`flex size-6 items-center justify-center rounded-full text-[11px] transition-colors ${x?"bg-accent font-semibold text-white shadow-sm":j?"font-semibold text-accent group-hover:bg-accent/12":f?"text-ink-tertiary group-hover:bg-raised group-hover:text-ink":"text-ink group-hover:bg-raised"}`,children:i.getDate()})},`${i.getFullYear()}-${i.getMonth()}-${i.getDate()}`)})})]})}const Mt="application/x-openmaus-bot";function Lt({bots:n,anchor:r,onSelectDate:l}){const[g,h]=m.useState(""),o=m.useMemo(()=>{const p=g.trim().toLocaleLowerCase();return p?n.filter(i=>`${i.name} ${i.title} ${i.description}`.toLocaleLowerCase().includes(p)):n},[n,g]),b=(p,i)=>{p.dataTransfer.effectAllowed="copy",p.dataTransfer.setData(Mt,i.id),p.dataTransfer.setData("text/plain",i.id)};return e.jsxs("aside",{"aria-label":t("routines.sidebar.label"),className:"flex h-full w-[320px] shrink-0 flex-col overflow-hidden border-r border-hairline/40 bg-panel",children:[e.jsx(Tt,{anchor:r,onSelect:l}),e.jsx("div",{className:"mx-4 border-t border-hairline/40"}),e.jsxs("section",{"aria-labelledby":"calendar-bots-heading",className:"flex min-h-0 flex-1 flex-col px-3 pb-3 pt-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between px-1",children:[e.jsxs("div",{id:"calendar-bots-heading",className:"flex items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.11em] text-ink-secondary",children:[e.jsx(Ze,{size:13,"aria-hidden":"true"}),t("routines.sidebar.myBots")]}),e.jsx("span",{className:"rounded-full bg-raised px-1.5 py-0.5 text-[9px] tabular-nums text-ink-secondary",children:n.length})]}),e.jsxs("label",{className:"relative mb-2 block",children:[e.jsx("span",{className:"sr-only",children:t("routines.sidebar.searchBots")}),e.jsx(Ae,{size:13,className:"pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2 text-ink-tertiary","aria-hidden":"true"}),e.jsx("input",{value:g,onChange:p=>h(p.target.value),type:"search",placeholder:t("routines.sidebar.searchBots"),className:"h-8 w-full rounded-lg border border-hairline/45 bg-control/55 pl-8 pr-2.5 text-[12px] text-ink outline-none placeholder:text-ink-tertiary focus:border-accent/60 focus:bg-control"})]}),e.jsxs("div",{role:"list","aria-label":t("routines.sidebar.availableBots"),className:"min-h-0 flex-1 space-y-0.5 overflow-y-auto pr-0.5",children:[o.map(p=>e.jsxs("div",{draggable:!0,onDragStart:i=>b(i,p),role:"listitem",className:"group flex cursor-grab items-center gap-2 rounded-xl px-2 py-2 transition-colors hover:bg-raised/80 active:cursor-grabbing","aria-label":t("routines.sidebar.dragBot",{name:p.name}),title:t("routines.sidebar.dragBot",{name:p.name}),children:[e.jsx(et,{size:13,className:"shrink-0 text-ink-secondary/35 transition-colors group-hover:text-ink-secondary","aria-hidden":"true"}),e.jsx(Te,{bot:p,size:27,animated:!1}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[12px] font-medium text-ink",children:p.name}),e.jsx("div",{className:"truncate text-[10px] text-ink-tertiary",children:p.title||t("routines.sidebar.botFallback")})]}),e.jsx("span",{className:"shrink-0 rounded-full border border-hairline/50 px-1.5 py-0.5 text-[9px] text-ink-tertiary opacity-0 transition-opacity group-hover:opacity-100",children:t("routines.sidebar.drag")})]},p.id)),o.length===0&&e.jsx("div",{className:"px-3 py-8 text-center text-[11px] leading-relaxed text-ink-secondary",children:n.length===0?t("routines.sidebar.noBots"):t("routines.sidebar.noMatch")})]}),e.jsx("p",{className:"mt-2 px-2 text-[10px] leading-relaxed text-ink-tertiary",children:t("routines.sidebar.dragHint")})]})]})}function Ot({botFilter:n,department:r="all",selectedAutomationId:l,onOpenAutomation:g,onOpenRoom:h}){const{state:o,dispatch:b}=H(),p=window.ogb?.remoteClient?.active===!0,[i,x]=m.useState(()=>window.innerWidth<640?1:7),[j,f]=m.useState(()=>Z(Date.now())),[v,y]=m.useState([]),[N,w]=m.useState(null),[A,B]=m.useState(null),[c,I]=m.useState(null),[T,R]=m.useState(""),Y=o.bots.filter(a=>!a.hidden),M=ve(Y,we(),A?.botIds[0]),D=i===7?tt(j):Z(j),E=ne(D,i);st(D);const _=nt(Ne(),D,E),z=m.useCallback(async()=>{try{y((await W("/api/calendar-calls")).calls??[])}catch(a){R(a instanceof Error?a.message:String(a))}},[]);m.useEffect(()=>{p||z()},[z,p]);const u=m.useMemo(()=>{const a=new Set(o.bots.map(k=>k.id)),s=o.routines.filter(k=>a.has(k.botId)),d=new Set(Ce({routines:s,webhooks:[],runs:o.routineRuns}).filter(k=>de(k).state==="needs-you").map(k=>k.id)),P=at(s,o.routineRuns.filter(k=>a.has(k.botId)),D,E).map(k=>({...k,kind:"routine",needsYou:!!(k.routine&&!k.run&&d.has(k.routine.id))})),F=it(v,D,E).map(k=>({...k,kind:"call"})),$=k=>o.bots.find(K=>K.id===k);return[...P,...F].filter(k=>k.kind==="call"?k.call.botIds.some(K=>te($(K),r)):te($(k.routine?.botId??k.run?.botId),r)).filter(k=>n==="all"||(k.kind==="call"?k.call.botIds.includes(n):(k.routine?.botId??k.run?.botId)===n)).sort((k,K)=>k.at-K.at)},[o.routines,o.routineRuns,o.bots,v,D,E,n,r]),C=c?.kind==="call"?(()=>{const a=v.find(s=>s.id===c.call.id);return a?{...c,call:a}:null})():null,U=a=>{if(a.kind==="call"){I(a);return}I(null);const s=a.routine?.id??a.run?.routineId;s&&g(s)},V=a=>g(a.routineId),L=C?.id??u.find(a=>a.kind==="routine"&&(a.routine?.id??a.run?.routineId)===l)?.id,O=a=>y(s=>s.some(d=>d.id===a.id)?s.map(d=>d.id===a.id?a:d):[a,...s]),G=async(a,s)=>{if(s!==a.at)try{if(a.kind==="routine"){const d=o.routines.find(F=>F.id===a.id);if(!d)return;if(d.schedule.type==="cron")throw new Error(t("automations.calendar.cronMove"));if(d.schedule.type!=="once"&&!window.confirm(t("automations.calendar.moveSeries")))return;const P=await W(`/api/routines/${d.id}`,{method:"PATCH",body:JSON.stringify({schedule:xe(d.schedule,a.at,s)})});b({type:"routinePatched",routine:P.routine})}else{const d=v.find(F=>F.id===a.id);if(!d||d.schedule.type==="daily"&&!window.confirm(t("automations.calendar.moveSeries")))return;const P=await W(`/api/calendar-calls/${d.id}`,{method:"PATCH",body:JSON.stringify({schedule:xe(d.schedule,a.at,s)})});O(P.call)}}catch(d){R(d instanceof Error?d.message:String(d))}},se=async(a,s)=>{if("botId"in a){I(null),w({kind:"routine",at:s.at,durationMinutes:30,botIds:[a.botId],limitReset:{engine:s.engine}});return}if(a.event.kind!=="routine")return R(t("limits.callNotOnReset"));try{const d=await W(`/api/routines/${a.event.id}`,{method:"PATCH",body:JSON.stringify({schedule:{type:"limit_reset",engine:s.engine,repeat:"once"}})});b({type:"routinePatched",routine:d.routine})}catch(d){R(d instanceof Error?d.message:String(d))}},X=async(a,s)=>{try{if(a.kind==="routine"&&a.routine){const d=await W(`/api/routines/${a.routine.id}`,{method:"PATCH",body:JSON.stringify({durationMinutes:s})});b({type:"routinePatched",routine:d.routine})}else if(a.kind==="call"){const d=await W(`/api/calendar-calls/${a.call.id}`,{method:"PATCH",body:JSON.stringify({durationMinutes:s})});O(d.call)}}catch(d){R(d instanceof Error?d.message:String(d))}},J=()=>{C&&(B({kind:"call",at:C.at,durationMinutes:C.call.durationMinutes,botIds:C.call.botIds,call:C.call}),I(null))},Q=a=>S("rounded-md px-3 py-1 text-[12px] font-medium",a?"bg-raised text-ink shadow-sm":"text-ink-secondary hover:text-ink");return e.jsxs("div",{className:"@container/routines relative flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b border-hairline/30 px-4 py-2",children:[e.jsx("button",{type:"button",onClick:()=>f(a=>ne(a,-i)),className:"rounded-md p-1.5 text-ink-secondary hover:bg-raised hover:text-ink","aria-label":t("routines.previous"),children:e.jsx(fe,{size:16})}),e.jsx("button",{type:"button",onClick:()=>f(a=>ne(a,i)),className:"rounded-md p-1.5 text-ink-secondary hover:bg-raised hover:text-ink","aria-label":t("routines.next"),children:e.jsx(Ie,{size:16})}),e.jsx("div",{className:"min-w-0 truncate px-1 text-[14px] font-medium text-ink","aria-live":"polite",children:ot(D,i)}),e.jsx("button",{type:"button",onClick:()=>f(Z(Date.now())),className:"rounded-lg border border-hairline/50 px-2.5 py-1 text-[12px] font-medium text-ink hover:bg-raised",children:t("routines.today")}),e.jsxs("div",{role:"group",className:"ml-auto flex items-center rounded-lg border border-hairline/50 bg-panel p-0.5","aria-label":t("routines.view.label"),children:[e.jsx("button",{type:"button","aria-pressed":i===1,onClick:()=>x(1),className:Q(i===1),children:t("routines.view.day")}),e.jsx("button",{type:"button","aria-pressed":i===7,onClick:()=>x(7),className:Q(i===7),children:t("routines.view.week")})]}),T&&e.jsx("button",{type:"button",onClick:()=>R(""),className:"w-full text-left text-[12px] text-danger",children:T})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-1",children:[!C&&e.jsx("div",{className:"hidden shrink-0 @min-[1040px]/routines:block",children:e.jsx(Lt,{bots:Y,anchor:j,onSelectDate:a=>f(Z(a))})}),e.jsx(vt,{anchor:D,days:i,items:u,bots:o.bots,groups:o.groups,selectedId:L,onOpen:U,onCreate:a=>{I(null),w(a)},onMove:(a,s)=>{G(a,s)},onResize:(a,s)=>{X(a,s)},markers:_,onDropOnReset:(a,s)=>{se(a,s)}}),C&&e.jsx("div",{className:"absolute inset-y-0 right-0 z-30 flex shadow-2xl @min-[760px]/routines:static @min-[760px]/routines:shadow-none",children:e.jsx(wt,{item:C,bots:o.bots,onClose:()=>I(null),onEdit:J,onOpenRun:V,onCallChanged:a=>{a?y(s=>s.filter(d=>d.id!==a)):z()},onOpenRoom:h},`${C.kind}:${C.id}`)})]}),N&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40 bg-black/25",onMouseDown:()=>w(null)}),e.jsx(Nt,{seed:N,bots:M,routinesOnly:p,onClose:()=>w(null),onMore:a=>{w(null),B(a)},onSavedRoutine:a=>b({type:"routinePatched",routine:a}),onSavedCall:O})]}),A&&e.jsx(Ct,{seed:A,bots:M,routinesOnly:p,onClose:()=>B(null),onSavedCall:O})]})}function Pt({botFilter:n="all"}){const{state:r,dispatch:l}=H(),g=rt(Ne()),[h,o]=m.useState(null),[b,p]=m.useState(null),[i,x]=m.useState("");if(!g.length)return null;const j=y=>r.bots.find(N=>N.id===y)?.modelSelection?.instanceId,f=r.routines.filter(y=>n==="all"||y.botId===n),v=async(y,N)=>{o(y.engine),x("");try{for(const w of N){const A=await W("/api/limit-resets/after-reset",{method:"POST",body:JSON.stringify({routineId:w.id,engine:y.engine})});l({type:"routinePatched",routine:A.routine})}p(y.engine)}catch(w){x(w instanceof Error?w.message:String(w))}finally{o(null)}};return e.jsxs("section",{"aria-label":t("limits.title"),className:"mb-4 space-y-2",children:[g.map(y=>{const N=lt(f,j,y);return e.jsxs("div",{"data-limit-warning":y.engine,role:"status",className:"flex flex-wrap items-center gap-x-2.5 gap-y-1.5 rounded-xl border border-warning/40 bg-warning/10 px-3.5 py-2.5 text-[13px] text-ink",children:[e.jsx(St,{size:15,className:"shrink-0 text-warning","aria-hidden":"true"}),e.jsx("span",{className:"font-medium tabular-nums",children:dt(y)}),N.length>0?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-ink-secondary",children:t(N.length===1?"limits.dueOne":"limits.dueMany",{count:N.length})}),e.jsx("button",{type:"button",disabled:h===y.engine,onClick:()=>{v(y,N)},className:"ml-auto rounded-lg bg-accent px-3 py-1.5 text-[13px] font-medium text-accent-ink hover:brightness-110 disabled:opacity-50",children:t("limits.moveAfterReset")})]}):b===y.engine&&e.jsx("span",{className:"text-ink-secondary",children:t("limits.moved")})]},y.engine)}),i&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:i})]})}function Ft(n,r){const l=n.find(h=>h.id===r);if(l)return l;const g=h=>h.messages.at(-1)?.at??0;return[...n].sort((h,o)=>g(o)-g(h))[0]}function $t({initialText:n="",onClose:r,onSetUpYourself:l}){const{state:g,dispatch:h}=H(),o=g.bots.filter(c=>!c.hidden),[b,p]=m.useState(n),[i,x]=m.useState(()=>Ft(o,g.selectedId)?.id??""),[j,f]=m.useState(!1),[v,y]=m.useState("schedule"),N=m.useRef(null);Me(N,r);const w=o.find(c=>c.id===i),A=()=>{const c=b.trim();!c||!w||(h({type:"select",id:w.id}),h({type:"send",botId:w.id,text:c,threadId:w.threadId}),r())},B=(c,I,T)=>e.jsxs("button",{type:"button",role:"radio","aria-checked":v===c,onClick:()=>y(c),className:S("flex w-full items-center gap-3 rounded-xl border px-3.5 py-3 text-left text-[14px]",v===c?"border-accent/70 bg-accent/10 text-ink":"border-hairline/50 text-ink-secondary hover:bg-raised"),children:[e.jsx(T,{size:16,className:"shrink-0 text-accent"}),I]});return e.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/50 p-5 pt-[14vh] backdrop-blur-sm",onMouseDown:c=>c.stopPropagation(),children:e.jsxs("div",{ref:N,role:"dialog","aria-modal":"true","aria-label":t("automations.newBox.title"),tabIndex:-1,className:"w-full max-w-[560px] rounded-2xl border border-hairline/60 bg-panel p-5 shadow-2xl",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("h2",{className:"text-[17px] font-semibold text-ink",children:j?t("automations.newBox.when"):t("automations.newBox.title")}),e.jsx("button",{type:"button",onClick:r,"aria-label":t("automations.newBox.cancel"),className:"rounded-full p-1.5 text-ink-secondary hover:bg-raised hover:text-ink",children:e.jsx(be,{size:16})})]}),j?e.jsxs(e.Fragment,{children:[e.jsxs("div",{role:"radiogroup","aria-label":t("automations.newBox.when"),className:"mt-4 space-y-2",children:[B("schedule",t("automations.newBox.onSchedule"),ut),B("app",t("automations.newBox.whenAppEvent"),xt),B("webhook",t("automations.newBox.whenApp"),pt)]}),e.jsxs("div",{className:"mt-5 flex items-center justify-between gap-2",children:[e.jsx("button",{type:"button",onClick:()=>f(!1),className:"rounded-lg px-2 py-1.5 text-[13px] text-ink-secondary hover:bg-raised hover:text-ink",children:t("automations.newBox.back")}),e.jsx("button",{type:"button",onClick:()=>l(v,w?.id??""),className:"rounded-xl bg-accent px-4 py-2 text-[13px] font-medium text-accent-ink hover:brightness-110",children:t("automations.newBox.continue")})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("textarea",{autoFocus:!0,value:b,onChange:c=>p(c.target.value),rows:3,"aria-label":t("automations.newBox.title"),placeholder:t("automations.newBox.placeholder"),onKeyDown:c=>{c.key==="Enter"&&!c.shiftKey&&!ct(c.nativeEvent)&&(c.preventDefault(),A())},className:"mt-4 w-full resize-none rounded-xl border border-hairline/60 bg-inset px-3.5 py-3 text-[14px] leading-relaxed text-ink outline-none placeholder:text-ink-tertiary focus:border-accent/70"}),o.length===0&&e.jsx("p",{className:"mt-2 text-[13px] text-warning",children:t("automations.newBox.noBots")}),o.length>1&&e.jsxs("label",{className:"mt-3 flex items-center gap-2 text-[13px] text-ink-secondary",children:[t("automations.newBox.bot"),e.jsx(re,{size:"sm",value:i,onChange:c=>x(c.target.value),"aria-label":t("automations.newBox.bot"),className:"max-w-[220px]",children:o.map(c=>e.jsx("option",{value:c.id,children:c.name},c.id))})]}),e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2",children:[e.jsx("button",{type:"button",onClick:()=>f(!0),className:"rounded-lg px-2 py-1.5 text-[13px] text-ink-secondary underline-offset-2 hover:text-ink hover:underline",children:t("automations.newBox.yourself")}),e.jsxs("button",{type:"button",disabled:!b.trim()||!w,onClick:A,className:"flex items-center gap-2 rounded-xl bg-accent px-4 py-2 text-[13px] font-medium text-accent-ink hover:brightness-110 disabled:opacity-40",children:[e.jsx(jt,{size:14}),t("automations.newBox.send")]})]})]})]})})}const Wt=9;function es({onBack:n,onOpenRoom:r}){const{state:l,dispatch:g}=H(),{capabilities:h}=Le(),o=ye(),b=ge(),p=m.useRef(null),i=l.routinesFocus,x=i?.view==="calendar"?"calendar":"list",[j,f]=m.useState(i?.section!=="logs"?i?.routineId??null:null),[v,y]=m.useState(i?.botId??"all"),[N,w]=m.useState("all"),[A,B]=m.useState(null),[c,I]=m.useState(null),T=window.ogb?.remoteClient?.active===!0,R=l.bots.filter(s=>!s.hidden),Y=we(),M=s=>l.bots.find(d=>d.id===s)?.name??t("routines.unavailableBot");m.useEffect(()=>{y(i?.botId??"all"),i?.routineId&&i.section!=="logs"&&f(i.routineId)},[i]),m.useEffect(()=>{p.current?.focus({preventScroll:!0})},[]);const D=m.useMemo(()=>Ce({routines:l.routines,webhooks:T?[]:l.webhooks,appTriggers:b.triggers,runs:l.routineRuns,bots:l.bots}),[l.routines,l.webhooks,b.triggers,l.routineRuns,l.bots,T]),E=Dt(l.bots,[...new Set([...l.sections??[],...l.bots.flatMap(s=>s.section?[s.section]:[])])]),_=E.names.length+(E.hasGeneral?1:0)>1,z=N==="all"||(N===le?E.hasGeneral:E.names.includes(N))?N:"all";m.useEffect(()=>{z!==N&&(w("all"),y("all"))},[z,N]);const u=s=>te(l.bots.find(d=>d.id===s),z),C=R.filter(s=>te(s,z)),U=D.length>=Wt&&new Set(D.map(s=>s.botId)).size>1,V=mt(D.filter(s=>u(s.botId)&&(!U||v==="all"||s.botId===v))),L=D.find(s=>s.id===j)??null,O=s=>yt(s,M(s.botId)),G=h.windowChrome==="mac-inset",se=G?{WebkitAppRegion:"drag"}:void 0,X=G?{WebkitAppRegion:"no-drag"}:void 0,J=c?.kind==="schedule"?l.routines.find(s=>s.id===c.id):void 0,Q=c?.kind==="webhook"?l.webhooks.find(s=>s.id===c.id):void 0,a=c?.kind==="app"?b.triggers.find(s=>s.id===c.id):void 0;return e.jsxs("main",{className:"flex h-full min-w-0 flex-1 flex-col bg-app animate-workspace-in",children:[e.jsx("header",{className:S("shrink-0 border-b border-hairline/35 bg-app py-3 pr-4",G&&!Oe(h)&&x==="calendar"?"pl-[86px]":x==="list"?"pl-12 md:pl-4":"pl-4"),style:se,children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",ref:p,onClick:n,"aria-label":t("automations.back"),title:t("automations.back"),className:"flex size-9 shrink-0 items-center justify-center rounded-lg text-ink-secondary hover:bg-raised hover:text-ink",style:X,children:e.jsx(ht,{size:18})}),e.jsx("h1",{"data-tour":"automations-page",className:"mr-1 text-[18px] font-semibold tracking-tight text-ink",children:t("automations.title")}),e.jsxs("div",{className:"ml-auto flex items-center gap-3",style:X,children:[_&&e.jsxs(re,{size:"sm","aria-label":t("automations.allDepartments"),value:z,onChange:s=>{w(s.target.value),y("all")},className:"max-w-[180px]",children:[e.jsx("option",{value:"all",children:t("automations.allDepartments")}),E.names.map(s=>e.jsx("option",{value:s,children:s},s)),E.hasGeneral&&e.jsx("option",{value:le,children:t("automations.generalDepartment")})]}),U&&x==="list"&&e.jsxs(re,{size:"sm","aria-label":t("automations.allBots"),value:v,onChange:s=>y(s.target.value),className:"max-w-[180px]",children:[e.jsx("option",{value:"all",children:t("automations.allBots")}),C.map(s=>e.jsx("option",{value:s.id,children:s.name},s.id))]}),e.jsx("div",{role:"group","aria-label":t("automations.view"),className:"flex items-center rounded-lg border border-hairline/50 bg-panel p-0.5",children:["list","calendar"].map(s=>e.jsx("button",{type:"button","aria-pressed":x===s,onClick:()=>g({type:"showRoutines",view:s,botId:v==="all"?void 0:v}),className:S("rounded-md px-3 py-1 text-[13px] font-medium",x===s?"bg-raised text-ink shadow-sm":"text-ink-secondary hover:text-ink"),children:s==="list"?t("automations.list"):t("automations.calendar")},s))}),e.jsxs("button",{type:"button",onClick:()=>B(""),className:"flex items-center gap-1.5 rounded-lg bg-accent px-3.5 py-2 text-[13px] font-semibold text-accent-ink hover:brightness-110",children:[e.jsx(ce,{size:15,"aria-hidden":"true"}),t("automations.new")]})]})]})}),e.jsxs("div",{className:"relative flex min-h-0 flex-1",children:[x==="calendar"?e.jsx(Ot,{botFilter:v,department:z,selectedAutomationId:j,onOpenAutomation:f,onOpenRoom:r}):e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:e.jsxs("div",{className:"mx-auto w-full max-w-3xl p-4 sm:p-6",children:[e.jsx(Pt,{botFilter:U?v:"all"}),D.length===0&&l.routinesLoadState!=="loading"&&l.hydrated?e.jsxs("section",{"aria-label":t("automations.empty.title"),className:"px-6 py-16 text-center",children:[e.jsx("div",{className:"mx-auto mb-4 flex size-12 items-center justify-center rounded-2xl bg-accent/10 text-accent",children:e.jsx(bt,{size:22})}),e.jsx("h2",{className:"text-[17px] font-semibold text-ink",children:t("automations.empty.title")}),e.jsx("button",{type:"button",onClick:()=>B(t("automations.empty.example")),className:"mt-3 text-[14px] text-accent-text underline-offset-2 hover:underline",children:t("automations.empty.try")}),e.jsx("div",{children:e.jsxs("button",{type:"button",onClick:()=>B(""),className:"mt-6 inline-flex items-center gap-2 rounded-xl bg-accent px-4 py-2.5 text-[13px] font-medium text-accent-ink hover:brightness-110",children:[e.jsx(ce,{size:15}),t("automations.new")]})})]}):e.jsx("ul",{"aria-label":t("automations.title"),className:"divide-y divide-hairline/30 overflow-hidden rounded-2xl border border-hairline/40 bg-card",children:V.map(s=>{const d=de(s),P=s.name.trim(),F=s.runs.find(k=>ee(k)&&!k.seenAt),$=F&&je(F);return e.jsxs("li",{"data-automation":s.id,"data-automation-status":d.state,className:S("flex items-start gap-3 px-4 py-3.5",j===s.id&&"bg-raised/60"),children:[e.jsx(Be,{status:d,className:"mt-[5px]"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("button",{type:"button",onClick:()=>f(s.id),className:"block text-left text-[15px] font-medium leading-snug text-ink hover:text-accent-text",children:P||O(s)}),P&&e.jsx("div",{className:"mt-0.5 text-[13px] text-ink",children:O(s)}),d.state==="needs-you"?e.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-2 text-[13px] text-warning",children:[t("automations.needsYou",{reason:d.reason??""}),e.jsx(De,{automation:s,status:d,actions:o,onEdit:()=>I({kind:s.kind,id:s.id})})]}):e.jsx("div",{className:"mt-0.5 text-[13px] text-ink-secondary",children:ft(s)}),$&&e.jsxs("button",{type:"button",onClick:()=>f(s.id),className:"mt-1 flex items-baseline gap-2 text-left text-[13px] text-danger",children:[e.jsx("span",{"aria-hidden":"true",className:"size-2 shrink-0 self-center rounded-full bg-danger"}),e.jsxs("span",{children:[$.when," ",$.mark," ",$.text]})]}),o.error&&o.errorFor?.endsWith(`:${s.id}`)&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:o.error})]}),d.state!=="done"&&e.jsx(Se,{checked:s.enabled,disabled:o.busy===`toggle:${s.id}`,"aria-label":t("automations.toggle",{name:s.name}),onClick:()=>{o.toggle(s)},className:"mt-0.5 shrink-0"})]},s.id)})}),o.error&&!V.some(s=>o.errorFor?.endsWith(`:${s.id}`))&&e.jsx("p",{role:"alert",className:"mt-3 text-[12px] text-danger",children:o.error}),e.jsx(Yt,{})]})}),L&&e.jsx("div",{className:"absolute inset-y-0 right-0 z-30 flex shadow-2xl lg:static lg:shadow-none",children:e.jsx(Et,{automation:L,sentence:O(L),onClose:()=>f(null),onDeleted:()=>f(null),onEdit:()=>I({kind:L.kind,id:L.id})},L.id)})]}),A!==null&&e.jsx($t,{initialText:A,onClose:()=>B(null),onSetUpYourself:(s,d)=>{B(null),I({kind:s,botId:d})}}),c?.kind==="schedule"&&(J||!c.id)&&e.jsx(It,{routine:J,bots:ve(R,Y,J?.botId),initialBotId:c.botId,plain:!0,onClose:()=>I(null)}),c?.kind==="webhook"&&(Q||!c.id)&&e.jsx(Bt,{webhook:Q,bots:R,initialBotId:c.botId,onClose:()=>I(null),onCredential:(s,d)=>{gt(ke(),d,s),f(d)}}),c?.kind==="app"&&(a||!c.id)&&e.jsx(kt,{trigger:a,bots:R,initialBotId:c.botId,onClose:()=>I(null),onSaved:s=>f(s.id)})]})}function Yt(){const n=typeof window<"u"?window.ogb?.routines:void 0,[r,l]=m.useState(null),[g,h]=m.useState(!1);return m.useEffect(()=>{if(!n)return;let o=!1;const b=()=>n.wakeState().then(i=>{o||l(i)}).catch(()=>{});b();const p=window.setInterval(b,3e4);return()=>{o=!0,window.clearInterval(p)}},[n]),!n||!r?null:e.jsxs("div",{className:"mt-6 flex items-center justify-between gap-4 px-1 text-[12px] text-ink-secondary",children:[e.jsxs("span",{children:[t("automations.wake"),r.keepAwake&&r.onBattery?` ${t("automations.wakeBattery")}`:""]}),e.jsx(Se,{checked:r.keepAwake,disabled:g,"aria-label":t("automations.wake"),onClick:()=>{h(!0),n.keepAwake(!r.keepAwake).then(l).catch(()=>{}).finally(()=>h(!1))},className:"shrink-0 disabled:cursor-wait disabled:opacity-50"})]})}export{es as TriggersPage};
|