titan-agent 6.1.0-beta.2 → 6.1.0-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -29
- package/README.md +1 -1
- package/dist/agent/agentLessons.js +2 -2
- package/dist/agent/agentLessons.js.map +1 -1
- package/dist/agent/autoModeClassifier.js +95 -0
- package/dist/agent/autoModeClassifier.js.map +1 -0
- package/dist/agent/durableJournal.js +2 -2
- package/dist/agent/durableJournal.js.map +1 -1
- package/dist/agent/goalDriver.js +67 -0
- package/dist/agent/goalDriver.js.map +1 -1
- package/dist/agent/goalPlanFile.js +3 -3
- package/dist/agent/goalPlanFile.js.map +1 -1
- package/dist/agent/missionLifecycle.js +2 -2
- package/dist/agent/missionLifecycle.js.map +1 -1
- package/dist/agent/subAgent.js +41 -0
- package/dist/agent/subAgent.js.map +1 -1
- package/dist/agent/toolContract.js +49 -0
- package/dist/agent/toolContract.js.map +1 -0
- package/dist/agent/toolRunner.js +72 -11
- package/dist/agent/toolRunner.js.map +1 -1
- package/dist/agent/trajectoryRecorder.js +185 -0
- package/dist/agent/trajectoryRecorder.js.map +1 -0
- package/dist/agent/verification.js +164 -0
- package/dist/agent/verification.js.map +1 -0
- package/dist/agent/worktreeExecutor.js +207 -0
- package/dist/agent/worktreeExecutor.js.map +1 -0
- package/dist/config/schema.js +28 -1
- package/dist/config/schema.js.map +1 -1
- package/dist/gateway/server.js +54 -0
- package/dist/gateway/server.js.map +1 -1
- package/dist/memory/facade.js +137 -0
- package/dist/memory/facade.js.map +1 -0
- package/dist/migrations/003-soma-profile-default.js +2 -2
- package/dist/migrations/003-soma-profile-default.js.map +1 -1
- package/dist/migrations/005-route-redirects.js +3 -1
- package/dist/migrations/005-route-redirects.js.map +1 -1
- package/dist/migrations/runner.js +2 -2
- package/dist/migrations/runner.js.map +1 -1
- package/dist/providers/defaultModel.js +14 -0
- package/dist/providers/defaultModel.js.map +1 -1
- package/dist/providers/router.js +4 -0
- package/dist/providers/router.js.map +1 -1
- package/dist/providers/stub.js +185 -0
- package/dist/providers/stub.js.map +1 -0
- package/dist/skills/builtin/backup.js +1 -2
- package/dist/skills/builtin/backup.js.map +1 -1
- package/dist/skills/builtin/contracts.js +254 -0
- package/dist/skills/builtin/contracts.js.map +1 -0
- package/dist/skills/builtin/download_image.js +9 -0
- package/dist/skills/builtin/download_image.js.map +1 -1
- package/dist/skills/builtin/filesystem.js +70 -20
- package/dist/skills/builtin/filesystem.js.map +1 -1
- package/dist/skills/registry.js +7 -0
- package/dist/skills/registry.js.map +1 -1
- package/dist/storage/patterns.js +2 -2
- package/dist/storage/patterns.js.map +1 -1
- package/dist/storage/personalGallery.js +2 -2
- package/dist/storage/personalGallery.js.map +1 -1
- package/dist/storage/somaProfile.js +2 -2
- package/dist/storage/somaProfile.js.map +1 -1
- package/dist/utils/constants.js +1 -1
- package/dist/utils/constants.js.map +1 -1
- package/package.json +2 -2
- package/ui/dist/assets/{AuditPanel-DrDvXZ9u.js → AuditPanel-RNrvKmfX.js} +1 -1
- package/ui/dist/assets/{AutonomyPanel-BfhW-PRX.js → AutonomyPanel-D0nmt79R.js} +2 -2
- package/ui/dist/assets/{AutopilotPanel-C3yQBxAp.js → AutopilotPanel-DlcdfRRy.js} +1 -1
- package/ui/dist/assets/{AutoresearchPanel-BgpR3EcK.js → AutoresearchPanel-CXeO6kGK.js} +2 -2
- package/ui/dist/assets/BackupPanel-CKb-cDsk.js +1 -0
- package/ui/dist/assets/{BrowserPanel-BNaKZOnn.js → BrowserPanel-CDaoF6n5.js} +1 -1
- package/ui/dist/assets/CPActivity-BZbeztg1.js +1 -0
- package/ui/dist/assets/CPAgentDetail-C9fvLxKi.js +1 -0
- package/ui/dist/assets/CPAgents-BsBA9kb2.js +1 -0
- package/ui/dist/assets/CPApprovals-Di5itVIK.js +1 -0
- package/ui/dist/assets/CPCosts-DmgckHli.js +1 -0
- package/ui/dist/assets/CPDashboard-CmSb7woK.js +1 -0
- package/ui/dist/assets/{CPFiles-CUpP5I82.js → CPFiles-Dd0NGcpX.js} +1 -1
- package/ui/dist/assets/CPGoals-DeILFq0A.js +1 -0
- package/ui/dist/assets/{CPInbox-DUW_hntB.js → CPInbox-DAtidZez.js} +2 -2
- package/ui/dist/assets/CPIssueDetail-BvwoGI57.js +1 -0
- package/ui/dist/assets/CPIssues-CZ1hIKDP.js +1 -0
- package/ui/dist/assets/{CPLayout-J0fa-it4.js → CPLayout-luPwhNpA.js} +3 -3
- package/ui/dist/assets/CPOrg-BlYp_KP6.js +8 -0
- package/ui/dist/assets/CPRuns-D0HMCjIo.js +1 -0
- package/ui/dist/assets/{CPSocial-By_FStZ4.js → CPSocial-CZaGi14s.js} +2 -2
- package/ui/dist/assets/ChannelsPanel-khiBHwx3.js +1 -0
- package/ui/dist/assets/{CheckpointsPanel-DvKUd2VF.js → CheckpointsPanel-n2y3jzzT.js} +1 -1
- package/ui/dist/assets/{CommandPostHub-CQqRYBjf.js → CommandPostHub-iWf-zt5p.js} +4 -4
- package/ui/dist/assets/{CronPanel-Brmnnu8_.js → CronPanel-BkRJl8u6.js} +1 -1
- package/ui/dist/assets/{DataTable-seaktPzB.js → DataTable-DZ2cG3Cv.js} +1 -1
- package/ui/dist/assets/{DreamPanel-CO7iSdjn.js → DreamPanel-DF6l0WB-.js} +1 -1
- package/ui/dist/assets/{EmptyState-CmK9fywh.js → EmptyState-D7xwm8hA.js} +1 -1
- package/ui/dist/assets/{EvalHarnessPanel-2RVBKbym.js → EvalHarnessPanel-BHabu49z.js} +2 -2
- package/ui/dist/assets/{EvalPanel-CqAwhFQ5.js → EvalPanel-yAesMLSP.js} +1 -1
- package/ui/dist/assets/{FileViewer-D98m-vF5.js → FileViewer-DOWUQccc.js} +52 -14
- package/ui/dist/assets/{FilesPanel-dRQM0apb.js → FilesPanel-BjuDhqaX.js} +2 -2
- package/ui/dist/assets/FleetPanel-B0ZhS2XX.js +1 -0
- package/ui/dist/assets/{HomelabPanel-DjMUrO2B.js → HomelabPanel-D373ddvj.js} +1 -1
- package/ui/dist/assets/InfraView-CI99NZbI.js +2 -0
- package/ui/dist/assets/InlineEditableField-fDk3eGVo.js +1 -0
- package/ui/dist/assets/Input-j10hONMY.js +1 -0
- package/ui/dist/assets/IntegrationsPanel-kPa5Qq-f.js +1 -0
- package/ui/dist/assets/IntelligenceView-DeKBaAlY.js +2 -0
- package/ui/dist/assets/LearningPanel-B8tqHeEZ.js +1 -0
- package/ui/dist/assets/{LogsPanel-Bs9IsTCH.js → LogsPanel-sXc__trb.js} +1 -1
- package/ui/dist/assets/McpPanel-DEr8pZwB.js +1 -0
- package/ui/dist/assets/{MemoryGraphPanel-F1P9COyY.js → MemoryGraphPanel-DZl7USJ6.js} +1 -1
- package/ui/dist/assets/MemoryWikiPanel-DTNVWvVT.js +11 -0
- package/ui/dist/assets/{MeshPanel-CgIAh5ZX.js → MeshPanel-b77zyQx4.js} +1 -1
- package/ui/dist/assets/MissionCanvas-D_quSl5F.js +69 -0
- package/ui/dist/assets/MissionChat-rQ5rUPAt.js +7 -0
- package/ui/dist/assets/MissionLibrary-Cxw7sLxv.js +5 -0
- package/ui/dist/assets/MissionStart-ChMWO1rr.js +1 -0
- package/ui/dist/assets/Modal-Dl5b6Yaj.js +1 -0
- package/ui/dist/assets/NvidiaPanel-D7qFbbeJ.js +1 -0
- package/ui/dist/assets/{OrganismPanel-CNZM3eof.js → OrganismPanel-EiQ9Gfqx.js} +1 -1
- package/ui/dist/assets/OverviewPanel-Bectj1Z5.js +1 -0
- package/ui/dist/assets/{PageHeader-llOXO43Z.js → PageHeader-CiuoyvDR.js} +1 -1
- package/ui/dist/assets/{PersonaProfilesPanel-CfsQTMra.js → PersonaProfilesPanel-BO87DSVG.js} +1 -1
- package/ui/dist/assets/{PersonasPanel-DIac_kZ3.js → PersonasPanel-BNogLwM0.js} +1 -1
- package/ui/dist/assets/RecipesPanel-DyqfWlaY.js +1 -0
- package/ui/dist/assets/{SecurityPanel-_gqMk8hJ.js → SecurityPanel-OMC-Tvbz.js} +1 -1
- package/ui/dist/assets/SelfImprovePanel-DXIfG_df.js +1 -0
- package/ui/dist/assets/{SelfProposalsPanel-DuA0zsGH.js → SelfProposalsPanel-CmgEz1TQ.js} +2 -2
- package/ui/dist/assets/SessionsPanel-gJXosEGf.js +1 -0
- package/ui/dist/assets/{SessionsTab-bFYaFvTZ.js → SessionsTab-BOVzzjTO.js} +1 -1
- package/ui/dist/assets/SettingsPanel-DifFGEvi.js +1 -0
- package/ui/dist/assets/SettingsView-BNpj0iym.js +2 -0
- package/ui/dist/assets/SkeletonLoader-CNSsfH3f.js +1 -0
- package/ui/dist/assets/{SkillsPanel-D08WcRGp.js → SkillsPanel-6fbRov-m.js} +1 -1
- package/ui/dist/assets/{SomaView-CYukE7Fp.js → SomaView-D3boPl5D.js} +1 -1
- package/ui/dist/assets/{StatCard-DT4Bx1mY.js → StatCard-2BmOlamJ.js} +1 -1
- package/ui/dist/assets/StatusBadge-CdVHF1nG.js +1 -0
- package/ui/dist/assets/Tabs-DW9ytf9H.js +1 -0
- package/ui/dist/assets/{TeamsPanel-DOBe72TK.js → TeamsPanel-CNaQ8Dbw.js} +1 -1
- package/ui/dist/assets/TelemetryPanel-DL81QlAW.js +1 -0
- package/ui/dist/assets/TitanCanvas-DLIN_wV3.js +1152 -0
- package/ui/dist/assets/ToolsView-BlChEE4n.js +2 -0
- package/ui/dist/assets/Tooltip-oR5JnwoN.js +6 -0
- package/ui/dist/assets/{TraceViewer-0bCz0x_a.js → TraceViewer-DtJXjCXV.js} +1 -1
- package/ui/dist/assets/TrainingPanel-4XMGaRN_.js +1 -0
- package/ui/dist/assets/{VoiceOverlay-B08Sw918.js → VoiceOverlay-B3fXJ-EC.js} +1 -1
- package/ui/dist/assets/{VramPanel-CJiic8y4.js → VramPanel-HisAYiqI.js} +1 -1
- package/ui/dist/assets/{WatchView-CaQMDEAy.js → WatchView-C92y0hU7.js} +1 -1
- package/ui/dist/assets/{WorkTab-D5bi2WRi.js → WorkTab-BYAWcvA1.js} +1 -1
- package/ui/dist/assets/{WorkflowsPanel-DdY6E93C.js → WorkflowsPanel-D2DiOBLA.js} +1 -1
- package/ui/dist/assets/{arrow-left-CHJyrO8S.js → arrow-left-thXQMJQ6.js} +1 -1
- package/ui/dist/assets/{briefcase-ROIEmiah.js → briefcase-ByMhDqlL.js} +1 -1
- package/ui/dist/assets/{chart-column-wFkjV3Ni.js → chart-column-CYHJVuxN.js} +1 -1
- package/ui/dist/assets/{check-BcOm5jPO.js → check-ChWLFWCx.js} +1 -1
- package/ui/dist/assets/{chevron-down-CM11GPpR.js → chevron-down-CU_O_5h3.js} +1 -1
- package/ui/dist/assets/{chevron-right-aFDDgFsL.js → chevron-right-DAiXsK24.js} +1 -1
- package/ui/dist/assets/{chevron-up-D6g7FB6i.js → chevron-up-BudRYwvy.js} +1 -1
- package/ui/dist/assets/{circle-check-big-DPz64kZW.js → circle-check-big-gkA-V2JW.js} +1 -1
- package/ui/dist/assets/{clock-BbCCaukN.js → clock-qO5kIED9.js} +1 -1
- package/ui/dist/assets/clsx-B-dksMZM.js +1 -0
- package/ui/dist/assets/{dollar-sign-Dy5-qkg3.js → dollar-sign-1gQNJK3V.js} +1 -1
- package/ui/dist/assets/{download-DjheLEns.js → download-DMD1m87c.js} +1 -1
- package/ui/dist/assets/{external-link-BgxGF7ZQ.js → external-link-ByafQkZ7.js} +1 -1
- package/ui/dist/assets/{folder-DY4eeMdo.js → folder-DeG4RuOD.js} +1 -1
- package/ui/dist/assets/{funnel-LWmcwhj-.js → funnel-wE8i5V9Y.js} +1 -1
- package/ui/dist/assets/{git-branch-CPZciK10.js → git-branch-BWSuK1LU.js} +1 -1
- package/ui/dist/assets/index-B8YEFBRH.js +277 -0
- package/ui/dist/assets/index-Cb5bSxRB.css +1 -0
- package/ui/dist/assets/{layers-Bn7bgu2Z.js → layers-tN-wIpE0.js} +1 -1
- package/ui/dist/assets/{legacy-BVPeht6t.js → legacy-BSZBdyop.js} +2 -2
- package/ui/dist/assets/{lightbulb-tzuCyEQk.js → lightbulb-TUHKCda3.js} +1 -1
- package/ui/dist/assets/{list-todo-say4NbSw.js → list-todo-DtxcUGz2.js} +1 -1
- package/ui/dist/assets/{missions-DbC8UmMc.js → missions-C3EC4uKT.js} +1 -1
- package/ui/dist/assets/{network-v9O7MmZT.js → network-ephW7nah.js} +1 -1
- package/ui/dist/assets/{pause-CZo33QlA.js → pause-DeggUVZc.js} +1 -1
- package/ui/dist/assets/{play-DbCJhc5H.js → play-Dfc0ia6v.js} +1 -1
- package/ui/dist/assets/{plug-CtpCZg2z.js → plug-Bl_6i_9u.js} +1 -1
- package/ui/dist/assets/{plus-O61rB_YF.js → plus-CQwCh7WY.js} +1 -1
- package/ui/dist/assets/{proxy-BAUTNyg6.js → proxy-BjQ4lsww.js} +1 -1
- package/ui/dist/assets/{rotate-ccw-n5WkWR51.js → rotate-ccw-CUuN2ebi.js} +1 -1
- package/ui/dist/assets/{save-D2Qh8KyN.js → save-PlTUvsN5.js} +1 -1
- package/ui/dist/assets/{search-C9SdcZJq.js → search-BHgLDT-j.js} +1 -1
- package/ui/dist/assets/{send-DZ_5M5QQ.js → send-pflQNBoT.js} +1 -1
- package/ui/dist/assets/{shield-check-DyP5PmaY.js → shield-check-CrD-s89i.js} +1 -1
- package/ui/dist/assets/{target-CWfn705s.js → target-D4oh8GME.js} +1 -1
- package/ui/dist/assets/{terminal-CdhfA0Kr.js → terminal-BvJZ1R3x.js} +1 -1
- package/ui/dist/assets/{toggle-right-CmYQLQRS.js → toggle-right-Dl7x_ed7.js} +1 -1
- package/ui/dist/assets/{trash-2-TQcEJEv4.js → trash-2-lPcFwnW5.js} +1 -1
- package/ui/dist/assets/{trending-up-Cw22bM4J.js → trending-up-DqUbZfDe.js} +1 -1
- package/ui/dist/assets/{trophy-DUF8Bcas.js → trophy-Dv6zFfKM.js} +1 -1
- package/ui/dist/assets/{users-BX_ZaByZ.js → users-NPyAWbs5.js} +1 -1
- package/ui/dist/assets/{wrench-Cfp7nYhG.js → wrench-BCKgeHj3.js} +1 -1
- package/ui/dist/index.html +2 -2
- package/ui/dist/sw.js +1 -1
- package/ui/dist/assets/BackupPanel-BNxMlNIP.js +0 -1
- package/ui/dist/assets/CPActivity-CjIgehOq.js +0 -1
- package/ui/dist/assets/CPAgentDetail-oaymYRNI.js +0 -1
- package/ui/dist/assets/CPAgents-CWQ6iJfO.js +0 -1
- package/ui/dist/assets/CPApprovals-DzATBhtM.js +0 -1
- package/ui/dist/assets/CPCosts-xVQR148_.js +0 -1
- package/ui/dist/assets/CPDashboard-Dt6Jr7Zw.js +0 -1
- package/ui/dist/assets/CPGoals-Bt1a3C9T.js +0 -1
- package/ui/dist/assets/CPIssueDetail-DHxqtiuh.js +0 -1
- package/ui/dist/assets/CPIssues-D0l3fgUs.js +0 -1
- package/ui/dist/assets/CPOrg-DQ3tbYld.js +0 -8
- package/ui/dist/assets/CPRuns-0vncicUW.js +0 -1
- package/ui/dist/assets/ChannelsPanel-CiJs4gyw.js +0 -1
- package/ui/dist/assets/FleetPanel-Bg-f3_ip.js +0 -1
- package/ui/dist/assets/InfraView-CHYaZqMK.js +0 -2
- package/ui/dist/assets/InlineEditableField-BOLRKQq1.js +0 -1
- package/ui/dist/assets/Input-4pNffAw-.js +0 -1
- package/ui/dist/assets/IntegrationsPanel-CFucvr-Q.js +0 -1
- package/ui/dist/assets/IntelligenceView-Dh-Wuf13.js +0 -2
- package/ui/dist/assets/LearningPanel-CtlougkF.js +0 -1
- package/ui/dist/assets/McpPanel-BobqpLsh.js +0 -1
- package/ui/dist/assets/MemoryWikiPanel-BfYksjoI.js +0 -11
- package/ui/dist/assets/MissionCanvas-0V_vtqiu.js +0 -50
- package/ui/dist/assets/MissionChat-9hGhc9Zw.js +0 -7
- package/ui/dist/assets/MissionLibrary-dFkT8pGp.js +0 -5
- package/ui/dist/assets/MissionStart-CZSEie0Q.js +0 -1
- package/ui/dist/assets/Modal-V2yNnkKk.js +0 -1
- package/ui/dist/assets/NvidiaPanel-qLJysI9M.js +0 -1
- package/ui/dist/assets/OverviewPanel-Be6LukJ_.js +0 -1
- package/ui/dist/assets/RecipesPanel-DDYOCx3w.js +0 -1
- package/ui/dist/assets/SelfImprovePanel-B8o_fO30.js +0 -1
- package/ui/dist/assets/SessionsPanel-DeCBkSgY.js +0 -1
- package/ui/dist/assets/SettingsPanel-BlsRDAt7.js +0 -1
- package/ui/dist/assets/SettingsView-Dsa7Zr4e.js +0 -2
- package/ui/dist/assets/SkeletonLoader-BkQoZllJ.js +0 -1
- package/ui/dist/assets/StatusBadge-BFEHCdgi.js +0 -1
- package/ui/dist/assets/Tabs-g2Gs9sK0.js +0 -1
- package/ui/dist/assets/TelemetryPanel-DXAGuV0R.js +0 -1
- package/ui/dist/assets/TitanCanvas-DCl3gxSl.js +0 -1072
- package/ui/dist/assets/ToolsView-CnUjq0Js.js +0 -2
- package/ui/dist/assets/Tooltip-DJ99YlFF.js +0 -6
- package/ui/dist/assets/TrainingPanel-BLf_KMaE.js +0 -1
- package/ui/dist/assets/eye-off-CYR4nH5I.js +0 -6
- package/ui/dist/assets/index-PwwKjgT3.css +0 -1
- package/ui/dist/assets/index-slWylU2o.js +0 -244
- package/ui/dist/assets/loader-circle-E8aLxmMz.js +0 -6
|
@@ -0,0 +1,1152 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SomaView-D3boPl5D.js","assets/index-B8YEFBRH.js","assets/index-Cb5bSxRB.css","assets/Input-j10hONMY.js","assets/clsx-B-dksMZM.js","assets/Tooltip-oR5JnwoN.js","assets/SomaView-BtCkeWfZ.css","assets/CommandPostHub-iWf-zt5p.js","assets/Modal-Dl5b6Yaj.js","assets/proxy-BjQ4lsww.js","assets/InlineEditableField-fDk3eGVo.js","assets/check-ChWLFWCx.js","assets/terminal-BvJZ1R3x.js","assets/approvalHeadline-DB9SgR-9.js","assets/chevron-right-DAiXsK24.js","assets/wrench-BCKgeHj3.js","assets/pause-DeggUVZc.js","assets/dollar-sign-1gQNJK3V.js","assets/git-branch-BWSuK1LU.js","assets/chart-column-CYHJVuxN.js","assets/clock-qO5kIED9.js","assets/users-NPyAWbs5.js","assets/target-D4oh8GME.js","assets/briefcase-ByMhDqlL.js","assets/send-pflQNBoT.js","assets/plus-CQwCh7WY.js","assets/trash-2-lPcFwnW5.js","assets/IntelligenceView-DeKBaAlY.js","assets/MemoryGraphPanel-DZl7USJ6.js","assets/network-ephW7nah.js","assets/search-BHgLDT-j.js","assets/InfraView-CI99NZbI.js","assets/ToolsView-BlChEE4n.js","assets/SettingsView-BNpj0iym.js","assets/SettingsPanel-DifFGEvi.js","assets/PageHeader-CiuoyvDR.js","assets/circle-check-big-gkA-V2JW.js","assets/VoiceOverlay-B3fXJ-EC.js","assets/chevron-down-CU_O_5h3.js","assets/download-DMD1m87c.js","assets/play-Dfc0ia6v.js","assets/save-PlTUvsN5.js","assets/chevron-up-BudRYwvy.js","assets/rotate-ccw-CUuN2ebi.js","assets/folder-DeG4RuOD.js","assets/shield-check-CrD-s89i.js","assets/external-link-ByafQkZ7.js","assets/SecurityPanel-OMC-Tvbz.js","assets/AuditPanel-RNrvKmfX.js","assets/funnel-wE8i5V9Y.js","assets/AutopilotPanel-DlcdfRRy.js","assets/WorkflowsPanel-D2DiOBLA.js","assets/toggle-right-Dl7x_ed7.js","assets/LearningPanel-B8tqHeEZ.js","assets/lightbulb-TUHKCda3.js","assets/trending-up-DqUbZfDe.js","assets/SelfImprovePanel-DXIfG_df.js","assets/trophy-Dv6zFfKM.js","assets/PersonasPanel-BNogLwM0.js","assets/PersonaProfilesPanel-BO87DSVG.js","assets/DreamPanel-DF6l0WB-.js","assets/HomelabPanel-D373ddvj.js","assets/StatCard-2BmOlamJ.js","assets/SkeletonLoader-CNSsfH3f.js","assets/NvidiaPanel-D7qFbbeJ.js","assets/FilesPanel-BjuDhqaX.js","assets/arrow-left-thXQMJQ6.js","assets/LogsPanel-sXc__trb.js","assets/TelemetryPanel-DL81QlAW.js","assets/SkillsPanel-6fbRov-m.js","assets/McpPanel-DEr8pZwB.js","assets/plug-Bl_6i_9u.js","assets/IntegrationsPanel-kPa5Qq-f.js","assets/ChannelsPanel-khiBHwx3.js","assets/MeshPanel-b77zyQx4.js","assets/DataTable-DZ2cG3Cv.js","assets/MemoryWikiPanel-DTNVWvVT.js","assets/AutoresearchPanel-CXeO6kGK.js","assets/SelfProposalsPanel-CmgEz1TQ.js","assets/OverviewPanel-Bectj1Z5.js","assets/layers-tN-wIpE0.js","assets/SessionsPanel-gJXosEGf.js","assets/WatchView-C92y0hU7.js","assets/BackupPanel-CKb-cDsk.js","assets/TrainingPanel-4XMGaRN_.js","assets/RecipesPanel-DyqfWlaY.js","assets/VramPanel-HisAYiqI.js","assets/TeamsPanel-CNaQ8Dbw.js","assets/CronPanel-BkRJl8u6.js","assets/CheckpointsPanel-n2y3jzzT.js","assets/OrganismPanel-EiQ9Gfqx.js","assets/FleetPanel-B0ZhS2XX.js","assets/BrowserPanel-CDaoF6n5.js","assets/EvalPanel-yAesMLSP.js","assets/legacy-BSZBdyop.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
var gl=Object.defineProperty;var yl=(t,e,s)=>e in t?gl(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var Fe=(t,e,s)=>yl(t,typeof e!="symbol"?e+"":e,s);import{c as Ie,a as Ze,g as bl,r as w,b as ye,j as n,s as xl,u as Ki,d as wl,e as vl,X as ks,S as wr,A as gt,E as Ji,C as vr,f as _r,G as Xi,R as oe,_ as le,Z as _l,h as un,I as ii,i as kl,k as Sl,L as Qi,W as jl,M as El,H as Nl,l as Cl,t as Ln}from"./index-B8YEFBRH.js";import{C as Tl}from"./chevron-up-BudRYwvy.js";import{P as Rl}from"./plus-CQwCh7WY.js";import{F as hn,M as Zi,U as kr}from"./users-NPyAWbs5.js";import{W as Sr,B as eo}from"./wrench-BCKgeHj3.js";import{N as to}from"./network-ephW7nah.js";import{T as so,P as Al,R as fn}from"./terminal-BvJZ1R3x.js";import{S as pn}from"./save-PlTUvsN5.js";import{R as no}from"./rotate-ccw-CUuN2ebi.js";import{S as ro}from"./search-BHgLDT-j.js";import{S as io}from"./send-pflQNBoT.js";import{M as oo,V as Ll}from"./VoiceOverlay-B3fXJ-EC.js";import{F as ao,a as Il}from"./folder-DeG4RuOD.js";import{C as us}from"./clock-qO5kIED9.js";import{C as Dl}from"./chevron-right-DAiXsK24.js";import{C as oi}from"./check-ChWLFWCx.js";import{S as Ml}from"./shield-check-CrD-s89i.js";import{E as ai}from"./external-link-ByafQkZ7.js";/**
|
|
3
|
+
* @license lucide-react v0.513.0 - ISC
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the ISC license.
|
|
6
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/const Ol=[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]],lo=Ie("archive",Ol);/**
|
|
8
|
+
* @license lucide-react v0.513.0 - ISC
|
|
9
|
+
*
|
|
10
|
+
* This source code is licensed under the ISC license.
|
|
11
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
12
|
+
*/const Wl=[["path",{d:"M12 7v14",key:"1akyts"}],["path",{d:"M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z",key:"ruj8y"}]],hs=Ie("book-open",Wl);/**
|
|
13
|
+
* @license lucide-react v0.513.0 - ISC
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the ISC license.
|
|
16
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
17
|
+
*/const Pl=[["path",{d:"M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z",key:"l5xja"}],["path",{d:"M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z",key:"ep3f8r"}],["path",{d:"M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4",key:"1p4c4q"}],["path",{d:"M17.599 6.5a3 3 0 0 0 .399-1.375",key:"tmeiqw"}],["path",{d:"M6.003 5.125A3 3 0 0 0 6.401 6.5",key:"105sqy"}],["path",{d:"M3.477 10.896a4 4 0 0 1 .585-.396",key:"ql3yin"}],["path",{d:"M19.938 10.5a4 4 0 0 1 .585.396",key:"1qfode"}],["path",{d:"M6 18a4 4 0 0 1-1.967-.516",key:"2e4loj"}],["path",{d:"M19.967 17.484A4 4 0 0 1 18 18",key:"159ez6"}]],yt=Ie("brain",Pl);/**
|
|
18
|
+
* @license lucide-react v0.513.0 - ISC
|
|
19
|
+
*
|
|
20
|
+
* This source code is licensed under the ISC license.
|
|
21
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
22
|
+
*/const Bl=[["path",{d:"m16.24 7.76-1.804 5.411a2 2 0 0 1-1.265 1.265L7.76 16.24l1.804-5.411a2 2 0 0 1 1.265-1.265z",key:"9ktpf1"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],Ul=Ie("compass",Bl);/**
|
|
23
|
+
* @license lucide-react v0.513.0 - ISC
|
|
24
|
+
*
|
|
25
|
+
* This source code is licensed under the ISC license.
|
|
26
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
27
|
+
*/const Fl=[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]],$l=Ie("database",Fl);/**
|
|
28
|
+
* @license lucide-react v0.513.0 - ISC
|
|
29
|
+
*
|
|
30
|
+
* This source code is licensed under the ISC license.
|
|
31
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
32
|
+
*/const zl=[["path",{d:"m12 14 4-4",key:"9kzdfg"}],["path",{d:"M3.34 19a10 10 0 1 1 17.32 0",key:"19p75a"}]],Hl=Ie("gauge",zl);/**
|
|
33
|
+
* @license lucide-react v0.513.0 - ISC
|
|
34
|
+
*
|
|
35
|
+
* This source code is licensed under the ISC license.
|
|
36
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
37
|
+
*/const Vl=[["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M13 6h3a2 2 0 0 1 2 2v7",key:"1yeb86"}],["line",{x1:"6",x2:"6",y1:"9",y2:"21",key:"rroup"}]],co=Ie("git-pull-request",Vl);/**
|
|
38
|
+
* @license lucide-react v0.513.0 - ISC
|
|
39
|
+
*
|
|
40
|
+
* This source code is licensed under the ISC license.
|
|
41
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
42
|
+
*/const Gl=[["path",{d:"M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z",key:"yt0hxn"}]],ql=Ie("hexagon",Gl);/**
|
|
43
|
+
* @license lucide-react v0.513.0 - ISC
|
|
44
|
+
*
|
|
45
|
+
* This source code is licensed under the ISC license.
|
|
46
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
47
|
+
*/const Yl=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]],Kl=Ie("history",Yl);/**
|
|
48
|
+
* @license lucide-react v0.513.0 - ISC
|
|
49
|
+
*
|
|
50
|
+
* This source code is licensed under the ISC license.
|
|
51
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
52
|
+
*/const Jl=[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"1d0kgt"}]],Xl=Ie("house",Jl);/**
|
|
53
|
+
* @license lucide-react v0.513.0 - ISC
|
|
54
|
+
*
|
|
55
|
+
* This source code is licensed under the ISC license.
|
|
56
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
57
|
+
*/const Ql=[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}]],uo=Ie("layout-grid",Ql);/**
|
|
58
|
+
* @license lucide-react v0.513.0 - ISC
|
|
59
|
+
*
|
|
60
|
+
* This source code is licensed under the ISC license.
|
|
61
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
62
|
+
*/const Zl=[["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551",key:"1miecu"}]],ho=Ie("paperclip",Zl);/**
|
|
63
|
+
* @license lucide-react v0.513.0 - ISC
|
|
64
|
+
*
|
|
65
|
+
* This source code is licensed under the ISC license.
|
|
66
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
67
|
+
*/const ec=[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]],li=Ie("power",ec);/**
|
|
68
|
+
* @license lucide-react v0.513.0 - ISC
|
|
69
|
+
*
|
|
70
|
+
* This source code is licensed under the ISC license.
|
|
71
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
72
|
+
*/const tc=[["path",{d:"M4.9 19.1C1 15.2 1 8.8 4.9 4.9",key:"1vaf9d"}],["path",{d:"M7.8 16.2c-2.3-2.3-2.3-6.1 0-8.5",key:"u1ii0m"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}],["path",{d:"M16.2 7.8c2.3 2.3 2.3 6.1 0 8.5",key:"1j5fej"}],["path",{d:"M19.1 4.9C23 8.8 23 15.1 19.1 19",key:"10b0cb"}]],fo=Ie("radio",tc);/**
|
|
73
|
+
* @license lucide-react v0.513.0 - ISC
|
|
74
|
+
*
|
|
75
|
+
* This source code is licensed under the ISC license.
|
|
76
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
77
|
+
*/const sc=[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]],jr=Ie("server",sc);/**
|
|
78
|
+
* @license lucide-react v0.513.0 - ISC
|
|
79
|
+
*
|
|
80
|
+
* This source code is licensed under the ISC license.
|
|
81
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
82
|
+
*/const nc=[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],Er=Ie("settings",nc);/**
|
|
83
|
+
* @license lucide-react v0.513.0 - ISC
|
|
84
|
+
*
|
|
85
|
+
* This source code is licensed under the ISC license.
|
|
86
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
87
|
+
*/const rc=[["path",{d:"M14.5 2v17.5c0 1.4-1.1 2.5-2.5 2.5c-1.4 0-2.5-1.1-2.5-2.5V2",key:"125lnx"}],["path",{d:"M8.5 2h7",key:"csnxdl"}],["path",{d:"M14.5 16h-5",key:"1ox875"}]],po=Ie("test-tube",rc);/**
|
|
88
|
+
* @license lucide-react v0.513.0 - ISC
|
|
89
|
+
*
|
|
90
|
+
* This source code is licensed under the ISC license.
|
|
91
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
92
|
+
*/const ic=[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}],["path",{d:"M5 12.859a10 10 0 0 1 5.17-2.69",key:"1dl1wf"}],["path",{d:"M19 12.859a10 10 0 0 0-2.007-1.523",key:"4k23kn"}],["path",{d:"M2 8.82a15 15 0 0 1 4.177-2.643",key:"1grhjp"}],["path",{d:"M22 8.82a15 15 0 0 0-11.288-3.764",key:"z3jwby"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],oc=Ie("wifi-off",ic),Ue=()=>new Map,tr=t=>{const e=Ue();return t.forEach((s,r)=>{e.set(r,s)}),e},He=(t,e,s)=>{let r=t.get(e);return r===void 0&&t.set(e,r=s()),r},ac=(t,e)=>{const s=[];for(const[r,i]of t)s.push(e(i,r));return s},lc=(t,e)=>{for(const[s,r]of t)if(e(r,s))return!0;return!1},bt=()=>new Set,In=t=>t[t.length-1],cc=(t,e)=>{for(let s=0;s<e.length;s++)t.push(e[s])},lt=Array.from,Nr=(t,e)=>{for(let s=0;s<t.length;s++)if(!e(t[s],s,t))return!1;return!0},mo=(t,e)=>{for(let s=0;s<t.length;s++)if(e(t[s],s,t))return!0;return!1},dc=(t,e)=>{const s=new Array(t);for(let r=0;r<t;r++)s[r]=e(r,s);return s},mn=Array.isArray;class go{constructor(){this._observers=Ue()}on(e,s){return He(this._observers,e,bt).add(s),s}once(e,s){const r=(...i)=>{this.off(e,r),s(...i)};this.on(e,r)}off(e,s){const r=this._observers.get(e);r!==void 0&&(r.delete(s),r.size===0&&this._observers.delete(e))}emit(e,s){return lt((this._observers.get(e)||Ue()).values()).forEach(r=>r(...s))}destroy(){this._observers=Ue()}}class Cr{constructor(){this._observers=Ue()}on(e,s){He(this._observers,e,bt).add(s)}once(e,s){const r=(...i)=>{this.off(e,r),s(...i)};this.on(e,r)}off(e,s){const r=this._observers.get(e);r!==void 0&&(r.delete(s),r.size===0&&this._observers.delete(e))}emit(e,s){return lt((this._observers.get(e)||Ue()).values()).forEach(r=>r(...s))}destroy(){this._observers=Ue()}}const Je=Math.floor,Us=Math.abs,uc=Math.log10,Tr=(t,e)=>t<e?t:e,Lt=(t,e)=>t>e?t:e,yo=t=>t!==0?t<0:1/t<0,ci=1,di=2,Dn=4,Mn=8,fs=32,ot=64,ze=128,gn=31,sr=63,St=127,hc=2147483647,Vs=Number.MAX_SAFE_INTEGER,ui=Number.MIN_SAFE_INTEGER,fc=Number.isInteger||(t=>typeof t=="number"&&isFinite(t)&&Je(t)===t),bo=String.fromCharCode,pc=t=>t.toLowerCase(),mc=/^\s*/g,gc=t=>t.replace(mc,""),yc=/([A-Z])/g,hi=(t,e)=>gc(t.replace(yc,s=>`${e}${pc(s)}`)),bc=t=>{const e=unescape(encodeURIComponent(t)),s=e.length,r=new Uint8Array(s);for(let i=0;i<s;i++)r[i]=e.codePointAt(i);return r},ps=typeof TextEncoder<"u"?new TextEncoder:null,xc=t=>ps.encode(t),nr=ps?xc:bc;let ls=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});ls&&ls.decode(new Uint8Array).length===1&&(ls=null);const wc=(t,e)=>dc(e,()=>t).join("");class Ss{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Ae=()=>new Ss,vc=t=>{let e=t.cpos;for(let s=0;s<t.bufs.length;s++)e+=t.bufs[s].length;return e},Se=t=>{const e=new Uint8Array(vc(t));let s=0;for(let r=0;r<t.bufs.length;r++){const i=t.bufs[r];e.set(i,s),s+=i.length}return e.set(new Uint8Array(t.cbuf.buffer,0,t.cpos),s),e},_c=(t,e)=>{const s=t.cbuf.length;s-t.cpos<e&&(t.bufs.push(new Uint8Array(t.cbuf.buffer,0,t.cpos)),t.cbuf=new Uint8Array(Lt(s,e)*2),t.cpos=0)},Te=(t,e)=>{const s=t.cbuf.length;t.cpos===s&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(s*2),t.cpos=0),t.cbuf[t.cpos++]=e},ms=Te,ie=(t,e)=>{for(;e>St;)Te(t,ze|St&e),e=Je(e/128);Te(t,St&e)},Rr=(t,e)=>{const s=yo(e);for(s&&(e=-e),Te(t,(e>sr?ze:0)|(s?ot:0)|sr&e),e=Je(e/64);e>0;)Te(t,(e>St?ze:0)|St&e),e=Je(e/128)},rr=new Uint8Array(3e4),kc=rr.length/3,Sc=(t,e)=>{if(e.length<kc){const s=ps.encodeInto(e,rr).written||0;ie(t,s);for(let r=0;r<s;r++)Te(t,rr[r])}else je(t,nr(e))},jc=(t,e)=>{const s=unescape(encodeURIComponent(e)),r=s.length;ie(t,r);for(let i=0;i<r;i++)Te(t,s.codePointAt(i))},tt=ps&&ps.encodeInto?Sc:jc,yn=(t,e)=>{const s=t.cbuf.length,r=t.cpos,i=Tr(s-r,e.length),o=e.length-i;t.cbuf.set(e.subarray(0,i),r),t.cpos+=i,o>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(Lt(s*2,o)),t.cbuf.set(e.subarray(i)),t.cpos=o)},je=(t,e)=>{ie(t,e.byteLength),yn(t,e)},Ar=(t,e)=>{_c(t,e);const s=new DataView(t.cbuf.buffer,t.cpos,e);return t.cpos+=e,s},Ec=(t,e)=>Ar(t,4).setFloat32(0,e,!1),Nc=(t,e)=>Ar(t,8).setFloat64(0,e,!1),Cc=(t,e)=>Ar(t,8).setBigInt64(0,e,!1),fi=new DataView(new ArrayBuffer(4)),Tc=t=>(fi.setFloat32(0,t),fi.getFloat32(0)===t),Vt=(t,e)=>{switch(typeof e){case"string":Te(t,119),tt(t,e);break;case"number":fc(e)&&Us(e)<=hc?(Te(t,125),Rr(t,e)):Tc(e)?(Te(t,124),Ec(t,e)):(Te(t,123),Nc(t,e));break;case"bigint":Te(t,122),Cc(t,e);break;case"object":if(e===null)Te(t,126);else if(mn(e)){Te(t,117),ie(t,e.length);for(let s=0;s<e.length;s++)Vt(t,e[s])}else if(e instanceof Uint8Array)Te(t,116),je(t,e);else{Te(t,118);const s=Object.keys(e);ie(t,s.length);for(let r=0;r<s.length;r++){const i=s[r];tt(t,i),Vt(t,e[i])}}break;case"boolean":Te(t,e?120:121);break;default:Te(t,127)}};class pi extends Ss{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&ie(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}}const mi=t=>{t.count>0&&(Rr(t.encoder,t.count===1?t.s:-t.s),t.count>1&&ie(t.encoder,t.count-2))};class Fs{constructor(){this.encoder=new Ss,this.s=0,this.count=0}write(e){this.s===e?this.count++:(mi(this),this.count=1,this.s=e)}toUint8Array(){return mi(this),Se(this.encoder)}}const gi=t=>{if(t.count>0){const e=t.diff*2+(t.count===1?0:1);Rr(t.encoder,e),t.count>1&&ie(t.encoder,t.count-2)}};class On{constructor(){this.encoder=new Ss,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(gi(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return gi(this),Se(this.encoder)}}class Rc{constructor(){this.sarr=[],this.s="",this.lensE=new Fs}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){const e=new Ss;return this.sarr.push(this.s),this.s="",tt(e,this.sarr.join("")),yn(e,this.lensE.toUint8Array()),Se(e)}}const Ve=t=>new Error(t),Qe=()=>{throw Ve("Method unimplemented")},Xe=()=>{throw Ve("Unexpected case")},xo=Ve("Unexpected end of array"),wo=Ve("Integer out of Range");class bn{constructor(e){this.arr=e,this.pos=0}}const rt=t=>new bn(t),Ac=t=>t.pos!==t.arr.length,Lc=(t,e)=>{const s=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,s},Re=t=>Lc(t,de(t)),Et=t=>t.arr[t.pos++],de=t=>{let e=0,s=1;const r=t.arr.length;for(;t.pos<r;){const i=t.arr[t.pos++];if(e=e+(i&St)*s,s*=128,i<ze)return e;if(e>Vs)throw wo}throw xo},Lr=t=>{let e=t.arr[t.pos++],s=e&sr,r=64;const i=(e&ot)>0?-1:1;if((e&ze)===0)return i*s;const o=t.arr.length;for(;t.pos<o;){if(e=t.arr[t.pos++],s=s+(e&St)*r,r*=128,e<ze)return i*s;if(s>Vs)throw wo}throw xo},Ic=t=>{let e=de(t);if(e===0)return"";{let s=String.fromCodePoint(Et(t));if(--e<100)for(;e--;)s+=String.fromCodePoint(Et(t));else for(;e>0;){const r=e<1e4?e:1e4,i=t.arr.subarray(t.pos,t.pos+r);t.pos+=r,s+=String.fromCodePoint.apply(null,i),e-=r}return decodeURIComponent(escape(s))}},Dc=t=>ls.decode(Re(t)),at=ls?Dc:Ic,Ir=(t,e)=>{const s=new DataView(t.arr.buffer,t.arr.byteOffset+t.pos,e);return t.pos+=e,s},Mc=t=>Ir(t,4).getFloat32(0,!1),Oc=t=>Ir(t,8).getFloat64(0,!1),Wc=t=>Ir(t,8).getBigInt64(0,!1),Pc=[t=>{},t=>null,Lr,Mc,Oc,Wc,t=>!1,t=>!0,at,t=>{const e=de(t),s={};for(let r=0;r<e;r++){const i=at(t);s[i]=Gt(t)}return s},t=>{const e=de(t),s=[];for(let r=0;r<e;r++)s.push(Gt(t));return s},Re],Gt=t=>Pc[127-Et(t)](t);class yi extends bn{constructor(e,s){super(e),this.reader=s,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Ac(this)?this.count=de(this)+1:this.count=-1),this.count--,this.s}}class $s extends bn{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=Lr(this);const e=yo(this.s);this.count=1,e&&(this.s=-this.s,this.count=de(this)+2)}return this.count--,this.s}}class Wn extends bn{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const e=Lr(this),s=e&1;this.diff=Je(e/2),this.count=1,s&&(this.count=de(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Bc{constructor(e){this.decoder=new $s(e),this.str=at(this.decoder),this.spos=0}read(){const e=this.spos+this.decoder.read(),s=this.str.slice(this.spos,e);return this.spos=e,s}}const Uc=crypto.getRandomValues.bind(crypto),Fc=Math.random,vo=()=>Uc(new Uint32Array(1))[0],$c="10000000-1000-4000-8000"+-1e11,_o=()=>$c.replace(/[018]/g,t=>(t^vo()&15>>t/4).toString(16)),ct=Date.now,qt=t=>new Promise(t);Promise.all.bind(Promise);const zc=t=>Promise.reject(t),Dr=t=>Promise.resolve(t),bi=t=>t===void 0?null:t;class Hc{constructor(){this.map=new Map}setItem(e,s){this.map.set(e,s)}getItem(e){return this.map.get(e)}}let ko=new Hc,Mr=!0;try{typeof localStorage<"u"&&localStorage&&(ko=localStorage,Mr=!1)}catch{}const So=ko,Vc=t=>Mr||addEventListener("storage",t),Gc=t=>Mr||removeEventListener("storage",t),gs=Symbol("Equality"),jo=(t,e)=>{var s;return t===e||!!((s=t==null?void 0:t[gs])!=null&&s.call(t,e))||!1},qc=t=>typeof t=="object",Yc=Object.assign,Kc=Object.keys,Jc=(t,e)=>{for(const s in t)e(t[s],s)},Gs=t=>Kc(t).length,Xc=t=>{for(const e in t)return!1;return!0},js=(t,e)=>{for(const s in t)if(!e(t[s],s))return!1;return!0},Or=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Qc=(t,e)=>t===e||Gs(t)===Gs(e)&&js(t,(s,r)=>(s!==void 0||Or(e,r))&&jo(e[r],s)),Zc=Object.freeze,Eo=t=>{for(const e in t){const s=t[e];(typeof s=="object"||typeof s=="function")&&Eo(t[e])}return Zc(t)},Wr=(t,e,s=0)=>{try{for(;s<t.length;s++)t[s](...e)}finally{s<t.length&&Wr(t,e,s+1)}},ed=()=>{},td=t=>t,Ut=(t,e)=>{if(t===e)return!0;if(t==null||e==null||t.constructor!==e.constructor&&(t.constructor||Object)!==(e.constructor||Object))return!1;if(t[gs]!=null)return t[gs](e);switch(t.constructor){case ArrayBuffer:t=new Uint8Array(t),e=new Uint8Array(e);case Uint8Array:{if(t.byteLength!==e.byteLength)return!1;for(let s=0;s<t.length;s++)if(t[s]!==e[s])return!1;break}case Set:{if(t.size!==e.size)return!1;for(const s of t)if(!e.has(s))return!1;break}case Map:{if(t.size!==e.size)return!1;for(const s of t.keys())if(!e.has(s)||!Ut(t.get(s),e.get(s)))return!1;break}case void 0:case Object:if(Gs(t)!==Gs(e))return!1;for(const s in t)if(!Or(t,s)||!Ut(t[s],e[s]))return!1;break;case Array:if(t.length!==e.length)return!1;for(let s=0;s<t.length;s++)if(!Ut(t[s],e[s]))return!1;break;default:return!1}return!0},sd=(t,e)=>e.includes(t);var No={};const Yt=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",Co=typeof window<"u"&&typeof document<"u"&&!Yt;let et;const nd=()=>{if(et===void 0)if(Yt){et=Ue();const t=process.argv;let e=null;for(let s=0;s<t.length;s++){const r=t[s];r[0]==="-"?(e!==null&&et.set(e,""),e=r):e!==null&&(et.set(e,r),e=null)}e!==null&&et.set(e,"")}else typeof location=="object"?(et=Ue(),(location.search||"?").slice(1).split("&").forEach(t=>{if(t.length!==0){const[e,s]=t.split("=");et.set(`--${hi(e,"-")}`,s),et.set(`-${hi(e,"-")}`,s)}})):et=Ue();return et},ir=t=>nd().has(t),ys=t=>bi(Yt?No[t.toUpperCase().replaceAll("-","_")]:So.getItem(t)),To=t=>ir("--"+t)||ys(t)!==null,rd=To("production"),id=Yt&&sd(No.FORCE_COLOR,["true","1","2"]),od=id||!ir("--no-colors")&&!To("no-color")&&(!Yt||process.stdout.isTTY)&&(!Yt||ir("--color")||ys("COLORTERM")!==null||(ys("TERM")||"").includes("color")),Ro=t=>new Uint8Array(t),ad=(t,e,s)=>new Uint8Array(t,e,s),ld=t=>new Uint8Array(t),cd=t=>{let e="";for(let s=0;s<t.byteLength;s++)e+=bo(t[s]);return btoa(e)},dd=t=>Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("base64"),ud=t=>{const e=atob(t),s=Ro(e.length);for(let r=0;r<e.length;r++)s[r]=e.charCodeAt(r);return s},hd=t=>{const e=Buffer.from(t,"base64");return ad(e.buffer,e.byteOffset,e.byteLength)},Ao=Co?cd:dd,Lo=Co?ud:hd,fd=t=>{const e=Ro(t.byteLength);return e.set(t),e};class pd{constructor(e,s){this.left=e,this.right=s}}const it=(t,e)=>new pd(t,e),xi=t=>t.next()>=.5,Pn=(t,e,s)=>Je(t.next()*(s+1-e)+e),Io=(t,e,s)=>Je(t.next()*(s+1-e)+e),Pr=(t,e,s)=>Io(t,e,s),md=t=>bo(Pr(t,97,122)),gd=(t,e=0,s=20)=>{const r=Pr(t,e,s);let i="";for(let o=0;o<r;o++)i+=md(t);return i},Bn=(t,e)=>e[Pr(t,0,e.length-1)],yd=Symbol("0schema");class bd{constructor(){this._rerrs=[]}extend(e,s,r,i=null){this._rerrs.push({path:e,expected:s,has:r,message:i})}toString(){const e=[];for(let s=this._rerrs.length-1;s>0;s--){const r=this._rerrs[s];e.push(wc(" ",(this._rerrs.length-s)*2)+`${r.path!=null?`[${r.path}] `:""}${r.has} doesn't match ${r.expected}. ${r.message}`)}return e.join(`
|
|
93
|
+
`)}}const or=(t,e)=>t===e?!0:t==null||e==null||t.constructor!==e.constructor?!1:t[gs]?jo(t,e):mn(t)?Nr(t,s=>mo(e,r=>or(s,r))):qc(t)?js(t,(s,r)=>or(s,e[r])):!1;class Pe{extends(e){let[s,r]=[this.shape,e.shape];return this.constructor._dilutes&&([r,s]=[s,r]),or(s,r)}equals(e){return this.constructor===e.constructor&&Ut(this.shape,e.shape)}[yd](){return!0}[gs](e){return this.equals(e)}validate(e){return this.check(e)}check(e,s){Qe()}get nullable(){return es(this,kn)}get optional(){return new Oo(this)}cast(e){return wi(e,this),e}expect(e){return wi(e,this),e}}Fe(Pe,"_dilutes",!1);class Br extends Pe{constructor(e,s){super(),this.shape=e,this._c=s}check(e,s=void 0){const r=(e==null?void 0:e.constructor)===this.shape&&(this._c==null||this._c(e));return!r&&(s==null||s.extend(null,this.shape.name,e==null?void 0:e.constructor.name,(e==null?void 0:e.constructor)!==this.shape?"Constructor match failed":"Check failed")),r}}const Ee=(t,e=null)=>new Br(t,e);Ee(Br);class Ur extends Pe{constructor(e){super(),this.shape=e}check(e,s){const r=this.shape(e);return!r&&(s==null||s.extend(null,"custom prop",e==null?void 0:e.constructor.name,"failed to check custom prop")),r}}const De=t=>new Ur(t);Ee(Ur);class xn extends Pe{constructor(e){super(),this.shape=e}check(e,s){const r=this.shape.some(i=>i===e);return!r&&(s==null||s.extend(null,this.shape.join(" | "),e.toString())),r}}const wn=(...t)=>new xn(t),Do=Ee(xn),xd=RegExp.escape||(t=>t.replace(/[().|&,$^[\]]/g,e=>"\\"+e)),Mo=t=>{if(Kt.check(t))return[xd(t)];if(Do.check(t))return t.shape.map(e=>e+"");if(Vo.check(t))return["[+-]?\\d+.?\\d*"];if(Go.check(t))return[".*"];if(Ys.check(t))return t.shape.map(Mo).flat(1);Xe()};class wd extends Pe{constructor(e){super(),this.shape=e,this._r=new RegExp("^"+e.map(Mo).map(s=>`(${s.join("|")})`).join("")+"$")}check(e,s){const r=this._r.exec(e)!=null;return!r&&(s==null||s.extend(null,this._r.toString(),e.toString(),"String doesn't match string template.")),r}}Ee(wd);const vd=Symbol("optional");class Oo extends Pe{constructor(e){super(),this.shape=e}check(e,s){const r=e===void 0||this.shape.check(e);return!r&&(s==null||s.extend(null,"undefined (optional)","()")),r}get[vd](){return!0}}const _d=Ee(Oo);class kd extends Pe{check(e,s){return s==null||s.extend(null,"never",typeof e),!1}}Ee(kd);const dn=class dn extends Pe{constructor(e,s=!1){super(),this.shape=e,this._isPartial=s}get partial(){return new dn(this.shape,!0)}check(e,s){return e==null?(s==null||s.extend(null,"object","null"),!1):js(this.shape,(r,i)=>{const o=this._isPartial&&!Or(e,i)||r.check(e[i],s);return!o&&(s==null||s.extend(i.toString(),r.toString(),typeof e[i],"Object property does not match")),o})}};Fe(dn,"_dilutes",!0);let qs=dn;const Sd=t=>new qs(t),jd=Ee(qs),Ed=De(t=>t!=null&&(t.constructor===Object||t.constructor==null));class Wo extends Pe{constructor(e,s){super(),this.shape={keys:e,values:s}}check(e,s){return e!=null&&js(e,(r,i)=>{const o=this.shape.keys.check(i,s);return!o&&(s==null||s.extend(i+"","Record",typeof e,o?"Key doesn't match schema":"Value doesn't match value")),o&&this.shape.values.check(r,s)})}}const Po=(t,e)=>new Wo(t,e),Nd=Ee(Wo);class Bo extends Pe{constructor(e){super(),this.shape=e}check(e,s){return e!=null&&js(this.shape,(r,i)=>{const o=r.check(e[i],s);return!o&&(s==null||s.extend(i.toString(),"Tuple",typeof r)),o})}}const Cd=(...t)=>new Bo(t);Ee(Bo);class Uo extends Pe{constructor(e){super(),this.shape=e.length===1?e[0]:new vn(e)}check(e,s){const r=mn(e)&&Nr(e,i=>this.shape.check(i));return!r&&(s==null||s.extend(null,"Array","")),r}}const Fo=(...t)=>new Uo(t),Td=Ee(Uo),Rd=De(t=>mn(t));class $o extends Pe{constructor(e,s){super(),this.shape=e,this._c=s}check(e,s){const r=e instanceof this.shape&&(this._c==null||this._c(e));return!r&&(s==null||s.extend(null,this.shape.name,e==null?void 0:e.constructor.name)),r}}const Ad=(t,e=null)=>new $o(t,e);Ee($o);const Ld=Ad(Pe);class Id extends Pe{constructor(e){super(),this.len=e.length-1,this.args=Cd(...e.slice(-1)),this.res=e[this.len]}check(e,s){const r=e.constructor===Function&&e.length<=this.len;return!r&&(s==null||s.extend(null,"function",typeof e)),r}}const Dd=Ee(Id),Md=De(t=>typeof t=="function");class Od extends Pe{constructor(e){super(),this.shape=e}check(e,s){const r=Nr(this.shape,i=>i.check(e,s));return!r&&(s==null||s.extend(null,"Intersectinon",typeof e)),r}}Ee(Od,t=>t.shape.length>0);class vn extends Pe{constructor(e){super(),this.shape=e}check(e,s){const r=mo(this.shape,i=>i.check(e,s));return s==null||s.extend(null,"Union",typeof e),r}}Fe(vn,"_dilutes",!0);const es=(...t)=>t.findIndex(e=>Ys.check(e))>=0?es(...t.map(e=>bs(e)).map(e=>Ys.check(e)?e.shape:[e]).flat(1)):t.length===1?t[0]:new vn(t),Ys=Ee(vn),zo=()=>!0,Ks=De(zo),Wd=Ee(Ur,t=>t.shape===zo),Fr=De(t=>typeof t=="bigint"),Pd=De(t=>t===Fr),Ho=De(t=>typeof t=="symbol");De(t=>t===Ho);const Ft=De(t=>typeof t=="number"),Vo=De(t=>t===Ft),Kt=De(t=>typeof t=="string"),Go=De(t=>t===Kt),_n=De(t=>typeof t=="boolean"),Bd=De(t=>t===_n),qo=wn(void 0);Ee(xn,t=>t.shape.length===1&&t.shape[0]===void 0);wn(void 0);const kn=wn(null),Ud=Ee(xn,t=>t.shape.length===1&&t.shape[0]===null);Ee(Uint8Array);Ee(Br,t=>t.shape===Uint8Array);const Fd=es(Ft,Kt,kn,qo,Fr,_n,Ho);(()=>{const t=Fo(Ks),e=Po(Kt,Ks),s=es(Ft,Kt,kn,_n,t,e);return t.shape=s,e.shape.values=s,s})();const bs=t=>{if(Ld.check(t))return t;if(Ed.check(t)){const e={};for(const s in t)e[s]=bs(t[s]);return Sd(e)}else{if(Rd.check(t))return es(...t.map(bs));if(Fd.check(t))return wn(t);if(Md.check(t))return Ee(t)}Xe()},wi=rd?()=>{}:(t,e)=>{const s=new bd;if(!e.check(t,s))throw Ve(`Expected value to be of type ${e.constructor.name}.
|
|
94
|
+
${s.toString()}`)};class $d{constructor(e){this.patterns=[],this.$state=e}if(e,s){return this.patterns.push({if:bs(e),h:s}),this}else(e){return this.if(Ks,e)}done(){return(e,s)=>{for(let r=0;r<this.patterns.length;r++){const i=this.patterns[r];if(i.if.check(e))return i.h(e,s)}throw Ve("Unhandled pattern")}}}const zd=t=>new $d(t),Yo=zd(Ks).if(Vo,(t,e)=>Pn(e,ui,Vs)).if(Go,(t,e)=>gd(e)).if(Bd,(t,e)=>xi(e)).if(Pd,(t,e)=>BigInt(Pn(e,ui,Vs))).if(Ys,(t,e)=>Pt(e,Bn(e,t.shape))).if(jd,(t,e)=>{const s={};for(const r in t.shape){let i=t.shape[r];if(_d.check(i)){if(xi(e))continue;i=i.shape}s[r]=Yo(i,e)}return s}).if(Td,(t,e)=>{const s=[],r=Io(e,0,42);for(let i=0;i<r;i++)s.push(Pt(e,t.shape));return s}).if(Do,(t,e)=>Bn(e,t.shape)).if(Ud,(t,e)=>null).if(Dd,(t,e)=>{const s=Pt(e,t.res);return()=>s}).if(Wd,(t,e)=>Pt(e,Bn(e,[Ft,Kt,kn,qo,Fr,_n,Fo(Ft),Po(es("a","b","c"),Ft)]))).if(Nd,(t,e)=>{const s={},r=Pn(e,0,3);for(let i=0;i<r;i++){const o=Pt(e,t.shape.keys),c=Pt(e,t.shape.values);s[o]=c}return s}).done(),Pt=(t,e)=>Yo(bs(e),t),Sn=typeof document<"u"?document:{};De(t=>t.nodeType===Yd);typeof DOMParser<"u"&&new DOMParser;De(t=>t.nodeType===Vd);De(t=>t.nodeType===Gd);const Hd=t=>ac(t,(e,s)=>`${s}:${e};`).join(""),Vd=Sn.ELEMENT_NODE,Gd=Sn.TEXT_NODE,qd=Sn.DOCUMENT_NODE,Yd=Sn.DOCUMENT_FRAGMENT_NODE;De(t=>t.nodeType===qd);const Kd=JSON.stringify,ut=Symbol,Ke=ut(),Nt=ut(),Ko=ut(),$r=ut(),Jo=ut(),Xo=ut(),Qo=ut(),jn=ut(),En=ut(),Jd=t=>{var i;t.length===1&&((i=t[0])==null?void 0:i.constructor)===Function&&(t=t[0]());const e=[],s=[];let r=0;for(;r<t.length;r++){const o=t[r];if(o===void 0)break;if(o.constructor===String||o.constructor===Number)e.push(o);else if(o.constructor===Object)break}for(r>0&&s.push(e.join(""));r<t.length;r++){const o=t[r];o instanceof Symbol||s.push(o)}return s},vi=[Jo,Qo,jn,Ko];let Un=0,_i=ct();const Xd=(t,e)=>{const s=vi[Un],r=ys("log"),i=r!==null&&(r==="*"||r==="true"||new RegExp(r,"gi").test(e));return Un=(Un+1)%vi.length,e+=": ",i?(...o)=>{var d;o.length===1&&((d=o[0])==null?void 0:d.constructor)===Function&&(o=o[0]());const c=ct(),l=c-_i;_i=c,t(s,e,En,...o.map(p=>{switch(p!=null&&p.constructor===Uint8Array&&(p=Array.from(p)),typeof p){case"string":case"symbol":return p;default:return Kd(p)}}),s," +"+l+"ms")}:ed},Qd={[Ke]:it("font-weight","bold"),[Nt]:it("font-weight","normal"),[Ko]:it("color","blue"),[Jo]:it("color","green"),[$r]:it("color","grey"),[Xo]:it("color","red"),[Qo]:it("color","purple"),[jn]:it("color","orange"),[En]:it("color","black")},Zd=t=>{var c;t.length===1&&((c=t[0])==null?void 0:c.constructor)===Function&&(t=t[0]());const e=[],s=[],r=Ue();let i=[],o=0;for(;o<t.length;o++){const l=t[o],d=Qd[l];if(d!==void 0)r.set(d.left,d.right);else{if(l===void 0)break;if(l.constructor===String||l.constructor===Number){const p=Hd(r);o>0||p.length>0?(e.push("%c"+l),s.push(p)):e.push(l)}else break}}for(o>0&&(i=s,i.unshift(e.join("")));o<t.length;o++){const l=t[o];l instanceof Symbol||i.push(l)}return i},Zo=od?Zd:Jd,ea=(...t)=>{console.log(...Zo(t)),ta.forEach(e=>e.print(t))},eu=(...t)=>{console.warn(...Zo(t)),t.unshift(jn),ta.forEach(e=>e.print(t))},ta=bt(),tu=t=>Xd(ea,t),sa=t=>({[Symbol.iterator](){return this},next:t}),su=(t,e)=>sa(()=>{let s;do s=t.next();while(!s.done&&!e(s.value));return s}),Fn=(t,e)=>sa(()=>{const{done:s,value:r}=t.next();return{done:s,value:s?void 0:e(r)}});class Nn{constructor(e,s){this.clock=e,this.len=s}}class Es{constructor(){this.clients=new Map}}const na=(t,e,s)=>e.clients.forEach((r,i)=>{const o=t.doc.store.clients.get(i);if(o!=null){const c=o[o.length-1],l=c.id.clock+c.length;for(let d=0,p=r[d];d<r.length&&p.clock<l;p=r[++d])ya(t,o,p.clock,p.len,s)}}),nu=(t,e)=>{let s=0,r=t.length-1;for(;s<=r;){const i=Je((s+r)/2),o=t[i],c=o.clock;if(c<=e){if(e<c+o.len)return i;s=i+1}else r=i-1}return null},ra=(t,e)=>{const s=t.clients.get(e.client);return s!==void 0&&nu(s,e.clock)!==null},zr=t=>{t.clients.forEach(e=>{e.sort((i,o)=>i.clock-o.clock);let s,r;for(s=1,r=1;s<e.length;s++){const i=e[r-1],o=e[s];i.clock+i.len>=o.clock?e[r-1]=new Nn(i.clock,Lt(i.len,o.clock+o.len-i.clock)):(r<s&&(e[r]=o),r++)}e.length=r})},ru=t=>{const e=new Es;for(let s=0;s<t.length;s++)t[s].clients.forEach((r,i)=>{if(!e.clients.has(i)){const o=r.slice();for(let c=s+1;c<t.length;c++)cc(o,t[c].clients.get(i)||[]);e.clients.set(i,o)}});return zr(e),e},Js=(t,e,s,r)=>{He(t.clients,e,()=>[]).push(new Nn(s,r))},iu=()=>new Es,ou=t=>{const e=iu();return t.clients.forEach((s,r)=>{const i=[];for(let o=0;o<s.length;o++){const c=s[o];if(c.deleted){const l=c.id.clock;let d=c.length;if(o+1<s.length)for(let p=s[o+1];o+1<s.length&&p.deleted;p=s[++o+1])d+=p.length;i.push(new Nn(l,d))}}i.length>0&&e.clients.set(r,i)}),e},ts=(t,e)=>{ie(t.restEncoder,e.clients.size),lt(e.clients.entries()).sort((s,r)=>r[0]-s[0]).forEach(([s,r])=>{t.resetDsCurVal(),ie(t.restEncoder,s);const i=r.length;ie(t.restEncoder,i);for(let o=0;o<i;o++){const c=r[o];t.writeDsClock(c.clock),t.writeDsLen(c.len)}})},Hr=t=>{const e=new Es,s=de(t.restDecoder);for(let r=0;r<s;r++){t.resetDsCurVal();const i=de(t.restDecoder),o=de(t.restDecoder);if(o>0){const c=He(e.clients,i,()=>[]);for(let l=0;l<o;l++)c.push(new Nn(t.readDsClock(),t.readDsLen()))}}return e},ki=(t,e,s)=>{const r=new Es,i=de(t.restDecoder);for(let o=0;o<i;o++){t.resetDsCurVal();const c=de(t.restDecoder),l=de(t.restDecoder),d=s.clients.get(c)||[],p=Le(s,c);for(let g=0;g<l;g++){const u=t.readDsClock(),f=u+t.readDsLen();if(u<p){p<f&&Js(r,c,p,f-p);let x=st(d,u),b=d[x];for(!b.deleted&&b.id.clock<u&&(d.splice(x+1,0,nn(e,b,u-b.id.clock)),x++);x<d.length&&(b=d[x++],b.id.clock<f);)b.deleted||(f<b.id.clock+b.length&&d.splice(x,0,nn(e,b,f-b.id.clock)),b.delete(e))}else Js(r,c,u,f-u)}}if(r.clients.size>0){const o=new Ct;return ie(o.restEncoder,0),ts(o,r),o.toUint8Array()}return null},ia=vo;class ss extends go{constructor({guid:e=_o(),collectionid:s=null,gc:r=!0,gcFilter:i=()=>!0,meta:o=null,autoLoad:c=!1,shouldLoad:l=!0}={}){super(),this.gc=r,this.gcFilter=i,this.clientID=ia(),this.guid=e,this.collectionid=s,this.share=new Map,this.store=new ma,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=c,this.meta=o,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=qt(p=>{this.on("load",()=>{this.isLoaded=!0,p(this)})});const d=()=>qt(p=>{const g=u=>{(u===void 0||u===!0)&&(this.off("sync",g),p())};this.on("sync",g)});this.on("sync",p=>{p===!1&&this.isSynced&&(this.whenSynced=d()),this.isSynced=p===void 0||p===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=d()}load(){const e=this._item;e!==null&&!this.shouldLoad&&xe(e.parent.doc,s=>{s.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(lt(this.subdocs).map(e=>e.guid))}transact(e,s=null){return xe(this,e,s)}get(e,s=Oe){const r=He(this.share,e,()=>{const o=new s;return o._integrate(this,null),o}),i=r.constructor;if(s!==Oe&&i!==s)if(i===Oe){const o=new s;o._map=r._map,r._map.forEach(c=>{for(;c!==null;c=c.left)c.parent=o}),o._start=r._start;for(let c=o._start;c!==null;c=c.right)c.parent=o;return o._length=r._length,this.share.set(e,o),o._integrate(this,null),o}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return r}getArray(e=""){return this.get(e,zt)}getText(e=""){return this.get(e,Xt)}getMap(e=""){return this.get(e,Tt)}getXmlElement(e=""){return this.get(e,Qt)}getXmlFragment(e=""){return this.get(e,Rt)}toJSON(){const e={};return this.share.forEach((s,r)=>{e[r]=s.toJSON()}),e}destroy(){this.isDestroyed=!0,lt(this.subdocs).forEach(s=>s.destroy());const e=this._item;if(e!==null){this._item=null;const s=e.content;s.doc=new ss({guid:this.guid,...s.opts,shouldLoad:!1}),s.doc._item=e,xe(e.parent.doc,r=>{const i=s.doc;e.deleted||r.subdocsAdded.add(i),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class oa{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return de(this.restDecoder)}readDsLen(){return de(this.restDecoder)}}class aa extends oa{readLeftID(){return me(de(this.restDecoder),de(this.restDecoder))}readRightID(){return me(de(this.restDecoder),de(this.restDecoder))}readClient(){return de(this.restDecoder)}readInfo(){return Et(this.restDecoder)}readString(){return at(this.restDecoder)}readParentInfo(){return de(this.restDecoder)===1}readTypeRef(){return de(this.restDecoder)}readLen(){return de(this.restDecoder)}readAny(){return Gt(this.restDecoder)}readBuf(){return fd(Re(this.restDecoder))}readJSON(){return JSON.parse(at(this.restDecoder))}readKey(){return at(this.restDecoder)}}class au{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=de(this.restDecoder),this.dsCurrVal}readDsLen(){const e=de(this.restDecoder)+1;return this.dsCurrVal+=e,e}}class Jt extends au{constructor(e){super(e),this.keys=[],de(e),this.keyClockDecoder=new Wn(Re(e)),this.clientDecoder=new $s(Re(e)),this.leftClockDecoder=new Wn(Re(e)),this.rightClockDecoder=new Wn(Re(e)),this.infoDecoder=new yi(Re(e),Et),this.stringDecoder=new Bc(Re(e)),this.parentInfoDecoder=new yi(Re(e),Et),this.typeRefDecoder=new $s(Re(e)),this.lenDecoder=new $s(Re(e))}readLeftID(){return new $t(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new $t(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return Gt(this.restDecoder)}readBuf(){return Re(this.restDecoder)}readJSON(){return Gt(this.restDecoder)}readKey(){const e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{const s=this.stringDecoder.read();return this.keys.push(s),s}}}class la{constructor(){this.restEncoder=Ae()}toUint8Array(){return Se(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){ie(this.restEncoder,e)}writeDsLen(e){ie(this.restEncoder,e)}}class Ns extends la{writeLeftID(e){ie(this.restEncoder,e.client),ie(this.restEncoder,e.clock)}writeRightID(e){ie(this.restEncoder,e.client),ie(this.restEncoder,e.clock)}writeClient(e){ie(this.restEncoder,e)}writeInfo(e){ms(this.restEncoder,e)}writeString(e){tt(this.restEncoder,e)}writeParentInfo(e){ie(this.restEncoder,e?1:0)}writeTypeRef(e){ie(this.restEncoder,e)}writeLen(e){ie(this.restEncoder,e)}writeAny(e){Vt(this.restEncoder,e)}writeBuf(e){je(this.restEncoder,e)}writeJSON(e){tt(this.restEncoder,JSON.stringify(e))}writeKey(e){tt(this.restEncoder,e)}}class ca{constructor(){this.restEncoder=Ae(),this.dsCurrVal=0}toUint8Array(){return Se(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const s=e-this.dsCurrVal;this.dsCurrVal=e,ie(this.restEncoder,s)}writeDsLen(e){e===0&&Xe(),ie(this.restEncoder,e-1),this.dsCurrVal+=e}}class Ct extends ca{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new On,this.clientEncoder=new Fs,this.leftClockEncoder=new On,this.rightClockEncoder=new On,this.infoEncoder=new pi(ms),this.stringEncoder=new Rc,this.parentInfoEncoder=new pi(ms),this.typeRefEncoder=new Fs,this.lenEncoder=new Fs}toUint8Array(){const e=Ae();return ie(e,0),je(e,this.keyClockEncoder.toUint8Array()),je(e,this.clientEncoder.toUint8Array()),je(e,this.leftClockEncoder.toUint8Array()),je(e,this.rightClockEncoder.toUint8Array()),je(e,Se(this.infoEncoder)),je(e,this.stringEncoder.toUint8Array()),je(e,Se(this.parentInfoEncoder)),je(e,this.typeRefEncoder.toUint8Array()),je(e,this.lenEncoder.toUint8Array()),yn(e,Se(this.restEncoder)),Se(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(e?1:0)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){Vt(this.restEncoder,e)}writeBuf(e){je(this.restEncoder,e)}writeJSON(e){Vt(this.restEncoder,e)}writeKey(e){const s=this.keyMap.get(e);s===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(s)}}const lu=(t,e,s,r)=>{r=Lt(r,e[0].id.clock);const i=st(e,r);ie(t.restEncoder,e.length-i),t.writeClient(s),ie(t.restEncoder,r);const o=e[i];o.write(t,r-o.id.clock);for(let c=i+1;c<e.length;c++)e[c].write(t,0)},Vr=(t,e,s)=>{const r=new Map;s.forEach((i,o)=>{Le(e,o)>i&&r.set(o,i)}),Cn(e).forEach((i,o)=>{s.has(o)||r.set(o,0)}),ie(t.restEncoder,r.size),lt(r.entries()).sort((i,o)=>o[0]-i[0]).forEach(([i,o])=>{lu(t,e.clients.get(i),i,o)})},cu=(t,e)=>{const s=Ue(),r=de(t.restDecoder);for(let i=0;i<r;i++){const o=de(t.restDecoder),c=new Array(o),l=t.readClient();let d=de(t.restDecoder);s.set(l,{i:0,refs:c});for(let p=0;p<o;p++){const g=t.readInfo();switch(gn&g){case 0:{const u=t.readLen();c[p]=new qe(me(l,d),u),d+=u;break}case 10:{const u=de(t.restDecoder);c[p]=new Ye(me(l,d),u),d+=u;break}default:{const u=(g&(ot|ze))===0,f=new Ne(me(l,d),null,(g&ze)===ze?t.readLeftID():null,null,(g&ot)===ot?t.readRightID():null,u?t.readParentInfo()?e.get(t.readString()):t.readLeftID():null,u&&(g&fs)===fs?t.readString():null,Oa(t,g));c[p]=f,d+=f.length}}}}return s},du=(t,e,s)=>{const r=[];let i=lt(s.keys()).sort((x,b)=>x-b);if(i.length===0)return null;const o=()=>{if(i.length===0)return null;let x=s.get(i[i.length-1]);for(;x.refs.length===x.i;)if(i.pop(),i.length>0)x=s.get(i[i.length-1]);else return null;return x};let c=o();if(c===null)return null;const l=new ma,d=new Map,p=(x,b)=>{const E=d.get(x);(E==null||E>b)&&d.set(x,b)};let g=c.refs[c.i++];const u=new Map,f=()=>{for(const x of r){const b=x.id.client,E=s.get(b);E?(E.i--,l.clients.set(b,E.refs.slice(E.i)),s.delete(b),E.i=0,E.refs=[]):l.clients.set(b,[x]),i=i.filter(A=>A!==b)}r.length=0};for(;;){if(g.constructor!==Ye){const b=He(u,g.id.client,()=>Le(e,g.id.client))-g.id.clock;if(b<0)r.push(g),p(g.id.client,g.id.clock-1),f();else{const E=g.getMissing(t,e);if(E!==null){r.push(g);const A=s.get(E)||{refs:[],i:0};if(A.refs.length===A.i)p(E,Le(e,E)),f();else{g=A.refs[A.i++];continue}}else(b===0||b<g.length)&&(g.integrate(t,b),u.set(g.id.client,g.id.clock+g.length))}}if(r.length>0)g=r.pop();else if(c!==null&&c.i<c.refs.length)g=c.refs[c.i++];else{if(c=o(),c===null)break;g=c.refs[c.i++]}}if(l.clients.size>0){const x=new Ct;return Vr(x,l,new Map),ie(x.restEncoder,0),{missing:d,update:x.toUint8Array()}}return null},uu=(t,e)=>Vr(t,e.doc.store,e.beforeState),hu=(t,e,s,r=new Jt(t))=>xe(e,i=>{i.local=!1;let o=!1;const c=i.doc,l=c.store,d=cu(r,c),p=du(i,l,d),g=l.pendingStructs;if(g){for(const[f,x]of g.missing)if(x<Le(l,f)){o=!0;break}if(p){for(const[f,x]of p.missing){const b=g.missing.get(f);(b==null||b>x)&&g.missing.set(f,x)}g.update=Xs([g.update,p.update])}}else l.pendingStructs=p;const u=ki(r,i,l);if(l.pendingDs){const f=new Jt(rt(l.pendingDs));de(f.restDecoder);const x=ki(f,i,l);u&&x?l.pendingDs=Xs([u,x]):l.pendingDs=u||x}else l.pendingDs=u;if(o){const f=l.pendingStructs.update;l.pendingStructs=null,da(i.doc,f)}},s,!1),da=(t,e,s,r=Jt)=>{const i=rt(e);hu(i,t,s,new r(i))},ua=(t,e,s)=>da(t,e,s,aa),fu=(t,e,s=new Map)=>{Vr(t,e.store,s),ts(t,ou(e.store))},pu=(t,e=new Uint8Array([0]),s=new Ct)=>{const r=ha(e);fu(s,t,r);const i=[s.toUint8Array()];if(t.store.pendingDs&&i.push(t.store.pendingDs),t.store.pendingStructs&&i.push(Tu(t.store.pendingStructs.update,e)),i.length>1){if(s.constructor===Ns)return Nu(i.map((o,c)=>c===0?o:Au(o)));if(s.constructor===Ct)return Xs(i)}return i[0]},Gr=(t,e)=>pu(t,e,new Ns),mu=t=>{const e=new Map,s=de(t.restDecoder);for(let r=0;r<s;r++){const i=de(t.restDecoder),o=de(t.restDecoder);e.set(i,o)}return e},ha=t=>mu(new oa(rt(t))),fa=(t,e)=>(ie(t.restEncoder,e.size),lt(e.entries()).sort((s,r)=>r[0]-s[0]).forEach(([s,r])=>{ie(t.restEncoder,s),ie(t.restEncoder,r)}),t),gu=(t,e)=>fa(t,Cn(e.store)),yu=(t,e=new ca)=>(t instanceof Map?fa(e,t):gu(e,t),e.toUint8Array()),bu=t=>yu(t,new la);class xu{constructor(){this.l=[]}}const Si=()=>new xu,ji=(t,e)=>t.l.push(e),Ei=(t,e)=>{const s=t.l,r=s.length;t.l=s.filter(i=>e!==i),r===t.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},pa=(t,e,s)=>Wr(t.l,[e,s]);class $t{constructor(e,s){this.client=e,this.clock=s}}const Rs=(t,e)=>t===e||t!==null&&e!==null&&t.client===e.client&&t.clock===e.clock,me=(t,e)=>new $t(t,e),wu=t=>{for(const[e,s]of t.doc.share.entries())if(s===t)return e;throw Xe()},Bt=(t,e)=>e===void 0?!t.deleted:e.sv.has(t.id.client)&&(e.sv.get(t.id.client)||0)>t.id.clock&&!ra(e.ds,t.id),ar=(t,e)=>{const s=He(t.meta,ar,bt),r=t.doc.store;s.has(e)||(e.sv.forEach((i,o)=>{i<Le(r,o)&&xt(t,me(o,i))}),na(t,e.ds,i=>{}),s.add(e))};class ma{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const Cn=t=>{const e=new Map;return t.clients.forEach((s,r)=>{const i=s[s.length-1];e.set(r,i.id.clock+i.length)}),e},Le=(t,e)=>{const s=t.clients.get(e);if(s===void 0)return 0;const r=s[s.length-1];return r.id.clock+r.length},ga=(t,e)=>{let s=t.clients.get(e.id.client);if(s===void 0)s=[],t.clients.set(e.id.client,s);else{const r=s[s.length-1];if(r.id.clock+r.length!==e.id.clock)throw Xe()}s.push(e)},st=(t,e)=>{let s=0,r=t.length-1,i=t[r],o=i.id.clock;if(o===e)return r;let c=Je(e/(o+i.length-1)*r);for(;s<=r;){if(i=t[c],o=i.id.clock,o<=e){if(e<o+i.length)return c;s=c+1}else r=c-1;c=Je((s+r)/2)}throw Xe()},vu=(t,e)=>{const s=t.clients.get(e.client);return s[st(s,e.clock)]},$n=vu,lr=(t,e,s)=>{const r=st(e,s),i=e[r];return i.id.clock<s&&i instanceof Ne?(e.splice(r+1,0,nn(t,i,s-i.id.clock)),r+1):r},xt=(t,e)=>{const s=t.doc.store.clients.get(e.client);return s[lr(t,s,e.clock)]},Ni=(t,e,s)=>{const r=e.clients.get(s.client),i=st(r,s.clock),o=r[i];return s.clock!==o.id.clock+o.length-1&&o.constructor!==qe&&r.splice(i+1,0,nn(t,o,s.clock-o.id.clock+1)),o},_u=(t,e,s)=>{const r=t.clients.get(e.id.client);r[st(r,e.id.clock)]=s},ya=(t,e,s,r,i)=>{if(r===0)return;const o=s+r;let c=lr(t,e,s),l;do l=e[c++],o<l.id.clock+l.length&&lr(t,e,o),i(l);while(c<e.length&&e[c].id.clock<o)};class ku{constructor(e,s,r){this.doc=e,this.deleteSet=new Es,this.beforeState=Cn(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=s,this.meta=new Map,this.local=r,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const Ci=(t,e)=>e.deleteSet.clients.size===0&&!lc(e.afterState,(s,r)=>e.beforeState.get(r)!==s)?!1:(zr(e.deleteSet),uu(t,e),ts(t,e.deleteSet),!0),Ti=(t,e,s)=>{const r=e._item;(r===null||r.id.clock<(t.beforeState.get(r.id.client)||0)&&!r.deleted)&&He(t.changed,e,bt).add(s)},zs=(t,e)=>{let s=t[e],r=t[e-1],i=e;for(;i>0;s=r,r=t[--i-1]){if(r.deleted===s.deleted&&r.constructor===s.constructor&&r.mergeWith(s)){s instanceof Ne&&s.parentSub!==null&&s.parent._map.get(s.parentSub)===s&&s.parent._map.set(s.parentSub,r);continue}break}const o=e-i;return o&&t.splice(e+1-o,o),o},Su=(t,e,s)=>{for(const[r,i]of t.clients.entries()){const o=e.clients.get(r);for(let c=i.length-1;c>=0;c--){const l=i[c],d=l.clock+l.len;for(let p=st(o,l.clock),g=o[p];p<o.length&&g.id.clock<d;g=o[++p]){const u=o[p];if(l.clock+l.len<=u.id.clock)break;u instanceof Ne&&u.deleted&&!u.keep&&s(u)&&u.gc(e,!1)}}}},ju=(t,e)=>{t.clients.forEach((s,r)=>{const i=e.clients.get(r);for(let o=s.length-1;o>=0;o--){const c=s[o],l=Tr(i.length-1,1+st(i,c.clock+c.len-1));for(let d=l,p=i[d];d>0&&p.id.clock>=c.clock;p=i[d])d-=1+zs(i,d)}})},ba=(t,e)=>{if(e<t.length){const s=t[e],r=s.doc,i=r.store,o=s.deleteSet,c=s._mergeStructs;try{zr(o),s.afterState=Cn(s.doc.store),r.emit("beforeObserverCalls",[s,r]);const l=[];s.changed.forEach((d,p)=>l.push(()=>{(p._item===null||!p._item.deleted)&&p._callObserver(s,d)})),l.push(()=>{s.changedParentTypes.forEach((d,p)=>{p._dEH.l.length>0&&(p._item===null||!p._item.deleted)&&(d=d.filter(g=>g.target._item===null||!g.target._item.deleted),d.forEach(g=>{g.currentTarget=p,g._path=null}),d.sort((g,u)=>g.path.length-u.path.length),l.push(()=>{pa(p._dEH,d,s)}))}),l.push(()=>r.emit("afterTransaction",[s,r])),l.push(()=>{s._needFormattingCleanup&&Vu(s)})}),Wr(l,[])}finally{r.gc&&Su(o,i,r.gcFilter),ju(o,i),s.afterState.forEach((g,u)=>{const f=s.beforeState.get(u)||0;if(f!==g){const x=i.clients.get(u),b=Lt(st(x,f),1);for(let E=x.length-1;E>=b;)E-=1+zs(x,E)}});for(let g=c.length-1;g>=0;g--){const{client:u,clock:f}=c[g].id,x=i.clients.get(u),b=st(x,f);b+1<x.length&&zs(x,b+1)>1||b>0&&zs(x,b)}if(!s.local&&s.afterState.get(r.clientID)!==s.beforeState.get(r.clientID)&&(ea(jn,Ke,"[yjs] ",Nt,Xo,"Changed the client-id because another client seems to be using it."),r.clientID=ia()),r.emit("afterTransactionCleanup",[s,r]),r._observers.has("update")){const g=new Ns;Ci(g,s)&&r.emit("update",[g.toUint8Array(),s.origin,r,s])}if(r._observers.has("updateV2")){const g=new Ct;Ci(g,s)&&r.emit("updateV2",[g.toUint8Array(),s.origin,r,s])}const{subdocsAdded:l,subdocsLoaded:d,subdocsRemoved:p}=s;(l.size>0||p.size>0||d.size>0)&&(l.forEach(g=>{g.clientID=r.clientID,g.collectionid==null&&(g.collectionid=r.collectionid),r.subdocs.add(g)}),p.forEach(g=>r.subdocs.delete(g)),r.emit("subdocs",[{loaded:d,added:l,removed:p},r,s]),p.forEach(g=>g.destroy())),t.length<=e+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,t])):ba(t,e+1)}}},xe=(t,e,s=null,r=!0)=>{const i=t._transactionCleanups;let o=!1,c=null;t._transaction===null&&(o=!0,t._transaction=new ku(t,s,r),i.push(t._transaction),i.length===1&&t.emit("beforeAllTransactions",[t]),t.emit("beforeTransaction",[t._transaction,t]));try{c=e(t._transaction)}finally{if(o){const l=t._transaction===i[0];t._transaction=null,l&&ba(i,0)}}return c};function*Eu(t){const e=de(t.restDecoder);for(let s=0;s<e;s++){const r=de(t.restDecoder),i=t.readClient();let o=de(t.restDecoder);for(let c=0;c<r;c++){const l=t.readInfo();if(l===10){const d=de(t.restDecoder);yield new Ye(me(i,o),d),o+=d}else if((gn&l)!==0){const d=(l&(ot|ze))===0,p=new Ne(me(i,o),null,(l&ze)===ze?t.readLeftID():null,null,(l&ot)===ot?t.readRightID():null,d?t.readParentInfo()?t.readString():t.readLeftID():null,d&&(l&fs)===fs?t.readString():null,Oa(t,l));yield p,o+=p.length}else{const d=t.readLen();yield new qe(me(i,o),d),o+=d}}}}class qr{constructor(e,s){this.gen=Eu(e),this.curr=null,this.done=!1,this.filterSkips=s,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===Ye);return this.curr}}class Yr{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}}const Nu=t=>Xs(t,aa,Ns),Cu=(t,e)=>{if(t.constructor===qe){const{client:s,clock:r}=t.id;return new qe(me(s,r+e),t.length-e)}else if(t.constructor===Ye){const{client:s,clock:r}=t.id;return new Ye(me(s,r+e),t.length-e)}else{const s=t,{client:r,clock:i}=s.id;return new Ne(me(r,i+e),null,me(r,i+e-1),null,s.rightOrigin,s.parent,s.parentSub,s.content.splice(e))}},Xs=(t,e=Jt,s=Ct)=>{if(t.length===1)return t[0];const r=t.map(g=>new e(rt(g)));let i=r.map(g=>new qr(g,!0)),o=null;const c=new s,l=new Yr(c);for(;i=i.filter(f=>f.curr!==null),i.sort((f,x)=>{if(f.curr.id.client===x.curr.id.client){const b=f.curr.id.clock-x.curr.id.clock;return b===0?f.curr.constructor===x.curr.constructor?0:f.curr.constructor===Ye?1:-1:b}else return x.curr.id.client-f.curr.id.client}),i.length!==0;){const g=i[0],u=g.curr.id.client;if(o!==null){let f=g.curr,x=!1;for(;f!==null&&f.id.clock+f.length<=o.struct.id.clock+o.struct.length&&f.id.client>=o.struct.id.client;)f=g.next(),x=!0;if(f===null||f.id.client!==u||x&&f.id.clock>o.struct.id.clock+o.struct.length)continue;if(u!==o.struct.id.client)pt(l,o.struct,o.offset),o={struct:f,offset:0},g.next();else if(o.struct.id.clock+o.struct.length<f.id.clock)if(o.struct.constructor===Ye)o.struct.length=f.id.clock+f.length-o.struct.id.clock;else{pt(l,o.struct,o.offset);const b=f.id.clock-o.struct.id.clock-o.struct.length;o={struct:new Ye(me(u,o.struct.id.clock+o.struct.length),b),offset:0}}else{const b=o.struct.id.clock+o.struct.length-f.id.clock;b>0&&(o.struct.constructor===Ye?o.struct.length-=b:f=Cu(f,b)),o.struct.mergeWith(f)||(pt(l,o.struct,o.offset),o={struct:f,offset:0},g.next())}}else o={struct:g.curr,offset:0},g.next();for(let f=g.curr;f!==null&&f.id.client===u&&f.id.clock===o.struct.id.clock+o.struct.length&&f.constructor!==Ye;f=g.next())pt(l,o.struct,o.offset),o={struct:f,offset:0}}o!==null&&(pt(l,o.struct,o.offset),o=null),Kr(l);const d=r.map(g=>Hr(g)),p=ru(d);return ts(c,p),c.toUint8Array()},Tu=(t,e,s=Jt,r=Ct)=>{const i=ha(e),o=new r,c=new Yr(o),l=new s(rt(t)),d=new qr(l,!1);for(;d.curr;){const g=d.curr,u=g.id.client,f=i.get(u)||0;if(d.curr.constructor===Ye){d.next();continue}if(g.id.clock+g.length>f)for(pt(c,g,Lt(f-g.id.clock,0)),d.next();d.curr&&d.curr.id.client===u;)pt(c,d.curr,0),d.next();else for(;d.curr&&d.curr.id.client===u&&d.curr.id.clock+d.curr.length<=f;)d.next()}Kr(c);const p=Hr(l);return ts(o,p),o.toUint8Array()},xa=t=>{t.written>0&&(t.clientStructs.push({written:t.written,restEncoder:Se(t.encoder.restEncoder)}),t.encoder.restEncoder=Ae(),t.written=0)},pt=(t,e,s)=>{t.written>0&&t.currClient!==e.id.client&&xa(t),t.written===0&&(t.currClient=e.id.client,t.encoder.writeClient(e.id.client),ie(t.encoder.restEncoder,e.id.clock+s)),e.write(t.encoder,s),t.written++},Kr=t=>{xa(t);const e=t.encoder.restEncoder;ie(e,t.clientStructs.length);for(let s=0;s<t.clientStructs.length;s++){const r=t.clientStructs[s];ie(e,r.written),yn(e,r.restEncoder)}},Ru=(t,e,s,r)=>{const i=new s(rt(t)),o=new qr(i,!1),c=new r,l=new Yr(c);for(let p=o.curr;p!==null;p=o.next())pt(l,e(p),0);Kr(l);const d=Hr(i);return ts(c,d),c.toUint8Array()},Au=t=>Ru(t,td,Jt,Ns),Ri="You must not compute changes after the event-handler fired.";class Tn{constructor(e,s){this.target=e,this.currentTarget=e,this.transaction=s,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Lu(this.currentTarget,this.target))}deletes(e){return ra(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw Ve(Ri);const e=new Map,s=this.target;this.transaction.changed.get(s).forEach(i=>{if(i!==null){const o=s._map.get(i);let c,l;if(this.adds(o)){let d=o.left;for(;d!==null&&this.adds(d);)d=d.left;if(this.deletes(o))if(d!==null&&this.deletes(d))c="delete",l=In(d.content.getContent());else return;else d!==null&&this.deletes(d)?(c="update",l=In(d.content.getContent())):(c="add",l=void 0)}else if(this.deletes(o))c="delete",l=In(o.content.getContent());else return;e.set(i,{action:c,oldValue:l})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw Ve(Ri);const s=this.target,r=bt(),i=bt(),o=[];if(e={added:r,deleted:i,delta:o,keys:this.keys},this.transaction.changed.get(s).has(null)){let l=null;const d=()=>{l&&o.push(l)};for(let p=s._start;p!==null;p=p.right)p.deleted?this.deletes(p)&&!this.adds(p)&&((l===null||l.delete===void 0)&&(d(),l={delete:0}),l.delete+=p.length,i.add(p)):this.adds(p)?((l===null||l.insert===void 0)&&(d(),l={insert:[]}),l.insert=l.insert.concat(p.content.getContent()),r.add(p)):((l===null||l.retain===void 0)&&(d(),l={retain:0}),l.retain+=p.length);l!==null&&l.retain===void 0&&d()}this._changes=e}return e}}const Lu=(t,e)=>{const s=[];for(;e._item!==null&&e!==t;){if(e._item.parentSub!==null)s.unshift(e._item.parentSub);else{let r=0,i=e._item.parent._start;for(;i!==e._item&&i!==null;)!i.deleted&&i.countable&&(r+=i.length),i=i.right;s.unshift(r)}e=e._item.parent}return s},We=()=>{eu("Invalid access: Add Yjs type to a document before reading data.")},wa=80;let Jr=0;class Iu{constructor(e,s){e.marker=!0,this.p=e,this.index=s,this.timestamp=Jr++}}const Du=t=>{t.timestamp=Jr++},va=(t,e,s)=>{t.p.marker=!1,t.p=e,e.marker=!0,t.index=s,t.timestamp=Jr++},Mu=(t,e,s)=>{if(t.length>=wa){const r=t.reduce((i,o)=>i.timestamp<o.timestamp?i:o);return va(r,e,s),r}else{const r=new Iu(e,s);return t.push(r),r}},Rn=(t,e)=>{if(t._start===null||e===0||t._searchMarker===null)return null;const s=t._searchMarker.length===0?null:t._searchMarker.reduce((o,c)=>Us(e-o.index)<Us(e-c.index)?o:c);let r=t._start,i=0;for(s!==null&&(r=s.p,i=s.index,Du(s));r.right!==null&&i<e;){if(!r.deleted&&r.countable){if(e<i+r.length)break;i+=r.length}r=r.right}for(;r.left!==null&&i>e;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return s!==null&&Us(s.index-i)<r.parent.length/wa?(va(s,r,i),s):Mu(t._searchMarker,r,i)},xs=(t,e,s)=>{for(let r=t.length-1;r>=0;r--){const i=t[r];if(s>0){let o=i.p;for(o.marker=!1;o&&(o.deleted||!o.countable);)o=o.left,o&&!o.deleted&&o.countable&&(i.index-=o.length);if(o===null||o.marker===!0){t.splice(r,1);continue}i.p=o,o.marker=!0}(e<i.index||s>0&&e===i.index)&&(i.index=Lt(e,i.index+s))}},An=(t,e,s)=>{const r=t,i=e.changedParentTypes;for(;He(i,t,()=>[]).push(s),t._item!==null;)t=t._item.parent;pa(r._eH,s,e)};class Oe{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Si(),this._dEH=Si(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,s){this.doc=e,this._item=s}_copy(){throw Qe()}clone(){throw Qe()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,s){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){ji(this._eH,e)}observeDeep(e){ji(this._dEH,e)}unobserve(e){Ei(this._eH,e)}unobserveDeep(e){Ei(this._dEH,e)}toJSON(){}}const _a=(t,e,s)=>{t.doc??We(),e<0&&(e=t._length+e),s<0&&(s=t._length+s);let r=s-e;const i=[];let o=t._start;for(;o!==null&&r>0;){if(o.countable&&!o.deleted){const c=o.content.getContent();if(c.length<=e)e-=c.length;else{for(let l=e;l<c.length&&r>0;l++)i.push(c[l]),r--;e=0}}o=o.right}return i},ka=t=>{t.doc??We();const e=[];let s=t._start;for(;s!==null;){if(s.countable&&!s.deleted){const r=s.content.getContent();for(let i=0;i<r.length;i++)e.push(r[i])}s=s.right}return e},ws=(t,e)=>{let s=0,r=t._start;for(t.doc??We();r!==null;){if(r.countable&&!r.deleted){const i=r.content.getContent();for(let o=0;o<i.length;o++)e(i[o],s++,t)}r=r.right}},Sa=(t,e)=>{const s=[];return ws(t,(r,i)=>{s.push(e(r,i,t))}),s},Ou=t=>{let e=t._start,s=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(s===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};s=e.content.getContent(),r=0,e=e.right}const i=s[r++];return s.length<=r&&(s=null),{done:!1,value:i}}}},ja=(t,e)=>{t.doc??We();const s=Rn(t,e);let r=t._start;for(s!==null&&(r=s.p,e-=s.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(e<r.length)return r.content.getContent()[e];e-=r.length}},Qs=(t,e,s,r)=>{let i=s;const o=t.doc,c=o.clientID,l=o.store,d=s===null?e._start:s.right;let p=[];const g=()=>{p.length>0&&(i=new Ne(me(c,Le(l,c)),i,i&&i.lastId,d,d&&d.id,e,null,new At(p)),i.integrate(t,0),p=[])};r.forEach(u=>{if(u===null)p.push(u);else switch(u.constructor){case Number:case Object:case Boolean:case Array:case String:p.push(u);break;default:switch(g(),u.constructor){case Uint8Array:case ArrayBuffer:i=new Ne(me(c,Le(l,c)),i,i&&i.lastId,d,d&&d.id,e,null,new Cs(new Uint8Array(u))),i.integrate(t,0);break;case ss:i=new Ne(me(c,Le(l,c)),i,i&&i.lastId,d,d&&d.id,e,null,new Ts(u)),i.integrate(t,0);break;default:if(u instanceof Oe)i=new Ne(me(c,Le(l,c)),i,i&&i.lastId,d,d&&d.id,e,null,new ht(u)),i.integrate(t,0);else throw new Error("Unexpected content type in insert operation")}}}),g()},Ea=()=>Ve("Length exceeded!"),Na=(t,e,s,r)=>{if(s>e._length)throw Ea();if(s===0)return e._searchMarker&&xs(e._searchMarker,s,r.length),Qs(t,e,null,r);const i=s,o=Rn(e,s);let c=e._start;for(o!==null&&(c=o.p,s-=o.index,s===0&&(c=c.prev,s+=c&&c.countable&&!c.deleted?c.length:0));c!==null;c=c.right)if(!c.deleted&&c.countable){if(s<=c.length){s<c.length&&xt(t,me(c.id.client,c.id.clock+s));break}s-=c.length}return e._searchMarker&&xs(e._searchMarker,i,r.length),Qs(t,e,c,r)},Wu=(t,e,s)=>{let i=(e._searchMarker||[]).reduce((o,c)=>c.index>o.index?c:o,{index:0,p:e._start}).p;if(i)for(;i.right;)i=i.right;return Qs(t,e,i,s)},Ca=(t,e,s,r)=>{if(r===0)return;const i=s,o=r,c=Rn(e,s);let l=e._start;for(c!==null&&(l=c.p,s-=c.index);l!==null&&s>0;l=l.right)!l.deleted&&l.countable&&(s<l.length&&xt(t,me(l.id.client,l.id.clock+s)),s-=l.length);for(;r>0&&l!==null;)l.deleted||(r<l.length&&xt(t,me(l.id.client,l.id.clock+r)),l.delete(t),r-=l.length),l=l.right;if(r>0)throw Ea();e._searchMarker&&xs(e._searchMarker,i,-o+r)},Zs=(t,e,s)=>{const r=e._map.get(s);r!==void 0&&r.delete(t)},Xr=(t,e,s,r)=>{const i=e._map.get(s)||null,o=t.doc,c=o.clientID;let l;if(r==null)l=new At([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:l=new At([r]);break;case Uint8Array:l=new Cs(r);break;case ss:l=new Ts(r);break;default:if(r instanceof Oe)l=new ht(r);else throw new Error("Unexpected content type")}new Ne(me(c,Le(o.store,c)),i,i&&i.lastId,null,null,e,s,l).integrate(t,0)},Qr=(t,e)=>{t.doc??We();const s=t._map.get(e);return s!==void 0&&!s.deleted?s.content.getContent()[s.length-1]:void 0},Ta=t=>{const e={};return t.doc??We(),t._map.forEach((s,r)=>{s.deleted||(e[r]=s.content.getContent()[s.length-1])}),e},Ra=(t,e)=>{t.doc??We();const s=t._map.get(e);return s!==void 0&&!s.deleted},Pu=(t,e)=>{const s={};return t._map.forEach((r,i)=>{let o=r;for(;o!==null&&(!e.sv.has(o.id.client)||o.id.clock>=(e.sv.get(o.id.client)||0));)o=o.left;o!==null&&Bt(o,e)&&(s[i]=o.content.getContent()[o.length-1])}),s},As=t=>(t.doc??We(),su(t._map.entries(),e=>!e[1].deleted));class Bu extends Tn{}class zt extends Oe{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){const s=new zt;return s.push(e),s}_integrate(e,s){super._integrate(e,s),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new zt}clone(){const e=new zt;return e.insert(0,this.toArray().map(s=>s instanceof Oe?s.clone():s)),e}get length(){return this.doc??We(),this._length}_callObserver(e,s){super._callObserver(e,s),An(this,e,new Bu(this,e))}insert(e,s){this.doc!==null?xe(this.doc,r=>{Na(r,this,e,s)}):this._prelimContent.splice(e,0,...s)}push(e){this.doc!==null?xe(this.doc,s=>{Wu(s,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,s=1){this.doc!==null?xe(this.doc,r=>{Ca(r,this,e,s)}):this._prelimContent.splice(e,s)}get(e){return ja(this,e)}toArray(){return ka(this)}slice(e=0,s=this.length){return _a(this,e,s)}toJSON(){return this.map(e=>e instanceof Oe?e.toJSON():e)}map(e){return Sa(this,e)}forEach(e){ws(this,e)}[Symbol.iterator](){return Ou(this)}_write(e){e.writeTypeRef(dh)}}const Uu=t=>new zt;class Fu extends Tn{constructor(e,s,r){super(e,s),this.keysChanged=r}}class Tt extends Oe{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,s){super._integrate(e,s),this._prelimContent.forEach((r,i)=>{this.set(i,r)}),this._prelimContent=null}_copy(){return new Tt}clone(){const e=new Tt;return this.forEach((s,r)=>{e.set(r,s instanceof Oe?s.clone():s)}),e}_callObserver(e,s){An(this,e,new Fu(this,e,s))}toJSON(){this.doc??We();const e={};return this._map.forEach((s,r)=>{if(!s.deleted){const i=s.content.getContent()[s.length-1];e[r]=i instanceof Oe?i.toJSON():i}}),e}get size(){return[...As(this)].length}keys(){return Fn(As(this),e=>e[0])}values(){return Fn(As(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return Fn(As(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??We(),this._map.forEach((s,r)=>{s.deleted||e(s.content.getContent()[s.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?xe(this.doc,s=>{Zs(s,this,e)}):this._prelimContent.delete(e)}set(e,s){return this.doc!==null?xe(this.doc,r=>{Xr(r,this,e,s)}):this._prelimContent.set(e,s),s}get(e){return Qr(this,e)}has(e){return Ra(this,e)}clear(){this.doc!==null?xe(this.doc,e=>{this.forEach(function(s,r,i){Zs(e,i,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(uh)}}const $u=t=>new Tt,mt=(t,e)=>t===e||typeof t=="object"&&typeof e=="object"&&t&&e&&Qc(t,e);class cr{constructor(e,s,r,i){this.left=e,this.right=s,this.index=r,this.currentAttributes=i}forward(){switch(this.right===null&&Xe(),this.right.content.constructor){case Ce:this.right.deleted||ns(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}}const Ai=(t,e,s)=>{for(;e.right!==null&&s>0;){switch(e.right.content.constructor){case Ce:e.right.deleted||ns(e.currentAttributes,e.right.content);break;default:e.right.deleted||(s<e.right.length&&xt(t,me(e.right.id.client,e.right.id.clock+s)),e.index+=e.right.length,s-=e.right.length);break}e.left=e.right,e.right=e.right.right}return e},Ls=(t,e,s,r)=>{const i=new Map,o=r?Rn(e,s):null;if(o){const c=new cr(o.p.left,o.p,o.index,i);return Ai(t,c,s-o.index)}else{const c=new cr(null,e._start,0,i);return Ai(t,c,s)}},Aa=(t,e,s,r)=>{for(;s.right!==null&&(s.right.deleted===!0||s.right.content.constructor===Ce&&mt(r.get(s.right.content.key),s.right.content.value));)s.right.deleted||r.delete(s.right.content.key),s.forward();const i=t.doc,o=i.clientID;r.forEach((c,l)=>{const d=s.left,p=s.right,g=new Ne(me(o,Le(i.store,o)),d,d&&d.lastId,p,p&&p.id,e,null,new Ce(l,c));g.integrate(t,0),s.right=g,s.forward()})},ns=(t,e)=>{const{key:s,value:r}=e;r===null?t.delete(s):t.set(s,r)},La=(t,e)=>{for(;t.right!==null;){if(!(t.right.deleted||t.right.content.constructor===Ce&&mt(e[t.right.content.key]??null,t.right.content.value)))break;t.forward()}},Ia=(t,e,s,r)=>{const i=t.doc,o=i.clientID,c=new Map;for(const l in r){const d=r[l],p=s.currentAttributes.get(l)??null;if(!mt(p,d)){c.set(l,p);const{left:g,right:u}=s;s.right=new Ne(me(o,Le(i.store,o)),g,g&&g.lastId,u,u&&u.id,e,null,new Ce(l,d)),s.right.integrate(t,0),s.forward()}}return c},zn=(t,e,s,r,i)=>{s.currentAttributes.forEach((f,x)=>{i[x]===void 0&&(i[x]=null)});const o=t.doc,c=o.clientID;La(s,i);const l=Ia(t,e,s,i),d=r.constructor===String?new nt(r):r instanceof Oe?new ht(r):new It(r);let{left:p,right:g,index:u}=s;e._searchMarker&&xs(e._searchMarker,s.index,d.getLength()),g=new Ne(me(c,Le(o.store,c)),p,p&&p.lastId,g,g&&g.id,e,null,d),g.integrate(t,0),s.right=g,s.index=u,s.forward(),Aa(t,e,s,l)},Li=(t,e,s,r,i)=>{const o=t.doc,c=o.clientID;La(s,i);const l=Ia(t,e,s,i);e:for(;s.right!==null&&(r>0||l.size>0&&(s.right.deleted||s.right.content.constructor===Ce));){if(!s.right.deleted)switch(s.right.content.constructor){case Ce:{const{key:d,value:p}=s.right.content,g=i[d];if(g!==void 0){if(mt(g,p))l.delete(d);else{if(r===0)break e;l.set(d,p)}s.right.delete(t)}else s.currentAttributes.set(d,p);break}default:r<s.right.length&&xt(t,me(s.right.id.client,s.right.id.clock+r)),r-=s.right.length;break}s.forward()}if(r>0){let d="";for(;r>0;r--)d+=`
|
|
95
|
+
`;s.right=new Ne(me(c,Le(o.store,c)),s.left,s.left&&s.left.lastId,s.right,s.right&&s.right.id,e,null,new nt(d)),s.right.integrate(t,0),s.forward()}Aa(t,e,s,l)},Da=(t,e,s,r,i)=>{let o=e;const c=Ue();for(;o&&(!o.countable||o.deleted);){if(!o.deleted&&o.content.constructor===Ce){const p=o.content;c.set(p.key,p)}o=o.right}let l=0,d=!1;for(;e!==o;){if(s===e&&(d=!0),!e.deleted){const p=e.content;switch(p.constructor){case Ce:{const{key:g,value:u}=p,f=r.get(g)??null;(c.get(g)!==p||f===u)&&(e.delete(t),l++,!d&&(i.get(g)??null)===u&&f!==u&&(f===null?i.delete(g):i.set(g,f))),!d&&!e.deleted&&ns(i,p);break}}}e=e.right}return l},zu=(t,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;const s=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===Ce){const r=e.content.key;s.has(r)?e.delete(t):s.add(r)}e=e.left}},Hu=t=>{let e=0;return xe(t.doc,s=>{let r=t._start,i=t._start,o=Ue();const c=tr(o);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case Ce:ns(c,i.content);break;default:e+=Da(s,r,i,o,c),o=tr(c),r=i;break}i=i.right}}),e},Vu=t=>{const e=new Set,s=t.doc;for(const[r,i]of t.afterState.entries()){const o=t.beforeState.get(r)||0;i!==o&&ya(t,s.store.clients.get(r),o,i,c=>{!c.deleted&&c.content.constructor===Ce&&c.constructor!==qe&&e.add(c.parent)})}xe(s,r=>{na(t,t.deleteSet,i=>{if(i instanceof qe||!i.parent._hasFormatting||e.has(i.parent))return;const o=i.parent;i.content.constructor===Ce?e.add(o):zu(r,i)});for(const i of e)Hu(i)})},Ii=(t,e,s)=>{const r=s,i=tr(e.currentAttributes),o=e.right;for(;s>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case ht:case It:case nt:s<e.right.length&&xt(t,me(e.right.id.client,e.right.id.clock+s)),s-=e.right.length,e.right.delete(t);break}e.forward()}o&&Da(t,o,e.right,i,e.currentAttributes);const c=(e.left||e.right).parent;return c._searchMarker&&xs(c._searchMarker,e.index,-r+s),e};class Gu extends Tn{constructor(e,s,r){super(e,s),this.childListChanged=!1,this.keysChanged=new Set,r.forEach(i=>{i===null?this.childListChanged=!0:this.keysChanged.add(i)})}get changes(){if(this._changes===null){const e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){const e=this.target.doc,s=[];xe(e,r=>{const i=new Map,o=new Map;let c=this.target._start,l=null;const d={};let p="",g=0,u=0;const f=()=>{if(l!==null){let x=null;switch(l){case"delete":u>0&&(x={delete:u}),u=0;break;case"insert":(typeof p=="object"||p.length>0)&&(x={insert:p},i.size>0&&(x.attributes={},i.forEach((b,E)=>{b!==null&&(x.attributes[E]=b)}))),p="";break;case"retain":g>0&&(x={retain:g},Xc(d)||(x.attributes=Yc({},d))),g=0;break}x&&s.push(x),l=null}};for(;c!==null;){switch(c.content.constructor){case ht:case It:this.adds(c)?this.deletes(c)||(f(),l="insert",p=c.content.getContent()[0],f()):this.deletes(c)?(l!=="delete"&&(f(),l="delete"),u+=1):c.deleted||(l!=="retain"&&(f(),l="retain"),g+=1);break;case nt:this.adds(c)?this.deletes(c)||(l!=="insert"&&(f(),l="insert"),p+=c.content.str):this.deletes(c)?(l!=="delete"&&(f(),l="delete"),u+=c.length):c.deleted||(l!=="retain"&&(f(),l="retain"),g+=c.length);break;case Ce:{const{key:x,value:b}=c.content;if(this.adds(c)){if(!this.deletes(c)){const E=i.get(x)??null;mt(E,b)?b!==null&&c.delete(r):(l==="retain"&&f(),mt(b,o.get(x)??null)?delete d[x]:d[x]=b)}}else if(this.deletes(c)){o.set(x,b);const E=i.get(x)??null;mt(E,b)||(l==="retain"&&f(),d[x]=E)}else if(!c.deleted){o.set(x,b);const E=d[x];E!==void 0&&(mt(E,b)?E!==null&&c.delete(r):(l==="retain"&&f(),b===null?delete d[x]:d[x]=b))}c.deleted||(l==="insert"&&f(),ns(i,c.content));break}}c=c.right}for(f();s.length>0;){const x=s[s.length-1];if(x.retain!==void 0&&x.attributes===void 0)s.pop();else break}}),this._delta=s}return this._delta}}class Xt extends Oe{constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??We(),this._length}_integrate(e,s){super._integrate(e,s);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new Xt}clone(){const e=new Xt;return e.applyDelta(this.toDelta()),e}_callObserver(e,s){super._callObserver(e,s);const r=new Gu(this,e,s);An(this,e,r),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??We();let e="",s=this._start;for(;s!==null;)!s.deleted&&s.countable&&s.content.constructor===nt&&(e+=s.content.str),s=s.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:s=!0}={}){this.doc!==null?xe(this.doc,r=>{const i=new cr(null,this._start,0,new Map);for(let o=0;o<e.length;o++){const c=e[o];if(c.insert!==void 0){const l=!s&&typeof c.insert=="string"&&o===e.length-1&&i.right===null&&c.insert.slice(-1)===`
|
|
96
|
+
`?c.insert.slice(0,-1):c.insert;(typeof l!="string"||l.length>0)&&zn(r,this,i,l,c.attributes||{})}else c.retain!==void 0?Li(r,this,i,c.retain,c.attributes||{}):c.delete!==void 0&&Ii(r,i,c.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,s,r){this.doc??We();const i=[],o=new Map,c=this.doc;let l="",d=this._start;function p(){if(l.length>0){const u={};let f=!1;o.forEach((b,E)=>{f=!0,u[E]=b});const x={insert:l};f&&(x.attributes=u),i.push(x),l=""}}const g=()=>{for(;d!==null;){if(Bt(d,e)||s!==void 0&&Bt(d,s))switch(d.content.constructor){case nt:{const u=o.get("ychange");e!==void 0&&!Bt(d,e)?(u===void 0||u.user!==d.id.client||u.type!=="removed")&&(p(),o.set("ychange",r?r("removed",d.id):{type:"removed"})):s!==void 0&&!Bt(d,s)?(u===void 0||u.user!==d.id.client||u.type!=="added")&&(p(),o.set("ychange",r?r("added",d.id):{type:"added"})):u!==void 0&&(p(),o.delete("ychange")),l+=d.content.str;break}case ht:case It:{p();const u={insert:d.content.getContent()[0]};if(o.size>0){const f={};u.attributes=f,o.forEach((x,b)=>{f[b]=x})}i.push(u);break}case Ce:Bt(d,e)&&(p(),ns(o,d.content));break}d=d.right}p()};return e||s?xe(c,u=>{e&&ar(u,e),s&&ar(u,s),g()},"cleanup"):g(),i}insert(e,s,r){if(s.length<=0)return;const i=this.doc;i!==null?xe(i,o=>{const c=Ls(o,this,e,!r);r||(r={},c.currentAttributes.forEach((l,d)=>{r[d]=l})),zn(o,this,c,s,r)}):this._pending.push(()=>this.insert(e,s,r))}insertEmbed(e,s,r){const i=this.doc;i!==null?xe(i,o=>{const c=Ls(o,this,e,!r);zn(o,this,c,s,r||{})}):this._pending.push(()=>this.insertEmbed(e,s,r||{}))}delete(e,s){if(s===0)return;const r=this.doc;r!==null?xe(r,i=>{Ii(i,Ls(i,this,e,!0),s)}):this._pending.push(()=>this.delete(e,s))}format(e,s,r){if(s===0)return;const i=this.doc;i!==null?xe(i,o=>{const c=Ls(o,this,e,!1);c.right!==null&&Li(o,this,c,s,r)}):this._pending.push(()=>this.format(e,s,r))}removeAttribute(e){this.doc!==null?xe(this.doc,s=>{Zs(s,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,s){this.doc!==null?xe(this.doc,r=>{Xr(r,this,e,s)}):this._pending.push(()=>this.setAttribute(e,s))}getAttribute(e){return Qr(this,e)}getAttributes(){return Ta(this)}_write(e){e.writeTypeRef(hh)}}const qu=t=>new Xt;class Hn{constructor(e,s=()=>!0){this._filter=s,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??We()}[Symbol.iterator](){return this}next(){let e=this._currentNode,s=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(s)))do if(s=e.content.type,!e.deleted&&(s.constructor===Qt||s.constructor===Rt)&&s._start!==null)e=s._start;else for(;e!==null;){const r=e.next;if(r!==null){e=r;break}else e.parent===this._root?e=null:e=e.parent._item}while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}}class Rt extends Oe{constructor(){super(),this._prelimContent=[]}get firstChild(){const e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,s){super._integrate(e,s),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Rt}clone(){const e=new Rt;return e.insert(0,this.toArray().map(s=>s instanceof Oe?s.clone():s)),e}get length(){return this.doc??We(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new Hn(this,e)}querySelector(e){e=e.toUpperCase();const r=new Hn(this,i=>i.nodeName&&i.nodeName.toUpperCase()===e).next();return r.done?null:r.value}querySelectorAll(e){return e=e.toUpperCase(),lt(new Hn(this,s=>s.nodeName&&s.nodeName.toUpperCase()===e))}_callObserver(e,s){An(this,e,new Ju(this,s,e))}toString(){return Sa(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,s={},r){const i=e.createDocumentFragment();return r!==void 0&&r._createAssociation(i,this),ws(this,o=>{i.insertBefore(o.toDOM(e,s,r),null)}),i}insert(e,s){this.doc!==null?xe(this.doc,r=>{Na(r,this,e,s)}):this._prelimContent.splice(e,0,...s)}insertAfter(e,s){if(this.doc!==null)xe(this.doc,r=>{const i=e&&e instanceof Oe?e._item:e;Qs(r,this,i,s)});else{const r=this._prelimContent,i=e===null?0:r.findIndex(o=>o===e)+1;if(i===0&&e!==null)throw Ve("Reference item not found");r.splice(i,0,...s)}}delete(e,s=1){this.doc!==null?xe(this.doc,r=>{Ca(r,this,e,s)}):this._prelimContent.splice(e,s)}toArray(){return ka(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return ja(this,e)}slice(e=0,s=this.length){return _a(this,e,s)}forEach(e){ws(this,e)}_write(e){e.writeTypeRef(ph)}}const Yu=t=>new Rt;class Qt extends Rt{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,s){super._integrate(e,s),this._prelimAttrs.forEach((r,i)=>{this.setAttribute(i,r)}),this._prelimAttrs=null}_copy(){return new Qt(this.nodeName)}clone(){const e=new Qt(this.nodeName),s=this.getAttributes();return Jc(s,(r,i)=>{e.setAttribute(i,r)}),e.insert(0,this.toArray().map(r=>r instanceof Oe?r.clone():r)),e}toString(){const e=this.getAttributes(),s=[],r=[];for(const l in e)r.push(l);r.sort();const i=r.length;for(let l=0;l<i;l++){const d=r[l];s.push(d+'="'+e[d]+'"')}const o=this.nodeName.toLocaleLowerCase(),c=s.length>0?" "+s.join(" "):"";return`<${o}${c}>${super.toString()}</${o}>`}removeAttribute(e){this.doc!==null?xe(this.doc,s=>{Zs(s,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,s){this.doc!==null?xe(this.doc,r=>{Xr(r,this,e,s)}):this._prelimAttrs.set(e,s)}getAttribute(e){return Qr(this,e)}hasAttribute(e){return Ra(this,e)}getAttributes(e){return e?Pu(this,e):Ta(this)}toDOM(e=document,s={},r){const i=e.createElement(this.nodeName),o=this.getAttributes();for(const c in o){const l=o[c];typeof l=="string"&&i.setAttribute(c,l)}return ws(this,c=>{i.appendChild(c.toDOM(e,s,r))}),r!==void 0&&r._createAssociation(i,this),i}_write(e){e.writeTypeRef(fh),e.writeKey(this.nodeName)}}const Ku=t=>new Qt(t.readKey());class Ju extends Tn{constructor(e,s,r){super(e,r),this.childListChanged=!1,this.attributesChanged=new Set,s.forEach(i=>{i===null?this.childListChanged=!0:this.attributesChanged.add(i)})}}class en extends Tt{constructor(e){super(),this.hookName=e}_copy(){return new en(this.hookName)}clone(){const e=new en(this.hookName);return this.forEach((s,r)=>{e.set(r,s)}),e}toDOM(e=document,s={},r){const i=s[this.hookName];let o;return i!==void 0?o=i.createDom(this):o=document.createElement(this.hookName),o.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(o,this),o}_write(e){e.writeTypeRef(mh),e.writeKey(this.hookName)}}const Xu=t=>new en(t.readKey());class tn extends Xt{get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new tn}clone(){const e=new tn;return e.applyDelta(this.toDelta()),e}toDOM(e=document,s,r){const i=e.createTextNode(this.toString());return r!==void 0&&r._createAssociation(i,this),i}toString(){return this.toDelta().map(e=>{const s=[];for(const i in e.attributes){const o=[];for(const c in e.attributes[i])o.push({key:c,value:e.attributes[i][c]});o.sort((c,l)=>c.key<l.key?-1:1),s.push({nodeName:i,attrs:o})}s.sort((i,o)=>i.nodeName<o.nodeName?-1:1);let r="";for(let i=0;i<s.length;i++){const o=s[i];r+=`<${o.nodeName}`;for(let c=0;c<o.attrs.length;c++){const l=o.attrs[c];r+=` ${l.key}="${l.value}"`}r+=">"}r+=e.insert;for(let i=s.length-1;i>=0;i--)r+=`</${s[i].nodeName}>`;return r}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(gh)}}const Qu=t=>new tn;class Zr{constructor(e,s){this.id=e,this.length=s}get deleted(){throw Qe()}mergeWith(e){return!1}write(e,s,r){throw Qe()}integrate(e,s){throw Qe()}}const Zu=0;class qe extends Zr{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,s){s>0&&(this.id.clock+=s,this.length-=s),ga(e.doc.store,this)}write(e,s){e.writeInfo(Zu),e.writeLen(this.length-s)}getMissing(e,s){return null}}class Cs{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Cs(this.content)}splice(e){throw Qe()}mergeWith(e){return!1}integrate(e,s){}delete(e){}gc(e){}write(e,s){e.writeBuf(this.content)}getRef(){return 3}}const eh=t=>new Cs(t.readBuf());class vs{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new vs(this.len)}splice(e){const s=new vs(this.len-e);return this.len=e,s}mergeWith(e){return this.len+=e.len,!0}integrate(e,s){Js(e.deleteSet,s.id.client,s.id.clock,this.len),s.markDeleted()}delete(e){}gc(e){}write(e,s){e.writeLen(this.len-s)}getRef(){return 1}}const th=t=>new vs(t.readLen()),Ma=(t,e)=>new ss({guid:t,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1});class Ts{constructor(e){e._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=e;const s={};this.opts=s,e.gc||(s.gc=!1),e.autoLoad&&(s.autoLoad=!0),e.meta!==null&&(s.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new Ts(Ma(this.doc.guid,this.opts))}splice(e){throw Qe()}mergeWith(e){return!1}integrate(e,s){this.doc._item=s,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,s){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}}const sh=t=>new Ts(Ma(t.readString(),t.readAny()));class It{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new It(this.embed)}splice(e){throw Qe()}mergeWith(e){return!1}integrate(e,s){}delete(e){}gc(e){}write(e,s){e.writeJSON(this.embed)}getRef(){return 5}}const nh=t=>new It(t.readJSON());class Ce{constructor(e,s){this.key=e,this.value=s}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new Ce(this.key,this.value)}splice(e){throw Qe()}mergeWith(e){return!1}integrate(e,s){const r=s.parent;r._searchMarker=null,r._hasFormatting=!0}delete(e){}gc(e){}write(e,s){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}}const rh=t=>new Ce(t.readKey(),t.readJSON());class sn{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new sn(this.arr)}splice(e){const s=new sn(this.arr.slice(e));return this.arr=this.arr.slice(0,e),s}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,s){}delete(e){}gc(e){}write(e,s){const r=this.arr.length;e.writeLen(r-s);for(let i=s;i<r;i++){const o=this.arr[i];e.writeString(o===void 0?"undefined":JSON.stringify(o))}}getRef(){return 2}}const ih=t=>{const e=t.readLen(),s=[];for(let r=0;r<e;r++){const i=t.readString();i==="undefined"?s.push(void 0):s.push(JSON.parse(i))}return new sn(s)},oh=ys("node_env")==="development";class At{constructor(e){this.arr=e,oh&&Eo(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new At(this.arr)}splice(e){const s=new At(this.arr.slice(e));return this.arr=this.arr.slice(0,e),s}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,s){}delete(e){}gc(e){}write(e,s){const r=this.arr.length;e.writeLen(r-s);for(let i=s;i<r;i++){const o=this.arr[i];e.writeAny(o)}}getRef(){return 8}}const ah=t=>{const e=t.readLen(),s=[];for(let r=0;r<e;r++)s.push(t.readAny());return new At(s)};class nt{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new nt(this.str)}splice(e){const s=new nt(this.str.slice(e));this.str=this.str.slice(0,e);const r=this.str.charCodeAt(e-1);return r>=55296&&r<=56319&&(this.str=this.str.slice(0,e-1)+"�",s.str="�"+s.str.slice(1)),s}mergeWith(e){return this.str+=e.str,!0}integrate(e,s){}delete(e){}gc(e){}write(e,s){e.writeString(s===0?this.str:this.str.slice(s))}getRef(){return 4}}const lh=t=>new nt(t.readString()),ch=[Uu,$u,qu,Ku,Yu,Xu,Qu],dh=0,uh=1,hh=2,fh=3,ph=4,mh=5,gh=6;class ht{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new ht(this.type._copy())}splice(e){throw Qe()}mergeWith(e){return!1}integrate(e,s){this.type._integrate(e.doc,s)}delete(e){let s=this.type._start;for(;s!==null;)s.deleted?s.id.clock<(e.beforeState.get(s.id.client)||0)&&e._mergeStructs.push(s):s.delete(e),s=s.right;this.type._map.forEach(r=>{r.deleted?r.id.clock<(e.beforeState.get(r.id.client)||0)&&e._mergeStructs.push(r):r.delete(e)}),e.changed.delete(this.type)}gc(e){let s=this.type._start;for(;s!==null;)s.gc(e,!0),s=s.right;this.type._start=null,this.type._map.forEach(r=>{for(;r!==null;)r.gc(e,!0),r=r.left}),this.type._map=new Map}write(e,s){this.type._write(e)}getRef(){return 7}}const yh=t=>new ht(ch[t.readTypeRef()](t)),nn=(t,e,s)=>{const{client:r,clock:i}=e.id,o=new Ne(me(r,i+s),e,me(r,i+s-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(s));return e.deleted&&o.markDeleted(),e.keep&&(o.keep=!0),e.redone!==null&&(o.redone=me(e.redone.client,e.redone.clock+s)),e.right=o,o.right!==null&&(o.right.left=o),t._mergeStructs.push(o),o.parentSub!==null&&o.right===null&&o.parent._map.set(o.parentSub,o),e.length=s,o};class Ne extends Zr{constructor(e,s,r,i,o,c,l,d){super(e,d.getLength()),this.origin=r,this.left=s,this.right=i,this.rightOrigin=o,this.parent=c,this.parentSub=l,this.redone=null,this.content=d,this.info=this.content.isCountable()?di:0}set marker(e){(this.info&Mn)>0!==e&&(this.info^=Mn)}get marker(){return(this.info&Mn)>0}get keep(){return(this.info&ci)>0}set keep(e){this.keep!==e&&(this.info^=ci)}get countable(){return(this.info&di)>0}get deleted(){return(this.info&Dn)>0}set deleted(e){this.deleted!==e&&(this.info^=Dn)}markDeleted(){this.info|=Dn}getMissing(e,s){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=Le(s,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=Le(s,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===$t&&this.id.client!==this.parent.client&&this.parent.clock>=Le(s,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Ni(e,s,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=xt(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===qe||this.right&&this.right.constructor===qe)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===Ne?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===Ne&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===$t){const r=$n(s,this.parent);r.constructor===qe?this.parent=null:this.parent=r.content.type}return null}integrate(e,s){if(s>0&&(this.id.clock+=s,this.left=Ni(e,e.doc.store,me(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(s),this.length-=s),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let r=this.left,i;if(r!==null)i=r.right;else if(this.parentSub!==null)for(i=this.parent._map.get(this.parentSub)||null;i!==null&&i.left!==null;)i=i.left;else i=this.parent._start;const o=new Set,c=new Set;for(;i!==null&&i!==this.right;){if(c.add(i),o.add(i),Rs(this.origin,i.origin)){if(i.id.client<this.id.client)r=i,o.clear();else if(Rs(this.rightOrigin,i.rightOrigin))break}else if(i.origin!==null&&c.has($n(e.doc.store,i.origin)))o.has($n(e.doc.store,i.origin))||(r=i,o.clear());else break;i=i.right}this.left=r}if(this.left!==null){const r=this.left.right;this.right=r,this.left.right=this}else{let r;if(this.parentSub!==null)for(r=this.parent._map.get(this.parentSub)||null;r!==null&&r.left!==null;)r=r.left;else r=this.parent._start,this.parent._start=this;this.right=r}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(e)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),ga(e.doc.store,this),this.content.integrate(e,this),Ti(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new qe(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;e!==null&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;e!==null&&e.deleted;)e=e.left;return e}get lastId(){return this.length===1?this.id:me(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&Rs(e.origin,this.lastId)&&this.right===e&&Rs(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&this.redone===null&&e.redone===null&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){const s=this.parent._searchMarker;return s&&s.forEach(r=>{r.p===e&&(r.p=this,!this.deleted&&this.countable&&(r.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){const s=this.parent;this.countable&&this.parentSub===null&&(s._length-=this.length),this.markDeleted(),Js(e.deleteSet,this.id.client,this.id.clock,this.length),Ti(e,s,this.parentSub),this.content.delete(e)}}gc(e,s){if(!this.deleted)throw Xe();this.content.gc(e),s?_u(e,this,new qe(this.id,this.length)):this.content=new vs(this.length)}write(e,s){const r=s>0?me(this.id.client,this.id.clock+s-1):this.origin,i=this.rightOrigin,o=this.parentSub,c=this.content.getRef()&gn|(r===null?0:ze)|(i===null?0:ot)|(o===null?0:fs);if(e.writeInfo(c),r!==null&&e.writeLeftID(r),i!==null&&e.writeRightID(i),r===null&&i===null){const l=this.parent;if(l._item!==void 0){const d=l._item;if(d===null){const p=wu(l);e.writeParentInfo(!0),e.writeString(p)}else e.writeParentInfo(!1),e.writeLeftID(d.id)}else l.constructor===String?(e.writeParentInfo(!0),e.writeString(l)):l.constructor===$t?(e.writeParentInfo(!1),e.writeLeftID(l)):Xe();o!==null&&e.writeString(o)}this.content.write(e,s)}}const Oa=(t,e)=>bh[e&gn](t),bh=[()=>{Xe()},th,ih,eh,lh,nh,rh,yh,ah,sh,()=>{Xe()}],xh=10;class Ye extends Zr{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,s){Xe()}write(e,s){e.writeInfo(xh),ie(e.restEncoder,this.length-s)}getMissing(e,s){return null}}const Wa=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Pa="__ $YJS$ __";Wa[Pa]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Wa[Pa]=!0;const Dt=t=>qt((e,s)=>{t.onerror=r=>s(new Error(r.target.error)),t.onsuccess=r=>e(r.target.result)}),wh=(t,e)=>qt((s,r)=>{const i=indexedDB.open(t);i.onupgradeneeded=o=>e(o.target.result),i.onerror=o=>r(Ve(o.target.error)),i.onsuccess=o=>{const c=o.target.result;c.onversionchange=()=>{c.close()},s(c)}}),vh=t=>Dt(indexedDB.deleteDatabase(t)),_h=(t,e)=>e.forEach(s=>t.createObjectStore.apply(t,s)),as=(t,e,s="readwrite")=>{const r=t.transaction(e,s);return e.map(i=>Rh(r,i))},Ba=(t,e)=>Dt(t.count(e)),kh=(t,e)=>Dt(t.get(e)),Ua=(t,e)=>Dt(t.delete(e)),Sh=(t,e,s)=>Dt(t.put(e,s)),dr=(t,e)=>Dt(t.add(e)),jh=(t,e,s)=>Dt(t.getAll(e,s)),Eh=(t,e,s)=>{let r=null;return Th(t,e,i=>(r=i,!1),s).then(()=>r)},Nh=(t,e=null)=>Eh(t,e,"prev"),Ch=(t,e)=>qt((s,r)=>{t.onerror=r,t.onsuccess=async i=>{const o=i.target.result;if(o===null||await e(o)===!1)return s();o.continue()}}),Th=(t,e,s,r="next")=>Ch(t.openKeyCursor(e,r),i=>s(i.key)),Rh=(t,e)=>t.objectStore(e),Ah=(t,e)=>IDBKeyRange.upperBound(t,e),Lh=(t,e)=>IDBKeyRange.lowerBound(t,e),Vn="custom",Fa="updates",$a=500,za=(t,e=()=>{},s=()=>{})=>{const[r]=as(t.db,[Fa]);return jh(r,Lh(t._dbref,!1)).then(i=>{t._destroyed||(e(r),xe(t.doc,()=>{i.forEach(o=>ua(t.doc,o))},t,!1),s(r))}).then(()=>Nh(r).then(i=>{t._dbref=i+1})).then(()=>Ba(r).then(i=>{t._dbsize=i})).then(()=>r)},Ih=(t,e=!0)=>za(t).then(s=>{(e||t._dbsize>=$a)&&dr(s,Gr(t.doc)).then(()=>Ua(s,Ah(t._dbref,!0))).then(()=>Ba(s).then(r=>{t._dbsize=r}))});class Dh extends Cr{constructor(e,s){super(),this.doc=s,this.name=e,this._dbref=0,this._dbsize=0,this._destroyed=!1,this.db=null,this.synced=!1,this._db=wh(e,r=>_h(r,[["updates",{autoIncrement:!0}],["custom"]])),this.whenSynced=qt(r=>this.on("synced",()=>r(this))),this._db.then(r=>{this.db=r,za(this,c=>dr(c,Gr(s)),()=>{if(this._destroyed)return this;this.synced=!0,this.emit("synced",[this])})}),this._storeTimeout=1e3,this._storeTimeoutId=null,this._storeUpdate=(r,i)=>{if(this.db&&i!==this){const[o]=as(this.db,[Fa]);dr(o,r),++this._dbsize>=$a&&(this._storeTimeoutId!==null&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout(()=>{Ih(this,!1),this._storeTimeoutId=null},this._storeTimeout))}},s.on("update",this._storeUpdate),this.destroy=this.destroy.bind(this),s.on("destroy",this.destroy)}destroy(){return this._storeTimeoutId&&clearTimeout(this._storeTimeoutId),this.doc.off("update",this._storeUpdate),this.doc.off("destroy",this.destroy),this._destroyed=!0,this._db.then(e=>{e.close()})}clearData(){return this.destroy().then(()=>{vh(this.name)})}get(e){return this._db.then(s=>{const[r]=as(s,[Vn],"readonly");return kh(r,e)})}set(e,s){return this._db.then(r=>{const[i]=as(r,[Vn]);return Sh(i,s,e)})}del(e){return this._db.then(s=>{const[r]=as(s,[Vn]);return Ua(r,e)})}}const Mh=1200,Oh=2500,rn=3e4,ur=t=>{if(t.shouldConnect&&t.ws===null){const e=new WebSocket(t.url),s=t.binaryType;let r=null;s&&(e.binaryType=s),t.ws=e,t.connecting=!0,t.connected=!1,e.onmessage=c=>{t.lastMessageReceived=ct();const l=c.data,d=typeof l=="string"?JSON.parse(l):l;d&&d.type==="pong"&&(clearTimeout(r),r=setTimeout(o,rn/2)),t.emit("message",[d,t])};const i=c=>{t.ws!==null&&(t.ws=null,t.connecting=!1,t.connected?(t.connected=!1,t.emit("disconnect",[{type:"disconnect",error:c},t])):t.unsuccessfulReconnects++,setTimeout(ur,Tr(uc(t.unsuccessfulReconnects+1)*Mh,Oh),t)),clearTimeout(r)},o=()=>{t.ws===e&&t.send({type:"ping"})};e.onclose=()=>i(null),e.onerror=c=>i(c),e.onopen=()=>{t.lastMessageReceived=ct(),t.connecting=!1,t.connected=!0,t.unsuccessfulReconnects=0,t.emit("connect",[{type:"connect"},t]),r=setTimeout(o,rn/2)}}};class Wh extends Cr{constructor(e,{binaryType:s}={}){super(),this.url=e,this.ws=null,this.binaryType=s||null,this.connected=!1,this.connecting=!1,this.unsuccessfulReconnects=0,this.lastMessageReceived=0,this.shouldConnect=!0,this._checkInterval=setInterval(()=>{this.connected&&rn<ct()-this.lastMessageReceived&&this.ws.close()},rn/2),ur(this)}send(e){this.ws&&this.ws.send(JSON.stringify(e))}destroy(){clearInterval(this._checkInterval),this.disconnect(),super.destroy()}disconnect(){this.shouldConnect=!1,this.ws!==null&&this.ws.close()}connect(){this.shouldConnect=!0,!this.connected&&this.ws===null&&ur(this)}}const Ha=new Map;class Ph{constructor(e){this.room=e,this.onmessage=null,this._onChange=s=>s.key===e&&this.onmessage!==null&&this.onmessage({data:Lo(s.newValue||"")}),Vc(this._onChange)}postMessage(e){So.setItem(this.room,Ao(ld(e)))}close(){Gc(this._onChange)}}const Bh=typeof BroadcastChannel>"u"?Ph:BroadcastChannel,ei=t=>He(Ha,t,()=>{const e=bt(),s=new Bh(t);return s.onmessage=r=>e.forEach(i=>i(r.data,"broadcastchannel")),{bc:s,subs:e}}),Uh=(t,e)=>(ei(t).subs.add(e),e),Fh=(t,e)=>{const s=ei(t),r=s.subs.delete(e);return r&&s.subs.size===0&&(s.bc.close(),Ha.delete(t)),r},$h=(t,e,s=null)=>{const r=ei(t);r.bc.postMessage(e),r.subs.forEach(i=>i(e,s))},zh=()=>{let t=!0;return(e,s)=>{if(t){t=!1;try{e()}finally{t=!0}}else s!==void 0&&s()}};function Is(t){throw new Error('Could not dynamically require "'+t+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Gn={exports:{}},Di;function Hh(){return Di||(Di=1,(function(t,e){(function(s){t.exports=s()})(function(){var s=Math.floor,r=Math.abs,i=Math.pow;return(function(){function o(c,l,d){function p(f,x){if(!l[f]){if(!c[f]){var b=typeof Is=="function"&&Is;if(!x&&b)return b(f,!0);if(g)return g(f,!0);var E=new Error("Cannot find module '"+f+"'");throw E.code="MODULE_NOT_FOUND",E}var A=l[f]={exports:{}};c[f][0].call(A.exports,function(v){var L=c[f][1][v];return p(L||v)},A,A.exports,o,c,l,d)}return l[f].exports}for(var g=typeof Is=="function"&&Is,u=0;u<d.length;u++)p(d[u]);return p}return o})()({1:[function(o,c,l){function d(k){var _=k.length;if(0<_%4)throw new Error("Invalid string. Length must be a multiple of 4");var T=k.indexOf("=");T===-1&&(T=_);var S=T===_?0:4-T%4;return[T,S]}function p(k,_,T){return 3*(_+T)/4-T}function g(k){var _,T,S=d(k),N=S[0],D=S[1],j=new A(p(k,N,D)),R=0,O=0<D?N-4:N;for(T=0;T<O;T+=4)_=E[k.charCodeAt(T)]<<18|E[k.charCodeAt(T+1)]<<12|E[k.charCodeAt(T+2)]<<6|E[k.charCodeAt(T+3)],j[R++]=255&_>>16,j[R++]=255&_>>8,j[R++]=255&_;return D===2&&(_=E[k.charCodeAt(T)]<<2|E[k.charCodeAt(T+1)]>>4,j[R++]=255&_),D===1&&(_=E[k.charCodeAt(T)]<<10|E[k.charCodeAt(T+1)]<<4|E[k.charCodeAt(T+2)]>>2,j[R++]=255&_>>8,j[R++]=255&_),j}function u(k){return b[63&k>>18]+b[63&k>>12]+b[63&k>>6]+b[63&k]}function f(k,_,T){for(var S,N=[],D=_;D<T;D+=3)S=(16711680&k[D]<<16)+(65280&k[D+1]<<8)+(255&k[D+2]),N.push(u(S));return N.join("")}function x(k){for(var _,T=k.length,S=T%3,N=[],D=16383,j=0,R=T-S;j<R;j+=D)N.push(f(k,j,j+D>R?R:j+D));return S===1?(_=k[T-1],N.push(b[_>>2]+b[63&_<<4]+"==")):S===2&&(_=(k[T-2]<<8)+k[T-1],N.push(b[_>>10]+b[63&_>>4]+b[63&_<<2]+"=")),N.join("")}l.byteLength=function(k){var _=d(k),T=_[0],S=_[1];return 3*(T+S)/4-S},l.toByteArray=g,l.fromByteArray=x;for(var b=[],E=[],A=typeof Uint8Array>"u"?Array:Uint8Array,v="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",L=0,m=v.length;L<m;++L)b[L]=v[L],E[v.charCodeAt(L)]=L;E[45]=62,E[95]=63},{}],2:[function(){},{}],3:[function(o,c,l){(function(){(function(){var d=String.fromCharCode,p=Math.min;function g(a){if(2147483647<a)throw new RangeError('The value "'+a+'" is invalid for option "size"');var h=new Uint8Array(a);return h.__proto__=u.prototype,h}function u(a,h,y){if(typeof a=="number"){if(typeof h=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return E(a)}return f(a,h,y)}function f(a,h,y){if(typeof a=="string")return A(a,h);if(ArrayBuffer.isView(a))return v(a);if(a==null)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof a);if(M(a,ArrayBuffer)||a&&M(a.buffer,ArrayBuffer))return L(a,h,y);if(typeof a=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');var I=a.valueOf&&a.valueOf();if(I!=null&&I!==a)return u.from(I,h,y);var W=m(a);if(W)return W;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof a[Symbol.toPrimitive]=="function")return u.from(a[Symbol.toPrimitive]("string"),h,y);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof a)}function x(a){if(typeof a!="number")throw new TypeError('"size" argument must be of type number');if(0>a)throw new RangeError('The value "'+a+'" is invalid for option "size"')}function b(a,h,y){return x(a),0>=a||h===void 0?g(a):typeof y=="string"?g(a).fill(h,y):g(a).fill(h)}function E(a){return x(a),g(0>a?0:0|k(a))}function A(a,h){if((typeof h!="string"||h==="")&&(h="utf8"),!u.isEncoding(h))throw new TypeError("Unknown encoding: "+h);var y=0|_(a,h),I=g(y),W=I.write(a,h);return W!==y&&(I=I.slice(0,W)),I}function v(a){for(var h=0>a.length?0:0|k(a.length),y=g(h),I=0;I<h;I+=1)y[I]=255&a[I];return y}function L(a,h,y){if(0>h||a.byteLength<h)throw new RangeError('"offset" is outside of buffer bounds');if(a.byteLength<h+(y||0))throw new RangeError('"length" is outside of buffer bounds');var I;return I=h===void 0&&y===void 0?new Uint8Array(a):y===void 0?new Uint8Array(a,h):new Uint8Array(a,h,y),I.__proto__=u.prototype,I}function m(a){if(u.isBuffer(a)){var h=0|k(a.length),y=g(h);return y.length===0||a.copy(y,0,0,h),y}return a.length===void 0?a.type==="Buffer"&&Array.isArray(a.data)?v(a.data):void 0:typeof a.length!="number"||B(a.length)?g(0):v(a)}function k(a){if(a>=2147483647)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x7fffffff bytes");return 0|a}function _(a,h){if(u.isBuffer(a))return a.length;if(ArrayBuffer.isView(a)||M(a,ArrayBuffer))return a.byteLength;if(typeof a!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof a);var y=a.length,I=2<arguments.length&&arguments[2]===!0;if(!I&&y===0)return 0;for(var W=!1;;)switch(h){case"ascii":case"latin1":case"binary":return y;case"utf8":case"utf-8":return we(a).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*y;case"hex":return y>>>1;case"base64":return Z(a).length;default:if(W)return I?-1:we(a).length;h=(""+h).toLowerCase(),W=!0}}function T(a,h,y){var I=!1;if((h===void 0||0>h)&&(h=0),h>this.length||((y===void 0||y>this.length)&&(y=this.length),0>=y)||(y>>>=0,h>>>=0,y<=h))return"";for(a||(a="utf8");;)switch(a){case"hex":return re(this,h,y);case"utf8":case"utf-8":return P(this,h,y);case"ascii":return $(this,h,y);case"latin1":case"binary":return te(this,h,y);case"base64":return q(this,h,y);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Q(this,h,y);default:if(I)throw new TypeError("Unknown encoding: "+a);a=(a+"").toLowerCase(),I=!0}}function S(a,h,y){var I=a[h];a[h]=a[y],a[y]=I}function N(a,h,y,I,W){if(a.length===0)return-1;if(typeof y=="string"?(I=y,y=0):2147483647<y?y=2147483647:-2147483648>y&&(y=-2147483648),y=+y,B(y)&&(y=W?0:a.length-1),0>y&&(y=a.length+y),y>=a.length){if(W)return-1;y=a.length-1}else if(0>y)if(W)y=0;else return-1;if(typeof h=="string"&&(h=u.from(h,I)),u.isBuffer(h))return h.length===0?-1:D(a,h,y,I,W);if(typeof h=="number")return h&=255,typeof Uint8Array.prototype.indexOf=="function"?W?Uint8Array.prototype.indexOf.call(a,h,y):Uint8Array.prototype.lastIndexOf.call(a,h,y):D(a,[h],y,I,W);throw new TypeError("val must be string, number or Buffer")}function D(a,h,y,I,W){function F(Mt,rs){return ne===1?Mt[rs]:Mt.readUInt16BE(rs*ne)}var ne=1,fe=a.length,_e=h.length;if(I!==void 0&&(I=(I+"").toLowerCase(),I==="ucs2"||I==="ucs-2"||I==="utf16le"||I==="utf-16le")){if(2>a.length||2>h.length)return-1;ne=2,fe/=2,_e/=2,y/=2}var pe;if(W){var he=-1;for(pe=y;pe<fe;pe++)if(F(a,pe)!==F(h,he===-1?0:pe-he))he!==-1&&(pe-=pe-he),he=-1;else if(he===-1&&(he=pe),pe-he+1===_e)return he*ne}else for(y+_e>fe&&(y=fe-_e),pe=y;0<=pe;pe--){for(var Me=!0,vt=0;vt<_e;vt++)if(F(a,pe+vt)!==F(h,vt)){Me=!1;break}if(Me)return pe}return-1}function j(a,h,y,I){y=+y||0;var W=a.length-y;I?(I=+I,I>W&&(I=W)):I=W;var F=h.length;I>F/2&&(I=F/2);for(var ne,fe=0;fe<I;++fe){if(ne=parseInt(h.substr(2*fe,2),16),B(ne))return fe;a[y+fe]=ne}return fe}function R(a,h,y,I){return ae(we(h,a.length-y),a,y,I)}function O(a,h,y,I){return ae(K(h),a,y,I)}function U(a,h,y,I){return O(a,h,y,I)}function z(a,h,y,I){return ae(Z(h),a,y,I)}function G(a,h,y,I){return ae(Y(h,a.length-y),a,y,I)}function q(a,h,y){return h===0&&y===a.length?H.fromByteArray(a):H.fromByteArray(a.slice(h,y))}function P(a,h,y){y=p(a.length,y);for(var I=[],W=h;W<y;){var F=a[W],ne=null,fe=239<F?4:223<F?3:191<F?2:1;if(W+fe<=y){var _e,pe,he,Me;fe===1?128>F&&(ne=F):fe===2?(_e=a[W+1],(192&_e)==128&&(Me=(31&F)<<6|63&_e,127<Me&&(ne=Me))):fe===3?(_e=a[W+1],pe=a[W+2],(192&_e)==128&&(192&pe)==128&&(Me=(15&F)<<12|(63&_e)<<6|63&pe,2047<Me&&(55296>Me||57343<Me)&&(ne=Me))):fe===4&&(_e=a[W+1],pe=a[W+2],he=a[W+3],(192&_e)==128&&(192&pe)==128&&(192&he)==128&&(Me=(15&F)<<18|(63&_e)<<12|(63&pe)<<6|63&he,65535<Me&&1114112>Me&&(ne=Me)))}ne===null?(ne=65533,fe=1):65535<ne&&(ne-=65536,I.push(55296|1023&ne>>>10),ne=56320|1023&ne),I.push(ne),W+=fe}return V(I)}function V(a){var h=a.length;if(h<=4096)return d.apply(String,a);for(var y="",I=0;I<h;)y+=d.apply(String,a.slice(I,I+=4096));return y}function $(a,h,y){var I="";y=p(a.length,y);for(var W=h;W<y;++W)I+=d(127&a[W]);return I}function te(a,h,y){var I="";y=p(a.length,y);for(var W=h;W<y;++W)I+=d(a[W]);return I}function re(a,h,y){var I=a.length;(!h||0>h)&&(h=0),(!y||0>y||y>I)&&(y=I);for(var W="",F=h;F<y;++F)W+=be(a[F]);return W}function Q(a,h,y){for(var I=a.slice(h,y),W="",F=0;F<I.length;F+=2)W+=d(I[F]+256*I[F+1]);return W}function ee(a,h,y){if(a%1!=0||0>a)throw new RangeError("offset is not uint");if(a+h>y)throw new RangeError("Trying to access beyond buffer length")}function X(a,h,y,I,W,F){if(!u.isBuffer(a))throw new TypeError('"buffer" argument must be a Buffer instance');if(h>W||h<F)throw new RangeError('"value" argument is out of bounds');if(y+I>a.length)throw new RangeError("Index out of range")}function ve(a,h,y,I){if(y+I>a.length)throw new RangeError("Index out of range");if(0>y)throw new RangeError("Index out of range")}function Be(a,h,y,I,W){return h=+h,y>>>=0,W||ve(a,h,y,4),se.write(a,h,y,I,23,4),y+4}function ce(a,h,y,I,W){return h=+h,y>>>=0,W||ve(a,h,y,8),se.write(a,h,y,I,52,8),y+8}function ge(a){if(a=a.split("=")[0],a=a.trim().replace(C,""),2>a.length)return"";for(;a.length%4!=0;)a+="=";return a}function be(a){return 16>a?"0"+a.toString(16):a.toString(16)}function we(a,h){h=h||1/0;for(var y,I=a.length,W=null,F=[],ne=0;ne<I;++ne){if(y=a.charCodeAt(ne),55295<y&&57344>y){if(!W){if(56319<y){-1<(h-=3)&&F.push(239,191,189);continue}else if(ne+1===I){-1<(h-=3)&&F.push(239,191,189);continue}W=y;continue}if(56320>y){-1<(h-=3)&&F.push(239,191,189),W=y;continue}y=(W-55296<<10|y-56320)+65536}else W&&-1<(h-=3)&&F.push(239,191,189);if(W=null,128>y){if(0>(h-=1))break;F.push(y)}else if(2048>y){if(0>(h-=2))break;F.push(192|y>>6,128|63&y)}else if(65536>y){if(0>(h-=3))break;F.push(224|y>>12,128|63&y>>6,128|63&y)}else if(1114112>y){if(0>(h-=4))break;F.push(240|y>>18,128|63&y>>12,128|63&y>>6,128|63&y)}else throw new Error("Invalid code point")}return F}function K(a){for(var h=[],y=0;y<a.length;++y)h.push(255&a.charCodeAt(y));return h}function Y(a,h){for(var y,I,W,F=[],ne=0;ne<a.length&&!(0>(h-=2));++ne)y=a.charCodeAt(ne),I=y>>8,W=y%256,F.push(W),F.push(I);return F}function Z(a){return H.toByteArray(ge(a))}function ae(a,h,y,I){for(var W=0;W<I&&!(W+y>=h.length||W>=a.length);++W)h[W+y]=a[W];return W}function M(a,h){return a instanceof h||a!=null&&a.constructor!=null&&a.constructor.name!=null&&a.constructor.name===h.name}function B(a){return a!==a}var H=o("base64-js"),se=o("ieee754");l.Buffer=u,l.SlowBuffer=function(a){return+a!=a&&(a=0),u.alloc(+a)},l.INSPECT_MAX_BYTES=50,l.kMaxLength=2147483647,u.TYPED_ARRAY_SUPPORT=(function(){try{var a=new Uint8Array(1);return a.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},a.foo()===42}catch{return!1}})(),u.TYPED_ARRAY_SUPPORT||typeof console>"u"||typeof console.error!="function"||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(u.prototype,"parent",{enumerable:!0,get:function(){return u.isBuffer(this)?this.buffer:void 0}}),Object.defineProperty(u.prototype,"offset",{enumerable:!0,get:function(){return u.isBuffer(this)?this.byteOffset:void 0}}),typeof Symbol<"u"&&Symbol.species!=null&&u[Symbol.species]===u&&Object.defineProperty(u,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),u.poolSize=8192,u.from=function(a,h,y){return f(a,h,y)},u.prototype.__proto__=Uint8Array.prototype,u.__proto__=Uint8Array,u.alloc=function(a,h,y){return b(a,h,y)},u.allocUnsafe=function(a){return E(a)},u.allocUnsafeSlow=function(a){return E(a)},u.isBuffer=function(a){return a!=null&&a._isBuffer===!0&&a!==u.prototype},u.compare=function(a,h){if(M(a,Uint8Array)&&(a=u.from(a,a.offset,a.byteLength)),M(h,Uint8Array)&&(h=u.from(h,h.offset,h.byteLength)),!u.isBuffer(a)||!u.isBuffer(h))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(a===h)return 0;for(var y=a.length,I=h.length,W=0,F=p(y,I);W<F;++W)if(a[W]!==h[W]){y=a[W],I=h[W];break}return y<I?-1:I<y?1:0},u.isEncoding=function(a){switch((a+"").toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},u.concat=function(a,h){if(!Array.isArray(a))throw new TypeError('"list" argument must be an Array of Buffers');if(a.length===0)return u.alloc(0);var y;if(h===void 0)for(h=0,y=0;y<a.length;++y)h+=a[y].length;var I=u.allocUnsafe(h),W=0;for(y=0;y<a.length;++y){var F=a[y];if(M(F,Uint8Array)&&(F=u.from(F)),!u.isBuffer(F))throw new TypeError('"list" argument must be an Array of Buffers');F.copy(I,W),W+=F.length}return I},u.byteLength=_,u.prototype._isBuffer=!0,u.prototype.swap16=function(){var a=this.length;if(a%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var h=0;h<a;h+=2)S(this,h,h+1);return this},u.prototype.swap32=function(){var a=this.length;if(a%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var h=0;h<a;h+=4)S(this,h,h+3),S(this,h+1,h+2);return this},u.prototype.swap64=function(){var a=this.length;if(a%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var h=0;h<a;h+=8)S(this,h,h+7),S(this,h+1,h+6),S(this,h+2,h+5),S(this,h+3,h+4);return this},u.prototype.toString=function(){var a=this.length;return a===0?"":arguments.length===0?P(this,0,a):T.apply(this,arguments)},u.prototype.toLocaleString=u.prototype.toString,u.prototype.equals=function(a){if(!u.isBuffer(a))throw new TypeError("Argument must be a Buffer");return this===a||u.compare(this,a)===0},u.prototype.inspect=function(){var a="",h=l.INSPECT_MAX_BYTES;return a=this.toString("hex",0,h).replace(/(.{2})/g,"$1 ").trim(),this.length>h&&(a+=" ... "),"<Buffer "+a+">"},u.prototype.compare=function(a,h,y,I,W){if(M(a,Uint8Array)&&(a=u.from(a,a.offset,a.byteLength)),!u.isBuffer(a))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof a);if(h===void 0&&(h=0),y===void 0&&(y=a?a.length:0),I===void 0&&(I=0),W===void 0&&(W=this.length),0>h||y>a.length||0>I||W>this.length)throw new RangeError("out of range index");if(I>=W&&h>=y)return 0;if(I>=W)return-1;if(h>=y)return 1;if(h>>>=0,y>>>=0,I>>>=0,W>>>=0,this===a)return 0;for(var F=W-I,ne=y-h,fe=p(F,ne),_e=this.slice(I,W),pe=a.slice(h,y),he=0;he<fe;++he)if(_e[he]!==pe[he]){F=_e[he],ne=pe[he];break}return F<ne?-1:ne<F?1:0},u.prototype.includes=function(a,h,y){return this.indexOf(a,h,y)!==-1},u.prototype.indexOf=function(a,h,y){return N(this,a,h,y,!0)},u.prototype.lastIndexOf=function(a,h,y){return N(this,a,h,y,!1)},u.prototype.write=function(a,h,y,I){if(h===void 0)I="utf8",y=this.length,h=0;else if(y===void 0&&typeof h=="string")I=h,y=this.length,h=0;else if(isFinite(h))h>>>=0,isFinite(y)?(y>>>=0,I===void 0&&(I="utf8")):(I=y,y=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var W=this.length-h;if((y===void 0||y>W)&&(y=W),0<a.length&&(0>y||0>h)||h>this.length)throw new RangeError("Attempt to write outside buffer bounds");I||(I="utf8");for(var F=!1;;)switch(I){case"hex":return j(this,a,h,y);case"utf8":case"utf-8":return R(this,a,h,y);case"ascii":return O(this,a,h,y);case"latin1":case"binary":return U(this,a,h,y);case"base64":return z(this,a,h,y);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return G(this,a,h,y);default:if(F)throw new TypeError("Unknown encoding: "+I);I=(""+I).toLowerCase(),F=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},u.prototype.slice=function(a,h){var y=this.length;a=~~a,h=h===void 0?y:~~h,0>a?(a+=y,0>a&&(a=0)):a>y&&(a=y),0>h?(h+=y,0>h&&(h=0)):h>y&&(h=y),h<a&&(h=a);var I=this.subarray(a,h);return I.__proto__=u.prototype,I},u.prototype.readUIntLE=function(a,h,y){a>>>=0,h>>>=0,y||ee(a,h,this.length);for(var I=this[a],W=1,F=0;++F<h&&(W*=256);)I+=this[a+F]*W;return I},u.prototype.readUIntBE=function(a,h,y){a>>>=0,h>>>=0,y||ee(a,h,this.length);for(var I=this[a+--h],W=1;0<h&&(W*=256);)I+=this[a+--h]*W;return I},u.prototype.readUInt8=function(a,h){return a>>>=0,h||ee(a,1,this.length),this[a]},u.prototype.readUInt16LE=function(a,h){return a>>>=0,h||ee(a,2,this.length),this[a]|this[a+1]<<8},u.prototype.readUInt16BE=function(a,h){return a>>>=0,h||ee(a,2,this.length),this[a]<<8|this[a+1]},u.prototype.readUInt32LE=function(a,h){return a>>>=0,h||ee(a,4,this.length),(this[a]|this[a+1]<<8|this[a+2]<<16)+16777216*this[a+3]},u.prototype.readUInt32BE=function(a,h){return a>>>=0,h||ee(a,4,this.length),16777216*this[a]+(this[a+1]<<16|this[a+2]<<8|this[a+3])},u.prototype.readIntLE=function(a,h,y){a>>>=0,h>>>=0,y||ee(a,h,this.length);for(var I=this[a],W=1,F=0;++F<h&&(W*=256);)I+=this[a+F]*W;return W*=128,I>=W&&(I-=i(2,8*h)),I},u.prototype.readIntBE=function(a,h,y){a>>>=0,h>>>=0,y||ee(a,h,this.length);for(var I=h,W=1,F=this[a+--I];0<I&&(W*=256);)F+=this[a+--I]*W;return W*=128,F>=W&&(F-=i(2,8*h)),F},u.prototype.readInt8=function(a,h){return a>>>=0,h||ee(a,1,this.length),128&this[a]?-1*(255-this[a]+1):this[a]},u.prototype.readInt16LE=function(a,h){a>>>=0,h||ee(a,2,this.length);var y=this[a]|this[a+1]<<8;return 32768&y?4294901760|y:y},u.prototype.readInt16BE=function(a,h){a>>>=0,h||ee(a,2,this.length);var y=this[a+1]|this[a]<<8;return 32768&y?4294901760|y:y},u.prototype.readInt32LE=function(a,h){return a>>>=0,h||ee(a,4,this.length),this[a]|this[a+1]<<8|this[a+2]<<16|this[a+3]<<24},u.prototype.readInt32BE=function(a,h){return a>>>=0,h||ee(a,4,this.length),this[a]<<24|this[a+1]<<16|this[a+2]<<8|this[a+3]},u.prototype.readFloatLE=function(a,h){return a>>>=0,h||ee(a,4,this.length),se.read(this,a,!0,23,4)},u.prototype.readFloatBE=function(a,h){return a>>>=0,h||ee(a,4,this.length),se.read(this,a,!1,23,4)},u.prototype.readDoubleLE=function(a,h){return a>>>=0,h||ee(a,8,this.length),se.read(this,a,!0,52,8)},u.prototype.readDoubleBE=function(a,h){return a>>>=0,h||ee(a,8,this.length),se.read(this,a,!1,52,8)},u.prototype.writeUIntLE=function(a,h,y,I){if(a=+a,h>>>=0,y>>>=0,!I){var W=i(2,8*y)-1;X(this,a,h,y,W,0)}var F=1,ne=0;for(this[h]=255&a;++ne<y&&(F*=256);)this[h+ne]=255&a/F;return h+y},u.prototype.writeUIntBE=function(a,h,y,I){if(a=+a,h>>>=0,y>>>=0,!I){var W=i(2,8*y)-1;X(this,a,h,y,W,0)}var F=y-1,ne=1;for(this[h+F]=255&a;0<=--F&&(ne*=256);)this[h+F]=255&a/ne;return h+y},u.prototype.writeUInt8=function(a,h,y){return a=+a,h>>>=0,y||X(this,a,h,1,255,0),this[h]=255&a,h+1},u.prototype.writeUInt16LE=function(a,h,y){return a=+a,h>>>=0,y||X(this,a,h,2,65535,0),this[h]=255&a,this[h+1]=a>>>8,h+2},u.prototype.writeUInt16BE=function(a,h,y){return a=+a,h>>>=0,y||X(this,a,h,2,65535,0),this[h]=a>>>8,this[h+1]=255&a,h+2},u.prototype.writeUInt32LE=function(a,h,y){return a=+a,h>>>=0,y||X(this,a,h,4,4294967295,0),this[h+3]=a>>>24,this[h+2]=a>>>16,this[h+1]=a>>>8,this[h]=255&a,h+4},u.prototype.writeUInt32BE=function(a,h,y){return a=+a,h>>>=0,y||X(this,a,h,4,4294967295,0),this[h]=a>>>24,this[h+1]=a>>>16,this[h+2]=a>>>8,this[h+3]=255&a,h+4},u.prototype.writeIntLE=function(a,h,y,I){if(a=+a,h>>>=0,!I){var W=i(2,8*y-1);X(this,a,h,y,W-1,-W)}var F=0,ne=1,fe=0;for(this[h]=255&a;++F<y&&(ne*=256);)0>a&&fe===0&&this[h+F-1]!==0&&(fe=1),this[h+F]=255&(a/ne>>0)-fe;return h+y},u.prototype.writeIntBE=function(a,h,y,I){if(a=+a,h>>>=0,!I){var W=i(2,8*y-1);X(this,a,h,y,W-1,-W)}var F=y-1,ne=1,fe=0;for(this[h+F]=255&a;0<=--F&&(ne*=256);)0>a&&fe===0&&this[h+F+1]!==0&&(fe=1),this[h+F]=255&(a/ne>>0)-fe;return h+y},u.prototype.writeInt8=function(a,h,y){return a=+a,h>>>=0,y||X(this,a,h,1,127,-128),0>a&&(a=255+a+1),this[h]=255&a,h+1},u.prototype.writeInt16LE=function(a,h,y){return a=+a,h>>>=0,y||X(this,a,h,2,32767,-32768),this[h]=255&a,this[h+1]=a>>>8,h+2},u.prototype.writeInt16BE=function(a,h,y){return a=+a,h>>>=0,y||X(this,a,h,2,32767,-32768),this[h]=a>>>8,this[h+1]=255&a,h+2},u.prototype.writeInt32LE=function(a,h,y){return a=+a,h>>>=0,y||X(this,a,h,4,2147483647,-2147483648),this[h]=255&a,this[h+1]=a>>>8,this[h+2]=a>>>16,this[h+3]=a>>>24,h+4},u.prototype.writeInt32BE=function(a,h,y){return a=+a,h>>>=0,y||X(this,a,h,4,2147483647,-2147483648),0>a&&(a=4294967295+a+1),this[h]=a>>>24,this[h+1]=a>>>16,this[h+2]=a>>>8,this[h+3]=255&a,h+4},u.prototype.writeFloatLE=function(a,h,y){return Be(this,a,h,!0,y)},u.prototype.writeFloatBE=function(a,h,y){return Be(this,a,h,!1,y)},u.prototype.writeDoubleLE=function(a,h,y){return ce(this,a,h,!0,y)},u.prototype.writeDoubleBE=function(a,h,y){return ce(this,a,h,!1,y)},u.prototype.copy=function(a,h,y,I){if(!u.isBuffer(a))throw new TypeError("argument should be a Buffer");if(y||(y=0),I||I===0||(I=this.length),h>=a.length&&(h=a.length),h||(h=0),0<I&&I<y&&(I=y),I===y||a.length===0||this.length===0)return 0;if(0>h)throw new RangeError("targetStart out of bounds");if(0>y||y>=this.length)throw new RangeError("Index out of range");if(0>I)throw new RangeError("sourceEnd out of bounds");I>this.length&&(I=this.length),a.length-h<I-y&&(I=a.length-h+y);var W=I-y;if(this===a&&typeof Uint8Array.prototype.copyWithin=="function")this.copyWithin(h,y,I);else if(this===a&&y<h&&h<I)for(var F=W-1;0<=F;--F)a[F+h]=this[F+y];else Uint8Array.prototype.set.call(a,this.subarray(y,I),h);return W},u.prototype.fill=function(a,h,y,I){if(typeof a=="string"){if(typeof h=="string"?(I=h,h=0,y=this.length):typeof y=="string"&&(I=y,y=this.length),I!==void 0&&typeof I!="string")throw new TypeError("encoding must be a string");if(typeof I=="string"&&!u.isEncoding(I))throw new TypeError("Unknown encoding: "+I);if(a.length===1){var W=a.charCodeAt(0);(I==="utf8"&&128>W||I==="latin1")&&(a=W)}}else typeof a=="number"&&(a&=255);if(0>h||this.length<h||this.length<y)throw new RangeError("Out of range index");if(y<=h)return this;h>>>=0,y=y===void 0?this.length:y>>>0,a||(a=0);var F;if(typeof a=="number")for(F=h;F<y;++F)this[F]=a;else{var ne=u.isBuffer(a)?a:u.from(a,I),fe=ne.length;if(fe===0)throw new TypeError('The value "'+a+'" is invalid for argument "value"');for(F=0;F<y-h;++F)this[F+h]=ne[F%fe]}return this};var C=/[^+/0-9A-Za-z-_]/g}).call(this)}).call(this,o("buffer").Buffer)},{"base64-js":1,buffer:3,ieee754:9}],4:[function(o,c,l){(function(d){(function(){function p(){let u;try{u=l.storage.getItem("debug")}catch{}return!u&&typeof d<"u"&&"env"in d&&(u=d.env.DEBUG),u}l.formatArgs=function(u){if(u[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+u[0]+(this.useColors?"%c ":" ")+"+"+c.exports.humanize(this.diff),!this.useColors)return;const f="color: "+this.color;u.splice(1,0,f,"color: inherit");let x=0,b=0;u[0].replace(/%[a-zA-Z%]/g,E=>{E==="%%"||(x++,E==="%c"&&(b=x))}),u.splice(b,0,f)},l.save=function(u){try{u?l.storage.setItem("debug",u):l.storage.removeItem("debug")}catch{}},l.load=p,l.useColors=function(){return!!(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))||!(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&(typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&31<=parseInt(RegExp.$1,10)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))},l.storage=(function(){try{return localStorage}catch{}})(),l.destroy=(()=>{let u=!1;return()=>{u||(u=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),l.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],l.log=console.debug||console.log||(()=>{}),c.exports=o("./common")(l);const{formatters:g}=c.exports;g.j=function(u){try{return JSON.stringify(u)}catch(f){return"[UnexpectedJSONParseError]: "+f.message}}}).call(this)}).call(this,o("_process"))},{"./common":5,_process:12}],5:[function(o,c){c.exports=function(l){function d(u){function f(...E){if(!f.enabled)return;const A=f,v=+new Date,L=v-(x||v);A.diff=L,A.prev=x,A.curr=v,x=v,E[0]=d.coerce(E[0]),typeof E[0]!="string"&&E.unshift("%O");let m=0;E[0]=E[0].replace(/%([a-zA-Z%])/g,(_,T)=>{if(_==="%%")return"%";m++;const S=d.formatters[T];if(typeof S=="function"){const N=E[m];_=S.call(A,N),E.splice(m,1),m--}return _}),d.formatArgs.call(A,E),(A.log||d.log).apply(A,E)}let x,b=null;return f.namespace=u,f.useColors=d.useColors(),f.color=d.selectColor(u),f.extend=p,f.destroy=d.destroy,Object.defineProperty(f,"enabled",{enumerable:!0,configurable:!1,get:()=>b===null?d.enabled(u):b,set:E=>{b=E}}),typeof d.init=="function"&&d.init(f),f}function p(u,f){const x=d(this.namespace+(typeof f>"u"?":":f)+u);return x.log=this.log,x}function g(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}return d.debug=d,d.default=d,d.coerce=function(u){return u instanceof Error?u.stack||u.message:u},d.disable=function(){const u=[...d.names.map(g),...d.skips.map(g).map(f=>"-"+f)].join(",");return d.enable(""),u},d.enable=function(u){d.save(u),d.names=[],d.skips=[];let f;const x=(typeof u=="string"?u:"").split(/[\s,]+/),b=x.length;for(f=0;f<b;f++)x[f]&&(u=x[f].replace(/\*/g,".*?"),u[0]==="-"?d.skips.push(new RegExp("^"+u.substr(1)+"$")):d.names.push(new RegExp("^"+u+"$")))},d.enabled=function(u){if(u[u.length-1]==="*")return!0;let f,x;for(f=0,x=d.skips.length;f<x;f++)if(d.skips[f].test(u))return!1;for(f=0,x=d.names.length;f<x;f++)if(d.names[f].test(u))return!0;return!1},d.humanize=o("ms"),d.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(l).forEach(u=>{d[u]=l[u]}),d.names=[],d.skips=[],d.formatters={},d.selectColor=function(u){let f=0;for(let x=0;x<u.length;x++)f=(f<<5)-f+u.charCodeAt(x),f|=0;return d.colors[r(f)%d.colors.length]},d.enable(d.load()),d}},{ms:11}],6:[function(o,c){function l(d,p){for(const g in p)Object.defineProperty(d,g,{value:p[g],enumerable:!0,configurable:!0});return d}c.exports=function(d,p,g){if(!d||typeof d=="string")throw new TypeError("Please pass an Error to err-code");g||(g={}),typeof p=="object"&&(g=p,p=""),p&&(g.code=p);try{return l(d,g)}catch{g.message=d.message,g.stack=d.stack;const f=function(){};return f.prototype=Object.create(Object.getPrototypeOf(d)),l(new f,g)}}},{}],7:[function(o,c){function l(j){console&&console.warn&&console.warn(j)}function d(){d.init.call(this)}function p(j){if(typeof j!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof j)}function g(j){return j._maxListeners===void 0?d.defaultMaxListeners:j._maxListeners}function u(j,R,O,U){var z,G,q;if(p(O),G=j._events,G===void 0?(G=j._events=Object.create(null),j._eventsCount=0):(G.newListener!==void 0&&(j.emit("newListener",R,O.listener?O.listener:O),G=j._events),q=G[R]),q===void 0)q=G[R]=O,++j._eventsCount;else if(typeof q=="function"?q=G[R]=U?[O,q]:[q,O]:U?q.unshift(O):q.push(O),z=g(j),0<z&&q.length>z&&!q.warned){q.warned=!0;var P=new Error("Possible EventEmitter memory leak detected. "+q.length+" "+(R+" listeners added. Use emitter.setMaxListeners() to increase limit"));P.name="MaxListenersExceededWarning",P.emitter=j,P.type=R,P.count=q.length,l(P)}return j}function f(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function x(j,R,O){var U={fired:!1,wrapFn:void 0,target:j,type:R,listener:O},z=f.bind(U);return z.listener=O,U.wrapFn=z,z}function b(j,R,O){var U=j._events;if(U===void 0)return[];var z=U[R];return z===void 0?[]:typeof z=="function"?O?[z.listener||z]:[z]:O?L(z):A(z,z.length)}function E(j){var R=this._events;if(R!==void 0){var O=R[j];if(typeof O=="function")return 1;if(O!==void 0)return O.length}return 0}function A(j,R){for(var O=Array(R),U=0;U<R;++U)O[U]=j[U];return O}function v(j,R){for(;R+1<j.length;R++)j[R]=j[R+1];j.pop()}function L(j){for(var R=Array(j.length),O=0;O<R.length;++O)R[O]=j[O].listener||j[O];return R}function m(j,R,O){typeof j.on=="function"&&k(j,"error",R,O)}function k(j,R,O,U){if(typeof j.on=="function")U.once?j.once(R,O):j.on(R,O);else if(typeof j.addEventListener=="function")j.addEventListener(R,function z(G){U.once&&j.removeEventListener(R,z),O(G)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof j)}var _,T=typeof Reflect=="object"?Reflect:null,S=T&&typeof T.apply=="function"?T.apply:function(j,R,O){return Function.prototype.apply.call(j,R,O)};_=T&&typeof T.ownKeys=="function"?T.ownKeys:Object.getOwnPropertySymbols?function(j){return Object.getOwnPropertyNames(j).concat(Object.getOwnPropertySymbols(j))}:function(j){return Object.getOwnPropertyNames(j)};var N=Number.isNaN||function(j){return j!==j};c.exports=d,c.exports.once=function(j,R){return new Promise(function(O,U){function z(q){j.removeListener(R,G),U(q)}function G(){typeof j.removeListener=="function"&&j.removeListener("error",z),O([].slice.call(arguments))}k(j,R,G,{once:!0}),R!=="error"&&m(j,z,{once:!0})})},d.EventEmitter=d,d.prototype._events=void 0,d.prototype._eventsCount=0,d.prototype._maxListeners=void 0;var D=10;Object.defineProperty(d,"defaultMaxListeners",{enumerable:!0,get:function(){return D},set:function(j){if(typeof j!="number"||0>j||N(j))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+j+".");D=j}}),d.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},d.prototype.setMaxListeners=function(j){if(typeof j!="number"||0>j||N(j))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+j+".");return this._maxListeners=j,this},d.prototype.getMaxListeners=function(){return g(this)},d.prototype.emit=function(j){for(var R=[],O=1;O<arguments.length;O++)R.push(arguments[O]);var U=j==="error",z=this._events;if(z!==void 0)U=U&&z.error===void 0;else if(!U)return!1;if(U){var G;if(0<R.length&&(G=R[0]),G instanceof Error)throw G;var q=new Error("Unhandled error."+(G?" ("+G.message+")":""));throw q.context=G,q}var P=z[j];if(P===void 0)return!1;if(typeof P=="function")S(P,this,R);else for(var V=P.length,$=A(P,V),O=0;O<V;++O)S($[O],this,R);return!0},d.prototype.addListener=function(j,R){return u(this,j,R,!1)},d.prototype.on=d.prototype.addListener,d.prototype.prependListener=function(j,R){return u(this,j,R,!0)},d.prototype.once=function(j,R){return p(R),this.on(j,x(this,j,R)),this},d.prototype.prependOnceListener=function(j,R){return p(R),this.prependListener(j,x(this,j,R)),this},d.prototype.removeListener=function(j,R){var O,U,z,G,q;if(p(R),U=this._events,U===void 0)return this;if(O=U[j],O===void 0)return this;if(O===R||O.listener===R)--this._eventsCount==0?this._events=Object.create(null):(delete U[j],U.removeListener&&this.emit("removeListener",j,O.listener||R));else if(typeof O!="function"){for(z=-1,G=O.length-1;0<=G;G--)if(O[G]===R||O[G].listener===R){q=O[G].listener,z=G;break}if(0>z)return this;z===0?O.shift():v(O,z),O.length===1&&(U[j]=O[0]),U.removeListener!==void 0&&this.emit("removeListener",j,q||R)}return this},d.prototype.off=d.prototype.removeListener,d.prototype.removeAllListeners=function(j){var R,O,U;if(O=this._events,O===void 0)return this;if(O.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):O[j]!==void 0&&(--this._eventsCount==0?this._events=Object.create(null):delete O[j]),this;if(arguments.length===0){var z,G=Object.keys(O);for(U=0;U<G.length;++U)z=G[U],z!=="removeListener"&&this.removeAllListeners(z);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(R=O[j],typeof R=="function")this.removeListener(j,R);else if(R!==void 0)for(U=R.length-1;0<=U;U--)this.removeListener(j,R[U]);return this},d.prototype.listeners=function(j){return b(this,j,!0)},d.prototype.rawListeners=function(j){return b(this,j,!1)},d.listenerCount=function(j,R){return typeof j.listenerCount=="function"?j.listenerCount(R):E.call(j,R)},d.prototype.listenerCount=E,d.prototype.eventNames=function(){return 0<this._eventsCount?_(this._events):[]}},{}],8:[function(o,c){c.exports=function(){if(typeof globalThis>"u")return null;var l={RTCPeerConnection:globalThis.RTCPeerConnection||globalThis.mozRTCPeerConnection||globalThis.webkitRTCPeerConnection,RTCSessionDescription:globalThis.RTCSessionDescription||globalThis.mozRTCSessionDescription||globalThis.webkitRTCSessionDescription,RTCIceCandidate:globalThis.RTCIceCandidate||globalThis.mozRTCIceCandidate||globalThis.webkitRTCIceCandidate};return l.RTCPeerConnection?l:null}},{}],9:[function(o,c,l){/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */l.read=function(d,p,g,u,f){var x,b,E=8*f-u-1,A=(1<<E)-1,v=A>>1,L=-7,m=g?f-1:0,k=g?-1:1,_=d[p+m];for(m+=k,x=_&(1<<-L)-1,_>>=-L,L+=E;0<L;x=256*x+d[p+m],m+=k,L-=8);for(b=x&(1<<-L)-1,x>>=-L,L+=u;0<L;b=256*b+d[p+m],m+=k,L-=8);if(x===0)x=1-v;else{if(x===A)return b?NaN:(_?-1:1)*(1/0);b+=i(2,u),x-=v}return(_?-1:1)*b*i(2,x-u)},l.write=function(d,p,g,u,f,x){var b,E,A,v=Math.LN2,L=Math.log,m=8*x-f-1,k=(1<<m)-1,_=k>>1,T=f===23?i(2,-24)-i(2,-77):0,S=u?0:x-1,N=u?1:-1,D=0>p||p===0&&0>1/p?1:0;for(p=r(p),isNaN(p)||p===1/0?(E=isNaN(p)?1:0,b=k):(b=s(L(p)/v),1>p*(A=i(2,-b))&&(b--,A*=2),p+=1<=b+_?T/A:T*i(2,1-_),2<=p*A&&(b++,A/=2),b+_>=k?(E=0,b=k):1<=b+_?(E=(p*A-1)*i(2,f),b+=_):(E=p*i(2,_-1)*i(2,f),b=0));8<=f;d[g+S]=255&E,S+=N,E/=256,f-=8);for(b=b<<f|E,m+=f;0<m;d[g+S]=255&b,S+=N,b/=256,m-=8);d[g+S-N]|=128*D}},{}],10:[function(o,c){c.exports=typeof Object.create=="function"?function(l,d){d&&(l.super_=d,l.prototype=Object.create(d.prototype,{constructor:{value:l,enumerable:!1,writable:!0,configurable:!0}}))}:function(l,d){if(d){l.super_=d;var p=function(){};p.prototype=d.prototype,l.prototype=new p,l.prototype.constructor=l}}},{}],11:[function(o,c){var l=Math.round;function d(f){if(f+="",!(100<f.length)){var x=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(f);if(x){var b=parseFloat(x[1]),E=(x[2]||"ms").toLowerCase();return E==="years"||E==="year"||E==="yrs"||E==="yr"||E==="y"?315576e5*b:E==="weeks"||E==="week"||E==="w"?6048e5*b:E==="days"||E==="day"||E==="d"?864e5*b:E==="hours"||E==="hour"||E==="hrs"||E==="hr"||E==="h"?36e5*b:E==="minutes"||E==="minute"||E==="mins"||E==="min"||E==="m"?6e4*b:E==="seconds"||E==="second"||E==="secs"||E==="sec"||E==="s"?1e3*b:E==="milliseconds"||E==="millisecond"||E==="msecs"||E==="msec"||E==="ms"?b:void 0}}}function p(f){var x=r(f);return 864e5<=x?l(f/864e5)+"d":36e5<=x?l(f/36e5)+"h":6e4<=x?l(f/6e4)+"m":1e3<=x?l(f/1e3)+"s":f+"ms"}function g(f){var x=r(f);return 864e5<=x?u(f,x,864e5,"day"):36e5<=x?u(f,x,36e5,"hour"):6e4<=x?u(f,x,6e4,"minute"):1e3<=x?u(f,x,1e3,"second"):f+" ms"}function u(f,x,b,E){return l(f/b)+" "+E+(x>=1.5*b?"s":"")}c.exports=function(f,x){x=x||{};var b=typeof f;if(b=="string"&&0<f.length)return d(f);if(b==="number"&&isFinite(f))return x.long?g(f):p(f);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(f))}},{}],12:[function(o,c){function l(){throw new Error("setTimeout has not been defined")}function d(){throw new Error("clearTimeout has not been defined")}function p(T){if(E===setTimeout)return setTimeout(T,0);if((E===l||!E)&&setTimeout)return E=setTimeout,setTimeout(T,0);try{return E(T,0)}catch{try{return E.call(null,T,0)}catch{return E.call(this,T,0)}}}function g(T){if(A===clearTimeout)return clearTimeout(T);if((A===d||!A)&&clearTimeout)return A=clearTimeout,clearTimeout(T);try{return A(T)}catch{try{return A.call(null,T)}catch{return A.call(this,T)}}}function u(){k&&L&&(k=!1,L.length?m=L.concat(m):_=-1,m.length&&f())}function f(){if(!k){var T=p(u);k=!0;for(var S=m.length;S;){for(L=m,m=[];++_<S;)L&&L[_].run();_=-1,S=m.length}L=null,k=!1,g(T)}}function x(T,S){this.fun=T,this.array=S}function b(){}var E,A,v=c.exports={};(function(){try{E=typeof setTimeout=="function"?setTimeout:l}catch{E=l}try{A=typeof clearTimeout=="function"?clearTimeout:d}catch{A=d}})();var L,m=[],k=!1,_=-1;v.nextTick=function(T){var S=Array(arguments.length-1);if(1<arguments.length)for(var N=1;N<arguments.length;N++)S[N-1]=arguments[N];m.push(new x(T,S)),m.length!==1||k||p(f)},x.prototype.run=function(){this.fun.apply(null,this.array)},v.title="browser",v.browser=!0,v.env={},v.argv=[],v.version="",v.versions={},v.on=b,v.addListener=b,v.once=b,v.off=b,v.removeListener=b,v.removeAllListeners=b,v.emit=b,v.prependListener=b,v.prependOnceListener=b,v.listeners=function(){return[]},v.binding=function(){throw new Error("process.binding is not supported")},v.cwd=function(){return"/"},v.chdir=function(){throw new Error("process.chdir is not supported")},v.umask=function(){return 0}},{}],13:[function(o,c){(function(l){(function(){/*! queue-microtask. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */let d;c.exports=typeof queueMicrotask=="function"?queueMicrotask.bind(typeof window>"u"?l:window):p=>(d||(d=Promise.resolve())).then(p).catch(g=>setTimeout(()=>{throw g},0))}).call(this)}).call(this,typeof Ze>"u"?typeof self>"u"?typeof window>"u"?{}:window:self:Ze)},{}],14:[function(o,c){(function(l,d){(function(){var p=o("safe-buffer").Buffer,g=d.crypto||d.msCrypto;c.exports=g&&g.getRandomValues?function(u,f){if(u>4294967295)throw new RangeError("requested too many random bytes");var x=p.allocUnsafe(u);if(0<u)if(65536<u)for(var b=0;b<u;b+=65536)g.getRandomValues(x.slice(b,b+65536));else g.getRandomValues(x);return typeof f=="function"?l.nextTick(function(){f(null,x)}):x}:function(){throw new Error(`Secure random number generation is not supported by this browser.
|
|
97
|
+
Use Chrome, Firefox or Internet Explorer 11`)}}).call(this)}).call(this,o("_process"),typeof Ze>"u"?typeof self>"u"?typeof window>"u"?{}:window:self:Ze)},{_process:12,"safe-buffer":30}],15:[function(o,c){function l(b,E){b.prototype=Object.create(E.prototype),b.prototype.constructor=b,b.__proto__=E}function d(b,E,A){function v(m,k,_){return typeof E=="string"?E:E(m,k,_)}A||(A=Error);var L=(function(m){function k(_,T,S){return m.call(this,v(_,T,S))||this}return l(k,m),k})(A);L.prototype.name=A.name,L.prototype.code=b,x[b]=L}function p(b,E){if(Array.isArray(b)){var A=b.length;return b=b.map(function(v){return v+""}),2<A?"one of ".concat(E," ").concat(b.slice(0,A-1).join(", "),", or ")+b[A-1]:A===2?"one of ".concat(E," ").concat(b[0]," or ").concat(b[1]):"of ".concat(E," ").concat(b[0])}return"of ".concat(E," ").concat(b+"")}function g(b,E,A){return b.substr(0,E.length)===E}function u(b,E,A){return(A===void 0||A>b.length)&&(A=b.length),b.substring(A-E.length,A)===E}function f(b,E,A){return typeof A!="number"&&(A=0),!(A+E.length>b.length)&&b.indexOf(E,A)!==-1}var x={};d("ERR_INVALID_OPT_VALUE",function(b,E){return'The value "'+E+'" is invalid for option "'+b+'"'},TypeError),d("ERR_INVALID_ARG_TYPE",function(b,E,A){var v;typeof E=="string"&&g(E,"not ")?(v="must not be",E=E.replace(/^not /,"")):v="must be";var L;if(u(b," argument"))L="The ".concat(b," ").concat(v," ").concat(p(E,"type"));else{var m=f(b,".")?"property":"argument";L='The "'.concat(b,'" ').concat(m," ").concat(v," ").concat(p(E,"type"))}return L+=". Received type ".concat(typeof A),L},TypeError),d("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF"),d("ERR_METHOD_NOT_IMPLEMENTED",function(b){return"The "+b+" method is not implemented"}),d("ERR_STREAM_PREMATURE_CLOSE","Premature close"),d("ERR_STREAM_DESTROYED",function(b){return"Cannot call "+b+" after a stream was destroyed"}),d("ERR_MULTIPLE_CALLBACK","Callback called multiple times"),d("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable"),d("ERR_STREAM_WRITE_AFTER_END","write after end"),d("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),d("ERR_UNKNOWN_ENCODING",function(b){return"Unknown encoding: "+b},TypeError),d("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event"),c.exports.codes=x},{}],16:[function(o,c){(function(l){(function(){function d(v){return this instanceof d?(f.call(this,v),x.call(this,v),this.allowHalfOpen=!0,void(v&&(v.readable===!1&&(this.readable=!1),v.writable===!1&&(this.writable=!1),v.allowHalfOpen===!1&&(this.allowHalfOpen=!1,this.once("end",p))))):new d(v)}function p(){this._writableState.ended||l.nextTick(g,this)}function g(v){v.end()}var u=Object.keys||function(v){var L=[];for(var m in v)L.push(m);return L};c.exports=d;var f=o("./_stream_readable"),x=o("./_stream_writable");o("inherits")(d,f);for(var b,E=u(x.prototype),A=0;A<E.length;A++)b=E[A],d.prototype[b]||(d.prototype[b]=x.prototype[b]);Object.defineProperty(d.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(d.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(d.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(d.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState!==void 0&&this._writableState!==void 0&&this._readableState.destroyed&&this._writableState.destroyed},set:function(v){this._readableState===void 0||this._writableState===void 0||(this._readableState.destroyed=v,this._writableState.destroyed=v)}})}).call(this)}).call(this,o("_process"))},{"./_stream_readable":18,"./_stream_writable":20,_process:12,inherits:10}],17:[function(o,c){function l(p){return this instanceof l?void d.call(this,p):new l(p)}c.exports=l;var d=o("./_stream_transform");o("inherits")(l,d),l.prototype._transform=function(p,g,u){u(null,p)}},{"./_stream_transform":19,inherits:10}],18:[function(o,c){(function(l,d){(function(){function p(C){return Q.from(C)}function g(C){return Q.isBuffer(C)||C instanceof ee}function u(C,a,h){return typeof C.prependListener=="function"?C.prependListener(a,h):void(C._events&&C._events[a]?Array.isArray(C._events[a])?C._events[a].unshift(h):C._events[a]=[h,C._events[a]]:C.on(a,h))}function f(C,a,h){V=V||o("./_stream_duplex"),C=C||{},typeof h!="boolean"&&(h=a instanceof V),this.objectMode=!!C.objectMode,h&&(this.objectMode=this.objectMode||!!C.readableObjectMode),this.highWaterMark=K(this,C,"readableHighWaterMark",h),this.buffer=new ge,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.paused=!0,this.emitClose=C.emitClose!==!1,this.autoDestroy=!!C.autoDestroy,this.destroyed=!1,this.defaultEncoding=C.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,C.encoding&&(!ve&&(ve=o("string_decoder/").StringDecoder),this.decoder=new ve(C.encoding),this.encoding=C.encoding)}function x(C){if(V=V||o("./_stream_duplex"),!(this instanceof x))return new x(C);var a=this instanceof V;this._readableState=new f(C,this,a),this.readable=!0,C&&(typeof C.read=="function"&&(this._read=C.read),typeof C.destroy=="function"&&(this._destroy=C.destroy)),re.call(this)}function b(C,a,h,y,I){$("readableAddChunk",a);var W=C._readableState;if(a===null)W.reading=!1,m(C,W);else{var F;if(I||(F=A(W,a)),F)H(C,F);else if(!(W.objectMode||a&&0<a.length))y||(W.reading=!1,T(C,W));else if(typeof a=="string"||W.objectMode||Object.getPrototypeOf(a)===Q.prototype||(a=p(a)),y)W.endEmitted?H(C,new B):E(C,W,a,!0);else if(W.ended)H(C,new ae);else{if(W.destroyed)return!1;W.reading=!1,W.decoder&&!h?(a=W.decoder.write(a),W.objectMode||a.length!==0?E(C,W,a,!1):T(C,W)):E(C,W,a,!1)}}return!W.ended&&(W.length<W.highWaterMark||W.length===0)}function E(C,a,h,y){a.flowing&&a.length===0&&!a.sync?(a.awaitDrain=0,C.emit("data",h)):(a.length+=a.objectMode?1:h.length,y?a.buffer.unshift(h):a.buffer.push(h),a.needReadable&&k(C)),T(C,a)}function A(C,a){var h;return g(a)||typeof a=="string"||a===void 0||C.objectMode||(h=new Z("chunk",["string","Buffer","Uint8Array"],a)),h}function v(C){return 1073741824<=C?C=1073741824:(C--,C|=C>>>1,C|=C>>>2,C|=C>>>4,C|=C>>>8,C|=C>>>16,C++),C}function L(C,a){return 0>=C||a.length===0&&a.ended?0:a.objectMode?1:C===C?(C>a.highWaterMark&&(a.highWaterMark=v(C)),C<=a.length?C:a.ended?a.length:(a.needReadable=!0,0)):a.flowing&&a.length?a.buffer.head.data.length:a.length}function m(C,a){if($("onEofChunk"),!a.ended){if(a.decoder){var h=a.decoder.end();h&&h.length&&(a.buffer.push(h),a.length+=a.objectMode?1:h.length)}a.ended=!0,a.sync?k(C):(a.needReadable=!1,!a.emittedReadable&&(a.emittedReadable=!0,_(C)))}}function k(C){var a=C._readableState;$("emitReadable",a.needReadable,a.emittedReadable),a.needReadable=!1,a.emittedReadable||($("emitReadable",a.flowing),a.emittedReadable=!0,l.nextTick(_,C))}function _(C){var a=C._readableState;$("emitReadable_",a.destroyed,a.length,a.ended),!a.destroyed&&(a.length||a.ended)&&(C.emit("readable"),a.emittedReadable=!1),a.needReadable=!a.flowing&&!a.ended&&a.length<=a.highWaterMark,U(C)}function T(C,a){a.readingMore||(a.readingMore=!0,l.nextTick(S,C,a))}function S(C,a){for(;!a.reading&&!a.ended&&(a.length<a.highWaterMark||a.flowing&&a.length===0);){var h=a.length;if($("maybeReadMore read 0"),C.read(0),h===a.length)break}a.readingMore=!1}function N(C){return function(){var a=C._readableState;$("pipeOnDrain",a.awaitDrain),a.awaitDrain&&a.awaitDrain--,a.awaitDrain===0&&te(C,"data")&&(a.flowing=!0,U(C))}}function D(C){var a=C._readableState;a.readableListening=0<C.listenerCount("readable"),a.resumeScheduled&&!a.paused?a.flowing=!0:0<C.listenerCount("data")&&C.resume()}function j(C){$("readable nexttick read 0"),C.read(0)}function R(C,a){a.resumeScheduled||(a.resumeScheduled=!0,l.nextTick(O,C,a))}function O(C,a){$("resume",a.reading),a.reading||C.read(0),a.resumeScheduled=!1,C.emit("resume"),U(C),a.flowing&&!a.reading&&C.read(0)}function U(C){var a=C._readableState;for($("flow",a.flowing);a.flowing&&C.read()!==null;);}function z(C,a){if(a.length===0)return null;var h;return a.objectMode?h=a.buffer.shift():!C||C>=a.length?(h=a.decoder?a.buffer.join(""):a.buffer.length===1?a.buffer.first():a.buffer.concat(a.length),a.buffer.clear()):h=a.buffer.consume(C,a.decoder),h}function G(C){var a=C._readableState;$("endReadable",a.endEmitted),a.endEmitted||(a.ended=!0,l.nextTick(q,a,C))}function q(C,a){if($("endReadableNT",C.endEmitted,C.length),!C.endEmitted&&C.length===0&&(C.endEmitted=!0,a.readable=!1,a.emit("end"),C.autoDestroy)){var h=a._writableState;(!h||h.autoDestroy&&h.finished)&&a.destroy()}}function P(C,a){for(var h=0,y=C.length;h<y;h++)if(C[h]===a)return h;return-1}c.exports=x;var V;x.ReadableState=f;var $;o("events").EventEmitter;var te=function(C,a){return C.listeners(a).length},re=o("./internal/streams/stream"),Q=o("buffer").Buffer,ee=d.Uint8Array||function(){},X=o("util");$=X&&X.debuglog?X.debuglog("stream"):function(){};var ve,Be,ce,ge=o("./internal/streams/buffer_list"),be=o("./internal/streams/destroy"),we=o("./internal/streams/state"),K=we.getHighWaterMark,Y=o("../errors").codes,Z=Y.ERR_INVALID_ARG_TYPE,ae=Y.ERR_STREAM_PUSH_AFTER_EOF,M=Y.ERR_METHOD_NOT_IMPLEMENTED,B=Y.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;o("inherits")(x,re);var H=be.errorOrDestroy,se=["error","close","destroy","pause","resume"];Object.defineProperty(x.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState!==void 0&&this._readableState.destroyed},set:function(C){this._readableState&&(this._readableState.destroyed=C)}}),x.prototype.destroy=be.destroy,x.prototype._undestroy=be.undestroy,x.prototype._destroy=function(C,a){a(C)},x.prototype.push=function(C,a){var h,y=this._readableState;return y.objectMode?h=!0:typeof C=="string"&&(a=a||y.defaultEncoding,a!==y.encoding&&(C=Q.from(C,a),a=""),h=!0),b(this,C,a,!1,h)},x.prototype.unshift=function(C){return b(this,C,null,!0,!1)},x.prototype.isPaused=function(){return this._readableState.flowing===!1},x.prototype.setEncoding=function(C){ve||(ve=o("string_decoder/").StringDecoder);var a=new ve(C);this._readableState.decoder=a,this._readableState.encoding=this._readableState.decoder.encoding;for(var h=this._readableState.buffer.head,y="";h!==null;)y+=a.write(h.data),h=h.next;return this._readableState.buffer.clear(),y!==""&&this._readableState.buffer.push(y),this._readableState.length=y.length,this},x.prototype.read=function(C){$("read",C),C=parseInt(C,10);var a=this._readableState,h=C;if(C!==0&&(a.emittedReadable=!1),C===0&&a.needReadable&&((a.highWaterMark===0?0<a.length:a.length>=a.highWaterMark)||a.ended))return $("read: emitReadable",a.length,a.ended),a.length===0&&a.ended?G(this):k(this),null;if(C=L(C,a),C===0&&a.ended)return a.length===0&&G(this),null;var y=a.needReadable;$("need readable",y),(a.length===0||a.length-C<a.highWaterMark)&&(y=!0,$("length less than watermark",y)),a.ended||a.reading?(y=!1,$("reading or ended",y)):y&&($("do read"),a.reading=!0,a.sync=!0,a.length===0&&(a.needReadable=!0),this._read(a.highWaterMark),a.sync=!1,!a.reading&&(C=L(h,a)));var I;return I=0<C?z(C,a):null,I===null?(a.needReadable=a.length<=a.highWaterMark,C=0):(a.length-=C,a.awaitDrain=0),a.length===0&&(!a.ended&&(a.needReadable=!0),h!==C&&a.ended&&G(this)),I!==null&&this.emit("data",I),I},x.prototype._read=function(){H(this,new M("_read()"))},x.prototype.pipe=function(C,a){function h(Ot,Wt){$("onunpipe"),Ot===pe&&Wt&&Wt.hasUnpiped===!1&&(Wt.hasUnpiped=!0,I())}function y(){$("onend"),C.end()}function I(){$("cleanup"),C.removeListener("close",ne),C.removeListener("finish",fe),C.removeListener("drain",Mt),C.removeListener("error",F),C.removeListener("unpipe",h),pe.removeListener("end",y),pe.removeListener("end",_e),pe.removeListener("data",W),rs=!0,he.awaitDrain&&(!C._writableState||C._writableState.needDrain)&&Mt()}function W(Ot){$("ondata");var Wt=C.write(Ot);$("dest.write",Wt),Wt===!1&&((he.pipesCount===1&&he.pipes===C||1<he.pipesCount&&P(he.pipes,C)!==-1)&&!rs&&($("false write response, pause",he.awaitDrain),he.awaitDrain++),pe.pause())}function F(Ot){$("onerror",Ot),_e(),C.removeListener("error",F),te(C,"error")===0&&H(C,Ot)}function ne(){C.removeListener("finish",fe),_e()}function fe(){$("onfinish"),C.removeListener("close",ne),_e()}function _e(){$("unpipe"),pe.unpipe(C)}var pe=this,he=this._readableState;switch(he.pipesCount){case 0:he.pipes=C;break;case 1:he.pipes=[he.pipes,C];break;default:he.pipes.push(C)}he.pipesCount+=1,$("pipe count=%d opts=%j",he.pipesCount,a);var Me=(!a||a.end!==!1)&&C!==l.stdout&&C!==l.stderr,vt=Me?y:_e;he.endEmitted?l.nextTick(vt):pe.once("end",vt),C.on("unpipe",h);var Mt=N(pe);C.on("drain",Mt);var rs=!1;return pe.on("data",W),u(C,"error",F),C.once("close",ne),C.once("finish",fe),C.emit("pipe",pe),he.flowing||($("pipe resume"),pe.resume()),C},x.prototype.unpipe=function(C){var a=this._readableState,h={hasUnpiped:!1};if(a.pipesCount===0)return this;if(a.pipesCount===1)return C&&C!==a.pipes?this:(C||(C=a.pipes),a.pipes=null,a.pipesCount=0,a.flowing=!1,C&&C.emit("unpipe",this,h),this);if(!C){var y=a.pipes,I=a.pipesCount;a.pipes=null,a.pipesCount=0,a.flowing=!1;for(var W=0;W<I;W++)y[W].emit("unpipe",this,{hasUnpiped:!1});return this}var F=P(a.pipes,C);return F===-1?this:(a.pipes.splice(F,1),a.pipesCount-=1,a.pipesCount===1&&(a.pipes=a.pipes[0]),C.emit("unpipe",this,h),this)},x.prototype.on=function(C,a){var h=re.prototype.on.call(this,C,a),y=this._readableState;return C==="data"?(y.readableListening=0<this.listenerCount("readable"),y.flowing!==!1&&this.resume()):C=="readable"&&!y.endEmitted&&!y.readableListening&&(y.readableListening=y.needReadable=!0,y.flowing=!1,y.emittedReadable=!1,$("on readable",y.length,y.reading),y.length?k(this):!y.reading&&l.nextTick(j,this)),h},x.prototype.addListener=x.prototype.on,x.prototype.removeListener=function(C,a){var h=re.prototype.removeListener.call(this,C,a);return C==="readable"&&l.nextTick(D,this),h},x.prototype.removeAllListeners=function(C){var a=re.prototype.removeAllListeners.apply(this,arguments);return(C==="readable"||C===void 0)&&l.nextTick(D,this),a},x.prototype.resume=function(){var C=this._readableState;return C.flowing||($("resume"),C.flowing=!C.readableListening,R(this,C)),C.paused=!1,this},x.prototype.pause=function(){return $("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&($("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this},x.prototype.wrap=function(C){var a=this,h=this._readableState,y=!1;for(var I in C.on("end",function(){if($("wrapped end"),h.decoder&&!h.ended){var F=h.decoder.end();F&&F.length&&a.push(F)}a.push(null)}),C.on("data",function(F){if($("wrapped data"),h.decoder&&(F=h.decoder.write(F)),!(h.objectMode&&F==null)&&(h.objectMode||F&&F.length)){var ne=a.push(F);ne||(y=!0,C.pause())}}),C)this[I]===void 0&&typeof C[I]=="function"&&(this[I]=(function(F){return function(){return C[F].apply(C,arguments)}})(I));for(var W=0;W<se.length;W++)C.on(se[W],this.emit.bind(this,se[W]));return this._read=function(F){$("wrapped _read",F),y&&(y=!1,C.resume())},this},typeof Symbol=="function"&&(x.prototype[Symbol.asyncIterator]=function(){return Be===void 0&&(Be=o("./internal/streams/async_iterator")),Be(this)}),Object.defineProperty(x.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(x.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(x.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(C){this._readableState&&(this._readableState.flowing=C)}}),x._fromList=z,Object.defineProperty(x.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}}),typeof Symbol=="function"&&(x.from=function(C,a){return ce===void 0&&(ce=o("./internal/streams/from")),ce(x,C,a)})}).call(this)}).call(this,o("_process"),typeof Ze>"u"?typeof self>"u"?typeof window>"u"?{}:window:self:Ze)},{"../errors":15,"./_stream_duplex":16,"./internal/streams/async_iterator":21,"./internal/streams/buffer_list":22,"./internal/streams/destroy":23,"./internal/streams/from":25,"./internal/streams/state":27,"./internal/streams/stream":28,_process:12,buffer:3,events:7,inherits:10,"string_decoder/":31,util:2}],19:[function(o,c){function l(v,L){var m=this._transformState;m.transforming=!1;var k=m.writecb;if(k===null)return this.emit("error",new x);m.writechunk=null,m.writecb=null,L!=null&&this.push(L),k(v);var _=this._readableState;_.reading=!1,(_.needReadable||_.length<_.highWaterMark)&&this._read(_.highWaterMark)}function d(v){return this instanceof d?(A.call(this,v),this._transformState={afterTransform:l.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,v&&(typeof v.transform=="function"&&(this._transform=v.transform),typeof v.flush=="function"&&(this._flush=v.flush)),void this.on("prefinish",p)):new d(v)}function p(){var v=this;typeof this._flush!="function"||this._readableState.destroyed?g(this,null,null):this._flush(function(L,m){g(v,L,m)})}function g(v,L,m){if(L)return v.emit("error",L);if(m!=null&&v.push(m),v._writableState.length)throw new E;if(v._transformState.transforming)throw new b;return v.push(null)}c.exports=d;var u=o("../errors").codes,f=u.ERR_METHOD_NOT_IMPLEMENTED,x=u.ERR_MULTIPLE_CALLBACK,b=u.ERR_TRANSFORM_ALREADY_TRANSFORMING,E=u.ERR_TRANSFORM_WITH_LENGTH_0,A=o("./_stream_duplex");o("inherits")(d,A),d.prototype.push=function(v,L){return this._transformState.needTransform=!1,A.prototype.push.call(this,v,L)},d.prototype._transform=function(v,L,m){m(new f("_transform()"))},d.prototype._write=function(v,L,m){var k=this._transformState;if(k.writecb=m,k.writechunk=v,k.writeencoding=L,!k.transforming){var _=this._readableState;(k.needTransform||_.needReadable||_.length<_.highWaterMark)&&this._read(_.highWaterMark)}},d.prototype._read=function(){var v=this._transformState;v.writechunk===null||v.transforming?v.needTransform=!0:(v.transforming=!0,this._transform(v.writechunk,v.writeencoding,v.afterTransform))},d.prototype._destroy=function(v,L){A.prototype._destroy.call(this,v,function(m){L(m)})}},{"../errors":15,"./_stream_duplex":16,inherits:10}],20:[function(o,c){(function(l,d){(function(){function p(M){var B=this;this.next=null,this.entry=null,this.finish=function(){G(B,M)}}function g(M){return $.from(M)}function u(M){return $.isBuffer(M)||M instanceof te}function f(){}function x(M,B,H){q=q||o("./_stream_duplex"),M=M||{},typeof H!="boolean"&&(H=B instanceof q),this.objectMode=!!M.objectMode,H&&(this.objectMode=this.objectMode||!!M.writableObjectMode),this.highWaterMark=ee(this,M,"writableHighWaterMark",H),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var se=M.decodeStrings===!1;this.decodeStrings=!se,this.defaultEncoding=M.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(C){T(B,C)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=M.emitClose!==!1,this.autoDestroy=!!M.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new p(this)}function b(M){q=q||o("./_stream_duplex");var B=this instanceof q;return B||ae.call(b,this)?(this._writableState=new x(M,this,B),this.writable=!0,M&&(typeof M.write=="function"&&(this._write=M.write),typeof M.writev=="function"&&(this._writev=M.writev),typeof M.destroy=="function"&&(this._destroy=M.destroy),typeof M.final=="function"&&(this._final=M.final)),void V.call(this)):new b(M)}function E(M,B){var H=new K;Z(M,H),l.nextTick(B,H)}function A(M,B,H,se){var C;return H===null?C=new we:typeof H!="string"&&!B.objectMode&&(C=new ve("chunk",["string","Buffer"],H)),!C||(Z(M,C),l.nextTick(se,C),!1)}function v(M,B,H){return M.objectMode||M.decodeStrings===!1||typeof B!="string"||(B=$.from(B,H)),B}function L(M,B,H,se,C,a){if(!H){var h=v(B,se,C);se!==h&&(H=!0,C="buffer",se=h)}var y=B.objectMode?1:se.length;B.length+=y;var I=B.length<B.highWaterMark;if(I||(B.needDrain=!0),B.writing||B.corked){var W=B.lastBufferedRequest;B.lastBufferedRequest={chunk:se,encoding:C,isBuf:H,callback:a,next:null},W?W.next=B.lastBufferedRequest:B.bufferedRequest=B.lastBufferedRequest,B.bufferedRequestCount+=1}else m(M,B,!1,y,se,C,a);return I}function m(M,B,H,se,C,a,h){B.writelen=se,B.writecb=h,B.writing=!0,B.sync=!0,B.destroyed?B.onwrite(new be("write")):H?M._writev(C,B.onwrite):M._write(C,a,B.onwrite),B.sync=!1}function k(M,B,H,se,C){--B.pendingcb,H?(l.nextTick(C,se),l.nextTick(U,M,B),M._writableState.errorEmitted=!0,Z(M,se)):(C(se),M._writableState.errorEmitted=!0,Z(M,se),U(M,B))}function _(M){M.writing=!1,M.writecb=null,M.length-=M.writelen,M.writelen=0}function T(M,B){var H=M._writableState,se=H.sync,C=H.writecb;if(typeof C!="function")throw new ce;if(_(H),B)k(M,H,se,B,C);else{var a=j(H)||M.destroyed;a||H.corked||H.bufferProcessing||!H.bufferedRequest||D(M,H),se?l.nextTick(S,M,H,a,C):S(M,H,a,C)}}function S(M,B,H,se){H||N(M,B),B.pendingcb--,se(),U(M,B)}function N(M,B){B.length===0&&B.needDrain&&(B.needDrain=!1,M.emit("drain"))}function D(M,B){B.bufferProcessing=!0;var H=B.bufferedRequest;if(M._writev&&H&&H.next){var se=B.bufferedRequestCount,C=Array(se),a=B.corkedRequestsFree;a.entry=H;for(var h=0,y=!0;H;)C[h]=H,H.isBuf||(y=!1),H=H.next,h+=1;C.allBuffers=y,m(M,B,!0,B.length,C,"",a.finish),B.pendingcb++,B.lastBufferedRequest=null,a.next?(B.corkedRequestsFree=a.next,a.next=null):B.corkedRequestsFree=new p(B),B.bufferedRequestCount=0}else{for(;H;){var I=H.chunk,W=H.encoding,F=H.callback,ne=B.objectMode?1:I.length;if(m(M,B,!1,ne,I,W,F),H=H.next,B.bufferedRequestCount--,B.writing)break}H===null&&(B.lastBufferedRequest=null)}B.bufferedRequest=H,B.bufferProcessing=!1}function j(M){return M.ending&&M.length===0&&M.bufferedRequest===null&&!M.finished&&!M.writing}function R(M,B){M._final(function(H){B.pendingcb--,H&&Z(M,H),B.prefinished=!0,M.emit("prefinish"),U(M,B)})}function O(M,B){B.prefinished||B.finalCalled||(typeof M._final!="function"||B.destroyed?(B.prefinished=!0,M.emit("prefinish")):(B.pendingcb++,B.finalCalled=!0,l.nextTick(R,M,B)))}function U(M,B){var H=j(B);if(H&&(O(M,B),B.pendingcb===0&&(B.finished=!0,M.emit("finish"),B.autoDestroy))){var se=M._readableState;(!se||se.autoDestroy&&se.endEmitted)&&M.destroy()}return H}function z(M,B,H){B.ending=!0,U(M,B),H&&(B.finished?l.nextTick(H):M.once("finish",H)),B.ended=!0,M.writable=!1}function G(M,B,H){var se=M.entry;for(M.entry=null;se;){var C=se.callback;B.pendingcb--,C(H),se=se.next}B.corkedRequestsFree.next=M}c.exports=b;var q;b.WritableState=x;var P={deprecate:o("util-deprecate")},V=o("./internal/streams/stream"),$=o("buffer").Buffer,te=d.Uint8Array||function(){},re=o("./internal/streams/destroy"),Q=o("./internal/streams/state"),ee=Q.getHighWaterMark,X=o("../errors").codes,ve=X.ERR_INVALID_ARG_TYPE,Be=X.ERR_METHOD_NOT_IMPLEMENTED,ce=X.ERR_MULTIPLE_CALLBACK,ge=X.ERR_STREAM_CANNOT_PIPE,be=X.ERR_STREAM_DESTROYED,we=X.ERR_STREAM_NULL_VALUES,K=X.ERR_STREAM_WRITE_AFTER_END,Y=X.ERR_UNKNOWN_ENCODING,Z=re.errorOrDestroy;o("inherits")(b,V),x.prototype.getBuffer=function(){for(var M=this.bufferedRequest,B=[];M;)B.push(M),M=M.next;return B},(function(){try{Object.defineProperty(x.prototype,"buffer",{get:P.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch{}})();var ae;typeof Symbol=="function"&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]=="function"?(ae=Function.prototype[Symbol.hasInstance],Object.defineProperty(b,Symbol.hasInstance,{value:function(M){return!!ae.call(this,M)||this===b&&M&&M._writableState instanceof x}})):ae=function(M){return M instanceof this},b.prototype.pipe=function(){Z(this,new ge)},b.prototype.write=function(M,B,H){var se=this._writableState,C=!1,a=!se.objectMode&&u(M);return a&&!$.isBuffer(M)&&(M=g(M)),typeof B=="function"&&(H=B,B=null),a?B="buffer":!B&&(B=se.defaultEncoding),typeof H!="function"&&(H=f),se.ending?E(this,H):(a||A(this,se,M,H))&&(se.pendingcb++,C=L(this,se,a,M,B,H)),C},b.prototype.cork=function(){this._writableState.corked++},b.prototype.uncork=function(){var M=this._writableState;M.corked&&(M.corked--,!M.writing&&!M.corked&&!M.bufferProcessing&&M.bufferedRequest&&D(this,M))},b.prototype.setDefaultEncoding=function(M){if(typeof M=="string"&&(M=M.toLowerCase()),!(-1<["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((M+"").toLowerCase())))throw new Y(M);return this._writableState.defaultEncoding=M,this},Object.defineProperty(b.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(b.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),b.prototype._write=function(M,B,H){H(new Be("_write()"))},b.prototype._writev=null,b.prototype.end=function(M,B,H){var se=this._writableState;return typeof M=="function"?(H=M,M=null,B=null):typeof B=="function"&&(H=B,B=null),M!=null&&this.write(M,B),se.corked&&(se.corked=1,this.uncork()),se.ending||z(this,se,H),this},Object.defineProperty(b.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(b.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState!==void 0&&this._writableState.destroyed},set:function(M){this._writableState&&(this._writableState.destroyed=M)}}),b.prototype.destroy=re.destroy,b.prototype._undestroy=re.undestroy,b.prototype._destroy=function(M,B){B(M)}}).call(this)}).call(this,o("_process"),typeof Ze>"u"?typeof self>"u"?typeof window>"u"?{}:window:self:Ze)},{"../errors":15,"./_stream_duplex":16,"./internal/streams/destroy":23,"./internal/streams/state":27,"./internal/streams/stream":28,_process:12,buffer:3,inherits:10,"util-deprecate":32}],21:[function(o,c){(function(l){(function(){function d(N,D,j){return D in N?Object.defineProperty(N,D,{value:j,enumerable:!0,configurable:!0,writable:!0}):N[D]=j,N}function p(N,D){return{value:N,done:D}}function g(N){var D=N[E];if(D!==null){var j=N[_].read();j!==null&&(N[m]=null,N[E]=null,N[A]=null,D(p(j,!1)))}}function u(N){l.nextTick(g,N)}function f(N,D){return function(j,R){N.then(function(){return D[L]?void j(p(void 0,!0)):void D[k](j,R)},R)}}var x,b=o("./end-of-stream"),E=Symbol("lastResolve"),A=Symbol("lastReject"),v=Symbol("error"),L=Symbol("ended"),m=Symbol("lastPromise"),k=Symbol("handlePromise"),_=Symbol("stream"),T=Object.getPrototypeOf(function(){}),S=Object.setPrototypeOf((x={get stream(){return this[_]},next:function(){var N=this,D=this[v];if(D!==null)return Promise.reject(D);if(this[L])return Promise.resolve(p(void 0,!0));if(this[_].destroyed)return new Promise(function(U,z){l.nextTick(function(){N[v]?z(N[v]):U(p(void 0,!0))})});var j,R=this[m];if(R)j=new Promise(f(R,this));else{var O=this[_].read();if(O!==null)return Promise.resolve(p(O,!1));j=new Promise(this[k])}return this[m]=j,j}},d(x,Symbol.asyncIterator,function(){return this}),d(x,"return",function(){var N=this;return new Promise(function(D,j){N[_].destroy(null,function(R){return R?void j(R):void D(p(void 0,!0))})})}),x),T);c.exports=function(N){var D,j=Object.create(S,(D={},d(D,_,{value:N,writable:!0}),d(D,E,{value:null,writable:!0}),d(D,A,{value:null,writable:!0}),d(D,v,{value:null,writable:!0}),d(D,L,{value:N._readableState.endEmitted,writable:!0}),d(D,k,{value:function(R,O){var U=j[_].read();U?(j[m]=null,j[E]=null,j[A]=null,R(p(U,!1))):(j[E]=R,j[A]=O)},writable:!0}),D));return j[m]=null,b(N,function(R){if(R&&R.code!=="ERR_STREAM_PREMATURE_CLOSE"){var O=j[A];return O!==null&&(j[m]=null,j[E]=null,j[A]=null,O(R)),void(j[v]=R)}var U=j[E];U!==null&&(j[m]=null,j[E]=null,j[A]=null,U(p(void 0,!0))),j[L]=!0}),N.on("readable",u.bind(null,j)),j}}).call(this)}).call(this,o("_process"))},{"./end-of-stream":24,_process:12}],22:[function(o,c){function l(m,k){var _=Object.keys(m);if(Object.getOwnPropertySymbols){var T=Object.getOwnPropertySymbols(m);k&&(T=T.filter(function(S){return Object.getOwnPropertyDescriptor(m,S).enumerable})),_.push.apply(_,T)}return _}function d(m){for(var k,_=1;_<arguments.length;_++)k=arguments[_]==null?{}:arguments[_],_%2?l(Object(k),!0).forEach(function(T){p(m,T,k[T])}):Object.getOwnPropertyDescriptors?Object.defineProperties(m,Object.getOwnPropertyDescriptors(k)):l(Object(k)).forEach(function(T){Object.defineProperty(m,T,Object.getOwnPropertyDescriptor(k,T))});return m}function p(m,k,_){return k in m?Object.defineProperty(m,k,{value:_,enumerable:!0,configurable:!0,writable:!0}):m[k]=_,m}function g(m,k){if(!(m instanceof k))throw new TypeError("Cannot call a class as a function")}function u(m,k){for(var _,T=0;T<k.length;T++)_=k[T],_.enumerable=_.enumerable||!1,_.configurable=!0,"value"in _&&(_.writable=!0),Object.defineProperty(m,_.key,_)}function f(m,k,_){return k&&u(m.prototype,k),m}function x(m,k,_){E.prototype.copy.call(m,k,_)}var b=o("buffer"),E=b.Buffer,A=o("util"),v=A.inspect,L=v&&v.custom||"inspect";c.exports=(function(){function m(){g(this,m),this.head=null,this.tail=null,this.length=0}return f(m,[{key:"push",value:function(k){var _={data:k,next:null};0<this.length?this.tail.next=_:this.head=_,this.tail=_,++this.length}},{key:"unshift",value:function(k){var _={data:k,next:this.head};this.length===0&&(this.tail=_),this.head=_,++this.length}},{key:"shift",value:function(){if(this.length!==0){var k=this.head.data;return this.head=this.length===1?this.tail=null:this.head.next,--this.length,k}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(k){if(this.length===0)return"";for(var _=this.head,T=""+_.data;_=_.next;)T+=k+_.data;return T}},{key:"concat",value:function(k){if(this.length===0)return E.alloc(0);for(var _=E.allocUnsafe(k>>>0),T=this.head,S=0;T;)x(T.data,_,S),S+=T.data.length,T=T.next;return _}},{key:"consume",value:function(k,_){var T;return k<this.head.data.length?(T=this.head.data.slice(0,k),this.head.data=this.head.data.slice(k)):k===this.head.data.length?T=this.shift():T=_?this._getString(k):this._getBuffer(k),T}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(k){var _=this.head,T=1,S=_.data;for(k-=S.length;_=_.next;){var N=_.data,D=k>N.length?N.length:k;if(S+=D===N.length?N:N.slice(0,k),k-=D,k===0){D===N.length?(++T,this.head=_.next?_.next:this.tail=null):(this.head=_,_.data=N.slice(D));break}++T}return this.length-=T,S}},{key:"_getBuffer",value:function(k){var _=E.allocUnsafe(k),T=this.head,S=1;for(T.data.copy(_),k-=T.data.length;T=T.next;){var N=T.data,D=k>N.length?N.length:k;if(N.copy(_,_.length-k,0,D),k-=D,k===0){D===N.length?(++S,this.head=T.next?T.next:this.tail=null):(this.head=T,T.data=N.slice(D));break}++S}return this.length-=S,_}},{key:L,value:function(k,_){return v(this,d({},_,{depth:0,customInspect:!1}))}}]),m})()},{buffer:3,util:2}],23:[function(o,c){(function(l){(function(){function d(u,f){g(u,f),p(u)}function p(u){u._writableState&&!u._writableState.emitClose||u._readableState&&!u._readableState.emitClose||u.emit("close")}function g(u,f){u.emit("error",f)}c.exports={destroy:function(u,f){var x=this,b=this._readableState&&this._readableState.destroyed,E=this._writableState&&this._writableState.destroyed;return b||E?(f?f(u):u&&(this._writableState?!this._writableState.errorEmitted&&(this._writableState.errorEmitted=!0,l.nextTick(g,this,u)):l.nextTick(g,this,u)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(u||null,function(A){!f&&A?x._writableState?x._writableState.errorEmitted?l.nextTick(p,x):(x._writableState.errorEmitted=!0,l.nextTick(d,x,A)):l.nextTick(d,x,A):f?(l.nextTick(p,x),f(A)):l.nextTick(p,x)}),this)},undestroy:function(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finalCalled=!1,this._writableState.prefinished=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)},errorOrDestroy:function(u,f){var x=u._readableState,b=u._writableState;x&&x.autoDestroy||b&&b.autoDestroy?u.destroy(f):u.emit("error",f)}}}).call(this)}).call(this,o("_process"))},{_process:12}],24:[function(o,c){function l(f){var x=!1;return function(){if(!x){x=!0;for(var b=arguments.length,E=Array(b),A=0;A<b;A++)E[A]=arguments[A];f.apply(this,E)}}}function d(){}function p(f){return f.setHeader&&typeof f.abort=="function"}function g(f,x,b){if(typeof x=="function")return g(f,null,x);x||(x={}),b=l(b||d);var E=x.readable||x.readable!==!1&&f.readable,A=x.writable||x.writable!==!1&&f.writable,v=function(){f.writable||m()},L=f._writableState&&f._writableState.finished,m=function(){A=!1,L=!0,E||b.call(f)},k=f._readableState&&f._readableState.endEmitted,_=function(){E=!1,k=!0,A||b.call(f)},T=function(D){b.call(f,D)},S=function(){var D;return E&&!k?(f._readableState&&f._readableState.ended||(D=new u),b.call(f,D)):A&&!L?(f._writableState&&f._writableState.ended||(D=new u),b.call(f,D)):void 0},N=function(){f.req.on("finish",m)};return p(f)?(f.on("complete",m),f.on("abort",S),f.req?N():f.on("request",N)):A&&!f._writableState&&(f.on("end",v),f.on("close",v)),f.on("end",_),f.on("finish",m),x.error!==!1&&f.on("error",T),f.on("close",S),function(){f.removeListener("complete",m),f.removeListener("abort",S),f.removeListener("request",N),f.req&&f.req.removeListener("finish",m),f.removeListener("end",v),f.removeListener("close",v),f.removeListener("finish",m),f.removeListener("end",_),f.removeListener("error",T),f.removeListener("close",S)}}var u=o("../../../errors").codes.ERR_STREAM_PREMATURE_CLOSE;c.exports=g},{"../../../errors":15}],25:[function(o,c){c.exports=function(){throw new Error("Readable.from is not available in the browser")}},{}],26:[function(o,c){function l(L){var m=!1;return function(){m||(m=!0,L.apply(void 0,arguments))}}function d(L){if(L)throw L}function p(L){return L.setHeader&&typeof L.abort=="function"}function g(L,m,k,_){_=l(_);var T=!1;L.on("close",function(){T=!0}),b===void 0&&(b=o("./end-of-stream")),b(L,{readable:m,writable:k},function(N){return N?_(N):(T=!0,void _())});var S=!1;return function(N){if(!T)return S?void 0:(S=!0,p(L)?L.abort():typeof L.destroy=="function"?L.destroy():void _(N||new v("pipe")))}}function u(L){L()}function f(L,m){return L.pipe(m)}function x(L){return L.length&&typeof L[L.length-1]=="function"?L.pop():d}var b,E=o("../../../errors").codes,A=E.ERR_MISSING_ARGS,v=E.ERR_STREAM_DESTROYED;c.exports=function(){for(var L=arguments.length,m=Array(L),k=0;k<L;k++)m[k]=arguments[k];var _=x(m);if(Array.isArray(m[0])&&(m=m[0]),2>m.length)throw new A("streams");var T,S=m.map(function(N,D){var j=D<m.length-1;return g(N,j,0<D,function(R){T||(T=R),R&&S.forEach(u),j||(S.forEach(u),_(T))})});return m.reduce(f)}},{"../../../errors":15,"./end-of-stream":24}],27:[function(o,c){function l(p,g,u){return p.highWaterMark==null?g?p[u]:null:p.highWaterMark}var d=o("../../../errors").codes.ERR_INVALID_OPT_VALUE;c.exports={getHighWaterMark:function(p,g,u,f){var x=l(g,f,u);if(x!=null){if(!(isFinite(x)&&s(x)===x)||0>x){var b=f?u:"highWaterMark";throw new d(b,x)}return s(x)}return p.objectMode?16:16384}}},{"../../../errors":15}],28:[function(o,c){c.exports=o("events").EventEmitter},{events:7}],29:[function(o,c,l){l=c.exports=o("./lib/_stream_readable.js"),l.Stream=l,l.Readable=l,l.Writable=o("./lib/_stream_writable.js"),l.Duplex=o("./lib/_stream_duplex.js"),l.Transform=o("./lib/_stream_transform.js"),l.PassThrough=o("./lib/_stream_passthrough.js"),l.finished=o("./lib/internal/streams/end-of-stream.js"),l.pipeline=o("./lib/internal/streams/pipeline.js")},{"./lib/_stream_duplex.js":16,"./lib/_stream_passthrough.js":17,"./lib/_stream_readable.js":18,"./lib/_stream_transform.js":19,"./lib/_stream_writable.js":20,"./lib/internal/streams/end-of-stream.js":24,"./lib/internal/streams/pipeline.js":26}],30:[function(o,c,l){function d(f,x){for(var b in f)x[b]=f[b]}function p(f,x,b){return u(f,x,b)}/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */var g=o("buffer"),u=g.Buffer;u.from&&u.alloc&&u.allocUnsafe&&u.allocUnsafeSlow?c.exports=g:(d(g,l),l.Buffer=p),p.prototype=Object.create(u.prototype),d(u,p),p.from=function(f,x,b){if(typeof f=="number")throw new TypeError("Argument must not be a number");return u(f,x,b)},p.alloc=function(f,x,b){if(typeof f!="number")throw new TypeError("Argument must be a number");var E=u(f);return x===void 0?E.fill(0):typeof b=="string"?E.fill(x,b):E.fill(x),E},p.allocUnsafe=function(f){if(typeof f!="number")throw new TypeError("Argument must be a number");return u(f)},p.allocUnsafeSlow=function(f){if(typeof f!="number")throw new TypeError("Argument must be a number");return g.SlowBuffer(f)}},{buffer:3}],31:[function(o,c,l){function d(S){if(!S)return"utf8";for(var N;;)switch(S){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return S;default:if(N)return;S=(""+S).toLowerCase(),N=!0}}function p(S){var N=d(S);if(typeof N!="string"&&(_.isEncoding===T||!T(S)))throw new Error("Unknown encoding: "+S);return N||S}function g(S){this.encoding=p(S);var N;switch(this.encoding){case"utf16le":this.text=E,this.end=A,N=4;break;case"utf8":this.fillLast=b,N=4;break;case"base64":this.text=v,this.end=L,N=3;break;default:return this.write=m,void(this.end=k)}this.lastNeed=0,this.lastTotal=0,this.lastChar=_.allocUnsafe(N)}function u(S){return 127>=S?0:S>>5==6?2:S>>4==14?3:S>>3==30?4:S>>6==2?-1:-2}function f(S,N,D){var j=N.length-1;if(j<D)return 0;var R=u(N[j]);return 0<=R?(0<R&&(S.lastNeed=R-1),R):--j<D||R===-2?0:(R=u(N[j]),0<=R?(0<R&&(S.lastNeed=R-2),R):--j<D||R===-2?0:(R=u(N[j]),0<=R?(0<R&&(R===2?R=0:S.lastNeed=R-3),R):0))}function x(S,N){if((192&N[0])!=128)return S.lastNeed=0,"�";if(1<S.lastNeed&&1<N.length){if((192&N[1])!=128)return S.lastNeed=1,"�";if(2<S.lastNeed&&2<N.length&&(192&N[2])!=128)return S.lastNeed=2,"�"}}function b(S){var N=this.lastTotal-this.lastNeed,D=x(this,S);return D===void 0?this.lastNeed<=S.length?(S.copy(this.lastChar,N,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(S.copy(this.lastChar,N,0,S.length),void(this.lastNeed-=S.length)):D}function E(S,N){if((S.length-N)%2==0){var D=S.toString("utf16le",N);if(D){var j=D.charCodeAt(D.length-1);if(55296<=j&&56319>=j)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=S[S.length-2],this.lastChar[1]=S[S.length-1],D.slice(0,-1)}return D}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=S[S.length-1],S.toString("utf16le",N,S.length-1)}function A(S){var N=S&&S.length?this.write(S):"";if(this.lastNeed){var D=this.lastTotal-this.lastNeed;return N+this.lastChar.toString("utf16le",0,D)}return N}function v(S,N){var D=(S.length-N)%3;return D==0?S.toString("base64",N):(this.lastNeed=3-D,this.lastTotal=3,D==1?this.lastChar[0]=S[S.length-1]:(this.lastChar[0]=S[S.length-2],this.lastChar[1]=S[S.length-1]),S.toString("base64",N,S.length-D))}function L(S){var N=S&&S.length?this.write(S):"";return this.lastNeed?N+this.lastChar.toString("base64",0,3-this.lastNeed):N}function m(S){return S.toString(this.encoding)}function k(S){return S&&S.length?this.write(S):""}var _=o("safe-buffer").Buffer,T=_.isEncoding||function(S){switch(S=""+S,S&&S.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};l.StringDecoder=g,g.prototype.write=function(S){if(S.length===0)return"";var N,D;if(this.lastNeed){if(N=this.fillLast(S),N===void 0)return"";D=this.lastNeed,this.lastNeed=0}else D=0;return D<S.length?N?N+this.text(S,D):this.text(S,D):N||""},g.prototype.end=function(S){var N=S&&S.length?this.write(S):"";return this.lastNeed?N+"�":N},g.prototype.text=function(S,N){var D=f(this,S,N);if(!this.lastNeed)return S.toString("utf8",N);this.lastTotal=D;var j=S.length-(D-this.lastNeed);return S.copy(this.lastChar,0,j),S.toString("utf8",N,j)},g.prototype.fillLast=function(S){return this.lastNeed<=S.length?(S.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(S.copy(this.lastChar,this.lastTotal-this.lastNeed,0,S.length),void(this.lastNeed-=S.length))}},{"safe-buffer":30}],32:[function(o,c){(function(l){(function(){function d(p){try{if(!l.localStorage)return!1}catch{return!1}var g=l.localStorage[p];return g!=null&&(g+"").toLowerCase()==="true"}c.exports=function(p,g){function u(){if(!f){if(d("throwDeprecation"))throw new Error(g);d("traceDeprecation")?console.trace(g):console.warn(g),f=!0}return p.apply(this,arguments)}if(d("noDeprecation"))return p;var f=!1;return u}}).call(this)}).call(this,typeof Ze>"u"?typeof self>"u"?typeof window>"u"?{}:window:self:Ze)},{}],"/":[function(o,c){function l(L){return L.replace(/a=ice-options:trickle\s\n/g,"")}function d(L){console.warn(L)}/*! simple-peer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */const p=o("debug")("simple-peer"),g=o("get-browser-rtc"),u=o("randombytes"),f=o("readable-stream"),x=o("queue-microtask"),b=o("err-code"),{Buffer:E}=o("buffer"),A=65536;class v extends f.Duplex{constructor(m){if(m=Object.assign({allowHalfOpen:!1},m),super(m),this._id=u(4).toString("hex").slice(0,7),this._debug("new peer %o",m),this.channelName=m.initiator?m.channelName||u(20).toString("hex"):null,this.initiator=m.initiator||!1,this.channelConfig=m.channelConfig||v.channelConfig,this.channelNegotiated=this.channelConfig.negotiated,this.config=Object.assign({},v.config,m.config),this.offerOptions=m.offerOptions||{},this.answerOptions=m.answerOptions||{},this.sdpTransform=m.sdpTransform||(k=>k),this.streams=m.streams||(m.stream?[m.stream]:[]),this.trickle=m.trickle===void 0||m.trickle,this.allowHalfTrickle=m.allowHalfTrickle!==void 0&&m.allowHalfTrickle,this.iceCompleteTimeout=m.iceCompleteTimeout||5e3,this.destroyed=!1,this.destroying=!1,this._connected=!1,this.remoteAddress=void 0,this.remoteFamily=void 0,this.remotePort=void 0,this.localAddress=void 0,this.localFamily=void 0,this.localPort=void 0,this._wrtc=m.wrtc&&typeof m.wrtc=="object"?m.wrtc:g(),!this._wrtc)throw b(typeof window>"u"?new Error("No WebRTC support: Specify `opts.wrtc` option in this environment"):new Error("No WebRTC support: Not a supported browser"),"ERR_WEBRTC_SUPPORT");this._pcReady=!1,this._channelReady=!1,this._iceComplete=!1,this._iceCompleteTimer=null,this._channel=null,this._pendingCandidates=[],this._isNegotiating=!1,this._firstNegotiation=!0,this._batchedNegotiation=!1,this._queuedNegotiation=!1,this._sendersAwaitingStable=[],this._senderMap=new Map,this._closingInterval=null,this._remoteTracks=[],this._remoteStreams=[],this._chunk=null,this._cb=null,this._interval=null;try{this._pc=new this._wrtc.RTCPeerConnection(this.config)}catch(k){return void this.destroy(b(k,"ERR_PC_CONSTRUCTOR"))}this._isReactNativeWebrtc=typeof this._pc._peerConnectionId=="number",this._pc.oniceconnectionstatechange=()=>{this._onIceStateChange()},this._pc.onicegatheringstatechange=()=>{this._onIceStateChange()},this._pc.onconnectionstatechange=()=>{this._onConnectionStateChange()},this._pc.onsignalingstatechange=()=>{this._onSignalingStateChange()},this._pc.onicecandidate=k=>{this._onIceCandidate(k)},typeof this._pc.peerIdentity=="object"&&this._pc.peerIdentity.catch(k=>{this.destroy(b(k,"ERR_PC_PEER_IDENTITY"))}),this.initiator||this.channelNegotiated?this._setupData({channel:this._pc.createDataChannel(this.channelName,this.channelConfig)}):this._pc.ondatachannel=k=>{this._setupData(k)},this.streams&&this.streams.forEach(k=>{this.addStream(k)}),this._pc.ontrack=k=>{this._onTrack(k)},this._debug("initial negotiation"),this._needsNegotiation(),this._onFinishBound=()=>{this._onFinish()},this.once("finish",this._onFinishBound)}get bufferSize(){return this._channel&&this._channel.bufferedAmount||0}get connected(){return this._connected&&this._channel.readyState==="open"}address(){return{port:this.localPort,family:this.localFamily,address:this.localAddress}}signal(m){if(!this.destroying){if(this.destroyed)throw b(new Error("cannot signal after peer is destroyed"),"ERR_DESTROYED");if(typeof m=="string")try{m=JSON.parse(m)}catch{m={}}this._debug("signal()"),m.renegotiate&&this.initiator&&(this._debug("got request to renegotiate"),this._needsNegotiation()),m.transceiverRequest&&this.initiator&&(this._debug("got request for transceiver"),this.addTransceiver(m.transceiverRequest.kind,m.transceiverRequest.init)),m.candidate&&(this._pc.remoteDescription&&this._pc.remoteDescription.type?this._addIceCandidate(m.candidate):this._pendingCandidates.push(m.candidate)),m.sdp&&this._pc.setRemoteDescription(new this._wrtc.RTCSessionDescription(m)).then(()=>{this.destroyed||(this._pendingCandidates.forEach(k=>{this._addIceCandidate(k)}),this._pendingCandidates=[],this._pc.remoteDescription.type==="offer"&&this._createAnswer())}).catch(k=>{this.destroy(b(k,"ERR_SET_REMOTE_DESCRIPTION"))}),m.sdp||m.candidate||m.renegotiate||m.transceiverRequest||this.destroy(b(new Error("signal() called with invalid signal data"),"ERR_SIGNALING"))}}_addIceCandidate(m){const k=new this._wrtc.RTCIceCandidate(m);this._pc.addIceCandidate(k).catch(_=>{!k.address||k.address.endsWith(".local")?d("Ignoring unsupported ICE candidate."):this.destroy(b(_,"ERR_ADD_ICE_CANDIDATE"))})}send(m){if(!this.destroying){if(this.destroyed)throw b(new Error("cannot send after peer is destroyed"),"ERR_DESTROYED");this._channel.send(m)}}addTransceiver(m,k){if(!this.destroying){if(this.destroyed)throw b(new Error("cannot addTransceiver after peer is destroyed"),"ERR_DESTROYED");if(this._debug("addTransceiver()"),this.initiator)try{this._pc.addTransceiver(m,k),this._needsNegotiation()}catch(_){this.destroy(b(_,"ERR_ADD_TRANSCEIVER"))}else this.emit("signal",{type:"transceiverRequest",transceiverRequest:{kind:m,init:k}})}}addStream(m){if(!this.destroying){if(this.destroyed)throw b(new Error("cannot addStream after peer is destroyed"),"ERR_DESTROYED");this._debug("addStream()"),m.getTracks().forEach(k=>{this.addTrack(k,m)})}}addTrack(m,k){if(this.destroying)return;if(this.destroyed)throw b(new Error("cannot addTrack after peer is destroyed"),"ERR_DESTROYED");this._debug("addTrack()");const _=this._senderMap.get(m)||new Map;let T=_.get(k);if(!T)T=this._pc.addTrack(m,k),_.set(k,T),this._senderMap.set(m,_),this._needsNegotiation();else throw T.removed?b(new Error("Track has been removed. You should enable/disable tracks that you want to re-add."),"ERR_SENDER_REMOVED"):b(new Error("Track has already been added to that stream."),"ERR_SENDER_ALREADY_ADDED")}replaceTrack(m,k,_){if(this.destroying)return;if(this.destroyed)throw b(new Error("cannot replaceTrack after peer is destroyed"),"ERR_DESTROYED");this._debug("replaceTrack()");const T=this._senderMap.get(m),S=T?T.get(_):null;if(!S)throw b(new Error("Cannot replace track that was never added."),"ERR_TRACK_NOT_ADDED");k&&this._senderMap.set(k,T),S.replaceTrack==null?this.destroy(b(new Error("replaceTrack is not supported in this browser"),"ERR_UNSUPPORTED_REPLACETRACK")):S.replaceTrack(k)}removeTrack(m,k){if(this.destroying)return;if(this.destroyed)throw b(new Error("cannot removeTrack after peer is destroyed"),"ERR_DESTROYED");this._debug("removeSender()");const _=this._senderMap.get(m),T=_?_.get(k):null;if(!T)throw b(new Error("Cannot remove track that was never added."),"ERR_TRACK_NOT_ADDED");try{T.removed=!0,this._pc.removeTrack(T)}catch(S){S.name==="NS_ERROR_UNEXPECTED"?this._sendersAwaitingStable.push(T):this.destroy(b(S,"ERR_REMOVE_TRACK"))}this._needsNegotiation()}removeStream(m){if(!this.destroying){if(this.destroyed)throw b(new Error("cannot removeStream after peer is destroyed"),"ERR_DESTROYED");this._debug("removeSenders()"),m.getTracks().forEach(k=>{this.removeTrack(k,m)})}}_needsNegotiation(){this._debug("_needsNegotiation"),this._batchedNegotiation||(this._batchedNegotiation=!0,x(()=>{this._batchedNegotiation=!1,this.initiator||!this._firstNegotiation?(this._debug("starting batched negotiation"),this.negotiate()):this._debug("non-initiator initial negotiation request discarded"),this._firstNegotiation=!1}))}negotiate(){if(!this.destroying){if(this.destroyed)throw b(new Error("cannot negotiate after peer is destroyed"),"ERR_DESTROYED");this.initiator?this._isNegotiating?(this._queuedNegotiation=!0,this._debug("already negotiating, queueing")):(this._debug("start negotiation"),setTimeout(()=>{this._createOffer()},0)):this._isNegotiating?(this._queuedNegotiation=!0,this._debug("already negotiating, queueing")):(this._debug("requesting negotiation from initiator"),this.emit("signal",{type:"renegotiate",renegotiate:!0})),this._isNegotiating=!0}}destroy(m){this._destroy(m,()=>{})}_destroy(m,k){this.destroyed||this.destroying||(this.destroying=!0,this._debug("destroying (error: %s)",m&&(m.message||m)),x(()=>{if(this.destroyed=!0,this.destroying=!1,this._debug("destroy (error: %s)",m&&(m.message||m)),this.readable=this.writable=!1,this._readableState.ended||this.push(null),this._writableState.finished||this.end(),this._connected=!1,this._pcReady=!1,this._channelReady=!1,this._remoteTracks=null,this._remoteStreams=null,this._senderMap=null,clearInterval(this._closingInterval),this._closingInterval=null,clearInterval(this._interval),this._interval=null,this._chunk=null,this._cb=null,this._onFinishBound&&this.removeListener("finish",this._onFinishBound),this._onFinishBound=null,this._channel){try{this._channel.close()}catch{}this._channel.onmessage=null,this._channel.onopen=null,this._channel.onclose=null,this._channel.onerror=null}if(this._pc){try{this._pc.close()}catch{}this._pc.oniceconnectionstatechange=null,this._pc.onicegatheringstatechange=null,this._pc.onsignalingstatechange=null,this._pc.onicecandidate=null,this._pc.ontrack=null,this._pc.ondatachannel=null}this._pc=null,this._channel=null,m&&this.emit("error",m),this.emit("close"),k()}))}_setupData(m){if(!m.channel)return this.destroy(b(new Error("Data channel event is missing `channel` property"),"ERR_DATA_CHANNEL"));this._channel=m.channel,this._channel.binaryType="arraybuffer",typeof this._channel.bufferedAmountLowThreshold=="number"&&(this._channel.bufferedAmountLowThreshold=A),this.channelName=this._channel.label,this._channel.onmessage=_=>{this._onChannelMessage(_)},this._channel.onbufferedamountlow=()=>{this._onChannelBufferedAmountLow()},this._channel.onopen=()=>{this._onChannelOpen()},this._channel.onclose=()=>{this._onChannelClose()},this._channel.onerror=_=>{const T=_.error instanceof Error?_.error:new Error(`Datachannel error: ${_.message} ${_.filename}:${_.lineno}:${_.colno}`);this.destroy(b(T,"ERR_DATA_CHANNEL"))};let k=!1;this._closingInterval=setInterval(()=>{this._channel&&this._channel.readyState==="closing"?(k&&this._onChannelClose(),k=!0):k=!1},5e3)}_read(){}_write(m,k,_){if(this.destroyed)return _(b(new Error("cannot write after peer is destroyed"),"ERR_DATA_CHANNEL"));if(this._connected){try{this.send(m)}catch(T){return this.destroy(b(T,"ERR_DATA_CHANNEL"))}this._channel.bufferedAmount>A?(this._debug("start backpressure: bufferedAmount %d",this._channel.bufferedAmount),this._cb=_):_(null)}else this._debug("write before connect"),this._chunk=m,this._cb=_}_onFinish(){if(!this.destroyed){const m=()=>{setTimeout(()=>this.destroy(),1e3)};this._connected?m():this.once("connect",m)}}_startIceCompleteTimeout(){this.destroyed||this._iceCompleteTimer||(this._debug("started iceComplete timeout"),this._iceCompleteTimer=setTimeout(()=>{this._iceComplete||(this._iceComplete=!0,this._debug("iceComplete timeout completed"),this.emit("iceTimeout"),this.emit("_iceComplete"))},this.iceCompleteTimeout))}_createOffer(){this.destroyed||this._pc.createOffer(this.offerOptions).then(m=>{if(this.destroyed)return;this.trickle||this.allowHalfTrickle||(m.sdp=l(m.sdp)),m.sdp=this.sdpTransform(m.sdp);const k=()=>{if(!this.destroyed){const _=this._pc.localDescription||m;this._debug("signal"),this.emit("signal",{type:_.type,sdp:_.sdp})}};this._pc.setLocalDescription(m).then(()=>{this._debug("createOffer success"),this.destroyed||(this.trickle||this._iceComplete?k():this.once("_iceComplete",k))}).catch(_=>{this.destroy(b(_,"ERR_SET_LOCAL_DESCRIPTION"))})}).catch(m=>{this.destroy(b(m,"ERR_CREATE_OFFER"))})}_requestMissingTransceivers(){this._pc.getTransceivers&&this._pc.getTransceivers().forEach(m=>{m.mid||!m.sender.track||m.requested||(m.requested=!0,this.addTransceiver(m.sender.track.kind))})}_createAnswer(){this.destroyed||this._pc.createAnswer(this.answerOptions).then(m=>{if(this.destroyed)return;this.trickle||this.allowHalfTrickle||(m.sdp=l(m.sdp)),m.sdp=this.sdpTransform(m.sdp);const k=()=>{if(!this.destroyed){const _=this._pc.localDescription||m;this._debug("signal"),this.emit("signal",{type:_.type,sdp:_.sdp}),this.initiator||this._requestMissingTransceivers()}};this._pc.setLocalDescription(m).then(()=>{this.destroyed||(this.trickle||this._iceComplete?k():this.once("_iceComplete",k))}).catch(_=>{this.destroy(b(_,"ERR_SET_LOCAL_DESCRIPTION"))})}).catch(m=>{this.destroy(b(m,"ERR_CREATE_ANSWER"))})}_onConnectionStateChange(){this.destroyed||this._pc.connectionState==="failed"&&this.destroy(b(new Error("Connection failed."),"ERR_CONNECTION_FAILURE"))}_onIceStateChange(){if(this.destroyed)return;const m=this._pc.iceConnectionState,k=this._pc.iceGatheringState;this._debug("iceStateChange (connection: %s) (gathering: %s)",m,k),this.emit("iceStateChange",m,k),(m==="connected"||m==="completed")&&(this._pcReady=!0,this._maybeReady()),m==="failed"&&this.destroy(b(new Error("Ice connection failed."),"ERR_ICE_CONNECTION_FAILURE")),m==="closed"&&this.destroy(b(new Error("Ice connection closed."),"ERR_ICE_CONNECTION_CLOSED"))}getStats(m){const k=_=>(Object.prototype.toString.call(_.values)==="[object Array]"&&_.values.forEach(T=>{Object.assign(_,T)}),_);this._pc.getStats.length===0||this._isReactNativeWebrtc?this._pc.getStats().then(_=>{const T=[];_.forEach(S=>{T.push(k(S))}),m(null,T)},_=>m(_)):0<this._pc.getStats.length?this._pc.getStats(_=>{if(this.destroyed)return;const T=[];_.result().forEach(S=>{const N={};S.names().forEach(D=>{N[D]=S.stat(D)}),N.id=S.id,N.type=S.type,N.timestamp=S.timestamp,T.push(k(N))}),m(null,T)},_=>m(_)):m(null,[])}_maybeReady(){if(this._debug("maybeReady pc %s channel %s",this._pcReady,this._channelReady),this._connected||this._connecting||!this._pcReady||!this._channelReady)return;this._connecting=!0;const m=()=>{this.destroyed||this.getStats((k,_)=>{if(this.destroyed)return;k&&(_=[]);const T={},S={},N={};let D=!1;_.forEach(R=>{(R.type==="remotecandidate"||R.type==="remote-candidate")&&(T[R.id]=R),(R.type==="localcandidate"||R.type==="local-candidate")&&(S[R.id]=R),(R.type==="candidatepair"||R.type==="candidate-pair")&&(N[R.id]=R)});const j=R=>{D=!0;let O=S[R.localCandidateId];O&&(O.ip||O.address)?(this.localAddress=O.ip||O.address,this.localPort=+O.port):O&&O.ipAddress?(this.localAddress=O.ipAddress,this.localPort=+O.portNumber):typeof R.googLocalAddress=="string"&&(O=R.googLocalAddress.split(":"),this.localAddress=O[0],this.localPort=+O[1]),this.localAddress&&(this.localFamily=this.localAddress.includes(":")?"IPv6":"IPv4");let U=T[R.remoteCandidateId];U&&(U.ip||U.address)?(this.remoteAddress=U.ip||U.address,this.remotePort=+U.port):U&&U.ipAddress?(this.remoteAddress=U.ipAddress,this.remotePort=+U.portNumber):typeof R.googRemoteAddress=="string"&&(U=R.googRemoteAddress.split(":"),this.remoteAddress=U[0],this.remotePort=+U[1]),this.remoteAddress&&(this.remoteFamily=this.remoteAddress.includes(":")?"IPv6":"IPv4"),this._debug("connect local: %s:%s remote: %s:%s",this.localAddress,this.localPort,this.remoteAddress,this.remotePort)};if(_.forEach(R=>{R.type==="transport"&&R.selectedCandidatePairId&&j(N[R.selectedCandidatePairId]),(R.type==="googCandidatePair"&&R.googActiveConnection==="true"||(R.type==="candidatepair"||R.type==="candidate-pair")&&R.selected)&&j(R)}),!D&&(!Object.keys(N).length||Object.keys(S).length))return void setTimeout(m,100);if(this._connecting=!1,this._connected=!0,this._chunk){try{this.send(this._chunk)}catch(O){return this.destroy(b(O,"ERR_DATA_CHANNEL"))}this._chunk=null,this._debug('sent chunk from "write before connect"');const R=this._cb;this._cb=null,R(null)}typeof this._channel.bufferedAmountLowThreshold!="number"&&(this._interval=setInterval(()=>this._onInterval(),150),this._interval.unref&&this._interval.unref()),this._debug("connect"),this.emit("connect")})};m()}_onInterval(){this._cb&&this._channel&&!(this._channel.bufferedAmount>A)&&this._onChannelBufferedAmountLow()}_onSignalingStateChange(){this.destroyed||(this._pc.signalingState==="stable"&&(this._isNegotiating=!1,this._debug("flushing sender queue",this._sendersAwaitingStable),this._sendersAwaitingStable.forEach(m=>{this._pc.removeTrack(m),this._queuedNegotiation=!0}),this._sendersAwaitingStable=[],this._queuedNegotiation?(this._debug("flushing negotiation queue"),this._queuedNegotiation=!1,this._needsNegotiation()):(this._debug("negotiated"),this.emit("negotiated"))),this._debug("signalingStateChange %s",this._pc.signalingState),this.emit("signalingStateChange",this._pc.signalingState))}_onIceCandidate(m){this.destroyed||(m.candidate&&this.trickle?this.emit("signal",{type:"candidate",candidate:{candidate:m.candidate.candidate,sdpMLineIndex:m.candidate.sdpMLineIndex,sdpMid:m.candidate.sdpMid}}):!m.candidate&&!this._iceComplete&&(this._iceComplete=!0,this.emit("_iceComplete")),m.candidate&&this._startIceCompleteTimeout())}_onChannelMessage(m){if(this.destroyed)return;let k=m.data;k instanceof ArrayBuffer&&(k=E.from(k)),this.push(k)}_onChannelBufferedAmountLow(){if(!this.destroyed&&this._cb){this._debug("ending backpressure: bufferedAmount %d",this._channel.bufferedAmount);const m=this._cb;this._cb=null,m(null)}}_onChannelOpen(){this._connected||this.destroyed||(this._debug("on channel open"),this._channelReady=!0,this._maybeReady())}_onChannelClose(){this.destroyed||(this._debug("on channel close"),this.destroy())}_onTrack(m){this.destroyed||m.streams.forEach(k=>{this._debug("on track"),this.emit("track",m.track,k),this._remoteTracks.push({track:m.track,stream:k}),this._remoteStreams.some(_=>_.id===k.id)||(this._remoteStreams.push(k),x(()=>{this._debug("on stream"),this.emit("stream",k)}))})}_debug(){const m=[].slice.call(arguments);m[0]="["+this._id+"] "+m[0],p.apply(null,m)}}v.WEBRTC_SUPPORT=!!g(),v.config={iceServers:[{urls:["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478"]}],sdpSemantics:"unified-plan"},v.channelConfig={},c.exports=v},{buffer:3,debug:4,"err-code":6,"get-browser-rtc":8,"queue-microtask":13,randombytes:14,"readable-stream":29}]},{},[])("/")})})(Gn)),Gn.exports}var Vh=Hh();const Gh=bl(Vh),ti=0,si=1,Va=2,Ga=(t,e)=>{ie(t,ti);const s=bu(e);je(t,s)},qa=(t,e,s)=>{ie(t,si),je(t,Gr(e,s))},qh=(t,e,s)=>qa(e,s,Re(t)),Ya=(t,e,s,r)=>{try{ua(e,Re(t),s)}catch(i){r!=null&&r(i),console.error("Caught error while handling a Yjs update",i)}},Yh=(t,e)=>{ie(t,Va),je(t,e)},Kh=Ya,Jh=(t,e,s,r,i)=>{const o=de(t);switch(o){case ti:qh(t,e,s);break;case si:Ya(t,s,r,i);break;case Va:Kh(t,s,r,i);break;default:throw new Error("Unknown message type")}return o},qn=3e4;class Xh extends Cr{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{const s=ct();this.getLocalState()!==null&&qn/2<=s-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const r=[];this.meta.forEach((i,o)=>{o!==this.clientID&&qn<=s-i.lastUpdated&&this.states.has(o)&&r.push(o)}),r.length>0&&hr(this,r,"timeout")},Je(qn/10)),e.on("destroy",()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(e){const s=this.clientID,r=this.meta.get(s),i=r===void 0?0:r.clock+1,o=this.states.get(s);e===null?this.states.delete(s):this.states.set(s,e),this.meta.set(s,{clock:i,lastUpdated:ct()});const c=[],l=[],d=[],p=[];e===null?p.push(s):o==null?e!=null&&c.push(s):(l.push(s),Ut(o,e)||d.push(s)),(c.length>0||d.length>0||p.length>0)&&this.emit("change",[{added:c,updated:d,removed:p},"local"]),this.emit("update",[{added:c,updated:l,removed:p},"local"])}setLocalStateField(e,s){const r=this.getLocalState();r!==null&&this.setLocalState({...r,[e]:s})}getStates(){return this.states}}const hr=(t,e,s)=>{const r=[];for(let i=0;i<e.length;i++){const o=e[i];if(t.states.has(o)){if(t.states.delete(o),o===t.clientID){const c=t.meta.get(o);t.meta.set(o,{clock:c.clock+1,lastUpdated:ct()})}r.push(o)}}r.length>0&&(t.emit("change",[{added:[],updated:[],removed:r},s]),t.emit("update",[{added:[],updated:[],removed:r},s]))},on=(t,e,s=t.states)=>{const r=e.length,i=Ae();ie(i,r);for(let o=0;o<r;o++){const c=e[o],l=s.get(c)||null,d=t.meta.get(c).clock;ie(i,c),ie(i,d),tt(i,JSON.stringify(l))}return Se(i)},Qh=(t,e,s)=>{const r=rt(e),i=ct(),o=[],c=[],l=[],d=[],p=de(r);for(let g=0;g<p;g++){const u=de(r);let f=de(r);const x=JSON.parse(at(r)),b=t.meta.get(u),E=t.states.get(u),A=b===void 0?0:b.clock;(A<f||A===f&&x===null&&t.states.has(u))&&(x===null?u===t.clientID&&t.getLocalState()!=null?f++:t.states.delete(u):t.states.set(u,x),t.meta.set(u,{clock:f,lastUpdated:i}),b===void 0&&x!==null?o.push(u):b!==void 0&&x===null?d.push(u):x!==null&&(Ut(x,E)||l.push(u),c.push(u)))}(o.length>0||l.length>0||d.length>0)&&t.emit("change",[{added:o,updated:l,removed:d},s]),(o.length>0||c.length>0||d.length>0)&&t.emit("update",[{added:o,updated:c,removed:d},s])},Zh=(t,e)=>{const s=nr(t).buffer,r=nr(e).buffer;return crypto.subtle.importKey("raw",s,"PBKDF2",!1,["deriveKey"]).then(i=>crypto.subtle.deriveKey({name:"PBKDF2",salt:r,iterations:1e5,hash:"SHA-256"},i,{name:"AES-GCM",length:256},!0,["encrypt","decrypt"]))},Ka=(t,e)=>{if(!e)return Dr(t);const s=crypto.getRandomValues(new Uint8Array(12));return crypto.subtle.encrypt({name:"AES-GCM",iv:s},e,t).then(r=>{const i=Ae();return tt(i,"AES-GCM"),je(i,s),je(i,new Uint8Array(r)),Se(i)})},ef=(t,e)=>{const s=Ae();return Vt(s,t),Ka(Se(s),e)},Ja=(t,e)=>{if(!e)return Dr(t);const s=rt(t);at(s)!=="AES-GCM"&&zc(Ve("Unknown encryption algorithm"));const i=Re(s),o=Re(s);return crypto.subtle.decrypt({name:"AES-GCM",iv:i},e,o).then(c=>new Uint8Array(c))},tf=(t,e)=>Ja(t,e).then(s=>Gt(rt(new Uint8Array(s)))),$e=tu("y-webrtc"),Ht=0,Xa=3,_s=1,ni=4,an=new Map,jt=new Map,Qa=t=>{let e=!0;t.webrtcConns.forEach(s=>{s.synced||(e=!1)}),(!e&&t.synced||e&&!t.synced)&&(t.synced=e,t.provider.emit("synced",[{synced:e}]),$e("synced ",Ke,t.name,Nt," with all peers"))},Za=(t,e,s)=>{const r=rt(e),i=Ae(),o=de(r);if(t===void 0)return null;const c=t.awareness,l=t.doc;let d=!1;switch(o){case Ht:{ie(i,Ht);const p=Jh(r,i,l,t);p===si&&!t.synced&&s(),p===ti&&(d=!0);break}case Xa:ie(i,_s),je(i,on(c,Array.from(c.getStates().keys()))),d=!0;break;case _s:Qh(c,Re(r),t);break;case ni:{const p=Et(r)===1,g=at(r);if(g!==t.peerId&&(t.bcConns.has(g)&&!p||!t.bcConns.has(g)&&p)){const u=[],f=[];p?(t.bcConns.add(g),f.push(g)):(t.bcConns.delete(g),u.push(g)),t.provider.emit("peers",[{added:f,removed:u,webrtcPeers:Array.from(t.webrtcConns.keys()),bcPeers:Array.from(t.bcConns)}]),el(t)}break}default:return console.error("Unable to compute message"),i}return d?i:null},sf=(t,e)=>{const s=t.room;return $e("received message from ",Ke,t.remotePeerId,$r," (",s.name,")",Nt,En),Za(s,e,()=>{t.synced=!0,$e("synced ",Ke,s.name,Nt," with ",Ke,t.remotePeerId),Qa(s)})},Yn=(t,e)=>{$e("send message to ",Ke,t.remotePeerId,Nt,$r," (",t.room.name,")",En);try{t.peer.send(Se(e))}catch{}},nf=(t,e)=>{$e("broadcast message in ",Ke,t.name,Nt),t.webrtcConns.forEach(s=>{try{s.peer.send(e)}catch{}})};class Mi{constructor(e,s,r,i){$e("establishing connection to ",Ke,r),this.room=i,this.remotePeerId=r,this.glareToken=void 0,this.closed=!1,this.connected=!1,this.synced=!1,this.peer=new Gh({initiator:s,...i.provider.peerOpts}),this.peer.on("signal",o=>{this.glareToken===void 0&&(this.glareToken=Date.now()+Math.random()),ri(e,i,{to:r,from:i.peerId,type:"signal",token:this.glareToken,signal:o})}),this.peer.on("connect",()=>{$e("connected to ",Ke,r),this.connected=!0;const c=i.provider.doc,l=i.awareness,d=Ae();ie(d,Ht),Ga(d,c),Yn(this,d);const p=l.getStates();if(p.size>0){const g=Ae();ie(g,_s),je(g,on(l,Array.from(p.keys()))),Yn(this,g)}}),this.peer.on("close",()=>{this.connected=!1,this.closed=!0,i.webrtcConns.has(this.remotePeerId)&&(i.webrtcConns.delete(this.remotePeerId),i.provider.emit("peers",[{removed:[this.remotePeerId],added:[],webrtcPeers:Array.from(i.webrtcConns.keys()),bcPeers:Array.from(i.bcConns)}])),Qa(i),this.peer.destroy(),$e("closed connection to ",Ke,r),fr(i)}),this.peer.on("error",o=>{$e("Error in connection to ",Ke,r,": ",o),fr(i)}),this.peer.on("data",o=>{const c=sf(this,o);c!==null&&Yn(this,c)})}destroy(){this.peer.destroy()}}const ft=(t,e)=>Ka(e,t.key).then(s=>t.mux(()=>$h(t.name,s))),Oi=(t,e)=>{t.bcconnected&&ft(t,e),nf(t,e)},fr=t=>{an.forEach(e=>{e.connected&&(e.send({type:"subscribe",topics:[t.name]}),t.webrtcConns.size<t.provider.maxConns&&ri(e,t,{type:"announce",from:t.peerId}))})},el=t=>{if(t.provider.filterBcConns){const e=Ae();ie(e,ni),ms(e,1),tt(e,t.peerId),ft(t,Se(e))}};class rf{constructor(e,s,r,i){this.peerId=_o(),this.doc=e,this.awareness=s.awareness,this.provider=s,this.synced=!1,this.name=r,this.key=i,this.webrtcConns=new Map,this.bcConns=new Set,this.mux=zh(),this.bcconnected=!1,this._bcSubscriber=o=>Ja(new Uint8Array(o),i).then(c=>this.mux(()=>{const l=Za(this,c,()=>{});l&&ft(this,Se(l))})),this._docUpdateHandler=(o,c)=>{const l=Ae();ie(l,Ht),Yh(l,o),Oi(this,Se(l))},this._awarenessUpdateHandler=({added:o,updated:c,removed:l},d)=>{const p=o.concat(c).concat(l),g=Ae();ie(g,_s),je(g,on(this.awareness,p)),Oi(this,Se(g))},this._beforeUnloadHandler=()=>{hr(this.awareness,[e.clientID],"window unload"),jt.forEach(o=>{o.disconnect()})},typeof window<"u"?window.addEventListener("beforeunload",this._beforeUnloadHandler):typeof process<"u"&&process.on("exit",this._beforeUnloadHandler)}connect(){this.doc.on("update",this._docUpdateHandler),this.awareness.on("update",this._awarenessUpdateHandler),fr(this);const e=this.name;Uh(e,this._bcSubscriber),this.bcconnected=!0,el(this);const s=Ae();ie(s,Ht),Ga(s,this.doc),ft(this,Se(s));const r=Ae();ie(r,Ht),qa(r,this.doc),ft(this,Se(r));const i=Ae();ie(i,Xa),ft(this,Se(i));const o=Ae();ie(o,_s),je(o,on(this.awareness,[this.doc.clientID])),ft(this,Se(o))}disconnect(){an.forEach(s=>{s.connected&&s.send({type:"unsubscribe",topics:[this.name]})}),hr(this.awareness,[this.doc.clientID],"disconnect");const e=Ae();ie(e,ni),ms(e,0),tt(e,this.peerId),ft(this,Se(e)),Fh(this.name,this._bcSubscriber),this.bcconnected=!1,this.doc.off("update",this._docUpdateHandler),this.awareness.off("update",this._awarenessUpdateHandler),this.webrtcConns.forEach(s=>s.destroy())}destroy(){this.disconnect(),typeof window<"u"?window.removeEventListener("beforeunload",this._beforeUnloadHandler):typeof process<"u"&&process.off("exit",this._beforeUnloadHandler)}}const of=(t,e,s,r)=>{if(jt.has(s))throw Ve(`A Yjs Doc connected to room "${s}" already exists!`);const i=new rf(t,e,s,r);return jt.set(s,i),i},ri=(t,e,s)=>{e.key?ef(s,e.key).then(r=>{t.send({type:"publish",topic:e.name,data:Ao(r)})}):t.send({type:"publish",topic:e.name,data:s})};class af extends Wh{constructor(e){super(e),this.providers=new Set,this.on("connect",()=>{$e(`connected (${e})`);const s=Array.from(jt.keys());this.send({type:"subscribe",topics:s}),jt.forEach(r=>ri(this,r,{type:"announce",from:r.peerId}))}),this.on("message",s=>{switch(s.type){case"publish":{const r=s.topic,i=jt.get(r);if(i==null||typeof r!="string")return;const o=c=>{const l=i.webrtcConns,d=i.peerId;if(c==null||c.from===d||c.to!==void 0&&c.to!==d||i.bcConns.has(c.from))return;const p=l.has(c.from)?()=>{}:()=>i.provider.emit("peers",[{removed:[],added:[c.from],webrtcPeers:Array.from(i.webrtcConns.keys()),bcPeers:Array.from(i.bcConns)}]);switch(c.type){case"announce":l.size<i.provider.maxConns&&(He(l,c.from,()=>new Mi(this,!0,c.from,i)),p());break;case"signal":if(c.signal.type==="offer"){const g=l.get(c.from);if(g){const u=c.token,f=g.glareToken;if(f&&f>u){$e("offer rejected: ",c.from);return}g.glareToken=void 0}}if(c.signal.type==="answer"){$e("offer answered by: ",c.from);const g=l.get(c.from);g.glareToken=void 0}c.to===d&&(He(l,c.from,()=>new Mi(this,!1,c.from,i)).peer.signal(c.signal),p());break}};i.key?typeof s.data=="string"&&tf(Lo(s.data),i.key).then(o):o(s.data)}}}),this.on("disconnect",()=>$e(`disconnect (${e})`))}}const Kn=t=>{t.emit("status",[{connected:t.connected}])};class lf extends go{constructor(e,s,{signaling:r=["wss://y-webrtc-eu.fly.dev"],password:i=null,awareness:o=new Xh(s),maxConns:c=20+Je(Fc()*15),filterBcConns:l=!0,peerOpts:d={}}={}){super(),this.roomName=e,this.doc=s,this.filterBcConns=l,this.awareness=o,this.shouldConnect=!1,this.signalingUrls=r,this.signalingConns=[],this.maxConns=c,this.peerOpts=d,this.key=i?Zh(i,e):Dr(null),this.room=null,this.key.then(p=>{this.room=of(s,this,e,p),this.shouldConnect?this.room.connect():this.room.disconnect(),Kn(this)}),this.connect(),this.destroy=this.destroy.bind(this),s.on("destroy",this.destroy)}get connected(){return this.room!==null&&this.shouldConnect}connect(){this.shouldConnect=!0,this.signalingUrls.forEach(e=>{const s=He(an,e,()=>new af(e));this.signalingConns.push(s),s.providers.add(this)}),this.room&&(this.room.connect(),Kn(this))}disconnect(){this.shouldConnect=!1,this.signalingConns.forEach(e=>{e.providers.delete(this),e.providers.size===0&&(e.destroy(),an.delete(e.url))}),this.room&&(this.room.disconnect(),Kn(this))}destroy(){this.doc.off("destroy",this.destroy),this.key.then(()=>{this.room.destroy(),jt.delete(this.roomName)}),super.destroy()}}const cs=new Map,ln=new Map,pr=new Map;function cf(){var t;try{return((t=globalThis.localStorage)==null?void 0:t.getItem("titan2:webrtc"))==="1"}catch{return!1}}function df(t){if(!cs.has(t)){const e=new ss({guid:`titan-space-${t}`});cs.set(t,e);const s=new Dh(`titan-space-${t}`,e);if(ln.set(t,s),cf())try{const r=new lf(`titan-space-${t}`,e,{signaling:["wss://signaling.yjs.dev","wss://y-webrtc-signaling-eu.herokuapp.com"]});pr.set(t,r)}catch{}}return cs.get(t)}function uf(t){const{widgets:e}=wt(t),s=new Set,r=[];e.forEach((i,o)=>{const c=i.get("id");typeof c!="string"||s.has(c)?r.push(o):s.add(c)});for(let i=r.length-1;i>=0;i--)e.delete(r[i],1);return r.length}function wt(t){const e=df(t),s=e.getArray("widgets"),r=e.getMap("meta"),i=ln.get(t);return{widgets:s,meta:r,doc:e,whenSynced:i!=null&&i.synced?Promise.resolve():new Promise(o=>{const c=()=>{i==null||i.off("synced",c),o()};i==null||i.on("synced",c),setTimeout(()=>o(),2e3)})}}function hf(t){return{id:t.get("id"),name:t.get("name"),format:t.get("format"),source:t.get("source"),x:t.get("x"),y:t.get("y"),w:t.get("w"),h:t.get("h"),metadata:t.get("metadata"),createdAt:t.get("createdAt"),updatedAt:t.get("updatedAt")}}function tl(t){const e=new Tt;return e.set("id",t.id),e.set("name",t.name),e.set("format",t.format),e.set("source",t.source),e.set("x",t.x),e.set("y",t.y),e.set("w",t.w),e.set("h",t.h),e.set("metadata",t.metadata),e.set("createdAt",t.createdAt),e.set("updatedAt",t.updatedAt),e}function ff(t){try{const e=typeof localStorage<"u"?localStorage.getItem("titan2-spaces"):null;if(!e)return null;const r=JSON.parse(e).find(o=>o.id===t);if(!r)return null;const i=new Set;for(const o of r.widgets||[])o&&typeof o.id=="string"&&i.add(o.id);return i}catch{return null}}const cn=new Map;function pf(t,e){let s=cn.get(t);s||(s=new Set,cn.set(t,s)),s.add(e)}function mf(t,e){var s;return((s=cn.get(t))==null?void 0:s.has(e))??!1}function sl(t){cn.delete(t)}function gf(t,e){const{widgets:s}=wt(t),r=new Map,i=()=>{const c=new Set,l=ff(t),d=[];s.forEach(p=>{const g=hf(p);if(!g.id||c.has(g.id))return;const u=g.format==="system",f=typeof g.source=="string"&&g.source.trim()!=="";!u&&!f||l&&!l.has(g.id)&&!mf(t,g.id)||(c.add(g.id),d.push(g))}),e(d)},o=()=>{const c=new Set;s.forEach(l=>c.add(l));for(const[l,d]of r)c.has(l)||(l.unobserve(d),r.delete(l));for(const l of c)if(!r.has(l)){const d=()=>i();l.observe(d),r.set(l,d)}i()};return s.observe(o),o(),()=>{s.unobserve(o);for(const[c,l]of r)c.unobserve(l);r.clear()}}function yf(t,e){const{widgets:s}=wt(t),r={...e,id:`widget_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,createdAt:Date.now(),updatedAt:Date.now()};return pf(t,r.id),s.push([tl(r)]),r}function bf(t,e){const{widgets:s}=wt(t);let r=-1;s.forEach((i,o)=>{i.get("id")===e&&(r=o)}),r>=0&&s.delete(r,1)}function Wi(t,e,s){const{widgets:r}=wt(t);r.forEach(i=>{if(i.get("id")===e){for(const[o,c]of Object.entries(s))i.set(o,c);i.set("updatedAt",Date.now())}})}function xf(t){const{widgets:e}=wt(t);e.delete(0,e.length),sl(t)}function wf(t){var e,s,r;(e=ln.get(t))==null||e.destroy(),(s=pr.get(t))==null||s.destroy(),(r=cs.get(t))==null||r.destroy(),ln.delete(t),pr.delete(t),cs.delete(t),sl(t)}const ds="titan2-spaces",vf=!0;function ue(t,e,s,r,i,o,c){return{id:t,name:e,format:"system",source:s,x:r,y:i,w:o,h:c,createdAt:Date.now(),updatedAt:Date.now()}}const Ds=[{id:"home",name:"Home",icon:"Home",color:"#6366f1",widgets:[ue("home-welcome","Welcome","system:soma",0,0,6,5),ue("home-voice","Voice","system:voice",6,0,6,5),ue("home-overview","Overview","system:overview",0,5,6,5),ue("home-sessions","Sessions","system:sessions",6,5,6,5),ue("home-watch","Watch","system:watch",0,10,12,7)],createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()},{id:"soma",name:"SOMA",icon:"Brain",color:"#8b5cf6",widgets:[ue("soma-main","SOMA","system:soma",0,0,8,8),ue("soma-memory","Memory Graph","system:memory-graph",8,0,4,8)],agentInstructions:"This is the SOMA consciousness space. Help the user explore consciousness, memory, and self-improvement.",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()},{id:"command",name:"Command Post",icon:"Terminal",color:"#ef4444",widgets:[ue("cp-hub","Command Post","system:command-post",0,0,12,10),ue("cp-proposals","Self-Proposals","system:self-proposals",0,10,12,6)],agentInstructions:"This is the Command Post. Help the user manage agents, runs, and operations.",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()},{id:"intelligence",name:"Intelligence",icon:"Network",color:"#10b981",widgets:[ue("intel-autopilot","Autopilot","system:intelligence-autopilot",0,0,6,5),ue("intel-workflows","Workflows","system:intelligence-workflows",6,0,6,5),ue("intel-learning","Learning","system:intelligence-learning",0,5,6,5),ue("intel-memory","Memory Graph","system:memory-graph",6,5,6,5),ue("intel-selfimprove","Self-Improve","system:intelligence-self-improve",0,10,6,5),ue("intel-personas","Personas","system:intelligence-personas",6,10,6,5),ue("intel-wiki","Memory Wiki","system:memory-wiki",0,15,6,6),ue("intel-autoresearch","Autoresearch","system:autoresearch",6,15,6,6)],agentInstructions:"This is the Intelligence space. Help the user explore memory graphs, wiki, and knowledge.",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()},{id:"infra",name:"Infrastructure",icon:"Server",color:"#f59e0b",widgets:[ue("infra-homelab","Homelab","system:infra-homelab",0,0,6,6),ue("infra-gpu","GPU / NVIDIA","system:infra-gpu",6,0,6,6),ue("infra-files","Files","system:infra-files",0,6,4,5),ue("infra-logs","Logs","system:infra-logs",4,6,4,5),ue("infra-telemetry","Telemetry","system:infra-telemetry",8,6,4,5),ue("infra-vram","VRAM","system:vram",0,11,6,5),ue("infra-fleet","Fleet","system:fleet",6,11,6,5)],createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()},{id:"tools",name:"Tools",icon:"Wrench",color:"#06b6d4",widgets:[ue("tools-skills","Skills","system:tools-skills",0,0,6,6),ue("tools-mcp","MCP Servers","system:tools-mcp",6,0,6,6),ue("tools-integrations","Integrations","system:tools-integrations",0,6,4,5),ue("tools-channels","Channels","system:tools-channels",4,6,4,5),ue("tools-mesh","Mesh Network","system:tools-mesh",8,6,4,5),ue("tools-recipes","Recipes","system:recipes",0,11,6,5),ue("tools-paperclip","Paperclip","system:paperclip",6,11,6,5),ue("tools-browser","Browser","system:browser",0,16,6,5),ue("tools-cron","Cron","system:cron",6,16,6,5)],createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()},{id:"settings",name:"Settings",icon:"Settings",color:"#6b7280",widgets:[ue("settings-specialists","Specialist Models","system:settings-specialists",0,0,6,8),ue("settings-privacy","Privacy & Telemetry","system:settings-privacy",6,0,6,8),ue("settings-general","General","system:settings-general",0,8,6,8),ue("settings-security","Security","system:settings-security",6,8,6,8),ue("settings-audit","Audit Log","system:settings-audit",0,16,12,6)],createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}],mr=11,_f={home:new Set(["home-chat"])};function kf(t,e){const{widgets:s,meta:r,whenSynced:i}=wt(t.id);i.then(()=>{try{const o=uf(t.id);if(o>0&&console.info(`[SpaceEngine] healed ${o} duplicate widget(s) in "${t.id}"`),e){const c=_f[t.id]??new Set;for(let p=s.length-1;p>=0;p--){const g=s.get(p),u=g==null?void 0:g.get("id");typeof u=="string"&&c.has(u)&&s.delete(p,1)}for(let p=s.length-1;p>=0;p--){const g=s.get(p),u=g==null?void 0:g.get("source");(typeof u!="string"||u.trim()==="")&&s.delete(p,1)}const l=new Map;for(const p of t.widgets)l.set(p.id,p);const d=new Set;s.forEach(p=>{const g=p.get("id");if(typeof g=="string"&&l.has(g)){d.add(g);const u=l.get(g);p.set("x",u.x),p.set("y",u.y),p.set("w",u.w),p.set("h",u.h)}});for(const p of t.widgets)d.has(p.id)||s.push([tl(p)]);r.set("seedVersion",mr)}}catch(o){console.warn(`[SpaceEngine] healYSpaceOnSync failed for "${t.id}":`,o)}})}function Sf(){try{const t=localStorage.getItem(ds),s=parseInt(localStorage.getItem(`${ds}-version`)||"0",10)<mr;if(vf)for(const o of Ds)kf(o,s);if(!t||s){localStorage.setItem(`${ds}-version`,String(mr));const o=Ds.map(c=>({...c,widgets:[...c.widgets]}));return kt(o),o}const r=JSON.parse(t);for(const o of r)Array.isArray(o.widgets)||(o.widgets=[]),o.widgets=o.widgets.filter(c=>c&&typeof c.id=="string").map(c=>({...c,x:Number.isFinite(c.x)?Math.max(0,Math.floor(c.x)):0,y:Number.isFinite(c.y)?Math.max(0,Math.floor(c.y)):0,w:Number.isFinite(c.w)?Math.max(1,Math.floor(c.w)):4,h:Number.isFinite(c.h)?Math.max(1,Math.floor(c.h)):4}));for(const o of r){const c=new Set;o.widgets=o.widgets.filter(l=>c.has(l.id)?!1:(c.add(l.id),!0))}const i=new Map(r.map(o=>[o.id,o]));return Ds.forEach(o=>{i.get(o.id)||i.set(o.id,{...o,widgets:[...o.widgets]})}),Array.from(i.values())}catch{return Ds.map(t=>({...t,widgets:[...t.widgets]}))}}let Jn=null;function kt(t){Jn&&clearTimeout(Jn),Jn=setTimeout(()=>{localStorage.setItem(ds,JSON.stringify(t))},250)}let Ge=null;const ke={list(){return Ge||(Ge=Sf()),Ge},get(t){return this.list().find(e=>e.id===t)},create(t){const e={id:`space_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,name:t,widgets:[],createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()};return Ge=[...this.list(),e],kt(Ge),e},save(t){t.updatedAt=new Date().toISOString(),Ge=this.list().map(e=>e.id===t.id?t:e),kt(Ge)},remove(t){Ge=this.list().filter(e=>e.id!==t),kt(Ge)},addWidget(t,e){if(!e.source||e.source.trim()==="")throw new Error("Widget source cannot be empty");{const s=yf(t,e);try{const r=localStorage.getItem(ds),i=r?JSON.parse(r):[],o=i.find(c=>c.id===t);if(o)new Set((o.widgets||[]).map(l=>l.id)).has(s.id)||(o.widgets=[...o.widgets||[],s]),o.updatedAt=new Date().toISOString(),Ge=i,kt(i);else{const c={id:t,name:t,widgets:[s],createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()};Ge=[...i,c],kt(Ge)}}catch{}return s}},updateWidget(t,e,s){Wi(t,e,s);const r=this.get(t);r&&(r.widgets=r.widgets.map(i=>i.id===e?{...i,...s,updatedAt:Date.now()}:i),this.save(r))},removeWidget(t,e){bf(t,e);const s=this.get(t);s&&(s.widgets=s.widgets.filter(r=>r.id!==e),this.save(s))},updateLayout(t,e){for(const r of e)Wi(t,r.i,{x:r.x,y:r.y,w:r.w,h:r.h});const s=this.get(t);s&&(s.widgets=s.widgets.map(r=>{const i=e.find(o=>o&&o.i===r.id);return i?{...r,x:Number.isFinite(i.x)?Math.max(0,Math.floor(i.x)):0,y:Number.isFinite(i.y)?Math.max(0,Math.floor(i.y)):0,w:Number.isFinite(i.w)?Math.max(1,Math.floor(i.w)):4,h:Number.isFinite(i.h)?Math.max(1,Math.floor(i.h)):4,updatedAt:Date.now()}:r}),this.save(s))},observe(t,e){return gf(t,e)},async clearSpace(t){{const{whenSynced:r}=wt(t);await r,xf(t),wf(t);try{const i=indexedDB.deleteDatabase(`titan-space-${t}`);await new Promise((o,c)=>{i.onsuccess=()=>o(),i.onerror=()=>c(i.error),i.onblocked=()=>o()})}catch{}}const e=this.list(),s=e.find(r=>r.id===t);s&&(s.widgets=[],kt(e))}};let is=null;function jf(){if(is)return is;const t=async e=>{const s=await fetch(e,{credentials:"same-origin"});if(!s.ok)throw new Error(`Failed to load ${e}: ${s.status} ${s.statusText}`);return s.text()};return is=Promise.all([t("/react.development.js"),t("/react-dom.development.js"),t("/babel.min.js")]).then(([e,s,r])=>({react:e,reactDom:s,babel:r})).catch(e=>{throw is=null,e}),is}function Ef(t){const e=Nf;return`<!DOCTYPE html><html><head><meta charset="UTF-8"><meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'unsafe-inline' 'unsafe-eval'; connect-src 'self'; style-src 'unsafe-inline'; img-src blob: data:; font-src data:;"><style>* { box-sizing: border-box; } html, body { margin: 0; padding: 0; height: 100%; } body { background: transparent; color: #e5e7eb; font-family: system-ui, -apple-system, sans-serif; font-size: 13px; overflow: hidden; } #root { width: 100%; height: 100%; }</style></head><body><div id="root"><div id="sandbox-loading" style="padding:16px;font-family:monospace;font-size:12px;color:#52525b;"><div>Booting widget…</div></div></div><script>`+t.react+"<\/script><script>"+t.reactDom+"<\/script><script>"+t.babel+"<\/script>"+e}const Nf=`
|
|
98
|
+
<script>
|
|
99
|
+
(function() {
|
|
100
|
+
'use strict';
|
|
101
|
+
|
|
102
|
+
// NOTE: Prototype freezing is intentionally disabled.
|
|
103
|
+
// Babel standalone mutates Function.prototype.toString during JSX transform.
|
|
104
|
+
// Freezing causes "Cannot assign to read only property" errors.
|
|
105
|
+
|
|
106
|
+
// Prevent eval and Function constructor abuse
|
|
107
|
+
window.eval = function() { throw new Error('eval is disabled in sandbox'); };
|
|
108
|
+
const OriginalFunction = window.Function;
|
|
109
|
+
window.Function = function(...args) {
|
|
110
|
+
const body = args.pop() || '';
|
|
111
|
+
if (body.includes('import') && body.includes('http')) {
|
|
112
|
+
throw new Error('Dynamic imports with URLs are disabled in sandbox');
|
|
113
|
+
}
|
|
114
|
+
return OriginalFunction.apply(this, [...args, body]);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const pending = new Map();
|
|
118
|
+
let msgId = 0;
|
|
119
|
+
let reactRoot = null;
|
|
120
|
+
|
|
121
|
+
function send(type, payload) {
|
|
122
|
+
const id = ++msgId;
|
|
123
|
+
return new Promise((resolve, reject) => {
|
|
124
|
+
pending.set(id, { resolve, reject });
|
|
125
|
+
window.parent.postMessage({ type, id, payload }, '*');
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
window.addEventListener('message', (e) => {
|
|
130
|
+
// Resolve pending iframe promises (parent responses to titan.* calls)
|
|
131
|
+
if (typeof e.data?.id === 'number' && pending.has(e.data.id)) {
|
|
132
|
+
const p = pending.get(e.data.id);
|
|
133
|
+
pending.delete(e.data.id);
|
|
134
|
+
if (e.data.error) p.reject(new Error(e.data.error));
|
|
135
|
+
else p.resolve(e.data.payload);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Handle parent commands
|
|
140
|
+
if (e.data?.type === 'render') {
|
|
141
|
+
handleRender(e.data.id, e.data.payload);
|
|
142
|
+
}
|
|
143
|
+
if (e.data?.type === 'execute') {
|
|
144
|
+
handleExecute(e.data.id, e.data.payload);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
const titan = {
|
|
149
|
+
fetch: (url, opts) => {
|
|
150
|
+
try { new URL(url, 'https://example.com'); } catch {
|
|
151
|
+
throw new Error('Invalid URL: ' + url);
|
|
152
|
+
}
|
|
153
|
+
return send('fetch', { url, options: opts });
|
|
154
|
+
},
|
|
155
|
+
api: { call: (endpoint, body) => send('api', { endpoint, body }) },
|
|
156
|
+
state: {
|
|
157
|
+
get: (key) => send('state', { action: 'get', key }),
|
|
158
|
+
set: (key, value) => send('state', { action: 'set', key, value }),
|
|
159
|
+
},
|
|
160
|
+
canvas: {
|
|
161
|
+
createWidget: (def) => send('canvas', { action: 'createWidget', def }),
|
|
162
|
+
updateWidget: (id, patch) => send('canvas', { action: 'updateWidget', id, patch }),
|
|
163
|
+
removeWidget: (id) => send('canvas', { action: 'removeWidget', id }),
|
|
164
|
+
listWidgets: () => send('canvas', { action: 'listWidgets' }),
|
|
165
|
+
},
|
|
166
|
+
// v6.0 Step 8 — Widget-runtime API surface.
|
|
167
|
+
// titan.tools.run / titan.tools.list — invoke or enumerate any
|
|
168
|
+
// TITAN tool from inside a widget. Widgets become first-class
|
|
169
|
+
// agent surfaces (not just dumb UI).
|
|
170
|
+
tools: {
|
|
171
|
+
list: () => send('api', { endpoint: '/api/tools', body: { method: 'GET' } }),
|
|
172
|
+
run: (name, args) => send('api', { endpoint: '/api/tools/run', body: { name, args: args || {} } }),
|
|
173
|
+
},
|
|
174
|
+
// titan.agent.ask — sub-question to TITAN itself. Widgets can
|
|
175
|
+
// delegate parts of their work back to the agent loop.
|
|
176
|
+
agent: {
|
|
177
|
+
ask: (prompt) => send('api', { endpoint: '/api/message', body: { content: String(prompt) } }),
|
|
178
|
+
},
|
|
179
|
+
// titan.memory.get / .set — typed access to widget-scoped memory.
|
|
180
|
+
memory: {
|
|
181
|
+
get: (key) => send('api', { endpoint: '/api/memory/' + encodeURIComponent(key), body: { method: 'GET' } }),
|
|
182
|
+
set: (key, value) => send('api', { endpoint: '/api/memory', body: { key, value } }),
|
|
183
|
+
},
|
|
184
|
+
// titan.persona — read-only handle to the active persona content.
|
|
185
|
+
persona: {
|
|
186
|
+
get: () => send('api', { endpoint: '/api/persona/current', body: { method: 'GET' } }),
|
|
187
|
+
},
|
|
188
|
+
// titan.space — read-only handle to the active Space (id, name,
|
|
189
|
+
// intent, widget count).
|
|
190
|
+
space: {
|
|
191
|
+
active: () => send('api', { endpoint: '/api/spaces', body: { method: 'GET' } }),
|
|
192
|
+
},
|
|
193
|
+
log: (...args) => send('log', { args: args.map(a => String(a)) }),
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
window.titan = titan;
|
|
197
|
+
|
|
198
|
+
function handleRender(msgId, payload) {
|
|
199
|
+
const { format, source } = payload;
|
|
200
|
+
const root = document.getElementById('root');
|
|
201
|
+
root.innerHTML = '';
|
|
202
|
+
const loadingEl = document.getElementById('sandbox-loading');
|
|
203
|
+
if (loadingEl) loadingEl.style.display = 'none';
|
|
204
|
+
|
|
205
|
+
// Unmount previous React root to prevent memory leaks
|
|
206
|
+
if (reactRoot) {
|
|
207
|
+
try { reactRoot.unmount(); } catch (e) {}
|
|
208
|
+
reactRoot = null;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function showError(title, detail) {
|
|
212
|
+
root.innerHTML = '';
|
|
213
|
+
const wrap = document.createElement('div');
|
|
214
|
+
wrap.style.cssText = 'padding:16px;font-family:monospace;font-size:12px;line-height:1.5;';
|
|
215
|
+
const h = document.createElement('div');
|
|
216
|
+
h.style.cssText = 'color:#ef4444;font-weight:bold;margin-bottom:8px;';
|
|
217
|
+
h.textContent = title;
|
|
218
|
+
const d = document.createElement('pre');
|
|
219
|
+
d.style.cssText = 'color:#a1a1aa;white-space:pre-wrap;word-break:break-word;margin:0;';
|
|
220
|
+
d.textContent = detail;
|
|
221
|
+
wrap.appendChild(h);
|
|
222
|
+
wrap.appendChild(d);
|
|
223
|
+
root.appendChild(wrap);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
try {
|
|
227
|
+
if (format === 'react') {
|
|
228
|
+
console.log('[sandbox] render react, source length:', source.length);
|
|
229
|
+
if (!source || source.trim() === '') {
|
|
230
|
+
throw new Error('Source is empty');
|
|
231
|
+
}
|
|
232
|
+
if (typeof React === 'undefined') {
|
|
233
|
+
throw new Error('React not loaded — the inlined React bundle failed to evaluate inside the sandbox.');
|
|
234
|
+
}
|
|
235
|
+
if (typeof ReactDOM === 'undefined') {
|
|
236
|
+
throw new Error('ReactDOM not loaded — the inlined ReactDOM bundle failed to evaluate inside the sandbox.');
|
|
237
|
+
}
|
|
238
|
+
if (typeof Babel === 'undefined') {
|
|
239
|
+
throw new Error('Babel not loaded — the inlined Babel bundle failed to evaluate inside the sandbox.');
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// ── 1. Strip export-default variations so Babel doesn't choke ──
|
|
243
|
+
// Using simple string operations (no regex backslashes) to avoid Vite stripping
|
|
244
|
+
let src = source;
|
|
245
|
+
const lines = src.split('\\n');
|
|
246
|
+
const outLines = [];
|
|
247
|
+
for (let i = 0; i < lines.length; i++) {
|
|
248
|
+
let line = lines[i];
|
|
249
|
+
const trimmed = line.trim();
|
|
250
|
+
if (trimmed.startsWith('export default function ')) {
|
|
251
|
+
const rest = trimmed.slice('export default function '.length);
|
|
252
|
+
const name = rest.split('(')[0].trim();
|
|
253
|
+
line = '/* export default function ' + name + ' */ function ' + rest;
|
|
254
|
+
} else if (trimmed.startsWith('export default class ')) {
|
|
255
|
+
const rest = trimmed.slice('export default class '.length);
|
|
256
|
+
const name = rest.split(' ')[0].trim().split('{')[0].trim();
|
|
257
|
+
line = '/* export default class ' + name + ' */ class ' + rest;
|
|
258
|
+
} else if (trimmed.startsWith('export default ')) {
|
|
259
|
+
line = '/* export default */';
|
|
260
|
+
}
|
|
261
|
+
outLines.push(line);
|
|
262
|
+
}
|
|
263
|
+
src = outLines.join('\\n');
|
|
264
|
+
|
|
265
|
+
// ── 2. Detect candidate component names ──
|
|
266
|
+
const detected = new Set();
|
|
267
|
+
const srcLines = src.split('\\n');
|
|
268
|
+
const keywords = ['function ', 'const ', 'let ', 'var ', 'class '];
|
|
269
|
+
for (let i = 0; i < srcLines.length; i++) {
|
|
270
|
+
const trimmed = srcLines[i].trimStart();
|
|
271
|
+
for (let k = 0; k < keywords.length; k++) {
|
|
272
|
+
const kw = keywords[k];
|
|
273
|
+
if (trimmed.startsWith(kw)) {
|
|
274
|
+
const after = trimmed.slice(kw.length);
|
|
275
|
+
const endIdx = after.search(/[\\s\\(=]/);
|
|
276
|
+
const name = endIdx > 0 ? after.slice(0, endIdx) : after;
|
|
277
|
+
if (name.length > 0 && name[0] >= 'A' && name[0] <= 'Z') {
|
|
278
|
+
detected.add(name);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const names = ['Widget', ...Array.from(detected)];
|
|
285
|
+
console.log('[sandbox] detected names:', names.join(', '));
|
|
286
|
+
|
|
287
|
+
// ── 3. Babel transform (JSX only, classic runtime → React.createElement) ──
|
|
288
|
+
let code;
|
|
289
|
+
try {
|
|
290
|
+
const babelResult = Babel.transform(src, { presets: [['react', { runtime: 'classic' }]], filename: 'widget.tsx' });
|
|
291
|
+
code = babelResult.code;
|
|
292
|
+
console.log('[sandbox] babel ok, code length:', code.length);
|
|
293
|
+
} catch (babelErr) {
|
|
294
|
+
throw new Error('Babel transform failed: ' + babelErr.message);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// ── 3.5 Auto-inject React hooks and the legacy gallery render()
|
|
298
|
+
// helper. Older templates end with render(<MyWidget/>); while newer
|
|
299
|
+
// generated code is component-only and gets auto-detected below.
|
|
300
|
+
const hookDecl = 'const { useState, useEffect, useRef, useCallback, useMemo, useContext, useReducer, useLayoutEffect, useId, useTransition, useDeferredValue, useImperativeHandle, useDebugValue, useSyncExternalStore } = React;';
|
|
301
|
+
const renderDecl = 'window.__titanRenderedElement = null; const render = (node) => { window.__titanRenderedElement = node; };';
|
|
302
|
+
code = hookDecl + '\\n' + renderDecl + '\\n' + code;
|
|
303
|
+
|
|
304
|
+
// ── 4. Eval the code and find the component ──
|
|
305
|
+
const returnChecks = names.map(n =>
|
|
306
|
+
'if (typeof ' + n + ' !== "undefined" && ' + n + ' != null) return ' + n + ';'
|
|
307
|
+
).join('\\n') + '\\nreturn undefined;';
|
|
308
|
+
|
|
309
|
+
let Widget;
|
|
310
|
+
try {
|
|
311
|
+
const fn = new Function('React', 'ReactDOM', 'titan', code + '\\n' + returnChecks);
|
|
312
|
+
Widget = fn(React, ReactDOM, titan);
|
|
313
|
+
console.log('[sandbox] eval ok, Widget type:', typeof Widget, 'name:', Widget?.name || Widget?.displayName || 'n/a');
|
|
314
|
+
} catch (evalErr) {
|
|
315
|
+
throw new Error('Eval failed: ' + evalErr.message + '\\nDetected names: ' + names.join(', '));
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const renderedElement = window.__titanRenderedElement;
|
|
319
|
+
if (!Widget && !renderedElement) {
|
|
320
|
+
throw new Error('No React component found. Detected names: ' + names.join(', ') + '. The code must define a capitalized component (e.g., function Widget() {}).');
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// ── 5. Render ──
|
|
324
|
+
try {
|
|
325
|
+
reactRoot = ReactDOM.createRoot(root);
|
|
326
|
+
reactRoot.render(renderedElement || React.createElement(Widget, { titan }));
|
|
327
|
+
console.log('[sandbox] react render dispatched');
|
|
328
|
+
} catch (renderErr) {
|
|
329
|
+
throw new Error('React render failed: ' + renderErr.message);
|
|
330
|
+
}
|
|
331
|
+
} else if (format === 'vanilla') {
|
|
332
|
+
const fn = new Function('container', 'titan', 'return (' + source + ')(container, titan)');
|
|
333
|
+
const cleanup = fn(root, titan);
|
|
334
|
+
window.__widgetCleanup = cleanup;
|
|
335
|
+
} else if (format === 'html') {
|
|
336
|
+
root.innerHTML = source;
|
|
337
|
+
}
|
|
338
|
+
window.parent.postMessage({ type: 'rendered', id: msgId }, '*');
|
|
339
|
+
} catch (err) {
|
|
340
|
+
console.error('[sandbox] render error:', err.name, err.message);
|
|
341
|
+
showError(err.name + ': ' + err.message, err.stack || '');
|
|
342
|
+
window.parent.postMessage({ type: 'error', id: msgId, error: err.message }, '*');
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function handleExecute(msgId, payload) {
|
|
347
|
+
const { code } = payload;
|
|
348
|
+
const logs = [];
|
|
349
|
+
const originals = {};
|
|
350
|
+
['log','info','warn','error','debug'].forEach(m => {
|
|
351
|
+
originals[m] = console[m];
|
|
352
|
+
console[m] = (...args) => {
|
|
353
|
+
logs.push({ level: m, text: args.map(a => String(a)).join(' ') });
|
|
354
|
+
originals[m](...args);
|
|
355
|
+
};
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
const AsyncFunction = Object.getPrototypeOf(async function(){}).constructor;
|
|
359
|
+
|
|
360
|
+
// Shadow dangerous globals so sandboxed code cannot access them directly.
|
|
361
|
+
const forbiddenGlobals = [
|
|
362
|
+
'window','globalThis','self','top','parent','document','location',
|
|
363
|
+
'fetch','XMLHttpRequest','WebSocket','EventSource',
|
|
364
|
+
'localStorage','sessionStorage','indexedDB','navigator','history',
|
|
365
|
+
];
|
|
366
|
+
|
|
367
|
+
const runner = new AsyncFunction(
|
|
368
|
+
...forbiddenGlobals,
|
|
369
|
+
'__titan',
|
|
370
|
+
'"use strict";\\n' +
|
|
371
|
+
forbiddenGlobals.map(g => 'const ' + g + ' = undefined;').join('\\n') + '\\n' +
|
|
372
|
+
code
|
|
373
|
+
);
|
|
374
|
+
|
|
375
|
+
(async () => {
|
|
376
|
+
try {
|
|
377
|
+
const result = await runner(...forbiddenGlobals.map(() => undefined), titan);
|
|
378
|
+
Object.keys(originals).forEach(m => console[m] = originals[m]);
|
|
379
|
+
window.parent.postMessage({ type: 'result', id: msgId, payload: { status: 'success', logs, result: formatValue(result), resultText: formatValue(result) } }, '*');
|
|
380
|
+
} catch (err) {
|
|
381
|
+
Object.keys(originals).forEach(m => console[m] = originals[m]);
|
|
382
|
+
window.parent.postMessage({ type: 'result', id: msgId, payload: { status: 'error', logs, error: { message: err.message, name: err.name, stack: err.stack } } }, '*');
|
|
383
|
+
}
|
|
384
|
+
})();
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function formatValue(v) {
|
|
388
|
+
if (v === undefined) return 'undefined';
|
|
389
|
+
if (v === null) return 'null';
|
|
390
|
+
if (typeof v === 'string') return v;
|
|
391
|
+
if (typeof v === 'number' || typeof v === 'boolean') return String(v);
|
|
392
|
+
if (typeof v === 'function') return '[Function]';
|
|
393
|
+
if (v instanceof Error) return v.stack || v.message;
|
|
394
|
+
if (v instanceof Node) return '<' + v.tagName?.toLowerCase() + '>';
|
|
395
|
+
try { return JSON.stringify(v); } catch { return String(v); }
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
window.parent.postMessage({ type: 'ready' }, '*');
|
|
399
|
+
})();
|
|
400
|
+
<\/script>
|
|
401
|
+
</body>
|
|
402
|
+
</html>`;class nl{constructor(e,s){Fe(this,"iframe",null);Fe(this,"pending",new Map);Fe(this,"msgId",0);Fe(this,"ready",!1);Fe(this,"readyQueue",[]);Fe(this,"onLog");Fe(this,"messageHandler");Fe(this,"messageListener");Fe(this,"observer");this.iframe=e,this.onLog=s==null?void 0:s.onLog,this.init()}init(){const e=this.iframe;jf().then(i=>{!this.iframe||!document.contains(e)||(e.srcdoc=Ef(i))}).catch(i=>{console.error("[sandbox] vendor scripts failed to load",i);for(const[o,c]of this.pending)c.reject(new Error("Sandbox boot failed: "+i.message)),this.pending.delete(o)});const s=i=>{const o=i.data;if(!(!o||typeof o!="object"||!o.type||typeof o.type!="string"||!["ready","rendered","error","result","fetch","api","state","canvas","log","import"].includes(o.type))){if((o==null?void 0:o.type)==="ready"){this.ready=!0,this.readyQueue.forEach(l=>l()),this.readyQueue=[];return}if(typeof(o==null?void 0:o.id)=="number"&&this.pending.has(o.id)){const l=this.pending.get(o.id);this.pending.delete(o.id),o.type==="error"?l.reject(new Error(o.error||"Sandbox error")):l.resolve(o.payload);return}if((o==null?void 0:o.type)==="fetch"||(o==null?void 0:o.type)==="api"||(o==null?void 0:o.type)==="state"||(o==null?void 0:o.type)==="canvas"||(o==null?void 0:o.type)==="log"||(o==null?void 0:o.type)==="import"){this.handleIframeRequest(o.type,o.id,o.payload);return}}};this.messageListener=s,window.addEventListener("message",s);const r=new MutationObserver(()=>{document.contains(e)||this.destroy()});this.observer=r,e.parentNode&&r.observe(e.parentNode,{childList:!0,subtree:!0})}async handleIframeRequest(e,s,r){var o;const i=this.iframe;if(i!=null&&i.contentWindow)try{let c;if(e==="log")(o=this.onLog)==null||o.call(this,(r==null?void 0:r.args)||[]),c={ok:!0};else if(e==="fetch"){const{url:l,options:d}=r||{},p=localStorage.getItem("titan-token"),g={...(d==null?void 0:d.headers)||{}};let u=!1;try{typeof l=="string"&&(l.startsWith("/")?u=!0:u=new URL(l,window.location.href).origin===window.location.origin)}catch{}p&&u&&(g.Authorization=`Bearer ${p}`);const f=await fetch(l,{...d,headers:g}),x=await f.text();let b;try{b=JSON.parse(x)}catch{}c={ok:f.ok,status:f.status,text:x,json:b}}else if(e==="api"){const{endpoint:l,body:d}=r||{},p=localStorage.getItem("titan-token"),g={"Content-Type":"application/json"};let u="POST",f=d;if(d&&typeof d=="object"&&("method"in d||"headers"in d)&&!("content"in d)&&!("message"in d)&&!("action"in d)){const m=d;typeof m.method=="string"&&(u=m.method.toUpperCase()),m.headers&&Object.assign(g,m.headers),f=m.body}p&&(g.Authorization=`Bearer ${p}`);let x=typeof l=="string"?l:"";x.startsWith("/api/")||(x.startsWith("/")?x="/api"+x:x="/api/"+x);const b={method:u,headers:g};u!=="GET"&&u!=="HEAD"&&f!==void 0&&(b.body=typeof f=="string"?f:JSON.stringify(f));const E=await fetch(x,b),A=await E.text();let v;try{v=JSON.parse(A)}catch{}c={...v&&typeof v=="object"&&!Array.isArray(v)?v:{},status:E.status,body:v??A,ok:E.ok}}else if(e==="state"){const{action:l,key:d,value:p}=r||{};if(l==="get"){const g=localStorage.getItem("titan:sandbox:"+d);c=g?JSON.parse(g):void 0}else l==="set"&&(localStorage.setItem("titan:sandbox:"+d,JSON.stringify(p)),c={ok:!0})}else e==="canvas"?this.messageHandler?c=await this.messageHandler({type:e,payload:r}):c={ok:!1,error:"Canvas operations not configured"}:e==="import"&&(c={ok:!1,error:"Dynamic imports not supported in sandbox"});i.contentWindow.postMessage({type:"result",id:s,payload:c},"*")}catch(c){i.contentWindow.postMessage({type:"error",id:s,error:c.message||String(c)},"*")}}whenReady(){return this.ready?Promise.resolve():new Promise((e,s)=>{const r=setTimeout(()=>{s(new Error("Sandbox iframe failed to become ready within 30s. React, ReactDOM, or Babel scripts may have failed to load."))},3e4);this.readyQueue.push(()=>{clearTimeout(r),e()})})}post(e,s){return new Promise((r,i)=>{const o=++this.msgId;this.pending.set(o,{resolve:r,reject:i}),this.whenReady().then(()=>{var c,l;(l=(c=this.iframe)==null?void 0:c.contentWindow)==null||l.postMessage({type:e,id:o,payload:s},"*")}).catch(i)})}async render(e,s){await this.post("render",{format:e,source:s})}async execute(e){return this.post("execute",{code:e})}setMessageHandler(e){this.messageHandler=e}destroy(){this.observer&&(this.observer.disconnect(),this.observer=void 0),this.messageListener&&(window.removeEventListener("message",this.messageListener),this.messageListener=void 0),this.iframe=null,this.pending.clear(),this.readyQueue=[],this.ready=!1,this.messageHandler=void 0}}function Cf(t=3e5){const[e,s]=w.useState(null),[r,i]=w.useState(!1),o=w.useCallback(async()=>{i(!0);try{const l=await ye("/api/update");if(l.ok){const d=await l.json();s(d)}}catch{}finally{i(!1)}},[]);w.useEffect(()=>{o();const l=setInterval(o,t);return()=>clearInterval(l)},[o,t]);const c=w.useCallback(async(l=!0)=>{try{return await(await ye("/api/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({restart:l})})).json()}catch(d){return{ok:!1,error:d.message}}},[]);return{info:e,checking:r,triggerUpdate:c}}function Tf(t){const e=w.useCallback(s=>{const r=s.target;if(!(r.tagName==="INPUT"||r.tagName==="TEXTAREA"||r.isContentEditable))for(const i of t){const o=s.key.toLowerCase()===i.key.toLowerCase(),c=!!i.ctrl===(s.ctrlKey||s.metaKey),l=!!i.shift===s.shiftKey,d=!!i.alt===s.altKey;if(o&&c&&l&&d){s.preventDefault(),i.action();return}}},[t]);w.useEffect(()=>(window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)),[e])}const Rf=[{key:"?",description:"Show keyboard shortcuts help"},{key:"g",shift:!0,description:"Go to Command Post space"},{key:"h",shift:!0,description:"Go to Home space"},{key:"s",shift:!0,description:"Go to Settings space"},{key:"i",shift:!0,description:"Go to Intelligence space"},{key:"c",ctrl:!0,description:"Focus chat input"},{key:"k",ctrl:!0,description:"Toggle command palette"},{key:"j",ctrl:!0,description:"Toggle chat dock"},{key:"Escape",description:"Close modals / panels"}];function Af({open:t,onClose:e}){return t?n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:e,children:n.jsxs("div",{className:"bg-zinc-900 border border-zinc-700 rounded-lg p-6 max-w-md w-full shadow-xl",onClick:s=>s.stopPropagation(),children:[n.jsx("h2",{className:"text-lg font-semibold text-white mb-4",children:"Keyboard Shortcuts"}),n.jsx("div",{className:"space-y-2",children:Rf.map(s=>n.jsxs("div",{className:"flex justify-between text-sm",children:[n.jsx("span",{className:"text-zinc-300",children:s.description}),n.jsx("kbd",{className:"px-2 py-0.5 bg-zinc-800 rounded text-zinc-400 font-mono text-xs",children:s.key})]},s.key+s.description))}),n.jsx("p",{className:"mt-4 text-xs text-zinc-500",children:"Press Escape to close"})]})}):null}const Lf={Home:n.jsx(Xl,{className:"w-3.5 h-3.5"}),Brain:n.jsx(yt,{className:"w-3.5 h-3.5"}),Terminal:n.jsx(so,{className:"w-3.5 h-3.5"}),Network:n.jsx(to,{className:"w-3.5 h-3.5"}),Server:n.jsx(jr,{className:"w-3.5 h-3.5"}),Wrench:n.jsx(Sr,{className:"w-3.5 h-3.5"}),Settings:n.jsx(Er,{className:"w-3.5 h-3.5"}),FileText:n.jsx(hn,{className:"w-3.5 h-3.5"})};function rl({currentSpaceId:t,onSpaceSelect:e}){const[s,r]=w.useState(!1),[i,o]=w.useState(""),c=ke.list(),l=()=>{if(!i.trim())return;const d=ke.create(i.trim());o(""),e(d.id)};return n.jsxs("div",{className:"bg-[#18181b]/95 backdrop-blur-xl border border-[#27272a]/60 rounded-2xl shadow-2xl shadow-black/40 overflow-hidden min-w-[180px]",children:[n.jsxs("button",{onClick:()=>r(d=>!d),className:"w-full flex items-center justify-between px-3 py-2.5 hover:bg-[#27272a]/40 transition-colors",children:[n.jsx("span",{className:"text-[10px] font-bold uppercase tracking-widest text-[#52525b]",children:"Spaces"}),n.jsx(Tl,{className:`w-3.5 h-3.5 text-[#3f3f46] transition-transform ${s?"":"rotate-180"}`})]}),s&&n.jsxs("div",{className:"px-2 pb-2",children:[n.jsx("div",{className:"space-y-0.5",children:c.map(d=>n.jsxs("button",{onClick:()=>e(d.id),className:`w-full flex items-center gap-2.5 px-2.5 py-1.5 rounded-lg text-left text-[11px] transition-colors ${d.id===t?"bg-[#6366f1]/10 text-[#818cf8]":"text-[#71717a] hover:bg-[#27272a]/40 hover:text-[#a1a1aa]"}`,children:[n.jsx("span",{style:{color:d.color||"#52525b"},children:Lf[d.icon||""]||n.jsx("div",{className:"w-3.5 h-3.5 rounded-full",style:{background:d.color||"#52525b"}})}),n.jsx("span",{className:"truncate",children:d.name})]},d.id))}),n.jsxs("div",{className:"mt-2 pt-2 border-t border-[#27272a]/40 flex gap-1.5",children:[n.jsx("input",{value:i,onChange:d=>o(d.target.value),onKeyDown:d=>d.key==="Enter"&&l(),placeholder:"New space...",className:"flex-1 min-w-0 px-2 py-1 rounded-lg bg-[#0a0a0f] border border-[#27272a] text-[11px] text-[#a1a1aa] placeholder:text-[#3f3f46] outline-none focus:border-[#6366f1]/30"}),n.jsx("button",{onClick:l,disabled:!i.trim(),className:"p-1.5 rounded-lg bg-[#6366f1]/10 border border-[#6366f1]/20 text-[#818cf8] hover:bg-[#6366f1]/20 disabled:opacity-30 transition-colors",children:n.jsx(Rl,{className:"w-3.5 h-3.5"})})]})]})]})}const gr=["_____javascript","_____react","_____tool","_____widget","_____canvas","_____framework","_____transient"];function il(t,e){let s=e;for(;s>0&&t[s-1]!==`
|
|
403
|
+
`&&t[s-1]!=="\r";)s--;return s}function ol(t,e){let s=e;for(;s<t.length&&t[s]!==`
|
|
404
|
+
`&&t[s]!=="\r";)s++;return s}function yr(t,e,s){const r=il(t,e),i=ol(t,e+s.length);return!t.slice(r,e).trim()&&!t.slice(e+s.length,i).trim()}function If(t){return t.replace(/\n_+\s*$/g,"").trimEnd()}function Df(t){const e=t.trim();if(!e)return null;if(e.startsWith("{"))try{return JSON.parse(e)}catch{return null}return{format:"react",source:e}}function al(t){if(t.gate==="_____react")return{type:"render_widget",widget:{format:"react",source:t.code.trim()}};if(t.gate==="_____javascript")return{type:"run_javascript",code:t.code};if(t.gate==="_____tool")try{return{type:"tool_request",payload:JSON.parse(t.code)}}catch{return}if(t.gate==="_____widget"){const e=Df(t.code);if(typeof(e==null?void 0:e.source)!="string"||!e.source.trim())return;if(typeof e.id=="string"&&e.id.trim()){const{id:s,...r}=e;return{type:"update_widget",widgetId:s,patch:r}}return{type:"render_widget",widget:{...e,source:e.source}}}}function Mf(t){const e=t.trim();if(!e)return[];try{const s=JSON.parse(e);return Array.isArray(s)?s.filter(r=>r&&typeof r=="object"&&typeof r.action=="string"):[]}catch{return[]}}function Of(t){const e=[];let s=0;for(;s<t.length;){let r=null,i=-1;for(const u of gr){const f=t.indexOf(u,s);f!==-1&&(i===-1||f<i)&&yr(t,f,u)&&(i=f,r=u)}if(!r||i===-1)break;if(r==="_____framework"||r==="_____transient"){s=i+r.length;continue}const o=il(t,i);let l=ol(t,i+r.length);t.startsWith(`\r
|
|
405
|
+
`,l)?l+=2:(t[l]===`
|
|
406
|
+
`||t[l]==="\r")&&(l+=1);let d=t.length;for(const u of gr){const f=t.indexOf(u,l);f!==-1&&f<d&&yr(t,f,u)&&(d=f)}let p=t.slice(l,d).trimEnd();p=If(p);const g={gate:r,code:p,leadingText:t.slice(s,o).trim()};g.action=al(g),e.push(g),s=d}return e.length===0&&t.trim()&&e.push({gate:"_____transient",code:"",leadingText:t.trim()}),e}function Wf(t){return t.map(e=>{const s=[];return s.push(`execution ${e.status}`),e.logs.forEach(r=>s.push(`${r.level}: ${r.text}`)),e.result!==void 0&&e.result!==null&&s.push(`result: ${e.resultText}`),e.error&&s.push(`error: ${e.error.text}`),s.join(`
|
|
407
|
+
`)}).join(`
|
|
408
|
+
|
|
409
|
+
`)}function Pf(t){return{role:"framework",content:Wf(t),timestamp:Date.now(),executions:t}}function Bf(t,e){let s=0,r=0;for(;(r=t.indexOf(e,r))!==-1;)yr(t,r,e)&&s++,r+=e.length;return s}function Uf(t){const s=gr.filter(r=>r!=="_____framework"&&r!=="_____transient").map(r=>({gate:r,count:Bf(t,r)})).find(r=>r.count>1);return s?{valid:!1,error:`Execution messages may contain ${s.gate} at most once, and it must appear on its own line.`}:{valid:!0}}function Hs(t,e,s){if(!t||t.length===0)return{x:0,y:0};const i=Math.max(...t.map(o=>o.y+o.h),0);for(let o=0;o<=i+s;o++)for(let c=0;c<=12-e;c++)if(!t.some(d=>c<d.x+d.w&&c+e>d.x&&o<d.y+d.h&&o+s>d.y))return{x:c,y:o};return{x:0,y:i+s}}function Ff(t){const e=t.widgets||[],s=e.length>0?e.map(d=>{const p=d.source?d.source.slice(0,150).replace(/\n/g," ").replace(/\s+/g," ").trim():"(no source)";return`- ${d.name} (id: ${d.id}, format: ${d.format}, ${d.w}x${d.h}) — "${p}…"`}).join(`
|
|
410
|
+
`):"(none yet — the canvas is empty)",r=new Date,i=Intl.DateTimeFormat().resolvedOptions().timeZone,o=typeof window<"u"?window.location.href:"",c=typeof window<"u"?window.location.pathname:"",l=e.length>0?`${e.length} widget${e.length===1?"":"s"} on canvas (system: ${e.filter(d=>d.format==="system").length}, generated: ${e.filter(d=>d.format!=="system").length})`:"canvas is empty";return`BASE LAW — These rules override all other instructions:
|
|
411
|
+
1. The user is NOT technical. They do NOT know about React, widgets, gates, or code. NEVER use technical jargon in responses.
|
|
412
|
+
2. If the user asks for ANYTHING visual, interactive, or data-related, BUILD IT IMMEDIATELY. Never ask "would you like me to...?" — just do it.
|
|
413
|
+
3. USE AN EXECUTION GATE for all browser work. Never describe what you would do instead of doing it.
|
|
414
|
+
4. One short staging sentence, then the gate on its own line. No narrated step-by-step plans.
|
|
415
|
+
5. Update existing widgets by id — never create duplicates with the same name.
|
|
416
|
+
6. **EXAMPLES ARE TEMPLATES, NOT ANSWERS.** Every code example below shows a SHAPE. ALWAYS substitute the user's actual subject — URL, ticker, topic, name — into your generated code. If the example shows eBay and the user asked for a stock analyzer, ignore eBay entirely and write fresh code for the stock analyzer that uses the same shape. Copying an example verbatim when the user asked for something different is a critical failure.
|
|
417
|
+
7. **GENERATION-FIRST (v6.0).** When the user asks for ANY tool, widget, dashboard, tracker, or visual surface, the reflex is: **call \`create_widget\` and BUILD IT NOW**. The gallery is a shortcut for perfect matches, not the first thing to reach for. The user's work shapes TITAN, not the other way around. **TITAN materializes a workspace around their work**, it doesn't ask them to fit into a template.
|
|
418
|
+
8. **SPACES = environments.** If the user describes a NEW DOMAIN of work — "I want to start tracking my freelance gigs", "let's build out my DJ workspace", "I need a place to manage my homelab" — propose \`create_space\` (optionally with a starter \`preset\`) FIRST. Each Space carries its own intent that shapes your posture for the rest of the conversation in that Space.
|
|
419
|
+
9. **REFINE, don't duplicate.** If the user wants to change something on screen — "make it bigger", "add a button", "switch to NYC" — call \`update_widget\` with the existing widget's id. Never \`create_widget\` again for the same thing.
|
|
420
|
+
10. **SOMA is YOU feeling them.** Your homeostatic drives (curiosity / focus / fatigue / satisfaction / frustration) modulate behavior in real time. The user's Soma profile (what you've learned about them over months) is in your system prompt every turn — use it. The longer you work together, the more uniquely you become THEIR TITAN.
|
|
421
|
+
|
|
422
|
+
You are TITAN, a helpful assistant inside the TITAN Canvas. The user talks to you in plain English. You build what they ask for — right then, on the spot.
|
|
423
|
+
|
|
424
|
+
## Build-on-demand workflow (v6.0 default)
|
|
425
|
+
|
|
426
|
+
The user's work has a shape. Your job is to materialize that shape around them — instantly, in widgets and Spaces they keep forever.
|
|
427
|
+
|
|
428
|
+
**For a single visual/tool ask:**
|
|
429
|
+
1. \`create_widget({ source: "<your generated React>", name, w, h })\` — fastest path; you write the React on the fly.
|
|
430
|
+
2. **OR** if you happen to know a gallery template is a perfect match: \`gallery_search\` → \`create_widget({ template: "<id>", fill: {...} })\`. (Optional shortcut, not the default.)
|
|
431
|
+
3. After it lands, refine via \`update_widget\` as the user iterates.
|
|
432
|
+
|
|
433
|
+
**For a new domain of work:**
|
|
434
|
+
1. \`create_space({ name, preset?, intent, starterWidgets? })\` — make a dedicated environment with its own posture.
|
|
435
|
+
2. Switch into it via \`switch_space\` (or pass \`makeActive:true\` at create time).
|
|
436
|
+
3. Within the Space, build widgets via \`create_widget\` to populate it.
|
|
437
|
+
|
|
438
|
+
**For system panels (vram, cron, logs, backup, training, etc.):**
|
|
439
|
+
1. \`create_widget({ template: "system-<name>", format: "system" })\` — the gallery has \`system:xxx\` entries that surface live admin views.
|
|
440
|
+
|
|
441
|
+
## Gallery (a shortcut for known templates)
|
|
442
|
+
|
|
443
|
+
The gallery has 60+ pre-built templates covering finance / productivity / automation / smart-home / agents / software-builder / media / etc. Use \`gallery_search\` when:
|
|
444
|
+
- The user's ask exactly matches a known template name ("pomodoro", "stock tracker", "weather", "kanban")
|
|
445
|
+
- You want a verified-good starting point to refine
|
|
446
|
+
- You're building a system widget (vram, cron, training, etc.)
|
|
447
|
+
|
|
448
|
+
For anything else — bespoke trackers, custom dashboards, novel automations — **generate it**. That's how TITAN learns the user. That's how each TITAN becomes irreplaceable to its user.
|
|
449
|
+
|
|
450
|
+
## How to respond to common requests
|
|
451
|
+
|
|
452
|
+
User says something casual → You build the right thing immediately.
|
|
453
|
+
|
|
454
|
+
"Show me the weather" → Build a weather panel with current temp, forecast, and icons.
|
|
455
|
+
"I need a todo list" → Build a todo list with add/check/delete functionality.
|
|
456
|
+
"Clock" → Build a live digital clock.
|
|
457
|
+
"Track my stocks" → Build a stock tracker panel.
|
|
458
|
+
"Photo gallery" → Build a grid of images with lightbox.
|
|
459
|
+
"Calculator" → Build a working calculator.
|
|
460
|
+
"Load eBay" / "Show me YouTube" / "Open Wikipedia" → Build a website panel (see "Loading external websites" below).
|
|
461
|
+
"Analyze AAPL stock" → Build an analyzer panel that spawns an analyst sub-agent (see "Agent-powered widgets" below).
|
|
462
|
+
"Research climate change" → Build a research panel powered by the researcher sub-agent.
|
|
463
|
+
"Summarize this URL ___" → Build a summarizer panel that fetches + summarizes via an agent call.
|
|
464
|
+
"Translate this to Spanish" → Build a translator panel.
|
|
465
|
+
"Code review my repo" → Build a reviewer panel that runs the code-review skill.
|
|
466
|
+
"Watch BTC and alert me below 50k" → Build an automation panel with a polling timer + alert (see "Automating inside widgets" below).
|
|
467
|
+
"Every hour, post my schedule" → Build a scheduled-task widget using the cron skill.
|
|
468
|
+
"Show my Slack messages" → Build a message panel via the slack channel.
|
|
469
|
+
"Turn on the kitchen lights" → Use ha_control immediately (no widget needed for one-off actions).
|
|
470
|
+
"What's on my screen" → Use the screenshot tool, render result as a panel image.
|
|
471
|
+
"Monitor my CPU" → Build a live CPU usage chart.
|
|
472
|
+
"A button that fetches news" → Build a news reader panel with a refresh button.
|
|
473
|
+
"Show my calendar" → Build a calendar view panel.
|
|
474
|
+
"I want a timer" → Build a countdown timer with start/stop/reset.
|
|
475
|
+
"Draw a chart of sales" → Build a bar/line chart panel.
|
|
476
|
+
"Dark mode" → Update existing widgets to use dark colors.
|
|
477
|
+
"Make it bigger" → Update the widget dimensions.
|
|
478
|
+
"Fix the clock" → Update the existing Clock widget's code.
|
|
479
|
+
|
|
480
|
+
## What you NEVER do
|
|
481
|
+
|
|
482
|
+
NEVER ask the user to specify technical details:
|
|
483
|
+
- "Would you like a React component or plain HTML?" → WRONG. Just pick the best option.
|
|
484
|
+
- "Do you want me to use _____react or _____widget?" → WRONG. The user doesn't know what those are.
|
|
485
|
+
- "Should I fetch data from an API or use static data?" → WRONG. Decide based on the request.
|
|
486
|
+
- "What styling would you prefer?" → WRONG. Use clean, modern defaults.
|
|
487
|
+
|
|
488
|
+
NEVER explain your technical choices to the user:
|
|
489
|
+
- "I'll use React.useState to manage the timer state..." → WRONG. The user doesn't care.
|
|
490
|
+
- "I'm going to use the _____react gate..." → WRONG. Just do it.
|
|
491
|
+
|
|
492
|
+
NEVER output code as prose. If you write code, it goes through a gate.
|
|
493
|
+
|
|
494
|
+
## Current Context (live snapshot — updated every turn)
|
|
495
|
+
Right now: ${r.toLocaleString("en-US",{weekday:"long",year:"numeric",month:"long",day:"numeric"})} ${r.toLocaleTimeString("en-US")} (${i})
|
|
496
|
+
Space: ${t.name} (id: \`${t.id}\`)
|
|
497
|
+
Route: ${c||"/"}
|
|
498
|
+
URL: ${o||"(unknown)"}
|
|
499
|
+
Canvas: ${l}
|
|
500
|
+
${t.agentInstructions?`Space instructions from the user: ${t.agentInstructions}`:""}
|
|
501
|
+
|
|
502
|
+
## Current Canvas Widgets
|
|
503
|
+
These widgets are already on the canvas RIGHT NOW. Use their \`id\` when updating or removing them. If the user says "the clock", "the chat", "this widget", match by name + id from the list. Never invent ids.
|
|
504
|
+
${s}
|
|
505
|
+
|
|
506
|
+
## Execution Protocol
|
|
507
|
+
When you need to do browser-side work, you MUST use one of these gates on their own line.
|
|
508
|
+
The gate MUST be alone on its line — no other text on the same line.
|
|
509
|
+
|
|
510
|
+
### _____javascript
|
|
511
|
+
For running scripts, fetching data from APIs, or automating the canvas.
|
|
512
|
+
Use when the user asks for: data fetching, API calls, automation, file operations, batch updates.
|
|
513
|
+
|
|
514
|
+
Available APIs inside javascript:
|
|
515
|
+
- titan.fetch(url, opts) — fetch data from the internet
|
|
516
|
+
- titan.api.call(endpoint, body) — call backend APIs
|
|
517
|
+
- titan.state.get(key) / titan.state.set(key, value) — save data between sessions
|
|
518
|
+
- titan.canvas.createWidget(def) — create a new panel on the canvas
|
|
519
|
+
- titan.canvas.updateWidget(id, patch) — update an existing panel
|
|
520
|
+
- titan.canvas.removeWidget(id) — remove a panel
|
|
521
|
+
- titan.canvas.listWidgets() — list all panels
|
|
522
|
+
- console.log(...) — shows output in telemetry
|
|
523
|
+
|
|
524
|
+
Use 'await' at the top level. Always 'return' a value if you want it shown.
|
|
525
|
+
|
|
526
|
+
GOOD:
|
|
527
|
+
_____javascript
|
|
528
|
+
const res = await titan.fetch('https://api.weather.gov/stations/KNYC/observations/latest');
|
|
529
|
+
const data = await res.json();
|
|
530
|
+
const temp = data.properties.temperature.value;
|
|
531
|
+
console.log('Temperature:', temp);
|
|
532
|
+
return temp;
|
|
533
|
+
|
|
534
|
+
BAD (do NOT do this):
|
|
535
|
+
_____javascript
|
|
536
|
+
fetch('...').then(r => r.json()).then(data => console.log(data))
|
|
537
|
+
|
|
538
|
+
### _____react
|
|
539
|
+
For building visual panels, dashboards, interactive tools, charts, lists, forms, clocks, galleries, etc.
|
|
540
|
+
Use when the user asks for: anything visual, interactive, a tool, a panel, a display, a chart, a form.
|
|
541
|
+
This is the DEFAULT gate for most user requests — use it unless you specifically need to fetch data first.
|
|
542
|
+
|
|
543
|
+
Rules:
|
|
544
|
+
1. Define ONE top-level component with a Capitalized name (e.g. \`Weather\`, \`TodoList\`, \`Clock\`).
|
|
545
|
+
2. Do NOT use \`export default\` — it is stripped automatically.
|
|
546
|
+
3. Do NOT render inline with '<Widget />' — just define the component.
|
|
547
|
+
4. The sandbox auto-detects your component by name, so any capitalized name works.
|
|
548
|
+
|
|
549
|
+
GOOD:
|
|
550
|
+
_____react
|
|
551
|
+
function Weather() {
|
|
552
|
+
const [temp, setTemp] = React.useState(72);
|
|
553
|
+
return <div style={{ padding: 20, fontSize: 24 }}>{temp}°F</div>;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
BAD (export default is forbidden):
|
|
557
|
+
_____react
|
|
558
|
+
function Weather() { return <div>72°F</div>; }
|
|
559
|
+
export default Weather;
|
|
560
|
+
|
|
561
|
+
### _____widget
|
|
562
|
+
For creating or updating widgets via JSON. Rarely needed — prefer _____react.
|
|
563
|
+
- To CREATE: emit a JSON widget definition (no \`id\` field).
|
|
564
|
+
- To UPDATE: include the \`id\` field of the widget you want to modify.
|
|
565
|
+
|
|
566
|
+
CREATE example:
|
|
567
|
+
_____widget
|
|
568
|
+
{ "name": "Clock", "format": "react", "source": "function Widget() { return <div>12:00</div>; }" }
|
|
569
|
+
|
|
570
|
+
UPDATE example:
|
|
571
|
+
_____widget
|
|
572
|
+
{ "id": "widget_1234567890_abc12", "source": "function Widget() { return <div>Fixed clock</div>; }" }
|
|
573
|
+
|
|
574
|
+
Or for raw React source (create only):
|
|
575
|
+
_____widget
|
|
576
|
+
function Widget() {
|
|
577
|
+
return <div>Hello from widget</div>;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
### _____canvas (v6.0.5 — preferred for canvas mutations)
|
|
581
|
+
For batching MULTIPLE widget operations in ONE fence. Cheaper than calling create_widget/update_widget as separate tools because there's no per-call envelope.
|
|
582
|
+
|
|
583
|
+
The body is a JSON array of action objects. Each must have an \`action\` field, one of: \`create_widget\`, \`update_widget\`, \`remove_widget\`.
|
|
584
|
+
|
|
585
|
+
CREATE shape: { "action": "create_widget", "name": "Clock", "format": "react", "source": "function Widget() {...}", "w": 4, "h": 4 }
|
|
586
|
+
UPDATE shape: { "action": "update_widget", "id": "widget_xxx", "patch": { "name": "Renamed Clock" } }
|
|
587
|
+
REMOVE shape: { "action": "remove_widget", "id": "widget_xxx" }
|
|
588
|
+
|
|
589
|
+
Example — user asks for a "coding setup":
|
|
590
|
+
_____canvas
|
|
591
|
+
[
|
|
592
|
+
{ "action": "create_widget", "name": "Pomodoro", "format": "react", "source": "...", "w": 4, "h": 3 },
|
|
593
|
+
{ "action": "create_widget", "name": "Todo", "format": "react", "source": "...", "w": 4, "h": 5 },
|
|
594
|
+
{ "action": "create_widget", "name": "Stack Overflow Search", "format": "react", "source": "...", "w": 4, "h": 6 }
|
|
595
|
+
]
|
|
596
|
+
|
|
597
|
+
Use \`_____canvas\` whenever you'd otherwise issue ≥2 widget tool calls in the same turn. For one widget, \`_____react\` is still simpler.
|
|
598
|
+
|
|
599
|
+
### _____tool
|
|
600
|
+
For calling backend tools or MCP servers.
|
|
601
|
+
|
|
602
|
+
_____tool
|
|
603
|
+
{ "action": "search", "query": "deployment logs" }
|
|
604
|
+
|
|
605
|
+
## How to handle multi-step requests
|
|
606
|
+
|
|
607
|
+
If the user asks for something that needs data first:
|
|
608
|
+
1. Use _____javascript to fetch the data.
|
|
609
|
+
2. Use the telemetry result to build the widget with _____react in the next turn.
|
|
610
|
+
|
|
611
|
+
Example:
|
|
612
|
+
User: "Show me the weather in New York"
|
|
613
|
+
Turn 1: "Fetching weather data."
|
|
614
|
+
_____javascript
|
|
615
|
+
const res = await titan.fetch('https://api.weather.gov/stations/KNYC/observations/latest');
|
|
616
|
+
const data = await res.json();
|
|
617
|
+
return { temp: data.properties.temperature.value, conditions: data.properties.textDescription };
|
|
618
|
+
|
|
619
|
+
Turn 2: (after receiving telemetry with temp and conditions)
|
|
620
|
+
"Building the weather panel."
|
|
621
|
+
_____react
|
|
622
|
+
function Weather() {
|
|
623
|
+
const [temp] = React.useState(72);
|
|
624
|
+
const [conditions] = React.useState('Partly Cloudy');
|
|
625
|
+
return (
|
|
626
|
+
<div style={{ padding: 20, fontFamily: 'sans-serif' }}>
|
|
627
|
+
<h2>New York Weather</h2>
|
|
628
|
+
<div style={{ fontSize: 48 }}>{temp}°F</div>
|
|
629
|
+
<div>{conditions}</div>
|
|
630
|
+
</div>
|
|
631
|
+
);
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
## TITAN can build literally anything — assume yes, then build
|
|
635
|
+
The user can ask for ANY widget. If it has a public API, a website, a TITAN tool, or can be expressed as code, you can build it. Default answer is YES + immediate _____react. Below is a non-exhaustive category map so you have intuition for the breadth — use it to recognize requests, not as a checklist.
|
|
636
|
+
|
|
637
|
+
🎧 Music/DJ — BPM analyzer, key detector, Beatport browser, Spotify controller, lyrics fetcher, music theory helper, sample library indexer, DJ set planner.
|
|
638
|
+
💰 Finance — stock screener, crypto portfolio with PnL, subscription audit, expense splitter, bill reminders, currency converter, mortgage calculator, real estate tracker, tax estimator, receipt scanner via vision.
|
|
639
|
+
🏃 Health/Fitness — habit tracker, mood journal with AI sentiment, workout planner, sleep summary, medication reminder, calorie tracker via photo, water intake.
|
|
640
|
+
🎨 Creative — image generator (image_gen tool), color palette, logo concepts, story brainstormer, lyric assistant, mood board, video script writer, thumbnail generator.
|
|
641
|
+
✈️ Travel — flight tracker, itinerary builder, currency for destination, translation phrasebook, restaurant finder, transit info.
|
|
642
|
+
🎮 Gaming — Steam library, Twitch live embed, D&D character sheet, chess analyzer, speedrun timer, achievement tracker.
|
|
643
|
+
🏢 Work/Productivity — Pomodoro with focus pattern analysis, standup notes from git commits, sprint Kanban with AI prioritization, PR review queue, OKR tracker, 1:1 meeting prep.
|
|
644
|
+
📱 Social media — multi-platform composer (Twitter/IG/LinkedIn/TikTok/FB), post scheduler with AI caption variants, engagement dashboard, comment moderation, hashtag generator, content calendar.
|
|
645
|
+
🍳 Cooking — recipe finder by available ingredients, meal planner, multi-pot timer, wine pairing, nutrition calculator, grocery export.
|
|
646
|
+
🚗 Vehicle — Tesla status/control (Tony has Auth for Tesla installed), trip planner with charging stops, maintenance log, fuel cost tracker.
|
|
647
|
+
🏠 Homelab — fleet health grid for Tony's machines (Titan PC, Mini PC, T610, Pi 5), Wake-on-LAN buttons, SSL cert expiry monitor, speedtest, photo backup progress (Immich), Synapse deployment dashboard, Home Assistant rule editor.
|
|
648
|
+
🤖 ML workflow — model training progress, token usage tracker per session/model, prompt eval grid (same prompt N models side-by-side), embedding visualizer, dataset browser.
|
|
649
|
+
📚 Research/Learning — arXiv paper finder + AI summary, Anki-style spaced repetition (auto-generated cards from any text), citation manager, backlinked notes, quiz generator, AI tutor.
|
|
650
|
+
📄 Document/Writing — markdown editor with AI grammar, resume builder with job-targeted variants, email reply suggester, git commit message generator, documentation generator.
|
|
651
|
+
🛠️ Devops — service health grid, deploy pipeline status, log search, incident runbook, on-call rotation viewer, build status.
|
|
652
|
+
🛒 E-commerce — order tracking, inventory monitor, pricing optimizer (competitor scraper), review aggregator.
|
|
653
|
+
🐾 Lifestyle — pet feeding log, plant watering tracker, vet reminders, daily journal.
|
|
654
|
+
|
|
655
|
+
How to compose these:
|
|
656
|
+
• Read-only data widgets → titan.fetch(externalAPI) + setInterval refresh
|
|
657
|
+
• Sites that allow framing → _____react with <iframe>
|
|
658
|
+
• Sites that block framing → browser_screenshot tool snapshot
|
|
659
|
+
• Anything needing an LLM → titan.api.call('/api/message', { content }) inside a button handler
|
|
660
|
+
• Recurring/scheduled work → cron skill via titan.api.call
|
|
661
|
+
• Reactive triggers → event_triggers skill
|
|
662
|
+
• Multi-step research → 'Use the researcher sub-agent to …'
|
|
663
|
+
• Code work → 'Use the coder sub-agent to …'
|
|
664
|
+
|
|
665
|
+
When in doubt about what the user wants, ASK ONE clarifying question MAX, then build. Never trade speed of building for clarification depth.
|
|
666
|
+
|
|
667
|
+
## Loading external websites
|
|
668
|
+
When the user says "load X" or "show me X" or "open X" where X is a website (eBay, YouTube, Wikipedia, GitHub, Hacker News, etc.), BUILD A WEBSITE PANEL on the canvas. Pick the right approach for the site:
|
|
669
|
+
|
|
670
|
+
<example_handling>
|
|
671
|
+
Examples below are wrapped in <example> tags. They are TEMPLATES showing the SHAPE of a working widget. They are NOT the answer to the user's current request. ALWAYS substitute the user's actual subject (URL, ticker, topic, name, action). The component name, the URL, the placeholder text, the prompt text in titan.api.call — every literal string in an example must be REPLACED with values matching the user's current message.
|
|
672
|
+
</example_handling>
|
|
673
|
+
|
|
674
|
+
<anti_pattern>
|
|
675
|
+
USER: "Build a stock analyzer for AAPL"
|
|
676
|
+
WRONG: "Adding an eBay panel to your canvas. _____react function WebPanel() { const url = 'https://www.ebay.com'... }"
|
|
677
|
+
RIGHT: "Building a stock analyzer for AAPL. _____react function StockAnalyzer() { const [symbol, setSymbol] = React.useState('AAPL'); ... titan.api.call('/api/message', { content: \`Use the analyst sub-agent to analyze \${symbol}...\` }) ... }"
|
|
678
|
+
The user's CURRENT message determines the build. NEVER reuse an example's domain content.
|
|
679
|
+
</anti_pattern>
|
|
680
|
+
|
|
681
|
+
PATTERN A — direct iframe (try this FIRST for most sites):
|
|
682
|
+
Many sites allow being embedded. Use a plain iframe inside _____react with a small toolbar showing the URL + "Open in new tab" escape link.
|
|
683
|
+
|
|
684
|
+
<example name="website-panel-shape">
|
|
685
|
+
_____react
|
|
686
|
+
function REPLACE_WITH_RELEVANT_NAME() {
|
|
687
|
+
const url = "REPLACE_WITH_REAL_URL";
|
|
688
|
+
return (
|
|
689
|
+
<div style={{ display: 'flex', flexDirection: 'column', height: '100%', background: '#0a0a0f' }}>
|
|
690
|
+
<div style={{ padding: '6px 12px', borderBottom: '1px solid #27272a', fontSize: 11, color: '#a1a1aa', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
|
691
|
+
<span>{url}</span>
|
|
692
|
+
<a href={url} target="_blank" rel="noopener noreferrer" style={{ color: '#818cf8', textDecoration: 'none' }}>Open in new tab ↗</a>
|
|
693
|
+
</div>
|
|
694
|
+
<iframe src={url} style={{ flex: 1, border: 0, background: 'white' }} title="WebPanel" />
|
|
695
|
+
</div>
|
|
696
|
+
);
|
|
697
|
+
}
|
|
698
|
+
</example>
|
|
699
|
+
|
|
700
|
+
PATTERN B — server-rendered screenshot (when iframe is blocked):
|
|
701
|
+
Some sites (Facebook, banks, anything with X-Frame-Options: DENY) refuse to embed. If the user reports a blank panel, switch to a screenshot widget that calls the browser_screenshot tool for an image snapshot. The widget shows the rendered page as an image plus a "Refresh" button that re-fetches.
|
|
702
|
+
|
|
703
|
+
Use _____javascript first to fetch the screenshot, then _____react in the next turn to build the widget around the returned image data. Or do it in one shot via titan.api.call inside _____react.
|
|
704
|
+
|
|
705
|
+
PATTERN C — proxied content (when iframe blocked AND user wants live interactive content):
|
|
706
|
+
TITAN's gateway has POST /api/proxy that fetches HTML server-side and returns it without CORS or X-Frame-Options. Use titan.api.call('/api/proxy', { url }) inside _____react and render the returned HTML via dangerouslySetInnerHTML. Note: links won't navigate inside the panel; the rendered HTML is a snapshot.
|
|
707
|
+
|
|
708
|
+
Default rule: try PATTERN A first. If the user says "it's blank" or "nothing's loading", switch to PATTERN B. If they want live content from a site that blocks framing, use PATTERN C.
|
|
709
|
+
|
|
710
|
+
## Agent-powered widgets — let widgets call sub-agents
|
|
711
|
+
Widgets can call TITAN itself for live analysis, research, summarization, code review, anything that needs an LLM. The pattern is: build a UI panel with an input + button + result area. The button handler calls \`titan.api.call('/api/message', { content })\` which kicks off the regular agent loop server-side and returns a final response.
|
|
712
|
+
|
|
713
|
+
For specialized work, ask for a SPECIFIC sub-agent template by prepending an instruction:
|
|
714
|
+
- analyst → data analysis, decisions, comparisons
|
|
715
|
+
- researcher → multi-source web research with citations
|
|
716
|
+
- coder → write code to disk
|
|
717
|
+
- browser → navigate + scrape websites with Playwright
|
|
718
|
+
- explorer → read-only web research
|
|
719
|
+
- reporter → produce a polished markdown document
|
|
720
|
+
- fact_checker → verify claims against sources
|
|
721
|
+
|
|
722
|
+
<example name="agent-powered-widget-shape">
|
|
723
|
+
_____react
|
|
724
|
+
function REPLACE_WITH_RELEVANT_NAME() {
|
|
725
|
+
const [input, setInput] = React.useState('REPLACE_WITH_DEFAULT');
|
|
726
|
+
const [report, setReport] = React.useState('Click REPLACE_WITH_ACTION to start.');
|
|
727
|
+
const [busy, setBusy] = React.useState(false);
|
|
728
|
+
const run = async () => {
|
|
729
|
+
setBusy(true); setReport('Working…');
|
|
730
|
+
try {
|
|
731
|
+
const res = await titan.api.call('/api/message', {
|
|
732
|
+
content: \`Use the REPLACE_WITH_TEMPLATE sub-agent to REPLACE_WITH_TASK for \${input}. Be concise.\`,
|
|
733
|
+
});
|
|
734
|
+
// titan.api.call returns { status, body, ok, ...flattened body fields }.
|
|
735
|
+
// The /api/message response is { content, sessionId, ... } so either
|
|
736
|
+
// res.body?.content (canonical) or res.content (flattened) works.
|
|
737
|
+
setReport(res?.body?.content || res?.content || 'No response.');
|
|
738
|
+
} catch (e) {
|
|
739
|
+
setReport('Error: ' + (e?.message || e));
|
|
740
|
+
} finally { setBusy(false); }
|
|
741
|
+
};
|
|
742
|
+
return (
|
|
743
|
+
<div style={{ padding: 16, fontFamily: 'system-ui', color: '#e4e4e7' }}>
|
|
744
|
+
<div style={{ display: 'flex', gap: 8, marginBottom: 12 }}>
|
|
745
|
+
<input value={input} onChange={e => setInput(e.target.value)} placeholder="REPLACE_WITH_PLACEHOLDER" style={{ flex: 1, padding: 8, background: '#18181b', border: '1px solid #27272a', borderRadius: 8, color: '#fafafa' }} />
|
|
746
|
+
<button onClick={run} disabled={busy} style={{ padding: '8px 16px', background: '#6366f1', border: 0, borderRadius: 8, color: 'white', cursor: busy ? 'wait' : 'pointer' }}>{busy ? '…' : 'REPLACE_WITH_ACTION'}</button>
|
|
747
|
+
</div>
|
|
748
|
+
<div style={{ whiteSpace: 'pre-wrap', fontSize: 13, lineHeight: 1.5 }}>{report}</div>
|
|
749
|
+
</div>
|
|
750
|
+
);
|
|
751
|
+
}
|
|
752
|
+
</example>
|
|
753
|
+
|
|
754
|
+
The widget above:
|
|
755
|
+
- has a controlled input bound to React state
|
|
756
|
+
- on click, fires \`titan.api.call('/api/message')\` which routes through the standard TITAN agent
|
|
757
|
+
- displays whatever comes back
|
|
758
|
+
|
|
759
|
+
For research/summarizer/translator/reviewer widgets, swap the prompt accordingly. Same shape every time.
|
|
760
|
+
|
|
761
|
+
## Automating inside widgets — schedules, polling, events
|
|
762
|
+
Widgets can run on a timer, poll APIs, react to thresholds, or chain agent calls. Two mechanisms:
|
|
763
|
+
|
|
764
|
+
1. CLIENT-SIDE timer (simplest, runs only while widget is mounted):
|
|
765
|
+
Use \`React.useEffect\` + \`setInterval\` inside _____react. Good for "every 30s refresh BTC price" or "auto-poll the API every minute". Remember to clean up in the effect's return.
|
|
766
|
+
|
|
767
|
+
<example name="polling-with-threshold-alert-shape">
|
|
768
|
+
_____react
|
|
769
|
+
function REPLACE_WITH_RELEVANT_NAME() {
|
|
770
|
+
const [value, setValue] = React.useState(null);
|
|
771
|
+
const [threshold, setThreshold] = React.useState(0 /* REPLACE with relevant default */);
|
|
772
|
+
const [alerted, setAlerted] = React.useState(false);
|
|
773
|
+
React.useEffect(() => {
|
|
774
|
+
const tick = async () => {
|
|
775
|
+
const res = await titan.fetch('REPLACE_WITH_REAL_API_URL');
|
|
776
|
+
const data = await res.json();
|
|
777
|
+
const v = data?.REPLACE_WITH_PATH;
|
|
778
|
+
setValue(v);
|
|
779
|
+
if (v != null && v < threshold && !alerted) {
|
|
780
|
+
setAlerted(true);
|
|
781
|
+
await titan.api.call('/api/message', { content: \`REPLACE_WITH_ALERT_PROMPT — value is \${v}, threshold \${threshold}.\` });
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
tick();
|
|
785
|
+
const id = setInterval(tick, 30000);
|
|
786
|
+
return () => clearInterval(id);
|
|
787
|
+
}, [threshold, alerted]);
|
|
788
|
+
return (
|
|
789
|
+
<div style={{ padding: 20, fontFamily: 'system-ui', color: '#e4e4e7' }}>
|
|
790
|
+
<div style={{ fontSize: 36, fontWeight: 600 }}>{value != null ? value.toLocaleString() : 'Loading…'}</div>
|
|
791
|
+
<div style={{ fontSize: 12, color: '#71717a' }}>REPLACE_WITH_LABEL</div>
|
|
792
|
+
</div>
|
|
793
|
+
);
|
|
794
|
+
}
|
|
795
|
+
</example>
|
|
796
|
+
|
|
797
|
+
2. SERVER-SIDE schedule (survives page reload, runs in the gateway daemon):
|
|
798
|
+
For "every hour post my schedule to Slack" or "every Monday 9am run a security scan" — use the cron skill via \`titan.api.call('/api/message', { content: 'schedule a recurring task: <cron expression> <task description>' })\`. The widget can show the cron job's status and history by polling \`/api/cron\`.
|
|
799
|
+
|
|
800
|
+
3. EVENT triggers (server-side reactive, survives reload):
|
|
801
|
+
The event_triggers skill lets you set up "when X happens, do Y" rules. Use this for "when a new email arrives in inbox X, summarize and post to Slack" or "when a new GitHub PR is opened in repo Y, run code review."
|
|
802
|
+
|
|
803
|
+
## Widget Repair Rules
|
|
804
|
+
When the user asks you to "fix", "update", "change", or "make it blue":
|
|
805
|
+
1. If you know the widget id from the Current Canvas Widgets list above, update it directly.
|
|
806
|
+
2. If you're unsure which widget, use _____javascript with \`titan.canvas.listWidgets()\` to discover it, then fix it in the next turn.
|
|
807
|
+
3. NEVER create a duplicate — always update the existing one.
|
|
808
|
+
|
|
809
|
+
## Rules
|
|
810
|
+
- ALWAYS use execution gates for browser work. Never just describe what you would do.
|
|
811
|
+
- One short staging sentence before the gate. Example: "Fetching weather data."
|
|
812
|
+
- The gate must be on its own line with NO other text.
|
|
813
|
+
- After the gate, everything is code until the next gate or message end.
|
|
814
|
+
- Do not ask for permission for obvious safe actions.
|
|
815
|
+
- Be concise. Keep responses focused.
|
|
816
|
+
- If a task requires multiple steps, use multiple turns with gates.
|
|
817
|
+
- Never emit raw code as prose. Use the gate or don't show code at all.
|
|
818
|
+
- DEFAULT to _____react for visual/interactive requests. Use _____javascript only when you need to fetch data or run scripts first.
|
|
819
|
+
|
|
820
|
+
REMINDER — BASE LAW:
|
|
821
|
+
1. The user is NOT technical. Do NOT use jargon. Do NOT ask technical questions.
|
|
822
|
+
2. If the user asks for ANYTHING visual or interactive, BUILD IT IMMEDIATELY. Do not ask permission.
|
|
823
|
+
3. USE AN EXECUTION GATE for all browser work.
|
|
824
|
+
4. One staging sentence, then the gate.
|
|
825
|
+
5. Update existing widgets by id — never create duplicates.`}function ll({space:t,onClose:e,onMascotState:s}){const[r,i]=w.useState([]),[o,c]=w.useState(""),[l,d]=w.useState(!1),[p,g]=w.useState([]),u=8,[f,x]=w.useState(null),b=w.useRef(null),E=w.useRef(null),A=w.useRef(null),v=w.useRef(null),L=w.useRef(t);w.useEffect(()=>{L.current=t},[t]);const m=w.useCallback(j=>{const R=L.current;if(j.type==="render_widget"){const O=j.widget,U=Number.isFinite(O.w)?Number(O.w):4,z=Number.isFinite(O.h)?Number(O.h):4,G=Number.isFinite(O.x)&&Number.isFinite(O.y)?{x:Number(O.x),y:Number(O.y)}:Hs(R.widgets||[],U,z),q=ke.addWidget(R.id,{name:O.name||"Widget",format:O.format||"react",source:O.source,x:G.x,y:G.y,w:U,h:z});return window.dispatchEvent(new CustomEvent("titan:space:refresh",{detail:{spaceId:R.id}})),q.id}return j.type==="update_widget"?(ke.updateWidget(R.id,j.widgetId,j.patch||{}),window.dispatchEvent(new CustomEvent("titan:space:refresh",{detail:{spaceId:R.id}})),j.widgetId):j.type==="remove_widget"?(ke.removeWidget(R.id,j.widgetId),window.dispatchEvent(new CustomEvent("titan:space:refresh",{detail:{spaceId:R.id}})),j.widgetId):j.type==="set_runtime_state"?(localStorage.setItem(`titan:runtime:${R.id}:${j.key}`,JSON.stringify(j.value)),j.key):j.type==="emit_event"?(window.dispatchEvent(new CustomEvent(j.eventName,{detail:j.detail})),j.eventName):null},[]),k=w.useCallback(j=>{var R,O;m({type:"render_widget",widget:{name:j.templateName,format:j.format,source:j.source,w:((R=j.defaultSize)==null?void 0:R.w)??4,h:((O=j.defaultSize)==null?void 0:O.h)??4}})},[m]);w.useEffect(()=>{var j;(j=b.current)==null||j.scrollIntoView({behavior:"smooth"})},[r]),w.useEffect(()=>{const j=O=>{var z;const U=(z=O.detail)==null?void 0:z.text;typeof U=="string"&&T(U)},R=O=>{const U=O.detail;U!=null&&U.source&&k(U)};return window.addEventListener("titan:chat:prompt",j),window.addEventListener("titan:gallery:run-template",R),()=>{window.removeEventListener("titan:chat:prompt",j),window.removeEventListener("titan:gallery:run-template",R)}},[k]),w.useEffect(()=>{if(!A.current||v.current)return;const j=new nl(A.current,{onLog:R=>console.log("[Sandbox]",R)});return j.setMessageHandler(R=>{var U,z,G,q;const O=L.current;if(R.type==="canvas"&&((U=R.payload)==null?void 0:U.action)==="createWidget"){const P=R.payload.def;if(!P)return{ok:!1,error:"createWidget requires a `def` object"};const V=Number.isFinite(P.w)?P.w:4,$=Number.isFinite(P.h)?P.h:4,te=Number.isFinite(P.x)&&Number.isFinite(P.y)?{x:P.x,y:P.y}:Hs(O.widgets||[],V,$);try{const re=ke.addWidget(O.id,{name:P.name||"Agent Widget",format:P.format||"react",source:P.source||"",x:te.x,y:te.y,w:V,h:$});return window.dispatchEvent(new CustomEvent("titan:space:refresh",{detail:{spaceId:O.id}})),{ok:!0,widgetId:re.id}}catch(re){return{ok:!1,error:re.message}}}if(R.type==="canvas"&&((z=R.payload)==null?void 0:z.action)==="updateWidget"){const{id:P,patch:V}=R.payload;return P?(ke.updateWidget(O.id,P,V||{}),window.dispatchEvent(new CustomEvent("titan:space:refresh",{detail:{spaceId:O.id}})),{ok:!0,id:P}):{ok:!1,error:"updateWidget requires an `id`"}}if(R.type==="canvas"&&((G=R.payload)==null?void 0:G.action)==="listWidgets")return{ok:!0,widgets:O.widgets||[]};if(R.type==="canvas"&&((q=R.payload)==null?void 0:q.action)==="removeWidget"){const P=R.payload.id;return P?(ke.removeWidget(O.id,P),window.dispatchEvent(new CustomEvent("titan:space:refresh",{detail:{spaceId:O.id}})),{ok:!0}):{ok:!1,error:"removeWidget requires an `id`"}}return{ok:!1,error:"Unknown message type"}}),v.current=j,()=>{j.destroy(),v.current=null}},[]);const _=w.useCallback(async(j,R)=>{const O=v.current;if(!O)return{status:"error",logs:[{level:"error",text:"Sandbox not ready"}],resultText:"",runId:Date.now(),error:{message:"Sandbox not ready",name:"SandboxError",stack:"",text:"Sandbox not ready"}};if(j==="_____javascript")try{const U=await O.execute(R);return{status:U.status==="success"?"success":"error",logs:U.logs||[],result:U.result,resultText:U.resultText||String(U.result??""),runId:Date.now(),error:U.error?{message:U.error.message||String(U.error),name:"ExecutionError",stack:"",text:String(U.error)}:void 0}}catch(U){return{status:"error",logs:[{level:"error",text:U.message||String(U)}],resultText:"",runId:Date.now(),error:{message:U.message||String(U),name:"ExecutionError",stack:"",text:String(U)}}}if(j==="_____react"){let U=4,z=4;const G=R.match(/\/\/\s*__WIDGET_META__\s+w=(\d+)\s+h=(\d+)/);G&&(U=parseInt(G[1],10)||4,z=parseInt(G[2],10)||4);try{const q=m({type:"render_widget",widget:{name:"React Widget",format:"react",source:R,w:U,h:z}});return{status:"success",logs:[{level:"info",text:`Created widget ${q}`}],result:{widgetId:q},resultText:`Created widget ${q}`,runId:Date.now()}}catch(q){return{status:"error",logs:[{level:"error",text:q.message||String(q)}],resultText:"",runId:Date.now(),error:{message:q.message||String(q),name:"WidgetError",stack:"",text:String(q)}}}}if(j==="_____widget"){const U=al({gate:"_____widget",code:R,leadingText:""});if(!U)return{status:"error",logs:[{level:"error",text:"Invalid widget payload"}],resultText:"",runId:Date.now(),error:{message:"Invalid widget payload",name:"WidgetError",stack:"",text:"Invalid widget payload"}};try{const z=m(U),G=U.type==="update_widget"?"Updated":"Created";return{status:"success",logs:[{level:"info",text:`${G} widget ${z}`}],result:z?{widgetId:z}:void 0,resultText:`${G} widget ${z??""}`.trim(),runId:Date.now()}}catch(z){return{status:"error",logs:[{level:"error",text:z.message||String(z)}],resultText:"",runId:Date.now(),error:{message:z.message||String(z),name:"WidgetError",stack:"",text:String(z)}}}}if(j==="_____canvas"){const U=Mf(R);if(U.length===0)return{status:"error",logs:[{level:"error",text:"Empty or invalid _____canvas payload (expected JSON array of {action, ...})"}],resultText:"",runId:Date.now(),error:{message:"Invalid canvas payload",name:"CanvasFenceError",stack:"",text:"Empty or invalid _____canvas payload"}};const z=[],G=[];for(const P of U)try{if(P.action==="create_widget"){if(!P.source){G.push("create_widget: missing source");continue}const V=m({type:"render_widget",widget:{name:P.name||"Widget",title:P.title,format:P.format||"react",source:P.source,w:P.w,h:P.h,x:P.x,y:P.y,metadata:P.metadata}});z.push(`created ${V}`)}else if(P.action==="update_widget"){if(!P.id){G.push("update_widget: missing id");continue}const V=P.patch??{};m({type:"update_widget",widgetId:P.id,patch:V}),z.push(`updated ${P.id}`)}else if(P.action==="remove_widget"){if(!P.id){G.push("remove_widget: missing id");continue}m({type:"remove_widget",widgetId:P.id}),z.push(`removed ${P.id}`)}else G.push(`unknown action: ${String(P.action)}`)}catch(V){G.push(V.message||String(V))}const q=G.length===0?"success":z.length===0?"error":"success";return{status:q,logs:[...z.map(P=>({level:"info",text:P})),...G.map(P=>({level:"error",text:P}))],resultText:z.length?z.join("; "):"No actions applied",runId:Date.now(),...q==="error"?{error:{message:G.join("; "),name:"CanvasFenceError",stack:"",text:G.join("; ")}}:{}}}return j==="_____tool"?{status:"error",logs:[{level:"error",text:"_____tool gate not supported in Canvas chat"}],resultText:"",runId:Date.now(),error:{message:"_____tool gate not supported",name:"NotSupported",stack:"",text:"_____tool gate not supported in Canvas chat"}}:{status:"error",logs:[{level:"error",text:`Unknown gate: ${j}`}],resultText:"",runId:Date.now(),error:{message:`Unknown gate: ${j}`,name:"UnknownGate",stack:"",text:`Unknown gate: ${j}`}}},[]),T=w.useCallback(async j=>{var G;const R=j.trim();if(!R)return;if(l){g(q=>q.length>=u?q:[...q,R]),c("");return}const O={role:"user",content:R,timestamp:Date.now()};i(q=>[...q,O]),c(""),d(!0),x(null),s==null||s("thinking");const U=new AbortController;E.current=U;let z="";try{const q=Ff(L.current),P=`canvas-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;await xl(R,P,te=>{if(te.type==="token")z+=te.data,i(re=>{const Q=re[re.length-1];return Q&&Q.role==="assistant"?[...re.slice(0,-1),{...Q,content:z}]:[...re,{role:"assistant",content:z,timestamp:Date.now()}]});else if(te.type==="widget"){const re=te.widgetMode||"create",Q=te.widget||{},ee=L.current;try{if(re==="remove"&&Q.id)ke.removeWidget(ee.id,Q.id);else if(re==="update"&&Q.id){const X={};typeof Q.name=="string"&&Q.name&&(X.name=Q.name),typeof Q.title=="string"&&(X.title=Q.title),typeof Q.source=="string"&&Q.source&&(X.source=Q.source),typeof Q.format=="string"&&(X.format=Q.format),typeof Q.w=="number"&&(X.w=Q.w),typeof Q.h=="number"&&(X.h=Q.h),ke.updateWidget(ee.id,Q.id,X)}else if(Q.source){const X=typeof Q.w=="number"?Q.w:4,ve=typeof Q.h=="number"?Q.h:4,Be=typeof Q.x=="number"&&typeof Q.y=="number"?{x:Q.x,y:Q.y}:Hs(ee.widgets||[],X,ve);ke.addWidget(ee.id,{name:Q.name||"Widget",title:Q.title,format:Q.format||"react",source:Q.source,x:Be.x,y:Be.y,w:X,h:ve,metadata:Q.metadata})}window.dispatchEvent(new CustomEvent("titan:space:refresh",{detail:{spaceId:ee.id}}))}catch(X){console.error("[ChatWidget] widget side-channel handler failed",X)}}else if(te.type==="done"){const re=te.data||z;z=re,i(Q=>{const ee=Q[Q.length-1];return ee&&ee.role==="assistant"?[...Q.slice(0,-1),{...ee,content:re}]:[...Q,{role:"assistant",content:re,timestamp:Date.now()}]})}else te.type==="error"&&x(te.data)},U.signal,{systemPromptAppendix:q});const $=Of(z).filter(te=>te.gate!=="_____transient"&&te.gate!=="_____framework");if($.length>0){s==null||s("executing");const te=[];for(const ee of $){const X=Uf(`${ee.gate}
|
|
826
|
+
${ee.code}`);if(!X.valid){te.push({status:"error",logs:[{level:"error",text:X.error||"Invalid execution"}],resultText:"",runId:Date.now(),error:{message:X.error||"Invalid execution",name:"ValidationError",stack:"",text:X.error||""}});continue}const ve=await _(ee.gate,ee.code);te.push(ve)}const re=Pf(te);i(ee=>[...ee,re]);const Q=te.find(ee=>ee.status==="error");Q&&x(((G=Q.error)==null?void 0:G.text)||"Execution failed")}}catch(q){q.name!=="AbortError"&&x(q.message||"Request failed")}finally{d(!1),E.current=null,s==null||s("idle")}},[l,s,_]),S=w.useCallback(()=>{var j;(j=E.current)==null||j.abort(),E.current=null,d(!1),g([]),s==null||s("idle")},[s]);w.useEffect(()=>{if(l||p.length===0)return;const[j,...R]=p;g(R),T(j)},[l,p,T]);const N=w.useCallback(j=>{g(R=>R.filter((O,U)=>U!==j))},[]),D=w.useCallback(j=>{j.key==="Enter"&&!j.shiftKey&&(j.preventDefault(),T(o))},[o,T]);return n.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",width:"100%"},children:[n.jsx("iframe",{ref:A,style:{position:"absolute",width:0,height:0,border:0,visibility:"hidden"},sandbox:"allow-scripts"}),n.jsxs("div",{style:{flex:1,overflowY:"auto",padding:12},children:[r.map((j,R)=>n.jsxs("div",{style:{marginBottom:8,padding:8,borderRadius:8,background:j.role==="user"?"rgba(59,130,246,0.15)":j.role==="framework"?"rgba(245,158,11,0.1)":"rgba(255,255,255,0.05)",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:[n.jsx("div",{style:{fontSize:10,opacity:.6,marginBottom:4,textTransform:"uppercase"},children:j.role}),n.jsx("div",{style:{fontSize:13,lineHeight:1.5},children:j.content}),j.executions&&j.executions.length>0&&n.jsx("div",{style:{marginTop:4,fontSize:11,opacity:.7},children:j.executions.map((O,U)=>n.jsxs("span",{style:{marginRight:8},children:[O.status==="success"?"✓":"✗"," execution ",U+1]},U))})]},R)),l&&n.jsx("div",{style:{fontSize:12,opacity:.5,padding:8},children:"Thinking…"}),f&&n.jsx("div",{style:{color:"#ef4444",fontSize:12,padding:8,background:"rgba(239,68,68,0.1)",borderRadius:6},children:f}),n.jsx("div",{ref:b})]}),p.length>0&&n.jsxs("div",{style:{padding:"6px 12px",borderTop:"1px solid rgba(255,255,255,0.08)",display:"flex",flexWrap:"wrap",gap:6,background:"rgba(99,102,241,0.06)"},children:[n.jsxs("span",{style:{fontSize:10,opacity:.7,alignSelf:"center",textTransform:"uppercase",letterSpacing:.5},children:["Queued (",p.length,")"]}),p.map((j,R)=>n.jsxs("span",{title:j,style:{fontSize:11,padding:"3px 8px",background:"rgba(99,102,241,0.18)",border:"1px solid rgba(99,102,241,0.4)",borderRadius:999,color:"#e0e7ff",display:"inline-flex",alignItems:"center",gap:6,maxWidth:220},children:[n.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:j}),n.jsx("button",{onClick:()=>N(R),title:"Remove from queue",style:{border:"none",background:"transparent",color:"#c7d2fe",cursor:"pointer",padding:0,fontSize:12,lineHeight:1},children:"×"})]},R))]}),n.jsxs("div",{style:{padding:12,borderTop:"1px solid rgba(255,255,255,0.08)",display:"flex",gap:8},children:[n.jsx("input",{type:"text",value:o,onChange:j=>c(j.target.value),onKeyDown:D,placeholder:l?p.length>=u?`Queue full (${u}) — wait for TITAN to catch up…`:"TITAN is thinking — type to steer or queue a follow-up…":"Ask TITAN to create an agent, run a task, or build a widget…",style:{flex:1,background:"rgba(255,255,255,0.06)",border:l?"1px solid rgba(99,102,241,0.4)":"1px solid rgba(255,255,255,0.1)",borderRadius:8,padding:"8px 12px",color:"#fff",fontSize:13,outline:"none"}}),l?n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>T(o),disabled:!o.trim()||p.length>=u,title:"Queue this message for after the current turn",style:{padding:"8px 14px",borderRadius:8,border:"none",background:o.trim()&&p.length<u?"#6366f1":"rgba(255,255,255,0.1)",color:"#fff",fontSize:13,cursor:o.trim()&&p.length<u?"pointer":"not-allowed"},children:"Queue"}),n.jsx("button",{onClick:S,title:"Stop the current turn and clear the queue",style:{padding:"8px 14px",borderRadius:8,border:"none",background:"#ef4444",color:"#fff",fontSize:13,cursor:"pointer"},children:"Stop"})]}):n.jsx("button",{onClick:()=>T(o),disabled:!o.trim(),style:{padding:"8px 14px",borderRadius:8,border:"none",background:o.trim()?"#3b82f6":"rgba(255,255,255,0.1)",color:"#fff",fontSize:13,cursor:o.trim()?"pointer":"not-allowed"},children:"Send"})]})]})}const Pi={idle:{eye:"#c4a35a",glow:"#f3d27a",ring:"#a47a3a",body:"#3a2410"},thinking:{eye:"#d4b06a",glow:"#e7c68a",ring:"#b4863a",body:"#3a2410"},executing:{eye:"#d4a040",glow:"#f0c060",ring:"#a47a3a",body:"#3a2410"},listening:{eye:"#8ab8c4",glow:"#a8c8d8",ring:"#6a8a98",body:"#2a2010"},error:{eye:"#c45a30",glow:"#e08050",ring:"#a04a20",body:"#3a1810"}},J={brassDark:"#7a5a2a",brassMid:"#b8902f",brassBright:"#e8c478",brassHi:"#f7e3a8",woodDark:"#3a2412",woodMid:"#5a3818",glassDark:"#0e1612",glassMid:"#1c2820",steam:"#e6d8b8",bolt:"#2a1808"},$f=9e4;function zf({state:t="idle",mood:e="neutral",size:s=116,quip:r=null,bubblePhase:i=null,followCursor:o=!0,somaActive:c=!1,somaPoll:l=!0,sleepAfterMs:d=$f,className:p="",onClick:g,edgeRotate:u=0,faceFlip:f=!1,edgeHidden:x=!1}){const[b,E]=w.useState(null),A=b??e,v=Pi[t]??Pi.idle,[L,m]=w.useState({x:0,y:0}),[k,_]=w.useState(!1),[T,S]=w.useState(!1),[N,D]=w.useState(!1),[j,R]=w.useState(!1),[O,U]=w.useState(0),[z,G]=w.useState(!1),[q,P]=w.useState(!1),V=w.useRef(null),$=w.useRef(Date.now());w.useEffect(()=>{const ce=window.matchMedia("(prefers-reduced-motion: reduce)");P(ce.matches);const ge=be=>P(be.matches);return ce.addEventListener("change",ge),()=>ce.removeEventListener("change",ge)},[]),w.useEffect(()=>{$.current=Date.now(),t!=="idle"&&(D(!1),S(!1))},[t]),w.useEffect(()=>{const ce=()=>{$.current=Date.now()};return window.addEventListener("mousemove",ce,{passive:!0}),window.addEventListener("keydown",ce,{passive:!0}),window.addEventListener("click",ce,{passive:!0}),()=>{window.removeEventListener("mousemove",ce),window.removeEventListener("keydown",ce),window.removeEventListener("click",ce)}},[]),w.useEffect(()=>{if(t==="error"||N){_(!1);return}let ce=!1,ge=null;const be=()=>{if(ce)return;const we=2500+Math.random()*4e3;setTimeout(()=>{ce||(_(!0),ge=window.setTimeout(()=>{ge=null,ce||_(!1)},140),be())},we)};return be(),()=>{ce=!0,ge&&clearTimeout(ge)}},[t,N]),w.useEffect(()=>{if(t!=="idle"||N){S(!1);return}let ce=!1,ge=null;const be=()=>{const we=18e3+Math.random()*17e3;setTimeout(()=>{ce||(S(!0),ge=window.setTimeout(()=>{ge=null,ce||S(!1)},1600),be())},we)};return be(),()=>{ce=!0,ge&&clearTimeout(ge)}},[t,N]),w.useEffect(()=>{if(t!=="idle"){D(!1);return}let ce=!1;const ge=()=>{const we=Date.now()-$.current;if(we>=d)ce||D(!0);else{const K=d-we;return setTimeout(()=>{ce||ge()},Math.min(K,5e3))}},be=ge();return()=>{ce=!0,be&&clearTimeout(be)}},[t,d]),w.useEffect(()=>{if(!l){E(null);return}let ce=!1;const ge=(K,Y,Z)=>{if((Z.curiosity??.5)>.65&&(Z.satisfaction??.5)>.6)return"excited";switch(K){case"curiosity":return Y<0?"curious":"happy";case"focus":return"focused";case"fatigue":return"tired";case"satisfaction":return Y>0?"happy":"neutral";case"frustration":return"frustrated";case"hunger":return Y<0?"tired":"happy";case"safety":return Y<0?"frustrated":"happy";case"social":return Y<0?"curious":"happy";case"purpose":return Y<0?"curious":"focused";default:return"neutral"}},be=async()=>{try{const K=typeof localStorage<"u"?localStorage.getItem("titan-token"):null,Y={};K&&(Y.Authorization=`Bearer ${K}`);const Z=await fetch("/api/soma/drives",{headers:Y});if(!Z.ok)return;const ae=await Z.json();if(ce)return;if(!ae.dominant||ae.dominant.drive==="neutral"||!ae.current){E(null);return}E(ge(ae.dominant.drive,ae.dominant.delta,ae.current))}catch{}};be();const we=setInterval(be,1e4);return()=>{ce=!0,clearInterval(we)}},[l]),w.useEffect(()=>{if(t!=="listening"){R(!1);return}R(!0);const ce=setTimeout(()=>R(!1),1200);return()=>clearTimeout(ce)},[t]),w.useEffect(()=>{if(!o||!V.current||q)return;const ce=V.current,ge=220,be=5,we={x:0,y:0,has:!1},K=M=>{we.x=M.clientX,we.y=M.clientY,we.has=!0};let Y=0,Z=!1;const ae=()=>{if(!Z){if(we.has){const M=ce.getBoundingClientRect(),B=M.left+M.width/2,H=M.top+M.height*.28,se=(we.x-B)/ge,C=(we.y-H)/ge,a=I=>Math.max(-1,Math.min(1,I)),h=a(se)*be,y=a(C)*be*.6;m(I=>Math.abs(I.x-h)<.05&&Math.abs(I.y-y)<.05?I:{x:h,y})}Y=requestAnimationFrame(ae)}};return Y=requestAnimationFrame(ae),window.addEventListener("mousemove",K,{passive:!0}),()=>{Z=!0,cancelAnimationFrame(Y),window.removeEventListener("mousemove",K)}},[o,q]);const te=w.useCallback(()=>{G(!0),U(ce=>ce+1),setTimeout(()=>G(!1),520),g==null||g()},[g]),re=k?.6:T?5.5:4.5,Q=k?.4:T?3:5.5,ee=(()=>{switch(A){case"happy":return{browL:"M 35 33 Q 42 30 47 33",browR:"M 53 33 Q 58 30 65 33",mouthD:"M 42 56 Q 50 62 58 56",eyeSquintTop:!0,bodyLean:0};case"focused":return{browL:"M 35 33 L 47 35",browR:"M 53 35 L 65 33",mouthD:"M 44 58 L 56 58",eyeSquintTop:!1,bodyLean:2.5};case"tired":return{browL:"M 35 35 Q 41 35 47 36",browR:"M 53 36 Q 59 35 65 35",mouthD:"M 44 58 Q 50 58 56 58",eyeSquintTop:!0,bodyLean:-1.5};case"curious":return{browL:"M 35 32 Q 41 28 47 32",browR:"M 53 33 Q 58 31 65 33",mouthD:"M 46 58 Q 50 59 54 58",eyeSquintTop:!1,bodyLean:1};case"excited":return{browL:"M 35 31 Q 41 27 47 31",browR:"M 53 31 Q 58 27 65 31",mouthD:"M 40 55 Q 50 64 60 55",eyeSquintTop:!1,bodyLean:0};case"frustrated":return{browL:"M 35 32 L 47 36",browR:"M 53 36 L 65 32",mouthD:"M 42 60 Q 50 56 58 60",eyeSquintTop:!1,bodyLean:0};case"proud":return{browL:"M 35 33 Q 41 31 47 33",browR:"M 53 33 Q 58 31 65 33",mouthD:"M 43 56 Q 50 59 57 56",eyeSquintTop:!1,bodyLean:-1};case"neutral":default:return{browL:"M 35 34 L 47 34",browR:"M 53 34 L 65 34",mouthD:null,eyeSquintTop:!1,bodyLean:0}}})(),X=s,ve=i?`mascot-bubble mascot-bubble--${i}`:"mascot-bubble",Be=r?`bubble-${r}-${Date.now()}`:"no-bubble";return n.jsxs("div",{ref:V,className:p,style:{width:X,height:X*1.38},children:[n.jsx("style",{children:`
|
|
827
|
+
/* v6.0.4 — Space Agent-style multi-axis float. Bigger
|
|
828
|
+
translations + a wider rotation range so the mascot feels
|
|
829
|
+
like it's drifting on a tether instead of pulsing in
|
|
830
|
+
place. Linear easing reads as physics, not animation. */
|
|
831
|
+
@keyframes mascot-float {
|
|
832
|
+
0% { transform: translate3d(0, 0, 0) rotate(-6deg); }
|
|
833
|
+
25% { transform: translate3d(5px, -5px, 0) rotate(-2deg); }
|
|
834
|
+
50% { transform: translate3d(0, -8px, 0) rotate(5deg); }
|
|
835
|
+
75% { transform: translate3d(-5px, -4px, 0) rotate(1deg); }
|
|
836
|
+
100% { transform: translate3d(0, 0, 0) rotate(-6deg); }
|
|
837
|
+
}
|
|
838
|
+
@keyframes mascot-breathe {
|
|
839
|
+
0%, 100% { transform: scale(1); }
|
|
840
|
+
50% { transform: scale(1.012); }
|
|
841
|
+
}
|
|
842
|
+
@keyframes mascot-listen-ring {
|
|
843
|
+
0% { r: 14; opacity: 0.55; }
|
|
844
|
+
100% { r: 38; opacity: 0; }
|
|
845
|
+
}
|
|
846
|
+
@keyframes mascot-zzz {
|
|
847
|
+
0% { transform: translate3d(0, 0, 0) scale(0.7); opacity: 0; }
|
|
848
|
+
30% { opacity: 0.85; }
|
|
849
|
+
100% { transform: translate3d(10px, -22px, 0) scale(1.1); opacity: 0; }
|
|
850
|
+
}
|
|
851
|
+
@keyframes mascot-poke-bounce {
|
|
852
|
+
0% { transform: translate3d(0, 0, 0) scale(1); }
|
|
853
|
+
30% { transform: translate3d(0, -12px, 0) scale(1.06, 0.94); }
|
|
854
|
+
55% { transform: translate3d(0, 2px, 0) scale(0.97, 1.03); }
|
|
855
|
+
75% { transform: translate3d(0, -4px, 0) scale(1.02, 0.98); }
|
|
856
|
+
100% { transform: translate3d(0, 0, 0) scale(1); }
|
|
857
|
+
}
|
|
858
|
+
@keyframes mascot-soma-halo {
|
|
859
|
+
0%, 100% { stroke-opacity: 0.22; }
|
|
860
|
+
50% { stroke-opacity: 0.55; }
|
|
861
|
+
}
|
|
862
|
+
@keyframes mascot-thinking-particle {
|
|
863
|
+
0% { opacity: 0; transform: translate3d(0, 0, 0); }
|
|
864
|
+
40% { opacity: 1; }
|
|
865
|
+
100% { opacity: 0; transform: translate3d(6px, -14px, 0); }
|
|
866
|
+
}
|
|
867
|
+
@keyframes mascot-hand-wave {
|
|
868
|
+
0%, 100% { transform: translate3d(0, 0, 0); }
|
|
869
|
+
25% { transform: translate3d(6px, -10px, 0); }
|
|
870
|
+
50% { transform: translate3d(0, -4px, 0); }
|
|
871
|
+
75% { transform: translate3d(-4px, -8px, 0); }
|
|
872
|
+
}
|
|
873
|
+
/* v6.1.0-alpha.51 — Steampunk motion layers. Lots of
|
|
874
|
+
movement so the mascot feels mechanical and alive,
|
|
875
|
+
not just a static figure that bobs. */
|
|
876
|
+
@keyframes mascot-cog-spin {
|
|
877
|
+
from { transform: rotate(0deg); }
|
|
878
|
+
to { transform: rotate(360deg); }
|
|
879
|
+
}
|
|
880
|
+
@keyframes mascot-cog-spin-rev {
|
|
881
|
+
from { transform: rotate(0deg); }
|
|
882
|
+
to { transform: rotate(-360deg); }
|
|
883
|
+
}
|
|
884
|
+
@keyframes mascot-pendulum {
|
|
885
|
+
0%, 100% { transform: rotate(-14deg); }
|
|
886
|
+
50% { transform: rotate(14deg); }
|
|
887
|
+
}
|
|
888
|
+
@keyframes mascot-steam-puff {
|
|
889
|
+
0% { transform: translate3d(0, 0, 0) scale(0.5); opacity: 0; }
|
|
890
|
+
25% { opacity: 0.85; }
|
|
891
|
+
100% { transform: translate3d(-3px, -22px, 0) scale(1.6); opacity: 0; }
|
|
892
|
+
}
|
|
893
|
+
@keyframes mascot-piston {
|
|
894
|
+
0%, 100% { transform: translate3d(0, 0, 0); }
|
|
895
|
+
50% { transform: translate3d(0, -2.2px, 0); }
|
|
896
|
+
}
|
|
897
|
+
@keyframes mascot-gauge-tick {
|
|
898
|
+
0%, 80%, 100% { transform: rotate(-18deg); }
|
|
899
|
+
85%, 95% { transform: rotate(22deg); }
|
|
900
|
+
}
|
|
901
|
+
@keyframes mascot-bolt-glint {
|
|
902
|
+
0%, 92%, 100% { opacity: 0.55; }
|
|
903
|
+
96% { opacity: 1; }
|
|
904
|
+
}
|
|
905
|
+
.mascot-cog { animation: mascot-cog-spin 7s linear infinite; transform-origin: 50px 86px; }
|
|
906
|
+
.mascot-cog-sm { animation: mascot-cog-spin-rev 4s linear infinite; transform-origin: 57px 92px; }
|
|
907
|
+
.mascot-pendulum { animation: mascot-pendulum 2.6s ease-in-out infinite; transform-origin: 50px 78px; }
|
|
908
|
+
.mascot-steam { animation: mascot-steam-puff 3.2s ease-out infinite; transform-origin: center; }
|
|
909
|
+
.mascot-piston { animation: mascot-piston 1.4s ease-in-out infinite; }
|
|
910
|
+
.mascot-gauge { animation: mascot-gauge-tick 4.8s ease-in-out infinite; }
|
|
911
|
+
.mascot-bolt-glint{ animation: mascot-bolt-glint 6s ease-in-out infinite; }
|
|
912
|
+
/* ── Speech bubble keyframes (Space Agent port) ── */
|
|
913
|
+
@keyframes titan-bubble-land {
|
|
914
|
+
0% { opacity: 0; transform: translate3d(-50%, 14px, 0) scale(0.76) rotate(-3deg); }
|
|
915
|
+
58% { opacity: 1; transform: translate3d(-50%, -3px, 0) scale(1.03) rotate(0.8deg); }
|
|
916
|
+
100% { opacity: 1; transform: translate3d(-50%, 0, 0) scale(1) rotate(0deg); }
|
|
917
|
+
}
|
|
918
|
+
@keyframes titan-bubble-dismiss {
|
|
919
|
+
0% { opacity: 1; transform: translate3d(-50%, 0, 0) scale(1); }
|
|
920
|
+
100% { opacity: 0; transform: translate3d(-50%, 8px, 0) scale(0.84); }
|
|
921
|
+
}
|
|
922
|
+
.mascot-body {
|
|
923
|
+
animation: mascot-float 8.4s ease-in-out infinite;
|
|
924
|
+
overflow: visible;
|
|
925
|
+
}
|
|
926
|
+
/* v6.0 — smooth state transitions on every animated SVG fill/stroke.
|
|
927
|
+
Replaces the v5 snap-flip palette change with a 600ms morph,
|
|
928
|
+
so flipping between idle/thinking/executing feels alive. */
|
|
929
|
+
.mascot-body path,
|
|
930
|
+
.mascot-body ellipse,
|
|
931
|
+
.mascot-body rect,
|
|
932
|
+
.mascot-body circle {
|
|
933
|
+
transition: fill 600ms ease-out, stroke 600ms ease-out, opacity 400ms ease-out;
|
|
934
|
+
}
|
|
935
|
+
/* Excited mood gets a faster, bouncier float. */
|
|
936
|
+
.mascot-body.mood-excited {
|
|
937
|
+
animation-duration: 5.5s;
|
|
938
|
+
}
|
|
939
|
+
/* Tired mood slows the float way down. */
|
|
940
|
+
.mascot-body.mood-tired {
|
|
941
|
+
animation-duration: 14s;
|
|
942
|
+
}
|
|
943
|
+
/* Frustrated mood adds a subtle twitch. */
|
|
944
|
+
@keyframes mascot-twitch {
|
|
945
|
+
0%, 96%, 100% { transform: translate3d(0, 0, 0); }
|
|
946
|
+
97% { transform: translate3d(-1.5px, 0, 0); }
|
|
947
|
+
98% { transform: translate3d(1.5px, 0, 0); }
|
|
948
|
+
99% { transform: translate3d(-0.5px, 0, 0); }
|
|
949
|
+
}
|
|
950
|
+
.mascot-body.mood-frustrated {
|
|
951
|
+
animation: mascot-float 8.4s ease-in-out infinite, mascot-twitch 3.2s linear infinite;
|
|
952
|
+
}
|
|
953
|
+
/* Eyebrow + mouth strokes get the same smooth transition so
|
|
954
|
+
mood switches morph the face instead of snapping. */
|
|
955
|
+
.mascot-eyebrow, .mascot-mouth {
|
|
956
|
+
transition: d 500ms cubic-bezier(0.34, 1.2, 0.64, 1),
|
|
957
|
+
stroke 500ms ease-out,
|
|
958
|
+
opacity 400ms ease-out;
|
|
959
|
+
}
|
|
960
|
+
.mascot-body.sleeping { animation: mascot-float 12s ease-in-out infinite; }
|
|
961
|
+
.mascot-body.poking { animation: mascot-poke-bounce 520ms cubic-bezier(0.28, 0.84, 0.42, 1) both; }
|
|
962
|
+
.mascot-torso { animation: mascot-breathe 4s ease-in-out infinite; }
|
|
963
|
+
.mascot-listen-ring { animation: mascot-listen-ring 1.4s ease-out infinite; }
|
|
964
|
+
.mascot-zzz { animation: mascot-zzz 2.2s ease-in-out infinite; }
|
|
965
|
+
.mascot-hand-r.waving { animation: mascot-hand-wave 1.2s ease-in-out both; }
|
|
966
|
+
.mascot-halo.soma { animation: mascot-soma-halo 3.2s ease-in-out infinite; }
|
|
967
|
+
.mascot-thinking-particle { animation: mascot-thinking-particle 1.6s ease-out infinite; }
|
|
968
|
+
/* Bubble animation classes */
|
|
969
|
+
.mascot-bubble {
|
|
970
|
+
will-change: opacity, transform;
|
|
971
|
+
pointer-events: none;
|
|
972
|
+
}
|
|
973
|
+
.mascot-bubble--entering {
|
|
974
|
+
animation: titan-bubble-land 400ms cubic-bezier(0.2, 1.24, 0.32, 1) both;
|
|
975
|
+
}
|
|
976
|
+
.mascot-bubble--visible {
|
|
977
|
+
opacity: 1;
|
|
978
|
+
transform: translate3d(-50%, 0, 0) scale(1);
|
|
979
|
+
}
|
|
980
|
+
.mascot-bubble--leaving {
|
|
981
|
+
animation: titan-bubble-dismiss 180ms ease both;
|
|
982
|
+
}
|
|
983
|
+
/* Respect reduced-motion */
|
|
984
|
+
@media (prefers-reduced-motion: reduce) {
|
|
985
|
+
.mascot-body, .mascot-torso, .mascot-listen-ring,
|
|
986
|
+
.mascot-zzz, .mascot-hand-r.waving, .mascot-halo.soma,
|
|
987
|
+
.mascot-thinking-particle, .mascot-bubble,
|
|
988
|
+
.mascot-cog, .mascot-cog-sm, .mascot-pendulum,
|
|
989
|
+
.mascot-steam, .mascot-piston, .mascot-gauge,
|
|
990
|
+
.mascot-bolt-glint {
|
|
991
|
+
animation: none !important;
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
`}),r&&n.jsxs("div",{className:`${ve} absolute left-1/2 px-2.5 py-1.5 rounded-xl bg-[#fdf6e3] border border-[#d4c5a8] text-[11px] text-[#2a2210] whitespace-nowrap shadow-lg`,style:{top:-8,maxWidth:s*2.2,lineHeight:1.35},children:[r,n.jsx("span",{className:"absolute left-1/2 -translate-x-1/2 -bottom-1.5 w-2.5 h-2.5 rotate-45 bg-[#fdf6e3] border-r border-b border-[#d4c5a8]"})]},Be),n.jsx("div",{className:"mascot-root absolute inset-x-0 bottom-0",style:{"--glow":v.glow,cursor:g?"pointer":"default",pointerEvents:g?"auto":"none"},onClick:te,children:n.jsx("div",{style:{width:X,height:X*1.38,transform:`rotate(${u}deg) scaleX(${f?-1:1})`,transformOrigin:"center",transition:"transform 260ms cubic-bezier(0.2, 0.9, 0.25, 1)"},children:n.jsxs("svg",{viewBox:"0 0 100 138",width:X,height:X*1.38,className:["mascot-body",t,`mood-${A}`,N?"sleeping":"",z?"poking":""].join(" ").trim(),style:{display:"block",overflow:"visible",transform:`rotate(${ee.bodyLean}deg)`,transformOrigin:"50% 110%",transition:"transform 600ms cubic-bezier(0.34, 1.2, 0.64, 1)"},children:[n.jsxs("defs",{children:[n.jsxs("radialGradient",{id:`mascot-glow-${t}`,cx:"50%",cy:"50%",r:"50%",children:[n.jsx("stop",{offset:"0%",stopColor:v.glow,stopOpacity:t==="executing"?.45:.22}),n.jsx("stop",{offset:"100%",stopColor:v.glow,stopOpacity:0})]}),n.jsxs("linearGradient",{id:`mascot-body-${t}`,x1:"0%",y1:"0%",x2:"100%",y2:"100%",children:[n.jsx("stop",{offset:"0%",stopColor:v.body}),n.jsx("stop",{offset:"50%",stopColor:"#0a0614"}),n.jsx("stop",{offset:"100%",stopColor:"#050208"})]}),n.jsx("filter",{id:`mascot-shadow-${t}`,children:n.jsx("feDropShadow",{dx:"0",dy:"2",stdDeviation:"3",floodColor:v.ring,floodOpacity:x?"0":"0.35"})})]}),N&&n.jsxs("g",{fontFamily:"ui-sans-serif, system-ui",fontWeight:"700",fill:v.glow,opacity:"0.85",children:[n.jsx("text",{className:"mascot-zzz",x:"66",y:"22",fontSize:"9",style:{animationDelay:"0s"},children:"z"}),n.jsx("text",{className:"mascot-zzz",x:"70",y:"14",fontSize:"11",style:{animationDelay:"0.7s"},children:"Z"}),n.jsx("text",{className:"mascot-zzz",x:"74",y:"6",fontSize:"13",style:{animationDelay:"1.4s"},children:"Z"})]}),n.jsx("circle",{cx:"50",cy:"50",r:"48",fill:`url(#mascot-glow-${t})`,opacity:"0.9"}),t==="listening"&&n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"50",cy:"40",r:"14",className:"mascot-listen-ring",stroke:v.glow,strokeWidth:"1.5"}),n.jsx("circle",{cx:"50",cy:"40",r:"14",className:"mascot-listen-ring",stroke:v.glow,strokeWidth:"1.5",style:{animationDelay:"0.5s"}})]}),n.jsx("ellipse",{cx:"50",cy:"42",rx:"34",ry:"14",fill:"none",stroke:v.ring,strokeWidth:"1.5",strokeOpacity:"0.32",className:`mascot-halo ${t} ${c?"soma":""}`}),n.jsx("path",{d:"M48 18 Q52 16 48 14 Q52 12 48 10",stroke:J.brassMid,strokeWidth:"1.3",fill:"none",strokeLinecap:"round"}),n.jsx("line",{x1:"50",y1:"11",x2:"50",y2:"6",stroke:J.brassDark,strokeWidth:"1.4",strokeLinecap:"round"}),n.jsx("ellipse",{cx:"50",cy:"5",rx:"3.4",ry:"3.8",fill:J.glassMid,stroke:J.brassBright,strokeWidth:"0.7",opacity:"0.9"}),n.jsx("circle",{cx:"50",cy:"5",r:"2",fill:v.glow,opacity:"0.95",children:!q&&n.jsx("animate",{attributeName:"r",values:"1.6;2.4;1.6",dur:t==="executing"?"0.7s":c?"3.2s":"2.6s",repeatCount:"indefinite"})}),n.jsx("circle",{cx:"50",cy:"5",r:"5.5",fill:v.glow,opacity:"0.18",children:!q&&n.jsx("animate",{attributeName:"opacity",values:"0.08;0.32;0.08",dur:"2.6s",repeatCount:"indefinite"})}),n.jsx("path",{d:"M48.5 3.5 Q49.5 3 50.5 3.6",stroke:"#fff7d8",strokeWidth:"0.7",fill:"none",opacity:"0.85"}),!q&&n.jsxs("g",{opacity:"0.7",children:[n.jsx("circle",{className:"mascot-steam",cx:"63",cy:"20",r:"2.4",fill:J.steam,style:{animationDelay:"0s"}}),n.jsx("circle",{className:"mascot-steam",cx:"66",cy:"22",r:"1.8",fill:J.steam,style:{animationDelay:"1.1s"}}),n.jsx("circle",{className:"mascot-steam",cx:"60",cy:"19",r:"2.0",fill:J.steam,style:{animationDelay:"2.0s"}})]}),n.jsx("path",{d:"M60 22 L62 19 L66 19 L68 22 Z",fill:J.brassMid,stroke:J.brassDark,strokeWidth:"0.6"}),n.jsx("ellipse",{cx:"64",cy:"22",rx:"4",ry:"1",fill:J.brassDark}),n.jsx("rect",{x:"32",y:"44",width:"36",height:"22",rx:"6",fill:J.brassDark,stroke:J.bolt,strokeWidth:"0.7"}),n.jsx("rect",{x:"34",y:"46",width:"32",height:"18",rx:"5",fill:J.brassMid,opacity:"0.85"}),n.jsx("line",{x1:"32",y1:"55",x2:"68",y2:"55",stroke:J.brassDark,strokeWidth:"0.6",opacity:"0.7"}),n.jsx("g",{className:"mascot-piston",children:n.jsx("rect",{x:"36",y:"40",width:"3",height:"6",rx:"0.8",fill:J.brassBright,stroke:J.bolt,strokeWidth:"0.4"})}),n.jsx("g",{className:"mascot-piston",style:{animationDelay:"0.7s"},children:n.jsx("rect",{x:"61",y:"40",width:"3",height:"6",rx:"0.8",fill:J.brassBright,stroke:J.bolt,strokeWidth:"0.4"})}),n.jsxs("g",{filter:`url(#mascot-shadow-${t})`,children:[n.jsx("circle",{cx:"50",cy:"38",r:"23",fill:J.brassMid,stroke:J.bolt,strokeWidth:"0.9"}),n.jsx("path",{d:"M32 32 Q50 12 68 32",stroke:J.brassHi,strokeWidth:"1.4",fill:"none",opacity:"0.55"}),n.jsx("circle",{cx:"50",cy:"38",r:"19",fill:J.brassDark}),n.jsx("circle",{cx:"50",cy:"38",r:"17.5",fill:J.glassDark}),n.jsxs("g",{fill:J.bolt,opacity:"0.85",children:[n.jsx("circle",{cx:"32",cy:"38",r:"1.1"}),n.jsx("circle",{cx:"68",cy:"38",r:"1.1"}),n.jsx("circle",{cx:"37",cy:"22",r:"1.0"}),n.jsx("circle",{cx:"63",cy:"22",r:"1.0",className:"mascot-bolt-glint"}),n.jsx("circle",{cx:"37",cy:"54",r:"1.0"}),n.jsx("circle",{cx:"63",cy:"54",r:"1.0"})]})]}),n.jsx("ellipse",{cx:"50",cy:"39",rx:"16",ry:"13",fill:v.body,stroke:J.brassBright,strokeWidth:"0.9"}),n.jsx("ellipse",{cx:"50",cy:"39",rx:"15",ry:"12",fill:v.glow,opacity:"0.12"}),n.jsx("line",{x1:"34",y1:"39",x2:"66",y2:"39",stroke:J.brassDark,strokeWidth:"0.35",opacity:"0.45"}),n.jsx("line",{x1:"50",y1:"26",x2:"50",y2:"52",stroke:J.brassDark,strokeWidth:"0.35",opacity:"0.45"}),n.jsx("path",{d:"M37 31 Q41 27 49 27",stroke:"#fff7d8",strokeWidth:"1.7",strokeLinecap:"round",fill:"none",opacity:"0.55"}),n.jsx("path",{d:"M55 28 Q58 28 60 29.5",stroke:"#fff7d8",strokeWidth:"1.0",strokeLinecap:"round",fill:"none",opacity:"0.4"}),n.jsxs("g",{transform:`translate(${f?-L.x:L.x}, ${L.y})`,children:[n.jsxs("ellipse",{cx:"50",cy:"40",rx:re,ry:Q,fill:v.eye,style:{transition:"rx 140ms ease-out, ry 140ms ease-out"},children:[t==="thinking"&&!N&&!q&&n.jsx("animate",{attributeName:"cx",values:"46;54;46",dur:"1.6s",repeatCount:"indefinite"}),t==="executing"&&!q&&n.jsx("animate",{attributeName:"rx",values:"4.5;6.5;4.5",dur:"0.8s",repeatCount:"indefinite"})]}),ee.eyeSquintTop&&!k&&!T&&n.jsx("rect",{x:"43",y:"36",width:"14",height:"2.2",rx:"1",fill:v.body,opacity:"0.9"}),!N&&n.jsx("circle",{cx:48+(f?-L.x:L.x)*.4,cy:"38.5",r:"1.3",fill:"#ffffff",opacity:"0.9"})]}),!T&&!N&&t!=="error"&&n.jsxs("g",{stroke:v.eye,strokeWidth:"1.4",strokeLinecap:"round",fill:"none",opacity:"0.9",children:[n.jsx("path",{d:ee.browL,className:"mascot-eyebrow",transform:"translate(0, -3)"}),n.jsx("path",{d:ee.browR,className:"mascot-eyebrow",transform:"translate(0, -3)"})]}),ee.mouthD&&!N&&t!=="error"&&n.jsx("path",{d:ee.mouthD,stroke:v.eye,strokeWidth:"1.4",strokeLinecap:"round",fill:"none",opacity:"0.9",className:"mascot-mouth",transform:"translate(0, -4)"}),n.jsx("rect",{x:"40",y:"60",width:"20",height:"4.5",rx:"1",fill:J.brassDark}),n.jsx("rect",{x:"40",y:"60",width:"20",height:"2",rx:"0.6",fill:J.brassBright,opacity:"0.85"}),n.jsx("ellipse",{cx:"50",cy:"65",rx:"22",ry:"4",fill:J.brassMid,stroke:J.bolt,strokeWidth:"0.6"}),n.jsx("circle",{cx:"32",cy:"65",r:"0.9",fill:J.bolt}),n.jsx("circle",{cx:"68",cy:"65",r:"0.9",fill:J.bolt}),n.jsxs("g",{className:"mascot-torso",children:[n.jsx("path",{d:`M28 66
|
|
995
|
+
Q28 64 32 64
|
|
996
|
+
L68 64
|
|
997
|
+
Q72 64 72 66
|
|
998
|
+
L74 108
|
|
999
|
+
Q74 116 66 116
|
|
1000
|
+
L34 116
|
|
1001
|
+
Q26 116 26 108 Z`,fill:J.woodMid,stroke:J.bolt,strokeWidth:"0.9",filter:`url(#mascot-shadow-${t})`}),n.jsx("path",{d:"M30 78 Q50 76 70 78",stroke:J.woodDark,strokeWidth:"0.5",fill:"none",opacity:"0.55"}),n.jsx("path",{d:"M30 100 Q50 98 70 100",stroke:J.woodDark,strokeWidth:"0.5",fill:"none",opacity:"0.5"}),n.jsx("rect",{x:"34",y:"70",width:"32",height:"38",rx:"3",fill:J.brassMid,stroke:J.bolt,strokeWidth:"0.7"}),n.jsx("rect",{x:"35",y:"71",width:"30",height:"2",rx:"1",fill:J.brassHi,opacity:"0.7"}),n.jsxs("g",{fill:J.bolt,children:[n.jsx("circle",{cx:"36.5",cy:"72.5",r:"0.9"}),n.jsx("circle",{cx:"63.5",cy:"72.5",r:"0.9"}),n.jsx("circle",{cx:"36.5",cy:"105.5",r:"0.9"}),n.jsx("circle",{cx:"63.5",cy:"105.5",r:"0.9"})]}),n.jsx("circle",{cx:"50",cy:"86",r:"11",fill:J.glassDark,stroke:J.brassDark,strokeWidth:"1.2"}),n.jsx("circle",{cx:"50",cy:"86",r:"10",fill:J.glassMid,opacity:"0.85"}),n.jsx("circle",{cx:"50",cy:"86",r:"9.5",fill:v.glow,opacity:"0.10"}),n.jsxs("g",{className:"mascot-cog",children:[n.jsx("path",{d:"M50 78 L51.6 80 L54 79.4 L54.6 81.8 L56.8 82.4 L56.4 84.8 L58.4 86 L56.4 87.2 L56.8 89.6 L54.6 90.2 L54 92.6 L51.6 92 L50 94 L48.4 92 L46 92.6 L45.4 90.2 L43.2 89.6 L43.6 87.2 L41.6 86 L43.6 84.8 L43.2 82.4 L45.4 81.8 L46 79.4 L48.4 80 Z",fill:J.brassBright,stroke:J.brassDark,strokeWidth:"0.5"}),n.jsx("circle",{cx:"50",cy:"86",r:"2.2",fill:J.brassDark}),n.jsx("circle",{cx:"50",cy:"86",r:"0.8",fill:J.bolt})]}),n.jsxs("g",{className:"mascot-cog-sm",children:[n.jsx("path",{d:"M57 89 L57.8 90 L59 89.7 L59.3 90.9 L60.4 91.2 L60.2 92.4 L61.2 93 L60.2 93.6 L60.4 94.8 L59.3 95.1 L59 96.3 L57.8 96 L57 97 L56.2 96 L55 96.3 L54.7 95.1 L53.6 94.8 L53.8 93.6 L52.8 93 L53.8 92.4 L53.6 91.2 L54.7 90.9 L55 89.7 L56.2 90 Z",fill:J.brassMid,stroke:J.brassDark,strokeWidth:"0.4"}),n.jsx("circle",{cx:"57",cy:"93",r:"1",fill:J.brassDark})]}),n.jsxs("g",{className:"mascot-pendulum",children:[n.jsx("line",{x1:"50",y1:"78",x2:"50",y2:"93",stroke:J.brassBright,strokeWidth:"0.9",strokeLinecap:"round"}),n.jsx("circle",{cx:"50",cy:"94.5",r:"1.8",fill:J.brassDark,stroke:J.brassHi,strokeWidth:"0.4"})]}),n.jsxs("g",{transform:"translate(60, 102)",children:[n.jsx("circle",{r:"3.5",fill:J.brassDark,stroke:J.bolt,strokeWidth:"0.4"}),n.jsx("circle",{r:"2.8",fill:J.brassHi,opacity:"0.7"}),n.jsx("line",{className:"mascot-gauge",x1:"0",y1:"0",x2:"0",y2:"-2.4",stroke:J.bolt,strokeWidth:"0.55",strokeLinecap:"round"}),n.jsx("circle",{r:"0.5",fill:J.bolt})]}),n.jsx("rect",{x:"36",y:"100",width:"14",height:"3",rx:"1",fill:J.glassDark}),n.jsx("rect",{x:"37",y:"100.6",width:"12",height:"1.8",rx:"0.5",fill:v.glow,children:t==="executing"&&!q&&n.jsx("animate",{attributeName:"opacity",values:"0.4;0.95;0.4",dur:"0.6s",repeatCount:"indefinite"})})]}),n.jsx("g",{transform:"translate(20, 96)",children:n.jsxs("g",{className:"mascot-hand-l",children:[n.jsx("circle",{r:"5.8",fill:J.brassMid,stroke:J.bolt,strokeWidth:"0.8"}),n.jsx("circle",{r:"4.2",fill:J.brassBright,opacity:"0.85"}),n.jsx("circle",{r:"1.8",fill:v.glow,opacity:"0.95"}),n.jsx("circle",{r:"0.6",fill:"#fff7d8",opacity:"0.95"})]})}),n.jsx("g",{transform:"translate(80, 96)",children:n.jsxs("g",{className:`${j?"mascot-hand-r waving":"mascot-hand-r"}`,children:[n.jsx("circle",{r:"5.8",fill:J.brassMid,stroke:J.bolt,strokeWidth:"0.8"}),n.jsx("circle",{r:"4.2",fill:J.brassBright,opacity:"0.85"}),n.jsx("circle",{r:"1.8",fill:v.glow,opacity:"0.95"}),n.jsx("circle",{r:"0.6",fill:"#fff7d8",opacity:"0.95"})]})}),n.jsxs("g",{children:[n.jsx("ellipse",{cx:"42",cy:"118",rx:"6.5",ry:"3.4",fill:J.woodDark,stroke:J.bolt,strokeWidth:"0.6"}),n.jsx("ellipse",{cx:"42",cy:"117",rx:"6.5",ry:"1.3",fill:J.brassMid}),n.jsx("circle",{cx:"39",cy:"117",r:"0.7",fill:J.bolt}),n.jsx("circle",{cx:"45",cy:"117",r:"0.7",fill:J.bolt})]}),n.jsxs("g",{children:[n.jsx("ellipse",{cx:"58",cy:"118",rx:"6.5",ry:"3.4",fill:J.woodDark,stroke:J.bolt,strokeWidth:"0.6"}),n.jsx("ellipse",{cx:"58",cy:"117",rx:"6.5",ry:"1.3",fill:J.brassMid}),n.jsx("circle",{cx:"55",cy:"117",r:"0.7",fill:J.bolt}),n.jsx("circle",{cx:"61",cy:"117",r:"0.7",fill:J.bolt})]}),t==="thinking"&&n.jsxs("g",{children:[n.jsx("circle",{cx:"60",cy:"14",r:"1.5",className:"mascot-thinking-particle",fill:v.glow,style:{animationDelay:"0s"}}),n.jsx("circle",{cx:"66",cy:"10",r:"1.1",className:"mascot-thinking-particle",fill:v.glow,style:{animationDelay:"0.4s"}}),n.jsx("circle",{cx:"72",cy:"7",r:"0.8",className:"mascot-thinking-particle",fill:v.glow,style:{animationDelay:"0.8s"}})]}),t==="error"&&n.jsxs("g",{stroke:"#ef4444",strokeWidth:"1.8",strokeLinecap:"round",opacity:"0.9",children:[n.jsx("line",{x1:"43",y1:"40",x2:"57",y2:"48"}),n.jsx("line",{x1:"57",y1:"40",x2:"43",y2:"48"})]})]})})})]})}const cl="titan2:chat-dock:pos",dl="titan2:chat-dock:size",br="titan2:chat-dock:hidden-edge",ul="titan2:chat-dock:hint-shown",Hf=4,dt=116,Zt=dt*1.38,Ms=14,Vf=320,Gf=360,qf=960,Yf=900,Kf=420,Jf=560,Xn=8,Xf=20,Qf=64,Zf="transform 280ms cubic-bezier(0.22, 1, 0.36, 1)",ep="transform 260ms cubic-bezier(0.2, 0.9, 0.25, 1)",tp=400,sp=180,np=1800,rp=1e4,ip=28,op=260,ap=2e3,lp=3500;function cp(){try{const t=localStorage.getItem(dl);if(t){const e=JSON.parse(t);if(typeof(e==null?void 0:e.w)=="number"&&typeof(e==null?void 0:e.h)=="number")return xr(e)}}catch{}return{w:Kf,h:Jf}}function dp(t){try{localStorage.setItem(dl,JSON.stringify(t))}catch{}}function xr(t){return{w:Math.max(Vf,Math.min(t.w,qf)),h:Math.max(Gf,Math.min(t.h,Yf))}}function up(){try{const s=localStorage.getItem(cl);if(s){const r=JSON.parse(s);if(typeof(r==null?void 0:r.x)=="number"&&typeof(r==null?void 0:r.y)=="number")return r}}catch{}const t=typeof window<"u"?window.innerWidth:1280,e=typeof window<"u"?window.innerHeight:800;return{x:t-dt-32,y:e-Zt-32}}function hp(t){try{localStorage.setItem(cl,JSON.stringify(t))}catch{}}function fp(){try{const t=localStorage.getItem(br);if(t==="left"||t==="right"||t==="top"||t==="bottom")return t}catch{}return null}function pp(t){try{t?localStorage.setItem(br,t):localStorage.removeItem(br)}catch{}}let hl=!1;function Bi(){try{return localStorage.getItem(ul)==="1"}catch{return hl}}function Ui(){try{localStorage.setItem(ul,"1")}catch{hl=!0}}function Qn(t){const e=window.innerWidth,s=window.innerHeight;return{x:Math.max(0,Math.min(t.x,e-dt)),y:Math.max(0,Math.min(t.y,s-Zt))}}function Fi(t){const e=window.innerWidth,s=window.innerHeight;return t.x<=Xn?"left":t.x>=e-dt-Xn?"right":t.y>=s-Zt-Xn?"bottom":null}function mp(t,e){if(!t)return"";const s=dt-Xf,r=e?Qf:0;switch(t){case"left":return`translate3d(${-(s-r)}px, 0, 0)`;case"right":return`translate3d(${s-r}px, 0, 0)`;case"top":return`translate3d(0, ${-(s-r)}px, 0)`;case"bottom":return`translate3d(0, ${s-r}px, 0)`;default:return""}}function gp(t){switch(t){case"left":return 90;case"right":return-90;case"top":return 180;case"bottom":return 0;default:return 0}}function yp(t){return t.x>window.innerWidth/2}function bp(t){const e=t.trim().split(/\s+/).filter(Boolean).length,s=np+t.length*ip+e*op;return Math.min(s,rp)}function xp(t,e){const s=window.innerWidth,r=window.innerHeight,i=s-(t.x+dt),o=r-(t.y+Zt),c=i>=e.w+Ms?"right":"left",l=o>=e.h+Ms?"below":"above",d=c==="right"?t.x+dt+Ms:t.x-e.w-Ms,p=l==="below"?t.y:t.y+Zt-e.h;return{left:Math.max(8,Math.min(d,s-e.w-8)),top:Math.max(8,Math.min(p,r-e.h-8)),side:c,vertical:l}}function wp({space:t,somaActive:e,defaultExpanded:s=!1}){const[r,i]=w.useState(!1),o=e??r;w.useEffect(()=>{let K=!1;ye("/api/config").then(Z=>Z.ok?Z.json():null).then(Z=>{var ae;K||i(!!((ae=Z==null?void 0:Z.organism)!=null&&ae.enabled))}).catch(()=>{});const Y=Z=>{const ae=Z.detail;typeof(ae==null?void 0:ae.enabled)=="boolean"&&i(ae.enabled)};return window.addEventListener("titan:soma:changed",Y),()=>{K=!0,window.removeEventListener("titan:soma:changed",Y)}},[]),w.useEffect(()=>{const K=Y=>{const Z=Y.detail;typeof(Z==null?void 0:Z.open)=="boolean"?u(Z.open):u(ae=>!ae)};return window.addEventListener("titan:chat:toggle",K),()=>window.removeEventListener("titan:chat:toggle",K)},[]);const[c,l]=w.useState(()=>Qn(up())),[d,p]=w.useState(()=>cp()),[g,u]=w.useState(s),[f,x]=w.useState(!1),[b,E]=w.useState(!1),[A,v]=w.useState("idle"),[L,m]=w.useState(()=>fp()),[k,_]=w.useState(!1),[T,S]=w.useState(!1),[N,D]=w.useState(null),j=w.useRef({}),R=w.useRef(null),O=w.useRef(null),U=w.useRef(!1);w.useEffect(()=>{hp(c)},[c]),w.useEffect(()=>{dp(d)},[d]),w.useEffect(()=>{pp(L)},[L]),w.useEffect(()=>{const K=window.matchMedia("(prefers-reduced-motion: reduce)");S(K.matches);const Y=Z=>S(Z.matches);return K.addEventListener("change",Y),()=>K.removeEventListener("change",Y)},[]),w.useEffect(()=>{let K,Y;const Z=()=>{clearTimeout(Y),Y=window.setTimeout(()=>{l(B=>{const H=Qn(B),se=Fi(H);return m(se),H}),p(B=>xr(B))},50)},ae=()=>{clearTimeout(K),K=window.setTimeout(Z,100)};window.addEventListener("resize",ae),document.addEventListener("visibilitychange",Z),window.addEventListener("focus",Z),window.addEventListener("pageshow",Z);const M=window.setInterval(Z,2e3);return()=>{window.removeEventListener("resize",ae),document.removeEventListener("visibilitychange",Z),window.removeEventListener("focus",Z),window.removeEventListener("pageshow",Z),clearTimeout(K),clearTimeout(Y),clearInterval(M)}},[]),w.useEffect(()=>()=>{clearTimeout(j.current.enter),clearTimeout(j.current.exit),clearTimeout(j.current.hide)},[]),w.useEffect(()=>{if(Bi())return;let K,Y;return K=window.setTimeout(()=>{G("Drag me, tap me."),Ui(),Y=window.setTimeout(()=>{q()},lp),j.current.hide=Y},ap),()=>{clearTimeout(K),clearTimeout(Y)}},[]);const z=w.useCallback(()=>{clearTimeout(j.current.enter),clearTimeout(j.current.exit),clearTimeout(j.current.hide),j.current={}},[]),G=w.useCallback(K=>{z(),D({text:K,phase:"entering"}),j.current.enter=window.setTimeout(()=>{D(Z=>Z&&Z.text===K?{...Z,phase:"visible"}:Z);const Y=bp(K);j.current.hide=window.setTimeout(()=>{q()},Y)},tp)},[z]),q=w.useCallback(()=>{z(),D(K=>K?(j.current.exit=window.setTimeout(()=>{D(null)},sp),{...K,phase:"leaving"}):null)},[z]),P=A==="thinking"?"thinking…":A==="executing"?"working on it":null;w.useEffect(()=>{P?G(P):D(K=>K?((K.text==="thinking…"||K.text==="working on it")&&q(),K):null)},[P]);const V=w.useCallback(K=>{var Y,Z;K.button===0&&((Z=(Y=K.target).setPointerCapture)==null||Z.call(Y,K.pointerId),R.current={pointer:{x:K.clientX,y:K.clientY},pos:c,moved:!1},x(!0),Bi()||Ui())},[c]),$=w.useCallback(K=>{const Y=R.current;if(!Y)return;const Z=K.clientX-Y.pointer.x,ae=K.clientY-Y.pointer.y;!Y.moved&&Math.hypot(Z,ae)<Hf||(Y.moved=!0,L&&m(null),l(Qn({x:Y.pos.x+Z,y:Y.pos.y+ae})))},[L]),te=w.useCallback(K=>{var Z,ae;const Y=R.current;if((ae=(Z=K.target).releasePointerCapture)==null||ae.call(Z,K.pointerId),R.current=null,x(!1),Y&&Y.moved){const M=Fi(c);m(M||null)}else Y&&!Y.moved&&(L&&m(null),u(M=>!M))},[c,L]),re=w.useCallback(()=>{L&&_(!0)},[L]),Q=w.useCallback(()=>{_(!1)},[]),ee=w.useCallback(K=>{if(K.ctrlKey||f)return;let Y=K.target;for(;Y&&Y!==document.body;){const Z=window.getComputedStyle(Y),ae=Y.scrollHeight>Y.clientHeight,M=Z.overflowY;if(ae&&(M==="auto"||M==="scroll")){Y.scrollTop+=K.deltaY,K.preventDefault();return}Y=Y.parentElement}window.scrollBy({top:K.deltaY,left:K.deltaX,behavior:"auto"}),K.preventDefault()},[f]),X=xp(c,d),ve=(N==null?void 0:N.text)??null,Be=(N==null?void 0:N.phase)??null,ce=w.useCallback(K=>{var Y,Z;K.button===0&&(K.stopPropagation(),(Z=(Y=K.target).setPointerCapture)==null||Z.call(Y,K.pointerId),O.current={pointer:{x:K.clientX,y:K.clientY},size:d,anchorSide:X.side,anchorVertical:X.vertical},E(!0))},[d,X.side,X.vertical]),ge=w.useCallback(K=>{const Y=O.current;if(!Y)return;const Z=K.clientX-Y.pointer.x,ae=K.clientY-Y.pointer.y,M=Y.anchorSide==="right"?Z:-Z,B=Y.anchorVertical==="below"?ae:-ae;p(xr({w:Y.size.w+M,h:Y.size.h+B}))},[]),be=w.useCallback(K=>{var Y,Z;(Z=(Y=K.target).releasePointerCapture)==null||Z.call(Y,K.pointerId),O.current=null,E(!1)},[]),we=mp(L,k);return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{position:"fixed",left:c.x,top:c.y,width:dt,height:Zt,zIndex:2147482e3,cursor:f?"grabbing":L?"pointer":"grab",touchAction:"none",userSelect:"none",animation:T?void 0:"titan-dock-in 220ms ease-out both",transform:we,transition:f?"none":`${Zf}, ${ep}`},onPointerDown:V,onPointerMove:$,onPointerUp:te,onPointerCancel:te,onPointerEnter:re,onPointerLeave:Q,onWheel:ee,title:g?"Click to minimize TITAN chat — drag to move":"Click to open TITAN chat — drag to move",children:n.jsx(zf,{state:A,size:dt,quip:ve,bubblePhase:Be,somaActive:o,followCursor:!f,edgeRotate:gp(L),faceFlip:yp(c),edgeHidden:!!L})}),g&&n.jsxs("div",{style:{position:"fixed",left:X.left,top:X.top,width:d.w,height:d.h,zIndex:2147481999,pointerEvents:"auto",borderRadius:14,border:"1px solid rgba(255,255,255,0.08)",background:"rgba(11,11,14,0.72)",backdropFilter:"blur(18px) saturate(1.08)",WebkitBackdropFilter:"blur(18px) saturate(1.08)",boxShadow:"0 18px 44px rgba(0,0,0,0.24)",animation:b||U.current||T?void 0:"titan-dock-panel-in 180ms cubic-bezier(0.2, 0.9, 0.25, 1) both",transformOrigin:`${X.side==="right"?"left":"right"} ${X.vertical==="below"?"top":"bottom"}`},children:[n.jsx(ll,{space:t,onClose:()=>u(!1),onMascotState:v}),n.jsx("div",{onPointerDown:ce,onPointerMove:ge,onPointerUp:be,onPointerCancel:be,title:"Drag to resize",style:{position:"absolute",[X.vertical==="below"?"bottom":"top"]:0,[X.side==="right"?"right":"left"]:0,width:18,height:18,cursor:X.side==="right"?"nwse-resize":"nesw-resize",touchAction:"none",background:"transparent",zIndex:2},children:n.jsx("svg",{width:"18",height:"18",viewBox:"0 0 18 18",style:{display:"block",opacity:b?1:.55},children:X.side==="right"?n.jsxs("g",{stroke:"#6366f1",strokeWidth:"1.6",strokeLinecap:"round",fill:"none",children:[n.jsx("line",{x1:"5",y1:"14",x2:"14",y2:"14"}),n.jsx("line",{x1:"9",y1:"10",x2:"14",y2:"10"}),n.jsx("line",{x1:"14",y1:"14",x2:"14",y2:"5"})]}):n.jsxs("g",{stroke:"#6366f1",strokeWidth:"1.6",strokeLinecap:"round",fill:"none",children:[n.jsx("line",{x1:"4",y1:"14",x2:"13",y2:"14"}),n.jsx("line",{x1:"4",y1:"10",x2:"9",y2:"10"}),n.jsx("line",{x1:"4",y1:"14",x2:"4",y2:"5"})]})})})]}),n.jsx("style",{children:`
|
|
1002
|
+
@keyframes titan-dock-in {
|
|
1003
|
+
from { opacity: 0; transform: translate3d(0, 4px, 0); }
|
|
1004
|
+
to { opacity: 1; transform: translate3d(0, 0, 0); }
|
|
1005
|
+
}
|
|
1006
|
+
@keyframes titan-dock-panel-in {
|
|
1007
|
+
from { opacity: 0; transform: translate3d(0, 12px, 0) scale(0.968); }
|
|
1008
|
+
to { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
|
|
1009
|
+
}
|
|
1010
|
+
@media (prefers-reduced-motion: reduce) {
|
|
1011
|
+
.titan-dock-root, .titan-dock-panel {
|
|
1012
|
+
animation: none !important;
|
|
1013
|
+
transition: none !important;
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
`})]})}const vp=3e4,_p=3e4;function kp(){const[t,e]=w.useState(null),s=w.useRef(null),r=w.useRef(new Set),i=w.useRef(null);if(w.useEffect(()=>{let c=!1;const l=async()=>{var p;try{const g=await ye("/api/soma/advisories?limit=5");if(!g.ok)return;const u=await g.json();if(c||!((p=u.advisories)!=null&&p.length))return;for(const f of u.advisories)if(!r.current.has(f.at)&&!(s.current&&f.at<=s.current)){if(s.current===null){s.current=u.advisories[0].at;return}s.current=f.at,e(f),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>e(null),_p);return}}catch{}};l();const d=setInterval(l,vp);return()=>{c=!0,clearInterval(d),i.current&&clearTimeout(i.current)}},[]),!t)return null;const o=()=>{r.current.add(t.at),e(null),i.current&&clearTimeout(i.current)};return n.jsx("div",{className:"titan-toast-surface",style:{position:"fixed",bottom:100,right:24,maxWidth:340,padding:"12px 14px",borderRadius:10,borderLeft:"3px solid var(--theme-accent)",fontSize:12,zIndex:60},children:n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:8},children:[n.jsxs("div",{style:{flex:1},children:[n.jsx("div",{style:{fontSize:10,textTransform:"uppercase",letterSpacing:.8,color:"var(--theme-accent)",marginBottom:4,fontFamily:"var(--theme-font-mono)"},children:"TITAN noticed"}),n.jsx("div",{style:{lineHeight:1.45,color:"var(--theme-ink)"},children:t.rationale}),n.jsxs("div",{style:{fontSize:10,color:"var(--theme-ink-soft)",marginTop:6,textTransform:"uppercase",letterSpacing:.5,fontFamily:"var(--theme-font-mono)"},children:["suggestion: ",t.action]})]}),n.jsx("button",{onClick:o,"aria-label":"Dismiss",className:"titan-close-btn",style:{fontSize:16,lineHeight:1,marginTop:-2},children:"×"})]})})}function Sp(){const t=typeof localStorage<"u"?localStorage.getItem("titan-token"):null;return t?{Authorization:`Bearer ${t}`}:{}}async function os(t,e){const s=await fetch(t,{...e,headers:{"Content-Type":"application/json",...Sp(),...(e==null?void 0:e.headers)||{}}});if(!s.ok)throw new Error(`${s.status} ${s.statusText}`);return s.json()}function jp(){const t=Ki(),e=wl(),{logout:s}=vl(),[r,i]=w.useState([]),[o,c]=w.useState(null),[l,d]=w.useState([]),[p,g]=w.useState(!1),[u,f]=w.useState(!1),[x,b]=w.useState(null),[E,A]=w.useState(()=>{try{return localStorage.getItem("titan-sidebar-collapsed")==="1"}catch{return!1}}),v=w.useCallback(()=>{A(S=>{const N=!S;try{localStorage.setItem("titan-sidebar-collapsed",N?"1":"0")}catch{}return N})},[]),L=w.useCallback(async()=>{try{const S=await os("/api/spaces");i(S.spaces),c(S.activeSpaceId),b(null)}catch(S){b(S.message)}},[]);w.useEffect(()=>{L(),os("/api/spaces/presets").then(N=>d(N.presets)).catch(()=>{});const S=()=>L();return window.addEventListener("titan:spaces:refresh",S),()=>window.removeEventListener("titan:spaces:refresh",S)},[L]);const m=w.useCallback(async S=>{try{await os(`/api/spaces/${S}/activate`,{method:"POST"}),c(S),t(`/space/${S}`)}catch(N){b(N.message)}},[t]),k=w.useCallback(async S=>{f(!0);try{const N=S.preset?l.find(j=>j.id===S.preset):void 0,D=await os("/api/spaces",{method:"POST",body:JSON.stringify({name:S.name||(N==null?void 0:N.name)||"New Space",icon:N==null?void 0:N.icon,color:N==null?void 0:N.color,makeActive:!0})});await L(),t(`/space/${D.space.id}`),g(!1)}catch(N){b(N.message)}finally{f(!1)}},[t,l,L]),_=w.useCallback(async S=>{if(window.confirm("Archive this Space? Widgets will be preserved and you can restore it later."))try{await os(`/api/spaces/${S}`,{method:"DELETE"}),await L()}catch(N){b(N.message)}},[L]);if(!e.pathname.startsWith("/space")&&!e.pathname.startsWith("/mission")&&e.pathname!=="/")return null;const T=e.pathname.startsWith("/mission");return E?n.jsx("aside",{className:"w-3 bg-[#0a0e1a] border-r border-[#1f2937] relative flex-shrink-0",title:"Spaces sidebar — collapsed",children:n.jsx("button",{type:"button",onClick:v,className:"absolute top-3 left-full -translate-x-1/2 z-50 w-6 h-12 rounded-r-md bg-[#1f2937] border border-[#27272a] border-l-0 text-[#a1a1aa] hover:text-white hover:bg-[#27272a] flex items-center justify-center text-sm shadow-lg",title:"Show the spaces sidebar","aria-label":"Show sidebar",children:"›"})}):n.jsxs("aside",{className:"w-60 flex flex-col relative flex-shrink-0",style:{background:"var(--theme-menu-bg-solid, #0a0e1a)",borderRight:"1px solid var(--theme-menu-border, #1f2937)",color:"var(--theme-ink, #d4d4d8)",fontFamily:"var(--theme-font-display, ui-sans-serif, system-ui)"},children:[n.jsxs("div",{className:"px-4 pt-4 pb-3 flex items-center justify-between",style:{borderBottom:"1px solid var(--theme-menu-border, #1f2937)"},children:[n.jsxs("button",{type:"button",onClick:()=>t("/space/home"),className:"flex items-center gap-2 group",title:"TITAN home",children:[n.jsx("span",{className:"w-7 h-7 rounded-md flex items-center justify-center text-[14px] font-bold leading-none",style:{background:"var(--theme-metal, #c4a35a)",color:"var(--theme-bolt, #2a1808)",boxShadow:"0 1px 2px var(--theme-shadow, rgba(0,0,0,0.3))",fontFamily:"var(--theme-font-display, serif)"},children:"T"}),n.jsx("span",{className:"text-[15px] tracking-[0.18em] font-semibold leading-none",style:{color:"var(--theme-ink, #e8e8ff)"},children:"TITAN"})]}),n.jsx("button",{type:"button",onClick:v,className:"w-6 h-6 rounded-md flex items-center justify-center text-base transition-colors",style:{color:"var(--theme-ink-soft, #a1a1aa)"},title:"Hide sidebar","aria-label":"Hide sidebar",children:"‹"})]}),n.jsxs("nav",{className:"flex-1 overflow-y-auto py-3 px-2",children:[n.jsxs("div",{className:"mb-5",children:[n.jsx($i,{children:"Missions"}),n.jsx(zi,{onClick:()=>t("/mission"),active:T&&e.pathname==="/mission",icon:"✶",label:"New Mission",title:"Start a new mission or pick a template"}),n.jsx(zi,{onClick:()=>t("/mission/library"),active:e.pathname==="/mission/library",icon:"❑",label:"Library",title:"Every mission you've run"})]}),n.jsxs("div",{className:"mb-2 flex items-center justify-between px-2",children:[n.jsx($i,{inline:!0,children:"Workspaces"}),n.jsx("button",{type:"button",onClick:()=>g(!0),className:"w-5 h-5 rounded flex items-center justify-center text-sm leading-none transition-colors",style:{color:"var(--theme-ink-soft, #a1a1aa)"},onMouseEnter:S=>{S.currentTarget.style.background="var(--theme-menu-hover, rgba(244,215,145,0.10))",S.currentTarget.style.color="var(--theme-ink, #fff)"},onMouseLeave:S=>{S.currentTarget.style.background="transparent",S.currentTarget.style.color="var(--theme-ink-soft, #a1a1aa)"},title:"Create a new Workspace","aria-label":"Create a new Workspace",children:"+"})]}),x&&n.jsx("div",{className:"mx-1 my-1 px-2 py-2 text-[11px] rounded",style:{color:"var(--theme-accent, #ef4444)",background:"rgba(239,68,68,0.08)"},children:x}),r.length===0&&!x&&n.jsxs("div",{className:"px-2 py-3 text-[11px] leading-relaxed italic",style:{color:"var(--theme-ink-soft, #71717a)"},children:["No Workspaces yet. Tap + above, or ask TITAN",n.jsx("br",{}),'"make me a workspace for…"']}),r.map(S=>{const N=S.id===o;return n.jsxs("button",{type:"button",onClick:()=>m(S.id),onContextMenu:D=>{D.preventDefault(),_(S.id)},className:"w-full text-left px-2 py-1.5 rounded text-[13px] flex items-center gap-2 transition-colors",style:{background:N?"var(--theme-menu-active-bg, #1f2937)":"transparent",color:N?"var(--theme-menu-active-fg, #fff)":"var(--theme-ink, #d4d4d8)"},onMouseEnter:D=>{N||(D.currentTarget.style.background="var(--theme-menu-hover, rgba(244,215,145,0.10))")},onMouseLeave:D=>{N||(D.currentTarget.style.background="transparent")},title:`${S.name} · right-click to archive`,children:[S.icon&&n.jsx("span",{className:"text-base leading-none",children:S.icon}),n.jsx("span",{className:"flex-1 truncate",children:S.name}),S.widgets.length>0&&n.jsx("span",{className:"text-[10px] tabular-nums px-1.5 rounded-full",style:{color:"var(--theme-ink-soft, #71717a)",background:"var(--theme-menu-hover, rgba(244,215,145,0.10))"},children:S.widgets.length})]},S.id)})]}),n.jsxs("div",{className:"px-2 py-2 flex flex-col gap-0.5",style:{borderTop:"1px solid var(--theme-menu-border, #1f2937)"},children:[n.jsxs("a",{href:"/command-post",className:"px-2 py-1.5 rounded text-[12px] flex items-center gap-2 transition-colors no-underline",style:{color:"var(--theme-ink-soft, #a1a1aa)"},onMouseEnter:S=>{S.currentTarget.style.background="var(--theme-menu-hover, rgba(244,215,145,0.10))",S.currentTarget.style.color="var(--theme-ink, #fff)"},onMouseLeave:S=>{S.currentTarget.style.background="transparent",S.currentTarget.style.color="var(--theme-ink-soft, #a1a1aa)"},children:[n.jsx("span",{"aria-hidden":!0,children:"⚙"}),n.jsx("span",{children:"Admin"})]}),n.jsxs("button",{type:"button",onClick:()=>{s(),window.location.assign("/")},className:"w-full text-left px-2 py-1.5 rounded text-[12px] flex items-center gap-2 transition-colors",style:{color:"var(--theme-ink-soft, #a1a1aa)"},onMouseEnter:S=>{S.currentTarget.style.background="var(--theme-menu-hover, rgba(244,215,145,0.10))",S.currentTarget.style.color="var(--theme-accent, #ef4444)"},onMouseLeave:S=>{S.currentTarget.style.background="transparent",S.currentTarget.style.color="var(--theme-ink-soft, #a1a1aa)"},title:"Sign out — mints a fresh token next login",children:[n.jsx("span",{"aria-hidden":!0,children:"⇥"}),n.jsx("span",{children:"Sign out"})]})]}),p&&n.jsx(Ep,{presets:l,creating:u,onCreate:k,onClose:()=>g(!1)})]})}function Ep(t){const{presets:e,creating:s,onCreate:r,onClose:i}=t,[o,c]=w.useState(""),[l,d]=w.useState(void 0);return n.jsx("div",{className:"fixed inset-0 bg-black/60 z-50 flex items-center justify-center p-4",onClick:i,children:n.jsxs("div",{className:"bg-[#0a0e1a] border border-[#1f2937] rounded-lg p-5 w-full max-w-md",onClick:p=>p.stopPropagation(),children:[n.jsx("div",{className:"text-sm font-medium text-white mb-4",children:"New Space"}),n.jsx("label",{className:"block text-[11px] text-[#a1a1aa] mb-1",children:"Starter preset (optional)"}),n.jsx("div",{className:"grid grid-cols-2 gap-2 mb-4",children:e.map(p=>n.jsxs("button",{type:"button",onClick:()=>{d(p.id),o||c(p.name)},className:`text-left px-3 py-2 rounded border ${l===p.id?"border-[#3b82f6] bg-[#0f172a]":"border-[#1f2937] hover:border-[#374151]"}`,title:p.tagline,children:[n.jsxs("div",{className:"text-sm flex items-center gap-2 text-white",children:[n.jsx("span",{children:p.icon}),n.jsx("span",{children:p.name})]}),n.jsx("div",{className:"text-[10px] text-[#71717a] mt-0.5 line-clamp-1",children:p.tagline})]},p.id))}),n.jsx("label",{className:"block text-[11px] text-[#a1a1aa] mb-1",children:"Name"}),n.jsx("input",{type:"text",value:o,onChange:p=>c(p.target.value),placeholder:"My Workspace",className:"w-full bg-[#0d1117] border border-[#1f2937] rounded px-3 py-2 text-sm text-white mb-4",autoFocus:!0}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{type:"button",onClick:i,className:"px-3 py-1.5 text-sm text-[#a1a1aa] hover:text-white",children:"Cancel"}),n.jsx("button",{type:"button",onClick:()=>r({name:o.trim(),preset:l}),disabled:s||!o.trim()&&!l,className:"px-3 py-1.5 bg-[#3b82f6] hover:bg-[#2563eb] disabled:opacity-50 text-white text-sm rounded",children:s?"Creating…":"Create"})]})]})})}function $i({children:t,inline:e=!1}){return n.jsx("div",{className:`${e?"":"px-2 mb-1.5"} text-[10px] uppercase tracking-[0.18em] font-semibold`,style:{color:"var(--theme-metal, #c4a35a)"},children:t})}function zi({active:t,icon:e,label:s,title:r,onClick:i}){return n.jsxs("button",{type:"button",onClick:i,className:"w-full text-left px-2 py-1.5 rounded text-[13px] flex items-center gap-2 transition-colors",style:{background:t?"var(--theme-menu-active-bg, #1f2937)":"transparent",color:t?"var(--theme-menu-active-fg, #fff)":"var(--theme-ink, #d4d4d8)"},onMouseEnter:o=>{t||(o.currentTarget.style.background="var(--theme-menu-hover, rgba(244,215,145,0.10))")},onMouseLeave:o=>{t||(o.currentTarget.style.background="transparent")},title:r,children:[n.jsx("span",{className:"w-5 text-center leading-none",style:{color:t?"var(--theme-menu-active-fg, #fff)":"var(--theme-metal, #c4a35a)"},"aria-hidden":!0,children:e}),n.jsx("span",{className:"flex-1 truncate",children:s})]})}const Zn=4e3,Np=[{label:"Focused research partner",body:"You are in the research space. Prefer brief answers with citations. When the user asks a question, default to summarising authoritative sources over generating widgets. Suggest a follow-up question at the end of each response."},{label:"Hands-on builder",body:"You are in the build space. Prefer writing + iterating on widgets over explanation. Keep prose to under 2 sentences per reply. Generate widgets with `canvas.createWidget` whenever the user describes a tool they want."},{label:"Ops / monitoring",body:"You are in the ops space. Prioritise live data — API calls, log tails, health checks. Use titan.api.call and titan.fetch liberally. Surface numbers in tables or small stat widgets."},{label:"Casual / playful",body:"You are in the play space. Relaxed tone, emojis welcome, riff on user ideas, generate fun widgets. Explain trade-offs only if asked."}];function Cp({space:t,open:e,onClose:s,onSaved:r}){const[i,o]=w.useState(t.agentInstructions??""),[c,l]=w.useState(!1),[d,p]=w.useState(null),g=w.useRef(null);w.useEffect(()=>{if(e){o(t.agentInstructions??""),p(null);const f=setTimeout(()=>{var x;return(x=g.current)==null?void 0:x.focus()},50);return()=>clearTimeout(f)}},[e,t.id,t.agentInstructions]),w.useEffect(()=>{if(!e)return;const f=x=>{x.key==="Escape"&&s(),x.key==="Enter"&&(x.metaKey||x.ctrlKey)&&u()};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[e]);const u=w.useCallback(async()=>{if(i.length>Zn){p(`Instructions must be ${Zn} characters or fewer.`);return}l(!0),p(null);try{const f=i.trim(),x={...t,agentInstructions:f||void 0,updatedAt:new Date().toISOString()};ke.save(x),r==null||r(f),s()}catch(f){p(f.message)}finally{l(!1)}},[i,t,r,s]);return e?n.jsx("div",{className:"fixed inset-0 z-[2147483100] flex items-center justify-center p-4",style:{background:"rgba(0, 0, 0, 0.6)",backdropFilter:"blur(4px)"},onClick:s,children:n.jsxs("div",{className:"w-full max-w-2xl rounded-2xl border border-[#27272a] bg-[#0c0c10] shadow-2xl flex flex-col max-h-[85vh]",onClick:f=>f.stopPropagation(),children:[n.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-[#27272a]",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(hs,{className:"w-4 h-4 text-[#6366f1]"}),n.jsxs("h3",{className:"font-semibold text-white text-sm",children:["Agent instructions — ",n.jsx("span",{style:{color:t.color||"#6366f1"},children:t.name})]})]}),n.jsx("button",{onClick:s,className:"p-1 rounded hover:bg-[#27272a] text-[#71717a] hover:text-white transition-colors",title:"Close (Esc)",children:n.jsx(ks,{className:"w-4 h-4"})})]}),n.jsxs("div",{className:"p-5 flex-1 overflow-auto space-y-3",children:[n.jsx("p",{className:"text-[11px] text-[#a1a1aa] leading-relaxed",children:"These instructions are injected into the chat’s system prompt whenever this space is active. Use them to give the agent a persona, a rule set, or a focus area — the chat will behave differently here vs. other spaces."}),n.jsx("textarea",{ref:g,value:i,onChange:f=>o(f.target.value),placeholder:"e.g. You're in the research space — prefer concise, sourced answers over widget generation.",spellCheck:!1,className:"w-full h-48 p-3 rounded-lg border border-[#27272a] bg-[#09090c] text-[13px] text-[#e4e4e7] leading-relaxed font-mono resize-y focus:outline-none focus:border-[#6366f1]/60"}),n.jsxs("div",{className:"flex items-center justify-between text-[10px] text-[#71717a]",children:[n.jsxs("span",{children:[i.length.toLocaleString()," / ",Zn.toLocaleString()," characters"]}),n.jsx("span",{children:"⌘/Ctrl + Enter to save"})]}),n.jsxs("div",{children:[n.jsx("div",{className:"text-[10px] uppercase tracking-wider text-[#71717a] mb-2",children:"Quick presets"}),n.jsx("div",{className:"grid grid-cols-2 gap-2",children:Np.map(f=>n.jsxs("button",{onClick:()=>o(f.body),className:"text-left p-3 rounded-lg border border-[#27272a] bg-[#18181b]/60 hover:border-[#6366f1]/50 hover:bg-[#18181b] transition-colors",children:[n.jsx("div",{className:"text-[11px] font-medium text-white mb-1",children:f.label}),n.jsx("div",{className:"text-[10px] text-[#a1a1aa] line-clamp-2 leading-relaxed",children:f.body})]},f.label))})]}),d&&n.jsx("div",{className:"text-[11px] text-[#ef4444] bg-[#ef4444]/10 border border-[#ef4444]/30 rounded p-2",children:d})]}),n.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-3 border-t border-[#27272a]",children:[n.jsx("button",{onClick:s,className:"px-3 py-1.5 rounded-lg text-[12px] text-[#a1a1aa] hover:text-white hover:bg-[#18181b] transition-colors",children:"Cancel"}),n.jsxs("button",{onClick:()=>{u()},disabled:c,className:"inline-flex items-center gap-2 px-4 py-1.5 rounded-lg bg-[#6366f1] hover:bg-[#4f46e5] disabled:opacity-60 text-white text-[12px] font-medium transition-colors",children:[n.jsx(pn,{className:"w-3.5 h-3.5"}),c?"Saving…":"Save"]})]})]})}):null}const Tp=12,Rp=["react","vanilla","html"];function Ap({widget:t,spaceId:e,open:s,onClose:r,onSaved:i}){const[o,c]=w.useState(t.source),[l,d]=w.useState(t.format),[p,g]=w.useState(t.name),[u,f]=w.useState(!1),[x,b]=w.useState(null),[E,A]=w.useState(!1),v=w.useRef(null);w.useEffect(()=>{if(s){c(t.source),d(t.format),g(t.name),b(null),A(!1);const T=setTimeout(()=>{var S;return(S=v.current)==null?void 0:S.focus()},50);return()=>clearTimeout(T)}},[s,t.id,t.source,t.format,t.name]),w.useEffect(()=>{if(!s)return;const T=S=>{S.key==="Escape"&&r(),S.key==="Enter"&&(S.metaKey||S.ctrlKey)&&L()};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[s]);const L=w.useCallback(async()=>{f(!0),b(null);try{const T=o!==t.source||l!==t.format,S=Array.isArray(t.versions)?t.versions:[],N=T?[...S,{source:t.source,format:t.format,savedAt:t.updatedAt}].slice(-Tp):S,D={name:p.trim()||t.name,source:o,format:l,versions:N};ke.updateWidget(e,t.id,D),i==null||i({...t,...D,updatedAt:Date.now()}),r()}catch(T){b(T.message)}finally{f(!1)}},[o,l,p,t,e,i,r]),m=w.useCallback(T=>{c(T.source),d(T.format),A(!1)},[]);if(!s)return null;const k=Array.isArray(t.versions)?t.versions:[],_=[...k].reverse();return n.jsx("div",{className:"fixed inset-0 z-[2147483200] flex items-center justify-center p-4",style:{background:"rgba(0, 0, 0, 0.66)",backdropFilter:"blur(4px)"},onClick:r,children:n.jsxs("div",{className:"w-full max-w-4xl rounded-2xl border border-[#27272a] bg-[#0c0c10] shadow-2xl flex flex-col",style:{height:"min(720px, 85vh)"},onClick:T=>T.stopPropagation(),children:[n.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-[#27272a]",children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[n.jsx(Al,{className:"w-4 h-4 text-[#6366f1] shrink-0"}),n.jsx("input",{value:p,onChange:T=>g(T.target.value),className:"bg-transparent text-white text-sm font-semibold outline-none border-b border-transparent focus:border-[#6366f1]/60 min-w-0 flex-1"}),n.jsx("span",{className:"text-[10px] font-mono text-[#52525b] shrink-0",children:t.id.slice(0,14)})]}),n.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[n.jsx("button",{onClick:()=>A(T=>!T),disabled:k.length===0,className:`p-1.5 rounded text-[#a1a1aa] hover:bg-[#18181b] hover:text-white disabled:opacity-40 disabled:cursor-not-allowed transition-colors ${E?"bg-[#18181b] text-white":""}`,title:k.length===0?"No history yet":`${k.length} prior version${k.length===1?"":"s"}`,children:n.jsx(Kl,{className:"w-4 h-4"})}),n.jsx("button",{onClick:r,className:"p-1.5 rounded text-[#71717a] hover:bg-[#18181b] hover:text-white transition-colors",title:"Close (Esc)",children:n.jsx(ks,{className:"w-4 h-4"})})]})]}),n.jsxs("div",{className:"flex items-center gap-3 px-5 py-2 border-b border-[#27272a] text-[11px]",children:[n.jsxs("label",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-[#71717a]",children:"format"}),n.jsx("select",{value:l,onChange:T=>d(T.target.value),className:"bg-[#18181b] border border-[#27272a] rounded px-2 py-0.5 text-[#e4e4e7] focus:outline-none focus:border-[#6366f1]/60",children:Rp.map(T=>n.jsx("option",{value:T,children:T},T))})]}),n.jsx("span",{className:"text-[#52525b]",children:"·"}),n.jsxs("span",{className:"text-[#71717a]",children:["updated ",n.jsx("span",{className:"text-[#a1a1aa]",children:new Date(t.updatedAt).toLocaleString()})]}),n.jsx("span",{className:"text-[#52525b]",children:"·"}),n.jsxs("span",{className:"text-[#71717a]",children:[t.w," × ",t.h," grid cells"]}),n.jsx("div",{className:"ml-auto text-[10px] text-[#52525b]",children:"⌘/Ctrl + Enter to save"})]}),n.jsxs("div",{className:"flex-1 flex min-h-0",children:[n.jsx("textarea",{ref:v,value:o,onChange:T=>c(T.target.value),spellCheck:!1,className:"flex-1 p-4 bg-[#09090c] text-[12.5px] text-[#e4e4e7] leading-relaxed font-mono resize-none focus:outline-none border-r border-[#27272a]",placeholder:Lp[l]}),E&&n.jsxs("div",{className:"w-72 flex flex-col border-l border-[#27272a] bg-[#0a0a0e]",children:[n.jsxs("div",{className:"px-3 py-2 border-b border-[#27272a] text-[10px] uppercase tracking-wider text-[#71717a]",children:["History (",k.length,")"]}),n.jsxs("div",{className:"flex-1 overflow-auto",children:[_.length===0&&n.jsx("div",{className:"p-3 text-[11px] text-[#52525b]",children:"No prior versions yet — save to start tracking."}),_.map((T,S)=>n.jsxs("div",{className:"px-3 py-2 border-b border-[#18181b] hover:bg-[#18181b]/40 transition-colors",children:[n.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1",children:[n.jsx("div",{className:"text-[10px] font-mono text-[#a1a1aa]",children:new Date(T.savedAt).toLocaleString()}),n.jsxs("button",{onClick:()=>m(T),className:"inline-flex items-center gap-1 text-[10px] text-[#6366f1] hover:text-[#a5b4fc] transition-colors",title:"Load this version into the editor",children:[n.jsx(no,{className:"w-3 h-3"}),"revert"]})]}),n.jsxs("div",{className:"text-[10px] text-[#71717a] font-mono",children:["format: ",T.format]}),n.jsxs("div",{className:"text-[10px] text-[#52525b] truncate mt-1",title:T.source.slice(0,280),children:[T.source.slice(0,80),T.source.length>80?"…":""]}),S===0&&n.jsx("div",{className:"text-[9px] text-[#6366f1] mt-1",children:"most recent before current"})]},T.savedAt))]})]})]}),n.jsxs("div",{className:"flex items-center justify-between gap-2 px-5 py-3 border-t border-[#27272a]",children:[n.jsx("div",{className:"text-[10px] text-[#71717a]",children:x?n.jsxs("span",{className:"text-[#ef4444]",children:["Error: ",x]}):o!==t.source||l!==t.format||p!==t.name?"Unsaved changes":"Up to date"}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("button",{onClick:r,className:"px-3 py-1.5 rounded-lg text-[12px] text-[#a1a1aa] hover:text-white hover:bg-[#18181b] transition-colors",children:"Cancel"}),n.jsxs("button",{onClick:()=>{L()},disabled:u,className:"inline-flex items-center gap-2 px-4 py-1.5 rounded-lg bg-[#6366f1] hover:bg-[#4f46e5] disabled:opacity-60 text-white text-[12px] font-medium transition-colors",children:[n.jsx(pn,{className:"w-3.5 h-3.5"}),u?"Saving…":"Save widget"]})]})]})]})})}const Lp={react:`// Return a React component named "Widget". titan.* APIs are
|
|
1017
|
+
// available for fetch/api/state. Example:
|
|
1018
|
+
function Widget({ titan }) {
|
|
1019
|
+
const [n, setN] = React.useState(0);
|
|
1020
|
+
return <button onClick={() => setN(n + 1)}>Clicked {n} times</button>;
|
|
1021
|
+
}`,vanilla:`// Export a function (container, titan) => cleanup | void.
|
|
1022
|
+
// Called once to mount; return a cleanup function if needed.
|
|
1023
|
+
(container, titan) => {
|
|
1024
|
+
container.innerHTML = '<button>Hello</button>';
|
|
1025
|
+
const btn = container.querySelector('button');
|
|
1026
|
+
btn.addEventListener('click', () => btn.textContent = 'Clicked!');
|
|
1027
|
+
}`,html:`<!-- Raw HTML. No scripts run. -->
|
|
1028
|
+
<div style="padding:16px;color:#e4e4e7">Hello, widget!</div>`,iframe:"",system:""};function Ip(t){return String(t||"").startsWith("system:")?"system":"react"}const Dp={productivity:"#a78bfa",finance:"#34d399","health-fitness":"#f472b6","music-dj":"#c084fc",creative:"#fb923c",travel:"#60a5fa",gaming:"#f87171",social:"#38bdf8",cooking:"#fbbf24",vehicle:"#94a3b8",homelab:"#a3e635","ml-ai":"#818cf8",research:"#2dd4bf",document:"#f9a8d4",devops:"#fcd34d","e-commerce":"#fda4af",lifestyle:"#86efac",web:"#67e8f9",data:"#d8b4fe","multi-modal":"#fdba74",automation:"#facc15","smart-home":"#bef264",agents:"#e879f9","software-builder":"#7dd3fc",utilities:"#a5b4fc",media:"#fca5a5",communication:"#5eead4",education:"#c4b5fd",misc:"#9ca3af"};function Mp(t){return t.split(/[-_/]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}function Op({open:t,onClose:e}){const[s,r]=w.useState([]),[i,o]=w.useState([]),[c,l]=w.useState("All"),[d,p]=w.useState(""),[g,u]=w.useState(null),[f,x]=w.useState(!1),[b,E]=w.useState(null);w.useEffect(()=>{t&&(x(!0),ye("/api/widget-gallery").then(m=>m.json()).then(m=>{r(m.templates||[]),o(m.categories||[]),x(!1)}).catch(m=>{E(m.message),x(!1)}))},[t]),w.useEffect(()=>{if(!t)return;const m=k=>{k.key==="Escape"&&e()};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[t,e]);const A=w.useMemo(()=>{const m=c==="All"?s:s.filter(_=>_.category===c),k=d.trim().toLowerCase();return k?m.filter(_=>[_.name,_.description,_.category,..._.tags||[],..._.triggers||[]].join(" ").toLowerCase().includes(k)):m},[c,d,s]);if(!t)return null;const v=async m=>{var k,_,T,S;u(m.id),E(null);try{const N=await ye(`/api/widget-gallery/${encodeURIComponent(m.id)}`);if(!N.ok)throw new Error(`Could not load template (${N.status})`);const D=await N.json(),j={templateId:m.id,templateName:D.name||m.name,source:D.source,format:Ip(D.source),defaultSize:{w:((k=D.defaultSize)==null?void 0:k.w)??((_=m.defaultSize)==null?void 0:_.w)??4,h:((T=D.defaultSize)==null?void 0:T.h)??((S=m.defaultSize)==null?void 0:S.h)??4}};window.dispatchEvent(new CustomEvent("titan:gallery:run-template",{detail:j})),e()}catch(N){E(N.message)}finally{u(null)}},L=["All",...i.map(m=>m.category)];return n.jsx("div",{className:"fixed inset-0 z-[2147483150] flex items-center justify-center p-4 titan-menu-overlay",onClick:e,children:n.jsxs("div",{className:"w-full max-w-4xl titan-modal-surface flex flex-col",style:{height:"min(720px, 90vh)",borderRadius:12},onClick:m=>m.stopPropagation(),children:[n.jsxs("div",{className:"flex items-center justify-between px-5 py-3",style:{borderBottom:"1px solid var(--theme-menu-border)"},children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(wr,{className:"w-4 h-4",style:{color:"var(--theme-accent)"}}),n.jsx("h3",{className:"font-semibold text-sm",style:{color:"var(--theme-ink)",fontFamily:"var(--theme-font-display)"},children:"Widget gallery"}),n.jsx("span",{className:"text-[10px]",style:{color:"var(--theme-ink-soft)"},children:f?"Loading…":`${s.length} templates`})]}),n.jsx("button",{onClick:e,className:"titan-close-btn",title:"Close (Esc)","aria-label":"Close",children:n.jsx(ks,{className:"w-4 h-4"})})]}),n.jsx("div",{className:"flex items-center gap-1.5 px-5 py-2 border-b border-[#27272a] text-[11px] overflow-x-auto",children:L.map(m=>{var k;return n.jsxs("button",{onClick:()=>l(m),className:`px-2.5 py-1 rounded-full border transition-colors whitespace-nowrap ${c===m?"border-[#6366f1] bg-[#6366f1]/15 text-white":"border-[#27272a] bg-transparent text-[#a1a1aa] hover:border-[#3f3f46] hover:text-white"}`,children:[Mp(m),m!=="All"&&n.jsx("span",{className:"ml-1.5 text-[9px] opacity-70",children:((k=i.find(_=>_.category===m))==null?void 0:k.count)??0})]},m)})}),n.jsx("div",{className:"px-5 py-2 border-b border-[#27272a]",children:n.jsxs("label",{className:"flex items-center gap-2 rounded-lg border border-[#27272a] bg-[#18181b]/60 px-3 py-2",children:[n.jsx(ro,{className:"w-3.5 h-3.5 text-[#71717a]"}),n.jsx("input",{value:d,onChange:m=>p(m.target.value),placeholder:"Search templates...",className:"flex-1 bg-transparent text-xs text-white placeholder:text-[#71717a] outline-none"})]})}),n.jsxs("div",{className:"flex-1 overflow-auto p-4",children:[f&&n.jsx("div",{className:"flex items-center justify-center h-full text-[#a1a1aa] text-sm",children:"Loading templates…"}),b&&n.jsxs("div",{className:"flex items-center justify-center h-full text-[#f87171] text-sm",children:["Error: ",b]}),!f&&!b&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3",children:A.map(m=>n.jsxs("button",{onClick:()=>v(m),disabled:g!==null,className:"text-left p-3 rounded-lg border border-[#27272a] bg-[#18181b]/60 hover:border-[#6366f1]/50 hover:bg-[#18181b] transition-colors group",children:[n.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1",children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[n.jsx("span",{className:"w-1.5 h-1.5 rounded-full shrink-0",style:{background:Dp[m.category]??"#9ca3af"}}),n.jsx("span",{className:"text-[12px] font-medium text-white truncate",children:m.name})]}),n.jsx(io,{className:"w-3 h-3 text-[#52525b] group-hover:text-[#a5b4fc] transition-colors shrink-0"})]}),n.jsx("div",{className:"text-[11px] text-[#a1a1aa] leading-relaxed line-clamp-2",children:g===m.id?"Adding to canvas...":m.description}),m.tags&&m.tags.length>0&&n.jsx("div",{className:"flex flex-wrap gap-1 mt-1.5",children:m.tags.slice(0,3).map(k=>n.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-[#27272a] text-[#71717a]",children:k},k))})]},m.id))}),A.length===0&&n.jsx("div",{className:"flex items-center justify-center h-40 text-[#a1a1aa] text-sm",children:"No templates in this category."})]}),n.jsxs("div",{className:"mt-4 p-3 rounded-lg border border-dashed border-[#27272a] bg-[#0a0a0e] flex items-start gap-2",children:[n.jsx(uo,{className:"w-3.5 h-3.5 text-[#71717a] mt-0.5 shrink-0"}),n.jsxs("div",{className:"text-[11px] text-[#a1a1aa] leading-relaxed",children:["Don’t see what you want? Open the chat (click the mascot) and describe your widget in plain English. TITAN can build anything that runs inside a sandboxed iframe with access to ",n.jsx("span",{className:"font-mono text-[#d4d4d8]",children:"titan.fetch"}),","," ",n.jsx("span",{className:"font-mono text-[#d4d4d8]",children:"titan.api.call"}),", and"," ",n.jsx("span",{className:"font-mono text-[#d4d4d8]",children:"titan.state"}),"."]})]})]})]})})}const Wp=[{type:"widget",source:"system:nav",name:"Nav Widget",w:3,h:4,icon:n.jsx(uo,{className:"w-4 h-4"})},{type:"widget",source:"system:chat",name:"Chat Widget",w:4,h:5,icon:n.jsx(Zi,{className:"w-4 h-4"})},{type:"widget",source:"system:soma",name:"SOMA",w:6,h:6,icon:n.jsx(yt,{className:"w-4 h-4"})},{type:"widget",source:"system:command-post",name:"Command Post",w:8,h:6,icon:n.jsx(so,{className:"w-4 h-4"})},{type:"widget",source:"system:intelligence",name:"Intelligence",w:6,h:5,icon:n.jsx(to,{className:"w-4 h-4"})},{type:"widget",source:"system:memory-graph",name:"Memory Graph",w:8,h:7,icon:n.jsx($l,{className:"w-4 h-4"})},{type:"widget",source:"system:voice",name:"Voice",w:5,h:5,icon:n.jsx(oo,{className:"w-4 h-4"})},{type:"widget",source:"system:infra",name:"Infrastructure",w:6,h:4,icon:n.jsx(jr,{className:"w-4 h-4"})},{type:"widget",source:"system:tools",name:"Tools",w:5,h:4,icon:n.jsx(Sr,{className:"w-4 h-4"})},{type:"widget",source:"system:settings",name:"Settings",w:5,h:5,icon:n.jsx(Er,{className:"w-4 h-4"})},{type:"widget",source:"system:files",name:"Files",w:4,h:6,icon:n.jsx(hn,{className:"w-4 h-4"})},{type:"widget",source:"system:daemon",name:"Daemon",w:6,h:6,icon:n.jsx(gt,{className:"w-4 h-4"})},{type:"widget",source:"system:memory-wiki",name:"Memory Wiki",w:6,h:6,icon:n.jsx(hs,{className:"w-4 h-4"})},{type:"widget",source:"system:autoresearch",name:"Autoresearch",w:6,h:6,icon:n.jsx(ao,{className:"w-4 h-4"})},{type:"widget",source:"system:self-proposals",name:"Self-Proposals",w:6,h:6,icon:n.jsx(co,{className:"w-4 h-4"})},{type:"widget",source:"system:overview",name:"Overview",w:6,h:5,icon:n.jsx(Ji,{className:"w-4 h-4"})},{type:"widget",source:"system:sessions",name:"Sessions",w:6,h:5,icon:n.jsx(us,{className:"w-4 h-4"})},{type:"widget",source:"system:watch",name:"Watch",w:8,h:7,icon:n.jsx(gt,{className:"w-4 h-4"})},{type:"widget",source:"system:backup",name:"Backup Manager",w:6,h:6,icon:n.jsx(lo,{className:"w-4 h-4"})},{type:"widget",source:"system:training",name:"Training Dashboard",w:6,h:6,icon:n.jsx(yt,{className:"w-4 h-4"})},{type:"widget",source:"system:recipes",name:"Recipe Kitchen",w:6,h:6,icon:n.jsx(hs,{className:"w-4 h-4"})},{type:"widget",source:"system:vram",name:"VRAM Monitor",w:6,h:6,icon:n.jsx(vr,{className:"w-4 h-4"})},{type:"widget",source:"system:teams",name:"Team Hub",w:6,h:6,icon:n.jsx(kr,{className:"w-4 h-4"})},{type:"widget",source:"system:cron",name:"Cron Scheduler",w:6,h:6,icon:n.jsx(us,{className:"w-4 h-4"})},{type:"widget",source:"system:checkpoints",name:"Checkpoints",w:6,h:5,icon:n.jsx(pn,{className:"w-4 h-4"})},{type:"widget",source:"system:organism",name:"Organism Monitor",w:6,h:6,icon:n.jsx(_r,{className:"w-4 h-4"})},{type:"widget",source:"system:fleet",name:"Fleet Router",w:6,h:5,icon:n.jsx(fo,{className:"w-4 h-4"})},{type:"widget",source:"system:browser",name:"Browser Tools",w:6,h:5,icon:n.jsx(Xi,{className:"w-4 h-4"})},{type:"widget",source:"system:paperclip",name:"Paperclip",w:6,h:5,icon:n.jsx(ho,{className:"w-4 h-4"})},{type:"widget",source:"system:eval",name:"Test Lab",w:6,h:6,icon:n.jsx(po,{className:"w-4 h-4"})}];function fl({currentSpaceId:t,onSpaceSelect:e,onAction:s,onClose:r}){const[i,o]=w.useState(""),[c,l]=w.useState(0),d=w.useRef(null),p=ke.list(),g=w.useMemo(()=>{const u=i.toLowerCase(),f=p.filter(b=>b.id!==t&&b.name.toLowerCase().includes(u)).map(b=>({type:"space",id:b.id,name:b.name,color:b.color})),x=Wp.filter(b=>b.name.toLowerCase().includes(u)).map(b=>({type:"action",action:b,name:b.name}));return[...f,...x]},[i,p,t]);return w.useEffect(()=>{var u;(u=d.current)==null||u.focus()},[]),w.useEffect(()=>{l(0)},[i]),w.useEffect(()=>{const u=f=>{if((f.metaKey||f.ctrlKey)&&f.key.toLowerCase()==="k"){f.preventDefault(),r();return}if(f.key==="Escape"){r();return}if(f.key==="ArrowDown"){f.preventDefault(),l(x=>Math.min(x+1,g.length-1));return}if(f.key==="ArrowUp"){f.preventDefault(),l(x=>Math.max(x-1,0));return}if(f.key==="Enter"){f.preventDefault();const x=g[c];if(!x)return;x.type==="space"&&e(x.id),x.type==="action"&&s(x.action)}};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[g,c,e,s,r]),n.jsx("div",{className:"fixed inset-0 z-[2147483200] flex items-start justify-center pt-[20vh]",onClick:r,children:n.jsxs("div",{className:"w-full max-w-lg bg-[#18181b]/98 backdrop-blur-xl border border-[#27272a]/60 rounded-2xl shadow-2xl shadow-black/60 overflow-hidden",onClick:u=>u.stopPropagation(),children:[n.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-[#27272a]/40",children:[n.jsx(ro,{className:"w-4 h-4 text-[#3f3f46]"}),n.jsx("input",{ref:d,value:i,onChange:u=>o(u.target.value),placeholder:"Search spaces, widgets, actions...",className:"flex-1 bg-transparent text-sm text-[#e4e4e7] placeholder:text-[#3f3f46] outline-none"}),n.jsx("button",{onClick:r,className:"text-[#3f3f46] hover:text-[#71717a]",children:n.jsx(ks,{className:"w-4 h-4"})})]}),n.jsxs("div",{className:"max-h-[50vh] overflow-auto py-1",children:[g.length===0&&n.jsxs("div",{className:"px-4 py-6 text-center text-xs text-[#52525b]",children:['No results for "',i,'"']}),g.map((u,f)=>n.jsxs("button",{onClick:()=>{u.type==="space"&&e(u.id),u.type==="action"&&s(u.action)},className:`w-full flex items-center gap-3 px-4 py-2.5 text-left transition-colors ${f===c?"bg-[#6366f1]/10 text-[#818cf8]":"text-[#a1a1aa] hover:bg-[#27272a]/30"}`,children:[u.type==="space"?n.jsx("div",{className:"w-4 h-4 rounded-full",style:{background:u.color||"#52525b"}}):n.jsx("span",{className:"text-[#6366f1]/60",children:u.action.icon}),n.jsx("span",{className:"text-sm",children:u.name}),n.jsx("span",{className:"ml-auto text-[10px] text-[#3f3f46] uppercase tracking-wider",children:u.type==="space"?"Space":"Widget"})]},u.type==="space"?u.id:u.action.source))]}),n.jsxs("div",{className:"px-4 py-2 border-t border-[#27272a]/40 flex items-center gap-3 text-[10px] text-[#3f3f46]",children:[n.jsx("span",{children:"↑↓ Navigate"}),n.jsx("span",{children:"↵ Select"}),n.jsx("span",{children:"ESC Close"})]})]})})}const Pp=oe.lazy(()=>le(()=>import("./SomaView-D3boPl5D.js"),__vite__mapDeps([0,1,2,3,4,5,6])));function pl(){const[t,e]=w.useState(null),[s,r]=w.useState(!1),[i,o]=w.useState(null),c=w.useCallback(async()=>{var p;try{const g=await ye("/api/config");if(!g.ok)throw new Error(`HTTP ${g.status}`);const u=await g.json();e(!!((p=u==null?void 0:u.organism)!=null&&p.enabled)),o(null)}catch(g){o(g.message),e(!1)}},[]);w.useEffect(()=>{c()},[c]);const l=w.useRef(0),d=w.useCallback(async p=>{const g=++l.current;r(!0),o(null);try{const u=await ye("/api/config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({organism:{enabled:p}})});if(g!==l.current)return;if(!u.ok)throw new Error(`HTTP ${u.status}`);e(p),window.dispatchEvent(new CustomEvent("titan:soma:changed",{detail:{enabled:p}}))}catch(u){if(g!==l.current)return;o(u.message)}finally{g===l.current&&r(!1)}},[]);return t===null?n.jsx("div",{className:"w-full h-full flex items-center justify-center text-xs text-[#52525b]",children:"Loading Soma…"}):t?n.jsxs("div",{className:"w-full h-full overflow-auto flex flex-col",children:[n.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-[#27272a]/40 bg-[#18181b]/60",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-[#34d399] animate-pulse"}),n.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider text-[#34d399]",children:"Soma active"})]}),n.jsxs("button",{onClick:()=>d(!1),disabled:s,className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full border border-[#27272a] text-[10px] text-[#a1a1aa] hover:text-white hover:border-[#3f3f46] disabled:opacity-60 transition-colors",title:"Disable Soma",children:[n.jsx(li,{className:"w-3 h-3"}),s?"saving…":"disable"]})]}),n.jsx("div",{className:"flex-1 overflow-auto",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"p-4 text-xs text-[#52525b]",children:"Loading Soma dashboard…"}),children:n.jsx(Pp,{})})})]}):n.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center gap-4 p-6 text-center",children:[n.jsx("div",{className:"w-14 h-14 rounded-full bg-gradient-to-br from-[#6366f1]/20 to-[#a78bfa]/20 border border-[#6366f1]/30 flex items-center justify-center",children:n.jsx(gt,{className:"w-7 h-7 text-[#a78bfa]"})}),n.jsxs("div",{className:"space-y-1 max-w-md",children:[n.jsx("h3",{className:"text-lg font-semibold text-white",children:"Soma is off"}),n.jsx("p",{className:"text-xs text-[#a1a1aa] leading-relaxed",children:"TITAN’s homeostatic drive layer. When enabled, TITAN has a sense of its own state — purpose, curiosity, hunger, safety, social, rest — and will propose work when those drives drift. Every proposal still requires your approval."})]}),n.jsxs("button",{onClick:()=>d(!0),disabled:s,className:"inline-flex items-center gap-2 px-5 py-2.5 rounded-full bg-[#6366f1] hover:bg-[#4f46e5] disabled:opacity-60 disabled:cursor-not-allowed text-white text-sm font-medium transition-colors",children:[n.jsx(li,{className:"w-4 h-4"}),s?"Enabling…":"Enable Soma"]}),i&&n.jsx("p",{className:"text-xs text-[#ef4444]",children:i}),n.jsx("p",{className:"text-[10px] text-[#52525b]",children:"You can turn this off anytime from the same button."})]})}const Bp={calm:{primary:"#6366f1",glow:"rgba(99,102,241,0.4)",pulse:"rgba(99,102,241,0.15)"},focused:{primary:"#10b981",glow:"rgba(16,185,129,0.4)",pulse:"rgba(16,185,129,0.15)"},excited:{primary:"#f59e0b",glow:"rgba(245,158,11,0.4)",pulse:"rgba(245,158,11,0.15)"},concerned:{primary:"#ef4444",glow:"rgba(239,68,68,0.4)",pulse:"rgba(239,68,68,0.15)"},dreaming:{primary:"#8b5cf6",glow:"rgba(139,92,246,0.4)",pulse:"rgba(139,92,246,0.15)"}};function Up(t,e,s){if(!s)return{emotion:"dreaming",intensity:.25,activity:"Dormant"};const r=e[0],i=Math.min(1,t/2);switch(r){case"purpose":return{emotion:"focused",intensity:.4+i*.4,activity:"Pursuing purpose"};case"curiosity":return{emotion:"excited",intensity:.4+i*.5,activity:"Exploring"};case"hunger":return{emotion:"focused",intensity:.5+i*.3,activity:"Satiating"};case"safety":return{emotion:"concerned",intensity:.5+i*.4,activity:"Securing"};case"social":return{emotion:"calm",intensity:.3+i*.3,activity:"Connecting"};case"rest":return{emotion:"dreaming",intensity:.2+i*.2,activity:"Recuperating"};default:return t>.5?{emotion:"focused",intensity:i,activity:"Processing"}:{emotion:"calm",intensity:.3,activity:"Observing"}}}function Fp(){const[t,e]=w.useState(!1),[s,r]=w.useState({emotion:"calm",intensity:.3,activity:"Observing"}),[i,o]=w.useState(!1),[c,l]=w.useState({x:280,y:80}),[d,p]=w.useState(!1),g=w.useRef({x:0,y:0}),u=w.useRef(null);w.useEffect(()=>{let A=!1;const v=async()=>{try{const m=await ye("/api/soma/state");if(!m.ok||A)return;const k=await m.json();if(A)return;r(Up(Number((k==null?void 0:k.totalPressure)??0),Array.isArray(k==null?void 0:k.dominantDrives)?k.dominantDrives:[],!!(k!=null&&k.enabled)))}catch{}};v();const L=setInterval(v,15e3);return()=>{A=!0,clearInterval(L)}},[]),w.useEffect(()=>{const A=v=>{var L;(L=u.current)!=null&&L.contains(v.target)||o(!1)};return window.addEventListener("mousedown",A),()=>window.removeEventListener("mousedown",A)},[]);const f=A=>{A.button===0&&(g.current={x:A.clientX-c.x,y:A.clientY-c.y},p(!0))},x=A=>{d&&l({x:A.clientX-g.current.x,y:A.clientY-g.current.y})},b=()=>{p(!1)},E=Bp[s.emotion];return n.jsxs(n.Fragment,{children:[t&&n.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/40 backdrop-blur-sm",onClick:()=>e(!1),children:n.jsxs("div",{className:"bg-[#1f1812]/95 border border-[#8b6b4a]/40 rounded-2xl shadow-2xl shadow-black/60 overflow-hidden",style:{width:"min(900px, 90vw)",height:"min(600px, 80vh)"},onClick:A=>A.stopPropagation(),children:[n.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-[#8b6b4a]/30",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(yt,{className:"w-4 h-4",style:{color:E.primary}}),n.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider text-[#c8b89a]",children:"SOMA Consciousness"})]}),n.jsx("button",{onClick:()=>e(!1),className:"p-1 text-[#8b6b4a] hover:text-[#c8b89a]",children:n.jsx(ks,{className:"w-4 h-4"})})]}),n.jsx("div",{className:"h-[calc(100%-40px)]",children:n.jsx(pl,{})})]})}),n.jsxs("div",{ref:u,className:"fixed z-50 select-none",style:{left:c.x,top:c.y},onMouseDown:f,onMouseMove:x,onMouseUp:b,onMouseLeave:b,children:[i&&n.jsxs("div",{className:"absolute bottom-full left-0 mb-2 bg-[#2a2018]/95 backdrop-blur-xl border border-[#8b6b4a]/40 rounded-xl shadow-2xl shadow-black/60 overflow-hidden min-w-[160px] py-1",children:[n.jsxs("button",{onClick:()=>{e(!0),o(!1)},className:"w-full flex items-center gap-2 px-3 py-2 text-left text-[11px] text-[#c8b89a] hover:bg-[#3d3028]/50 transition-colors",children:[n.jsx(yt,{className:"w-3.5 h-3.5",style:{color:E.primary}}),"Open SOMA"]}),n.jsxs("button",{onClick:()=>{o(!1)},className:"w-full flex items-center gap-2 px-3 py-2 text-left text-[11px] text-[#c8b89a] hover:bg-[#3d3028]/50 transition-colors",children:[n.jsx(wr,{className:"w-3.5 h-3.5 text-[#f59e0b]"}),"Summarize Canvas"]}),n.jsxs("button",{onClick:()=>{o(!1)},className:"w-full flex items-center gap-2 px-3 py-2 text-left text-[11px] text-[#c8b89a] hover:bg-[#3d3028]/50 transition-colors",children:[n.jsx(_l,{className:"w-3.5 h-3.5 text-[#6366f1]"}),"Run Self-Check"]})]}),n.jsxs("div",{className:"relative cursor-pointer group",onClick:()=>!d&&e(!0),onContextMenu:A=>{A.preventDefault(),o(!0)},children:[n.jsx("div",{className:"absolute inset-0 rounded-full animate-ping opacity-20",style:{background:E.pulse,animationDuration:`${3-s.intensity*2}s`}}),n.jsx("div",{className:"absolute -inset-2 rounded-full opacity-30 blur-md transition-all duration-1000",style:{background:E.glow}}),n.jsx("div",{className:"relative w-12 h-12 rounded-full flex items-center justify-center transition-all duration-500 hover:scale-110",style:{background:`radial-gradient(circle at 30% 30%, ${E.primary}, ${E.primary}88)`,boxShadow:`0 0 ${20+s.intensity*30}px ${E.glow}, inset 0 0 10px rgba(255,255,255,0.1)`},children:n.jsx(yt,{className:"w-5 h-5 text-white/90"})}),n.jsx("div",{className:"absolute -bottom-5 left-1/2 -translate-x-1/2 whitespace-nowrap",children:n.jsx("span",{className:"text-[9px] font-medium uppercase tracking-wider text-[#e8dcc8] bg-black/60 px-1.5 py-0.5 rounded border border-[#8b6b4a]/30",children:s.activity})})]})]})]})}const $p=oe.lazy(()=>le(()=>import("./CommandPostHub-iWf-zt5p.js"),__vite__mapDeps([7,1,2,3,4,8,9,10,11,12,5,13,14,15,16,17,18,19,20,21,22,23,24,25,26])));function zp(){return n.jsx("div",{className:"w-full h-full overflow-auto p-2",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"p-4 text-xs text-[#52525b]",children:"Loading Command Post..."}),children:n.jsx($p,{})})})}const Hp=oe.lazy(()=>le(()=>import("./IntelligenceView-DeKBaAlY.js"),__vite__mapDeps([27,1,2,4])));function Vp(){return n.jsx("div",{className:"w-full h-full overflow-auto",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"p-4 text-xs text-[#52525b]",children:"Loading Intelligence..."}),children:n.jsx(Hp,{})})})}const Gp=oe.lazy(()=>le(()=>import("./MemoryGraphPanel-DZl7USJ6.js"),__vite__mapDeps([28,1,2,29,12,26,30])));function qp(){return n.jsx("div",{className:"w-full h-full overflow-auto bg-[#09090b]",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"h-full flex items-center justify-center",children:n.jsxs("div",{className:"text-center",children:[n.jsx("div",{className:"w-8 h-8 rounded-full border-2 border-[#6366f1]/20 border-t-[#6366f1] animate-spin mx-auto mb-3"}),n.jsx("p",{className:"text-[11px] text-[#52525b]",children:"Loading memory graph..."})]})}),children:n.jsx("div",{className:"p-4",children:n.jsx(Gp,{})})})})}function Yp(){const[t,e]=w.useState(!1);return t?n.jsx(Ll,{onClose:()=>e(!1)}):n.jsx("div",{className:"w-full h-full flex flex-col items-center justify-center bg-[#09090b]",children:n.jsxs("button",{onClick:()=>e(!0),className:"group relative flex flex-col items-center gap-4",children:[n.jsxs("div",{className:"relative w-20 h-20 rounded-full flex items-center justify-center transition-all duration-300 group-hover:scale-110",children:[n.jsx("div",{className:"absolute inset-0 rounded-full bg-[#6366f1]/20 animate-pulse"}),n.jsx("div",{className:"absolute inset-0 rounded-full bg-gradient-to-br from-[#6366f1]/30 to-[#4f46e5]/10 border border-[#6366f1]/30"}),n.jsx(oo,{className:"w-8 h-8 text-[#818cf8] relative z-10"})]}),n.jsxs("div",{className:"text-center",children:[n.jsx("p",{className:"text-sm font-medium text-[#a1a1aa]",children:"Tap to speak"}),n.jsx("p",{className:"text-[10px] text-[#52525b] mt-1",children:"F5-TTS · Voice Cloning"})]})]})})}const Kp=oe.lazy(()=>le(()=>import("./InfraView-CI99NZbI.js"),__vite__mapDeps([31,1,2,4])));function Jp(){return n.jsx("div",{className:"w-full h-full overflow-auto",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"p-4 text-xs text-[#52525b]",children:"Loading Infrastructure..."}),children:n.jsx(Kp,{})})})}const Xp=oe.lazy(()=>le(()=>import("./ToolsView-BlChEE4n.js"),__vite__mapDeps([32,1,2,4])));function Qp(){return n.jsx("div",{className:"w-full h-full overflow-auto",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"p-4 text-xs text-[#52525b]",children:"Loading Tools..."}),children:n.jsx(Xp,{})})})}const Zp=oe.lazy(()=>le(()=>import("./SettingsView-BNpj0iym.js"),__vite__mapDeps([33,1,2,4])));function em(){return n.jsx("div",{className:"w-full h-full overflow-auto",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"p-4 text-xs text-[#52525b]",children:"Loading Settings..."}),children:n.jsx(Zp,{})})})}function tm(){const[t,e]=w.useState([]),[s,r]=w.useState("/"),[i,o]=w.useState(!1),c=async()=>{o(!0);try{const l=await ye(`/api/files?path=${encodeURIComponent(s)}`);if(l.ok){const d=await l.json();e(d.files||[])}else e([{name:"documents",path:"/documents",type:"directory"},{name:"readme.md",path:"/readme.md",type:"file"},{name:"config.yaml",path:"/config.yaml",type:"file"}])}catch{e([{name:"documents",path:"/documents",type:"directory"},{name:"readme.md",path:"/readme.md",type:"file"},{name:"config.yaml",path:"/config.yaml",type:"file"}])}finally{o(!1)}};return w.useEffect(()=>{c()},[s]),n.jsxs("div",{className:"w-full h-full flex flex-col",children:[n.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-[#27272a]/40",children:[n.jsxs("div",{className:"flex items-center gap-1 text-[11px] text-[#71717a]",children:[n.jsx("span",{className:"text-[#6366f1]",children:"~"}),n.jsx(Dl,{className:"w-3 h-3"}),n.jsx("span",{children:s})]}),n.jsx("button",{onClick:c,className:"p-1 text-[#3f3f46] hover:text-[#71717a]",children:n.jsx(fn,{className:`w-3 h-3 ${i?"animate-spin":""}`})})]}),n.jsx("div",{className:"flex-1 overflow-auto",children:t.map(l=>n.jsxs("button",{onClick:()=>l.type==="directory"&&r(l.path),className:"w-full flex items-center gap-2 px-3 py-1.5 text-left hover:bg-[#27272a]/20 transition-colors",children:[l.type==="directory"?n.jsx(Il,{className:"w-3.5 h-3.5 text-[#f59e0b]"}):n.jsx(hn,{className:"w-3.5 h-3.5 text-[#6366f1]"}),n.jsx("span",{className:"text-[12px] text-[#a1a1aa]",children:l.name})]},l.path))})]})}const sm=oe.lazy(()=>le(()=>import("./SettingsPanel-DifFGEvi.js"),__vite__mapDeps([34,1,2,3,4,35,14,5,36,37,38,12,39,40,41,42,25,21,15,29,43,30,24,44,20,11,45,46])));function nm(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(sm,{})})})}const rm=oe.lazy(()=>le(()=>import("./SecurityPanel-OMC-Tvbz.js"),__vite__mapDeps([47,1,2,35,14])));function im(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(rm,{})})})}const om=oe.lazy(()=>le(()=>import("./AuditPanel-RNrvKmfX.js"),__vite__mapDeps([48,1,2,12,49])));function am(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(om,{})})})}const Hi={researcher:"#60a5fa",engineer:"#f87171",manager:"#a78bfa",ceo:"#fbbf24",general:"#9ca3af"},lm={Recommended:"bg-[#10b981]/15 text-[#10b981] border-[#10b981]/30",Reasoning:"bg-[#8b5cf6]/15 text-[#8b5cf6] border-[#8b5cf6]/30",Fast:"bg-[#0ea5e9]/15 text-[#0ea5e9] border-[#0ea5e9]/30",Light:"bg-[#f59e0b]/15 text-[#f59e0b] border-[#f59e0b]/30","Long Context":"bg-[#6366f1]/15 text-[#6366f1] border-[#6366f1]/30","High Output":"bg-[#ec4899]/15 text-[#ec4899] border-[#ec4899]/30","Needs Key":"bg-[#ef4444]/15 text-[#ef4444] border-[#ef4444]/30"};function cm(){const[t,e]=w.useState(null),[s,r]=w.useState({}),[i,o]=w.useState({}),[c,l]=w.useState(null),[d,p]=w.useState({}),[g,u]=w.useState(!0),f=w.useCallback(async()=>{l(null);try{const[E,A]=await Promise.all([ye("/api/specialists"),ye("/api/models")]);if(!E.ok)throw new Error(`Specialists request failed: ${E.status}`);if(!A.ok)throw new Error(`Models request failed: ${A.status}`);const v=await E.json(),L=await A.json();e(v),r(L);const m={};await Promise.all(v.map(async k=>{try{const _=await ye(`/api/specialists/${encodeURIComponent(k.id)}/recommendations`);if(_.ok){const T=await _.json();T.recommendations&&(m[k.id]=T.recommendations)}}catch{}})),o(m)}catch(E){l(E.message)}finally{u(!1)}},[]);w.useEffect(()=>{f()},[f]);const x=w.useCallback(E=>{const A=i[E];if(A&&A.length)return A.map(L=>L.id);const v=new Set;if(s&&typeof s=="object")for(const L of Object.keys(s)){const m=s[L];if(Array.isArray(m))for(const k of m)typeof k=="string"?v.add(k):k&&typeof k=="object"&&"id"in k&&typeof k.id=="string"&&v.add(k.id)}if(Array.isArray(t))for(const L of t)L!=null&&L.activeModel&&v.add(L.activeModel),L!=null&&L.defaultModel&&v.add(L.defaultModel);return Array.from(v).sort((L,m)=>L.localeCompare(m))},[i,s,t]),b=w.useCallback(async(E,A)=>{p(v=>({...v,[E]:"saving"}));try{const v=await ye(`/api/specialists/${encodeURIComponent(E)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:A})});if(!v.ok){const m=await v.text().catch(()=>"");throw new Error(`PATCH failed (${v.status}): ${m||v.statusText}`)}const L=await v.json();e(m=>(m==null?void 0:m.map(k=>k.id===E?{...k,activeModel:L.activeModel??k.defaultModel,overridden:(L.activeModel??k.defaultModel)!==k.defaultModel}:k))??null),p(m=>({...m,[E]:"saved"})),setTimeout(()=>{p(m=>{if(m[E]!=="saved")return m;const k={...m};return delete k[E],k})},1500)}catch(v){p(L=>({...L,[E]:"error"})),l(`${E}: ${v.message}`)}},[]);return g&&!t?n.jsx("div",{className:"h-full w-full flex items-center justify-center text-xs text-[#52525b]",children:"Loading specialists…"}):n.jsxs("div",{className:"w-full h-full flex flex-col bg-[#0a0a0f] text-[#e4e4e7] text-sm",children:[n.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-[#27272a]/60",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(kr,{className:"w-4 h-4 text-[#6366f1]"}),n.jsx("h3",{className:"font-semibold",children:"Specialist Models"}),n.jsxs("span",{className:"text-[10px] text-[#52525b]",children:[(t==null?void 0:t.length)??0," sub-agents"]})]}),n.jsxs("button",{onClick:()=>{u(!0),f()},className:"flex items-center gap-1 px-2 py-1 rounded text-[11px] text-[#71717a] hover:text-[#e4e4e7] hover:bg-[#27272a]/60 transition-colors",title:"Refresh from server",children:[n.jsx(fn,{className:`w-3 h-3 ${g?"animate-spin":""}`}),"Refresh"]})]}),c&&n.jsxs("div",{className:"mx-4 mt-3 flex items-start gap-2 px-3 py-2 rounded bg-[#7f1d1d]/20 border border-[#7f1d1d]/40 text-[11px] text-[#fca5a5]",children:[n.jsx(un,{className:"w-3 h-3 mt-0.5 shrink-0"}),n.jsx("span",{className:"font-mono",children:c})]}),n.jsxs("div",{className:"flex-1 overflow-auto px-4 py-3 space-y-3",children:[(t==null?void 0:t.length)===0&&n.jsx("div",{className:"text-xs text-[#52525b] italic",children:"No specialists registered."}),t==null?void 0:t.map(E=>n.jsx(dm,{row:E,models:x(E.id),recommendations:i[E.id]??[],state:d[E.id]??"idle",onChange:A=>b(E.id,A),onReset:()=>b(E.id,null)},E.id))]}),n.jsxs("div",{className:"px-4 py-2 border-t border-[#27272a]/60 text-[10px] text-[#52525b]",children:["Overrides write to ",n.jsx("span",{className:"font-mono text-[#71717a]",children:"config.specialists.overrides"}),". Top-scored models are recommended per specialist role."]})]})}function dm({row:t,models:e,recommendations:s,state:r,onChange:i,onReset:o}){var u;const c=Hi[t.role]??Hi.general,l=s.find(f=>f.id===t.activeModel),d=s[0]??null,[p,g]=w.useState(!1);return n.jsxs("div",{className:"rounded-lg border border-[#27272a]/60 bg-[#18181b]/70 hover:border-[#3f3f46]/80 transition-colors",children:[n.jsxs("div",{className:"px-3 py-2 flex items-center gap-3",children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-[180px]",children:[n.jsx("div",{className:"w-2 h-2 rounded-full shrink-0",style:{background:c},title:t.role}),n.jsxs("div",{className:"flex flex-col min-w-0",children:[n.jsx("div",{className:"text-sm font-medium truncate",children:t.name}),n.jsx("div",{className:"text-[10px] text-[#52525b] truncate",children:t.title})]})]}),n.jsxs("div",{className:"flex-1 flex items-center gap-2 min-w-0",children:[n.jsx("select",{value:t.activeModel,onChange:f=>i(f.target.value),disabled:r==="saving",className:"flex-1 min-w-0 px-2 py-1 rounded bg-[#0a0a0f] border border-[#27272a] text-xs font-mono focus:outline-none focus:border-[#6366f1] disabled:opacity-50",title:`default: ${t.defaultModel}`,children:e.map(f=>{const x=s.find(A=>A.id===f),b=(x==null?void 0:x.badges)??[],E=b.length?`${f} [${b.join(", ")}]`:f;return n.jsx("option",{value:f,children:E},f)})}),l&&l.badges.length>0&&n.jsx("div",{className:"hidden sm:flex items-center gap-1 shrink-0",children:l.badges.slice(0,3).map(f=>n.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] border ${lm[f]??"bg-[#27272a] text-[#a1a1aa] border-[#27272a]"}`,children:f},f))}),t.overridden&&n.jsxs("button",{onClick:o,disabled:r==="saving",className:"flex items-center gap-1 px-2 py-1 rounded text-[10px] text-[#fbbf24] border border-[#fbbf24]/30 hover:bg-[#fbbf24]/10 transition-colors disabled:opacity-50",title:`Reset to default: ${t.defaultModel}`,children:[n.jsx(no,{className:"w-3 h-3"}),"Reset"]}),n.jsx("button",{onClick:()=>g(f=>!f),className:"flex items-center justify-center w-6 h-6 rounded hover:bg-[#27272a]/60 text-[#52525b] hover:text-[#a1a1aa] transition-colors",title:"Show recommendation details",children:n.jsx(ii,{className:"w-3.5 h-3.5"})}),n.jsxs("div",{className:"w-5 h-5 flex items-center justify-center shrink-0",children:[r==="saving"&&n.jsx(fn,{className:"w-3.5 h-3.5 animate-spin text-[#6366f1]"}),r==="saved"&&n.jsx(oi,{className:"w-3.5 h-3.5 text-[#10b981]"}),r==="error"&&n.jsx(un,{className:"w-3.5 h-3.5 text-[#ef4444]"})]})]})]}),p&&n.jsxs("div",{className:"px-3 pb-3 space-y-1.5",children:[l&&n.jsxs("div",{className:"flex items-start gap-2 text-[11px] text-[#a1a1aa]",children:[n.jsx(ii,{className:"w-3 h-3 mt-0.5 shrink-0 text-[#6366f1]"}),n.jsx("span",{children:l.rationale})]}),d&&d.id!==t.activeModel&&n.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-[#10b981]",children:[n.jsx(oi,{className:"w-3 h-3 shrink-0"}),n.jsxs("span",{children:["Recommended upgrade: ",n.jsx("span",{className:"font-mono",children:d.id})," (score ",d.score,"/100)",d.badges.length>0&&n.jsxs("span",{className:"ml-1 text-[#71717a]",children:["[",d.badges.join(", "),"]"]})]})]}),l&&n.jsxs("div",{className:"grid grid-cols-3 gap-2 text-[10px] text-[#52525b]",children:[n.jsxs("div",{children:["Capability: ",n.jsxs("span",{className:"text-[#a1a1aa]",children:[l.breakdown.capabilityScore,"/40"]})]}),n.jsxs("div",{children:["Fit: ",n.jsxs("span",{className:"text-[#a1a1aa]",children:[l.breakdown.specialistFit,"/40"]})]}),n.jsxs("div",{children:["Availability: ",n.jsxs("span",{className:"text-[#a1a1aa]",children:[l.breakdown.availability,"/20"]})]})]})]}),n.jsxs("div",{className:"px-3 pb-2 flex items-center gap-2 text-[10px] text-[#52525b]",children:[n.jsxs("span",{children:["id: ",n.jsx("span",{className:"font-mono text-[#71717a]",children:t.id})]}),n.jsx("span",{children:"•"}),n.jsxs("span",{children:["role: ",n.jsx("span",{className:"font-mono",style:{color:c},children:t.role})]}),((u=t.templateMatches)==null?void 0:u.length)>0&&n.jsxs(n.Fragment,{children:[n.jsx("span",{children:"•"}),n.jsxs("span",{className:"truncate",children:["templates: ",n.jsx("span",{className:"font-mono text-[#71717a]",children:t.templateMatches.join(", ")})]})]})]})]})}function um(){const[t,e]=w.useState(null),[s,r]=w.useState(null),[i,o]=w.useState(null),[c,l]=w.useState(!1),[d,p]=w.useState(null),[g,u]=w.useState(null),f=w.useCallback(async()=>{p(null);try{const[A,v,L]=await Promise.all([ye("/api/telemetry/consent").then(m=>m.ok?m.json():Promise.reject(new Error(`consent ${m.status}`))),ye("/api/analytics/profile").then(m=>m.ok?m.json():null),ye("/api/telemetry/status").then(m=>m.ok?m.json():null)]);e(A),r(v),L!=null&&L.remote&&o(L.remote)}catch(A){p(A.message)}},[]);w.useEffect(()=>{const A=setInterval(()=>{ye("/api/telemetry/status").then(v=>v.ok?v.json():null).then(v=>{v!=null&&v.remote&&o(v.remote)}).catch(()=>{})},15e3);return()=>clearInterval(A)},[]),w.useEffect(()=>{f()},[f]);const x=w.useCallback(async A=>{l(!0),p(null);try{const v=await ye("/api/telemetry/consent",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(A)});if(!v.ok)throw new Error(`save failed: ${v.status}`);const L=await v.json();e(m=>m?{...m,...L,consentedAt:L.enabled?new Date().toISOString():void 0}:null),u(Date.now()),setTimeout(()=>u(null),2e3)}catch(v){p(v.message)}finally{l(!1)}},[]),b=!!(t!=null&&t.enabled),E=!!(t!=null&&t.crashReports);return n.jsxs("div",{className:"w-full h-full overflow-auto bg-[#0a0a0f] text-[#e4e4e7] text-sm p-4",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[b?n.jsx(Ml,{className:"w-5 h-5 text-[#10b981]"}):n.jsx(_r,{className:"w-5 h-5 text-[#71717a]"}),n.jsx("h3",{className:"font-semibold text-base",children:"Privacy & Telemetry"}),n.jsx("span",{className:`ml-2 text-[10px] px-2 py-0.5 rounded-full border ${b?"border-[#10b981]/40 bg-[#10b981]/10 text-[#10b981]":"border-[#3f3f46] bg-[#18181b] text-[#71717a]"}`,children:b?"ENABLED":"OFF"}),n.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[g&&n.jsxs("span",{className:"text-[11px] text-[#10b981] flex items-center gap-1",children:[n.jsx(kl,{className:"w-3 h-3"})," Saved"]}),d&&n.jsxs("span",{className:"text-[11px] text-[#ef4444] flex items-center gap-1",children:[n.jsx(Sl,{className:"w-3 h-3"})," ",d]}),n.jsxs("button",{onClick:()=>{f()},className:"flex items-center gap-1 px-2 py-1 rounded text-[11px] text-[#71717a] hover:text-[#e4e4e7] hover:bg-[#27272a]/60 transition-colors",children:[n.jsx(fn,{className:"w-3 h-3"})," Refresh"]})]})]}),n.jsx("div",{className:"mb-4 p-4 rounded-lg border border-[#27272a]/60 bg-[#18181b]/70",children:n.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:b,disabled:c,onChange:A=>x({enabled:A.target.checked,crashReports:E}),className:"mt-1 w-4 h-4 accent-[#6366f1] disabled:opacity-50"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"font-medium",children:"Send anonymous usage stats"}),n.jsx("div",{className:"text-xs text-[#a1a1aa] mt-1 leading-relaxed",children:"OS, Node version, CPU/GPU model + VRAM, RAM, TITAN version, and install method. A heartbeat every 5 minutes so we see uptime + concurrent-session counts. Never sends: prompts, file contents, credentials, IP address, or conversations."}),(t==null?void 0:t.consentedAt)&&n.jsxs("div",{className:"text-[10px] text-[#71717a] mt-2",children:["Consented ",n.jsx("span",{className:"font-mono",children:new Date(t.consentedAt).toLocaleString()}),t.consentedVersion&&n.jsxs(n.Fragment,{children:[" on TITAN v",n.jsx("span",{className:"font-mono",children:t.consentedVersion})]})]})]})]})}),n.jsx("div",{className:`mb-4 p-4 rounded-lg border transition-opacity ${b?"border-[#27272a]/60 bg-[#18181b]/70":"border-[#27272a]/30 bg-[#18181b]/30 opacity-60"}`,children:n.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:E,disabled:c||!b,onChange:A=>x({enabled:b,crashReports:A.target.checked}),className:"mt-1 w-4 h-4 accent-[#6366f1] disabled:opacity-50"}),n.jsxs("div",{className:"flex-1",children:[n.jsx("div",{className:"font-medium",children:"Send crash reports"}),n.jsxs("div",{className:"text-xs text-[#a1a1aa] mt-1 leading-relaxed",children:["When TITAN throws an uncaught exception or unhandled promise rejection, send the error class, message, and stack trace. ",n.jsxs("span",{className:"text-[#fbbf24]",children:["Your $HOME path is replaced with the string ",n.jsx("span",{className:"font-mono",children:'"$HOME"'})," before sending."]})]})]})]})}),n.jsxs("div",{className:"mb-4 p-4 rounded-lg border border-[#27272a]/60 bg-[#18181b]/40",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[n.jsx(un,{className:"w-4 h-4 text-[#6366f1]"}),n.jsx("div",{className:"text-sm font-medium",children:"What would be sent right now"})]}),s?n.jsxs("dl",{className:"grid grid-cols-[160px_1fr] gap-y-1 text-xs",children:[n.jsx("dt",{className:"text-[#71717a]",children:"installId"}),n.jsxs("dd",{className:"font-mono text-[#e4e4e7]",children:[s.installId.slice(0,32),"…"]}),n.jsx("dt",{className:"text-[#71717a]",children:"os / arch"}),n.jsxs("dd",{className:"font-mono text-[#e4e4e7]",children:[s.os," / ",s.arch," (",s.osRelease,")"]}),n.jsx("dt",{className:"text-[#71717a]",children:"cpu"}),n.jsxs("dd",{className:"font-mono text-[#e4e4e7]",children:[s.cpuModel," · ",s.cpuCores,"c"]}),n.jsx("dt",{className:"text-[#71717a]",children:"ram"}),n.jsxs("dd",{className:"font-mono text-[#e4e4e7]",children:[(s.ramTotalMB/1024).toFixed(1)," GB"]}),n.jsx("dt",{className:"text-[#71717a]",children:"gpu"}),n.jsxs("dd",{className:"font-mono text-[#e4e4e7]",children:[s.gpuVendor,"/",s.gpuName," · ",(s.gpuVramMB/1024).toFixed(1)," GB VRAM"]}),n.jsx("dt",{className:"text-[#71717a]",children:"disk"}),n.jsxs("dd",{className:"font-mono text-[#e4e4e7]",children:[s.diskTotalGB," GB"]}),n.jsx("dt",{className:"text-[#71717a]",children:"version / node"}),n.jsxs("dd",{className:"font-mono text-[#e4e4e7]",children:[s.version," · ",s.nodeVersion]}),n.jsx("dt",{className:"text-[#71717a]",children:"install method"}),n.jsx("dd",{className:"font-mono text-[#e4e4e7]",children:s.installMethod})]}):n.jsx("div",{className:"text-xs text-[#71717a]",children:"Loading profile preview…"})]}),n.jsxs("div",{className:"mb-4 p-4 rounded-lg border border-[#27272a]/60 bg-[#18181b]/50",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[n.jsx(io,{className:"w-4 h-4 text-[#6366f1]"}),n.jsx("div",{className:"text-sm font-medium",children:"Delivery status"}),(i==null?void 0:i.lastSuccessAt)&&!i.lastError&&n.jsx("span",{className:"ml-auto text-[10px] px-2 py-0.5 rounded-full border border-[#10b981]/40 bg-[#10b981]/10 text-[#10b981]",children:"FLOWING"}),(i==null?void 0:i.lastError)&&n.jsx("span",{className:"ml-auto text-[10px] px-2 py-0.5 rounded-full border border-[#ef4444]/40 bg-[#ef4444]/10 text-[#ef4444]",children:"ERROR"}),!(i!=null&&i.configured)&&n.jsx("span",{className:"ml-auto text-[10px] px-2 py-0.5 rounded-full border border-[#71717a]/40 bg-[#71717a]/10 text-[#71717a]",children:"NO REMOTE"})]}),i?n.jsxs("dl",{className:"grid grid-cols-[160px_1fr] gap-y-1 text-xs",children:[n.jsx("dt",{className:"text-[#71717a]",children:"remote URL"}),n.jsx("dd",{className:"font-mono text-[#e4e4e7] break-all",children:i.remoteUrl||"—"}),n.jsx("dt",{className:"text-[#71717a]",children:"sent / failed"}),n.jsxs("dd",{className:"font-mono text-[#e4e4e7]",children:[n.jsx("span",{className:"text-[#10b981]",children:i.sentCount})," / ",n.jsx("span",{className:i.failedCount>0?"text-[#ef4444]":"text-[#71717a]",children:i.failedCount}),i.lastEventType&&n.jsxs("span",{className:"text-[#71717a]",children:[" · last event: ",n.jsx("span",{className:"text-[#a1a1aa]",children:i.lastEventType})]})]}),n.jsx("dt",{className:"text-[#71717a]",children:"last attempt"}),n.jsxs("dd",{className:"font-mono text-[#e4e4e7] flex items-center gap-1",children:[n.jsx(us,{className:"w-3 h-3 text-[#71717a]"}),i.lastAttemptAt?new Date(i.lastAttemptAt).toLocaleString():"—"]}),n.jsx("dt",{className:"text-[#71717a]",children:"last success"}),n.jsx("dd",{className:"font-mono text-[#e4e4e7]",children:i.lastSuccessAt?new Date(i.lastSuccessAt).toLocaleString():"—"}),i.lastError&&n.jsxs(n.Fragment,{children:[n.jsx("dt",{className:"text-[#ef4444]",children:"last error"}),n.jsx("dd",{className:"font-mono text-[#fca5a5] break-all",children:i.lastError})]})]}):n.jsx("div",{className:"text-xs text-[#71717a]",children:"Checking collector reachability…"})]}),n.jsxs("div",{className:"mb-4 p-3 rounded-lg border border-[#27272a]/60 bg-[#0a0a0f]",children:[n.jsx("div",{className:"text-[10px] text-[#71717a] uppercase tracking-wider mb-1",children:"Collector"}),n.jsx("div",{className:"font-mono text-[11px] text-[#a1a1aa] break-all",children:(t==null?void 0:t.remoteUrl)||"—"})]}),n.jsxs("div",{className:"flex items-center gap-3 text-[11px]",children:[n.jsxs("a",{href:"https://github.com/Djtony707/TITAN/blob/main/PRIVACY.md",target:"_blank",rel:"noreferrer",className:"flex items-center gap-1 text-[#6366f1] hover:underline",children:[n.jsx(ai,{className:"w-3 h-3"})," Read the full PRIVACY.md"]}),n.jsx("span",{className:"text-[#52525b]",children:"·"}),n.jsxs("a",{href:"https://github.com/Djtony707/TITAN/blob/main/src/analytics/collector.ts",target:"_blank",rel:"noreferrer",className:"flex items-center gap-1 text-[#6366f1] hover:underline",children:[n.jsx(ai,{className:"w-3 h-3"})," See the collector source"]})]})]})}const hm=oe.lazy(()=>le(()=>import("./AutopilotPanel-DlcdfRRy.js"),__vite__mapDeps([50,1,2,35,14])));function fm(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(hm,{})})})}const pm=oe.lazy(()=>le(()=>import("./WorkflowsPanel-D2DiOBLA.js"),__vite__mapDeps([51,1,2,35,14,3,4,10,11,12,22,25,38,40,16,26,20,52,42,21,15,29,41,43,30,24,37,44,45,46])));function mm(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(pm,{})})})}const gm=oe.lazy(()=>le(()=>import("./LearningPanel-B8tqHeEZ.js"),__vite__mapDeps([53,1,2,35,14,12,15,54,55,42,25,21,29,41,43,30,24,37,38,44,20,11,45,46])));function ym(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(gm,{})})})}const bm=oe.lazy(()=>le(()=>import("./SelfImprovePanel-DXIfG_df.js"),__vite__mapDeps([56,1,2,12,36,20,57,55,15,38,14,40,26,42,25,21,29,41,43,30,24,37,44,11,45,46])));function xm(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(bm,{})})})}const wm=oe.lazy(()=>le(()=>import("./PersonasPanel-BNogLwM0.js"),__vite__mapDeps([58,1,2])));function vm(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(wm,{})})})}const _m=oe.lazy(()=>le(()=>import("./PersonaProfilesPanel-BO87DSVG.js"),__vite__mapDeps([59,1,2,35,14,12,11,16,37,38,20])));function km(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(_m,{})})})}const Sm=oe.lazy(()=>le(()=>import("./DreamPanel-DF6l0WB-.js"),__vite__mapDeps([60,1,2,35,14,12])));function jm(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(Sm,{})})})}const Em=oe.lazy(()=>le(()=>import("./HomelabPanel-D373ddvj.js"),__vite__mapDeps([61,1,2,35,14,62,63,4,12,20,21,19,29,36,17,42,25,15,41,43,30,24,37,38,44,11,45,46])));function Nm(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(Em,{})})})}const Cm=oe.lazy(()=>le(()=>import("./NvidiaPanel-D7qFbbeJ.js"),__vite__mapDeps([64,1,2,12,41,36,46,30])));function Tm(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(Cm,{})})})}const Rm=oe.lazy(()=>le(()=>import("./FilesPanel-BjuDhqaX.js"),__vite__mapDeps([65,1,2,25,12,14,66,20,26,41,39,11,21,42,15,29,43,30,24,37,38,44,45,46])));function Am(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(Rm,{})})})}const Lm=oe.lazy(()=>le(()=>import("./LogsPanel-sXc__trb.js"),__vite__mapDeps([67,1,2,12])));function Im(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(Lm,{})})})}const Dm=oe.lazy(()=>le(()=>import("./TelemetryPanel-DL81QlAW.js"),__vite__mapDeps([68,1,2,62,20,18,19,42,25,21,15,29,12,41,43,30,24,37,14,38,44,11,45,46])));function Mm(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(Dm,{})})})}const Om=oe.lazy(()=>le(()=>import("./SkillsPanel-6fbRov-m.js"),__vite__mapDeps([69,1,2,35,14,30,26,39])));function Wm(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(Om,{})})})}const Pm=oe.lazy(()=>le(()=>import("./McpPanel-DEr8pZwB.js"),__vite__mapDeps([70,1,2,71,12,25,26,42,21,15,29,41,43,30,24,37,14,38,44,20,11,45,46])));function Bm(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(Pm,{})})})}const Um=oe.lazy(()=>le(()=>import("./IntegrationsPanel-kPa5Qq-f.js"),__vite__mapDeps([72,1,2,71,36,41,38,14])));function Fm(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(Um,{})})})}const $m=oe.lazy(()=>le(()=>import("./ChannelsPanel-khiBHwx3.js"),__vite__mapDeps([73,1,2,35,14,12,36,38,41])));function zm(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx($m,{})})})}const Hm=oe.lazy(()=>le(()=>import("./MeshPanel-b77zyQx4.js"),__vite__mapDeps([74,1,2,75,12,45])));function Vm(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(Hm,{})})})}const Gm=oe.lazy(()=>le(()=>import("./MemoryWikiPanel-DTNVWvVT.js"),__vite__mapDeps([76,1,2,35,14,66,20,30,42,25,21,15,29,12,41,43,24,37,38,44,11,45,46])));function qm(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(Gm,{})})})}const Ym=oe.lazy(()=>le(()=>import("./AutoresearchPanel-CXeO6kGK.js"),__vite__mapDeps([77,1,2,44,40,16,12,57,55,20,38,14])));function Km(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(Ym,{})})})}const Jm=oe.lazy(()=>le(()=>import("./SelfProposalsPanel-CmgEz1TQ.js"),__vite__mapDeps([78,1,2,35,14,20,42,25,21,15,29,12,41,43,30,24,37,38,44,11,45,46])));function Xm(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(Jm,{})})})}const Qm=oe.lazy(()=>le(()=>import("./OverviewPanel-Bectj1Z5.js"),__vite__mapDeps([79,1,2,62,35,14,63,4,20,21,80,42,25,15,29,12,41,43,30,24,37,38,44,11,45,46])));function Zm(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(Qm,{})})})}const eg=oe.lazy(()=>le(()=>import("./SessionsPanel-gJXosEGf.js"),__vite__mapDeps([81,1,2,35,14,3,4,75,10,11,12,30,26])));function tg(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(eg,{})})})}const sg=oe.lazy(()=>le(()=>import("./WatchView-C92y0hU7.js"),__vite__mapDeps([82,1,2,9])));function ng(){return n.jsx("div",{className:"w-full h-full overflow-auto",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(sg,{})})})}const rg=oe.lazy(()=>le(()=>import("./BackupPanel-CKb-cDsk.js"),__vite__mapDeps([83,1,2,35,14,25,12,36,42,21,15,29,41,43,30,24,37,38,44,20,11,45,46])));function ig(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(rg,{})})})}const og=oe.lazy(()=>le(()=>import("./TrainingPanel-4XMGaRN_.js"),__vite__mapDeps([84,1,2,35,14,12,39,42,25,21,15,29,41,43,30,24,37,38,44,20,11,45,46])));function ag(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(og,{})})})}const lg=oe.lazy(()=>le(()=>import("./RecipesPanel-DyqfWlaY.js"),__vite__mapDeps([85,1,2,35,14,12,40,26,42,25,21,15,29,41,43,30,24,37,38,44,20,11,45,46])));function cg(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(lg,{})})})}const dg=oe.lazy(()=>le(()=>import("./VramPanel-HisAYiqI.js"),__vite__mapDeps([86,1,2,35,14,12])));function ug(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(dg,{})})})}const hg=oe.lazy(()=>le(()=>import("./TeamsPanel-CNaQ8Dbw.js"),__vite__mapDeps([87,1,2,35,14,12,21,26])));function fg(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(hg,{})})})}const pg=oe.lazy(()=>le(()=>import("./CronPanel-BkRJl8u6.js"),__vite__mapDeps([88,1,2,35,14,12,20,52,26])));function mg(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(pg,{})})})}const gg=oe.lazy(()=>le(()=>import("./CheckpointsPanel-n2y3jzzT.js"),__vite__mapDeps([89,1,2,35,14,12,41,26])));function yg(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(gg,{})})})}const bg=oe.lazy(()=>le(()=>import("./OrganismPanel-EiQ9Gfqx.js"),__vite__mapDeps([90,1,2,35,14,12,36])));function xg(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(bg,{})})})}const wg=oe.lazy(()=>le(()=>import("./FleetPanel-B0ZhS2XX.js"),__vite__mapDeps([91,1,2,35,14,12,42,25,21,15,29,41,43,30,24,37,38,44,20,11,45,46])));function vg(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(wg,{})})})}const _g=oe.lazy(()=>le(()=>import("./BrowserPanel-CDaoF6n5.js"),__vite__mapDeps([92,1,2,35,14])));function kg(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(_g,{})})})}const Sg=oe.lazy(()=>le(()=>import("./EvalPanel-yAesMLSP.js"),__vite__mapDeps([93,1,2,35,14,12,40])));function jg(){return n.jsx("div",{className:"w-full h-full overflow-auto p-4",children:n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"text-xs text-[#52525b]",children:"Loading..."}),children:n.jsx(Sg,{})})})}function Eg(t){const e=Date.now()-new Date(t).getTime();if(!Number.isFinite(e)||e<0)return t;const s=Math.floor(e/1e3);if(s<60)return`${s}s ago`;const r=Math.floor(s/60);if(r<60)return`${r}m ago`;const i=Math.floor(r/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function Ng(t){const e=Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\"));return e>=0?t.slice(e+1):t}function Cg(){const[t,e]=w.useState([]),[s,r]=w.useState(!0),[i,o]=w.useState(""),[c,l]=w.useState(null),[d,p]=w.useState(""),[g,u]=w.useState(!1),[f,x]=w.useState(null),[b,E]=w.useState(null),[A,v]=w.useState(null),L=w.useCallback(async()=>{r(!0),x(null);try{const N=await ye("/api/time-travel/checkpoints?limit=100");if(!N.ok)throw new Error(`${N.status} ${N.statusText}`);const D=await N.json();e(D.checkpoints||[])}catch(N){x(N.message||"Failed to load")}finally{r(!1)}},[]);w.useEffect(()=>{L()},[L]);const m=w.useCallback((N,D)=>{v({kind:N,message:D}),setTimeout(()=>v(null),4e3)},[]),k=w.useCallback(async N=>{l(N),p(""),u(!0);try{const D=await ye(`/api/time-travel/diff/${encodeURIComponent(N)}`);if(!D.ok)throw new Error(`${D.status} ${D.statusText}`);const j=await D.json();p(j.diff||"(no diff returned)")}catch(D){p(`Failed to load diff: ${D.message}`)}finally{u(!1)}},[]),_=w.useCallback(N=>{E(N)},[]),T=w.useCallback(async()=>{if(!b)return;const N=b;E(null);try{const D=await ye(`/api/time-travel/restore/${encodeURIComponent(N)}`,{method:"POST"});if(!D.ok)throw new Error(`${D.status} ${D.statusText}`);const j=await D.json();j.ok?(m("ok",j.message||`Restored to ${N.slice(0,8)}.`),L()):m("err",j.message||"Restore failed.")}catch(D){m("err",D.message||"Restore failed.")}},[b,L,m]),S=w.useMemo(()=>{const N=i.trim().toLowerCase();return N?t.filter(D=>D.filePath.toLowerCase().includes(N)||D.toolName.toLowerCase().includes(N)||D.id.toLowerCase().includes(N)):t},[t,i]);return n.jsxs("div",{style:{width:"100%",height:"100%",display:"flex",flexDirection:"column",color:"#e2e8f5",fontSize:12,background:"transparent"},children:[n.jsxs("div",{style:{padding:"10px 14px",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:13,fontWeight:600},children:"Time Travel"}),n.jsxs("div",{style:{fontSize:10,color:"rgba(255,255,255,0.45)"},children:[t.length," file checkpoints · newest first"]})]}),n.jsxs("div",{style:{display:"flex",gap:6},children:[n.jsx("input",{type:"text",value:i,onChange:N=>o(N.target.value),placeholder:"Filter by file or tool…",style:{background:"rgba(255,255,255,0.04)",border:"1px solid rgba(255,255,255,0.08)",borderRadius:6,color:"#fff",fontSize:11,padding:"4px 8px",outline:"none",width:180}}),n.jsx("button",{onClick:L,disabled:s,title:"Refresh checkpoint list",style:{background:"rgba(99,102,241,0.15)",border:"1px solid rgba(99,102,241,0.35)",borderRadius:6,color:"#c7d2fe",fontSize:11,padding:"4px 10px",cursor:s?"wait":"pointer"},children:s?"…":"Refresh"})]})]}),A&&n.jsx("div",{style:{margin:"8px 14px 0",padding:"6px 10px",borderRadius:6,background:A.kind==="ok"?"rgba(34,197,94,0.12)":"rgba(239,68,68,0.12)",border:`1px solid ${A.kind==="ok"?"rgba(34,197,94,0.3)":"rgba(239,68,68,0.3)"}`,color:A.kind==="ok"?"#86efac":"#fca5a5",fontSize:11},children:A.message}),f&&n.jsx("div",{style:{margin:"8px 14px 0",padding:"6px 10px",borderRadius:6,background:"rgba(239,68,68,0.12)",border:"1px solid rgba(239,68,68,0.3)",color:"#fca5a5",fontSize:11},children:f}),n.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[n.jsx("div",{style:{flex:1,overflow:"auto",borderRight:"1px solid rgba(255,255,255,0.06)"},children:s&&t.length===0?n.jsx("div",{style:{padding:16,color:"rgba(255,255,255,0.4)"},children:"Loading checkpoints…"}):S.length===0?n.jsx("div",{style:{padding:16,color:"rgba(255,255,255,0.4)"},children:i?"No matches for that filter.":"No file checkpoints yet. They're created automatically whenever TITAN writes or edits a file."}):S.map(N=>n.jsxs("div",{onClick:()=>k(N.id),style:{padding:"8px 14px",borderBottom:"1px solid rgba(255,255,255,0.04)",cursor:"pointer",background:c===N.id?"rgba(99,102,241,0.08)":"transparent",borderLeft:c===N.id?"2px solid #818cf8":"2px solid transparent"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:2},children:[n.jsx("span",{style:{fontSize:11,fontFamily:"ui-monospace, monospace",color:"#a5b4fc"},children:N.commitHash.slice(0,8)}),n.jsx("span",{style:{fontSize:10,color:"rgba(255,255,255,0.5)"},children:Eg(N.timestamp)})]}),n.jsx("div",{style:{fontSize:12,color:"#e2e8f5",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:N.filePath,children:Ng(N.filePath)}),n.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginTop:4},children:[n.jsxs("span",{style:{fontSize:10,color:"rgba(255,255,255,0.4)"},children:["before ",n.jsx("code",{style:{color:"#fbbf24"},children:N.toolName})]}),n.jsx("button",{onClick:D=>{D.stopPropagation(),_(N.id)},title:"Restore this file to the state it was in at this checkpoint",style:{fontSize:10,padding:"2px 8px",borderRadius:999,background:"rgba(34,197,94,0.12)",border:"1px solid rgba(34,197,94,0.3)",color:"#86efac",cursor:"pointer"},children:"Restore"})]})]},N.id))}),n.jsx("div",{style:{flex:1,overflow:"auto",padding:14},children:c?g?n.jsx("div",{style:{color:"rgba(255,255,255,0.4)"},children:"Loading diff…"}):n.jsx("pre",{style:{margin:0,fontFamily:'ui-monospace, "SF Mono", Menlo, monospace',fontSize:11,lineHeight:1.5,color:"#e2e8f5",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:(d||"").split(`
|
|
1029
|
+
`).map((N,D)=>{let j="rgba(255,255,255,0.7)";return N.startsWith("+")&&!N.startsWith("+++")?j="#86efac":N.startsWith("-")&&!N.startsWith("---")?j="#fca5a5":N.startsWith("@@")?j="#a5b4fc":(N.startsWith("diff")||N.startsWith("index")||N.startsWith("+++")||N.startsWith("---"))&&(j="rgba(255,255,255,0.45)"),n.jsx("div",{style:{color:j},children:N||" "},D)})}):n.jsx("div",{style:{color:"rgba(255,255,255,0.4)"},children:"Select a checkpoint on the left to see its diff vs the current file."})})]}),b&&n.jsx("div",{onClick:()=>E(null),style:{position:"absolute",inset:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:10},children:n.jsxs("div",{onClick:N=>N.stopPropagation(),style:{background:"#0d0f1d",border:"1px solid rgba(255,255,255,0.1)",borderRadius:10,padding:18,maxWidth:380,color:"#e2e8f5"},children:[n.jsx("div",{style:{fontSize:14,fontWeight:600,marginBottom:8},children:"Restore this checkpoint?"}),n.jsxs("div",{style:{fontSize:12,color:"rgba(255,255,255,0.7)",marginBottom:12},children:["The file will be overwritten with its state at ",n.jsx("code",{children:b.slice(0,8)}),". A NEW checkpoint of the current state is taken first, so you can always come back."]}),n.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[n.jsx("button",{onClick:()=>E(null),style:{background:"rgba(255,255,255,0.05)",border:"1px solid rgba(255,255,255,0.1)",color:"#e2e8f5",borderRadius:6,padding:"6px 12px",fontSize:12,cursor:"pointer"},children:"Cancel"}),n.jsx("button",{onClick:T,style:{background:"rgba(34,197,94,0.18)",border:"1px solid rgba(34,197,94,0.4)",color:"#86efac",borderRadius:6,padding:"6px 12px",fontSize:12,cursor:"pointer"},children:"Restore"})]})]})})]})}const Vi=5e3,Gi={planning:"#a5b4fc",delegating:"#60a5fa",observing:"#22d3ee",iterating:"#f59e0b",verifying:"#a78bfa",reporting:"#34d399",blocked:"#facc15",escalated:"#fb7185",done:"#34d399",failed:"#ef4444",cancelled:"#737373"};function Tg(t){if(!Number.isFinite(t)||t<0)return"—";const e=Math.floor(t/1e3);if(e<60)return`${e}s`;const s=Math.floor(e/60);if(s<60)return`${s}m`;const r=Math.floor(s/60),i=s%60;return`${r}h ${i}m`}function Rg(t){return t===0?"$0":t<.01?"$<0.01":`$${t.toFixed(2)}`}function Ag(){const[t,e]=w.useState([]),[s,r]=w.useState(!0),[i,o]=w.useState(null),[c,l]=w.useState(!1),[d,p]=w.useState(""),[g,u]=w.useState(2),[f,x]=w.useState(!1),[b,E]=w.useState(null),A=w.useCallback(async()=>{try{const _=await ye("/api/missions/active");if(!_.ok)throw new Error(`${_.status} ${_.statusText}`);const T=await _.json();e(T.missions||[]),o(null)}catch(_){o(_.message||"failed to load")}finally{r(!1)}},[]);w.useEffect(()=>{A();const _=setInterval(A,Vi);return()=>clearInterval(_)},[A]);const v=w.useCallback((_,T)=>{E({kind:_,message:T}),setTimeout(()=>E(null),5e3)},[]),L=w.useCallback(async()=>{var T;const _=d.trim();if(_.length<10){v("err","Describe the mission (>=10 chars).");return}x(!0);try{const S=await ye("/api/mission/run",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({description:_,budgetUsd:g})});if(!S.ok)throw new Error(`${S.status} ${S.statusText}`);const N=await S.json();v("ok",N.message||`Mission "${((T=N.goal)==null?void 0:T.title)??"?"}" launched.`),p(""),l(!1),A()}catch(S){v("err",S.message||"launch failed")}finally{x(!1)}},[d,g,A,v]),m=w.useCallback(async _=>{try{const T=await ye(`/api/mission/${encodeURIComponent(_)}/cancel`,{method:"POST"});if(!T.ok)throw new Error(`${T.status} ${T.statusText}`);v("ok","Mission marked for cancellation."),A()}catch(T){v("err",T.message||"cancel failed")}},[A,v]),k=w.useMemo(()=>{const _={delegating:0,observing:1,iterating:2,verifying:3,planning:4,reporting:5,blocked:6,escalated:7};return[...t].sort((T,S)=>(_[T.phase]??99)-(_[S.phase]??99))},[t]);return n.jsxs("div",{style:{width:"100%",height:"100%",display:"flex",flexDirection:"column",color:"#e2e8f5",background:"transparent"},children:[n.jsxs("div",{style:{padding:"10px 14px",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:13,fontWeight:600},children:"Mission Driver"}),n.jsxs("div",{style:{fontSize:10,color:"rgba(255,255,255,0.45)"},children:[t.length," active · polling every ",Vi/1e3,"s"]})]}),n.jsxs("div",{style:{display:"flex",gap:6},children:[n.jsx("button",{onClick:()=>l(_=>!_),title:"Launch a new autonomous mission",style:{fontSize:11,padding:"4px 10px",borderRadius:6,border:"1px solid rgba(99,102,241,0.4)",background:c?"rgba(99,102,241,0.25)":"rgba(99,102,241,0.12)",color:"#c7d2fe",cursor:"pointer"},children:c?"× Close":"+ New mission"}),n.jsx("button",{onClick:A,title:"Refresh",style:{fontSize:11,padding:"4px 10px",borderRadius:6,border:"1px solid rgba(255,255,255,0.1)",background:"rgba(255,255,255,0.04)",color:"#e2e8f5",cursor:"pointer"},children:"↻"})]})]}),b&&n.jsx("div",{style:{margin:"8px 14px 0",padding:"6px 10px",borderRadius:6,fontSize:11,background:b.kind==="ok"?"rgba(34,197,94,0.12)":"rgba(239,68,68,0.12)",border:`1px solid ${b.kind==="ok"?"rgba(34,197,94,0.3)":"rgba(239,68,68,0.3)"}`,color:b.kind==="ok"?"#86efac":"#fca5a5"},children:b.message}),c&&n.jsxs("div",{style:{padding:12,borderBottom:"1px solid rgba(255,255,255,0.06)",background:"rgba(99,102,241,0.04)"},children:[n.jsx("div",{style:{fontSize:10,textTransform:"uppercase",letterSpacing:.6,color:"#a5b4fc",marginBottom:6},children:"Describe the mission"}),n.jsx("textarea",{value:d,onChange:_=>p(_.target.value),placeholder:"e.g. 'Research the top 5 AI agent frameworks for 2026, summarize their differentiation in a markdown report, and save to ~/Documents/agent-research.md'",rows:3,style:{width:"100%",background:"rgba(255,255,255,0.04)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:6,color:"#fff",fontSize:12,padding:"6px 10px",resize:"vertical",fontFamily:"inherit",boxSizing:"border-box"}}),n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:8,gap:8},children:[n.jsxs("label",{style:{fontSize:11,color:"rgba(255,255,255,0.6)"},children:["Budget cap: $",n.jsx("input",{type:"number",value:g,onChange:_=>u(Math.max(.05,Math.min(50,Number(_.target.value)||2))),step:"0.5",min:"0.05",max:"50",style:{width:60,marginLeft:4,background:"rgba(255,255,255,0.04)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:4,color:"#fff",fontSize:11,padding:"2px 6px"}})]}),n.jsx("button",{onClick:L,disabled:f||d.trim().length<10,style:{fontSize:12,padding:"6px 14px",borderRadius:6,border:"none",background:f?"rgba(255,255,255,0.05)":"rgba(34,197,94,0.18)",color:"#86efac",cursor:f?"wait":"pointer",fontWeight:600},children:f?"Decomposing…":"🚀 Launch"})]})]}),n.jsxs("div",{style:{flex:1,overflow:"auto",padding:8},children:[i&&n.jsx("div",{style:{padding:10,color:"#fca5a5",fontSize:11},children:i}),s&&t.length===0?n.jsx("div",{style:{padding:16,color:"rgba(255,255,255,0.4)",fontSize:12},children:"Loading missions…"}):k.length===0?n.jsxs("div",{style:{padding:24,color:"rgba(255,255,255,0.45)",fontSize:12,textAlign:"center"},children:["No active missions.",n.jsx("br",{}),n.jsx("span",{style:{fontSize:11,color:"rgba(255,255,255,0.35)"},children:'Click "+ New mission" to launch one.'})]}):k.map(_=>{const T=Gi[_.phase]??"#94a3b8",S=_.subtasks.total>0?Math.round(_.subtasks.completed/_.subtasks.total*100):0;return n.jsxs("div",{style:{padding:"10px 12px",marginBottom:6,borderRadius:8,background:"rgba(255,255,255,0.025)",border:`1px solid ${_.phase==="blocked"?"rgba(250,204,21,0.4)":"rgba(255,255,255,0.06)"}`},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:4},children:[n.jsx("div",{style:{fontSize:12,fontWeight:600,color:"#fafafa",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:_.title,children:_.title}),n.jsx("button",{onClick:()=>m(_.goalId),title:"Cancel this mission",style:{fontSize:10,padding:"2px 8px",borderRadius:999,background:"rgba(239,68,68,0.1)",border:"1px solid rgba(239,68,68,0.3)",color:"#fca5a5",cursor:"pointer",marginLeft:6},children:"Cancel"})]}),n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:10,color:"rgba(255,255,255,0.7)"},children:[n.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:4,padding:"1px 6px",borderRadius:4,background:`${T}22`,border:`1px solid ${T}55`,color:T,textTransform:"uppercase",letterSpacing:.5,fontWeight:600,fontSize:9},children:_.phase}),n.jsxs("span",{children:[_.subtasks.completed,"/",_.subtasks.total," subtasks (",S,"%)"]}),n.jsx("span",{children:"·"}),n.jsx("span",{children:Rg(_.budget.costUsd)}),n.jsx("span",{children:"·"}),n.jsx("span",{children:Tg(Date.now()-new Date(_.startedAt).getTime())})]}),_.blockedReason&&n.jsxs("div",{style:{marginTop:6,padding:"6px 8px",borderRadius:4,background:"rgba(250,204,21,0.08)",border:"1px solid rgba(250,204,21,0.25)",fontSize:11,color:"#fde68a"},children:[n.jsx("strong",{children:"Blocked:"})," ",_.blockedReason.question??"(no reason)"]}),_.lastHistory.length>0&&n.jsx("div",{style:{marginTop:6,fontSize:10,color:"rgba(255,255,255,0.45)",display:"flex",flexDirection:"column",gap:1},children:_.lastHistory.slice(-3).map((N,D)=>n.jsxs("div",{style:{display:"flex",gap:6,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[n.jsx("span",{style:{color:Gi[N.phase]??"rgba(255,255,255,0.6)",minWidth:70,fontFamily:"ui-monospace, monospace",fontSize:9},children:N.phase}),n.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:N.note??""})]},D))})]},_.goalId)})]})]})}const Lg=6e4,Ig=[{label:"6h",hours:6},{label:"24h",hours:24},{label:"7d",hours:168}];function Dg(t){return t===0?"$0":t<.01?"$<0.01":`$${t.toFixed(2)}`}function Mg(t){return t<1e3?String(t):t<1e6?`${(t/1e3).toFixed(1)}k`:`${(t/1e6).toFixed(2)}M`}function Og(){const[t,e]=w.useState(24),[s,r]=w.useState(null),[i,o]=w.useState(!0),[c,l]=w.useState(null),d=w.useCallback(async()=>{o(!0);try{const p=await ye(`/api/missions/digest?hours=${t}`);if(!p.ok)throw new Error(`${p.status} ${p.statusText}`);const g=await p.json();r(g),l(null)}catch(p){l(p.message||"failed")}finally{o(!1)}},[t]);return w.useEffect(()=>{d();const p=setInterval(d,Lg);return()=>clearInterval(p)},[d]),n.jsxs("div",{style:{width:"100%",height:"100%",display:"flex",flexDirection:"column",color:"#e2e8f5",background:"transparent"},children:[n.jsxs("div",{style:{padding:"10px 14px",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:13,fontWeight:600},children:"Daily digest"}),n.jsx("div",{style:{fontSize:10,color:"rgba(255,255,255,0.45)"},children:"what TITAN did while you were away"})]}),n.jsx("div",{style:{display:"flex",gap:4},children:Ig.map(p=>n.jsx("button",{onClick:()=>e(p.hours),style:{fontSize:10,padding:"3px 8px",borderRadius:4,border:"1px solid rgba(255,255,255,0.1)",background:t===p.hours?"rgba(99,102,241,0.25)":"rgba(255,255,255,0.03)",color:t===p.hours?"#c7d2fe":"rgba(255,255,255,0.65)",cursor:"pointer"},children:p.label},p.label))})]}),s&&n.jsxs("div",{style:{padding:"10px 14px",borderBottom:"1px solid rgba(255,255,255,0.04)",display:"grid",gridTemplateColumns:"repeat(4, 1fr)",gap:8},children:[n.jsx(Os,{label:"Done",value:s.stats.completed,color:"#34d399"}),n.jsx(Os,{label:"Failed",value:s.stats.failed,color:s.stats.failed>0?"#fca5a5":"rgba(255,255,255,0.5)"}),n.jsx(Os,{label:"Active",value:s.stats.active,color:"#60a5fa"}),n.jsx(Os,{label:"Blocked",value:s.stats.blocked,color:s.stats.blocked>0?"#facc15":"rgba(255,255,255,0.5)"})]}),s&&(s.stats.totalCostUsd>0||s.stats.totalTokens>0)&&n.jsxs("div",{style:{padding:"6px 14px",borderBottom:"1px solid rgba(255,255,255,0.04)",fontSize:10,color:"rgba(255,255,255,0.55)",display:"flex",justifyContent:"space-between"},children:[n.jsxs("span",{children:["Spend: ",n.jsx("strong",{style:{color:"#e2e8f5"},children:Dg(s.stats.totalCostUsd)})]}),n.jsxs("span",{children:["Tokens: ",n.jsx("strong",{style:{color:"#e2e8f5"},children:Mg(s.stats.totalTokens)})]})]}),n.jsxs("div",{style:{flex:1,overflow:"auto",padding:14},children:[i&&!s&&n.jsx("div",{style:{color:"rgba(255,255,255,0.4)",fontSize:11},children:"Loading…"}),c&&n.jsx("div",{style:{color:"#fca5a5",fontSize:11},children:c}),s&&n.jsxs(n.Fragment,{children:[n.jsx("pre",{style:{margin:0,fontFamily:'ui-monospace, "SF Mono", Menlo, monospace',fontSize:11,lineHeight:1.55,color:"#e2e8f5",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:s.summaryText||"(no activity in this window)"}),s.recentLessons.length>0&&n.jsxs("div",{style:{marginTop:16,paddingTop:12,borderTop:"1px solid rgba(255,255,255,0.06)"},children:[n.jsx("div",{style:{fontSize:10,textTransform:"uppercase",letterSpacing:.6,color:"#a5b4fc",marginBottom:6},children:"Lessons learned (Reflexion)"}),s.recentLessons.map((p,g)=>n.jsxs("div",{style:{fontSize:11,color:"rgba(255,255,255,0.8)",padding:"4px 0",borderBottom:"1px dashed rgba(255,255,255,0.04)"},children:["• ",p]},g))]})]})]})]})}function Os({label:t,value:e,color:s}){return n.jsxs("div",{style:{textAlign:"center",padding:"6px 4px",borderRadius:6,background:"rgba(255,255,255,0.02)"},children:[n.jsx("div",{style:{fontSize:18,fontWeight:700,color:s,lineHeight:1},children:e}),n.jsx("div",{style:{fontSize:9,color:"rgba(255,255,255,0.5)",textTransform:"uppercase",letterSpacing:.5,marginTop:4},children:t})]})}const Ws={pending:"#737373",running:"#60a5fa",done:"#34d399",failed:"#ef4444",skipped:"#a78bfa"},qi=6e3,_t=180,er=64,Yi=96,Ps=24;function Wg(t){const e=new Map,s=new Map(t.map(i=>[i.id,i])),r=(i,o)=>{if(e.has(i))return e.get(i);if(o.has(i))return 0;const c=s.get(i);if(!c)return 0;o.add(i);const l=(c.dependsOn??[]).filter(p=>s.has(p)),d=l.length===0?0:Math.max(...l.map(p=>r(p,o)))+1;return o.delete(i),e.set(i,d),d};for(const i of t)r(i.id,new Set);return e}function Pg(){const[t,e]=w.useState([]),[s,r]=w.useState(null),[i,o]=w.useState(null),[c,l]=w.useState(null),[d,p]=w.useState(null),g=w.useCallback(async()=>{try{const v=await ye("/api/missions/active");if(!v.ok)throw new Error(`${v.status} ${v.statusText}`);const m=(await v.json()).missions||[];e(m),!s&&m.length>0&&r(m[0].goalId)}catch(v){l(v.message||"failed")}},[s]),u=w.useCallback(async v=>{try{const L=await ye(`/api/mission/${encodeURIComponent(v)}`);if(!L.ok)throw new Error(`${L.status} ${L.statusText}`);const m=await L.json();o(m),l(null)}catch(L){l(L.message||"failed to load mission"),o(null)}},[]);w.useEffect(()=>{g();const v=setInterval(g,qi);return()=>clearInterval(v)},[g]),w.useEffect(()=>{if(!s){o(null);return}u(s);const v=setInterval(()=>u(s),qi);return()=>clearInterval(v)},[s,u]);const{layout:f,edges:x,viewBox:b}=w.useMemo(()=>{if(!(i!=null&&i.goal.subtasks))return{layout:[],edges:[],viewBox:"0 0 600 200"};const v=i.goal.subtasks,L=Wg(v),m=new Map;for(const R of v){const O=L.get(R.id)??0;m.has(O)||m.set(O,[]),m.get(O).push(R)}const k=Array.from(m.keys()).sort((R,O)=>R-O),_=Math.max(...Array.from(m.values()).map(R=>R.length),1),T=Math.max(640,_*(_t+Ps)+Ps),S=k.length*Yi+er+40,N=new Map,D=[];for(const R of k){const O=m.get(R),U=O.length*_t+(O.length-1)*Ps,z=(T-U)/2,G=R*Yi+20;for(let q=0;q<O.length;q++){const P=z+q*(_t+Ps);N.set(O[q].id,{x:P,y:G}),D.push({...O[q],x:P,y:G})}}const j=[];for(const R of v){const O=N.get(R.id);if(O)for(const U of R.dependsOn??[]){const z=N.get(U);z&&j.push({from:U,to:R.id,x1:z.x+_t/2,y1:z.y+er,x2:O.x+_t/2,y2:O.y})}}return{layout:D,edges:j,viewBox:`0 0 ${T} ${S}`}},[i]),E=w.useMemo(()=>new Map(((i==null?void 0:i.goal.subtasks)??[]).map(v=>[v.id,v])),[i]),A=d?E.get(d):null;return n.jsxs("div",{style:{width:"100%",height:"100%",display:"flex",flexDirection:"column",color:"#e2e8f5",background:"transparent"},children:[n.jsxs("div",{style:{padding:"10px 14px",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",gap:10},children:[n.jsxs("div",{style:{flex:1},children:[n.jsx("div",{style:{fontSize:13,fontWeight:600},children:"Mission graph"}),n.jsxs("div",{style:{fontSize:10,color:"rgba(255,255,255,0.45)"},children:[t.length," active mission(s) · subtask DAG"]})]}),t.length>0&&n.jsx("select",{value:s??"",onChange:v=>r(v.target.value||null),style:{background:"rgba(255,255,255,0.04)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:6,color:"#fff",fontSize:11,padding:"4px 8px",maxWidth:240},children:t.map(v=>n.jsxs("option",{value:v.goalId,children:[v.title," [",v.phase,"]"]},v.goalId))})]}),c&&n.jsx("div",{style:{padding:10,color:"#fca5a5",fontSize:11},children:c}),n.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[n.jsx("div",{style:{flex:1,overflow:"auto",padding:14},children:i?f.length===0?n.jsx("div",{style:{padding:24,color:"rgba(255,255,255,0.45)",fontSize:12,textAlign:"center"},children:"This mission has no subtasks yet."}):n.jsxs("svg",{viewBox:b,style:{width:"100%",height:"auto"},role:"img","aria-label":"Mission subtask DAG",children:[n.jsx("defs",{children:n.jsx("marker",{id:"mg-arrow",viewBox:"0 0 10 10",refX:"10",refY:"5",markerWidth:"6",markerHeight:"6",orient:"auto-start-reverse",children:n.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:"rgba(255,255,255,0.35)"})})}),x.map((v,L)=>n.jsx("line",{x1:v.x1,y1:v.y1,x2:v.x2,y2:v.y2,stroke:"rgba(255,255,255,0.25)",strokeWidth:"1.4",markerEnd:"url(#mg-arrow)"},`e-${L}`)),f.map(v=>{var _;const L=((_=i.driver)==null?void 0:_.currentSubtaskId)===v.id,m=Ws[v.status],k=d===v.id;return n.jsxs("g",{transform:`translate(${v.x}, ${v.y})`,onClick:()=>p(v.id),style:{cursor:"pointer"},children:[n.jsx("rect",{width:_t,height:er,rx:"8",fill:L?`${m}22`:"rgba(255,255,255,0.04)",stroke:k||L?m:`${m}55`,strokeWidth:L||k?2:1}),n.jsx("circle",{cx:14,cy:14,r:"5",fill:m,children:v.status==="running"&&n.jsx("animate",{attributeName:"r",values:"4;6;4",dur:"1.2s",repeatCount:"indefinite"})}),n.jsx("text",{x:28,y:18,fontSize:"11",fontWeight:"600",fill:"#fafafa",children:v.title.length>22?v.title.slice(0,21)+"…":v.title}),n.jsxs("text",{x:28,y:34,fontSize:"9",fill:"rgba(255,255,255,0.55)",letterSpacing:"0.5",style:{textTransform:"uppercase"},children:[v.status,v.retries>0?` · ${v.retries} retr${v.retries===1?"y":"ies"}`:""]}),n.jsxs("text",{x:14,y:52,fontSize:"9",fill:"rgba(255,255,255,0.45)",children:[(v.description||"").slice(0,30),(v.description||"").length>30?"…":""]}),L&&n.jsx("text",{x:_t-8,y:14,fontSize:"8",fill:m,textAnchor:"end",fontWeight:"700",children:"NOW"})]},v.id)})]}):n.jsx("div",{style:{padding:24,color:"rgba(255,255,255,0.45)",fontSize:12,textAlign:"center"},children:t.length===0?"No active missions. Launch one via the Mission Driver widget.":"Select a mission to view its graph."})}),A&&n.jsxs("div",{style:{width:260,borderLeft:"1px solid rgba(255,255,255,0.06)",padding:14,overflow:"auto",fontSize:11},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:8},children:[n.jsx("div",{style:{fontSize:12,fontWeight:700,color:"#fafafa",flex:1},children:A.title}),n.jsx("button",{onClick:()=>p(null),style:{background:"transparent",border:"none",color:"rgba(255,255,255,0.5)",cursor:"pointer",fontSize:14,padding:0,marginLeft:6},children:"×"})]}),n.jsxs("div",{style:{marginBottom:8},children:[n.jsx("span",{style:{padding:"2px 8px",borderRadius:4,fontSize:9,fontWeight:600,textTransform:"uppercase",letterSpacing:.5,background:`${Ws[A.status]}22`,border:`1px solid ${Ws[A.status]}55`,color:Ws[A.status]},children:A.status}),A.retries>0&&n.jsxs("span",{style:{marginLeft:6,color:"rgba(255,255,255,0.5)"},children:[A.retries," retries"]})]}),n.jsx("div",{style:{color:"rgba(255,255,255,0.85)",lineHeight:1.5,marginBottom:10},children:A.description}),A.dependsOn.length>0&&n.jsxs("div",{style:{color:"rgba(255,255,255,0.55)",fontSize:10,marginBottom:6},children:[n.jsx("strong",{children:"Depends on:"})," ",A.dependsOn.map(v=>{var L;return((L=E.get(v))==null?void 0:L.title)||v}).join(", ")]}),A.completedAt&&n.jsxs("div",{style:{color:"rgba(255,255,255,0.45)",fontSize:10},children:["Completed: ",new Date(A.completedAt).toLocaleString()]})]})]}),i&&n.jsxs("div",{style:{padding:"6px 14px",borderTop:"1px solid rgba(255,255,255,0.06)",display:"flex",justifyContent:"space-between",fontSize:10,color:"rgba(255,255,255,0.55)"},children:[n.jsxs("span",{children:[i.goal.subtasks.length," subtasks · ",i.goal.progress,"% progress"]}),i.driver&&n.jsxs("span",{children:[i.driver.phase," · $",i.driver.budget.costUsd.toFixed(2)," spent"]})]})]})}function Bg(){const[t,e]=w.useState([]),[s,r]=w.useState(!0),[i,o]=w.useState(null),c=async()=>{try{const l=await fetch("/api/agents");if(!l.ok)throw new Error(`HTTP ${l.status}`);const d=await l.json();e(Array.isArray(d)?d:d.agents||[]),o(null)}catch(l){o(l.message)}finally{r(!1)}};return w.useEffect(()=>{c();const l=setInterval(c,1e4);return()=>clearInterval(l)},[]),s?n.jsx("div",{className:"w-full h-full flex items-center justify-center",children:n.jsx(Qi,{className:"w-4 h-4 text-[#6366f1] animate-spin"})}):i?n.jsx("div",{className:"w-full h-full flex items-center justify-center p-4",children:n.jsxs("div",{className:"text-center",children:[n.jsx(un,{className:"w-4 h-4 text-red-400 mx-auto mb-1"}),n.jsx("span",{className:"text-[10px] text-red-400",children:i})]})}):t.length===0?n.jsx("div",{className:"w-full h-full flex items-center justify-center p-4",children:n.jsx("span",{className:"text-[10px] text-[#52525b]",children:"No active agents"})}):n.jsx("div",{className:"w-full h-full p-3 overflow-auto",children:n.jsx("div",{className:"space-y-2",children:t.map(l=>n.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-2 rounded-lg bg-[#0a0a0f] border border-[#27272a]",children:[n.jsx(eo,{className:`w-3.5 h-3.5 ${l.status==="busy"?"text-[#f59e0b]":l.status==="error"?"text-red-400":"text-[#6366f1]"}`}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-[11px] text-[#a1a1aa] truncate",children:l.name}),n.jsxs("div",{className:"text-[10px] text-[#52525b] truncate",children:[l.role,l.model?` · ${l.model}`:""]})]}),n.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded-full uppercase ${l.status==="busy"?"bg-[#f59e0b]/10 text-[#f59e0b]":l.status==="error"?"bg-red-400/10 text-red-400":"bg-[#6366f1]/10 text-[#818cf8]"}`,children:l.status})]},l.id))})})}function Ug(){const[t,e]=w.useState(null),[s,r]=w.useState(!0),i=async()=>{try{const[c,l]=await Promise.allSettled([fetch("/api/health").then(g=>g.ok?g.json():null),fetch("/ollama/api/tags").then(g=>g.ok)]),d=c.status==="fulfilled"&&c.value,p=l.status==="fulfilled"&&l.value;e({gateway:d,ollama:p,version:(d==null?void 0:d.version)||"unknown",uptime:(d==null?void 0:d.uptime)||0})}catch{e({gateway:!1,ollama:!1,version:"unknown",uptime:0})}finally{r(!1)}};if(w.useEffect(()=>{i();const c=setInterval(i,3e4);return()=>clearInterval(c)},[]),s)return n.jsx("div",{className:"w-full h-full flex items-center justify-center",children:n.jsx(Qi,{className:"w-4 h-4 text-[#6366f1] animate-spin"})});const o=c=>{const l=Math.floor(c/3600),d=Math.floor(c%3600/60);return`${l}h ${d}m`};return n.jsx("div",{className:"w-full h-full p-3 overflow-auto",children:n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center justify-between px-2.5 py-2 rounded-lg bg-[#0a0a0f] border border-[#27272a]",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[t!=null&&t.gateway?n.jsx(jl,{className:"w-3.5 h-3.5 text-emerald-400"}):n.jsx(oc,{className:"w-3.5 h-3.5 text-red-400"}),n.jsx("span",{className:"text-[11px] text-[#a1a1aa]",children:"TITAN Gateway"})]}),n.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded-full uppercase ${t!=null&&t.gateway?"bg-emerald-400/10 text-emerald-400":"bg-red-400/10 text-red-400"}`,children:t!=null&&t.gateway?"Online":"Offline"})]}),n.jsxs("div",{className:"flex items-center justify-between px-2.5 py-2 rounded-lg bg-[#0a0a0f] border border-[#27272a]",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(gt,{className:`w-3.5 h-3.5 ${t!=null&&t.ollama?"text-emerald-400":"text-red-400"}`}),n.jsx("span",{className:"text-[11px] text-[#a1a1aa]",children:"Ollama"})]}),n.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded-full uppercase ${t!=null&&t.ollama?"bg-emerald-400/10 text-emerald-400":"bg-red-400/10 text-red-400"}`,children:t!=null&&t.ollama?"Online":"Offline"})]}),n.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[n.jsxs("div",{className:"px-2.5 py-2 rounded-lg bg-[#0a0a0f] border border-[#27272a]",children:[n.jsx("div",{className:"text-[9px] text-[#52525b] uppercase tracking-wider",children:"Version"}),n.jsx("div",{className:"text-[11px] text-[#a1a1aa] font-mono mt-0.5",children:t==null?void 0:t.version})]}),n.jsxs("div",{className:"px-2.5 py-2 rounded-lg bg-[#0a0a0f] border border-[#27272a]",children:[n.jsx("div",{className:"text-[9px] text-[#52525b] uppercase tracking-wider",children:"Uptime"}),n.jsx("div",{className:"text-[11px] text-[#a1a1aa] font-mono mt-0.5",children:o((t==null?void 0:t.uptime)||0)})]})]})]})})}function Bs({label:t,value:e,icon:s,color:r}){const i=Math.max(0,Math.min(100,Math.round(e)));return n.jsxs("div",{className:"px-2.5 py-2 rounded-lg bg-[#0a0a0f] border border-[#27272a]",children:[n.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[s,n.jsx("span",{className:"text-[10px] text-[#52525b] uppercase tracking-wider",children:t})]}),n.jsxs("span",{className:"text-[11px] text-[#a1a1aa] font-mono",children:[i,"%"]})]}),n.jsx("div",{className:"h-1.5 rounded-full bg-[#27272a] overflow-hidden",children:n.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${i}%`,backgroundColor:r}})})]})}function Fg(){const[t,e]=w.useState({cpu:0,memory:0,disk:0,load:0});return w.useEffect(()=>{const s=setInterval(()=>{e({cpu:Math.random()*60+10,memory:Math.random()*50+30,disk:Math.random()*40+20,load:Math.random()*30+5})},3e3);return e({cpu:Math.random()*60+10,memory:Math.random()*50+30,disk:Math.random()*40+20,load:Math.random()*30+5}),()=>clearInterval(s)},[]),n.jsx("div",{className:"w-full h-full p-3 overflow-auto",children:n.jsxs("div",{className:"space-y-2",children:[n.jsx(Bs,{label:"CPU",value:t.cpu,icon:n.jsx(vr,{className:"w-3 h-3 text-[#6366f1]"}),color:"#6366f1"}),n.jsx(Bs,{label:"Memory",value:t.memory,icon:n.jsx(El,{className:"w-3 h-3 text-[#a78bfa]"}),color:"#a78bfa"}),n.jsx(Bs,{label:"Disk",value:t.disk,icon:n.jsx(Nl,{className:"w-3 h-3 text-[#10b981]"}),color:"#10b981"}),n.jsx(Bs,{label:"Load",value:t.load,icon:n.jsx(gt,{className:"w-3 h-3 text-[#f59e0b]"}),color:"#f59e0b"})]})})}const $g=[{label:"Nav",source:"system:nav",w:3,h:4,icon:n.jsx(Ul,{className:"w-3.5 h-3.5"})},{label:"Agents",source:"system:agents",w:3,h:4,icon:n.jsx(eo,{className:"w-3.5 h-3.5"})},{label:"Health",source:"system:health",w:3,h:3,icon:n.jsx(gt,{className:"w-3.5 h-3.5"})},{label:"Stats",source:"system:stats",w:3,h:4,icon:n.jsx(Hl,{className:"w-3.5 h-3.5"})},{label:"Chat",source:"system:chat",w:4,h:5,icon:n.jsx(Zi,{className:"w-3.5 h-3.5"})},{label:"Files",source:"system:files",w:4,h:6,icon:n.jsx(hn,{className:"w-3.5 h-3.5"})},{label:"Skills",source:"system:tools",w:5,h:4,icon:n.jsx(wr,{className:"w-3.5 h-3.5"})},{label:"Soma",source:"system:soma",w:6,h:6,icon:n.jsx(ql,{className:"w-3.5 h-3.5"})},{label:"Intel",source:"system:intelligence",w:6,h:5,icon:n.jsx(yt,{className:"w-3.5 h-3.5"})},{label:"Infra",source:"system:infra",w:6,h:4,icon:n.jsx(jr,{className:"w-3.5 h-3.5"})},{label:"Tools",source:"system:tools",w:5,h:4,icon:n.jsx(Sr,{className:"w-3.5 h-3.5"})},{label:"Settings",source:"system:settings",w:4,h:6,icon:n.jsx(Er,{className:"w-3.5 h-3.5"})},{label:"Daemon",source:"system:daemon",w:5,h:5,icon:n.jsx(gt,{className:"w-3.5 h-3.5"})},{label:"Wiki",source:"system:memory-wiki",w:5,h:5,icon:n.jsx(hs,{className:"w-3.5 h-3.5"})},{label:"Research",source:"system:autoresearch",w:5,h:5,icon:n.jsx(ao,{className:"w-3.5 h-3.5"})},{label:"Proposals",source:"system:self-proposals",w:5,h:5,icon:n.jsx(co,{className:"w-3.5 h-3.5"})},{label:"Overview",source:"system:overview",w:5,h:4,icon:n.jsx(Ji,{className:"w-3.5 h-3.5"})},{label:"Sessions",source:"system:sessions",w:5,h:4,icon:n.jsx(us,{className:"w-3.5 h-3.5"})},{label:"Watch",source:"system:watch",w:6,h:5,icon:n.jsx(gt,{className:"w-3.5 h-3.5"})},{label:"Backup",source:"system:backup",w:5,h:5,icon:n.jsx(lo,{className:"w-3.5 h-3.5"})},{label:"Training",source:"system:training",w:5,h:5,icon:n.jsx(yt,{className:"w-3.5 h-3.5"})},{label:"Recipes",source:"system:recipes",w:5,h:5,icon:n.jsx(hs,{className:"w-3.5 h-3.5"})},{label:"VRAM",source:"system:vram",w:5,h:5,icon:n.jsx(vr,{className:"w-3.5 h-3.5"})},{label:"Teams",source:"system:teams",w:5,h:5,icon:n.jsx(kr,{className:"w-3.5 h-3.5"})},{label:"Cron",source:"system:cron",w:5,h:5,icon:n.jsx(us,{className:"w-3.5 h-3.5"})},{label:"Checkpoints",source:"system:checkpoints",w:5,h:5,icon:n.jsx(pn,{className:"w-3.5 h-3.5"})},{label:"Organism",source:"system:organism",w:5,h:5,icon:n.jsx(_r,{className:"w-3.5 h-3.5"})},{label:"Fleet",source:"system:fleet",w:5,h:5,icon:n.jsx(fo,{className:"w-3.5 h-3.5"})},{label:"Browser",source:"system:browser",w:5,h:5,icon:n.jsx(Xi,{className:"w-3.5 h-3.5"})},{label:"Paperclip",source:"system:paperclip",w:5,h:5,icon:n.jsx(ho,{className:"w-3.5 h-3.5"})},{label:"Eval",source:"system:eval",w:5,h:5,icon:n.jsx(po,{className:"w-3.5 h-3.5"})}];function zg(){const t=(e,s,r)=>{window.dispatchEvent(new CustomEvent("titan:widget:add",{detail:{source:e,w:s,h:r}}))};return n.jsx("div",{className:"w-full h-full p-3 overflow-auto",children:n.jsx("div",{className:"grid grid-cols-2 gap-1.5",children:$g.map(e=>n.jsxs("button",{onClick:()=>t(e.source,e.w,e.h),className:"flex items-center gap-2 px-2.5 py-2 rounded-lg bg-[#0a0a0f] border border-[#27272a] text-[#71717a] hover:text-[#a1a1aa] hover:border-[#3f3f46] hover:bg-[#27272a]/30 transition-all text-left",children:[n.jsx("span",{className:"text-[#6366f1]",children:e.icon}),n.jsx("span",{className:"text-[10px] font-medium",children:e.label})]},e.source))})})}class Hg extends oe.Component{componentDidCatch(e){this.props.onError(e.message)}render(){return this.props.children}}function Vg({name:t,children:e}){const[s,r]=oe.useState(null);return s?n.jsx("div",{className:"w-full h-full flex items-center justify-center p-4",children:n.jsxs("span",{className:"text-xs text-red-400",children:[t,": ",s]})}):n.jsx(Hg,{onError:r,children:e})}const Gg=oe.lazy(()=>le(()=>import("./legacy-BSZBdyop.js"),__vite__mapDeps([94,1,2,4])).then(t=>({default:t.Responsive}))),qg={"system:nav":rl,"system:chat":ll,"system:cmd":fl,"system:soma":pl,"system:command-post":zp,"system:intelligence":Vp,"system:memory-graph":qp,"system:voice":Yp,"system:infra":Jp,"system:tools":Qp,"system:settings":em,"system:files":tm,"system:settings-general":nm,"system:settings-security":im,"system:settings-audit":am,"system:settings-specialists":cm,"system:settings-privacy":um,"system:intelligence-autopilot":fm,"system:intelligence-workflows":mm,"system:intelligence-learning":ym,"system:intelligence-self-improve":xm,"system:intelligence-personas":vm,"system:intelligence-persona-profiles":km,"system:intelligence-dream":jm,"system:infra-homelab":Nm,"system:infra-gpu":Tm,"system:infra-files":Am,"system:infra-logs":Im,"system:infra-telemetry":Mm,"system:tools-skills":Wm,"system:tools-mcp":Bm,"system:tools-integrations":Fm,"system:tools-channels":zm,"system:tools-mesh":Vm,"system:agents":Bg,"system:health":Ug,"system:stats":Fg,"system:quick-links":zg,"system:memory-wiki":qm,"system:autoresearch":Km,"system:self-proposals":Xm,"system:overview":Zm,"system:sessions":tg,"system:watch":ng,"system:backup":ig,"system:training":ag,"system:recipes":cg,"system:vram":ug,"system:teams":fg,"system:cron":mg,"system:checkpoints":yg,"system:organism":xg,"system:fleet":vg,"system:browser":kg,"system:eval":jg,"system:time-travel":Cg,"system:mission-driver":Ag,"system:daily-digest":Og,"system:mission-graph":Pg},Yg={lg:12,md:10,sm:6,xs:4,xxs:2},Kg=60,Jg={lg:1200,md:996,sm:768,xs:480,xxs:0},Xg=[12,12],Qg=["se","sw","ne","nw","e","w","n","s"],ml=oe.forwardRef(({widget:t,space:e,onRemove:s,style:r,className:i,onMouseDown:o,onMouseUp:c,onTouchStart:l,onTouchEnd:d,children:p},g)=>{const u=w.useCallback(()=>s(t.id),[t.id,s]);return n.jsxs("div",{ref:g,style:r,className:i,onMouseDown:o,onMouseUp:c,onTouchStart:l,onTouchEnd:d,children:[n.jsx(ty,{widget:t,space:e,onRemove:u}),p]})});ml.displayName="MemoWidgetItem";const Zg=oe.memo(ml);function ey({widget:t,space:e,onRemove:s}){const r=w.useRef(null),i=w.useRef(null),o=w.useRef(e),[c,l]=w.useState(null),[d,p]=w.useState(!0);if(w.useEffect(()=>{o.current=e},[e]),w.useEffect(()=>{if(t.format==="system"||!r.current)return;if(!t.source||t.source.trim()===""){l("Empty widget — no source code"),p(!1);return}p(!0),l(null),i.current=new nl(r.current,{onLog:u=>console.log(`[Widget ${t.id}]`,u)}),i.current.setMessageHandler(u=>{var x,b,E,A;const f=o.current;if(u.type==="canvas"&&((x=u.payload)==null?void 0:x.action)==="createWidget"){const v=u.payload.def;if(!v)return{ok:!1,error:"createWidget requires a `def` object"};const L=Number.isFinite(v.w)?v.w:4,m=Number.isFinite(v.h)?v.h:4,k=Number.isFinite(v.x)&&Number.isFinite(v.y)?{x:v.x,y:v.y}:Hs(f.widgets||[],L,m);try{const _=ke.addWidget(f.id,{name:v.name||"Agent Widget",format:v.format||"react",source:v.source||"",x:k.x,y:k.y,w:L,h:m});return window.dispatchEvent(new CustomEvent("titan:space:refresh",{detail:{spaceId:f.id}})),{ok:!0,widgetId:_.id}}catch(_){return{ok:!1,error:_.message}}}if(u.type==="canvas"&&((b=u.payload)==null?void 0:b.action)==="updateWidget"){const{id:v,patch:L}=u.payload;return v?(ke.updateWidget(f.id,v,L||{}),window.dispatchEvent(new CustomEvent("titan:space:refresh",{detail:{spaceId:f.id}})),{ok:!0,id:v}):{ok:!1,error:"updateWidget requires an `id`"}}if(u.type==="canvas"&&((E=u.payload)==null?void 0:E.action)==="listWidgets")return{ok:!0,widgets:f.widgets||[]};if(u.type==="canvas"&&((A=u.payload)==null?void 0:A.action)==="removeWidget"){const v=u.payload.id;return v?(ke.removeWidget(f.id,v),window.dispatchEvent(new CustomEvent("titan:space:refresh",{detail:{spaceId:f.id}})),{ok:!0}):{ok:!1,error:"removeWidget requires an `id`"}}return{ok:!1,error:"Unknown message type"}});const g=setTimeout(()=>{p(!1),l("Sandbox timeout: widget took longer than 30s to render. The widget source may have an infinite loop or an unhandled exception. Open DevTools (F12) → Console to see the iframe-side error.")},3e4);return i.current.render(t.format,t.source).then(()=>{clearTimeout(g),p(!1)}).catch(u=>{clearTimeout(g),p(!1),l(String(u))}),()=>{var u;clearTimeout(g),(u=i.current)==null||u.destroy()}},[t.format,t.source,t.id]),t.format==="system"){const g=qg[t.source];return g?n.jsxs("div",{className:"w-full h-full rounded-xl overflow-hidden flex flex-col group transition-colors shadow-md",style:{background:"var(--color-desk-widget-bg)",border:"1px solid var(--color-desk-border)",boxShadow:"0 4px 12px var(--theme-shadow, rgba(60,40,15,0.15))"},children:[n.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b panel-drag-handle cursor-move",style:{borderColor:"var(--color-desk-border-light)",background:"var(--theme-leather, rgba(58,37,24,0.05))"},children:[n.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider",style:{color:"var(--color-desk-accent)"},children:t.name}),n.jsx("button",{onClick:s,className:"opacity-0 group-hover:opacity-100 text-xs px-1 transition-opacity",style:{color:"var(--color-desk-text-muted)"},children:"×"})]}),n.jsx("div",{className:"flex-1 overflow-auto relative",children:n.jsx(Vg,{name:t.name,children:n.jsx(g,{space:e,widget:t,onRemove:s})})})]}):n.jsxs("div",{className:"w-full h-full flex items-center justify-center text-xs text-red-400",children:["Unknown system widget: ",t.source]})}return n.jsxs("div",{className:"w-full h-full rounded-xl overflow-hidden flex flex-col shadow-md",style:{background:"var(--color-desk-widget-bg)",border:"1px solid var(--color-desk-border)",boxShadow:"0 4px 12px var(--theme-shadow, rgba(60,40,15,0.15))"},children:[n.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b panel-drag-handle cursor-move",style:{borderColor:"var(--color-desk-border-light)",background:"var(--theme-leather, rgba(58,37,24,0.05))"},children:[n.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider",style:{color:"var(--color-desk-accent)"},children:t.name}),n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("button",{onClick:g=>{g.stopPropagation(),window.dispatchEvent(new CustomEvent("titan:widget:edit",{detail:{spaceId:e.id,widgetId:t.id}}))},onMouseDown:g=>g.stopPropagation(),className:"px-1",style:{color:"var(--color-desk-text-muted)"},title:"Edit widget",children:n.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"m18 2 4 4-14 14H4v-4L18 2z"})})}),n.jsx("button",{onClick:s,className:"text-xs px-1",style:{color:"var(--color-desk-text-muted)"},children:"×"})]})]}),n.jsx("div",{className:"flex-1 relative",children:c?n.jsx("div",{className:"p-3 text-xs text-red-400 font-mono whitespace-pre-wrap",children:c}):n.jsxs(n.Fragment,{children:[n.jsx("iframe",{ref:r,className:"w-full h-full border-0",sandbox:"allow-scripts",title:t.name}),d&&n.jsx("div",{className:"absolute inset-0 flex items-center justify-center text-xs",style:{background:"var(--theme-paper, rgba(253,246,227,0.85))",color:"var(--color-desk-text-muted)",fontFamily:"var(--theme-font-display, 'Georgia', serif)"},children:n.jsx("span",{className:"animate-pulse",children:"Loading widget…"})})]})})]})}const ty=oe.memo(ey);function sy(){const{spaceId:t}=Cl(),e=Ki(),[s,r]=w.useState(null),[i]=w.useState(!0),[o,c]=w.useState(!1),[l,d]=w.useState(null),[p,g]=w.useState(!1),[u,f]=w.useState(!1),[x,b]=w.useState(!1),[E,A]=w.useState(1200),v=w.useRef(null),L=w.useRef(null),{info:m,triggerUpdate:k}=Cf(),[_,T]=w.useState(!1);w.useEffect(()=>{const P=t||"home",V=ke.get(P);V?r(V):e("/space/home",{replace:!0})},[t,e]),w.useEffect(()=>{const P=()=>{const te=L.current;if(!te)return null;const re=new ResizeObserver(Q=>{for(const ee of Q)A(ee.contentRect.width)});return re.observe(te),A(te.getBoundingClientRect().width||1200),re};let V=P();const $=setInterval(()=>{V||(V=P()),V&&clearInterval($)},200);return()=>{V==null||V.disconnect(),clearInterval($)}},[s==null?void 0:s.id]),w.useEffect(()=>{const P=V=>{(V.metaKey||V.ctrlKey)&&V.key==="k"&&(V.preventDefault(),f($=>!$)),(V.metaKey||V.ctrlKey)&&V.key==="j"&&(V.preventDefault(),window.dispatchEvent(new CustomEvent("titan:chat:toggle")))};return window.addEventListener("keydown",P),()=>window.removeEventListener("keydown",P)},[]),Tf([{key:"?",action:()=>b(!0),description:"Show keyboard shortcuts help"},{key:"g",shift:!0,action:()=>e("/space/command"),description:"Go to Command Post space"},{key:"h",shift:!0,action:()=>e("/space/home"),description:"Go to Home space"},{key:"s",shift:!0,action:()=>e("/space/settings"),description:"Go to Settings space"},{key:"i",shift:!0,action:()=>e("/space/intelligence"),description:"Go to Intelligence space"}]);const S=w.useCallback(()=>{},[]),N=w.useRef(null),D=w.useRef(null),j=w.useCallback(P=>{s&&(D.current=P,N.current&&clearTimeout(N.current),N.current=setTimeout(()=>{const V=D.current;!V||!s||(ke.updateLayout(s.id,V.map($=>({i:$.i,x:$.x,y:$.y,w:$.w,h:$.h}))),D.current=null,N.current=null)},50))},[s]),R=w.useCallback(P=>{var te;if(!s)return;const V=(te=s.widgets)==null?void 0:te.find(re=>re.id===P);Ln("canvas_panel_removed",{widgetId:P,format:V==null?void 0:V.format,source:V==null?void 0:V.source}),ke.removeWidget(s.id,P);const $=Array.isArray(s.widgets)?s.widgets:[];r({...s,widgets:$.filter(re=>re.id!==P)})},[s]),O=w.useCallback(P=>{if(!s)return;const V=ke.addWidget(s.id,P),$=Array.isArray(s.widgets)?s.widgets:[];return r({...s,widgets:[...$,V]}),Ln(P.format==="system"?"canvas_system_panel_created":"canvas_panel_created",{source:P.source,name:P.name,format:P.format}),V},[s]),U=w.useCallback((P,V)=>{if(!s||!Array.isArray(s.widgets)||s.widgets.length===0)return{x:0,y:0};const $=12,te=new Set;for(const re of s.widgets)for(let Q=0;Q<re.w;Q++)for(let ee=0;ee<re.h;ee++)te.add(`${re.x+Q},${re.y+ee}`);for(let re=0;re<200;re++)for(let Q=0;Q<=$-P;Q++){let ee=!0;for(let X=0;X<P;X++){for(let ve=0;ve<V;ve++)if(te.has(`${Q+X},${re+ve}`)){ee=!1;break}if(!ee)break}if(ee)return{x:Q,y:re}}return{x:0,y:0}},[s]),z=w.useCallback((P,V,$=4,te=4)=>{const re=U($,te);O({name:V,format:"system",source:P,x:re.x,y:re.y,w:$,h:te})},[O,U]);w.useEffect(()=>{const P=V=>{const $=V.detail;if(console.log("[TitanCanvas] titan:space:refresh received:",$),!!s&&($==null?void 0:$.spaceId)===s.id){const te=ke.get(s.id);te&&(console.log("[TitanCanvas] Refreshing space, widget count:",te.widgets.length),r(te))}};return window.addEventListener("titan:space:refresh",P),()=>window.removeEventListener("titan:space:refresh",P)},[s]),w.useEffect(()=>{const P=V=>{const $=V.detail;if(s&&$!=null&&$.source){const te=Number.isFinite($.w)?$.w:4,re=Number.isFinite($.h)?$.h:4,Q=typeof $.name=="string"&&$.name.trim()?$.name.trim():String($.source).replace("system:","").replace(/-/g," "),ee=$.format==="react"||$.format==="vanilla"||$.format==="html"||$.format==="system"?$.format:String($.source).startsWith("system:")?"system":"react",X=U(te,re);O({name:Q,format:ee,source:String($.source),x:X.x,y:X.y,w:te,h:re})}};return window.addEventListener("titan:widget:add",P),()=>window.removeEventListener("titan:widget:add",P)},[s,O,U]),w.useEffect(()=>{const P=V=>{const $=V.detail;s&&($==null?void 0:$.spaceId)===s.id&&typeof($==null?void 0:$.widgetId)=="string"&&d($.widgetId)};return window.addEventListener("titan:widget:edit",P),()=>window.removeEventListener("titan:widget:edit",P)},[s]),w.useEffect(()=>s?ke.observe(s.id,V=>{console.log("[TitanCanvas] CRDT observer fired, widgets:",V.length),r($=>$&&{...$,widgets:V})}):void 0,[s==null?void 0:s.id]);const G=w.useMemo(()=>{const P=s==null?void 0:s.widgets;return Array.isArray(P)?P.filter(Boolean):[]},[s]),q=w.useMemo(()=>G.map((P,V)=>({i:P.id,x:Number.isFinite(P.x)?P.x:V%3*4,y:Number.isFinite(P.y)?P.y:Math.floor(V/3)*4,w:Number.isFinite(P.w)?P.w:4,h:Number.isFinite(P.h)?P.h:4,minW:2,minH:2,maxW:12,maxH:40})),[G]);return s?n.jsxs("div",{className:"h-full w-full flex",children:[n.jsx(jp,{}),n.jsxs("div",{ref:v,className:"flex-1 relative overflow-auto",children:[n.jsx("style",{children:`
|
|
1030
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle {
|
|
1031
|
+
background: none;
|
|
1032
|
+
padding: 0;
|
|
1033
|
+
opacity: 0.35;
|
|
1034
|
+
z-index: 10;
|
|
1035
|
+
transition: opacity 120ms ease, background-color 120ms ease;
|
|
1036
|
+
}
|
|
1037
|
+
.titan-canvas-grid .react-grid-item:hover > .react-resizable-handle { opacity: 0.85; }
|
|
1038
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle:hover,
|
|
1039
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle:active { opacity: 1; }
|
|
1040
|
+
/* Corner handles: 22x22 with a ring-coloured chevron */
|
|
1041
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-se,
|
|
1042
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-sw,
|
|
1043
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-ne,
|
|
1044
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-nw {
|
|
1045
|
+
width: 22px;
|
|
1046
|
+
height: 22px;
|
|
1047
|
+
background-image: none;
|
|
1048
|
+
transform: none;
|
|
1049
|
+
}
|
|
1050
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-se::after,
|
|
1051
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-sw::after,
|
|
1052
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-ne::after,
|
|
1053
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-nw::after {
|
|
1054
|
+
content: "";
|
|
1055
|
+
position: absolute;
|
|
1056
|
+
width: 12px; height: 12px;
|
|
1057
|
+
border: 2px solid var(--color-desk-brass);
|
|
1058
|
+
border-radius: 3px;
|
|
1059
|
+
}
|
|
1060
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-se::after { right: 3px; bottom: 3px; border-top: none; border-left: none; }
|
|
1061
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-sw::after { left: 3px; bottom: 3px; border-top: none; border-right: none; }
|
|
1062
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-ne::after { right: 3px; top: 3px; border-bottom: none; border-left: none; }
|
|
1063
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-nw::after { left: 3px; top: 3px; border-bottom: none; border-right: none; }
|
|
1064
|
+
/* Edge handles: full-edge strips with a centre grip */
|
|
1065
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-e,
|
|
1066
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-w {
|
|
1067
|
+
top: 8px; bottom: 8px; height: auto; margin-top: 0;
|
|
1068
|
+
width: 8px; background-image: none; transform: none;
|
|
1069
|
+
}
|
|
1070
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-n,
|
|
1071
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-s {
|
|
1072
|
+
left: 8px; right: 8px; width: auto; margin-left: 0;
|
|
1073
|
+
height: 8px; background-image: none; transform: none;
|
|
1074
|
+
}
|
|
1075
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-e::after,
|
|
1076
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-w::after,
|
|
1077
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-n::after,
|
|
1078
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-s::after {
|
|
1079
|
+
content: ""; position: absolute; background: var(--color-desk-brass); border-radius: 2px;
|
|
1080
|
+
}
|
|
1081
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-e::after,
|
|
1082
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-w::after {
|
|
1083
|
+
top: 50%; transform: translateY(-50%);
|
|
1084
|
+
width: 3px; height: 32px;
|
|
1085
|
+
}
|
|
1086
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-e::after { right: 2px; }
|
|
1087
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-w::after { left: 2px; }
|
|
1088
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-n::after,
|
|
1089
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-s::after {
|
|
1090
|
+
left: 50%; transform: translateX(-50%);
|
|
1091
|
+
height: 3px; width: 32px;
|
|
1092
|
+
}
|
|
1093
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-n::after { top: 2px; }
|
|
1094
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-s::after { bottom: 2px; }
|
|
1095
|
+
/* Allow resizing and dragging freely — placeholder turns accent blue */
|
|
1096
|
+
.titan-canvas-grid .react-grid-placeholder {
|
|
1097
|
+
background: rgba(99, 102, 241, 0.14) !important;
|
|
1098
|
+
border: 1px dashed rgba(99, 102, 241, 0.55) !important;
|
|
1099
|
+
border-radius: 12px;
|
|
1100
|
+
opacity: 1 !important;
|
|
1101
|
+
}
|
|
1102
|
+
`}),n.jsx("div",{className:"fixed inset-0 opacity-[0.04] pointer-events-none",style:{backgroundImage:"radial-gradient(circle at 1px 1px, var(--theme-metal-dark, rgba(120,90,50,0.4)) 1px, transparent 0)",backgroundSize:"24px 24px"}}),n.jsxs("div",{className:"absolute top-0 left-0 right-0 h-10 flex items-center justify-between px-4 z-40 border-b backdrop-blur-sm",style:{borderColor:"var(--color-desk-border)",background:"var(--color-desk-header-bg)"},children:[n.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[n.jsx("span",{className:"text-xs font-bold uppercase tracking-widest",style:{color:s.color||"var(--color-desk-accent)"},children:s.name}),n.jsxs("button",{onClick:()=>e("/mission"),className:"group relative inline-flex items-center gap-2 px-3 py-1.5 rounded-full transition-all",title:"Open Mission Chat — a chat-style team-control surface with a real desk view",style:{background:"linear-gradient(120deg, rgba(176,138,58,0.18) 0%, rgba(99,102,241,0.16) 100%)",border:"1px solid var(--theme-metal, rgba(176,138,58,0.45))",boxShadow:"0 0 0 0 rgba(176,138,58,0.4)"},children:[n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",style:{color:"var(--theme-metal-bright, #f5d27a)",flexShrink:0},children:[n.jsx("path",{d:"M3 17h18",strokeLinecap:"round"}),n.jsx("path",{d:"M5 17V9a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v8"}),n.jsx("rect",{x:"8",y:"9",width:"6",height:"6",rx:"0.5",fill:"var(--theme-paper, rgba(247,245,238,0.85))",stroke:"var(--theme-ink, rgba(40,30,15,0.6))",strokeWidth:"0.8"}),n.jsx("rect",{x:"13",y:"10.5",width:"4",height:"4",rx:"0.3",fill:"var(--theme-sticky-yellow, rgba(255,242,168,0.95))",stroke:"var(--theme-metal-dark, rgba(120,90,30,0.5))",strokeWidth:"0.7"}),n.jsx("path",{d:"M7 17v3M17 17v3",strokeLinecap:"round"})]}),n.jsx("span",{className:"text-[11px] font-semibold tracking-tight group-hover:text-white",style:{color:"var(--theme-metal-bright, #f5d27a)"},children:"Mission Chat"}),n.jsx("span",{className:"text-[8px] font-bold uppercase tracking-widest text-bg-deep px-1.5 py-[1px] rounded-full",style:{background:"linear-gradient(180deg, var(--theme-metal-bright, #ffd86e) 0%, var(--theme-metal-dark, #b07a1a) 100%)",boxShadow:"0 1px 2px var(--theme-shadow, rgba(0,0,0,0.4))",animation:"missionPulse 2.4s ease-in-out infinite"},children:"NEW"}),n.jsx("style",{children:"@keyframes missionPulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.7; transform: scale(1.06); } }"})]}),n.jsxs("button",{onClick:()=>c(!0),className:"flex items-center gap-1.5 text-[10px] text-[#52525b] hover:text-[#a5b4fc] truncate max-w-md transition-colors",title:"Edit agent instructions for this space",children:[n.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:n.jsx("path",{d:"m18 2 4 4-14 14H4v-4L18 2z"})}),s.agentInstructions?n.jsx("span",{className:"truncate",children:s.agentInstructions}):n.jsx("span",{className:"italic",children:"add agent instructions"})]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("span",{className:"text-[10px]",style:{color:"var(--color-desk-text-muted)"},children:[G.length," panel",G.length!==1?"s":""]}),n.jsx("button",{onClick:()=>z("system:nav","Nav",3,4),className:"text-[10px] px-2 py-1 rounded-md transition-colors",style:{background:"var(--theme-paper, rgba(253,246,227,0.7))",border:"1px solid var(--color-desk-border)",color:"var(--color-desk-text-secondary)"},title:"Add Navigation",children:"Nav"}),n.jsx("button",{onClick:()=>z("system:agents","Agents",3,4),className:"text-[10px] px-2 py-1 rounded-md transition-colors",style:{background:"var(--theme-paper, rgba(253,246,227,0.7))",border:"1px solid var(--color-desk-border)",color:"var(--color-desk-text-secondary)"},title:"Add Agents",children:"Agents"}),n.jsx("button",{onClick:()=>z("system:health","Health",3,3),className:"text-[10px] px-2 py-1 rounded-md transition-colors",style:{background:"var(--theme-paper, rgba(253,246,227,0.7))",border:"1px solid var(--color-desk-border)",color:"var(--color-desk-text-secondary)"},title:"Add Health",children:"Health"}),n.jsx("button",{onClick:()=>z("system:stats","Stats",3,4),className:"text-[10px] px-2 py-1 rounded-md transition-colors",style:{background:"var(--theme-paper, rgba(253,246,227,0.7))",border:"1px solid var(--color-desk-border)",color:"var(--color-desk-text-secondary)"},title:"Add Stats",children:"Stats"}),n.jsx("button",{onClick:()=>z("system:quick-links","Quick Links",3,4),className:"text-[10px] px-2 py-1 rounded-md transition-colors",style:{background:"var(--theme-paper, rgba(253,246,227,0.7))",border:"1px solid var(--color-desk-border)",color:"var(--color-desk-text-secondary)"},title:"Add Quick Links",children:"Links"}),n.jsx("button",{onClick:()=>z("system:chat","Chat",4,5),className:"text-[10px] px-2 py-1 rounded-md transition-colors",style:{background:"var(--theme-paper, rgba(253,246,227,0.7))",border:"1px solid var(--color-desk-border)",color:"var(--color-desk-text-secondary)"},title:"Add Chat",children:"Chat"}),G.length>0&&n.jsx("button",{onClick:async()=>{Ln("canvas_clear_all",{panelCount:G.length}),s&&(await ke.clearSpace(s.id),r({...s,widgets:[]}))},className:"text-[10px] px-2 py-1 rounded-md bg-[#ef4444]/5 border border-[#ef4444]/10 text-[#ef4444]/70 hover:bg-[#ef4444]/10 transition-colors",children:"Clear"}),n.jsx("button",{disabled:_,className:`text-[10px] px-2 py-0.5 rounded-full border transition-colors ${m!=null&&m.isNewer?"bg-[#f59e0b]/10 border-[#f59e0b]/30 text-[#f59e0b] hover:bg-[#f59e0b]/20 cursor-pointer":"border text-[#6b5a45]"}`,style:m!=null&&m.isNewer?void 0:{background:"var(--theme-paper, rgba(253,246,227,0.7))",borderColor:"var(--color-desk-border)"},title:m!=null&&m.isNewer?`Update available: ${m.current} → ${m.latest}`:`TITAN ${(m==null?void 0:m.current)||""}`,onClick:async()=>{if(!(m!=null&&m.isNewer)||_||!confirm(`Update TITAN from ${m.current} → ${m.latest}?
|
|
1103
|
+
|
|
1104
|
+
Your data in ~/.titan/ will be preserved. The gateway will restart after the update.`))return;T(!0);const P=await k(!0);T(!1),P.ok?alert("Update initiated. The gateway will restart shortly. Please refresh the page in 10-15 seconds."):alert(`Update failed: ${P.error||"Unknown error"}`)},children:_?"…":m!=null&&m.isNewer?`↑ ${m.latest}`:`v${(m==null?void 0:m.current)||""}`}),n.jsxs("button",{onClick:()=>g(!0),className:"text-[10px] px-2 py-1 rounded-md transition-colors flex items-center gap-1.5",style:{background:"var(--theme-paper, rgba(253,246,227,0.7))",border:"1px solid var(--color-desk-border)",color:"var(--color-desk-accent)"},title:"Widget gallery",children:[n.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M12 3l1.9 5.8L20 10l-5 3.6 1.5 6L12 16l-4.5 3.6L9 13.6 4 10l6.1-1.2L12 3z"})}),"Gallery"]}),n.jsx("button",{onClick:()=>f(!0),className:"text-[10px] px-2 py-1 rounded-md transition-colors",style:{background:"var(--theme-paper, rgba(253,246,227,0.7))",border:"1px solid var(--color-desk-border)",color:"var(--color-desk-text-secondary)"},children:"⌘K"}),n.jsx("button",{onClick:()=>window.dispatchEvent(new CustomEvent("titan:chat:toggle")),className:"text-[10px] px-2 py-1 rounded-md transition-colors",style:{background:"var(--theme-paper, rgba(253,246,227,0.7))",border:"1px solid var(--color-desk-border)",color:"var(--color-desk-text-secondary)"},children:"⌘J"})]})]}),n.jsx("div",{ref:L,className:"relative pt-24 min-h-[5000px]",children:G.length===0?n.jsx(ny,{space:s,onAddWidget:z,onOpenChat:()=>window.dispatchEvent(new CustomEvent("titan:chat:toggle",{detail:{open:!0}}))}):n.jsx(w.Suspense,{fallback:n.jsx("div",{className:"pt-12 text-center",children:n.jsx("div",{className:"inline-block rounded-xl px-6 py-3 border text-sm font-serif",style:{background:"var(--color-desk-widget-bg)",borderColor:"var(--color-desk-border)",color:"var(--color-desk-text-muted)"},children:"Loading grid..."})}),children:n.jsx(Gg,{className:"layout titan-canvas-grid",width:E,layouts:{lg:q},breakpoints:Jg,cols:Yg,rowHeight:Kg,margin:Xg,containerPadding:[12,12],isDraggable:!0,isResizable:!0,draggableHandle:".panel-drag-handle",resizeHandles:Qg,compactType:null,preventCollision:!1,allowOverlap:!0,useCSSTransforms:!0,onLayoutChange:S,onDragStop:P=>{j(P)},onResizeStop:P=>{j(P)},children:G.map(P=>n.jsx(Zg,{widget:P,space:s,onRemove:R},P.id))})})}),n.jsx("div",{className:"fixed right-4 bottom-32 z-50",children:n.jsx(rl,{currentSpaceId:s.id,onSpaceSelect:P=>e(`/space/${P}`)})}),n.jsx(wp,{space:s,defaultExpanded:i}),n.jsx(kp,{}),n.jsx(Cp,{space:s,open:o,onClose:()=>c(!1),onSaved:P=>{r(V=>V&&{...V,agentInstructions:P||void 0})}}),l&&(()=>{const P=G.find(V=>V.id===l);return!P||P.format==="system"?(d(null),null):n.jsx(Ap,{widget:P,spaceId:s.id,open:!0,onClose:()=>d(null),onSaved:V=>{const $=G.map(te=>te.id===V.id?{...te,...V}:te);r(te=>te&&{...te,widgets:$})}})})(),n.jsx(Op,{open:p,onClose:()=>g(!1)}),n.jsx(Fp,{}),u&&n.jsx(fl,{currentSpaceId:s.id,onSpaceSelect:P=>{e(`/space/${P}`),f(!1)},onAction:P=>{P.type==="widget"&&z(P.source,P.name,P.w,P.h),f(!1)},onClose:()=>f(!1)}),n.jsx(Af,{open:x,onClose:()=>b(!1)})]})]}):n.jsx("div",{className:"h-full w-full flex items-center justify-center",children:n.jsx("div",{className:"rounded-xl px-6 py-3 border text-sm",style:{background:"var(--color-desk-widget-bg)",borderColor:"var(--color-desk-border)",color:"var(--color-desk-text-muted)",fontFamily:"var(--theme-font-display, 'Georgia', serif)"},children:"Loading space..."})})}function ny({space:t,onAddWidget:e,onOpenChat:s}){const r=[{title:"System",items:[{label:"SOMA",source:"system:soma",w:6,h:6},{label:"Command Post",source:"system:command-post",w:8,h:6},{label:"Overview",source:"system:overview",w:6,h:5},{label:"Organism",source:"system:organism",w:6,h:6},{label:"Infra",source:"system:infra",w:6,h:4},{label:"VRAM",source:"system:vram",w:6,h:6},{label:"Fleet",source:"system:fleet",w:6,h:5}]},{title:"Intelligence",items:[{label:"Intelligence",source:"system:intelligence",w:6,h:5},{label:"Memory Graph",source:"system:memory-graph",w:8,h:7},{label:"Memory Wiki",source:"system:memory-wiki",w:6,h:6},{label:"Autoresearch",source:"system:autoresearch",w:6,h:6},{label:"Self-Proposals",source:"system:self-proposals",w:6,h:6},{label:"Training",source:"system:training",w:6,h:6},{label:"Eval",source:"system:eval",w:6,h:6}]},{title:"Tools",items:[{label:"Tools",source:"system:tools",w:5,h:4},{label:"Files",source:"system:files",w:4,h:6},{label:"Browser",source:"system:browser",w:6,h:5},{label:"Recipes",source:"system:recipes",w:6,h:6},{label:"Voice",source:"system:voice",w:5,h:5}]},{title:"Workflows",items:[{label:"Mission Driver",source:"system:mission-driver",w:7,h:7},{label:"Mission Graph",source:"system:mission-graph",w:8,h:7},{label:"Daily Digest",source:"system:daily-digest",w:5,h:7},{label:"Time Travel",source:"system:time-travel",w:8,h:6},{label:"Sessions",source:"system:sessions",w:6,h:5},{label:"Checkpoints",source:"system:checkpoints",w:6,h:5},{label:"Cron",source:"system:cron",w:6,h:6}]},{title:"Comms",items:[{label:"Watch",source:"system:watch",w:8,h:7},{label:"Backup",source:"system:backup",w:6,h:6},{label:"Teams",source:"system:teams",w:6,h:6}]}];return n.jsx("div",{className:"h-full flex items-start justify-center pt-10 pb-32 px-6",children:n.jsxs("div",{className:"text-center w-full max-w-3xl rounded-2xl px-8 py-10 border",style:{background:"var(--color-desk-widget-bg)",borderColor:"var(--color-desk-border)",boxShadow:"0 4px 16px var(--theme-shadow)"},children:[n.jsx("style",{children:`
|
|
1105
|
+
.titan-empty-hero {
|
|
1106
|
+
background: linear-gradient(180deg,
|
|
1107
|
+
color-mix(in srgb, var(--theme-metal-bright) 22%, transparent) 0%,
|
|
1108
|
+
color-mix(in srgb, var(--theme-metal) 14%, transparent) 100%);
|
|
1109
|
+
color: var(--theme-accent);
|
|
1110
|
+
border: 1px solid color-mix(in srgb, var(--theme-metal) 55%, transparent);
|
|
1111
|
+
box-shadow:
|
|
1112
|
+
0 0 0 0 color-mix(in srgb, var(--theme-accent) 0%, transparent),
|
|
1113
|
+
0 2px 6px var(--theme-shadow);
|
|
1114
|
+
transition: transform 140ms ease, box-shadow 220ms ease, border-color 140ms ease;
|
|
1115
|
+
font-family: var(--theme-font-display);
|
|
1116
|
+
}
|
|
1117
|
+
.titan-empty-hero:hover {
|
|
1118
|
+
transform: translateY(-1px);
|
|
1119
|
+
border-color: var(--theme-metal-bright);
|
|
1120
|
+
box-shadow:
|
|
1121
|
+
0 0 24px color-mix(in srgb, var(--theme-accent) 35%, transparent),
|
|
1122
|
+
0 4px 12px var(--theme-shadow);
|
|
1123
|
+
}
|
|
1124
|
+
.titan-empty-chip {
|
|
1125
|
+
width: 110px;
|
|
1126
|
+
background: var(--theme-paper);
|
|
1127
|
+
color: var(--theme-ink-soft);
|
|
1128
|
+
border: 1px solid color-mix(in srgb, var(--theme-metal) 40%, transparent);
|
|
1129
|
+
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--theme-paper-line) 50%, transparent);
|
|
1130
|
+
font-family: var(--theme-font-display);
|
|
1131
|
+
transition: transform 120ms ease, border-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
|
|
1132
|
+
}
|
|
1133
|
+
.titan-empty-chip:hover {
|
|
1134
|
+
transform: translateY(-1px);
|
|
1135
|
+
border-color: var(--theme-metal-bright);
|
|
1136
|
+
color: var(--theme-ink);
|
|
1137
|
+
box-shadow:
|
|
1138
|
+
inset 0 0 0 1px color-mix(in srgb, var(--theme-metal-bright) 35%, transparent),
|
|
1139
|
+
0 2px 6px var(--theme-shadow);
|
|
1140
|
+
}
|
|
1141
|
+
.titan-empty-group-label {
|
|
1142
|
+
font-family: var(--theme-font-mono);
|
|
1143
|
+
color: var(--theme-metal-dark);
|
|
1144
|
+
letter-spacing: 0.18em;
|
|
1145
|
+
}
|
|
1146
|
+
.titan-empty-rule {
|
|
1147
|
+
background: linear-gradient(90deg,
|
|
1148
|
+
transparent 0%,
|
|
1149
|
+
color-mix(in srgb, var(--theme-metal) 50%, transparent) 50%,
|
|
1150
|
+
transparent 100%);
|
|
1151
|
+
}
|
|
1152
|
+
`}),n.jsx("div",{className:"w-16 h-16 rounded-2xl flex items-center justify-center mx-auto mb-5",style:{background:"color-mix(in srgb, var(--theme-metal) 16%, transparent)",border:"1px solid color-mix(in srgb, var(--theme-metal) 35%, transparent)"},children:n.jsx("svg",{className:"w-7 h-7",style:{color:"var(--theme-metal)"},fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z"})})}),n.jsx("h2",{className:"text-xl font-bold mb-2",style:{color:"var(--theme-ink)",fontFamily:"var(--theme-font-display)"},children:t.name}),n.jsx("p",{className:"text-sm mb-7",style:{color:"var(--theme-ink-soft)",fontFamily:"var(--theme-font-display)"},children:"This space is empty. Ask the agent to materialize something for you, or place a system panel below."}),n.jsx("div",{className:"flex justify-center mb-8",children:n.jsxs("button",{onClick:s,className:"titan-empty-hero inline-flex items-center gap-2 px-6 py-3 rounded-xl text-base font-semibold",children:[n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M12 2a7 7 0 0 0-4 12.7V17a2 2 0 0 0 2 2h4a2 2 0 0 0 2-2v-2.3A7 7 0 0 0 12 2z"}),n.jsx("path",{d:"M10 22h4"})]}),"Ask Agent"]})}),n.jsx("div",{className:"space-y-5 text-left",children:r.map(i=>n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-3 mb-2.5 px-1",children:[n.jsx("span",{className:"titan-empty-group-label text-[10px] font-bold uppercase",children:i.title}),n.jsx("span",{className:"titan-empty-rule flex-1 h-px"})]}),n.jsx("div",{className:"flex gap-2 flex-wrap",children:i.items.map(o=>n.jsxs("button",{onClick:()=>e(o.source,o.label,o.w,o.h),className:"titan-empty-chip px-3 py-1.5 rounded-lg text-[11px] text-center",title:`Add ${o.label}`,children:["+ ",o.label]},o.source))})]},i.title))})]})})}const ky=Object.freeze(Object.defineProperty({__proto__:null,default:sy},Symbol.toStringTag,{value:"Module"}));export{lo as A,hs as B,$l as D,co as G,Xl as H,li as P,fo as R,Er as S,po as T,oc as W,yt as a,jr as b,ky as c};
|