openmausbot 0.1.96 → 0.1.98

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/dist/assets/ActivityPanel-H6D3SD39.js +1 -0
  2. package/dist/assets/BotSettingsDialog-Dqz_AiBZ.js +7 -0
  3. package/dist/assets/CloudBackendPicker-iezpJFpF.js +1 -0
  4. package/dist/assets/ComputerPanel-DZPj-IWu.js +1 -0
  5. package/dist/assets/DesktopViewer-utONms1p.js +5 -0
  6. package/dist/assets/InspectorPanel-OVaBVrzC.js +5 -0
  7. package/dist/assets/KeyboardShortcutsModal-gk9mvHj_.js +1 -0
  8. package/dist/assets/LocalVmWorkspace-DLIvd2kC.js +1 -0
  9. package/dist/assets/MacLocalControl-bJv8yiPB.js +1 -0
  10. package/dist/assets/NewBotDialog-1qGOAdUM.js +2 -0
  11. package/dist/assets/RemoteAgentSettingsPanel-DqKr0HkO.js +1 -0
  12. package/dist/assets/RoutinesPage-BM2D4qGi.js +1 -0
  13. package/dist/assets/RoutinesSection-Dny9ra-c.js +1 -0
  14. package/dist/assets/SettingsModal-gC6XJJmt.js +11 -0
  15. package/dist/assets/TeamMapPage-B6fuu4r_.js +8 -0
  16. package/dist/assets/TriggersPanel-j0qTP2CO.js +1 -0
  17. package/dist/assets/VisibilitySection-DT0FqPvu.js +12 -0
  18. package/dist/assets/WebhooksPanel--YQyCjKO.js +3 -0
  19. package/dist/assets/{abnfDiagram-O67JEVCF-Dkbd2hcj.js → abnfDiagram-O67JEVCF-BsjcFX0-.js} +1 -1
  20. package/dist/assets/activity-BxOkayvD.js +1 -0
  21. package/dist/assets/{arc-Duj5Coy2.js → arc-CJNA94c6.js} +1 -1
  22. package/dist/assets/architectureDiagram-NJMV4G6O-dz2ud7lP.js +36 -0
  23. package/dist/assets/{blockDiagram-BEXU5L5S-CWDlTpXe.js → blockDiagram-BEXU5L5S-ChBEALoR.js} +1 -1
  24. package/dist/assets/brain-CFZ7PEXc.js +1 -0
  25. package/dist/assets/{c4Diagram-YGBWAQC7-B0t15PDc.js → c4Diagram-YGBWAQC7-KZNRKDQe.js} +1 -1
  26. package/dist/assets/channel-WhFyujhZ.js +1 -0
  27. package/dist/assets/{chunk-2Q5K7J3B-BJSCL-HV.js → chunk-2Q5K7J3B-BLLwmCET.js} +1 -1
  28. package/dist/assets/{chunk-3FUC2YCW-D3_ILccd.js → chunk-3FUC2YCW-CQxyreBZ.js} +2 -2
  29. package/dist/assets/{chunk-5VM5RSS4-D3dmwT_S.js → chunk-5VM5RSS4-D6sFMW0u.js} +1 -1
  30. package/dist/assets/{chunk-GTNCS2PH-Br73HFPD.js → chunk-GTNCS2PH-BaZ1YgLF.js} +1 -1
  31. package/dist/assets/{chunk-GWA4HPMP-uSsjxubC.js → chunk-GWA4HPMP-CcalphmC.js} +1 -1
  32. package/dist/assets/{chunk-JWPE2WC7-C40VWFyr.js → chunk-JWPE2WC7-CSk8R3ve.js} +1 -1
  33. package/dist/assets/{chunk-NETBCI7D-D6WNNYwU.js → chunk-NETBCI7D-CTmLjA57.js} +1 -1
  34. package/dist/assets/{chunk-WEXAMYUT-DOEhq64P.js → chunk-WEXAMYUT-CM9Z77Ne.js} +1 -1
  35. package/dist/assets/{chunk-XXDRQBXY-BqJEi6Pi.js → chunk-XXDRQBXY-B1fxpMS2.js} +1 -1
  36. package/dist/assets/{classDiagram-v2-NBCMYWYE-ByU_GnxT.js → classDiagram-v2-NBCMYWYE-DCCyoLpj.js} +1 -1
  37. package/dist/assets/computer-control-NLov352p.js +1 -0
  38. package/dist/assets/cose-bilkent-JH36ORCC-KyImBKvE.js +1 -0
  39. package/dist/assets/{cynefin-OW5HDTMX-CZWO7aYj.js → cynefin-OW5HDTMX-fsZc6MGa.js} +1 -1
  40. package/dist/assets/{cynefinDiagram-VND7K2PF-C70-w0la.js → cynefinDiagram-VND7K2PF-CGmHsShB.js} +1 -1
  41. package/dist/assets/{dagre-6A5THRUB-CnhjhExB.js → dagre-6A5THRUB-Dah1h-CH.js} +1 -1
  42. package/dist/assets/{diagram-22UHCM2B-bnjWCNb4.js → diagram-22UHCM2B-BIu71OyV.js} +1 -1
  43. package/dist/assets/{diagram-3UASUU5V-A4uTWoFV.js → diagram-3UASUU5V-gxhUB_Mu.js} +1 -1
  44. package/dist/assets/{diagram-ATOU4E4O-Zi6m3NUl.js → diagram-ATOU4E4O-CBhusUBn.js} +1 -1
  45. package/dist/assets/{diagram-CDSNMT55-DtCcmd5k.js → diagram-CDSNMT55-BdPrc86x.js} +1 -1
  46. package/dist/assets/{diagram-MLGK6HIB-DofuETS3.js → diagram-MLGK6HIB-Clp110R_.js} +1 -1
  47. package/dist/assets/{diagram-MPIPVDR6-Dw2T9PuU.js → diagram-MPIPVDR6-DJKfbugw.js} +1 -1
  48. package/dist/assets/{ebnfDiagram-ZINNZB2B-DbrwPiem.js → ebnfDiagram-ZINNZB2B-DnsltoBu.js} +1 -1
  49. package/dist/assets/{elk-276RUBZZ-BvCt1dCb.js → elk-276RUBZZ-jWdq6gqH.js} +1 -1
  50. package/dist/assets/{erDiagram-OPXOYQCR-Y-QKqPnU.js → erDiagram-OPXOYQCR-DArPVf8u.js} +1 -1
  51. package/dist/assets/{flowDiagram-KWPJA3E3-CDkL1B5w.js → flowDiagram-KWPJA3E3-D2HZ-2f7.js} +1 -1
  52. package/dist/assets/ganttDiagram-FUAMR5RP--o0KIxEo.js +292 -0
  53. package/dist/assets/{gitGraphDiagram-X574FWY7-nL9iFTCv.js → gitGraphDiagram-X574FWY7-CsoXr2D7.js} +1 -1
  54. package/dist/assets/image-plus-BbVjGHin.js +1 -0
  55. package/dist/assets/index-BrPW5HDO.css +1 -0
  56. package/dist/assets/index-C3NqfdVU.js +585 -0
  57. package/dist/assets/{index-DreDnjOu.js → index-CJTp9JEp.js} +1 -1
  58. package/dist/assets/{infoDiagram-VRGFBTTK-C7aHjzsf.js → infoDiagram-VRGFBTTK-g-6lNp7r.js} +1 -1
  59. package/dist/assets/{ishikawaDiagram-OU5B5YK6-KUZsNBTh.js → ishikawaDiagram-OU5B5YK6-B1d6qVTV.js} +1 -1
  60. package/dist/assets/{journeyDiagram-ZHPQQLJL-CGUuodFl.js → journeyDiagram-ZHPQQLJL-BTPuiU6T.js} +1 -1
  61. package/dist/assets/{kanban-definition-PNTS6WVX-Cy6r868Z.js → kanban-definition-PNTS6WVX-bDDuRJvP.js} +1 -1
  62. package/dist/assets/{linear-Bl669148.js → linear-BVVKbEMy.js} +1 -1
  63. package/dist/assets/{mermaid.core-86Xqz5Mr.js → mermaid.core-JJdoKyKB.js} +5 -5
  64. package/dist/assets/{mindmap-definition-NLK3R4M7-G4DzHLrd.js → mindmap-definition-NLK3R4M7-B4aE3T0q.js} +1 -1
  65. package/dist/assets/module-DCUsy2BQ.js +3 -0
  66. package/dist/assets/page-visible-BBo_Zm8g.js +1 -0
  67. package/dist/assets/{pegDiagram-GJSIUBJH-K4eruzY0.js → pegDiagram-GJSIUBJH-DFKQWpR7.js} +1 -1
  68. package/dist/assets/{pieDiagram-5QR66LMP-DYdR9PPq.js → pieDiagram-5QR66LMP-Iv7OKVJi.js} +1 -1
  69. package/dist/assets/{quadrantDiagram-O4NWA36T-BCAh0nEy.js → quadrantDiagram-O4NWA36T-U2YnfwBk.js} +1 -1
  70. package/dist/assets/{railroadDiagram-XR7U4H2S-p0dGRc4g.js → railroadDiagram-XR7U4H2S-CuPy6RqM.js} +1 -1
  71. package/dist/assets/remote-desktop-panel-BNEj7tUx.js +1 -0
  72. package/dist/assets/{requirementDiagram-PLB6GJNP-tLeBG0aL.js → requirementDiagram-PLB6GJNP-bMI5AK7T.js} +1 -1
  73. package/dist/assets/{sankeyDiagram-IPEJSGJF-QRuN16rV.js → sankeyDiagram-IPEJSGJF-BKcFE2WQ.js} +1 -1
  74. package/dist/assets/{sequenceDiagram-PO4LG4MO-ueT1nVoa.js → sequenceDiagram-PO4LG4MO-Bn9q88kl.js} +1 -1
  75. package/dist/assets/{sizeCapture-INFHLROL-wRS2zWg2.js → sizeCapture-INFHLROL-Cvmdq9HD.js} +1 -1
  76. package/dist/assets/{stateDiagram-v2-GCMORJYK-CYzA_hE1.js → stateDiagram-v2-GCMORJYK-JJQYw3eQ.js} +1 -1
  77. package/dist/assets/{swimlanes-2SLR337P-kDnv6LMc.js → swimlanes-2SLR337P-BkSCBEwp.js} +1 -1
  78. package/dist/assets/swimlanesDiagram-TC7HE7FX-CmTirbVT.js +8 -0
  79. package/dist/assets/table-file.worker-KkMx-SNx.js +10 -0
  80. package/dist/assets/{timeline-definition-EJHVYXUP-D1y2UbbH.js → timeline-definition-EJHVYXUP-DsaM4GHr.js} +1 -1
  81. package/dist/assets/{usecaseDiagram-POWQR4AR-IqB4v9HX.js → usecaseDiagram-POWQR4AR-3FOwLq7B.js} +1 -1
  82. package/dist/assets/user-DcZBnAuv.js +1 -0
  83. package/dist/assets/{vennDiagram-UO4OBE2U-BEi7KYVF.js → vennDiagram-UO4OBE2U-DyNjJsKt.js} +1 -1
  84. package/dist/assets/{wardleyDiagram-VNRHLVJA-Dkybo-Yf.js → wardleyDiagram-VNRHLVJA-Y4ZMcnBC.js} +1 -1
  85. package/dist/assets/{xychartDiagram-PMCCYNJV-BAPFJLpg.js → xychartDiagram-PMCCYNJV-BXZpg955.js} +1 -1
  86. package/dist/index.html +2 -2
  87. package/dist-server/cloud-home-start.js +20 -9
  88. package/dist-server/container-mcp.js +8 -0
  89. package/dist-server/desktop-entry.mjs +54 -0
  90. package/dist-server/drivers/agents-proxy.js +26 -9
  91. package/dist-server/index.js +3734 -2360
  92. package/dist-server/openmausbot.js +1664 -1553
  93. package/dist-server/pair-cli.js +1664 -1553
  94. package/dist-server/permission-proxy.js +2 -4
  95. package/dist-server/server/atomic.js +70 -2
  96. package/dist-server/server/auto-approve.js +1 -1
  97. package/dist-server/server/auto-vm-claims.js +13 -1
  98. package/dist-server/server/automatic-recovery.js +1 -2
  99. package/dist-server/server/boat.js +68 -84
  100. package/dist-server/server/bot-overview.js +1 -1
  101. package/dist-server/server/browser-engine.js +38 -1
  102. package/dist-server/server/browser-live.js +112 -25
  103. package/dist-server/server/browser-runtime.js +31 -1
  104. package/dist-server/server/checkpoints.js +275 -44
  105. package/dist-server/server/cli-setup.js +3 -3
  106. package/dist-server/server/cloud-computer-tools.js +11 -4
  107. package/dist-server/server/cloud-home-start.js +4 -4
  108. package/dist-server/server/cloud-home.js +3 -9
  109. package/dist-server/server/cloud-owner.js +1 -1
  110. package/dist-server/server/computer-engine-removal.js +70 -0
  111. package/dist-server/server/computer-selection.js +18 -0
  112. package/dist-server/server/config.js +29 -12
  113. package/dist-server/server/connector-card-text.js +15 -0
  114. package/dist-server/server/connector-scope-hint.js +83 -0
  115. package/dist-server/server/default-model-selection.js +23 -14
  116. package/dist-server/server/delegations.js +11 -5
  117. package/dist-server/server/delta-context.js +6 -1
  118. package/dist-server/server/drivers/acp/core.js +11 -1
  119. package/dist-server/server/drivers/acp/grok.js +47 -5
  120. package/dist-server/server/drivers/acp/opencode-go.js +16 -21
  121. package/dist-server/server/drivers/agents-call.js +1 -1
  122. package/dist-server/server/drivers/agents-catalog.js +27 -7
  123. package/dist-server/server/drivers/agents-proxy.js +1 -0
  124. package/dist-server/server/drivers/builtIn.js +0 -2
  125. package/dist-server/server/drivers/chat-mcp-tools.js +5 -3
  126. package/dist-server/server/drivers/claude-login-auth.js +1 -1
  127. package/dist-server/server/drivers/claude.js +84 -41
  128. package/dist-server/server/drivers/codex-device-auth.js +27 -319
  129. package/dist-server/server/drivers/codex.js +2 -2
  130. package/dist-server/server/drivers/device-auth.js +342 -0
  131. package/dist-server/server/drivers/openai-chat.js +110 -10
  132. package/dist-server/server/drivers/pi.js +184 -49
  133. package/dist-server/server/fleet-agent.js +18 -5
  134. package/dist-server/server/harness/http.js +5 -2
  135. package/dist-server/server/harness/registry.js +19 -0
  136. package/dist-server/server/harness-capabilities.js +7 -4
  137. package/dist-server/server/hosted-models.js +3 -1
  138. package/dist-server/server/index.js +823 -333
  139. package/dist-server/server/key-rejections.js +57 -0
  140. package/dist-server/server/live-call.js +11 -6
  141. package/dist-server/server/managed-policy.js +1 -1
  142. package/dist-server/server/message-file.js +7 -4
  143. package/dist-server/server/model-catalog/presets.js +8 -0
  144. package/dist-server/server/peer-roster.js +10 -2
  145. package/dist-server/server/permission-proxy.js +4 -0
  146. package/dist-server/server/provider-key-check.js +5 -1
  147. package/dist-server/server/request-auth.js +1 -1
  148. package/dist-server/server/room-turn-end.js +15 -0
  149. package/dist-server/server/room-turn-timeout.js +28 -0
  150. package/dist-server/server/routes/live.js +3 -3
  151. package/dist-server/server/routes/thread-models.js +36 -0
  152. package/dist-server/server/routine-requests.js +1 -1
  153. package/dist-server/server/routines.js +3 -3
  154. package/dist-server/server/screen-frame-gate.js +1 -3
  155. package/dist-server/server/skills.js +3 -2
  156. package/dist-server/server/store.js +273 -61
  157. package/dist-server/server/surface.js +29 -49
  158. package/dist-server/server/system-prompt.js +10 -10
  159. package/dist-server/server/team-backup.js +19 -4
  160. package/dist-server/server/thread-model.js +25 -0
  161. package/dist-server/server/turn-continuation.js +168 -0
  162. package/dist-server/server/webhook-ingress.js +8 -3
  163. package/dist-server/server/webhooks.js +40 -5
  164. package/dist-server/server/workspace.js +1 -1
  165. package/dist-server/shared/ask-question.js +0 -70
  166. package/dist-server/shared/cloud-computer.js +4 -6
  167. package/dist-server/shared/credential-request.js +1 -1
  168. package/dist-server/shared/device-sign-in.js +57 -0
  169. package/dist-server/shared/failed-turn.js +1 -4
  170. package/dist-server/shared/place-view.js +409 -0
  171. package/dist-server/shared/team-backup.js +2 -0
  172. package/dist-server/shared/thread-model.js +13 -0
  173. package/dist-server/shared/tool-scope-support.js +1 -2
  174. package/dist-server/vps-container-mcp.js +8 -0
  175. package/dist-server/workspace-backup.worker.js +41 -22
  176. package/package.json +1 -1
  177. package/dist/assets/DesktopViewer-DsnA23KM.js +0 -5
  178. package/dist/assets/architectureDiagram-NJMV4G6O-uYUsDawP.js +0 -36
  179. package/dist/assets/channel-BZxwC-Gw.js +0 -1
  180. package/dist/assets/cose-bilkent-JH36ORCC-D-Uglxqq.js +0 -1
  181. package/dist/assets/ganttDiagram-FUAMR5RP-CKV5D2F6.js +0 -292
  182. package/dist/assets/index-Du7o6Dsf.js +0 -610
  183. package/dist/assets/index-KxG4bWSr.css +0 -1
  184. package/dist/assets/swimlanesDiagram-TC7HE7FX-C7voMDle.js +0 -8
  185. package/dist-server/server/drivers/boatagent.js +0 -443
@@ -0,0 +1 @@
1
+ import{z as oe,D as ae,G as M,H as I,J as he,u as me,r as i,j as a,M as ie,X as ve,N as ce,g as P,c as Q,d as q,O as Z,R as we}from"./index-C3NqfdVU.js";import{t as ee}from"./computer-control-NLov352p.js";function xe(r,e){const l=(t,o)=>t.left<o.right&&t.right>o.left&&t.top<o.bottom&&t.bottom>o.top;return e.some(t=>t.visible&&t.rect.width>0&&t.rect.height>0&&(t.explicit||t.zIndex!==null&&t.zIndex>=10)&&r.some(o=>l(t.rect,o)))}async function be(r,e,l,t){e&&e!==l&&(await r.setInteractive(null),await r.release(e));const o=await r.take(l);if(!o.held)throw new Error("The Local VM control hold was not acquired");if(o.owned!==!0)return{status:"held-elsewhere",botId:l,snapshot:o};try{await r.setInteractive(t)}catch(u){throw await r.setInteractive(null).catch(()=>{}),await r.release(l).catch(()=>{}),u}return{status:"controlled",botId:l,snapshot:o}}async function F(r,e){return e?(await r.setInteractive(null).catch(()=>{}),r.release(e)):null}function le(r){return r.filter(e=>e.computer==="vm"&&e.hidden!==!0).map(e=>e.id)}function ye(r,e){const l=le(r),t=l.includes(e)?e:l[0]??null;return[t,l.find(o=>o!==t)??null]}function ge(r,e,l){const t=[...r],o=e===0?1:0;return l&&t[o]===l&&(t[o]=t[e]),t[e]=l,t}function ke(r,e){const l=le(e),t=new Set(l),o=[null,null];for(const u of[0,1]){const p=r[u];p&&t.delete(p)&&(o[u]=p)}for(const u of[0,1]){if(o[u])continue;const p=[...t][0];p&&(o[u]=p,t.delete(p))}return o}const Ne=oe({mode:I(["shared","per-bot","pool"]).optional(),max_instances:he().int().positive().optional(),container:I(["running","stopped","missing"]).optional(),network:I(["loopback","unsafe","unknown"]).optional(),security:I(["hardened","unsafe","unknown"]).optional(),persistence:I(["durable","unsafe","unknown"]).optional(),desktopReady:M().optional(),ready:M().optional(),viewer_url:ae().min(1).optional()});function ue(r){const e=Ne.safeParse(r);return e.success?e.data:null}function D(r){const e=ue(r),l=e?.mode??"unknown",t=e?.container??"unknown",o=e?.network??"unknown",u=e?.security??"unknown",p=e?.persistence??"unknown",h=e?.max_instances??0,g=e?.desktopReady===!0,v=!!(e?.ready===!0&&t==="running"&&o==="loopback"&&u==="hardened"&&p==="durable"&&g);return{mode:l,maxInstances:h,container:t,network:o,security:u,persistence:p,desktopReady:g,ready:v}}function Ce(r){const e=ue(r);return!e||!D(r).ready?null:e.viewer_url??null}const U=["local-vm-workspace:left","local-vm-workspace:right"],de=oe({held:M(),helpReason:ae().nullable(),owned:M().optional(),acquired:M().optional(),released:M().optional()});async function te(r,e,l){const t=await P(`/api/bots/${r}/computer/control`,{method:"POST",body:JSON.stringify({action:e,controlLeaseId:l})}),o=de.safeParse(t);if(!o.success)throw new Error("invalid-control-snapshot");return o.data}async function je(r){const e=de.safeParse(await P(`/api/bots/${r}/computer/control`));if(!e.success)throw new Error("invalid-control-snapshot");return e.data}function ne(r,e){fetch(`/api/bots/${r}/computer/control`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({action:"release",controlLeaseId:e}),keepalive:!0}).then(async l=>{l.ok}).catch(()=>{})}async function re(r,e){return!0}function H(r,e,l){r({type:"computerControl",botId:e,held:l.held,helpReason:l.helpReason})}function se(r){const e=r.current?.getBoundingClientRect();return!e||e.width<1||e.height<1?null:{x:Math.round(e.left),y:Math.round(e.top),width:Math.round(e.width),height:Math.round(e.height)}}const Le=['[aria-modal="true"]','[role="dialog"]','[role="menu"]',"[popover]","[data-native-view-overlay]",".fixed",".absolute"].join(",");function Se(){const r=[...document.querySelectorAll("[data-native-view-host]")],e=r.map(t=>t.getBoundingClientRect()).filter(t=>t.width>0&&t.height>0);if(e.length===0)return!1;const l=[...document.querySelectorAll(Le)].filter(t=>!r.some(o=>t===o||t.contains(o)||o.contains(t))).map(t=>{const o=window.getComputedStyle(t),u=t.matches('[aria-modal="true"], [role="dialog"], [role="menu"], [popover], [data-native-view-overlay]'),p=Number.parseInt(o.zIndex,10);return{rect:t.getBoundingClientRect(),explicit:u,visible:o.display!=="none"&&o.visibility!=="hidden"&&Number(o.opacity)!==0,zIndex:Number.isFinite(p)?p:null}});return xe(e,l)}function Re(r){const[e,l]=i.useState(!1);return i.useEffect(()=>{let t=0;const o=()=>l(Se()),u=()=>{t||(t=requestAnimationFrame(()=>{t=0,o()}))};o();const p=new MutationObserver(u);p.observe(document.body,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["class","style","aria-hidden","aria-modal","role","open","popover"]});const h=new ResizeObserver(u);h.observe(document.body);for(const v of document.querySelectorAll("[data-native-view-host]"))h.observe(v);const g=["toggle","animationstart","animationend","transitionstart","transitionend"];for(const v of g)document.addEventListener(v,u,!0);return window.addEventListener("resize",u),window.addEventListener("scroll",u,!0),()=>{t&&cancelAnimationFrame(t),p.disconnect(),h.disconnect();for(const v of g)document.removeEventListener(v,u,!0);window.removeEventListener("resize",u),window.removeEventListener("scroll",u,!0)}},[]),r||e}function Ve(r,e){return r?r.container==="missing"?"VM not created":r.container==="stopped"?"VM stopped":r.ready?e==="error"?"Viewer unavailable":e!=="ready"?"Connecting viewer":"Live · watch-only":"VM unavailable":"Checking VM"}function Ee({index:r,bot:e,bots:l,otherBotId:t,obscured:o,active:u,heldElsewhere:p,controlPending:h,onSelect:g,onTake:v,onRelease:W,onOpenComputer:C}){const f=U[r],b=e?.id??null,k=e?.name??"Local VM",x=i.useRef(null),N=i.useRef(Promise.resolve()),z=i.useRef(o),[V,_]=i.useState(0),[w,O]=i.useState(null),[m,j]=i.useState({contextId:f,open:!1,status:"closed",interactive:!1}),[y,E]=i.useState(null),L=i.useCallback(async s=>{if(b)try{const c=await P(`/api/bots/${b}/local-computer`,{signal:s});s?.aborted||O(D(c))}catch{}},[b]),A=i.useRef(L);i.useEffect(()=>{A.current=L},[L]),i.useEffect(()=>{z.current=o},[o]),i.useEffect(()=>window.ogb?.desktopWorkspace?.onState(c=>{c.contextId===f&&(j(c),(c.status==="error"||c.status==="closed")&&A.current())}),[f]),i.useEffect(()=>{const s=window.ogb?.desktopWorkspace;let c=!0;const R=new AbortController;O(null),E(null),j({contextId:f,open:!1,status:"closed",interactive:!1});const T=async()=>{if(s&&await s.close(f).catch(()=>{}),!(!c||!b)){if(!s){E("The two-desktop view requires the OpenMausBot desktop app.");return}try{const B=await P(`/api/bots/${b}/local-computer`,{signal:R.signal});if(!c)return;const J=D(B);O(J);const X=Ce(B);if(!J.ready||!X||(await new Promise(fe=>{let G=!1;const K=()=>{G||(G=!0,fe())},pe=setTimeout(K,100);requestAnimationFrame(()=>{clearTimeout(pe),K()})}),!c))return;const $=se(x);if(!$)throw new Error("layout-unavailable");const Y=await s.open({contextId:f,url:X,title:`${k}'s Local VM`,bounds:$});if(!c){await s.close(f).catch(()=>{});return}j(Y),await s.layout([{contextId:f,bounds:$,visible:!z.current&&Y.open}])}catch(B){if(!c||R.signal.aborted)return;E(B instanceof Error&&B.message==="layout-unavailable"?"The viewer area is not laid out yet. Retry after resizing the window.":"OpenMausBot could not connect this Local VM viewer.")}}};return N.current=N.current.catch(()=>{}).then(T),()=>{c=!1,R.abort(),s&&(N.current=N.current.catch(()=>{}).then(()=>s.close(f).then(()=>{}).catch(()=>{})))}},[b,k,f,V]),i.useEffect(()=>{if(!b)return;const s=new AbortController,c=window.setInterval(()=>{L(s.signal)},3e4);return()=>{s.abort(),window.clearInterval(c)}},[b,L]);const S=i.useCallback(()=>{const s=window.ogb?.desktopWorkspace,c=se(x);!s||!c||!m.open||s.layout([{contextId:f,bounds:c,visible:!o}]).catch(()=>E("OpenMausBot could not position this Local VM viewer."))},[f,m.open,o]);i.useEffect(()=>{const s=x.current;if(!s)return;const c=new ResizeObserver(S);c.observe(s),window.addEventListener("resize",S);const R=requestAnimationFrame(S);return()=>{cancelAnimationFrame(R),c.disconnect(),window.removeEventListener("resize",S)}},[S]);const n=Ve(w,m.status),d=!!(e&&w?.ready&&m.status==="ready"&&m.open);return a.jsxs("section",{className:Q("flex min-h-0 min-w-0 flex-col overflow-hidden rounded-xl border bg-panel",u?"border-accent/80 shadow-[0_0_0_1px_rgb(var(--accent)/0.35)]":"border-hairline/50"),children:[a.jsxs("div",{className:"flex min-h-[68px] items-center gap-3 border-b border-hairline/40 px-3 py-2.5",children:[a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsxs("label",{className:"sr-only",htmlFor:`local-vm-slot-${r}`,children:["Local VM for pane ",r+1]}),a.jsxs("select",{id:`local-vm-slot-${r}`,value:e?.id??"",onChange:s=>g(s.target.value||null),disabled:h,className:"w-full truncate rounded-lg border border-hairline/50 bg-card px-2.5 py-1.5 text-[13px] font-medium text-ink outline-none focus:border-accent/70",children:[a.jsx("option",{value:"",children:"Choose a Local VM bot"}),l.map(s=>a.jsx("option",{value:s.id,disabled:s.id===t,children:s.name},s.id))]}),a.jsxs("div",{className:"mt-1 flex items-center gap-1.5 text-[11px] text-ink-secondary",children:[a.jsx("span",{className:Q("h-1.5 w-1.5 rounded-full",u?"bg-accent":m.status==="ready"?"bg-success":m.status==="error"?"bg-danger":"bg-ink-secondary/50")}),u?"You have control":p?"Control held elsewhere":n]})]}),e&&u?a.jsxs("button",{type:"button",onClick:W,disabled:h,className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-accent px-2.5 py-2 text-[12px] font-medium text-white hover:brightness-110 disabled:opacity-50",children:[h?a.jsx(q,{size:13,className:"animate-spin"}):a.jsx(Z,{size:13}),"Hand back"]}):e?a.jsxs("button",{type:"button",onClick:()=>v(e.id),disabled:!d||h||p,className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-raised px-2.5 py-2 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-45",title:"Pause only this bot and enable keyboard and pointer input in this pane",children:[h?a.jsx(q,{size:13,className:"animate-spin"}):a.jsx(Z,{size:13}),p?"Held elsewhere":"Take control"]}):null]}),a.jsx("div",{ref:x,"data-native-view-host":!0,className:"relative min-h-0 flex-1 bg-[#070707]",children:a.jsx("div",{className:"absolute inset-0 flex items-center justify-center p-6 text-center",children:e?!w&&!y?a.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[a.jsx(q,{size:15,className:"animate-spin"})," Checking ",e.name,"'s VM…"]}):w?.ready&&m.status!=="error"&&!y?a.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[a.jsx(q,{size:15,className:"animate-spin"})," Connecting live view…"]}):a.jsxs("div",{className:"flex max-w-[300px] flex-col items-center gap-3 text-ink-secondary",children:[a.jsx(ce,{size:21,className:"text-warning"}),a.jsx("div",{className:"text-[12px] leading-relaxed",children:y??(w?.container==="missing"?`${e.name}'s Local VM has not been created.`:w?.container==="stopped"?`${e.name}'s Local VM is stopped.`:`${e.name}'s Local VM is not ready for a live view.`)}),a.jsxs("div",{className:"flex gap-2",children:[a.jsxs("button",{type:"button",onClick:()=>_(s=>s+1),className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-2 text-[12px] text-ink hover:bg-raised-hover",children:[a.jsx(we,{size:13})," Retry status"]}),a.jsx("button",{type:"button",onClick:()=>C(e.id),className:"rounded-lg bg-raised px-3 py-2 text-[12px] text-ink hover:bg-raised-hover",children:"Open Computer"})]})]}):a.jsxs("div",{className:"flex max-w-[260px] flex-col items-center gap-2 text-ink-secondary",children:[a.jsx(ie,{size:22}),a.jsx("span",{className:"text-[12px]",children:"Choose another bot configured for a Local VM."})]})})})]})}function Oe({primaryBotId:r,overlayOpen:e,onClose:l,onOpenComputer:t}){const{state:o,dispatch:u}=me(),p=i.useMemo(()=>o.bots.filter(n=>n.computer==="vm"&&!n.hidden),[o.bots]),[h,g]=i.useState(()=>ye(o.bots,r)),v=i.useRef(h),[W,C]=i.useState(null),f=i.useRef(null),b=i.useRef(null),k=b.current??crypto.randomUUID();b.current=k;const x=i.useRef(!1),N=i.useRef(!0),[z,V]=i.useState(!1),[_,w]=i.useState(null),O=Re(e);i.useEffect(()=>{v.current=h},[h]);const m=i.useMemo(()=>({async take(n){const d=await ee({action:"take",syncNativeBrowser:!0,requestControl:s=>te(n,s,k),setNativeBrowserControl:s=>re()});return H(u,n,d),d.held&&d.owned===!0?f.current=n:f.current===n&&(f.current=null),d},async release(n){const d=await ee({action:"release",syncNativeBrowser:!0,requestControl:s=>te(n,s,k),setNativeBrowserControl:s=>re()});return H(u,n,d),f.current===n&&(f.current=null),d},async setInteractive(n){const d=window.ogb?.desktopWorkspace;if(!d)throw new Error("The two-desktop view bridge is unavailable");return d.setInteractive(n)}}),[k,u]);i.useEffect(()=>{g(n=>{const d=ke(n,o.bots);return d[0]===n[0]&&d[1]===n[1]?n:d})},[o.bots]),i.useEffect(()=>{let n=!0;return(async()=>{for(const s of h)if(s)try{const c=await je(s);n&&H(u,s,c)}catch{}})(),()=>{n=!1}},[u,h]),i.useEffect(()=>{const n=f.current;!n||h.includes(n)||F(m,n).then(()=>{C(null)}).catch(()=>{w("The removed pane could not hand control back safely.")})},[m,h]),i.useEffect(()=>(N.current=!0,()=>{N.current=!1;const n=f.current,d=window.ogb?.desktopWorkspace;if(!d){n&&ne(n,k);return}d.setInteractive(null).catch(()=>{}).then(()=>(n&&ne(n,k),d.close())).catch(()=>{})}),[k]);const j=i.useCallback(n=>{const d=v.current.indexOf(n);return d<0?null:U[d]},[]),y=i.useCallback(async()=>{const n=f.current;if(!n)return!0;if(x.current)return!1;x.current=!0,V(!0),w(null);try{return await F(m,n),C(null),!0}catch{return w("OpenMausBot could not hand control back. The view stayed open."),!1}finally{x.current=!1,V(!1)}},[m]),E=i.useCallback(async n=>{if(x.current||f.current===n)return;const d=window.ogb?.desktopWorkspace,s=j(n);if(!(!d||!s)){x.current=!0,V(!0),w(null);try{const c={...m,async setInteractive(T){if(T&&j(n)!==T)throw new Error("The Local VM pane changed during control acquisition");return m.setInteractive(T)}},R=await be(c,f.current,n,s);if(C(null),R.status==="held-elsewhere"){w("This VM is already controlled in another viewer. Hand it back there first.");return}if(!N.current){await F(m,n).catch(()=>{});return}C(n)}catch{C(f.current),w("Control could not switch safely. Any remaining hold stayed paused.")}finally{x.current=!1,V(!1)}}},[j,m]),L=i.useCallback(async(n,d)=>{if(x.current)return;const s=v.current[n];s!==d&&(s&&f.current===s&&!await y()||g(c=>ge(c,n,d)))},[y]),A=i.useCallback(async()=>{f.current&&!await y()||l()},[y,l]),S=i.useCallback(async n=>{f.current&&!await y()||t(n)},[y,t]);return a.jsxs("main",{className:"flex h-full min-w-0 flex-1 flex-col bg-app",children:[a.jsxs("header",{className:"flex min-h-[60px] items-center gap-3 border-b border-hairline/40 px-5 py-3",children:[a.jsx("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-accent/15 text-accent",children:a.jsx(ie,{size:18})}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsx("h1",{className:"truncate text-[14px] font-semibold text-ink",children:"Local VM view"}),a.jsx("p",{className:"truncate text-[11.5px] text-ink-secondary",children:"Two live desktops · one active controller · watch-only by default"})]}),a.jsx("button",{type:"button",onClick:()=>{A()},disabled:z,className:"rounded-md p-1.5 text-ink-secondary hover:bg-raised hover:text-ink disabled:opacity-50","aria-label":"Close Local VM view",children:a.jsx(ve,{size:18})})]}),_&&a.jsxs("div",{className:"mx-3 mt-3 flex items-center gap-2 rounded-lg border border-danger/30 bg-danger/10 px-3 py-2 text-[12px] text-danger",children:[a.jsx(ce,{size:14,className:"shrink-0"})," ",_]}),a.jsx("div",{className:"grid min-h-0 flex-1 grid-cols-2 gap-3 p-3",children:[0,1].map(n=>{const d=h[n],s=p.find(c=>c.id===d)??null;return a.jsx(Ee,{index:n,bot:s,bots:p,otherBotId:h[n===0?1:0],obscured:O,active:!!(s&&W===s.id),heldElsewhere:!!(s&&o.computerControl[s.id]?.held&&W!==s.id),controlPending:z,onSelect:c=>{L(n,c)},onTake:c=>{E(c)},onRelease:()=>{y()},onOpenComputer:c=>{S(c)}},U[n])})})]})}export{Oe as LocalVmWorkspace};
@@ -0,0 +1 @@
1
+ import{k as q,u as M,r as o,j as e,c as G,t as s,d as T,N as _,g as L,aq as Y,ar as X,E as Z,o as H,as as ee,at as te,P as se,au as ne,T as ae,A as F,av as re,aw as ie,ax as oe,ay as le}from"./index-C3NqfdVU.js";const ce=[["path",{d:"M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401",key:"kfwtm"}]],ge=q("moon",ce);const de=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]],pe=q("shield",de);async function be(t,a,r,c=6e4){const d=Date.now()+c;let x=t;for(;!x.ready&&x.container==="running"&&Date.now()<d;)r.throwIfAborted(),await new Promise((l,u)=>{const i=()=>{window.clearTimeout(h),u(r.reason)},h=window.setTimeout(()=>{r.removeEventListener("abort",i),l()},2e3);r.addEventListener("abort",i,{once:!0})}),x=await a();return r.throwIfAborted(),x}const $={composio:{body:t=>({composio:{apiKey:t}}),flag:t=>t.composio.configured},box:{body:t=>({box:{token:t}}),flag:t=>t.box.configured&&t.box.included!==!0,included:t=>t.box.included===!0},opencodeGo:{body:t=>({opencodeGo:{apiKey:t}}),flag:t=>t.opencodeGo?.configured??!1},anthropic:{body:(t,a)=>({anthropic:{key:t,...a&&t?{everyClaudeBot:!1}:{}}}),flag:t=>t.anthropic?.configured??!1},openai:{body:t=>({openai:{key:t}}),flag:t=>t.openai?.configured??!1},openrouter:{body:t=>({openrouter:{key:t}}),flag:t=>t.openrouter?.configured??!1},openaiCompat:{body:t=>({openaiCompat:{key:t}}),flag:t=>t.openaiCompat?.configured??!1},mistral:{body:t=>({mistral:{key:t}}),flag:t=>t.mistral?.configured??!1},cerebras:{body:t=>({cerebras:{key:t}}),flag:t=>t.cerebras?.configured??!1},xai:{body:t=>({xai:{key:t}}),flag:t=>t.xai?.configured??!1}},ue={composio:"composioApiKey",box:"boxToken",opencodeGo:"opencodeGoApiKey"},me={composio:{labelKey:"keys.composio.label",placeholder:"ak_…",descriptionKey:"keys.composio.desc",href:"https://dashboard.composio.dev",linkLabelKey:"keys.composio.link",optional:!0},box:{labelKey:"keys.boat.label",placeholderKey:"keys.boat.placeholder",descriptionKey:"keys.boat.desc",href:"https://docs.boat.dev/api-keys",linkLabelKey:"keys.boat.link",optional:!0,warningKey:"keys.boat.warning"},opencodeGo:{labelKey:"keys.opencode.label",placeholderKey:"keys.opencode.placeholder",descriptionKey:"keys.opencode.desc",href:"https://opencode.ai/docs/providers/",linkLabelKey:"keys.opencode.link",optional:!0},anthropic:{labelKey:"keys.anthropic.label",placeholder:"sk-ant-…",descriptionKey:"keys.anthropic.desc",href:"https://console.anthropic.com/settings/keys",linkLabelKey:"keys.anthropic.link",optional:!0},openai:{labelKey:"keys.openai.label",placeholder:"sk-…",descriptionKey:"keys.openai.desc",href:"https://platform.openai.com/api-keys",linkLabelKey:"keys.openai.link",optional:!0,noteKey:"keys.openai.note"},openrouter:{labelKey:"keys.openrouter.label",placeholder:"sk-or-v1-…",descriptionKey:"keys.openrouter.desc",href:"https://openrouter.ai/keys",linkLabelKey:"keys.openrouter.link",optional:!0},openaiCompat:{labelKey:"keys.openaiCompat.label",placeholderKey:"keys.openaiCompat.placeholder",descriptionKey:"keys.openaiCompat.desc",href:"https://platform.openai.com/docs/api-reference",linkLabelKey:"keys.openaiCompat.link",optional:!0},mistral:{labelKey:"keys.mistral.label",placeholderKey:"keys.mistral.placeholder",descriptionKey:"keys.mistral.desc",href:"https://console.mistral.ai/api-keys",linkLabelKey:"keys.mistral.link",optional:!0},cerebras:{labelKey:"keys.cerebras.label",placeholder:"csk-…",descriptionKey:"keys.cerebras.desc",href:"https://cloud.cerebras.ai/",linkLabelKey:"keys.cerebras.link",optional:!0},xai:{labelKey:"keys.xai.label",placeholder:"xai-…",descriptionKey:"keys.xai.desc",href:"https://console.x.ai",linkLabelKey:"keys.xai.link",optional:!0}};function Q(t){const a=me[t];return{...a,label:s(a.labelKey),placeholder:a.placeholderKey?s(a.placeholderKey):a.placeholder??"",description:s(a.descriptionKey),linkLabel:s(a.linkLabelKey),warning:a.warningKey?s(a.warningKey):void 0,note:a.noteKey?s(a.noteKey):void 0}}function xe({section:t}){const a=Q(t),[r,c]=o.useState(!1),d=Y(r),x=o.useRef(null),l=o.useRef(null),u=o.useId();return o.useEffect(()=>{if(!r)return;const i=f=>{f.target instanceof Node&&!x.current?.contains(f.target)&&c(!1)},h=f=>{f.key==="Escape"&&(c(!1),l.current?.focus())};return document.addEventListener("pointerdown",i),document.addEventListener("keydown",h),()=>{document.removeEventListener("pointerdown",i),document.removeEventListener("keydown",h)}},[r]),e.jsxs("div",{ref:x,className:"relative ml-auto",children:[e.jsx("button",{ref:l,type:"button","aria-label":s("keys.aboutAria",{label:a.label}),"aria-expanded":r,"aria-controls":u,onClick:()=>c(i=>!i),className:"flex size-6 items-center justify-center rounded-md text-ink-secondary outline-none transition-colors hover:bg-control hover:text-ink focus-visible:ring-2 focus-visible:ring-accent/70",children:e.jsx(X,{size:14,"aria-hidden":"true"})}),d.shown&&e.jsxs("div",{id:u,role:"group","aria-label":s("keys.helpAria",{label:a.label}),className:G("absolute right-0 z-30 mt-1.5 w-[270px] rounded-xl border border-hairline bg-panel p-3 text-left shadow-2xl",d.className),...d.exitProps,children:[e.jsx("div",{className:"text-[12px] leading-[1.45] text-ink-secondary",children:a.description}),e.jsxs("a",{href:a.href,target:"_blank",rel:"noopener noreferrer",onClick:()=>c(!1),className:"mt-2.5 flex items-center gap-1.5 text-[12px] font-medium text-accent hover:underline focus-visible:rounded-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/70",children:[a.linkLabel,e.jsx(Z,{size:12,"aria-hidden":"true"})]})]})]})}function W(t){return t.length>0&&!/\s/.test(t)}function ke({section:t,onSaved:a,testProvider:r}){const{state:c,dispatch:d}=M(),[x,l]=o.useState(""),[u,i]=o.useState(!1),[h,f]=o.useState(null),[y,p]=o.useState(!1),[j,C]=o.useState(null),b=o.useRef(0),S=o.useRef(!1),m=o.useRef(!1),g=c.config?$[t].flag(c.config):!1,K=c.config?$[t].included?.(c.config)===!0:!1,w=!x.trim()&&g,E=Q(t),z=async()=>{if(!r)return;p(!0),C(null);const N=++b.current;try{const k=await L("/api/keys/test",{method:"POST",body:JSON.stringify({provider:r})});if(N!==b.current)return;const B=k.ok?k.check==="authentication"?s("keys.testAuthenticated"):k.models?.length?s("keys.testCatalog",{models:k.models.join(", ")}):s("keys.testCatalogNoModels"):k.reason==="rejected"?s("keys.testRejected"):k.reason==="unreachable"?s("keys.testUnreachable"):s("keys.testUnexpected",{status:String(k.status??"?")});C(`${s("keys.testSaved")} ${B}`)}catch(k){N===b.current&&C(k instanceof Error?k.message:String(k))}finally{N===b.current&&p(!1)}},R=(N=!1)=>{const k=N?"":x.trim();if(S.current||!N&&!k)return;if(!N&&!W(k)){f(s("keys.notAKey"));return}S.current=!0,i(!0),f(null),b.current++,C(null);const B=ue[t];(window.ogb?.setCredential&&B?window.ogb.setCredential(B,k):L("/api/config",{method:"PUT",body:JSON.stringify($[t].body(k,!g))})).then(O=>{d({type:"configStatus",config:O}),l("");const P=$[t].flag(O);a?.(P),k&&P&&z()}).catch(O=>f(O.message)).finally(()=>{S.current=!1,i(!1)})};return o.useEffect(()=>{m.current&&(m.current=!1,R())}),e.jsxs("div",{"data-api-key-row":t,children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx("span",{className:G("size-1.5 rounded-full",g||K?"bg-success":"bg-raised-hover")}),e.jsx("span",{children:E.label}),E.optional&&e.jsx("span",{className:"rounded bg-control px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-ink-secondary",children:s("keys.optional")}),g&&e.jsx("span",{className:"text-[11px] text-ink-secondary",children:s("keys.configured")}),K&&e.jsx("span",{className:"text-[11px] text-ink-secondary",children:s("keys.includedWithCloudPro")}),e.jsx(xe,{section:t})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative w-full",children:[e.jsx("input",{type:"password",value:x,onChange:N=>{b.current++,C(null),f(null),l(N.target.value)},onPaste:()=>{m.current=!0},onBlur:()=>R(),disabled:u,onKeyDown:N=>N.key==="Enter"&&R(),placeholder:g?s("keys.replace"):E.placeholder,"aria-label":E.label,autoComplete:"off",className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 pr-8 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"}),(u||y)&&e.jsx(T,{size:13,"aria-hidden":"true",className:"absolute right-2.5 top-1/2 -translate-y-1/2 animate-spin text-ink-secondary"})]}),w&&e.jsx("button",{type:"button",onClick:()=>R(!0),disabled:u,className:"flex w-[72px] shrink-0 items-center justify-center rounded-lg bg-control py-2 text-[13px] text-danger hover:bg-raised-hover disabled:cursor-not-allowed disabled:opacity-50",title:s("keys.removeKey"),children:s("keys.clear")}),r&&w&&e.jsx("button",{type:"button",onClick:()=>{z()},disabled:y||u,className:"flex shrink-0 items-center justify-center rounded-lg border border-hairline/40 px-3 py-2 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:cursor-not-allowed disabled:opacity-50",children:y?s("keys.testing"):s("keys.test")})]}),E.warning&&e.jsxs("div",{className:"mt-1.5 flex gap-1.5 text-[11.5px] leading-[1.4] text-warning",children:[e.jsx(_,{size:13,className:"mt-px shrink-0","aria-hidden":"true"}),e.jsx("span",{children:E.warning})]}),E.note&&e.jsx("p",{className:"mt-1.5 text-[11.5px] leading-[1.4] text-ink-secondary",children:E.note}),h&&e.jsx("div",{className:"mt-1 text-[12px] text-danger",children:h}),j&&e.jsx("div",{role:"status",className:"mt-1 text-[12px] text-ink-secondary",children:j})]})}function ve(){const{state:t,dispatch:a}=M(),r=t.config?.opencodeGo?.providerKeys??[],[c,d]=o.useState(""),[x,l]=o.useState(""),[u,i]=o.useState(!1),[h,f]=o.useState(null),[y,p]=o.useState(null),j=u||h!==null,C=(m,g)=>L("/api/config",{method:"PUT",body:JSON.stringify({opencodeGo:{providerKeys:{[m]:g}}})}).then(K=>a({type:"configStatus",config:K})),b=()=>{const m=c.trim().toUpperCase(),g=x.trim();if(!(j||!m||!g)){if(!W(g)){p(s("keys.notAKey"));return}i(!0),p(null),C(m,g).then(()=>{d(""),l("")}).catch(K=>p(K.message)).finally(()=>i(!1))}},S=m=>{j||(f(m),p(null),C(m,"").catch(g=>p(g.message)).finally(()=>f(null)))};return e.jsxs("details",{"data-opencode-provider-keys":!0,className:"rounded-lg border border-hairline/40 bg-inset px-3 py-2",open:r.length>0,children:[e.jsx("summary",{className:"cursor-pointer text-[13px] text-ink-secondary",children:s("keys.opencode.otherProviders.title")}),e.jsxs("div",{className:"mt-3 flex flex-col gap-2",children:[e.jsx("p",{className:"text-[11.5px] leading-relaxed text-ink-secondary",children:s("keys.opencode.otherProviders.hint")}),r.map(m=>e.jsxs("div",{"data-opencode-provider-key":m,className:"flex items-center gap-2",children:[e.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-success"}),e.jsx("code",{className:"min-w-0 flex-1 truncate font-mono text-[12px] text-ink",children:m}),e.jsx("span",{className:"text-[11px] text-ink-secondary",children:s("keys.configured")}),e.jsx("button",{type:"button",onClick:()=>S(m),disabled:j,"aria-label":s("keys.opencode.otherProviders.removeAria",{name:m}),className:"flex w-[72px] shrink-0 items-center justify-center rounded-lg bg-control py-1.5 text-[13px] text-danger hover:bg-raised-hover disabled:cursor-not-allowed disabled:opacity-50",children:h===m?e.jsx(T,{size:13,className:"animate-spin","aria-hidden":"true"}):s("keys.clear")})]},m)),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:c,onChange:m=>{p(null),d(m.target.value)},onKeyDown:m=>m.key==="Enter"&&b(),disabled:j,placeholder:"VENICE_API_KEY","aria-label":s("keys.opencode.otherProviders.name"),autoComplete:"off",spellCheck:!1,className:"w-[44%] min-w-0 rounded-lg border border-hairline/40 bg-panel px-3 py-2 font-mono text-[12px] uppercase text-ink placeholder:normal-case placeholder:text-ink-secondary focus:outline-none"}),e.jsx("input",{type:"password",value:x,onChange:m=>{p(null),l(m.target.value)},onKeyDown:m=>m.key==="Enter"&&b(),disabled:j,placeholder:s("keys.opencode.otherProviders.keyPlaceholder"),"aria-label":s("keys.opencode.otherProviders.key"),autoComplete:"off",className:"w-full min-w-0 rounded-lg border border-hairline/40 bg-panel px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"}),e.jsx("button",{type:"button",onClick:b,disabled:j||!c.trim()||!x.trim(),className:"flex w-[72px] shrink-0 items-center justify-center gap-1.5 rounded-lg bg-control py-2 text-[13px] text-ink hover:bg-raised-hover disabled:cursor-not-allowed disabled:opacity-50",children:u?e.jsx(T,{size:13,className:"animate-spin","aria-hidden":"true"}):e.jsxs(e.Fragment,{children:[e.jsx(H,{size:13,"aria-hidden":"true"}),s("common.save")]})})]}),y&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:y})]})]})}function je(){const{state:t,dispatch:a}=M(),[r,c]=o.useState(!1),[d,x]=o.useState(null);if(!t.config?.anthropic?.configured)return null;const l=t.config.anthropic.everyClaudeBot===!0,u=()=>{r||(c(!0),x(null),L("/api/config",{method:"PUT",body:JSON.stringify({anthropic:{everyClaudeBot:!l}})}).then(i=>a({type:"configStatus",config:i})).catch(i=>x(i.message)).finally(()=>c(!1)))};return e.jsxs("div",{"data-anthropic-every-claude-bot":!0,className:"-mt-2",children:[e.jsxs("label",{className:"flex cursor-pointer items-start gap-2 text-[12.5px] text-ink",children:[e.jsx("input",{type:"checkbox",checked:l,disabled:r,onChange:u,className:"mt-0.5 accent-accent"}),e.jsxs("span",{children:[s("keys.anthropic.everyBot"),e.jsx("span",{className:"block text-[11.5px] leading-[1.4] text-ink-secondary",children:l?s("keys.anthropic.everyBotOn"):s("keys.anthropic.everyBotOff")})]})]}),l&&e.jsxs("div",{className:"mt-1.5 flex gap-1.5 text-[11.5px] leading-[1.4] text-warning",children:[e.jsx(_,{size:13,className:"mt-px shrink-0","aria-hidden":"true"}),e.jsx("span",{children:s("keys.anthropic.warning")})]}),d&&e.jsx("div",{className:"mt-1 text-[12px] text-danger",children:d})]})}function we(){const{state:t,dispatch:a}=M(),[r,c]=o.useState(""),[d,x]=o.useState(!1),[l,u]=o.useState(null),i=!!t.config?.vps?.configured;o.useEffect(()=>{c(t.config?.vps?.sshAlias??"")},[t.config?.vps?.sshAlias]);const h=()=>{d||!r.trim()&&!i||(x(!0),u(null),L("/api/config",{method:"PUT",body:JSON.stringify({vps:{sshAlias:r.trim()}})}).then(f=>{a({type:"configStatus",config:f}),c(f.vps?.sshAlias??"")}).catch(f=>u(f.message)).finally(()=>x(!1)))};return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx("span",{className:G("size-1.5 rounded-full",i?"bg-success":"bg-raised-hover")}),e.jsx("span",{children:s("keys.vps.label")}),e.jsx("span",{className:"rounded bg-control px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-ink-secondary",children:s("keys.optional")}),i&&e.jsx("span",{className:"text-[11px] text-success",children:s("keys.connected")})]}),e.jsxs("div",{className:"mb-1.5 text-[12px] leading-relaxed text-ink-secondary",children:[s("keys.vps.descBefore"),e.jsx("a",{href:"https://github.com/milind-soni/OpenMausBot/blob/main/docs/byo-vps.md",target:"_blank",rel:"noopener noreferrer",className:"text-accent hover:underline",children:s("keys.vps.descLink")}),s("keys.vps.descAfter")]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:r,onChange:f=>c(f.target.value),onKeyDown:f=>f.key==="Enter"&&h(),placeholder:"my-vps","aria-label":s("keys.vps.aria"),autoComplete:"off",className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"}),e.jsx("button",{onClick:h,disabled:d||!r.trim()&&!i,className:G("flex w-[72px] shrink-0 items-center justify-center gap-1.5 rounded-lg py-2 text-[13px]",!r.trim()&&i?"bg-control text-danger hover:bg-raised-hover":"bg-control text-ink hover:bg-raised-hover","disabled:cursor-not-allowed disabled:opacity-50"),title:!r.trim()&&i?s("keys.vps.removeAlias"):s("common.save"),children:d?e.jsx(T,{size:13,className:"animate-spin"}):!r.trim()&&i?s("keys.clear"):e.jsxs(e.Fragment,{children:[e.jsx(H,{size:13}),s("common.save")]})})]}),l&&e.jsx("div",{className:"mt-1 text-[12px] text-danger",children:l})]})}function Ne(){const{state:t,dispatch:a}=M(),r=t.config?.openaiCompat?.url??"",[c,d]=o.useState(r),[x,l]=o.useState(!1),[u,i]=o.useState(null),h=o.useRef(!1);o.useEffect(()=>{d(r)},[r]);const f=c.trim()!==r,y=()=>{h.current||!f||(h.current=!0,l(!0),i(null),L("/api/config",{method:"PUT",body:JSON.stringify({openaiCompat:{url:c.trim()}})}).then(p=>a({type:"configStatus",config:p})).catch(p=>i(p.message)).finally(()=>{h.current=!1,l(!1)}))};return e.jsxs("div",{children:[e.jsx("div",{className:"mb-1.5 text-[13px] text-ink-secondary",children:s("keys.openaiCompat.url")}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"url",value:c,onChange:p=>d(p.target.value),onBlur:y,onKeyDown:p=>p.key==="Enter"&&y(),placeholder:"https://api.groq.com/openai/v1","aria-label":s("keys.openaiCompat.url"),spellCheck:!1,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 pr-8 font-mono text-[12px] text-ink placeholder:text-ink-secondary focus:outline-none"}),x&&e.jsx(T,{size:13,"aria-hidden":"true",className:"absolute right-2.5 top-1/2 -translate-y-1/2 animate-spin text-ink-secondary"})]}),e.jsx("p",{className:"mt-1 text-[11.5px] leading-relaxed text-ink-secondary",children:s("keys.openaiCompat.urlHint")}),u&&e.jsx("div",{className:"mt-1 text-[12px] text-danger",children:u})]})}function J(t){return t.map(({id:a,name:r})=>({id:a,name:r}))}function fe(t,a){return{browserProfiles:J(a),expectedBrowserProfiles:J(t)}}function ye(){return`profile-${crypto.randomUUID().replaceAll("-","")}`}function V(t,a){const r=t.filter(d=>d.browserProfile===a&&d.busy);if(!r.length)return null;const c=r.map(d=>d.name).join(", ");return r.length===1?s("settings.profiles.busyOne",{names:c}):s("settings.profiles.busyMany",{names:c})}function Ce({bot:t,onProfileChanged:a,disabled:r=!1}){const{state:c,dispatch:d,flushBotPatches:x}=M(),l=c.config?.browserProfiles??[],u=c.bots??[],i=t?u.find(n=>n.id===t.id)??t:void 0,[h,f]=o.useState(null),[y,p]=o.useState(!1),[j,C]=o.useState(""),[b,S]=o.useState(null),[m,g]=o.useState(""),K=o.useId(),w=y||r||h!==!0;o.useEffect(()=>{let n=!0;return ee().then(v=>{n&&f(te(v))}),()=>{n=!1}},[]);const E=async n=>{if(g(n instanceof Error?n.message:s("settings.profiles.saveError")),n instanceof F&&n.status===409)try{const v=await L("/api/config");d({type:"configStatus",config:v})}catch{g(s("settings.profiles.refreshError"))}n instanceof F&&(n.status===401||n.status===403)&&f(!1)},z=async n=>{try{const v=await L("/api/config",{method:"PATCH",body:JSON.stringify(fe(l,n))});return d({type:"configStatus",config:v}),!0}catch(v){return await E(v),!1}},R=async()=>{if(!(w||!j.trim()||l.length>=20)){p(!0),g("");try{await z([...l,{id:ye(),name:j.trim()}])&&C("")}finally{p(!1)}}},N=async()=>{if(!(w||!b?.name.trim())){if(!l.some(n=>n.id===b.id)){g(s("settings.profiles.removed"));return}p(!0),g("");try{await z(l.map(n=>n.id===b.id?{...n,name:b.name.trim()}:n))&&S(null)}finally{p(!1)}}},k=async n=>{if(w)return;const v=V(u,n.id);if(v)return g(v);const D=u.filter(I=>I.browserProfile===n.id),A=D.length?` ${s("settings.profiles.deleteUsers",{names:D.map(I=>I.name).join(", ")})}`:"";if(window.confirm(s("settings.profiles.confirm",{name:n.name,bots:A}))){p(!0),g("");try{await z(l.filter(I=>I.id!==n.id))&&(b?.id===n.id&&S(null),i?.browserProfile===n.id&&a?.())}finally{p(!1)}}},B=async n=>{if(!(w||!i||i.busy||n===(i.browserProfile??""))){p(!0),g("");try{await x(i.id);const v=await L(`/api/bots/${encodeURIComponent(i.id)}`,{method:"PATCH",body:JSON.stringify({browserProfile:n||null})});d({type:"botPatched",bot:v.bot}),a?.()}catch(v){await E(v)}finally{p(!1)}}};if(h===!1)return e.jsx("p",{className:"text-[12px] text-ink-secondary",children:s("settings.profiles.ownerOnly")});const U="min-w-0 flex-1 rounded-md border border-hairline/40 bg-inset px-2.5 py-2 text-[13px] text-ink outline-none focus:border-accent disabled:opacity-50",O="shrink-0 rounded-md bg-control px-2.5 py-2 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-50",P=i?.browserProfile??"";return e.jsxs("div",{className:"flex min-w-0 flex-col gap-3","aria-busy":y,children:[i&&e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{htmlFor:`${K}-profile`,className:"text-[12px] font-medium text-ink",children:s("settings.profiles.browserSession")}),e.jsxs("select",{id:`${K}-profile`,value:P,disabled:w||i.busy,onChange:n=>{B(n.target.value)},className:U,children:[e.jsx("option",{value:"",children:s("settings.profiles.own")}),l.map(n=>e.jsx("option",{value:n.id,children:n.name},n.id)),e.jsx("option",{value:"guest",children:s("settings.profiles.temporary")}),P&&P!=="guest"&&!l.some(n=>n.id===P)?e.jsx("option",{value:P,disabled:!0,children:s("settings.profiles.removed")}):null]}),e.jsx("p",{className:"text-[11px] leading-relaxed text-ink-secondary",children:i.busy?s("settings.profiles.stopToSwitch"):P==="guest"?s("settings.profiles.temporaryHint"):s("settings.profiles.sharedHint")})]}),e.jsxs("details",{open:!i,className:"min-w-0",children:[e.jsx("summary",{className:"cursor-pointer text-[12px] font-medium text-ink-secondary hover:text-ink",children:s("settings.profiles.manage")}),e.jsxs("div",{className:"mt-3 flex flex-col gap-3",children:[e.jsxs("form",{className:"flex flex-wrap gap-2",onSubmit:n=>{n.preventDefault(),R()},children:[e.jsx("label",{htmlFor:`${K}-new`,className:"sr-only",children:s("settings.profiles.newName")}),e.jsx("input",{id:`${K}-new`,value:j,onChange:n=>C(n.target.value),maxLength:40,required:!0,disabled:w||l.length>=20,placeholder:s("settings.profiles.newName"),className:U}),e.jsxs("button",{type:"submit",disabled:w||!j.trim()||l.length>=20,className:`${O} flex items-center gap-1`,children:[e.jsx(se,{size:13}),s("settings.profiles.create")]})]}),l.length>=20&&e.jsx("p",{className:"text-[11px] text-ink-secondary",children:s("settings.profiles.limit")}),!l.length&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:s("settings.profiles.sharedEmpty")}),e.jsx("div",{className:"divide-y divide-hairline/30",children:l.map(n=>{const v=u.filter(A=>A.browserProfile===n.id).map(A=>A.name),D=V(u,n.id);return e.jsxs("div",{className:"flex flex-col gap-1 py-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(ne,{size:14,className:"shrink-0 text-ink-secondary"}),b?.id===n.id?e.jsxs("form",{className:"flex min-w-0 flex-1 flex-wrap gap-2",onSubmit:A=>{A.preventDefault(),N()},children:[e.jsx("input",{autoFocus:!0,value:b.name,onChange:A=>S({id:n.id,name:A.target.value}),maxLength:40,required:!0,disabled:w,className:U,"aria-label":s("settings.profiles.nameAria")}),e.jsx("button",{type:"submit",disabled:w||!b.name.trim(),className:O,children:s("common.save")}),e.jsx("button",{type:"button",disabled:y,onClick:()=>S(null),className:O,children:s("common.cancel")})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:w,onClick:()=>{S({id:n.id,name:n.name}),g("")},className:"min-w-0 flex-1 truncate text-left text-[13px] font-medium text-ink hover:underline disabled:opacity-50",title:s("settings.profiles.rename"),children:n.name}),e.jsxs("button",{type:"button",onClick:()=>{k(n)},disabled:w||!!D,title:D??s("settings.profiles.deleteTitle"),"aria-label":`${s("common.delete")} ${n.name}`,className:"flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-[12px] text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-50",children:[e.jsx(ae,{size:13}),s("common.delete")]})]})]}),e.jsx("p",{className:"break-words pl-6 text-[11px] text-ink-secondary",children:v.length?s("settings.profiles.usedBy",{names:v.join(", ")}):s("settings.profiles.notInUse")})]},n.id)})})]})]}),m&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:m})]})}function Se(){const{capabilities:t}=re(),a=t.localComputer.available?null:t.localComputer.message,r=ie(oe(a)),[c,d]=o.useState(!1),[x,l]=o.useState(!1),[u,i]=o.useState(null),h=async()=>{d(!0),i(null);try{await window.ogb?.localControl?.retry()}catch(y){i(y instanceof Error?y.message:String(y))}finally{d(!1)}},f=async()=>{i(null),l(!0);try{await window.ogb?.permOpenSettings?.("accessibility"),await window.ogb?.permOpenSettings?.("screen")}catch(y){l(!1),i(y instanceof Error?y.message:String(y))}};return o.useEffect(()=>{if(!x)return;let y=!1;const p=()=>{y||document.visibilityState==="visible"&&(y=!0,l(!1),h())};return window.addEventListener("focus",p),document.addEventListener("visibilitychange",p),()=>{window.removeEventListener("focus",p),document.removeEventListener("visibilitychange",p)}},[x]),t.host.platform!=="darwin"||t.localComputer.reasonCode==="remote-server"||t.localComputer.available?null:e.jsx("section",{className:"mt-4 rounded-xl border border-warning/25 bg-warning/10 p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(pe,{size:16,className:"mt-0.5 shrink-0 text-warning"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[14px] font-medium text-ink",children:"Allow control of this computer"}),e.jsx("p",{className:"mt-1 text-[12.5px] leading-relaxed text-ink-secondary",children:r??s("computer.mac.permission.generic")}),a&&e.jsxs("details",{className:"mt-2 text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer",children:s("computer.mac.permission.driverDetail")}),e.jsx("p",{className:"mt-1 break-words",children:a})]}),u&&e.jsxs("div",{className:"mt-2 flex gap-1.5 text-[12px] text-danger",children:[e.jsx(_,{size:13,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:u})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[r&&a&&e.jsx(le,{reason:a}),!r&&e.jsx("button",{type:"button",onClick:()=>{f()},disabled:c,className:"inline-flex items-center gap-1.5 rounded-lg bg-accent px-3 py-1.5 text-[12.5px] font-medium text-white hover:brightness-110 disabled:opacity-50",children:"Open System Settings"}),e.jsxs("button",{type:"button",onClick:()=>{h()},disabled:c,className:"inline-flex items-center gap-1.5 rounded-lg border border-hairline/50 px-3 py-1.5 text-[12.5px] font-medium text-ink hover:bg-raised disabled:opacity-50",children:[c&&e.jsx(T,{size:13,className:"animate-spin"}),"Retry"]})]})]})]})})}export{ke as A,Ce as B,ge as M,Ne as O,we as V,Se as a,je as b,ve as c,be as w};
@@ -0,0 +1,2 @@
1
+ import{g as T,a9 as ne,Y as oe,$ as ie,t as i,r as p,aa as re,ab as le,ac as ce,j as e,X as te,o as de,d as z,ad as pe,ae as ue,af as me,ag as he,u as W,ah as xe,c as J,ai as fe,aj as be,ak as ge,al as ye,am as X,P as ve,T as se,an as we}from"./index-C3NqfdVU.js";import{I as ke,i as I,S as je,a as Se,A as Ne,M as Ee,P as Ce,V as Pe,v as Ae}from"./VisibilitySection-DT0FqPvu.js";import{B as Oe,a as Te}from"./RoutinesPage-BM2D4qGi.js";import"./image-plus-BbVjGHin.js";import"./CloudBackendPicker-iezpJFpF.js";import"./WebhooksPanel--YQyCjKO.js";const Be={profile:{},memory:{},skills:[],routines:[]},Re=t=>({name:t.name,prompt:t.prompt,schedule:t.schedule,enabled:t.enabled,runOn:t.runOn,durationMinutes:t.durationMinutes,timeoutMinutes:t.timeoutMinutes,overlap:t.overlap,attachments:t.attachments});class Z{constructor(s,a,n=T){this.changed=a,this.network=n,this.template=structuredClone(s),this.routines=s.routines.map(r=>this.routine({...r,botId:this.id}))}changed;network;id=`draft-${crypto.randomUUID()}`;template;consent={};routines;preset;avatarFile;avatarObjectUrl;get bot(){const{computer:s,cwd:a,peers:n,toolScope:r,...o}=this.template.profile;return{id:this.id,threadId:this.id,name:"",title:"",description:"",soul:"",color:"green",notifications:!0,unread:!1,messages:[],modelSelection:{instanceId:"",model:""},...o,computer:s??void 0,cwd:a??void 0,peers:n??void 0,toolScope:r??void 0}}patch(s){const{confirmFullAccess:a,acknowledgeLocalAuto:n,acknowledgePeerScope:r,applyToAllThreads:o,autoApprove:c,...l}=s;a!==void 0&&(this.consent.confirmFullAccess=a),n!==void 0&&(this.consent.acknowledgeLocalAuto=n),r!==void 0&&(this.consent.acknowledgePeerScope=r),c!==void 0&&l.approvalMode===void 0&&(l.approvalMode=c?"auto":"ask"),this.template.profile={...this.template.profile,...l},this.changed()}setModel(s){this.patch({modelSelection:s})}choosePreset(s){this.preset=s,this.changed()}setMemory(s,a){a===null?delete this.template.memory[s]:this.template.memory[s]=a,this.changed()}setRoutineEnabled(s,a){this.routines=this.routines.map(n=>n.id===s?{...n,enabled:a}:n),this.changed()}removeRoutine(s){this.routines=this.routines.filter(a=>a.id!==s),this.changed()}export(){return structuredClone({...this.template,routines:this.routines.map(Re)})}uploadAvatar=async s=>{if(!["image/png","image/jpeg","image/gif","image/webp"].includes(s.type))throw new Error("Choose a PNG, JPEG, GIF, or WebP image");if(s.size>10*1024*1024)throw new Error("Choose an image smaller than 10 MiB");return this.avatarObjectUrl&&URL.revokeObjectURL(this.avatarObjectUrl),this.avatarFile=s,this.avatarObjectUrl=URL.createObjectURL(s),this.avatarObjectUrl};dispose(){this.avatarObjectUrl&&URL.revokeObjectURL(this.avatarObjectUrl)}routine(s,a){const{groupId:n,resultsThreadId:r,schedule:o,...c}=s,l=o.type==="interval"?{...o,weekdays:o.weekdays??void 0,window:o.window??void 0,endsAt:o.endsAt??void 0}:o;return{id:a?.id??`draft-${crypto.randomUUID()}`,createdAt:a?.createdAt??Date.now(),updatedAt:Date.now(),nextRunAt:null,runOn:"maus",...a,...c,enabled:s.enabled??a?.enabled??!0,target:"bot",botId:this.id,timeoutMinutes:s.timeoutMinutes??void 0,durationMinutes:s.durationMinutes??a?.durationMinutes??30,schedule:l}}request=async(s,a)=>{const n=a?.method??"GET",r=typeof a?.body=="string"?JSON.parse(a.body):{},o=`/api/bots/${this.id}`;let c;if(s===o&&n==="PATCH")this.patch(r),c={bot:this.bot};else if(s===`${o}/soul`&&n==="GET")c={soul:this.bot.soul,revision:"draft",bytes:new TextEncoder().encode(this.bot.soul).length,limit:24e3,file:"",drift:!1};else if(s===`${o}/skills`&&n==="GET")c={skills:this.template.skills,staged:[]};else if(s===`${o}/skills`&&n==="POST"){const l=await this.network("/api/bot-defaults/skills/preview",{method:"POST",body:JSON.stringify(r)}),y=new Set(this.template.skills.map(m=>m.name));if(l.skills.some(m=>y.has(m.name)))throw new Error("A skill with this name is already in the draft");this.template.skills.push(...l.skills),this.changed(),c={installed:l.skills}}else if(s.startsWith(`${o}/skills/`)){const l=decodeURIComponent(s.slice(`${o}/skills/`.length)),y=this.template.skills.find(m=>m.name===l);if(!y)throw new Error("No such draft skill");if(n==="GET")c={text:y.text};else if(n==="PATCH"&&typeof r.enabled=="boolean")y.enabled=r.enabled,this.changed(),c={ok:!0};else if(n==="DELETE")this.template.skills=this.template.skills.filter(m=>m!==y),this.changed(),c={ok:!0};else throw new Error("Unsupported draft skill operation")}else if(s===`${o}/avatar/generate`&&n==="POST"){const{name:l,title:y,description:m}=this.bot,{dataUrl:E}=await this.network("/api/bot-defaults/avatar",{method:"POST",body:JSON.stringify({profile:{name:l,title:y,description:m},prompt:r.prompt})}),P=await(await fetch(E)).blob(),b=await this.uploadAvatar(new File([P],"avatar.png",{type:P.type}));c={avatarUrl:b,bot:{...this.bot,avatarUrl:b,avatarCrop:"circle"}}}else if(s==="/api/routines"&&n==="POST"||s.startsWith("/api/routines/draft-")&&n==="PATCH"){if(r.target&&r.target!=="bot")throw new Error("A new bot's routine must target that bot");if(r.botId!==this.id)throw new Error("Routine belongs to another bot");const l=this.routines.find(m=>s===`/api/routines/${m.id}`);if(n==="PATCH"&&!l)throw new Error("No such draft routine");const y=this.routine(r,l);this.routines=[...this.routines.filter(m=>m.id!==y.id),y],this.changed(),c={routine:y}}else throw new Error("This operation requires a created bot");return c}}async function ae(t){const s=t.export();if(s.profile.avatarUrl?.startsWith("blob:")){if(!t.avatarFile)throw new Error("Choose the avatar image again");const a=await oe(t.avatarFile),n=a&&ie(a.path);if(!n)throw new Error("Could not store the avatar image");s.profile.avatarUrl=n}return s}async function Me(t,s=T,a=ne,n=typeof window>"u"?void 0:window.ogb?.approvals,r){const o=await ae(t),{chiefOfStaff:c,managedSections:l,toolScope:y,...m}=o.profile;if(!m.name?.trim())throw new Error("Give the bot a name");const E=t.preset;let b=(await s("/api/bots",{method:"POST",body:JSON.stringify({name:m.name,title:m.title,description:m.description,modelSelection:m.modelSelection,section:m.section,requireAvailableModel:!0,useDefaults:!1,...r!==void 0?{visibility:r}:{},...Object.hasOwn(o.profile,"toolScope")?{settings:{toolScope:y}}:{},...E?{preset:E.id}:{}})})).bot;const x=[],f=[];try{const g=await a(b.id,{...m,modelSelection:b.modelSelection,...t.consent},new AbortController().signal,s,n,b);if(b={...b,...g},m.approvalMode==="full"||m.approvalMode==="custom"){if(g.approvalMode!==m.approvalMode||!n)throw new Error("The bot's requested approval level was not granted");if((await n.setMode(b.id,m.approvalMode,{threadId:b.threadId,threadOnly:!0,acknowledgeLocalAuto:t.consent.acknowledgeLocalAuto===!0})).approvalMode!==m.approvalMode)throw new Error("The initial thread's requested approval level was not granted")}for(const[u,k]of Object.entries(o.memory))E?.notes.includes(u)||await s(`/api/bots/${b.id}/memory/file`,{method:"PUT",body:JSON.stringify({path:u,text:k})});for(const u of o.skills)E?.skills.includes(u.name)||await s(`/api/bots/${b.id}/skill-template`,{method:"POST",body:JSON.stringify(u)});for(const u of o.routines){const k=await s("/api/routines",{method:"POST",body:JSON.stringify({...u,botId:b.id,enabled:!1})});x.push({id:k.routine.id,enabled:u.enabled!==!1})}}catch(g){const u=[];for(const v of x)try{await s(`/api/routines/${v.id}`,{method:"DELETE"})}catch{u.push(`routine ${v.id}`)}try{await s(`/api/bots/${b.id}`,{method:"DELETE"})}catch{u.push(`bot ${b.name} (${b.id})`)}const k=g instanceof Error?g.message:String(g);throw new Error(u.length?`${k}. Cleanup failed for ${u.join(", ")}; remove them before retrying.`:k)}if(c)try{const g=await s(`/api/bots/${b.id}`,{method:"PATCH",body:JSON.stringify({chiefOfStaff:c,managedSections:l,acknowledgePeerScope:!0})});b={...b,...g.bot}}catch(g){f.push(`Review this bot's Chief of Staff setting: ${g instanceof Error?g.message:String(g)}`)}for(const g of x.filter(u=>u.enabled))try{await s(`/api/routines/${g.id}`,{method:"PATCH",body:JSON.stringify({enabled:!0})})}catch(u){f.push(`Could not activate a routine: ${u instanceof Error?u.message:String(u)}`)}return{bot:b,warnings:f}}function De(t){const s=[];for(const a of t){const n=a.source==="org"?i("newBot.presetsFromOrganization",{name:a.publisherName??a.packageName}):i("newBot.presetsImported"),r=s.find(o=>o.label===n);r?r.presets.push(a):s.push({label:n,presets:[a]})}return s}function $e(t){const s={name:t.bot.name??t.name,title:t.bot.title??"",description:t.bot.description??"",soul:t.bot.soul??""},a=t.bot.appearance;return a&&(s.color=a.color,s.mascotExpression=a.mascotExpression??null,a.mascotBody&&(s.mascotBody=a.mascotBody)),s}function Ue(t){const s=t.bot.appearance?.avatar;if(!s)return null;let a;try{a=atob(s.data)}catch{return null}const n=new Uint8Array(a.length);for(let r=0;r<a.length;r+=1)n[r]=a.charCodeAt(r);return new File([n],`preset.${s.mime.slice(6)}`,{type:s.mime})}function Le(t){const s=[t.source==="org"&&t.publisherName?i("newBot.presetFromOrg",{package:t.packageName,release:t.release,publisher:t.publisherName}):i("newBot.presetFrom",{package:t.packageName,release:t.release})];t.description&&s.push(t.description);const a=t.skills.map(n=>n.name).join(", ");return a&&s.push(i(t.skillsEnabled?"newBot.presetSkillsOn":"newBot.presetSkillsOff",{names:a})),t.notes.length&&s.push(i("newBot.presetNotes",{names:t.notes.join(", ")})),t.playbooks.length&&s.push(i("newBot.presetPlaybooks",{names:t.playbooks.join(", ")})),s.push(i("newBot.presetKeeps")),s}function Ie(t){return{id:t.id,skills:t.skills.map(s=>s.name),notes:[...t.notes]}}function Q(t){const s=a=>a?.trim()?a.trim():void 0;return{format:"package",version:2,kind:"library",name:s(t.name),presetName:s(t.name),presetDescription:s(t.description),release:s(t.release),notes:s(t.notes),includeMemory:t.includeNotes,...t.picture?{presetAvatar:t.picture}:{},...t.dryRun?{dryRun:!0}:{}}}function ee({preview:t,localSkips:s}){const a=t.document.package.presets?.[0],n=Object.keys(a?.seed?.memory??{}).length,r=[[i("teamShare.part.skills"),a?.skills?.length?`${a.skills.length} · ${a.skills.join(", ")}`:"0"],[i("teamShare.part.notes"),n?String(n):i("teamShare.none")],[i("teamShare.part.pictures"),a?.bot.appearance?.avatar?i("teamShare.yes"):i("teamShare.none")]],o=[...s,...t.skipped.map(c=>pe(c,t.document))];return e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] font-medium text-ink-secondary",children:i("teamShare.included")}),e.jsx("dl",{className:"mt-2 grid grid-cols-[minmax(0,1fr)_auto] gap-x-4 gap-y-1.5 rounded-xl bg-raised/45 px-4 py-3 text-[12.5px]",children:r.map(([c,l])=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-ink-secondary",children:c}),e.jsx("dd",{className:"max-w-[300px] truncate text-right text-ink",title:l,children:l})]},c))}),e.jsxs("p",{className:"mt-3 flex items-start gap-2 text-[12.5px] leading-relaxed text-ink-secondary",children:[e.jsx(ue,{size:15,className:"mt-0.5 shrink-0 text-success"}),e.jsx("span",{children:i("presetShare.never")})]}),t.redacted.length>0&&e.jsxs("div",{className:"mt-3 rounded-xl border border-hairline px-4 py-3 text-[12.5px] text-ink-secondary",children:[e.jsx("div",{className:"font-medium text-ink",children:i("teamShare.redacted")}),e.jsx("ul",{className:"mt-1 list-disc pl-5",children:t.redacted.map(c=>e.jsx("li",{children:me(c,t.document)},c))})]}),o.length>0&&e.jsxs("div",{className:"mt-3 rounded-xl border border-hairline px-4 py-3 text-[12.5px] text-ink-secondary",children:[e.jsx("div",{className:"font-medium text-ink",children:i("teamShare.skipped")}),e.jsx("ul",{className:"mt-1 list-disc pl-5",children:o.map((c,l)=>e.jsx("li",{children:c},`${c}-${l}`))})]})]})}function Fe({onClose:t}){const s=p.useRef(null),[a,n]=p.useState(""),[r,o]=p.useState(""),[c,l]=p.useState(""),[y,m]=p.useState(""),[E,P]=p.useState(!0),[b,x]=p.useState(!0),[f,g]=p.useState(null),[u,k]=p.useState(null),[v,R]=p.useState(!1),[M,B]=p.useState(null),[D,$]=p.useState(""),U=p.useRef(0);p.useEffect(()=>{let d=!1;return T("/api/bot-defaults").then(async({defaults:S})=>{!d&&S.profile.name?.trim()&&n(A=>A||S.profile.name.trim());const j=await re([{id:"defaults",avatarUrl:S.profile.avatarUrl,avatarCrop:S.profile.avatarCrop}]);d||g({dataUrl:j.avatars.defaults,skipped:j.skipped.map(A=>`${i("teamShare.field.picture")} — ${le(`teamShare.skip.${A.reason}`,A.reason)}`)})}).catch(()=>{d||g({skipped:[]})}),()=>{d=!0}},[]);const F=d=>({name:a,description:r,release:c,notes:y,includeNotes:E,dryRun:d,...b&&f?.dataUrl?{picture:f.dataUrl}:{}});p.useEffect(()=>{if(!f)return;const d=++U.current,S=window.setTimeout(()=>{T("/api/teams/export",{method:"POST",body:JSON.stringify(Q({...F(!0),release:void 0}))}).then(j=>{d===U.current&&(k(j),$(""),l(A=>A||j.document.package.release))}).catch(j=>{d===U.current&&(k(null),$(j instanceof Error?j.message:String(j)))})},250);return()=>window.clearTimeout(S)},[f,E,b]);const H=async()=>{if(!v){R(!0),$("");try{const d=await T("/api/teams/export",{method:"POST",body:JSON.stringify(Q(F(!1)))});he(d.filename,d.document),B(d)}catch(d){$(d instanceof Error?d.message:String(d))}finally{R(!1)}}};p.useEffect(()=>{const d=document.activeElement instanceof HTMLElement?document.activeElement:null;return s.current?.focus(),()=>{d?.isConnected&&d.focus()}},[]);const L=b?f?.skipped??[]:[],O="mt-1 w-full rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[13.5px] text-ink disabled:opacity-60";return ce.createPortal(e.jsx("div",{className:"fixed inset-0 z-[80] flex items-center justify-center bg-black/55 p-4",onMouseDown:d=>{d.target===d.currentTarget&&!v&&t()},children:e.jsxs("div",{ref:s,role:"dialog","aria-modal":"true","aria-labelledby":"share-preset-title",tabIndex:-1,className:"flex max-h-[90vh] w-full max-w-[560px] flex-col overflow-hidden rounded-2xl border border-hairline/50 bg-panel text-ink shadow-2xl outline-none",onKeyDown:d=>{if(d.key==="Escape"&&!v&&(d.stopPropagation(),t()),d.key==="Tab"){const S=s.current?.querySelectorAll("input:enabled, textarea:enabled, button:enabled");if(!S?.length)return;const j=S[0],A=S[S.length-1];d.shiftKey&&document.activeElement===j?(d.preventDefault(),A.focus()):!d.shiftKey&&document.activeElement===A&&(d.preventDefault(),j.focus())}},children:[e.jsxs("header",{className:"flex items-start justify-between gap-3 px-6 pb-2 pt-5",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"share-preset-title",className:"text-[17px] font-semibold",children:i("presetShare.title")}),e.jsx("p",{className:"mt-1 text-[12.5px] leading-relaxed text-ink-secondary",children:i("presetShare.intro")})]}),e.jsx("button",{"aria-label":i("presetShare.close"),disabled:v,onClick:t,className:"rounded-lg p-1.5 text-ink-secondary hover:bg-raised",children:e.jsx(te,{size:18})})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 pb-4 pt-2",children:M?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"flex items-center gap-2 text-[13.5px] font-medium text-ink",children:[e.jsx(de,{size:16,className:"text-success"}),i("teamShare.saved",{filename:M.filename})]}),e.jsx("p",{className:"mt-1 text-[12.5px] leading-relaxed text-ink-secondary",children:i("presetShare.savedHint")}),e.jsx("div",{className:"mt-4",children:e.jsx(ee,{preview:M,localSkips:L})})]}):e.jsxs(e.Fragment,{children:[u?e.jsx(ee,{preview:u,localSkips:L}):!D&&e.jsxs("div",{className:"flex items-center gap-2 py-6 text-[13px] text-ink-secondary",children:[e.jsx(z,{size:15,className:"animate-spin"}),i("presetShare.preparing")]}),e.jsxs("fieldset",{className:"mt-4 space-y-2 text-[13px]",disabled:v,children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",className:"size-4 accent-accent",checked:b,onChange:d=>x(d.target.checked)}),i("presetShare.includePicture")]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",className:"size-4 accent-accent",checked:E,onChange:d=>P(d.target.checked)}),i("presetShare.includeNotes")]})]}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"block text-[12.5px] text-ink-secondary",children:[i("presetShare.name"),e.jsx("input",{value:a,maxLength:100,disabled:v,onChange:d=>n(d.target.value),className:O})]}),e.jsxs("label",{className:"block text-[12.5px] text-ink-secondary",children:[i("teamShare.release"),e.jsx("input",{value:c,maxLength:20,disabled:v,placeholder:"1.0.0",onChange:d=>l(d.target.value),className:O})]})]}),e.jsxs("label",{className:"mt-3 block text-[12.5px] text-ink-secondary",children:[i("presetShare.description"),e.jsx("input",{value:r,maxLength:300,disabled:v,onChange:d=>o(d.target.value),className:O})]}),e.jsxs("label",{className:"mt-3 block text-[12.5px] text-ink-secondary",children:[i("teamShare.notes"),e.jsx("textarea",{value:y,maxLength:4e3,rows:2,disabled:v,onChange:d=>m(d.target.value),className:O})]})]})}),D&&e.jsx("p",{role:"alert",className:"mx-6 mb-2 rounded-lg bg-danger/10 px-3 py-2 text-[12.5px] text-danger",children:D}),e.jsx("footer",{className:"flex justify-end gap-2 border-t border-hairline/35 px-6 py-3",children:M?e.jsx("button",{onClick:t,className:"rounded-lg bg-accent px-4 py-2 text-[13px] font-medium text-white",children:i("teamShare.done")}):e.jsxs(e.Fragment,{children:[e.jsx("button",{disabled:v,onClick:t,className:"rounded-lg px-3 py-2 text-[13px] text-ink-secondary hover:bg-raised",children:i("common.cancel")}),e.jsxs("button",{disabled:v||!u,onClick:()=>{H()},className:"flex items-center gap-2 rounded-lg bg-accent px-4 py-2 text-[13px] font-medium text-white disabled:opacity-40",children:[v&&e.jsx(z,{size:14,className:"animate-spin"}),v?i("teamShare.saving"):i("teamShare.save")]})]})})]})}),document.body)}const ze=["Identity","Soul","Skills","Memory","Routines","Access","Model","Permissions","Voice & alerts"];function Je(){const{state:t,dispatch:s}=W(),a=p.useRef(null),n=()=>s({type:"toggleNewBot",open:!1});return p.useEffect(()=>{const r=document.activeElement instanceof HTMLElement?document.activeElement:null;return a.current?.focus(),()=>{r?.isConnected&&r.focus()}},[]),e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",children:e.jsxs("div",{ref:a,role:"dialog","aria-modal":"true","aria-label":i("newBot.create"),tabIndex:-1,className:"w-full max-w-sm rounded-2xl border border-hairline/50 bg-panel p-5 text-ink shadow-2xl",onKeyDown:r=>{if(r.key==="Escape"&&(r.stopPropagation(),n()),r.key==="Tab"){const o=r.currentTarget,c=[...o.querySelectorAll("button:not([disabled])")];r.shiftKey&&(document.activeElement===o||document.activeElement===c[0])?(r.preventDefault(),c.at(-1)?.focus()):!r.shiftKey&&document.activeElement===c.at(-1)&&(r.preventDefault(),c[0]?.focus())}},children:[e.jsx("h2",{className:"mb-4 text-[17px] font-semibold",children:i("newBot.create")}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:n,className:"rounded-lg px-3 py-2",children:i("common.cancel")}),e.jsx("button",{type:"button",disabled:t.botCreationPending,onClick:()=>s({type:"newBot",onCreated:n}),className:"rounded-lg bg-accent px-4 py-2 text-white disabled:opacity-40",children:i("newBot.create")})]})]})})}function He(t={}){return typeof window<"u"&&window.ogb?.remoteClient?.active?e.jsx(Je,{}):e.jsx(Ge,{...t})}function Ge({defaultsMode:t=!1,onClose:s,section:a,onCreated:n,preserveSelection:r=!1}={}){const o=W(),[,c]=p.useState(0),[l,y]=p.useState(()=>new Z(Be,()=>c(h=>h+1))),[m,E]=p.useState("Identity"),[P,b]=p.useState(!1),[x,f]=p.useState(!1),g=x||o.state.botCreationPending,u=p.useRef(!1),k=p.useRef(!0),[v,R]=p.useState(""),[M,B]=p.useState(null),[D,$]=p.useState("everyone"),[U,F]=p.useState(""),H=xe(),L=!t&&typeof window<"u"&&!window.ogb&&H===!0,O=p.useRef(null),d=p.useRef(()=>{});d.current=()=>{s?s():o.dispatch({type:"toggleNewBot",open:!1})},p.useEffect(()=>{let h=!1;return T("/api/bot-defaults").then(N=>{if(h)return;const w=structuredClone(N.defaults);w.profile.modelSelection??=N.modelSelection,t||(w.profile.name=w.profile.name?.trim()||N.suggestedName),a!==void 0&&(w.profile.section=a),y(new Z(w,()=>c(C=>C+1))),b(!0)}).catch(N=>{h||R(String(N))}),()=>{h=!0}},[t,a]),p.useEffect(()=>(k.current=!0,()=>{k.current=!1}),[]),p.useEffect(()=>()=>l.dispose(),[l]),p.useEffect(()=>{g&&O.current?.focus()},[g]),p.useEffect(()=>{const h=document.activeElement instanceof HTMLElement?document.activeElement:null;O.current?.focus();const N=w=>{const C=O.current;if(!C||w.target instanceof Node&&!C.contains(w.target))return;const Y=C.querySelector('[role="dialog"], [role="alertdialog"]');if(Y&&Y.getClientRects().length||(w.key==="Escape"&&(w.preventDefault(),d.current()),w.key!=="Tab"))return;const q=[...C.querySelectorAll('button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex="0"]')].filter(V=>V.getClientRects().length&&!V.closest("[hidden],fieldset:disabled")),G=q[0],K=q.at(-1);if(!G||!K){w.preventDefault(),C.focus();return}w.shiftKey&&(document.activeElement===G||document.activeElement===C)?(w.preventDefault(),K.focus()):!w.shiftKey&&(document.activeElement===K||document.activeElement===C)&&(w.preventDefault(),G.focus())};return window.addEventListener("keydown",N),()=>{window.removeEventListener("keydown",N),h?.isConnected&&h.focus()}},[]);const S=async()=>{if(!P||u.current||o.state.botCreationPending)return;if(!t&&l.bot.approvalMode==="full"&&!l.consent.confirmFullAccess){B("full");return}if(!t&&l.bot.approvalMode==="auto"&&l.bot.computer==="local"&&!l.consent.acknowledgeLocalAuto){B("local");return}const h=L?Ae(D,U):null;if(h&&!h.ok){R(i("botSettings.visibility.needPeople"));return}u.current=!0,f(!0),R(""),o.dispatch({type:"botCreationPending",on:!0});try{if(t)await T("/api/config",{method:"PATCH",body:JSON.stringify({newBotDefaults:await ae(l)})});else{const{bot:N,warnings:w}=await Me(l,void 0,void 0,void 0,h?.ok?h.visibility:void 0);o.dispatch({type:"botAdded",bot:N,preserveSelection:r}),w.length&&o.dispatch({type:"error",message:w.join(`
2
+ `)});try{await n?.(N)}catch(C){o.dispatch({type:"error",message:C instanceof Error?C.message:String(C)})}}u.current=!1,k.current&&d.current()}catch(N){k.current&&R(N instanceof Error?N.message:String(N))}finally{u.current=!1,o.dispatch({type:"botCreationPending",on:!1}),k.current&&f(!1)}},j=l.bot,A={...o,state:{...o.state,bots:[j,...o.state.bots],routines:l.routines,routineRuns:[],routinesLoadState:"ready"},flushBotPatches:async()=>j,dispatch:h=>{h.type==="updateBot"&&h.botId===l.id?l.patch(h.patch):h.type==="setModel"&&h.botId===l.id?(l.setModel(h.selection),h.resetApprovalToAsk&&l.patch({approvalMode:"ask"})):h.type==="routinePatched"||h.type==="toggleSettings"||o.dispatch(h)}},_=t?i("newBot.defaults"):i("sidebar.newBot");return e.jsx("div",{className:"fixed inset-0 z-[70] flex items-center justify-center bg-black/60 p-3 sm:p-5",children:e.jsxs("div",{ref:O,role:"dialog","aria-modal":"true","aria-label":_,"aria-busy":g,tabIndex:-1,className:"flex h-[min(760px,94dvh)] w-full max-w-[900px] flex-col overflow-hidden rounded-2xl border border-hairline/50 bg-panel shadow-2xl outline-none",children:[e.jsxs("div",{className:"flex shrink-0 items-center justify-between border-b border-hairline/40 px-5 py-4",children:[e.jsx("h2",{className:"text-[17px] font-semibold text-ink",children:_}),e.jsx("button",{type:"button",onClick:()=>d.current(),"aria-label":i("common.close"),className:"flex size-8 shrink-0 items-center justify-center rounded-lg text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:e.jsx(te,{size:18,className:"pointer-events-none"})})]}),L&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 px-5 pt-3 text-[13px] text-ink-secondary","data-new-bot-visibility":!0,children:[e.jsxs("label",{className:"flex items-center gap-2",children:[i("botSettings.visibility.title"),e.jsxs("select",{value:D,disabled:g,onChange:h=>$(h.target.value),className:"rounded-lg border border-hairline/40 bg-inset px-2 py-1.5 text-[13px] text-ink focus:outline-none",children:[e.jsx("option",{value:"everyone",children:i("botSettings.visibility.everyone")}),e.jsx("option",{value:"admins",children:i("botSettings.visibility.admins")}),e.jsx("option",{value:"people",children:i("botSettings.visibility.people")})]})]}),D==="people"&&e.jsx("input",{value:U,disabled:g,onChange:h=>F(h.target.value),placeholder:i("botSettings.visibility.peoplePlaceholder"),"aria-label":i("botSettings.visibility.peopleLabel"),className:"min-w-[16rem] flex-1 rounded-lg border border-hairline/40 bg-inset px-3 py-1.5 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col sm:flex-row",children:[e.jsx("nav",{"aria-label":i("newBot.sections"),className:"flex shrink-0 gap-1 overflow-x-auto border-b border-hairline/40 p-2 sm:w-40 sm:flex-col sm:border-b-0 sm:border-r",children:ze.map(h=>e.jsx("button",{type:"button",onClick:()=>E(h),"aria-current":m===h?"page":void 0,className:J("shrink-0 rounded-lg px-3 py-2 text-left text-[13px]",m===h?"bg-control text-ink":"text-ink-secondary hover:bg-control/50"),children:h},h))}),e.jsxs("div",{className:"min-h-0 min-w-0 flex-1 overflow-y-auto p-4 sm:p-5",children:[!P&&!v&&e.jsxs("div",{role:"status",className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(z,{size:16,className:"animate-spin"}),i("newBot.loading")]}),P&&e.jsx("fieldset",{disabled:g,className:"min-w-0",children:e.jsx(fe,{value:A,children:e.jsx(Oe.Provider,{value:{request:l.request,draft:!0,uploadAvatar:l.uploadAvatar},children:e.jsx(Ke,{active:m,draft:l,defaultsMode:t})})})})]})]}),v&&e.jsx("p",{role:"alert",className:"max-h-24 overflow-y-auto border-t border-hairline/40 px-5 py-3 text-[13px] text-danger",children:v}),e.jsxs("div",{className:"flex shrink-0 justify-end gap-2 border-t border-hairline/40 px-5 py-3",children:[e.jsx("button",{type:"button",onClick:()=>d.current(),className:"rounded-lg px-4 py-2 text-[13px] text-ink-secondary hover:bg-control",children:i("common.cancel")}),e.jsxs("button",{type:"button",disabled:!P||g||!t&&!j.name.trim(),onClick:()=>{S()},className:"flex items-center gap-2 rounded-lg bg-accent px-5 py-2 text-[13px] font-medium text-white hover:brightness-110 disabled:opacity-40",children:[g&&e.jsx(z,{size:15,className:"animate-spin"}),i(t?"newBot.saveDefaults":"newBot.create")]})]}),e.jsx(be,{open:M==="full",onCancel:()=>B(null),onConfirm:()=>{l.consent.confirmFullAccess=!0,B(null),S()}}),e.jsx(ge,{open:M==="local",onCancel:()=>B(null),onConfirm:()=>{l.consent.acknowledgeLocalAuto=!0,B(null),S()}})]})})}function Ke({active:t,draft:s,defaultsMode:a}){const n=s.bot,{state:r}=W(),o=ye(n);return t==="Identity"?e.jsxs("div",{className:"space-y-4",children:[e.jsx(We,{draft:s,defaultsMode:a}),e.jsx(ke,{bot:n,patch:o.patch,activeState:o.activeState,mascotMotion:null,namePlaceholder:a?i("newBot.randomName"):void 0}),e.jsxs("label",{className:"block text-[13px] text-ink-secondary",children:["Team",e.jsxs("select",{className:J(I,"mt-1.5"),value:n.section??"",onChange:c=>s.patch({section:c.target.value}),children:[e.jsx("option",{value:"",children:"General"}),[...new Set([...r.sections??[],...r.bots.map(c=>c.section??"")])].filter(Boolean).map(c=>e.jsx("option",{children:c},c))]})]})]}):t==="Soul"?e.jsx(je,{bot:n,patch:o.patch}):t==="Skills"?e.jsx(Se,{bot:n}):t==="Memory"?e.jsx(_e,{draft:s}):t==="Routines"?e.jsx(Ye,{draft:s}):t==="Access"?e.jsx(Ne,{bot:n,derived:o}):t==="Model"?e.jsx(Ee,{bot:n}):t==="Permissions"?e.jsx(Ce,{bot:n,derived:o}):e.jsx(Pe,{bot:n,derived:o})}function We({draft:t,defaultsMode:s}){const[a,n]=p.useState([]),[r,o]=p.useState(0),[c,l]=p.useState(""),y=p.useRef(!1);p.useEffect(()=>{if(s)return;let x=!1;return T("/api/bot-presets").then(f=>{x||n(f.presets)}).catch(()=>{x||n([])}),()=>{x=!0}},[s,r]);const m=t.preset?a.find(x=>x.id===t.preset.id):void 0,E=async x=>{l("");const f=x.startsWith("preset:")?a.find(u=>u.id===x.slice(7)):void 0;if(!f){t.choosePreset(void 0);const u=X.find(k=>k.id===x);u&&t.patch(we(u));return}t.patch($e(f)),t.choosePreset(Ie(f));const g=Ue(f);try{g?(t.patch({avatarUrl:await t.uploadAvatar(g),avatarCrop:f.bot.appearance.avatar.crop}),y.current=!0):y.current&&(t.patch({avatarUrl:""}),y.current=!1)}catch(u){l(u instanceof Error?u.message:String(u))}},P=async x=>{l("");try{await T(`/api/bot-presets/${encodeURIComponent(x.id)}`,{method:"DELETE"}),t.preset?.id===x.id&&t.choosePreset(void 0),o(f=>f+1)}catch(f){l(f instanceof Error?f.message:String(f))}},b=X.map(x=>e.jsx("option",{value:x.id,children:x.title},x.id));return e.jsxs("div",{children:[e.jsxs("label",{className:"block text-[13px] text-ink-secondary",children:[i("newBot.startingRole"),e.jsxs("select",{className:J(I,"mt-1.5"),value:t.preset?`preset:${t.preset.id}`:"",onChange:x=>{E(x.target.value)},children:[e.jsx("option",{value:"",children:i("newBot.customSettings")}),De(a).map(x=>e.jsx("optgroup",{label:x.label,children:x.presets.map(f=>e.jsx("option",{value:`preset:${f.id}`,children:f.name},f.id))},x.label)),a.length?e.jsx("optgroup",{label:i("newBot.builtInRoles"),children:b}):b]})]}),m&&e.jsxs("div",{className:"mt-2 space-y-1 rounded-lg bg-card px-3 py-2.5 text-[12.5px] text-ink-secondary","data-new-bot-preset":!0,children:[Le(m).map((x,f)=>e.jsx("p",{className:"break-words",children:x},f)),m.source==="file"&&e.jsx("button",{type:"button",onClick:()=>{P(m)},className:"mt-1 rounded-md px-2 py-1 text-[12px] text-ink-secondary hover:bg-control hover:text-ink",children:i("newBot.presetRemove")})]}),c&&e.jsx("p",{role:"alert",className:"mt-2 text-[12.5px] text-danger",children:c})]})}function _e({draft:t}){const[s,a]=p.useState("MEMORY.md"),[n,r]=p.useState("");return e.jsxs("div",{className:"space-y-3",children:[e.jsx("select",{className:I,"aria-label":"Memory file",value:s,onChange:o=>a(o.target.value),children:[...new Set(["MEMORY.md",...Object.keys(t.template.memory)])].map(o=>e.jsx("option",{children:o},o))}),e.jsx("textarea",{className:J(I,"min-h-72 font-mono"),"aria-label":"Memory contents",value:t.template.memory[s]??"",onChange:o=>t.setMemory(s,o.target.value)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{className:I,"aria-label":"New memory topic",placeholder:"Topic name",value:n,onChange:o=>r(o.target.value)}),e.jsx("button",{type:"button","aria-label":"Add memory topic",disabled:!/^[a-zA-Z0-9_-]+$/.test(n),className:"rounded-lg bg-control px-3 disabled:opacity-40",onClick:()=>{const o=`memory/${n}.md`;o in t.template.memory||t.setMemory(o,""),a(o),r("")},children:e.jsx(ve,{size:16})}),s!=="MEMORY.md"&&e.jsx("button",{type:"button","aria-label":"Remove memory topic",className:"rounded-lg bg-control px-3",onClick:()=>{t.setMemory(s,null),a("MEMORY.md")},children:e.jsx(se,{size:16})})]})]})}function Ye({draft:t}){const[s,a]=p.useState(null);return e.jsxs("div",{className:"space-y-3",children:[e.jsx("button",{type:"button",className:"rounded-lg bg-accent px-3 py-2 text-[13px] text-white",onClick:()=>a("new"),children:i("computer.routines.create")}),t.routines.map(n=>e.jsxs("div",{className:"flex items-center gap-2 rounded-lg bg-card p-3",children:[e.jsx("button",{type:"button",className:"min-w-0 flex-1 text-left text-[13px]",onClick:()=>a(n),children:n.name}),e.jsxs("label",{className:"flex items-center gap-1.5 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:n.enabled,onChange:r=>t.setRoutineEnabled(n.id,r.target.checked)}),"Enabled"]}),e.jsx("button",{type:"button","aria-label":`Remove ${n.name}`,onClick:()=>t.removeRoutine(n.id),className:"rounded p-1.5 hover:bg-control",children:e.jsx(se,{size:15})})]},n.id)),s&&e.jsx(Te,{routine:s==="new"?void 0:s,bots:[t.bot],lockedBotId:t.id,onClose:()=>a(null)})]})}function tt(){const[t,s]=p.useState(!1),[a,n]=p.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 py-3",children:[e.jsx("span",{className:"text-[13px] text-ink",children:i("newBot.defaults")}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[e.jsx("button",{type:"button",onClick:()=>n(!0),className:"rounded-lg px-3 py-1.5 text-[13px] text-ink-secondary hover:bg-control hover:text-ink",children:i("newBot.sharePreset")}),e.jsx("button",{type:"button",onClick:()=>s(!0),className:"rounded-lg bg-control px-3 py-1.5 text-[13px] text-ink hover:bg-raised-hover",children:i("newBot.edit")})]})]}),t&&e.jsx(He,{defaultsMode:!0,onClose:()=>s(!1)}),a&&e.jsx(Fe,{onClose:()=>n(!1)})]})}export{Je as CompanionNewBotDialog,tt as DefaultBotSettings,Ge as LocalNewBotDialog,He as NewBotDialog};
@@ -0,0 +1 @@
1
+ import{k as w,u as C,a as z,r as i,j as e,Q as S,X as P,c as y,B as T,d as A,T as E,U as m,V as L,q as I,Y as R,$ as B,g as U}from"./index-C3NqfdVU.js";import{I as F}from"./image-plus-BbVjGHin.js";const V=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}]],_=w("bell",V);function M({bot:t,overlay:b=!1}){const{dispatch:p}=C(),{padClass:k}=z(),[x,f]=i.useState(!1),[g,r]=i.useState(""),[h,v]=i.useState(!1),o=i.useRef(null),l=i.useRef(null),c=i.useRef(null),j=()=>p({type:"toggleSettings",open:!1}),n=a=>{if(l.current={...l.current,...a},c.current)return c.current;f(!0),r("");const s=async()=>{for(;l.current;){const d=l.current;l.current=null,r("");try{const u=await U(`/api/bots/${t.id}/profile`,{method:"PATCH",body:JSON.stringify(d)});p({type:"botPatched",bot:u.bot})}catch(u){r(u instanceof Error?u.message:"Could not update this agent.")}}};return c.current=s().finally(()=>{c.current=null,f(!1)}),c.current},N=async a=>{if(a){v(!0),r("");try{const s=await R(a),d=s?B(s.path):null;if(!d)throw new Error("Choose a PNG, JPEG, GIF, or WebP image.");await n({avatarUrl:d,avatarCrop:t.avatarCrop==="square"?"square":"circle"})}catch(s){r(s instanceof Error?s.message:String(s))}finally{v(!1),o.current&&(o.current.value="")}}};return e.jsxs("aside",{className:y("animate-panel-in absolute inset-0 z-40 flex h-full min-w-0 flex-col border-l border-hairline/40 bg-panel",b?"md:left-auto md:w-[400px] md:shadow-2xl":"md:relative md:z-20 md:w-[400px] md:shrink-0"),children:[e.jsxs("div",{className:y("flex items-center justify-between px-4 py-3",k),children:[e.jsx("button",{onClick:j,"aria-label":"Collapse remote agent settings",className:"flex size-10 items-center justify-center rounded-md text-ink-secondary hover:bg-control hover:text-ink",children:e.jsx(S,{size:18})}),e.jsx("span",{className:"text-[15px] font-semibold text-ink",children:"Remote agent settings"}),e.jsx("button",{onClick:j,"aria-label":"Close remote agent settings",className:"flex size-10 items-center justify-center rounded-md text-ink-secondary hover:bg-control hover:text-ink",children:e.jsx(P,{size:18})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-5 pb-5",children:e.jsxs("div",{className:"flex flex-col gap-4 pt-4",children:[e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[e.jsx(T,{bot:t,state:"idle",size:64,motion:"none",motionKey:0,animated:!1}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{ref:o,type:"file",accept:"image/png,image/jpeg,image/gif,image/webp",className:"sr-only",onChange:a=>{N(a.target.files?.[0])}}),e.jsxs("button",{type:"button",disabled:h||x,onClick:()=>o.current?.click(),className:"flex items-center gap-1.5 rounded-lg bg-control px-3 py-2 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50",children:[h?e.jsx(A,{size:14,className:"animate-spin"}):e.jsx(F,{size:14})," Avatar"]}),t.avatarUrl&&e.jsx("button",{type:"button",disabled:x,onClick:()=>{n({avatarUrl:null,avatarCrop:"mascot"})},"aria-label":"Remove custom avatar",className:"flex size-9 items-center justify-center rounded-lg text-ink-secondary hover:bg-control hover:text-danger",children:e.jsx(E,{size:14})})]})]}),e.jsxs("label",{className:"block text-[12px] font-medium text-ink-secondary",children:["Name",e.jsx("input",{defaultValue:t.name,maxLength:m.name,onBlur:a=>{const s=a.currentTarget.value.trim();s&&s!==t.name&&n({name:s})},className:"mt-1 w-full rounded-lg bg-inset px-3 py-2 text-[14px] text-ink focus:outline-none focus:ring-1 focus:ring-accent"},t.id)]}),e.jsxs("label",{className:"mt-3 block text-[12px] font-medium text-ink-secondary",children:["Title",e.jsx("input",{defaultValue:t.title??"",maxLength:m.title,onBlur:a=>{a.currentTarget.value!==(t.title??"")&&n({title:a.currentTarget.value})},className:"mt-1 w-full rounded-lg bg-inset px-3 py-2 text-[14px] text-ink focus:outline-none focus:ring-1 focus:ring-accent"},t.id)]}),e.jsxs("label",{className:"mt-3 block text-[12px] font-medium text-ink-secondary",children:["Description",e.jsx("textarea",{defaultValue:t.description??"",maxLength:m.description,rows:4,onBlur:a=>{a.currentTarget.value!==(t.description??"")&&n({description:a.currentTarget.value})},className:"mt-1 w-full resize-y rounded-lg bg-inset px-3 py-2 text-[13px] leading-relaxed text-ink focus:outline-none focus:ring-1 focus:ring-accent"},t.id)]})]}),e.jsx(L,{bot:t,workspaceConfigurationLocked:!0,onPatch:a=>{n(a)}}),e.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[e.jsx(_,{size:16,className:"mt-0.5 shrink-0 text-ink-secondary"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:"Notifications"}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:"Enable completion and attention notifications for this agent on the host and paired clients."})]})]}),e.jsx(I,{checked:t.notifications,disabled:x,"aria-label":"Agent notifications",onClick:()=>{n({notifications:!t.notifications})}})]}),g?e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:g}):null]})})]})}export{M as RemoteAgentSettingsPanel};
@@ -0,0 +1 @@
1
+ import{k as ht,dG as At,r as m,g as oe,j as e,Q as kn,a8 as Et,S as zt,dH as Xn,B as Ye,t as x,d as De,dI as es,dJ as Dt,c as C,dK as ln,bA as qe,bB as jn,dL as Mt,F as Le,dM as nt,dN as pt,dO as Ge,dP as ts,u as rt,av as ns,b7 as Lt,ba as ss,W as as,P as dn,dQ as rs,aA as wn,X as ze,q as is,dR as os,v as Nn,w as Sn,aB as cn,E as Qe,dS as ls,T as ds,dT as Rt,dU as un,dV as cs,bM as us,a2 as Cn,a1 as xs,dW as ps,Y as ms,dX as hs}from"./index-C3NqfdVU.js";import{k as gs,b as bs}from"./WebhooksPanel--YQyCjKO.js";const fs=[["path",{d:"m2 9 3-3 3 3",key:"1ltn5i"}],["path",{d:"M13 18H7a2 2 0 0 1-2-2V6",key:"1r6tfw"}],["path",{d:"m22 15-3 3-3-3",key:"4rnwn2"}],["path",{d:"M11 6h6a2 2 0 0 1 2 2v10",key:"2f72bc"}]],Dn=ht("repeat-2",fs);const ys=[["path",{d:"M2 21a8 8 0 0 1 13.292-6",key:"bjp14o"}],["circle",{cx:"10",cy:"8",r:"5",key:"o932ke"}],["path",{d:"M19 16v6",key:"tddt3s"}],["path",{d:"M22 19h-6",key:"vcuq98"}]],It=ht("user-round-plus",ys);const vs=[["path",{d:"M18 21a8 8 0 0 0-16 0",key:"3ypg7q"}],["circle",{cx:"10",cy:"8",r:"5",key:"o932ke"}],["path",{d:"M22 20c0-3.37-2-6.5-4-8a5 5 0 0 0-.45-8.3",key:"10s06x"}]],gt=ht("users-round",vs);const ks=[["path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5",key:"ftymec"}],["rect",{x:"2",y:"6",width:"14",height:"12",rx:"2",key:"158x01"}]],Ot=ht("video",ks),le=5,Xe=30,js=12,ws=12;function ne(t){const n=new Date(t);return n.setHours(0,0,0,0),n.getTime()}function pe(t,n){const s=new Date(t);return s.setDate(s.getDate()+n),s.getTime()}function Ns(t){const n=new Date(ne(t));return n.setDate(n.getDate()-(n.getDay()+6)%7),n.getTime()}function Me(t,n){const[s,o]=n.split(":").map(Number),l=new Date(t);return l.setHours(s,o,0,0),l.getTime()}function tt(t){return new Date(t-new Date(t).getTimezoneOffset()*6e4).toISOString().slice(0,10)}function bt(t){return new Date(t-new Date(t).getTimezoneOffset()*6e4).toISOString().slice(11,16)}function Nt(t,n,s){return s!=null&&t===tt(s)&&n===bt(s)?s:new Date(`${t}T${n}`).getTime()}function Ss(t,n){return Math.ceil((t+n*6e4)/6e4)*6e4}function Mn(t,n,s){return s?.everyMinutes===n?s.anchorAt:Ss(t,n)}function xn(t,n,s){const o=Mn(t,n,s);if(o>t)return o;const l=n*6e4;return o+(Math.floor((t-o)/l)+1)*l}function Cs(t,n=le){return Math.max(0,Math.min(1440-n,Math.round(t/n)*n))}function Ds(t){const n=l=>l.at+Math.max(15,l.durationMinutes)*6e4,s=[...t].sort((l,p)=>l.at-p.at||n(l)-n(p)||l.id.localeCompare(p.id)),o=new Map;for(let l=0;l<s.length;){const p=[];let g=s[l].at;for(;l<s.length;){const c=s[l];if(p.length>0&&c.at>=g)break;p.push(c),g=Math.max(g,n(c)),l+=1}const u=[],r=p.map(c=>{const y=u.findIndex(F=>F<=c.at),v=y===-1?u.length:y;return u[v]=n(c),{id:c.id,column:v}}),a=Math.max(1,u.length);for(const c of r)o.set(c.id,{column:c.column,columns:a})}return o}function Ms(t){if(t===0)return"GMT+0";const n=t>0?"+":"-",s=Math.abs(t),o=Math.floor(s/60),l=s%60;return`GMT${n}${o}${l?`:${String(l).padStart(2,"0")}`:""}`}function ut(t,n,s,o){const l=Cs((n-s)/o*60),p=new Date(t);return p.setHours(Math.floor(l/60),l%60,0,0),p.getTime()}function pn(t,n,s){if(t.type==="cron")throw new Error("Edit this routine's schedule to change its cron timing.");if(t.type==="once")return{type:"once",at:s};if(t.type==="interval")return{...t,anchorAt:t.anchorAt+(s-n)};const o=Math.round((ne(s)-ne(n))/864e5);return{type:"daily",time:bt(s),weekdays:t.weekdays.map(l=>((l+o)%7+7)%7).sort()}}function mn(t,n,s,o){const l=new Map(t.map(a=>[a.id,a])),p=new Map,u=n.filter(a=>a.scheduledFor>=s&&a.scheduledFor<o).sort((a,c)=>c.scheduledFor-a.scheduledFor).filter(a=>{if(a.status==="queued"||a.status==="running"||a.status==="waiting")return!0;const c=p.get(a.routineId)??0;return c>=js?!1:(p.set(a.routineId,c+1),!0)}).map(a=>({id:`run-${a.id}`,at:a.scheduledFor,durationMinutes:Xe,routine:l.get(a.routineId)??null,run:a})),r=(a,c)=>n.some(y=>y.routineId===a&&Math.abs(y.scheduledFor-c)<6e4);for(const a of t)if(a.enabled){if(a.schedule.type==="cron"){if(a.nextRunAt==null)continue;for(let c=ne(Math.max(s,a.nextRunAt));c<o;c=pe(c,1)){const y=Math.max(c,s,a.createdAt,a.nextRunAt)-1,v=At(a.schedule,y,ws);if(!v.length||v[0]>=o)break;c=ne(v[0]);const F=Math.min(o,pe(c,1));for(const h of v){if(h>=F)break;r(a.id,h)||u.push({id:`next-${a.id}-${h}`,at:h,durationMinutes:Xe,routine:a,run:null})}}continue}if(a.schedule.type==="once"){const c=a.schedule.at;c>=s&&c<o&&!r(a.id,c)&&u.push({id:`next-${a.id}-${c}`,at:c,durationMinutes:Xe,routine:a,run:null});continue}if(a.schedule.type==="interval"){const c=a.nextRunAt;c!=null&&c>=s&&c<o&&!r(a.id,c)&&u.push({id:`next-${a.id}-${c}`,at:c,durationMinutes:Xe,routine:a,run:null});continue}for(let c=ne(s);c<o;c=pe(c,1)){if(!a.schedule.weekdays.includes(new Date(c).getDay()))continue;const y=Me(c,a.schedule.time);y>=s&&y<o&&y>=a.createdAt&&!r(a.id,y)&&u.push({id:`next-${a.id}-${y}`,at:y,durationMinutes:Xe,routine:a,run:null})}}return u.sort((a,c)=>a.at-c.at)}function Rs(t,n){const s=pe(t,n-1),o=new Date(t),l=new Date(s);return n===1?o.toLocaleDateString([],{month:"long",day:"numeric",year:"numeric"}):o.getMonth()===l.getMonth()?`${o.toLocaleDateString([],{month:"long"})} ${o.getDate()} – ${l.getDate()}, ${l.getFullYear()}`:`${o.toLocaleDateString([],{month:"short",day:"numeric"})} – ${l.toLocaleDateString([],{month:"short",day:"numeric",year:"numeric"})}`}const hn=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Is=["January","February","March","April","May","June","July","August","September","October","November","December"];function $s(t){const[n,s,o,l,p]=t.expression.trim().split(/\s+/);let g=`Cron ${t.expression}`;if(/^\d+$/.test(n??"")&&/^\d+$/.test(s??"")){const u=`${s.padStart(2,"0")}:${n.padStart(2,"0")}`,r=/^\d+$/.test(o??"")?Number(o):null;if(p==="*"&&l==="*")o==="*"?g=`Every day at ${u}`:o==="L"?g=`Monthly on the last day at ${u}`:r!==null&&(g=`Monthly on day ${r} at ${u}`);else if(p==="*"&&/^\d+$/.test(l??"")&&r!==null){const a=Is[Number(l)-1];a&&(g=`Yearly on ${a} ${r} at ${u}`)}else if(o==="*"&&l==="*")if(p==="1-5"||p?.toUpperCase()==="MON-FRI")g=`Every weekday at ${u}`;else if(/^[0-7]$/.test(p??""))g=`Weekly on ${hn[Number(p)%7]} at ${u}`;else{const a=/^([0-7])#([1-5]|L)$/i.exec(p??"");a&&(g=`Monthly on the ${a[2].toUpperCase()==="L"?"last":["","first","second","third","fourth","fifth"][Number(a[2])]} ${hn[Number(a[1])%7]} at ${u}`)}}return`${g} · ${t.timeZone}`}const Ee=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function se(t){return new Date(t).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}function ft(t){return new Date(t).toLocaleDateString([],{weekday:"long",month:"long",day:"numeric"})}function ga(t){const n=new Date(t);return new Date().toDateString()===n.toDateString()?se(t):n.toLocaleDateString([],{month:"short",day:"numeric"})}function st(t){return t<60?`${t} min`:t%60===0?`${t/60} hr`:`${Math.floor(t/60)} hr ${t%60} min`}function Rn(t){return t<60?`Every ${t} min`:t===60?"Every hour":t%60===0?`Every ${t/60} hr`:`Every ${Math.floor(t/60)} hr ${t%60} min`}function Ts(t){const n=[];if(t.weekdays&&t.weekdays.length<7&&n.push(t.weekdays.join(",")==="1,2,3,4,5"?"weekdays":t.weekdays.map(s=>Ee[s]).join(", ")),t.window){const s=o=>{const[l,p]=o.split(":").map(Number);return se(new Date(2e3,0,1,l,p).getTime())};n.push(`${s(t.window.start)}–${s(t.window.end)}`)}return t.endsAt!=null&&n.push(`until ${new Date(t.endsAt).toLocaleDateString([],{month:"short",day:"numeric",year:"numeric"})}`),n}function yt(t){if(t.type==="cron")return $s(t);if(t.type==="once")return`${ft(t.at)}, ${se(t.at)}`;if(t.type==="interval")return[Rn(t.everyMinutes),...Ts(t)].join(" · ");const n=t.weekdays;return`${n.length===7?"Every day":n.join(",")==="1,2,3,4,5"?"Every weekday":n.length===1?`Weekly on ${Ee[n[0]]}`:n.map(o=>Ee[o]).join(", ")} at ${se(Me(Date.now(),t.time))}`}const As=m.createContext({request:oe});function Es(){return m.useContext(As)}const zs=["M","T","W","T","F","S","S"];function St(t){const n=new Date(t);return new Date(n.getFullYear(),n.getMonth(),1)}function gn(t,n){return t.getFullYear()===n.getFullYear()&&t.getMonth()===n.getMonth()&&t.getDate()===n.getDate()}function bn(t,n){return new Date(t.getFullYear(),t.getMonth()+n,1)}function Ls({anchor:t,onSelect:n}){const[s,o]=m.useState(()=>St(t));m.useEffect(()=>{o(St(t))},[t]);const l=m.useMemo(()=>{const r=St(s),a=(r.getDay()+6)%7,c=new Date(r);return c.setDate(r.getDate()-a),Array.from({length:42},(y,v)=>{const F=new Date(c);return F.setDate(c.getDate()+v),F})},[s]),p=new Date(t),g=new Date,u=s.toLocaleDateString(void 0,{month:"long",year:"numeric"});return e.jsxs("section",{"aria-label":"Mini calendar",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-[12.5px] font-semibold text-ink",children:u}),e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsx("button",{type:"button",onClick:()=>o(r=>bn(r,-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":"Previous month",children:e.jsx(kn,{size:15,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>o(r=>bn(r,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":"Next month",children:e.jsx(Et,{size:15,"aria-hidden":"true"})})]})]}),e.jsx("div",{className:"grid grid-cols-7","aria-hidden":"true",children:zs.map((r,a)=>e.jsx("div",{className:"flex h-6 items-center justify-center text-[9px] font-semibold uppercase tracking-[0.08em] text-ink-tertiary",children:r},`${r}-${a}`))}),e.jsx("div",{className:"grid grid-cols-7 gap-y-0.5",children:l.map(r=>{const a=gn(r,p),c=gn(r,g),y=r.getMonth()!==s.getMonth(),v=r.toLocaleDateString(void 0,{weekday:"long",month:"long",day:"numeric",year:"numeric"});return e.jsx("button",{type:"button",onClick:()=>n(r.getTime()),"aria-label":v,"aria-current":c?"date":void 0,"aria-pressed":a,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-[10.5px] transition-colors ${a?"bg-accent font-semibold text-white shadow-sm":c?"font-semibold text-accent group-hover:bg-accent/12":y?"text-ink-tertiary group-hover:bg-raised group-hover:text-ink":"text-ink group-hover:bg-raised"}`,children:r.getDate()})},`${r.getFullYear()}-${r.getMonth()}-${r.getDate()}`)})})]})}const Os="application/x-openmaus-bot";function Ps({bots:t,anchor:n,onSelectDate:s}){const[o,l]=m.useState(""),p=m.useMemo(()=>{const u=o.trim().toLocaleLowerCase();return u?t.filter(r=>`${r.name} ${r.title} ${r.description}`.toLocaleLowerCase().includes(u)):t},[t,o]),g=(u,r)=>{u.dataTransfer.effectAllowed="copy",u.dataTransfer.setData(Os,r.id),u.dataTransfer.setData("text/plain",r.id)};return e.jsxs("aside",{"aria-label":"Schedule sidebar",className:"flex h-full w-[320px] shrink-0 flex-col overflow-hidden border-r border-hairline/40 bg-panel",children:[e.jsx(Ls,{anchor:n,onSelect:s}),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(gt,{size:13,"aria-hidden":"true"}),"My bots"]}),e.jsx("span",{className:"rounded-full bg-raised px-1.5 py-0.5 text-[9px] tabular-nums text-ink-secondary",children:t.length})]}),e.jsxs("label",{className:"relative mb-2 block",children:[e.jsx("span",{className:"sr-only",children:"Search bots"}),e.jsx(zt,{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:o,onChange:u=>l(u.target.value),type:"search",placeholder:"Search bots",className:"h-8 w-full rounded-lg border border-hairline/45 bg-control/55 pl-8 pr-2.5 text-[11.5px] text-ink outline-none placeholder:text-ink-tertiary focus:border-accent/60 focus:bg-control"})]}),e.jsxs("div",{role:"list","aria-label":"Bots available to schedule",className:"min-h-0 flex-1 space-y-0.5 overflow-y-auto pr-0.5",children:[p.map(u=>e.jsxs("div",{draggable:!0,onDragStart:r=>g(r,u),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":`Drag ${u.name} onto the schedule`,title:`Drag ${u.name} onto the schedule`,children:[e.jsx(Xn,{size:13,className:"shrink-0 text-ink-secondary/35 transition-colors group-hover:text-ink-secondary","aria-hidden":"true"}),e.jsx(Ye,{bot:u,size:27,animated:!1}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[11.5px] font-medium text-ink",children:u.name}),e.jsx("div",{className:"truncate text-[9.5px] text-ink-tertiary",children:u.title||"BotAgent"})]}),e.jsx("span",{className:"shrink-0 rounded-full border border-hairline/50 px-1.5 py-0.5 text-[8.5px] text-ink-tertiary opacity-0 transition-opacity group-hover:opacity-100",children:"Drag"})]},u.id)),p.length===0&&e.jsx("div",{className:"px-3 py-8 text-center text-[11px] leading-relaxed text-ink-secondary",children:t.length===0?"Create a bot to schedule work.":"No bots match your search."})]}),e.jsx("p",{className:"mt-2 px-2 text-[9.5px] leading-relaxed text-ink-tertiary",children:"Drag a bot onto any time to schedule it."})]})]})}function Fs({routines:t,runs:n,bots:s,loading:o,error:l,onOpen:p,onLogs:g}){const u=[...t].sort((r,a)=>Number(a.enabled)-Number(r.enabled)||(r.nextRunAt??1/0)-(a.nextRunAt??1/0)||r.name.localeCompare(a.name));return e.jsxs("div",{className:"space-y-3","aria-label":x("routines.list"),children:[l&&e.jsx("div",{role:"alert",className:"rounded-lg bg-danger/10 p-3 text-[12px] text-danger",children:x("routines.loadError")}),o&&e.jsxs("p",{role:"status",className:"flex items-center gap-2 p-3 text-[12px] text-ink-secondary",children:[e.jsx(De,{size:14,className:"animate-spin"}),x("routines.loading")]}),!o&&!l&&u.length===0&&e.jsxs("div",{className:"rounded-xl border border-dashed border-hairline/50 p-5 text-center text-[13px] text-ink-secondary",children:[e.jsx(Dn,{size:20,className:"mx-auto mb-2 opacity-60"}),x("routines.empty")]}),u.map(r=>{const a=es(r.id,n),c=s?.find(y=>y.id===r.botId);return e.jsxs("article",{className:"rounded-xl border border-hairline/40 bg-card p-3.5","aria-label":r.name,children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>p(r),className:"min-w-0 flex-1 text-left hover:text-accent",children:[e.jsx("span",{className:"block truncate text-[13px] font-semibold text-ink",children:r.name}),e.jsxs("span",{className:"mt-1 block text-[11.5px] leading-relaxed text-ink-secondary",children:[c&&`${c.name} · `,yt(r.schedule)]})]}),e.jsx("span",{className:C("shrink-0 rounded-full bg-inset px-2 py-0.5 text-[10px]",r.enabled&&r.nextRunAt!=null?"text-accent":"text-ink-secondary"),children:Dt(r)})]}),ln(r)!==Dt(r)&&e.jsx("div",{className:"mt-2 text-[11.5px] text-ink-secondary",children:ln(r)}),e.jsxs("div",{className:"mt-1 flex items-start justify-between gap-2",children:[e.jsx("div",{className:"min-w-0 text-[11.5px]",children:a?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:jn(a),children:x("routines.latestRun",{status:qe(a)})}),e.jsx("span",{className:"block text-[10.5px] text-ink-secondary",children:Mt(a.finishedAt??a.startedAt??a.scheduledFor)})]}):e.jsx("span",{className:"text-ink-secondary",children:x("routines.neverRun")})}),e.jsxs("button",{type:"button",onClick:()=>g(r),"aria-label":x("routines.logsFor",{name:r.name}),className:"flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-[11px] text-ink-secondary hover:bg-raised hover:text-ink",children:[e.jsx(Le,{size:12}),x("routines.logs")]})]}),a&&(a.attention||a.error||a.output)&&e.jsx("p",{className:C("mt-2 line-clamp-2 whitespace-pre-wrap text-[11.5px] leading-relaxed",a.error?"text-danger":"text-ink-secondary"),children:a.attention||a.error||a.output}),!!r.failureStreak&&e.jsx("p",{className:"mt-2 text-[11.5px] text-danger",children:x("routines.failureStreak",{count:r.failureStreak})}),!!r.skippedRuns&&e.jsxs("p",{className:"mt-2 text-[11.5px] text-ink-secondary",children:[x("routines.skippedRuns",{count:r.skippedRuns}),r.lastSkippedAt!=null&&e.jsxs(e.Fragment,{children:[" · ",x("routines.lastSkipped",{date:Mt(r.lastSkippedAt)})]})]})]},r.id)})]})}function Bs({runs:t,bots:n,loading:s,error:o,routineId:l,status:p,onStatusChange:g,onClearRoutine:u,onOpen:r}){const[a,c]=m.useState(""),[y,v]=m.useState(50),F=t.filter(h=>(!l||h.routineId===l)&&(p==="all"||(p==="problems"?nt(h):h.status===p))&&`${h.routineName} ${n.find(P=>P.id===h.botId)?.name??""} ${h.output??""} ${h.error??""} ${h.attention??""}`.toLowerCase().includes(a.trim().toLowerCase())).sort((h,P)=>pt(P)-pt(h));return e.jsxs("section",{className:"mx-auto w-full max-w-5xl space-y-4 p-4 sm:p-6","aria-label":x("routines.logs"),children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-[17px] font-semibold text-ink",children:x("routines.logs")}),e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:x("routines.logsHint")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("label",{className:"flex min-w-[180px] flex-1 items-center gap-2 rounded-lg border border-hairline/50 bg-panel px-3 py-2 text-ink-secondary focus-within:border-focus",children:[e.jsx(zt,{size:14}),e.jsx("input",{"aria-label":x("routines.searchLogs"),placeholder:x("routines.searchLogs"),value:a,onChange:h=>{c(h.target.value),v(50)},className:"min-w-0 flex-1 bg-transparent text-[12px] text-ink outline-none"})]}),e.jsxs("select",{"aria-label":x("routines.filterStatus"),value:p,onChange:h=>{g(h.target.value),v(50)},className:"rounded-lg border border-hairline/50 bg-panel px-3 py-2 text-[12px] text-ink",children:[e.jsx("option",{value:"all",children:x("routines.allStatuses")}),e.jsx("option",{value:"problems",children:x("routines.status.problems")}),["queued","running","waiting","completed","failed","missed","cancelled"].map(h=>e.jsx("option",{value:h,children:x(`routines.status.${h}`)},h))]})]}),l&&e.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[x("routines.filteredRoutine"),e.jsx("button",{type:"button",onClick:u,className:"text-accent hover:underline",children:x("routines.showAll")})]}),o&&e.jsxs("p",{role:"alert",className:"flex items-center gap-2 rounded-lg bg-danger/10 p-3 text-[12px] text-danger",children:[e.jsx(Ge,{size:14}),x("routines.loadError")]}),s&&e.jsxs("p",{role:"status",className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx(De,{size:14,className:"animate-spin"}),x("routines.loading")]}),!s&&!o&&F.length===0&&e.jsxs("div",{className:"rounded-xl border border-dashed border-hairline/50 p-10 text-center text-[13px] text-ink-secondary",children:[e.jsx(Le,{size:24,className:"mx-auto mb-3 opacity-50"}),t.length?x("routines.noMatchingRuns"):x("routines.noRuns")]}),e.jsx("div",{className:"space-y-2",children:F.slice(0,y).map(h=>{const P=n.find(U=>U.id===h.botId);return e.jsxs("button",{type:"button",onClick:()=>r(h),"aria-label":x("routines.openRun",{name:h.routineName,status:qe(h)})+(nt(h)&&!h.seenAt?` · ${x("routines.unread")}`:""),className:"block w-full rounded-xl border border-hairline/40 bg-card p-4 text-left hover:border-accent/40 hover:bg-raised/40",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-[13px] font-semibold text-ink",children:h.routineName}),e.jsxs("span",{className:"mt-1 block text-[11px] text-ink-secondary",children:[P?.name??x("routines.unavailableBot")," · ",Mt(h.scheduledFor)," · ",x(`routines.trigger.${h.triggerSource??(h.manual?"manual":"schedule")}`)]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[nt(h)&&!h.seenAt&&e.jsx("span",{className:"size-1.5 shrink-0 rounded-full bg-danger",title:x("routines.unread")}),e.jsx("span",{className:C("text-[11.5px] font-medium",jn(h)),children:qe(h)})]})]}),e.jsx("p",{className:C("mt-2 line-clamp-2 whitespace-pre-wrap text-[12px] leading-relaxed",h.error?"text-danger":"text-ink-secondary"),children:h.attention||h.error||h.output||x("routines.noOutput")})]},h.id)})}),F.length>y&&e.jsx("button",{type:"button",onClick:()=>v(h=>h+50),className:"rounded-lg bg-raised px-4 py-2 text-[12px] text-ink",children:x("routines.loadMore")})]})}function In({bot:t,value:n,allowCurrent:s=!1,onChange:o}){const l=m.useId(),p=(t?.tasks??[]).filter(r=>!r.routineRunId),g=typeof n=="string"&&!p.some(r=>r.threadId===n),u=[...t?.projects??[],{id:"",name:x("folder.none")}];return e.jsxs("div",{className:"min-w-0 space-y-1.5",children:[e.jsx("label",{htmlFor:l,className:"block text-[12px] font-medium text-ink",children:x("routines.results.label")}),e.jsxs("select",{id:l,"aria-describedby":`${l}-help`,disabled:!t,value:n??(n===null?"new":"current"),onChange:r=>o(r.target.value==="new"?null:r.target.value==="current"?void 0:r.target.value),className:"w-full min-w-0 rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[12.5px] text-ink outline-none focus:border-accent disabled:opacity-50",children:[s&&e.jsx("option",{value:"current",children:x("routines.results.keep")}),e.jsx("option",{value:"new",children:x("routines.results.main")}),g&&e.jsx("option",{value:n,disabled:!0,children:x("routines.results.unavailable")}),u.map(r=>{const a=p.filter(c=>r.id?c.projectId===r.id:!t?.projects?.some(y=>y.id===c.projectId));return a.length?e.jsx("optgroup",{label:r.name,children:a.map(c=>e.jsx("option",{value:c.threadId,children:c.title},c.threadId))},r.id):null})]}),e.jsx("p",{id:`${l}-help`,className:"text-[11px] leading-relaxed text-ink-secondary",children:x("routines.results.mainHelp")})]})}const et="min-w-0 rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[12.5px] text-ink outline-none focus:border-accent [color-scheme:dark]",_s=Array.from({length:12},(t,n)=>new Intl.DateTimeFormat("en",{month:"long",timeZone:"UTC"}).format(new Date(Date.UTC(2024,n,1)))),Hs=["UTC",...typeof Intl.supportedValuesOf=="function"?Intl.supportedValuesOf("timeZone"):[]];function $n({runs:t,timeZone:n,paused:s=!1}){if(!t.length)return null;const o=new Intl.DateTimeFormat(void 0,{timeZone:n,weekday:"short",year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"});return e.jsxs("div",{className:"space-y-1 text-[11px] leading-relaxed text-ink-secondary","aria-label":s?"Paused schedule preview":"Next scheduled runs",children:[e.jsxs("div",{className:"font-medium",children:[s?"Paused — schedule preview":"Next runs"," · ",n]}),t.map(l=>e.jsx("div",{children:e.jsx("time",{dateTime:new Date(l).toISOString(),children:o.format(l)})},l)),e.jsx("div",{className:"pt-1",children:"Clock changes: skipped times shift forward; repeated times run once."})]})}function Ws({schedule:t,paused:n=!1}){const s=m.useMemo(()=>{try{return At(t,Date.now(),3)}catch{return[]}},[t]);return e.jsx($n,{runs:s,timeZone:t.timeZone,paused:n})}function Ys({choice:t,value:n,onChange:s,runs:o,error:l}){const p=g=>s({...n,...g});return e.jsxs("div",{className:"space-y-3",children:[t==="cron"?e.jsxs("label",{className:"block space-y-1.5 text-[11.5px] text-ink-secondary",children:[e.jsx("span",{children:"Cron expression"}),e.jsx("input",{value:n.expression,onChange:g=>p({expression:g.target.value}),placeholder:"0 9 1 * *",spellCheck:!1,autoComplete:"off","aria-invalid":!!l,"aria-describedby":"routine-cron-help routine-cron-error",className:C(et,"w-full font-mono")}),e.jsx("span",{id:"routine-cron-help",className:"block text-[11px]",children:"Minute · hour · day of month · month · day of week. For example, 0 9 1 * * runs at 9 am on the first of each month."})]}):e.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[t==="yearly"&&e.jsxs("label",{className:"space-y-1.5 text-[11.5px] text-ink-secondary",children:[e.jsx("span",{className:"block",children:"Month"}),e.jsx("select",{value:n.month,onChange:g=>p({month:g.target.value}),className:et,children:_s.map((g,u)=>e.jsx("option",{value:String(u+1),children:g},g))})]}),e.jsxs("label",{className:"space-y-1.5 text-[11.5px] text-ink-secondary",children:[e.jsx("span",{className:"block",children:"Day of month"}),e.jsxs("select",{value:n.day,onChange:g=>p({day:g.target.value}),className:et,children:[Array.from({length:31},(g,u)=>e.jsx("option",{value:String(u+1),children:u+1},u+1)),e.jsx("option",{value:"L",children:"Last day"})]})]}),e.jsxs("label",{className:"space-y-1.5 text-[11.5px] text-ink-secondary",children:[e.jsx("span",{className:"block",children:"Time"}),e.jsx("input",{type:"time",step:60,value:n.time,onChange:g=>p({time:g.target.value}),className:et})]})]}),t!=="cron"&&Number(n.day)>28&&e.jsx("p",{className:"text-[11px] text-ink-secondary",children:"Months without this date are skipped. Choose Last day to always use the end of the month."}),e.jsxs("label",{className:"block space-y-1.5 text-[11.5px] text-ink-secondary",children:[e.jsx("span",{children:"Time zone"}),e.jsx("input",{list:"routine-time-zones",value:n.timeZone,onChange:g=>p({timeZone:g.target.value}),placeholder:"America/New_York",spellCheck:!1,autoComplete:"off","aria-invalid":!!l,"aria-describedby":"routine-cron-error",className:C(et,"block w-full")})]}),e.jsx("datalist",{id:"routine-time-zones",children:Hs.map(g=>e.jsx("option",{value:g},g))}),l&&e.jsx("p",{id:"routine-cron-error",role:"alert",className:"text-[11.5px] text-danger",children:l}),!l&&e.jsx($n,{runs:o,timeZone:n.timeZone.trim()})]})}const Ae=t=>["monthly","yearly","cron"].includes(t);function Tn(t){const n=t.trim().split(/\s+/);if(n.length!==5)return null;const[s,o,l,p,g]=n;return!/^\d+$/.test(s)||Number(s)>59||!/^\d+$/.test(o)||Number(o)>23||!(l==="L"||/^\d+$/.test(l)&&Number(l)>=1&&Number(l)<=31)||!(p==="*"||/^\d+$/.test(p)&&Number(p)>=1&&Number(p)<=12)||g!=="*"?null:{day:l==="L"?l:String(Number(l)),month:p,time:`${String(Number(o)).padStart(2,"0")}:${String(Number(s)).padStart(2,"0")}`}}function qs(t){const n=Tn(t.expression);return n?n.month==="*"?"monthly":"yearly":"cron"}function Gs(t,n){const s=t?.timeZone??Intl.DateTimeFormat().resolvedOptions().timeZone,o=t&&Tn(t.expression);let l;try{l=new Intl.DateTimeFormat("en-US",{timeZone:s,month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(n)}catch{l=new Intl.DateTimeFormat("en-US",{timeZone:"UTC",month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(n)}const p=r=>l.find(a=>a.type===r).value,g=o?.time??`${p("hour")}:${p("minute")}`,u=o?.day??p("day");return{expression:t?.expression??`${Number(g.slice(3))} ${Number(g.slice(0,2))} ${u} * *`,timeZone:s,day:u,month:o&&o.month!=="*"?String(Number(o.month)):p("month"),time:g}}function Us(t,n,s,o){try{if(t!=="cron"&&!/^\d{2}:\d{2}$/.test(n.time))throw new Error("Choose a time for this routine.");const[l,p]=n.time.split(":"),g=o??{type:"cron",timeZone:n.timeZone,expression:t==="cron"?n.expression:`${Number(p)} ${Number(l)} ${n.day} ${t==="yearly"?n.month:"*"} *`},u=ts(g,s);return{schedule:o??u,runs:At(u,s,3),error:""}}catch(l){return{schedule:null,runs:[],error:l instanceof Error?l.message:String(l)}}}const Ks='button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function An(t,n){const s=m.useRef(n);s.current=n,m.useEffect(()=>{const o=t.current;if(!o)return;const l=document.activeElement instanceof HTMLElement?document.activeElement:null;o.contains(document.activeElement)||o.focus();const p=()=>Array.from(o.querySelectorAll(Ks)).filter(u=>!u.hasAttribute("hidden")),g=u=>{if(u.defaultPrevented)return;if(u.key==="Escape"){u.preventDefault(),u.stopPropagation(),s.current();return}if(u.key!=="Tab")return;const r=p();if(!r.length)return u.preventDefault();const a=r[0],c=r[r.length-1];u.shiftKey&&(document.activeElement===a||!o.contains(document.activeElement)||document.activeElement===o)?(u.preventDefault(),c.focus()):!u.shiftKey&&document.activeElement===c&&(u.preventDefault(),a.focus())};return o.addEventListener("keydown",g),()=>{o.removeEventListener("keydown",g),l?.focus()}},[t])}const Q=64,Js=["Su","Mo","Tu","We","Th","Fr","Sa"],$t=[0,1,2,3,4,5,6],mt=[1,2,3,4,5],Ct=[5,10,15,30,60],fn=Array.from({length:240/le},(t,n)=>(n+1)*le),yn="application/x-openmaus-bot",xt="application/x-openmaus-calendar-event";function En(t,n){return t?t.memberIds.flatMap(s=>{const o=n.find(l=>l.id===s);return o&&!o.hidden?[o]:[]}):[]}function Vs(t){return t.dm?!1:!(Object.prototype.hasOwnProperty.call(t,"setupCompletedAt")||Object.prototype.hasOwnProperty.call(t,"setupSkippedAt"))||t.setupCompletedAt!=null||t.setupSkippedAt!=null||(t.messages?.length??0)>0}function vn(t,n,s){const o=En(t,n),l=t?.defaultResponder.kind==="member"?t.defaultResponder.botId:void 0;return o.find(p=>p.id===s)??o.find(p=>p.id===l)??o.find(p=>p.chiefOfStaff)??o[0]}function at(){const t=new Date(Date.now()+36e5);return t.setMinutes(0,0,0),t.getTime()}function Zs(t,n){return!!(t&&t.length===n.length&&t.every((s,o)=>s===n[o]))}function Qs(t){return t.type!=="interval"||!t.weekdays||t.weekdays.length===7?"every-day":Zs(t.weekdays,mt)?"weekdays":"custom"}function Xs(t){const n=new Date(`${t}T00:00`);return n.setHours(23,59,59,999),n.getTime()}function ea(t,n){return t.type==="once"?"none":t.type==="interval"?"interval":t.type==="cron"?qs(t):t.weekdays.length===7?"daily":t.weekdays.join(",")==="1,2,3,4,5"?"weekdays":t.weekdays.length===1&&t.weekdays[0]===new Date(n).getDay()?"weekly":"custom"}function zn(t,n,s){if(t==="none")return{type:"once",at:n};const o=t==="daily"?$t:t==="weekdays"?mt:t==="weekly"?[new Date(n).getDay()]:s;return{type:"daily",time:bt(n),weekdays:[...o].sort()}}function ta(t,n,s,o,l){return t==="interval"?{type:"interval",everyMinutes:o,...l}:zn(t,n,s)}function na(t,n,s){const o=[];for(const l of t){if(l.schedule.type==="once"){l.schedule.at>=n&&l.schedule.at<s&&o.push({id:`call-${l.id}-${l.schedule.at}`,at:l.schedule.at,durationMinutes:l.durationMinutes,call:l});continue}for(let p=ne(n);p<s;p=pe(p,1)){if(!l.schedule.weekdays.includes(new Date(p).getDay()))continue;const g=Me(p,l.schedule.time);g>=n&&g<s&&g>=l.createdAt&&o.push({id:`call-${l.id}-${g}`,at:g,durationMinutes:l.durationMinutes,call:l})}}return o.sort((l,p)=>l.at-p.at)}function Ln(t){return t==="running"?"working":t==="waiting"?"curious":t==="completed"?"proud":t==="failed"||t==="missed"?"sad":t==="cancelled"?"sleeping":"drowsy"}function On({attachments:t,onRemove:n}){return t.length?e.jsx("div",{className:"flex flex-wrap gap-2",children:t.map(s=>e.jsxs("div",{className:"flex max-w-[260px] items-center gap-2 rounded-lg border border-hairline/50 bg-inset px-2.5 py-2 text-[12px] text-ink",children:[e.jsx(Le,{size:14,className:"shrink-0 text-accent"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:s.name}),n&&e.jsx("button",{type:"button",onClick:()=>n(s.id),className:"rounded p-0.5 text-ink-secondary hover:bg-raised hover:text-ink","aria-label":`Remove ${s.name}`,children:e.jsx(ze,{size:12})})]},s.id))}):null}function Tt({bots:t,selected:n,multiple:s,locked:o,onChange:l}){const[p,g]=m.useState(""),u=t.filter(r=>`${r.name} ${r.title}`.toLowerCase().includes(p.toLowerCase()));return e.jsxs("div",{className:"rounded-xl border border-hairline/50 bg-inset/60 p-2",children:[!o&&t.length>5&&e.jsxs("label",{className:"mb-2 flex items-center gap-2 rounded-lg border border-transparent bg-panel px-2.5 py-2 text-ink-secondary focus-within:border-focus",children:[e.jsx(zt,{size:14}),e.jsx("input",{value:p,onChange:r=>g(r.target.value),placeholder:"Find a bot",className:"min-w-0 flex-1 bg-transparent text-[12px] text-ink outline-none placeholder:text-ink-tertiary"})]}),e.jsx("div",{className:"grid max-h-48 grid-cols-1 gap-1 overflow-y-auto sm:grid-cols-2",children:u.map(r=>{const a=n.includes(r.id);return e.jsxs("button",{type:"button",disabled:o,onClick:()=>l(s?a?n.filter(c=>c!==r.id):[...n,r.id]:[r.id]),className:C("flex min-w-0 items-center gap-2 rounded-lg px-2 py-2 text-left transition",a?"bg-accent/12 ring-1 ring-accent/50":"hover:bg-raised",o&&"cursor-default"),children:[e.jsx(Ye,{bot:r,state:a?"happy":"idle",size:32,animated:!1}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12.5px] font-medium text-ink",children:r.name}),a&&e.jsx(Cn,{size:14,className:"shrink-0 text-accent"})]},r.id)})})]})}function sa(t){return t.flatMap(n=>n.kind==="paste"||n.kind==="citation"?[]:[{id:n.id,kind:n.kind,name:n.name,path:n.path,size:n.size}])}function Pn({seed:t,bots:n,lockedBotId:s,defaultRunOn:o,routinesOnly:l=!1,onClose:p,onSavedCall:g}){const{state:u,dispatch:r}=rt(),a=t.routine,{request:c}=Es(),y=t.call,[v,F]=m.useState(l?"routine":t.kind),[h]=m.useState(()=>Date.now()),[P,U]=m.useState(a?.name??y?.name??t.name??""),[Y,G]=m.useState(a?.prompt??y?.description??t.description??""),z=a?.schedule.type==="once"?a.schedule.at:a?.schedule.type==="daily"?Me(t.at,a.schedule.time):a?.schedule.type==="interval"?a.schedule.anchorAt:y?.schedule.type==="once"?y.schedule.at:y?.schedule.type==="daily"?Me(t.at,y.schedule.time):t.at,b=a?.schedule??y?.schedule??{type:"once",at:z},[j,L]=m.useState(tt(z)),[f,N]=m.useState(bt(z)),[E,S]=m.useState(a?.durationMinutes??y?.durationMinutes??t.durationMinutes),[T,A]=m.useState(a?.timeoutMinutes??null),[k,I]=m.useState(!!a),[q,_]=m.useState(a?.overlap??"skip"),[V,J]=m.useState(!!a?.continuity),[$,B]=m.useState(ea(b,z)),[ie,ae]=m.useState(()=>Gs(b.type==="cron"?b:void 0,z)),[je,me]=m.useState(!1),[he,Ue]=m.useState(b.type==="daily"?b.weekdays:[new Date(z).getDay()]),[O,ge]=m.useState(b.type==="interval"?b.everyMinutes:15),[re,ce]=m.useState(()=>Qs(b)),[de,we]=m.useState(()=>b.type==="interval"&&b.weekdays?.length?b.weekdays:[...$t]),[be,w]=m.useState(b.type==="interval"&&b.window?"custom":"all-day"),[Z,Re]=m.useState(b.type==="interval"?b.window?.start??"09:00":"09:00"),[X,Ke]=m.useState(b.type==="interval"?b.window?.end??"17:00":"17:00"),[Oe,Pe]=m.useState(b.type==="interval"&&b.endsAt!=null?"on-date":"never"),[fe,Je]=m.useState(()=>b.type==="interval"&&b.endsAt!=null?tt(b.endsAt):tt(pe(ne(Math.max(Date.now(),z)),7))),[K,Ie]=m.useState(s?[s]:a?[a.botId]:y?.botIds??t.botIds),[it,$e]=m.useState(a?a.resultsThreadId:t.resultsThreadId??null),Fe=d=>{d[0]!==K[0]&&$e(null),Ie(d)},[ee,vt]=m.useState(a?.target??"bot"),[Ne,Be]=m.useState(a?.groupId??""),[i,D]=m.useState(a?.runOn??o??"maus"),[R,ye]=m.useState(a?.target==="room-goal"?[]:a?.attachments??y?.attachments??[]),[Se,H]=m.useState(!1),[_e,Pt]=m.useState(""),[Ft,Bt]=m.useState(""),[Fn,_t]=m.useState(0),ot=Fn>0,Ht=m.useRef(null),Bn=!!(u.config?.box.configured&&K.length>0&&K.every(d=>bs(u.instances,n.find(M=>M.id===d)?.modelSelection.instanceId)?.snapshot.state==="available")),Ve=u.groups.filter(Vs),lt=Ve.find(d=>d.id===Ne),kt=En(lt,u.bots),ue=v==="routine"&&ee==="room-goal",Wt=u.config?.cloudHome===!0,dt=Nt(j,f,a||y?z:void 0),_n=dt+E*6e4,jt=K.flatMap(d=>n.find(M=>M.id===d)??[]),Yt=m.useRef(null),Ze=$==="interval"&&(!Number.isInteger(O)||O<5||O>1440),He=$==="interval"&&re==="custom"&&de.length===0,qt=Nt("2000-01-01",X)-Nt("2000-01-01",Z),xe=$==="interval"&&be==="custom"&&(!Z||!X||!Number.isFinite(qt)||qt<O*6e4),wt=a?.schedule.type==="interval"?a.schedule:void 0,Gt=xn(h,Math.max(5,O||5),wt),We=Oe==="on-date"?Xs(fe):null,Te=$==="interval"&&Oe==="on-date"&&(We==null||!Number.isSafeInteger(We)||We<Gt),Ut=re==="every-day"?void 0:re==="weekdays"?mt:de,Hn=be==="custom"?{start:Z,end:X}:void 0,Ce=Ae($)?Us($,ie,h,!je&&b.type==="cron"?b:void 0):null,Kt=d=>{d==="interval"&&!k&&(A(M=>M??30),I(!0)),Ae(d)&&(d==="cron"&&Ce?.schedule&&ae(M=>({...M,expression:Ce.schedule.expression})),me(!0)),B(d)},Wn=d=>{d==="custom"&&re!=="custom"&&we(re==="weekdays"?[...mt]:[...$t]),ce(d)},Jt=d=>{if(vt(d),d==="bot"){Be("");return}D("maus"),ye([]),Bt("");const M=lt??Ve[0];Be(M?.id??"");const W=vn(M,u.bots,K[0]);Fe(W?[W.id]:[])},Yn=d=>{const M=Ve.find(ve=>ve.id===d);Be(d);const W=vn(M,u.bots,K[0]);Fe(W?[W.id]:[])},qn=async d=>{if(!(!d?.length||ue)){_t(M=>M+1);try{const M=await ps(Array.from(d),{allowImages:!0,getPath:hs,uploadImage:ms}),W=sa(M.attachments);W.length&&(ye(ve=>[...ve,...W].slice(0,20)),i==="cloud"&&D("maus")),M.notice&&Bt(M.notice)}finally{_t(M=>Math.max(0,M-1))}}},Gn=async()=>{if(!ot){H(!0),Pt("");try{if(v==="routine"||l){const d=Date.now(),M=Mn(d,O,wt);if($==="interval"&&We!=null&&We<xn(d,O,wt))throw new Error("Choose an end date after the first run.");const W=Ae($)?Ce?.schedule:ta($,dt,he,O,{anchorAt:M,weekdays:Ut?[...Ut].sort():null,window:Hn??null,endsAt:We});if(!W)throw new Error(Ce?.error||"Choose a valid schedule.");const ve={name:P,prompt:Y,target:ee,botId:s??K[0]??"",groupId:ee==="room-goal"?Ne:null,runOn:ee==="room-goal"?"maus":i,enabled:a?void 0:!0,schedule:W,durationMinutes:E,timeoutMinutes:T,overlap:q,continuity:ee==="bot"&&$!=="none"&&V,attachments:ee==="room-goal"?[]:R,...ee==="bot"?{resultsThreadId:it}:{}},Qn=await c(a?`/api/routines/${a.id}`:"/api/routines",{method:a?"PATCH":"POST",body:JSON.stringify(ve)});r({type:"routinePatched",routine:Qn.routine})}else{if($==="interval"||Ae($))throw new Error("Choose a supported call schedule.");const d=zn($,dt,he),M={name:P,description:Y,botIds:K,schedule:d,durationMinutes:E,attachments:R},W=await oe(y?`/api/calendar-calls/${y.id}`:"/api/calendar-calls",{method:y?"PATCH":"POST",body:JSON.stringify(M)});g(W.call)}p()}catch(d){Pt(d instanceof Error?d.message:String(d))}finally{H(!1)}}},Un=!!(P.trim()&&(v==="call"||Y.trim())&&(!s||K[0]===s)&&(v==="call"?K.length>0:ee==="room-goal"?Ne&&K[0]&&kt.some(d=>d.id===K[0]):K.length>0)&&!Ze&&!He&&!xe&&!Te&&!Ce?.error),Kn=!l&&!a&&!y&&!s,te=Lt(),[ct,Jn]=m.useState(()=>!["none","daily","weekdays","weekly"].includes($)||ee==="room-goal"||R.length>0||i==="cloud"||T!=null||q==="queue");An(Yt,p);const Vt=Kn&&e.jsxs("div",{className:C(te&&"ml-10","inline-flex rounded-lg bg-inset p-1"),children:[e.jsx("button",{type:"button",onClick:()=>{F("routine"),Ie(d=>d.slice(0,1))},className:C("rounded-md px-4 py-1.5 text-[12.5px] font-medium",v==="routine"?"bg-raised text-ink shadow":"text-ink-secondary"),children:"Routine"}),e.jsx("button",{type:"button",onClick:()=>{F("call"),($==="interval"||Ae($))&&B("none")},className:C("rounded-md px-4 py-1.5 text-[12.5px] font-medium",v==="call"?"bg-raised text-ink shadow":"text-ink-secondary"),children:"Call"})]}),Zt=v==="routine"&&!s&&e.jsxs("div",{className:C(te&&"ml-10"),children:[e.jsx("div",{className:"mb-2 text-[11px] font-medium uppercase tracking-wider text-ink-secondary",children:"Routine type"}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("button",{type:"button",onClick:()=>Jt("bot"),className:C("flex items-start gap-3 rounded-xl border p-3 text-left transition",ee==="bot"?"border-accent/60 bg-accent/10":"border-hairline/50 bg-inset hover:bg-raised"),children:[e.jsx(It,{size:17,className:C("mt-0.5 shrink-0",ee==="bot"?"text-accent":"text-ink-secondary")}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-[12.5px] font-medium text-ink",children:"Bot task"}),e.jsx("span",{className:"mt-1 block text-[11px] leading-relaxed text-ink-secondary",children:"One bot owns and completes each run."})]})]}),e.jsxs("button",{type:"button",onClick:()=>Jt("room-goal"),className:C("flex items-start gap-3 rounded-xl border p-3 text-left transition",ee==="room-goal"?"border-accent/60 bg-accent/10":"border-hairline/50 bg-inset hover:bg-raised"),children:[e.jsx(un,{size:17,className:C("mt-0.5 shrink-0",ee==="room-goal"?"text-accent":"text-ink-secondary")}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-[12.5px] font-medium text-ink",children:"Team goal"}),e.jsx("span",{className:"mt-1 block text-[11px] leading-relaxed text-ink-secondary",children:"A lead coordinates the group until the goal settles."})]})]})]})]}),Qt=$!=="interval"&&!Ae($)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[v==="routine"&&$==="none"&&e.jsx("span",{className:"text-[12px] font-medium text-ink-secondary",children:"Starts"}),v==="routine"&&$==="weekly"&&e.jsx("span",{className:"text-[12px] font-medium text-ink-secondary",children:"On"}),(v==="call"||$==="none"||$==="weekly")&&e.jsx("input",{type:"date",value:j,onChange:d=>L(d.target.value),className:"rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[13px] text-ink outline-none focus:border-accent [color-scheme:dark]"}),e.jsx("input",{type:"time",step:le*60,value:f,onChange:d=>N(d.target.value),className:"rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[13px] text-ink outline-none focus:border-accent [color-scheme:dark]"}),v==="call"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[12px] text-ink-secondary",children:"to"}),e.jsx("span",{className:"rounded-lg border border-hairline/40 bg-inset/60 px-3 py-2 text-[13px] text-ink",children:se(_n)}),e.jsx("select",{"aria-label":"Call duration",value:E,onChange:d=>S(Number(d.target.value)),className:"rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[12px] text-ink outline-none focus:border-accent",children:fn.map(d=>e.jsx("option",{value:d,children:st(d)},d))})]})]}),Xt=e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Dn,{size:14,className:"text-ink-secondary"}),e.jsxs("select",{"aria-label":"Repeat",value:$,onChange:d=>Kt(d.target.value),className:"rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[12.5px] text-ink outline-none focus:border-accent",children:[e.jsx("option",{value:"none",children:"Does not repeat"}),v==="routine"&&e.jsx("option",{value:"interval",children:"Every X minutes"}),e.jsx("option",{value:"daily",children:"Daily"}),e.jsx("option",{value:"weekdays",children:"Every weekday (Monday to Friday)"}),e.jsxs("option",{value:"weekly",children:["Weekly on ",Ee[new Date(dt).getDay()]]}),e.jsx("option",{value:"custom",children:"Selected weekdays"}),v==="routine"&&e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"monthly",children:"Monthly"}),e.jsx("option",{value:"yearly",children:"Yearly"}),e.jsx("option",{value:"cron",children:"Custom cron (advanced)"})]})]})]}),en=v==="routine"&&e.jsx("p",{className:"text-[11px] leading-relaxed text-ink-secondary",children:"Runs while OpenMausBot is open on this computer — it cannot wake a sleeping Mac. A run missed by less than 12 hours still happens when the app is back; for 24/7, run OpenMausBot on a VPS."}),tn=e.jsxs(e.Fragment,{children:[Ae($)&&v==="routine"&&Ce&&e.jsx(Ys,{choice:$,value:ie,onChange:d=>{ae(d),me(!0)},runs:Ce.runs,error:Ce.error}),$==="custom"&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Ee.map((d,M)=>e.jsx("button",{type:"button",onClick:()=>Ue(W=>W.includes(M)?W.length===1?W:W.filter(ve=>ve!==M):[...W,M].sort()),className:C("size-8 rounded-full text-[10px] font-semibold",he.includes(M)?"bg-accent text-white":"bg-inset text-ink-secondary hover:bg-raised hover:text-ink"),children:d[0]},d))}),$==="interval"&&v==="routine"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[12.5px] text-ink",children:[e.jsx("span",{className:"font-medium",children:"Runs every"}),e.jsxs("select",{value:Ct.includes(O)?String(O):"custom",onChange:d=>ge(d.target.value==="custom"?0:Number(d.target.value)),"aria-label":"How often this routine runs",className:"rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[12.5px] tabular-nums text-ink outline-none focus:border-accent",children:[Ct.map(d=>e.jsx("option",{value:d,children:d},d)),e.jsx("option",{value:"custom",children:"Custom…"})]}),!Ct.includes(O)&&e.jsx("input",{type:"number",min:5,max:1440,step:1,value:O||"",onChange:d=>ge(Number(d.target.value)),"aria-label":"Custom interval in minutes","aria-invalid":Ze,"aria-describedby":Ze?"routine-interval-error":"routine-interval-help",autoFocus:!0,className:C("w-20 rounded-lg border bg-inset px-3 py-2 text-[12.5px] tabular-nums text-ink outline-none focus:border-accent",Ze?"border-danger/70":"border-hairline/50")}),e.jsx("span",{children:"minutes"})]}),e.jsxs("div",{className:"grid items-center gap-2 text-[12.5px] text-ink sm:flex sm:flex-wrap",children:[e.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[e.jsx("span",{className:"font-medium",children:"On"}),e.jsxs("select",{value:re,onChange:d=>Wn(d.target.value),"aria-label":"Days this interval runs","aria-invalid":He,"aria-describedby":He?"routine-interval-days-error":void 0,className:"rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[12.5px] text-ink outline-none focus:border-accent",children:[e.jsx("option",{value:"every-day",children:"Every day"}),e.jsx("option",{value:"weekdays",children:"Weekdays"}),e.jsx("option",{value:"custom",children:"Custom…"})]})]}),e.jsx("span",{"aria-hidden":"true",className:"hidden text-ink-secondary sm:inline",children:"·"}),e.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[e.jsx("span",{className:"font-medium",children:"During"}),e.jsxs("select",{value:be,onChange:d=>w(d.target.value),"aria-label":"Hours this interval runs","aria-invalid":xe,"aria-describedby":xe?"routine-interval-window-error":void 0,className:"rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[12.5px] text-ink outline-none focus:border-accent",children:[e.jsx("option",{value:"all-day",children:"All day"}),e.jsx("option",{value:"custom",children:"Custom hours…"})]})]}),e.jsx("span",{"aria-hidden":"true",className:"hidden text-ink-secondary sm:inline",children:"·"}),e.jsxs("span",{className:"inline-flex items-center gap-2 whitespace-nowrap",children:[e.jsx("span",{className:"font-medium",children:"Ends"}),e.jsxs("select",{value:Oe,onChange:d=>Pe(d.target.value),"aria-label":"When this interval ends","aria-invalid":Te,"aria-describedby":Te?"routine-interval-end-error":void 0,className:"rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[12.5px] text-ink outline-none focus:border-accent",children:[e.jsx("option",{value:"never",children:"Never"}),e.jsx("option",{value:"on-date",children:"On a date…"})]})]})]}),re==="custom"&&e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-[11px] font-medium text-ink-secondary",children:"Choose the days"}),e.jsx("div",{role:"group","aria-label":"Custom interval days","aria-invalid":He,"aria-describedby":He?"routine-interval-days-error":void 0,className:"flex flex-wrap gap-1.5",children:Ee.map((d,M)=>e.jsx("button",{type:"button",onClick:()=>we(W=>W.includes(M)?W.filter(ve=>ve!==M):[...W,M].sort()),"aria-label":`${d}, ${de.includes(M)?"selected":"not selected"}`,"aria-pressed":de.includes(M),className:C("size-8 rounded-full text-[10px] font-semibold",de.includes(M)?"bg-accent text-white":"bg-inset text-ink-secondary hover:bg-raised hover:text-ink"),children:Js[M]},d))})]}),be==="custom"&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[12px] text-ink",children:[e.jsx("span",{className:"font-medium text-ink-secondary",children:"Run between"}),e.jsx("input",{"aria-label":"Interval window start","aria-invalid":xe,"aria-describedby":xe?"routine-interval-window-error":void 0,type:"time",step:le*60,value:Z,onChange:d=>Re(d.target.value),className:C("rounded-lg border bg-inset px-3 py-2 text-[13px] text-ink outline-none focus:border-accent [color-scheme:dark]",xe?"border-danger/70":"border-hairline/50")}),e.jsx("span",{className:"text-ink-secondary",children:"and"}),e.jsx("input",{"aria-label":"Interval window end","aria-invalid":xe,"aria-describedby":xe?"routine-interval-window-error":void 0,type:"time",step:le*60,value:X,onChange:d=>Ke(d.target.value),className:C("rounded-lg border bg-inset px-3 py-2 text-[13px] text-ink outline-none focus:border-accent [color-scheme:dark]",xe?"border-danger/70":"border-hairline/50")})]}),Oe==="on-date"&&e.jsxs("label",{className:"flex flex-wrap items-center gap-2 text-[12px] text-ink",children:[e.jsx("span",{className:"font-medium text-ink-secondary",children:"Stop scheduling after"}),e.jsx("input",{"aria-label":"Interval end date","aria-invalid":Te,"aria-describedby":Te?"routine-interval-end-error":void 0,type:"date",min:tt(Gt),value:fe,onChange:d=>Je(d.target.value),className:C("rounded-lg border bg-inset px-3 py-2 text-[13px] text-ink outline-none focus:border-accent [color-scheme:dark]",Te?"border-danger/70":"border-hairline/50")})]}),Ze&&e.jsx("div",{id:"routine-interval-error",className:"text-[11px] text-danger",children:"Choose a whole number from 5 to 1,440 minutes."}),He&&e.jsx("div",{id:"routine-interval-days-error",className:"text-[11px] text-danger",children:"Choose at least one day."}),xe&&e.jsxs("div",{id:"routine-interval-window-error",className:"text-[11px] text-danger",children:["Choose a same-day window at least ",O||5," minutes long."]}),Te&&e.jsx("div",{id:"routine-interval-end-error",className:"text-[11px] text-danger",children:"Choose an end date after the first run."}),e.jsx("div",{id:"routine-interval-help",className:"text-[11px] leading-relaxed text-ink-secondary",children:x(q==="queue"?"routines.overlapQueueHelp":"routines.overlapSkipHelp")})]})]}),nn=v==="routine"&&e.jsxs("details",{className:"rounded-xl border border-hairline/40 bg-inset/40 px-3 py-2.5",children:[e.jsxs("summary",{className:"cursor-pointer select-none text-[11.5px] font-medium text-ink-secondary hover:text-ink",children:["Advanced · ",T==null?"no run limit":`${st(T)} run limit`]}),e.jsxs("div",{className:"mt-3 border-t border-hairline/35 pt-3",children:[e.jsxs("label",{className:"flex flex-wrap items-center gap-2 text-[12px] text-ink",children:[e.jsx("span",{children:"Stop if still running after"}),e.jsxs("select",{"aria-label":"Routine safety limit",value:T??"",onChange:d=>A(d.target.value?Number(d.target.value):null),className:"rounded-lg border border-hairline/50 bg-panel px-3 py-2 text-[12px] text-ink outline-none focus:border-accent",children:[e.jsx("option",{value:"",children:"No limit"}),fn.map(d=>e.jsx("option",{value:d,children:st(d)},d))]})]}),e.jsx("div",{className:"mt-1.5 text-[10.5px] leading-relaxed text-ink-secondary",children:"Optional. The clock starts when work actually begins and does not control how often the routine starts."}),$!=="none"&&e.jsxs("div",{className:"mt-3",children:[e.jsxs("label",{className:"flex flex-wrap items-center gap-2 text-[12px] text-ink",children:[e.jsx("span",{children:x("routines.overlapLabel")}),e.jsxs("select",{"aria-label":x("routines.overlapLabel"),value:q,onChange:d=>_(d.target.value==="queue"?"queue":"skip"),className:"rounded-lg border border-hairline/50 bg-panel px-3 py-2 text-[12px] text-ink outline-none focus:border-accent",children:[e.jsx("option",{value:"skip",children:x("routines.overlapSkip")}),e.jsx("option",{value:"queue",children:x("routines.overlapQueue")})]})]}),e.jsx("p",{className:"mt-1.5 text-[10.5px] leading-relaxed text-ink-secondary",children:x(q==="queue"?"routines.overlapQueueHelp":"routines.overlapSkipHelp")})]})]})]}),Vn=v==="routine"&&!ue&&$!=="none"&&e.jsxs("label",{className:C("flex items-start gap-3 rounded-xl border border-hairline/40 bg-inset/40 px-3.5 py-3",te&&"ml-8"),children:[e.jsx("input",{type:"checkbox","aria-label":x("routines.continuityLabel"),checked:V,onChange:d=>J(d.target.checked),className:"mt-0.5 accent-accent"}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-[12.5px] font-medium text-ink",children:x("routines.continuityLabel")}),e.jsx("span",{className:"mt-1 block text-[11px] leading-relaxed text-ink-secondary",children:x("routines.continuityHelp")})]})]}),sn=v==="routine"&&!ue&&e.jsx("div",{className:C(te&&"ml-8"),children:e.jsx(In,{bot:n.find(d=>d.id===K[0]),value:it,allowCurrent:!!a,onChange:$e})}),an=e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(cs,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}),ue?e.jsxs("div",{className:"min-w-0 flex-1 rounded-xl border border-hairline/50 bg-inset px-3.5 py-3",children:[e.jsx("div",{className:"text-[12.5px] font-medium text-ink",children:"Use the group’s shared context"}),e.jsx("div",{className:"mt-1 text-[11px] leading-relaxed text-ink-secondary",children:"Team goals cannot carry routine attachments. Put shared context in the goal instructions or the group instructions."})]}):e.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[e.jsx("input",{ref:Ht,type:"file",multiple:!0,className:"hidden",onChange:d=>{qn(d.target.files),d.target.value=""}}),e.jsx("button",{type:"button",onClick:()=>Ht.current?.click(),className:"rounded-lg border border-hairline/50 px-3 py-2 text-[12.5px] font-medium text-ink hover:bg-raised",children:"Add attachment"}),e.jsx(On,{attachments:R,onRemove:d=>ye(M=>M.filter(W=>W.id!==d))}),e.jsx("div",{className:"text-[11px] leading-relaxed text-ink-secondary",children:v==="routine"?"Attachments are passed to each local routine run and excluded from shared team files.":jt.length>1?"References will be shared in the group when the event starts.":"References stay with the event and are available when you join the group."}),Ft&&e.jsx("div",{className:"text-[11.5px] text-warning",children:Ft})]})]}),rn=v==="routine"&&e.jsxs("div",{className:"flex items-start gap-4",children:[ue?e.jsx(un,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}):i==="cloud"?e.jsx(Nn,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}):e.jsx(Sn,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}),e.jsx("div",{className:"min-w-0 flex-1",children:ue?e.jsxs("div",{className:"rounded-xl border border-accent/35 bg-accent/[0.07] p-3",children:[e.jsx("div",{className:"text-[12.5px] font-medium text-ink",children:Wt?"Runs on My Cloud":"Runs on this computer"}),e.jsx("div",{className:"mt-1 text-[11px] leading-relaxed text-ink-secondary",children:"OpenMausBot keeps the group and its member hand-offs together for the full goal."})]}):e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>D("maus"),className:C("rounded-xl border p-3 text-left",i==="maus"?"border-accent/60 bg-accent/10":"border-hairline/50 bg-inset hover:bg-raised"),children:[e.jsx("div",{className:"text-[12.5px] font-medium text-ink",children:"Bot’s current setup"}),e.jsx("div",{className:"mt-1 text-[11px] text-ink-secondary",children:"Keeps its model and configured computer, including a self-hosted VPS."})]}),e.jsxs("button",{type:"button",disabled:!Bn||R.length>0,onClick:()=>D("cloud"),className:C("rounded-xl border p-3 text-left disabled:cursor-not-allowed disabled:opacity-45",i==="cloud"?"border-accent/60 bg-accent/10":"border-hairline/50 bg-inset hover:bg-raised"),children:[e.jsx("div",{className:"text-[12.5px] font-medium text-ink",children:x("routines.runsOn.boat")}),e.jsx("div",{className:"mt-1 text-[11px] text-ink-secondary",children:x(Wt?"routines.runsOn.boatHintCloudHome":"routines.runsOn.boatHint")})]})]})})]}),Zn=!te&&v==="routine"?x(a?"routines.editor.edit":"routines.editor.new"):a||y?"Edit event":"New event",on=[["none","routines.repeat.once"],["daily","routines.repeat.daily"],["weekdays","routines.repeat.weekdays"],["weekly","routines.repeat.weekly"]];return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/65 p-3 backdrop-blur-sm",onMouseDown:d=>d.target===d.currentTarget&&p(),children:e.jsxs("div",{ref:Yt,role:"dialog","aria-modal":"true","aria-label":a||y?"Edit calendar event":"Create calendar event",tabIndex:-1,className:"max-h-[94vh] w-full max-w-[760px] overflow-y-auto rounded-2xl border border-hairline/60 bg-panel shadow-2xl",children:[e.jsxs("div",{className:"sticky top-0 z-20 flex items-center justify-between border-b border-hairline/40 bg-panel/95 px-5 py-3.5 backdrop-blur",children:[e.jsx("div",{className:"text-[15px] font-semibold text-ink",children:Zn}),e.jsx("button",{onClick:p,className:"rounded-full p-2 text-ink-secondary hover:bg-raised hover:text-ink","aria-label":"Close",children:e.jsx(ze,{size:18})})]}),e.jsxs("div",{className:"space-y-5 px-5 py-5 sm:px-8",children:[te&&Vt,te&&Zt,e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("span",{className:"mt-3 size-4 shrink-0 rounded bg-accent"}),e.jsx("input",{autoFocus:!0,value:P,onChange:d=>U(d.target.value),placeholder:v==="routine"?te?"Add title":x("routines.editor.titlePlaceholder"):"Add call title",className:"min-w-0 flex-1 border-b border-hairline/60 bg-transparent px-1 pb-2 text-[22px] font-medium text-ink outline-none placeholder:text-ink-tertiary focus:border-accent"})]}),te?e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(Rt,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-3",children:[Qt,Xt,en,tn,nn]})]}):e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(Rt,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-3",children:[e.jsx("div",{className:"text-[12.5px] font-medium text-ink",children:x("routines.editor.when")}),Qt,e.jsx("div",{role:"group","aria-label":x("routines.editor.repeat"),className:"flex flex-wrap gap-1.5",children:on.map(([d,M])=>e.jsx("button",{type:"button","aria-pressed":$===d,onClick:()=>Kt(d),className:C("rounded-full border px-3 py-1.5 text-[12px] font-medium transition",$===d?"border-accent-border bg-accent/15 text-accent-text":"border-hairline/50 bg-inset text-ink-secondary hover:bg-raised hover:text-ink"),children:x(M)},d))}),!on.some(([d])=>d===$)&&e.jsx("div",{className:"text-[11.5px] text-ink-secondary",children:x("routines.editor.customRepeat")})]})]}),e.jsxs("div",{className:"flex items-start gap-4",children:[ue?e.jsx(gt,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}):e.jsx(It,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}),e.jsx("div",{className:"min-w-0 flex-1",children:ue?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"routine-goal-room",className:"mb-2 block text-[12.5px] font-medium text-ink",children:"Choose a group"}),Ve.length>0?e.jsxs("select",{id:"routine-goal-room",value:Ne,onChange:d=>Yn(d.target.value),className:"w-full rounded-lg border border-hairline/50 bg-inset px-3 py-2.5 text-[12.5px] text-ink outline-none focus:border-accent",children:[e.jsx("option",{value:"",children:"Select a group"}),Ve.map(d=>e.jsx("option",{value:d.id,children:d.name},d.id))]}):e.jsx("div",{className:"rounded-xl border border-dashed border-hairline/60 bg-inset px-3.5 py-3 text-[11.5px] leading-relaxed text-ink-secondary",children:"Create a group from the sidebar first, then come back to schedule its goal."})]}),lt&&e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-[12.5px] font-medium text-ink",children:"Choose the lead"}),kt.length>0?e.jsxs(e.Fragment,{children:[e.jsx(Tt,{bots:kt,selected:K,multiple:!1,onChange:Fe}),e.jsxs("div",{className:"mt-2 text-[11.5px] text-ink-secondary",children:["The lead coordinates ",lt.name," and assigns work to its active members."]})]}):e.jsx("div",{className:"rounded-xl border border-warning/30 bg-warning/10 px-3.5 py-3 text-[11.5px] text-warning",children:"This group has no active members. Add or restore a bot before scheduling the goal."})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mb-2 text-[12.5px] font-medium text-ink",children:v==="routine"?te?"Assign a bot":x("routines.editor.who"):"Add guests"}),n.length>0?e.jsxs(e.Fragment,{children:[e.jsx(Tt,{bots:n,selected:K,multiple:v==="call",locked:!!s,onChange:Fe}),e.jsx("div",{className:"mt-2 text-[11.5px] text-ink-secondary",children:v==="routine"?"This bot owns each scheduled run.":`${jt.length||"No"} bot${jt.length===1?"":"s"} invited to the call.`})]}):e.jsxs("button",{type:"button",onClick:()=>{r({type:"toggleNewBot",open:!0}),p()},className:"w-full rounded-xl border border-dashed border-accent/45 bg-accent/[0.06] px-4 py-4 text-left hover:bg-accent/10",children:[e.jsx("div",{className:"text-[12.5px] font-medium text-accent",children:"Create your first bot"}),e.jsx("div",{className:"mt-1 text-[11.5px] text-ink-secondary",children:"A calendar event needs at least one bot."})]})]})})]}),te&&sn,e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(Le,{size:18,className:"mt-2.5 shrink-0 text-ink-secondary"}),e.jsx("textarea",{value:Y,onChange:d=>G(d.target.value),rows:5,placeholder:ue?"What should the team accomplish?":v==="routine"?te?"Add instructions for the bot":x("routines.editor.instructionsPlaceholder"):"Add description or agenda",className:"min-w-0 flex-1 resize-y rounded-xl border border-hairline/50 bg-inset px-3.5 py-3 text-[13px] leading-relaxed text-ink outline-none placeholder:text-ink-tertiary focus:border-accent"})]}),Vn,te&&an,te&&rn,!te&&e.jsxs("div",{children:[e.jsxs("button",{type:"button","aria-expanded":ct,"aria-controls":"routine-more-options",onClick:()=>Jn(d=>!d),className:"flex items-center gap-1.5 rounded-lg px-2 py-1.5 text-[12.5px] font-medium text-accent-text hover:bg-raised",children:[e.jsx(Et,{size:14,className:C("transition-transform",ct&&"rotate-90")}),x(ct?"routines.editor.fewer":"routines.editor.more")]}),ct&&e.jsxs("div",{id:"routine-more-options",className:"mt-3 space-y-5 rounded-xl border border-hairline/40 bg-inset/30 p-4",children:[Vt,Zt,e.jsxs("div",{className:"space-y-3",children:[Xt,en,tn,nn]}),sn,an,rn]})]}),_e&&e.jsxs("div",{className:"ml-10 flex items-start gap-2 rounded-xl border border-danger/30 bg-danger/10 px-3 py-2.5 text-[12.5px] text-danger",children:[e.jsx(Ge,{size:15,className:"mt-0.5 shrink-0"}),_e]})]}),e.jsxs("div",{className:"sticky bottom-0 flex items-center justify-end gap-2 border-t border-hairline/40 bg-panel/95 px-5 py-3.5 backdrop-blur",children:[e.jsx("button",{onClick:p,className:"rounded-lg px-4 py-2 text-[12.5px] text-ink-secondary hover:bg-raised hover:text-ink",children:"Cancel"}),e.jsxs("button",{onClick:Gn,disabled:Se||ot||!Un,className:"flex items-center gap-2 rounded-lg bg-accent px-5 py-2 text-[12.5px] font-semibold text-white hover:brightness-110 disabled:opacity-40",children:[(Se||ot)&&e.jsx(De,{size:14,className:"animate-spin"}),ot?"Attaching…":a||y?"Save":v==="call"?"Schedule call":ue?"Schedule team goal":"Schedule routine"]})]})]})})}function aa({seed:t,bots:n,routinesOnly:s=!1,onClose:o,onMore:l,onSavedRoutine:p,onSavedCall:g}){const{dispatch:u}=rt(),[r,a]=m.useState(s?"routine":t.kind),[c,y]=m.useState(t.name??""),[v,F]=m.useState(t.description??""),[h,P]=m.useState(t.botIds.length?t.botIds:n[0]?[n[0].id]:[]),[U,Y]=m.useState(t.resultsThreadId??null),G=k=>{k[0]!==h[0]&&Y(null),P(k)},[z,b]=m.useState(!1),[j,L]=m.useState(""),f=m.useRef(null),[N,E]=m.useState(null),S=r==="routine"?30:t.durationMinutes;m.useLayoutEffect(()=>{if(!t.anchor){E(null);return}const k=f.current;if(!k)return;const I=()=>{const _=k.getBoundingClientRect();let V=t.anchor.x+12,J=t.anchor.y+12;V+_.width>window.innerWidth-12&&(V=t.anchor.x-_.width-12),J+_.height>window.innerHeight-12&&(J=t.anchor.y-_.height-12),E({left:Math.max(12,Math.min(V,window.innerWidth-_.width-12)),top:Math.max(12,Math.min(J,window.innerHeight-_.height-12))})};return I(),window.addEventListener("resize",I),()=>window.removeEventListener("resize",I)},[r,t.anchor]);const T=async()=>{b(!0),L("");try{if(r==="routine"||s){const k=await oe("/api/routines",{method:"POST",body:JSON.stringify({name:c,prompt:v,botId:h[0],runOn:"maus",enabled:!0,schedule:{type:"once",at:t.at},durationMinutes:S,attachments:[],resultsThreadId:U})});p(k.routine)}else{const k=await oe("/api/calendar-calls",{method:"POST",body:JSON.stringify({name:c,description:v,botIds:h,schedule:{type:"once",at:t.at},durationMinutes:S})});g(k.call)}o()}catch(k){L(k instanceof Error?k.message:String(k))}finally{b(!1)}},A=!!(c.trim()&&h.length&&(r==="call"||v.trim()));return e.jsxs("div",{ref:f,role:"dialog","aria-label":"Quick create",style:N??void 0,className:C("fixed z-50 max-h-[calc(100vh-24px)] w-[min(430px,calc(100vw-24px))] overflow-y-auto rounded-2xl border border-hairline/60 bg-panel shadow-2xl",!N&&"left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2"),children:[e.jsxs("div",{className:"flex items-center justify-between bg-raised/70 px-4 py-2.5",children:[e.jsx("div",{className:"text-[12px] font-medium text-ink-secondary",children:"New calendar event"}),e.jsx("button",{onClick:o,className:"rounded-full p-1.5 text-ink-secondary hover:bg-inset hover:text-ink","aria-label":"Close",children:e.jsx(ze,{size:16})})]}),e.jsxs("div",{className:"space-y-3 p-4",children:[e.jsx("input",{autoFocus:!0,value:c,onChange:k=>y(k.target.value),placeholder:"Add title",onKeyDown:k=>{k.key==="Enter"&&A&&T()},className:"w-full border-b border-hairline/60 bg-transparent pb-2 text-[18px] font-medium text-ink outline-none placeholder:text-ink-tertiary focus:border-accent"}),!s&&e.jsxs("div",{className:"flex items-center gap-1 border-b border-hairline/35 pb-2",children:[e.jsx("button",{type:"button",onClick:()=>{a("routine"),P(k=>k.slice(0,1))},className:C("rounded-lg px-3 py-1.5 text-[12px] font-medium",r==="routine"?"bg-accent/15 text-accent":"text-ink-secondary hover:bg-raised hover:text-ink"),children:"Routine"}),e.jsx("button",{type:"button",onClick:()=>a("call"),className:C("rounded-lg px-3 py-1.5 text-[12px] font-medium",r==="call"?"bg-accent/15 text-accent":"text-ink-secondary hover:bg-raised hover:text-ink"),children:"Call"})]}),e.jsxs("div",{className:"flex items-start gap-3 text-[12.5px] text-ink",children:[e.jsx(Rt,{size:16,className:"mt-0.5 shrink-0 text-ink-secondary"}),e.jsxs("div",{children:[e.jsx("div",{children:ft(t.at)}),e.jsxs("div",{className:"mt-0.5 text-ink-secondary",children:[se(t.at),r==="call"?` – ${se(t.at+S*6e4)}`:""]})]})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(It,{size:16,className:"mt-2.5 shrink-0 text-ink-secondary"}),n.length===0?e.jsxs("button",{type:"button",onClick:()=>{u({type:"toggleNewBot",open:!0}),o()},className:"min-w-0 flex-1 rounded-xl border border-dashed border-accent/45 bg-accent/[0.06] px-3 py-3 text-left hover:bg-accent/10",children:[e.jsx("div",{className:"text-[12px] font-medium text-accent",children:"Create your first bot"}),e.jsx("div",{className:"mt-0.5 text-[10.5px] text-ink-secondary",children:"Then come back to schedule it."})]}):r==="routine"?e.jsxs("select",{value:h[0]??"",onChange:k=>G([k.target.value]),className:"min-w-0 flex-1 rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[12.5px] text-ink outline-none focus:border-accent",children:[e.jsx("option",{value:"",children:"Assign a bot"}),n.map(k=>e.jsx("option",{value:k.id,children:k.name},k.id))]}):e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(Tt,{bots:n,selected:h,multiple:!0,onChange:G})})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Le,{size:16,className:"mt-2.5 shrink-0 text-ink-secondary"}),e.jsx("textarea",{value:v,onChange:k=>F(k.target.value),rows:3,placeholder:r==="routine"?"What should the bot do?":"Add a description (optional)",className:"min-w-0 flex-1 resize-none rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[12.5px] leading-relaxed text-ink outline-none placeholder:text-ink-tertiary focus:border-accent"})]}),r==="routine"&&e.jsx(In,{bot:n.find(k=>k.id===h[0]),value:U,onChange:k=>Y(k??null)}),j&&e.jsx("div",{className:"rounded-lg bg-danger/10 px-3 py-2 text-[11.5px] text-danger",children:j})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-hairline/40 px-4 py-3",children:[e.jsx("button",{onClick:()=>l({...t,kind:r,botIds:h,name:c,description:v,durationMinutes:S,resultsThreadId:U}),title:"Choose repeating schedules and other options",className:"rounded-lg px-3 py-2 text-[12px] font-medium text-accent hover:bg-accent/10",children:"More options"}),e.jsxs("button",{onClick:T,disabled:!A||z,className:"flex items-center gap-1.5 rounded-lg bg-accent px-4 py-2 text-[12px] font-semibold text-white hover:brightness-110 disabled:opacity-40",children:[z&&e.jsx(De,{size:13,className:"animate-spin"}),"Save"]})]})]})}function ra({item:t,bots:n,groups:s,compact:o,layout:l,selected:p=!1,onOpen:g,onResize:u}){const r=t.kind==="call",a=t.kind==="routine"?t.routine:null,c=t.kind==="routine"?t.run:null,y=!r&&(c?.target??a?.target)==="room-goal",v=y?s.find(A=>A.id===(c?.groupId??a?.groupId)):void 0,h=(r?t.call.botIds:[c?.botId??a?.botId??""]).flatMap(A=>n.find(k=>k.id===A)??[]),P=h[0],U=r?t.call.name:c?.routineName??a?.name??"Routine",Y=r?"var(--color-accent)":P?us[P.color]:"var(--color-ink-tertiary)",G=!!(a&&!c&&!a.enabled),[z,b]=m.useState(t.durationMinutes);m.useEffect(()=>b(t.durationMinutes),[t.durationMinutes]);const j=c?.status,L=c?qe(c):void 0,f=r||!!(a&&!c&&!G&&a.schedule.type!=="cron"),N=r?t.call.schedule:a?.schedule,E=!!(N&&N.type!=="once"),S=N?.type==="interval"?Rn(N.everyMinutes):null,T=A=>{A.preventDefault(),A.stopPropagation();const k=A.clientY,I=z;let q=I;const _=J=>{q=Math.max(le,Math.min(240,Math.round((I+(J.clientY-k)/Q*60)/le)*le)),b(q)},V=()=>{if(document.removeEventListener("pointermove",_),document.removeEventListener("pointerup",V),q!==t.durationMinutes){if(E&&!window.confirm("Resize this entire recurring series?")){b(t.durationMinutes);return}u(q)}};document.addEventListener("pointermove",_),document.addEventListener("pointerup",V,{once:!0})};return e.jsxs("button",{"data-event-card":!0,type:"button",draggable:f,title:a?.schedule.type==="cron"?"Open this routine to edit its repeating schedule and time zone.":void 0,onDragStart:A=>{if(!f)return A.preventDefault();A.dataTransfer.effectAllowed="move",A.dataTransfer.setData(xt,JSON.stringify({kind:t.kind,id:r?t.call.id:a.id,at:t.at}))},onClick:A=>{A.stopPropagation(),g()},"aria-pressed":p,"aria-label":`${U}, ${se(t.at)}${G?`, ${x("routines.pausedSchedule")}`:L?`, ${L}`:""}`,className:C("group absolute z-10 overflow-hidden rounded-md border border-l-[3px] text-left transition hover:z-20 focus:z-20 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent",z<30?"px-1.5 py-0":"px-1.5 py-1",G&&"border-dashed opacity-70",j==="cancelled"&&"opacity-55",(j==="failed"||j==="missed")&&"border-danger/60",p&&"z-20 ring-2 ring-accent ring-offset-1 ring-offset-app"),style:{left:`calc(${l.column/l.columns*100}% + 2px)`,width:`calc(${100/l.columns}% - 4px)`,top:`${(new Date(t.at).getHours()*60+new Date(t.at).getMinutes())/60*Q}px`,height:`${Math.max(16,z/60*Q)}px`,background:`color-mix(in srgb, ${Y} ${G?6:16}%, var(--color-card))`,borderColor:`color-mix(in srgb, ${Y} 40%, transparent)`,borderLeftColor:Y,color:`color-mix(in srgb, ${Y} 55%, var(--color-ink))`},children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-1.5",children:[z>=30&&(r?e.jsx(Ot,{size:o?11:13,className:"mt-0.5 shrink-0"}):P?e.jsx(Ye,{bot:P,state:j?Ln(j):G?"sleeping":"idle",size:o?18:22,animated:j==="running"||j==="waiting"}):null),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:C("truncate text-[11px] font-semibold",z<30?"leading-none":"leading-tight"),children:U}),z>=30&&e.jsxs("div",{className:"mt-0.5 truncate text-[9.5px] opacity-80",children:[se(t.at)," · ",G?x("routines.pausedSchedule"):S??(r?`${h.length} bot${h.length===1?"":"s"}`:y?`Team goal · ${v?.name??"Group"}${L?` · ${L}`:""}`:L??P?.name)]})]}),z>=30&&h.length>1&&e.jsxs("span",{className:"rounded bg-inset/60 px-1 py-0.5 text-[8px]",children:["+",h.length-1]})]}),r&&e.jsx("div",{onPointerDown:T,className:"absolute inset-x-1 bottom-0 h-1.5 cursor-ns-resize rounded-full opacity-0 transition group-hover:opacity-100","aria-label":"Resize event",children:e.jsx("div",{className:"mx-auto mt-0.5 h-0.5 w-5 rounded-full bg-current opacity-50"})})]})}function ia({anchor:t,days:n,items:s,bots:o,groups:l,selectedId:p,onOpen:g,onCreate:u,onMove:r,onResize:a}){const c=m.useRef(null),[y,v]=m.useState(null),[F,h]=m.useState(null),P=ne(Date.now()),U=Array.from({length:n},(f,N)=>pe(t,N)),Y=n===7?64:n===3?180:280,G=`64px repeat(${n}, minmax(${Y}px, 1fr))`,z=64+n*Y;m.useEffect(()=>{const f=c.current;if(!f)return;const N=new Date,E=U.includes(P)?Math.max(0,N.getHours()-2):7;f.scrollTo({top:E*Q})},[n]);const b=(f,N)=>{if(f.button!==0||f.target.closest("[data-event-card]"))return;const E=f.currentTarget.getBoundingClientRect(),S=ut(N,f.clientY,E.top,Q);let T=S+30*6e4;v({day:N,start:S,end:T});const A=I=>{const q=ut(N,I.clientY,E.top,Q);T=Math.max(S+le*6e4,q+le*6e4),v({day:N,start:S,end:T})},k=I=>{document.removeEventListener("pointermove",A),document.removeEventListener("pointerup",k),v(null),u({kind:"routine",at:S,durationMinutes:Math.max(le,Math.round((T-S)/6e4)),botIds:[],anchor:{x:I.clientX,y:I.clientY}})};document.addEventListener("pointermove",A),document.addEventListener("pointerup",k,{once:!0})},j=(f,N)=>{f.preventDefault(),h(null);const E=f.currentTarget.getBoundingClientRect(),S=ut(N,f.clientY,E.top,Q),T=f.dataTransfer.getData(yn);if(T)return u({kind:"routine",at:S,durationMinutes:30,botIds:[T],anchor:{x:f.clientX,y:f.clientY}});const A=f.dataTransfer.getData(xt);if(A)try{const k=JSON.parse(A);r(k,S)}catch{}},L=(f,N)=>{if(!f.dataTransfer.types.includes(yn)&&!f.dataTransfer.types.includes(xt))return;f.preventDefault(),f.dataTransfer.dropEffect=f.dataTransfer.types.includes(xt)?"move":"copy";const E=f.currentTarget.getBoundingClientRect(),S=ut(N,f.clientY,E.top,Q);h(T=>T?.day===N&&T.at===S?T:{day:N,at:S})};return e.jsxs("div",{ref:c,className:"min-h-0 flex-1 overflow-auto border-l border-t border-hairline/40 bg-app",children:[e.jsxs("div",{className:"sticky top-0 z-30 grid bg-app/95 backdrop-blur",style:{gridTemplateColumns:G,minWidth:z},children:[e.jsx("div",{className:"border-b border-r border-hairline/40 px-2 py-3 text-center text-[9px] uppercase tracking-wider text-ink-secondary",children:Ms(-new Date(t).getTimezoneOffset())}),U.map(f=>{const N=new Date(f),E=f===P;return e.jsxs("div",{role:"columnheader",className:C("border-b border-r border-hairline/40 px-2 py-2 text-center last:border-r-0",E&&"bg-accent/[0.035]"),children:[e.jsx("div",{className:C("text-[10px] font-medium uppercase tracking-[0.14em]",E?"text-accent":"text-ink-secondary"),children:Ee[N.getDay()]}),e.jsx("div",{className:C("mx-auto mt-1 flex size-8 items-center justify-center rounded-full text-[15px] font-medium",E?"bg-accent text-accent-ink":"text-ink"),children:N.getDate()})]},f)})]}),e.jsxs("div",{role:"grid","aria-label":"Routine and call calendar",onDragEnd:()=>h(null),className:"relative grid",style:{height:Q*24,gridTemplateColumns:G,minWidth:z},children:[e.jsx("div",{className:"relative border-r border-hairline/40",children:Array.from({length:24},(f,N)=>e.jsx("div",{className:"absolute right-2 -translate-y-1/2 text-[9.5px] tabular-nums text-ink-tertiary",style:{top:N*Q},children:N===0?"":new Date(2e3,0,1,N).toLocaleTimeString([],{hour:"numeric"})},N))}),U.map(f=>{const N=new Date,E=(N.getHours()*60+N.getMinutes())/60*Q,S=s.filter(I=>ne(I.at)===f),T=Ds(S),A=y?.day===f?y:null,k=F?.day===f?F:null;return e.jsxs("div",{role:"gridcell","aria-label":`${ft(f)} calendar`,onPointerDown:I=>b(I,f),onDragOver:I=>L(I,f),onDragLeave:I=>{(!(I.relatedTarget instanceof Node)||!I.currentTarget.contains(I.relatedTarget))&&h(null)},onDrop:I=>j(I,f),className:C("relative border-r border-hairline/40 last:border-r-0",f===P&&"bg-accent/[0.025]"),children:[Array.from({length:48},(I,q)=>e.jsx("div",{className:C("pointer-events-none absolute inset-x-0 border-t",q%2===0?"border-hairline/30":"border-hairline/10"),style:{top:q/2*Q}},q)),f===P&&e.jsxs("div",{className:"pointer-events-none absolute inset-x-0 z-20 flex items-center",style:{top:E},children:[e.jsx("span",{className:"-ml-1 size-2 rounded-full bg-danger"}),e.jsx("span",{className:"h-px flex-1 bg-danger/80"})]}),A&&e.jsx("div",{className:"pointer-events-none absolute inset-x-1 z-10 rounded-md border border-accent/70 bg-accent/20",style:{top:(new Date(A.start).getHours()*60+new Date(A.start).getMinutes())/60*Q,height:Math.max(16,(A.end-A.start)/36e5*Q)}}),k&&e.jsx("div",{className:"pointer-events-none absolute inset-x-1 z-20 rounded-md border border-accent/80 bg-accent/25 shadow-sm",style:{top:(new Date(k.at).getHours()*60+new Date(k.at).getMinutes())/60*Q,height:Q/2},children:e.jsx("div",{className:"px-2 py-1 text-[9.5px] font-medium text-accent",children:se(k.at)})}),S.map(I=>e.jsx(ra,{item:I,bots:o,groups:l,compact:n===7,layout:T.get(I.id)??{column:0,columns:1},selected:I.id===p,onOpen:()=>g(I),onResize:q=>a(I,q)},I.id))]},f)})]})]})}function oa({item:t,bots:n,onClose:s,onEdit:o,onCallChanged:l,onOpenRoom:p,onOpenRun:g}){const{state:u,dispatch:r}=rt(),a=Lt(),[c,y]=m.useState(!1),v=m.useRef(!1),[F,h]=m.useState(!1),[P,U]=m.useState(void 0),[Y,G]=m.useState(""),z=t.kind==="call",b=t.kind==="routine"?t.routine:null,j=P===void 0?t.kind==="routine"?t.run:null:P&&(u.routineRuns.find(w=>w.id===P.id)??P),L=t.kind==="call"?t.call:null,f=!z&&(j?.target??b?.target)==="room-goal",N=f?j?.groupId??b?.groupId:void 0,E=u.groups.find(w=>w.id===N),S=j?.executionThreadId??j?.threadId,T=L?.botIds??[j?.botId??b?.botId??""],A=T.flatMap(w=>n.find(Z=>Z.id===w)??[]),k=A[0],I=f?E:k,q=!!(S&&(I?.threadId===S||I?.tasks?.some(w=>w.threadId===S))),_=j?j.resultsThreadId??j.sourceThreadId:b?.resultsThreadId,V=_&&[...u.bots,...u.groups].some(w=>w.threadId===_||w.tasks?.some(Z=>Z.threadId===_)),J=L?.name??j?.routineName??b?.name??"Routine",$=L?.description??j?.prompt??b?.prompt??"",B=L?.attachments??j?.attachments??b?.attachments??[],ie=L?.botIds.length===1?k?.id:void 0,ae=j?j.timeoutMinutes:b?.timeoutMinutes,je=()=>{S&&(f&&N?(r({type:"switchGroupTask",groupId:N,threadId:S}),p(N)):k&&(r({type:"select",id:k.id}),r({type:"switchTask",botId:k.id,threadId:S})),s())},me=async(w,Z="POST",Re)=>{y(!0),G("");try{const X=await oe(w,{method:Z,...Re?{body:JSON.stringify(Re)}:{}});X.routine&&r({type:"routinePatched",routine:X.routine}),X.run&&r({type:"routineRunPatched",run:X.run})}catch(X){G(X instanceof Error?X.message:String(X))}finally{y(!1)}},he=()=>{!b||c||v.current||(v.current=!0,h(!0),U(null),y(!0),G(""),r({type:"runRoutine",routineId:b.id,onStarted:U,onError:w=>G(w instanceof Error?w.message:String(w)),onSettled:()=>{v.current=!1,h(!1),y(!1)}}))},Ue=async()=>{if(L){y(!0),G("");try{const{group:w}=await oe(`/api/calendar-calls/${L.id}/room`,{method:"POST"});r({type:"groupPatched",group:w}),p(w.id)}catch(w){G(w instanceof Error?w.message:String(w))}finally{y(!1)}}},O=async()=>{window.confirm(`Delete “${J}”?`)&&(L?(await oe(`/api/calendar-calls/${L.id}`,{method:"DELETE"}),l(L.id)):b&&r({type:"deleteRoutine",routineId:b.id}),s())},ge=b?.id??j?.routineId,re=ge?u.routineRuns.filter(w=>w.routineId===ge).sort((w,Z)=>pt(Z)-pt(w)).slice(0,3):[],ce=j?.runOn??b?.runOn,de=os({roomGoal:f,runOn:ce,computer:k?.computer,cloudHome:u.config?.cloudHome===!0}),we=_?[...u.bots,...u.groups].find(w=>w.threadId===_||w.tasks?.some(Z=>Z.threadId===_)):void 0,be=_?we?.tasks?.find(w=>w.threadId===_)?.title??we?.name??x("routines.results.missing"):x("routines.results.main");return e.jsxs("aside",{"aria-label":x("routines.drawer.label"),className:"flex h-full w-[min(310px,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-4 py-3.5",children:[z?e.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-full bg-accent/15 text-accent-text",children:e.jsx(Ot,{size:16})}):f?e.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-full bg-accent/15 text-accent-text",children:e.jsx(gt,{size:16})}):k&&e.jsx(Ye,{bot:k,state:j?Ln(j.status):b?.enabled===!1?"sleeping":"idle",size:36,animated:!1}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"break-words text-[15px] font-semibold leading-snug text-ink",children:J}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1.5",children:[b&&e.jsx("span",{className:C("rounded-full px-2 py-0.5 text-[10.5px] font-medium",b.enabled?"bg-success/15 text-success":"bg-inset text-ink-secondary"),children:Dt(b)}),e.jsxs("span",{className:"text-[11px] text-ink-secondary",children:[ft(t.at)," · ",se(t.at),z?` – ${se(t.at+t.durationMinutes*6e4)}`:""]})]})]}),e.jsx("button",{type:"button",onClick:s,className:"rounded-full p-1.5 text-ink-secondary hover:bg-raised hover:text-ink","aria-label":x("routines.drawer.close"),children:e.jsx(ze,{size:16})})]}),e.jsxs("div",{className:"min-h-0 flex-1 space-y-4 overflow-y-auto px-4 py-4",children:[j&&e.jsxs("div",{role:"status","aria-live":"polite",className:"rounded-xl border border-hairline/40 bg-inset p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[12px] font-medium text-ink",children:[j.status==="running"&&e.jsx(De,{size:13,className:"animate-spin text-accent"}),qe(j)]}),j.output&&e.jsx("div",{className:"mt-2 max-h-48 overflow-y-auto whitespace-pre-wrap text-[11.5px] leading-relaxed text-ink-secondary",children:j.output}),j.error&&e.jsx("div",{className:"mt-2 text-[11.5px] text-danger",children:j.error})]}),j?.attention&&e.jsxs("div",{className:"flex items-start gap-2 rounded-xl border border-warning/30 bg-warning/10 px-3 py-2.5 text-warning",children:[e.jsx(Ge,{size:15,className:"mt-0.5 shrink-0"}),e.jsx("div",{className:"min-w-0 whitespace-pre-wrap text-[11.5px] leading-relaxed",children:j.attention})]}),j?.status==="waiting"&&!j.attention&&e.jsx("div",{className:"rounded-xl border border-warning/30 bg-warning/10 px-3 py-2.5 text-[11.5px] text-warning",children:"This run is waiting. Open its execution thread for more context."}),e.jsx(ke,{label:z?x("routines.drawer.guests"):f?x("routines.drawer.lead"):x("routines.drawer.bot"),children:e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[A.map(w=>e.jsxs("div",{className:"flex items-center gap-1.5 rounded-full border border-hairline/50 bg-inset py-0.5 pl-0.5 pr-2.5",children:[e.jsx(Ye,{bot:w,state:"idle",size:22,animated:!1}),e.jsx("span",{className:"text-[12px] text-ink",children:w.name})]},w.id)),A.length===0&&e.jsx("span",{className:"text-[12.5px] text-ink-secondary",children:x("routines.unavailableBot")})]})}),f&&e.jsx(ke,{label:x("routines.drawer.group"),children:e.jsx("div",{className:"text-[12.5px] text-ink",children:E?.name??"Group unavailable"})}),(b||L)&&e.jsxs(ke,{label:x("routines.drawer.schedule"),children:[e.jsx("div",{className:"text-[12.5px] text-ink",children:yt((b??L).schedule)}),b?.schedule.type==="cron"&&e.jsx("div",{className:"mt-2",children:e.jsx(Ws,{schedule:b.schedule,paused:!b.enabled})})]}),$&&e.jsx(ke,{label:z?x("routines.drawer.agenda"):x("routines.drawer.what"),children:e.jsx("div",{className:"whitespace-pre-wrap text-[12.5px] leading-relaxed text-ink",children:$})}),!z&&e.jsxs(ke,{label:x("routines.drawer.runsOn"),children:[e.jsxs("div",{className:"flex items-start gap-2 text-[12.5px] text-ink",children:[ce==="cloud"?e.jsx(Nn,{size:14,className:"mt-0.5 shrink-0 text-ink-secondary"}):e.jsx(Sn,{size:14,className:"mt-0.5 shrink-0 text-ink-secondary"}),e.jsx("span",{children:de.label})]}),e.jsx("div",{className:"mt-0.5 text-[11px] leading-relaxed text-ink-secondary",children:de.hint})]}),!z&&!f&&e.jsx(ke,{label:x("routines.results.label"),children:e.jsx("div",{className:"text-[12.5px] text-ink",children:be})}),B.length>0&&e.jsxs(ke,{label:"Attachments",children:[e.jsx(On,{attachments:B}),L&&e.jsx("div",{className:"mt-1.5 text-[11px] leading-relaxed text-ink-secondary",children:L.botIds.length>1?"These references will be shared in the group when the event starts.":"These references stay with the event and are available when you join the group."})]}),a&&!z&&e.jsx(ke,{label:x("routines.drawer.runLimit"),children:e.jsx("div",{className:"text-[12.5px] text-ink",children:ae==null?"No time limit":`Stops if still running after ${st(ae)}`})}),!z&&e.jsx(ke,{label:x("routines.logs"),action:b&&e.jsxs("button",{type:"button",onClick:()=>{r({type:"showRoutines",section:"logs",routineId:b.id,botId:b.botId}),s()},className:"flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[11px] text-accent-text hover:bg-raised",children:[e.jsx(Le,{size:11}),x("routines.drawer.allRuns")]}),children:re.length===0?e.jsx("div",{className:"text-[12px] text-ink-secondary",children:x("routines.drawer.noRuns")}):e.jsx("div",{className:"space-y-1",children:re.map(w=>e.jsx(da,{run:w,current:w.id===j?.id,onOpen:()=>g?.(w)},w.id))})}),Y&&e.jsx("div",{role:"alert",className:"rounded-lg bg-danger/10 px-3 py-2 text-[11.5px] text-danger",children:Y})]}),e.jsxs("div",{className:"space-y-2 border-t border-hairline/40 px-4 py-3",children:[b&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:he,disabled:c,className:"flex flex-1 items-center justify-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[12px] font-semibold text-accent-ink hover:brightness-110 disabled:opacity-50",children:[F?e.jsx(De,{size:13,className:"animate-spin"}):e.jsx(cn,{size:13}),F?x("routines.starting"):x("routines.runNow")]}),e.jsxs("button",{disabled:c,onClick:()=>{me(`/api/routines/${b.id}`,"PATCH",{enabled:!b.enabled})},title:b.enabled?"Pause routine":"Resume routine",className:"flex flex-1 items-center justify-center gap-1.5 rounded-lg border border-hairline/50 bg-control px-3 py-2 text-[12px] font-medium text-ink hover:bg-raised-hover disabled:opacity-40",children:[b.enabled?e.jsx(wn,{size:13}):e.jsx(cn,{size:13}),b.enabled?x("routines.pause"):x("routines.resume")]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[ie&&e.jsxs("button",{onClick:()=>p(ie),className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[12px] font-semibold text-accent-ink hover:brightness-110",children:[e.jsx(Qe,{size:13}),"Join group"]}),L&&L.botIds.length>1&&e.jsxs("button",{onClick:Ue,disabled:c,className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[12px] font-semibold text-accent-ink hover:brightness-110 disabled:opacity-50",children:[e.jsx(Qe,{size:13}),"Join group"]}),f&&E&&!S&&e.jsxs("button",{onClick:()=>{p(E.id),s()},className:"flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-raised hover:text-ink",children:[e.jsx(Qe,{size:13}),"Open group"]}),q&&e.jsxs("button",{onClick:je,className:"flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-raised hover:text-ink",children:[e.jsx(Qe,{size:13}),f?"Open group thread":"Open thread"]}),V&&_&&e.jsxs("button",{type:"button",onClick:()=>{ls(r,{botId:T[0],threadId:_},u),s()},className:"flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-raised hover:text-ink",children:[e.jsx(Qe,{size:13}),x("routines.results.open")]}),j&&["queued","running","waiting"].includes(j.status)&&e.jsxs("button",{onClick:()=>{me(`/api/routine-runs/${j.id}/cancel`)},disabled:c,className:"flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-raised hover:text-ink disabled:opacity-40",children:[e.jsx(ze,{size:13}),"Cancel run"]}),e.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[(b||L)&&e.jsx("button",{onClick:o,className:"rounded-lg px-2.5 py-1.5 text-[12px] font-medium text-ink hover:bg-raised",children:x("routines.edit")}),(b||L)&&e.jsx("button",{onClick:()=>{O()},className:"rounded-lg p-2 text-ink-secondary hover:bg-danger/10 hover:text-danger",title:x("routines.delete"),"aria-label":x("routines.delete"),children:e.jsx(ds,{size:14})})]})]})]})]})}function ke({label:t,action:n,children:s}){return e.jsxs("section",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between gap-2",children:[e.jsx("h3",{className:"text-[10.5px] font-semibold uppercase tracking-wider text-ink-tertiary",children:t}),n]}),s]})}function la(t){if(t.startedAt==null||t.finishedAt==null||t.finishedAt<t.startedAt)return null;const n=Math.round((t.finishedAt-t.startedAt)/1e3);return n<60?`${n}s`:st(Math.round(n/60))}function da({run:t,current:n,onOpen:s}){const o=t.startedAt??t.scheduledFor,l=la(t),p=t.status==="completed"&&(!t.goalStatus||t.goalStatus==="completed"),g=nt(t)||t.goalStatus==="failed"||t.goalStatus==="blocked",u=["queued","running","waiting"].includes(t.status);return e.jsxs("button",{type:"button",onClick:s,"aria-label":x("routines.openRun",{name:t.routineName,status:qe(t)}),"aria-current":n||void 0,className:C("flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left hover:bg-raised",n&&"bg-raised"),children:[p?e.jsx(Cn,{size:14,className:"shrink-0 text-success","aria-hidden":"true"}):g?e.jsx(xs,{size:14,className:"shrink-0 text-danger","aria-hidden":"true"}):u?e.jsx(De,{size:14,className:"shrink-0 animate-spin text-accent","aria-hidden":"true"}):e.jsx(Ge,{size:14,className:"shrink-0 text-ink-tertiary","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] text-ink",children:new Date(o).toLocaleDateString([],{month:"short",day:"numeric"})}),e.jsxs("span",{className:"shrink-0 text-[11px] tabular-nums text-ink-secondary",children:[se(o),l?` · ${l}`:""]})]})}function ca({routines:t,bots:n,groups:s,onClose:o,onEdit:l,onOpenRoom:p}){const{dispatch:g}=rt(),u=m.useRef(null);return An(u,o),e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-3",onMouseDown:r=>r.target===r.currentTarget&&o(),children:e.jsxs("div",{ref:u,role:"dialog","aria-modal":"true","aria-label":"Paused routines",tabIndex:-1,className:"w-full max-w-[520px] rounded-2xl border border-hairline/60 bg-panel shadow-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-hairline/40 px-5 py-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[16px] font-semibold text-ink",children:"Paused routines"}),e.jsx("div",{className:"mt-0.5 text-[11.5px] text-ink-secondary",children:"History is kept; no new tasks will run."})]}),e.jsx("button",{onClick:o,className:"rounded-full p-2 text-ink-secondary hover:bg-raised","aria-label":x("routines.paused.close"),children:e.jsx(ze,{size:17})})]}),e.jsx("div",{className:"max-h-[55vh] space-y-1 overflow-y-auto p-3",children:t.map(r=>{const a=n.find(y=>y.id===r.botId),c=r.target==="room-goal"?s.find(y=>y.id===r.groupId):void 0;return e.jsxs("div",{className:"flex items-center gap-3 rounded-xl px-3 py-2.5 hover:bg-raised/60",children:[c?e.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-full bg-accent/12 text-accent",children:e.jsx(gt,{size:17})}):a&&e.jsx(Ye,{bot:a,state:"sleeping",size:36,animated:!1}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[12.5px] font-medium text-ink",children:r.name}),e.jsxs("div",{className:"mt-0.5 truncate text-[10.5px] text-ink-secondary",children:[c?`Team goal · ${c.name} · `:"",yt(r.schedule)]})]}),c&&e.jsx("button",{onClick:()=>{p(c.id),o()},className:"rounded-lg px-2 py-1.5 text-[11px] text-ink-secondary hover:bg-inset",children:"Group"}),e.jsx("button",{onClick:()=>g({type:"updateRoutine",routineId:r.id,patch:{enabled:!0}}),className:"rounded-lg bg-accent/15 px-2.5 py-1.5 text-[11px] font-medium text-accent",children:"Resume"}),e.jsx("button",{onClick:()=>l(r),className:"rounded-lg px-2 py-1.5 text-[11px] text-ink-secondary hover:bg-inset",children:"Edit"})]},r.id)})})]})})}function ua({routine:t,bots:n,lockedBotId:s,defaultRunOn:o,onClose:l}){const p=t?.schedule.type==="once"?t.schedule.at:t?.schedule.type==="daily"?Me(Date.now(),t.schedule.time):t?.schedule.type==="interval"?t.schedule.anchorAt:t?.schedule.type==="cron"?t.nextRunAt??at():at();return e.jsx(Pn,{seed:{kind:"routine",at:p,durationMinutes:t?.durationMinutes??30,botIds:s?[s]:t?[t.botId]:[],routine:t},bots:n,lockedBotId:s,defaultRunOn:o,onClose:l,onSavedCall:()=>{}})}function xa({onBack:t,onOpenRoom:n}){const{state:s,dispatch:o}=rt(),{capabilities:l}=ns(),p=Lt(),g=window.ogb?.remoteClient?.active===!0,u=m.useRef(null),[r,a]=m.useState(s.routinesFocus?.section==="logs"?"logs":"calendar"),[c,y]=m.useState(s.routinesFocus?.view==="list"?"list":"week"),[v,F]=m.useState(()=>ne(Date.now())),[h,P]=m.useState(s.routinesFocus?.botId??"all"),[U,Y]=m.useState(s.routinesFocus?.routineId),[G,z]=m.useState(s.routinesFocus?.runStatus??"all"),[b,j]=m.useState([]),[L,f]=m.useState(null),[N,E]=m.useState(null),[S,T]=m.useState(null),[A,k]=m.useState(!1),[I,q]=m.useState(0),[_,V]=m.useState(""),J=s.bots.filter(i=>!i.hidden),$=p&&!g,B=r==="webhooks"&&!$?"calendar":r,ie=c==="day"?1:7,ae=ie===7?Ns(v):ne(v),je=pe(ae,ie),me=B==="calendar"&&c!=="list";m.useEffect(()=>{const i=s.routinesFocus;a(i?.section==="logs"?"logs":"calendar"),y(i?.view==="list"?"list":"week"),P(i?.botId??"all"),Y(i?.routineId),z(i?.runStatus??"all")},[s.routinesFocus]);const he=m.useCallback(async()=>{try{const i=await oe("/api/calendar-calls");j(i.calls??[])}catch(i){V(i instanceof Error?i.message:String(i))}},[]);m.useEffect(()=>{g||he()},[he,g]),m.useEffect(()=>{u.current?.focus({preventScroll:!0})},[]);const Ue=m.useMemo(()=>{const i=mn(s.routines,s.routineRuns,ae,je).map(H=>({...H,kind:"routine"})),D=Date.now(),R=s.routines.filter(H=>!H.enabled),ye=mn(R.map(H=>({...H,enabled:!0})),s.routineRuns,ae,je).filter(H=>!H.run&&H.at>=D).map(H=>({...H,id:`paused-${H.id}`,routine:R.find(_e=>_e.id===H.routine?.id)??H.routine,kind:"routine"})),Se=na(b,ae,je).map(H=>({...H,kind:"call"}));return[...i,...ye,...Se].filter(H=>h==="all"||(H.kind==="call"?H.call.botIds.includes(h):(H.routine?.botId??H.run?.botId)===h)).sort((H,_e)=>H.at-_e.at)},[s.routines,s.routineRuns,b,ae,je,h]),O=S?.kind==="call"?(()=>{const i=b.find(D=>D.id===S.call.id);return i?{...S,call:i}:null})():S?.kind==="routine"?{...S,routine:S.routine?s.routines.find(i=>i.id===S.routine?.id)??null:null,run:S.run?s.routineRuns.find(i=>i.id===S.run?.id)??S.run:null}:null,ge=s.routines.filter(i=>!i.enabled&&(i.schedule.type!=="once"||i.schedule.at>Date.now())),re=s.routineRuns.filter(i=>["queued","running","waiting"].includes(i.status)).length,ce=s.routineRuns.filter(i=>nt(i)&&!i.seenAt).length,de=s.routines.filter(i=>h==="all"||i.botId===h),we=s.routineRuns.filter(i=>h==="all"||i.botId===h),be=i=>i.schedule.type==="once"?i.schedule.at:i.schedule.type==="interval"?i.schedule.anchorAt:i.schedule.type==="cron"?i.nextRunAt??at():Me(Date.now(),i.schedule.time),w=i=>T({kind:"routine",id:i.id,at:i.nextRunAt??be(i),durationMinutes:i.durationMinutes,routine:i,run:null}),Z=i=>{Y(i.id),a("logs")},Re=i=>{T({kind:"routine",id:i.id,at:i.scheduledFor,durationMinutes:i.durationMinutes??30,routine:s.routines.find(D=>D.id===i.routineId)??null,run:i}),["failed","missed"].includes(i.status)&&!i.seenAt&&o({type:"markRoutineRunSeen",runId:i.id})},X=i=>{T(i),i.kind==="routine"&&i.run&&["failed","missed"].includes(i.run.status)&&!i.run.seenAt&&o({type:"markRoutineRunSeen",runId:i.run.id})},Ke=l.windowChrome==="mac-inset",Oe=Ke?{WebkitAppRegion:"drag"}:void 0,Pe=Ke?{WebkitAppRegion:"no-drag"}:void 0,fe=i=>{a("calendar"),y(i),F(D=>ne(D))},Je=m.useCallback(()=>F(ne(Date.now())),[]),K=m.useCallback(()=>q(0),[]),Ie=m.useCallback(i=>{T(null),f({kind:"routine",at:at(),durationMinutes:30,botIds:[],...i})},[]),it=()=>{if(r==="webhooks"&&a("calendar"),p)return Ie({kind:"routine"});T(null),E({kind:"routine",at:at(),durationMinutes:30,botIds:h!=="all"?[h]:[]})};m.useEffect(()=>{const i=D=>{if(!D.target?.matches("input, textarea, select, [contenteditable=true]")){if(D.key==="Escape"){f(null),E(null),T(null);return}B!=="calendar"||D.metaKey||D.ctrlKey||D.altKey||(D.key.toLowerCase()==="c"&&(D.preventDefault(),Ie()),D.key.toLowerCase()==="t"&&Je(),(D.key==="1"||D.key.toLowerCase()==="d")&&fe("day"),D.key.toLowerCase()==="w"&&fe("week"),D.key.toLowerCase()==="l"&&fe("list"))}};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[B,Ie,Je,v]);const $e=i=>j(D=>D.some(R=>R.id===i.id)?D.map(R=>R.id===i.id?i:R):[i,...D]),Fe=async(i,D)=>{if(D!==i.at)try{if(i.kind==="routine"){const R=s.routines.find(Se=>Se.id===i.id);if(!R)return;if(R.schedule.type==="cron")throw new Error("Open this routine to edit its repeating schedule and time zone.");if(R.schedule.type!=="once"&&!window.confirm("Move this entire recurring series?"))return;const ye=await oe(`/api/routines/${R.id}`,{method:"PATCH",body:JSON.stringify({schedule:pn(R.schedule,i.at,D)})});o({type:"routinePatched",routine:ye.routine})}else{const R=b.find(Se=>Se.id===i.id);if(!R||R.schedule.type==="daily"&&!window.confirm("Move this entire recurring series?"))return;const ye=await oe(`/api/calendar-calls/${R.id}`,{method:"PATCH",body:JSON.stringify({schedule:pn(R.schedule,i.at,D)})});$e(ye.call)}}catch(R){V(R instanceof Error?R.message:String(R))}},ee=async(i,D)=>{try{if(i.kind==="routine"&&i.routine){const R=await oe(`/api/routines/${i.routine.id}`,{method:"PATCH",body:JSON.stringify({durationMinutes:D})});o({type:"routinePatched",routine:R.routine})}else if(i.kind==="call"){const R=await oe(`/api/calendar-calls/${i.call.id}`,{method:"PATCH",body:JSON.stringify({durationMinutes:D})});$e(R.call)}}catch(R){V(R instanceof Error?R.message:String(R))}},vt=()=>{if(!O)return;const i=O.kind==="call"?{kind:"call",at:O.at,durationMinutes:O.call.durationMinutes,botIds:O.call.botIds,call:O.call}:{kind:"routine",at:O.at,durationMinutes:O.routine?.durationMinutes??O.run?.durationMinutes??30,botIds:[O.routine?.botId??O.run?.botId??""].filter(Boolean),routine:O.routine??void 0};T(null),E(i)},Ne=i=>C("flex items-center gap-1.5 rounded-md px-3 py-1.5 text-[12px] font-medium",i?"bg-raised text-ink shadow-sm":"text-ink-secondary hover:text-ink"),Be=!!O&&B!=="webhooks";return e.jsxs("main",{className:"flex h-full min-w-0 flex-1 flex-col bg-app animate-workspace-in",children:[e.jsxs("header",{className:C("shrink-0 border-b border-hairline/35 bg-app py-3 pr-4",Ke?"pl-[86px]":"pl-4"),style:Oe,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",ref:u,onClick:t,"aria-label":"Back",title:"Back",className:"flex size-9 shrink-0 items-center justify-center rounded-lg text-ink-secondary hover:bg-raised hover:text-ink",style:Pe,children:e.jsx(ss,{size:18})}),e.jsx("h1",{"data-tour":"automations-page",className:"mr-1 text-[18px] font-semibold tracking-tight text-ink",children:x("routines.title")}),me&&e.jsxs("div",{className:"flex min-w-0 items-center gap-1",style:Pe,children:[e.jsx("button",{type:"button",onClick:()=>F(i=>pe(i,-ie)),className:"rounded-md p-1.5 text-ink-secondary hover:bg-raised hover:text-ink","aria-label":x("routines.previous"),children:e.jsx(kn,{size:16})}),e.jsx("button",{type:"button",onClick:()=>F(i=>pe(i,ie)),className:"rounded-md p-1.5 text-ink-secondary hover:bg-raised hover:text-ink","aria-label":x("routines.next"),children:e.jsx(Et,{size:16})}),e.jsx("div",{className:"min-w-0 truncate px-1 text-[14px] font-medium text-ink","aria-live":"polite",children:Rs(ae,ie)}),e.jsx("button",{type:"button",onClick:Je,className:"ml-1 rounded-lg border border-hairline/50 bg-panel px-2.5 py-1 text-[12px] font-medium text-ink hover:bg-raised",children:x("routines.today")})]}),e.jsxs("div",{className:"ml-auto flex flex-wrap items-center gap-2",style:Pe,children:[e.jsxs("div",{role:"group",className:"flex items-center rounded-lg border border-hairline/50 bg-panel p-0.5","aria-label":x("routines.view.label"),children:[e.jsx("button",{type:"button","aria-pressed":B==="calendar"&&c==="day",onClick:()=>fe("day"),className:Ne(B==="calendar"&&c==="day"),children:x("routines.view.day")}),e.jsx("button",{type:"button","aria-pressed":B==="calendar"&&c==="week",onClick:()=>fe("week"),className:Ne(B==="calendar"&&c==="week"),children:x("routines.view.week")}),e.jsx("button",{type:"button","aria-pressed":B==="calendar"&&c==="list",onClick:()=>fe("list"),className:Ne(B==="calendar"&&c==="list"),children:x("routines.view.list")})]}),e.jsxs("button",{type:"button","aria-pressed":B==="logs",onClick:()=>{if(B==="logs"){a("calendar");return}a("logs"),Y(void 0)},className:C("flex items-center gap-1.5 rounded-lg border border-hairline/50 px-2.5 py-1.5 text-[12px] font-medium",B==="logs"?"bg-raised text-ink":"bg-panel text-ink-secondary hover:text-ink"),children:[e.jsx(Le,{size:13}),x("routines.logs"),ce>0&&e.jsx("span",{className:"rounded-full bg-danger/10 px-1.5 text-[9px] text-danger",children:ce})]}),$&&e.jsxs("button",{type:"button","aria-pressed":B==="webhooks",onClick:()=>a(B==="webhooks"?"calendar":"webhooks"),className:C("flex items-center gap-1.5 rounded-lg border border-hairline/50 px-2.5 py-1.5 text-[12px] font-medium",B==="webhooks"?"bg-raised text-ink":"bg-panel text-ink-secondary hover:text-ink"),children:[e.jsx(as,{size:13}),x("routines.webhooks"),s.webhooks.length>0&&e.jsx("span",{className:"rounded-full bg-accent/15 px-1.5 text-[9px] text-accent-text",children:s.webhooks.length})]}),B==="webhooks"?e.jsxs("button",{type:"button",disabled:J.length===0,onClick:()=>q(i=>i+1),className:"flex items-center gap-1.5 rounded-lg bg-accent px-3.5 py-2 text-[12px] font-semibold text-accent-ink hover:brightness-110 disabled:opacity-40",children:[e.jsx(dn,{size:15,"aria-hidden":"true"}),x("routines.newWebhook")]}):e.jsxs("button",{type:"button",onClick:it,className:"flex items-center gap-1.5 rounded-lg bg-accent px-3.5 py-2 text-[12px] font-semibold text-accent-ink hover:brightness-110",children:[e.jsx(dn,{size:15,"aria-hidden":"true"}),x("routines.newRoutine")]})]})]}),B!=="webhooks"&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",style:Pe,children:[ce>0&&e.jsxs("button",{type:"button",onClick:()=>o({type:"markAllRoutineRunsSeen"}),className:"flex items-center gap-1.5 rounded-lg border border-hairline/50 bg-panel px-2.5 py-1.5 text-[11.5px] text-ink-secondary hover:bg-raised hover:text-ink",title:x("routines.markAllSeen"),"aria-label":x("routines.markAllSeen"),children:[e.jsx(rs,{size:12}),x("routines.markAllSeen")]}),re>0&&e.jsxs("span",{className:"flex items-center gap-1.5 rounded-full bg-accent/10 px-2.5 py-1.5 text-[10.5px] text-accent-text",children:[e.jsx(De,{size:11,className:"animate-spin"}),re," active"]}),ce>0&&e.jsxs("button",{type:"button",onClick:()=>o({type:"showRoutines",section:"logs",runStatus:"problems"}),className:"flex items-center gap-1.5 rounded-full bg-danger/10 px-2.5 py-1.5 text-[10.5px] text-danger",title:"Open problem run logs","aria-label":"Open problem run logs",children:[e.jsx(Ge,{size:11}),ce]}),ge.length>0&&e.jsxs("button",{type:"button",onClick:()=>k(!0),"aria-label":"View paused routines",className:"flex items-center gap-1.5 rounded-full border border-hairline/50 px-2.5 py-1.5 text-[10.5px] text-ink-secondary hover:bg-raised",children:[e.jsx(wn,{size:11}),ge.length]}),e.jsx("div",{className:"ml-auto flex items-center gap-2",children:e.jsxs("select",{"aria-label":"Filter schedule by bot",value:h,onChange:i=>{P(i.target.value),Y(void 0)},className:"max-w-[180px] rounded-lg border border-hairline/50 bg-panel px-2.5 py-1.5 text-[11.5px] text-ink outline-none focus:border-accent",children:[e.jsx("option",{value:"all",children:"All bots"}),J.map(i=>e.jsx("option",{value:i.id,children:i.name},i.id))]})}),_&&e.jsxs("button",{type:"button",onClick:()=>V(""),className:"flex items-center gap-1.5 rounded-lg bg-danger/10 px-2.5 py-1.5 text-[10.5px] text-danger",children:[e.jsx(Ge,{size:11}),_,e.jsx(ze,{size:11})]}),me&&s.routinesLoadState==="error"&&e.jsx("p",{role:"alert",className:"w-full text-[11.5px] text-danger",children:x("routines.loadError")}),me&&s.routinesLoadState==="loading"&&s.routines.length===0&&e.jsx("p",{role:"status",className:"w-full text-[11.5px] text-ink-secondary",children:x("routines.loading")})]})]}),e.jsx(pa,{}),e.jsxs("div",{className:"@container/routines relative flex min-h-0 flex-1",children:[e.jsx("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:B==="webhooks"?e.jsx(gs,{bots:J,createRequest:I,onCreateHandled:K}):B==="logs"?e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:e.jsx(Bs,{runs:we,bots:s.bots,loading:s.routinesLoadState==="loading"&&we.length===0,error:s.routinesLoadState==="error",routineId:U,status:G,onStatusChange:z,onClearRoutine:()=>Y(void 0),onOpen:Re})}):c==="list"?e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:e.jsxs("div",{className:"mx-auto w-full max-w-4xl space-y-5 p-4 sm:p-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-[17px] font-semibold text-ink",children:x("routines.title")}),e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:"All schedules, including paused and finished routines."})]}),e.jsx(Fs,{routines:de,runs:s.routineRuns,bots:s.bots,loading:s.routinesLoadState==="loading"&&de.length===0,error:s.routinesLoadState==="error",onOpen:w,onLogs:Z}),!g&&b.some(i=>h==="all"||i.botIds.includes(h))&&e.jsxs("section",{className:"space-y-2","aria-label":"Scheduled calls",children:[e.jsx("h2",{className:"text-[15px] font-semibold text-ink",children:"Scheduled calls"}),b.filter(i=>h==="all"||i.botIds.includes(h)).map(i=>e.jsxs("button",{type:"button",onClick:()=>T({kind:"call",id:i.id,at:i.schedule.type==="once"?i.schedule.at:Me(Date.now(),i.schedule.time),durationMinutes:i.durationMinutes,call:i}),className:"flex w-full items-center gap-3 rounded-xl border border-hairline/40 bg-card p-4 text-left hover:bg-raised",children:[e.jsx(Ot,{size:17,className:"text-accent"}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-[13px] font-medium text-ink",children:i.name}),e.jsx("span",{className:"mt-1 block text-[11.5px] text-ink-secondary",children:yt(i.schedule)})]})]},i.id))]})]})}):e.jsxs("div",{className:"flex min-h-0 flex-1",children:[!Be&&e.jsx("div",{className:"hidden shrink-0 @min-[1040px]/routines:block",children:e.jsx(Ps,{bots:J,anchor:v,onSelectDate:i=>F(ne(i))})}),e.jsx(ia,{anchor:ae,days:ie,items:Ue,bots:s.bots,groups:s.groups,selectedId:O?.id,onOpen:X,onCreate:Ie,onMove:(i,D)=>{Fe(i,D)},onResize:(i,D)=>{ee(i,D)}})]})}),Be&&O&&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(oa,{item:O,bots:s.bots,onClose:()=>T(null),onEdit:vt,onOpenRun:Re,onCallChanged:i=>{i?j(D=>D.filter(R=>R.id!==i)):he()},onOpenRoom:n},`${O.kind}:${O.id}`)})]}),L&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40 bg-black/25",onMouseDown:()=>f(null)}),e.jsx(aa,{seed:L,bots:J,routinesOnly:g,onClose:()=>f(null),onMore:i=>{f(null),E(i)},onSavedRoutine:i=>o({type:"routinePatched",routine:i}),onSavedCall:$e})]}),N&&e.jsx(Pn,{seed:N,bots:J,routinesOnly:g,onClose:()=>E(null),onSavedCall:$e}),A&&e.jsx(ca,{routines:ge,bots:s.bots,groups:s.groups,onClose:()=>k(!1),onEdit:i=>{k(!1),E({kind:"routine",at:be(i),durationMinutes:i.durationMinutes,botIds:[i.botId],routine:i})},onOpenRoom:n})]})}function pa(){const t=typeof window<"u"?window.ogb?.routines:void 0,[n,s]=m.useState(null),[o,l]=m.useState(!1);if(m.useEffect(()=>{if(!t)return;let g=!1;const u=()=>t.wakeState().then(a=>{g||s(a)}).catch(()=>{});u();const r=window.setInterval(u,3e4);return()=>{g=!0,window.clearInterval(r)}},[t]),!t||!n)return null;const p=n.keepAwake?n.onBattery?"On battery, so not holding; plug in to keep it awake.":n.hold?n.reason==="running"?"Holding it awake now: a routine is running.":`Holding it awake now: a routine is due at ${n.at?se(n.at):"the top of the hour"}.`:"Holds it awake for the hour before a routine and while one runs, while plugged in. A closed lid still sleeps.":"Off — this computer may sleep through a scheduled routine.";return e.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-hairline/35 bg-panel/60 px-4 py-2.5",children:[e.jsxs("div",{className:"min-w-0 text-[12px] leading-relaxed text-ink-secondary",children:[e.jsx("span",{className:"font-medium text-ink",children:"Keep this computer awake for routines."})," ",p]}),e.jsx(is,{checked:n.keepAwake,disabled:o,"aria-label":"Keep this computer awake for scheduled routines",onClick:()=>{l(!0),t.keepAwake(!n.keepAwake).then(s).catch(()=>{}).finally(()=>l(!1))},className:"shrink-0 disabled:cursor-wait disabled:opacity-50"})]})}const ba=Object.freeze(Object.defineProperty({__proto__:null,RoutineEditor:ua,RoutinesPage:xa},Symbol.toStringTag,{value:"Module"}));export{As as B,Fs as R,ua as a,An as b,ba as c,yt as s,Es as u,ga as w};
@@ -0,0 +1 @@
1
+ import{u as x,r as u,j as e,C as p,t as s,P as m,F as h}from"./index-C3NqfdVU.js";import{R as g,a as j}from"./RoutinesPage-BM2D4qGi.js";function v({bot:t,routines:n,runs:r,defaultRunOn:c}){const{state:l,dispatch:o}=x(),[i,a]=u.useState(null);return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(p,{size:16,className:"text-accent"}),e.jsx("h2",{className:"min-w-0 flex-1 text-[15px] font-medium text-ink",children:s("computer.tab.routines")}),e.jsx("span",{className:"text-[11.5px] text-ink-secondary",children:n.length})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>a("new"),className:"flex flex-1 items-center justify-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[12px] font-medium text-white hover:brightness-110",children:[e.jsx(m,{size:14}),s("computer.routines.create")]}),e.jsxs("button",{type:"button",onClick:()=>o({type:"showRoutines",section:"logs",botId:t.id}),className:"flex items-center gap-1.5 rounded-lg bg-control px-3 py-2 text-[12px] text-ink hover:bg-raised-hover",children:[e.jsx(h,{size:13}),s("routines.logs")]})]})]}),e.jsx(g,{routines:n,runs:r,loading:l.routinesLoadState==="loading"&&n.length===0,error:l.routinesLoadState==="error",onOpen:a,onLogs:d=>o({type:"showRoutines",section:"logs",botId:t.id,routineId:d.id})}),e.jsxs("button",{type:"button",onClick:()=>o({type:"showRoutines",section:"schedule",view:"list",botId:t.id}),className:"self-start text-[12px] text-accent hover:underline",children:[s("computer.routines.openTitle")," →"]}),i&&e.jsx(j,{routine:i==="new"?void 0:i,bots:[t],lockedBotId:t.id,defaultRunOn:c,onClose:()=>a(null)},t.id)]})}export{v as R};